const __vite__fileDeps=["assets/search-docs-data-JLe790su.js","assets/vendor-BCKkA27H.js"],__vite__mapDeps=i=>i.map(i=>__vite__fileDeps[i]); import { _ as __vitePreload } from "./GenericMountStory.vue2-BX48YWx2.js"; import { r as ref, k as watch, c as computed, d as defineComponent, o as openBlock, b as createElementBlock, aF as renderSlot, n as normalizeClass, m as withKeys, q as createBlock, g as unref, I as Icon, e as createVNode, f as createBaseVNode, z as createTextVNode, t as toDisplayString, F as Fragment, p as renderList, h as createCommentVNode, u as useCssVars, aS as toRefs, aT as useRouter, w as withCtx, aB as markRaw, b4 as useFocus, b5 as refDebounced, y as withDirectives, aM as vModelText, aL as withModifiers, b6 as flexsearch_bundleExports } from "./vendor-BCKkA27H.js"; import { u as useStoryStore } from "./story--eZPzd9h.js"; import { B as BaseEmpty } from "./BaseEmpty.vue-C0i8tRal.js"; import { o as onKeyboardShortcut, u as useCommandStore } from "./bundle-main-BYW_JKZH.js"; import { _ as _export_sfc, u as useScrollOnActive, B as BaseListItemLink } from "./MobileOverlay.vue2-BRmV4xb2.js"; function pipeline(a, b, c, d) { if (a && (b && (a = replace(a, b)), this.matcher && (a = replace(a, this.matcher)), this.stemmer && 1 < a.length && (a = replace(a, this.stemmer)), d && 1 < a.length && (a = collapse(a)), c || "" === c)) { const b2 = a.split(c); return this.filter ? filter$1(b2, this.filter) : b2; } return a; } const regex_whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u; const regex_normalize = /[\u0300-\u036f]/g; function normalize(a) { return a.normalize && (a = a.normalize("NFD").replace(regex_normalize, "")), a; } function replace(a, b) { for (let c = 0, d = b.length; c < d && (a = a.replace(b[c], b[c + 1]), !!a); c += 2) ; return a; } function regex(a) { return new RegExp(a, "g"); } function collapse(a) { let b = "", c = ""; for (let d, e = 0, f = a.length; e < f; e++) (d = a[e]) !== c && (b += c = d); return b; } function filter$1(a, b) { const c = a.length, d = []; for (let e = 0, f = 0; e < c; e++) { const c2 = a[e]; c2 && !b[c2] && (d[f++] = c2); } return d; } const regex_a = regex("[àáâãäå]"), regex_e = regex("[èéêë]"), regex_i = regex("[ìíîï]"), regex_o = regex("[òóôõöő]"), regex_u = regex("[ùúûüű]"), regex_y = regex("[ýŷÿ]"), regex_n = regex("ñ"), regex_c = regex("[çc]"), regex_s = regex("ß"), regex_and = regex(" & "), pairs$1 = [regex_a, "a", regex_e, "e", regex_i, "i", regex_o, "o", regex_u, "u", regex_y, "y", regex_n, "n", regex_c, "k", regex_s, "s", regex_and, " and "]; function encode$2(a) { return a = "" + a, pipeline.call(this, normalize(a).toLowerCase(), !a.normalize && pairs$1, regex_whitespace, false); } const regex_strip = /[^a-z0-9]+/, soundex = { b: "p", v: "f", w: "f", z: "s", x: "s", ß: "s", d: "t", n: "m", c: "k", g: "k", j: "k", q: "k", i: "e", y: "e", u: "o" }; function encode$1(a) { a = encode$2.call(this, a).join(" "); const b = []; if (a) { const c = a.split(regex_strip), d = c.length; for (let e, f = 0, g = 0; f < d; f++) if ((a = c[f]) && (!this.filter || !this.filter[a])) { e = a[0]; let c2 = soundex[e] || e, d2 = c2; for (let b2 = 1; b2 < a.length; b2++) { e = a[b2]; const f2 = soundex[e] || e; f2 && f2 !== d2 && (c2 += f2, d2 = f2); } b[g++] = c2; } } return b; } const charset = { encode, rtl: false, tokenize: "" }; const regex_ae = regex("ae"), regex_oe = regex("oe"), regex_sh = regex("sh"), regex_th = regex("th"), regex_ph = regex("ph"), regex_pf = regex("pf"), pairs = [regex_ae, "a", regex_oe, "o", regex_sh, "s", regex_th, "t", regex_ph, "f", regex_pf, "f", regex("(?![aeo])h(?![aeo])"), "", regex("(?!^[aeo])h(?!^[aeo])"), ""]; function encode(a, b) { return a && (a = encode$1.call(this, a).join(" "), 2 < a.length && (a = replace(a, pairs)), !b && (1 < a.length && (a = collapse(a)), a && (a = a.split(" ")))), a; } const filter = ["a", "about", "above", "after", "again", "against", "all", "also", "am", "an", "and", "any", "are", "aren't", "as", "at", "be", "because", "been", "before", "being", "below", "both", "but", "by", "can", "cannot", "can't", "come", "could", "couldn't", "did", "didn't", "do", "does", "doesn't", "doing", "dont", "down", "during", "each", "even", "few", "first", "for", "from", "further", "get", "go", "had", "hadn't", "has", "hasn't", "have", "haven't", "having", "he", "hed", "her", "here", "here's", "hers", "herself", "hes", "him", "himself", "his", "how", "how's", "i", "id", "if", "ill", "im", "in", "into", "is", "isn't", "it", "it's", "itself", "i've", "just", "know", "let's", "like", "make", "me", "more", "most", "mustn't", "my", "myself", "new", "no", "nor", "not", "now", "of", "off", "on", "once", "only", "or", "other", "ought", "our", "our's", "ourselves", "out", "over", "own", "same", "say", "see", "shan't", "she", "she'd", "shell", "shes", "should", "shouldn't", "so", "some", "such", "than", "that", "that's", "the", "their", "theirs", "them", "themselves", "then", "there", "there's", "these", "they", "they'd", "they'll", "they're", "they've", "this", "those", "through", "time", "to", "too", "until", "up", "us", "very", "want", "was", "wasn't", "way", "we", "wed", "well", "were", "weren't", "we've", "what", "what's", "when", "when's", "where", "where's", "which", "while", "who", "whom", "who's", "why", "why's", "will", "with", "won't", "would", "wouldn't", "you", "you'd", "you'll", "your", "you're", "your's", "yourself", "yourselves", "you've"]; const stemmer = { ational: "ate", iveness: "ive", fulness: "ful", ousness: "ous", ization: "ize", tional: "tion", biliti: "ble", icate: "ic", ative: "", alize: "al", iciti: "ic", entli: "ent", ousli: "ous", alism: "al", ation: "ate", aliti: "al", iviti: "ive", ement: "", enci: "ence", anci: "ance", izer: "ize", alli: "al", ator: "ate", logi: "log", ical: "ic", ance: "", ence: "", ness: "", able: "", ible: "", ment: "", eli: "e", bli: "ble", ful: "", ant: "", ent: "", ism: "", ate: "", iti: "", ous: "", ive: "", ize: "", al: "", ou: "", er: "", ic: "" }; const matcher = {}; const language = { filter, stemmer, matcher }; function useSelection(list) { const selectedIndex = ref(0); watch(list, () => { selectedIndex.value = 0; }); function selectNext() { selectedIndex.value++; if (selectedIndex.value > list.value.length - 1) { selectedIndex.value = 0; } } function selectPrevious() { selectedIndex.value--; if (selectedIndex.value < 0) { selectedIndex.value = list.value.length - 1; } } return { selectedIndex: computed(() => selectedIndex.value), selectNext, selectPrevious }; } const _sfc_main$4 = /* @__PURE__ */ defineComponent({ __name: "BaseListItem", props: { isActive: { type: Boolean } }, emits: ["navigate"], setup(__props, { emit: __emit }) { const emit = __emit; function handleNavigate() { emit("navigate"); } return (_ctx, _cache) => { return openBlock(), createElementBlock("a", { class: normalizeClass(["istoire-base-list-ite htw-flex htw-items-center htw-gap-2 htw-text-gray-900 dark:htw-text-gray-100", [ _ctx.$attrs.class, _ctx.isActive ? "active htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black" : "hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900" ]]), onClick: _cache[0] || (_cache[0] = ($event) => handleNavigate()), onKeyup: [ _cache[1] || (_cache[1] = withKeys(($event) => handleNavigate(), ["enter"])), _cache[2] || (_cache[2] = withKeys(($event) => handleNavigate(), ["space"])) ] }, [ renderSlot(_ctx.$slots, "default") ], 34); }; } }); const _hoisted_1$3 = ["src", "alt"]; const _sfc_main$3 = /* @__PURE__ */ defineComponent({ __name: "BaseIcon", props: { icon: {} }, setup(__props) { const props = __props; const isUrl = computed(() => props.icon.startsWith("http") || props.icon.startsWith("data:image") || props.icon.startsWith(".") || props.icon.startsWith("/")); return (_ctx, _cache) => { return isUrl.value ? (openBlock(), createElementBlock("img", { key: 0, src: _ctx.icon, alt: _ctx.icon, class: "histoire-base-icon" }, null, 8, _hoisted_1$3)) : (openBlock(), createBlock(unref(Icon), { key: 1, icon: _ctx.icon, class: "histoire-base-icon" }, null, 8, ["icon"])); }; } }); const BaseIcon = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-2114f510"]]); const _hoisted_1$2 = { class: "htw-flex-1" }; const _hoisted_2 = { class: "htw-flex" }; const _hoisted_3 = { class: "htw-ml-auto htw-opacity-40" }; const _hoisted_4 = { key: 0, class: "htw-flex htw-items-center htw-gap-0.5 htw-opacity-60" }; const _sfc_main$2 = /* @__PURE__ */ defineComponent({ __name: "SearchItemContent", props: { result: {}, selected: { type: Boolean } }, setup(__props) { const defaultIcons = { story: "carbon:cube", variant: "carbon:cube" }; const kindLabels = { story: "Story", variant: "Variant", command: "Command" }; return (_ctx, _cache) => { var _a; return openBlock(), createElementBlock(Fragment, null, [ createVNode(BaseIcon, { icon: _ctx.result.icon ?? defaultIcons[_ctx.result.kind], class: normalizeClass(["htw-w-4 htw-h-4", [ !_ctx.selected ? [ _ctx.result.iconColor ? "bind-icon-color" : { "htw-text-primary-500": _ctx.result.kind === "story", "htw-text-gray-500": _ctx.result.kind === "variant" } ] : [], { "colorize-black": _ctx.selected } ]]) }, null, 8, ["icon", "class"]), createBaseVNode("div", _hoisted_1$2, [ createBaseVNode("div", _hoisted_2, [ createTextVNode(toDisplayString(_ctx.result.title) + " ", 1), createBaseVNode("span", _hoisted_3, toDisplayString(kindLabels[_ctx.result.kind]), 1) ]), ((_a = _ctx.result.path) == null ? void 0 : _a.length) ? (openBlock(), createElementBlock("div", _hoisted_4, [ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.result.path, (p, index) => { return openBlock(), createElementBlock("div", { key: index, class: "htw-flex htw-items-center htw-gap-0.5" }, [ index > 0 ? (openBlock(), createBlock(unref(Icon), { key: 0, icon: "carbon:chevron-right", class: "htw-w-4 htw-h-4 htw-mt-0.5 htw-opacity-50" })) : createCommentVNode("", true), createBaseVNode("span", null, toDisplayString(p), 1) ]); }), 128)) ])) : createCommentVNode("", true) ]) ], 64); }; } }); const _hoisted_1$1 = ["data-selected"]; const _sfc_main$1 = /* @__PURE__ */ defineComponent({ __name: "SearchItem", props: { result: { type: Object, required: true }, selected: { type: Boolean, default: false } }, emits: { close: () => true }, setup(__props, { emit: __emit }) { useCssVars((_ctx) => ({ "ddaae392": __props.result.iconColor })); const props = __props; const emit = __emit; const el = ref(); const { selected } = toRefs(props); useScrollOnActive(selected, el); const router = useRouter(); onKeyboardShortcut(["enter"], () => { if (!props.selected) return; action(); }); function action(fromClick = false) { if ("route" in props.result && !fromClick) { router.push(props.result.route); } if ("onActivate" in props.result) { props.result.onActivate(); } emit("close"); } return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { ref_key: "el", ref: el, class: "histoire-search-item", "data-test-id": "search-item", "data-selected": unref(selected) ? "" : void 0 }, [ "route" in __props.result ? (openBlock(), createBlock(BaseListItemLink, { key: 0, to: __props.result.route, "is-active": unref(selected), class: "htw-px-6 htw-py-4 htw-gap-4", onNavigate: _cache[0] || (_cache[0] = ($event) => action(true)) }, { default: withCtx(() => [ createVNode(_sfc_main$2, { result: __props.result, selected: unref(selected) }, null, 8, ["result", "selected"]) ]), _: 1 }, 8, ["to", "is-active"])) : createCommentVNode("", true), "onActivate" in __props.result ? (openBlock(), createBlock(_sfc_main$4, { key: 1, "is-active": unref(selected), class: "htw-px-6 htw-py-4 htw-gap-4", onNavigate: _cache[1] || (_cache[1] = ($event) => action(true)) }, { default: withCtx(() => [ createVNode(_sfc_main$2, { result: __props.result, selected: unref(selected) }, null, 8, ["result", "selected"]) ]), _: 1 }, 8, ["is-active"])) : createCommentVNode("", true) ], 8, _hoisted_1$1); }; } }); const SearchItem = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-d75a2748"]]); let searchData$1 = { "index": { "reg": '{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1}', "text.cfg": '{"doc":0,"opt":1}', "text.map": '[{"k":[0,1],"ke":[0,1],"kek":[0,1],"kekp":[0,1],"kekpo":[0,1],"kekpos":[0,1],"f":[2,3],"fl":[2,3],"flo":[2,3],"floa":[2,3],"float":[2,3],"e":[4,5],"em":[4,5],"emt":[4,5],"emte":[4,5],"emtek":[4,5],"emteke":[4,5],"emteker":[4,5],"s":[6,7],"se":[6,7],"sel":[6,7],"sele":[6,7],"selek":[6,7],"selekt":[6,7]},{"t":[1,3,5,7],"te":[1,3,5,7],"tef":[1,3,5,7],"tefa":[1,3,5,7],"tefao":[1,3,5,7],"tefaol":[1,3,5,7],"tefaolt":[1,3,5,7]},{},{},{},{},{},{},{}]', "text.ctx": "[{}]" }, "idMap": { "0": { "id": "src-lib-elements-checkbox-story-svelte", "kind": "story" }, "1": { "id": "src-lib-elements-checkbox-story-svelte:_default", "kind": "variant" }, "2": { "id": "src-lib-elements-float-story-svelte", "kind": "story" }, "3": { "id": "src-lib-elements-float-story-svelte:_default", "kind": "variant" }, "4": { "id": "src-lib-elements-integer-story-svelte", "kind": "story" }, "5": { "id": "src-lib-elements-integer-story-svelte:_default", "kind": "variant" }, "6": { "id": "src-lib-elements-select-story-svelte", "kind": "story" }, "7": { "id": "src-lib-elements-select-story-svelte:_default", "kind": "variant" } } }; const searchData = markRaw(searchData$1); const _hoisted_1 = { key: 1, class: "htw-max-h-[400px] htw-overflow-y-auto htw-rounded-b-lg" }; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "SearchPane", props: { shown: { type: Boolean, default: false } }, emits: { close: () => true }, setup(__props, { emit: __emit }) { const DocSearchData = () => __vitePreload(() => import("./search-docs-data-JLe790su.js"), true ? __vite__mapDeps([0,1]) : void 0); const props = __props; const emit = __emit; function close() { emit("close"); } const input = ref(); const { focused } = useFocus(input, { initialValue: true }); watch(() => props.shown, (value) => { if (value) { requestAnimationFrame(() => { focused.value = true; input.value.select(); }); } }); const searchInputText = ref(""); const rateLimitedSearch = refDebounced(searchInputText, 50); const storyStore = useStoryStore(); let titleSearchIndex; let titleIdMap; function createIndex() { return new flexsearch_bundleExports.Document({ preset: "match", document: { id: "id", index: [ "text" ] }, worker: true, charset, language, tokenize: "forward" }); } async function loadSearchIndex(data) { titleSearchIndex = createIndex(); for (const key of Object.keys(data.index)) { await titleSearchIndex.import(key, data.index[key]); } titleIdMap = data.idMap; } loadSearchIndex(searchData); let docSearchIndex; let docIdMap; async function loadDocSearchIndex() { async function load(data) { docSearchIndex = createIndex(); for (const key of Object.keys(data.index)) { await docSearchIndex.import(key, data.index[key]); } docIdMap = data.idMap; if (rateLimitedSearch.value) { searchOnDocField(rateLimitedSearch.value); } } const searchDataModule = await DocSearchData(); load(searchDataModule.searchData); searchDataModule.onUpdate((searchData2) => { load(searchData2); }); } loadDocSearchIndex(); const titleResults = ref([]); watch(rateLimitedSearch, async (value) => { const list = []; const raw = await titleSearchIndex.search(value); let rank = 0; for (const field of raw) { for (const id of field.result) { const idMapData = titleIdMap[id]; if (!idMapData) continue; switch (idMapData.kind) { case "story": { list.push(storyResultFactory(storyStore.getStoryById(idMapData.id), rank)); rank++; break; } case "variant": { const [storyId] = idMapData.id.split(":"); const story = storyStore.getStoryById(storyId); const variant = storyStore.getVariantById(idMapData.id); list.push(variantResultFactory(story, variant, rank)); rank++; break; } } } } titleResults.value = list; }); const docsResults = ref([]); async function searchOnDocField(query) { if (docSearchIndex) { const list = []; const raw = await docSearchIndex.search(query); let rank = 0; for (const field of raw) { for (const id of field.result) { const idMapData = docIdMap[id]; if (!idMapData) continue; switch (idMapData.kind) { case "story": { list.push(storyResultFactory(storyStore.getStoryById(idMapData.id), rank, "docs")); rank++; break; } } } } docsResults.value = list; } } watch(rateLimitedSearch, searchOnDocField); function storyResultFactory(story, rank, type = "title") { return { kind: "story", rank, id: `story:${story.id}`, title: story.title, route: { name: "story", params: { storyId: story.id }, query: { ...type === "docs" ? { tab: "docs" } : {} } }, path: story.file.path.slice(0, -1), icon: story.icon, iconColor: story.iconColor }; } function variantResultFactory(story, variant, rank, type = "title") { return { kind: "variant", rank, id: `variant:${story.id}:${variant.id}`, title: variant.title, route: { name: "story", params: { storyId: story.id }, query: { variantId: variant.id, ...type === "docs" ? { tab: "docs" } : {} } }, path: [...story.file.path ?? [], story.title], icon: variant.icon, iconColor: variant.iconColor }; } const commandResults = computed(() => { return []; }); useCommandStore(); const results = computed(() => { const list = [ ...commandResults.value, ...titleResults.value ]; const seen = {}; for (const r of titleResults.value) { seen[r.id] = true; } for (const r of docsResults.value) { if (!seen[r.id]) { list.push(r); } } return list; }); const { selectedIndex, selectNext, selectPrevious } = useSelection(results); return (_ctx, _cache) => { return openBlock(), createElementBlock(Fragment, null, [ createBaseVNode("div", { class: "histoire-search-pane htw-flex htw-items-center htw-gap-4 htw-pl-6 htw-border htw-border-transparent focus-visible:htw-border-primary-500", onClick: _cache[4] || (_cache[4] = ($event) => focused.value = true) }, [ createVNode(unref(Icon), { icon: "carbon:search", class: "flex-none htw-w-4 htw-h-4" }), withDirectives(createBaseVNode("input", { ref_key: "input", ref: input, "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchInputText.value = $event), placeholder: "Search for stories, variants...", class: "htw-bg-transparent htw-w-full htw-flex-1 htw-pl-0 htw-pr-6 htw-py-4 htw-outline-none", onKeydown: [ _cache[1] || (_cache[1] = withKeys(withModifiers(($event) => unref(selectNext)(), ["prevent"]), ["down"])), _cache[2] || (_cache[2] = withKeys(withModifiers(($event) => unref(selectPrevious)(), ["prevent"]), ["up"])), _cache[3] || (_cache[3] = withKeys(($event) => close(), ["escape"])) ] }, null, 544), [ [vModelText, searchInputText.value] ]) ]), unref(rateLimitedSearch) && !results.value.length ? (openBlock(), createBlock(BaseEmpty, { key: 0, class: "no-animation" }, { default: withCtx(() => [ createTextVNode(" No results ") ]), _: 1 })) : results.value.length ? (openBlock(), createElementBlock("div", _hoisted_1, [ (openBlock(true), createElementBlock(Fragment, null, renderList(results.value, (result, index) => { return openBlock(), createBlock(SearchItem, { key: result.id, result, selected: index === unref(selectedIndex), onClose: _cache[5] || (_cache[5] = ($event) => close()) }, null, 8, ["result", "selected"]); }), 128)) ])) : createCommentVNode("", true) ], 64); }; } }); export { _sfc_main as default };