@uibot/registry 0.2.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  // @bun
2
- import{lstatSync as cr,mkdirSync as Le,readFileSync as lr,realpathSync as dr,writeFileSync as Ne}from"fs";import{basename as ur,dirname as ue,isAbsolute as pr,resolve as E,sep as _e}from"path";function ze(e){let t=e.lockfilePath??"uibot.artifacts.lock.json",r=e.manifest.items??[],n=new Map;for(let i of r)n.set(i.name,i);if(e.lockfile===null)return{ok:!1,lockfilePath:t,registryName:e.manifest.name,lockCount:0,manifestCount:r.length,drifts:[{name:"*",kind:"missing-in-lock",detail:"lockfile missing or unreadable"}]};let o=[],a=new Set;for(let i of e.lockfile.artifacts??[]){a.add(i.name);let l=n.get(i.name);if(!l){o.push({name:i.name,kind:"missing-in-manifest",lockVersion:i.version,detail:`locked ${i.name}@${i.version} not present in registry manifest`});continue}let c=He(l);if(c&&c!==i.version)o.push({name:i.name,kind:"version-mismatch",lockVersion:i.version,manifestVersion:c,detail:`${i.name}: lock ${i.version} \u2260 registry ${c}`})}return{ok:o.length===0,lockfilePath:t,registryName:e.manifest.name,lockCount:(e.lockfile.artifacts??[]).length,manifestCount:r.length,drifts:o}}function He(e){return e.artifact?.version??e.version}function We(){return{version:1,artifacts:[]}}function Ke(e){return{version:1,artifacts:e}}import{readFileSync as Ye,realpathSync as ge}from"fs";import{resolve as B,relative as Ge,dirname as Je,extname as Qe,sep as Z}from"path";function Ze(e){if(e.endsWith(".css"))return"style";if(e.endsWith(".tsx")||e.endsWith(".jsx"))return"component";if(/(^|\/)use-[^/]+\.ts$/.test(e))return"hook";return"lib"}function Xe(e){let t=e.readFile??((c)=>Ye(c,"utf8")),r=new Map,n=(c,d=B(e.sourceDir))=>{let p=Ge(d,B(c));if(p===".."||p.startsWith(`..${Z}`)||p.startsWith(Z))throw Error(`Block dependency outside sourceDir: ${c}`);return p.replaceAll(Z,"/")},o=(c)=>{if(n(B(e.sourceDir,c)),!e.readFile)n(ge(B(e.sourceDir,c)),ge(e.sourceDir));let d=r.get(c);if(d!==void 0)return d;let p=t(B(e.sourceDir,c));return r.set(c,p),p},a=(c)=>{let d=new Map,p=(y)=>{if(d.has(y))return;let u=o(y);d.set(y,{path:y,type:Ze(y),content:u});let s=u.matchAll(/(?:\bfrom\s*|\bimport\s*)["'](\.[^"']+)["']/g);for(let g of s){let f=n(B(e.sourceDir,Je(y),g[1]??"")),C=Qe(f)?[f]:[`${f}.ts`,`${f}.tsx`,`${f}/index.ts`,`${f}/index.tsx`],S;for(let F of C)try{o(F),S=F;break}catch(D){if(D instanceof Error&&D.message.includes("outside sourceDir"))throw D}if(!S)throw Error(`Unresolved block dependency: ${y} -> ${g[1]}`);p(S)}};return p(c),[...d.values()]},i=(c)=>{let d=new Set;for(let p of c){if(typeof p.content!=="string")continue;for(let y of p.content.matchAll(/(?:\bfrom\s*|\bimport\s*)["']([^."'/][^"']*|@[^"']+)["']/g)){let u=y[1]??"";if(u.startsWith("node:"))continue;let s=u.startsWith("@")?u.split("/").slice(0,2).join("/"):u.split("/")[0]??"";if(s==="react"||s==="react-dom"||s.startsWith("@uibot/"))continue;d.add(s)}}return[...d].sort()},l=[];for(let c of Object.keys(e.catalog)){let d=e.blockFileMap[c];if(d===void 0)continue;let p=e.catalog[c];if(p===void 0)continue;let y=o(d),u=a(d),s=i(u);l.push({name:c,category:p.category,description:p.description,sourceCode:y,files:u,catalogEntry:p,...s.length>0?{dependencies:s}:{}})}return l}function Lr(e){return e.flatMap((t)=>Xe(t))}import{readdirSync as et,readFileSync as tt,statSync as rt}from"fs";import{basename as nt,join as ot}from"path";var it="0.1.0";function me(e){let{dir:t}=e,r;try{r=et(t)}catch{return[]}let n=e.defaultVersion??it,o=e.defaultLevel??"L4",a=e.defaultCategory??"template",i=[];for(let l of r){if(!/\.ya?ml$/i.test(l))continue;let c=ot(t,l);try{if(!rt(c).isFile())continue}catch{continue}let d=tt(c,"utf8");if(!d.trim())continue;let p=nt(l).replace(/\.ya?ml$/i,""),y=at(p),u=ct(p),s=lt(d)??`${u} template`;i.push({name:y,version:n,title:u,description:s,yaml:d,absolutePath:c,templateContract:{name:y,description:s,level:o,category:a,keywords:[y,p.toLowerCase(),"uibot-template",...e.extraKeywords??[]],composedFrom:dt(d)}})}return i.sort((l,c)=>l.name.localeCompare(c.name))}function st(e){let t=new Map;for(let r of e)for(let n of me(r)){let o=t.get(n.name);if(o)throw Error(`duplicate template source name "${n.name}": ${o.absolutePath} and ${n.absolutePath}`);t.set(n.name,n)}return[...t.values()].sort((r,n)=>r.name.localeCompare(n.name))}function fe(e){return{kind:"template",name:e.name,version:e.version,files:[{path:`${e.name}.yaml`,type:"template",content:e.yaml,target:`${e.name}.yaml`}],templateContract:e.templateContract}}function X(e){return{name:e.name,kind:"template",title:e.title,description:e.description,artifact:fe(e)}}function at(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9]+/g,"-").replace(/^-|-$/g,"").toLowerCase()}function ct(e){return e.replace(/[-_]+/g," ").replace(/\b\w/g,(t)=>t.toUpperCase())}function lt(e){return(e.match(/^\s*title:\s*["']?(.+?)["']?\s*$/m)??e.match(/^\s*-\s*id:.*\n\s*path:.*\n\s*title:\s*["']?(.+?)["']?\s*$/m))?.[1]?.trim()}function dt(e){let t=new Set;for(let r of e.matchAll(/^\s*-\s*type:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let n=r[1]?.trim();if(n)t.add(n)}for(let r of e.matchAll(/^\s*template:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let n=r[1]?.trim();if(n)t.add(n)}return[...t].sort()}var ut="0.1.0";function pt(e,t={}){return{kind:"component",name:e.name,version:t.defaultVersion??ut,runtime:t.runtime??"react",files:e.files,...e.dependencies?{dependencies:e.dependencies}:{},...e.registryDependencies?{registryDependencies:e.registryDependencies}:{},...e.catalogEntry.tags?{tags:e.catalogEntry.tags}:{},catalogEntry:e.catalogEntry}}function ye(e,t={}){return{name:e.name,kind:"component",title:e.catalogEntry.name,description:e.description??e.catalogEntry.description,artifact:pt(e,t)}}function qr(e,t){let r={...t.runtime?{runtime:t.runtime}:{},...t.defaultVersion?{defaultVersion:t.defaultVersion}:{}},n=e.map((a)=>ye(a,r)),o=(t.templates??[]).map((a)=>X(a));return{name:t.name,items:[...n,...o]}}function zr(e,t={}){return ye(e,t)}var ft={spec:["html","markdown","zip"],prototype:["html","zip"],deck:["html","pptx","zip"],poster:["html","zip"]},Fn=Array.from(new Set(Object.values(ft).flat()));var Ce=["experimental","candidate","recommended"];var be=["missing","declared","verified","external-consumer"],ee=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure","packed-install","typecheck","browser"],yt=Object.freeze([Object.freeze({name:"manifest",summary:"Describe query operations and list the derived resource index.",positionals:Object.freeze([]),options:Object.freeze([])}),Object.freeze({name:"search",summary:"Search resources with deterministic bilingual ranking and reasons.",positionals:Object.freeze([Object.freeze({name:"text",property:"text",type:"string",required:!1})]),options:Object.freeze([Object.freeze({name:"kind",property:"kinds",type:"resource-kind",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"tag",property:"tags",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"category",property:"categories",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"capability",property:"capabilities",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"maturity",property:"maturities",type:"resource-maturity",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"limit",property:"limit",type:"positive-integer"})])}),Object.freeze({name:"get",summary:"Resolve one canonical resource id or unambiguous alias.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])}),Object.freeze({name:"build",summary:"Plan dependency closure and gaps without writing or installing.",positionals:Object.freeze([Object.freeze({name:"root",property:"roots",type:"string",required:!0,variadic:!0})]),options:Object.freeze([])})]);var te="uibot.registry.item.v1";var Ct="https://ui.shadcn.com/schema/registry.json",bt="https://ui.shadcn.com/schema/registry-item.json",ht=["clsx","tailwind-merge"],Rt="components/uibot",xt="lib",kt="@uibot",Pt="uibot/templates",re="uibot-base";function ne(e){return e.replace(/\./g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function he(e,t){let r=e.sourceCode;if(r=r.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/renderer-react["'];?/g,(a,i,l)=>`import ${i??"type "}${l} from "${t.rendererShimImport}";`),t.contractsShimImport){let a=t.contractsShimImport;r=r.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/contracts["'];?/g,(i,l,c)=>`import ${l??"type "}${c} from "${a}";`)}let n=new Set;r=r.replace(/\bReact\.([A-Z]\w*)/g,(a,i)=>(n.add(i),i));let o=!1;if(r=r.replace(/(?:^|\n)function cn\([\s\S]*?\)\s*(?::[^\n{]+)?\{[\s\S]*?\n\}\n?/,()=>(o=!0,`
2
+ import{lstatSync as pr,mkdirSync as Ve,readFileSync as gr,realpathSync as mr,writeFileSync as Ue}from"fs";import{basename as fr,dirname as ue,isAbsolute as yr,resolve as E,sep as Le}from"path";function We(e){let t=e.lockfilePath??"uibot.artifacts.lock.json",r=e.manifest.items??[],n=new Map;for(let i of r)n.set(i.name,i);if(e.lockfile===null)return{ok:!1,lockfilePath:t,registryName:e.manifest.name,lockCount:0,manifestCount:r.length,drifts:[{name:"*",kind:"missing-in-lock",detail:"lockfile missing or unreadable"}]};let o=[],a=new Set;for(let i of e.lockfile.artifacts??[]){a.add(i.name);let l=n.get(i.name);if(!l){o.push({name:i.name,kind:"missing-in-manifest",lockVersion:i.version,detail:`locked ${i.name}@${i.version} not present in registry manifest`});continue}let c=Ke(l);if(c&&c!==i.version)o.push({name:i.name,kind:"version-mismatch",lockVersion:i.version,manifestVersion:c,detail:`${i.name}: lock ${i.version} \u2260 registry ${c}`})}return{ok:o.length===0,lockfilePath:t,registryName:e.manifest.name,lockCount:(e.lockfile.artifacts??[]).length,manifestCount:r.length,drifts:o}}function Ke(e){return e.artifact?.version??e.version}function Ge(){return{version:1,artifacts:[]}}function Ye(e){return{version:1,artifacts:e}}import{readFileSync as Je,realpathSync as ge}from"fs";import{resolve as B,relative as Qe,dirname as Ze,extname as Xe,sep as Z}from"path";function et(e){if(e.endsWith(".css"))return"style";if(e.endsWith(".tsx")||e.endsWith(".jsx"))return"component";if(/(^|\/)use-[^/]+\.ts$/.test(e))return"hook";return"lib"}function tt(e){let t=e.readFile??((c)=>Je(c,"utf8")),r=new Map,n=(c,d=B(e.sourceDir))=>{let u=Qe(d,B(c));if(u===".."||u.startsWith(`..${Z}`)||u.startsWith(Z))throw Error(`Block dependency outside sourceDir: ${c}`);return u.replaceAll(Z,"/")},o=(c)=>{if(n(B(e.sourceDir,c)),!e.readFile)n(ge(B(e.sourceDir,c)),ge(e.sourceDir));let d=r.get(c);if(d!==void 0)return d;let u=t(B(e.sourceDir,c));return r.set(c,u),u},a=(c)=>{let d=new Map,u=(f)=>{if(d.has(f))return;let p=o(f);d.set(f,{path:f,type:et(f),content:p});let s=p.matchAll(/(?:\bfrom\s*|\bimport\s*)["'](\.[^"']+)["']/g);for(let g of s){let y=n(B(e.sourceDir,Ze(f),g[1]??"")),C=Xe(y)?[y]:[`${y}.ts`,`${y}.tsx`,`${y}/index.ts`,`${y}/index.tsx`],S;for(let F of C)try{o(F),S=F;break}catch(D){if(D instanceof Error&&D.message.includes("outside sourceDir"))throw D}if(!S)throw Error(`Unresolved block dependency: ${f} -> ${g[1]}`);u(S)}};return u(c),[...d.values()]},i=(c)=>{let d=new Set;for(let u of c){if(typeof u.content!=="string")continue;for(let f of u.content.matchAll(/(?:\bfrom\s*|\bimport\s*)["']([^."'/][^"']*|@[^"']+)["']/g)){let p=f[1]??"";if(p.startsWith("node:"))continue;let s=p.startsWith("@")?p.split("/").slice(0,2).join("/"):p.split("/")[0]??"";if(s==="react"||s==="react-dom"||s.startsWith("@uibot/"))continue;d.add(s)}}return[...d].sort()},l=[];for(let c of Object.keys(e.catalog)){let d=e.blockFileMap[c];if(d===void 0)continue;let u=e.catalog[c];if(u===void 0)continue;let f=o(d),p=a(d),s=i(p);l.push({name:c,category:u.category,description:u.description,sourceCode:f,files:p,catalogEntry:u,...s.length>0?{dependencies:s}:{}})}return l}function jr(e){return e.flatMap((t)=>tt(t))}import{readdirSync as rt,readFileSync as nt,statSync as ot}from"fs";import{basename as it,join as st}from"path";var at="0.1.0";function me(e){let{dir:t}=e,r;try{r=rt(t)}catch{return[]}let n=e.defaultVersion??at,o=e.defaultLevel??"L4",a=e.defaultCategory??"template",i=[];for(let l of r){if(!/\.ya?ml$/i.test(l))continue;let c=st(t,l);try{if(!ot(c).isFile())continue}catch{continue}let d=nt(c,"utf8");if(!d.trim())continue;let u=it(l).replace(/\.ya?ml$/i,""),f=lt(u),p=dt(u),s=ut(d)??`${p} template`;i.push({name:f,version:n,title:p,description:s,yaml:d,absolutePath:c,templateContract:{name:f,description:s,level:o,category:a,keywords:[f,u.toLowerCase(),"uibot-template",...e.extraKeywords??[]],composedFrom:pt(d)}})}return i.sort((l,c)=>l.name.localeCompare(c.name))}function ct(e){let t=new Map;for(let r of e)for(let n of me(r)){let o=t.get(n.name);if(o)throw Error(`duplicate template source name "${n.name}": ${o.absolutePath} and ${n.absolutePath}`);t.set(n.name,n)}return[...t.values()].sort((r,n)=>r.name.localeCompare(n.name))}function fe(e){return{kind:"template",name:e.name,version:e.version,files:[{path:`${e.name}.yaml`,type:"template",content:e.yaml,target:`${e.name}.yaml`}],templateContract:e.templateContract}}function X(e){return{name:e.name,kind:"template",title:e.title,description:e.description,artifact:fe(e)}}function lt(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9]+/g,"-").replace(/^-|-$/g,"").toLowerCase()}function dt(e){return e.replace(/[-_]+/g," ").replace(/\b\w/g,(t)=>t.toUpperCase())}function ut(e){return(e.match(/^\s*title:\s*["']?(.+?)["']?\s*$/m)??e.match(/^\s*-\s*id:.*\n\s*path:.*\n\s*title:\s*["']?(.+?)["']?\s*$/m))?.[1]?.trim()}function pt(e){let t=new Set;for(let r of e.matchAll(/^\s*-\s*type:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let n=r[1]?.trim();if(n)t.add(n)}for(let r of e.matchAll(/^\s*template:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let n=r[1]?.trim();if(n)t.add(n)}return[...t].sort()}var gt="0.1.0";function mt(e,t={}){return{kind:"component",name:e.name,version:t.defaultVersion??gt,runtime:t.runtime??"react",files:e.files,...e.dependencies?{dependencies:e.dependencies}:{},...e.registryDependencies?{registryDependencies:e.registryDependencies}:{},...e.catalogEntry.tags?{tags:e.catalogEntry.tags}:{},catalogEntry:e.catalogEntry}}function ye(e,t={}){return{name:e.name,kind:"component",title:e.catalogEntry.name,description:e.description??e.catalogEntry.description,artifact:mt(e,t)}}function Kr(e,t){let r={...t.runtime?{runtime:t.runtime}:{},...t.defaultVersion?{defaultVersion:t.defaultVersion}:{}},n=e.map((a)=>ye(a,r)),o=(t.templates??[]).map((a)=>X(a));return{name:t.name,items:[...n,...o]}}function Gr(e,t={}){return ye(e,t)}var Ct={spec:["html","markdown","zip"],prototype:["html","zip"],deck:["html","pptx","zip"],poster:["html","zip"]},Vn=Array.from(new Set(Object.values(Ct).flat()));var Ce=["experimental","candidate","recommended"];var he=["missing","declared","verified","external-consumer"],ee=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure","packed-install","typecheck","browser"],ht=Object.freeze([Object.freeze({name:"manifest",summary:"Describe query operations and list the derived resource index.",positionals:Object.freeze([]),options:Object.freeze([])}),Object.freeze({name:"search",summary:"Search resources with deterministic bilingual ranking and reasons.",positionals:Object.freeze([Object.freeze({name:"text",property:"text",type:"string",required:!1})]),options:Object.freeze([Object.freeze({name:"kind",property:"kinds",type:"resource-kind",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"tag",property:"tags",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"category",property:"categories",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"capability",property:"capabilities",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"maturity",property:"maturities",type:"resource-maturity",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"limit",property:"limit",type:"positive-integer"})])}),Object.freeze({name:"get",summary:"Resolve one canonical resource id or unambiguous alias.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])}),Object.freeze({name:"build",summary:"Plan dependency closure and gaps without writing or installing.",positionals:Object.freeze([Object.freeze({name:"root",property:"roots",type:"string",required:!0,variadic:!0})]),options:Object.freeze([])})]);var te="uibot.registry.item.v1";var bt="https://ui.shadcn.com/schema/registry.json",Rt="https://ui.shadcn.com/schema/registry-item.json",xt=["clsx","tailwind-merge"],kt="components/uibot",Pt="lib",St="@uibot",It="uibot/templates",re="uibot-base";function ne(e){return e.replace(/\./g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function be(e,t){let r=e.sourceCode;if(r=r.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/renderer-react["'];?/g,(a,i,l)=>`import ${i??"type "}${l} from "${t.rendererShimImport}";`),t.contractsShimImport){let a=t.contractsShimImport;r=r.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/contracts["'];?/g,(i,l,c)=>`import ${l??"type "}${c} from "${a}";`)}let n=new Set;r=r.replace(/\bReact\.([A-Z]\w*)/g,(a,i)=>(n.add(i),i));let o=!1;if(r=r.replace(/(?:^|\n)function cn\([\s\S]*?\)\s*(?::[^\n{]+)?\{[\s\S]*?\n\}\n?/,()=>(o=!0,`
3
3
  `)),o){let a=`import { cn } from "${t.cnUtilImport}";
4
4
  `,i=r.indexOf(`
5
- `,r.indexOf("import "));if(i>=0)r=`${r.slice(0,i+1)}${a}${r.slice(i+1)}`;else r=a+r}if(n.size>0){let a=[...n].sort().join(", "),i=/import\s+type\s+\{([^}]*)\}\s+from\s+["']react["'];?/;if(i.test(r))r=r.replace(i,(l,c)=>`import type { ${[...new Set([...c.split(",").map((p)=>p.trim()).filter(Boolean),...n])].sort().join(", ")} } from "react";`);else{let l=`import type { ${a} } from "react";
5
+ `,r.indexOf("import "));if(i>=0)r=`${r.slice(0,i+1)}${a}${r.slice(i+1)}`;else r=a+r}if(n.size>0){let a=[...n].sort().join(", "),i=/import\s+type\s+\{([^}]*)\}\s+from\s+["']react["'];?/;if(i.test(r))r=r.replace(i,(l,c)=>`import type { ${[...new Set([...c.split(",").map((u)=>u.trim()).filter(Boolean),...n])].sort().join(", ")} } from "react";`);else{let l=`import type { ${a} } from "react";
6
6
  `,c=r.indexOf(`
7
7
  `,r.indexOf("import "));if(c>=0)r=`${r.slice(0,c+1)}${l}${r.slice(c+1)}`;else r=l+r}}return`${r.replace(/\n{3,}/g,`
8
8
 
9
9
  `).trimStart().trimEnd()}
10
- `}function St(e){let t={category:e.category,level:e.level};if(e.props)t.props=e.props;if(e.slots)t.slots=e.slots;if(e.events)t.events=e.events;if(e.usageScenarios)t.scenarios=e.usageScenarios;if(e.constraints)t.constraints=e.constraints;return t}function Vo(e){return{light:Re(e,":root"),dark:Re(e,".dark")}}function Re(e,t){let r={},n=new RegExp(`${xe(t)}\\s*\\{`,"g"),o;while((o=n.exec(e))!==null){let a=o.index+o[0].length,i=1,l=a;for(;l<e.length&&i>0;l++){let d=e[l];if(d==="{")i++;else if(d==="}")i--}let c=e.slice(a,l-1);for(let d of c.matchAll(/--([\w-]+)\s*:\s*([^;]+);/g)){let p=d[1],y=d[2];if(p!==void 0&&y!==void 0)r[p]=y.trim()}}return r}function xe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Uo(e,t){let r=t.sharedDependencies??ht,n=t.channel??"public",o=It(t),a=(t.componentsDir??Rt).replace(/\/$/,""),i=(t.libDir??xt).replace(/\/$/,""),l=`${i}/uibot-renderer.ts`,c=`${i}/utils.ts`,d=`${i}/uibot-contracts.ts`,p="@/lib/uibot-renderer",y="@/lib/utils",u="@/lib/uibot-contracts",s={},g={name:re,type:"registry:lib",description:"UIBot runtime base: RendererComponent type shim + cn util + OKLCH theme tokens. Pulled automatically by every UIBot block.",dependencies:r,files:[{path:l,content:t.rendererShimContent,type:"registry:lib"},{path:c,content:t.cnUtilContent,type:"registry:lib"},...t.contractsShimContent?[{path:d,content:t.contractsShimContent,type:"registry:lib"}]:[]],...t.cssVars?{cssVars:t.cssVars}:{},meta:{base:!0}};s[re]=g;let f=new Map,C=new Map,S=new Map,F=new Map;for(let m of e){let I=m.files[0]?.path??`${ne(m.name)}.tsx`,x=m.channel??"public",b=F.get(I);if(b&&b!==x)throw Error(`${I} mixes ${b} and ${x} blocks; split the file`);F.set(I,x)}for(let m of e){if((m.channel??"public")!==n)continue;let x=m.files[0]?.path??`${ne(m.name)}.tsx`,b=f.get(x);if(!b){let R=ne(wt(x,m.name)),W=he(m,{rendererShimImport:"@/lib/uibot-renderer",cnUtilImport:"@/lib/utils",...t.contractsShimContent?{contractsShimImport:"@/lib/uibot-contracts"}:{}}),T=`${a}/${R}.tsx`,V={schema:te,item:R,channel:n,components:[]};S.set(R,V),b={name:R,type:"registry:ui",description:m.description??m.catalogEntry.description,dependencies:["react",...m.dependencies??[]],registryDependencies:[o(re)],files:m.files.length<=1?[{path:T,target:T,content:W,type:"registry:ui"}]:m.files.map((K)=>{if(typeof K.content!=="string")throw Error(`Missing block source content: ${K.path}`);let pe=`${a}/${K.path.replace(/^blocks\//,"")}`;return{path:pe,target:pe,content:he({...m,sourceCode:K.content},{rendererShimImport:"@/lib/uibot-renderer",cnUtilImport:"@/lib/utils",...t.contractsShimContent?{contractsShimImport:"@/lib/uibot-contracts"}:{}}),type:"registry:ui"}}),meta:{...St(m.catalogEntry),provides:[m.name],uibot:V}},f.set(x,b),s[R]=b}else{let R=b.meta;if(R.provides&&!R.provides.includes(m.name))R.provides.push(m.name)}let A=S.get(b.name);if(A?.components&&!C.has(m.name))A.components.push(At(m,b,a)),C.set(m.name,b.name)}for(let[m,I]of S){let x=s[m];if(!x)continue;I.components?.sort((A,R)=>A.name.localeCompare(R.name));let b=`${a}/${m}.uibot.json`;x.files.push({path:b,target:b,content:`${JSON.stringify(I,null,2)}
11
- `,type:"registry:ui"})}let D={},Q=(t.templates??[]).filter((m)=>(m.channel??"public")===n),qe=new Set(Q.map((m)=>m.name));for(let m of Q){if(s[m.name])throw Error(`template item "${m.name}" collides with a component item`);let I=m.templateContract.composedFrom??[],x=new Set,b=[];for(let T of I){let V=C.get(T);if(V)x.add(o(V));else if(qe.has(T)&&T!==m.name)x.add(o(T));else b.push(T)}if(b.length>0)D[m.name]=b;let A=`${i}/${Pt}`,R=`${m.name}.uibot.yaml`,W={schema:te,item:m.name,channel:n,template:{file:R,contract:m.templateContract}};s[m.name]={name:m.name,type:"registry:block",description:m.description,registryDependencies:[...x].sort(),files:[{path:`${A}/${R}`,target:`${A}/${R}`,content:m.yaml,type:"registry:lib"},{path:`${A}/${m.name}.uibot.json`,target:`${A}/${m.name}.uibot.json`,content:`${JSON.stringify(W,null,2)}
12
- `,type:"registry:lib"}],meta:{uibot:W}}}return{registry:{$schema:Ct,name:t.registryName,...t.homepage?{homepage:t.homepage}:{},items:Object.values(s).map((m)=>({name:m.name,type:m.type,...m.description?{description:m.description}:{},...m.registryDependencies?{registryDependencies:m.registryDependencies}:{},...m.dependencies?{dependencies:m.dependencies}:{}}))},items:s,unresolvedTemplateTypes:D}}function It(e){if(e.baseUrl){let r=e.baseUrl.replace(/\/$/,"");return(n)=>`${r}/r/${n}.json`}let t=e.namespace??kt;if(!/^@[a-z0-9][a-z0-9-]*$/.test(t))throw Error(`registry namespace must look like "@uibot", got "${t}"`);return(r)=>`${t}/${r}`}function At(e,t,r){let n=e.name.replace(/\./g,""),o=`${r}/`,a=t.files.find((i)=>i.path.startsWith(o)&&/\.(tsx|ts)$/.test(i.path)&&vt(i.content,n));if(!a)throw Error(`block "${e.name}" has no named export "${n}" in item "${t.name}"`);return{name:e.name,export:n,module:a.path.slice(o.length),catalog:e.catalogEntry}}function vt(e,t){let r=xe(t),n=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*\/\/.*$/gm,"");if(new RegExp(`export\\s+(?:const|let|function|class)\\s+${r}\\b`).test(n))return!0;for(let o of n.matchAll(/export\s*\{([^}]*)\}/g)){let a=(o[1]??"").split(",").map((l)=>{let[,c]=l.trim().split(/\s+as\s+/);return(c??l.trim().replace(/^type\s+/,"")).trim()}),i=(o[1]??"").split(",").map((l)=>l.trim()).filter((l)=>l.startsWith("type ")).map((l)=>l.replace(/^type\s+/,"").split(/\s+as\s+/).pop()?.trim());if(a.includes(t)&&!i.includes(t))return!0}return!1}function wt(e,t){return(e.split("/").pop()??t).replace(/\.(tsx|ts|jsx|js)$/,"")||t}var jo=bt;function Et(e="/api/registry"){let t=(e||"/api/registry").trim(),r=t.startsWith("/")?t:`/${t}`;return r.length>1?r.replace(/\/$/,""):r}function U(e,t=200){return Response.json(e,{status:t})}function qo(e){let t=Et(e.basePath),r=`${t}/registry.json`,n=`${t}/artifacts/`,o=new Map(e.manifest.items.map((a)=>[a.name,a]));return async function(i){let l=new URL(i.url);if(i.method!=="GET")return U({error:"Method not allowed"},405);if(l.pathname===r)return U(e.manifest);if(l.pathname.startsWith(n)){let c=l.pathname.slice(n.length),d=decodeURIComponent(c.endsWith(".json")?c.slice(0,-5):c),p=o.get(d);if(!p)return U({error:`Artifact '${d}' not found`},404);return U(p)}return U({error:"Not found"},404)}}var oe="uibot.resource.admission.v1",Dt=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure"],Tt=["packed-install","typecheck","browser"],Wo=["invalid-admission-manifest","invalid-admission-record","invalid-admission-check","duplicate-admission-record","unknown-admission-resource","missing-source-metadata","missing-license-metadata","dependency-closure-failed"];class ke extends Error{expected;actual;code="resource-admission-index-mismatch";constructor(e,t){super(`resource admission index mismatch: expected ${e}, received ${t}`);this.expected=e;this.actual=t;this.name="ResourceAdmissionIndexMismatchError"}}class Pe extends Error{issueCount;code="resource-admission-report-rejected";constructor(e){super(`resource admission report contains ${e.toString()} issue(s)`);this.issueCount=e;this.name="ResourceAdmissionReportRejectedError"}}class Se extends Error{code="resource-admission-report-not-derived";constructor(){super("resource admission report must come directly from assessResourceAdmissions");this.name="ResourceAdmissionReportNotDerivedError"}}var Ot=new Set(ee),Ft=new Set(be),Ie=new WeakSet,Y={missing:0,declared:1,verified:2,"external-consumer":3};function Mt(e,t){return e<t?-1:e>t?1:0}function L(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function G(e,t){let r=new Set(t);return Object.keys(e).every((n)=>r.has(n))}function Ae(e){return[...new Set(e.map((t)=>t.trim()).filter(Boolean))].sort(Mt)}function _t(e,t,r,n){if(!L(r)||!G(r,["status","evidence"])){n.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} must contain only status and evidence`});return}if(typeof r.status!=="string"||!Ft.has(r.status)||r.status==="missing"){n.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} status must be declared, verified or external-consumer`});return}if(!Array.isArray(r.evidence)||r.evidence.length===0||r.evidence.some((o)=>typeof o!=="string"||!o.trim())){n.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} evidence must be a non-empty string array`});return}return{status:r.status,evidence:Ae(r.evidence)}}function Bt(e){if(e===void 0)return;if(!L(e)||!G(e,["source","version","license"]))return;if(Object.values(e).some((r)=>r!==void 0&&typeof r!=="string"))return;return{...typeof e.source==="string"&&e.source.trim()?{source:e.source.trim()}:{},...typeof e.version==="string"&&e.version.trim()?{version:e.version.trim()}:{},...typeof e.license==="string"&&e.license.trim()?{license:e.license.trim()}:{}}}function Lt(e,t){let r=new Map,n=[];if(!L(t)||!G(t,["schemaVersion","records"])||t.schemaVersion!==oe||!Array.isArray(t.records))return n.push({code:"invalid-admission-manifest",detail:`expected ${oe} with a records array`}),{records:r,issues:n};let o=new Set(e.resources.map((a)=>a.id));for(let a of t.records){if(!L(a)||!G(a,["resourceId","provenance","checks"])||typeof a.resourceId!=="string"||!a.resourceId.trim()||!L(a.checks)){n.push({code:"invalid-admission-record",...L(a)&&typeof a.resourceId==="string"?{resourceId:a.resourceId}:{},detail:"record must contain only resourceId, optional provenance and checks"});continue}let i=a.resourceId.trim();if(r.has(i)){n.push({code:"duplicate-admission-record",resourceId:i,detail:i});continue}if(!o.has(i)){n.push({code:"unknown-admission-resource",resourceId:i,detail:i});continue}let l=Bt(a.provenance);if(a.provenance!==void 0&&!l){n.push({code:"invalid-admission-record",resourceId:i,detail:"provenance must contain only string source, version and license fields"});continue}let c={},d=!1;for(let[p,y]of Object.entries(a.checks)){if(!Ot.has(p)){n.push({code:"invalid-admission-check",resourceId:i,detail:`unknown receipt check: ${p}`}),d=!0;continue}let u=p,s=_t(i,u,y,n);if(s)c[u]=s;else d=!0}if(d)continue;r.set(i,{resourceId:i,...l?{provenance:l}:{},checks:c})}return{records:r,issues:n}}function Nt(e){let t=new Map(e.resources.map((o)=>[o.id,o])),r=new Map;function n(o,a,i,l){if(r.has(o)||l.has(a))return;if(i.has(a)){r.set(o,`dependency cycle reached ${a}`);return}let c=t.get(a);if(!c){r.set(o,`missing dependency ${a}`);return}i.add(a);for(let d of c.dependencies)if(n(o,d,i,l),r.has(o))break;i.delete(a),l.add(a)}for(let o of e.resources)n(o.id,o.id,new Set,new Set);return r}var Vt=/^(unknown|unlicensed|none|n\/?a)$/i,Ut=/^SPDX-License-Identifier:\s*(\S+)/im,jt=/^(?:the\s+)?(mit|apache(?:\s+license(?:\s*,?\s*version\s*2\.0)?)?|bsd-2-clause|bsd-3-clause|isc|unlicense)\b/i;function M(e){let t=e?.trim();if(!t||Vt.test(t))return;return t}function $t(e){if(!e?.trim())return;let t=e.match(Ut)?.[1];if(t)return M(t);let r=e.match(jt)?.[1];if(!r)return;let n=r.toLowerCase();if(n.startsWith("mit"))return"MIT";if(n.startsWith("apache"))return"Apache-2.0";if(n.startsWith("bsd-2"))return"BSD-2-Clause";if(n.startsWith("bsd-3"))return"BSD-3-Clause";if(n==="isc")return"ISC";if(n==="unlicense")return"Unlicense";return}function Ko(e){return M(e.frontmatterLicense)??M(e.packageJsonLicense)??$t(e.licenseFileText)}function ve(e){return Boolean(M(e))}var j={states:/\b(disabled|loading|error|empty|pending|busy|children|active|muted|boolean-state)\b/i,accessibility:/\b(label|aria|accessible|alt|role)\b/i,"light-theme":/:root\b|\b(light(?:-theme)?|theme token|css variables?)\b/i,"dark-theme":/\b(dark(?:-theme)?)\b/i,responsive:/\b(size|responsive|breakpoint|sm|md|lg|xl|full)\b/i};function ie(e,t){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let n of e)ie(n,t);return}let r=e;for(let[n,o]of Object.entries(r)){if(t.push(n),n==="type"&&o==="boolean")t.push("boolean-state");ie(o,t)}}function qt(e){let t=[];return ie(e.props,t),[e.name,e.description,...e.tags??[],...e.usageScenarios??[],...e.constraints??[],...t,...Object.keys(e.slots??{}),...Object.keys(e.events??{}),e.slots&&Object.keys(e.slots).length>0?"empty":""].join(`
13
- `)}function Yo(e,t={}){let r=[qt(e),t.sourceText??"",t.stylesText??""].join(`
14
- `);return{contract:Boolean(e.props&&Object.keys(e.props).length>0||e.events&&Object.keys(e.events).length>0||e.slots&&Object.keys(e.slots).length>0)?"verified":"declared",states:j.states.test(r)?"verified":"missing",accessibility:j.accessibility.test(r)?"verified":"missing","light-theme":j["light-theme"].test(r)?"verified":"missing","dark-theme":j["dark-theme"].test(r)?"verified":"missing",responsive:j.responsive.test(r)?"verified":"missing"}}function zt(e){return{source:"declared",license:ve(e.source.license)?"declared":"missing",contract:"declared",states:"missing",accessibility:"missing","light-theme":"missing","dark-theme":"missing",responsive:"missing","dependency-closure":"missing","packed-install":"missing",typecheck:"missing",browser:"missing"}}function Ht(e){if(!Dt.every((n)=>Y[e[n]]>=Y.verified))return"experimental";return Tt.every((n)=>e[n]==="external-consumer")?"recommended":"candidate"}function we(e){let t=JSON.stringify({schemaVersion:e.schemaVersion,resources:e.resources.map((o)=>({id:o.id,kind:o.kind,title:o.title,description:o.description,...o.category?{category:o.category}:{},tags:o.tags,aliases:o.aliases,capabilities:o.capabilities,dependencies:o.dependencies,source:o.source})),aliases:e.aliases}),r=0xcbf29ce484222325n,n=0x100000001b3n;for(let o of new TextEncoder().encode(t))r^=BigInt(o),r=BigInt.asUintN(64,r*n);return`fnv1a64:${r.toString(16).padStart(16,"0")}`}function Wt(e,t,r){let n=zt(e),o=[`resource://${e.source.type}/${e.source.id}`,`resource://contract/${e.id}`],a=[];if(r)a.push({code:"dependency-closure-failed",resourceId:e.id,check:"dependency-closure",detail:r});else n["dependency-closure"]="verified",o.push(`resource://index/${e.id}`);if(t)for(let c of ee){if(c==="dependency-closure")continue;let d=t.checks[c];if(!d)continue;if(c==="source"&&Y[d.status]>=Y.verified&&(!t.provenance?.source||!t.provenance.version)){a.push({code:"missing-source-metadata",resourceId:e.id,check:c,detail:"verified source requires provenance.source and provenance.version"});continue}if(c==="license"&&!ve(t.provenance?.license)){a.push({code:"missing-license-metadata",resourceId:e.id,check:c,detail:"license evidence requires a concrete provenance.license"});continue}if(n[c]=d.status,o.push(...d.evidence),c==="source"&&t.provenance?.source)o.push(t.provenance.source)}let i=Ht(n),l={level:i==="recommended"?"external-consumer":i==="candidate"?"verified":"declared",maturity:i,checks:n,evidence:Ae(o)};return Object.freeze(l.checks),Object.freeze(l.evidence),Object.freeze(l),Object.freeze(a),Object.freeze({resourceId:e.id,receipt:l,issues:a})}function Go(e,t){let r=Lt(e,t),n=Nt(e),o=e.resources.map((c)=>Wt(c,r.records.get(c.id),n.get(c.id))),a=[...r.issues,...o.flatMap((c)=>c.issues)],i=Object.fromEntries(Ce.map((c)=>[c,0]));for(let c of o)i[c.receipt.maturity]+=1;Object.freeze(o),Object.freeze(i);for(let c of a)Object.freeze(c);Object.freeze(a);let l=Object.freeze({schemaVersion:oe,indexFingerprint:we(e),resources:o,counts:i,issues:a});return Ie.add(l),l}function Jo(e,t){if(!Ie.has(t))throw new Se;if(t.issues.length>0)throw new Pe(t.issues.length);let r=we(e);if(r!==t.indexFingerprint)throw new ke(t.indexFingerprint,r);let n=new Map(t.resources.map((a)=>[a.resourceId,a.receipt])),o=e.resources.map((a)=>{let i=n.get(a.id);if(!i)return a;return Object.freeze({...a,receipt:i})});return Object.freeze(o),Object.freeze({schemaVersion:e.schemaVersion,resources:o,aliases:e.aliases})}var Kt="uibot.resource.index.v1",Xo=["invalid-resource-source-id","duplicate-resource-id","dangling-resource-dependency","ambiguous-resource-dependency"];class N extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceIndexError"}}function k(e,t){return e<t?-1:e>t?1:0}function h(e){return e.normalize("NFKC").replace(/([\p{Lu}]+)([\p{Lu}][\p{Ll}])/gu,"$1 $2").replace(/([\p{Ll}\p{N}])([\p{Lu}])/gu,"$1 $2").toLowerCase().replace(/[^\p{L}\p{N}]+/gu," ").trim().replace(/\s+/g," ")}function Yt(e){let t=h(e).replace(/ /g,"-");if(!t)throw new N("invalid-resource-source-id",e);return t}function v(e,t){return`${e}:${Yt(t)}`}function J(e){let t=new Map;for(let r of e){let n=r?.trim();if(!n)continue;let o=h(n);if(!o||t.has(o))continue;t.set(o,n)}return[...t.entries()].sort(([r],[n])=>k(r,n)).map(([,r])=>r)}function q(e){return{level:"declared",maturity:"experimental",checks:{source:"declared",license:e?"declared":"missing",contract:"declared",states:"missing",accessibility:"missing","light-theme":"missing","dark-theme":"missing",responsive:"missing","dependency-closure":"missing","packed-install":"missing",typecheck:"missing",browser:"missing"},evidence:[]}}function Gt(e){let t=M(e.license);return{type:e.type,id:e.id,...e.version?{version:e.version}:{},...e.url?{url:e.url}:{},...t?{license:t}:{}}}function z(e){return{id:e.id,kind:e.kind,title:e.title,description:e.description,...e.category?{category:e.category}:{},tags:J(e.tags),aliases:J(e.aliases),capabilities:J(e.capabilities),dependencies:[...new Set(e.dependencies)].sort(k),source:Gt(e.source),receipt:e.receipt}}function Jt(e){return(e.body.split(/\r?\n/).map((r)=>r.replace(/^#+\s*/,"").trim()).find(Boolean)??e.title).slice(0,240)}function Qt(e){return Object.freeze(e.tags),Object.freeze(e.aliases),Object.freeze(e.capabilities),Object.freeze(e.dependencies),Object.freeze(e.source),Object.freeze(e.receipt.checks),Object.freeze(e.receipt.evidence),Object.freeze(e.receipt),Object.freeze(e)}function Zt(e){let t=new Map;for(let r of Object.keys(e).sort(k)){let n=e[r];if(!n)continue;let o=v("component",r);for(let a of J([r,n.name])){let i=h(a),l=t.get(i)??[];if(!l.includes(o))l.push(o);t.set(i,l.sort(k))}}return t}function Xt(e,t,r){let n=r.get(h(e))??[];if(n.length===0)throw new N("dangling-resource-dependency",`${t} -> ${v("component",e)}`);if(n.length>1)throw new N("ambiguous-resource-dependency",`${t} -> ${e}: ${n.join(",")}`);return n[0]}function er(e,t,r,n){let o=e.startsWith("template:")?e.slice(9):e;if(Object.hasOwn(n,o))return v("template",o);return Xt(e,t,r)}function H(e,t,r){return M(r?.[e]??t)}function ei(e){return Object.entries(e).filter(([,t])=>t.level==="L4").sort(([t],[r])=>k(t,r)).map(([t,r])=>({id:`${t}-example`,title:`${r.name} Example`,description:r.description,category:r.category,tags:r.keywords,aliases:[`${t} example`,`${r.name} example`],capabilities:["example:template"],dependencies:[v("template",t)]}))}function ti(e){let t=e.components??{},r=e.templates??{},n=e.designGuides??[],o=e.examples??[],a=e.skills??[],i=e.licenses,l=Zt(t),c=[];for(let s of Object.keys(t).sort(k)){let g=t[s];if(!g)continue;let f=v("component",s),C=H(f,void 0,i);c.push(z({id:f,kind:"component",title:g.name,description:g.description,category:g.category,tags:g.tags??[],aliases:[s,g.name],capabilities:["catalog:component"],dependencies:[],source:{type:"catalog",id:s,...C?{license:C}:{}},receipt:q(Boolean(C))}))}for(let s of Object.keys(r).sort(k)){let g=r[s];if(!g)continue;let f=v("template",s),C=H(f,void 0,i);c.push(z({id:f,kind:"template",title:g.name,description:g.description,category:g.category,tags:g.keywords,aliases:[s,g.name],capabilities:[],dependencies:(g.composedFrom??[]).map((S)=>er(S,f,l,r)),source:{type:"template-contract",id:s,...C?{license:C}:{}},receipt:q(Boolean(C))}))}for(let s of[...n].sort((g,f)=>k(g.id,f.id))){let g=v("design-guide",s.id),f=H(g,void 0,i);c.push(z({id:g,kind:"design-guide",title:s.title,description:Jt(s),category:s.category,tags:s.tags,aliases:[s.id,s.title],capabilities:["designMd:source"],dependencies:[],source:{type:"design-md",id:s.id,...s.sourceUrl?{url:s.sourceUrl}:{},...f?{license:f}:{}},receipt:q(Boolean(f))}))}for(let s of[...o].sort((g,f)=>k(g.id,f.id))){let g=v("example",s.id),f=H(g,s.license,i);c.push(z({id:g,kind:"example",title:s.title,description:s.description,...s.category?{category:s.category}:{},tags:s.tags??[],aliases:[s.id,s.title,...s.aliases??[]],capabilities:s.capabilities??[],dependencies:s.dependencies??[],source:{type:"example",id:s.id,...s.version?{version:s.version}:{},...s.sourceUrl?{url:s.sourceUrl}:{},...f?{license:f}:{}},receipt:q(Boolean(f))}))}for(let s of[...a].sort((g,f)=>k(g.id,f.id))){let g=v("skill",s.id),f=H(g,void 0,i);c.push(z({id:g,kind:"skill",title:s.title,description:s.description?.trim()||s.title,tags:[...s.tags??[],...s.triggers??[]],aliases:[s.id,s.title,...s.triggers??[]],capabilities:["skill:definition"],dependencies:[],source:{type:"skill",id:s.id,...s.version?{version:s.version}:{},...f?{license:f}:{}},receipt:q(Boolean(f))}))}c.sort((s,g)=>k(s.id,g.id));let d=new Set;for(let s of c){if(d.has(s.id))throw new N("duplicate-resource-id",s.id);d.add(s.id)}for(let s of c)for(let g of s.dependencies)if(!d.has(g))throw new N("dangling-resource-dependency",`${s.id} -> ${g}`);let p=new Map;for(let s of c)for(let g of s.aliases){let f=h(g);if(!f)continue;let C=p.get(f)??new Set;C.add(s.id),p.set(f,C)}let y=Object.freeze(Object.fromEntries([...p.entries()].sort(([s],[g])=>k(s,g)).map(([s,g])=>[s,Object.freeze([...g].sort(k))]))),u=Object.freeze(c.map(Qt));return Object.freeze({schemaVersion:Kt,resources:u,aliases:y})}var tr=[["data table","data grid","datatable","table","\u8868\u683C","\u6570\u636E\u8868","\u6570\u636E\u8868\u683C"],["button","action button","\u6309\u94AE","\u64CD\u4F5C\u6309\u94AE"],["dashboard","admin dashboard","\u4EEA\u8868\u76D8","\u540E\u53F0","\u7BA1\u7406\u540E\u53F0"],["kanban","kanban board","\u770B\u677F","\u4EFB\u52A1\u770B\u677F"],["form","input form","\u8868\u5355","\u8F93\u5165\u8868\u5355"],["navigation","nav","sidebar","\u5BFC\u822A","\u4FA7\u8FB9\u680F"]],rr=Object.freeze(tr.map((e)=>Object.freeze([...e]))),Ee=new Map;for(let e of rr){let t=Object.freeze([...new Set(e.map(h).filter(Boolean))].sort());for(let r of t)Ee.set(r,t)}function se(e){let t=h(e);return Ee.get(t)??Object.freeze([t])}var ai=["resource-query-empty","resource-query-invalid-limit","resource-not-found","resource-alias-ambiguous"];class O extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceQueryError"}}var de=Object.freeze({"exact-id":1000,"exact-title":900,alias:800,tag:600,capability:500,category:400,token:200,fuzzy:100}),nr=Object.freeze(Object.keys(de)),De=new Map(nr.map((e,t)=>[e,t])),Te=new Map([["component",0],["template",1],["design-guide",2],["example",3],["skill",4]]);function P(e,t){return e<t?-1:e>t?1:0}function Oe(e){return new Set((e??[]).map(h).filter(Boolean))}function ae(e,t){let r=Oe(t);if(r.size===0)return!0;let n=Oe(e);return[...r].some((o)=>n.has(o))}function or(e,t){if(t.kinds?.length&&!t.kinds.includes(e.kind))return!1;if(!ae(e.tags,t.tags))return!1;if(!ae(e.category?[e.category]:[],t.categories))return!1;if(!ae(e.capabilities,t.capabilities))return!1;if(t.maturities?.length&&!t.maturities.includes(e.receipt.maturity))return!1;return!0}function ir(e){return Boolean(e.kinds?.length||e.tags?.length||e.categories?.length||e.capabilities?.length||e.maturities?.length)}function w(e,t,r,n=de[t]){if(e.some((o)=>o.code===t&&o.value===r))return;e.push({code:t,value:r,score:n})}function ce(e,t){return e.find((r)=>h(r)===t)}function le(e){return[e.id,e.title,...e.aliases,...e.tags,...e.category?[e.category]:[],...e.capabilities]}function sr(e,t,r){if(Math.abs(e.length-t.length)>r)return r+1;let n=Array.from({length:t.length+1},(o,a)=>a);for(let o=1;o<=e.length;o+=1){let a=[o],i=o;for(let l=1;l<=t.length;l+=1){let c=(n[l-1]??r+1)+(e[o-1]===t[l-1]?0:1),d=Math.min((n[l]??r+1)+1,(a[l-1]??r+1)+1,c);a.push(d),i=Math.min(i,d)}if(i>r)return r+1;n=a}return n[t.length]??r+1}function ar(e,t){let r=h(t),n=[];if(h(e.id)===r)w(n,"exact-id",e.id);if(h(e.title)===r)w(n,"exact-title",e.title);let o=ce(e.aliases,r);if(o)w(n,"alias",o);let a=ce(e.tags,r);if(a)w(n,"tag",a);let i=ce(e.capabilities,r);if(i)w(n,"capability",i);if(e.category&&h(e.category)===r)w(n,"category",e.category);if(!o){let d=se(r).filter((y)=>y!==r),p=new Set(le(e).map(h));if(d.some((y)=>p.has(y)))w(n,"alias",t.trim())}let l=r.split(" ").filter(Boolean),c=h(le(e).join(" "));if(l.length>0&&l.every((d)=>c.includes(d)))w(n,"token",t.trim());if(n.length===0&&r.length>=4){let d;for(let p of le(e)){let y=h(p);if(y.length<4)continue;let u=sr(r,y,2);if(u<=2&&(!d||u<d.distance||u===d.distance&&P(p,d.value)<0))d={value:p,distance:u}}if(d)w(n,"fuzzy",d.value,de.fuzzy-d.distance)}return n.sort((d,p)=>{if(d.score!==p.score)return p.score-d.score;return(De.get(d.code)??99)-(De.get(p.code)??99)||P(d.value,p.value)})}function Fe(e,t,r){if(t.has(r))return[r];let n=h(r),o=e.aliases[n];if(o?.length)return[...o];let a=new Set;for(let i of se(n))for(let l of e.aliases[i]??[])a.add(l);return[...a].sort(P)}function Me(e,t){return new O("resource-alias-ambiguous",`${e.trim()}: ${t.join(",")}`)}function ci(e){let t=new Map(e.resources.map((n)=>[n.id,n]));function r(n){let o=n.trim(),a=Fe(e,t,o);if(a.length===0)throw new O("resource-not-found",o);if(a.length>1)throw Me(o,a);let i=a[0],l=i?t.get(i):void 0;if(!l)throw new O("resource-not-found",o);return l}return Object.freeze({manifest:()=>e,search(n){let o=n.text?.trim()??"";if(!o&&!ir(n))throw new O("resource-query-empty","text or filter is required");if(n.limit!==void 0&&(!Number.isInteger(n.limit)||n.limit<=0))throw new O("resource-query-invalid-limit",String(n.limit));let a=e.resources.filter((i)=>or(i,n)).map((i)=>{let l=o?ar(i,o):[];return{resource:i,score:l.reduce((c,d)=>c+d.score,0),reasons:l}}).filter((i)=>!o||i.reasons.length>0).sort((i,l)=>l.score-i.score||P(i.resource.id,l.resource.id));return n.limit===void 0?a:a.slice(0,n.limit)},get:r,build(n){if(n.length===0||n.every((u)=>!u.trim()))throw new O("resource-query-empty","at least one build root is required");let o=[],a=new Set;for(let u of n){let s=u.trim(),g=Fe(e,t,s);if(g.length===0)o.push({id:s,reason:"missing-resource"});else if(g.length>1)throw Me(s,g);else{let f=g[0];if(f)a.add(f)}}let i=new Set,l=new Set,c=new Set,d=[],p=[],y=(u,s)=>{if(i.has(u))return;if(l.has(u)){o.push({id:u,...s?{requiredBy:s}:{},reason:"dependency-cycle"});return}let g=t.get(u);if(!g){o.push({id:u,...s?{requiredBy:s}:{},reason:"missing-resource"});return}l.add(u),c.add(u);let f=[...g.dependencies].sort((C,S)=>{let F=t.get(C),D=t.get(S);return(Te.get(F?.kind??"")??99)-(Te.get(D?.kind??"")??99)||P(C,S)});for(let C of f)p.push({from:u,to:C,relation:"depends-on"}),y(C,u);l.delete(u),i.add(u),d.push(u)};for(let u of[...a].sort(P))y(u);return{roots:[...a].sort(P),nodes:[...c].sort(P).map((u)=>{let s=t.get(u);if(!s)throw new O("resource-not-found",u);return{id:u,kind:s.kind,maturity:s.receipt.maturity}}),edges:p.sort((u,s)=>P(u.from,s.from)||P(u.to,s.to)),order:d,gaps:o.sort((u,s)=>P(u.id,s.id)||P(u.requiredBy??"",s.requiredBy??"")||P(u.reason,s.reason))}}})}function gr(e){if(!e.name)throw Error("Artifact registry manifest requires a name");return e}function mr(e){if(!e.name)throw Error("Plugin distribution manifest requires a name");return e}class fr{id;priority;items;constructor(e,t,r){this.id=e;this.priority=t;this.items=r}get(e){return this.items[e]}}class yr{id;priority;items;constructor(e,t,r){this.id=e;this.priority=t;this.items=r}get(e){return this.items[e]}}async function Ve(e,t){let r=await fetch(e,t?{headers:t}:{});if(!r.ok)throw Error(`Failed to fetch ${e}: ${r.status} ${r.statusText}`);return await r.json()}async function Cr(e,t){let r=e.endsWith("/registry.json")?e:`${e.replace(/\/$/,"")}/registry.json`,n=await Ve(r,t);return gr(n)}async function br(e,t){let r=e.endsWith("/plugins.json")?e:`${e.replace(/\/$/,"")}/plugins.json`,n=await Ve(r,t);return mr(n)}class hr{options;id;priority;manifestPromise;constructor(e){this.options=e;this.id=e.id??e.registryUrl,this.priority=e.priority}getManifest(){return this.manifestPromise??=Cr(this.options.registryUrl,this.options.headers),this.manifestPromise}async get(e){return(await this.getManifest()).items.find((r)=>r.name===e)}}class Rr{options;id;priority;manifestPromise;constructor(e){this.options=e;this.id=e.id??e.registryUrl,this.priority=e.priority}getManifest(){return this.manifestPromise??=br(this.options.registryUrl,this.options.headers),this.manifestPromise}async get(e){return(await this.getManifest()).plugins.find((r)=>r.pluginId===e)}}class xr{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((r,n)=>r.priority-n.priority);for(let r of t){let n=await r.get(e);if(n)return n}return}}class kr{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((r,n)=>r.priority-n.priority);for(let r of t){let n=await r.get(e);if(n)return n}return}}var Pr="uibot.artifacts.lock.json";function Sr(e){return E(e,"components","registry")}function Ir(e){return E(e,"templates","registry")}function Ar(e,t){if(e.kind==="component")return E(t.componentsDir??Sr(t.workspaceRoot));return E(t.templatesDir??Ir(t.workspaceRoot))}function vr(e){return E(e.workspaceRoot,e.lockfilePath??Pr)}function wr(e){try{return JSON.parse(lr(e,"utf8"))}catch{return{version:1,artifacts:[]}}}function Er(e,t){Le(ue(e),{recursive:!0}),Ne(e,`${JSON.stringify(t,null,2)}
15
- `,"utf8")}function Dr(e,t){return{version:1,artifacts:[...e.artifacts.filter((n)=>n.name!==t.name),t].sort((n,o)=>n.name.localeCompare(o.name))}}function Tr(e){if(e.kind==="component")return{components:{[e.name]:e.catalogEntry}};return{templates:{[e.name]:e.templateContract}}}class _ extends Error{artifactName;offendingPath;baseDir;constructor(e,t,r){super(`Artifact "${e}" file path escapes workspace: "${t}" resolves outside "${r}"`);this.artifactName=e;this.offendingPath=t;this.baseDir=r;this.name="ArtifactContainmentError"}}function Ue(e,t){let r=t.endsWith(_e)?t:t+_e;return e===t||e.startsWith(r)}function Be(e){let t=E(e),r=[];while(!0)try{return cr(t),E(dr(t),...r)}catch(n){if(n.code!=="ENOENT")throw n;let o=ue(t);if(o===t)throw n;r.unshift(ur(t)),t=o}}function je(e,t,r,n){try{let o=Be(t),a=Be(e);if(!Ue(a,o))throw new _(r,n,t)}catch(o){if(o instanceof _)throw o;throw new _(r,n,t)}}function $e(e,t,r){if(e.includes("\x00"))throw new _(r,e,t);if(pr(e))throw new _(r,e,t);let n=E(t,e);if(!Ue(n,t))throw new _(r,e,t);return je(n,t,r,e),n}function Or(e,t){let r=[];for(let n of e.files){let o=n.target??n.path;r.push($e(o,t,e.name))}return r}function gi(e,t){let r=E(t.workspaceRoot),n=Ar(e,t);je(n,r,e.name,n);let o=$e(e.name,n,e.name),a=Or(e,o),i=[];for(let y=0;y<e.files.length;y++){let u=e.files[y],s=a[y];Le(ue(s),{recursive:!0}),Ne(s,u.content??"","utf8"),i.push(s)}let l={name:e.name,version:e.version,source:t.source??"registry",installedAt:new Date().toISOString()},c=vr(t),d=wr(c),p=Dr(d,l);return Er(c,p),{artifactLock:l,catalogPatch:Tr(e),writtenFiles:i}}export{_ as ArtifactContainmentError,xr as ArtifactRegistryResolver,fr as MemoryArtifactRegistrySource,yr as MemoryPluginRegistrySource,kr as PluginRegistryResolver,Wo as RESOURCE_ADMISSION_ERROR_CODES,oe as RESOURCE_ADMISSION_SCHEMA_VERSION,Tt as RESOURCE_EXTERNAL_CHECKS,Xo as RESOURCE_INDEX_ERROR_CODES,Kt as RESOURCE_INDEX_SCHEMA_VERSION,Dt as RESOURCE_PREFLIGHT_CHECKS,rr as RESOURCE_QUERY_ALIAS_GROUPS,ai as RESOURCE_QUERY_ERROR_CODES,yt as RESOURCE_QUERY_OPERATION_MANIFEST,de as RESOURCE_QUERY_SCORE_WEIGHTS,hr as RemoteArtifactRegistrySource,Rr as RemotePluginRegistrySource,ke as ResourceAdmissionIndexMismatchError,Se as ResourceAdmissionReportNotDerivedError,Pe as ResourceAdmissionReportRejectedError,N as ResourceIndexError,O as ResourceQueryError,jo as SHADCN_REGISTRY_ITEM_SCHEMA,re as UIBOT_BASE_ITEM,Jo as applyResourceAdmissionReport,$e as assertPathContained,Go as assessResourceAdmissions,ei as buildExamplesFromL4Templates,ti as buildResourceIndex,Uo as buildShadcnRegistry,qr as buildUiBotRegistryManifest,St as catalogEntryToMeta,Lr as collectAllBlockSources,Xe as collectBlockSources,me as collectTemplateSources,st as collectTemplateSourcesFromDirs,ze as compareLockToManifest,ci as createResourceQueryService,qo as createUIBotRegistryHttpHandler,Ko as deriveResourceLicense,zr as emitArtifactJson,We as emptyLockfile,Yo as evaluateCatalogPreflight,se as expandResourceQueryAliases,Cr as fetchArtifactRegistryManifest,br as fetchPluginDistributionManifest,gi as installArtifactToWorkspace,Ke as lockfileWith,Et as normalizeRegistryBasePath,h as normalizeResourceAlias,M as normalizeResourceLicense,Vo as parseOklchCssVars,mr as parsePluginDistributionManifest,gr as parseRegistryManifest,we as resourceAdmissionIndexFingerprint,X as templateSourceToRegistryItem,ye as toArtifactRegistryItem,pt as toComponentArtifact,ne as toItemName,v as toResourceId,fe as toTemplateArtifact,he as transformBlockSource};
10
+ `}function At(e){let t={category:e.category,level:e.level};if(e.props)t.props=e.props;if(e.slots)t.slots=e.slots;if(e.events)t.events=e.events;if(e.usageScenarios)t.scenarios=e.usageScenarios;if(e.constraints)t.constraints=e.constraints;return t}function Ho(e){return{light:Re(e,":root"),dark:Re(e,".dark")}}function Re(e,t){let r={},n=new RegExp(`${ke(t)}\\s*\\{`,"g"),o;while((o=n.exec(e))!==null){let a=o.index+o[0].length,i=1,l=a;for(;l<e.length&&i>0;l++){let d=e[l];if(d==="{")i++;else if(d==="}")i--}let c=e.slice(a,l-1);for(let d of c.matchAll(/--([\w-]+)\s*:\s*([^;]+);/g)){let u=d[1],f=d[2];if(u!==void 0&&f!==void 0)r[u]=f.trim()}}return r}function ke(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Wo(e,t){let r=t.sharedDependencies??xt,n=t.channel??"public",o=Et(t),a=(t.componentsDir??kt).replace(/\/$/,""),i=(t.libDir??Pt).replace(/\/$/,""),l=`${i}/uibot-renderer.ts`,c=`${i}/utils.ts`,d=`${i}/uibot-contracts.ts`,u="@/lib/uibot-renderer",f="@/lib/utils",p="@/lib/uibot-contracts",s={},g={name:re,type:"registry:lib",description:"UIBot runtime base: RendererComponent type shim + cn util + OKLCH theme tokens. Pulled automatically by every UIBot block.",dependencies:r,files:[{path:l,content:t.rendererShimContent,type:"registry:lib"},{path:c,content:t.cnUtilContent,type:"registry:lib"},...t.contractsShimContent?[{path:d,content:t.contractsShimContent,type:"registry:lib"}]:[]],...t.cssVars?{cssVars:t.cssVars}:{},meta:{base:!0}};s[re]=g;let y=new Map,C=new Map,S=new Map,F=new Map;for(let m of e){let I=m.files[0]?.path??`${ne(m.name)}.tsx`,x=m.channel??"public",h=F.get(I);if(h&&h!==x)throw Error(`${I} mixes ${h} and ${x} blocks; split the file`);F.set(I,x)}for(let m of e){if((m.channel??"public")!==n)continue;let x=m.files[0]?.path??`${ne(m.name)}.tsx`,h=y.get(x);if(!h){let R=ne(Ot(x,m.name)),W=be(m,{rendererShimImport:"@/lib/uibot-renderer",cnUtilImport:"@/lib/utils",...t.contractsShimContent?{contractsShimImport:"@/lib/uibot-contracts"}:{}}),T=`${a}/${R}.tsx`,V={schema:te,item:R,channel:n,components:[]};S.set(R,V),h={name:R,type:"registry:ui",description:m.description??m.catalogEntry.description,dependencies:["react",...m.dependencies??[]],registryDependencies:[o(re)],files:m.files.length<=1?[{path:T,target:T,content:W,type:"registry:ui"}]:m.files.map((K)=>{if(typeof K.content!=="string")throw Error(`Missing block source content: ${K.path}`);let pe=`${a}/${K.path.replace(/^blocks\//,"")}`;return{path:pe,target:pe,content:be({...m,sourceCode:K.content},{rendererShimImport:"@/lib/uibot-renderer",cnUtilImport:"@/lib/utils",...t.contractsShimContent?{contractsShimImport:"@/lib/uibot-contracts"}:{}}),type:"registry:ui"}}),meta:{...At(m.catalogEntry),provides:[m.name],uibot:V}},y.set(x,h),s[R]=h}else{let R=h.meta;if(R.provides&&!R.provides.includes(m.name))R.provides.push(m.name)}let A=S.get(h.name);if(A?.components&&!C.has(m.name))A.components.push(Dt(m,h,a)),C.set(m.name,h.name)}for(let[m,I]of S){let x=s[m];if(!x)continue;I.components?.sort((A,R)=>A.name.localeCompare(R.name));let h=`${a}/${m}.uibot.json`;x.files.push({path:h,target:h,content:`${JSON.stringify(I,null,2)}
11
+ `,type:"registry:ui"})}let D={},Q=(t.templates??[]).filter((m)=>(m.channel??"public")===n),He=new Set(Q.map((m)=>m.name));for(let m of Q){if(s[m.name])throw Error(`template item "${m.name}" collides with a component item`);let I=m.templateContract.composedFrom??[],x=new Set,h=[];for(let T of I){let V=C.get(T);if(V)x.add(o(V));else if(He.has(T)&&T!==m.name)x.add(o(T));else h.push(T)}if(h.length>0)D[m.name]=h;let A=`${i}/${It}`,R=`${m.name}.uibot.yaml`,W={schema:te,item:m.name,channel:n,template:{file:R,contract:m.templateContract}};s[m.name]={name:m.name,type:"registry:block",description:m.description,registryDependencies:[...x].sort(),files:[{path:`${A}/${R}`,target:`${A}/${R}`,content:m.yaml,type:"registry:lib"},{path:`${A}/${m.name}.uibot.json`,target:`${A}/${m.name}.uibot.json`,content:`${JSON.stringify(W,null,2)}
12
+ `,type:"registry:lib"}],meta:{uibot:W}}}return vt(s,t.composites??[],{channel:n,ref:o,componentsDir:a}),{registry:{$schema:bt,name:t.registryName,...t.homepage?{homepage:t.homepage}:{},items:Object.values(s).map((m)=>({name:m.name,type:m.type,...m.description?{description:m.description}:{},...m.registryDependencies?{registryDependencies:m.registryDependencies}:{},...m.dependencies?{dependencies:m.dependencies}:{}}))},items:s,unresolvedTemplateTypes:D}}function vt(e,t,r){let n=new Map;for(let o of t){if(n.has(o.name)||e[o.name])throw Error(`composite item "${o.name}" collides with another item`);n.set(o.name,o)}for(let o of t){let a=o.channel??"public",i=xe(o),l=new Set(o.files.map((d)=>d.path));for(let d of o.requires??[]){let u=n.get(d);if(!u)throw Error(`composite "${o.name}" requires unknown "${d}"`);if((u.channel??"public")!==a)throw Error(`composite "${o.name}" (${a}) requires "${d}" from another channel`);if(xe(u)!==i)throw Error(`composite "${o.name}" requires "${d}" from another directory`);for(let f of u.files)l.add(f.path)}for(let d of o.files){if(!Pe.test(d.path))throw Error(`composite "${o.name}" file "${d.path}" must be a plain relative path`);for(let u of wt(d.content)){if(!u.startsWith("./")||u.includes("/../"))throw Error(`${o.name}/${d.path} imports ${u}; only ./ imports within the item directory are allowed`);let f=u.slice(2).replace(/\.js$/,"");if(![f,`${f}.ts`,`${f}.tsx`,`${f}/index.ts`,`${f}/index.tsx`].some((s)=>l.has(s)))throw Error(`${o.name}/${d.path} imports ${u}, which no required item ships`)}}if(a!==r.channel)continue;let c=o.files.map((d)=>{let u=`${r.componentsDir}/${i}/${d.path}`;return{path:u,target:u,content:d.content,type:d.path.endsWith(".tsx")?"registry:component":"registry:lib"}});e[o.name]={name:o.name,type:o.type,description:o.description,dependencies:["react",...o.dependencies??[]],registryDependencies:[...o.primitives??[],...(o.requires??[]).map(r.ref)],files:c,meta:{composite:!0,channel:a}}}}var Pe=/^[a-z0-9][a-z0-9._-]*(\/[a-z0-9][a-z0-9._-]*)*$/i;function xe(e){if(!Pe.test(e.dir)||e.dir.split("/").includes(".."))throw Error(`composite "${e.name}" dir "${e.dir}" must be a plain relative path`);return e.dir}function wt(e){let t=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1"),r=[],n=[/\bfrom\s*["'](\.{1,2}\/[^"']+)["']/g,/\bimport\s*["'](\.{1,2}\/[^"']+)["']/g,/\bimport\s*\(\s*["'](\.{1,2}\/[^"']+)["']\s*\)/g];for(let o of n)for(let a of t.matchAll(o))r.push(a[1]??"");return r}function Et(e){if(e.baseUrl){let r=e.baseUrl.replace(/\/$/,"");return(n)=>`${r}/r/${n}.json`}let t=e.namespace??St;if(!/^@[a-z0-9][a-z0-9-]*$/.test(t))throw Error(`registry namespace must look like "@uibot", got "${t}"`);return(r)=>`${t}/${r}`}function Dt(e,t,r){let n=e.name.replace(/\./g,""),o=`${r}/`,a=t.files.find((i)=>i.path.startsWith(o)&&/\.(tsx|ts)$/.test(i.path)&&Tt(i.content,n));if(!a)throw Error(`block "${e.name}" has no named export "${n}" in item "${t.name}"`);return{name:e.name,export:n,module:a.path.slice(o.length),catalog:e.catalogEntry}}function Tt(e,t){let r=ke(t),n=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*\/\/.*$/gm,"");if(new RegExp(`export\\s+(?:const|let|function|class)\\s+${r}\\b`).test(n))return!0;for(let o of n.matchAll(/export\s*\{([^}]*)\}/g)){let a=(o[1]??"").split(",").map((l)=>{let[,c]=l.trim().split(/\s+as\s+/);return(c??l.trim().replace(/^type\s+/,"")).trim()}),i=(o[1]??"").split(",").map((l)=>l.trim()).filter((l)=>l.startsWith("type ")).map((l)=>l.replace(/^type\s+/,"").split(/\s+as\s+/).pop()?.trim());if(a.includes(t)&&!i.includes(t))return!0}return!1}function Ot(e,t){return(e.split("/").pop()??t).replace(/\.(tsx|ts|jsx|js)$/,"")||t}var Ko=Rt;function Ft(e="/api/registry"){let t=(e||"/api/registry").trim(),r=t.startsWith("/")?t:`/${t}`;return r.length>1?r.replace(/\/$/,""):r}function U(e,t=200){return Response.json(e,{status:t})}function Yo(e){let t=Ft(e.basePath),r=`${t}/registry.json`,n=`${t}/artifacts/`,o=new Map(e.manifest.items.map((a)=>[a.name,a]));return async function(i){let l=new URL(i.url);if(i.method!=="GET")return U({error:"Method not allowed"},405);if(l.pathname===r)return U(e.manifest);if(l.pathname.startsWith(n)){let c=l.pathname.slice(n.length),d=decodeURIComponent(c.endsWith(".json")?c.slice(0,-5):c),u=o.get(d);if(!u)return U({error:`Artifact '${d}' not found`},404);return U(u)}return U({error:"Not found"},404)}}var oe="uibot.resource.admission.v1",Mt=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure"],_t=["packed-install","typecheck","browser"],Zo=["invalid-admission-manifest","invalid-admission-record","invalid-admission-check","duplicate-admission-record","unknown-admission-resource","missing-source-metadata","missing-license-metadata","dependency-closure-failed"];class Se extends Error{expected;actual;code="resource-admission-index-mismatch";constructor(e,t){super(`resource admission index mismatch: expected ${e}, received ${t}`);this.expected=e;this.actual=t;this.name="ResourceAdmissionIndexMismatchError"}}class Ie extends Error{issueCount;code="resource-admission-report-rejected";constructor(e){super(`resource admission report contains ${e.toString()} issue(s)`);this.issueCount=e;this.name="ResourceAdmissionReportRejectedError"}}class Ae extends Error{code="resource-admission-report-not-derived";constructor(){super("resource admission report must come directly from assessResourceAdmissions");this.name="ResourceAdmissionReportNotDerivedError"}}var Bt=new Set(ee),Lt=new Set(he),ve=new WeakSet,G={missing:0,declared:1,verified:2,"external-consumer":3};function Nt(e,t){return e<t?-1:e>t?1:0}function L(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function Y(e,t){let r=new Set(t);return Object.keys(e).every((n)=>r.has(n))}function we(e){return[...new Set(e.map((t)=>t.trim()).filter(Boolean))].sort(Nt)}function Vt(e,t,r,n){if(!L(r)||!Y(r,["status","evidence"])){n.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} must contain only status and evidence`});return}if(typeof r.status!=="string"||!Lt.has(r.status)||r.status==="missing"){n.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} status must be declared, verified or external-consumer`});return}if(!Array.isArray(r.evidence)||r.evidence.length===0||r.evidence.some((o)=>typeof o!=="string"||!o.trim())){n.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} evidence must be a non-empty string array`});return}return{status:r.status,evidence:we(r.evidence)}}function Ut(e){if(e===void 0)return;if(!L(e)||!Y(e,["source","version","license"]))return;if(Object.values(e).some((r)=>r!==void 0&&typeof r!=="string"))return;return{...typeof e.source==="string"&&e.source.trim()?{source:e.source.trim()}:{},...typeof e.version==="string"&&e.version.trim()?{version:e.version.trim()}:{},...typeof e.license==="string"&&e.license.trim()?{license:e.license.trim()}:{}}}function jt(e,t){let r=new Map,n=[];if(!L(t)||!Y(t,["schemaVersion","records"])||t.schemaVersion!==oe||!Array.isArray(t.records))return n.push({code:"invalid-admission-manifest",detail:`expected ${oe} with a records array`}),{records:r,issues:n};let o=new Set(e.resources.map((a)=>a.id));for(let a of t.records){if(!L(a)||!Y(a,["resourceId","provenance","checks"])||typeof a.resourceId!=="string"||!a.resourceId.trim()||!L(a.checks)){n.push({code:"invalid-admission-record",...L(a)&&typeof a.resourceId==="string"?{resourceId:a.resourceId}:{},detail:"record must contain only resourceId, optional provenance and checks"});continue}let i=a.resourceId.trim();if(r.has(i)){n.push({code:"duplicate-admission-record",resourceId:i,detail:i});continue}if(!o.has(i)){n.push({code:"unknown-admission-resource",resourceId:i,detail:i});continue}let l=Ut(a.provenance);if(a.provenance!==void 0&&!l){n.push({code:"invalid-admission-record",resourceId:i,detail:"provenance must contain only string source, version and license fields"});continue}let c={},d=!1;for(let[u,f]of Object.entries(a.checks)){if(!Bt.has(u)){n.push({code:"invalid-admission-check",resourceId:i,detail:`unknown receipt check: ${u}`}),d=!0;continue}let p=u,s=Vt(i,p,f,n);if(s)c[p]=s;else d=!0}if(d)continue;r.set(i,{resourceId:i,...l?{provenance:l}:{},checks:c})}return{records:r,issues:n}}function $t(e){let t=new Map(e.resources.map((o)=>[o.id,o])),r=new Map;function n(o,a,i,l){if(r.has(o)||l.has(a))return;if(i.has(a)){r.set(o,`dependency cycle reached ${a}`);return}let c=t.get(a);if(!c){r.set(o,`missing dependency ${a}`);return}i.add(a);for(let d of c.dependencies)if(n(o,d,i,l),r.has(o))break;i.delete(a),l.add(a)}for(let o of e.resources)n(o.id,o.id,new Set,new Set);return r}var qt=/^(unknown|unlicensed|none|n\/?a)$/i,zt=/^SPDX-License-Identifier:\s*(\S+)/im,Ht=/^(?:the\s+)?(mit|apache(?:\s+license(?:\s*,?\s*version\s*2\.0)?)?|bsd-2-clause|bsd-3-clause|isc|unlicense)\b/i;function M(e){let t=e?.trim();if(!t||qt.test(t))return;return t}function Wt(e){if(!e?.trim())return;let t=e.match(zt)?.[1];if(t)return M(t);let r=e.match(Ht)?.[1];if(!r)return;let n=r.toLowerCase();if(n.startsWith("mit"))return"MIT";if(n.startsWith("apache"))return"Apache-2.0";if(n.startsWith("bsd-2"))return"BSD-2-Clause";if(n.startsWith("bsd-3"))return"BSD-3-Clause";if(n==="isc")return"ISC";if(n==="unlicense")return"Unlicense";return}function Xo(e){return M(e.frontmatterLicense)??M(e.packageJsonLicense)??Wt(e.licenseFileText)}function Ee(e){return Boolean(M(e))}var j={states:/\b(disabled|loading|error|empty|pending|busy|children|active|muted|boolean-state)\b/i,accessibility:/\b(label|aria|accessible|alt|role)\b/i,"light-theme":/:root\b|\b(light(?:-theme)?|theme token|css variables?)\b/i,"dark-theme":/\b(dark(?:-theme)?)\b/i,responsive:/\b(size|responsive|breakpoint|sm|md|lg|xl|full)\b/i};function ie(e,t){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let n of e)ie(n,t);return}let r=e;for(let[n,o]of Object.entries(r)){if(t.push(n),n==="type"&&o==="boolean")t.push("boolean-state");ie(o,t)}}function Kt(e){let t=[];return ie(e.props,t),[e.name,e.description,...e.tags??[],...e.usageScenarios??[],...e.constraints??[],...t,...Object.keys(e.slots??{}),...Object.keys(e.events??{}),e.slots&&Object.keys(e.slots).length>0?"empty":""].join(`
13
+ `)}function ei(e,t={}){let r=[Kt(e),t.sourceText??"",t.stylesText??""].join(`
14
+ `);return{contract:Boolean(e.props&&Object.keys(e.props).length>0||e.events&&Object.keys(e.events).length>0||e.slots&&Object.keys(e.slots).length>0)?"verified":"declared",states:j.states.test(r)?"verified":"missing",accessibility:j.accessibility.test(r)?"verified":"missing","light-theme":j["light-theme"].test(r)?"verified":"missing","dark-theme":j["dark-theme"].test(r)?"verified":"missing",responsive:j.responsive.test(r)?"verified":"missing"}}function Gt(e){return{source:"declared",license:Ee(e.source.license)?"declared":"missing",contract:"declared",states:"missing",accessibility:"missing","light-theme":"missing","dark-theme":"missing",responsive:"missing","dependency-closure":"missing","packed-install":"missing",typecheck:"missing",browser:"missing"}}function Yt(e){if(!Mt.every((n)=>G[e[n]]>=G.verified))return"experimental";return _t.every((n)=>e[n]==="external-consumer")?"recommended":"candidate"}function De(e){let t=JSON.stringify({schemaVersion:e.schemaVersion,resources:e.resources.map((o)=>({id:o.id,kind:o.kind,title:o.title,description:o.description,...o.category?{category:o.category}:{},tags:o.tags,aliases:o.aliases,capabilities:o.capabilities,dependencies:o.dependencies,source:o.source})),aliases:e.aliases}),r=0xcbf29ce484222325n,n=0x100000001b3n;for(let o of new TextEncoder().encode(t))r^=BigInt(o),r=BigInt.asUintN(64,r*n);return`fnv1a64:${r.toString(16).padStart(16,"0")}`}function Jt(e,t,r){let n=Gt(e),o=[`resource://${e.source.type}/${e.source.id}`,`resource://contract/${e.id}`],a=[];if(r)a.push({code:"dependency-closure-failed",resourceId:e.id,check:"dependency-closure",detail:r});else n["dependency-closure"]="verified",o.push(`resource://index/${e.id}`);if(t)for(let c of ee){if(c==="dependency-closure")continue;let d=t.checks[c];if(!d)continue;if(c==="source"&&G[d.status]>=G.verified&&(!t.provenance?.source||!t.provenance.version)){a.push({code:"missing-source-metadata",resourceId:e.id,check:c,detail:"verified source requires provenance.source and provenance.version"});continue}if(c==="license"&&!Ee(t.provenance?.license)){a.push({code:"missing-license-metadata",resourceId:e.id,check:c,detail:"license evidence requires a concrete provenance.license"});continue}if(n[c]=d.status,o.push(...d.evidence),c==="source"&&t.provenance?.source)o.push(t.provenance.source)}let i=Yt(n),l={level:i==="recommended"?"external-consumer":i==="candidate"?"verified":"declared",maturity:i,checks:n,evidence:we(o)};return Object.freeze(l.checks),Object.freeze(l.evidence),Object.freeze(l),Object.freeze(a),Object.freeze({resourceId:e.id,receipt:l,issues:a})}function ti(e,t){let r=jt(e,t),n=$t(e),o=e.resources.map((c)=>Jt(c,r.records.get(c.id),n.get(c.id))),a=[...r.issues,...o.flatMap((c)=>c.issues)],i=Object.fromEntries(Ce.map((c)=>[c,0]));for(let c of o)i[c.receipt.maturity]+=1;Object.freeze(o),Object.freeze(i);for(let c of a)Object.freeze(c);Object.freeze(a);let l=Object.freeze({schemaVersion:oe,indexFingerprint:De(e),resources:o,counts:i,issues:a});return ve.add(l),l}function ri(e,t){if(!ve.has(t))throw new Ae;if(t.issues.length>0)throw new Ie(t.issues.length);let r=De(e);if(r!==t.indexFingerprint)throw new Se(t.indexFingerprint,r);let n=new Map(t.resources.map((a)=>[a.resourceId,a.receipt])),o=e.resources.map((a)=>{let i=n.get(a.id);if(!i)return a;return Object.freeze({...a,receipt:i})});return Object.freeze(o),Object.freeze({schemaVersion:e.schemaVersion,resources:o,aliases:e.aliases})}var Qt="uibot.resource.index.v1",ii=["invalid-resource-source-id","duplicate-resource-id","dangling-resource-dependency","ambiguous-resource-dependency"];class N extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceIndexError"}}function k(e,t){return e<t?-1:e>t?1:0}function b(e){return e.normalize("NFKC").replace(/([\p{Lu}]+)([\p{Lu}][\p{Ll}])/gu,"$1 $2").replace(/([\p{Ll}\p{N}])([\p{Lu}])/gu,"$1 $2").toLowerCase().replace(/[^\p{L}\p{N}]+/gu," ").trim().replace(/\s+/g," ")}function Zt(e){let t=b(e).replace(/ /g,"-");if(!t)throw new N("invalid-resource-source-id",e);return t}function v(e,t){return`${e}:${Zt(t)}`}function J(e){let t=new Map;for(let r of e){let n=r?.trim();if(!n)continue;let o=b(n);if(!o||t.has(o))continue;t.set(o,n)}return[...t.entries()].sort(([r],[n])=>k(r,n)).map(([,r])=>r)}function q(e){return{level:"declared",maturity:"experimental",checks:{source:"declared",license:e?"declared":"missing",contract:"declared",states:"missing",accessibility:"missing","light-theme":"missing","dark-theme":"missing",responsive:"missing","dependency-closure":"missing","packed-install":"missing",typecheck:"missing",browser:"missing"},evidence:[]}}function Xt(e){let t=M(e.license);return{type:e.type,id:e.id,...e.version?{version:e.version}:{},...e.url?{url:e.url}:{},...t?{license:t}:{}}}function z(e){return{id:e.id,kind:e.kind,title:e.title,description:e.description,...e.category?{category:e.category}:{},tags:J(e.tags),aliases:J(e.aliases),capabilities:J(e.capabilities),dependencies:[...new Set(e.dependencies)].sort(k),source:Xt(e.source),receipt:e.receipt}}function er(e){return(e.body.split(/\r?\n/).map((r)=>r.replace(/^#+\s*/,"").trim()).find(Boolean)??e.title).slice(0,240)}function tr(e){return Object.freeze(e.tags),Object.freeze(e.aliases),Object.freeze(e.capabilities),Object.freeze(e.dependencies),Object.freeze(e.source),Object.freeze(e.receipt.checks),Object.freeze(e.receipt.evidence),Object.freeze(e.receipt),Object.freeze(e)}function rr(e){let t=new Map;for(let r of Object.keys(e).sort(k)){let n=e[r];if(!n)continue;let o=v("component",r);for(let a of J([r,n.name])){let i=b(a),l=t.get(i)??[];if(!l.includes(o))l.push(o);t.set(i,l.sort(k))}}return t}function nr(e,t,r){let n=r.get(b(e))??[];if(n.length===0)throw new N("dangling-resource-dependency",`${t} -> ${v("component",e)}`);if(n.length>1)throw new N("ambiguous-resource-dependency",`${t} -> ${e}: ${n.join(",")}`);return n[0]}function or(e,t,r,n){let o=e.startsWith("template:")?e.slice(9):e;if(Object.hasOwn(n,o))return v("template",o);return nr(e,t,r)}function H(e,t,r){return M(r?.[e]??t)}function si(e){return Object.entries(e).filter(([,t])=>t.level==="L4").sort(([t],[r])=>k(t,r)).map(([t,r])=>({id:`${t}-example`,title:`${r.name} Example`,description:r.description,category:r.category,tags:r.keywords,aliases:[`${t} example`,`${r.name} example`],capabilities:["example:template"],dependencies:[v("template",t)]}))}function ai(e){let t=e.components??{},r=e.templates??{},n=e.designGuides??[],o=e.examples??[],a=e.skills??[],i=e.licenses,l=rr(t),c=[];for(let s of Object.keys(t).sort(k)){let g=t[s];if(!g)continue;let y=v("component",s),C=H(y,void 0,i);c.push(z({id:y,kind:"component",title:g.name,description:g.description,category:g.category,tags:g.tags??[],aliases:[s,g.name],capabilities:["catalog:component"],dependencies:[],source:{type:"catalog",id:s,...C?{license:C}:{}},receipt:q(Boolean(C))}))}for(let s of Object.keys(r).sort(k)){let g=r[s];if(!g)continue;let y=v("template",s),C=H(y,void 0,i);c.push(z({id:y,kind:"template",title:g.name,description:g.description,category:g.category,tags:g.keywords,aliases:[s,g.name],capabilities:[],dependencies:(g.composedFrom??[]).map((S)=>or(S,y,l,r)),source:{type:"template-contract",id:s,...C?{license:C}:{}},receipt:q(Boolean(C))}))}for(let s of[...n].sort((g,y)=>k(g.id,y.id))){let g=v("design-guide",s.id),y=H(g,void 0,i);c.push(z({id:g,kind:"design-guide",title:s.title,description:er(s),category:s.category,tags:s.tags,aliases:[s.id,s.title],capabilities:["designMd:source"],dependencies:[],source:{type:"design-md",id:s.id,...s.sourceUrl?{url:s.sourceUrl}:{},...y?{license:y}:{}},receipt:q(Boolean(y))}))}for(let s of[...o].sort((g,y)=>k(g.id,y.id))){let g=v("example",s.id),y=H(g,s.license,i);c.push(z({id:g,kind:"example",title:s.title,description:s.description,...s.category?{category:s.category}:{},tags:s.tags??[],aliases:[s.id,s.title,...s.aliases??[]],capabilities:s.capabilities??[],dependencies:s.dependencies??[],source:{type:"example",id:s.id,...s.version?{version:s.version}:{},...s.sourceUrl?{url:s.sourceUrl}:{},...y?{license:y}:{}},receipt:q(Boolean(y))}))}for(let s of[...a].sort((g,y)=>k(g.id,y.id))){let g=v("skill",s.id),y=H(g,void 0,i);c.push(z({id:g,kind:"skill",title:s.title,description:s.description?.trim()||s.title,tags:[...s.tags??[],...s.triggers??[]],aliases:[s.id,s.title,...s.triggers??[]],capabilities:["skill:definition"],dependencies:[],source:{type:"skill",id:s.id,...s.version?{version:s.version}:{},...y?{license:y}:{}},receipt:q(Boolean(y))}))}c.sort((s,g)=>k(s.id,g.id));let d=new Set;for(let s of c){if(d.has(s.id))throw new N("duplicate-resource-id",s.id);d.add(s.id)}for(let s of c)for(let g of s.dependencies)if(!d.has(g))throw new N("dangling-resource-dependency",`${s.id} -> ${g}`);let u=new Map;for(let s of c)for(let g of s.aliases){let y=b(g);if(!y)continue;let C=u.get(y)??new Set;C.add(s.id),u.set(y,C)}let f=Object.freeze(Object.fromEntries([...u.entries()].sort(([s],[g])=>k(s,g)).map(([s,g])=>[s,Object.freeze([...g].sort(k))]))),p=Object.freeze(c.map(tr));return Object.freeze({schemaVersion:Qt,resources:p,aliases:f})}var ir=[["data table","data grid","datatable","table","\u8868\u683C","\u6570\u636E\u8868","\u6570\u636E\u8868\u683C"],["button","action button","\u6309\u94AE","\u64CD\u4F5C\u6309\u94AE"],["dashboard","admin dashboard","\u4EEA\u8868\u76D8","\u540E\u53F0","\u7BA1\u7406\u540E\u53F0"],["kanban","kanban board","\u770B\u677F","\u4EFB\u52A1\u770B\u677F"],["form","input form","\u8868\u5355","\u8F93\u5165\u8868\u5355"],["navigation","nav","sidebar","\u5BFC\u822A","\u4FA7\u8FB9\u680F"]],sr=Object.freeze(ir.map((e)=>Object.freeze([...e]))),Te=new Map;for(let e of sr){let t=Object.freeze([...new Set(e.map(b).filter(Boolean))].sort());for(let r of t)Te.set(r,t)}function se(e){let t=b(e);return Te.get(t)??Object.freeze([t])}var gi=["resource-query-empty","resource-query-invalid-limit","resource-not-found","resource-alias-ambiguous"];class O extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceQueryError"}}var de=Object.freeze({"exact-id":1000,"exact-title":900,alias:800,tag:600,capability:500,category:400,token:200,fuzzy:100}),ar=Object.freeze(Object.keys(de)),Oe=new Map(ar.map((e,t)=>[e,t])),Fe=new Map([["component",0],["template",1],["design-guide",2],["example",3],["skill",4]]);function P(e,t){return e<t?-1:e>t?1:0}function Me(e){return new Set((e??[]).map(b).filter(Boolean))}function ae(e,t){let r=Me(t);if(r.size===0)return!0;let n=Me(e);return[...r].some((o)=>n.has(o))}function cr(e,t){if(t.kinds?.length&&!t.kinds.includes(e.kind))return!1;if(!ae(e.tags,t.tags))return!1;if(!ae(e.category?[e.category]:[],t.categories))return!1;if(!ae(e.capabilities,t.capabilities))return!1;if(t.maturities?.length&&!t.maturities.includes(e.receipt.maturity))return!1;return!0}function lr(e){return Boolean(e.kinds?.length||e.tags?.length||e.categories?.length||e.capabilities?.length||e.maturities?.length)}function w(e,t,r,n=de[t]){if(e.some((o)=>o.code===t&&o.value===r))return;e.push({code:t,value:r,score:n})}function ce(e,t){return e.find((r)=>b(r)===t)}function le(e){return[e.id,e.title,...e.aliases,...e.tags,...e.category?[e.category]:[],...e.capabilities]}function dr(e,t,r){if(Math.abs(e.length-t.length)>r)return r+1;let n=Array.from({length:t.length+1},(o,a)=>a);for(let o=1;o<=e.length;o+=1){let a=[o],i=o;for(let l=1;l<=t.length;l+=1){let c=(n[l-1]??r+1)+(e[o-1]===t[l-1]?0:1),d=Math.min((n[l]??r+1)+1,(a[l-1]??r+1)+1,c);a.push(d),i=Math.min(i,d)}if(i>r)return r+1;n=a}return n[t.length]??r+1}function ur(e,t){let r=b(t),n=[];if(b(e.id)===r)w(n,"exact-id",e.id);if(b(e.title)===r)w(n,"exact-title",e.title);let o=ce(e.aliases,r);if(o)w(n,"alias",o);let a=ce(e.tags,r);if(a)w(n,"tag",a);let i=ce(e.capabilities,r);if(i)w(n,"capability",i);if(e.category&&b(e.category)===r)w(n,"category",e.category);if(!o){let d=se(r).filter((f)=>f!==r),u=new Set(le(e).map(b));if(d.some((f)=>u.has(f)))w(n,"alias",t.trim())}let l=r.split(" ").filter(Boolean),c=b(le(e).join(" "));if(l.length>0&&l.every((d)=>c.includes(d)))w(n,"token",t.trim());if(n.length===0&&r.length>=4){let d;for(let u of le(e)){let f=b(u);if(f.length<4)continue;let p=dr(r,f,2);if(p<=2&&(!d||p<d.distance||p===d.distance&&P(u,d.value)<0))d={value:u,distance:p}}if(d)w(n,"fuzzy",d.value,de.fuzzy-d.distance)}return n.sort((d,u)=>{if(d.score!==u.score)return u.score-d.score;return(Oe.get(d.code)??99)-(Oe.get(u.code)??99)||P(d.value,u.value)})}function _e(e,t,r){if(t.has(r))return[r];let n=b(r),o=e.aliases[n];if(o?.length)return[...o];let a=new Set;for(let i of se(n))for(let l of e.aliases[i]??[])a.add(l);return[...a].sort(P)}function Be(e,t){return new O("resource-alias-ambiguous",`${e.trim()}: ${t.join(",")}`)}function mi(e){let t=new Map(e.resources.map((n)=>[n.id,n]));function r(n){let o=n.trim(),a=_e(e,t,o);if(a.length===0)throw new O("resource-not-found",o);if(a.length>1)throw Be(o,a);let i=a[0],l=i?t.get(i):void 0;if(!l)throw new O("resource-not-found",o);return l}return Object.freeze({manifest:()=>e,search(n){let o=n.text?.trim()??"";if(!o&&!lr(n))throw new O("resource-query-empty","text or filter is required");if(n.limit!==void 0&&(!Number.isInteger(n.limit)||n.limit<=0))throw new O("resource-query-invalid-limit",String(n.limit));let a=e.resources.filter((i)=>cr(i,n)).map((i)=>{let l=o?ur(i,o):[];return{resource:i,score:l.reduce((c,d)=>c+d.score,0),reasons:l}}).filter((i)=>!o||i.reasons.length>0).sort((i,l)=>l.score-i.score||P(i.resource.id,l.resource.id));return n.limit===void 0?a:a.slice(0,n.limit)},get:r,build(n){if(n.length===0||n.every((p)=>!p.trim()))throw new O("resource-query-empty","at least one build root is required");let o=[],a=new Set;for(let p of n){let s=p.trim(),g=_e(e,t,s);if(g.length===0)o.push({id:s,reason:"missing-resource"});else if(g.length>1)throw Be(s,g);else{let y=g[0];if(y)a.add(y)}}let i=new Set,l=new Set,c=new Set,d=[],u=[],f=(p,s)=>{if(i.has(p))return;if(l.has(p)){o.push({id:p,...s?{requiredBy:s}:{},reason:"dependency-cycle"});return}let g=t.get(p);if(!g){o.push({id:p,...s?{requiredBy:s}:{},reason:"missing-resource"});return}l.add(p),c.add(p);let y=[...g.dependencies].sort((C,S)=>{let F=t.get(C),D=t.get(S);return(Fe.get(F?.kind??"")??99)-(Fe.get(D?.kind??"")??99)||P(C,S)});for(let C of y)u.push({from:p,to:C,relation:"depends-on"}),f(C,p);l.delete(p),i.add(p),d.push(p)};for(let p of[...a].sort(P))f(p);return{roots:[...a].sort(P),nodes:[...c].sort(P).map((p)=>{let s=t.get(p);if(!s)throw new O("resource-not-found",p);return{id:p,kind:s.kind,maturity:s.receipt.maturity}}),edges:u.sort((p,s)=>P(p.from,s.from)||P(p.to,s.to)),order:d,gaps:o.sort((p,s)=>P(p.id,s.id)||P(p.requiredBy??"",s.requiredBy??"")||P(p.reason,s.reason))}}})}function Cr(e){if(!e.name)throw Error("Artifact registry manifest requires a name");return e}function hr(e){if(!e.name)throw Error("Plugin distribution manifest requires a name");return e}class br{id;priority;items;constructor(e,t,r){this.id=e;this.priority=t;this.items=r}get(e){return this.items[e]}}class Rr{id;priority;items;constructor(e,t,r){this.id=e;this.priority=t;this.items=r}get(e){return this.items[e]}}async function je(e,t){let r=await fetch(e,t?{headers:t}:{});if(!r.ok)throw Error(`Failed to fetch ${e}: ${r.status} ${r.statusText}`);return await r.json()}async function xr(e,t){let r=e.endsWith("/registry.json")?e:`${e.replace(/\/$/,"")}/registry.json`,n=await je(r,t);return Cr(n)}async function kr(e,t){let r=e.endsWith("/plugins.json")?e:`${e.replace(/\/$/,"")}/plugins.json`,n=await je(r,t);return hr(n)}class Pr{options;id;priority;manifestPromise;constructor(e){this.options=e;this.id=e.id??e.registryUrl,this.priority=e.priority}getManifest(){return this.manifestPromise??=xr(this.options.registryUrl,this.options.headers),this.manifestPromise}async get(e){return(await this.getManifest()).items.find((r)=>r.name===e)}}class Sr{options;id;priority;manifestPromise;constructor(e){this.options=e;this.id=e.id??e.registryUrl,this.priority=e.priority}getManifest(){return this.manifestPromise??=kr(this.options.registryUrl,this.options.headers),this.manifestPromise}async get(e){return(await this.getManifest()).plugins.find((r)=>r.pluginId===e)}}class Ir{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((r,n)=>r.priority-n.priority);for(let r of t){let n=await r.get(e);if(n)return n}return}}class Ar{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((r,n)=>r.priority-n.priority);for(let r of t){let n=await r.get(e);if(n)return n}return}}var vr="uibot.artifacts.lock.json";function wr(e){return E(e,"components","registry")}function Er(e){return E(e,"templates","registry")}function Dr(e,t){if(e.kind==="component")return E(t.componentsDir??wr(t.workspaceRoot));return E(t.templatesDir??Er(t.workspaceRoot))}function Tr(e){return E(e.workspaceRoot,e.lockfilePath??vr)}function Or(e){try{return JSON.parse(gr(e,"utf8"))}catch{return{version:1,artifacts:[]}}}function Fr(e,t){Ve(ue(e),{recursive:!0}),Ue(e,`${JSON.stringify(t,null,2)}
15
+ `,"utf8")}function Mr(e,t){return{version:1,artifacts:[...e.artifacts.filter((n)=>n.name!==t.name),t].sort((n,o)=>n.name.localeCompare(o.name))}}function _r(e){if(e.kind==="component")return{components:{[e.name]:e.catalogEntry}};return{templates:{[e.name]:e.templateContract}}}class _ extends Error{artifactName;offendingPath;baseDir;constructor(e,t,r){super(`Artifact "${e}" file path escapes workspace: "${t}" resolves outside "${r}"`);this.artifactName=e;this.offendingPath=t;this.baseDir=r;this.name="ArtifactContainmentError"}}function $e(e,t){let r=t.endsWith(Le)?t:t+Le;return e===t||e.startsWith(r)}function Ne(e){let t=E(e),r=[];while(!0)try{return pr(t),E(mr(t),...r)}catch(n){if(n.code!=="ENOENT")throw n;let o=ue(t);if(o===t)throw n;r.unshift(fr(t)),t=o}}function qe(e,t,r,n){try{let o=Ne(t),a=Ne(e);if(!$e(a,o))throw new _(r,n,t)}catch(o){if(o instanceof _)throw o;throw new _(r,n,t)}}function ze(e,t,r){if(e.includes("\x00"))throw new _(r,e,t);if(yr(e))throw new _(r,e,t);let n=E(t,e);if(!$e(n,t))throw new _(r,e,t);return qe(n,t,r,e),n}function Br(e,t){let r=[];for(let n of e.files){let o=n.target??n.path;r.push(ze(o,t,e.name))}return r}function bi(e,t){let r=E(t.workspaceRoot),n=Dr(e,t);qe(n,r,e.name,n);let o=ze(e.name,n,e.name),a=Br(e,o),i=[];for(let f=0;f<e.files.length;f++){let p=e.files[f],s=a[f];Ve(ue(s),{recursive:!0}),Ue(s,p.content??"","utf8"),i.push(s)}let l={name:e.name,version:e.version,source:t.source??"registry",installedAt:new Date().toISOString()},c=Tr(t),d=Or(c),u=Mr(d,l);return Fr(c,u),{artifactLock:l,catalogPatch:_r(e),writtenFiles:i}}export{_ as ArtifactContainmentError,Ir as ArtifactRegistryResolver,br as MemoryArtifactRegistrySource,Rr as MemoryPluginRegistrySource,Ar as PluginRegistryResolver,Zo as RESOURCE_ADMISSION_ERROR_CODES,oe as RESOURCE_ADMISSION_SCHEMA_VERSION,_t as RESOURCE_EXTERNAL_CHECKS,ii as RESOURCE_INDEX_ERROR_CODES,Qt as RESOURCE_INDEX_SCHEMA_VERSION,Mt as RESOURCE_PREFLIGHT_CHECKS,sr as RESOURCE_QUERY_ALIAS_GROUPS,gi as RESOURCE_QUERY_ERROR_CODES,ht as RESOURCE_QUERY_OPERATION_MANIFEST,de as RESOURCE_QUERY_SCORE_WEIGHTS,Pr as RemoteArtifactRegistrySource,Sr as RemotePluginRegistrySource,Se as ResourceAdmissionIndexMismatchError,Ae as ResourceAdmissionReportNotDerivedError,Ie as ResourceAdmissionReportRejectedError,N as ResourceIndexError,O as ResourceQueryError,Ko as SHADCN_REGISTRY_ITEM_SCHEMA,re as UIBOT_BASE_ITEM,ri as applyResourceAdmissionReport,ze as assertPathContained,ti as assessResourceAdmissions,si as buildExamplesFromL4Templates,ai as buildResourceIndex,Wo as buildShadcnRegistry,Kr as buildUiBotRegistryManifest,At as catalogEntryToMeta,jr as collectAllBlockSources,tt as collectBlockSources,me as collectTemplateSources,ct as collectTemplateSourcesFromDirs,We as compareLockToManifest,mi as createResourceQueryService,Yo as createUIBotRegistryHttpHandler,Xo as deriveResourceLicense,Gr as emitArtifactJson,Ge as emptyLockfile,ei as evaluateCatalogPreflight,se as expandResourceQueryAliases,xr as fetchArtifactRegistryManifest,kr as fetchPluginDistributionManifest,bi as installArtifactToWorkspace,Ye as lockfileWith,Ft as normalizeRegistryBasePath,b as normalizeResourceAlias,M as normalizeResourceLicense,Ho as parseOklchCssVars,hr as parsePluginDistributionManifest,Cr as parseRegistryManifest,De as resourceAdmissionIndexFingerprint,X as templateSourceToRegistryItem,ye as toArtifactRegistryItem,mt as toComponentArtifact,ne as toItemName,v as toResourceId,fe as toTemplateArtifact,be as transformBlockSource};
package/dist/shadcn.d.ts CHANGED
@@ -47,7 +47,7 @@ export interface ShadcnRegistryFile {
47
47
  /** Verbatim source written to `path`. */
48
48
  content: string;
49
49
  /** shadcn file type. */
50
- type: "registry:ui" | "registry:lib";
50
+ type: "registry:ui" | "registry:lib" | "registry:component";
51
51
  /** Optional explicit install target (defaults to `path`). */
52
52
  target?: string;
53
53
  }
