// @bun
var{defineProperty:I,getOwnPropertyNames:M,getOwnPropertyDescriptor:Q}=Object,R=Object.prototype.hasOwnProperty;function S(q){return this[q]}var _=(q)=>{var z=(K??=new WeakMap).get(q),B;if(z)return z;if(z=I({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var A of M(q))if(!R.call(z,A))I(z,A,{get:S.bind(q,A),enumerable:!(B=Q(q,A))||B.enumerable})}return K.set(q,z),z},K;var U=(q)=>q;function W(q,z){this[q]=U.bind(null,z)}var $=(q,z)=>{for(var B in z)I(q,B,{get:z[B],enumerable:!0,configurable:!0,set:W.bind(z,B)})};var V=(q,z)=>()=>(q&&(z=q(q=0)),z);var N=import.meta.require;function X(q,z){let B=z.treeFile||{title:z.fileName,path:z.relativePath};if(q.tree.file==="title")return B.title.split("/");if(q.tree.file==="path")return[...z.relativePath.split("/").slice(0,-1),B.title];if(typeof q.tree.file==="function")return q.tree.file(B);return[B.title]}function w(q,z){for(let C of z)C.treePath=X(q,C);let B=(q.tree.groups||[]).map((C)=>({groupConfig:{id:C.id||C.title,title:C.title,include:C.include},treeObject:{}})),A={treeObject:{}};B.push(A);for(let C=0;C<z.length;C++){let H=z[C],L=Y(H,B,A);Z(H.treePath,C,L.treeObject)}let D=q.tree.order==="asc"?(C,H)=>C.localeCompare(H):q.tree.order,E=[];for(let C of B)if(C===A)E.push(...J(C.treeObject,D));else if(C.groupConfig&&Object.keys(C.treeObject).length>0)E.push({group:!0,id:C.groupConfig.id,title:C.groupConfig.title,children:J(C.treeObject,D)});return E}function Y(q,z,B){let A=q.treeFile||{title:q.fileName,path:q.relativePath};for(let D of z)if(D.groupConfig?.include&&D.groupConfig.include(A))return D;return B}function Z(q,z,B){let A=B;for(let D=0;D<q.length;D++){let E=q[D];if(D===q.length-1)if(A[E]!==void 0){let H=1;while(A[`${E}-${H}`]!==void 0)H++;A[`${E}-${H}`]=z}else A[E]=z;else{if(A[E]===void 0)A[E]={};else if(typeof A[E]==="number"){let H=A[E];A[E]={"":H}}A=A[E]}}}function J(q,z){let B=[];for(let[A,D]of Object.entries(q))if(typeof D==="number")B.push({title:A,index:D});else B.push({title:A,children:J(D,z)});return B.sort((A,D)=>z(A.title,D.title)),B}function T(q){let z=[];function B(A){for(let D of A)if("index"in D)z.push(D.index);else if("children"in D)B(D.children)}return B(q),z}function j(q,z){function B(A,D){for(let E of A)if("index"in E&&E.index===z)return{path:[...D,E.title],node:E};else if("children"in E){let C=B(E.children,[...D,E.title]);if(C)return C}return null}return B(q,[])}export{T as flattenTree,j as findStoryInTree,X as createTreePath,w as buildTree};
