// @bun
var{defineProperty:E,getOwnPropertyNames:N,getOwnPropertyDescriptor:P}=Object,Q=Object.prototype.hasOwnProperty;function R(b){return this[b]}var S=(b)=>{var h=(L??=new WeakMap).get(b),j;if(h)return h;if(h=E({},"__esModule",{value:!0}),b&&typeof b==="object"||typeof b==="function"){for(var z of N(b))if(!Q.call(h,z))E(h,z,{get:R.bind(b,z),enumerable:!(j=P(b,z))||j.enumerable})}return L.set(b,h),h},L;var V=(b)=>b;function W(b,h){this[b]=V.bind(null,h)}var X=(b,h)=>{for(var j in h)E(b,j,{get:h[j],enumerable:!0,configurable:!0,set:W.bind(h,j)})};var Y=(b,h)=>()=>(b&&(h=b(b=0)),h);var T={};X(T,{groupByToArray:()=>Z,groupByMultiple:()=>_,groupBy:()=>D,getUniqueTags:()=>J,getUniqueOwners:()=>$,getUniqueDomains:()=>O,filterBy:()=>I,GroupingStrategies:()=>H});function I(b,h){return b.filter((j)=>{if(h.tags?.length){if(!h.tags.some((A)=>j.meta.tags?.includes(A)))return!1}if(h.owners?.length){if(!h.owners.some((A)=>j.meta.owners?.includes(A)))return!1}if(h.stability?.length){if(!h.stability.includes(j.meta.stability??"stable"))return!1}if(h.domain){if(H.byDomain(j)!==h.domain)return!1}if(h.keyPattern){let z=j.meta.key??j.meta.key??"",A=h.keyPattern.replace(/\*/g,".*").replace(/\?/g,".");if(!new RegExp(`^${A}$`,"i").test(z))return!1}return!0})}function D(b,h){let j=new Map;for(let z of b){let A=h(z),C=j.get(A);if(C)C.push(z);else j.set(A,[z])}return j}function Z(b,h){let j=D(b,h);return Array.from(j.entries()).map(([z,A])=>({key:z,items:A}))}function _(b,h){let j=new Map;for(let z of b){let A=h(z);for(let C of A){let K=j.get(C);if(K)K.push(z);else j.set(C,[z])}}return j}function J(b){let h=new Set;for(let j of b)for(let z of j.meta.tags??[])h.add(z);return Array.from(h).sort()}function $(b){let h=new Set;for(let j of b)for(let z of j.meta.owners??[])h.add(z);return Array.from(h).sort()}function O(b){let h=new Set;for(let j of b)h.add(H.byDomain(j));return Array.from(h).sort()}var H;var M=Y(()=>{H={byTag:(b)=>b.meta.tags?.[0]??"untagged",byAllTags:(b)=>b.meta.tags?.length?b.meta.tags:["untagged"],byOwner:(b)=>b.meta.owners?.[0]??"unowned",byDomain:(b)=>{return(b.meta.key??b.meta.key??"").split(".")[0]??"default"},byStability:(b)=>b.meta.stability??"stable",byUrlPath:(b)=>(h)=>{if(!h.path)return"root";return h.path.split("/").filter(Boolean).slice(0,b).join("/")||"root"}}});M();function U(b){return b.meta.key}class v{items=new Map;register(b){let h=U(b);if(this.items.has(h))throw Error(`Duplicate feature ${h}`);return this.items.set(h,b),this}list(){return[...this.items.values()]}get(b){return this.items.get(b)}filter(b){return I(this.list(),b)}listByTag(b){return this.list().filter((h)=>h.meta.tags?.includes(b))}listByOwner(b){return this.list().filter((h)=>h.meta.owners?.includes(b))}groupBy(b){return D(this.list(),b)}getUniqueTags(){return J(this.list())}}export{v as FeatureRegistry};
