// @bun
var P=Object.defineProperty;var R=(j)=>j;function S(j,w){this[j]=R.bind(null,w)}var z=(j,w)=>{for(var C in w)P(j,C,{get:w[C],enumerable:!0,configurable:!0,set:S.bind(w,C)})};var h=(j,w)=>()=>(j&&(w=j(j=0)),w);import{defaultDocRegistry as E}from"@contractspec/lib.contracts-spec/docs";var L=20,I=100;function N(j){return j?.trim().toLowerCase()??""}function U(j){let w=decodeURIComponent(j).trim();if(!w)return"/";return w.startsWith("/")?w:`/${w}`}function p(j){return(Array.isArray(j)?j:j?[j]:[]).map((C)=>N(C)).filter(Boolean)}function q(j){if(!j||Number.isNaN(j))return L;return Math.min(Math.max(j,1),I)}function D(j){if(!j||Number.isNaN(j))return 0;return Math.max(j,0)}function Q({block:j,route:w}){return{id:j.id,title:j.title,summary:j.summary??"",route:w,visibility:j.visibility??"public",kind:j.kind??"reference",version:j.version??"1.0.0",tags:j.tags??[]}}function x(j,w){if(!w)return 1;let C=w.split(/\s+/).filter(Boolean),J=N(j.block.title),W=N(j.block.id),Y=N(j.block.summary),$=N(j.block.body),G=N(j.route),H=(j.block.tags??[]).map((B)=>N(B)),K=[J,W,Y,$,G,...H].join(" ");if(C.some((B)=>!K.includes(B)))return 0;let Z=0;for(let B of C){if(W.includes(B))Z+=8;if(J.includes(B))Z+=7;if(H.some((F)=>F.includes(B)))Z+=5;if(Y.includes(B))Z+=4;if(G.includes(B))Z+=3;if($.includes(B))Z+=2}return Z}function y(j,w){let C=N(typeof w.query==="string"?w.query:void 0),J=p(w.tag),W=N(typeof w.visibility==="string"?w.visibility:void 0),Y=N(typeof w.kind==="string"?w.kind:void 0),$=q(typeof w.limit==="number"?w.limit:void 0),G=D(typeof w.offset==="number"?w.offset:void 0),H=j.map((B)=>({doc:Q(B),score:x(B,C)})).filter(({doc:B,score:F})=>{let V=C?F>0:!0,X=J.length?J.every((M)=>B.tags.some((O)=>N(O).includes(M))):!0,A=W?N(B.visibility)===W:!0,_=Y?N(B.kind)===Y:!0;return V&&X&&A&&_}).sort((B,F)=>{if(F.score!==B.score)return F.score-B.score;return B.doc.title.localeCompare(F.doc.title)}),K=H.slice(G,G+$).map(({doc:B})=>B),Z=G+K.length<H.length?G+K.length:void 0;return{docs:K,items:K,total:H.length,...Z!=null?{nextOffset:Z}:{}}}function b(j){let w=decodeURIComponent(j),C=E.get(w);if(!C)return;return{doc:Q(C),content:String(C.block.body??"")}}function k(j,w){let C=U(w),J=j.find((W)=>U(W.route)===C);if(!J)return;return{doc:Q(J),content:String(J.block.body??"")}}function m(j){let w=new Map,C=new Map,J=new Map;for(let Y of j){let $=Y.block.kind??"reference",G=Y.block.visibility??"public";C.set($,(C.get($)??0)+1),J.set(G,(J.get(G)??0)+1);for(let H of Y.block.tags??[])w.set(H,(w.get(H)??0)+1)}let W=(Y,$)=>[...Y.entries()].sort((G,H)=>H[1]-G[1]||G[0].localeCompare(H[0])).map(([G,H])=>({[$]:G,count:H}));return{totalDocs:j.length,tags:W(w,"tag"),kinds:W(C,"kind"),visibilities:W(J,"visibility")}}export{Q as toDocSummary,y as searchDocs,m as listDocFacets,k as getDocByRoute,b as getDocById};