@@ -90,6 +90,32 @@ export interface ShadcnRegistry {
90
90
  homepage?: string;
91
91
  items: ShadcnRegistryItemSummary[];
92
92
  }
93
+ /**
94
+ * A composite block shipped as host-owned source (ADR 0012 §2): UI over a headless hook from a
95
+ * published package, with transport and locale injected by the host. Its files install together
96
+ * under `<componentsDir>/<dir>/`, so relative imports between them and the items it `requires`
97
+ * keep working.
98
+ */
99
+ export interface CompositeBlockSource {
100
+ name: string;
101
+ /** `registry:block` for a block; `registry:lib` for source shared by several blocks. */
102
+ type: "registry:block" | "registry:lib";
103
+ description: string;
104
+ channel?: UIBotRegistryChannel;
105
+ /** Install directory below the components dir, e.g. `creation`. */
106
+ dir: string;
107
+ /** File names (relative to `dir`) and their source. */
108
+ files: Array<{
109
+ path: string;
110
+ content: string;
111
+ }>;
112
+ /** npm dependencies, e.g. `@uibot/creation-kit@^0.3.0`. */
113
+ dependencies?: string[];
114
+ /** shadcn primitives the source imports from the host's `ui` alias (`button`, `label`, …). */
115
+ primitives?: string[];
116
+ /** Other composite items of this registry whose files it imports. */
117
+ requires?: string[];
118
+ }
93
119
  /** Options for {@link buildShadcnRegistry}. */
94
120
  export interface BuildShadcnRegistryOptions {
95
121
  /** Registry name, e.g. `"uibot"`. */
@@ -130,6 +156,8 @@ export interface BuildShadcnRegistryOptions {
130
156
  channel?: UIBotRegistryChannel;
131
157
  /** Spec templates to emit as `registry:block` items (see {@link buildShadcnRegistry}). */
132
158
  templates?: TemplateSource[];
159
+ /** Composite blocks (and their shared libs) emitted as host-owned source. */
160
+ composites?: CompositeBlockSource[];
133
161
  }
134
162
  export interface BuildShadcnRegistryResult {
135
163
  /** The top-level `registry.json`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uibot/registry",
3
- "version": "0.2.1",
3
+ "version": "0.5.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,7 +27,7 @@
27
27
  "access": "public"
28
28
  },
29
29
  "dependencies": {
30
- "@uibot/contracts": "^0.2.1"
30
+ "@uibot/contracts": "^0.5.0"
31
31
  },
32
32
  "scripts": {
33
33
  "build": "rm -rf dist tsconfig.tsbuildinfo && bun build --minify ./src/index.ts --outdir ./dist --format esm --target bun && bun x tsc -b",