// @bun
var{defineProperty:Z,getOwnPropertyNames:M,getOwnPropertyDescriptor:R}=Object,_=Object.prototype.hasOwnProperty;function k(j){return this[j]}var m=(j)=>{var q=(W??=new WeakMap).get(j),B;if(q)return q;if(q=Z({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var H of M(j))if(!_.call(q,H))Z(q,H,{get:k.bind(j,H),enumerable:!(B=R(j,H))||B.enumerable})}return W.set(j,q),q},W;var G=(j)=>j;function O(j,q){this[j]=G.bind(null,q)}var T=(j,q)=>{for(var B in q)Z(j,B,{get:q[B],enumerable:!0,configurable:!0,set:O.bind(q,B)})};var C=(j,q)=>()=>(j&&(q=j(j=0)),q);var u=import.meta.require;var F={};T(F,{watchStoryFiles:()=>S,scanStoryFiles:()=>w,isNonComponentFile:()=>x});import $ from"fs";import Y from"path";async function w(j){let{root:q,config:B}=j,H=[],J=await D(q,B.storyMatch,B.storyIgnored);for(let Q of J){let L=Y.resolve(q,Q),V=z(Q,L);H.push(V)}return H}async function D(j,q,B){let H=[];async function J(Q,L){let V=await $.promises.readdir(Q,{withFileTypes:!0});for(let K of V){let X=Y.join(Q,K.name),U=Y.relative(L,X);if(E(U,B))continue;if(K.isDirectory())await J(X,L);else if(K.isFile()){if(I(U,q))H.push(U)}}}return await J(j,j),H}function E(j,q){for(let B of q)if(A(j,B))return!0;return!1}function x(j){for(let q of N)if(A(j,q))return!0;return!1}function I(j,q){for(let B of q)if(A(j,B))return!0;return!1}function A(j,q){let B=j.replace(/\\/g,"/"),J=q.replace(/\\/g,"/").replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"{{GLOBSTAR}}").replace(/\*/g,"[^/]*").replace(/\?/g,".").replace(/\{\{GLOBSTAR\}\}/g,".*");return J=`^${J}$`,new RegExp(J).test(B)}function z(j,q){let B=Y.basename(j,".story.stx");return{id:j.toLowerCase().replace(/\.story\.stx$/,"").replace(/[/\\]/g,"-").replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,""),path:q,relativePath:j,fileName:B,treeFile:{title:B,path:j}}}function S(j,q){let{root:B,config:H}=j,J=[],Q=$.watch(B,{recursive:!0},async(L,V)=>{if(!V)return;let K=V.replace(/\\/g,"/");if(!I(K,H.storyMatch))return;if(E(K,H.storyIgnored))return;let X=Y.resolve(B,K);try{await $.promises.access(X);let U=z(K,X);q(L==="rename"?"add":"change",U)}catch{let U=z(K,X);q("unlink",U)}});return J.push(Q),()=>{for(let L of J)L.close()}}var N;var b=C(()=>{N=["**/layouts/**","**/pages/**","**/partials/**","**/_*.stx","**/layout.stx","**/page.stx","**/error.stx","**/loading.stx"]});b();export{S as watchStoryFiles,w as scanStoryFiles,x as isNonComponentFile};
