import { d as defineComponent, o as openBlock, e as createElementBlock, aY as renderSlot, n as normalizeClass, m as withKeys, c as computed, a as unref, q as createBlock, I as Icon, f as createVNode, g as createBaseVNode, D as createTextVNode, t as toDisplayString, F as Fragment, p as renderList, h as createCommentVNode, u as useCssVars, r as ref, aS as toRefs, aU as useRouter, w as withCtx, aO as markRaw, k as watch, bi as useFocus, bj as refDebounced, B as withDirectives, aZ as vModelText, aX as withModifiers, _ as __vitePreload, bk as flexsearch_bundleExports } from "./vendor-3ab3e533.js"; import { u as useStoryStore } from "./story-804dabc9.js"; import { B as BaseEmpty } from "./BaseEmpty.vue-045cbb89.js"; import { o as onKeyboardShortcut, u as useCommandStore } from "./bundle-main-f9305308.js"; import { _ as _export_sfc, u as useScrollOnActive, B as BaseListItemLink } from "./MobileOverlay.vue2-a3503848.js"; import "./GenericMountStory.vue2-2bb5633d.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 }; const _sfc_main$4 = /* @__PURE__ */ defineComponent({ __name: "BaseListItem", props: { isActive: { type: Boolean } }, emits: ["navigate"], setup(__props, { 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, __props.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: null }, 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 unref(isUrl) ? (openBlock(), createElementBlock("img", { key: 0, src: __props.icon, alt: __props.icon, class: "histoire-base-icon" }, null, 8, _hoisted_1$3)) : (openBlock(), createBlock(unref(Icon), { key: 1, icon: __props.icon, class: "histoire-base-icon" }, null, 8, ["icon"])); }; } }); const BaseIcon = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-74182813"]]); 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: null, 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: __props.result.icon ?? defaultIcons[__props.result.kind], class: normalizeClass(["htw-w-4 htw-h-4", [ !__props.selected ? [ __props.result.iconColor ? "bind-icon-color" : { "htw-text-primary-500": __props.result.kind === "story", "htw-text-gray-500": __props.result.kind === "variant" } ] : [], { "colorize-black": __props.selected } ]]) }, null, 8, ["icon", "class"]), createBaseVNode("div", _hoisted_1$2, [ createBaseVNode("div", _hoisted_2, [ createTextVNode(toDisplayString(__props.result.title) + " ", 1), createBaseVNode("span", _hoisted_3, toDisplayString(kindLabels[__props.result.kind]), 1) ]), ((_a = __props.result.path) == null ? void 0 : _a.length) ? (openBlock(), createElementBlock("div", _hoisted_4, [ (openBlock(true), createElementBlock(Fragment, null, renderList(__props.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 }) { const props = __props; useCssVars((_ctx) => ({ "a8c1277e": __props.result.iconColor })); 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-6c8e9661"]]); let searchData$1 = { "index": { "reg": '{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1}', "text.cfg": '{"doc":0,"opt":1}', "text.map": '[{"s":[0,1],"se":[0,1],"sep":[0,1],"k":[2,3],"ko":[2,3],"kos":[2,3],"kost":[2,3],"p":[4,5],"pr":[4,5],"pro":[4,5],"prop":[4,5],"propo":[4,5],"propol":[4,5],"propols":[4,5],"propolse":[4,5],"propolseo":[4,5],"propolseom":[4,5],"e":[6,7],"em":[6,7],"emk":[6,7],"emke":[6,7],"emkem":[6,7],"emkeme":[6,7],"f":[8,9],"ft":[8,9],"ftl":[8,9]},{"e":[0,1],"et":[0,1],"ete":[0,1],"etem":[0,1],"m":[2,3],"ma":[2,3],"mas":[2,3],"t":[5,7,9],"te":[5,7,9],"tef":[5,7,9],"tefa":[5,7,9],"tefao":[5,7,9],"tefaol":[5,7,9],"tefaolt":[5,7,9]},{"t":[1,3],"te":[1,3],"tef":[1,3],"tefa":[1,3],"tefao":[1,3],"tefaol":[1,3],"tefaolt":[1,3]},{},{},{},{},{},{}]', "text.ctx": "[{}]" }, "idMap": { "0": { "id": "src-lib-components-shipitem-story-svelte", "kind": "story" }, "1": { "id": "src-lib-components-shipitem-story-svelte:_default", "kind": "variant" }, "2": { "id": "src-lib-components-costmass-index-story-svelte", "kind": "story" }, "3": { "id": "src-lib-components-costmass-index-story-svelte:_default", "kind": "variant" }, "4": { "id": "src-lib-components-shipedit-propulsion-story-svelte", "kind": "story" }, "5": { "id": "src-lib-components-shipedit-propulsion-story-svelte:_default", "kind": "variant" }, "6": { "id": "src-lib-components-shipedit-propulsion-engine-story-svelte", "kind": "story" }, "7": { "id": "src-lib-components-shipedit-propulsion-engine-story-svelte:_default", "kind": "variant" }, "8": { "id": "src-lib-components-shipedit-propulsion-ftl-story-svelte", "kind": "story" }, "9": { "id": "src-lib-components-shipedit-propulsion-ftl-story-svelte:_default", "kind": "variant" } } }; const searchData = markRaw(searchData$1); 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 _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 }) { const props = __props; const DocSearchData = () => __vitePreload(() => import("./search-docs-data-9f078283.js"), true ? ["assets/search-docs-data-9f078283.js","assets/vendor-3ab3e533.js"] : void 0); 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) && !unref(results).length ? (openBlock(), createBlock(BaseEmpty, { key: 0, class: "no-animation" }, { default: withCtx(() => [ createTextVNode(" No results ") ]), _: 1 })) : unref(results).length ? (openBlock(), createElementBlock("div", _hoisted_1, [ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(results), (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 };