@uibot/registry 0.19.0 → 0.22.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/component-replacement.d.ts +10 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2117 -12
- package/dist/materialize-templates.d.ts +28 -0
- package/dist/materialize.d.ts +63 -0
- package/dist/resources.d.ts +5 -0
- package/dist/resources.js +2108 -3
- package/dist/shadcn/r/admin-apps.json +1 -1
- package/dist/shadcn/r/admin-chats.json +1 -1
- package/dist/shadcn/r/admin-settings-account.json +1 -1
- package/dist/shadcn/r/admin-settings-appearance.json +1 -1
- package/dist/shadcn/r/admin-settings-display.json +1 -1
- package/dist/shadcn/r/admin-settings-notifications.json +1 -1
- package/dist/shadcn/r/admin-settings-profile.json +1 -1
- package/dist/shadcn/r/admin-settings.json +1 -1
- package/dist/shadcn/r/admin-shell.json +16 -3
- package/dist/shadcn/r/admin-tasks.json +1 -1
- package/dist/shadcn/r/admin-users.json +1 -1
- package/dist/shadcn/r/agent-run-console.json +64 -0
- package/dist/shadcn/r/auth-minimal.json +59 -0
- package/dist/shadcn/r/billing-overview.json +66 -0
- package/dist/shadcn/r/billing-usage-ledger.json +66 -0
- package/dist/shadcn/r/charts.json +44 -17
- package/dist/shadcn/r/chat-workspace.json +1 -1
- package/dist/shadcn/r/collection-cell-editor.json +1 -1
- package/dist/shadcn/r/collection-kanban.json +134 -0
- package/dist/shadcn/r/collection-panel-drawer.json +1 -1
- package/dist/shadcn/r/collection-record-menu.json +1 -1
- package/dist/shadcn/r/collection-shared.json +1 -1
- package/dist/shadcn/r/commerce-workspace.json +1 -1
- package/dist/shadcn/r/console-billing.json +1 -1
- package/dist/shadcn/r/console-page.json +14 -14
- package/dist/shadcn/r/console-shell.json +2 -2
- package/dist/shadcn/r/creation-html-generation.json +2 -2
- package/dist/shadcn/r/creation-reference-generation.json +2 -2
- package/dist/shadcn/r/creation-revision-export.json +2 -2
- package/dist/shadcn/r/creation-shared.json +2 -2
- package/dist/shadcn/r/creation-variant-compare.json +3 -3
- package/dist/shadcn/r/creation-workspace.json +3 -3
- package/dist/shadcn/r/crm-workspace.json +1 -1
- package/dist/shadcn/r/dashboard-01.json +78 -0
- package/dist/shadcn/r/dashboard.json +113 -3
- package/dist/shadcn/r/data-crud-gallery.json +66 -0
- package/dist/shadcn/r/data-crud-kanban.json +66 -0
- package/dist/shadcn/r/data-crud-master-detail.json +66 -0
- package/dist/shadcn/r/data-crud-table.json +66 -0
- package/dist/shadcn/r/data-table.json +120 -10
- package/dist/shadcn/r/data.json +9 -2
- package/dist/shadcn/r/document-assistant.json +1 -1
- package/dist/shadcn/r/document-workspace.json +1 -1
- package/dist/shadcn/r/drilldown-menu.json +1 -1
- package/dist/shadcn/r/education-workspace.json +1 -1
- package/dist/shadcn/r/feedback.json +15 -2
- package/dist/shadcn/r/form.json +1 -1
- package/dist/shadcn/r/launch-site.json +72 -0
- package/dist/shadcn/r/layout.json +57 -22
- package/dist/shadcn/r/nav.json +38 -10
- package/dist/shadcn/r/onboarding-checklist.json +63 -0
- package/dist/shadcn/r/onboarding-wizard.json +66 -0
- package/dist/shadcn/r/prompt-eval-workbench.json +65 -0
- package/dist/shadcn/r/record-master-detail.json +132 -0
- package/dist/shadcn/r/shadcn-admin.json +1 -1
- package/dist/shadcn/r/sidebar-primitives.json +1 -1
- package/dist/shadcn/r/workspace.json +9 -2
- package/dist/shadcn/registry.json +229 -27
- package/dist/solution-regions.d.ts +12 -2
- package/dist/spec-blueprint.d.ts +11 -0
- package/dist/spec-patch.d.ts +10 -0
- package/dist/variant-swap.d.ts +22 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,15 +1,2120 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{lstatSync as zr,mkdirSync as at,readFileSync as qr,realpathSync as Hr,writeFileSync as ct}from"fs";import{basename as Kr,dirname as Ie,isAbsolute as Wr,resolve as O,sep as ot}from"path";function mt(e){let t=e.lockfilePath??"uibot.artifacts.lock.json",r=e.manifest.items??[],i=new Map;for(let o of r)i.set(o.name,o);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 n=[],a=new Set;for(let o of e.lockfile.artifacts??[]){a.add(o.name);let s=i.get(o.name);if(!s){n.push({name:o.name,kind:"missing-in-manifest",lockVersion:o.version,detail:`locked ${o.name}@${o.version} not present in registry manifest`});continue}let c=ft(s);if(c&&c!==o.version)n.push({name:o.name,kind:"version-mismatch",lockVersion:o.version,manifestVersion:c,detail:`${o.name}: lock ${o.version} \u2260 registry ${c}`})}return{ok:n.length===0,lockfilePath:t,registryName:e.manifest.name,lockCount:(e.lockfile.artifacts??[]).length,manifestCount:r.length,drifts:n}}function ft(e){return e.artifact?.version??e.version}function yt(){return{version:1,artifacts:[]}}function ht(e){return{version:1,artifacts:e}}import{readFileSync as bt,realpathSync as we}from"fs";import{resolve as z,relative as Ct,dirname as Rt,extname as xt,sep as pe}from"path";function kt(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 St(e){let t=e.readFile??((c)=>bt(c,"utf8")),r=new Map,i=(c,l=z(e.sourceDir))=>{let u=Ct(l,z(c));if(u===".."||u.startsWith(`..${pe}`)||u.startsWith(pe))throw Error(`Block dependency outside sourceDir: ${c}`);return u.replaceAll(pe,"/")},n=(c)=>{if(i(z(e.sourceDir,c)),!e.readFile)i(we(z(e.sourceDir,c)),we(e.sourceDir));let l=r.get(c);if(l!==void 0)return l;let u=t(z(e.sourceDir,c));return r.set(c,u),u},a=(c)=>{let l=new Map,u=(f)=>{if(l.has(f))return;let p=n(f);l.set(f,{path:f,type:kt(f),content:p});let d=p.matchAll(/(?:\bfrom\s*|\bimport\s*)["'](\.[^"']+)["']/g);for(let m of d){let y=i(z(e.sourceDir,Rt(f),m[1]??"")),h=xt(y)?[y]:[`${y}.ts`,`${y}.tsx`,`${y}/index.ts`,`${y}/index.tsx`],A;for(let N of h)try{n(N),A=N;break}catch(_){if(_ instanceof Error&&_.message.includes("outside sourceDir"))throw _}if(!A)throw Error(`Unresolved block dependency: ${f} -> ${m[1]}`);u(A)}};return u(c),[...l.values()]},o=(c)=>{let l=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 d=p.startsWith("@")?p.split("/").slice(0,2).join("/"):p.split("/")[0]??"";if(d==="react"||d==="react-dom"||d.startsWith("@uibot/"))continue;l.add(d)}}return[...l].sort()},s=[];for(let c of Object.keys(e.catalog)){let l=e.blockFileMap[c];if(l===void 0)continue;let u=e.catalog[c];if(u===void 0)continue;let f=n(l),p=a(l),d=o(p);s.push({name:c,category:u.category,description:u.description,sourceCode:f,files:p,catalogEntry:u,...d.length>0?{dependencies:d}:{}})}return s}function Cn(e){return e.flatMap((t)=>St(t))}import{readdirSync as It,readFileSync as At,statSync as wt}from"fs";import{basename as Pt,join as vt}from"path";var Et="0.1.0";function Pe(e){let{dir:t}=e,r;try{r=It(t)}catch{return[]}let i=e.defaultVersion??Et,n=e.defaultLevel??"L4",a=e.defaultCategory??"template",o=[];for(let s of r){if(!/\.ya?ml$/i.test(s))continue;let c=vt(t,s);try{if(!wt(c).isFile())continue}catch{continue}let l=At(c,"utf8");if(!l.trim())continue;let u=Pt(s).replace(/\.ya?ml$/i,""),f=Tt(u),p=Ot(u),d=_t(l)??`${p} template`;o.push({name:f,version:i,title:p,description:d,yaml:l,absolutePath:c,templateContract:{name:f,description:d,level:n,category:a,keywords:[f,u.toLowerCase(),"uibot-template",...e.extraKeywords??[]],composedFrom:Ft(l)}})}return o.sort((s,c)=>s.name.localeCompare(c.name))}function Dt(e){let t=new Map;for(let r of e)for(let i of Pe(r)){let n=t.get(i.name);if(n)throw Error(`duplicate template source name "${i.name}": ${n.absolutePath} and ${i.absolutePath}`);t.set(i.name,i)}return[...t.values()].sort((r,i)=>r.name.localeCompare(i.name))}function ve(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 ge(e){return{name:e.name,kind:"template",title:e.title,description:e.description,artifact:ve(e)}}function Tt(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9]+/g,"-").replace(/^-|-$/g,"").toLowerCase()}function Ot(e){return e.replace(/[-_]+/g," ").replace(/\b\w/g,(t)=>t.toUpperCase())}function _t(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 Ft(e){let t=new Set;for(let r of e.matchAll(/^\s*-\s*type:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let i=r[1]?.trim();if(i)t.add(i)}for(let r of e.matchAll(/^\s*template:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let i=r[1]?.trim();if(i)t.add(i)}return[...t].sort()}var Mt="0.1.0";function Nt(e,t={}){return{kind:"component",name:e.name,version:t.defaultVersion??Mt,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 Ee(e,t={}){return{name:e.name,kind:"component",title:e.catalogEntry.name,description:e.description??e.catalogEntry.description,artifact:Nt(e,t)}}function An(e,t){let r={...t.runtime?{runtime:t.runtime}:{},...t.defaultVersion?{defaultVersion:t.defaultVersion}:{}},i=e.map((a)=>Ee(a,r)),n=(t.templates??[]).map((a)=>ge(a));return{name:t.name,items:[...i,...n]}}function wn(e,t={}){return Ee(e,t)}import{posix as L}from"path";var jt={spec:["html","markdown","zip"],prototype:["html","zip"],deck:["html","pptx","zip"],poster:["html","zip"]},Ri=Array.from(new Set(Object.values(jt).flat()));var De=["component","template","design-guide","example","skill","block","package","theme"],te=["experimental","candidate","recommended"],Te=["declared","verified","external-consumer"],re=["missing","declared","verified","external-consumer"],Y=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure","packed-install","typecheck","browser"],Vt=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([...[["function","functions"],["scenario","scenarios"],["unit","units"],["industry","industries"]].map(([e,t])=>Object.freeze({name:e,property:t,type:"string",multiple:!0,cliEncoding:"comma-separated"})),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([])}),Object.freeze({name:"docs",summary:"Read curated public documentation for one resource.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"locale",property:"locale",type:"string"},{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"examples",summary:"Read one bounded page of examples and exact dependencies. Follow nextPage for complete source.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"install-plan",summary:"Describe distribution channels and fixed snapshot identity/closure without installing or writing.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])})]);var me="uibot.registry.item.v1";var $t=["background","foreground","card","card-foreground","popover","popover-foreground","primary","primary-foreground","secondary","secondary-foreground","muted","muted-foreground","accent","accent-foreground","border","input","ring","destructive","destructive-foreground","success","success-foreground","warning","warning-foreground"],Ai=[...$t,"radius","font-display","font-body","font-mono"];var D=(e)=>!!e&&typeof e==="object"&&!Array.isArray(e),k=(e)=>typeof e==="string"&&e.length>0&&!["__proto__","prototype","constructor"].includes(e),Oe=(e)=>D(e)&&Object.entries(e).every(([t,r])=>k(t)&&k(r));function Li(e){if(e.composition===void 0)return;let t=e.composition;if(!D(t)||t.schema!=="uibot.solution-composition.v1"||!Array.isArray(t.pages))throw Error("invalid-solution-composition");let r=new Set;for(let i of t.pages){if(!D(i)||!k(i.resourceId)||!k(i.version)||typeof i.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(i.sourceHash)||!k(i.sourcePageId)||!k(i.targetPageId)||r.has(i.targetPageId)||!D(i.baseline)||i.baseline.id!==i.targetPageId||typeof i.baseline.path!=="string"||!Array.isArray(i.baseline.blocks)||!D(i.bindings)||!["source","target"].includes(String(i.bindings.layout))||!Oe(i.bindings.paths)||!Oe(i.bindings.connections)||i.bindings.frame!==void 0&&(!D(i.bindings.frame)||Object.keys(i.bindings.frame).some((n)=>!["props","slots","events"].includes(n)))||i.detached!==void 0&&typeof i.detached!=="boolean"||i.configuration!==void 0&&(!D(i.configuration)||Object.entries(i.configuration).some(([n,a])=>!k(n)||!["string","number","boolean"].includes(typeof a)||typeof a==="number"&&!Number.isFinite(a))))throw Error("invalid-solution-adoption");r.add(i.targetPageId)}if(t.regions!==void 0){if(!Array.isArray(t.regions))throw Error("invalid-solution-regions");let i=new Set;for(let n of t.regions){if(!D(n)||!k(n.resourceId)||!k(n.version)||typeof n.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(n.sourceHash)||!k(n.targetPageId)||i.has(n.targetPageId)||!k(n.role)||n.target!=="page-frame"||!k(n.contentBlockId)||!D(n.baseline)||!k(n.baseline.type))throw Error("invalid-solution-region");i.add(n.targetPageId)}}}var Ut="https://ui.shadcn.com/schema/registry.json",zt="https://ui.shadcn.com/schema/registry-item.json",qt=["clsx","tailwind-merge"],Ht="components/uibot",Kt="lib",Wt="@uibot",Gt="uibot/templates",fe="uibot-base",_e="uibot-theme";function ye(e){return e.replace(/\./g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function Fe(e,t){let r=e.sourceCode;if(r=r.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/renderer-react["'];?/g,(o,s,c)=>`import ${s??"type "}${c} from "${t.rendererShimImport}";`),t.contractsShimImport){let o=t.contractsShimImport;r=r.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/contracts["'];?/g,(s,c,l)=>`import ${c??"type "}${l} from "${o}";`)}let i=new Set,n=new Set(["Children","Component","PureComponent","Fragment","StrictMode","Profiler","Suspense","Activity","ViewTransition"]);r=r.replace(/\bReact\.([A-Z]\w*)/g,(o,s)=>{if(n.has(s))return o;return i.add(s),s});let a=!1;if(r=r.replace(/(?:^|\n)function cn\([\s\S]*?\)\s*(?::[^\n{]+)?\{[\s\S]*?\n\}\n?/,()=>(a=!0,`
|
|
3
|
-
`)),a){let
|
|
4
|
-
`,
|
|
5
|
-
`,
|
|
6
|
-
`,l=
|
|
7
|
-
`,
|
|
2
|
+
import{lstatSync as ai,mkdirSync as On,readFileSync as ci,realpathSync as li,writeFileSync as Bn}from"fs";import{basename as di,dirname as It,isAbsolute as pi,resolve as W,sep as Tn}from"path";function Ln(e){let t=e.lockfilePath??"uibot.artifacts.lock.json",n=e.manifest.items??[],o=new Map;for(let s of n)o.set(s.name,s);if(e.lockfile===null)return{ok:!1,lockfilePath:t,registryName:e.manifest.name,lockCount:0,manifestCount:n.length,drifts:[{name:"*",kind:"missing-in-lock",detail:"lockfile missing or unreadable"}]};let r=[],a=new Set;for(let s of e.lockfile.artifacts??[]){a.add(s.name);let i=o.get(s.name);if(!i){r.push({name:s.name,kind:"missing-in-manifest",lockVersion:s.version,detail:`locked ${s.name}@${s.version} not present in registry manifest`});continue}let c=jn(i);if(c&&c!==s.version)r.push({name:s.name,kind:"version-mismatch",lockVersion:s.version,manifestVersion:c,detail:`${s.name}: lock ${s.version} \u2260 registry ${c}`})}return{ok:r.length===0,lockfilePath:t,registryName:e.manifest.name,lockCount:(e.lockfile.artifacts??[]).length,manifestCount:n.length,drifts:r}}function jn(e){return e.artifact?.version??e.version}function Fn(){return{version:1,artifacts:[]}}function Vn(e){return{version:1,artifacts:e}}import{readFileSync as Un,realpathSync as Pt}from"fs";import{resolve as ce,relative as zn,dirname as Hn,extname as qn,sep as Ye}from"path";function Kn(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 Wn(e){let t=e.readFile??((c)=>Un(c,"utf8")),n=new Map,o=(c,l=ce(e.sourceDir))=>{let d=zn(l,ce(c));if(d===".."||d.startsWith(`..${Ye}`)||d.startsWith(Ye))throw Error(`Block dependency outside sourceDir: ${c}`);return d.replaceAll(Ye,"/")},r=(c)=>{if(o(ce(e.sourceDir,c)),!e.readFile)o(Pt(ce(e.sourceDir,c)),Pt(e.sourceDir));let l=n.get(c);if(l!==void 0)return l;let d=t(ce(e.sourceDir,c));return n.set(c,d),d},a=(c)=>{let l=new Map,d=(u)=>{if(l.has(u))return;let g=r(u);l.set(u,{path:u,type:Kn(u),content:g});let p=g.matchAll(/(?:\bfrom\s*|\bimport\s*)["'](\.[^"']+)["']/g);for(let f of p){let m=o(ce(e.sourceDir,Hn(u),f[1]??"")),h=qn(m)?[m]:[`${m}.ts`,`${m}.tsx`,`${m}/index.ts`,`${m}/index.tsx`],x;for(let k of h)try{r(k),x=k;break}catch(b){if(b instanceof Error&&b.message.includes("outside sourceDir"))throw b}if(!x)throw Error(`Unresolved block dependency: ${u} -> ${f[1]}`);d(x)}};return d(c),[...l.values()]},s=(c)=>{let l=new Set;for(let d of c){if(typeof d.content!=="string")continue;for(let u of d.content.matchAll(/(?:\bfrom\s*|\bimport\s*)["']([^."'/][^"']*|@[^"']+)["']/g)){let g=u[1]??"";if(g.startsWith("node:"))continue;let p=g.startsWith("@")?g.split("/").slice(0,2).join("/"):g.split("/")[0]??"";if(p==="react"||p==="react-dom"||p.startsWith("@uibot/"))continue;l.add(p)}}return[...l].sort()},i=[];for(let c of Object.keys(e.catalog)){let l=e.blockFileMap[c];if(l===void 0)continue;let d=e.catalog[c];if(d===void 0)continue;let u=r(l),g=a(l),p=s(g);i.push({name:c,category:d.category,description:d.description,sourceCode:u,files:g,catalogEntry:d,...p.length>0?{dependencies:p}:{}})}return i}function $i(e){return e.flatMap((t)=>Wn(t))}import{readdirSync as Gn,readFileSync as Yn,statSync as Jn}from"fs";import{basename as Zn,join as Qn}from"path";var Xn="0.1.0";function At(e){let{dir:t}=e,n;try{n=Gn(t)}catch{return[]}let o=e.defaultVersion??Xn,r=e.defaultLevel??"L4",a=e.defaultCategory??"template",s=[];for(let i of n){if(!/\.ya?ml$/i.test(i))continue;let c=Qn(t,i);try{if(!Jn(c).isFile())continue}catch{continue}let l=Yn(c,"utf8");if(!l.trim())continue;let d=Zn(i).replace(/\.ya?ml$/i,""),u=tr(d),g=nr(d),p=rr(l)??`${g} template`;s.push({name:u,version:o,title:g,description:p,yaml:l,absolutePath:c,templateContract:{name:u,description:p,level:r,category:a,keywords:[u,d.toLowerCase(),"uibot-template",...e.extraKeywords??[]],composedFrom:or(l)}})}return s.sort((i,c)=>i.name.localeCompare(c.name))}function er(e){let t=new Map;for(let n of e)for(let o of At(n)){let r=t.get(o.name);if(r)throw Error(`duplicate template source name "${o.name}": ${r.absolutePath} and ${o.absolutePath}`);t.set(o.name,o)}return[...t.values()].sort((n,o)=>n.name.localeCompare(o.name))}function Et(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 Je(e){return{name:e.name,kind:"template",title:e.title,description:e.description,artifact:Et(e)}}function tr(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9]+/g,"-").replace(/^-|-$/g,"").toLowerCase()}function nr(e){return e.replace(/[-_]+/g," ").replace(/\b\w/g,(t)=>t.toUpperCase())}function rr(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 or(e){let t=new Set;for(let n of e.matchAll(/^\s*-\s*type:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let o=n[1]?.trim();if(o)t.add(o)}for(let n of e.matchAll(/^\s*template:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let o=n[1]?.trim();if(o)t.add(o)}return[...t].sort()}var ir="0.1.0";function sr(e,t={}){return{kind:"component",name:e.name,version:t.defaultVersion??ir,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 Tt(e,t={}){return{name:e.name,kind:"component",title:e.catalogEntry.name,description:e.description??e.catalogEntry.description,artifact:sr(e,t)}}function Vi(e,t){let n={...t.runtime?{runtime:t.runtime}:{},...t.defaultVersion?{defaultVersion:t.defaultVersion}:{}},o=e.map((a)=>Tt(a,n)),r=(t.templates??[]).map((a)=>Je(a));return{name:t.name,items:[...o,...r]}}function Ui(e,t={}){return Tt(e,t)}import{posix as te}from"path";var lr={spec:["html","markdown","zip"],prototype:["html","zip"],deck:["html","pptx","zip"],poster:["html","zip"]},Ms=Array.from(new Set(Object.values(lr).flat()));var Dt=["component","template","design-guide","example","skill","block","package","theme"],Ae=["experimental","candidate","recommended"],Ot=["declared","verified","external-consumer"],Ee=["missing","declared","verified","external-consumer"],be=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure","packed-install","typecheck","browser"],dr=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([...[["function","functions"],["scenario","scenarios"],["unit","units"],["industry","industries"]].map(([e,t])=>Object.freeze({name:e,property:t,type:"string",multiple:!0,cliEncoding:"comma-separated"})),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([])}),Object.freeze({name:"docs",summary:"Read curated public documentation for one resource.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"locale",property:"locale",type:"string"},{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"examples",summary:"Read one bounded page of examples and exact dependencies. Follow nextPage for complete source.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"install-plan",summary:"Describe distribution channels and fixed snapshot identity/closure without installing or writing.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])})]);var Ze="uibot.registry.item.v1";var pr=["background","foreground","card","card-foreground","popover","popover-foreground","primary","primary-foreground","secondary","secondary-foreground","muted","muted-foreground","accent","accent-foreground","border","input","ring","destructive","destructive-foreground","success","success-foreground","warning","warning-foreground"],Vs=[...pr,"radius","font-display","font-body","font-mono"];var ur=["L1","L2","L3","L4"],Xe=["shell","page","frame","section","block"],gr=["block-node","block-prop","block-events","block-children","page-field","spec-layout"],F=(e)=>Boolean(e)&&typeof e==="object"&&!Array.isArray(e),q=(e)=>typeof e==="string"&&e.length>0&&!["__proto__","prototype","constructor"].includes(e),Qe=(e)=>F(e)&&typeof e.zh==="string"&&typeof e.en==="string";function fr(e,t){if(e==="shell"){if(!F(t.shellLayout))throw Error("missing-variant-payload");return}if(e==="page"){let n=t.pageTemplate;if(!F(n)||!q(n.id)||typeof n.path!=="string"||!Array.isArray(n.blocks))throw Error("missing-variant-payload");return}if(e==="frame"){let n=t.frameTemplate;if(!F(n)||!q(n.contentBlockId)||!F(n.frame)||!q(n.frame.type))throw Error("missing-variant-payload");return}if(!F(t.blockTemplate)||!q(t.blockTemplate.type))throw Error("missing-variant-payload")}function et(e){if(!F(e)||e.schema!=="uibot.variant-contract.v1"||!q(e.familyId)||!ur.includes(e.level)||!Xe.includes(e.targetKind)||!Qe(e.title)||typeof e.description!=="string"||!Array.isArray(e.semanticSlots)||!Array.isArray(e.variants)||e.variants.length===0)throw Error("invalid-variant-contract");let t=new Set;for(let a of e.semanticSlots){if(!F(a)||!q(a.id)||!Qe(a.label))throw Error("invalid-variant-slot");if(a.preserveMode!==void 0&&a.preserveMode!=="always"&&a.preserveMode!=="when-customized")throw Error("invalid-variant-slot");if(t.has(a.id))throw Error("duplicate-variant-slot");t.add(a.id)}let n=new Set,o=new Set,r=e.targetKind;for(let a of e.variants){if(!F(a)||!q(a.id)||!Qe(a.title)||typeof a.description!=="string"||!F(a.slotBindings))throw Error("invalid-variant-member");if(n.has(a.id)||o.has(a.id))throw Error("duplicate-variant-id");if(n.add(a.id),a.aliases!==void 0){if(!Array.isArray(a.aliases))throw Error("invalid-variant-alias");for(let s of a.aliases){if(!q(s))throw Error("invalid-variant-alias");if(n.has(s)||o.has(s))throw Error("duplicate-variant-alias");o.add(s)}}for(let[s,i]of Object.entries(a.slotBindings)){if(!q(s)||!t.has(s))throw Error(`undeclared-variant-slot:${s}`);if(!F(i)||!gr.includes(i.kind)||i.occurrence!==void 0&&(typeof i.occurrence!=="number"||!Number.isInteger(i.occurrence)||i.occurrence<0))throw Error(`invalid-variant-slot-binding:${s}`)}fr(r,a)}}var U=(e)=>!!e&&typeof e==="object"&&!Array.isArray(e),N=(e)=>typeof e==="string"&&e.length>0&&!["__proto__","prototype","constructor"].includes(e),Bt=(e)=>U(e)&&Object.entries(e).every(([t,n])=>N(t)&&N(n));function B(e){if(e.composition===void 0)return;let t=e.composition;if(!U(t)||t.schema!=="uibot.solution-composition.v1"||!Array.isArray(t.pages))throw Error("invalid-solution-composition");let n=new Set;for(let o of t.pages){if(!U(o)||!N(o.resourceId)||!N(o.version)||typeof o.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(o.sourceHash)||!N(o.sourcePageId)||!N(o.targetPageId)||n.has(o.targetPageId)||!U(o.baseline)||o.baseline.id!==o.targetPageId||typeof o.baseline.path!=="string"||!Array.isArray(o.baseline.blocks)||!U(o.bindings)||!["source","target"].includes(String(o.bindings.layout))||!Bt(o.bindings.paths)||!Bt(o.bindings.connections)||o.bindings.frame!==void 0&&(!U(o.bindings.frame)||Object.keys(o.bindings.frame).some((r)=>!["props","slots","events"].includes(r)))||o.detached!==void 0&&typeof o.detached!=="boolean"||o.configuration!==void 0&&(!U(o.configuration)||Object.entries(o.configuration).some(([r,a])=>!N(r)||!["string","number","boolean"].includes(typeof a)||typeof a==="number"&&!Number.isFinite(a))))throw Error("invalid-solution-adoption");n.add(o.targetPageId)}if(t.regions!==void 0){if(!Array.isArray(t.regions))throw Error("invalid-solution-regions");let o=new Set;for(let r of t.regions){if(!U(r)||!N(r.resourceId)||!N(r.version)||typeof r.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(r.sourceHash)||!N(r.targetPageId)||o.has(r.targetPageId)||!N(r.role)||r.target!=="page-frame"||!N(r.contentBlockId)||!U(r.baseline)||!N(r.baseline.type))throw Error("invalid-solution-region");o.add(r.targetPageId)}}if(t.variants!==void 0){if(!Array.isArray(t.variants))throw Error("invalid-solution-variants");let o=new Set;for(let r of t.variants){if(!U(r)||!N(r.familyId)||!N(r.variantId)||!N(r.targetId)||!Xe.includes(r.targetKind))throw Error("invalid-solution-variant");let a=`${r.targetKind}:${r.targetId}:${r.familyId}`;if(o.has(a))throw Error("invalid-solution-variant");o.add(a)}}}var hr=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,yr=["string","number","boolean","date","datetime","enum","json","ref"];function Mt(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e))}function ke(e,t){if(!Mt(e)||t&&Object.keys(e).some((n)=>!t.includes(n)))throw Error("Invalid data object or unknown field");return e}function xe(e){if(typeof e!=="string"||!hr.test(e))throw Error("Invalid data name")}function $t(e){if(typeof e!=="string"||!e||e.length>2048)throw Error("Invalid data text")}function br(e){return e===null||typeof e==="string"||typeof e==="boolean"||typeof e==="number"&&Number.isFinite(e)}function _t(e){for(let t=0;t<e.length;t++)if(!Object.hasOwn(e,t))return!1;return!0}function tt(e,t={left:1e4},n=0){if(--t.left<0||n>32)return!1;if(br(e))return!0;if(Array.isArray(e)){if(e.length>t.left||!_t(e))return!1;return e.every((o)=>tt(o,t,n+1))}return Mt(e)&&Object.values(e).every((o)=>tt(o,t,n+1))}function Y(e){let t=ke(e,["entities"]),n=ke(t.entities);if(Object.keys(n).length>64)throw Error("Data model exceeds 64 entities");for(let[o,r]of Object.entries(n)){xe(o);let a=ke(r,["title","key","fields","version"]);if(a.title!==void 0)$t(a.title);xe(a.key);let s=ke(a.fields);if(Object.keys(s).length>128)throw Error("Data entity exceeds 128 fields");if(!Object.hasOwn(s,a.key))throw Error("Data key must name an entity field");if(a.version!==void 0){if(xe(a.version),!Object.hasOwn(s,a.version))throw Error("Unknown data version field")}for(let[i,c]of Object.entries(s)){xe(i);let l=ke(c,["type","title","required","readOnly","default","values","entity","maxLength"]);if(typeof l.type!=="string"||!yr.includes(l.type))throw Error("Invalid data field type");if(l.title!==void 0)$t(l.title);for(let d of["required","readOnly"])if(l[d]!==void 0&&typeof l[d]!=="boolean")throw Error("Invalid data field flag");if(l.type==="enum"||l.values!==void 0){if(!Array.isArray(l.values)||!l.values.length||l.values.length>500||!_t(l.values)||l.values.some((d)=>typeof d!=="string"||d.length>2048))throw Error("Data enum requires bounded string values")}if(l.type==="ref"||l.entity!==void 0){if(xe(l.entity),!Object.hasOwn(n,l.entity))throw Error("Unknown referenced data entity")}if(l.maxLength!==void 0&&(!Number.isSafeInteger(l.maxLength)||l.maxLength<0))throw Error("Invalid data maxLength");if(Object.hasOwn(l,"default")&&!tt(l.default))throw Error("Invalid or excessive data default")}}return e}class w extends Error{code;opIndex;opKind;constructor(e,t,n,o){super(`${e} at op[${t}] (${n}): ${o}`);this.code=e;this.opIndex=t;this.opKind=n;this.name="SpecPatchError"}}var Te=new Set(["__proto__","prototype","constructor"]),kr=/^@[A-Za-z_][A-Za-z0-9_]*$/,Lt=/^(0|[1-9]\d*)$/,xr=/^[A-Za-z_][A-Za-z0-9_]*$/,M=(e)=>Boolean(e)&&typeof e==="object"&&!Array.isArray(e),D=(e)=>typeof e==="string"&&e.length>0&&!Te.has(e);function De(e,t=64){let n=(o,r)=>{if(r>t)throw Error("spec-json-depth-exceeded");if(o===null||typeof o!=="object")return;if(Array.isArray(o)){for(let a of o)n(a,r+1);return}for(let a of Object.getOwnPropertyNames(o)){if(Te.has(a))throw Error(`unsafe-spec-key:${a}`);n(o[a],r+1)}};n(e,0)}function J(e,t={}){let n;if(typeof e==="string"){let a=e.trim(),s=a.startsWith("uibot-path:")?a.slice(11):a;if(s===""){if(t.allowRoot)return[];throw Error("invalid-spec-block-path")}n=s.split(".")}else if(Array.isArray(e))n=e;else throw Error("invalid-spec-block-path");if(n.length===0){if(t.allowRoot)return[];throw Error("invalid-spec-block-path")}let o=[];for(let a=0;a<n.length;a++){let s=n[a];if(typeof s==="number"){if(!Number.isInteger(s)||s<0)throw Error("invalid-spec-block-path");if(a>0&&typeof o[o.length-1]==="number");o.push(s);continue}if(typeof s==="string"){if(Lt.test(s)){o.push(Number(s));continue}if(kr.test(s)){let i=s.slice(1);if(Te.has(i))throw Error("invalid-spec-block-path");if(a===0)throw Error("invalid-spec-block-path");if(a<n.length-1){let c=n[a+1];if(!(typeof c==="number"&&Number.isInteger(c)&&c>=0||typeof c==="string"&&Lt.test(c)))throw Error("invalid-spec-block-path")}else if(!t.allowSlotEnd)throw Error("invalid-spec-block-path");o.push(s);continue}}throw Error("invalid-spec-block-path")}if(typeof o[0]!=="number")throw Error("invalid-spec-block-path");let r=o[o.length-1];if(typeof r!=="number"&&!(t.allowSlotEnd&&typeof r==="string"))throw Error("invalid-spec-block-path");return o}function nt(e,t,n){if(!M(e)||!D(e.pageId))throw new w("invalid-spec-patch",t,n,"target.pageId is required");if(!e.blockId&&e.blockPath===void 0)throw new w("invalid-spec-patch",t,n,"target requires blockId or blockPath");if(e.blockId!==void 0&&!D(e.blockId))throw new w("invalid-spec-patch",t,n,"invalid target.blockId");if(e.blockPath!==void 0)try{J(e.blockPath,{allowRoot:!1,allowSlotEnd:!1})}catch{throw new w("invalid-spec-block-path",t,n,"invalid target.blockPath")}}function jt(e,t,n){if(!M(e)||!D(e.pageId))throw new w("invalid-spec-patch",t,n,"target.pageId is required");if(e.parentBlockId!==void 0&&!D(e.parentBlockId))throw new w("invalid-spec-patch",t,n,"invalid parentBlockId");if(e.parentPath!==void 0)try{J(e.parentPath,{allowRoot:!0,allowSlotEnd:!0})}catch{throw new w("invalid-spec-block-path",t,n,"invalid parentPath")}if(e.slot!==void 0){if(typeof e.slot!=="string"||!xr.test(e.slot)||Te.has(e.slot))throw new w("patch-slot-invalid",t,n,"invalid target.slot")}if(e.index!==void 0&&(typeof e.index!=="number"||!Number.isInteger(e.index)||e.index<0))throw new w("invalid-spec-patch",t,n,"invalid target.index")}function Ft(e){if(De(e),!M(e)||!Array.isArray(e.pages)||e.pages.length===0)throw Error("invalid-blueprint-pages");if(e.pages.length>64)throw Error("invalid-blueprint-pages");if(e.connections!==void 0){if(!Array.isArray(e.connections))throw Error("invalid-blueprint-connection");let t=new Set;for(let n of e.connections){if(!M(n)||!D(n.id)||!D(n.entity))throw Error("invalid-blueprint-connection");if(t.has(n.id))throw Error("duplicate-blueprint-connection");if(t.add(n.id),Object.hasOwn(n,"bindings")&&n.bindings!==void 0)throw Error("blueprint-connection-bindings-forbidden");if(n.mockSeed!==void 0&&(!Array.isArray(n.mockSeed)||n.mockSeed.some((o)=>!M(o))))throw Error("invalid-blueprint-connection");if(n.mockGenerate!==void 0&&(typeof n.mockGenerate!=="number"||!Number.isInteger(n.mockGenerate)||n.mockGenerate<0||n.mockGenerate>500))throw Error("invalid-blueprint-connection")}}for(let t of e.pages){if(!M(t))throw Error("invalid-blueprint-page");if(t.id!==void 0&&!D(t.id))throw Error("invalid-blueprint-page");if(t.path!==void 0&&typeof t.path!=="string")throw Error("invalid-blueprint-page");if(t.kind==="blocks"||t.kind===void 0&&Array.isArray(t.blocks)){if(!D(t.id)||typeof t.path!=="string"||!Array.isArray(t.blocks))throw Error("invalid-blueprint-page");continue}if(!(D(t.solutionId)||D(t.familyId)&&D(t.variantId)))throw Error("invalid-blueprint-page")}}function Vt(e,t={}){if(!Array.isArray(e))throw new w("invalid-spec-patch",0,"batch","operations must be an array");if(e.length>200)throw new w("spec-patch-batch-too-large",e.length,"batch","exceeds maximum batch size 200");for(let n=0;n<e.length;n++){let o=e[n];if(!M(o)||typeof o.op!=="string")throw new w("invalid-spec-patch",n,"unknown","operation must declare op");let r=o.op;try{De(o)}catch(a){let s=a instanceof Error?a.message:"unsafe json",i=s.includes("spec-json-depth-exceeded")?"spec-json-depth-exceeded":"unsafe-spec-key";throw new w(i,n,r,s)}switch(r){case"addPage":if(!M(o.page)||!D(o.page.id)||typeof o.page.path!=="string"||!Array.isArray(o.page.blocks))throw new w("invalid-spec-patch",n,r,"invalid page object");break;case"removePage":case"updatePage":case"setPageState":if(!D(o.pageId))throw new w("invalid-spec-patch",n,r,"pageId is required");break;case"insertBlock":if(jt(o.target,n,r),!M(o.block)||!D(o.block.type))throw new w("invalid-spec-patch",n,r,"block.type is required");break;case"replaceBlock":if(nt(o.target,n,r),!M(o.block)||!D(o.block.type))throw new w("invalid-spec-patch",n,r,"block.type is required");break;case"removeBlock":case"updateProps":case"setEvents":nt(o.target,n,r);break;case"moveBlock":nt(o.from,n,r),jt(o.to,n,r);break;case"upsertEntity":if(!D(o.name)||!M(o.entity))throw new w("invalid-spec-patch",n,r,"name and entity required");break;case"removeEntity":if(!D(o.name))throw new w("invalid-spec-patch",n,r,"name is required");break;case"upsertConnection":if(!M(o.connection)||!D(o.connection.id)||!D(o.connection.entity))throw new w("invalid-spec-patch",n,r,"valid connection is required");if(!t.allowConnectionBindings&&Object.hasOwn(o.connection,"bindings")&&o.connection.bindings!==void 0)throw new w("spec-patch-connection-bindings-forbidden",n,r,"connection.bindings is host-owned and forbidden in spec patches");break;case"removeConnection":if(!D(o.connectionId))throw new w("invalid-spec-patch",n,r,"connectionId is required");break;case"setLayout":if(!M(o.layout))throw new w("invalid-spec-patch",n,r,"layout object is required");break;case"setMenus":if(!M(o.menus)||!Array.isArray(o.menus.items))throw new w("invalid-spec-patch",n,r,"menus.items is required");break;case"setDesign":if(!M(o.design))throw new w("invalid-spec-patch",n,r,"design object is required");break;case"swapVariant":if(!M(o.target)||typeof o.targetVariantId!=="string")throw new w("invalid-spec-patch",n,r,"target and targetVariantId are required");if(o.target.blockPath!==void 0)try{J(o.target.blockPath,{allowRoot:!1,allowSlotEnd:!1})}catch{throw new w("invalid-spec-block-path",n,r,"invalid target.blockPath")}break;default:throw new w("invalid-spec-patch",n,r,`unknown op "${r}"`)}}}var vr="https://ui.shadcn.com/schema/registry.json",Cr="https://ui.shadcn.com/schema/registry-item.json",wr=["clsx","tailwind-merge"],Sr="components/uibot",Ir="lib",Rr="@uibot",Pr="uibot/templates",rt="uibot-base",Ut="uibot-theme";function ot(e){return e.replace(/\./g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function zt(e,t){let n=e.sourceCode;if(n=n.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/renderer-react["'];?/g,(s,i,c)=>`import ${i??"type "}${c} from "${t.rendererShimImport}";`),t.contractsShimImport){let s=t.contractsShimImport;n=n.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/contracts["'];?/g,(i,c,l)=>`import ${c??"type "}${l} from "${s}";`)}let o=new Set,r=new Set(["Children","Component","PureComponent","Fragment","StrictMode","Profiler","Suspense","Activity","ViewTransition"]);n=n.replace(/\bReact\.([A-Z]\w*)/g,(s,i)=>{if(r.has(i))return s;return o.add(i),i});let a=!1;if(n=n.replace(/(?:^|\n)function cn\([\s\S]*?\)\s*(?::[^\n{]+)?\{[\s\S]*?\n\}\n?/,()=>(a=!0,`
|
|
3
|
+
`)),a){let s=`import { cn } from "${t.cnUtilImport}";
|
|
4
|
+
`,i=n.indexOf(`
|
|
5
|
+
`,n.indexOf("import "));if(i>=0)n=`${n.slice(0,i+1)}${s}${n.slice(i+1)}`;else n=s+n}if(o.size>0){let s=[...o].sort().join(", "),i=/import\s+type\s+\{([^}]*)\}\s+from\s+["']react["'];?/;if(i.test(n))n=n.replace(i,(c,l)=>`import type { ${[...new Set([...l.split(",").map((u)=>u.trim()).filter(Boolean),...o])].sort().join(", ")} } from "react";`);else{let c=`import type { ${s} } from "react";
|
|
6
|
+
`,l=n.indexOf(`
|
|
7
|
+
`,n.indexOf("import "));if(l>=0)n=`${n.slice(0,l+1)}${c}${n.slice(l+1)}`;else n=c+n}}return`${n.replace(/\n{3,}/g,`
|
|
8
8
|
|
|
9
9
|
`).trimStart().trimEnd()}
|
|
10
|
-
`}function
|
|
11
|
-
`,type:"registry:ui"})}let
|
|
12
|
-
`,type:"registry:lib"}],meta:{uibot:ee}}}return Jt(d,t.composites??[],{channel:i,ref:n,componentsDir:a}),{registry:{$schema:Ut,name:t.registryName,...t.homepage?{homepage:t.homepage}:{},items:Object.values(d).map((g)=>({name:g.name,type:g.type,...g.description?{description:g.description}:{},...g.registryDependencies?{registryDependencies:g.registryDependencies}:{},...g.dependencies?{dependencies:g.dependencies}:{}}))},items:d,unresolvedTemplateTypes:_}}function Jt(e,t,r){let i=new Map;for(let n of t){if(i.has(n.name)||e[n.name])throw Error(`composite item "${n.name}" collides with another item`);i.set(n.name,n)}for(let n of t){let a=n.channel??"public",o=Ne(n),s=new Set(n.files.map((l)=>l.path));for(let l of n.requires??[]){let u=i.get(l);if(!u)throw Error(`composite "${n.name}" requires unknown "${l}"`);if((u.channel??"public")!==a)throw Error(`composite "${n.name}" (${a}) requires "${l}" from another channel`);if(Ne(u)!==o)throw Error(`composite "${n.name}" requires "${l}" from another directory`);for(let f of u.files)s.add(f.path)}for(let l of n.files){if(!Be.test(l.path))throw Error(`composite "${n.name}" file "${l.path}" must be a plain relative path`);for(let u of Qt(l.content)){if(!u.startsWith("./")||u.includes("/../"))throw Error(`${n.name}/${l.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((d)=>s.has(d)))throw Error(`${n.name}/${l.path} imports ${u}, which no required item ships`)}}if(a!==r.channel)continue;let c=n.files.map((l)=>{let u=`${r.componentsDir}/${o}/${l.path}`;return{path:u,target:u,content:l.content,type:l.path.endsWith(".tsx")?"registry:component":"registry:lib"}});e[n.name]={name:n.name,type:n.type,description:n.description,dependencies:["react",...n.dependencies??[]],registryDependencies:[...n.primitives??[],...(n.requires??[]).map(r.ref)],files:c,meta:{composite:!0,channel:a}}}}var Be=/^[a-z0-9][a-z0-9._-]*(\/[a-z0-9][a-z0-9._-]*)*$/i;function Ne(e){if(!Be.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 Qt(e){let t=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1"),r=[],i=[/\bfrom\s*["'](\.{1,2}\/[^"']+)["']/g,/\bimport\s*["'](\.{1,2}\/[^"']+)["']/g,/\bimport\s*\(\s*["'](\.{1,2}\/[^"']+)["']\s*\)/g];for(let n of i)for(let a of t.matchAll(n))r.push(a[1]??"");return r}function Zt(e){if(e.baseUrl){let r=e.baseUrl.replace(/\/$/,"");return(i)=>`${r}/r/${i}.json`}let t=e.namespace??Wt;if(!/^@[a-z0-9][a-z0-9-]*$/.test(t))throw Error(`registry namespace must look like "@uibot", got "${t}"`);return(r)=>`${t}/${r}`}function Xt(e,t,r){let i=e.name.replace(/\./g,""),n=`${r}/`,a=t.files.find((o)=>o.path.startsWith(n)&&/\.(tsx|ts)$/.test(o.path)&&er(o.content,i));if(!a)throw Error(`block "${e.name}" has no named export "${i}" in item "${t.name}"`);return{name:e.name,export:i,module:a.path.slice(n.length),catalog:e.catalogEntry}}function er(e,t){let r=Le(t),i=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*\/\/.*$/gm,"");if(new RegExp(`export\\s+(?:const|let|function|class)\\s+${r}\\b`).test(i))return!0;for(let n of i.matchAll(/export\s*\{([^}]*)\}/g)){let a=(n[1]??"").split(",").map((s)=>{let[,c]=s.trim().split(/\s+as\s+/);return(c??s.trim().replace(/^type\s+/,"")).trim()}),o=(n[1]??"").split(",").map((s)=>s.trim()).filter((s)=>s.startsWith("type ")).map((s)=>s.replace(/^type\s+/,"").split(/\s+as\s+/).pop()?.trim());if(a.includes(t)&&!o.includes(t))return!0}return!1}function tr(e,t,r){let i=new Set(r.files.map((a)=>a.path)),n=(a)=>a.replace(/^blocks\//,"");return t.replace(/((?:\bfrom\s*|\bimport\s*)["'])(\.[^"']+)(["'])/g,(a,o,s,c)=>{let l=L.normalize(L.join(L.dirname(e),s)),f=(L.extname(l)?[l]:[l,`${l}.ts`,`${l}.tsx`,`${l}/index.ts`,`${l}/index.tsx`]).find((d)=>i.has(d));if(!f)return a;let p=L.relative(L.dirname(n(e)),n(f));if(!L.extname(s))p=p.replace(/\.(tsx?|jsx?)$/,"");if(!p.startsWith("."))p=`./${p}`;return o+p+c})}function rr(e,t){return(e.split("/").pop()??t).replace(/\.(tsx|ts|jsx|js)$/,"")||t}var ns=zt;function nr(e="/api/registry"){let t=(e||"/api/registry").trim(),r=t.startsWith("/")?t:`/${t}`;return r.length>1?r.replace(/\/$/,""):r}function J(e,t=200){return Response.json(e,{status:t})}function os(e){let t=nr(e.basePath),r=`${t}/registry.json`,i=`${t}/artifacts/`,n=new Map(e.manifest.items.map((a)=>[a.name,a]));return async function(o){let s=new URL(o.url);if(o.method!=="GET")return J({error:"Method not allowed"},405);if(s.pathname===r)return J(e.manifest);if(s.pathname.startsWith(i)){let c=s.pathname.slice(i.length),l=decodeURIComponent(c.endsWith(".json")?c.slice(0,-5):c),u=n.get(l);if(!u)return J({error:`Artifact '${l}' not found`},404);return J(u)}return J({error:"Not found"},404)}}var he="uibot.resource.admission.v1",ir=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure"],or=["packed-install","typecheck","browser"],cs=["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 je 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 Ve 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 $e extends Error{code="resource-admission-report-not-derived";constructor(){super("resource admission report must come directly from assessResourceAdmissions");this.name="ResourceAdmissionReportNotDerivedError"}}var sr=new Set(Y),ar=new Set(re),Ue=new WeakSet,ne={missing:0,declared:1,verified:2,"external-consumer":3};function cr(e,t){return e<t?-1:e>t?1:0}function q(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function ie(e,t){let r=new Set(t);return Object.keys(e).every((i)=>r.has(i))}function ze(e){return[...new Set(e.map((t)=>t.trim()).filter(Boolean))].sort(cr)}function lr(e,t,r,i){if(!q(r)||!ie(r,["status","evidence"])){i.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} must contain only status and evidence`});return}if(typeof r.status!=="string"||!ar.has(r.status)||r.status==="missing"){i.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((n)=>typeof n!=="string"||!n.trim())){i.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:ze(r.evidence)}}function dr(e){if(e===void 0)return;if(!q(e)||!ie(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 ur(e,t){let r=new Map,i=[];if(!q(t)||!ie(t,["schemaVersion","records"])||t.schemaVersion!==he||!Array.isArray(t.records))return i.push({code:"invalid-admission-manifest",detail:`expected ${he} with a records array`}),{records:r,issues:i};let n=new Set(e.resources.map((a)=>a.id));for(let a of t.records){if(!q(a)||!ie(a,["resourceId","provenance","checks"])||typeof a.resourceId!=="string"||!a.resourceId.trim()||!q(a.checks)){i.push({code:"invalid-admission-record",...q(a)&&typeof a.resourceId==="string"?{resourceId:a.resourceId}:{},detail:"record must contain only resourceId, optional provenance and checks"});continue}let o=a.resourceId.trim();if(r.has(o)){i.push({code:"duplicate-admission-record",resourceId:o,detail:o});continue}if(!n.has(o)){i.push({code:"unknown-admission-resource",resourceId:o,detail:o});continue}let s=dr(a.provenance);if(a.provenance!==void 0&&!s){i.push({code:"invalid-admission-record",resourceId:o,detail:"provenance must contain only string source, version and license fields"});continue}let c={},l=!1;for(let[u,f]of Object.entries(a.checks)){if(!sr.has(u)){i.push({code:"invalid-admission-check",resourceId:o,detail:`unknown receipt check: ${u}`}),l=!0;continue}let p=u,d=lr(o,p,f,i);if(d)c[p]=d;else l=!0}if(l)continue;r.set(o,{resourceId:o,...s?{provenance:s}:{},checks:c})}return{records:r,issues:i}}function pr(e){let t=new Map(e.resources.map((n)=>[n.id,n])),r=new Map;function i(n,a,o,s){if(r.has(n)||s.has(a))return;if(o.has(a)){r.set(n,`dependency cycle reached ${a}`);return}let c=t.get(a);if(!c){r.set(n,`missing dependency ${a}`);return}o.add(a);for(let l of c.dependencies)if(i(n,l,o,s),r.has(n))break;o.delete(a),s.add(a)}for(let n of e.resources)i(n.id,n.id,new Set,new Set);return r}var gr=/^(unknown|unlicensed|none|n\/?a)$/i,mr=/^SPDX-License-Identifier:\s*(\S+)/im,fr=/^(?:the\s+)?(mit|apache(?:\s+license(?:\s*,?\s*version\s*2\.0)?)?|bsd-2-clause|bsd-3-clause|isc|unlicense)\b/i;function B(e){let t=e?.trim();if(!t||gr.test(t))return;return t}function yr(e){if(!e?.trim())return;let t=e.match(mr)?.[1];if(t)return B(t);let r=e.match(fr)?.[1];if(!r)return;let i=r.toLowerCase();if(i.startsWith("mit"))return"MIT";if(i.startsWith("apache"))return"Apache-2.0";if(i.startsWith("bsd-2"))return"BSD-2-Clause";if(i.startsWith("bsd-3"))return"BSD-3-Clause";if(i==="isc")return"ISC";if(i==="unlicense")return"Unlicense";return}function ls(e){return B(e.frontmatterLicense)??B(e.packageJsonLicense)??yr(e.licenseFileText)}function qe(e){return Boolean(B(e))}var Q={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 be(e,t){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let i of e)be(i,t);return}let r=e;for(let[i,n]of Object.entries(r)){if(t.push(i),i==="type"&&n==="boolean")t.push("boolean-state");be(n,t)}}function hr(e){let t=[];return be(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
|
|
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:Q.states.test(r)?"verified":"missing",accessibility:Q.accessibility.test(r)?"verified":"missing","light-theme":Q["light-theme"].test(r)?"verified":"missing","dark-theme":Q["dark-theme"].test(r)?"verified":"missing",responsive:Q.responsive.test(r)?"verified":"missing"}}function br(e){return{source:"declared",license:qe(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 Cr(e){if(!ir.every((i)=>ne[e[i]]>=ne.verified))return"experimental";return or.every((i)=>e[i]==="external-consumer")?"recommended":"candidate"}function He(e){let t=JSON.stringify({schemaVersion:e.schemaVersion,resources:e.resources.map((n)=>({id:n.id,kind:n.kind,title:n.title,description:n.description,...n.category?{category:n.category}:{},tags:n.tags,aliases:n.aliases,capabilities:n.capabilities,dependencies:n.dependencies,source:n.source})),aliases:e.aliases}),r=0xcbf29ce484222325n,i=0x100000001b3n;for(let n of new TextEncoder().encode(t))r^=BigInt(n),r=BigInt.asUintN(64,r*i);return`fnv1a64:${r.toString(16).padStart(16,"0")}`}function Rr(e,t,r){let i=br(e),n=[`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 i["dependency-closure"]="verified",n.push(`resource://index/${e.id}`);if(t)for(let c of Y){if(c==="dependency-closure")continue;let l=t.checks[c];if(!l)continue;if(c==="source"&&ne[l.status]>=ne.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"&&!qe(t.provenance?.license)){a.push({code:"missing-license-metadata",resourceId:e.id,check:c,detail:"license evidence requires a concrete provenance.license"});continue}if(i[c]=l.status,n.push(...l.evidence),c==="source"&&t.provenance?.source)n.push(t.provenance.source)}let o=Cr(i),s={level:o==="recommended"?"external-consumer":o==="candidate"?"verified":"declared",maturity:o,checks:i,evidence:ze(n)};return Object.freeze(s.checks),Object.freeze(s.evidence),Object.freeze(s),Object.freeze(a),Object.freeze({resourceId:e.id,receipt:s,issues:a})}function us(e,t){let r=ur(e,t),i=pr(e),n=e.resources.map((c)=>Rr(c,r.records.get(c.id),i.get(c.id))),a=[...r.issues,...n.flatMap((c)=>c.issues)],o=Object.fromEntries(te.map((c)=>[c,0]));for(let c of n)o[c.receipt.maturity]+=1;Object.freeze(n),Object.freeze(o);for(let c of a)Object.freeze(c);Object.freeze(a);let s=Object.freeze({schemaVersion:he,indexFingerprint:He(e),resources:n,counts:o,issues:a});return Ue.add(s),s}function ps(e,t){if(!Ue.has(t))throw new $e;if(t.issues.length>0)throw new Ve(t.issues.length);let r=He(e);if(r!==t.indexFingerprint)throw new je(t.indexFingerprint,r);let i=new Map(t.resources.map((a)=>[a.resourceId,a.receipt])),n=e.resources.map((a)=>{let o=i.get(a.id);if(!o)return a;return Object.freeze({...a,receipt:o})});return Object.freeze(n),Object.freeze({schemaVersion:e.schemaVersion,resources:n,aliases:e.aliases})}var xr="uibot.resource.index.v1",fs=["invalid-resource-source-id","duplicate-resource-id","dangling-resource-dependency","ambiguous-resource-dependency"];class K extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceIndexError"}}function S(e,t){return e<t?-1:e>t?1:0}function C(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 kr(e){let t=C(e).replace(/ /g,"-");if(!t)throw new K("invalid-resource-source-id",e);return t}function T(e,t){return`${e}:${kr(t)}`}function oe(e){let t=new Map;for(let r of e){let i=r?.trim();if(!i)continue;let n=C(i);if(!n||t.has(n))continue;t.set(n,i)}return[...t.entries()].sort(([r],[i])=>S(r,i)).map(([,r])=>r)}function Z(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 Sr(e){let t=B(e.license);return{type:e.type,id:e.id,...e.version?{version:e.version}:{},...e.sourceHash?{sourceHash:e.sourceHash}:{},...e.packageName?{packageName:e.packageName}:{},...e.url?{url:e.url}:{},...t?{license:t}:{}}}function H(e){return{id:e.id,kind:e.kind,title:e.title,description:e.description,...e.category?{category:e.category}:{},tags:oe(e.tags),aliases:oe(e.aliases),capabilities:oe(e.capabilities),dependencies:[...new Set(e.dependencies)].sort(S),source:Sr(e.source),receipt:e.receipt,...e.solution?{solution:structuredClone(e.solution)}:{}}}function Ir(e){return(e.body.split(/\r?\n/).map((r)=>r.replace(/^#+\s*/,"").trim()).find(Boolean)??e.title).slice(0,240)}function Ar(e){if(e.solution){let t=(r)=>{if(r&&typeof r==="object"){for(let i of Object.values(r))t(i);Object.freeze(r)}};t(e.solution)}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 wr(e){let t=new Map;for(let r of Object.keys(e).sort(S)){let i=e[r];if(!i)continue;let n=T("component",r);for(let a of oe([r,i.name])){let o=C(a),s=t.get(o)??[];if(!s.includes(n))s.push(n);t.set(o,s.sort(S))}}return t}function Pr(e,t,r){let i=r.get(C(e))??[];if(i.length===0)throw new K("dangling-resource-dependency",`${t} -> ${T("component",e)}`);if(i.length>1)throw new K("ambiguous-resource-dependency",`${t} -> ${e}: ${i.join(",")}`);return i[0]}function vr(e,t,r,i){let n=e.startsWith("template:")?e.slice(9):e;if(Object.hasOwn(i,n))return T("template",n);return Pr(e,t,r)}function X(e,t,r){return B(r?.[e]??t)}function ys(e){return Object.entries(e).filter(([,t])=>t.level==="L4").sort(([t],[r])=>S(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:[T("template",t)]}))}function hs(e){let t=e.components??{},r=e.templates??{},i=e.designGuides??[],n=e.examples??[],a=e.skills??[],o=e.licenses,s=wr(t),c=[];for(let d of Object.keys(t).sort(S)){let m=t[d];if(!m)continue;let y=T("component",d),h=X(y,void 0,o);c.push(H({id:y,kind:"component",title:m.name,description:m.description,category:m.category,tags:m.tags??[],aliases:[d,m.name],capabilities:["catalog:component"],dependencies:[],source:{type:"catalog",id:d,...h?{license:h}:{}},receipt:Z(Boolean(h))}))}for(let d of Object.keys(r).sort(S)){let m=r[d];if(!m)continue;let y=T("template",d),h=X(y,void 0,o);c.push(H({id:y,kind:"template",title:m.name,description:m.description,category:m.category,tags:m.keywords,aliases:[d,m.name],capabilities:[],dependencies:(m.composedFrom??[]).map((A)=>vr(A,y,s,r)),source:{type:"template-contract",id:d,...h?{license:h}:{}},receipt:Z(Boolean(h))}))}for(let d of[...i].sort((m,y)=>S(m.id,y.id))){let m=T("design-guide",d.id),y=X(m,void 0,o);c.push(H({id:m,kind:"design-guide",title:d.title,description:Ir(d),category:d.category,tags:d.tags,aliases:[d.id,d.title],capabilities:["designMd:source"],dependencies:[],source:{type:"design-md",id:d.id,...d.sourceUrl?{url:d.sourceUrl}:{},...y?{license:y}:{}},receipt:Z(Boolean(y))}))}for(let d of[...n].sort((m,y)=>S(m.id,y.id))){let m=T("example",d.id),y=X(m,d.license,o);c.push(H({id:m,kind:"example",title:d.title,description:d.description,...d.category?{category:d.category}:{},tags:d.tags??[],aliases:[d.id,d.title,...d.aliases??[]],capabilities:d.capabilities??[],dependencies:d.dependencies??[],source:{type:"example",id:d.id,...d.version?{version:d.version}:{},...d.sourceUrl?{url:d.sourceUrl}:{},...y?{license:y}:{}},receipt:Z(Boolean(y))}))}for(let d of[...a].sort((m,y)=>S(m.id,y.id))){let m=T("skill",d.id),y=X(m,void 0,o);c.push(H({id:m,kind:"skill",title:d.title,description:d.description?.trim()||d.title,tags:[...d.tags??[],...d.triggers??[]],aliases:[d.id,d.title,...d.triggers??[]],capabilities:["skill:definition"],dependencies:[],source:{type:"skill",id:d.id,...d.version?{version:d.version}:{},...y?{license:y}:{}},receipt:Z(Boolean(y))}))}for(let d of e.additional??[])c.push(H(d));c.sort((d,m)=>S(d.id,m.id));let l=new Set;for(let d of c){if(l.has(d.id))throw new K("duplicate-resource-id",d.id);l.add(d.id)}for(let d of c)for(let m of d.dependencies)if(!l.has(m))throw new K("dangling-resource-dependency",`${d.id} -> ${m}`);let u=new Map;for(let d of c)for(let m of d.aliases){let y=C(m);if(!y)continue;let h=u.get(y)??new Set;h.add(d.id),u.set(y,h)}let f=Object.freeze(Object.fromEntries([...u.entries()].sort(([d],[m])=>S(d,m)).map(([d,m])=>[d,Object.freeze([...m].sort(S))]))),p=Object.freeze(c.map(Ar));return Object.freeze({schemaVersion:xr,resources:p,aliases:f})}var Er=[["chat","assistant","\u804A\u5929","\u52A9\u624B","\u5BF9\u8BDD"],["document","documents","\u6587\u6863","\u5199\u4F5C"],["auth","authentication","\u8BA4\u8BC1","\u767B\u5F55"],["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"]],Dr=Object.freeze(Er.map((e)=>Object.freeze([...e]))),Ke=new Map;for(let e of Dr){let t=Object.freeze([...new Set(e.map(C).filter(Boolean))].sort());for(let r of t)Ke.set(r,t)}function Ce(e){let t=C(e);return Ke.get(t)??Object.freeze([t])}var Ss=["resource-query-empty","resource-query-invalid-limit","resource-not-found","resource-alias-ambiguous"];class w extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceQueryError"}}var ke=Object.freeze({function:180,scenario:180,unit:180,industry:180,"exact-id":1000,"exact-title":900,alias:800,tag:600,capability:500,category:400,token:200,fuzzy:100}),Tr=Object.freeze(Object.keys(ke)),We=new Map(Tr.map((e,t)=>[e,t])),Ge=new Map([["component",0],["template",1],["design-guide",2],["example",3],["skill",4]]);function I(e,t){return e<t?-1:e>t?1:0}function Ye(e){return new Set((e??[]).map(C).filter(Boolean))}function j(e,t){let r=Ye(t);if(r.size===0)return!0;let i=Ye(e);return[...r].some((n)=>i.has(n))}function Or(e,t){if(!j(e.solution?.functions??[],t.functions))return!1;if(!j(e.solution?.scenarios??[],t.scenarios))return!1;if(!j(e.solution?[e.solution.unit]:[],t.units))return!1;if(!j(e.solution?.industries??[],t.industries))return!1;if(t.kinds?.length&&!t.kinds.includes(e.kind))return!1;if(!j(e.tags,t.tags))return!1;if(!j(e.category?[e.category]:[],t.categories))return!1;if(!j(e.capabilities,t.capabilities))return!1;if(t.maturities?.length&&!t.maturities.includes(e.receipt.maturity))return!1;return!0}function _r(e){return Boolean(e.functions?.length||e.scenarios?.length||e.units?.length||e.industries?.length||e.kinds?.length||e.tags?.length||e.categories?.length||e.capabilities?.length||e.maturities?.length)}function P(e,t,r,i=ke[t]){if(e.some((n)=>n.code===t&&n.value===r))return;e.push({code:t,value:r,score:i})}function Re(e,t){return e.find((r)=>C(r)===t)}function xe(e){return[e.id,e.title,...e.aliases,...e.tags,...e.category?[e.category]:[],...e.capabilities,...e.solution?.functions??[],...e.solution?.scenarios??[],...e.solution?.industries??[]]}function Fr(e,t,r){if(Math.abs(e.length-t.length)>r)return r+1;let i=Array.from({length:t.length+1},(n,a)=>a);for(let n=1;n<=e.length;n+=1){let a=[n],o=n;for(let s=1;s<=t.length;s+=1){let c=(i[s-1]??r+1)+(e[n-1]===t[s-1]?0:1),l=Math.min((i[s]??r+1)+1,(a[s-1]??r+1)+1,c);a.push(l),o=Math.min(o,l)}if(o>r)return r+1;i=a}return i[t.length]??r+1}function Je(e,t){let r=C(t),i=[];if(C(e.id)===r)P(i,"exact-id",e.id);if(C(e.title)===r)P(i,"exact-title",e.title);let n=Re(e.aliases,r);if(n)P(i,"alias",n);let a=Re(e.tags,r);if(a)P(i,"tag",a);let o=Re(e.capabilities,r);if(o)P(i,"capability",o);if(e.category&&C(e.category)===r)P(i,"category",e.category);if(!n){let l=Ce(r).filter((f)=>f!==r),u=new Set(xe(e).map(C));if(l.some((f)=>u.has(f)))P(i,"alias",t.trim())}let s=r.split(" ").filter(Boolean),c=C(xe(e).join(" "));if(s.length>0&&s.every((l)=>c.includes(l)))P(i,"token",t.trim());if(i.length===0&&r.length>=4){let l;for(let u of xe(e)){let f=C(u);if(f.length<4)continue;let p=Fr(r,f,2);if(p<=2&&(!l||p<l.distance||p===l.distance&&I(u,l.value)<0))l={value:u,distance:p}}if(l)P(i,"fuzzy",l.value,ke.fuzzy-l.distance)}return i.sort((l,u)=>{if(l.score!==u.score)return u.score-l.score;return(We.get(l.code)??99)-(We.get(u.code)??99)||I(l.value,u.value)})}function Qe(e,t,r){if(t.has(r))return[r];let i=C(r),n=e.aliases[i];if(n?.length)return[...n];let a=new Set;for(let o of Ce(i))for(let s of e.aliases[o]??[])a.add(s);return[...a].sort(I)}function Ze(e,t){return new w("resource-alias-ambiguous",`${e.trim()}: ${t.join(",")}`)}function Xe(e){let t=new Map(e.resources.map((i)=>[i.id,i]));function r(i){let n=i.trim(),a=Qe(e,t,n);if(a.length===0)throw new w("resource-not-found",n);if(a.length>1)throw Ze(n,a);let o=a[0],s=o?t.get(o):void 0;if(!s)throw new w("resource-not-found",n);return s}return Object.freeze({manifest:()=>e,search(i){let n=i.text?.trim()??"";if(!n&&!_r(i))throw new w("resource-query-empty","text or filter is required");if(i.limit!==void 0&&(!Number.isInteger(i.limit)||i.limit<=0))throw new w("resource-query-invalid-limit",String(i.limit));let a=e.resources.filter((o)=>Or(o,i)).filter((o)=>!n||Je(o,n).length>0).map((o)=>{let s=n?Je(o,n):[];for(let[c,l]of[[i.functions,"function"],[i.scenarios,"scenario"],[i.units,"unit"],[i.industries,"industry"]])if(c?.length)P(s,l,c.join(","));return{resource:o,score:s.reduce((c,l)=>c+l.score,0),reasons:s}}).filter((o)=>!n||o.reasons.length>0).sort((o,s)=>s.score-o.score||I(o.resource.id,s.resource.id));return i.limit===void 0?a:a.slice(0,i.limit)},get:r,build(i){if(i.length===0||i.every((p)=>!p.trim()))throw new w("resource-query-empty","at least one build root is required");let n=[],a=new Set;for(let p of i){let d=p.trim(),m=Qe(e,t,d);if(m.length===0)n.push({id:d,reason:"missing-resource"});else if(m.length>1)throw Ze(d,m);else{let y=m[0];if(y)a.add(y)}}let o=new Set,s=new Set,c=new Set,l=[],u=[],f=(p,d)=>{if(o.has(p))return;if(s.has(p)){n.push({id:p,...d?{requiredBy:d}:{},reason:"dependency-cycle"});return}let m=t.get(p);if(!m){n.push({id:p,...d?{requiredBy:d}:{},reason:"missing-resource"});return}s.add(p),c.add(p);let y=[...m.dependencies].sort((h,A)=>{let N=t.get(h),_=t.get(A);return(Ge.get(N?.kind??"")??99)-(Ge.get(_?.kind??"")??99)||I(h,A)});for(let h of y)u.push({from:p,to:h,relation:"depends-on"}),f(h,p);s.delete(p),o.add(p),l.push(p)};for(let p of[...a].sort(I))f(p);return{roots:[...a].sort(I),nodes:[...c].sort(I).map((p)=>{let d=t.get(p);if(!d)throw new w("resource-not-found",p);return{id:p,kind:d.kind,maturity:d.receipt.maturity}}),edges:u.sort((p,d)=>I(p.from,d.from)||I(p.to,d.to)),order:l,gaps:n.sort((p,d)=>I(p.id,d.id)||I(p.requiredBy??"",d.requiredBy??"")||I(p.reason,d.reason))}}})}function Mr(e){if(!e||typeof e!=="object")throw Error("invalid-public-resource-bundle");jr(e);let t=e;if(t.schemaVersion!=="uibot.public-resources.v1"||typeof t.release?.version!=="string"||!/^[a-f0-9]{64}$/.test(t.release?.sourceHash)||t.index?.schemaVersion!=="uibot.resource.index.v1"||!Array.isArray(t.index.resources)||!t.index.aliases||!t.showcases)throw Error("invalid-public-resource-bundle");if(t.documents&&(!Array.isArray(t.documents)||t.documents.some((n)=>typeof n.title!=="string"||typeof n.markdown!=="string"||!/^\/(?:en\/)?docs\/[a-z0-9-]+$/.test(n.path))))throw Error("invalid-public-documentation");let r=new Set,i=new Set;for(let n of t.index.resources){if(!n||typeof n.id!=="string"||r.has(n.id)||!De.includes(n.kind)||!n.id.startsWith(`${n.kind}:`)||typeof n.description!=="string"||typeof n.title!=="string"||!Array.isArray(n.dependencies)||!n.source||!n.receipt||!Array.isArray(n.aliases)||!Array.isArray(n.tags)||!Array.isArray(n.capabilities)||![n.aliases,n.dependencies,n.tags,n.capabilities].every((o)=>o.every((s)=>typeof s==="string"&&s.length<=1000))||!["catalog","template-contract","design-md","example","skill","registry","package","theme"].includes(n.source.type)||typeof n.source.id!=="string"||n.source.sourceHash!==void 0&&!/^[a-f0-9]{64}$/.test(n.source.sourceHash)||n.source.packageName!==void 0&&(typeof n.source.packageName!=="string"||!n.source.packageName.startsWith("@uibot/"))||!te.includes(n.receipt.maturity)||!Te.includes(n.receipt.level)||!Array.isArray(n.receipt.evidence)||!n.receipt.evidence.every((o)=>typeof o==="string")||!Y.every((o)=>re.includes(n.receipt.checks?.[o])))throw Error("invalid-public-resource");if(r.add(n.id),n.solution){let o=n.solution;if(![o.functions,o.scenarios,o.industries,o.hostRequirements,o.limitations].every((s)=>Array.isArray(s)&&s.every((c)=>typeof c==="string"&&c.length>0&&c.length<=2000))||!["page","flow","industry"].includes(o.unit)||!["interactive-demo","needs-enhancement"].includes(o.readiness)||o.members!==void 0&&(!Array.isArray(o.members)||o.members.some((s)=>typeof s.resourceId!=="string"||typeof s.version!=="string"||!s.version||s.sourceHash!==void 0&&(typeof s.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(s.sourceHash)))))throw Error("invalid-resource-solution")}let a=t.showcases[n.id];if(!a||a.resourceId!==n.id||typeof a.docs?.zh!=="string"||typeof a.docs?.en!=="string"||!Array.isArray(a.examples)||!Array.isArray(a.distributions))throw Error("invalid-resource-showcase");if(a.collection!==void 0){let o=a.collection;if(!o||typeof o.id!=="string"||!/^[a-z0-9-]+$/.test(o.id)||typeof o.group?.id!=="string"||!/^[a-z0-9-]+$/.test(o.group.id)||[o.title,o.group.title].some((s)=>!s||[s.zh,s.en].some((c)=>typeof c!=="string"||!c.trim()||c.length>200)))throw Error("invalid-resource-collection")}if(a.agentKit!==void 0){let o=a.agentKit;if(i.has(n.source?.id))throw Error("invalid-resource-agent-kit");if(i.add(n.source?.id),!o||!["skill","prompt","recipe"].includes(o.type)||(o.type==="skill"?n.kind!=="skill":n.kind!=="example")||!/^[a-z][a-z0-9-]*$/.test(n.source.id)||o.fileName!=={skill:"SKILL.md",prompt:"PROMPT.md",recipe:"RECIPE.md"}[o.type]||[o.summary?.zh,o.summary?.en].some((s)=>typeof s!=="string"||!s.trim())||!Array.isArray(o.resources)||new Set(o.resources.map((s)=>s?.id)).size!==o.resources.length||o.resources.some((s)=>!s||!n.dependencies.includes(s.id)||!t.index.resources.some((c)=>c.id===s.id&&(c.source.version??null)===s.version)||s.version!==null&&(typeof s.version!=="string"||!s.version)||typeof s.contentHash!=="string"||!/^[a-f0-9]{64}$/.test(s.contentHash)||s.sourceHash!==void 0&&(typeof s.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(s.sourceHash)))||o.resources.length!==n.dependencies.length)throw Error("invalid-resource-agent-kit")}if(a.solutionControls!==void 0){let o=new Set;if(!Array.isArray(a.solutionControls)||a.solutionControls.some((s)=>{if(!s||typeof s.id!=="string"||o.has(s.id)||typeof s.label?.zh!=="string"||typeof s.label?.en!=="string"||!Array.isArray(s.values)||!s.values.length||s.values.some((c)=>!["string","boolean","number"].includes(typeof c)||typeof c==="number"&&!Number.isFinite(c))||typeof s.target?.pageId!=="string"||typeof s.target?.property!=="string"||["__proto__","prototype","constructor"].includes(s.target.property)||s.target.blockId!==void 0&&typeof s.target.blockId!=="string")return!0;return o.add(s.id),!1}))throw Error("invalid-solution-controls")}if(a.templateContract&&(a.templateContract.name!==n.source.id||typeof a.templateContract.description!=="string"||!["L3","L4","L5"].includes(a.templateContract.level)||!["feature","template","page","app"].includes(a.templateContract.category)||!Array.isArray(a.templateContract.keywords)))throw Error("invalid-public-template-contract");if(typeof a.title?.zh!=="string"||typeof a.title?.en!=="string"||a.examples.some((o)=>!o||typeof o.id!=="string"||typeof o.title!=="string"||typeof o.code!=="string"||!["spec","tsx","source"].includes(o.mode)||!["tsx","json","yaml","css","ts"].includes(o.language)||!Array.isArray(o.dependencies)||!o.dependencies.every((s)=>typeof s==="string"))||a.distributions.some((o)=>!o||!["spec","npm","shadcn"].includes(o.channel)||typeof o.name!=="string"||!/^[@a-zA-Z0-9._/-]+$/.test(o.name)||typeof o.version!=="string"||!["source","published"].includes(o.availability)))throw Error("invalid-resource-content")}for(let[n,a]of Object.entries(t.index.aliases))if(!n||!Array.isArray(a)||a.some((o)=>!r.has(o)))throw Error("invalid-public-resource-alias");if(Object.keys(t.showcases).some((n)=>!r.has(n)))throw Error("unexpected-public-resource-showcase");for(let n of t.index.resources)for(let a of n.dependencies)if(!r.has(a))throw Error("invalid-public-resource-dependency");if(t.distributionSnapshot){let n=t.distributionSnapshot;if(!/^[a-f0-9]{64}$/.test(n.snapshotId)||n.manifestPath!==`../snapshots/${n.snapshotId}/snapshot.json`||!n.resources||!n.unavailable||!n.external||Object.entries(n.external).some(([a,o])=>!Object.hasOwn(n.unavailable,a)||!Array.isArray(o)||o.some((s)=>typeof s!=="string"||s.startsWith("@uibot/"))))throw Error("invalid-distribution-snapshot-reference");for(let[a,o]of Object.entries(n.resources))if(!r.has(a)||o.version!==(t.index.resources.find((s)=>s.id===a)?.source.version??t.release.version)||!/^[a-f0-9]{64}$/.test(o.resourceHash)||!Array.isArray(o.entrypoints)||!o.entrypoints.length||!Array.isArray(o.closure)||![...o.entrypoints,...o.closure].every((s)=>/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(s))||o.entrypoints.some((s)=>!o.closure.includes(s)))throw Error("invalid-distribution-snapshot-resource")}}function vs(e){Mr(e),e=JSON.parse(JSON.stringify(e));let t=(n)=>{if(n&&typeof n==="object"){for(let a of Object.values(n))t(a);Object.freeze(n)}};t(e);let r=Xe(e.index),i=(n)=>{let a=r.get(n),o=e.showcases[a.id];if(!o)throw new w("resource-not-found",a.id);return o};return Object.freeze({...r,get(n){let a=r.get(n),o=i(n).agentKit;return o?Object.freeze({...a,agentKit:o}):a},docs(n,a="zh",o=1){if(a!=="zh"&&a!=="en")throw Error("unsupported-resource-locale");let s=i(n);return{resourceId:s.resourceId,locale:a,...Lr(s.docs[a],o),release:e.release}},examples(n,a=1){let o=i(n);return{resourceId:o.resourceId,...Br(o.examples,a),release:e.release}},installPlan(n){let a=i(n);return{resourceId:a.resourceId,distributions:a.distributions,dependencies:r.build([a.resourceId]),release:e.release,snapshot:e.distributionSnapshot&&Object.hasOwn(e.distributionSnapshot.resources,a.resourceId)?{snapshotId:e.distributionSnapshot.snapshotId,manifestPath:e.distributionSnapshot.manifestPath,...e.distributionSnapshot.resources[a.resourceId]}:null,snapshotUnavailable:e.distributionSnapshot?.unavailable[a.resourceId]??null,install:a.distributions.map((o)=>Nr(o,e.distributionSnapshot,a.resourceId))}}})}function Nr(e,t,r){let{channel:i,name:n,version:a}=e;if(i==="npm")return{channel:i,name:n,command:`add ${n}@${a}`,note:null};if(i==="spec")return{channel:i,name:n,command:null,note:"Read the Spec through examples and compile it strictly with the matching Catalog."};let o=!!t&&Object.hasOwn(t.resources,r),s=t?.external[r]??[];return{channel:i,name:n,command:`shadcn add @uibot/${n}`,registries:{"@uibot":"/r/{name}.json"},externalRegistryDependencies:s,note:o?"A hash-pinned snapshot exists: export and verify it, then map @uibot to the local snapshot server.":s.length?`No hash-pinned snapshot: the install also pulls stock shadcn items (${s.join(", ")}) from the host's default registry. Installing through the portal mapping still works; report the files as not snapshot-verified.`:"No hash-pinned snapshot; report the files as not snapshot-verified."}}var M=24000;function et(e,t){if(!Number.isSafeInteger(e)||e<1||e>Math.max(1,t))throw new w("resource-query-invalid-limit","page is outside the available range")}function Lr(e,t){let r=Math.max(1,Math.ceil(e.length/M));return et(t,r),{markdown:e.slice((t-1)*M,t*M),page:t,totalPages:r,...t<r?{nextPage:t+1}:{}}}function Br(e,t){let r=e.flatMap((i)=>Array.from({length:Math.max(1,Math.ceil(i.code.length/M))},(n,a)=>({...i,code:i.code.slice(a*M,(a+1)*M),codeOffset:a*M,codeLength:i.code.length,complete:i.code.length<=M})));return et(t,r.length),{examples:r.slice(t-1,t),page:t,totalPages:r.length,...t<r.length?{nextPage:t+1}:{}}}function jr(e){let t=0,r=0,i=new Set,n=(a,o)=>{if(++t>300000||o>64)throw Error("public-resource-budget-exceeded");if(typeof a==="string"){if(r+=new TextEncoder().encode(a).length,r>16777216)throw Error("public-resource-budget-exceeded")}else if(a&&typeof a==="object"){if(i.has(a))throw Error("invalid-public-resource-cycle");let s=Object.getPrototypeOf(a);if(!Array.isArray(a)&&s!==Object.prototype&&s!==null)throw Error("invalid-public-resource-object");i.add(a);for(let[c,l]of Object.entries(a))n(c,o+1),n(l,o+1);i.delete(a)}else if(a!==null&&typeof a!=="boolean"&&(typeof a!=="number"||!Number.isFinite(a)))throw Error("invalid-public-resource-json")};n(e,1)}import{createHash as Vr}from"crypto";var le=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,se=/^[a-f0-9]{64}$/,ae=/^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/,tt=new TextEncoder,$r=new TextDecoder("utf-8",{fatal:!0});function de(e){return Vr("sha256").update(e).digest("hex")}function V(e){let t=0,r=(n,a)=>{if(++t>400000||a>32)throw Error("snapshot-json-budget-exceeded");if(Array.isArray(n))return n.map((o)=>r(o,a+1));if(n&&typeof n==="object"){if(Object.getPrototypeOf(n)!==Object.prototype)throw Error("snapshot-invalid-json");return Object.fromEntries(Object.keys(n).sort().map((o)=>[o,r(n[o],a+1)]))}if(n===null||typeof n==="string"||typeof n==="boolean"||typeof n==="number"&&Number.isFinite(n))return n;throw Error("snapshot-invalid-json")},i=JSON.stringify(r(e,0));if(tt.encode(i).length>16777216)throw Error("snapshot-json-budget-exceeded");return i}function ce(e){if(typeof e!=="string"||!/^[a-zA-Z0-9_./-]+$/.test(e)||e.split("/").some((t)=>!t||t==="."||t==="..")||e.startsWith("/"))throw Error(`snapshot-unsafe-path: ${e}`)}function Se(e,t){return ce(e),{path:e,bytes:t.byteLength,sha256:de(t)}}function Ur(e){if(typeof e!=="string"||!e.startsWith("@uibot/")||!le.test(e.slice(7)))throw Error(`snapshot-external-registry-dependency: ${e}`);return e.slice(7)}function rt(e,t){if(!le.test(e)||t.byteLength>16777216)throw Error("snapshot-invalid-item");let r=JSON.parse($r.decode(t));if(r.name!==e||!Array.isArray(r.files)||r.files.length>2000||(r.devDependencies?.length??0)>0)throw Error(`snapshot-invalid-item: ${e}`);let i={};for(let s of r.dependencies??[]){let c=s.lastIndexOf("@"),l=s.slice(0,c),u=s.slice(c+1);if(c<1||!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(l)||!ae.test(u)||i[l]&&i[l]!==u)throw Error(`snapshot-unpinned-npm-dependency: ${s}`);i[l]=u}let n=[...new Set((r.registryDependencies??[]).map(Ur))].sort(),a=new Set,o=r.files.map((s)=>{if(typeof s.content!=="string")throw Error(`snapshot-missing-file-content: ${e}`);let c=s.target??s.path;if(ce(c),a.has(c))throw Error(`snapshot-duplicate-target: ${c}`);return a.add(c),{...Se(s.path,tt.encode(s.content)),target:c}});return{...Se(`r/${e}.json`,t),registryDependencies:n,npmDependencies:i,files:o}}function nt(e,t){let r=new Set,i=new Set,n=(s)=>{if(!le.test(s)||!Object.hasOwn(e,s))throw Error(`snapshot-missing-item: ${s}`);if(i.has(s))throw Error(`snapshot-dependency-cycle: ${s}`);if(r.has(s))return;i.add(s);for(let c of e[s].registryDependencies)n(c);i.delete(s),r.add(s)};if(!t.length)throw Error("snapshot-empty-entrypoints");t.forEach(n);let a=new Map,o=new Map;for(let s of r){for(let c of e[s].files){let l=a.get(c.target);if(l&&l!==c.sha256)throw Error(`snapshot-target-conflict: ${c.target}`);a.set(c.target,c.sha256)}for(let[c,l]of Object.entries(e[s].npmDependencies)){if(o.has(c)&&o.get(c)!==l)throw Error(`snapshot-npm-conflict: ${c}`);o.set(c,l)}}return[...r].sort()}function Ts(e){let t=Object.fromEntries(Object.entries(e.items).map(([a,o])=>[a,rt(a,o)])),r=Object.fromEntries(Object.entries(e.resources).map(([a,o])=>[a,{...o,closure:nt(t,o.entrypoints)}])),i={schemaVersion:"uibot.distribution.snapshot.v1",bundleHash:e.bundleHash,version:e.version,namespace:"@uibot",resources:r,items:t,license:"MIT AND ISC",licenseFiles:Object.entries(e.licenseFiles).sort(([a],[o])=>a.localeCompare(o)).map(([a,o])=>Se(a,o))},n={...i,snapshotId:de(V(i))};return it(n),n}function it(e,t){if(!e||typeof e!=="object")throw Error("snapshot-invalid-manifest");V(e);let r=e,{snapshotId:i,...n}=r;if(r.schemaVersion!=="uibot.distribution.snapshot.v1"||r.namespace!=="@uibot"||r.license!=="MIT AND ISC"||!ae.test(r.version)||!se.test(r.bundleHash)||!se.test(i)||t!==void 0&&t!==i||de(V(n))!==i)throw Error("snapshot-identity-mismatch");if(!r.items||!r.resources||!Array.isArray(r.licenseFiles)||!r.licenseFiles.length)throw Error("snapshot-invalid-manifest");let a=(s)=>{if(ce(s.path),!se.test(s.sha256)||!Number.isSafeInteger(s.bytes)||s.bytes<0||s.bytes>16777216)throw Error("snapshot-invalid-file-digest")},o=new Set;for(let s of r.licenseFiles){if(a(s),!s.path.startsWith("licenses/")||o.has(s.path))throw Error("snapshot-invalid-license");o.add(s.path)}for(let[s,c]of Object.entries(r.items)){if(a(c),!le.test(s)||c.path!==`r/${s}.json`||!Array.isArray(c.registryDependencies)||!Array.isArray(c.files)||!c.npmDependencies)throw Error("snapshot-invalid-item");for(let l of c.files)a(l),ce(l.target);for(let[l,u]of Object.entries(c.npmDependencies))if(!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(l)||!ae.test(u))throw Error("snapshot-unpinned-npm-dependency")}for(let s of Object.values(r.resources))if(!ae.test(s.version)||!se.test(s.resourceHash)||!Array.isArray(s.entrypoints)||V(nt(r.items,s.entrypoints))!==V(s.closure))throw Error("snapshot-resource-closure-mismatch")}function Os(e,t,r,i){it(e,i);let n=Object.hasOwn(e.resources,t)?e.resources[t]:void 0;if(!n)throw Error(`snapshot-resource-unavailable: ${t}`);let a=(s)=>{let c=r.get(s.path);if(!c||c.byteLength!==s.bytes||de(c)!==s.sha256)throw Error(`snapshot-file-mismatch: ${s.path}`);return c},o={};for(let s of n.closure){let c=e.items[s],l=rt(s,a(c));if(V(l)!==V(c))throw Error(`snapshot-item-metadata-mismatch: ${s}`);Object.assign(o,c.npmDependencies)}return e.licenseFiles.forEach(a),{snapshotId:e.snapshotId,resourceId:t,closure:[...n.closure],npmDependencies:o}}function Gr(e){if(!e.name)throw Error("Artifact registry manifest requires a name");return e}function Yr(e){if(!e.name)throw Error("Plugin distribution manifest requires a name");return e}class Jr{id;priority;items;constructor(e,t,r){this.id=e;this.priority=t;this.items=r}get(e){return this.items[e]}}class Qr{id;priority;items;constructor(e,t,r){this.id=e;this.priority=t;this.items=r}get(e){return this.items[e]}}async function lt(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 Zr(e,t){let r=e.endsWith("/registry.json")?e:`${e.replace(/\/$/,"")}/registry.json`,i=await lt(r,t);return Gr(i)}async function Xr(e,t){let r=e.endsWith("/plugins.json")?e:`${e.replace(/\/$/,"")}/plugins.json`,i=await lt(r,t);return Yr(i)}class en{options;id;priority;manifestPromise;constructor(e){this.options=e;this.id=e.id??e.registryUrl,this.priority=e.priority}getManifest(){return this.manifestPromise??=Zr(this.options.registryUrl,this.options.headers),this.manifestPromise}async get(e){return(await this.getManifest()).items.find((r)=>r.name===e)}}class tn{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()).plugins.find((r)=>r.pluginId===e)}}class rn{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((r,i)=>r.priority-i.priority);for(let r of t){let i=await r.get(e);if(i)return i}return}}class nn{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((r,i)=>r.priority-i.priority);for(let r of t){let i=await r.get(e);if(i)return i}return}}var on="uibot.artifacts.lock.json";function sn(e){return O(e,"components","registry")}function an(e){return O(e,"templates","registry")}function cn(e,t){if(e.kind==="component")return O(t.componentsDir??sn(t.workspaceRoot));return O(t.templatesDir??an(t.workspaceRoot))}function ln(e){return O(e.workspaceRoot,e.lockfilePath??on)}function dn(e){try{return JSON.parse(qr(e,"utf8"))}catch{return{version:1,artifacts:[]}}}function un(e,t){at(Ie(e),{recursive:!0}),ct(e,`${JSON.stringify(t,null,2)}
|
|
15
|
-
`,"utf8")}function pn(e,t){return{version:1,artifacts:[...e.artifacts.filter((i)=>i.name!==t.name),t].sort((i,n)=>i.name.localeCompare(n.name))}}function gn(e){if(e.kind==="component")return{components:{[e.name]:e.catalogEntry}};return{templates:{[e.name]:e.templateContract}}}class U 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 dt(e,t){let r=t.endsWith(ot)?t:t+ot;return e===t||e.startsWith(r)}function st(e){let t=O(e),r=[];while(!0)try{return zr(t),O(Hr(t),...r)}catch(i){if(i.code!=="ENOENT")throw i;let n=Ie(t);if(n===t)throw i;r.unshift(Kr(t)),t=n}}function ut(e,t,r,i){try{let n=st(t),a=st(e);if(!dt(a,n))throw new U(r,i,t)}catch(n){if(n instanceof U)throw n;throw new U(r,i,t)}}function pt(e,t,r){if(e.includes("\x00"))throw new U(r,e,t);if(Wr(e))throw new U(r,e,t);let i=O(t,e);if(!dt(i,t))throw new U(r,e,t);return ut(i,t,r,e),i}function mn(e,t){let r=[];for(let i of e.files){let n=i.target??i.path;r.push(pt(n,t,e.name))}return r}function Ns(e,t){let r=O(t.workspaceRoot),i=cn(e,t);ut(i,r,e.name,i);let n=pt(e.name,i,e.name),a=mn(e,n),o=[];for(let f=0;f<e.files.length;f++){let p=e.files[f],d=a[f];at(Ie(d),{recursive:!0}),ct(d,p.content??"","utf8"),o.push(d)}let s={name:e.name,version:e.version,source:t.source??"registry",installedAt:new Date().toISOString()},c=ln(t),l=dn(c),u=pn(l,s);return un(c,u),{artifactLock:s,catalogPatch:gn(e),writtenFiles:o}}export{U as ArtifactContainmentError,rn as ArtifactRegistryResolver,Jr as MemoryArtifactRegistrySource,Qr as MemoryPluginRegistrySource,nn as PluginRegistryResolver,cs as RESOURCE_ADMISSION_ERROR_CODES,he as RESOURCE_ADMISSION_SCHEMA_VERSION,or as RESOURCE_EXTERNAL_CHECKS,fs as RESOURCE_INDEX_ERROR_CODES,xr as RESOURCE_INDEX_SCHEMA_VERSION,ir as RESOURCE_PREFLIGHT_CHECKS,Dr as RESOURCE_QUERY_ALIAS_GROUPS,Ss as RESOURCE_QUERY_ERROR_CODES,Vt as RESOURCE_QUERY_OPERATION_MANIFEST,ke as RESOURCE_QUERY_SCORE_WEIGHTS,en as RemoteArtifactRegistrySource,tn as RemotePluginRegistrySource,je as ResourceAdmissionIndexMismatchError,$e as ResourceAdmissionReportNotDerivedError,Ve as ResourceAdmissionReportRejectedError,K as ResourceIndexError,w as ResourceQueryError,ns as SHADCN_REGISTRY_ITEM_SCHEMA,fe as UIBOT_BASE_ITEM,_e as UIBOT_THEME_ITEM,ps as applyResourceAdmissionReport,ce as assertDistributionPath,it as assertDistributionSnapshot,pt as assertPathContained,Mr as assertPublicResourceBundle,us as assessResourceAdmissions,ys as buildExamplesFromL4Templates,hs as buildResourceIndex,rs as buildShadcnRegistry,An as buildUiBotRegistryManifest,Yt as catalogEntryToMeta,Cn as collectAllBlockSources,St as collectBlockSources,Pe as collectTemplateSources,Dt as collectTemplateSourcesFromDirs,mt as compareLockToManifest,Ts as createDistributionSnapshot,vs as createPublicResourceQueryService,Xe as createResourceQueryService,os as createUIBotRegistryHttpHandler,ls as deriveResourceLicense,rt as describeDistributionItem,V as distributionCanonicalJson,nt as distributionClosure,de as distributionSha256,wn as emitArtifactJson,yt as emptyLockfile,ds as evaluateCatalogPreflight,Ce as expandResourceQueryAliases,Zr as fetchArtifactRegistryManifest,Xr as fetchPluginDistributionManifest,Ns as installArtifactToWorkspace,ht as lockfileWith,nr as normalizeRegistryBasePath,C as normalizeResourceAlias,B as normalizeResourceLicense,ts as parseOklchCssVars,Yr as parsePluginDistributionManifest,Gr as parseRegistryManifest,He as resourceAdmissionIndexFingerprint,Ur as snapshotDependencyName,ge as templateSourceToRegistryItem,Ee as toArtifactRegistryItem,Nt as toComponentArtifact,ye as toItemName,T as toResourceId,ve as toTemplateArtifact,Fe as transformBlockSource,Os as verifyDistributionSnapshot};
|
|
10
|
+
`}function Ar(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 Dc(e){return{light:Ht(e,":root"),dark:Ht(e,".dark")}}function Ht(e,t){let n={},o=new RegExp(`${Kt(t)}\\s*\\{`,"g"),r;while((r=o.exec(e))!==null){let a=r.index+r[0].length,s=1,i=a;for(;i<e.length&&s>0;i++){let l=e[i];if(l==="{")s++;else if(l==="}")s--}let c=e.slice(a,i-1);for(let l of c.matchAll(/--([\w-]+)\s*:\s*([^;]+);/g)){let d=l[1],u=l[2];if(d!==void 0&&u!==void 0)n[d]=u.trim()}}return n}function Kt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Oc(e,t){let n=t.sharedDependencies??wr,o=t.channel??"public",r=Dr(t),a=(t.componentsDir??Sr).replace(/\/$/,""),s=(t.libDir??Ir).replace(/\/$/,""),i=`${s}/uibot-renderer.ts`,c=`${s}/utils.ts`,l=`${s}/uibot-contracts.ts`,d="@/lib/uibot-renderer",u="@/lib/utils",g="@/lib/uibot-contracts",p={},f={name:rt,type:"registry:lib",description:"UIBot runtime base: RendererComponent type shim + cn util. Pulled automatically by every UIBot block.",dependencies:n,files:[{path:i,content:t.rendererShimContent,type:"registry:lib"},{path:c,content:t.cnUtilContent,type:"registry:lib"},...t.contractsShimContent?[{path:l,content:t.contractsShimContent,type:"registry:lib"}]:[]],meta:{base:!0}};if(p[rt]=f,t.cssVars)p[Ut]={name:Ut,type:"registry:theme",description:"UIBot OKLCH palette for the semantic tokens the blocks use. Optional: skip it when the host defines its own.",files:[],cssVars:t.cssVars};let m=new Map,h=new Map,x=new Map,k=new Map;for(let y of e){let T=y.files[0]?.path??`${ot(y.name)}.tsx`,v=y.channel??"public",I=k.get(T);if(I&&I!==v)throw Error(`${T} mixes ${I} and ${v} blocks; split the file`);k.set(T,v)}for(let y of e){if((y.channel??"public")!==o)continue;let v=y.files[0]?.path??`${ot(y.name)}.tsx`,I=m.get(v);if(!I){let P=ot($r(v,y.name)),ee=zt(y,{rendererShimImport:"@/lib/uibot-renderer",cnUtilImport:"@/lib/utils",...t.contractsShimContent?{contractsShimImport:"@/lib/uibot-contracts"}:{}}),G=`${a}/${P}.tsx`,he={schema:Ze,item:P,channel:o,components:[]};x.set(P,he),I={name:P,type:"registry:ui",description:y.description??y.catalogEntry.description,dependencies:["react",...y.dependencies??[]],registryDependencies:[r(rt)],files:y.files.length<=1?[{path:G,target:G,content:ee,type:"registry:ui"}]:y.files.map((ye)=>{if(typeof ye.content!=="string")throw Error(`Missing block source content: ${ye.path}`);let Rt=`${a}/${ye.path.replace(/^blocks\//,"")}`;return{path:Rt,target:Rt,content:zt({...y,sourceCode:Nr(ye.path,ye.content,y)},{rendererShimImport:"@/lib/uibot-renderer",cnUtilImport:"@/lib/utils",...t.contractsShimContent?{contractsShimImport:"@/lib/uibot-contracts"}:{}}),type:"registry:ui"}}),meta:{...Ar(y.catalogEntry),provides:[y.name],uibot:he}},m.set(v,I),p[P]=I}else{let P=I.meta;if(P.provides&&!P.provides.includes(y.name))P.provides.push(y.name)}let R=x.get(I.name);if(R?.components&&!h.has(y.name))R.components.push(Or(y,I,a)),h.set(y.name,I.name)}for(let[y,T]of x){let v=p[y];if(!v)continue;T.components?.sort((R,P)=>R.name.localeCompare(P.name));let I=`${a}/${y}.uibot.json`;v.files.push({path:I,target:I,content:`${JSON.stringify(T,null,2)}
|
|
11
|
+
`,type:"registry:ui"})}let b={},C=(t.templates??[]).filter((y)=>(y.channel??"public")===o),E=new Set(C.map((y)=>y.name));for(let y of C){if(p[y.name])throw Error(`template item "${y.name}" collides with a component item`);let T=y.templateContract.composedFrom??[],v=new Set,I=[];for(let G of T){let he=h.get(G);if(he)v.add(r(he));else if(E.has(G)&&G!==y.name)v.add(r(G));else I.push(G)}if(I.length>0)b[y.name]=I;let R=`${s}/${Pr}`,P=`${y.name}.uibot.yaml`,ee={schema:Ze,item:y.name,channel:o,template:{file:P,contract:y.templateContract}};p[y.name]={name:y.name,type:"registry:block",description:y.description,registryDependencies:[...v].sort(),files:[{path:`${R}/${P}`,target:`${R}/${P}`,content:y.yaml,type:"registry:lib"},{path:`${R}/${y.name}.uibot.json`,target:`${R}/${y.name}.uibot.json`,content:`${JSON.stringify(ee,null,2)}
|
|
12
|
+
`,type:"registry:lib"}],meta:{uibot:ee}}}return Er(p,t.composites??[],{channel:o,ref:r,componentsDir:a}),{registry:{$schema:vr,name:t.registryName,...t.homepage?{homepage:t.homepage}:{},items:Object.values(p).map((y)=>({name:y.name,type:y.type,...y.description?{description:y.description}:{},...y.registryDependencies?{registryDependencies:y.registryDependencies}:{},...y.dependencies?{dependencies:y.dependencies}:{}}))},items:p,unresolvedTemplateTypes:b}}function Er(e,t,n){let o=new Map;for(let r of t){if(o.has(r.name)||e[r.name])throw Error(`composite item "${r.name}" collides with another item`);o.set(r.name,r)}for(let r of t){let a=r.channel??"public",s=qt(r),i=new Set(r.files.map((l)=>l.path));for(let l of r.requires??[]){let d=o.get(l);if(!d)throw Error(`composite "${r.name}" requires unknown "${l}"`);if((d.channel??"public")!==a)throw Error(`composite "${r.name}" (${a}) requires "${l}" from another channel`);if(qt(d)!==s)throw Error(`composite "${r.name}" requires "${l}" from another directory`);for(let u of d.files)i.add(u.path)}for(let l of r.files){if(!Wt.test(l.path))throw Error(`composite "${r.name}" file "${l.path}" must be a plain relative path`);for(let d of Tr(l.content)){if(!d.startsWith("./")||d.includes("/../"))throw Error(`${r.name}/${l.path} imports ${d}; only ./ imports within the item directory are allowed`);let u=d.slice(2).replace(/\.js$/,"");if(![u,`${u}.ts`,`${u}.tsx`,`${u}/index.ts`,`${u}/index.tsx`].some((p)=>i.has(p)))throw Error(`${r.name}/${l.path} imports ${d}, which no required item ships`)}}if(a!==n.channel)continue;let c=r.files.map((l)=>{let d=`${n.componentsDir}/${s}/${l.path}`;return{path:d,target:d,content:l.content,type:l.path.endsWith(".tsx")?"registry:component":"registry:lib"}});e[r.name]={name:r.name,type:r.type,description:r.description,dependencies:["react",...r.dependencies??[]],registryDependencies:[...r.primitives??[],...(r.requires??[]).map(n.ref)],files:c,meta:{composite:!0,channel:a}}}}var Wt=/^[a-z0-9][a-z0-9._-]*(\/[a-z0-9][a-z0-9._-]*)*$/i;function qt(e){if(!Wt.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 Tr(e){let t=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1"),n=[],o=[/\bfrom\s*["'](\.{1,2}\/[^"']+)["']/g,/\bimport\s*["'](\.{1,2}\/[^"']+)["']/g,/\bimport\s*\(\s*["'](\.{1,2}\/[^"']+)["']\s*\)/g];for(let r of o)for(let a of t.matchAll(r))n.push(a[1]??"");return n}function Dr(e){if(e.baseUrl){let n=e.baseUrl.replace(/\/$/,"");return(o)=>`${n}/r/${o}.json`}let t=e.namespace??Rr;if(!/^@[a-z0-9][a-z0-9-]*$/.test(t))throw Error(`registry namespace must look like "@uibot", got "${t}"`);return(n)=>`${t}/${n}`}function Or(e,t,n){let o=e.name.replace(/\./g,""),r=`${n}/`,a=t.files.find((s)=>s.path.startsWith(r)&&/\.(tsx|ts)$/.test(s.path)&&Br(s.content,o));if(!a)throw Error(`block "${e.name}" has no named export "${o}" in item "${t.name}"`);return{name:e.name,export:o,module:a.path.slice(r.length),catalog:e.catalogEntry}}function Br(e,t){let n=Kt(t),o=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*\/\/.*$/gm,"");if(new RegExp(`export\\s+(?:const|let|function|class)\\s+${n}\\b`).test(o))return!0;for(let r of o.matchAll(/export\s*\{([^}]*)\}/g)){let a=(r[1]??"").split(",").map((i)=>{let[,c]=i.trim().split(/\s+as\s+/);return(c??i.trim().replace(/^type\s+/,"")).trim()}),s=(r[1]??"").split(",").map((i)=>i.trim()).filter((i)=>i.startsWith("type ")).map((i)=>i.replace(/^type\s+/,"").split(/\s+as\s+/).pop()?.trim());if(a.includes(t)&&!s.includes(t))return!0}return!1}function Nr(e,t,n){let o=new Set(n.files.map((a)=>a.path)),r=(a)=>a.replace(/^blocks\//,"");return t.replace(/((?:\bfrom\s*|\bimport\s*)["'])(\.[^"']+)(["'])/g,(a,s,i,c)=>{let l=te.normalize(te.join(te.dirname(e),i)),u=(te.extname(l)?[l]:[l,`${l}.ts`,`${l}.tsx`,`${l}/index.ts`,`${l}/index.tsx`]).find((p)=>o.has(p));if(!u)return a;let g=te.relative(te.dirname(r(e)),r(u));if(!te.extname(i))g=g.replace(/\.(tsx?|jsx?)$/,"");if(!g.startsWith("."))g=`./${g}`;return s+g+c})}function $r(e,t){return(e.split("/").pop()??t).replace(/\.(tsx|ts|jsx|js)$/,"")||t}var Bc=Cr;function Mr(e="/api/registry"){let t=(e||"/api/registry").trim(),n=t.startsWith("/")?t:`/${t}`;return n.length>1?n.replace(/\/$/,""):n}function ve(e,t=200){return Response.json(e,{status:t})}function $c(e){let t=Mr(e.basePath),n=`${t}/registry.json`,o=`${t}/artifacts/`,r=new Map(e.manifest.items.map((a)=>[a.name,a]));return async function(s){let i=new URL(s.url);if(s.method!=="GET")return ve({error:"Method not allowed"},405);if(i.pathname===n)return ve(e.manifest);if(i.pathname.startsWith(o)){let c=i.pathname.slice(o.length),l=decodeURIComponent(c.endsWith(".json")?c.slice(0,-5):c),d=r.get(l);if(!d)return ve({error:`Artifact '${l}' not found`},404);return ve(d)}return ve({error:"Not found"},404)}}var it="uibot.resource.admission.v1",_r=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure"],Lr=["packed-install","typecheck","browser"],Lc=["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 Gt 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 Yt 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 Jt extends Error{code="resource-admission-report-not-derived";constructor(){super("resource admission report must come directly from assessResourceAdmissions");this.name="ResourceAdmissionReportNotDerivedError"}}var jr=new Set(be),Fr=new Set(Ee),Zt=new WeakSet,Oe={missing:0,declared:1,verified:2,"external-consumer":3};function Vr(e,t){return e<t?-1:e>t?1:0}function le(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function Be(e,t){let n=new Set(t);return Object.keys(e).every((o)=>n.has(o))}function Qt(e){return[...new Set(e.map((t)=>t.trim()).filter(Boolean))].sort(Vr)}function Ur(e,t,n,o){if(!le(n)||!Be(n,["status","evidence"])){o.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} must contain only status and evidence`});return}if(typeof n.status!=="string"||!Fr.has(n.status)||n.status==="missing"){o.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} status must be declared, verified or external-consumer`});return}if(!Array.isArray(n.evidence)||n.evidence.length===0||n.evidence.some((r)=>typeof r!=="string"||!r.trim())){o.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} evidence must be a non-empty string array`});return}return{status:n.status,evidence:Qt(n.evidence)}}function zr(e){if(e===void 0)return;if(!le(e)||!Be(e,["source","version","license"]))return;if(Object.values(e).some((n)=>n!==void 0&&typeof n!=="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 Hr(e,t){let n=new Map,o=[];if(!le(t)||!Be(t,["schemaVersion","records"])||t.schemaVersion!==it||!Array.isArray(t.records))return o.push({code:"invalid-admission-manifest",detail:`expected ${it} with a records array`}),{records:n,issues:o};let r=new Set(e.resources.map((a)=>a.id));for(let a of t.records){if(!le(a)||!Be(a,["resourceId","provenance","checks"])||typeof a.resourceId!=="string"||!a.resourceId.trim()||!le(a.checks)){o.push({code:"invalid-admission-record",...le(a)&&typeof a.resourceId==="string"?{resourceId:a.resourceId}:{},detail:"record must contain only resourceId, optional provenance and checks"});continue}let s=a.resourceId.trim();if(n.has(s)){o.push({code:"duplicate-admission-record",resourceId:s,detail:s});continue}if(!r.has(s)){o.push({code:"unknown-admission-resource",resourceId:s,detail:s});continue}let i=zr(a.provenance);if(a.provenance!==void 0&&!i){o.push({code:"invalid-admission-record",resourceId:s,detail:"provenance must contain only string source, version and license fields"});continue}let c={},l=!1;for(let[d,u]of Object.entries(a.checks)){if(!jr.has(d)){o.push({code:"invalid-admission-check",resourceId:s,detail:`unknown receipt check: ${d}`}),l=!0;continue}let g=d,p=Ur(s,g,u,o);if(p)c[g]=p;else l=!0}if(l)continue;n.set(s,{resourceId:s,...i?{provenance:i}:{},checks:c})}return{records:n,issues:o}}function qr(e){let t=new Map(e.resources.map((r)=>[r.id,r])),n=new Map;function o(r,a,s,i){if(n.has(r)||i.has(a))return;if(s.has(a)){n.set(r,`dependency cycle reached ${a}`);return}let c=t.get(a);if(!c){n.set(r,`missing dependency ${a}`);return}s.add(a);for(let l of c.dependencies)if(o(r,l,s,i),n.has(r))break;s.delete(a),i.add(a)}for(let r of e.resources)o(r.id,r.id,new Set,new Set);return n}var Kr=/^(unknown|unlicensed|none|n\/?a)$/i,Wr=/^SPDX-License-Identifier:\s*(\S+)/im,Gr=/^(?:the\s+)?(mit|apache(?:\s+license(?:\s*,?\s*version\s*2\.0)?)?|bsd-2-clause|bsd-3-clause|isc|unlicense)\b/i;function ne(e){let t=e?.trim();if(!t||Kr.test(t))return;return t}function Yr(e){if(!e?.trim())return;let t=e.match(Wr)?.[1];if(t)return ne(t);let n=e.match(Gr)?.[1];if(!n)return;let o=n.toLowerCase();if(o.startsWith("mit"))return"MIT";if(o.startsWith("apache"))return"Apache-2.0";if(o.startsWith("bsd-2"))return"BSD-2-Clause";if(o.startsWith("bsd-3"))return"BSD-3-Clause";if(o==="isc")return"ISC";if(o==="unlicense")return"Unlicense";return}function jc(e){return ne(e.frontmatterLicense)??ne(e.packageJsonLicense)??Yr(e.licenseFileText)}function Xt(e){return Boolean(ne(e))}var Ce={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 st(e,t){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let o of e)st(o,t);return}let n=e;for(let[o,r]of Object.entries(n)){if(t.push(o),o==="type"&&r==="boolean")t.push("boolean-state");st(r,t)}}function Jr(e){let t=[];return st(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 Fc(e,t={}){let n=[Jr(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:Ce.states.test(n)?"verified":"missing",accessibility:Ce.accessibility.test(n)?"verified":"missing","light-theme":Ce["light-theme"].test(n)?"verified":"missing","dark-theme":Ce["dark-theme"].test(n)?"verified":"missing",responsive:Ce.responsive.test(n)?"verified":"missing"}}function Zr(e){return{source:"declared",license:Xt(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 Qr(e){if(!_r.every((o)=>Oe[e[o]]>=Oe.verified))return"experimental";return Lr.every((o)=>e[o]==="external-consumer")?"recommended":"candidate"}function en(e){let t=JSON.stringify({schemaVersion:e.schemaVersion,resources:e.resources.map((r)=>({id:r.id,kind:r.kind,title:r.title,description:r.description,...r.category?{category:r.category}:{},tags:r.tags,aliases:r.aliases,capabilities:r.capabilities,dependencies:r.dependencies,source:r.source})),aliases:e.aliases}),n=0xcbf29ce484222325n,o=0x100000001b3n;for(let r of new TextEncoder().encode(t))n^=BigInt(r),n=BigInt.asUintN(64,n*o);return`fnv1a64:${n.toString(16).padStart(16,"0")}`}function Xr(e,t,n){let o=Zr(e),r=[`resource://${e.source.type}/${e.source.id}`,`resource://contract/${e.id}`],a=[];if(n)a.push({code:"dependency-closure-failed",resourceId:e.id,check:"dependency-closure",detail:n});else o["dependency-closure"]="verified",r.push(`resource://index/${e.id}`);if(t)for(let c of be){if(c==="dependency-closure")continue;let l=t.checks[c];if(!l)continue;if(c==="source"&&Oe[l.status]>=Oe.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"&&!Xt(t.provenance?.license)){a.push({code:"missing-license-metadata",resourceId:e.id,check:c,detail:"license evidence requires a concrete provenance.license"});continue}if(o[c]=l.status,r.push(...l.evidence),c==="source"&&t.provenance?.source)r.push(t.provenance.source)}let s=Qr(o),i={level:s==="recommended"?"external-consumer":s==="candidate"?"verified":"declared",maturity:s,checks:o,evidence:Qt(r)};return Object.freeze(i.checks),Object.freeze(i.evidence),Object.freeze(i),Object.freeze(a),Object.freeze({resourceId:e.id,receipt:i,issues:a})}function Vc(e,t){let n=Hr(e,t),o=qr(e),r=e.resources.map((c)=>Xr(c,n.records.get(c.id),o.get(c.id))),a=[...n.issues,...r.flatMap((c)=>c.issues)],s=Object.fromEntries(Ae.map((c)=>[c,0]));for(let c of r)s[c.receipt.maturity]+=1;Object.freeze(r),Object.freeze(s);for(let c of a)Object.freeze(c);Object.freeze(a);let i=Object.freeze({schemaVersion:it,indexFingerprint:en(e),resources:r,counts:s,issues:a});return Zt.add(i),i}function Uc(e,t){if(!Zt.has(t))throw new Jt;if(t.issues.length>0)throw new Yt(t.issues.length);let n=en(e);if(n!==t.indexFingerprint)throw new Gt(t.indexFingerprint,n);let o=new Map(t.resources.map((a)=>[a.resourceId,a.receipt])),r=e.resources.map((a)=>{let s=o.get(a.id);if(!s)return a;return Object.freeze({...a,receipt:s})});return Object.freeze(r),Object.freeze({schemaVersion:e.schemaVersion,resources:r,aliases:e.aliases})}var eo="uibot.resource.index.v1",qc=["invalid-resource-source-id","duplicate-resource-id","dangling-resource-dependency","ambiguous-resource-dependency"];class pe extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceIndexError"}}function _(e,t){return e<t?-1:e>t?1:0}function O(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 to(e){let t=O(e).replace(/ /g,"-");if(!t)throw new pe("invalid-resource-source-id",e);return t}function K(e,t){return`${e}:${to(t)}`}function Ne(e){let t=new Map;for(let n of e){let o=n?.trim();if(!o)continue;let r=O(o);if(!r||t.has(r))continue;t.set(r,o)}return[...t.entries()].sort(([n],[o])=>_(n,o)).map(([,n])=>n)}function we(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 no(e){let t=ne(e.license);return{type:e.type,id:e.id,...e.version?{version:e.version}:{},...e.sourceHash?{sourceHash:e.sourceHash}:{},...e.packageName?{packageName:e.packageName}:{},...e.url?{url:e.url}:{},...t?{license:t}:{}}}function de(e){return{id:e.id,kind:e.kind,title:e.title,description:e.description,...e.category?{category:e.category}:{},tags:Ne(e.tags),aliases:Ne(e.aliases),capabilities:Ne(e.capabilities),dependencies:[...new Set(e.dependencies)].sort(_),source:no(e.source),receipt:e.receipt,...e.solution?{solution:structuredClone(e.solution)}:{}}}function ro(e){return(e.body.split(/\r?\n/).map((n)=>n.replace(/^#+\s*/,"").trim()).find(Boolean)??e.title).slice(0,240)}function oo(e){if(e.solution){let t=(n)=>{if(n&&typeof n==="object"){for(let o of Object.values(n))t(o);Object.freeze(n)}};t(e.solution)}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 io(e){let t=new Map;for(let n of Object.keys(e).sort(_)){let o=e[n];if(!o)continue;let r=K("component",n);for(let a of Ne([n,o.name])){let s=O(a),i=t.get(s)??[];if(!i.includes(r))i.push(r);t.set(s,i.sort(_))}}return t}function so(e,t,n){let o=n.get(O(e))??[];if(o.length===0)throw new pe("dangling-resource-dependency",`${t} -> ${K("component",e)}`);if(o.length>1)throw new pe("ambiguous-resource-dependency",`${t} -> ${e}: ${o.join(",")}`);return o[0]}function ao(e,t,n,o){let r=e.startsWith("template:")?e.slice(9):e;if(Object.hasOwn(o,r))return K("template",r);return so(e,t,n)}function Se(e,t,n){return ne(n?.[e]??t)}function Kc(e){return Object.entries(e).filter(([,t])=>t.level==="L4").sort(([t],[n])=>_(t,n)).map(([t,n])=>({id:`${t}-example`,title:`${n.name} Example`,description:n.description,category:n.category,tags:n.keywords,aliases:[`${t} example`,`${n.name} example`],capabilities:["example:template"],dependencies:[K("template",t)]}))}function Wc(e){let t=e.components??{},n=e.templates??{},o=e.designGuides??[],r=e.examples??[],a=e.skills??[],s=e.licenses,i=io(t),c=[];for(let p of Object.keys(t).sort(_)){let f=t[p];if(!f)continue;let m=K("component",p),h=Se(m,void 0,s);c.push(de({id:m,kind:"component",title:f.name,description:f.description,category:f.category,tags:f.tags??[],aliases:[p,f.name],capabilities:["catalog:component"],dependencies:[],source:{type:"catalog",id:p,...h?{license:h}:{}},receipt:we(Boolean(h))}))}for(let p of Object.keys(n).sort(_)){let f=n[p];if(!f)continue;let m=K("template",p),h=Se(m,void 0,s);c.push(de({id:m,kind:"template",title:f.name,description:f.description,category:f.category,tags:f.keywords,aliases:[p,f.name],capabilities:[],dependencies:(f.composedFrom??[]).map((x)=>ao(x,m,i,n)),source:{type:"template-contract",id:p,...h?{license:h}:{}},receipt:we(Boolean(h))}))}for(let p of[...o].sort((f,m)=>_(f.id,m.id))){let f=K("design-guide",p.id),m=Se(f,void 0,s);c.push(de({id:f,kind:"design-guide",title:p.title,description:ro(p),category:p.category,tags:p.tags,aliases:[p.id,p.title],capabilities:["designMd:source"],dependencies:[],source:{type:"design-md",id:p.id,...p.sourceUrl?{url:p.sourceUrl}:{},...m?{license:m}:{}},receipt:we(Boolean(m))}))}for(let p of[...r].sort((f,m)=>_(f.id,m.id))){let f=K("example",p.id),m=Se(f,p.license,s);c.push(de({id:f,kind:"example",title:p.title,description:p.description,...p.category?{category:p.category}:{},tags:p.tags??[],aliases:[p.id,p.title,...p.aliases??[]],capabilities:p.capabilities??[],dependencies:p.dependencies??[],source:{type:"example",id:p.id,...p.version?{version:p.version}:{},...p.sourceUrl?{url:p.sourceUrl}:{},...m?{license:m}:{}},receipt:we(Boolean(m))}))}for(let p of[...a].sort((f,m)=>_(f.id,m.id))){let f=K("skill",p.id),m=Se(f,void 0,s);c.push(de({id:f,kind:"skill",title:p.title,description:p.description?.trim()||p.title,tags:[...p.tags??[],...p.triggers??[]],aliases:[p.id,p.title,...p.triggers??[]],capabilities:["skill:definition"],dependencies:[],source:{type:"skill",id:p.id,...p.version?{version:p.version}:{},...m?{license:m}:{}},receipt:we(Boolean(m))}))}for(let p of e.additional??[])c.push(de(p));c.sort((p,f)=>_(p.id,f.id));let l=new Set;for(let p of c){if(l.has(p.id))throw new pe("duplicate-resource-id",p.id);l.add(p.id)}for(let p of c)for(let f of p.dependencies)if(!l.has(f))throw new pe("dangling-resource-dependency",`${p.id} -> ${f}`);let d=new Map;for(let p of c)for(let f of p.aliases){let m=O(f);if(!m)continue;let h=d.get(m)??new Set;h.add(p.id),d.set(m,h)}let u=Object.freeze(Object.fromEntries([...d.entries()].sort(([p],[f])=>_(p,f)).map(([p,f])=>[p,Object.freeze([...f].sort(_))]))),g=Object.freeze(c.map(oo));return Object.freeze({schemaVersion:eo,resources:g,aliases:u})}var co=[["chat","assistant","\u804A\u5929","\u52A9\u624B","\u5BF9\u8BDD"],["document","documents","\u6587\u6863","\u5199\u4F5C"],["auth","authentication","\u8BA4\u8BC1","\u767B\u5F55"],["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"]],lo=Object.freeze(co.map((e)=>Object.freeze([...e]))),tn=new Map;for(let e of lo){let t=Object.freeze([...new Set(e.map(O).filter(Boolean))].sort());for(let n of t)tn.set(n,t)}function at(e){let t=O(e);return tn.get(t)??Object.freeze([t])}var Xc=["resource-query-empty","resource-query-invalid-limit","resource-not-found","resource-alias-ambiguous"];class V extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceQueryError"}}var dt=Object.freeze({function:180,scenario:180,unit:180,industry:180,"exact-id":1000,"exact-title":900,alias:800,tag:600,capability:500,category:400,token:200,fuzzy:100}),po=Object.freeze(Object.keys(dt)),nn=new Map(po.map((e,t)=>[e,t])),rn=new Map([["component",0],["template",1],["design-guide",2],["example",3],["skill",4]]);function L(e,t){return e<t?-1:e>t?1:0}function on(e){return new Set((e??[]).map(O).filter(Boolean))}function re(e,t){let n=on(t);if(n.size===0)return!0;let o=on(e);return[...n].some((r)=>o.has(r))}function uo(e,t){if(!re(e.solution?.functions??[],t.functions))return!1;if(!re(e.solution?.scenarios??[],t.scenarios))return!1;if(!re(e.solution?[e.solution.unit]:[],t.units))return!1;if(!re(e.solution?.industries??[],t.industries))return!1;if(t.kinds?.length&&!t.kinds.includes(e.kind))return!1;if(!re(e.tags,t.tags))return!1;if(!re(e.category?[e.category]:[],t.categories))return!1;if(!re(e.capabilities,t.capabilities))return!1;if(t.maturities?.length&&!t.maturities.includes(e.receipt.maturity))return!1;return!0}function go(e){return Boolean(e.functions?.length||e.scenarios?.length||e.units?.length||e.industries?.length||e.kinds?.length||e.tags?.length||e.categories?.length||e.capabilities?.length||e.maturities?.length)}function z(e,t,n,o=dt[t]){if(e.some((r)=>r.code===t&&r.value===n))return;e.push({code:t,value:n,score:o})}function ct(e,t){return e.find((n)=>O(n)===t)}function lt(e){return[e.id,e.title,...e.aliases,...e.tags,...e.category?[e.category]:[],...e.capabilities,...e.solution?.functions??[],...e.solution?.scenarios??[],...e.solution?.industries??[]]}function fo(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;let o=Array.from({length:t.length+1},(r,a)=>a);for(let r=1;r<=e.length;r+=1){let a=[r],s=r;for(let i=1;i<=t.length;i+=1){let c=(o[i-1]??n+1)+(e[r-1]===t[i-1]?0:1),l=Math.min((o[i]??n+1)+1,(a[i-1]??n+1)+1,c);a.push(l),s=Math.min(s,l)}if(s>n)return n+1;o=a}return o[t.length]??n+1}function sn(e,t){let n=O(t),o=[];if(O(e.id)===n)z(o,"exact-id",e.id);if(O(e.title)===n)z(o,"exact-title",e.title);let r=ct(e.aliases,n);if(r)z(o,"alias",r);let a=ct(e.tags,n);if(a)z(o,"tag",a);let s=ct(e.capabilities,n);if(s)z(o,"capability",s);if(e.category&&O(e.category)===n)z(o,"category",e.category);if(!r){let l=at(n).filter((u)=>u!==n),d=new Set(lt(e).map(O));if(l.some((u)=>d.has(u)))z(o,"alias",t.trim())}let i=n.split(" ").filter(Boolean),c=O(lt(e).join(" "));if(i.length>0&&i.every((l)=>c.includes(l)))z(o,"token",t.trim());if(o.length===0&&n.length>=4){let l;for(let d of lt(e)){let u=O(d);if(u.length<4)continue;let g=fo(n,u,2);if(g<=2&&(!l||g<l.distance||g===l.distance&&L(d,l.value)<0))l={value:d,distance:g}}if(l)z(o,"fuzzy",l.value,dt.fuzzy-l.distance)}return o.sort((l,d)=>{if(l.score!==d.score)return d.score-l.score;return(nn.get(l.code)??99)-(nn.get(d.code)??99)||L(l.value,d.value)})}function an(e,t,n){if(t.has(n))return[n];let o=O(n),r=e.aliases[o];if(r?.length)return[...r];let a=new Set;for(let s of at(o))for(let i of e.aliases[s]??[])a.add(i);return[...a].sort(L)}function cn(e,t){return new V("resource-alias-ambiguous",`${e.trim()}: ${t.join(",")}`)}function ln(e){let t=new Map(e.resources.map((o)=>[o.id,o]));function n(o){let r=o.trim(),a=an(e,t,r);if(a.length===0)throw new V("resource-not-found",r);if(a.length>1)throw cn(r,a);let s=a[0],i=s?t.get(s):void 0;if(!i)throw new V("resource-not-found",r);return i}return Object.freeze({manifest:()=>e,search(o){let r=o.text?.trim()??"";if(!r&&!go(o))throw new V("resource-query-empty","text or filter is required");if(o.limit!==void 0&&(!Number.isInteger(o.limit)||o.limit<=0))throw new V("resource-query-invalid-limit",String(o.limit));let a=e.resources.filter((s)=>uo(s,o)).filter((s)=>!r||sn(s,r).length>0).map((s)=>{let i=r?sn(s,r):[];for(let[c,l]of[[o.functions,"function"],[o.scenarios,"scenario"],[o.units,"unit"],[o.industries,"industry"]])if(c?.length)z(i,l,c.join(","));return{resource:s,score:i.reduce((c,l)=>c+l.score,0),reasons:i}}).filter((s)=>!r||s.reasons.length>0).sort((s,i)=>i.score-s.score||L(s.resource.id,i.resource.id));return o.limit===void 0?a:a.slice(0,o.limit)},get:n,build(o){if(o.length===0||o.every((g)=>!g.trim()))throw new V("resource-query-empty","at least one build root is required");let r=[],a=new Set;for(let g of o){let p=g.trim(),f=an(e,t,p);if(f.length===0)r.push({id:p,reason:"missing-resource"});else if(f.length>1)throw cn(p,f);else{let m=f[0];if(m)a.add(m)}}let s=new Set,i=new Set,c=new Set,l=[],d=[],u=(g,p)=>{if(s.has(g))return;if(i.has(g)){r.push({id:g,...p?{requiredBy:p}:{},reason:"dependency-cycle"});return}let f=t.get(g);if(!f){r.push({id:g,...p?{requiredBy:p}:{},reason:"missing-resource"});return}i.add(g),c.add(g);let m=[...f.dependencies].sort((h,x)=>{let k=t.get(h),b=t.get(x);return(rn.get(k?.kind??"")??99)-(rn.get(b?.kind??"")??99)||L(h,x)});for(let h of m)d.push({from:g,to:h,relation:"depends-on"}),u(h,g);i.delete(g),s.add(g),l.push(g)};for(let g of[...a].sort(L))u(g);return{roots:[...a].sort(L),nodes:[...c].sort(L).map((g)=>{let p=t.get(g);if(!p)throw new V("resource-not-found",g);return{id:g,kind:p.kind,maturity:p.receipt.maturity}}),edges:d.sort((g,p)=>L(g.from,p.from)||L(g.to,p.to)),order:l,gaps:r.sort((g,p)=>L(g.id,p.id)||L(g.requiredBy??"",p.requiredBy??"")||L(g.reason,p.reason))}}})}function mo(e){if(!e||typeof e!=="object")throw Error("invalid-public-resource-bundle");xo(e);let t=e;if(t.schemaVersion!=="uibot.public-resources.v1"||typeof t.release?.version!=="string"||!/^[a-f0-9]{64}$/.test(t.release?.sourceHash)||t.index?.schemaVersion!=="uibot.resource.index.v1"||!Array.isArray(t.index.resources)||!t.index.aliases||!t.showcases)throw Error("invalid-public-resource-bundle");if(t.documents&&(!Array.isArray(t.documents)||t.documents.some((r)=>typeof r.title!=="string"||typeof r.markdown!=="string"||!/^\/(?:en\/)?docs\/[a-z0-9-]+$/.test(r.path))))throw Error("invalid-public-documentation");let n=new Set,o=new Set;for(let r of t.index.resources){if(!r||typeof r.id!=="string"||n.has(r.id)||!Dt.includes(r.kind)||!r.id.startsWith(`${r.kind}:`)||typeof r.description!=="string"||typeof r.title!=="string"||!Array.isArray(r.dependencies)||!r.source||!r.receipt||!Array.isArray(r.aliases)||!Array.isArray(r.tags)||!Array.isArray(r.capabilities)||![r.aliases,r.dependencies,r.tags,r.capabilities].every((s)=>s.every((i)=>typeof i==="string"&&i.length<=1000))||!["catalog","template-contract","design-md","example","skill","registry","package","theme"].includes(r.source.type)||typeof r.source.id!=="string"||r.source.sourceHash!==void 0&&!/^[a-f0-9]{64}$/.test(r.source.sourceHash)||r.source.packageName!==void 0&&(typeof r.source.packageName!=="string"||!r.source.packageName.startsWith("@uibot/"))||!Ae.includes(r.receipt.maturity)||!Ot.includes(r.receipt.level)||!Array.isArray(r.receipt.evidence)||!r.receipt.evidence.every((s)=>typeof s==="string")||!be.every((s)=>Ee.includes(r.receipt.checks?.[s])))throw Error("invalid-public-resource");if(n.add(r.id),r.solution){let s=r.solution;if(![s.functions,s.scenarios,s.industries,s.hostRequirements,s.limitations].every((i)=>Array.isArray(i)&&i.every((c)=>typeof c==="string"&&c.length>0&&c.length<=2000))||!["page","flow","industry"].includes(s.unit)||!["interactive-demo","needs-enhancement"].includes(s.readiness)||s.members!==void 0&&(!Array.isArray(s.members)||s.members.some((i)=>typeof i.resourceId!=="string"||typeof i.version!=="string"||!i.version||i.sourceHash!==void 0&&(typeof i.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(i.sourceHash)))))throw Error("invalid-resource-solution")}let a=t.showcases[r.id];if(!a||a.resourceId!==r.id||typeof a.docs?.zh!=="string"||typeof a.docs?.en!=="string"||!Array.isArray(a.examples)||!Array.isArray(a.distributions))throw Error("invalid-resource-showcase");if(a.collection!==void 0){let s=a.collection;if(!s||typeof s.id!=="string"||!/^[a-z0-9-]+$/.test(s.id)||typeof s.group?.id!=="string"||!/^[a-z0-9-]+$/.test(s.group.id)||[s.title,s.group.title].some((i)=>!i||[i.zh,i.en].some((c)=>typeof c!=="string"||!c.trim()||c.length>200)))throw Error("invalid-resource-collection")}if(a.agentKit!==void 0){let s=a.agentKit;if(o.has(r.source?.id))throw Error("invalid-resource-agent-kit");if(o.add(r.source?.id),!s||!["skill","prompt","recipe"].includes(s.type)||(s.type==="skill"?r.kind!=="skill":r.kind!=="example")||!/^[a-z][a-z0-9-]*$/.test(r.source.id)||s.fileName!=={skill:"SKILL.md",prompt:"PROMPT.md",recipe:"RECIPE.md"}[s.type]||[s.summary?.zh,s.summary?.en].some((i)=>typeof i!=="string"||!i.trim())||!Array.isArray(s.resources)||new Set(s.resources.map((i)=>i?.id)).size!==s.resources.length||s.resources.some((i)=>!i||!r.dependencies.includes(i.id)||!t.index.resources.some((c)=>c.id===i.id&&(c.source.version??null)===i.version)||i.version!==null&&(typeof i.version!=="string"||!i.version)||typeof i.contentHash!=="string"||!/^[a-f0-9]{64}$/.test(i.contentHash)||i.sourceHash!==void 0&&(typeof i.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(i.sourceHash)))||s.resources.length!==r.dependencies.length)throw Error("invalid-resource-agent-kit")}if(a.solutionControls!==void 0){let s=new Set;if(!Array.isArray(a.solutionControls)||a.solutionControls.some((i)=>{if(!i||typeof i.id!=="string"||s.has(i.id)||typeof i.label?.zh!=="string"||typeof i.label?.en!=="string"||!Array.isArray(i.values)||!i.values.length||i.values.some((c)=>!["string","boolean","number"].includes(typeof c)||typeof c==="number"&&!Number.isFinite(c))||typeof i.target?.pageId!=="string"||typeof i.target?.property!=="string"||["__proto__","prototype","constructor"].includes(i.target.property)||i.target.blockId!==void 0&&typeof i.target.blockId!=="string")return!0;return s.add(i.id),!1}))throw Error("invalid-solution-controls")}if(a.templateContract&&(a.templateContract.name!==r.source.id||typeof a.templateContract.description!=="string"||!["L3","L4","L5"].includes(a.templateContract.level)||!["feature","template","page","app"].includes(a.templateContract.category)||!Array.isArray(a.templateContract.keywords)))throw Error("invalid-public-template-contract");if(typeof a.title?.zh!=="string"||typeof a.title?.en!=="string"||a.examples.some((s)=>!s||typeof s.id!=="string"||typeof s.title!=="string"||typeof s.code!=="string"||!["spec","tsx","source"].includes(s.mode)||!["tsx","json","yaml","css","ts"].includes(s.language)||!Array.isArray(s.dependencies)||!s.dependencies.every((i)=>typeof i==="string"))||a.distributions.some((s)=>!s||!["spec","npm","shadcn"].includes(s.channel)||typeof s.name!=="string"||!/^[@a-zA-Z0-9._/-]+$/.test(s.name)||typeof s.version!=="string"||!["source","published"].includes(s.availability)||s.connections!==void 0&&(s.channel!=="spec"||!Array.isArray(s.connections)||s.connections.some((i)=>typeof i!=="string"||!i))))throw Error("invalid-resource-content")}for(let[r,a]of Object.entries(t.index.aliases))if(!r||!Array.isArray(a)||a.some((s)=>!n.has(s)))throw Error("invalid-public-resource-alias");if(Object.keys(t.showcases).some((r)=>!n.has(r)))throw Error("unexpected-public-resource-showcase");for(let r of t.index.resources)for(let a of r.dependencies)if(!n.has(a))throw Error("invalid-public-resource-dependency");if(t.distributionSnapshot){let r=t.distributionSnapshot;if(!/^[a-f0-9]{64}$/.test(r.snapshotId)||r.manifestPath!==`../snapshots/${r.snapshotId}/snapshot.json`||!r.resources||!r.unavailable||!r.external||Object.entries(r.external).some(([a,s])=>!Object.hasOwn(r.unavailable,a)||!Array.isArray(s)||s.some((i)=>typeof i!=="string"||i.startsWith("@uibot/"))))throw Error("invalid-distribution-snapshot-reference");for(let[a,s]of Object.entries(r.resources))if(!n.has(a)||s.version!==(t.index.resources.find((i)=>i.id===a)?.source.version??t.release.version)||!/^[a-f0-9]{64}$/.test(s.resourceHash)||!Array.isArray(s.entrypoints)||!s.entrypoints.length||!Array.isArray(s.closure)||![...s.entrypoints,...s.closure].every((i)=>/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(i))||s.entrypoints.some((i)=>!s.closure.includes(i)))throw Error("invalid-distribution-snapshot-resource")}}function ol(e){mo(e),e=JSON.parse(JSON.stringify(e));let t=(r)=>{if(r&&typeof r==="object"){for(let a of Object.values(r))t(a);Object.freeze(r)}};t(e);let n=ln(e.index),o=(r)=>{let a=n.get(r),s=e.showcases[a.id];if(!s)throw new V("resource-not-found",a.id);return s};return Object.freeze({...n,get(r){let a=n.get(r),s=o(r).agentKit;return s?Object.freeze({...a,agentKit:s}):a},docs(r,a="zh",s=1){if(a!=="zh"&&a!=="en")throw Error("unsupported-resource-locale");let i=o(r);return{resourceId:i.resourceId,locale:a,...bo(i.docs[a],s),release:e.release}},examples(r,a=1){let s=o(r);return{resourceId:s.resourceId,...ko(s.examples,a),release:e.release}},installPlan(r){let a=o(r);return{resourceId:a.resourceId,distributions:a.distributions,dependencies:n.build([a.resourceId]),release:e.release,snapshot:e.distributionSnapshot&&Object.hasOwn(e.distributionSnapshot.resources,a.resourceId)?{snapshotId:e.distributionSnapshot.snapshotId,manifestPath:e.distributionSnapshot.manifestPath,...e.distributionSnapshot.resources[a.resourceId]}:null,snapshotUnavailable:e.distributionSnapshot?.unavailable[a.resourceId]??null,install:a.distributions.map((s)=>yo(s,e.distributionSnapshot,a.resourceId))}}})}var ho={Collection:{real:"@uibot/application/data-gateway (server only; nowapi/http/pg bindings)",demo:"createMockCollectionConnectionDriver from @uibot/connection-mock/browser"}};function yo(e,t,n){let{channel:o,name:r,version:a}=e;if(o==="npm")return{channel:o,name:r,command:`add ${r}@${a}`,note:null};if(o==="spec"){let c=Object.entries(e.dependencies??{}).map(([l,d])=>`${l}@${d}`);return{channel:o,name:r,command:c.length?`add ${c.join(" ")}`:null,drivers:(e.connections??[]).map((l)=>({type:l,...ho[l]??{real:null,demo:null}})),note:"Read the Spec through examples (join paginated code), compile it strictly at build time with the Catalog from @uibot/blocks-shadcn/catalog (plus the other packages listed), then render with createLiveRuntimeAdapter from @uibot/runtime and UIBotLiveRenderer from @uibot/renderer-react, one adapter per page. Inject the model-driven mock adapter or a same-origin host adapter; real nowapi/http/pg bindings execute only in the server data gateway."}}let s=!!t&&Object.hasOwn(t.resources,n),i=t?.external[n]??[];return{channel:o,name:r,command:`shadcn add @uibot/${r}`,registries:{"@uibot":"/r/{name}.json"},externalRegistryDependencies:i,note:s?"A hash-pinned snapshot exists: export and verify it, then map @uibot to the local snapshot server.":i.length?`No hash-pinned snapshot: the install also pulls stock shadcn items (${i.join(", ")}) from the host's default registry. Installing through the portal mapping still works; report the files as not snapshot-verified.`:"No hash-pinned snapshot; report the files as not snapshot-verified."}}var Z=24000;function dn(e,t){if(!Number.isSafeInteger(e)||e<1||e>Math.max(1,t))throw new V("resource-query-invalid-limit","page is outside the available range")}function bo(e,t){let n=Math.max(1,Math.ceil(e.length/Z));return dn(t,n),{markdown:e.slice((t-1)*Z,t*Z),page:t,totalPages:n,...t<n?{nextPage:t+1}:{}}}function ko(e,t){let n=e.flatMap((o)=>Array.from({length:Math.max(1,Math.ceil(o.code.length/Z))},(r,a)=>({...o,code:o.code.slice(a*Z,(a+1)*Z),codeOffset:a*Z,codeLength:o.code.length,complete:o.code.length<=Z})));return dn(t,n.length),{examples:n.slice(t-1,t),page:t,totalPages:n.length,...t<n.length?{nextPage:t+1}:{}}}function xo(e){let t=0,n=0,o=new Set,r=(a,s)=>{if(++t>300000||s>64)throw Error("public-resource-budget-exceeded");if(typeof a==="string"){if(n+=new TextEncoder().encode(a).length,n>16777216)throw Error("public-resource-budget-exceeded")}else if(a&&typeof a==="object"){if(o.has(a))throw Error("invalid-public-resource-cycle");let i=Object.getPrototypeOf(a);if(!Array.isArray(a)&&i!==Object.prototype&&i!==null)throw Error("invalid-public-resource-object");o.add(a);for(let[c,l]of Object.entries(a))r(c,s+1),r(l,s+1);o.delete(a)}else if(a!==null&&typeof a!=="boolean"&&(typeof a!=="number"||!Number.isFinite(a)))throw Error("invalid-public-resource-json")};r(e,1)}var vo=(e)=>e.length>0&&!["__proto__","constructor","prototype"].includes(e);function Ie(e){return e.flatMap((t)=>[t,...Ie(t.children??[]),...Object.values(t.slots??{}).flatMap(Ie)])}function $e(e,t,n){let o=structuredClone(e);for(let[r,a]of Object.entries(n)){let s=t.find((c)=>c.id===r);if(!s?.values.includes(a)||!vo(s.target.property))throw Error(`invalid-solution-control:${r}`);let i=o.pages?.find((c)=>c.id===s.target.pageId);if(!i)throw Error(`solution-page-missing:${r}`);if(s.target.blockId){let c=Ie(i.blocks).filter((d)=>d.id===s.target.blockId),l=c[0];if(c.length!==1||!l)throw Error(`solution-block-missing:${r}`);l.props={...l.props,[s.target.property]:a}}else i.state={...i.state,[s.target.property]:a}}return o}function Re(e,t,n={}){let o=new Set((e.pages??[]).map((i)=>i.id)),r=new Set((e.pages??[]).map((i)=>i.path)),a=new Set((e.pages??[]).flatMap((i)=>Ie(i.blocks).flatMap((c)=>c.id?[c.id]:[])));for(let i of t.pages??[]){if(o.has(i.id)||r.has(i.path))throw Error(`solution-page-conflict:${i.id}:${i.path}`);o.add(i.id),r.add(i.path);for(let c of Ie(i.blocks))if(c.id){if(a.has(c.id))throw Error(`solution-block-conflict:${c.id}`);a.add(c.id)}}if(t.connections||t.auth||t.layout)throw Error("solution-global-config-conflict");if(n.addNavigation){let i=new Set((e.menus?.items??[]).map((c)=>c.key));for(let c of t.pages)if(i.has(`solution:${c.id}`))throw Error(`solution-navigation-conflict:${c.id}`)}let s=n.addNavigation?{...structuredClone(e.menus),items:[...structuredClone(e.menus?.items??[]),...t.pages.map((i)=>({key:`solution:${i.id}`,label:i.title??i.id,path:i.path}))]}:e.menus;return{...structuredClone(e),...s?{menus:structuredClone(s)}:{},pages:[...structuredClone(e.pages??[]),...structuredClone(t.pages??[])]}}function S(e){if(Array.isArray(e))return`[${e.map(S).join(",")}]`;if(e&&typeof e==="object")return`{${Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[n])=>t<n?-1:t>n?1:0).map(([t,n])=>`${JSON.stringify(t)}:${S(n)}`).join(",")}}`;return JSON.stringify(e)??"null"}var Me=(e)=>typeof e==="string"&&e.length>0&&!["__proto__","prototype","constructor"].includes(e);function pn(e){if(!Me(e.resourceId)||!Me(e.version)||!/^[a-f0-9]{64}$/.test(e.sourceHash))throw Error("invalid-solution-identity")}function pt(e,t,n,o=e.id){let r=structuredClone(e);if(r.id=o,r.path=n.paths[e.path]??e.path,!Me(r.id)||typeof r.path!=="string"||!r.path.startsWith("/"))throw Error("invalid-solution-page-target");if(n.frame)r.blocks=r.blocks.map((s)=>s.type==="PageLayout"?{...s,props:{...s.props,...structuredClone(n.frame?.props)},slots:{...s.slots,...structuredClone(n.frame?.slots)},events:{...s.events,...structuredClone(n.frame?.events)}}:s);let a=(s)=>{if(!s||typeof s!=="object")return;for(let[i,c]of Object.entries(s))if(typeof c==="string"){if(i==="connectionId"&&n.connections[c])s[i]=n.connections[c];else if(["href","path","url","redirect","currentPath"].includes(i)&&n.paths[c])s[i]=n.paths[c]}else a(c)};if(a(r),n.layout==="source"&&t.layout&&r.blocks.some((s)=>s.type==="PageLayout"))r.layout={...structuredClone(t.layout),...r.layout,inherit:!1};return r}function ut(e,t){if(!t.data)return structuredClone(e.data);let n=structuredClone(e.data?.entities??{});for(let[o,r]of Object.entries(t.data.entities)){if(Object.hasOwn(n,o)&&S(n[o])!==S(r))throw Error(`solution-entity-conflict:${o}`);Object.defineProperty(n,o,{value:structuredClone(r),enumerable:!0,writable:!0,configurable:!0})}return Y({entities:n})}function _e(e,t,n){ut(e,t);let o=structuredClone(e.connections??[]);for(let r of t.connections??[]){let a=n[r.id];if(!a||!Me(a))throw Error(`solution-connection-binding-required:${r.id}`);let s=o.find((i)=>i.id===a);if(s&&s.type!==r.type)throw Error(`solution-connection-type-conflict:${r.id}:${a}`);if(s&&s.entity!==r.entity)throw Error(`solution-connection-entity-conflict:${r.id}:${a}`);if(!s)o.push({id:a,type:r.type,entity:r.entity,...r.mock?{mock:structuredClone(r.mock)}:{}})}return o}function gt(e,t,n,o){let r=new Set([...e.pages,...n].map((c)=>c.path)),a=new Set(t.pages.map((c)=>o.paths[c.path]??c.path)),s=new Set(_e(e,t,o.connections).map((c)=>c.id)),i=(c)=>{if(!c||typeof c!=="object")return;for(let[l,d]of Object.entries(c))if(typeof d==="string"){if(l==="connectionId"&&!s.has(d))throw Error(`solution-connection-missing:${d}`);if(["href","url","redirect","path"].includes(l)&&a.has(d)&&!r.has(d))throw Error(`solution-route-dependency-missing:${d}`)}else i(d)};for(let c of n)i(c)}function un(e,t,n){if(pn(t.identity),B(e),t.spec.auth)throw Error("solution-host-auth-required");let o=$e(t.spec,t.controls??[],n.configuration??{}),r={paths:{...n.paths},connections:{...n.connections},layout:n.layout,...n.frame?{frame:structuredClone(n.frame)}:{}},a=_e(e,o,r.connections),s=n.selectedPageIds?o.pages.filter((u)=>n.selectedPageIds?.includes(u.id)):o.pages;if(!s.length||n.selectedPageIds&&s.length!==new Set(n.selectedPageIds).size)throw Error("solution-select-pages");let i=s.map((u)=>pt(u,o,r,n.pageIds?.[u.id]??u.id));gt(e,t.spec,i,r);let c=Re(e,{version:"2.0",pages:i},{addNavigation:n.addNavigation??!1}),l=s.map((u,g)=>({...t.identity,sourcePageId:u.id,targetPageId:i[g]?.id??u.id,baseline:structuredClone(i[g]),bindings:structuredClone(r),...n.configuration?{configuration:structuredClone(n.configuration)}:{}}));if(c.composition={...structuredClone(e.composition),schema:"uibot.solution-composition.v1",pages:[...structuredClone(e.composition?.pages??[]),...l]},a.length)c.connections=a;let d=ut(e,o);if(d)c.data=d;return{spec:c,pages:i.map((u)=>({id:u.id,path:u.path})),connections:a.filter((u)=>!e.connections?.some((g)=>g.id===u.id)),layout:n.layout}}function Co(e,t,n={}){pn(t.identity),B(e);let o=[];for(let r of e.composition?.pages??[]){if(r.resourceId!==t.identity.resourceId||r.detached)continue;let a=e.pages.find((c)=>c.id===r.targetPageId),s=t.spec.pages.find((c)=>c.id===r.sourcePageId),i={pageId:r.targetPageId,path:a?.path??r.baseline.path,from:{resourceId:r.resourceId,version:r.version,sourceHash:r.sourceHash},to:t.identity};if(!a){o.push({...i,status:"deleted-locally"});continue}if(!s){o.push({...i,status:"removed"});continue}try{let c=$e(t.spec,t.controls??[],r.configuration??{}),l={...r.bindings,connections:{...r.bindings.connections,...n}};if(_e(e,c,l.connections),c.auth)throw Error("solution-host-auth-required");let d=pt(c.pages.find((f)=>f.id===s.id),c,l,a.id),u=e.pages.flatMap((f)=>{if(f.id===a.id)return[];let m=e.composition?.pages.find((x)=>x.resourceId===t.identity.resourceId&&x.targetPageId===f.id&&!x.detached),h=c.pages.find((x)=>x.id===m?.sourcePageId);return m&&h?[{...f,path:m.bindings.paths[h.path]??h.path}]:[f]});gt({...e,pages:u},c,[d],l);let g=S(a)!==S(r.baseline),p=S(d)!==S(r.baseline);o.push({...i,nextPath:d.path,incoming:d,status:g?p?"conflict":"customized":p?"update":"unchanged"})}catch(c){o.push({...i,status:"blocked",error:String(c)})}}return{pages:o,tracked:o.length>0}}function ll(e,t,n,o={}){let r=Co(e,t,o),a=structuredClone(e);if(r.pages.some((s)=>["conflict","removed","deleted-locally"].includes(s.status)&&!n[s.pageId]))throw Error("solution-upgrade-unresolved");for(let[s,i]of Object.entries(n)){let c=r.pages.find((m)=>m.pageId===s),l=a.composition?.pages.find((m)=>m.targetPageId===s);if(!c||!l)throw Error(`solution-untracked-page:${s}`);if(c.status==="blocked")throw Error(`solution-upgrade-blocked:${s}`);if(i==="detach"){l.detached=!0;continue}if(["removed","deleted-locally"].includes(c.status))throw Error(`solution-upgrade-detach-required:${s}`);if(i==="update"&&["conflict","customized"].includes(c.status))throw Error(`solution-upgrade-conflict:${s}`);if(!["update","replace","keep"].includes(i))throw Error("invalid-solution-upgrade-decision");let d=$e(t.spec,t.controls??[],l.configuration??{});l.bindings.connections={...l.bindings.connections,...o};let u=d.pages.find((m)=>m.id===l.sourcePageId);if(!u)throw Error(`solution-page-missing:${s}`);let g=pt(u,d,l.bindings,s);if(i!=="keep"){let m=a.pages.find((h)=>h.id===s)?.path;if(a.pages=a.pages.map((h)=>h.id===s?g:h),m&&m!==g.path){let h=(x)=>{if(!x||typeof x!=="object")return;for(let[k,b]of Object.entries(x))if(["path","href"].includes(k)&&b===m)x[k]=g.path;else if(typeof b==="object")h(b)};h(a.menus);for(let x of a.pages)for(let k of x.blocks)if(k.type==="PageLayout")h(k.props?.routes),h(k.slots?.sidebar)}}l.baseline=structuredClone(g),Object.assign(l,t.identity);let p=_e(a,d,l.bindings.connections);if(p.length)a.connections=p;let f=ut(a,d);if(f)a.data=f}Re({version:"2.0",pages:[]},{version:"2.0",pages:a.pages});for(let[s,i]of Object.entries(n))if(i!=="detach"){let c=a.composition?.pages.find((d)=>d.targetPageId===s),l=a.pages.find((d)=>d.id===s);if(c&&l)gt(a,{...t.spec,pages:[...t.spec.pages,...e.pages]},a.pages,c.bindings)}return a}function Q(e,t=160){let n=typeof e==="string"?e:JSON.stringify(e)??String(e);if(n.length<=t)return n;return`${n.slice(0,t-3)}...`}function ue(e){return e.flatMap((t)=>[t,...ue(t.children??[]),...Object.values(t.slots??{}).flatMap(ue)])}function gn(e){if(e?.type!=="Box"||e.template||e.slots||e.events||e.visible!==void 0)throw Error("solution-region-slot-invalid");return e}function fn(e,t){let n=ue(e).filter((o)=>o.id===t);if(n.length!==1)return;return n[0]}function ft(e,t){return gn(fn([e],t))}function wo(e,t){return ue([e]).some((n)=>n.id===t)}function mt(e,t,n,o){if(e.type!==t.type){o.push({code:"unmapped-block",path:`${n}.type`,message:`Outer frame block type changed from "${t.type}" to "${e.type}".`,preservedSummary:Q(e)});return}let r=new Set([...Object.keys(e.props??{}),...Object.keys(t.props??{})]);for(let d of r){let u=e.props?.[d],g=t.props?.[d];if(S(u)!==S(g))o.push({code:"unmapped-frame-prop",path:`${n}.props.${d}`,message:`Customized outer frame prop "${d}" does not map automatically to the replacement frame.`,preservedSummary:`${d}=${Q(u??null)}`})}let a=new Set([...Object.keys(e.events??{}),...Object.keys(t.events??{})]);for(let d of a){let u=e.events?.[d],g=t.events?.[d];if(S(u)!==S(g))o.push({code:"unmapped-event",path:`${n}.events.${d}`,message:`Customized outer frame event "${d}" does not map automatically to the replacement frame.`,preservedSummary:`${d}:${Q(u??null)}`})}if(S(e.visible)!==S(t.visible))o.push({code:"unmapped-frame-prop",path:`${n}.visible`,message:"Customized outer frame visibility condition does not map to the replacement frame.",preservedSummary:`visible=${Q(e.visible??null)}`});let s=e.children??[],i=t.children??[],c=Math.min(s.length,i.length);for(let d=0;d<c;d++){let u=s[d],g=i[d];if(u&&g)mt(u,g,`${n}.children[${d}]`,o)}for(let d=c;d<s.length;d++){let u=s[d];if(u)o.push({code:"unmapped-block",path:`${n}.children[${d}]`,message:"Additional block inside outer frame was not carried over into the new frame.",preservedSummary:Q(u)})}let l=new Set([...Object.keys(e.slots??{}),...Object.keys(t.slots??{})]);for(let d of l){let u=e.slots?.[d]??[],g=t.slots?.[d]??[],p=Math.min(u.length,g.length);for(let f=0;f<p;f++){let m=u[f],h=g[f];if(m&&h)mt(m,h,`${n}.slots.${d}[${f}]`,o)}for(let f=p;f<u.length;f++){let m=u[f];if(m)o.push({code:"unmapped-block",path:`${n}.slots.${d}[${f}]`,message:`Additional block in frame slot "${d}" was not carried over into the new frame.`,preservedSummary:Q(m)})}}}function ht(e,t,n,o){if(B(e),!t.identity.resourceId||!t.identity.version||!/^[a-f0-9]{64}$/.test(t.identity.sourceHash))throw Error("invalid-solution-identity");let r=Object.entries(n);if(!r.length||r.some(([i,c])=>!i||!c)||new Set(r.map(([,i])=>i)).size!==r.length)throw Error("solution-region-explicit-mapping-required");let a=structuredClone(e),s=[];for(let[i,c]of r){let l=a.pages.findIndex((x)=>x.id===c),d=l>=0?a.pages[l]:void 0;if(!d||ue(d.blocks).some((x)=>x.type==="PageLayout"))throw Error(`solution-region-independent-page-required:${c}`);let u=d.blocks,g=a.composition?.regions?.find((x)=>x.targetPageId===c);if(g)if(o?.strictBaseline){if(d.blocks.length!==1||!d.blocks[0])throw Error("solution-region-frame-customized");let x=structuredClone(d.blocks[0]),k=ft(x,g.contentBlockId);if(u=k.children??[],k.children=[],S(x)!==S(g.baseline))throw Error("solution-region-frame-customized")}else{let x=structuredClone(d.blocks),k=fn(x,g.contentBlockId);if(!k)s.push({code:"unmapped-block",path:`pages[${l}].blocks`,message:`Previous frame content slot "${g.contentBlockId}" could not be isolated; preserved full page body inside the new frame.`,preservedSummary:Q(d.blocks)}),u=d.blocks;else{let b=gn(k);u=b.children??[],b.children=[];let C=x.findIndex((A)=>wo(A,g.contentBlockId)),E=C>=0?x[C]:void 0;if(E)mt(E,g.baseline,`pages[${l}].blocks[${C}]`,s);for(let A=0;A<x.length;A++){if(A===C)continue;let y=x[A];if(y)s.push({code:"unmapped-block",path:`pages[${l}].blocks[${A}]`,message:"Extra sibling block outside the frame content slot was not mapped to the new frame.",preservedSummary:Q(y)})}}}let p=structuredClone(t.frame);if(ft(p,t.contentBlockId).children?.length)throw Error("solution-region-slot-not-empty");for(let x of ue([p]))if(x.id)x.id=`${c}-${x.id}`;let f=`${c}-${t.contentBlockId}`,m=structuredClone(p);ft(p,f).children=structuredClone(u),d.blocks=[p];let h={...t.identity,targetPageId:c,role:i,target:"page-frame",contentBlockId:f,baseline:m};a.composition??={schema:"uibot.solution-composition.v1",pages:[]},a.composition.regions=[...(a.composition.regions??[]).filter((x)=>x.targetPageId!==c),h]}return Re({version:"2.0",pages:[]},{version:"2.0",pages:a.pages}),B(a),{spec:a,unmappedWarnings:s}}function ml(e,t,n,o){return ht(e,t,n,o).spec}var So=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function fe(e){let t=new TextEncoder().encode(e),n=t.length*8,o=Math.ceil((t.length+9)/64)*64,r=new Uint8Array(o);r.set(t),r[t.length]=128;let a=new DataView(r.buffer),s=Math.floor(n/4294967296),i=n>>>0;a.setUint32(o-8,s,!1),a.setUint32(o-4,i,!1);let c=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],l=new Uint32Array(64),d=(u,g)=>u>>>g|u<<32-g;for(let u=0;u<o;u+=64){for(let C=0;C<16;C++)l[C]=a.getUint32(u+C*4,!1);for(let C=16;C<64;C++){let E=l[C-15]??0,A=l[C-2]??0,y=d(E,7)^d(E,18)^E>>>3,T=d(A,17)^d(A,19)^A>>>10;l[C]=(l[C-16]??0)+y+(l[C-7]??0)+T>>>0}let[g,p,f,m,h,x,k,b]=c;for(let C=0;C<64;C++){let E=d(h,6)^d(h,11)^d(h,25),A=h&x^~h&k,y=b+E+A+(So[C]??0)+(l[C]??0)>>>0,T=d(g,2)^d(g,13)^d(g,22),v=g&p^g&f^p&f,I=T+v>>>0;b=k,k=x,x=h,h=m+y>>>0,m=f,f=p,p=g,g=y+I>>>0}c[0]=(c[0]??0)+g>>>0,c[1]=(c[1]??0)+p>>>0,c[2]=(c[2]??0)+f>>>0,c[3]=(c[3]??0)+m>>>0,c[4]=(c[4]??0)+h>>>0,c[5]=(c[5]??0)+x>>>0,c[6]=(c[6]??0)+k>>>0,c[7]=(c[7]??0)+b>>>0}return c.map((u)=>u.toString(16).padStart(8,"0")).join("")}function j(e,t=160){let n=typeof e==="string"?e:JSON.stringify(e)??String(e);if(n.length<=t)return n;return`${n.slice(0,t-3)}...`}function xl(e=[]){let t=new Map,n=(o)=>{et(o),t.set(o.familyId,structuredClone(o))};for(let o of e)n(o);return{register:n,get:(o)=>{let r=t.get(o);return r?structuredClone(r):void 0},list:(o)=>mn([...t.values()],o)}}function Io(e,t){if(!t)return!0;if(t.familyId&&e.familyId!==t.familyId)return!1;if(t.level&&e.level!==t.level)return!1;if(t.targetKind&&e.targetKind!==t.targetKind)return!1;if(t.resourceId&&!e.variants.some((n)=>n.resourceId===t.resourceId||n.identity?.resourceId===t.resourceId))return!1;if(t.query){let n=t.query.trim().toLowerCase();if(n){if(![e.familyId,e.title.zh,e.title.en,e.description,...e.variants.flatMap((r)=>[r.id,r.title.zh,r.title.en,r.description,r.resourceId??""])].join(`
|
|
15
|
+
`).toLowerCase().includes(n))return!1}}return!0}function mn(e,t){return e.filter((n)=>Io(n,t)).map((n)=>structuredClone(n))}function je(e,t){if(!Array.isArray(e)&&"list"in e&&typeof e.list==="function")return e.list(t);return mn(e,t)}function vl(e){let t=new Map;for(let[o,r]of Object.entries(e)){let a=r.replacement?.family;if(!a)continue;let s=t.get(a)??[];s.push({component:o,entry:r}),t.set(a,s)}let n=[];for(let[o,r]of t.entries()){let a=Array.from(new Set(r.flatMap((l)=>l.entry.replacement?.presentationProps??[]))),s=new Map,i=(l,d)=>{if(!s.has(l))s.set(l,{id:l,label:{zh:l,en:l},preserveMode:d})};for(let{entry:l}of r){let d=new Set(l.replacement?.presentationProps??[]);for(let u of Object.keys(l.props??{}))if(!d.has(u))i(`prop:${u}`,"when-customized");for(let u of Object.keys(l.events??{}))i(`event:${u}`,"always");for(let u of Object.keys(l.slots??{}))i(`slot:${u}`,"always")}let c=[];for(let{component:l,entry:d}of r){let u=new Set(d.replacement?.presentationProps??[]),g={};for(let p of Object.keys(d.props??{}))if(!u.has(p))g[`prop:${p}`]={kind:"block-prop",property:p};for(let p of Object.keys(d.events??{}))g[`event:${p}`]={kind:"block-events",property:p};for(let p of Object.keys(d.slots??{}))g[`slot:${p}`]=p==="children"?{kind:"block-children"}:{kind:"block-children",property:p};for(let p of d.replacement?.variants??[])c.push({id:`${l}:${p.id}`,title:{zh:p.title,en:p.title},description:d.description,resourceId:`component:${l.toLowerCase()}`,slotBindings:structuredClone(g),blockTemplate:{type:l,...p.props?{props:structuredClone(p.props)}:{}}})}if(c.length>0){let l=r[0];n.push({schema:"uibot.variant-contract.v1",familyId:o,level:"L1",targetKind:"block",title:{zh:l?.entry.name??o,en:l?.entry.name??o},description:l?.entry.description??`Component replacement family ${o}`,semanticSlots:[...s.values()],presentationProps:a,variants:c})}}return n}function ge(e,t,n){for(let o=0;o<e.length;o++){let r=e[o];if(!r)continue;let a=`${t}[${o}]`;if(n({node:r,path:a}),r.children?.length)ge(r.children,`${a}.children`,n);for(let[s,i]of Object.entries(r.slots??{}))ge(i,`${a}.slots.${s}`,n)}}function kt(e,t,n){let o=[];return ge(e,n,(r)=>{if(t.blockIdSuffix){let a=r.node.id??"";if(a===t.blockIdSuffix||a.endsWith(`-${t.blockIdSuffix}`))o.push(r);return}if(t.blockType){if(r.node.type===t.blockType)o.push(r);return}o.push(r)}),o[t.occurrence??0]}function oe(e,t,n){if(t.kind==="page-field"){let r=t.property??"";return{value:e[r],path:`${n}.${r}`}}let o=kt(e.blocks,t,`${n}.blocks`);if(!o)return{value:void 0,path:`${n}.blocks`};if(t.kind==="block-node")return{value:o.node,path:o.path,locatedNodePath:o.path};if(t.kind==="block-prop"){let r=t.property??"";return{value:o.node.props?.[r],path:`${o.path}.props.${r}`,locatedNodePath:o.path}}if(t.kind==="block-events"){let r=t.property;return{value:r?o.node.events?.[r]:o.node.events,path:r?`${o.path}.events.${r}`:`${o.path}.events`,locatedNodePath:o.path}}if(t.kind==="block-children"){let r=t.property;return{value:r?o.node.slots?.[r]:o.node.children,path:r?`${o.path}.slots.${r}`:`${o.path}.children`,locatedNodePath:o.path}}return{value:void 0,path:n}}function Ro(e,t,n,o){let r={...structuredClone(e.props)};for(let[a,s]of Object.entries(t.props??{})){let i=n?.props?.[a];if(s!==null&&typeof s==="object"&&!Array.isArray(s)||!n||S(s)!==S(i))r[a]=structuredClone(s)}if(Object.keys(r).length>0)e.props=r;if(t.visible!==void 0)e.visible=structuredClone(t.visible);if(t.events&&(!n||S(t.events)!==S(n.events)))e.events=structuredClone(t.events);else if(!e.events&&t.events)e.events=structuredClone(t.events);if(t.children&&(!n||S(t.children)!==S(n.children)))e.children=structuredClone(t.children);else if(!e.children&&t.children)e.children=structuredClone(t.children);if(t.slots&&(!n||S(t.slots)!==S(n.slots)))e.slots=structuredClone(t.slots);else if(!e.slots&&t.slots)e.slots=structuredClone(t.slots);if(t.id&&!o.has(t.id))e.id=t.id}function hn(e,t,n,o,r){if(t.kind==="page-field"){let s=t.property;if(!s||["__proto__","prototype","constructor"].includes(s))return!1;return e[s]=structuredClone(n),!0}let a=kt(e.blocks,t,"page.blocks");if(!a)return!1;if(t.kind==="block-node"){if(!n||typeof n!=="object")return!1;return Ro(a.node,n,o&&typeof o==="object"?o:void 0,r),!0}if(t.kind==="block-prop"){let s=t.property;if(!s)return!1;return a.node.props??={},a.node.props[s]=structuredClone(n),!0}if(t.kind==="block-events"){let s=t.property;if(s)a.node.events??={},a.node.events[s]=structuredClone(n);else if(n&&typeof n==="object")a.node.events=structuredClone(n);return!0}if(t.kind==="block-children"){let s=t.property;if(s)a.node.slots??={},a.node.slots[s]=structuredClone(n);else a.node.children=structuredClone(n);return!0}return!1}function Po(e,t){ge(e,"",({node:n})=>{if(n.id)t.add(n.id)})}function Ao(e,t){let n=new Set;for(let o of e){if(o.id===t)continue;Po(o.blocks,n)}return n}function Eo(e,t,n){let o=new Set,r=(a)=>{let s=`${n}-${a}`;if(t.has(s)||o.has(s)){let i=2;while(t.has(`${s}-${i}`)||o.has(`${s}-${i}`))i+=1;s=`${s}-${i}`}return s};ge(e,"",({node:a})=>{if(!a.id)return;if(t.has(a.id)||o.has(a.id))a.id=r(a.id);o.add(a.id)})}function To(e,t,n){let o=new Set;if(!t)return o;for(let r of Object.values(t.slotBindings)){if(r.kind==="page-field")continue;let a=kt(e.blocks,r,`${n}.blocks`);if(!a)continue;if(r.kind==="block-node")o.add(`${a.path}.*`);else if(r.kind==="block-prop"&&r.property)o.add(`${a.path}.props.${r.property}`);else if(r.kind==="block-events")o.add(r.property?`${a.path}.events.${r.property}`:`${a.path}.events.*`);else if(r.kind==="block-children")o.add(r.property?`${a.path}.slots.${r.property}`:`${a.path}.children`)}return o}function yt(e,t,n,o,r){let a=Math.min(e.length,t.length);for(let s=0;s<a;s++){let i=e[s],c=t[s];if(!i||!c)continue;let l=`${n}[${s}]`;if(o.has(`${l}.*`))continue;if(i.type!==c.type){r.push({code:"unmapped-block",path:l,message:`Customized block "${i.type}" does not match template structure "${c.type}".`,preservedSummary:j(i)});continue}let d=new Set([...Object.keys(i.props??{}),...Object.keys(c.props??{})]);for(let p of d){let f=`${l}.props.${p}`;if(o.has(f))continue;let m=i.props?.[p],h=c.props?.[p];if(S(m)!==S(h))r.push({code:"unmapped-frame-prop",path:f,message:`Customized layout prop "${p}" cannot be projected onto target variant.`,preservedSummary:`${p}=${j(m??null)}`})}let u=new Set([...Object.keys(i.events??{}),...Object.keys(c.events??{})]);for(let p of u){let f=`${l}.events.${p}`;if(o.has(`${l}.events.*`)||o.has(f))continue;let m=i.events?.[p],h=c.events?.[p];if(S(m)!==S(h))r.push({code:"unmapped-event",path:f,message:`Customized event "${p}" outside semantic slots cannot be mapped.`,preservedSummary:`${p}:${j(m??null)}`})}if(!o.has(`${l}.children`))yt(i.children??[],c.children??[],`${l}.children`,o,r);let g=new Set([...Object.keys(i.slots??{}),...Object.keys(c.slots??{})]);for(let p of g){if(o.has(`${l}.slots.${p}`))continue;yt(i.slots?.[p]??[],c.slots?.[p]??[],`${l}.slots.${p}`,o,r)}}for(let s=a;s<e.length;s++){let i=e[s];if(!i)continue;let c=`${n}[${s}]`;if(o.has(`${c}.*`))continue;r.push({code:"unmapped-block",path:c,message:"Extra user-added block outside semantic slots is not in target variant.",preservedSummary:j(i)})}}function Do(e,t){let n=e.variants.find((a)=>a.id===t);if(n)return n;let o=e.variants.find((a)=>a.aliases?.includes(t));if(o)return o;let r=e.variants.filter((a)=>a.id.endsWith(`:${t}`));if(r.length===1&&r[0])return r[0];throw Error(`unknown-variant:${e.familyId}:${t}`)}function Fe(e,t){e.composition??={schema:"uibot.solution-composition.v1",pages:[]},e.composition.variants=[...(e.composition.variants??[]).filter((n)=>!(n.targetKind===t.targetKind&&n.targetId===t.targetId&&n.familyId===t.familyId)),t]}function Oo(e,t,n){let o=e.composition?.variants?.find((i)=>i.targetKind==="page"&&i.targetId===t.id&&i.familyId===n.familyId);if(o){let i=n.variants.find((c)=>c.id===o.variantId);if(i)return i}let r=e.composition?.pages.find((i)=>i.targetPageId===t.id);if(r){let i=n.variants.find((c)=>c.resourceId===r.resourceId);if(i)return i}let a,s=-1;for(let i of n.variants){let c=i.pageTemplate;if(!c)continue;let l=0;if(c.id===t.id)l+=4;if(c.blocks.length>0&&t.blocks.length>0&&c.blocks[0]?.type===t.blocks[0]?.type)l+=2;for(let d of n.semanticSlots){let u=i.slotBindings[d.id];if(!u||u.kind==="page-field")continue;let g=oe(t,u,"page"),p=oe(c,u,"template");if(g.value!==void 0){if(l+=2,S(g.value)===S(p.value))l+=3}}if(c.state&&t.state)for(let[d,u]of Object.entries(c.state)){if(d==="currentPath")continue;if(d in t.state){if(l+=1,S(t.state[d])===S(u))l+=2}}if(l>s)s=l,a=i}return a}function Bo(e,t,n,o){let r=o.preserveCustomizations??!0,a=o.target.pageId??(e.pages.length===1?e.pages[0]?.id:void 0),s=e.pages.findIndex((b)=>b.id===a);if(s<0)throw Error(`unknown-variant-target-page:${o.target.pageId??""}`);let i=e.pages[s];if(!i||!n.pageTemplate)throw Error(`missing-variant-payload:${t.familyId}:${n.id}`);let c=Oo(e,i,t),l=c?.pageTemplate,d=`pages[${s}]`,u=Ao(e.pages,i.id),g=[];for(let b of t.semanticSlots){let C=c?.slotBindings[b.id]??n.slotBindings[b.id];if(!C)continue;let E=oe(i,C,d);if(E.value===void 0)continue;let A=l?oe(l,C,"baseline"):{value:void 0,path:"baseline"},y=A.value===void 0||S(E.value)!==S(A.value);if(b.preserveMode==="always"||r&&y)g.push({slotId:b.id,value:E.value,baselineValue:A.value,sourcePath:E.path})}let p=[];if(l&&r){let b=To(i,c,d);yt(i.blocks,l.blocks,`${d}.blocks`,b,p)}let f=structuredClone(n.pageTemplate);f.id=i.id,f.path=i.path;let m=i.title!==void 0&&l?.title!==void 0&&i.title!==l.title;if(i.title!==void 0&&(m&&r||f.title===void 0))f.title=i.title;if(i.layout)f.layout=structuredClone(i.layout);if(i.auth)f.auth=structuredClone(i.auth);if(i.lifecycle)f.lifecycle=structuredClone(i.lifecycle);if(i.computed)f.computed=structuredClone(i.computed);if(i.urlState)f.urlState=structuredClone(i.urlState);let h={...f.state??{}};if(i.state)for(let[b,C]of Object.entries(i.state)){if(b==="currentPath")continue;if(!l?.state||!(b in l.state)){h[b]=structuredClone(C);continue}if(S(C)!==S(l.state[b]))h[b]=structuredClone(C);else if(!(b in h))h[b]=structuredClone(C)}if("currentPath"in h||i.state?.currentPath!==void 0)h.currentPath=i.path;if(Object.keys(h).length>0)f.state=h;for(let b of g){let C=n.slotBindings[b.slotId];if(!C){p.push({code:"unmapped-slot",slotId:b.slotId,path:b.sourcePath,message:`Target variant "${n.id}" does not expose semantic slot "${b.slotId}".`,preservedSummary:j(b.value)});continue}let E=oe(n.pageTemplate,C,"targetTemplate").value;if(!hn(f,C,b.value,b.baselineValue??E,u))p.push({code:"unmapped-slot",slotId:b.slotId,path:b.sourcePath,message:`Target variant "${n.id}" slot "${b.slotId}" could not be located during projection.`,preservedSummary:j(b.value)})}let x=Le(n.pageTemplate.lifecycle),k=Le(f.lifecycle??i.lifecycle);if(x&&k&&x!==k)bt(f.blocks,x,k);return Eo(f.blocks,u,f.id),e.pages[s]=f,Fe(e,{familyId:t.familyId,variantId:n.id,targetKind:"page",targetId:f.id}),B(e),{spec:e,familyId:t.familyId,...c?{fromVariantId:c.id}:{},toVariantId:n.id,changedPaths:[d],unmappedWarnings:p}}function Le(e){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let n of e){let o=Le(n);if(o)return o}return}let t=e;if(typeof t.connectionId==="string"&&t.connectionId)return t.connectionId;for(let n of Object.values(t)){let o=Le(n);if(o)return o}return}function bt(e,t,n){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let r of e)bt(r,t,n);return}let o=e;if(o.connectionId===t)o.connectionId=n;for(let r of Object.values(o))bt(r,t,n)}function No(e,t){let n=e.composition?.variants?.find((r)=>r.targetKind==="shell"&&r.familyId===t.familyId);if(n){let r=t.variants.find((a)=>a.id===n.variantId||a.aliases?.includes(n.variantId));if(r)return r}let o=e.layout;if(!o)return;if(o.shell){let r=t.variants.filter((a)=>a.shellLayout?.shell===o.shell);if(r.length===1)return r[0];if(r.length>1)return r.find((a)=>Object.entries(a.shellLayout??{}).every(([s,i])=>o[s]===i))??r.find((a)=>o.sidebar?a.shellLayout?.sidebar===o.sidebar:!0)??r[0]}return t.variants.find((r)=>{if(!r.shellLayout)return!1;let a=Object.entries(r.shellLayout).filter(([s])=>s!=="shell");return a.length>0&&a.every(([s,i])=>o[s]===i)})}function $o(e,t,n,o){if(!n.shellLayout)throw Error(`missing-variant-payload:${t.familyId}:${n.id}`);let r=No(e,t),a=structuredClone(e.layout??{}),s=n.shellCapabilities?.supportsSidebarBehavior??n.shellCapabilities?.supportsSidebarSlots??!0,i=n.shellCapabilities?.sidebarSlotPlacement??(n.shellCapabilities?.supportsSidebarSlots??!0?"sidebar":"hidden"),{sidebar:c,shell:l,...d}=a,u={...d,...s&&c!==void 0?{sidebar:c}:{},...structuredClone(n.shellLayout)},g=[];if(!s&&c!==void 0)g.push({code:"unmapped-shell-option",path:"layout.sidebar",...t.semanticSlots.some((p)=>p.id==="sidebarBehavior")?{slotId:"sidebarBehavior"}:{},message:`Target shell "${n.id}" does not use sidebar folding behavior.`,preservedSummary:`sidebar=${c}`});if(i==="hidden")for(let p=0;p<e.pages.length;p++){let f=e.pages[p];if(!f||f.layout?.inherit===!1)continue;ge(f.blocks,`pages[${p}].blocks`,({node:m,path:h})=>{if(m.type==="PageLayout"&&m.slots?.sidebar?.length)g.push({code:"unmapped-slot",path:`${h}.slots.sidebar`,message:`PageLayout sidebar slot on page "${f.id}" is hidden under "${n.id}".`,preservedSummary:j(m.slots.sidebar)})})}return e.layout=u,Fe(e,{familyId:t.familyId,variantId:n.id,targetKind:"shell",targetId:"spec"}),B(e),{spec:e,familyId:t.familyId,...r?{fromVariantId:r.id}:{},toVariantId:n.id,changedPaths:["layout"],unmappedWarnings:g}}function Mo(e,t,n,o){if(!n.frameTemplate)throw Error(`missing-variant-payload:${t.familyId}:${n.id}`);let r=o.pageMapping??(o.target.pageId?{[o.target.role??o.target.pageId]:o.target.pageId}:{}),a=t.variants.find((c)=>Object.values(r).some((l)=>e.composition?.regions?.some((d)=>d.targetPageId===l&&(d.resourceId===c.resourceId||d.resourceId===`layout:${c.id}`)))),s={identity:n.identity??{resourceId:n.resourceId??`layout:${n.id}`,version:"1",sourceHash:fe(S(n.frameTemplate))},contentBlockId:n.frameTemplate.contentBlockId,frame:structuredClone(n.frameTemplate.frame)},i=ht(e,s,r);for(let c of Object.values(r))Fe(i.spec,{familyId:t.familyId,variantId:n.id,targetKind:"frame",targetId:c});return B(i.spec),{spec:i.spec,familyId:t.familyId,...a?{fromVariantId:a.id}:{},toVariantId:n.id,changedPaths:Object.values(r).map((c)=>{let l=i.spec.pages.findIndex((d)=>d.id===c);return l>=0?`pages[${l}].blocks[0]`:`pages.${c}.blocks[0]`}),unmappedWarnings:i.unmappedWarnings}}function _o(e,t,n,o){let r=n.map((p,f)=>{if(typeof p==="number"||f===0)return p;if(/^(0|[1-9]\d*)$/.test(p)||p.startsWith("@"))return p;if(p.startsWith("slots."))return`@${p.slice(6)}`;return`@${p}`}),a=J(r,{allowRoot:!1,allowSlotEnd:!1}),s=e.blocks,i=null,c=e.blocks,l=0,d,u=`pages[${t}].blocks`,g=0;while(g<a.length){let p=a[g];if(typeof p==="string"&&p.startsWith("@")){let f=p.slice(1),m=a[g+1];if(!i||typeof m!=="number")return;let h=i.slots?.[f];if(!h?.[m])return;c=h,l=m,d=h[m],i=d??null,s=d?.children??[],u=`${u}.slots.${f}[${m}]`,g+=2;continue}if(typeof p!=="number"||!s[p])return;c=s,l=p,d=s[p],i=d??null,s=d?.children??[],u=g===0?`${u}[${p}]`:`${u}.children[${p}]`,g+=1}if(!d)return;if(o&&d.id!==o)throw Error(`mismatched-variant-target-block:${o}`);return{pageIndex:t,blockPath:u,block:d,replace:(p)=>{c[l]=p}}}function Lo(e,t,n,o){for(let r=0;r<e.pages.length;r++){let a=e.pages[r];if(!a||t&&a.id!==t)continue;if(o!==void 0){let c=_o(a,r,o,n);if(c)return c;continue}let s=(c,l)=>{for(let d=0;d<c.length;d++){let u=c[d];if(!u)continue;let g=`${l}[${d}]`;if(n?u.id===n:c.length===1&&l.endsWith(".blocks"))return{pageIndex:r,blockPath:g,block:u,replace:(p)=>{c[d]=p}};if(u.children?.length){let p=s(u.children,`${g}.children`);if(p)return p}for(let[p,f]of Object.entries(u.slots??{})){let m=s(f,`${g}.slots.${p}`);if(m)return m}}return},i=s(a.blocks,`pages[${r}].blocks`);if(i)return i}throw Error(`unknown-variant-target-block:${n??""}`)}function jo(e,t){let n,o=-1;for(let r of t.variants){let a=r.blockTemplate;if(!a||a.type!==e.type)continue;let s=1;for(let[i,c]of Object.entries(a.props??{}))if(S(e.props?.[i])===S(c))s+=2;if(s>o)o=s,n=r}return n}function Fo(e,t,n,o){if(!n.blockTemplate)throw Error(`missing-variant-payload:${t.familyId}:${n.id}`);let r=o.preserveCustomizations??!0,a=Lo(e,o.target.pageId,o.target.blockId,o.target.blockPath),s=a.block,i=jo(s,t),c={id:"_block",path:"/_block",blocks:[s]},l={id:"_target",path:"/_target",blocks:[structuredClone(n.blockTemplate)]},d=new Set(t.presentationProps??[]),u=new Set,g=new Set,p=!1,f=(k)=>{if(!k)return;if(k.kind==="block-prop"&&k.property)d.add(k.property);if(k.kind==="block-events")if(k.property)u.add(k.property);else for(let b of Object.keys(s.events??{}))u.add(b);if(k.kind==="block-children")if(k.property)g.add(k.property);else p=!0},m=[];for(let k of t.semanticSlots){let b=i?.slotBindings[k.id]??n.slotBindings[k.id];if(f(b),!b)continue;let C=oe(c,b,a.blockPath);if(C.value===void 0)continue;let E=i?.blockTemplate?oe({id:"_base",path:"/_base",blocks:[i.blockTemplate]},b,"baseline").value:void 0,A=E===void 0||S(C.value)!==S(E);if(k.preserveMode!=="always"&&!(r&&A))continue;let y=n.slotBindings[k.id];if(!y){m.push({code:"unmapped-slot",slotId:k.id,path:C.path,message:`Target variant "${n.id}" does not support semantic slot "${k.id}".`,preservedSummary:j(C.value)});continue}hn(l,y,C.value,E,new Set)}let h=l.blocks[0];if(!h)throw Error("variant-block-instantiation-failed");if(s.id)h.id=s.id;if(s.visible!==void 0)h.visible=structuredClone(s.visible);let x=s.type===h.type;for(let[k,b]of Object.entries(s.props??{})){if(d.has(k))continue;if(x)h.props??={},h.props[k]=structuredClone(b);else m.push({code:"unmapped-prop",path:`${a.blockPath}.props.${k}`,message:`Custom property "${k}" on "${s.type}" does not map to "${h.type}".`,preservedSummary:`${k}=${j(b)}`})}for(let[k,b]of Object.entries(s.events??{})){if(u.has(k))continue;if(x)h.events??={},h.events[k]=structuredClone(b);else m.push({code:"unmapped-event",path:`${a.blockPath}.events.${k}`,message:`Event handler "${k}" on "${s.type}" does not map to "${h.type}".`,preservedSummary:j(b)})}for(let[k,b]of Object.entries(s.slots??{})){if(g.has(k))continue;if(x)h.slots??={},h.slots[k]=structuredClone(b);else m.push({code:"unmapped-slot",path:`${a.blockPath}.slots.${k}`,message:`Named slot "${k}" on "${s.type}" does not map to "${h.type}".`,preservedSummary:j(b)})}if(!p&&s.children?.length)if(x)h.children=structuredClone(s.children);else m.push({code:"unmapped-block",path:`${a.blockPath}.children`,message:`Child blocks of "${s.type}" cannot auto-map onto "${h.type}".`,preservedSummary:j(s.children)});return a.replace(h),Fe(e,{familyId:t.familyId,variantId:n.id,targetKind:t.targetKind,targetId:s.id??a.blockPath}),B(e),{spec:e,familyId:t.familyId,...i?{fromVariantId:i.id}:{},toVariantId:n.id,changedPaths:[a.blockPath],unmappedWarnings:m}}function Vo(e,t){if(t.familyId){let o=!Array.isArray(e)&&"get"in e?e.get(t.familyId):e.find((r)=>r.familyId===t.familyId);if(!o)throw Error(`unknown-variant-family:${t.familyId}`);return o}let n=je(e,{targetKind:t.target.kind}).filter((o)=>o.variants.some((r)=>r.id===t.targetVariantId||Boolean(r.aliases?.includes(t.targetVariantId))||r.id.endsWith(`:${t.targetVariantId}`)));if(n.length===1&&n[0])return n[0];if(n.length>1){let o=t.target.kind==="shell"?"spec":t.target.kind==="page"||t.target.kind==="frame"?t.target.pageId:t.target.blockId??(t.target.blockPath?`pages[${Math.max(0,t.spec.pages.findIndex((a)=>a.id===t.target.pageId))}].blocks.${t.target.blockPath.join(".")}`:void 0),r=(t.spec.composition?.variants??[]).filter((a)=>a.targetKind===t.target.kind&&(!o||a.targetId===o)).map((a)=>n.find((s)=>s.familyId===a.familyId)).filter((a)=>Boolean(a));if(r.length===1&&r[0])return r[0]}throw Error("ambiguous-or-unknown-variant-family")}function ie(e,t){let n=Vo(e,t);if(et(n),n.targetKind!==t.target.kind)throw Error(`variant-target-kind-mismatch:${n.targetKind}:${t.target.kind}`);let o=Do(n,t.targetVariantId),r=structuredClone(t.spec);if(B(r),n.targetKind==="shell")return $o(r,n,o,t);if(n.targetKind==="frame")return Mo(r,n,o,t);if(n.targetKind==="page")return Bo(r,n,o,t);return Fo(r,n,o,t)}var Uo=(e)=>Boolean(e)&&typeof e==="object"&&!Array.isArray(e);function vt(e,t,n){for(let o of e){if(o===n)continue;if(o.id)t.add(o.id);if(o.children?.length)vt(o.children,t,n);for(let r of Object.values(o.slots??{}))vt(r,t,n)}}function Ve(e,t){let n=new Set;for(let o of e.pages)vt(o.blocks,n,t);return n}function Ue(e,t,n,o){let r=new Set,a=(s)=>{if(s.id){if(t.has(s.id)||r.has(s.id))throw new w("invalid-spec-patch",n,o,`duplicate block id "${s.id}"`);r.add(s.id)}for(let i of s.children??[])a(i);for(let i of Object.values(s.slots??{}))for(let c of i)a(c)};a(e)}function Pe(e,t,n,o){let r=e.pages.findIndex((s)=>s.id===t),a=r>=0?e.pages[r]:void 0;if(!a)throw new w("patch-page-not-found",n,o,`unknown page "${t}"`);return{page:a,pageIndex:r}}function ze(e,t,n,o,r){for(let a=0;a<e.length;a++){let s=e[a];if(!s)continue;let i=[...n,a];if(s.id===t)return{pageIndex:r,page:o,node:s,path:i,parentList:e,index:a};if(s.children?.length){let c=ze(s.children,t,i,o,r);if(c)return c}for(let[c,l]of Object.entries(s.slots??{})){let d=ze(l,t,[...i,`@${c}`],o,r);if(d)return d}}return}function Ct(e,t,n,o,r){let a;try{a=J(n,{allowRoot:!1,allowSlotEnd:!1})}catch{throw new w("invalid-spec-block-path",o,r,"malformed blockPath")}let s=e.blocks,i=null,c,l=e.blocks,d=0,u=0;while(u<a.length){let g=a[u];if(typeof g==="string"&&g.startsWith("@")){let p=g.slice(1),f=a[u+1];if(!i||typeof f!=="number")throw new w("patch-block-not-found",o,r,"invalid slot path");let m=i.slots?.[p];if(!m?.[f])throw new w("patch-block-not-found",o,r,`block missing at slot "${p}[${f}]"`);l=m,d=f,c=m[f],i=c??null,s=c?.children??[],u+=2;continue}if(typeof g!=="number")throw new w("invalid-spec-block-path",o,r,"expected index segment");if(!s[g])throw new w("patch-block-not-found",o,r,`block missing at path segment ${g}`);l=s,d=g,c=s[g],i=c??null,s=c?.children??[],u+=1}if(!c)throw new w("patch-block-not-found",o,r,"target block not found");return{pageIndex:t,page:e,node:c,path:a,parentList:l,index:d}}function me(e,t,n,o){let{page:r,pageIndex:a}=Pe(e,t.pageId,n,o);if(t.blockPath!==void 0)return Ct(r,a,t.blockPath,n,o);if(t.blockId){let s=ze(r.blocks,t.blockId,[],r,a);if(!s)throw new w("patch-block-not-found",n,o,`unknown blockId "${t.blockId}" on page "${t.pageId}"`);return s}throw new w("invalid-spec-patch",n,o,"locator needs blockId or blockPath")}function xt(e,t,n,o){let{page:r,pageIndex:a}=Pe(e,t.pageId,n,o);if(t.parentBlockId){let s=ze(r.blocks,t.parentBlockId,[],r,a);if(!s)throw new w("patch-block-not-found",n,o,`unknown parentBlockId "${t.parentBlockId}"`);let i=s.node;if(t.slot){let c=t.slot;return{page:r,parentNode:i,parentNodePath:s.path,list:i.slots?.[c]??[],ensureCreated:()=>(i.slots??={},i.slots[c]??=[],i.slots[c])}}return{page:r,parentNode:i,parentNodePath:s.path,list:i.children??[],ensureCreated:()=>(i.children??=[],i.children)}}if(t.parentPath!==void 0){let s;try{s=J(t.parentPath,{allowRoot:!0,allowSlotEnd:!0})}catch{throw new w("invalid-spec-block-path",n,o,"invalid parentPath")}if(s.length===0){if(t.slot)throw new w("patch-slot-invalid",n,o,"root page has no named slot");return{page:r,parentNode:null,parentNodePath:[],list:r.blocks,ensureCreated:()=>r.blocks}}let i=s[s.length-1];if(typeof i==="string"&&i.startsWith("@")){let l=i.slice(1),d=s.slice(0,-1),u=Ct(r,a,d,n,o);return{page:r,parentNode:u.node,parentNodePath:u.path,list:u.node.slots?.[l]??[],ensureCreated:()=>(u.node.slots??={},u.node.slots[l]??=[],u.node.slots[l])}}let c=Ct(r,a,s,n,o);if(t.slot){let l=t.slot;return{page:r,parentNode:c.node,parentNodePath:c.path,list:c.node.slots?.[l]??[],ensureCreated:()=>(c.node.slots??={},c.node.slots[l]??=[],c.node.slots[l])}}return{page:r,parentNode:c.node,parentNodePath:c.path,list:c.node.children??[],ensureCreated:()=>(c.node.children??=[],c.node.children)}}if(t.slot)throw new w("patch-slot-invalid",n,o,"slot requires a parent block");return{page:r,parentNode:null,parentNodePath:[],list:r.blocks,ensureCreated:()=>r.blocks}}function zo(e,t){return e.length<=t.length&&e.every((n,o)=>t[o]===n)}function yn(e,t){let n=[];for(let o of e){if("children"in o&&Array.isArray(o.children)){let r=yn(o.children,t);n.push({...o,children:r});continue}if("path"in o&&o.path===t)continue;n.push(o)}return n}function Il(e,t,n={}){De(e),Vt(t,n);let o=structuredClone(e);B(o);let r=new Set,a=[];for(let s=0;s<t.length;s++){let i=t[s];if(!i)continue;switch(i.op){case"addPage":{let c=o.pages.some((p)=>p.id===i.page.id),l=o.pages.some((p)=>p.path===i.page.path);if(c||l)throw new w("patch-page-conflict",s,i.op,`page id "${i.page.id}" or path "${i.page.path}" already exists`);let d=Ve(o),u=structuredClone(i.page);for(let p of u.blocks)Ue(p,d,s,i.op);let g=i.index!==void 0?Math.max(0,Math.min(i.index,o.pages.length)):o.pages.length;if(o.pages.splice(g,0,u),i.addToMenu===!0)o.menus??={items:[]},o.menus.items.push({key:`page:${u.id}`,label:u.title??u.id,path:u.path}),r.add("menus");r.add("pages");break}case"removePage":{let{page:c,pageIndex:l}=Pe(o,i.pageId,s,i.op);if(o.pages.splice(l,1),o.composition){if(o.composition.pages=o.composition.pages.filter((d)=>d.targetPageId!==i.pageId),o.composition.regions)o.composition.regions=o.composition.regions.filter((d)=>d.targetPageId!==i.pageId);if(o.composition.variants)o.composition.variants=o.composition.variants.filter((d)=>!((d.targetKind==="page"||d.targetKind==="frame")&&d.targetId===i.pageId))}if(i.removeFromMenu!==!1&&o.menus?.items)o.menus.items=yn(o.menus.items,c.path),r.add("menus");r.add("pages");break}case"updatePage":{let{page:c,pageIndex:l}=Pe(o,i.pageId,s,i.op);if(i.patch.path!==void 0){if(o.pages.some((u,g)=>g!==l&&u.path===i.patch.path))throw new w("patch-page-conflict",s,i.op,`page path "${i.patch.path}" already exists`);c.path=i.patch.path}if(i.patch.title!==void 0)c.title=i.patch.title;if(i.patch.layout!==void 0)c.layout=structuredClone(i.patch.layout);if(i.patch.auth!==void 0)c.auth=structuredClone(i.patch.auth);r.add(`pages[${l}]`);break}case"setPageState":{let{page:c,pageIndex:l}=Pe(o,i.pageId,s,i.op);if(i.state)c.state={...c.state,...structuredClone(i.state)};if(i.removeStateKeys?.length&&c.state)for(let d of i.removeStateKeys)delete c.state[d];if(i.computed!==void 0)c.computed=structuredClone(i.computed);if(i.lifecycle!==void 0)c.lifecycle=structuredClone(i.lifecycle);if(i.urlState!==void 0)c.urlState=structuredClone(i.urlState);r.add(`pages[${l}]`);break}case"insertBlock":{let c=xt(o,i.target,s,i.op),l=Ve(o),d=structuredClone(i.block);Ue(d,l,s,i.op);let u=c.ensureCreated(),g=i.target.index!==void 0?Math.max(0,Math.min(i.target.index,u.length)):u.length;u.splice(g,0,d);let p=o.pages.indexOf(c.page);r.add(`pages[${p}].blocks`);break}case"replaceBlock":{let c=me(o,i.target,s,i.op),l=Ve(o,c.node),d=structuredClone(i.block);if((i.preserveId??!0)&&!d.id&&c.node.id)d.id=c.node.id;Ue(d,l,s,i.op),c.parentList[c.index]=d,r.add(`pages[${c.pageIndex}].blocks`);break}case"removeBlock":{let c=me(o,i.target,s,i.op);c.parentList.splice(c.index,1),r.add(`pages[${c.pageIndex}].blocks`);break}case"moveBlock":{if(i.from.pageId!==i.to.pageId){let f=me(o,i.from,s,i.op),m=xt(o,i.to,s,i.op),h=Ve(o,f.node);Ue(f.node,h,s,i.op);let[x]=f.parentList.splice(f.index,1);if(!x)break;let k=m.ensureCreated(),b=i.to.index!==void 0?Math.max(0,Math.min(i.to.index,k.length)):k.length;k.splice(b,0,x),r.add(`pages[${f.pageIndex}].blocks`),r.add(`pages[${o.pages.indexOf(m.page)}].blocks`);break}let c=me(o,i.from,s,i.op),l=xt(o,i.to,s,i.op);if(zo(c.path,l.parentNodePath))throw new w("patch-move-cycle",s,i.op,"cannot move a block into itself or its descendant");let d=l.ensureCreated(),u=d===c.parentList,g=i.to.index!==void 0?Math.max(0,Math.min(i.to.index,d.length)):d.length,[p]=c.parentList.splice(c.index,1);if(!p)break;if(u&&g>c.index)g=Math.max(0,g-1);d.splice(g,0,p),r.add(`pages[${c.pageIndex}].blocks`);break}case"updateProps":{let c=me(o,i.target,s,i.op),l={...c.node.props};for(let[d,u]of Object.entries(i.props))l[d]=structuredClone(u);if(i.removeKeys?.length)for(let d of i.removeKeys)delete l[d];if(Object.keys(l).length>0)c.node.props=l;else delete c.node.props;r.add(`pages[${c.pageIndex}].blocks`);break}case"setEvents":{let c=me(o,i.target,s,i.op),l=i.merge?{...c.node.events}:{};for(let[d,u]of Object.entries(i.events))l[d]=structuredClone(u);if(i.removeEvents?.length)for(let d of i.removeEvents)delete l[d];if(Object.keys(l).length>0)c.node.events=l;else delete c.node.events;r.add(`pages[${c.pageIndex}].blocks`);break}case"upsertEntity":{let c=structuredClone(o.data?.entities??{});c[i.name]=structuredClone(i.entity);try{o.data=Y({entities:c})}catch(l){throw new w("invalid-spec-patch",s,i.op,l instanceof Error?l.message:"invalid entity")}r.add(`data.entities.${i.name}`);break}case"removeEntity":{if(!o.data?.entities||!Object.hasOwn(o.data.entities,i.name))throw new w("patch-entity-not-found",s,i.op,`unknown entity "${i.name}"`);let c=structuredClone(o.data.entities);delete c[i.name],o.data=Y({entities:c}),r.add("data.entities");break}case"upsertConnection":{if(o.data?.entities&&!Object.hasOwn(o.data.entities,i.connection.entity))throw new w("patch-entity-not-found",s,i.op,`connection references undeclared entity "${i.connection.entity}"`);let c=structuredClone(i.connection);o.connections??=[];let l=o.connections.findIndex((d)=>d.id===c.id);if(l>=0)o.connections[l]=c;else o.connections.push(c);r.add("connections");break}case"removeConnection":{let c=o.connections?.findIndex((l)=>l.id===i.connectionId)??-1;if(c<0)throw new w("patch-connection-not-found",s,i.op,`unknown connection "${i.connectionId}"`);o.connections?.splice(c,1),r.add("connections");break}case"setLayout":{o.layout=i.merge?{...o.layout,...structuredClone(i.layout)}:structuredClone(i.layout),r.add("layout");break}case"setMenus":{o.menus=structuredClone(i.menus),r.add("menus");break}case"setDesign":{let c=structuredClone(i.design);if(i.merge&&o.design)o.design={...o.design,...c,...o.design.tokens||c.tokens?{tokens:{...o.design.tokens,...c.tokens}}:{}};else o.design=c;r.add("design");break}case"swapVariant":{if(!n.variantRegistry)throw new w("patch-variant-failed",s,i.op,"variantRegistry option is required for swapVariant patch ops");try{let c,l=-1;if(i.target.kind==="page"&&i.target.pageId){l=o.pages.findIndex((g)=>g.id===i.target.pageId);let u=l>=0?o.pages[l]:void 0;if(u&&u.blocks.length===1&&u.blocks[0]?.type==="PageLayout"&&u.blocks[0].children&&Uo(u.blocks[0].children)===!1){let g=u.blocks[0];c={...g,children:[]},u.blocks=structuredClone(g.children??[])}}let d=ie(n.variantRegistry,{spec:o,...i.familyId!==void 0?{familyId:i.familyId}:{},target:i.target,targetVariantId:i.targetVariantId,...i.preserveCustomizations!==void 0?{preserveCustomizations:i.preserveCustomizations}:{},...i.pageMapping?{pageMapping:i.pageMapping}:{}});if(o=d.spec,c&&l>=0){let u=o.pages[l];if(u&&!u.blocks.some((g)=>g.type==="PageLayout"))c.children=u.blocks,u.blocks=[c]}for(let u of d.changedPaths)r.add(u);a.push(...d.unmappedWarnings)}catch(c){throw new w("patch-variant-failed",s,i.op,c instanceof Error?c.message:"swapVariant failed")}break}}}return B(o),{spec:o,appliedCount:t.length,changedPaths:[...r],unmappedWarnings:a}}var Ho=new Set(["__proto__","prototype","constructor"]);function bn(e){let t=e.trim();if(!t)return"/";return t.startsWith("/")?t:`/${t}`}function wt(e,t){for(let n of e){if(n.id)t.add(n.id);if(n.children?.length)wt(n.children,t);for(let o of Object.values(n.slots??{}))wt(o,t)}}function kn(e,t,n){let o=(r)=>{for(let a of r){if(a.id){if(n.has(a.id)){let s=`${t}-${a.id}`,i=2;while(n.has(s))s=`${t}-${a.id}-${i}`,i+=1;a.id=s}n.add(a.id)}if(a.children?.length)o(a.children);for(let s of Object.values(a.slots??{}))o(s)}};o(e)}function qo(e,t,n){if(!e)return;let o=je(e,{targetKind:"shell"});if(n){let r=o.find((a)=>a.familyId===n);if(r)return r}return o.find((r)=>r.variants.some((a)=>a.id===t))??o[0]}function Ko(e,t){if(!e)return{};let n=je(e,{targetKind:"page"});if(t.familyId){let o=n.find((a)=>a.familyId===t.familyId);if(!o)throw Error(`unknown-variant-family:${t.familyId}`);if(t.solutionId){let a=`template:${t.solutionId}`;if(!o.variants.some((i)=>i.resourceId===a||i.id===t.solutionId))throw Error(`blueprint-solution-variant-mismatch:${t.solutionId}:${t.familyId}`)}let r=t.variantId?o.variants.find((a)=>a.id===t.variantId):o.variants[0];if(t.variantId&&!r)throw Error(`unknown-variant:${o.familyId}:${t.variantId}`);return{family:o,...r?{variant:r}:{}}}if(t.solutionId){let o=`template:${t.solutionId}`;for(let r of n){let a=r.variants.find((s)=>s.resourceId===o);if(a){let s=t.variantId?r.variants.find((i)=>i.id===t.variantId):a;if(t.variantId&&!s)throw Error(`unknown-variant:${r.familyId}:${t.variantId}`);return{family:r,...s?{variant:s}:{}}}}}return{}}function xn(e,t,n,o){if(!t)return;if(e.blocks.some((s)=>s.type==="PageLayout"||Boolean(s.template)))return;let r=`${e.id}-shell`,a=2;while(n.has(r))r=`${e.id}-shell-${a}`,a+=1;n.add(r),e.blocks=[{id:r,type:"PageLayout",props:{title:e.title??o??e.id},children:e.blocks}]}function Tl(e,t={}){Ft(e);let n={version:"2.0",pages:[],...e.layout?{layout:structuredClone(e.layout)}:{},...e.design?{design:structuredClone(e.design)}:{},...e.auth?{auth:structuredClone(e.auth)}:{},...e.menus?{menus:structuredClone(e.menus)}:{}};if(e.entities&&Object.keys(e.entities).length>0)n.data=Y({entities:structuredClone(e.entities)});let o=[];if(e.connections?.length){let l=[];for(let d of e.connections){let u=d.mockSeed!==void 0||d.mockGenerate!==void 0;l.push({id:d.id,type:"Collection",entity:d.entity,...u?{mock:{...d.mockSeed?{seed:structuredClone(d.mockSeed)}:{},...d.mockGenerate!==void 0?{generate:d.mockGenerate}:{}}}:{}}),o.push(d.id)}n.connections=l}let r=[];if(e.shellVariant){let l=qo(t.variantRegistry,e.shellVariant,t.shellFamilyId??"shell.workspace.v1");if(!l)throw Error(`unknown-shell-variant:${e.shellVariant}`);let d=ie(t.variantRegistry??[l],{spec:n,familyId:l.familyId,target:{kind:"shell"},targetVariantId:e.shellVariant});if(n=d.spec,r.push(...d.unmappedWarnings),e.layout)n.layout={...n.layout,...structuredClone(e.layout)}}let a=Boolean(e.shellVariant||n.layout),s=new Set,i=[],c=[];for(let l of e.pages){if(l.kind==="blocks"||l.kind===void 0&&"blocks"in l){let v=l,I=bn(v.path);if(n.pages.some((ee)=>ee.id===v.id||ee.path===I)||Ho.has(v.id))throw Error(`solution-page-conflict:${v.id}:${I}`);let R={id:v.id,path:I,...v.title!==void 0?{title:v.title}:{},...v.standalone?{layout:{inherit:!1}}:{},...v.state?{state:structuredClone(v.state)}:{},blocks:structuredClone(v.blocks)};kn(R.blocks,R.id,s);let P=!v.standalone&&(v.wrapInShell??a);if(xn(R,P,s,e.title),n.pages.push(R),i.push({id:R.id,path:R.path}),!v.standalone)c.push({id:R.id,label:R.title??R.id,path:R.path});continue}let u=l,{family:g,variant:p}=Ko(t.variantRegistry,u),f=t.solutions??[],m=u.solutionId?f.find((v)=>v.id===u.solutionId):void 0;if(!m&&p?.resourceId?.startsWith("template:")){let v=p.resourceId.slice(9);m=f.find((I)=>I.id===v)}let h,x=u.solutionId?`template:${u.solutionId}`:p?.resourceId;if(m){if(h=structuredClone(m.spec),h.auth)n.auth??=structuredClone(h.auth),delete h.auth}else if(p?.pageTemplate)h={version:"2.0",pages:[structuredClone(p.pageTemplate)]},x??=`variant:${g?.familyId??"page"}:${p.id}`;if(!h||h.pages.length===0||!x)throw Error(`unknown-blueprint-solution:${u.solutionId??`${u.familyId??""}:${u.variantId??""}`}`);let k=u.selectedPageIds?h.pages.filter((v)=>u.selectedPageIds?.includes(v.id)):h.pages;if(k.length===0)throw Error("solution-select-pages");let b={...u.connectionBindings};for(let v of h.connections??[]){if(b[v.id])continue;let I=n.connections?.find((P)=>P.id===v.id&&P.entity===v.entity);if(I){b[v.id]=I.id;continue}let R=n.connections?.filter((P)=>P.entity===v.entity)??[];if(R.length===1&&R[0])b[v.id]=R[0].id;else b[v.id]=v.id}let C={...u.pathBindings},E={};if(k.length===1&&k[0]){let v=k[0];if(u.id)E[v.id]=u.id;if(u.path)C[v.path]=bn(u.path)}for(let v of k){let I=E[v.id]??v.id;kn(v.blocks,I,s)}let A=n.auth?structuredClone(n.auth):void 0;if(A)delete n.auth;let y=p?.identity??{resourceId:x,version:"0.22.0",sourceHash:fe(S(h))},T=un(n,{identity:y,spec:h,...m?.controls?{controls:m.controls}:{}},{...u.selectedPageIds?{selectedPageIds:u.selectedPageIds}:{},...Object.keys(C).length?{paths:C}:{},...Object.keys(E).length?{pageIds:E}:{},connections:b,layout:"target",...u.configuration?{configuration:u.configuration}:{}});if(n=T.spec,A)n.auth=A;for(let v of T.connections)if(!o.includes(v.id))o.push(v.id);for(let v of T.pages){let I=v.id;if(g&&p&&p.resourceId!==x){let P=ie(t.variantRegistry??[g],{spec:n,familyId:g.familyId,target:{kind:"page",pageId:I},targetVariantId:p.id});n=P.spec,r.push(...P.unmappedWarnings)}else if(g&&p)n.composition??={schema:"uibot.solution-composition.v1",pages:[]},n.composition.variants=[...(n.composition.variants??[]).filter((P)=>!(P.targetKind==="page"&&P.targetId===I&&P.familyId===g.familyId)),{familyId:g.familyId,variantId:p.id,targetKind:"page",targetId:I}];let R=n.pages.find((P)=>P.id===I);if(R){if(u.title!==void 0&&T.pages.length===1)R.title=u.title;if(u.standalone)R.layout={...R.layout,inherit:!1};wt(R.blocks,s);let P=!u.standalone&&(u.wrapInShell??a);if(xn(R,P,s,e.title),i.push({id:R.id,path:R.path}),!u.standalone)c.push({id:R.id,label:R.title??R.id,path:R.path})}}}for(let l of n.connections??[])if(!n.data?.entities||!Object.hasOwn(n.data.entities,l.entity))throw Error(`blueprint-missing-entity:${l.entity}`);if(!n.menus&&c.length>0&&a)n.menus={items:c.map((l)=>({key:`nav-${l.id}`,label:l.label,path:l.path}))};return B(n),{spec:n,addedPages:i,addedConnections:o,unmappedWarnings:r}}function vn(){return`/* Generated by UIBot materialize (uibot.materialize.manifest.v1) */
|
|
16
|
+
:root {
|
|
17
|
+
--um-bg: #ffffff;
|
|
18
|
+
--um-fg: #0f172a;
|
|
19
|
+
--um-muted: #f4f4f5;
|
|
20
|
+
--um-muted-fg: #64748b;
|
|
21
|
+
--um-surface: #ffffff;
|
|
22
|
+
--um-border: #e4e4e7;
|
|
23
|
+
--um-primary: #18181b;
|
|
24
|
+
--um-primary-fg: #fafafa;
|
|
25
|
+
--um-accent: #e4e4e7;
|
|
26
|
+
--um-accent-fg: #18181b;
|
|
27
|
+
--um-radius: 10px;
|
|
28
|
+
--um-font: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.um-dark {
|
|
32
|
+
--um-bg: #09090b;
|
|
33
|
+
--um-fg: #fafafa;
|
|
34
|
+
--um-muted: #18181b;
|
|
35
|
+
--um-muted-fg: #a1a1aa;
|
|
36
|
+
--um-surface: #111113;
|
|
37
|
+
--um-border: #27272a;
|
|
38
|
+
--um-primary: #fafafa;
|
|
39
|
+
--um-primary-fg: #18181b;
|
|
40
|
+
--um-accent: #27272a;
|
|
41
|
+
--um-accent-fg: #fafafa;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.um-root,
|
|
45
|
+
.um-root * {
|
|
46
|
+
box-sizing: border-box;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.um-root {
|
|
50
|
+
font-family: var(--um-font);
|
|
51
|
+
color: var(--um-fg);
|
|
52
|
+
background: var(--um-muted);
|
|
53
|
+
height: 100dvh;
|
|
54
|
+
min-height: 0;
|
|
55
|
+
overflow: hidden;
|
|
56
|
+
display: flex;
|
|
57
|
+
font-size: 14px;
|
|
58
|
+
line-height: 1.5;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.um-root[data-shell="top-navbar"],
|
|
62
|
+
.um-root[data-shell="console-drilldown"] {
|
|
63
|
+
flex-direction: column;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.um-topbar {
|
|
67
|
+
height: 56px;
|
|
68
|
+
flex: none;
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
gap: 14px;
|
|
72
|
+
padding: 0 20px;
|
|
73
|
+
background: var(--um-surface);
|
|
74
|
+
border-bottom: 1px solid var(--um-border);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.um-body {
|
|
78
|
+
flex: 1;
|
|
79
|
+
min-height: 0;
|
|
80
|
+
min-width: 0;
|
|
81
|
+
display: flex;
|
|
82
|
+
overflow: hidden;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.um-sidebar {
|
|
86
|
+
width: 248px;
|
|
87
|
+
flex: none;
|
|
88
|
+
display: flex;
|
|
89
|
+
flex-direction: column;
|
|
90
|
+
min-height: 0;
|
|
91
|
+
background: var(--um-muted);
|
|
92
|
+
border-inline-end: 1px solid var(--um-border);
|
|
93
|
+
padding: 12px 10px;
|
|
94
|
+
gap: 8px;
|
|
95
|
+
overflow-y: auto;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.um-root[data-folded="true"] .um-sidebar {
|
|
99
|
+
width: 68px;
|
|
100
|
+
align-items: center;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.um-root[data-folded="true"] .um-nav-label,
|
|
104
|
+
.um-root[data-folded="true"] .um-nav-group-title,
|
|
105
|
+
.um-root[data-folded="true"] .um-brand-text,
|
|
106
|
+
.um-root[data-folded="true"] .um-badge {
|
|
107
|
+
display: none;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.um-root[data-shell="sidebar-floating"] .um-sidebar {
|
|
111
|
+
margin: 10px;
|
|
112
|
+
border: 1px solid var(--um-border);
|
|
113
|
+
border-radius: 12px;
|
|
114
|
+
background: var(--um-surface);
|
|
115
|
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.um-root[data-shell="sidebar-inset"] .um-main {
|
|
119
|
+
margin: 10px;
|
|
120
|
+
margin-inline-start: 0;
|
|
121
|
+
border: 1px solid var(--um-border);
|
|
122
|
+
border-radius: 12px;
|
|
123
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.um-rail {
|
|
127
|
+
width: 60px;
|
|
128
|
+
flex: none;
|
|
129
|
+
display: flex;
|
|
130
|
+
flex-direction: column;
|
|
131
|
+
align-items: center;
|
|
132
|
+
gap: 6px;
|
|
133
|
+
padding: 10px 6px;
|
|
134
|
+
border-inline-end: 1px solid var(--um-border);
|
|
135
|
+
background: var(--um-muted);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.um-rail-btn {
|
|
139
|
+
width: 40px;
|
|
140
|
+
height: 40px;
|
|
141
|
+
border-radius: 8px;
|
|
142
|
+
display: grid;
|
|
143
|
+
place-items: center;
|
|
144
|
+
color: inherit;
|
|
145
|
+
text-decoration: none;
|
|
146
|
+
border: 0;
|
|
147
|
+
background: transparent;
|
|
148
|
+
cursor: pointer;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.um-rail-btn:hover {
|
|
152
|
+
background: rgba(128, 128, 128, 0.14);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.um-rail-btn[aria-current="page"] {
|
|
156
|
+
background: var(--um-accent);
|
|
157
|
+
color: var(--um-accent-fg);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.um-main {
|
|
161
|
+
flex: 1;
|
|
162
|
+
min-width: 0;
|
|
163
|
+
min-height: 0;
|
|
164
|
+
display: flex;
|
|
165
|
+
flex-direction: column;
|
|
166
|
+
background: var(--um-surface);
|
|
167
|
+
overflow: hidden;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.um-root[data-container="boxed"] {
|
|
171
|
+
padding: 12px;
|
|
172
|
+
gap: 12px;
|
|
173
|
+
justify-content: center;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.um-root[data-container="boxed"] .um-main {
|
|
177
|
+
max-width: 1120px;
|
|
178
|
+
border: 1px solid var(--um-border);
|
|
179
|
+
border-radius: 12px;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.um-content {
|
|
183
|
+
flex: 1;
|
|
184
|
+
min-height: 0;
|
|
185
|
+
overflow-y: auto;
|
|
186
|
+
padding: 24px;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.um-content-inner {
|
|
190
|
+
display: flex;
|
|
191
|
+
flex-direction: column;
|
|
192
|
+
gap: 18px;
|
|
193
|
+
max-width: 1280px;
|
|
194
|
+
margin-inline: auto;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.um-brand {
|
|
198
|
+
display: inline-flex;
|
|
199
|
+
align-items: center;
|
|
200
|
+
gap: 10px;
|
|
201
|
+
text-decoration: none;
|
|
202
|
+
color: inherit;
|
|
203
|
+
font-weight: 600;
|
|
204
|
+
padding: 6px 8px;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.um-brand-mark {
|
|
208
|
+
width: 30px;
|
|
209
|
+
height: 30px;
|
|
210
|
+
border-radius: 8px;
|
|
211
|
+
background: var(--um-primary);
|
|
212
|
+
color: var(--um-primary-fg);
|
|
213
|
+
display: grid;
|
|
214
|
+
place-items: center;
|
|
215
|
+
flex: none;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.um-nav-group {
|
|
219
|
+
display: flex;
|
|
220
|
+
flex-direction: column;
|
|
221
|
+
gap: 3px;
|
|
222
|
+
margin-top: 6px;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.um-nav-group-title {
|
|
226
|
+
font-size: 11px;
|
|
227
|
+
font-weight: 600;
|
|
228
|
+
text-transform: uppercase;
|
|
229
|
+
letter-spacing: 0.04em;
|
|
230
|
+
color: var(--um-muted-fg);
|
|
231
|
+
padding: 4px 10px;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.um-nav-link {
|
|
235
|
+
display: flex;
|
|
236
|
+
align-items: center;
|
|
237
|
+
gap: 9px;
|
|
238
|
+
padding: 7px 10px;
|
|
239
|
+
border-radius: 7px;
|
|
240
|
+
color: inherit;
|
|
241
|
+
text-decoration: none;
|
|
242
|
+
border: 0;
|
|
243
|
+
background: transparent;
|
|
244
|
+
cursor: pointer;
|
|
245
|
+
font-size: 14px;
|
|
246
|
+
width: 100%;
|
|
247
|
+
text-align: start;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.um-nav-link:hover {
|
|
251
|
+
background: rgba(128, 128, 128, 0.12);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.um-nav-link[aria-current="page"] {
|
|
255
|
+
background: var(--um-accent);
|
|
256
|
+
color: var(--um-accent-fg);
|
|
257
|
+
font-weight: 600;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.um-top-links {
|
|
261
|
+
display: flex;
|
|
262
|
+
align-items: center;
|
|
263
|
+
gap: 6px;
|
|
264
|
+
overflow-x: auto;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
.um-top-links .um-nav-link {
|
|
268
|
+
width: auto;
|
|
269
|
+
white-space: nowrap;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.um-toolbar {
|
|
273
|
+
margin-inline-start: auto;
|
|
274
|
+
display: flex;
|
|
275
|
+
align-items: center;
|
|
276
|
+
gap: 8px;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.um-icon-btn {
|
|
280
|
+
display: inline-flex;
|
|
281
|
+
align-items: center;
|
|
282
|
+
justify-content: center;
|
|
283
|
+
gap: 6px;
|
|
284
|
+
height: 34px;
|
|
285
|
+
min-width: 34px;
|
|
286
|
+
padding: 0 10px;
|
|
287
|
+
border-radius: 7px;
|
|
288
|
+
border: 1px solid var(--um-border);
|
|
289
|
+
background: var(--um-surface);
|
|
290
|
+
color: inherit;
|
|
291
|
+
cursor: pointer;
|
|
292
|
+
font-size: 13px;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
.um-icon-btn:hover {
|
|
296
|
+
background: var(--um-muted);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.um-mobile-only {
|
|
300
|
+
display: none;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.um-drawer-backdrop {
|
|
304
|
+
position: fixed;
|
|
305
|
+
inset: 0;
|
|
306
|
+
background: rgba(0, 0, 0, 0.45);
|
|
307
|
+
z-index: 60;
|
|
308
|
+
display: flex;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
.um-drawer-panel {
|
|
312
|
+
width: 288px;
|
|
313
|
+
max-width: 85vw;
|
|
314
|
+
height: 100dvh;
|
|
315
|
+
background: var(--um-surface);
|
|
316
|
+
border-inline-end: 1px solid var(--um-border);
|
|
317
|
+
padding: 14px;
|
|
318
|
+
display: flex;
|
|
319
|
+
flex-direction: column;
|
|
320
|
+
gap: 10px;
|
|
321
|
+
overflow-y: auto;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.um-modal-backdrop {
|
|
325
|
+
position: fixed;
|
|
326
|
+
inset: 0;
|
|
327
|
+
background: rgba(0, 0, 0, 0.45);
|
|
328
|
+
z-index: 70;
|
|
329
|
+
display: grid;
|
|
330
|
+
place-items: center;
|
|
331
|
+
padding: 16px;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.um-modal-card {
|
|
335
|
+
width: min(480px, 100%);
|
|
336
|
+
border-radius: 12px;
|
|
337
|
+
border: 1px solid var(--um-border);
|
|
338
|
+
background: var(--um-surface);
|
|
339
|
+
overflow: hidden;
|
|
340
|
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
.um-standalone {
|
|
344
|
+
min-height: 100dvh;
|
|
345
|
+
background: var(--um-bg);
|
|
346
|
+
color: var(--um-fg);
|
|
347
|
+
padding: 24px;
|
|
348
|
+
display: flex;
|
|
349
|
+
flex-direction: column;
|
|
350
|
+
justify-content: center;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.um-standalone[data-container="boxed"] {
|
|
354
|
+
background: var(--um-muted);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.um-standalone-inner {
|
|
358
|
+
width: 100%;
|
|
359
|
+
max-width: 1080px;
|
|
360
|
+
margin-inline: auto;
|
|
361
|
+
display: flex;
|
|
362
|
+
flex-direction: column;
|
|
363
|
+
gap: 16px;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
.um-standalone[data-container="boxed"] .um-standalone-inner {
|
|
367
|
+
max-width: 520px;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.um-card {
|
|
371
|
+
border: 1px solid var(--um-border);
|
|
372
|
+
border-radius: var(--um-radius);
|
|
373
|
+
background: var(--um-surface);
|
|
374
|
+
padding: 18px 20px;
|
|
375
|
+
display: flex;
|
|
376
|
+
flex-direction: column;
|
|
377
|
+
gap: 12px;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.um-card-title {
|
|
381
|
+
margin: 0;
|
|
382
|
+
font-size: 16px;
|
|
383
|
+
font-weight: 600;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
.um-card-desc {
|
|
387
|
+
margin: 0;
|
|
388
|
+
font-size: 13px;
|
|
389
|
+
color: var(--um-muted-fg);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.um-stat-label {
|
|
393
|
+
font-size: 12px;
|
|
394
|
+
color: var(--um-muted-fg);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
.um-stat-value {
|
|
398
|
+
font-size: 26px;
|
|
399
|
+
font-weight: 700;
|
|
400
|
+
letter-spacing: -0.02em;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
.um-badge {
|
|
404
|
+
display: inline-flex;
|
|
405
|
+
align-items: center;
|
|
406
|
+
padding: 2px 8px;
|
|
407
|
+
border-radius: 999px;
|
|
408
|
+
font-size: 12px;
|
|
409
|
+
font-weight: 500;
|
|
410
|
+
background: var(--um-muted);
|
|
411
|
+
color: var(--um-fg);
|
|
412
|
+
border: 1px solid var(--um-border);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
.um-btn {
|
|
416
|
+
display: inline-flex;
|
|
417
|
+
align-items: center;
|
|
418
|
+
justify-content: center;
|
|
419
|
+
gap: 6px;
|
|
420
|
+
padding: 8px 14px;
|
|
421
|
+
border-radius: 8px;
|
|
422
|
+
border: 1px solid var(--um-primary);
|
|
423
|
+
background: var(--um-primary);
|
|
424
|
+
color: var(--um-primary-fg);
|
|
425
|
+
font-weight: 500;
|
|
426
|
+
font-size: 14px;
|
|
427
|
+
cursor: pointer;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
.um-btn-secondary {
|
|
431
|
+
background: var(--um-surface);
|
|
432
|
+
color: var(--um-fg);
|
|
433
|
+
border-color: var(--um-border);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
.um-input,
|
|
437
|
+
.um-select,
|
|
438
|
+
.um-textarea {
|
|
439
|
+
width: 100%;
|
|
440
|
+
padding: 8px 10px;
|
|
441
|
+
border-radius: 8px;
|
|
442
|
+
border: 1px solid var(--um-border);
|
|
443
|
+
background: var(--um-surface);
|
|
444
|
+
color: var(--um-fg);
|
|
445
|
+
font: inherit;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
.um-field {
|
|
449
|
+
display: flex;
|
|
450
|
+
flex-direction: column;
|
|
451
|
+
gap: 5px;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
.um-field label {
|
|
455
|
+
font-size: 13px;
|
|
456
|
+
font-weight: 500;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
.um-table-wrap {
|
|
460
|
+
width: 100%;
|
|
461
|
+
overflow-x: auto;
|
|
462
|
+
border: 1px solid var(--um-border);
|
|
463
|
+
border-radius: var(--um-radius);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
.um-table {
|
|
467
|
+
width: 100%;
|
|
468
|
+
border-collapse: collapse;
|
|
469
|
+
font-size: 13px;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
.um-table th,
|
|
473
|
+
.um-table td {
|
|
474
|
+
padding: 10px 12px;
|
|
475
|
+
text-align: start;
|
|
476
|
+
border-bottom: 1px solid var(--um-border);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
.um-table th {
|
|
480
|
+
font-weight: 600;
|
|
481
|
+
color: var(--um-muted-fg);
|
|
482
|
+
background: var(--um-muted);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
.um-alert {
|
|
486
|
+
padding: 12px 14px;
|
|
487
|
+
border-radius: var(--um-radius);
|
|
488
|
+
border: 1px solid var(--um-border);
|
|
489
|
+
background: var(--um-muted);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
.um-toast-stack {
|
|
493
|
+
position: fixed;
|
|
494
|
+
right: 16px;
|
|
495
|
+
bottom: 16px;
|
|
496
|
+
display: flex;
|
|
497
|
+
flex-direction: column;
|
|
498
|
+
gap: 8px;
|
|
499
|
+
z-index: 90;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
.um-toast {
|
|
503
|
+
padding: 10px 14px;
|
|
504
|
+
border-radius: 8px;
|
|
505
|
+
background: var(--um-primary);
|
|
506
|
+
color: var(--um-primary-fg);
|
|
507
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
|
|
508
|
+
font-size: 13px;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
@media (max-width: 767px) {
|
|
512
|
+
.um-sidebar,
|
|
513
|
+
.um-rail,
|
|
514
|
+
.um-top-links {
|
|
515
|
+
display: none;
|
|
516
|
+
}
|
|
517
|
+
.um-mobile-only {
|
|
518
|
+
display: inline-flex;
|
|
519
|
+
}
|
|
520
|
+
.um-root[data-shell="sidebar-inset"] .um-main {
|
|
521
|
+
margin: 0;
|
|
522
|
+
border-radius: 0;
|
|
523
|
+
border: 0;
|
|
524
|
+
}
|
|
525
|
+
.um-content {
|
|
526
|
+
padding: 16px;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
`}function Cn(e){return`import {
|
|
530
|
+
createContext,
|
|
531
|
+
useCallback,
|
|
532
|
+
useContext,
|
|
533
|
+
useEffect,
|
|
534
|
+
useMemo,
|
|
535
|
+
useState,
|
|
536
|
+
type FormEvent,
|
|
537
|
+
type ReactNode,
|
|
538
|
+
} from "react";
|
|
539
|
+
|
|
540
|
+
export interface MaterializedAction {
|
|
541
|
+
action: string;
|
|
542
|
+
params?: Record<string, unknown>;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export interface MaterializedBlock {
|
|
546
|
+
id?: string;
|
|
547
|
+
type: string;
|
|
548
|
+
props?: Record<string, unknown>;
|
|
549
|
+
visible?: unknown;
|
|
550
|
+
events?: Record<string, MaterializedAction[]>;
|
|
551
|
+
children?: MaterializedBlock[];
|
|
552
|
+
slots?: Record<string, MaterializedBlock[]>;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export interface RouterContextValue {
|
|
556
|
+
path: string;
|
|
557
|
+
navigate: (nextPath: string) => void;
|
|
558
|
+
pushToast: (message: string) => void;
|
|
559
|
+
dispatchHostAction: (action: string, params: Record<string, unknown>) => void;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
const RouterContext = createContext<RouterContextValue>({
|
|
563
|
+
path: "/",
|
|
564
|
+
navigate: () => {},
|
|
565
|
+
pushToast: () => {},
|
|
566
|
+
dispatchHostAction: () => {},
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
export function useAppRouter(): RouterContextValue {
|
|
570
|
+
return useContext(RouterContext);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
const INITIAL_MOCK_COLLECTIONS: Record<string, Record<string, unknown>[]> = ${e};
|
|
574
|
+
|
|
575
|
+
export function RouterProvider({
|
|
576
|
+
initialPath,
|
|
577
|
+
fallbackPath = "/",
|
|
578
|
+
onNavigate,
|
|
579
|
+
onHostAction,
|
|
580
|
+
children,
|
|
581
|
+
}: {
|
|
582
|
+
initialPath?: string;
|
|
583
|
+
fallbackPath?: string;
|
|
584
|
+
onNavigate?: (nextPath: string) => void;
|
|
585
|
+
onHostAction?: (action: string, params: Record<string, unknown>) => void;
|
|
586
|
+
children: ReactNode;
|
|
587
|
+
}) {
|
|
588
|
+
const [path, setPath] = useState<string>(() => {
|
|
589
|
+
if (initialPath) return initialPath;
|
|
590
|
+
if (typeof window !== "undefined" && window.location.pathname) {
|
|
591
|
+
return window.location.pathname;
|
|
592
|
+
}
|
|
593
|
+
return fallbackPath;
|
|
594
|
+
});
|
|
595
|
+
const [toasts, setToasts] = useState<Array<{ id: number; message: string }>>([]);
|
|
596
|
+
|
|
597
|
+
useEffect(() => {
|
|
598
|
+
if (initialPath) setPath(initialPath);
|
|
599
|
+
}, [initialPath]);
|
|
600
|
+
|
|
601
|
+
useEffect(() => {
|
|
602
|
+
if (typeof window === "undefined") return;
|
|
603
|
+
const onPop = () => setPath(window.location.pathname || "/");
|
|
604
|
+
window.addEventListener("popstate", onPop);
|
|
605
|
+
return () => window.removeEventListener("popstate", onPop);
|
|
606
|
+
}, []);
|
|
607
|
+
|
|
608
|
+
const navigate = useCallback(
|
|
609
|
+
(nextPath: string) => {
|
|
610
|
+
if (!nextPath) return;
|
|
611
|
+
setPath(nextPath);
|
|
612
|
+
if (typeof window !== "undefined" && nextPath.startsWith("/")) {
|
|
613
|
+
window.history.pushState({}, "", nextPath);
|
|
614
|
+
}
|
|
615
|
+
onNavigate?.(nextPath);
|
|
616
|
+
},
|
|
617
|
+
[onNavigate],
|
|
618
|
+
);
|
|
619
|
+
|
|
620
|
+
const pushToast = useCallback((message: string) => {
|
|
621
|
+
const id = Date.now() + Math.floor(Math.random() * 1000);
|
|
622
|
+
setToasts((prev) => [...prev.slice(-3), { id, message }]);
|
|
623
|
+
setTimeout(() => {
|
|
624
|
+
setToasts((prev) => prev.filter((item) => item.id !== id));
|
|
625
|
+
}, 3200);
|
|
626
|
+
}, []);
|
|
627
|
+
|
|
628
|
+
const dispatchHostAction = useCallback(
|
|
629
|
+
(action: string, params: Record<string, unknown>) => {
|
|
630
|
+
onHostAction?.(action, params);
|
|
631
|
+
},
|
|
632
|
+
[onHostAction],
|
|
633
|
+
);
|
|
634
|
+
|
|
635
|
+
const value = useMemo<RouterContextValue>(
|
|
636
|
+
() => ({ path, navigate, pushToast, dispatchHostAction }),
|
|
637
|
+
[path, navigate, pushToast, dispatchHostAction],
|
|
638
|
+
);
|
|
639
|
+
|
|
640
|
+
return (
|
|
641
|
+
<RouterContext.Provider value={value}>
|
|
642
|
+
{children}
|
|
643
|
+
{toasts.length > 0 && (
|
|
644
|
+
<div className="um-toast-stack" role="status" aria-live="polite">
|
|
645
|
+
{toasts.map((toast) => (
|
|
646
|
+
<div key={toast.id} className="um-toast">
|
|
647
|
+
{toast.message}
|
|
648
|
+
</div>
|
|
649
|
+
))}
|
|
650
|
+
</div>
|
|
651
|
+
)}
|
|
652
|
+
</RouterContext.Provider>
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
export function AppLink({
|
|
657
|
+
href,
|
|
658
|
+
className,
|
|
659
|
+
ariaCurrent,
|
|
660
|
+
title,
|
|
661
|
+
ariaLabel,
|
|
662
|
+
onAfterClick,
|
|
663
|
+
children,
|
|
664
|
+
}: {
|
|
665
|
+
href: string;
|
|
666
|
+
className?: string;
|
|
667
|
+
ariaCurrent?: "page";
|
|
668
|
+
title?: string;
|
|
669
|
+
ariaLabel?: string;
|
|
670
|
+
onAfterClick?: () => void;
|
|
671
|
+
children: ReactNode;
|
|
672
|
+
}) {
|
|
673
|
+
const { navigate } = useAppRouter();
|
|
674
|
+
return (
|
|
675
|
+
<a
|
|
676
|
+
href={href}
|
|
677
|
+
className={className}
|
|
678
|
+
aria-current={ariaCurrent}
|
|
679
|
+
title={title}
|
|
680
|
+
aria-label={ariaLabel}
|
|
681
|
+
onClick={(event) => {
|
|
682
|
+
if (
|
|
683
|
+
event.button !== 0 ||
|
|
684
|
+
event.metaKey ||
|
|
685
|
+
event.ctrlKey ||
|
|
686
|
+
event.shiftKey ||
|
|
687
|
+
event.altKey ||
|
|
688
|
+
!href.startsWith("/")
|
|
689
|
+
) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
event.preventDefault();
|
|
693
|
+
navigate(href);
|
|
694
|
+
onAfterClick?.();
|
|
695
|
+
}}
|
|
696
|
+
>
|
|
697
|
+
{children}
|
|
698
|
+
</a>
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
export function ShellIcon({ name, size = 16 }: { name?: string; size?: number }) {
|
|
703
|
+
const common = {
|
|
704
|
+
width: size,
|
|
705
|
+
height: size,
|
|
706
|
+
viewBox: "0 0 24 24",
|
|
707
|
+
fill: "none",
|
|
708
|
+
stroke: "currentColor",
|
|
709
|
+
strokeWidth: 2,
|
|
710
|
+
strokeLinecap: "round" as const,
|
|
711
|
+
strokeLinejoin: "round" as const,
|
|
712
|
+
"aria-hidden": true,
|
|
713
|
+
};
|
|
714
|
+
switch (name) {
|
|
715
|
+
case "search":
|
|
716
|
+
return (
|
|
717
|
+
<svg {...common}>
|
|
718
|
+
<circle cx="11" cy="11" r="8" />
|
|
719
|
+
<path d="m21 21-4.3-4.3" />
|
|
720
|
+
</svg>
|
|
721
|
+
);
|
|
722
|
+
case "x":
|
|
723
|
+
return (
|
|
724
|
+
<svg {...common}>
|
|
725
|
+
<path d="M18 6 6 18" />
|
|
726
|
+
<path d="m6 6 12 12" />
|
|
727
|
+
</svg>
|
|
728
|
+
);
|
|
729
|
+
case "menu":
|
|
730
|
+
return (
|
|
731
|
+
<svg {...common}>
|
|
732
|
+
<path d="M4 6h16M4 12h16M4 18h16" />
|
|
733
|
+
</svg>
|
|
734
|
+
);
|
|
735
|
+
case "panel-left":
|
|
736
|
+
return (
|
|
737
|
+
<svg {...common}>
|
|
738
|
+
<rect width="18" height="18" x="3" y="3" rx="2" />
|
|
739
|
+
<path d="M9 3v18" />
|
|
740
|
+
</svg>
|
|
741
|
+
);
|
|
742
|
+
case "chevron-left":
|
|
743
|
+
return (
|
|
744
|
+
<svg {...common}>
|
|
745
|
+
<path d="m15 18-6-6 6-6" />
|
|
746
|
+
</svg>
|
|
747
|
+
);
|
|
748
|
+
case "chevron-right":
|
|
749
|
+
return (
|
|
750
|
+
<svg {...common}>
|
|
751
|
+
<path d="m9 18 6-6-6-6" />
|
|
752
|
+
</svg>
|
|
753
|
+
);
|
|
754
|
+
case "sun":
|
|
755
|
+
return (
|
|
756
|
+
<svg {...common}>
|
|
757
|
+
<circle cx="12" cy="12" r="4" />
|
|
758
|
+
<path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41" />
|
|
759
|
+
</svg>
|
|
760
|
+
);
|
|
761
|
+
case "moon":
|
|
762
|
+
return (
|
|
763
|
+
<svg {...common}>
|
|
764
|
+
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
|
|
765
|
+
</svg>
|
|
766
|
+
);
|
|
767
|
+
case "settings":
|
|
768
|
+
return (
|
|
769
|
+
<svg {...common}>
|
|
770
|
+
<circle cx="12" cy="12" r="3" />
|
|
771
|
+
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9c.26.6.85 1 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1Z" />
|
|
772
|
+
</svg>
|
|
773
|
+
);
|
|
774
|
+
case "layout-dashboard":
|
|
775
|
+
return (
|
|
776
|
+
<svg {...common}>
|
|
777
|
+
<rect width="7" height="9" x="3" y="3" rx="1" />
|
|
778
|
+
<rect width="7" height="5" x="14" y="3" rx="1" />
|
|
779
|
+
<rect width="7" height="9" x="14" y="12" rx="1" />
|
|
780
|
+
<rect width="7" height="5" x="3" y="16" rx="1" />
|
|
781
|
+
</svg>
|
|
782
|
+
);
|
|
783
|
+
default:
|
|
784
|
+
return (
|
|
785
|
+
<svg {...common}>
|
|
786
|
+
<rect width="18" height="18" x="3" y="3" rx="3" />
|
|
787
|
+
<path d="M8 8h8M8 12h8M8 16h5" />
|
|
788
|
+
</svg>
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
function getByPath(source: Record<string, unknown>, keyPath: string): unknown {
|
|
794
|
+
const segments = keyPath.split(".");
|
|
795
|
+
let current: unknown = source;
|
|
796
|
+
for (const segment of segments) {
|
|
797
|
+
if (!current || typeof current !== "object") return undefined;
|
|
798
|
+
current = (current as Record<string, unknown>)[segment];
|
|
799
|
+
}
|
|
800
|
+
return current;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function setByPath(
|
|
804
|
+
source: Record<string, unknown>,
|
|
805
|
+
keyPath: string,
|
|
806
|
+
value: unknown,
|
|
807
|
+
): Record<string, unknown> {
|
|
808
|
+
const segments = keyPath.split(".");
|
|
809
|
+
if (segments.length === 1) {
|
|
810
|
+
return { ...source, [keyPath]: value };
|
|
811
|
+
}
|
|
812
|
+
const head = segments[0] ?? keyPath;
|
|
813
|
+
const tail = segments.slice(1).join(".");
|
|
814
|
+
const nested =
|
|
815
|
+
source[head] && typeof source[head] === "object" && !Array.isArray(source[head])
|
|
816
|
+
? (source[head] as Record<string, unknown>)
|
|
817
|
+
: {};
|
|
818
|
+
return { ...source, [head]: setByPath(nested, tail, value) };
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
export function resolveExpr(
|
|
822
|
+
expr: unknown,
|
|
823
|
+
state: Record<string, unknown>,
|
|
824
|
+
eventValue?: unknown,
|
|
825
|
+
): unknown {
|
|
826
|
+
if (expr === null || expr === undefined) return expr;
|
|
827
|
+
if (Array.isArray(expr)) return expr.map((item) => resolveExpr(item, state, eventValue));
|
|
828
|
+
if (typeof expr !== "object") return expr;
|
|
829
|
+
|
|
830
|
+
const record = expr as Record<string, unknown>;
|
|
831
|
+
if (typeof record._state === "string") return getByPath(state, record._state);
|
|
832
|
+
if (typeof record._bindState === "string") return getByPath(state, record._bindState);
|
|
833
|
+
if (record._event !== undefined) {
|
|
834
|
+
if (typeof record._event === "string" && eventValue && typeof eventValue === "object") {
|
|
835
|
+
return getByPath(eventValue as Record<string, unknown>, record._event);
|
|
836
|
+
}
|
|
837
|
+
return eventValue;
|
|
838
|
+
}
|
|
839
|
+
if (Array.isArray(record._eq) && record._eq.length === 2) {
|
|
840
|
+
return (
|
|
841
|
+
resolveExpr(record._eq[0], state, eventValue) ===
|
|
842
|
+
resolveExpr(record._eq[1], state, eventValue)
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
if (Array.isArray(record._ne) && record._ne.length === 2) {
|
|
846
|
+
return (
|
|
847
|
+
resolveExpr(record._ne[0], state, eventValue) !==
|
|
848
|
+
resolveExpr(record._ne[1], state, eventValue)
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
if ("_not" in record) return !resolveExpr(record._not, state, eventValue);
|
|
852
|
+
if (Array.isArray(record._and)) {
|
|
853
|
+
return record._and.every((item) => Boolean(resolveExpr(item, state, eventValue)));
|
|
854
|
+
}
|
|
855
|
+
if (Array.isArray(record._or)) {
|
|
856
|
+
return record._or.some((item) => Boolean(resolveExpr(item, state, eventValue)));
|
|
857
|
+
}
|
|
858
|
+
if (record._if && typeof record._if === "object") {
|
|
859
|
+
const cond = record._if as { test?: unknown; then?: unknown; else?: unknown };
|
|
860
|
+
return resolveExpr(cond.test, state, eventValue)
|
|
861
|
+
? resolveExpr(cond.then, state, eventValue)
|
|
862
|
+
: resolveExpr(cond.else, state, eventValue);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
const resolved: Record<string, unknown> = {};
|
|
866
|
+
for (const [key, val] of Object.entries(record)) {
|
|
867
|
+
resolved[key] = resolveExpr(val, state, eventValue);
|
|
868
|
+
}
|
|
869
|
+
return resolved;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
export function usePageRuntime(initialState: Record<string, unknown>) {
|
|
873
|
+
const [state, setState] = useState<Record<string, unknown>>(() => structuredClone(initialState));
|
|
874
|
+
const [collections, setCollections] = useState<Record<string, Record<string, unknown>[]>>(() =>
|
|
875
|
+
structuredClone(INITIAL_MOCK_COLLECTIONS),
|
|
876
|
+
);
|
|
877
|
+
const router = useAppRouter();
|
|
878
|
+
|
|
879
|
+
const updateKey = useCallback((key: string, value: unknown) => {
|
|
880
|
+
setState((prev) => setByPath(prev, key, value));
|
|
881
|
+
}, []);
|
|
882
|
+
|
|
883
|
+
const runActions = useCallback(
|
|
884
|
+
(actions: MaterializedAction[] | undefined, eventValue?: unknown) => {
|
|
885
|
+
if (!actions?.length) return;
|
|
886
|
+
for (const act of actions) {
|
|
887
|
+
const params = (resolveExpr(act.params ?? {}, state, eventValue) ?? {}) as Record<
|
|
888
|
+
string,
|
|
889
|
+
unknown
|
|
890
|
+
>;
|
|
891
|
+
if (act.action === "SetState") {
|
|
892
|
+
for (const [k, v] of Object.entries(params)) {
|
|
893
|
+
if (k === "path" && typeof v === "string" && "value" in params) {
|
|
894
|
+
updateKey(v, params.value);
|
|
895
|
+
} else if (k !== "value" || !("path" in params)) {
|
|
896
|
+
updateKey(k, v);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
if (act.action === "ResetState") {
|
|
902
|
+
setState(structuredClone(initialState));
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
if (act.action === "Link" || act.action === "Navigate") {
|
|
906
|
+
const to = typeof params.to === "string" ? params.to : String(params.href ?? "/");
|
|
907
|
+
router.navigate(to);
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
if (act.action === "DisplayMessage" || act.action === "Toast") {
|
|
911
|
+
const msg =
|
|
912
|
+
typeof params.content === "string"
|
|
913
|
+
? params.content
|
|
914
|
+
: typeof params.message === "string"
|
|
915
|
+
? params.message
|
|
916
|
+
: typeof params.title === "string"
|
|
917
|
+
? params.title
|
|
918
|
+
: "Action completed";
|
|
919
|
+
router.pushToast(msg);
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
if (act.action === "Request") {
|
|
923
|
+
const connectionId = typeof params.connectionId === "string" ? params.connectionId : "";
|
|
924
|
+
const operation = typeof params.operation === "string" ? params.operation : "FindPage";
|
|
925
|
+
const responsePath =
|
|
926
|
+
typeof params.responsePath === "string" ? params.responsePath : "rows";
|
|
927
|
+
const existing = collections[connectionId] ?? [];
|
|
928
|
+
if (operation === "FindPage" || operation === "list") {
|
|
929
|
+
updateKey(responsePath, existing);
|
|
930
|
+
} else if (operation === "InsertOne" || operation === "create") {
|
|
931
|
+
const payload =
|
|
932
|
+
params.payload && typeof params.payload === "object"
|
|
933
|
+
? (params.payload as Record<string, unknown>)
|
|
934
|
+
: {};
|
|
935
|
+
const nextRows = [...existing, { id: \`row-\${Date.now()}\`, ...payload }];
|
|
936
|
+
setCollections((prev) => ({ ...prev, [connectionId]: nextRows }));
|
|
937
|
+
updateKey(responsePath, nextRows);
|
|
938
|
+
} else if (operation === "DeleteOne" || operation === "delete") {
|
|
939
|
+
const targetId = String(params.id ?? "");
|
|
940
|
+
const nextRows = existing.filter((row) => String(row.id ?? "") !== targetId);
|
|
941
|
+
setCollections((prev) => ({ ...prev, [connectionId]: nextRows }));
|
|
942
|
+
updateKey(responsePath, nextRows);
|
|
943
|
+
}
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
router.dispatchHostAction(act.action, params);
|
|
947
|
+
}
|
|
948
|
+
},
|
|
949
|
+
[collections, initialState, router, state, updateKey],
|
|
950
|
+
);
|
|
951
|
+
|
|
952
|
+
return { state, updateKey, runActions };
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
function asText(value: unknown, fallback = ""): string {
|
|
956
|
+
if (typeof value === "string") return value;
|
|
957
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
958
|
+
return fallback;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
export function BlockList({
|
|
962
|
+
blocks,
|
|
963
|
+
state,
|
|
964
|
+
updateKey,
|
|
965
|
+
runActions,
|
|
966
|
+
}: {
|
|
967
|
+
blocks: MaterializedBlock[];
|
|
968
|
+
state: Record<string, unknown>;
|
|
969
|
+
updateKey: (key: string, value: unknown) => void;
|
|
970
|
+
runActions: (actions: MaterializedAction[] | undefined, eventValue?: unknown) => void;
|
|
971
|
+
}) {
|
|
972
|
+
return (
|
|
973
|
+
<>
|
|
974
|
+
{blocks.map((block, index) => (
|
|
975
|
+
<BlockItem
|
|
976
|
+
key={block.id ?? \`\${block.type}-\${index}\`}
|
|
977
|
+
block={block}
|
|
978
|
+
state={state}
|
|
979
|
+
updateKey={updateKey}
|
|
980
|
+
runActions={runActions}
|
|
981
|
+
/>
|
|
982
|
+
))}
|
|
983
|
+
</>
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
function TableBlock({
|
|
988
|
+
props,
|
|
989
|
+
}: {
|
|
990
|
+
props: Record<string, unknown>;
|
|
991
|
+
}) {
|
|
992
|
+
const [search, setSearch] = useState("");
|
|
993
|
+
const rawColumns = Array.isArray(props.columns) ? props.columns : [];
|
|
994
|
+
const rawRows = Array.isArray(props.rows)
|
|
995
|
+
? props.rows
|
|
996
|
+
: Array.isArray(props.data)
|
|
997
|
+
? props.data
|
|
998
|
+
: [];
|
|
999
|
+
const rows = rawRows.filter((row): row is Record<string, unknown> =>
|
|
1000
|
+
Boolean(row && typeof row === "object"),
|
|
1001
|
+
);
|
|
1002
|
+
const columns =
|
|
1003
|
+
rawColumns.length > 0
|
|
1004
|
+
? rawColumns.map((col) => {
|
|
1005
|
+
if (typeof col === "string") return { key: col, label: col };
|
|
1006
|
+
const obj = col as Record<string, unknown>;
|
|
1007
|
+
const key = asText(obj.key, asText(obj.accessorKey, "id"));
|
|
1008
|
+
return { key, label: asText(obj.label, asText(obj.header, key)) };
|
|
1009
|
+
})
|
|
1010
|
+
: rows[0]
|
|
1011
|
+
? Object.keys(rows[0]).map((key) => ({ key, label: key }))
|
|
1012
|
+
: [];
|
|
1013
|
+
const filtered = search.trim()
|
|
1014
|
+
? rows.filter((row) =>
|
|
1015
|
+
Object.values(row).some((v) =>
|
|
1016
|
+
asText(v).toLowerCase().includes(search.trim().toLowerCase()),
|
|
1017
|
+
),
|
|
1018
|
+
)
|
|
1019
|
+
: rows;
|
|
1020
|
+
|
|
1021
|
+
return (
|
|
1022
|
+
<div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
|
|
1023
|
+
{props.searchable !== false && (
|
|
1024
|
+
<input
|
|
1025
|
+
type="search"
|
|
1026
|
+
className="um-input"
|
|
1027
|
+
style={{ maxWidth: 280 }}
|
|
1028
|
+
placeholder="Filter rows..."
|
|
1029
|
+
aria-label="Filter table rows"
|
|
1030
|
+
value={search}
|
|
1031
|
+
onChange={(event) => setSearch(event.target.value)}
|
|
1032
|
+
/>
|
|
1033
|
+
)}
|
|
1034
|
+
<div className="um-table-wrap">
|
|
1035
|
+
<table className="um-table">
|
|
1036
|
+
<thead>
|
|
1037
|
+
<tr>
|
|
1038
|
+
{columns.map((col) => (
|
|
1039
|
+
<th key={col.key}>{col.label}</th>
|
|
1040
|
+
))}
|
|
1041
|
+
</tr>
|
|
1042
|
+
</thead>
|
|
1043
|
+
<tbody>
|
|
1044
|
+
{filtered.map((row, idx) => (
|
|
1045
|
+
<tr key={asText(row.id, String(idx))}>
|
|
1046
|
+
{columns.map((col) => (
|
|
1047
|
+
<td key={col.key}>{asText(row[col.key], "\u2014")}</td>
|
|
1048
|
+
))}
|
|
1049
|
+
</tr>
|
|
1050
|
+
))}
|
|
1051
|
+
{filtered.length === 0 && (
|
|
1052
|
+
<tr>
|
|
1053
|
+
<td colSpan={Math.max(1, columns.length)} style={{ color: "var(--um-muted-fg)" }}>
|
|
1054
|
+
No matching records.
|
|
1055
|
+
</td>
|
|
1056
|
+
</tr>
|
|
1057
|
+
)}
|
|
1058
|
+
</tbody>
|
|
1059
|
+
</table>
|
|
1060
|
+
</div>
|
|
1061
|
+
</div>
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
function BlockItem({
|
|
1066
|
+
block,
|
|
1067
|
+
state,
|
|
1068
|
+
updateKey,
|
|
1069
|
+
runActions,
|
|
1070
|
+
}: {
|
|
1071
|
+
block: MaterializedBlock;
|
|
1072
|
+
state: Record<string, unknown>;
|
|
1073
|
+
updateKey: (key: string, value: unknown) => void;
|
|
1074
|
+
runActions: (actions: MaterializedAction[] | undefined, eventValue?: unknown) => void;
|
|
1075
|
+
}) {
|
|
1076
|
+
if (block.visible !== undefined && !resolveExpr(block.visible, state)) {
|
|
1077
|
+
return null;
|
|
1078
|
+
}
|
|
1079
|
+
const rawProps = block.props ?? {};
|
|
1080
|
+
const props = (resolveExpr(rawProps, state) ?? {}) as Record<string, unknown>;
|
|
1081
|
+
const children = block.children?.length ? (
|
|
1082
|
+
<BlockList
|
|
1083
|
+
blocks={block.children}
|
|
1084
|
+
state={state}
|
|
1085
|
+
updateKey={updateKey}
|
|
1086
|
+
runActions={runActions}
|
|
1087
|
+
/>
|
|
1088
|
+
) : null;
|
|
1089
|
+
|
|
1090
|
+
switch (block.type) {
|
|
1091
|
+
case "Heading": {
|
|
1092
|
+
const level = Number(props.level ?? 1);
|
|
1093
|
+
const text = asText(props.text, asText(props.title));
|
|
1094
|
+
if (level <= 1) return <h1 style={{ margin: 0, fontSize: 24, fontWeight: 700 }}>{text}</h1>;
|
|
1095
|
+
if (level === 2) return <h2 style={{ margin: 0, fontSize: 19, fontWeight: 600 }}>{text}</h2>;
|
|
1096
|
+
return <h3 style={{ margin: 0, fontSize: 16, fontWeight: 600 }}>{text}</h3>;
|
|
1097
|
+
}
|
|
1098
|
+
case "Paragraph":
|
|
1099
|
+
case "Text":
|
|
1100
|
+
case "Markdown":
|
|
1101
|
+
return (
|
|
1102
|
+
<p
|
|
1103
|
+
style={{
|
|
1104
|
+
margin: 0,
|
|
1105
|
+
color: props.muted ? "var(--um-muted-fg)" : "inherit",
|
|
1106
|
+
}}
|
|
1107
|
+
>
|
|
1108
|
+
{asText(props.text, asText(props.content))}
|
|
1109
|
+
</p>
|
|
1110
|
+
);
|
|
1111
|
+
case "Badge":
|
|
1112
|
+
return <span className="um-badge">{asText(props.text, asText(props.label))}</span>;
|
|
1113
|
+
case "Alert":
|
|
1114
|
+
return (
|
|
1115
|
+
<div className="um-alert" role="status">
|
|
1116
|
+
{typeof props.title === "string" && <strong>{props.title}</strong>}
|
|
1117
|
+
<div>{asText(props.description, asText(props.text, asText(props.message)))}</div>
|
|
1118
|
+
</div>
|
|
1119
|
+
);
|
|
1120
|
+
case "Divider":
|
|
1121
|
+
return <hr style={{ border: 0, borderTop: "1px solid var(--um-border)", width: "100%" }} />;
|
|
1122
|
+
case "Stat":
|
|
1123
|
+
case "StatCard":
|
|
1124
|
+
return (
|
|
1125
|
+
<div className="um-card">
|
|
1126
|
+
<span className="um-stat-label">{asText(props.label, asText(props.title))}</span>
|
|
1127
|
+
<span className="um-stat-value">{asText(props.value, "0")}</span>
|
|
1128
|
+
{(props.note !== undefined || props.delta !== undefined) && (
|
|
1129
|
+
<span className="um-card-desc">{asText(props.note, asText(props.delta))}</span>
|
|
1130
|
+
)}
|
|
1131
|
+
</div>
|
|
1132
|
+
);
|
|
1133
|
+
case "Card":
|
|
1134
|
+
return (
|
|
1135
|
+
<section className="um-card">
|
|
1136
|
+
{typeof props.title === "string" && <h3 className="um-card-title">{props.title}</h3>}
|
|
1137
|
+
{typeof props.description === "string" && (
|
|
1138
|
+
<p className="um-card-desc">{props.description}</p>
|
|
1139
|
+
)}
|
|
1140
|
+
{children}
|
|
1141
|
+
</section>
|
|
1142
|
+
);
|
|
1143
|
+
case "Box":
|
|
1144
|
+
case "Stack": {
|
|
1145
|
+
const direction = props.direction === "row" ? "row" : "column";
|
|
1146
|
+
return (
|
|
1147
|
+
<div style={{ display: "flex", flexDirection: direction, gap: 14, flexWrap: "wrap" }}>
|
|
1148
|
+
{children}
|
|
1149
|
+
</div>
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
case "Grid":
|
|
1153
|
+
case "StatGrid": {
|
|
1154
|
+
const cols = Math.max(1, Math.min(4, Number(props.columns ?? 3)));
|
|
1155
|
+
return (
|
|
1156
|
+
<div
|
|
1157
|
+
style={{
|
|
1158
|
+
display: "grid",
|
|
1159
|
+
gridTemplateColumns: \`repeat(auto-fit, minmax(\${Math.floor(720 / cols)}px, 1fr))\`,
|
|
1160
|
+
gap: 14,
|
|
1161
|
+
}}
|
|
1162
|
+
>
|
|
1163
|
+
{children}
|
|
1164
|
+
</div>
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
case "Button":
|
|
1168
|
+
return (
|
|
1169
|
+
<button
|
|
1170
|
+
type="button"
|
|
1171
|
+
className={
|
|
1172
|
+
props.variant === "outline" || props.variant === "secondary" || props.variant === "ghost"
|
|
1173
|
+
? "um-btn um-btn-secondary"
|
|
1174
|
+
: "um-btn"
|
|
1175
|
+
}
|
|
1176
|
+
onClick={() => runActions(block.events?.onClick, { type: "click" })}
|
|
1177
|
+
>
|
|
1178
|
+
{asText(props.label, asText(props.text, "Button"))}
|
|
1179
|
+
</button>
|
|
1180
|
+
);
|
|
1181
|
+
case "Link":
|
|
1182
|
+
case "MenuLink":
|
|
1183
|
+
return (
|
|
1184
|
+
<AppLink href={asText(props.href, asText(props.to, "/"))} className="um-nav-link">
|
|
1185
|
+
{asText(props.label, asText(props.text, asText(props.href, "Link")))}
|
|
1186
|
+
</AppLink>
|
|
1187
|
+
);
|
|
1188
|
+
case "Table":
|
|
1189
|
+
case "DataTable":
|
|
1190
|
+
case "SearchableTable":
|
|
1191
|
+
return <TableBlock props={props} />;
|
|
1192
|
+
case "CollectionKanban": {
|
|
1193
|
+
const kRows = (Array.isArray(props.rows) ? props.rows : []).filter(
|
|
1194
|
+
(r): r is Record<string, unknown> => Boolean(r && typeof r === "object"),
|
|
1195
|
+
);
|
|
1196
|
+
const groupBy = asText(props.groupBy, "status");
|
|
1197
|
+
const titleField = asText(props.titleField, "title");
|
|
1198
|
+
const rawLanes = Array.isArray(props.lanes) ? props.lanes : [];
|
|
1199
|
+
const lanes = rawLanes
|
|
1200
|
+
.filter((l): l is Record<string, unknown> => Boolean(l && typeof l === "object"))
|
|
1201
|
+
.map((l) => ({ value: asText(l.value), label: asText(l.label, asText(l.value)) }));
|
|
1202
|
+
return (
|
|
1203
|
+
<div
|
|
1204
|
+
data-uibot-block="CollectionKanban"
|
|
1205
|
+
style={{
|
|
1206
|
+
display: "grid",
|
|
1207
|
+
gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))",
|
|
1208
|
+
gap: 14,
|
|
1209
|
+
}}
|
|
1210
|
+
>
|
|
1211
|
+
{lanes.map((lane) => {
|
|
1212
|
+
const laneRows = kRows.filter((row) => asText(row[groupBy]) === lane.value);
|
|
1213
|
+
return (
|
|
1214
|
+
<div key={lane.value} className="um-card" style={{ background: "var(--um-muted)" }}>
|
|
1215
|
+
<strong>
|
|
1216
|
+
{lane.label} ({laneRows.length})
|
|
1217
|
+
</strong>
|
|
1218
|
+
{laneRows.map((row, idx) => (
|
|
1219
|
+
<button
|
|
1220
|
+
key={asText(row.id, String(idx))}
|
|
1221
|
+
type="button"
|
|
1222
|
+
className="um-card"
|
|
1223
|
+
style={{ textAlign: "start", cursor: "pointer" }}
|
|
1224
|
+
onClick={() =>
|
|
1225
|
+
runActions(block.events?.onSelect, { values: { id: asText(row.id) } })
|
|
1226
|
+
}
|
|
1227
|
+
>
|
|
1228
|
+
<strong>{asText(row[titleField], asText(row.id))}</strong>
|
|
1229
|
+
{typeof row.description === "string" && (
|
|
1230
|
+
<span className="um-card-desc">{row.description}</span>
|
|
1231
|
+
)}
|
|
1232
|
+
</button>
|
|
1233
|
+
))}
|
|
1234
|
+
</div>
|
|
1235
|
+
);
|
|
1236
|
+
})}
|
|
1237
|
+
</div>
|
|
1238
|
+
);
|
|
1239
|
+
}
|
|
1240
|
+
case "ItemGrid": {
|
|
1241
|
+
const items = (Array.isArray(props.items) ? props.items : []).filter(
|
|
1242
|
+
(r): r is Record<string, unknown> => Boolean(r && typeof r === "object"),
|
|
1243
|
+
);
|
|
1244
|
+
return (
|
|
1245
|
+
<div
|
|
1246
|
+
data-uibot-block="ItemGrid"
|
|
1247
|
+
style={{
|
|
1248
|
+
display: "grid",
|
|
1249
|
+
gridTemplateColumns: "repeat(auto-fit, minmax(240px, 1fr))",
|
|
1250
|
+
gap: 14,
|
|
1251
|
+
}}
|
|
1252
|
+
>
|
|
1253
|
+
{items.map((item, idx) => (
|
|
1254
|
+
<button
|
|
1255
|
+
key={asText(item.id, String(idx))}
|
|
1256
|
+
type="button"
|
|
1257
|
+
className="um-card"
|
|
1258
|
+
style={{ textAlign: "start", cursor: "pointer" }}
|
|
1259
|
+
onClick={() =>
|
|
1260
|
+
runActions(block.events?.onSelect, { values: { id: asText(item.id) } })
|
|
1261
|
+
}
|
|
1262
|
+
>
|
|
1263
|
+
<strong className="um-card-title">{asText(item.title, asText(item.id))}</strong>
|
|
1264
|
+
{typeof item.description === "string" && (
|
|
1265
|
+
<p className="um-card-desc">{item.description}</p>
|
|
1266
|
+
)}
|
|
1267
|
+
</button>
|
|
1268
|
+
))}
|
|
1269
|
+
</div>
|
|
1270
|
+
);
|
|
1271
|
+
}
|
|
1272
|
+
case "RecordMasterDetail": {
|
|
1273
|
+
const mdRows = (Array.isArray(props.rows) ? props.rows : []).filter(
|
|
1274
|
+
(r): r is Record<string, unknown> => Boolean(r && typeof r === "object"),
|
|
1275
|
+
);
|
|
1276
|
+
const selectedId = asText(props.selectedId);
|
|
1277
|
+
const active = mdRows.find((r) => asText(r.id) === selectedId) ?? mdRows[0];
|
|
1278
|
+
const detailBlocks = block.slots?.detail ?? [];
|
|
1279
|
+
return (
|
|
1280
|
+
<div
|
|
1281
|
+
data-uibot-block="RecordMasterDetail"
|
|
1282
|
+
style={{
|
|
1283
|
+
display: "grid",
|
|
1284
|
+
gridTemplateColumns: "minmax(220px, 1fr) minmax(0, 2fr)",
|
|
1285
|
+
gap: 16,
|
|
1286
|
+
}}
|
|
1287
|
+
>
|
|
1288
|
+
<div className="um-card" style={{ gap: 6 }}>
|
|
1289
|
+
{mdRows.map((row, idx) => (
|
|
1290
|
+
<button
|
|
1291
|
+
key={asText(row.id, String(idx))}
|
|
1292
|
+
type="button"
|
|
1293
|
+
className="um-nav-link"
|
|
1294
|
+
aria-current={asText(row.id) === asText(active?.id) ? "page" : undefined}
|
|
1295
|
+
onClick={() =>
|
|
1296
|
+
runActions(block.events?.onSelect, { values: { id: asText(row.id) } })
|
|
1297
|
+
}
|
|
1298
|
+
>
|
|
1299
|
+
{asText(row.title, asText(row.id))}
|
|
1300
|
+
</button>
|
|
1301
|
+
))}
|
|
1302
|
+
</div>
|
|
1303
|
+
<div className="um-card">
|
|
1304
|
+
{active && (
|
|
1305
|
+
<>
|
|
1306
|
+
<h3 className="um-card-title">{asText(active.title, asText(active.id))}</h3>
|
|
1307
|
+
{typeof active.description === "string" && (
|
|
1308
|
+
<p className="um-card-desc">{active.description}</p>
|
|
1309
|
+
)}
|
|
1310
|
+
</>
|
|
1311
|
+
)}
|
|
1312
|
+
{detailBlocks.length > 0 && (
|
|
1313
|
+
<BlockList
|
|
1314
|
+
blocks={detailBlocks}
|
|
1315
|
+
state={state}
|
|
1316
|
+
updateKey={updateKey}
|
|
1317
|
+
runActions={runActions}
|
|
1318
|
+
/>
|
|
1319
|
+
)}
|
|
1320
|
+
</div>
|
|
1321
|
+
</div>
|
|
1322
|
+
);
|
|
1323
|
+
}
|
|
1324
|
+
case "Form": {
|
|
1325
|
+
const handleSubmit = (event: FormEvent) => {
|
|
1326
|
+
event.preventDefault();
|
|
1327
|
+
runActions(block.events?.onSubmit, state);
|
|
1328
|
+
};
|
|
1329
|
+
return (
|
|
1330
|
+
<form
|
|
1331
|
+
onSubmit={handleSubmit}
|
|
1332
|
+
style={{ display: "flex", flexDirection: "column", gap: 14, maxWidth: 560 }}
|
|
1333
|
+
>
|
|
1334
|
+
{children}
|
|
1335
|
+
</form>
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
case "Form.Input":
|
|
1339
|
+
case "Field": {
|
|
1340
|
+
const bindKey =
|
|
1341
|
+
rawProps.value &&
|
|
1342
|
+
typeof rawProps.value === "object" &&
|
|
1343
|
+
typeof (rawProps.value as Record<string, unknown>)._bindState === "string"
|
|
1344
|
+
? ((rawProps.value as Record<string, unknown>)._bindState as string)
|
|
1345
|
+
: typeof props.name === "string"
|
|
1346
|
+
? props.name
|
|
1347
|
+
: "";
|
|
1348
|
+
const inputId = block.id ?? \`field-\${bindKey || "input"}\`;
|
|
1349
|
+
const val = asText(props.value);
|
|
1350
|
+
return (
|
|
1351
|
+
<div className="um-field">
|
|
1352
|
+
{typeof props.label === "string" && <label htmlFor={inputId}>{props.label}</label>}
|
|
1353
|
+
<input
|
|
1354
|
+
id={inputId}
|
|
1355
|
+
name={asText(props.name, bindKey)}
|
|
1356
|
+
type={asText(props.inputType, asText(props.type, "text"))}
|
|
1357
|
+
className="um-input"
|
|
1358
|
+
placeholder={asText(props.placeholder)}
|
|
1359
|
+
value={val}
|
|
1360
|
+
onChange={(event) => {
|
|
1361
|
+
if (bindKey) updateKey(bindKey, event.target.value);
|
|
1362
|
+
runActions(block.events?.onChange, { value: event.target.value });
|
|
1363
|
+
}}
|
|
1364
|
+
/>
|
|
1365
|
+
</div>
|
|
1366
|
+
);
|
|
1367
|
+
}
|
|
1368
|
+
case "Form.TextArea": {
|
|
1369
|
+
const bindKey =
|
|
1370
|
+
rawProps.value &&
|
|
1371
|
+
typeof rawProps.value === "object" &&
|
|
1372
|
+
typeof (rawProps.value as Record<string, unknown>)._bindState === "string"
|
|
1373
|
+
? ((rawProps.value as Record<string, unknown>)._bindState as string)
|
|
1374
|
+
: typeof props.name === "string"
|
|
1375
|
+
? props.name
|
|
1376
|
+
: "";
|
|
1377
|
+
const inputId = block.id ?? \`textarea-\${bindKey || "input"}\`;
|
|
1378
|
+
return (
|
|
1379
|
+
<div className="um-field">
|
|
1380
|
+
{typeof props.label === "string" && <label htmlFor={inputId}>{props.label}</label>}
|
|
1381
|
+
<textarea
|
|
1382
|
+
id={inputId}
|
|
1383
|
+
className="um-textarea"
|
|
1384
|
+
rows={Number(props.rows ?? 4)}
|
|
1385
|
+
value={asText(props.value)}
|
|
1386
|
+
onChange={(event) => {
|
|
1387
|
+
if (bindKey) updateKey(bindKey, event.target.value);
|
|
1388
|
+
runActions(block.events?.onChange, { value: event.target.value });
|
|
1389
|
+
}}
|
|
1390
|
+
/>
|
|
1391
|
+
</div>
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
case "Form.Select": {
|
|
1395
|
+
const bindKey =
|
|
1396
|
+
rawProps.value &&
|
|
1397
|
+
typeof rawProps.value === "object" &&
|
|
1398
|
+
typeof (rawProps.value as Record<string, unknown>)._bindState === "string"
|
|
1399
|
+
? ((rawProps.value as Record<string, unknown>)._bindState as string)
|
|
1400
|
+
: typeof props.name === "string"
|
|
1401
|
+
? props.name
|
|
1402
|
+
: "";
|
|
1403
|
+
const inputId = block.id ?? \`select-\${bindKey || "input"}\`;
|
|
1404
|
+
const options = Array.isArray(props.options) ? props.options : [];
|
|
1405
|
+
return (
|
|
1406
|
+
<div className="um-field">
|
|
1407
|
+
{typeof props.label === "string" && <label htmlFor={inputId}>{props.label}</label>}
|
|
1408
|
+
<select
|
|
1409
|
+
id={inputId}
|
|
1410
|
+
className="um-select"
|
|
1411
|
+
value={asText(props.value)}
|
|
1412
|
+
onChange={(event) => {
|
|
1413
|
+
if (bindKey) updateKey(bindKey, event.target.value);
|
|
1414
|
+
runActions(block.events?.onChange, { value: event.target.value });
|
|
1415
|
+
}}
|
|
1416
|
+
>
|
|
1417
|
+
{options.map((opt) => {
|
|
1418
|
+
const obj =
|
|
1419
|
+
opt && typeof opt === "object"
|
|
1420
|
+
? (opt as Record<string, unknown>)
|
|
1421
|
+
: { value: String(opt), label: String(opt) };
|
|
1422
|
+
const val = asText(obj.value);
|
|
1423
|
+
return (
|
|
1424
|
+
<option key={val} value={val}>
|
|
1425
|
+
{asText(obj.label, val)}
|
|
1426
|
+
</option>
|
|
1427
|
+
);
|
|
1428
|
+
})}
|
|
1429
|
+
</select>
|
|
1430
|
+
</div>
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
case "Form.Checkbox": {
|
|
1434
|
+
const bindKey =
|
|
1435
|
+
rawProps.checked &&
|
|
1436
|
+
typeof rawProps.checked === "object" &&
|
|
1437
|
+
typeof (rawProps.checked as Record<string, unknown>)._bindState === "string"
|
|
1438
|
+
? ((rawProps.checked as Record<string, unknown>)._bindState as string)
|
|
1439
|
+
: typeof props.name === "string"
|
|
1440
|
+
? props.name
|
|
1441
|
+
: "";
|
|
1442
|
+
return (
|
|
1443
|
+
<label style={{ display: "inline-flex", alignItems: "center", gap: 8 }}>
|
|
1444
|
+
<input
|
|
1445
|
+
type="checkbox"
|
|
1446
|
+
checked={Boolean(props.checked ?? props.value)}
|
|
1447
|
+
onChange={(event) => {
|
|
1448
|
+
if (bindKey) updateKey(bindKey, event.target.checked);
|
|
1449
|
+
runActions(block.events?.onChange, { checked: event.target.checked });
|
|
1450
|
+
}}
|
|
1451
|
+
/>
|
|
1452
|
+
<span>{asText(props.label, bindKey)}</span>
|
|
1453
|
+
</label>
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1456
|
+
case "Form.Submit":
|
|
1457
|
+
return (
|
|
1458
|
+
<div>
|
|
1459
|
+
<button type="submit" className="um-btn">
|
|
1460
|
+
{asText(props.label, asText(props.text, "Submit"))}
|
|
1461
|
+
</button>
|
|
1462
|
+
</div>
|
|
1463
|
+
);
|
|
1464
|
+
case "PanelHeader":
|
|
1465
|
+
return (
|
|
1466
|
+
<div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
|
|
1467
|
+
<h2 style={{ margin: 0, fontSize: 20, fontWeight: 600 }}>{asText(props.title)}</h2>
|
|
1468
|
+
{typeof props.description === "string" && (
|
|
1469
|
+
<p className="um-card-desc">{props.description}</p>
|
|
1470
|
+
)}
|
|
1471
|
+
</div>
|
|
1472
|
+
);
|
|
1473
|
+
case "EmptyState":
|
|
1474
|
+
return (
|
|
1475
|
+
<div className="um-card" style={{ textAlign: "center", padding: 32 }}>
|
|
1476
|
+
<h3 className="um-card-title">{asText(props.title, "Empty")}</h3>
|
|
1477
|
+
{typeof props.description === "string" && (
|
|
1478
|
+
<p className="um-card-desc">{props.description}</p>
|
|
1479
|
+
)}
|
|
1480
|
+
{children}
|
|
1481
|
+
</div>
|
|
1482
|
+
);
|
|
1483
|
+
default:
|
|
1484
|
+
return (
|
|
1485
|
+
<div data-uibot-block={block.type} style={{ display: "flex", flexDirection: "column", gap: 10 }}>
|
|
1486
|
+
{typeof props.title === "string" && <h3 className="um-card-title">{props.title}</h3>}
|
|
1487
|
+
{typeof props.text === "string" && <p style={{ margin: 0 }}>{props.text}</p>}
|
|
1488
|
+
{children}
|
|
1489
|
+
</div>
|
|
1490
|
+
);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
`}function wn(e){let t=JSON.stringify(e.navGroups,null,2);return`import { useEffect, useMemo, useState, type ReactNode } from "react";
|
|
1494
|
+
import { AppLink, ShellIcon, useAppRouter } from "../lib/runtime";
|
|
1495
|
+
|
|
1496
|
+
export type ShellVariant =
|
|
1497
|
+
| "admin-sidebar"
|
|
1498
|
+
| "console-drilldown"
|
|
1499
|
+
| "sidebar-floating"
|
|
1500
|
+
| "sidebar-inset"
|
|
1501
|
+
| "top-navbar"
|
|
1502
|
+
| "dual-pane";
|
|
1503
|
+
|
|
1504
|
+
export interface ShellNavItem {
|
|
1505
|
+
label: string;
|
|
1506
|
+
href: string;
|
|
1507
|
+
icon?: string;
|
|
1508
|
+
badge?: string;
|
|
1509
|
+
children?: Array<{ label: string; href: string }>;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
export interface ShellNavGroup {
|
|
1513
|
+
label: string;
|
|
1514
|
+
items: ShellNavItem[];
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
export const DEFAULT_SHELL: ShellVariant = ${JSON.stringify(e.defaultShell)};
|
|
1518
|
+
export const DEFAULT_FOLDED = ${JSON.stringify(e.defaultFolded)};
|
|
1519
|
+
export const DEFAULT_CONTAINER = ${JSON.stringify(e.defaultContainer)};
|
|
1520
|
+
export const WORKSPACE_NAV_GROUPS: ShellNavGroup[] = ${t};
|
|
1521
|
+
|
|
1522
|
+
export interface WorkspaceShellProps {
|
|
1523
|
+
title?: string;
|
|
1524
|
+
shell?: ShellVariant;
|
|
1525
|
+
container?: string;
|
|
1526
|
+
folded?: boolean;
|
|
1527
|
+
navGroups?: ShellNavGroup[];
|
|
1528
|
+
children: ReactNode;
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
export function WorkspaceShell({
|
|
1532
|
+
title = ${JSON.stringify(e.brand)},
|
|
1533
|
+
shell = DEFAULT_SHELL,
|
|
1534
|
+
container = DEFAULT_CONTAINER,
|
|
1535
|
+
folded: initialFolded = DEFAULT_FOLDED,
|
|
1536
|
+
navGroups = WORKSPACE_NAV_GROUPS,
|
|
1537
|
+
children,
|
|
1538
|
+
}: WorkspaceShellProps) {
|
|
1539
|
+
const { path } = useAppRouter();
|
|
1540
|
+
const [folded, setFolded] = useState(initialFolded);
|
|
1541
|
+
const [dark, setDark] = useState(false);
|
|
1542
|
+
const [drawerOpen, setDrawerOpen] = useState(false);
|
|
1543
|
+
const [searchOpen, setSearchOpen] = useState(false);
|
|
1544
|
+
const [query, setQuery] = useState("");
|
|
1545
|
+
const [drillGroup, setDrillGroup] = useState<string | null>(null);
|
|
1546
|
+
const [secondaryOpen, setSecondaryOpen] = useState(!initialFolded);
|
|
1547
|
+
|
|
1548
|
+
const flatItems = useMemo(() => {
|
|
1549
|
+
const list: Array<{ label: string; href: string; icon?: string }> = [];
|
|
1550
|
+
for (const group of navGroups) {
|
|
1551
|
+
for (const item of group.items) {
|
|
1552
|
+
list.push({ label: item.label, href: item.href, ...(item.icon ? { icon: item.icon } : {}) });
|
|
1553
|
+
for (const child of item.children ?? []) {
|
|
1554
|
+
list.push({ label: child.label, href: child.href });
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
return list;
|
|
1559
|
+
}, [navGroups]);
|
|
1560
|
+
|
|
1561
|
+
const filteredRoutes = useMemo(
|
|
1562
|
+
() =>
|
|
1563
|
+
flatItems.filter((item) =>
|
|
1564
|
+
item.label.toLowerCase().includes(query.trim().toLowerCase()),
|
|
1565
|
+
),
|
|
1566
|
+
[flatItems, query],
|
|
1567
|
+
);
|
|
1568
|
+
|
|
1569
|
+
useEffect(() => {
|
|
1570
|
+
const onKey = (event: KeyboardEvent) => {
|
|
1571
|
+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
|
|
1572
|
+
event.preventDefault();
|
|
1573
|
+
setSearchOpen((prev) => !prev);
|
|
1574
|
+
} else if (event.key === "Escape") {
|
|
1575
|
+
setSearchOpen(false);
|
|
1576
|
+
setDrawerOpen(false);
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1579
|
+
window.addEventListener("keydown", onKey);
|
|
1580
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
1581
|
+
}, []);
|
|
1582
|
+
|
|
1583
|
+
const activeDrill = drillGroup ? navGroups.find((g) => g.label === drillGroup) : undefined;
|
|
1584
|
+
|
|
1585
|
+
const renderSidebarNav = (closeDrawer?: () => void) => {
|
|
1586
|
+
if (shell === "console-drilldown" && activeDrill) {
|
|
1587
|
+
return (
|
|
1588
|
+
<nav aria-label={activeDrill.label}>
|
|
1589
|
+
<button
|
|
1590
|
+
type="button"
|
|
1591
|
+
className="um-nav-link"
|
|
1592
|
+
onClick={() => setDrillGroup(null)}
|
|
1593
|
+
>
|
|
1594
|
+
<ShellIcon name="chevron-left" />
|
|
1595
|
+
<span className="um-nav-label">Back</span>
|
|
1596
|
+
</button>
|
|
1597
|
+
<div className="um-nav-group">
|
|
1598
|
+
<div className="um-nav-group-title">{activeDrill.label}</div>
|
|
1599
|
+
{activeDrill.items.map((item) => (
|
|
1600
|
+
<AppLink
|
|
1601
|
+
key={item.href}
|
|
1602
|
+
href={item.href}
|
|
1603
|
+
className="um-nav-link"
|
|
1604
|
+
ariaCurrent={path === item.href ? "page" : undefined}
|
|
1605
|
+
onAfterClick={closeDrawer}
|
|
1606
|
+
>
|
|
1607
|
+
<ShellIcon name={item.icon} />
|
|
1608
|
+
<span className="um-nav-label">{item.label}</span>
|
|
1609
|
+
</AppLink>
|
|
1610
|
+
))}
|
|
1611
|
+
</div>
|
|
1612
|
+
</nav>
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
return (
|
|
1617
|
+
<nav aria-label="Main navigation">
|
|
1618
|
+
{navGroups.map((group) => (
|
|
1619
|
+
<div key={group.label} className="um-nav-group">
|
|
1620
|
+
<div className="um-nav-group-title">{group.label}</div>
|
|
1621
|
+
{shell === "console-drilldown" && navGroups.length > 1 ? (
|
|
1622
|
+
<button
|
|
1623
|
+
type="button"
|
|
1624
|
+
className="um-nav-link"
|
|
1625
|
+
onClick={() => setDrillGroup(group.label)}
|
|
1626
|
+
>
|
|
1627
|
+
<ShellIcon name="boxes" />
|
|
1628
|
+
<span className="um-nav-label">{group.label}</span>
|
|
1629
|
+
<ShellIcon name="chevron-right" size={14} />
|
|
1630
|
+
</button>
|
|
1631
|
+
) : (
|
|
1632
|
+
group.items.map((item) => (
|
|
1633
|
+
<AppLink
|
|
1634
|
+
key={item.href}
|
|
1635
|
+
href={item.href}
|
|
1636
|
+
className="um-nav-link"
|
|
1637
|
+
ariaCurrent={path === item.href ? "page" : undefined}
|
|
1638
|
+
title={item.label}
|
|
1639
|
+
onAfterClick={closeDrawer}
|
|
1640
|
+
>
|
|
1641
|
+
<ShellIcon name={item.icon} />
|
|
1642
|
+
<span className="um-nav-label">{item.label}</span>
|
|
1643
|
+
{item.badge && <span className="um-badge">{item.badge}</span>}
|
|
1644
|
+
</AppLink>
|
|
1645
|
+
))
|
|
1646
|
+
)}
|
|
1647
|
+
</div>
|
|
1648
|
+
))}
|
|
1649
|
+
</nav>
|
|
1650
|
+
);
|
|
1651
|
+
};
|
|
1652
|
+
|
|
1653
|
+
const toolbar = (
|
|
1654
|
+
<div className="um-toolbar">
|
|
1655
|
+
<button
|
|
1656
|
+
type="button"
|
|
1657
|
+
className="um-icon-btn"
|
|
1658
|
+
aria-label="Search pages"
|
|
1659
|
+
onClick={() => setSearchOpen(true)}
|
|
1660
|
+
>
|
|
1661
|
+
<ShellIcon name="search" size={15} />
|
|
1662
|
+
<span>Search</span>
|
|
1663
|
+
<kbd>\u2318K</kbd>
|
|
1664
|
+
</button>
|
|
1665
|
+
<button
|
|
1666
|
+
type="button"
|
|
1667
|
+
className="um-icon-btn"
|
|
1668
|
+
aria-label={dark ? "Use light theme" : "Use dark theme"}
|
|
1669
|
+
onClick={() => setDark((prev) => !prev)}
|
|
1670
|
+
>
|
|
1671
|
+
<ShellIcon name={dark ? "moon" : "sun"} size={15} />
|
|
1672
|
+
</button>
|
|
1673
|
+
</div>
|
|
1674
|
+
);
|
|
1675
|
+
|
|
1676
|
+
const overlays = (
|
|
1677
|
+
<>
|
|
1678
|
+
{drawerOpen && (
|
|
1679
|
+
<div
|
|
1680
|
+
className="um-drawer-backdrop"
|
|
1681
|
+
role="dialog"
|
|
1682
|
+
aria-modal="true"
|
|
1683
|
+
aria-label="Navigation"
|
|
1684
|
+
onClick={(event) => {
|
|
1685
|
+
if (event.target === event.currentTarget) setDrawerOpen(false);
|
|
1686
|
+
}}
|
|
1687
|
+
>
|
|
1688
|
+
<div className="um-drawer-panel">
|
|
1689
|
+
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
|
|
1690
|
+
<strong>{title}</strong>
|
|
1691
|
+
<button
|
|
1692
|
+
type="button"
|
|
1693
|
+
className="um-icon-btn"
|
|
1694
|
+
aria-label="Close navigation"
|
|
1695
|
+
onClick={() => setDrawerOpen(false)}
|
|
1696
|
+
>
|
|
1697
|
+
<ShellIcon name="x" />
|
|
1698
|
+
</button>
|
|
1699
|
+
</div>
|
|
1700
|
+
{renderSidebarNav(() => setDrawerOpen(false))}
|
|
1701
|
+
</div>
|
|
1702
|
+
</div>
|
|
1703
|
+
)}
|
|
1704
|
+
{searchOpen && (
|
|
1705
|
+
<div
|
|
1706
|
+
className="um-modal-backdrop"
|
|
1707
|
+
role="dialog"
|
|
1708
|
+
aria-modal="true"
|
|
1709
|
+
aria-label="Search pages"
|
|
1710
|
+
onClick={(event) => {
|
|
1711
|
+
if (event.target === event.currentTarget) setSearchOpen(false);
|
|
1712
|
+
}}
|
|
1713
|
+
>
|
|
1714
|
+
<div className="um-modal-card">
|
|
1715
|
+
<input
|
|
1716
|
+
type="search"
|
|
1717
|
+
autoFocus
|
|
1718
|
+
className="um-input"
|
|
1719
|
+
style={{ border: 0, borderBottom: "1px solid var(--um-border)", borderRadius: 0 }}
|
|
1720
|
+
placeholder="Jump to page..."
|
|
1721
|
+
aria-label="Jump to page"
|
|
1722
|
+
value={query}
|
|
1723
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
1724
|
+
/>
|
|
1725
|
+
<div style={{ padding: 10, display: "flex", flexDirection: "column", gap: 4 }}>
|
|
1726
|
+
{filteredRoutes.map((item) => (
|
|
1727
|
+
<AppLink
|
|
1728
|
+
key={item.href}
|
|
1729
|
+
href={item.href}
|
|
1730
|
+
className="um-nav-link"
|
|
1731
|
+
onAfterClick={() => {
|
|
1732
|
+
setSearchOpen(false);
|
|
1733
|
+
setQuery("");
|
|
1734
|
+
}}
|
|
1735
|
+
>
|
|
1736
|
+
<ShellIcon name={item.icon} />
|
|
1737
|
+
<span>{item.label}</span>
|
|
1738
|
+
</AppLink>
|
|
1739
|
+
))}
|
|
1740
|
+
{filteredRoutes.length === 0 && (
|
|
1741
|
+
<p className="um-card-desc" style={{ padding: 8 }}>
|
|
1742
|
+
No pages found.
|
|
1743
|
+
</p>
|
|
1744
|
+
)}
|
|
1745
|
+
</div>
|
|
1746
|
+
</div>
|
|
1747
|
+
</div>
|
|
1748
|
+
)}
|
|
1749
|
+
</>
|
|
1750
|
+
);
|
|
1751
|
+
|
|
1752
|
+
if (shell === "top-navbar") {
|
|
1753
|
+
return (
|
|
1754
|
+
<div
|
|
1755
|
+
className={\`um-root \${dark ? "um-dark" : ""}\`}
|
|
1756
|
+
data-shell="top-navbar"
|
|
1757
|
+
data-container={container}
|
|
1758
|
+
>
|
|
1759
|
+
<header className="um-topbar">
|
|
1760
|
+
<button
|
|
1761
|
+
type="button"
|
|
1762
|
+
className="um-icon-btn um-mobile-only"
|
|
1763
|
+
aria-label="Open navigation"
|
|
1764
|
+
onClick={() => setDrawerOpen(true)}
|
|
1765
|
+
>
|
|
1766
|
+
<ShellIcon name="menu" />
|
|
1767
|
+
</button>
|
|
1768
|
+
<AppLink href="/" className="um-brand">
|
|
1769
|
+
<span className="um-brand-mark">
|
|
1770
|
+
<ShellIcon name="layout-dashboard" size={16} />
|
|
1771
|
+
</span>
|
|
1772
|
+
<span>{title}</span>
|
|
1773
|
+
</AppLink>
|
|
1774
|
+
<nav className="um-top-links" aria-label="Main navigation">
|
|
1775
|
+
{flatItems.map((item) => (
|
|
1776
|
+
<AppLink
|
|
1777
|
+
key={item.href}
|
|
1778
|
+
href={item.href}
|
|
1779
|
+
className="um-nav-link"
|
|
1780
|
+
ariaCurrent={path === item.href ? "page" : undefined}
|
|
1781
|
+
>
|
|
1782
|
+
{item.label}
|
|
1783
|
+
</AppLink>
|
|
1784
|
+
))}
|
|
1785
|
+
</nav>
|
|
1786
|
+
{toolbar}
|
|
1787
|
+
</header>
|
|
1788
|
+
<main className="um-main">
|
|
1789
|
+
<div className="um-content">
|
|
1790
|
+
<div className="um-content-inner">{children}</div>
|
|
1791
|
+
</div>
|
|
1792
|
+
</main>
|
|
1793
|
+
{overlays}
|
|
1794
|
+
</div>
|
|
1795
|
+
);
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
if (shell === "console-drilldown") {
|
|
1799
|
+
return (
|
|
1800
|
+
<div
|
|
1801
|
+
className={\`um-root \${dark ? "um-dark" : ""}\`}
|
|
1802
|
+
data-shell="console-drilldown"
|
|
1803
|
+
data-container={container}
|
|
1804
|
+
>
|
|
1805
|
+
<header className="um-topbar">
|
|
1806
|
+
<button
|
|
1807
|
+
type="button"
|
|
1808
|
+
className="um-icon-btn um-mobile-only"
|
|
1809
|
+
aria-label="Open navigation"
|
|
1810
|
+
onClick={() => setDrawerOpen(true)}
|
|
1811
|
+
>
|
|
1812
|
+
<ShellIcon name="menu" />
|
|
1813
|
+
</button>
|
|
1814
|
+
<AppLink href="/" className="um-brand">
|
|
1815
|
+
<span className="um-brand-mark">
|
|
1816
|
+
<ShellIcon name="layout-dashboard" size={16} />
|
|
1817
|
+
</span>
|
|
1818
|
+
<span>{title}</span>
|
|
1819
|
+
</AppLink>
|
|
1820
|
+
{toolbar}
|
|
1821
|
+
</header>
|
|
1822
|
+
<div className="um-body">
|
|
1823
|
+
<aside className="um-sidebar" aria-label="Console navigation">
|
|
1824
|
+
{renderSidebarNav()}
|
|
1825
|
+
</aside>
|
|
1826
|
+
<main className="um-main">
|
|
1827
|
+
<div className="um-content">
|
|
1828
|
+
<div className="um-content-inner">{children}</div>
|
|
1829
|
+
</div>
|
|
1830
|
+
</main>
|
|
1831
|
+
</div>
|
|
1832
|
+
{overlays}
|
|
1833
|
+
</div>
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
if (shell === "dual-pane") {
|
|
1838
|
+
return (
|
|
1839
|
+
<div
|
|
1840
|
+
className={\`um-root \${dark ? "um-dark" : ""}\`}
|
|
1841
|
+
data-shell="dual-pane"
|
|
1842
|
+
data-container={container}
|
|
1843
|
+
>
|
|
1844
|
+
<nav className="um-rail" aria-label="Primary sections">
|
|
1845
|
+
<AppLink href="/" className="um-brand-mark" ariaLabel={title} title={title}>
|
|
1846
|
+
<ShellIcon name="layout-dashboard" size={16} />
|
|
1847
|
+
</AppLink>
|
|
1848
|
+
{flatItems.slice(0, 8).map((item) => (
|
|
1849
|
+
<AppLink
|
|
1850
|
+
key={item.href}
|
|
1851
|
+
href={item.href}
|
|
1852
|
+
className="um-rail-btn"
|
|
1853
|
+
title={item.label}
|
|
1854
|
+
ariaLabel={item.label}
|
|
1855
|
+
ariaCurrent={path === item.href ? "page" : undefined}
|
|
1856
|
+
>
|
|
1857
|
+
<ShellIcon name={item.icon} size={17} />
|
|
1858
|
+
</AppLink>
|
|
1859
|
+
))}
|
|
1860
|
+
</nav>
|
|
1861
|
+
{secondaryOpen && (
|
|
1862
|
+
<aside className="um-sidebar" aria-label="Workspace navigation">
|
|
1863
|
+
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "4px 6px" }}>
|
|
1864
|
+
<strong>{title}</strong>
|
|
1865
|
+
<button
|
|
1866
|
+
type="button"
|
|
1867
|
+
className="um-icon-btn"
|
|
1868
|
+
aria-label="Collapse secondary pane"
|
|
1869
|
+
onClick={() => setSecondaryOpen(false)}
|
|
1870
|
+
>
|
|
1871
|
+
<ShellIcon name="panel-left" size={15} />
|
|
1872
|
+
</button>
|
|
1873
|
+
</div>
|
|
1874
|
+
{renderSidebarNav()}
|
|
1875
|
+
</aside>
|
|
1876
|
+
)}
|
|
1877
|
+
<div className="um-main">
|
|
1878
|
+
<header className="um-topbar">
|
|
1879
|
+
<button
|
|
1880
|
+
type="button"
|
|
1881
|
+
className="um-icon-btn um-mobile-only"
|
|
1882
|
+
aria-label="Open navigation"
|
|
1883
|
+
onClick={() => setDrawerOpen(true)}
|
|
1884
|
+
>
|
|
1885
|
+
<ShellIcon name="menu" />
|
|
1886
|
+
</button>
|
|
1887
|
+
{!secondaryOpen && (
|
|
1888
|
+
<button
|
|
1889
|
+
type="button"
|
|
1890
|
+
className="um-icon-btn"
|
|
1891
|
+
aria-label="Expand secondary pane"
|
|
1892
|
+
onClick={() => setSecondaryOpen(true)}
|
|
1893
|
+
>
|
|
1894
|
+
<ShellIcon name="panel-left" size={15} />
|
|
1895
|
+
</button>
|
|
1896
|
+
)}
|
|
1897
|
+
<strong>{title}</strong>
|
|
1898
|
+
{toolbar}
|
|
1899
|
+
</header>
|
|
1900
|
+
<main className="um-content">
|
|
1901
|
+
<div className="um-content-inner">{children}</div>
|
|
1902
|
+
</main>
|
|
1903
|
+
</div>
|
|
1904
|
+
{overlays}
|
|
1905
|
+
</div>
|
|
1906
|
+
);
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
return (
|
|
1910
|
+
<div
|
|
1911
|
+
className={\`um-root \${dark ? "um-dark" : ""}\`}
|
|
1912
|
+
data-shell={shell}
|
|
1913
|
+
data-folded={folded ? "true" : "false"}
|
|
1914
|
+
data-container={container}
|
|
1915
|
+
>
|
|
1916
|
+
<aside className="um-sidebar" aria-label="Workspace navigation">
|
|
1917
|
+
<AppLink href="/" className="um-brand">
|
|
1918
|
+
<span className="um-brand-mark">
|
|
1919
|
+
<ShellIcon name="layout-dashboard" size={16} />
|
|
1920
|
+
</span>
|
|
1921
|
+
<span className="um-brand-text">{title}</span>
|
|
1922
|
+
</AppLink>
|
|
1923
|
+
{renderSidebarNav()}
|
|
1924
|
+
</aside>
|
|
1925
|
+
<div className="um-main">
|
|
1926
|
+
<header className="um-topbar">
|
|
1927
|
+
<button
|
|
1928
|
+
type="button"
|
|
1929
|
+
className="um-icon-btn um-mobile-only"
|
|
1930
|
+
aria-label="Open navigation"
|
|
1931
|
+
onClick={() => setDrawerOpen(true)}
|
|
1932
|
+
>
|
|
1933
|
+
<ShellIcon name="menu" />
|
|
1934
|
+
</button>
|
|
1935
|
+
<button
|
|
1936
|
+
type="button"
|
|
1937
|
+
className="um-icon-btn"
|
|
1938
|
+
aria-label="Toggle sidebar"
|
|
1939
|
+
aria-expanded={!folded}
|
|
1940
|
+
onClick={() => setFolded((prev) => !prev)}
|
|
1941
|
+
>
|
|
1942
|
+
<ShellIcon name="panel-left" size={15} />
|
|
1943
|
+
</button>
|
|
1944
|
+
<strong>{title}</strong>
|
|
1945
|
+
{toolbar}
|
|
1946
|
+
</header>
|
|
1947
|
+
<main className="um-content">
|
|
1948
|
+
<div className="um-content-inner">{children}</div>
|
|
1949
|
+
</main>
|
|
1950
|
+
</div>
|
|
1951
|
+
{overlays}
|
|
1952
|
+
</div>
|
|
1953
|
+
);
|
|
1954
|
+
}
|
|
1955
|
+
`}function Sn(e){let t=e.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/^-+|-+$/g,"")||"uibot-materialized-app";return[{path:"package.json",content:`${JSON.stringify({name:t,private:!0,version:"0.1.0",type:"module",scripts:{dev:"vite",build:"tsc --noEmit && vite build",typecheck:"tsc --noEmit",preview:"vite preview"},dependencies:{react:"^19.2.8","react-dom":"^19.2.8"},devDependencies:{"@types/react":"^19.2.14","@types/react-dom":"^19.2.3","@vitejs/plugin-react":"^5.0.0",typescript:"^5.9.3",vite:"^8.3.7"}},null,2)}
|
|
1956
|
+
`},{path:"index.html",content:`<!doctype html>
|
|
1957
|
+
<html lang="en">
|
|
1958
|
+
<head>
|
|
1959
|
+
<meta charset="UTF-8" />
|
|
1960
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
1961
|
+
<title>${e.replace(/[<>&"]/g,"")}</title>
|
|
1962
|
+
</head>
|
|
1963
|
+
<body>
|
|
1964
|
+
<div id="root"></div>
|
|
1965
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
1966
|
+
</body>
|
|
1967
|
+
</html>
|
|
1968
|
+
`},{path:"tsconfig.json",content:`${JSON.stringify({compilerOptions:{target:"ES2022",lib:["ES2022","DOM","DOM.Iterable"],module:"ESNext",moduleResolution:"Bundler",jsx:"react-jsx",strict:!0,verbatimModuleSyntax:!0,noUnusedLocals:!0,noUnusedParameters:!0,noEmit:!0,skipLibCheck:!0},include:["src"]},null,2)}
|
|
1969
|
+
`},{path:"vite.config.ts",content:`import { defineConfig } from "vite";
|
|
1970
|
+
import react from "@vitejs/plugin-react";
|
|
1971
|
+
|
|
1972
|
+
export default defineConfig({
|
|
1973
|
+
plugins: [react()],
|
|
1974
|
+
});
|
|
1975
|
+
`},{path:"src/main.tsx",content:`import { StrictMode } from "react";
|
|
1976
|
+
import { createRoot } from "react-dom/client";
|
|
1977
|
+
import { MaterializedApp } from "./uibot/App";
|
|
1978
|
+
|
|
1979
|
+
const root = document.getElementById("root");
|
|
1980
|
+
if (root) {
|
|
1981
|
+
createRoot(root).render(
|
|
1982
|
+
<StrictMode>
|
|
1983
|
+
<MaterializedApp />
|
|
1984
|
+
</StrictMode>,
|
|
1985
|
+
);
|
|
1986
|
+
}
|
|
1987
|
+
`}]}var Wo="uibot.materialize.manifest.v1",Go=new Set(["SetState","ResetState","Link","Navigate","DisplayMessage","Toast","Request"]);function Yo(e){if(e.layout?.shell)return e.layout.shell;if(e.layout?.navigation==="navbar")return"top-navbar";if(e.layout?.navigationStyle==="floating")return"sidebar-floating";if(e.pages.some((n)=>n.blocks.some((o)=>o.type==="PageLayout"&&o.props?.appearance==="console")))return"console-drilldown";return"admin-sidebar"}function Jo(e,t){let o=e.replace(/[^A-Za-z0-9]+/g," ").trim().split(/\s+/).filter(Boolean).map((a)=>a[0]?a[0].toUpperCase()+a.slice(1):"").join(""),r=`Page${String(t+1).padStart(3,"0")}`;return o?`${r}_${o}`:r}function X(e){let t=e?.trim();if(!t)return"/";return t.startsWith("/")?t:`/${t}`}function In(e){if(e.layout?.inherit===!1)return!0;let t=e.blocks.find((n)=>n.type==="PageLayout");if(!t)return!0;return t.props?.appearance==="standalone"}function Zo(e){let t=e.blocks.find((n)=>n.type==="PageLayout");if(t&&t.props?.appearance!=="standalone")return t.children??[];if(t&&t.props?.appearance==="standalone")return t.children??[];return e.blocks}function Qo(e,t){let n=t,o="",r=[];for(let a of e.pages){let s=a.blocks.find((c)=>c.type==="PageLayout");if(s?.props){if(typeof s.props.title==="string"&&s.props.title.trim())n=s.props.title.trim();else if(typeof s.props.brand==="string"&&s.props.brand.trim())n=s.props.brand.trim();if(typeof s.props.subtitle==="string"&&s.props.subtitle.trim())o=s.props.subtitle.trim()}let i=s?.slots?.sidebar??[];for(let c of i)if(c.type==="AppNavigation"&&c.props){if(typeof c.props.brand==="string"&&c.props.brand.trim())n=c.props.brand.trim();if(typeof c.props.subtitle==="string"&&c.props.subtitle.trim())o=c.props.subtitle.trim();if(Array.isArray(c.props.groups)&&r.length===0)for(let l of c.props.groups){if(!l||typeof l!=="object")continue;let d=l,u=typeof d.label==="string"?d.label:"Navigation",g=Array.isArray(d.items)?d.items.filter((p)=>Boolean(p&&typeof p==="object")).map((p)=>({label:typeof p.label==="string"?p.label:String(p.href??"/"),href:X(typeof p.href==="string"?p.href:"/"),...typeof p.icon==="string"?{icon:p.icon}:{},...typeof p.badge==="string"?{badge:p.badge}:{},...Array.isArray(p.children)?{children:p.children.filter((f)=>Boolean(f&&typeof f==="object")).map((f)=>({label:typeof f.label==="string"?f.label:String(f.href??"/"),href:X(typeof f.href==="string"?f.href:"/")}))}:{}})):[];if(g.length>0)r.push({label:u,items:g})}}}if(r.length===0&&e.menus?.items?.length){let a=[];for(let s of e.menus.items)if("items"in s&&Array.isArray(s.items)){let i=[];for(let c of s.items)if("path"in c&&typeof c.path==="string")i.push({label:c.label,href:X(c.path),...c.icon?{icon:c.icon}:{}});if(i.length>0)r.push({label:s.label,items:i})}else if("path"in s&&typeof s.path==="string")a.push({label:s.label,href:X(s.path),...s.icon?{icon:s.icon}:{}});if(a.length>0)r.unshift({label:"Workspace",items:a})}if(r.length===0){let a=e.pages.filter((i)=>!In(i)),s=a.length>0?a:e.pages;r.push({label:"Pages",items:s.map((i)=>({label:i.title??i.id,href:X(i.path)}))})}return{brand:n,subtitle:o,navGroups:r}}function Xo(e){let t=[],n={};for(let r of e.connections??[]){let a=r;if(a.bindings&&typeof a.bindings==="object")t.push({level:"warning",code:"stripped-connection-bindings",path:`connections.${r.id}.bindings`,message:`Connection "${r.id}" environment bindings are host-owned and omitted from materialized client source; wire them via the host data gateway.`});let s=a.mock?.seed;if(Array.isArray(s))n[r.id]=s.filter((i)=>Boolean(i&&typeof i==="object"));else n[r.id]=[]}if(e.auth)t.push({level:"info",code:"host-auth-boundary",path:"auth",message:"Authentication session and ACL enforcement remain host-owned; pass `onHostAction` to `MaterializedApp` to handle auth actions."});let o=(r,a)=>{for(let[s,i]of Object.entries(r.events??{})){if(!Array.isArray(i))continue;for(let c=0;c<i.length;c++){let l=i[c];if(l&&!Go.has(l.action))t.push({level:"warning",code:"host-action-delegated",path:`${a}.events.${s}[${c}]`,message:`Action "${l.action}" is forwarded to MaterializedApp's \`onHostAction\` prop.`})}}for(let s=0;s<(r.children?.length??0);s++){let i=r.children?.[s];if(i)o(i,`${a}.children[${s}]`)}for(let[s,i]of Object.entries(r.slots??{}))for(let c=0;c<i.length;c++){let l=i[c];if(l)o(l,`${a}.slots.${s}[${c}]`)}};for(let r=0;r<e.pages.length;r++){let a=e.pages[r];if(!a)continue;for(let s=0;s<a.blocks.length;s++){let i=a.blocks[s];if(i)o(i,`pages[${r}].blocks[${s}]`)}}return{diagnostics:t,mockCollections:n}}function ei(e){let t=structuredClone(e),n=[];if(t.connections)for(let o of t.connections){let r=o;if(r.bindings&&typeof r.bindings==="object")n.push({level:"warning",code:"stripped-connection-bindings",path:`connections.${o.id}.bindings`,message:`Connection "${o.id}" environment bindings are host-owned and omitted from materialized client source; wire them via the host data gateway.`}),delete r.bindings}return{spec:t,strippedDiagnostics:n}}function ti(e,t,n,o,r){let a=e.state??{},s=Zo(e),i=e.layout?.container??r,c=e.layout?.shell??o,l=e.layout?.sidebar==="folded",d=JSON.stringify(s,null,2),u=JSON.stringify(a,null,2);if(n)return`import { BlockList, usePageRuntime, type MaterializedBlock } from "../lib/runtime";
|
|
1988
|
+
|
|
1989
|
+
export const PAGE_META = ${JSON.stringify({id:e.id,path:X(e.path),title:e.title??e.id,standalone:!0},null,2)} as const;
|
|
1990
|
+
|
|
1991
|
+
const INITIAL_STATE: Record<string, unknown> = ${u};
|
|
1992
|
+
const PAGE_BLOCKS: MaterializedBlock[] = ${d};
|
|
1993
|
+
|
|
1994
|
+
export function ${t}() {
|
|
1995
|
+
const { state, updateKey, runActions } = usePageRuntime(INITIAL_STATE);
|
|
1996
|
+
return (
|
|
1997
|
+
<div className="um-standalone" data-container=${JSON.stringify(i)}>
|
|
1998
|
+
<div className="um-standalone-inner">
|
|
1999
|
+
<BlockList
|
|
2000
|
+
blocks={PAGE_BLOCKS}
|
|
2001
|
+
state={state}
|
|
2002
|
+
updateKey={updateKey}
|
|
2003
|
+
runActions={runActions}
|
|
2004
|
+
/>
|
|
2005
|
+
</div>
|
|
2006
|
+
</div>
|
|
2007
|
+
);
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
export default ${t};
|
|
2011
|
+
`;return`import { BlockList, usePageRuntime, type MaterializedBlock } from "../lib/runtime";
|
|
2012
|
+
import { WorkspaceShell } from "../shell/WorkspaceShell";
|
|
2013
|
+
|
|
2014
|
+
export const PAGE_META = ${JSON.stringify({id:e.id,path:X(e.path),title:e.title??e.id,standalone:!1},null,2)} as const;
|
|
2015
|
+
|
|
2016
|
+
const INITIAL_STATE: Record<string, unknown> = ${u};
|
|
2017
|
+
const PAGE_BLOCKS: MaterializedBlock[] = ${d};
|
|
2018
|
+
|
|
2019
|
+
export function ${t}() {
|
|
2020
|
+
const { state, updateKey, runActions } = usePageRuntime(INITIAL_STATE);
|
|
2021
|
+
return (
|
|
2022
|
+
<WorkspaceShell
|
|
2023
|
+
shell=${JSON.stringify(c)}
|
|
2024
|
+
container=${JSON.stringify(i)}
|
|
2025
|
+
folded={${l?"true":"false"}}
|
|
2026
|
+
>
|
|
2027
|
+
<BlockList
|
|
2028
|
+
blocks={PAGE_BLOCKS}
|
|
2029
|
+
state={state}
|
|
2030
|
+
updateKey={updateKey}
|
|
2031
|
+
runActions={runActions}
|
|
2032
|
+
/>
|
|
2033
|
+
</WorkspaceShell>
|
|
2034
|
+
);
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
export default ${t};
|
|
2038
|
+
`}function ni(e,t){let n=e.map((r)=>`import { ${r.componentName} } from "./pages/${r.componentName}";`).join(`
|
|
2039
|
+
`),o=e.map((r)=>` {
|
|
2040
|
+
pageId: ${JSON.stringify(r.pageId)},
|
|
2041
|
+
path: ${JSON.stringify(r.path)},
|
|
2042
|
+
title: ${JSON.stringify(r.title)},
|
|
2043
|
+
standalone: ${r.standalone?"true":"false"},
|
|
2044
|
+
Component: ${r.componentName},
|
|
2045
|
+
}`).join(`,
|
|
2046
|
+
`);return`import type { ComponentType } from "react";
|
|
2047
|
+
${n}
|
|
2048
|
+
|
|
2049
|
+
export interface MaterializedRoute {
|
|
2050
|
+
pageId: string;
|
|
2051
|
+
path: string;
|
|
2052
|
+
title: string;
|
|
2053
|
+
standalone: boolean;
|
|
2054
|
+
Component: ComponentType;
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
export const ENTRY_PATH = ${JSON.stringify(t)};
|
|
2058
|
+
|
|
2059
|
+
export const MATERIALIZED_ROUTES: MaterializedRoute[] = [
|
|
2060
|
+
${o}
|
|
2061
|
+
];
|
|
2062
|
+
`}function ri(){return`import "./styles.css";
|
|
2063
|
+
import { AppLink, RouterProvider, useAppRouter } from "./lib/runtime";
|
|
2064
|
+
import { ENTRY_PATH, MATERIALIZED_ROUTES } from "./routes";
|
|
2065
|
+
|
|
2066
|
+
export interface MaterializedAppProps {
|
|
2067
|
+
initialPath?: string;
|
|
2068
|
+
onNavigate?: (nextPath: string) => void;
|
|
2069
|
+
onHostAction?: (action: string, params: Record<string, unknown>) => void;
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
function ActiveRoute() {
|
|
2073
|
+
const { path } = useAppRouter();
|
|
2074
|
+
const matched =
|
|
2075
|
+
MATERIALIZED_ROUTES.find((route) => route.path === path) ??
|
|
2076
|
+
(path === "/" ? MATERIALIZED_ROUTES.find((route) => route.path === ENTRY_PATH) : undefined);
|
|
2077
|
+
|
|
2078
|
+
if (!matched) {
|
|
2079
|
+
return (
|
|
2080
|
+
<div className="um-standalone" data-container="boxed">
|
|
2081
|
+
<div className="um-standalone-inner">
|
|
2082
|
+
<section className="um-card">
|
|
2083
|
+
<h1 className="um-card-title">Page not found</h1>
|
|
2084
|
+
<p className="um-card-desc">No route matches {path}.</p>
|
|
2085
|
+
<AppLink href={ENTRY_PATH} className="um-btn">
|
|
2086
|
+
Back to workspace
|
|
2087
|
+
</AppLink>
|
|
2088
|
+
</section>
|
|
2089
|
+
</div>
|
|
2090
|
+
</div>
|
|
2091
|
+
);
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
const PageComponent = matched.Component;
|
|
2095
|
+
return <PageComponent />;
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
export function MaterializedApp({
|
|
2099
|
+
initialPath,
|
|
2100
|
+
onNavigate,
|
|
2101
|
+
onHostAction,
|
|
2102
|
+
}: MaterializedAppProps = {}) {
|
|
2103
|
+
return (
|
|
2104
|
+
<RouterProvider
|
|
2105
|
+
{...(initialPath !== undefined ? { initialPath } : {})}
|
|
2106
|
+
fallbackPath={ENTRY_PATH}
|
|
2107
|
+
onNavigate={onNavigate}
|
|
2108
|
+
onHostAction={onHostAction}
|
|
2109
|
+
>
|
|
2110
|
+
<ActiveRoute />
|
|
2111
|
+
</RouterProvider>
|
|
2112
|
+
);
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
export default MaterializedApp;
|
|
2116
|
+
`}function H(e,t,n,o){let r=n.replace(/\\/g,"/").replace(/^\/+/,"");if(!r||r.includes("..")||r.includes("\x00")||t.has(r.toLowerCase()))throw Error(`invalid-or-colliding-materialized-path:${n}`);t.add(r.toLowerCase()),e.push({path:r,content:o,sha256:fe(o)})}function $l(e){let t=e.target??"react-tsx",n=e.scaffold??"none";if(n==="vite-react"&&t!=="react-tsx")throw Error("scaffold-requires-react-tsx-target");let o=ei(e.spec),r=o.spec;if(e.shellVariant){if(!e.variantRegistry)throw Error("missing-variant-registry-for-shell-swap");r=ie(e.variantRegistry,{spec:r,target:{kind:"shell"},targetVariantId:e.shellVariant}).spec}if(!Array.isArray(r.pages)||r.pages.length===0)throw Error("materialize-empty-spec-pages");let a=fe(JSON.stringify(r)),s=Yo(r),i=r.layout?.sidebar==="folded",c=r.layout?.container??"fluid",l=e.appName?.trim()||"UIBot App",{brand:d,subtitle:u,navGroups:g}=Qo(r,l),{diagnostics:p,mockCollections:f}=Xo(r),m=[...o.strippedDiagnostics,...p],h=n==="vite-react"?"src/uibot/":"",x=r.pages.map((y,T)=>{let v=Jo(y.id,T);return{pageId:y.id,path:X(y.path),title:y.title??y.id,componentName:v,filePath:t==="react-tsx"?`${h}pages/${v}.tsx`:"app.uibot.yaml",standalone:In(y)}}),k=x.find((y)=>y.path==="/")?.path??x.find((y)=>!y.standalone)?.path??x[0]?.path??"/",b=[],C=new Set;if(t==="uibot-yaml"){let y=e.stringifyYaml?e.stringifyYaml(r):`${JSON.stringify(r,null,2)}
|
|
2117
|
+
`;H(b,C,"app.uibot.yaml",y)}else{H(b,C,`${h}styles.css`,vn()),H(b,C,`${h}styles.d.ts`,`declare module "*.css" {}
|
|
2118
|
+
`),H(b,C,`${h}lib/runtime.tsx`,Cn(JSON.stringify(f,null,2))),H(b,C,`${h}shell/WorkspaceShell.tsx`,wn({brand:d,subtitle:u,defaultShell:s,defaultFolded:i,defaultContainer:c,navGroups:g}));for(let y=0;y<r.pages.length;y++){let T=r.pages[y],v=x[y];if(!T||!v)continue;H(b,C,v.filePath,ti(T,v.componentName,v.standalone,s,c))}if(H(b,C,`${h}routes.tsx`,ni(x,k)),H(b,C,`${h}App.tsx`,ri()),n==="vite-react")for(let y of Sn(d))H(b,C,y.path,y.content)}let A={contract:Wo,target:t,scaffold:n,appName:d,inputSpecSha256:a,effectiveShell:s,entryPath:k,routes:x,peerDependencies:t==="react-tsx"?{react:"^19.0.0","react-dom":"^19.0.0"}:{},files:b.map((y)=>({path:y.path,sha256:y.sha256})),diagnostics:m};return H(b,C,"materialize.manifest.json",`${JSON.stringify(A,null,2)}
|
|
2119
|
+
`),{spec:r,manifest:A,files:b,diagnostics:m}}import{createHash as oi}from"crypto";var We=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,He=/^[a-f0-9]{64}$/,qe=/^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/,Rn=new TextEncoder,ii=new TextDecoder("utf-8",{fatal:!0});function Ge(e){return oi("sha256").update(e).digest("hex")}function se(e){let t=0,n=(r,a)=>{if(++t>400000||a>32)throw Error("snapshot-json-budget-exceeded");if(Array.isArray(r))return r.map((s)=>n(s,a+1));if(r&&typeof r==="object"){if(Object.getPrototypeOf(r)!==Object.prototype)throw Error("snapshot-invalid-json");return Object.fromEntries(Object.keys(r).sort().map((s)=>[s,n(r[s],a+1)]))}if(r===null||typeof r==="string"||typeof r==="boolean"||typeof r==="number"&&Number.isFinite(r))return r;throw Error("snapshot-invalid-json")},o=JSON.stringify(n(e,0));if(Rn.encode(o).length>16777216)throw Error("snapshot-json-budget-exceeded");return o}function Ke(e){if(typeof e!=="string"||!/^[a-zA-Z0-9_./-]+$/.test(e)||e.split("/").some((t)=>!t||t==="."||t==="..")||e.startsWith("/"))throw Error(`snapshot-unsafe-path: ${e}`)}function St(e,t){return Ke(e),{path:e,bytes:t.byteLength,sha256:Ge(t)}}function si(e){if(typeof e!=="string"||!e.startsWith("@uibot/")||!We.test(e.slice(7)))throw Error(`snapshot-external-registry-dependency: ${e}`);return e.slice(7)}function Pn(e,t){if(!We.test(e)||t.byteLength>16777216)throw Error("snapshot-invalid-item");let n=JSON.parse(ii.decode(t));if(n.name!==e||!Array.isArray(n.files)||n.files.length>2000||(n.devDependencies?.length??0)>0)throw Error(`snapshot-invalid-item: ${e}`);let o={};for(let i of n.dependencies??[]){let c=i.lastIndexOf("@"),l=i.slice(0,c),d=i.slice(c+1);if(c<1||!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(l)||!qe.test(d)||o[l]&&o[l]!==d)throw Error(`snapshot-unpinned-npm-dependency: ${i}`);o[l]=d}let r=[...new Set((n.registryDependencies??[]).map(si))].sort(),a=new Set,s=n.files.map((i)=>{if(typeof i.content!=="string")throw Error(`snapshot-missing-file-content: ${e}`);let c=i.target??i.path;if(Ke(c),a.has(c))throw Error(`snapshot-duplicate-target: ${c}`);return a.add(c),{...St(i.path,Rn.encode(i.content)),target:c}});return{...St(`r/${e}.json`,t),registryDependencies:r,npmDependencies:o,files:s}}function An(e,t){let n=new Set,o=new Set,r=(i)=>{if(!We.test(i)||!Object.hasOwn(e,i))throw Error(`snapshot-missing-item: ${i}`);if(o.has(i))throw Error(`snapshot-dependency-cycle: ${i}`);if(n.has(i))return;o.add(i);for(let c of e[i].registryDependencies)r(c);o.delete(i),n.add(i)};if(!t.length)throw Error("snapshot-empty-entrypoints");t.forEach(r);let a=new Map,s=new Map;for(let i of n){for(let c of e[i].files){let l=a.get(c.target);if(l&&l!==c.sha256)throw Error(`snapshot-target-conflict: ${c.target}`);a.set(c.target,c.sha256)}for(let[c,l]of Object.entries(e[i].npmDependencies)){if(s.has(c)&&s.get(c)!==l)throw Error(`snapshot-npm-conflict: ${c}`);s.set(c,l)}}return[...n].sort()}function Ll(e){let t=Object.fromEntries(Object.entries(e.items).map(([a,s])=>[a,Pn(a,s)])),n=Object.fromEntries(Object.entries(e.resources).map(([a,s])=>[a,{...s,closure:An(t,s.entrypoints)}])),o={schemaVersion:"uibot.distribution.snapshot.v1",bundleHash:e.bundleHash,version:e.version,namespace:"@uibot",resources:n,items:t,license:"MIT AND ISC",licenseFiles:Object.entries(e.licenseFiles).sort(([a],[s])=>a.localeCompare(s)).map(([a,s])=>St(a,s))},r={...o,snapshotId:Ge(se(o))};return En(r),r}function En(e,t){if(!e||typeof e!=="object")throw Error("snapshot-invalid-manifest");se(e);let n=e,{snapshotId:o,...r}=n;if(n.schemaVersion!=="uibot.distribution.snapshot.v1"||n.namespace!=="@uibot"||n.license!=="MIT AND ISC"||!qe.test(n.version)||!He.test(n.bundleHash)||!He.test(o)||t!==void 0&&t!==o||Ge(se(r))!==o)throw Error("snapshot-identity-mismatch");if(!n.items||!n.resources||!Array.isArray(n.licenseFiles)||!n.licenseFiles.length)throw Error("snapshot-invalid-manifest");let a=(i)=>{if(Ke(i.path),!He.test(i.sha256)||!Number.isSafeInteger(i.bytes)||i.bytes<0||i.bytes>16777216)throw Error("snapshot-invalid-file-digest")},s=new Set;for(let i of n.licenseFiles){if(a(i),!i.path.startsWith("licenses/")||s.has(i.path))throw Error("snapshot-invalid-license");s.add(i.path)}for(let[i,c]of Object.entries(n.items)){if(a(c),!We.test(i)||c.path!==`r/${i}.json`||!Array.isArray(c.registryDependencies)||!Array.isArray(c.files)||!c.npmDependencies)throw Error("snapshot-invalid-item");for(let l of c.files)a(l),Ke(l.target);for(let[l,d]of Object.entries(c.npmDependencies))if(!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(l)||!qe.test(d))throw Error("snapshot-unpinned-npm-dependency")}for(let i of Object.values(n.resources))if(!qe.test(i.version)||!He.test(i.resourceHash)||!Array.isArray(i.entrypoints)||se(An(n.items,i.entrypoints))!==se(i.closure))throw Error("snapshot-resource-closure-mismatch")}function jl(e,t,n,o){En(e,o);let r=Object.hasOwn(e.resources,t)?e.resources[t]:void 0;if(!r)throw Error(`snapshot-resource-unavailable: ${t}`);let a=(i)=>{let c=n.get(i.path);if(!c||c.byteLength!==i.bytes||Ge(c)!==i.sha256)throw Error(`snapshot-file-mismatch: ${i.path}`);return c},s={};for(let i of r.closure){let c=e.items[i],l=Pn(i,a(c));if(se(l)!==se(c))throw Error(`snapshot-item-metadata-mismatch: ${i}`);Object.assign(s,c.npmDependencies)}return e.licenseFiles.forEach(a),{snapshotId:e.snapshotId,resourceId:t,closure:[...r.closure],npmDependencies:s}}function ui(e){if(!e.name)throw Error("Artifact registry manifest requires a name");return e}function gi(e){if(!e.name)throw Error("Plugin distribution manifest requires a name");return e}class fi{id;priority;items;constructor(e,t,n){this.id=e;this.priority=t;this.items=n}get(e){return this.items[e]}}class mi{id;priority;items;constructor(e,t,n){this.id=e;this.priority=t;this.items=n}get(e){return this.items[e]}}async function Nn(e,t){let n=await fetch(e,t?{headers:t}:{});if(!n.ok)throw Error(`Failed to fetch ${e}: ${n.status} ${n.statusText}`);return await n.json()}async function hi(e,t){let n=e.endsWith("/registry.json")?e:`${e.replace(/\/$/,"")}/registry.json`,o=await Nn(n,t);return ui(o)}async function yi(e,t){let n=e.endsWith("/plugins.json")?e:`${e.replace(/\/$/,"")}/plugins.json`,o=await Nn(n,t);return gi(o)}class bi{options;id;priority;manifestPromise;constructor(e){this.options=e;this.id=e.id??e.registryUrl,this.priority=e.priority}getManifest(){return this.manifestPromise??=hi(this.options.registryUrl,this.options.headers),this.manifestPromise}async get(e){return(await this.getManifest()).items.find((n)=>n.name===e)}}class ki{options;id;priority;manifestPromise;constructor(e){this.options=e;this.id=e.id??e.registryUrl,this.priority=e.priority}getManifest(){return this.manifestPromise??=yi(this.options.registryUrl,this.options.headers),this.manifestPromise}async get(e){return(await this.getManifest()).plugins.find((n)=>n.pluginId===e)}}class xi{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((n,o)=>n.priority-o.priority);for(let n of t){let o=await n.get(e);if(o)return o}return}}class vi{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((n,o)=>n.priority-o.priority);for(let n of t){let o=await n.get(e);if(o)return o}return}}var Ci="uibot.artifacts.lock.json";function wi(e){return W(e,"components","registry")}function Si(e){return W(e,"templates","registry")}function Ii(e,t){if(e.kind==="component")return W(t.componentsDir??wi(t.workspaceRoot));return W(t.templatesDir??Si(t.workspaceRoot))}function Ri(e){return W(e.workspaceRoot,e.lockfilePath??Ci)}function Pi(e){try{return JSON.parse(ci(e,"utf8"))}catch{return{version:1,artifacts:[]}}}function Ai(e,t){On(It(e),{recursive:!0}),Bn(e,`${JSON.stringify(t,null,2)}
|
|
2120
|
+
`,"utf8")}function Ei(e,t){return{version:1,artifacts:[...e.artifacts.filter((o)=>o.name!==t.name),t].sort((o,r)=>o.name.localeCompare(r.name))}}function Ti(e){if(e.kind==="component")return{components:{[e.name]:e.catalogEntry}};return{templates:{[e.name]:e.templateContract}}}class ae extends Error{artifactName;offendingPath;baseDir;constructor(e,t,n){super(`Artifact "${e}" file path escapes workspace: "${t}" resolves outside "${n}"`);this.artifactName=e;this.offendingPath=t;this.baseDir=n;this.name="ArtifactContainmentError"}}function $n(e,t){let n=t.endsWith(Tn)?t:t+Tn;return e===t||e.startsWith(n)}function Dn(e){let t=W(e),n=[];while(!0)try{return ai(t),W(li(t),...n)}catch(o){if(o.code!=="ENOENT")throw o;let r=It(t);if(r===t)throw o;n.unshift(di(t)),t=r}}function Mn(e,t,n,o){try{let r=Dn(t),a=Dn(e);if(!$n(a,r))throw new ae(n,o,t)}catch(r){if(r instanceof ae)throw r;throw new ae(n,o,t)}}function _n(e,t,n){if(e.includes("\x00"))throw new ae(n,e,t);if(pi(e))throw new ae(n,e,t);let o=W(t,e);if(!$n(o,t))throw new ae(n,e,t);return Mn(o,t,n,e),o}function Di(e,t){let n=[];for(let o of e.files){let r=o.target??o.path;n.push(_n(r,t,e.name))}return n}function zl(e,t){let n=W(t.workspaceRoot),o=Ii(e,t);Mn(o,n,e.name,o);let r=_n(e.name,o,e.name),a=Di(e,r),s=[];for(let u=0;u<e.files.length;u++){let g=e.files[u],p=a[u];On(It(p),{recursive:!0}),Bn(p,g.content??"","utf8"),s.push(p)}let i={name:e.name,version:e.version,source:t.source??"registry",installedAt:new Date().toISOString()},c=Ri(t),l=Pi(c),d=Ei(l,i);return Ai(c,d),{artifactLock:i,catalogPatch:Ti(e),writtenFiles:s}}export{ae as ArtifactContainmentError,xi as ArtifactRegistryResolver,fi as MemoryArtifactRegistrySource,mi as MemoryPluginRegistrySource,vi as PluginRegistryResolver,Lc as RESOURCE_ADMISSION_ERROR_CODES,it as RESOURCE_ADMISSION_SCHEMA_VERSION,Lr as RESOURCE_EXTERNAL_CHECKS,qc as RESOURCE_INDEX_ERROR_CODES,eo as RESOURCE_INDEX_SCHEMA_VERSION,_r as RESOURCE_PREFLIGHT_CHECKS,lo as RESOURCE_QUERY_ALIAS_GROUPS,Xc as RESOURCE_QUERY_ERROR_CODES,dr as RESOURCE_QUERY_OPERATION_MANIFEST,dt as RESOURCE_QUERY_SCORE_WEIGHTS,bi as RemoteArtifactRegistrySource,ki as RemotePluginRegistrySource,Gt as ResourceAdmissionIndexMismatchError,Jt as ResourceAdmissionReportNotDerivedError,Yt as ResourceAdmissionReportRejectedError,pe as ResourceIndexError,V as ResourceQueryError,Bc as SHADCN_REGISTRY_ITEM_SCHEMA,rt as UIBOT_BASE_ITEM,Wo as UIBOT_MATERIALIZE_MANIFEST_CONTRACT,Ut as UIBOT_THEME_ITEM,Uc as applyResourceAdmissionReport,Il as applySpecPatch,Ke as assertDistributionPath,En as assertDistributionSnapshot,_n as assertPathContained,mo as assertPublicResourceBundle,Vc as assessResourceAdmissions,Kc as buildExamplesFromL4Templates,Wc as buildResourceIndex,Oc as buildShadcnRegistry,Vi as buildUiBotRegistryManifest,Ar as catalogEntryToMeta,$i as collectAllBlockSources,Wn as collectBlockSources,At as collectTemplateSources,er as collectTemplateSourcesFromDirs,Ln as compareLockToManifest,Tl as composeSpecFromBlueprint,Ll as createDistributionSnapshot,ol as createPublicResourceQueryService,ln as createResourceQueryService,$c as createUIBotRegistryHttpHandler,xl as createVariantRegistry,vl as deriveComponentVariantFamilies,jc as deriveResourceLicense,Pn as describeDistributionItem,se as distributionCanonicalJson,An as distributionClosure,Ge as distributionSha256,Ui as emitArtifactJson,Fn as emptyLockfile,Fc as evaluateCatalogPreflight,at as expandResourceQueryAliases,hi as fetchArtifactRegistryManifest,yi as fetchPluginDistributionManifest,zl as installArtifactToWorkspace,je as listVariantFamilies,Vn as lockfileWith,$l as materializeSpec,Mr as normalizeRegistryBasePath,O as normalizeResourceAlias,ne as normalizeResourceLicense,Dc as parseOklchCssVars,gi as parsePluginDistributionManifest,ui as parseRegistryManifest,ml as replaceSolutionPageFrames,ht as replaceSolutionPageFramesWithWarnings,en as resourceAdmissionIndexFingerprint,fe as sha256Hex,si as snapshotDependencyName,j as summarizeVariantValue,ie as swapVariant,Je as templateSourceToRegistryItem,Tt as toArtifactRegistryItem,sr as toComponentArtifact,ot as toItemName,K as toResourceId,Et as toTemplateArtifact,zt as transformBlockSource,jl as verifyDistributionSnapshot};
|