// @bun
var{defineProperty:Q,getOwnPropertyNames:Z,getOwnPropertyDescriptor:$}=Object,w=Object.prototype.hasOwnProperty;function L(j){return this[j]}var D=(j)=>{var z=(U??=new WeakMap).get(j),C;if(z)return z;if(z=Q({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var A of Z(j))if(!w.call(z,A))Q(z,A,{get:L.bind(j,A),enumerable:!(C=$(j,A))||C.enumerable})}return U.set(j,z),z},U;var k=(j)=>j;function q(j,z){this[j]=k.bind(null,z)}var R=(j,z)=>{for(var C in z)Q(j,C,{get:z[C],enumerable:!0,configurable:!0,set:q.bind(z,C)})};var F=(j,z)=>()=>(j&&(z=j(j=0)),z);var N=import.meta.require;import M from"fs";import T from"path";var W=1,O=".stx/story/search-index.json";function Y(j){return T.join(j,O)}async function V(j){let z=Y(j.root);try{let C=await M.promises.readFile(z,"utf-8"),A=JSON.parse(C);if(A.version!==W)return null;return A}catch{return null}}async function X(j,z){let C=Y(j.root),A=T.dirname(C);await M.promises.mkdir(A,{recursive:!0});let G={version:W,created:Date.now(),updated:Date.now(),entries:z};await M.promises.writeFile(C,JSON.stringify(G,null,2))}function _(j,z){let C=[];for(let A of j){let G=z.get(A.fileName),B=[A.fileName.toLowerCase(),A.relativePath.toLowerCase()],J=[],K=[];if(G){if(G.description)B.push(G.description.toLowerCase());for(let H of G.props)if(J.push(H.name),B.push(H.name.toLowerCase()),H.description)B.push(H.description.toLowerCase());for(let H of G.slots)K.push(`slot:${H.name}`);for(let H of G.directives||[])K.push(`directive:${H.name}`);for(let H of G.dependencies)K.push(`uses:${H}`)}C.push({id:A.id,name:A.fileName,path:A.relativePath,searchText:B.join(" "),props:J,tags:K,mtime:Date.now()})}return C}async function v(j,z){for(let C of z.entries)try{let A=T.join(j.root,C.path);if((await M.promises.stat(A)).mtimeMs>C.mtime)return!0}catch{return!0}return!1}function S(j,z){let A=z.toLowerCase().split(/\s+/).filter(Boolean);if(A.length===0)return j.entries;return j.entries.map((B)=>{let J=0;for(let K of A)if(B.name.toLowerCase()===K)J+=100;else if(B.name.toLowerCase().startsWith(K))J+=50;else if(B.name.toLowerCase().includes(K))J+=25;else if(B.props.some((H)=>H.toLowerCase().includes(K)))J+=15;else if(B.tags.some((H)=>H.toLowerCase().includes(K)))J+=10;else if(B.searchText.includes(K))J+=5;return{entry:B,score:J}}).filter((B)=>B.score>0).sort((B,J)=>J.score-B.score).map((B)=>B.entry)}async function g(j,z,C,A=!1){if(!A){let B=await V(j);if(B&&!await v(j,B))return B.entries}let G=_(z,C);return X(j,G).catch(()=>{}),G}export{S as searchIndex,X as saveSearchIndex,V as loadSearchIndex,v as isIndexStale,g as getOrBuildSearchIndex,_ as buildPersistedSearchIndex};
