@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.
Files changed (70) hide show
  1. package/dist/component-replacement.d.ts +10 -0
  2. package/dist/index.d.ts +5 -0
  3. package/dist/index.js +2117 -12
  4. package/dist/materialize-templates.d.ts +28 -0
  5. package/dist/materialize.d.ts +63 -0
  6. package/dist/resources.d.ts +5 -0
  7. package/dist/resources.js +2108 -3
  8. package/dist/shadcn/r/admin-apps.json +1 -1
  9. package/dist/shadcn/r/admin-chats.json +1 -1
  10. package/dist/shadcn/r/admin-settings-account.json +1 -1
  11. package/dist/shadcn/r/admin-settings-appearance.json +1 -1
  12. package/dist/shadcn/r/admin-settings-display.json +1 -1
  13. package/dist/shadcn/r/admin-settings-notifications.json +1 -1
  14. package/dist/shadcn/r/admin-settings-profile.json +1 -1
  15. package/dist/shadcn/r/admin-settings.json +1 -1
  16. package/dist/shadcn/r/admin-shell.json +16 -3
  17. package/dist/shadcn/r/admin-tasks.json +1 -1
  18. package/dist/shadcn/r/admin-users.json +1 -1
  19. package/dist/shadcn/r/agent-run-console.json +64 -0
  20. package/dist/shadcn/r/auth-minimal.json +59 -0
  21. package/dist/shadcn/r/billing-overview.json +66 -0
  22. package/dist/shadcn/r/billing-usage-ledger.json +66 -0
  23. package/dist/shadcn/r/charts.json +44 -17
  24. package/dist/shadcn/r/chat-workspace.json +1 -1
  25. package/dist/shadcn/r/collection-cell-editor.json +1 -1
  26. package/dist/shadcn/r/collection-kanban.json +134 -0
  27. package/dist/shadcn/r/collection-panel-drawer.json +1 -1
  28. package/dist/shadcn/r/collection-record-menu.json +1 -1
  29. package/dist/shadcn/r/collection-shared.json +1 -1
  30. package/dist/shadcn/r/commerce-workspace.json +1 -1
  31. package/dist/shadcn/r/console-billing.json +1 -1
  32. package/dist/shadcn/r/console-page.json +14 -14
  33. package/dist/shadcn/r/console-shell.json +2 -2
  34. package/dist/shadcn/r/creation-html-generation.json +2 -2
  35. package/dist/shadcn/r/creation-reference-generation.json +2 -2
  36. package/dist/shadcn/r/creation-revision-export.json +2 -2
  37. package/dist/shadcn/r/creation-shared.json +2 -2
  38. package/dist/shadcn/r/creation-variant-compare.json +3 -3
  39. package/dist/shadcn/r/creation-workspace.json +3 -3
  40. package/dist/shadcn/r/crm-workspace.json +1 -1
  41. package/dist/shadcn/r/dashboard-01.json +78 -0
  42. package/dist/shadcn/r/dashboard.json +113 -3
  43. package/dist/shadcn/r/data-crud-gallery.json +66 -0
  44. package/dist/shadcn/r/data-crud-kanban.json +66 -0
  45. package/dist/shadcn/r/data-crud-master-detail.json +66 -0
  46. package/dist/shadcn/r/data-crud-table.json +66 -0
  47. package/dist/shadcn/r/data-table.json +120 -10
  48. package/dist/shadcn/r/data.json +9 -2
  49. package/dist/shadcn/r/document-assistant.json +1 -1
  50. package/dist/shadcn/r/document-workspace.json +1 -1
  51. package/dist/shadcn/r/drilldown-menu.json +1 -1
  52. package/dist/shadcn/r/education-workspace.json +1 -1
  53. package/dist/shadcn/r/feedback.json +15 -2
  54. package/dist/shadcn/r/form.json +1 -1
  55. package/dist/shadcn/r/launch-site.json +72 -0
  56. package/dist/shadcn/r/layout.json +57 -22
  57. package/dist/shadcn/r/nav.json +38 -10
  58. package/dist/shadcn/r/onboarding-checklist.json +63 -0
  59. package/dist/shadcn/r/onboarding-wizard.json +66 -0
  60. package/dist/shadcn/r/prompt-eval-workbench.json +65 -0
  61. package/dist/shadcn/r/record-master-detail.json +132 -0
  62. package/dist/shadcn/r/shadcn-admin.json +1 -1
  63. package/dist/shadcn/r/sidebar-primitives.json +1 -1
  64. package/dist/shadcn/r/workspace.json +9 -2
  65. package/dist/shadcn/registry.json +229 -27
  66. package/dist/solution-regions.d.ts +12 -2
  67. package/dist/spec-blueprint.d.ts +11 -0
  68. package/dist/spec-patch.d.ts +10 -0
  69. package/dist/variant-swap.d.ts +22 -0
  70. package/package.json +2 -2
package/dist/resources.js CHANGED
@@ -1,4 +1,2109 @@
1
1
  // @bun
2
- var Ee={spec:["html","markdown","zip"],prototype:["html","zip"],deck:["html","pptx","zip"],poster:["html","zip"]},dn=Array.from(new Set(Object.values(Ee).flat()));var se=["component","template","design-guide","example","skill","block","package","theme"],z=["experimental","candidate","recommended"],ae=["declared","verified","external-consumer"],q=["missing","declared","verified","external-consumer"],N=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure","packed-install","typecheck","browser"],De=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 mn="uibot.registry.item.v1";var Oe=["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"],yn=[...Oe,"radius","font-display","font-body","font-mono"];var S=(e)=>!!e&&typeof e==="object"&&!Array.isArray(e),C=(e)=>typeof e==="string"&&e.length>0&&!["__proto__","prototype","constructor"].includes(e),ce=(e)=>S(e)&&Object.entries(e).every(([t,o])=>C(t)&&C(o));function v(e){if(e.composition===void 0)return;let t=e.composition;if(!S(t)||t.schema!=="uibot.solution-composition.v1"||!Array.isArray(t.pages))throw Error("invalid-solution-composition");let o=new Set;for(let i of t.pages){if(!S(i)||!C(i.resourceId)||!C(i.version)||typeof i.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(i.sourceHash)||!C(i.sourcePageId)||!C(i.targetPageId)||o.has(i.targetPageId)||!S(i.baseline)||i.baseline.id!==i.targetPageId||typeof i.baseline.path!=="string"||!Array.isArray(i.baseline.blocks)||!S(i.bindings)||!["source","target"].includes(String(i.bindings.layout))||!ce(i.bindings.paths)||!ce(i.bindings.connections)||i.bindings.frame!==void 0&&(!S(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&&(!S(i.configuration)||Object.entries(i.configuration).some(([n,s])=>!C(n)||!["string","number","boolean"].includes(typeof s)||typeof s==="number"&&!Number.isFinite(s))))throw Error("invalid-solution-adoption");o.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(!S(n)||!C(n.resourceId)||!C(n.version)||typeof n.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(n.sourceHash)||!C(n.targetPageId)||i.has(n.targetPageId)||!C(n.role)||n.target!=="page-frame"||!C(n.contentBlockId)||!S(n.baseline)||!C(n.baseline.type))throw Error("invalid-solution-region");i.add(n.targetPageId)}}}var J="uibot.resource.admission.v1",Te=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure"],_e=["packed-install","typecheck","browser"],qr=["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 le 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 de 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 ue extends Error{code="resource-admission-report-not-derived";constructor(){super("resource admission report must come directly from assessResourceAdmissions");this.name="ResourceAdmissionReportNotDerivedError"}}var Fe=new Set(N),Ne=new Set(q),pe=new WeakSet,H={missing:0,declared:1,verified:2,"external-consumer":3};function Me(e,t){return e<t?-1:e>t?1:0}function O(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function K(e,t){let o=new Set(t);return Object.keys(e).every((i)=>o.has(i))}function ge(e){return[...new Set(e.map((t)=>t.trim()).filter(Boolean))].sort(Me)}function Le(e,t,o,i){if(!O(o)||!K(o,["status","evidence"])){i.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} must contain only status and evidence`});return}if(typeof o.status!=="string"||!Ne.has(o.status)||o.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(o.evidence)||o.evidence.length===0||o.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:o.status,evidence:ge(o.evidence)}}function Be(e){if(e===void 0)return;if(!O(e)||!K(e,["source","version","license"]))return;if(Object.values(e).some((o)=>o!==void 0&&typeof o!=="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 je(e,t){let o=new Map,i=[];if(!O(t)||!K(t,["schemaVersion","records"])||t.schemaVersion!==J||!Array.isArray(t.records))return i.push({code:"invalid-admission-manifest",detail:`expected ${J} with a records array`}),{records:o,issues:i};let n=new Set(e.resources.map((s)=>s.id));for(let s of t.records){if(!O(s)||!K(s,["resourceId","provenance","checks"])||typeof s.resourceId!=="string"||!s.resourceId.trim()||!O(s.checks)){i.push({code:"invalid-admission-record",...O(s)&&typeof s.resourceId==="string"?{resourceId:s.resourceId}:{},detail:"record must contain only resourceId, optional provenance and checks"});continue}let r=s.resourceId.trim();if(o.has(r)){i.push({code:"duplicate-admission-record",resourceId:r,detail:r});continue}if(!n.has(r)){i.push({code:"unknown-admission-resource",resourceId:r,detail:r});continue}let a=Be(s.provenance);if(s.provenance!==void 0&&!a){i.push({code:"invalid-admission-record",resourceId:r,detail:"provenance must contain only string source, version and license fields"});continue}let c={},u=!1;for(let[p,f]of Object.entries(s.checks)){if(!Fe.has(p)){i.push({code:"invalid-admission-check",resourceId:r,detail:`unknown receipt check: ${p}`}),u=!0;continue}let m=p,l=Le(r,m,f,i);if(l)c[m]=l;else u=!0}if(u)continue;o.set(r,{resourceId:r,...a?{provenance:a}:{},checks:c})}return{records:o,issues:i}}function Ve(e){let t=new Map(e.resources.map((n)=>[n.id,n])),o=new Map;function i(n,s,r,a){if(o.has(n)||a.has(s))return;if(r.has(s)){o.set(n,`dependency cycle reached ${s}`);return}let c=t.get(s);if(!c){o.set(n,`missing dependency ${s}`);return}r.add(s);for(let u of c.dependencies)if(i(n,u,r,a),o.has(n))break;r.delete(s),a.add(s)}for(let n of e.resources)i(n.id,n.id,new Set,new Set);return o}var Ue=/^(unknown|unlicensed|none|n\/?a)$/i,ze=/^SPDX-License-Identifier:\s*(\S+)/im,qe=/^(?:the\s+)?(mit|apache(?:\s+license(?:\s*,?\s*version\s*2\.0)?)?|bsd-2-clause|bsd-3-clause|isc|unlicense)\b/i;function E(e){let t=e?.trim();if(!t||Ue.test(t))return;return t}function $e(e){if(!e?.trim())return;let t=e.match(ze)?.[1];if(t)return E(t);let o=e.match(qe)?.[1];if(!o)return;let i=o.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 $r(e){return E(e.frontmatterLicense)??E(e.packageJsonLicense)??$e(e.licenseFileText)}function me(e){return Boolean(E(e))}var M={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 Z(e,t){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let i of e)Z(i,t);return}let o=e;for(let[i,n]of Object.entries(o)){if(t.push(i),i==="type"&&n==="boolean")t.push("boolean-state");Z(n,t)}}function He(e){let t=[];return Z(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(`
3
- `)}function Hr(e,t={}){let o=[He(e),t.sourceText??"",t.stylesText??""].join(`
4
- `);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:M.states.test(o)?"verified":"missing",accessibility:M.accessibility.test(o)?"verified":"missing","light-theme":M["light-theme"].test(o)?"verified":"missing","dark-theme":M["dark-theme"].test(o)?"verified":"missing",responsive:M.responsive.test(o)?"verified":"missing"}}function Ke(e){return{source:"declared",license:me(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 We(e){if(!Te.every((i)=>H[e[i]]>=H.verified))return"experimental";return _e.every((i)=>e[i]==="external-consumer")?"recommended":"candidate"}function fe(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}),o=0xcbf29ce484222325n,i=0x100000001b3n;for(let n of new TextEncoder().encode(t))o^=BigInt(n),o=BigInt.asUintN(64,o*i);return`fnv1a64:${o.toString(16).padStart(16,"0")}`}function Ge(e,t,o){let i=Ke(e),n=[`resource://${e.source.type}/${e.source.id}`,`resource://contract/${e.id}`],s=[];if(o)s.push({code:"dependency-closure-failed",resourceId:e.id,check:"dependency-closure",detail:o});else i["dependency-closure"]="verified",n.push(`resource://index/${e.id}`);if(t)for(let c of N){if(c==="dependency-closure")continue;let u=t.checks[c];if(!u)continue;if(c==="source"&&H[u.status]>=H.verified&&(!t.provenance?.source||!t.provenance.version)){s.push({code:"missing-source-metadata",resourceId:e.id,check:c,detail:"verified source requires provenance.source and provenance.version"});continue}if(c==="license"&&!me(t.provenance?.license)){s.push({code:"missing-license-metadata",resourceId:e.id,check:c,detail:"license evidence requires a concrete provenance.license"});continue}if(i[c]=u.status,n.push(...u.evidence),c==="source"&&t.provenance?.source)n.push(t.provenance.source)}let r=We(i),a={level:r==="recommended"?"external-consumer":r==="candidate"?"verified":"declared",maturity:r,checks:i,evidence:ge(n)};return Object.freeze(a.checks),Object.freeze(a.evidence),Object.freeze(a),Object.freeze(s),Object.freeze({resourceId:e.id,receipt:a,issues:s})}function Kr(e,t){let o=je(e,t),i=Ve(e),n=e.resources.map((c)=>Ge(c,o.records.get(c.id),i.get(c.id))),s=[...o.issues,...n.flatMap((c)=>c.issues)],r=Object.fromEntries(z.map((c)=>[c,0]));for(let c of n)r[c.receipt.maturity]+=1;Object.freeze(n),Object.freeze(r);for(let c of s)Object.freeze(c);Object.freeze(s);let a=Object.freeze({schemaVersion:J,indexFingerprint:fe(e),resources:n,counts:r,issues:s});return pe.add(a),a}function Wr(e,t){if(!pe.has(t))throw new ue;if(t.issues.length>0)throw new de(t.issues.length);let o=fe(e);if(o!==t.indexFingerprint)throw new le(t.indexFingerprint,o);let i=new Map(t.resources.map((s)=>[s.resourceId,s.receipt])),n=e.resources.map((s)=>{let r=i.get(s.id);if(!r)return s;return Object.freeze({...s,receipt:r})});return Object.freeze(n),Object.freeze({schemaVersion:e.schemaVersion,resources:n,aliases:e.aliases})}var Ye="uibot.resource.index.v1",Qr=["invalid-resource-source-id","duplicate-resource-id","dangling-resource-dependency","ambiguous-resource-dependency"];class _ extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceIndexError"}}function x(e,t){return e<t?-1:e>t?1:0}function h(e){return e.normalize("NFKC").replace(/([\p{Lu}]+)([\p{Lu}][\p{Ll}])/gu,"$1 $2").replace(/([\p{Ll}\p{N}])([\p{Lu}])/gu,"$1 $2").toLowerCase().replace(/[^\p{L}\p{N}]+/gu," ").trim().replace(/\s+/g," ")}function Qe(e){let t=h(e).replace(/ /g,"-");if(!t)throw new _("invalid-resource-source-id",e);return t}function P(e,t){return`${e}:${Qe(t)}`}function W(e){let t=new Map;for(let o of e){let i=o?.trim();if(!i)continue;let n=h(i);if(!n||t.has(n))continue;t.set(n,i)}return[...t.entries()].sort(([o],[i])=>x(o,i)).map(([,o])=>o)}function L(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 Je(e){let t=E(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 T(e){return{id:e.id,kind:e.kind,title:e.title,description:e.description,...e.category?{category:e.category}:{},tags:W(e.tags),aliases:W(e.aliases),capabilities:W(e.capabilities),dependencies:[...new Set(e.dependencies)].sort(x),source:Je(e.source),receipt:e.receipt,...e.solution?{solution:structuredClone(e.solution)}:{}}}function Ze(e){return(e.body.split(/\r?\n/).map((o)=>o.replace(/^#+\s*/,"").trim()).find(Boolean)??e.title).slice(0,240)}function Xe(e){if(e.solution){let t=(o)=>{if(o&&typeof o==="object"){for(let i of Object.values(o))t(i);Object.freeze(o)}};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 et(e){let t=new Map;for(let o of Object.keys(e).sort(x)){let i=e[o];if(!i)continue;let n=P("component",o);for(let s of W([o,i.name])){let r=h(s),a=t.get(r)??[];if(!a.includes(n))a.push(n);t.set(r,a.sort(x))}}return t}function tt(e,t,o){let i=o.get(h(e))??[];if(i.length===0)throw new _("dangling-resource-dependency",`${t} -> ${P("component",e)}`);if(i.length>1)throw new _("ambiguous-resource-dependency",`${t} -> ${e}: ${i.join(",")}`);return i[0]}function nt(e,t,o,i){let n=e.startsWith("template:")?e.slice(9):e;if(Object.hasOwn(i,n))return P("template",n);return tt(e,t,o)}function B(e,t,o){return E(o?.[e]??t)}function Jr(e){return Object.entries(e).filter(([,t])=>t.level==="L4").sort(([t],[o])=>x(t,o)).map(([t,o])=>({id:`${t}-example`,title:`${o.name} Example`,description:o.description,category:o.category,tags:o.keywords,aliases:[`${t} example`,`${o.name} example`],capabilities:["example:template"],dependencies:[P("template",t)]}))}function Zr(e){let t=e.components??{},o=e.templates??{},i=e.designGuides??[],n=e.examples??[],s=e.skills??[],r=e.licenses,a=et(t),c=[];for(let l of Object.keys(t).sort(x)){let d=t[l];if(!d)continue;let g=P("component",l),y=B(g,void 0,r);c.push(T({id:g,kind:"component",title:d.name,description:d.description,category:d.category,tags:d.tags??[],aliases:[l,d.name],capabilities:["catalog:component"],dependencies:[],source:{type:"catalog",id:l,...y?{license:y}:{}},receipt:L(Boolean(y))}))}for(let l of Object.keys(o).sort(x)){let d=o[l];if(!d)continue;let g=P("template",l),y=B(g,void 0,r);c.push(T({id:g,kind:"template",title:d.name,description:d.description,category:d.category,tags:d.keywords,aliases:[l,d.name],capabilities:[],dependencies:(d.composedFrom??[]).map((b)=>nt(b,g,a,o)),source:{type:"template-contract",id:l,...y?{license:y}:{}},receipt:L(Boolean(y))}))}for(let l of[...i].sort((d,g)=>x(d.id,g.id))){let d=P("design-guide",l.id),g=B(d,void 0,r);c.push(T({id:d,kind:"design-guide",title:l.title,description:Ze(l),category:l.category,tags:l.tags,aliases:[l.id,l.title],capabilities:["designMd:source"],dependencies:[],source:{type:"design-md",id:l.id,...l.sourceUrl?{url:l.sourceUrl}:{},...g?{license:g}:{}},receipt:L(Boolean(g))}))}for(let l of[...n].sort((d,g)=>x(d.id,g.id))){let d=P("example",l.id),g=B(d,l.license,r);c.push(T({id:d,kind:"example",title:l.title,description:l.description,...l.category?{category:l.category}:{},tags:l.tags??[],aliases:[l.id,l.title,...l.aliases??[]],capabilities:l.capabilities??[],dependencies:l.dependencies??[],source:{type:"example",id:l.id,...l.version?{version:l.version}:{},...l.sourceUrl?{url:l.sourceUrl}:{},...g?{license:g}:{}},receipt:L(Boolean(g))}))}for(let l of[...s].sort((d,g)=>x(d.id,g.id))){let d=P("skill",l.id),g=B(d,void 0,r);c.push(T({id:d,kind:"skill",title:l.title,description:l.description?.trim()||l.title,tags:[...l.tags??[],...l.triggers??[]],aliases:[l.id,l.title,...l.triggers??[]],capabilities:["skill:definition"],dependencies:[],source:{type:"skill",id:l.id,...l.version?{version:l.version}:{},...g?{license:g}:{}},receipt:L(Boolean(g))}))}for(let l of e.additional??[])c.push(T(l));c.sort((l,d)=>x(l.id,d.id));let u=new Set;for(let l of c){if(u.has(l.id))throw new _("duplicate-resource-id",l.id);u.add(l.id)}for(let l of c)for(let d of l.dependencies)if(!u.has(d))throw new _("dangling-resource-dependency",`${l.id} -> ${d}`);let p=new Map;for(let l of c)for(let d of l.aliases){let g=h(d);if(!g)continue;let y=p.get(g)??new Set;y.add(l.id),p.set(g,y)}let f=Object.freeze(Object.fromEntries([...p.entries()].sort(([l],[d])=>x(l,d)).map(([l,d])=>[l,Object.freeze([...d].sort(x))]))),m=Object.freeze(c.map(Xe));return Object.freeze({schemaVersion:Ye,resources:m,aliases:f})}var rt=[["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"]],ot=Object.freeze(rt.map((e)=>Object.freeze([...e]))),ye=new Map;for(let e of ot){let t=Object.freeze([...new Set(e.map(h).filter(Boolean))].sort());for(let o of t)ye.set(o,t)}function X(e){let t=h(e);return ye.get(t)??Object.freeze([t])}var oo=["resource-query-empty","resource-query-invalid-limit","resource-not-found","resource-alias-ambiguous"];class k extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceQueryError"}}var ne=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}),it=Object.freeze(Object.keys(ne)),he=new Map(it.map((e,t)=>[e,t])),be=new Map([["component",0],["template",1],["design-guide",2],["example",3],["skill",4]]);function R(e,t){return e<t?-1:e>t?1:0}function Ce(e){return new Set((e??[]).map(h).filter(Boolean))}function D(e,t){let o=Ce(t);if(o.size===0)return!0;let i=Ce(e);return[...o].some((n)=>i.has(n))}function st(e,t){if(!D(e.solution?.functions??[],t.functions))return!1;if(!D(e.solution?.scenarios??[],t.scenarios))return!1;if(!D(e.solution?[e.solution.unit]:[],t.units))return!1;if(!D(e.solution?.industries??[],t.industries))return!1;if(t.kinds?.length&&!t.kinds.includes(e.kind))return!1;if(!D(e.tags,t.tags))return!1;if(!D(e.category?[e.category]:[],t.categories))return!1;if(!D(e.capabilities,t.capabilities))return!1;if(t.maturities?.length&&!t.maturities.includes(e.receipt.maturity))return!1;return!0}function at(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 I(e,t,o,i=ne[t]){if(e.some((n)=>n.code===t&&n.value===o))return;e.push({code:t,value:o,score:i})}function ee(e,t){return e.find((o)=>h(o)===t)}function te(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 ct(e,t,o){if(Math.abs(e.length-t.length)>o)return o+1;let i=Array.from({length:t.length+1},(n,s)=>s);for(let n=1;n<=e.length;n+=1){let s=[n],r=n;for(let a=1;a<=t.length;a+=1){let c=(i[a-1]??o+1)+(e[n-1]===t[a-1]?0:1),u=Math.min((i[a]??o+1)+1,(s[a-1]??o+1)+1,c);s.push(u),r=Math.min(r,u)}if(r>o)return o+1;i=s}return i[t.length]??o+1}function xe(e,t){let o=h(t),i=[];if(h(e.id)===o)I(i,"exact-id",e.id);if(h(e.title)===o)I(i,"exact-title",e.title);let n=ee(e.aliases,o);if(n)I(i,"alias",n);let s=ee(e.tags,o);if(s)I(i,"tag",s);let r=ee(e.capabilities,o);if(r)I(i,"capability",r);if(e.category&&h(e.category)===o)I(i,"category",e.category);if(!n){let u=X(o).filter((f)=>f!==o),p=new Set(te(e).map(h));if(u.some((f)=>p.has(f)))I(i,"alias",t.trim())}let a=o.split(" ").filter(Boolean),c=h(te(e).join(" "));if(a.length>0&&a.every((u)=>c.includes(u)))I(i,"token",t.trim());if(i.length===0&&o.length>=4){let u;for(let p of te(e)){let f=h(p);if(f.length<4)continue;let m=ct(o,f,2);if(m<=2&&(!u||m<u.distance||m===u.distance&&R(p,u.value)<0))u={value:p,distance:m}}if(u)I(i,"fuzzy",u.value,ne.fuzzy-u.distance)}return i.sort((u,p)=>{if(u.score!==p.score)return p.score-u.score;return(he.get(u.code)??99)-(he.get(p.code)??99)||R(u.value,p.value)})}function Re(e,t,o){if(t.has(o))return[o];let i=h(o),n=e.aliases[i];if(n?.length)return[...n];let s=new Set;for(let r of X(i))for(let a of e.aliases[r]??[])s.add(a);return[...s].sort(R)}function ke(e,t){return new k("resource-alias-ambiguous",`${e.trim()}: ${t.join(",")}`)}function Ie(e){let t=new Map(e.resources.map((i)=>[i.id,i]));function o(i){let n=i.trim(),s=Re(e,t,n);if(s.length===0)throw new k("resource-not-found",n);if(s.length>1)throw ke(n,s);let r=s[0],a=r?t.get(r):void 0;if(!a)throw new k("resource-not-found",n);return a}return Object.freeze({manifest:()=>e,search(i){let n=i.text?.trim()??"";if(!n&&!at(i))throw new k("resource-query-empty","text or filter is required");if(i.limit!==void 0&&(!Number.isInteger(i.limit)||i.limit<=0))throw new k("resource-query-invalid-limit",String(i.limit));let s=e.resources.filter((r)=>st(r,i)).filter((r)=>!n||xe(r,n).length>0).map((r)=>{let a=n?xe(r,n):[];for(let[c,u]of[[i.functions,"function"],[i.scenarios,"scenario"],[i.units,"unit"],[i.industries,"industry"]])if(c?.length)I(a,u,c.join(","));return{resource:r,score:a.reduce((c,u)=>c+u.score,0),reasons:a}}).filter((r)=>!n||r.reasons.length>0).sort((r,a)=>a.score-r.score||R(r.resource.id,a.resource.id));return i.limit===void 0?s:s.slice(0,i.limit)},get:o,build(i){if(i.length===0||i.every((m)=>!m.trim()))throw new k("resource-query-empty","at least one build root is required");let n=[],s=new Set;for(let m of i){let l=m.trim(),d=Re(e,t,l);if(d.length===0)n.push({id:l,reason:"missing-resource"});else if(d.length>1)throw ke(l,d);else{let g=d[0];if(g)s.add(g)}}let r=new Set,a=new Set,c=new Set,u=[],p=[],f=(m,l)=>{if(r.has(m))return;if(a.has(m)){n.push({id:m,...l?{requiredBy:l}:{},reason:"dependency-cycle"});return}let d=t.get(m);if(!d){n.push({id:m,...l?{requiredBy:l}:{},reason:"missing-resource"});return}a.add(m),c.add(m);let g=[...d.dependencies].sort((y,b)=>{let F=t.get(y),we=t.get(b);return(be.get(F?.kind??"")??99)-(be.get(we?.kind??"")??99)||R(y,b)});for(let y of g)p.push({from:m,to:y,relation:"depends-on"}),f(y,m);a.delete(m),r.add(m),u.push(m)};for(let m of[...s].sort(R))f(m);return{roots:[...s].sort(R),nodes:[...c].sort(R).map((m)=>{let l=t.get(m);if(!l)throw new k("resource-not-found",m);return{id:m,kind:l.kind,maturity:l.receipt.maturity}}),edges:p.sort((m,l)=>R(m.from,l.from)||R(m.to,l.to)),order:u,gaps:n.sort((m,l)=>R(m.id,l.id)||R(m.requiredBy??"",l.requiredBy??"")||R(m.reason,l.reason))}}})}function lt(e){if(!e||typeof e!=="object")throw Error("invalid-public-resource-bundle");gt(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 o=new Set,i=new Set;for(let n of t.index.resources){if(!n||typeof n.id!=="string"||o.has(n.id)||!se.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((r)=>r.every((a)=>typeof a==="string"&&a.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/"))||!z.includes(n.receipt.maturity)||!ae.includes(n.receipt.level)||!Array.isArray(n.receipt.evidence)||!n.receipt.evidence.every((r)=>typeof r==="string")||!N.every((r)=>q.includes(n.receipt.checks?.[r])))throw Error("invalid-public-resource");if(o.add(n.id),n.solution){let r=n.solution;if(![r.functions,r.scenarios,r.industries,r.hostRequirements,r.limitations].every((a)=>Array.isArray(a)&&a.every((c)=>typeof c==="string"&&c.length>0&&c.length<=2000))||!["page","flow","industry"].includes(r.unit)||!["interactive-demo","needs-enhancement"].includes(r.readiness)||r.members!==void 0&&(!Array.isArray(r.members)||r.members.some((a)=>typeof a.resourceId!=="string"||typeof a.version!=="string"||!a.version||a.sourceHash!==void 0&&(typeof a.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(a.sourceHash)))))throw Error("invalid-resource-solution")}let s=t.showcases[n.id];if(!s||s.resourceId!==n.id||typeof s.docs?.zh!=="string"||typeof s.docs?.en!=="string"||!Array.isArray(s.examples)||!Array.isArray(s.distributions))throw Error("invalid-resource-showcase");if(s.collection!==void 0){let r=s.collection;if(!r||typeof r.id!=="string"||!/^[a-z0-9-]+$/.test(r.id)||typeof r.group?.id!=="string"||!/^[a-z0-9-]+$/.test(r.group.id)||[r.title,r.group.title].some((a)=>!a||[a.zh,a.en].some((c)=>typeof c!=="string"||!c.trim()||c.length>200)))throw Error("invalid-resource-collection")}if(s.agentKit!==void 0){let r=s.agentKit;if(i.has(n.source?.id))throw Error("invalid-resource-agent-kit");if(i.add(n.source?.id),!r||!["skill","prompt","recipe"].includes(r.type)||(r.type==="skill"?n.kind!=="skill":n.kind!=="example")||!/^[a-z][a-z0-9-]*$/.test(n.source.id)||r.fileName!=={skill:"SKILL.md",prompt:"PROMPT.md",recipe:"RECIPE.md"}[r.type]||[r.summary?.zh,r.summary?.en].some((a)=>typeof a!=="string"||!a.trim())||!Array.isArray(r.resources)||new Set(r.resources.map((a)=>a?.id)).size!==r.resources.length||r.resources.some((a)=>!a||!n.dependencies.includes(a.id)||!t.index.resources.some((c)=>c.id===a.id&&(c.source.version??null)===a.version)||a.version!==null&&(typeof a.version!=="string"||!a.version)||typeof a.contentHash!=="string"||!/^[a-f0-9]{64}$/.test(a.contentHash)||a.sourceHash!==void 0&&(typeof a.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(a.sourceHash)))||r.resources.length!==n.dependencies.length)throw Error("invalid-resource-agent-kit")}if(s.solutionControls!==void 0){let r=new Set;if(!Array.isArray(s.solutionControls)||s.solutionControls.some((a)=>{if(!a||typeof a.id!=="string"||r.has(a.id)||typeof a.label?.zh!=="string"||typeof a.label?.en!=="string"||!Array.isArray(a.values)||!a.values.length||a.values.some((c)=>!["string","boolean","number"].includes(typeof c)||typeof c==="number"&&!Number.isFinite(c))||typeof a.target?.pageId!=="string"||typeof a.target?.property!=="string"||["__proto__","prototype","constructor"].includes(a.target.property)||a.target.blockId!==void 0&&typeof a.target.blockId!=="string")return!0;return r.add(a.id),!1}))throw Error("invalid-solution-controls")}if(s.templateContract&&(s.templateContract.name!==n.source.id||typeof s.templateContract.description!=="string"||!["L3","L4","L5"].includes(s.templateContract.level)||!["feature","template","page","app"].includes(s.templateContract.category)||!Array.isArray(s.templateContract.keywords)))throw Error("invalid-public-template-contract");if(typeof s.title?.zh!=="string"||typeof s.title?.en!=="string"||s.examples.some((r)=>!r||typeof r.id!=="string"||typeof r.title!=="string"||typeof r.code!=="string"||!["spec","tsx","source"].includes(r.mode)||!["tsx","json","yaml","css","ts"].includes(r.language)||!Array.isArray(r.dependencies)||!r.dependencies.every((a)=>typeof a==="string"))||s.distributions.some((r)=>!r||!["spec","npm","shadcn"].includes(r.channel)||typeof r.name!=="string"||!/^[@a-zA-Z0-9._/-]+$/.test(r.name)||typeof r.version!=="string"||!["source","published"].includes(r.availability)))throw Error("invalid-resource-content")}for(let[n,s]of Object.entries(t.index.aliases))if(!n||!Array.isArray(s)||s.some((r)=>!o.has(r)))throw Error("invalid-public-resource-alias");if(Object.keys(t.showcases).some((n)=>!o.has(n)))throw Error("unexpected-public-resource-showcase");for(let n of t.index.resources)for(let s of n.dependencies)if(!o.has(s))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(([s,r])=>!Object.hasOwn(n.unavailable,s)||!Array.isArray(r)||r.some((a)=>typeof a!=="string"||a.startsWith("@uibot/"))))throw Error("invalid-distribution-snapshot-reference");for(let[s,r]of Object.entries(n.resources))if(!o.has(s)||r.version!==(t.index.resources.find((a)=>a.id===s)?.source.version??t.release.version)||!/^[a-f0-9]{64}$/.test(r.resourceHash)||!Array.isArray(r.entrypoints)||!r.entrypoints.length||!Array.isArray(r.closure)||![...r.entrypoints,...r.closure].every((a)=>/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(a))||r.entrypoints.some((a)=>!r.closure.includes(a)))throw Error("invalid-distribution-snapshot-resource")}}function lo(e){lt(e),e=JSON.parse(JSON.stringify(e));let t=(n)=>{if(n&&typeof n==="object"){for(let s of Object.values(n))t(s);Object.freeze(n)}};t(e);let o=Ie(e.index),i=(n)=>{let s=o.get(n),r=e.showcases[s.id];if(!r)throw new k("resource-not-found",s.id);return r};return Object.freeze({...o,get(n){let s=o.get(n),r=i(n).agentKit;return r?Object.freeze({...s,agentKit:r}):s},docs(n,s="zh",r=1){if(s!=="zh"&&s!=="en")throw Error("unsupported-resource-locale");let a=i(n);return{resourceId:a.resourceId,locale:s,...ut(a.docs[s],r),release:e.release}},examples(n,s=1){let r=i(n);return{resourceId:r.resourceId,...pt(r.examples,s),release:e.release}},installPlan(n){let s=i(n);return{resourceId:s.resourceId,distributions:s.distributions,dependencies:o.build([s.resourceId]),release:e.release,snapshot:e.distributionSnapshot&&Object.hasOwn(e.distributionSnapshot.resources,s.resourceId)?{snapshotId:e.distributionSnapshot.snapshotId,manifestPath:e.distributionSnapshot.manifestPath,...e.distributionSnapshot.resources[s.resourceId]}:null,snapshotUnavailable:e.distributionSnapshot?.unavailable[s.resourceId]??null,install:s.distributions.map((r)=>dt(r,e.distributionSnapshot,s.resourceId))}}})}function dt(e,t,o){let{channel:i,name:n,version:s}=e;if(i==="npm")return{channel:i,name:n,command:`add ${n}@${s}`,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 r=!!t&&Object.hasOwn(t.resources,o),a=t?.external[o]??[];return{channel:i,name:n,command:`shadcn add @uibot/${n}`,registries:{"@uibot":"/r/{name}.json"},externalRegistryDependencies:a,note:r?"A hash-pinned snapshot exists: export and verify it, then map @uibot to the local snapshot server.":a.length?`No hash-pinned snapshot: the install also pulls stock shadcn items (${a.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 A=24000;function Se(e,t){if(!Number.isSafeInteger(e)||e<1||e>Math.max(1,t))throw new k("resource-query-invalid-limit","page is outside the available range")}function ut(e,t){let o=Math.max(1,Math.ceil(e.length/A));return Se(t,o),{markdown:e.slice((t-1)*A,t*A),page:t,totalPages:o,...t<o?{nextPage:t+1}:{}}}function pt(e,t){let o=e.flatMap((i)=>Array.from({length:Math.max(1,Math.ceil(i.code.length/A))},(n,s)=>({...i,code:i.code.slice(s*A,(s+1)*A),codeOffset:s*A,codeLength:i.code.length,complete:i.code.length<=A})));return Se(t,o.length),{examples:o.slice(t-1,t),page:t,totalPages:o.length,...t<o.length?{nextPage:t+1}:{}}}function gt(e){let t=0,o=0,i=new Set,n=(s,r)=>{if(++t>300000||r>64)throw Error("public-resource-budget-exceeded");if(typeof s==="string"){if(o+=new TextEncoder().encode(s).length,o>16777216)throw Error("public-resource-budget-exceeded")}else if(s&&typeof s==="object"){if(i.has(s))throw Error("invalid-public-resource-cycle");let a=Object.getPrototypeOf(s);if(!Array.isArray(s)&&a!==Object.prototype&&a!==null)throw Error("invalid-public-resource-object");i.add(s);for(let[c,u]of Object.entries(s))n(c,r+1),n(u,r+1);i.delete(s)}else if(s!==null&&typeof s!=="boolean"&&(typeof s!=="number"||!Number.isFinite(s)))throw Error("invalid-public-resource-json")};n(e,1)}var mt=(e)=>e.length>0&&!["__proto__","constructor","prototype"].includes(e);function j(e){return e.flatMap((t)=>[t,...j(t.children??[]),...Object.values(t.slots??{}).flatMap(j)])}function G(e,t,o){let i=structuredClone(e);for(let[n,s]of Object.entries(o)){let r=t.find((c)=>c.id===n);if(!r?.values.includes(s)||!mt(r.target.property))throw Error(`invalid-solution-control:${n}`);let a=i.pages?.find((c)=>c.id===r.target.pageId);if(!a)throw Error(`solution-page-missing:${n}`);if(r.target.blockId){let c=j(a.blocks).filter((p)=>p.id===r.target.blockId),u=c[0];if(c.length!==1||!u)throw Error(`solution-block-missing:${n}`);u.props={...u.props,[r.target.property]:s}}else a.state={...a.state,[r.target.property]:s}}return i}function V(e,t,o={}){let i=new Set((e.pages??[]).map((a)=>a.id)),n=new Set((e.pages??[]).map((a)=>a.path)),s=new Set((e.pages??[]).flatMap((a)=>j(a.blocks).flatMap((c)=>c.id?[c.id]:[])));for(let a of t.pages??[]){if(i.has(a.id)||n.has(a.path))throw Error(`solution-page-conflict:${a.id}:${a.path}`);i.add(a.id),n.add(a.path);for(let c of j(a.blocks))if(c.id){if(s.has(c.id))throw Error(`solution-block-conflict:${c.id}`);s.add(c.id)}}if(t.connections||t.auth||t.layout)throw Error("solution-global-config-conflict");if(o.addNavigation){let a=new Set((e.menus?.items??[]).map((c)=>c.key));for(let c of t.pages)if(a.has(`solution:${c.id}`))throw Error(`solution-navigation-conflict:${c.id}`)}let r=o.addNavigation?{...structuredClone(e.menus),items:[...structuredClone(e.menus?.items??[]),...t.pages.map((a)=>({key:`solution:${a.id}`,label:a.title??a.id,path:a.path}))]}:e.menus;return{...structuredClone(e),...r?{menus:structuredClone(r)}:{},pages:[...structuredClone(e.pages??[]),...structuredClone(t.pages??[])]}}function w(e){if(Array.isArray(e))return`[${e.map(w).join(",")}]`;if(e&&typeof e==="object")return`{${Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[o])=>t<o?-1:t>o?1:0).map(([t,o])=>`${JSON.stringify(t)}:${w(o)}`).join(",")}}`;return JSON.stringify(e)??"null"}var Y=(e)=>typeof e==="string"&&e.length>0&&!["__proto__","prototype","constructor"].includes(e);function Pe(e){if(!Y(e.resourceId)||!Y(e.version)||!/^[a-f0-9]{64}$/.test(e.sourceHash))throw Error("invalid-solution-identity")}function re(e,t,o,i=e.id){let n=structuredClone(e);if(n.id=i,n.path=o.paths[e.path]??e.path,!Y(n.id)||typeof n.path!=="string"||!n.path.startsWith("/"))throw Error("invalid-solution-page-target");if(o.frame)n.blocks=n.blocks.map((r)=>r.type==="PageLayout"?{...r,props:{...r.props,...structuredClone(o.frame?.props)},slots:{...r.slots,...structuredClone(o.frame?.slots)},events:{...r.events,...structuredClone(o.frame?.events)}}:r);let s=(r)=>{if(!r||typeof r!=="object")return;for(let[a,c]of Object.entries(r))if(typeof c==="string"){if(a==="connectionId"&&o.connections[c])r[a]=o.connections[c];else if(["href","path","url","redirect","currentPath"].includes(a)&&o.paths[c])r[a]=o.paths[c]}else s(c)};if(s(n),o.layout==="source"&&t.layout&&n.blocks.some((r)=>r.type==="PageLayout"))n.layout={...structuredClone(t.layout),...n.layout,inherit:!1};return n}function Q(e,t,o){let i=structuredClone(e.connections??[]);for(let n of t.connections??[]){let s=o[n.id];if(!s||!Y(s))throw Error(`solution-connection-binding-required:${n.id}`);let r=i.find((a)=>a.id===s);if(r&&r.type!==n.type)throw Error(`solution-connection-type-conflict:${n.id}:${s}`);if(!r)i.push({id:s,type:n.type})}return i}function oe(e,t,o,i){let n=new Set([...e.pages,...o].map((c)=>c.path)),s=new Set(t.pages.map((c)=>i.paths[c.path]??c.path)),r=new Set(Q(e,t,i.connections).map((c)=>c.id)),a=(c)=>{if(!c||typeof c!=="object")return;for(let[u,p]of Object.entries(c))if(typeof p==="string"){if(u==="connectionId"&&!r.has(p))throw Error(`solution-connection-missing:${p}`);if(["href","url","redirect","path"].includes(u)&&s.has(p)&&!n.has(p))throw Error(`solution-route-dependency-missing:${p}`)}else a(p)};for(let c of o)a(c)}function fo(e,t,o){if(Pe(t.identity),v(e),t.spec.auth)throw Error("solution-host-auth-required");let i=G(t.spec,t.controls??[],o.configuration??{}),n={paths:{...o.paths},connections:{...o.connections},layout:o.layout,...o.frame?{frame:structuredClone(o.frame)}:{}},s=Q(e,i,n.connections),r=o.selectedPageIds?i.pages.filter((p)=>o.selectedPageIds?.includes(p.id)):i.pages;if(!r.length||o.selectedPageIds&&r.length!==new Set(o.selectedPageIds).size)throw Error("solution-select-pages");let a=r.map((p)=>re(p,i,n,o.pageIds?.[p.id]??p.id));oe(e,t.spec,a,n);let c=V(e,{version:"2.0",pages:a},{addNavigation:o.addNavigation??!1}),u=r.map((p,f)=>({...t.identity,sourcePageId:p.id,targetPageId:a[f]?.id??p.id,baseline:structuredClone(a[f]),bindings:structuredClone(n),...o.configuration?{configuration:structuredClone(o.configuration)}:{}}));if(c.composition={...structuredClone(e.composition),schema:"uibot.solution-composition.v1",pages:[...structuredClone(e.composition?.pages??[]),...u]},s.length)c.connections=s;return{spec:c,pages:a.map((p)=>({id:p.id,path:p.path})),connections:s.filter((p)=>!e.connections?.some((f)=>f.id===p.id)),layout:o.layout}}function ft(e,t,o={}){Pe(t.identity),v(e);let i=[];for(let n of e.composition?.pages??[]){if(n.resourceId!==t.identity.resourceId||n.detached)continue;let s=e.pages.find((c)=>c.id===n.targetPageId),r=t.spec.pages.find((c)=>c.id===n.sourcePageId),a={pageId:n.targetPageId,path:s?.path??n.baseline.path,from:{resourceId:n.resourceId,version:n.version,sourceHash:n.sourceHash},to:t.identity};if(!s){i.push({...a,status:"deleted-locally"});continue}if(!r){i.push({...a,status:"removed"});continue}try{let c=G(t.spec,t.controls??[],n.configuration??{}),u={...n.bindings,connections:{...n.bindings.connections,...o}};if(Q(e,c,u.connections),c.auth)throw Error("solution-host-auth-required");let p=re(c.pages.find((d)=>d.id===r.id),c,u,s.id),f=e.pages.flatMap((d)=>{if(d.id===s.id)return[];let g=e.composition?.pages.find((b)=>b.resourceId===t.identity.resourceId&&b.targetPageId===d.id&&!b.detached),y=c.pages.find((b)=>b.id===g?.sourcePageId);return g&&y?[{...d,path:g.bindings.paths[y.path]??y.path}]:[d]});oe({...e,pages:f},c,[p],u);let m=w(s)!==w(n.baseline),l=w(p)!==w(n.baseline);i.push({...a,nextPath:p.path,incoming:p,status:m?l?"conflict":"customized":l?"update":"unchanged"})}catch(c){i.push({...a,status:"blocked",error:String(c)})}}return{pages:i,tracked:i.length>0}}function yo(e,t,o,i={}){let n=ft(e,t,i),s=structuredClone(e);if(n.pages.some((r)=>["conflict","removed","deleted-locally"].includes(r.status)&&!o[r.pageId]))throw Error("solution-upgrade-unresolved");for(let[r,a]of Object.entries(o)){let c=n.pages.find((d)=>d.pageId===r),u=s.composition?.pages.find((d)=>d.targetPageId===r);if(!c||!u)throw Error(`solution-untracked-page:${r}`);if(c.status==="blocked")throw Error(`solution-upgrade-blocked:${r}`);if(a==="detach"){u.detached=!0;continue}if(["removed","deleted-locally"].includes(c.status))throw Error(`solution-upgrade-detach-required:${r}`);if(a==="update"&&["conflict","customized"].includes(c.status))throw Error(`solution-upgrade-conflict:${r}`);if(!["update","replace","keep"].includes(a))throw Error("invalid-solution-upgrade-decision");let p=G(t.spec,t.controls??[],u.configuration??{});u.bindings.connections={...u.bindings.connections,...i};let f=p.pages.find((d)=>d.id===u.sourcePageId);if(!f)throw Error(`solution-page-missing:${r}`);let m=re(f,p,u.bindings,r);if(a!=="keep"){let d=s.pages.find((g)=>g.id===r)?.path;if(s.pages=s.pages.map((g)=>g.id===r?m:g),d&&d!==m.path){let g=(y)=>{if(!y||typeof y!=="object")return;for(let[b,F]of Object.entries(y))if(["path","href"].includes(b)&&F===d)y[b]=m.path;else if(typeof F==="object")g(F)};g(s.menus);for(let y of s.pages)for(let b of y.blocks)if(b.type==="PageLayout")g(b.props?.routes),g(b.slots?.sidebar)}}u.baseline=structuredClone(m),Object.assign(u,t.identity);let l=Q(s,p,u.bindings.connections);if(l.length)s.connections=l}V({version:"2.0",pages:[]},{version:"2.0",pages:s.pages});for(let[r,a]of Object.entries(o))if(a!=="detach"){let c=s.composition?.pages.find((p)=>p.targetPageId===r),u=s.pages.find((p)=>p.id===r);if(c&&u)oe(s,{...t.spec,pages:[...t.spec.pages,...e.pages]},s.pages,c.bindings)}return s}function U(e){return e.flatMap((t)=>[t,...U(t.children??[]),...Object.values(t.slots??{}).flatMap(U)])}function ie(e,t){let o=U([e]).filter((i)=>i.id===t);if(o.length!==1||!o[0]||o[0].type!=="Box"||o[0].template||o[0].slots||o[0].events||o[0].visible!==void 0)throw Error("solution-region-slot-invalid");return o[0]}function ko(e,t,o){if(v(e),!t.identity.resourceId||!t.identity.version||!/^[a-f0-9]{64}$/.test(t.identity.sourceHash))throw Error("invalid-solution-identity");let i=Object.entries(o);if(!i.length||i.some(([s,r])=>!s||!r)||new Set(i.map(([,s])=>s)).size!==i.length)throw Error("solution-region-explicit-mapping-required");let n=structuredClone(e);for(let[s,r]of i){let a=n.pages.find((d)=>d.id===r);if(!a||U(a.blocks).some((d)=>d.type==="PageLayout"))throw Error(`solution-region-independent-page-required:${r}`);let c=a.blocks,u=n.composition?.regions?.find((d)=>d.targetPageId===r);if(u){if(a.blocks.length!==1||!a.blocks[0])throw Error("solution-region-frame-customized");let d=structuredClone(a.blocks[0]),g=ie(d,u.contentBlockId);if(c=g.children??[],g.children=[],w(d)!==w(u.baseline))throw Error("solution-region-frame-customized")}let p=structuredClone(t.frame);if(ie(p,t.contentBlockId).children?.length)throw Error("solution-region-slot-not-empty");for(let d of U([p]))if(d.id)d.id=`${r}-${d.id}`;let f=`${r}-${t.contentBlockId}`,m=structuredClone(p);ie(p,f).children=structuredClone(c),a.blocks=[p];let l={...t.identity,targetPageId:r,role:s,target:"page-frame",contentBlockId:f,baseline:m};n.composition??={schema:"uibot.solution-composition.v1",pages:[]},n.composition.regions=[...(n.composition.regions??[]).filter((d)=>d.targetPageId!==r),l]}return V({version:"2.0",pages:[]},{version:"2.0",pages:n.pages}),v(n),n}export{Qr as RESOURCE_INDEX_ERROR_CODES,Ye as RESOURCE_INDEX_SCHEMA_VERSION,oo as RESOURCE_QUERY_ERROR_CODES,De as RESOURCE_QUERY_OPERATION_MANIFEST,ne as RESOURCE_QUERY_SCORE_WEIGHTS,_ as ResourceIndexError,k as ResourceQueryError,V as appendSolutionPages,yo as applySolutionUpgrade,lt as assertPublicResourceBundle,v as assertSolutionComposition,Jr as buildExamplesFromL4Templates,Zr as buildResourceIndex,fo as composeSolutionSpec,G as configureSolutionSpec,lo as createPublicResourceQueryService,Ie as createResourceQueryService,h as normalizeResourceAlias,ft as planSolutionUpgrade,ko as replaceSolutionPageFrames,w as solutionContentKey,P as toResourceId};
2
+ var Yt={spec:["html","markdown","zip"],prototype:["html","zip"],deck:["html","pptx","zip"],poster:["html","zip"]},vo=Array.from(new Set(Object.values(Yt).flat()));var it=["component","template","design-guide","example","skill","block","package","theme"],be=["experimental","candidate","recommended"],st=["declared","verified","external-consumer"],ke=["missing","declared","verified","external-consumer"],le=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure","packed-install","typecheck","browser"],Jt=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 So="uibot.registry.item.v1";var Zt=["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"],Po=[...Zt,"radius","font-display","font-body","font-mono"];var Qt=["L1","L2","L3","L4"],_e=["shell","page","frame","section","block"],Xt=["block-node","block-prop","block-events","block-children","page-field","spec-layout"],V=(e)=>Boolean(e)&&typeof e==="object"&&!Array.isArray(e),q=(e)=>typeof e==="string"&&e.length>0&&!["__proto__","prototype","constructor"].includes(e),Ne=(e)=>V(e)&&typeof e.zh==="string"&&typeof e.en==="string";function en(e,t){if(e==="shell"){if(!V(t.shellLayout))throw Error("missing-variant-payload");return}if(e==="page"){let r=t.pageTemplate;if(!V(r)||!q(r.id)||typeof r.path!=="string"||!Array.isArray(r.blocks))throw Error("missing-variant-payload");return}if(e==="frame"){let r=t.frameTemplate;if(!V(r)||!q(r.contentBlockId)||!V(r.frame)||!q(r.frame.type))throw Error("missing-variant-payload");return}if(!V(t.blockTemplate)||!q(t.blockTemplate.type))throw Error("missing-variant-payload")}function Me(e){if(!V(e)||e.schema!=="uibot.variant-contract.v1"||!q(e.familyId)||!Qt.includes(e.level)||!_e.includes(e.targetKind)||!Ne(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(!V(a)||!q(a.id)||!Ne(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 r=new Set,o=new Set,n=e.targetKind;for(let a of e.variants){if(!V(a)||!q(a.id)||!Ne(a.title)||typeof a.description!=="string"||!V(a.slotBindings))throw Error("invalid-variant-member");if(r.has(a.id)||o.has(a.id))throw Error("duplicate-variant-id");if(r.add(a.id),a.aliases!==void 0){if(!Array.isArray(a.aliases))throw Error("invalid-variant-alias");for(let i of a.aliases){if(!q(i))throw Error("invalid-variant-alias");if(r.has(i)||o.has(i))throw Error("duplicate-variant-alias");o.add(i)}}for(let[i,s]of Object.entries(a.slotBindings)){if(!q(i)||!t.has(i))throw Error(`undeclared-variant-slot:${i}`);if(!V(s)||!Xt.includes(s.kind)||s.occurrence!==void 0&&(typeof s.occurrence!=="number"||!Number.isInteger(s.occurrence)||s.occurrence<0))throw Error(`invalid-variant-slot-binding:${i}`)}en(n,a)}}var U=(e)=>!!e&&typeof e==="object"&&!Array.isArray(e),D=(e)=>typeof e==="string"&&e.length>0&&!["__proto__","prototype","constructor"].includes(e),at=(e)=>U(e)&&Object.entries(e).every(([t,r])=>D(t)&&D(r));function O(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 r=new Set;for(let o of t.pages){if(!U(o)||!D(o.resourceId)||!D(o.version)||typeof o.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(o.sourceHash)||!D(o.sourcePageId)||!D(o.targetPageId)||r.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))||!at(o.bindings.paths)||!at(o.bindings.connections)||o.bindings.frame!==void 0&&(!U(o.bindings.frame)||Object.keys(o.bindings.frame).some((n)=>!["props","slots","events"].includes(n)))||o.detached!==void 0&&typeof o.detached!=="boolean"||o.configuration!==void 0&&(!U(o.configuration)||Object.entries(o.configuration).some(([n,a])=>!D(n)||!["string","number","boolean"].includes(typeof a)||typeof a==="number"&&!Number.isFinite(a))))throw Error("invalid-solution-adoption");r.add(o.targetPageId)}if(t.regions!==void 0){if(!Array.isArray(t.regions))throw Error("invalid-solution-regions");let o=new Set;for(let n of t.regions){if(!U(n)||!D(n.resourceId)||!D(n.version)||typeof n.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(n.sourceHash)||!D(n.targetPageId)||o.has(n.targetPageId)||!D(n.role)||n.target!=="page-frame"||!D(n.contentBlockId)||!U(n.baseline)||!D(n.baseline.type))throw Error("invalid-solution-region");o.add(n.targetPageId)}}if(t.variants!==void 0){if(!Array.isArray(t.variants))throw Error("invalid-solution-variants");let o=new Set;for(let n of t.variants){if(!U(n)||!D(n.familyId)||!D(n.variantId)||!D(n.targetId)||!_e.includes(n.targetKind))throw Error("invalid-solution-variant");let a=`${n.targetKind}:${n.targetId}:${n.familyId}`;if(o.has(a))throw Error("invalid-solution-variant");o.add(a)}}}var nn=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,rn=["string","number","boolean","date","datetime","enum","json","ref"];function dt(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e))}function de(e,t){if(!dt(e)||t&&Object.keys(e).some((r)=>!t.includes(r)))throw Error("Invalid data object or unknown field");return e}function pe(e){if(typeof e!=="string"||!nn.test(e))throw Error("Invalid data name")}function lt(e){if(typeof e!=="string"||!e||e.length>2048)throw Error("Invalid data text")}function on(e){return e===null||typeof e==="string"||typeof e==="boolean"||typeof e==="number"&&Number.isFinite(e)}function pt(e){for(let t=0;t<e.length;t++)if(!Object.hasOwn(e,t))return!1;return!0}function Le(e,t={left:1e4},r=0){if(--t.left<0||r>32)return!1;if(on(e))return!0;if(Array.isArray(e)){if(e.length>t.left||!pt(e))return!1;return e.every((o)=>Le(o,t,r+1))}return dt(e)&&Object.values(e).every((o)=>Le(o,t,r+1))}function W(e){let t=de(e,["entities"]),r=de(t.entities);if(Object.keys(r).length>64)throw Error("Data model exceeds 64 entities");for(let[o,n]of Object.entries(r)){pe(o);let a=de(n,["title","key","fields","version"]);if(a.title!==void 0)lt(a.title);pe(a.key);let i=de(a.fields);if(Object.keys(i).length>128)throw Error("Data entity exceeds 128 fields");if(!Object.hasOwn(i,a.key))throw Error("Data key must name an entity field");if(a.version!==void 0){if(pe(a.version),!Object.hasOwn(i,a.version))throw Error("Unknown data version field")}for(let[s,c]of Object.entries(i)){pe(s);let l=de(c,["type","title","required","readOnly","default","values","entity","maxLength"]);if(typeof l.type!=="string"||!rn.includes(l.type))throw Error("Invalid data field type");if(l.title!==void 0)lt(l.title);for(let p of["required","readOnly"])if(l[p]!==void 0&&typeof l[p]!=="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||!pt(l.values)||l.values.some((p)=>typeof p!=="string"||p.length>2048))throw Error("Data enum requires bounded string values")}if(l.type==="ref"||l.entity!==void 0){if(pe(l.entity),!Object.hasOwn(r,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")&&!Le(l.default))throw Error("Invalid or excessive data default")}}return e}class v extends Error{code;opIndex;opKind;constructor(e,t,r,o){super(`${e} at op[${t}] (${r}): ${o}`);this.code=e;this.opIndex=t;this.opKind=r;this.name="SpecPatchError"}}var xe=new Set(["__proto__","prototype","constructor"]),sn=/^@[A-Za-z_][A-Za-z0-9_]*$/,ut=/^(0|[1-9]\d*)$/,an=/^[A-Za-z_][A-Za-z0-9_]*$/,N=(e)=>Boolean(e)&&typeof e==="object"&&!Array.isArray(e),A=(e)=>typeof e==="string"&&e.length>0&&!xe.has(e);function ve(e,t=64){let r=(o,n)=>{if(n>t)throw Error("spec-json-depth-exceeded");if(o===null||typeof o!=="object")return;if(Array.isArray(o)){for(let a of o)r(a,n+1);return}for(let a of Object.getOwnPropertyNames(o)){if(xe.has(a))throw Error(`unsafe-spec-key:${a}`);r(o[a],n+1)}};r(e,0)}function G(e,t={}){let r;if(typeof e==="string"){let a=e.trim(),i=a.startsWith("uibot-path:")?a.slice(11):a;if(i===""){if(t.allowRoot)return[];throw Error("invalid-spec-block-path")}r=i.split(".")}else if(Array.isArray(e))r=e;else throw Error("invalid-spec-block-path");if(r.length===0){if(t.allowRoot)return[];throw Error("invalid-spec-block-path")}let o=[];for(let a=0;a<r.length;a++){let i=r[a];if(typeof i==="number"){if(!Number.isInteger(i)||i<0)throw Error("invalid-spec-block-path");if(a>0&&typeof o[o.length-1]==="number");o.push(i);continue}if(typeof i==="string"){if(ut.test(i)){o.push(Number(i));continue}if(sn.test(i)){let s=i.slice(1);if(xe.has(s))throw Error("invalid-spec-block-path");if(a===0)throw Error("invalid-spec-block-path");if(a<r.length-1){let c=r[a+1];if(!(typeof c==="number"&&Number.isInteger(c)&&c>=0||typeof c==="string"&&ut.test(c)))throw Error("invalid-spec-block-path")}else if(!t.allowSlotEnd)throw Error("invalid-spec-block-path");o.push(i);continue}}throw Error("invalid-spec-block-path")}if(typeof o[0]!=="number")throw Error("invalid-spec-block-path");let n=o[o.length-1];if(typeof n!=="number"&&!(t.allowSlotEnd&&typeof n==="string"))throw Error("invalid-spec-block-path");return o}function je(e,t,r){if(!N(e)||!A(e.pageId))throw new v("invalid-spec-patch",t,r,"target.pageId is required");if(!e.blockId&&e.blockPath===void 0)throw new v("invalid-spec-patch",t,r,"target requires blockId or blockPath");if(e.blockId!==void 0&&!A(e.blockId))throw new v("invalid-spec-patch",t,r,"invalid target.blockId");if(e.blockPath!==void 0)try{G(e.blockPath,{allowRoot:!1,allowSlotEnd:!1})}catch{throw new v("invalid-spec-block-path",t,r,"invalid target.blockPath")}}function gt(e,t,r){if(!N(e)||!A(e.pageId))throw new v("invalid-spec-patch",t,r,"target.pageId is required");if(e.parentBlockId!==void 0&&!A(e.parentBlockId))throw new v("invalid-spec-patch",t,r,"invalid parentBlockId");if(e.parentPath!==void 0)try{G(e.parentPath,{allowRoot:!0,allowSlotEnd:!0})}catch{throw new v("invalid-spec-block-path",t,r,"invalid parentPath")}if(e.slot!==void 0){if(typeof e.slot!=="string"||!an.test(e.slot)||xe.has(e.slot))throw new v("patch-slot-invalid",t,r,"invalid target.slot")}if(e.index!==void 0&&(typeof e.index!=="number"||!Number.isInteger(e.index)||e.index<0))throw new v("invalid-spec-patch",t,r,"invalid target.index")}function ft(e){if(ve(e),!N(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 r of e.connections){if(!N(r)||!A(r.id)||!A(r.entity))throw Error("invalid-blueprint-connection");if(t.has(r.id))throw Error("duplicate-blueprint-connection");if(t.add(r.id),Object.hasOwn(r,"bindings")&&r.bindings!==void 0)throw Error("blueprint-connection-bindings-forbidden");if(r.mockSeed!==void 0&&(!Array.isArray(r.mockSeed)||r.mockSeed.some((o)=>!N(o))))throw Error("invalid-blueprint-connection");if(r.mockGenerate!==void 0&&(typeof r.mockGenerate!=="number"||!Number.isInteger(r.mockGenerate)||r.mockGenerate<0||r.mockGenerate>500))throw Error("invalid-blueprint-connection")}}for(let t of e.pages){if(!N(t))throw Error("invalid-blueprint-page");if(t.id!==void 0&&!A(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(!A(t.id)||typeof t.path!=="string"||!Array.isArray(t.blocks))throw Error("invalid-blueprint-page");continue}if(!(A(t.solutionId)||A(t.familyId)&&A(t.variantId)))throw Error("invalid-blueprint-page")}}function mt(e,t={}){if(!Array.isArray(e))throw new v("invalid-spec-patch",0,"batch","operations must be an array");if(e.length>200)throw new v("spec-patch-batch-too-large",e.length,"batch","exceeds maximum batch size 200");for(let r=0;r<e.length;r++){let o=e[r];if(!N(o)||typeof o.op!=="string")throw new v("invalid-spec-patch",r,"unknown","operation must declare op");let n=o.op;try{ve(o)}catch(a){let i=a instanceof Error?a.message:"unsafe json",s=i.includes("spec-json-depth-exceeded")?"spec-json-depth-exceeded":"unsafe-spec-key";throw new v(s,r,n,i)}switch(n){case"addPage":if(!N(o.page)||!A(o.page.id)||typeof o.page.path!=="string"||!Array.isArray(o.page.blocks))throw new v("invalid-spec-patch",r,n,"invalid page object");break;case"removePage":case"updatePage":case"setPageState":if(!A(o.pageId))throw new v("invalid-spec-patch",r,n,"pageId is required");break;case"insertBlock":if(gt(o.target,r,n),!N(o.block)||!A(o.block.type))throw new v("invalid-spec-patch",r,n,"block.type is required");break;case"replaceBlock":if(je(o.target,r,n),!N(o.block)||!A(o.block.type))throw new v("invalid-spec-patch",r,n,"block.type is required");break;case"removeBlock":case"updateProps":case"setEvents":je(o.target,r,n);break;case"moveBlock":je(o.from,r,n),gt(o.to,r,n);break;case"upsertEntity":if(!A(o.name)||!N(o.entity))throw new v("invalid-spec-patch",r,n,"name and entity required");break;case"removeEntity":if(!A(o.name))throw new v("invalid-spec-patch",r,n,"name is required");break;case"upsertConnection":if(!N(o.connection)||!A(o.connection.id)||!A(o.connection.entity))throw new v("invalid-spec-patch",r,n,"valid connection is required");if(!t.allowConnectionBindings&&Object.hasOwn(o.connection,"bindings")&&o.connection.bindings!==void 0)throw new v("spec-patch-connection-bindings-forbidden",r,n,"connection.bindings is host-owned and forbidden in spec patches");break;case"removeConnection":if(!A(o.connectionId))throw new v("invalid-spec-patch",r,n,"connectionId is required");break;case"setLayout":if(!N(o.layout))throw new v("invalid-spec-patch",r,n,"layout object is required");break;case"setMenus":if(!N(o.menus)||!Array.isArray(o.menus.items))throw new v("invalid-spec-patch",r,n,"menus.items is required");break;case"setDesign":if(!N(o.design))throw new v("invalid-spec-patch",r,n,"design object is required");break;case"swapVariant":if(!N(o.target)||typeof o.targetVariantId!=="string")throw new v("invalid-spec-patch",r,n,"target and targetVariantId are required");if(o.target.blockPath!==void 0)try{G(o.target.blockPath,{allowRoot:!1,allowSlotEnd:!1})}catch{throw new v("invalid-spec-block-path",r,n,"invalid target.blockPath")}break;default:throw new v("invalid-spec-patch",r,n,`unknown op "${n}"`)}}}var Ve="uibot.resource.admission.v1",cn=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure"],ln=["packed-install","typecheck","browser"],ys=["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 yt 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 ht 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 bt extends Error{code="resource-admission-report-not-derived";constructor(){super("resource admission report must come directly from assessResourceAdmissions");this.name="ResourceAdmissionReportNotDerivedError"}}var dn=new Set(le),pn=new Set(ke),kt=new WeakSet,Ce={missing:0,declared:1,verified:2,"external-consumer":3};function un(e,t){return e<t?-1:e>t?1:0}function ne(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function we(e,t){let r=new Set(t);return Object.keys(e).every((o)=>r.has(o))}function xt(e){return[...new Set(e.map((t)=>t.trim()).filter(Boolean))].sort(un)}function gn(e,t,r,o){if(!ne(r)||!we(r,["status","evidence"])){o.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} must contain only status and evidence`});return}if(typeof r.status!=="string"||!pn.has(r.status)||r.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(r.evidence)||r.evidence.length===0||r.evidence.some((n)=>typeof n!=="string"||!n.trim())){o.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:xt(r.evidence)}}function fn(e){if(e===void 0)return;if(!ne(e)||!we(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 mn(e,t){let r=new Map,o=[];if(!ne(t)||!we(t,["schemaVersion","records"])||t.schemaVersion!==Ve||!Array.isArray(t.records))return o.push({code:"invalid-admission-manifest",detail:`expected ${Ve} with a records array`}),{records:r,issues:o};let n=new Set(e.resources.map((a)=>a.id));for(let a of t.records){if(!ne(a)||!we(a,["resourceId","provenance","checks"])||typeof a.resourceId!=="string"||!a.resourceId.trim()||!ne(a.checks)){o.push({code:"invalid-admission-record",...ne(a)&&typeof a.resourceId==="string"?{resourceId:a.resourceId}:{},detail:"record must contain only resourceId, optional provenance and checks"});continue}let i=a.resourceId.trim();if(r.has(i)){o.push({code:"duplicate-admission-record",resourceId:i,detail:i});continue}if(!n.has(i)){o.push({code:"unknown-admission-resource",resourceId:i,detail:i});continue}let s=fn(a.provenance);if(a.provenance!==void 0&&!s){o.push({code:"invalid-admission-record",resourceId:i,detail:"provenance must contain only string source, version and license fields"});continue}let c={},l=!1;for(let[p,u]of Object.entries(a.checks)){if(!dn.has(p)){o.push({code:"invalid-admission-check",resourceId:i,detail:`unknown receipt check: ${p}`}),l=!0;continue}let g=p,d=gn(i,g,u,o);if(d)c[g]=d;else l=!0}if(l)continue;r.set(i,{resourceId:i,...s?{provenance:s}:{},checks:c})}return{records:r,issues:o}}function yn(e){let t=new Map(e.resources.map((n)=>[n.id,n])),r=new Map;function o(n,a,i,s){if(r.has(n)||s.has(a))return;if(i.has(a)){r.set(n,`dependency cycle reached ${a}`);return}let c=t.get(a);if(!c){r.set(n,`missing dependency ${a}`);return}i.add(a);for(let l of c.dependencies)if(o(n,l,i,s),r.has(n))break;i.delete(a),s.add(a)}for(let n of e.resources)o(n.id,n.id,new Set,new Set);return r}var hn=/^(unknown|unlicensed|none|n\/?a)$/i,bn=/^SPDX-License-Identifier:\s*(\S+)/im,kn=/^(?:the\s+)?(mit|apache(?:\s+license(?:\s*,?\s*version\s*2\.0)?)?|bsd-2-clause|bsd-3-clause|isc|unlicense)\b/i;function Q(e){let t=e?.trim();if(!t||hn.test(t))return;return t}function xn(e){if(!e?.trim())return;let t=e.match(bn)?.[1];if(t)return Q(t);let r=e.match(kn)?.[1];if(!r)return;let o=r.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 hs(e){return Q(e.frontmatterLicense)??Q(e.packageJsonLicense)??xn(e.licenseFileText)}function vt(e){return Boolean(Q(e))}var ue={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 Fe(e,t){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let o of e)Fe(o,t);return}let r=e;for(let[o,n]of Object.entries(r)){if(t.push(o),o==="type"&&n==="boolean")t.push("boolean-state");Fe(n,t)}}function vn(e){let t=[];return Fe(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(`
3
+ `)}function bs(e,t={}){let r=[vn(e),t.sourceText??"",t.stylesText??""].join(`
4
+ `);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:ue.states.test(r)?"verified":"missing",accessibility:ue.accessibility.test(r)?"verified":"missing","light-theme":ue["light-theme"].test(r)?"verified":"missing","dark-theme":ue["dark-theme"].test(r)?"verified":"missing",responsive:ue.responsive.test(r)?"verified":"missing"}}function Cn(e){return{source:"declared",license:vt(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 wn(e){if(!cn.every((o)=>Ce[e[o]]>=Ce.verified))return"experimental";return ln.every((o)=>e[o]==="external-consumer")?"recommended":"candidate"}function Ct(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,o=0x100000001b3n;for(let n of new TextEncoder().encode(t))r^=BigInt(n),r=BigInt.asUintN(64,r*o);return`fnv1a64:${r.toString(16).padStart(16,"0")}`}function In(e,t,r){let o=Cn(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 o["dependency-closure"]="verified",n.push(`resource://index/${e.id}`);if(t)for(let c of le){if(c==="dependency-closure")continue;let l=t.checks[c];if(!l)continue;if(c==="source"&&Ce[l.status]>=Ce.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"&&!vt(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,n.push(...l.evidence),c==="source"&&t.provenance?.source)n.push(t.provenance.source)}let i=wn(o),s={level:i==="recommended"?"external-consumer":i==="candidate"?"verified":"declared",maturity:i,checks:o,evidence:xt(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 ks(e,t){let r=mn(e,t),o=yn(e),n=e.resources.map((c)=>In(c,r.records.get(c.id),o.get(c.id))),a=[...r.issues,...n.flatMap((c)=>c.issues)],i=Object.fromEntries(be.map((c)=>[c,0]));for(let c of n)i[c.receipt.maturity]+=1;Object.freeze(n),Object.freeze(i);for(let c of a)Object.freeze(c);Object.freeze(a);let s=Object.freeze({schemaVersion:Ve,indexFingerprint:Ct(e),resources:n,counts:i,issues:a});return kt.add(s),s}function xs(e,t){if(!kt.has(t))throw new bt;if(t.issues.length>0)throw new ht(t.issues.length);let r=Ct(e);if(r!==t.indexFingerprint)throw new yt(t.indexFingerprint,r);let o=new Map(t.resources.map((a)=>[a.resourceId,a.receipt])),n=e.resources.map((a)=>{let i=o.get(a.id);if(!i)return a;return Object.freeze({...a,receipt:i})});return Object.freeze(n),Object.freeze({schemaVersion:e.schemaVersion,resources:n,aliases:e.aliases})}var Sn="uibot.resource.index.v1",ws=["invalid-resource-source-id","duplicate-resource-id","dangling-resource-dependency","ambiguous-resource-dependency"];class oe extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceIndexError"}}function M(e,t){return e<t?-1:e>t?1:0}function E(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 Rn(e){let t=E(e).replace(/ /g,"-");if(!t)throw new oe("invalid-resource-source-id",e);return t}function K(e,t){return`${e}:${Rn(t)}`}function Ie(e){let t=new Map;for(let r of e){let o=r?.trim();if(!o)continue;let n=E(o);if(!n||t.has(n))continue;t.set(n,o)}return[...t.entries()].sort(([r],[o])=>M(r,o)).map(([,r])=>r)}function ge(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 Pn(e){let t=Q(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 re(e){return{id:e.id,kind:e.kind,title:e.title,description:e.description,...e.category?{category:e.category}:{},tags:Ie(e.tags),aliases:Ie(e.aliases),capabilities:Ie(e.capabilities),dependencies:[...new Set(e.dependencies)].sort(M),source:Pn(e.source),receipt:e.receipt,...e.solution?{solution:structuredClone(e.solution)}:{}}}function An(e){return(e.body.split(/\r?\n/).map((r)=>r.replace(/^#+\s*/,"").trim()).find(Boolean)??e.title).slice(0,240)}function En(e){if(e.solution){let t=(r)=>{if(r&&typeof r==="object"){for(let o of Object.values(r))t(o);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 On(e){let t=new Map;for(let r of Object.keys(e).sort(M)){let o=e[r];if(!o)continue;let n=K("component",r);for(let a of Ie([r,o.name])){let i=E(a),s=t.get(i)??[];if(!s.includes(n))s.push(n);t.set(i,s.sort(M))}}return t}function Tn(e,t,r){let o=r.get(E(e))??[];if(o.length===0)throw new oe("dangling-resource-dependency",`${t} -> ${K("component",e)}`);if(o.length>1)throw new oe("ambiguous-resource-dependency",`${t} -> ${e}: ${o.join(",")}`);return o[0]}function Bn(e,t,r,o){let n=e.startsWith("template:")?e.slice(9):e;if(Object.hasOwn(o,n))return K("template",n);return Tn(e,t,r)}function fe(e,t,r){return Q(r?.[e]??t)}function Is(e){return Object.entries(e).filter(([,t])=>t.level==="L4").sort(([t],[r])=>M(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:[K("template",t)]}))}function Ss(e){let t=e.components??{},r=e.templates??{},o=e.designGuides??[],n=e.examples??[],a=e.skills??[],i=e.licenses,s=On(t),c=[];for(let d of Object.keys(t).sort(M)){let f=t[d];if(!f)continue;let m=K("component",d),y=fe(m,void 0,i);c.push(re({id:m,kind:"component",title:f.name,description:f.description,category:f.category,tags:f.tags??[],aliases:[d,f.name],capabilities:["catalog:component"],dependencies:[],source:{type:"catalog",id:d,...y?{license:y}:{}},receipt:ge(Boolean(y))}))}for(let d of Object.keys(r).sort(M)){let f=r[d];if(!f)continue;let m=K("template",d),y=fe(m,void 0,i);c.push(re({id:m,kind:"template",title:f.name,description:f.description,category:f.category,tags:f.keywords,aliases:[d,f.name],capabilities:[],dependencies:(f.composedFrom??[]).map((k)=>Bn(k,m,s,r)),source:{type:"template-contract",id:d,...y?{license:y}:{}},receipt:ge(Boolean(y))}))}for(let d of[...o].sort((f,m)=>M(f.id,m.id))){let f=K("design-guide",d.id),m=fe(f,void 0,i);c.push(re({id:f,kind:"design-guide",title:d.title,description:An(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}:{},...m?{license:m}:{}},receipt:ge(Boolean(m))}))}for(let d of[...n].sort((f,m)=>M(f.id,m.id))){let f=K("example",d.id),m=fe(f,d.license,i);c.push(re({id:f,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}:{},...m?{license:m}:{}},receipt:ge(Boolean(m))}))}for(let d of[...a].sort((f,m)=>M(f.id,m.id))){let f=K("skill",d.id),m=fe(f,void 0,i);c.push(re({id:f,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}:{},...m?{license:m}:{}},receipt:ge(Boolean(m))}))}for(let d of e.additional??[])c.push(re(d));c.sort((d,f)=>M(d.id,f.id));let l=new Set;for(let d of c){if(l.has(d.id))throw new oe("duplicate-resource-id",d.id);l.add(d.id)}for(let d of c)for(let f of d.dependencies)if(!l.has(f))throw new oe("dangling-resource-dependency",`${d.id} -> ${f}`);let p=new Map;for(let d of c)for(let f of d.aliases){let m=E(f);if(!m)continue;let y=p.get(m)??new Set;y.add(d.id),p.set(m,y)}let u=Object.freeze(Object.fromEntries([...p.entries()].sort(([d],[f])=>M(d,f)).map(([d,f])=>[d,Object.freeze([...f].sort(M))]))),g=Object.freeze(c.map(En));return Object.freeze({schemaVersion:Sn,resources:g,aliases:u})}var Dn=[["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"]],Nn=Object.freeze(Dn.map((e)=>Object.freeze([...e]))),wt=new Map;for(let e of Nn){let t=Object.freeze([...new Set(e.map(E).filter(Boolean))].sort());for(let r of t)wt.set(r,t)}function $e(e){let t=E(e);return wt.get(t)??Object.freeze([t])}var Ts=["resource-query-empty","resource-query-invalid-limit","resource-not-found","resource-alias-ambiguous"];class F extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceQueryError"}}var He=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}),_n=Object.freeze(Object.keys(He)),It=new Map(_n.map((e,t)=>[e,t])),St=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 Rt(e){return new Set((e??[]).map(E).filter(Boolean))}function X(e,t){let r=Rt(t);if(r.size===0)return!0;let o=Rt(e);return[...r].some((n)=>o.has(n))}function Mn(e,t){if(!X(e.solution?.functions??[],t.functions))return!1;if(!X(e.solution?.scenarios??[],t.scenarios))return!1;if(!X(e.solution?[e.solution.unit]:[],t.units))return!1;if(!X(e.solution?.industries??[],t.industries))return!1;if(t.kinds?.length&&!t.kinds.includes(e.kind))return!1;if(!X(e.tags,t.tags))return!1;if(!X(e.category?[e.category]:[],t.categories))return!1;if(!X(e.capabilities,t.capabilities))return!1;if(t.maturities?.length&&!t.maturities.includes(e.receipt.maturity))return!1;return!0}function Ln(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,r,o=He[t]){if(e.some((n)=>n.code===t&&n.value===r))return;e.push({code:t,value:r,score:o})}function Ue(e,t){return e.find((r)=>E(r)===t)}function ze(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 jn(e,t,r){if(Math.abs(e.length-t.length)>r)return r+1;let o=Array.from({length:t.length+1},(n,a)=>a);for(let n=1;n<=e.length;n+=1){let a=[n],i=n;for(let s=1;s<=t.length;s+=1){let c=(o[s-1]??r+1)+(e[n-1]===t[s-1]?0:1),l=Math.min((o[s]??r+1)+1,(a[s-1]??r+1)+1,c);a.push(l),i=Math.min(i,l)}if(i>r)return r+1;o=a}return o[t.length]??r+1}function Pt(e,t){let r=E(t),o=[];if(E(e.id)===r)z(o,"exact-id",e.id);if(E(e.title)===r)z(o,"exact-title",e.title);let n=Ue(e.aliases,r);if(n)z(o,"alias",n);let a=Ue(e.tags,r);if(a)z(o,"tag",a);let i=Ue(e.capabilities,r);if(i)z(o,"capability",i);if(e.category&&E(e.category)===r)z(o,"category",e.category);if(!n){let l=$e(r).filter((u)=>u!==r),p=new Set(ze(e).map(E));if(l.some((u)=>p.has(u)))z(o,"alias",t.trim())}let s=r.split(" ").filter(Boolean),c=E(ze(e).join(" "));if(s.length>0&&s.every((l)=>c.includes(l)))z(o,"token",t.trim());if(o.length===0&&r.length>=4){let l;for(let p of ze(e)){let u=E(p);if(u.length<4)continue;let g=jn(r,u,2);if(g<=2&&(!l||g<l.distance||g===l.distance&&L(p,l.value)<0))l={value:p,distance:g}}if(l)z(o,"fuzzy",l.value,He.fuzzy-l.distance)}return o.sort((l,p)=>{if(l.score!==p.score)return p.score-l.score;return(It.get(l.code)??99)-(It.get(p.code)??99)||L(l.value,p.value)})}function At(e,t,r){if(t.has(r))return[r];let o=E(r),n=e.aliases[o];if(n?.length)return[...n];let a=new Set;for(let i of $e(o))for(let s of e.aliases[i]??[])a.add(s);return[...a].sort(L)}function Et(e,t){return new F("resource-alias-ambiguous",`${e.trim()}: ${t.join(",")}`)}function Ot(e){let t=new Map(e.resources.map((o)=>[o.id,o]));function r(o){let n=o.trim(),a=At(e,t,n);if(a.length===0)throw new F("resource-not-found",n);if(a.length>1)throw Et(n,a);let i=a[0],s=i?t.get(i):void 0;if(!s)throw new F("resource-not-found",n);return s}return Object.freeze({manifest:()=>e,search(o){let n=o.text?.trim()??"";if(!n&&!Ln(o))throw new F("resource-query-empty","text or filter is required");if(o.limit!==void 0&&(!Number.isInteger(o.limit)||o.limit<=0))throw new F("resource-query-invalid-limit",String(o.limit));let a=e.resources.filter((i)=>Mn(i,o)).filter((i)=>!n||Pt(i,n).length>0).map((i)=>{let s=n?Pt(i,n):[];for(let[c,l]of[[o.functions,"function"],[o.scenarios,"scenario"],[o.units,"unit"],[o.industries,"industry"]])if(c?.length)z(s,l,c.join(","));return{resource:i,score:s.reduce((c,l)=>c+l.score,0),reasons:s}}).filter((i)=>!n||i.reasons.length>0).sort((i,s)=>s.score-i.score||L(i.resource.id,s.resource.id));return o.limit===void 0?a:a.slice(0,o.limit)},get:r,build(o){if(o.length===0||o.every((g)=>!g.trim()))throw new F("resource-query-empty","at least one build root is required");let n=[],a=new Set;for(let g of o){let d=g.trim(),f=At(e,t,d);if(f.length===0)n.push({id:d,reason:"missing-resource"});else if(f.length>1)throw Et(d,f);else{let m=f[0];if(m)a.add(m)}}let i=new Set,s=new Set,c=new Set,l=[],p=[],u=(g,d)=>{if(i.has(g))return;if(s.has(g)){n.push({id:g,...d?{requiredBy:d}:{},reason:"dependency-cycle"});return}let f=t.get(g);if(!f){n.push({id:g,...d?{requiredBy:d}:{},reason:"missing-resource"});return}s.add(g),c.add(g);let m=[...f.dependencies].sort((y,k)=>{let b=t.get(y),h=t.get(k);return(St.get(b?.kind??"")??99)-(St.get(h?.kind??"")??99)||L(y,k)});for(let y of m)p.push({from:g,to:y,relation:"depends-on"}),u(y,g);s.delete(g),i.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 d=t.get(g);if(!d)throw new F("resource-not-found",g);return{id:g,kind:d.kind,maturity:d.receipt.maturity}}),edges:p.sort((g,d)=>L(g.from,d.from)||L(g.to,d.to)),order:l,gaps:n.sort((g,d)=>L(g.id,d.id)||L(g.requiredBy??"",d.requiredBy??"")||L(g.reason,d.reason))}}})}function Vn(e){if(!e||typeof e!=="object")throw Error("invalid-public-resource-bundle");Hn(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,o=new Set;for(let n of t.index.resources){if(!n||typeof n.id!=="string"||r.has(n.id)||!it.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((i)=>i.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/"))||!be.includes(n.receipt.maturity)||!st.includes(n.receipt.level)||!Array.isArray(n.receipt.evidence)||!n.receipt.evidence.every((i)=>typeof i==="string")||!le.every((i)=>ke.includes(n.receipt.checks?.[i])))throw Error("invalid-public-resource");if(r.add(n.id),n.solution){let i=n.solution;if(![i.functions,i.scenarios,i.industries,i.hostRequirements,i.limitations].every((s)=>Array.isArray(s)&&s.every((c)=>typeof c==="string"&&c.length>0&&c.length<=2000))||!["page","flow","industry"].includes(i.unit)||!["interactive-demo","needs-enhancement"].includes(i.readiness)||i.members!==void 0&&(!Array.isArray(i.members)||i.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 i=a.collection;if(!i||typeof i.id!=="string"||!/^[a-z0-9-]+$/.test(i.id)||typeof i.group?.id!=="string"||!/^[a-z0-9-]+$/.test(i.group.id)||[i.title,i.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 i=a.agentKit;if(o.has(n.source?.id))throw Error("invalid-resource-agent-kit");if(o.add(n.source?.id),!i||!["skill","prompt","recipe"].includes(i.type)||(i.type==="skill"?n.kind!=="skill":n.kind!=="example")||!/^[a-z][a-z0-9-]*$/.test(n.source.id)||i.fileName!=={skill:"SKILL.md",prompt:"PROMPT.md",recipe:"RECIPE.md"}[i.type]||[i.summary?.zh,i.summary?.en].some((s)=>typeof s!=="string"||!s.trim())||!Array.isArray(i.resources)||new Set(i.resources.map((s)=>s?.id)).size!==i.resources.length||i.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)))||i.resources.length!==n.dependencies.length)throw Error("invalid-resource-agent-kit")}if(a.solutionControls!==void 0){let i=new Set;if(!Array.isArray(a.solutionControls)||a.solutionControls.some((s)=>{if(!s||typeof s.id!=="string"||i.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 i.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((i)=>!i||typeof i.id!=="string"||typeof i.title!=="string"||typeof i.code!=="string"||!["spec","tsx","source"].includes(i.mode)||!["tsx","json","yaml","css","ts"].includes(i.language)||!Array.isArray(i.dependencies)||!i.dependencies.every((s)=>typeof s==="string"))||a.distributions.some((i)=>!i||!["spec","npm","shadcn"].includes(i.channel)||typeof i.name!=="string"||!/^[@a-zA-Z0-9._/-]+$/.test(i.name)||typeof i.version!=="string"||!["source","published"].includes(i.availability)||i.connections!==void 0&&(i.channel!=="spec"||!Array.isArray(i.connections)||i.connections.some((s)=>typeof s!=="string"||!s))))throw Error("invalid-resource-content")}for(let[n,a]of Object.entries(t.index.aliases))if(!n||!Array.isArray(a)||a.some((i)=>!r.has(i)))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,i])=>!Object.hasOwn(n.unavailable,a)||!Array.isArray(i)||i.some((s)=>typeof s!=="string"||s.startsWith("@uibot/"))))throw Error("invalid-distribution-snapshot-reference");for(let[a,i]of Object.entries(n.resources))if(!r.has(a)||i.version!==(t.index.resources.find((s)=>s.id===a)?.source.version??t.release.version)||!/^[a-f0-9]{64}$/.test(i.resourceHash)||!Array.isArray(i.entrypoints)||!i.entrypoints.length||!Array.isArray(i.closure)||![...i.entrypoints,...i.closure].every((s)=>/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(s))||i.entrypoints.some((s)=>!i.closure.includes(s)))throw Error("invalid-distribution-snapshot-resource")}}function Ms(e){Vn(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=Ot(e.index),o=(n)=>{let a=r.get(n),i=e.showcases[a.id];if(!i)throw new F("resource-not-found",a.id);return i};return Object.freeze({...r,get(n){let a=r.get(n),i=o(n).agentKit;return i?Object.freeze({...a,agentKit:i}):a},docs(n,a="zh",i=1){if(a!=="zh"&&a!=="en")throw Error("unsupported-resource-locale");let s=o(n);return{resourceId:s.resourceId,locale:a,...Un(s.docs[a],i),release:e.release}},examples(n,a=1){let i=o(n);return{resourceId:i.resourceId,...zn(i.examples,a),release:e.release}},installPlan(n){let a=o(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((i)=>$n(i,e.distributionSnapshot,a.resourceId))}}})}var Fn={Collection:{real:"@uibot/application/data-gateway (server only; nowapi/http/pg bindings)",demo:"createMockCollectionConnectionDriver from @uibot/connection-mock/browser"}};function $n(e,t,r){let{channel:o,name:n,version:a}=e;if(o==="npm")return{channel:o,name:n,command:`add ${n}@${a}`,note:null};if(o==="spec"){let c=Object.entries(e.dependencies??{}).map(([l,p])=>`${l}@${p}`);return{channel:o,name:n,command:c.length?`add ${c.join(" ")}`:null,drivers:(e.connections??[]).map((l)=>({type:l,...Fn[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 i=!!t&&Object.hasOwn(t.resources,r),s=t?.external[r]??[];return{channel:o,name:n,command:`shadcn add @uibot/${n}`,registries:{"@uibot":"/r/{name}.json"},externalRegistryDependencies:s,note:i?"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 Y=24000;function Tt(e,t){if(!Number.isSafeInteger(e)||e<1||e>Math.max(1,t))throw new F("resource-query-invalid-limit","page is outside the available range")}function Un(e,t){let r=Math.max(1,Math.ceil(e.length/Y));return Tt(t,r),{markdown:e.slice((t-1)*Y,t*Y),page:t,totalPages:r,...t<r?{nextPage:t+1}:{}}}function zn(e,t){let r=e.flatMap((o)=>Array.from({length:Math.max(1,Math.ceil(o.code.length/Y))},(n,a)=>({...o,code:o.code.slice(a*Y,(a+1)*Y),codeOffset:a*Y,codeLength:o.code.length,complete:o.code.length<=Y})));return Tt(t,r.length),{examples:r.slice(t-1,t),page:t,totalPages:r.length,...t<r.length?{nextPage:t+1}:{}}}function Hn(e){let t=0,r=0,o=new Set,n=(a,i)=>{if(++t>300000||i>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(o.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");o.add(a);for(let[c,l]of Object.entries(a))n(c,i+1),n(l,i+1);o.delete(a)}else if(a!==null&&typeof a!=="boolean"&&(typeof a!=="number"||!Number.isFinite(a)))throw Error("invalid-public-resource-json")};n(e,1)}var qn=(e)=>e.length>0&&!["__proto__","constructor","prototype"].includes(e);function me(e){return e.flatMap((t)=>[t,...me(t.children??[]),...Object.values(t.slots??{}).flatMap(me)])}function Se(e,t,r){let o=structuredClone(e);for(let[n,a]of Object.entries(r)){let i=t.find((c)=>c.id===n);if(!i?.values.includes(a)||!qn(i.target.property))throw Error(`invalid-solution-control:${n}`);let s=o.pages?.find((c)=>c.id===i.target.pageId);if(!s)throw Error(`solution-page-missing:${n}`);if(i.target.blockId){let c=me(s.blocks).filter((p)=>p.id===i.target.blockId),l=c[0];if(c.length!==1||!l)throw Error(`solution-block-missing:${n}`);l.props={...l.props,[i.target.property]:a}}else s.state={...s.state,[i.target.property]:a}}return o}function ye(e,t,r={}){let o=new Set((e.pages??[]).map((s)=>s.id)),n=new Set((e.pages??[]).map((s)=>s.path)),a=new Set((e.pages??[]).flatMap((s)=>me(s.blocks).flatMap((c)=>c.id?[c.id]:[])));for(let s of t.pages??[]){if(o.has(s.id)||n.has(s.path))throw Error(`solution-page-conflict:${s.id}:${s.path}`);o.add(s.id),n.add(s.path);for(let c of me(s.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(r.addNavigation){let s=new Set((e.menus?.items??[]).map((c)=>c.key));for(let c of t.pages)if(s.has(`solution:${c.id}`))throw Error(`solution-navigation-conflict:${c.id}`)}let i=r.addNavigation?{...structuredClone(e.menus),items:[...structuredClone(e.menus?.items??[]),...t.pages.map((s)=>({key:`solution:${s.id}`,label:s.title??s.id,path:s.path}))]}:e.menus;return{...structuredClone(e),...i?{menus:structuredClone(i)}:{},pages:[...structuredClone(e.pages??[]),...structuredClone(t.pages??[])]}}function w(e){if(Array.isArray(e))return`[${e.map(w).join(",")}]`;if(e&&typeof e==="object")return`{${Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[r])=>t<r?-1:t>r?1:0).map(([t,r])=>`${JSON.stringify(t)}:${w(r)}`).join(",")}}`;return JSON.stringify(e)??"null"}var Re=(e)=>typeof e==="string"&&e.length>0&&!["__proto__","prototype","constructor"].includes(e);function Bt(e){if(!Re(e.resourceId)||!Re(e.version)||!/^[a-f0-9]{64}$/.test(e.sourceHash))throw Error("invalid-solution-identity")}function qe(e,t,r,o=e.id){let n=structuredClone(e);if(n.id=o,n.path=r.paths[e.path]??e.path,!Re(n.id)||typeof n.path!=="string"||!n.path.startsWith("/"))throw Error("invalid-solution-page-target");if(r.frame)n.blocks=n.blocks.map((i)=>i.type==="PageLayout"?{...i,props:{...i.props,...structuredClone(r.frame?.props)},slots:{...i.slots,...structuredClone(r.frame?.slots)},events:{...i.events,...structuredClone(r.frame?.events)}}:i);let a=(i)=>{if(!i||typeof i!=="object")return;for(let[s,c]of Object.entries(i))if(typeof c==="string"){if(s==="connectionId"&&r.connections[c])i[s]=r.connections[c];else if(["href","path","url","redirect","currentPath"].includes(s)&&r.paths[c])i[s]=r.paths[c]}else a(c)};if(a(n),r.layout==="source"&&t.layout&&n.blocks.some((i)=>i.type==="PageLayout"))n.layout={...structuredClone(t.layout),...n.layout,inherit:!1};return n}function Ke(e,t){if(!t.data)return structuredClone(e.data);let r=structuredClone(e.data?.entities??{});for(let[o,n]of Object.entries(t.data.entities)){if(Object.hasOwn(r,o)&&w(r[o])!==w(n))throw Error(`solution-entity-conflict:${o}`);Object.defineProperty(r,o,{value:structuredClone(n),enumerable:!0,writable:!0,configurable:!0})}return W({entities:r})}function Pe(e,t,r){Ke(e,t);let o=structuredClone(e.connections??[]);for(let n of t.connections??[]){let a=r[n.id];if(!a||!Re(a))throw Error(`solution-connection-binding-required:${n.id}`);let i=o.find((s)=>s.id===a);if(i&&i.type!==n.type)throw Error(`solution-connection-type-conflict:${n.id}:${a}`);if(i&&i.entity!==n.entity)throw Error(`solution-connection-entity-conflict:${n.id}:${a}`);if(!i)o.push({id:a,type:n.type,entity:n.entity,...n.mock?{mock:structuredClone(n.mock)}:{}})}return o}function We(e,t,r,o){let n=new Set([...e.pages,...r].map((c)=>c.path)),a=new Set(t.pages.map((c)=>o.paths[c.path]??c.path)),i=new Set(Pe(e,t,o.connections).map((c)=>c.id)),s=(c)=>{if(!c||typeof c!=="object")return;for(let[l,p]of Object.entries(c))if(typeof p==="string"){if(l==="connectionId"&&!i.has(p))throw Error(`solution-connection-missing:${p}`);if(["href","url","redirect","path"].includes(l)&&a.has(p)&&!n.has(p))throw Error(`solution-route-dependency-missing:${p}`)}else s(p)};for(let c of r)s(c)}function Dt(e,t,r){if(Bt(t.identity),O(e),t.spec.auth)throw Error("solution-host-auth-required");let o=Se(t.spec,t.controls??[],r.configuration??{}),n={paths:{...r.paths},connections:{...r.connections},layout:r.layout,...r.frame?{frame:structuredClone(r.frame)}:{}},a=Pe(e,o,n.connections),i=r.selectedPageIds?o.pages.filter((u)=>r.selectedPageIds?.includes(u.id)):o.pages;if(!i.length||r.selectedPageIds&&i.length!==new Set(r.selectedPageIds).size)throw Error("solution-select-pages");let s=i.map((u)=>qe(u,o,n,r.pageIds?.[u.id]??u.id));We(e,t.spec,s,n);let c=ye(e,{version:"2.0",pages:s},{addNavigation:r.addNavigation??!1}),l=i.map((u,g)=>({...t.identity,sourcePageId:u.id,targetPageId:s[g]?.id??u.id,baseline:structuredClone(s[g]),bindings:structuredClone(n),...r.configuration?{configuration:structuredClone(r.configuration)}:{}}));if(c.composition={...structuredClone(e.composition),schema:"uibot.solution-composition.v1",pages:[...structuredClone(e.composition?.pages??[]),...l]},a.length)c.connections=a;let p=Ke(e,o);if(p)c.data=p;return{spec:c,pages:s.map((u)=>({id:u.id,path:u.path})),connections:a.filter((u)=>!e.connections?.some((g)=>g.id===u.id)),layout:r.layout}}function Kn(e,t,r={}){Bt(t.identity),O(e);let o=[];for(let n of e.composition?.pages??[]){if(n.resourceId!==t.identity.resourceId||n.detached)continue;let a=e.pages.find((c)=>c.id===n.targetPageId),i=t.spec.pages.find((c)=>c.id===n.sourcePageId),s={pageId:n.targetPageId,path:a?.path??n.baseline.path,from:{resourceId:n.resourceId,version:n.version,sourceHash:n.sourceHash},to:t.identity};if(!a){o.push({...s,status:"deleted-locally"});continue}if(!i){o.push({...s,status:"removed"});continue}try{let c=Se(t.spec,t.controls??[],n.configuration??{}),l={...n.bindings,connections:{...n.bindings.connections,...r}};if(Pe(e,c,l.connections),c.auth)throw Error("solution-host-auth-required");let p=qe(c.pages.find((f)=>f.id===i.id),c,l,a.id),u=e.pages.flatMap((f)=>{if(f.id===a.id)return[];let m=e.composition?.pages.find((k)=>k.resourceId===t.identity.resourceId&&k.targetPageId===f.id&&!k.detached),y=c.pages.find((k)=>k.id===m?.sourcePageId);return m&&y?[{...f,path:m.bindings.paths[y.path]??y.path}]:[f]});We({...e,pages:u},c,[p],l);let g=w(a)!==w(n.baseline),d=w(p)!==w(n.baseline);o.push({...s,nextPath:p.path,incoming:p,status:g?d?"conflict":"customized":d?"update":"unchanged"})}catch(c){o.push({...s,status:"blocked",error:String(c)})}}return{pages:o,tracked:o.length>0}}function $s(e,t,r,o={}){let n=Kn(e,t,o),a=structuredClone(e);if(n.pages.some((i)=>["conflict","removed","deleted-locally"].includes(i.status)&&!r[i.pageId]))throw Error("solution-upgrade-unresolved");for(let[i,s]of Object.entries(r)){let c=n.pages.find((m)=>m.pageId===i),l=a.composition?.pages.find((m)=>m.targetPageId===i);if(!c||!l)throw Error(`solution-untracked-page:${i}`);if(c.status==="blocked")throw Error(`solution-upgrade-blocked:${i}`);if(s==="detach"){l.detached=!0;continue}if(["removed","deleted-locally"].includes(c.status))throw Error(`solution-upgrade-detach-required:${i}`);if(s==="update"&&["conflict","customized"].includes(c.status))throw Error(`solution-upgrade-conflict:${i}`);if(!["update","replace","keep"].includes(s))throw Error("invalid-solution-upgrade-decision");let p=Se(t.spec,t.controls??[],l.configuration??{});l.bindings.connections={...l.bindings.connections,...o};let u=p.pages.find((m)=>m.id===l.sourcePageId);if(!u)throw Error(`solution-page-missing:${i}`);let g=qe(u,p,l.bindings,i);if(s!=="keep"){let m=a.pages.find((y)=>y.id===i)?.path;if(a.pages=a.pages.map((y)=>y.id===i?g:y),m&&m!==g.path){let y=(k)=>{if(!k||typeof k!=="object")return;for(let[b,h]of Object.entries(k))if(["path","href"].includes(b)&&h===m)k[b]=g.path;else if(typeof h==="object")y(h)};y(a.menus);for(let k of a.pages)for(let b of k.blocks)if(b.type==="PageLayout")y(b.props?.routes),y(b.slots?.sidebar)}}l.baseline=structuredClone(g),Object.assign(l,t.identity);let d=Pe(a,p,l.bindings.connections);if(d.length)a.connections=d;let f=Ke(a,p);if(f)a.data=f}ye({version:"2.0",pages:[]},{version:"2.0",pages:a.pages});for(let[i,s]of Object.entries(r))if(s!=="detach"){let c=a.composition?.pages.find((p)=>p.targetPageId===i),l=a.pages.find((p)=>p.id===i);if(c&&l)We(a,{...t.spec,pages:[...t.spec.pages,...e.pages]},a.pages,c.bindings)}return a}function J(e,t=160){let r=typeof e==="string"?e:JSON.stringify(e)??String(e);if(r.length<=t)return r;return`${r.slice(0,t-3)}...`}function ie(e){return e.flatMap((t)=>[t,...ie(t.children??[]),...Object.values(t.slots??{}).flatMap(ie)])}function Nt(e){if(e?.type!=="Box"||e.template||e.slots||e.events||e.visible!==void 0)throw Error("solution-region-slot-invalid");return e}function _t(e,t){let r=ie(e).filter((o)=>o.id===t);if(r.length!==1)return;return r[0]}function Ge(e,t){return Nt(_t([e],t))}function Wn(e,t){return ie([e]).some((r)=>r.id===t)}function Ye(e,t,r,o){if(e.type!==t.type){o.push({code:"unmapped-block",path:`${r}.type`,message:`Outer frame block type changed from "${t.type}" to "${e.type}".`,preservedSummary:J(e)});return}let n=new Set([...Object.keys(e.props??{}),...Object.keys(t.props??{})]);for(let p of n){let u=e.props?.[p],g=t.props?.[p];if(w(u)!==w(g))o.push({code:"unmapped-frame-prop",path:`${r}.props.${p}`,message:`Customized outer frame prop "${p}" does not map automatically to the replacement frame.`,preservedSummary:`${p}=${J(u??null)}`})}let a=new Set([...Object.keys(e.events??{}),...Object.keys(t.events??{})]);for(let p of a){let u=e.events?.[p],g=t.events?.[p];if(w(u)!==w(g))o.push({code:"unmapped-event",path:`${r}.events.${p}`,message:`Customized outer frame event "${p}" does not map automatically to the replacement frame.`,preservedSummary:`${p}:${J(u??null)}`})}if(w(e.visible)!==w(t.visible))o.push({code:"unmapped-frame-prop",path:`${r}.visible`,message:"Customized outer frame visibility condition does not map to the replacement frame.",preservedSummary:`visible=${J(e.visible??null)}`});let i=e.children??[],s=t.children??[],c=Math.min(i.length,s.length);for(let p=0;p<c;p++){let u=i[p],g=s[p];if(u&&g)Ye(u,g,`${r}.children[${p}]`,o)}for(let p=c;p<i.length;p++){let u=i[p];if(u)o.push({code:"unmapped-block",path:`${r}.children[${p}]`,message:"Additional block inside outer frame was not carried over into the new frame.",preservedSummary:J(u)})}let l=new Set([...Object.keys(e.slots??{}),...Object.keys(t.slots??{})]);for(let p of l){let u=e.slots?.[p]??[],g=t.slots?.[p]??[],d=Math.min(u.length,g.length);for(let f=0;f<d;f++){let m=u[f],y=g[f];if(m&&y)Ye(m,y,`${r}.slots.${p}[${f}]`,o)}for(let f=d;f<u.length;f++){let m=u[f];if(m)o.push({code:"unmapped-block",path:`${r}.slots.${p}[${f}]`,message:`Additional block in frame slot "${p}" was not carried over into the new frame.`,preservedSummary:J(m)})}}}function Je(e,t,r,o){if(O(e),!t.identity.resourceId||!t.identity.version||!/^[a-f0-9]{64}$/.test(t.identity.sourceHash))throw Error("invalid-solution-identity");let n=Object.entries(r);if(!n.length||n.some(([s,c])=>!s||!c)||new Set(n.map(([,s])=>s)).size!==n.length)throw Error("solution-region-explicit-mapping-required");let a=structuredClone(e),i=[];for(let[s,c]of n){let l=a.pages.findIndex((k)=>k.id===c),p=l>=0?a.pages[l]:void 0;if(!p||ie(p.blocks).some((k)=>k.type==="PageLayout"))throw Error(`solution-region-independent-page-required:${c}`);let u=p.blocks,g=a.composition?.regions?.find((k)=>k.targetPageId===c);if(g)if(o?.strictBaseline){if(p.blocks.length!==1||!p.blocks[0])throw Error("solution-region-frame-customized");let k=structuredClone(p.blocks[0]),b=Ge(k,g.contentBlockId);if(u=b.children??[],b.children=[],w(k)!==w(g.baseline))throw Error("solution-region-frame-customized")}else{let k=structuredClone(p.blocks),b=_t(k,g.contentBlockId);if(!b)i.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:J(p.blocks)}),u=p.blocks;else{let h=Nt(b);u=h.children??[],h.children=[];let x=k.findIndex((S)=>Wn(S,g.contentBlockId)),P=x>=0?k[x]:void 0;if(P)Ye(P,g.baseline,`pages[${l}].blocks[${x}]`,i);for(let S=0;S<k.length;S++){if(S===x)continue;let I=k[S];if(I)i.push({code:"unmapped-block",path:`pages[${l}].blocks[${S}]`,message:"Extra sibling block outside the frame content slot was not mapped to the new frame.",preservedSummary:J(I)})}}}let d=structuredClone(t.frame);if(Ge(d,t.contentBlockId).children?.length)throw Error("solution-region-slot-not-empty");for(let k of ie([d]))if(k.id)k.id=`${c}-${k.id}`;let f=`${c}-${t.contentBlockId}`,m=structuredClone(d);Ge(d,f).children=structuredClone(u),p.blocks=[d];let y={...t.identity,targetPageId:c,role:s,target:"page-frame",contentBlockId:f,baseline:m};a.composition??={schema:"uibot.solution-composition.v1",pages:[]},a.composition.regions=[...(a.composition.regions??[]).filter((k)=>k.targetPageId!==c),y]}return ye({version:"2.0",pages:[]},{version:"2.0",pages:a.pages}),O(a),{spec:a,unmappedWarnings:i}}function Ws(e,t,r,o){return Je(e,t,r,o).spec}function Ys(e,t){let r=t[e.type]?.replacement?.family;if(!r)return[];return Object.entries(t).flatMap(([o,n])=>n.replacement?.family===r?n.replacement.variants.map((a)=>({component:o,variant:a.id,title:a.title})):[])}function Js(e,t,r,o){let n=t[e.type],a=t[r.component],i=a?.replacement?.variants.find((l)=>l.id===r.variant);if(!n?.replacement||n.replacement.family!==a?.replacement?.family||!i)throw Error("replacement-incompatible");if(e.template||e.variant)throw Error("replacement-template-unsupported");let s=structuredClone(e),c={...s.props};for(let l of n.replacement.presentationProps??[]){if(c[l]&&typeof c[l]==="object")throw Error(`replacement-bound-presentation:${l}`);delete c[l]}for(let l of Object.keys(i.props??{}))if(!a.replacement?.presentationProps?.includes(l))throw Error(`replacement-invalid-presentation:${l}`);Object.assign(c,structuredClone(i.props??{}));for(let l of Object.keys(c))if(!Object.hasOwn(a.props??{},l))throw Error(`replacement-unmapped-property:${l}`);for(let l of Object.keys(e.events??{}))if(!Object.hasOwn(a.events??{},l)||JSON.stringify(n.events?.[l])!==JSON.stringify(a.events?.[l]))throw Error(`replacement-unmapped-event:${l}`);if(e.children?.length&&!a.slots?.children)throw Error("replacement-unmapped-children");for(let l of Object.keys(e.slots??{}))if(!a.slots?.[l]||a.slots[l]?.type!==n.slots?.[l]?.type)throw Error(`replacement-unmapped-slot:${l}`);if(s.type=r.component,s.props=c,!s.id&&o)s.id=o;return s}var Gn=[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 ae(e){let t=new TextEncoder().encode(e),r=t.length*8,o=Math.ceil((t.length+9)/64)*64,n=new Uint8Array(o);n.set(t),n[t.length]=128;let a=new DataView(n.buffer),i=Math.floor(r/4294967296),s=r>>>0;a.setUint32(o-8,i,!1),a.setUint32(o-4,s,!1);let c=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],l=new Uint32Array(64),p=(u,g)=>u>>>g|u<<32-g;for(let u=0;u<o;u+=64){for(let x=0;x<16;x++)l[x]=a.getUint32(u+x*4,!1);for(let x=16;x<64;x++){let P=l[x-15]??0,S=l[x-2]??0,I=p(P,7)^p(P,18)^P>>>3,_=p(S,17)^p(S,19)^S>>>10;l[x]=(l[x-16]??0)+I+(l[x-7]??0)+_>>>0}let[g,d,f,m,y,k,b,h]=c;for(let x=0;x<64;x++){let P=p(y,6)^p(y,11)^p(y,25),S=y&k^~y&b,I=h+P+S+(Gn[x]??0)+(l[x]??0)>>>0,_=p(g,2)^p(g,13)^p(g,22),C=g&d^g&f^d&f,T=_+C>>>0;h=b,b=k,k=y,y=m+I>>>0,m=f,f=d,d=g,g=I+T>>>0}c[0]=(c[0]??0)+g>>>0,c[1]=(c[1]??0)+d>>>0,c[2]=(c[2]??0)+f>>>0,c[3]=(c[3]??0)+m>>>0,c[4]=(c[4]??0)+y>>>0,c[5]=(c[5]??0)+k>>>0,c[6]=(c[6]??0)+b>>>0,c[7]=(c[7]??0)+h>>>0}return c.map((u)=>u.toString(16).padStart(8,"0")).join("")}function j(e,t=160){let r=typeof e==="string"?e:JSON.stringify(e)??String(e);if(r.length<=t)return r;return`${r.slice(0,t-3)}...`}function ta(e=[]){let t=new Map,r=(o)=>{Me(o),t.set(o.familyId,structuredClone(o))};for(let o of e)r(o);return{register:r,get:(o)=>{let n=t.get(o);return n?structuredClone(n):void 0},list:(o)=>Mt([...t.values()],o)}}function Yn(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((r)=>r.resourceId===t.resourceId||r.identity?.resourceId===t.resourceId))return!1;if(t.query){let r=t.query.trim().toLowerCase();if(r){if(![e.familyId,e.title.zh,e.title.en,e.description,...e.variants.flatMap((n)=>[n.id,n.title.zh,n.title.en,n.description,n.resourceId??""])].join(`
5
+ `).toLowerCase().includes(r))return!1}}return!0}function Mt(e,t){return e.filter((r)=>Yn(r,t)).map((r)=>structuredClone(r))}function Ee(e,t){if(!Array.isArray(e)&&"list"in e&&typeof e.list==="function")return e.list(t);return Mt(e,t)}function na(e){let t=new Map;for(let[o,n]of Object.entries(e)){let a=n.replacement?.family;if(!a)continue;let i=t.get(a)??[];i.push({component:o,entry:n}),t.set(a,i)}let r=[];for(let[o,n]of t.entries()){let a=Array.from(new Set(n.flatMap((l)=>l.entry.replacement?.presentationProps??[]))),i=new Map,s=(l,p)=>{if(!i.has(l))i.set(l,{id:l,label:{zh:l,en:l},preserveMode:p})};for(let{entry:l}of n){let p=new Set(l.replacement?.presentationProps??[]);for(let u of Object.keys(l.props??{}))if(!p.has(u))s(`prop:${u}`,"when-customized");for(let u of Object.keys(l.events??{}))s(`event:${u}`,"always");for(let u of Object.keys(l.slots??{}))s(`slot:${u}`,"always")}let c=[];for(let{component:l,entry:p}of n){let u=new Set(p.replacement?.presentationProps??[]),g={};for(let d of Object.keys(p.props??{}))if(!u.has(d))g[`prop:${d}`]={kind:"block-prop",property:d};for(let d of Object.keys(p.events??{}))g[`event:${d}`]={kind:"block-events",property:d};for(let d of Object.keys(p.slots??{}))g[`slot:${d}`]=d==="children"?{kind:"block-children"}:{kind:"block-children",property:d};for(let d of p.replacement?.variants??[])c.push({id:`${l}:${d.id}`,title:{zh:d.title,en:d.title},description:p.description,resourceId:`component:${l.toLowerCase()}`,slotBindings:structuredClone(g),blockTemplate:{type:l,...d.props?{props:structuredClone(d.props)}:{}}})}if(c.length>0){let l=n[0];r.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:[...i.values()],presentationProps:a,variants:c})}}return r}function se(e,t,r){for(let o=0;o<e.length;o++){let n=e[o];if(!n)continue;let a=`${t}[${o}]`;if(r({node:n,path:a}),n.children?.length)se(n.children,`${a}.children`,r);for(let[i,s]of Object.entries(n.slots??{}))se(s,`${a}.slots.${i}`,r)}}function Xe(e,t,r){let o=[];return se(e,r,(n)=>{if(t.blockIdSuffix){let a=n.node.id??"";if(a===t.blockIdSuffix||a.endsWith(`-${t.blockIdSuffix}`))o.push(n);return}if(t.blockType){if(n.node.type===t.blockType)o.push(n);return}o.push(n)}),o[t.occurrence??0]}function ee(e,t,r){if(t.kind==="page-field"){let n=t.property??"";return{value:e[n],path:`${r}.${n}`}}let o=Xe(e.blocks,t,`${r}.blocks`);if(!o)return{value:void 0,path:`${r}.blocks`};if(t.kind==="block-node")return{value:o.node,path:o.path,locatedNodePath:o.path};if(t.kind==="block-prop"){let n=t.property??"";return{value:o.node.props?.[n],path:`${o.path}.props.${n}`,locatedNodePath:o.path}}if(t.kind==="block-events"){let n=t.property;return{value:n?o.node.events?.[n]:o.node.events,path:n?`${o.path}.events.${n}`:`${o.path}.events`,locatedNodePath:o.path}}if(t.kind==="block-children"){let n=t.property;return{value:n?o.node.slots?.[n]:o.node.children,path:n?`${o.path}.slots.${n}`:`${o.path}.children`,locatedNodePath:o.path}}return{value:void 0,path:r}}function Jn(e,t,r,o){let n={...structuredClone(e.props)};for(let[a,i]of Object.entries(t.props??{})){let s=r?.props?.[a];if(i!==null&&typeof i==="object"&&!Array.isArray(i)||!r||w(i)!==w(s))n[a]=structuredClone(i)}if(Object.keys(n).length>0)e.props=n;if(t.visible!==void 0)e.visible=structuredClone(t.visible);if(t.events&&(!r||w(t.events)!==w(r.events)))e.events=structuredClone(t.events);else if(!e.events&&t.events)e.events=structuredClone(t.events);if(t.children&&(!r||w(t.children)!==w(r.children)))e.children=structuredClone(t.children);else if(!e.children&&t.children)e.children=structuredClone(t.children);if(t.slots&&(!r||w(t.slots)!==w(r.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 Lt(e,t,r,o,n){if(t.kind==="page-field"){let i=t.property;if(!i||["__proto__","prototype","constructor"].includes(i))return!1;return e[i]=structuredClone(r),!0}let a=Xe(e.blocks,t,"page.blocks");if(!a)return!1;if(t.kind==="block-node"){if(!r||typeof r!=="object")return!1;return Jn(a.node,r,o&&typeof o==="object"?o:void 0,n),!0}if(t.kind==="block-prop"){let i=t.property;if(!i)return!1;return a.node.props??={},a.node.props[i]=structuredClone(r),!0}if(t.kind==="block-events"){let i=t.property;if(i)a.node.events??={},a.node.events[i]=structuredClone(r);else if(r&&typeof r==="object")a.node.events=structuredClone(r);return!0}if(t.kind==="block-children"){let i=t.property;if(i)a.node.slots??={},a.node.slots[i]=structuredClone(r);else a.node.children=structuredClone(r);return!0}return!1}function Zn(e,t){se(e,"",({node:r})=>{if(r.id)t.add(r.id)})}function Qn(e,t){let r=new Set;for(let o of e){if(o.id===t)continue;Zn(o.blocks,r)}return r}function Xn(e,t,r){let o=new Set,n=(a)=>{let i=`${r}-${a}`;if(t.has(i)||o.has(i)){let s=2;while(t.has(`${i}-${s}`)||o.has(`${i}-${s}`))s+=1;i=`${i}-${s}`}return i};se(e,"",({node:a})=>{if(!a.id)return;if(t.has(a.id)||o.has(a.id))a.id=n(a.id);o.add(a.id)})}function er(e,t,r){let o=new Set;if(!t)return o;for(let n of Object.values(t.slotBindings)){if(n.kind==="page-field")continue;let a=Xe(e.blocks,n,`${r}.blocks`);if(!a)continue;if(n.kind==="block-node")o.add(`${a.path}.*`);else if(n.kind==="block-prop"&&n.property)o.add(`${a.path}.props.${n.property}`);else if(n.kind==="block-events")o.add(n.property?`${a.path}.events.${n.property}`:`${a.path}.events.*`);else if(n.kind==="block-children")o.add(n.property?`${a.path}.slots.${n.property}`:`${a.path}.children`)}return o}function Ze(e,t,r,o,n){let a=Math.min(e.length,t.length);for(let i=0;i<a;i++){let s=e[i],c=t[i];if(!s||!c)continue;let l=`${r}[${i}]`;if(o.has(`${l}.*`))continue;if(s.type!==c.type){n.push({code:"unmapped-block",path:l,message:`Customized block "${s.type}" does not match template structure "${c.type}".`,preservedSummary:j(s)});continue}let p=new Set([...Object.keys(s.props??{}),...Object.keys(c.props??{})]);for(let d of p){let f=`${l}.props.${d}`;if(o.has(f))continue;let m=s.props?.[d],y=c.props?.[d];if(w(m)!==w(y))n.push({code:"unmapped-frame-prop",path:f,message:`Customized layout prop "${d}" cannot be projected onto target variant.`,preservedSummary:`${d}=${j(m??null)}`})}let u=new Set([...Object.keys(s.events??{}),...Object.keys(c.events??{})]);for(let d of u){let f=`${l}.events.${d}`;if(o.has(`${l}.events.*`)||o.has(f))continue;let m=s.events?.[d],y=c.events?.[d];if(w(m)!==w(y))n.push({code:"unmapped-event",path:f,message:`Customized event "${d}" outside semantic slots cannot be mapped.`,preservedSummary:`${d}:${j(m??null)}`})}if(!o.has(`${l}.children`))Ze(s.children??[],c.children??[],`${l}.children`,o,n);let g=new Set([...Object.keys(s.slots??{}),...Object.keys(c.slots??{})]);for(let d of g){if(o.has(`${l}.slots.${d}`))continue;Ze(s.slots?.[d]??[],c.slots?.[d]??[],`${l}.slots.${d}`,o,n)}}for(let i=a;i<e.length;i++){let s=e[i];if(!s)continue;let c=`${r}[${i}]`;if(o.has(`${c}.*`))continue;n.push({code:"unmapped-block",path:c,message:"Extra user-added block outside semantic slots is not in target variant.",preservedSummary:j(s)})}}function tr(e,t){let r=e.variants.find((a)=>a.id===t);if(r)return r;let o=e.variants.find((a)=>a.aliases?.includes(t));if(o)return o;let n=e.variants.filter((a)=>a.id.endsWith(`:${t}`));if(n.length===1&&n[0])return n[0];throw Error(`unknown-variant:${e.familyId}:${t}`)}function Oe(e,t){e.composition??={schema:"uibot.solution-composition.v1",pages:[]},e.composition.variants=[...(e.composition.variants??[]).filter((r)=>!(r.targetKind===t.targetKind&&r.targetId===t.targetId&&r.familyId===t.familyId)),t]}function nr(e,t,r){let o=e.composition?.variants?.find((s)=>s.targetKind==="page"&&s.targetId===t.id&&s.familyId===r.familyId);if(o){let s=r.variants.find((c)=>c.id===o.variantId);if(s)return s}let n=e.composition?.pages.find((s)=>s.targetPageId===t.id);if(n){let s=r.variants.find((c)=>c.resourceId===n.resourceId);if(s)return s}let a,i=-1;for(let s of r.variants){let c=s.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 p of r.semanticSlots){let u=s.slotBindings[p.id];if(!u||u.kind==="page-field")continue;let g=ee(t,u,"page"),d=ee(c,u,"template");if(g.value!==void 0){if(l+=2,w(g.value)===w(d.value))l+=3}}if(c.state&&t.state)for(let[p,u]of Object.entries(c.state)){if(p==="currentPath")continue;if(p in t.state){if(l+=1,w(t.state[p])===w(u))l+=2}}if(l>i)i=l,a=s}return a}function rr(e,t,r,o){let n=o.preserveCustomizations??!0,a=o.target.pageId??(e.pages.length===1?e.pages[0]?.id:void 0),i=e.pages.findIndex((h)=>h.id===a);if(i<0)throw Error(`unknown-variant-target-page:${o.target.pageId??""}`);let s=e.pages[i];if(!s||!r.pageTemplate)throw Error(`missing-variant-payload:${t.familyId}:${r.id}`);let c=nr(e,s,t),l=c?.pageTemplate,p=`pages[${i}]`,u=Qn(e.pages,s.id),g=[];for(let h of t.semanticSlots){let x=c?.slotBindings[h.id]??r.slotBindings[h.id];if(!x)continue;let P=ee(s,x,p);if(P.value===void 0)continue;let S=l?ee(l,x,"baseline"):{value:void 0,path:"baseline"},I=S.value===void 0||w(P.value)!==w(S.value);if(h.preserveMode==="always"||n&&I)g.push({slotId:h.id,value:P.value,baselineValue:S.value,sourcePath:P.path})}let d=[];if(l&&n){let h=er(s,c,p);Ze(s.blocks,l.blocks,`${p}.blocks`,h,d)}let f=structuredClone(r.pageTemplate);f.id=s.id,f.path=s.path;let m=s.title!==void 0&&l?.title!==void 0&&s.title!==l.title;if(s.title!==void 0&&(m&&n||f.title===void 0))f.title=s.title;if(s.layout)f.layout=structuredClone(s.layout);if(s.auth)f.auth=structuredClone(s.auth);if(s.lifecycle)f.lifecycle=structuredClone(s.lifecycle);if(s.computed)f.computed=structuredClone(s.computed);if(s.urlState)f.urlState=structuredClone(s.urlState);let y={...f.state??{}};if(s.state)for(let[h,x]of Object.entries(s.state)){if(h==="currentPath")continue;if(!l?.state||!(h in l.state)){y[h]=structuredClone(x);continue}if(w(x)!==w(l.state[h]))y[h]=structuredClone(x);else if(!(h in y))y[h]=structuredClone(x)}if("currentPath"in y||s.state?.currentPath!==void 0)y.currentPath=s.path;if(Object.keys(y).length>0)f.state=y;for(let h of g){let x=r.slotBindings[h.slotId];if(!x){d.push({code:"unmapped-slot",slotId:h.slotId,path:h.sourcePath,message:`Target variant "${r.id}" does not expose semantic slot "${h.slotId}".`,preservedSummary:j(h.value)});continue}let P=ee(r.pageTemplate,x,"targetTemplate").value;if(!Lt(f,x,h.value,h.baselineValue??P,u))d.push({code:"unmapped-slot",slotId:h.slotId,path:h.sourcePath,message:`Target variant "${r.id}" slot "${h.slotId}" could not be located during projection.`,preservedSummary:j(h.value)})}let k=Ae(r.pageTemplate.lifecycle),b=Ae(f.lifecycle??s.lifecycle);if(k&&b&&k!==b)Qe(f.blocks,k,b);return Xn(f.blocks,u,f.id),e.pages[i]=f,Oe(e,{familyId:t.familyId,variantId:r.id,targetKind:"page",targetId:f.id}),O(e),{spec:e,familyId:t.familyId,...c?{fromVariantId:c.id}:{},toVariantId:r.id,changedPaths:[p],unmappedWarnings:d}}function Ae(e){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let r of e){let o=Ae(r);if(o)return o}return}let t=e;if(typeof t.connectionId==="string"&&t.connectionId)return t.connectionId;for(let r of Object.values(t)){let o=Ae(r);if(o)return o}return}function Qe(e,t,r){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let n of e)Qe(n,t,r);return}let o=e;if(o.connectionId===t)o.connectionId=r;for(let n of Object.values(o))Qe(n,t,r)}function or(e,t){let r=e.composition?.variants?.find((n)=>n.targetKind==="shell"&&n.familyId===t.familyId);if(r){let n=t.variants.find((a)=>a.id===r.variantId||a.aliases?.includes(r.variantId));if(n)return n}let o=e.layout;if(!o)return;if(o.shell){let n=t.variants.filter((a)=>a.shellLayout?.shell===o.shell);if(n.length===1)return n[0];if(n.length>1)return n.find((a)=>Object.entries(a.shellLayout??{}).every(([i,s])=>o[i]===s))??n.find((a)=>o.sidebar?a.shellLayout?.sidebar===o.sidebar:!0)??n[0]}return t.variants.find((n)=>{if(!n.shellLayout)return!1;let a=Object.entries(n.shellLayout).filter(([i])=>i!=="shell");return a.length>0&&a.every(([i,s])=>o[i]===s)})}function ir(e,t,r,o){if(!r.shellLayout)throw Error(`missing-variant-payload:${t.familyId}:${r.id}`);let n=or(e,t),a=structuredClone(e.layout??{}),i=r.shellCapabilities?.supportsSidebarBehavior??r.shellCapabilities?.supportsSidebarSlots??!0,s=r.shellCapabilities?.sidebarSlotPlacement??(r.shellCapabilities?.supportsSidebarSlots??!0?"sidebar":"hidden"),{sidebar:c,shell:l,...p}=a,u={...p,...i&&c!==void 0?{sidebar:c}:{},...structuredClone(r.shellLayout)},g=[];if(!i&&c!==void 0)g.push({code:"unmapped-shell-option",path:"layout.sidebar",...t.semanticSlots.some((d)=>d.id==="sidebarBehavior")?{slotId:"sidebarBehavior"}:{},message:`Target shell "${r.id}" does not use sidebar folding behavior.`,preservedSummary:`sidebar=${c}`});if(s==="hidden")for(let d=0;d<e.pages.length;d++){let f=e.pages[d];if(!f||f.layout?.inherit===!1)continue;se(f.blocks,`pages[${d}].blocks`,({node:m,path:y})=>{if(m.type==="PageLayout"&&m.slots?.sidebar?.length)g.push({code:"unmapped-slot",path:`${y}.slots.sidebar`,message:`PageLayout sidebar slot on page "${f.id}" is hidden under "${r.id}".`,preservedSummary:j(m.slots.sidebar)})})}return e.layout=u,Oe(e,{familyId:t.familyId,variantId:r.id,targetKind:"shell",targetId:"spec"}),O(e),{spec:e,familyId:t.familyId,...n?{fromVariantId:n.id}:{},toVariantId:r.id,changedPaths:["layout"],unmappedWarnings:g}}function sr(e,t,r,o){if(!r.frameTemplate)throw Error(`missing-variant-payload:${t.familyId}:${r.id}`);let n=o.pageMapping??(o.target.pageId?{[o.target.role??o.target.pageId]:o.target.pageId}:{}),a=t.variants.find((c)=>Object.values(n).some((l)=>e.composition?.regions?.some((p)=>p.targetPageId===l&&(p.resourceId===c.resourceId||p.resourceId===`layout:${c.id}`)))),i={identity:r.identity??{resourceId:r.resourceId??`layout:${r.id}`,version:"1",sourceHash:ae(w(r.frameTemplate))},contentBlockId:r.frameTemplate.contentBlockId,frame:structuredClone(r.frameTemplate.frame)},s=Je(e,i,n);for(let c of Object.values(n))Oe(s.spec,{familyId:t.familyId,variantId:r.id,targetKind:"frame",targetId:c});return O(s.spec),{spec:s.spec,familyId:t.familyId,...a?{fromVariantId:a.id}:{},toVariantId:r.id,changedPaths:Object.values(n).map((c)=>{let l=s.spec.pages.findIndex((p)=>p.id===c);return l>=0?`pages[${l}].blocks[0]`:`pages.${c}.blocks[0]`}),unmappedWarnings:s.unmappedWarnings}}function ar(e,t,r,o){let n=r.map((d,f)=>{if(typeof d==="number"||f===0)return d;if(/^(0|[1-9]\d*)$/.test(d)||d.startsWith("@"))return d;if(d.startsWith("slots."))return`@${d.slice(6)}`;return`@${d}`}),a=G(n,{allowRoot:!1,allowSlotEnd:!1}),i=e.blocks,s=null,c=e.blocks,l=0,p,u=`pages[${t}].blocks`,g=0;while(g<a.length){let d=a[g];if(typeof d==="string"&&d.startsWith("@")){let f=d.slice(1),m=a[g+1];if(!s||typeof m!=="number")return;let y=s.slots?.[f];if(!y?.[m])return;c=y,l=m,p=y[m],s=p??null,i=p?.children??[],u=`${u}.slots.${f}[${m}]`,g+=2;continue}if(typeof d!=="number"||!i[d])return;c=i,l=d,p=i[d],s=p??null,i=p?.children??[],u=g===0?`${u}[${d}]`:`${u}.children[${d}]`,g+=1}if(!p)return;if(o&&p.id!==o)throw Error(`mismatched-variant-target-block:${o}`);return{pageIndex:t,blockPath:u,block:p,replace:(d)=>{c[l]=d}}}function cr(e,t,r,o){for(let n=0;n<e.pages.length;n++){let a=e.pages[n];if(!a||t&&a.id!==t)continue;if(o!==void 0){let c=ar(a,n,o,r);if(c)return c;continue}let i=(c,l)=>{for(let p=0;p<c.length;p++){let u=c[p];if(!u)continue;let g=`${l}[${p}]`;if(r?u.id===r:c.length===1&&l.endsWith(".blocks"))return{pageIndex:n,blockPath:g,block:u,replace:(d)=>{c[p]=d}};if(u.children?.length){let d=i(u.children,`${g}.children`);if(d)return d}for(let[d,f]of Object.entries(u.slots??{})){let m=i(f,`${g}.slots.${d}`);if(m)return m}}return},s=i(a.blocks,`pages[${n}].blocks`);if(s)return s}throw Error(`unknown-variant-target-block:${r??""}`)}function lr(e,t){let r,o=-1;for(let n of t.variants){let a=n.blockTemplate;if(!a||a.type!==e.type)continue;let i=1;for(let[s,c]of Object.entries(a.props??{}))if(w(e.props?.[s])===w(c))i+=2;if(i>o)o=i,r=n}return r}function dr(e,t,r,o){if(!r.blockTemplate)throw Error(`missing-variant-payload:${t.familyId}:${r.id}`);let n=o.preserveCustomizations??!0,a=cr(e,o.target.pageId,o.target.blockId,o.target.blockPath),i=a.block,s=lr(i,t),c={id:"_block",path:"/_block",blocks:[i]},l={id:"_target",path:"/_target",blocks:[structuredClone(r.blockTemplate)]},p=new Set(t.presentationProps??[]),u=new Set,g=new Set,d=!1,f=(b)=>{if(!b)return;if(b.kind==="block-prop"&&b.property)p.add(b.property);if(b.kind==="block-events")if(b.property)u.add(b.property);else for(let h of Object.keys(i.events??{}))u.add(h);if(b.kind==="block-children")if(b.property)g.add(b.property);else d=!0},m=[];for(let b of t.semanticSlots){let h=s?.slotBindings[b.id]??r.slotBindings[b.id];if(f(h),!h)continue;let x=ee(c,h,a.blockPath);if(x.value===void 0)continue;let P=s?.blockTemplate?ee({id:"_base",path:"/_base",blocks:[s.blockTemplate]},h,"baseline").value:void 0,S=P===void 0||w(x.value)!==w(P);if(b.preserveMode!=="always"&&!(n&&S))continue;let I=r.slotBindings[b.id];if(!I){m.push({code:"unmapped-slot",slotId:b.id,path:x.path,message:`Target variant "${r.id}" does not support semantic slot "${b.id}".`,preservedSummary:j(x.value)});continue}Lt(l,I,x.value,P,new Set)}let y=l.blocks[0];if(!y)throw Error("variant-block-instantiation-failed");if(i.id)y.id=i.id;if(i.visible!==void 0)y.visible=structuredClone(i.visible);let k=i.type===y.type;for(let[b,h]of Object.entries(i.props??{})){if(p.has(b))continue;if(k)y.props??={},y.props[b]=structuredClone(h);else m.push({code:"unmapped-prop",path:`${a.blockPath}.props.${b}`,message:`Custom property "${b}" on "${i.type}" does not map to "${y.type}".`,preservedSummary:`${b}=${j(h)}`})}for(let[b,h]of Object.entries(i.events??{})){if(u.has(b))continue;if(k)y.events??={},y.events[b]=structuredClone(h);else m.push({code:"unmapped-event",path:`${a.blockPath}.events.${b}`,message:`Event handler "${b}" on "${i.type}" does not map to "${y.type}".`,preservedSummary:j(h)})}for(let[b,h]of Object.entries(i.slots??{})){if(g.has(b))continue;if(k)y.slots??={},y.slots[b]=structuredClone(h);else m.push({code:"unmapped-slot",path:`${a.blockPath}.slots.${b}`,message:`Named slot "${b}" on "${i.type}" does not map to "${y.type}".`,preservedSummary:j(h)})}if(!d&&i.children?.length)if(k)y.children=structuredClone(i.children);else m.push({code:"unmapped-block",path:`${a.blockPath}.children`,message:`Child blocks of "${i.type}" cannot auto-map onto "${y.type}".`,preservedSummary:j(i.children)});return a.replace(y),Oe(e,{familyId:t.familyId,variantId:r.id,targetKind:t.targetKind,targetId:i.id??a.blockPath}),O(e),{spec:e,familyId:t.familyId,...s?{fromVariantId:s.id}:{},toVariantId:r.id,changedPaths:[a.blockPath],unmappedWarnings:m}}function pr(e,t){if(t.familyId){let o=!Array.isArray(e)&&"get"in e?e.get(t.familyId):e.find((n)=>n.familyId===t.familyId);if(!o)throw Error(`unknown-variant-family:${t.familyId}`);return o}let r=Ee(e,{targetKind:t.target.kind}).filter((o)=>o.variants.some((n)=>n.id===t.targetVariantId||Boolean(n.aliases?.includes(t.targetVariantId))||n.id.endsWith(`:${t.targetVariantId}`)));if(r.length===1&&r[0])return r[0];if(r.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),n=(t.spec.composition?.variants??[]).filter((a)=>a.targetKind===t.target.kind&&(!o||a.targetId===o)).map((a)=>r.find((i)=>i.familyId===a.familyId)).filter((a)=>Boolean(a));if(n.length===1&&n[0])return n[0]}throw Error("ambiguous-or-unknown-variant-family")}function te(e,t){let r=pr(e,t);if(Me(r),r.targetKind!==t.target.kind)throw Error(`variant-target-kind-mismatch:${r.targetKind}:${t.target.kind}`);let o=tr(r,t.targetVariantId),n=structuredClone(t.spec);if(O(n),r.targetKind==="shell")return ir(n,r,o,t);if(r.targetKind==="frame")return sr(n,r,o,t);if(r.targetKind==="page")return rr(n,r,o,t);return dr(n,r,o,t)}var ur=(e)=>Boolean(e)&&typeof e==="object"&&!Array.isArray(e);function tt(e,t,r){for(let o of e){if(o===r)continue;if(o.id)t.add(o.id);if(o.children?.length)tt(o.children,t,r);for(let n of Object.values(o.slots??{}))tt(n,t,r)}}function Te(e,t){let r=new Set;for(let o of e.pages)tt(o.blocks,r,t);return r}function Be(e,t,r,o){let n=new Set,a=(i)=>{if(i.id){if(t.has(i.id)||n.has(i.id))throw new v("invalid-spec-patch",r,o,`duplicate block id "${i.id}"`);n.add(i.id)}for(let s of i.children??[])a(s);for(let s of Object.values(i.slots??{}))for(let c of s)a(c)};a(e)}function he(e,t,r,o){let n=e.pages.findIndex((i)=>i.id===t),a=n>=0?e.pages[n]:void 0;if(!a)throw new v("patch-page-not-found",r,o,`unknown page "${t}"`);return{page:a,pageIndex:n}}function De(e,t,r,o,n){for(let a=0;a<e.length;a++){let i=e[a];if(!i)continue;let s=[...r,a];if(i.id===t)return{pageIndex:n,page:o,node:i,path:s,parentList:e,index:a};if(i.children?.length){let c=De(i.children,t,s,o,n);if(c)return c}for(let[c,l]of Object.entries(i.slots??{})){let p=De(l,t,[...s,`@${c}`],o,n);if(p)return p}}return}function nt(e,t,r,o,n){let a;try{a=G(r,{allowRoot:!1,allowSlotEnd:!1})}catch{throw new v("invalid-spec-block-path",o,n,"malformed blockPath")}let i=e.blocks,s=null,c,l=e.blocks,p=0,u=0;while(u<a.length){let g=a[u];if(typeof g==="string"&&g.startsWith("@")){let d=g.slice(1),f=a[u+1];if(!s||typeof f!=="number")throw new v("patch-block-not-found",o,n,"invalid slot path");let m=s.slots?.[d];if(!m?.[f])throw new v("patch-block-not-found",o,n,`block missing at slot "${d}[${f}]"`);l=m,p=f,c=m[f],s=c??null,i=c?.children??[],u+=2;continue}if(typeof g!=="number")throw new v("invalid-spec-block-path",o,n,"expected index segment");if(!i[g])throw new v("patch-block-not-found",o,n,`block missing at path segment ${g}`);l=i,p=g,c=i[g],s=c??null,i=c?.children??[],u+=1}if(!c)throw new v("patch-block-not-found",o,n,"target block not found");return{pageIndex:t,page:e,node:c,path:a,parentList:l,index:p}}function ce(e,t,r,o){let{page:n,pageIndex:a}=he(e,t.pageId,r,o);if(t.blockPath!==void 0)return nt(n,a,t.blockPath,r,o);if(t.blockId){let i=De(n.blocks,t.blockId,[],n,a);if(!i)throw new v("patch-block-not-found",r,o,`unknown blockId "${t.blockId}" on page "${t.pageId}"`);return i}throw new v("invalid-spec-patch",r,o,"locator needs blockId or blockPath")}function et(e,t,r,o){let{page:n,pageIndex:a}=he(e,t.pageId,r,o);if(t.parentBlockId){let i=De(n.blocks,t.parentBlockId,[],n,a);if(!i)throw new v("patch-block-not-found",r,o,`unknown parentBlockId "${t.parentBlockId}"`);let s=i.node;if(t.slot){let c=t.slot;return{page:n,parentNode:s,parentNodePath:i.path,list:s.slots?.[c]??[],ensureCreated:()=>(s.slots??={},s.slots[c]??=[],s.slots[c])}}return{page:n,parentNode:s,parentNodePath:i.path,list:s.children??[],ensureCreated:()=>(s.children??=[],s.children)}}if(t.parentPath!==void 0){let i;try{i=G(t.parentPath,{allowRoot:!0,allowSlotEnd:!0})}catch{throw new v("invalid-spec-block-path",r,o,"invalid parentPath")}if(i.length===0){if(t.slot)throw new v("patch-slot-invalid",r,o,"root page has no named slot");return{page:n,parentNode:null,parentNodePath:[],list:n.blocks,ensureCreated:()=>n.blocks}}let s=i[i.length-1];if(typeof s==="string"&&s.startsWith("@")){let l=s.slice(1),p=i.slice(0,-1),u=nt(n,a,p,r,o);return{page:n,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=nt(n,a,i,r,o);if(t.slot){let l=t.slot;return{page:n,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:n,parentNode:c.node,parentNodePath:c.path,list:c.node.children??[],ensureCreated:()=>(c.node.children??=[],c.node.children)}}if(t.slot)throw new v("patch-slot-invalid",r,o,"slot requires a parent block");return{page:n,parentNode:null,parentNodePath:[],list:n.blocks,ensureCreated:()=>n.blocks}}function gr(e,t){return e.length<=t.length&&e.every((r,o)=>t[o]===r)}function jt(e,t){let r=[];for(let o of e){if("children"in o&&Array.isArray(o.children)){let n=jt(o.children,t);r.push({...o,children:n});continue}if("path"in o&&o.path===t)continue;r.push(o)}return r}function sa(e,t,r={}){ve(e),mt(t,r);let o=structuredClone(e);O(o);let n=new Set,a=[];for(let i=0;i<t.length;i++){let s=t[i];if(!s)continue;switch(s.op){case"addPage":{let c=o.pages.some((d)=>d.id===s.page.id),l=o.pages.some((d)=>d.path===s.page.path);if(c||l)throw new v("patch-page-conflict",i,s.op,`page id "${s.page.id}" or path "${s.page.path}" already exists`);let p=Te(o),u=structuredClone(s.page);for(let d of u.blocks)Be(d,p,i,s.op);let g=s.index!==void 0?Math.max(0,Math.min(s.index,o.pages.length)):o.pages.length;if(o.pages.splice(g,0,u),s.addToMenu===!0)o.menus??={items:[]},o.menus.items.push({key:`page:${u.id}`,label:u.title??u.id,path:u.path}),n.add("menus");n.add("pages");break}case"removePage":{let{page:c,pageIndex:l}=he(o,s.pageId,i,s.op);if(o.pages.splice(l,1),o.composition){if(o.composition.pages=o.composition.pages.filter((p)=>p.targetPageId!==s.pageId),o.composition.regions)o.composition.regions=o.composition.regions.filter((p)=>p.targetPageId!==s.pageId);if(o.composition.variants)o.composition.variants=o.composition.variants.filter((p)=>!((p.targetKind==="page"||p.targetKind==="frame")&&p.targetId===s.pageId))}if(s.removeFromMenu!==!1&&o.menus?.items)o.menus.items=jt(o.menus.items,c.path),n.add("menus");n.add("pages");break}case"updatePage":{let{page:c,pageIndex:l}=he(o,s.pageId,i,s.op);if(s.patch.path!==void 0){if(o.pages.some((u,g)=>g!==l&&u.path===s.patch.path))throw new v("patch-page-conflict",i,s.op,`page path "${s.patch.path}" already exists`);c.path=s.patch.path}if(s.patch.title!==void 0)c.title=s.patch.title;if(s.patch.layout!==void 0)c.layout=structuredClone(s.patch.layout);if(s.patch.auth!==void 0)c.auth=structuredClone(s.patch.auth);n.add(`pages[${l}]`);break}case"setPageState":{let{page:c,pageIndex:l}=he(o,s.pageId,i,s.op);if(s.state)c.state={...c.state,...structuredClone(s.state)};if(s.removeStateKeys?.length&&c.state)for(let p of s.removeStateKeys)delete c.state[p];if(s.computed!==void 0)c.computed=structuredClone(s.computed);if(s.lifecycle!==void 0)c.lifecycle=structuredClone(s.lifecycle);if(s.urlState!==void 0)c.urlState=structuredClone(s.urlState);n.add(`pages[${l}]`);break}case"insertBlock":{let c=et(o,s.target,i,s.op),l=Te(o),p=structuredClone(s.block);Be(p,l,i,s.op);let u=c.ensureCreated(),g=s.target.index!==void 0?Math.max(0,Math.min(s.target.index,u.length)):u.length;u.splice(g,0,p);let d=o.pages.indexOf(c.page);n.add(`pages[${d}].blocks`);break}case"replaceBlock":{let c=ce(o,s.target,i,s.op),l=Te(o,c.node),p=structuredClone(s.block);if((s.preserveId??!0)&&!p.id&&c.node.id)p.id=c.node.id;Be(p,l,i,s.op),c.parentList[c.index]=p,n.add(`pages[${c.pageIndex}].blocks`);break}case"removeBlock":{let c=ce(o,s.target,i,s.op);c.parentList.splice(c.index,1),n.add(`pages[${c.pageIndex}].blocks`);break}case"moveBlock":{if(s.from.pageId!==s.to.pageId){let f=ce(o,s.from,i,s.op),m=et(o,s.to,i,s.op),y=Te(o,f.node);Be(f.node,y,i,s.op);let[k]=f.parentList.splice(f.index,1);if(!k)break;let b=m.ensureCreated(),h=s.to.index!==void 0?Math.max(0,Math.min(s.to.index,b.length)):b.length;b.splice(h,0,k),n.add(`pages[${f.pageIndex}].blocks`),n.add(`pages[${o.pages.indexOf(m.page)}].blocks`);break}let c=ce(o,s.from,i,s.op),l=et(o,s.to,i,s.op);if(gr(c.path,l.parentNodePath))throw new v("patch-move-cycle",i,s.op,"cannot move a block into itself or its descendant");let p=l.ensureCreated(),u=p===c.parentList,g=s.to.index!==void 0?Math.max(0,Math.min(s.to.index,p.length)):p.length,[d]=c.parentList.splice(c.index,1);if(!d)break;if(u&&g>c.index)g=Math.max(0,g-1);p.splice(g,0,d),n.add(`pages[${c.pageIndex}].blocks`);break}case"updateProps":{let c=ce(o,s.target,i,s.op),l={...c.node.props};for(let[p,u]of Object.entries(s.props))l[p]=structuredClone(u);if(s.removeKeys?.length)for(let p of s.removeKeys)delete l[p];if(Object.keys(l).length>0)c.node.props=l;else delete c.node.props;n.add(`pages[${c.pageIndex}].blocks`);break}case"setEvents":{let c=ce(o,s.target,i,s.op),l=s.merge?{...c.node.events}:{};for(let[p,u]of Object.entries(s.events))l[p]=structuredClone(u);if(s.removeEvents?.length)for(let p of s.removeEvents)delete l[p];if(Object.keys(l).length>0)c.node.events=l;else delete c.node.events;n.add(`pages[${c.pageIndex}].blocks`);break}case"upsertEntity":{let c=structuredClone(o.data?.entities??{});c[s.name]=structuredClone(s.entity);try{o.data=W({entities:c})}catch(l){throw new v("invalid-spec-patch",i,s.op,l instanceof Error?l.message:"invalid entity")}n.add(`data.entities.${s.name}`);break}case"removeEntity":{if(!o.data?.entities||!Object.hasOwn(o.data.entities,s.name))throw new v("patch-entity-not-found",i,s.op,`unknown entity "${s.name}"`);let c=structuredClone(o.data.entities);delete c[s.name],o.data=W({entities:c}),n.add("data.entities");break}case"upsertConnection":{if(o.data?.entities&&!Object.hasOwn(o.data.entities,s.connection.entity))throw new v("patch-entity-not-found",i,s.op,`connection references undeclared entity "${s.connection.entity}"`);let c=structuredClone(s.connection);o.connections??=[];let l=o.connections.findIndex((p)=>p.id===c.id);if(l>=0)o.connections[l]=c;else o.connections.push(c);n.add("connections");break}case"removeConnection":{let c=o.connections?.findIndex((l)=>l.id===s.connectionId)??-1;if(c<0)throw new v("patch-connection-not-found",i,s.op,`unknown connection "${s.connectionId}"`);o.connections?.splice(c,1),n.add("connections");break}case"setLayout":{o.layout=s.merge?{...o.layout,...structuredClone(s.layout)}:structuredClone(s.layout),n.add("layout");break}case"setMenus":{o.menus=structuredClone(s.menus),n.add("menus");break}case"setDesign":{let c=structuredClone(s.design);if(s.merge&&o.design)o.design={...o.design,...c,...o.design.tokens||c.tokens?{tokens:{...o.design.tokens,...c.tokens}}:{}};else o.design=c;n.add("design");break}case"swapVariant":{if(!r.variantRegistry)throw new v("patch-variant-failed",i,s.op,"variantRegistry option is required for swapVariant patch ops");try{let c,l=-1;if(s.target.kind==="page"&&s.target.pageId){l=o.pages.findIndex((g)=>g.id===s.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&&ur(u.blocks[0].children)===!1){let g=u.blocks[0];c={...g,children:[]},u.blocks=structuredClone(g.children??[])}}let p=te(r.variantRegistry,{spec:o,...s.familyId!==void 0?{familyId:s.familyId}:{},target:s.target,targetVariantId:s.targetVariantId,...s.preserveCustomizations!==void 0?{preserveCustomizations:s.preserveCustomizations}:{},...s.pageMapping?{pageMapping:s.pageMapping}:{}});if(o=p.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 p.changedPaths)n.add(u);a.push(...p.unmappedWarnings)}catch(c){throw new v("patch-variant-failed",i,s.op,c instanceof Error?c.message:"swapVariant failed")}break}}}return O(o),{spec:o,appliedCount:t.length,changedPaths:[...n],unmappedWarnings:a}}var fr=new Set(["__proto__","prototype","constructor"]);function Vt(e){let t=e.trim();if(!t)return"/";return t.startsWith("/")?t:`/${t}`}function rt(e,t){for(let r of e){if(r.id)t.add(r.id);if(r.children?.length)rt(r.children,t);for(let o of Object.values(r.slots??{}))rt(o,t)}}function Ft(e,t,r){let o=(n)=>{for(let a of n){if(a.id){if(r.has(a.id)){let i=`${t}-${a.id}`,s=2;while(r.has(i))i=`${t}-${a.id}-${s}`,s+=1;a.id=i}r.add(a.id)}if(a.children?.length)o(a.children);for(let i of Object.values(a.slots??{}))o(i)}};o(e)}function mr(e,t,r){if(!e)return;let o=Ee(e,{targetKind:"shell"});if(r){let n=o.find((a)=>a.familyId===r);if(n)return n}return o.find((n)=>n.variants.some((a)=>a.id===t))??o[0]}function yr(e,t){if(!e)return{};let r=Ee(e,{targetKind:"page"});if(t.familyId){let o=r.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((s)=>s.resourceId===a||s.id===t.solutionId))throw Error(`blueprint-solution-variant-mismatch:${t.solutionId}:${t.familyId}`)}let n=t.variantId?o.variants.find((a)=>a.id===t.variantId):o.variants[0];if(t.variantId&&!n)throw Error(`unknown-variant:${o.familyId}:${t.variantId}`);return{family:o,...n?{variant:n}:{}}}if(t.solutionId){let o=`template:${t.solutionId}`;for(let n of r){let a=n.variants.find((i)=>i.resourceId===o);if(a){let i=t.variantId?n.variants.find((s)=>s.id===t.variantId):a;if(t.variantId&&!i)throw Error(`unknown-variant:${n.familyId}:${t.variantId}`);return{family:n,...i?{variant:i}:{}}}}}return{}}function $t(e,t,r,o){if(!t)return;if(e.blocks.some((i)=>i.type==="PageLayout"||Boolean(i.template)))return;let n=`${e.id}-shell`,a=2;while(r.has(n))n=`${e.id}-shell-${a}`,a+=1;r.add(n),e.blocks=[{id:n,type:"PageLayout",props:{title:e.title??o??e.id},children:e.blocks}]}function pa(e,t={}){ft(e);let r={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)r.data=W({entities:structuredClone(e.entities)});let o=[];if(e.connections?.length){let l=[];for(let p of e.connections){let u=p.mockSeed!==void 0||p.mockGenerate!==void 0;l.push({id:p.id,type:"Collection",entity:p.entity,...u?{mock:{...p.mockSeed?{seed:structuredClone(p.mockSeed)}:{},...p.mockGenerate!==void 0?{generate:p.mockGenerate}:{}}}:{}}),o.push(p.id)}r.connections=l}let n=[];if(e.shellVariant){let l=mr(t.variantRegistry,e.shellVariant,t.shellFamilyId??"shell.workspace.v1");if(!l)throw Error(`unknown-shell-variant:${e.shellVariant}`);let p=te(t.variantRegistry??[l],{spec:r,familyId:l.familyId,target:{kind:"shell"},targetVariantId:e.shellVariant});if(r=p.spec,n.push(...p.unmappedWarnings),e.layout)r.layout={...r.layout,...structuredClone(e.layout)}}let a=Boolean(e.shellVariant||r.layout),i=new Set,s=[],c=[];for(let l of e.pages){if(l.kind==="blocks"||l.kind===void 0&&"blocks"in l){let C=l,T=Vt(C.path);if(r.pages.some((ot)=>ot.id===C.id||ot.path===T)||fr.has(C.id))throw Error(`solution-page-conflict:${C.id}:${T}`);let R={id:C.id,path:T,...C.title!==void 0?{title:C.title}:{},...C.standalone?{layout:{inherit:!1}}:{},...C.state?{state:structuredClone(C.state)}:{},blocks:structuredClone(C.blocks)};Ft(R.blocks,R.id,i);let B=!C.standalone&&(C.wrapInShell??a);if($t(R,B,i,e.title),r.pages.push(R),s.push({id:R.id,path:R.path}),!C.standalone)c.push({id:R.id,label:R.title??R.id,path:R.path});continue}let u=l,{family:g,variant:d}=yr(t.variantRegistry,u),f=t.solutions??[],m=u.solutionId?f.find((C)=>C.id===u.solutionId):void 0;if(!m&&d?.resourceId?.startsWith("template:")){let C=d.resourceId.slice(9);m=f.find((T)=>T.id===C)}let y,k=u.solutionId?`template:${u.solutionId}`:d?.resourceId;if(m){if(y=structuredClone(m.spec),y.auth)r.auth??=structuredClone(y.auth),delete y.auth}else if(d?.pageTemplate)y={version:"2.0",pages:[structuredClone(d.pageTemplate)]},k??=`variant:${g?.familyId??"page"}:${d.id}`;if(!y||y.pages.length===0||!k)throw Error(`unknown-blueprint-solution:${u.solutionId??`${u.familyId??""}:${u.variantId??""}`}`);let b=u.selectedPageIds?y.pages.filter((C)=>u.selectedPageIds?.includes(C.id)):y.pages;if(b.length===0)throw Error("solution-select-pages");let h={...u.connectionBindings};for(let C of y.connections??[]){if(h[C.id])continue;let T=r.connections?.find((B)=>B.id===C.id&&B.entity===C.entity);if(T){h[C.id]=T.id;continue}let R=r.connections?.filter((B)=>B.entity===C.entity)??[];if(R.length===1&&R[0])h[C.id]=R[0].id;else h[C.id]=C.id}let x={...u.pathBindings},P={};if(b.length===1&&b[0]){let C=b[0];if(u.id)P[C.id]=u.id;if(u.path)x[C.path]=Vt(u.path)}for(let C of b){let T=P[C.id]??C.id;Ft(C.blocks,T,i)}let S=r.auth?structuredClone(r.auth):void 0;if(S)delete r.auth;let I=d?.identity??{resourceId:k,version:"0.22.0",sourceHash:ae(w(y))},_=Dt(r,{identity:I,spec:y,...m?.controls?{controls:m.controls}:{}},{...u.selectedPageIds?{selectedPageIds:u.selectedPageIds}:{},...Object.keys(x).length?{paths:x}:{},...Object.keys(P).length?{pageIds:P}:{},connections:h,layout:"target",...u.configuration?{configuration:u.configuration}:{}});if(r=_.spec,S)r.auth=S;for(let C of _.connections)if(!o.includes(C.id))o.push(C.id);for(let C of _.pages){let T=C.id;if(g&&d&&d.resourceId!==k){let B=te(t.variantRegistry??[g],{spec:r,familyId:g.familyId,target:{kind:"page",pageId:T},targetVariantId:d.id});r=B.spec,n.push(...B.unmappedWarnings)}else if(g&&d)r.composition??={schema:"uibot.solution-composition.v1",pages:[]},r.composition.variants=[...(r.composition.variants??[]).filter((B)=>!(B.targetKind==="page"&&B.targetId===T&&B.familyId===g.familyId)),{familyId:g.familyId,variantId:d.id,targetKind:"page",targetId:T}];let R=r.pages.find((B)=>B.id===T);if(R){if(u.title!==void 0&&_.pages.length===1)R.title=u.title;if(u.standalone)R.layout={...R.layout,inherit:!1};rt(R.blocks,i);let B=!u.standalone&&(u.wrapInShell??a);if($t(R,B,i,e.title),s.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 r.connections??[])if(!r.data?.entities||!Object.hasOwn(r.data.entities,l.entity))throw Error(`blueprint-missing-entity:${l.entity}`);if(!r.menus&&c.length>0&&a)r.menus={items:c.map((l)=>({key:`nav-${l.id}`,label:l.label,path:l.path}))};return O(r),{spec:r,addedPages:s,addedConnections:o,unmappedWarnings:n}}function Ut(){return`/* Generated by UIBot materialize (uibot.materialize.manifest.v1) */
6
+ :root {
7
+ --um-bg: #ffffff;
8
+ --um-fg: #0f172a;
9
+ --um-muted: #f4f4f5;
10
+ --um-muted-fg: #64748b;
11
+ --um-surface: #ffffff;
12
+ --um-border: #e4e4e7;
13
+ --um-primary: #18181b;
14
+ --um-primary-fg: #fafafa;
15
+ --um-accent: #e4e4e7;
16
+ --um-accent-fg: #18181b;
17
+ --um-radius: 10px;
18
+ --um-font: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
19
+ }
20
+
21
+ .um-dark {
22
+ --um-bg: #09090b;
23
+ --um-fg: #fafafa;
24
+ --um-muted: #18181b;
25
+ --um-muted-fg: #a1a1aa;
26
+ --um-surface: #111113;
27
+ --um-border: #27272a;
28
+ --um-primary: #fafafa;
29
+ --um-primary-fg: #18181b;
30
+ --um-accent: #27272a;
31
+ --um-accent-fg: #fafafa;
32
+ }
33
+
34
+ .um-root,
35
+ .um-root * {
36
+ box-sizing: border-box;
37
+ }
38
+
39
+ .um-root {
40
+ font-family: var(--um-font);
41
+ color: var(--um-fg);
42
+ background: var(--um-muted);
43
+ height: 100dvh;
44
+ min-height: 0;
45
+ overflow: hidden;
46
+ display: flex;
47
+ font-size: 14px;
48
+ line-height: 1.5;
49
+ }
50
+
51
+ .um-root[data-shell="top-navbar"],
52
+ .um-root[data-shell="console-drilldown"] {
53
+ flex-direction: column;
54
+ }
55
+
56
+ .um-topbar {
57
+ height: 56px;
58
+ flex: none;
59
+ display: flex;
60
+ align-items: center;
61
+ gap: 14px;
62
+ padding: 0 20px;
63
+ background: var(--um-surface);
64
+ border-bottom: 1px solid var(--um-border);
65
+ }
66
+
67
+ .um-body {
68
+ flex: 1;
69
+ min-height: 0;
70
+ min-width: 0;
71
+ display: flex;
72
+ overflow: hidden;
73
+ }
74
+
75
+ .um-sidebar {
76
+ width: 248px;
77
+ flex: none;
78
+ display: flex;
79
+ flex-direction: column;
80
+ min-height: 0;
81
+ background: var(--um-muted);
82
+ border-inline-end: 1px solid var(--um-border);
83
+ padding: 12px 10px;
84
+ gap: 8px;
85
+ overflow-y: auto;
86
+ }
87
+
88
+ .um-root[data-folded="true"] .um-sidebar {
89
+ width: 68px;
90
+ align-items: center;
91
+ }
92
+
93
+ .um-root[data-folded="true"] .um-nav-label,
94
+ .um-root[data-folded="true"] .um-nav-group-title,
95
+ .um-root[data-folded="true"] .um-brand-text,
96
+ .um-root[data-folded="true"] .um-badge {
97
+ display: none;
98
+ }
99
+
100
+ .um-root[data-shell="sidebar-floating"] .um-sidebar {
101
+ margin: 10px;
102
+ border: 1px solid var(--um-border);
103
+ border-radius: 12px;
104
+ background: var(--um-surface);
105
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
106
+ }
107
+
108
+ .um-root[data-shell="sidebar-inset"] .um-main {
109
+ margin: 10px;
110
+ margin-inline-start: 0;
111
+ border: 1px solid var(--um-border);
112
+ border-radius: 12px;
113
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
114
+ }
115
+
116
+ .um-rail {
117
+ width: 60px;
118
+ flex: none;
119
+ display: flex;
120
+ flex-direction: column;
121
+ align-items: center;
122
+ gap: 6px;
123
+ padding: 10px 6px;
124
+ border-inline-end: 1px solid var(--um-border);
125
+ background: var(--um-muted);
126
+ }
127
+
128
+ .um-rail-btn {
129
+ width: 40px;
130
+ height: 40px;
131
+ border-radius: 8px;
132
+ display: grid;
133
+ place-items: center;
134
+ color: inherit;
135
+ text-decoration: none;
136
+ border: 0;
137
+ background: transparent;
138
+ cursor: pointer;
139
+ }
140
+
141
+ .um-rail-btn:hover {
142
+ background: rgba(128, 128, 128, 0.14);
143
+ }
144
+
145
+ .um-rail-btn[aria-current="page"] {
146
+ background: var(--um-accent);
147
+ color: var(--um-accent-fg);
148
+ }
149
+
150
+ .um-main {
151
+ flex: 1;
152
+ min-width: 0;
153
+ min-height: 0;
154
+ display: flex;
155
+ flex-direction: column;
156
+ background: var(--um-surface);
157
+ overflow: hidden;
158
+ }
159
+
160
+ .um-root[data-container="boxed"] {
161
+ padding: 12px;
162
+ gap: 12px;
163
+ justify-content: center;
164
+ }
165
+
166
+ .um-root[data-container="boxed"] .um-main {
167
+ max-width: 1120px;
168
+ border: 1px solid var(--um-border);
169
+ border-radius: 12px;
170
+ }
171
+
172
+ .um-content {
173
+ flex: 1;
174
+ min-height: 0;
175
+ overflow-y: auto;
176
+ padding: 24px;
177
+ }
178
+
179
+ .um-content-inner {
180
+ display: flex;
181
+ flex-direction: column;
182
+ gap: 18px;
183
+ max-width: 1280px;
184
+ margin-inline: auto;
185
+ }
186
+
187
+ .um-brand {
188
+ display: inline-flex;
189
+ align-items: center;
190
+ gap: 10px;
191
+ text-decoration: none;
192
+ color: inherit;
193
+ font-weight: 600;
194
+ padding: 6px 8px;
195
+ }
196
+
197
+ .um-brand-mark {
198
+ width: 30px;
199
+ height: 30px;
200
+ border-radius: 8px;
201
+ background: var(--um-primary);
202
+ color: var(--um-primary-fg);
203
+ display: grid;
204
+ place-items: center;
205
+ flex: none;
206
+ }
207
+
208
+ .um-nav-group {
209
+ display: flex;
210
+ flex-direction: column;
211
+ gap: 3px;
212
+ margin-top: 6px;
213
+ }
214
+
215
+ .um-nav-group-title {
216
+ font-size: 11px;
217
+ font-weight: 600;
218
+ text-transform: uppercase;
219
+ letter-spacing: 0.04em;
220
+ color: var(--um-muted-fg);
221
+ padding: 4px 10px;
222
+ }
223
+
224
+ .um-nav-link {
225
+ display: flex;
226
+ align-items: center;
227
+ gap: 9px;
228
+ padding: 7px 10px;
229
+ border-radius: 7px;
230
+ color: inherit;
231
+ text-decoration: none;
232
+ border: 0;
233
+ background: transparent;
234
+ cursor: pointer;
235
+ font-size: 14px;
236
+ width: 100%;
237
+ text-align: start;
238
+ }
239
+
240
+ .um-nav-link:hover {
241
+ background: rgba(128, 128, 128, 0.12);
242
+ }
243
+
244
+ .um-nav-link[aria-current="page"] {
245
+ background: var(--um-accent);
246
+ color: var(--um-accent-fg);
247
+ font-weight: 600;
248
+ }
249
+
250
+ .um-top-links {
251
+ display: flex;
252
+ align-items: center;
253
+ gap: 6px;
254
+ overflow-x: auto;
255
+ }
256
+
257
+ .um-top-links .um-nav-link {
258
+ width: auto;
259
+ white-space: nowrap;
260
+ }
261
+
262
+ .um-toolbar {
263
+ margin-inline-start: auto;
264
+ display: flex;
265
+ align-items: center;
266
+ gap: 8px;
267
+ }
268
+
269
+ .um-icon-btn {
270
+ display: inline-flex;
271
+ align-items: center;
272
+ justify-content: center;
273
+ gap: 6px;
274
+ height: 34px;
275
+ min-width: 34px;
276
+ padding: 0 10px;
277
+ border-radius: 7px;
278
+ border: 1px solid var(--um-border);
279
+ background: var(--um-surface);
280
+ color: inherit;
281
+ cursor: pointer;
282
+ font-size: 13px;
283
+ }
284
+
285
+ .um-icon-btn:hover {
286
+ background: var(--um-muted);
287
+ }
288
+
289
+ .um-mobile-only {
290
+ display: none;
291
+ }
292
+
293
+ .um-drawer-backdrop {
294
+ position: fixed;
295
+ inset: 0;
296
+ background: rgba(0, 0, 0, 0.45);
297
+ z-index: 60;
298
+ display: flex;
299
+ }
300
+
301
+ .um-drawer-panel {
302
+ width: 288px;
303
+ max-width: 85vw;
304
+ height: 100dvh;
305
+ background: var(--um-surface);
306
+ border-inline-end: 1px solid var(--um-border);
307
+ padding: 14px;
308
+ display: flex;
309
+ flex-direction: column;
310
+ gap: 10px;
311
+ overflow-y: auto;
312
+ }
313
+
314
+ .um-modal-backdrop {
315
+ position: fixed;
316
+ inset: 0;
317
+ background: rgba(0, 0, 0, 0.45);
318
+ z-index: 70;
319
+ display: grid;
320
+ place-items: center;
321
+ padding: 16px;
322
+ }
323
+
324
+ .um-modal-card {
325
+ width: min(480px, 100%);
326
+ border-radius: 12px;
327
+ border: 1px solid var(--um-border);
328
+ background: var(--um-surface);
329
+ overflow: hidden;
330
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
331
+ }
332
+
333
+ .um-standalone {
334
+ min-height: 100dvh;
335
+ background: var(--um-bg);
336
+ color: var(--um-fg);
337
+ padding: 24px;
338
+ display: flex;
339
+ flex-direction: column;
340
+ justify-content: center;
341
+ }
342
+
343
+ .um-standalone[data-container="boxed"] {
344
+ background: var(--um-muted);
345
+ }
346
+
347
+ .um-standalone-inner {
348
+ width: 100%;
349
+ max-width: 1080px;
350
+ margin-inline: auto;
351
+ display: flex;
352
+ flex-direction: column;
353
+ gap: 16px;
354
+ }
355
+
356
+ .um-standalone[data-container="boxed"] .um-standalone-inner {
357
+ max-width: 520px;
358
+ }
359
+
360
+ .um-card {
361
+ border: 1px solid var(--um-border);
362
+ border-radius: var(--um-radius);
363
+ background: var(--um-surface);
364
+ padding: 18px 20px;
365
+ display: flex;
366
+ flex-direction: column;
367
+ gap: 12px;
368
+ }
369
+
370
+ .um-card-title {
371
+ margin: 0;
372
+ font-size: 16px;
373
+ font-weight: 600;
374
+ }
375
+
376
+ .um-card-desc {
377
+ margin: 0;
378
+ font-size: 13px;
379
+ color: var(--um-muted-fg);
380
+ }
381
+
382
+ .um-stat-label {
383
+ font-size: 12px;
384
+ color: var(--um-muted-fg);
385
+ }
386
+
387
+ .um-stat-value {
388
+ font-size: 26px;
389
+ font-weight: 700;
390
+ letter-spacing: -0.02em;
391
+ }
392
+
393
+ .um-badge {
394
+ display: inline-flex;
395
+ align-items: center;
396
+ padding: 2px 8px;
397
+ border-radius: 999px;
398
+ font-size: 12px;
399
+ font-weight: 500;
400
+ background: var(--um-muted);
401
+ color: var(--um-fg);
402
+ border: 1px solid var(--um-border);
403
+ }
404
+
405
+ .um-btn {
406
+ display: inline-flex;
407
+ align-items: center;
408
+ justify-content: center;
409
+ gap: 6px;
410
+ padding: 8px 14px;
411
+ border-radius: 8px;
412
+ border: 1px solid var(--um-primary);
413
+ background: var(--um-primary);
414
+ color: var(--um-primary-fg);
415
+ font-weight: 500;
416
+ font-size: 14px;
417
+ cursor: pointer;
418
+ }
419
+
420
+ .um-btn-secondary {
421
+ background: var(--um-surface);
422
+ color: var(--um-fg);
423
+ border-color: var(--um-border);
424
+ }
425
+
426
+ .um-input,
427
+ .um-select,
428
+ .um-textarea {
429
+ width: 100%;
430
+ padding: 8px 10px;
431
+ border-radius: 8px;
432
+ border: 1px solid var(--um-border);
433
+ background: var(--um-surface);
434
+ color: var(--um-fg);
435
+ font: inherit;
436
+ }
437
+
438
+ .um-field {
439
+ display: flex;
440
+ flex-direction: column;
441
+ gap: 5px;
442
+ }
443
+
444
+ .um-field label {
445
+ font-size: 13px;
446
+ font-weight: 500;
447
+ }
448
+
449
+ .um-table-wrap {
450
+ width: 100%;
451
+ overflow-x: auto;
452
+ border: 1px solid var(--um-border);
453
+ border-radius: var(--um-radius);
454
+ }
455
+
456
+ .um-table {
457
+ width: 100%;
458
+ border-collapse: collapse;
459
+ font-size: 13px;
460
+ }
461
+
462
+ .um-table th,
463
+ .um-table td {
464
+ padding: 10px 12px;
465
+ text-align: start;
466
+ border-bottom: 1px solid var(--um-border);
467
+ }
468
+
469
+ .um-table th {
470
+ font-weight: 600;
471
+ color: var(--um-muted-fg);
472
+ background: var(--um-muted);
473
+ }
474
+
475
+ .um-alert {
476
+ padding: 12px 14px;
477
+ border-radius: var(--um-radius);
478
+ border: 1px solid var(--um-border);
479
+ background: var(--um-muted);
480
+ }
481
+
482
+ .um-toast-stack {
483
+ position: fixed;
484
+ right: 16px;
485
+ bottom: 16px;
486
+ display: flex;
487
+ flex-direction: column;
488
+ gap: 8px;
489
+ z-index: 90;
490
+ }
491
+
492
+ .um-toast {
493
+ padding: 10px 14px;
494
+ border-radius: 8px;
495
+ background: var(--um-primary);
496
+ color: var(--um-primary-fg);
497
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
498
+ font-size: 13px;
499
+ }
500
+
501
+ @media (max-width: 767px) {
502
+ .um-sidebar,
503
+ .um-rail,
504
+ .um-top-links {
505
+ display: none;
506
+ }
507
+ .um-mobile-only {
508
+ display: inline-flex;
509
+ }
510
+ .um-root[data-shell="sidebar-inset"] .um-main {
511
+ margin: 0;
512
+ border-radius: 0;
513
+ border: 0;
514
+ }
515
+ .um-content {
516
+ padding: 16px;
517
+ }
518
+ }
519
+ `}function zt(e){return`import {
520
+ createContext,
521
+ useCallback,
522
+ useContext,
523
+ useEffect,
524
+ useMemo,
525
+ useState,
526
+ type FormEvent,
527
+ type ReactNode,
528
+ } from "react";
529
+
530
+ export interface MaterializedAction {
531
+ action: string;
532
+ params?: Record<string, unknown>;
533
+ }
534
+
535
+ export interface MaterializedBlock {
536
+ id?: string;
537
+ type: string;
538
+ props?: Record<string, unknown>;
539
+ visible?: unknown;
540
+ events?: Record<string, MaterializedAction[]>;
541
+ children?: MaterializedBlock[];
542
+ slots?: Record<string, MaterializedBlock[]>;
543
+ }
544
+
545
+ export interface RouterContextValue {
546
+ path: string;
547
+ navigate: (nextPath: string) => void;
548
+ pushToast: (message: string) => void;
549
+ dispatchHostAction: (action: string, params: Record<string, unknown>) => void;
550
+ }
551
+
552
+ const RouterContext = createContext<RouterContextValue>({
553
+ path: "/",
554
+ navigate: () => {},
555
+ pushToast: () => {},
556
+ dispatchHostAction: () => {},
557
+ });
558
+
559
+ export function useAppRouter(): RouterContextValue {
560
+ return useContext(RouterContext);
561
+ }
562
+
563
+ const INITIAL_MOCK_COLLECTIONS: Record<string, Record<string, unknown>[]> = ${e};
564
+
565
+ export function RouterProvider({
566
+ initialPath,
567
+ fallbackPath = "/",
568
+ onNavigate,
569
+ onHostAction,
570
+ children,
571
+ }: {
572
+ initialPath?: string;
573
+ fallbackPath?: string;
574
+ onNavigate?: (nextPath: string) => void;
575
+ onHostAction?: (action: string, params: Record<string, unknown>) => void;
576
+ children: ReactNode;
577
+ }) {
578
+ const [path, setPath] = useState<string>(() => {
579
+ if (initialPath) return initialPath;
580
+ if (typeof window !== "undefined" && window.location.pathname) {
581
+ return window.location.pathname;
582
+ }
583
+ return fallbackPath;
584
+ });
585
+ const [toasts, setToasts] = useState<Array<{ id: number; message: string }>>([]);
586
+
587
+ useEffect(() => {
588
+ if (initialPath) setPath(initialPath);
589
+ }, [initialPath]);
590
+
591
+ useEffect(() => {
592
+ if (typeof window === "undefined") return;
593
+ const onPop = () => setPath(window.location.pathname || "/");
594
+ window.addEventListener("popstate", onPop);
595
+ return () => window.removeEventListener("popstate", onPop);
596
+ }, []);
597
+
598
+ const navigate = useCallback(
599
+ (nextPath: string) => {
600
+ if (!nextPath) return;
601
+ setPath(nextPath);
602
+ if (typeof window !== "undefined" && nextPath.startsWith("/")) {
603
+ window.history.pushState({}, "", nextPath);
604
+ }
605
+ onNavigate?.(nextPath);
606
+ },
607
+ [onNavigate],
608
+ );
609
+
610
+ const pushToast = useCallback((message: string) => {
611
+ const id = Date.now() + Math.floor(Math.random() * 1000);
612
+ setToasts((prev) => [...prev.slice(-3), { id, message }]);
613
+ setTimeout(() => {
614
+ setToasts((prev) => prev.filter((item) => item.id !== id));
615
+ }, 3200);
616
+ }, []);
617
+
618
+ const dispatchHostAction = useCallback(
619
+ (action: string, params: Record<string, unknown>) => {
620
+ onHostAction?.(action, params);
621
+ },
622
+ [onHostAction],
623
+ );
624
+
625
+ const value = useMemo<RouterContextValue>(
626
+ () => ({ path, navigate, pushToast, dispatchHostAction }),
627
+ [path, navigate, pushToast, dispatchHostAction],
628
+ );
629
+
630
+ return (
631
+ <RouterContext.Provider value={value}>
632
+ {children}
633
+ {toasts.length > 0 && (
634
+ <div className="um-toast-stack" role="status" aria-live="polite">
635
+ {toasts.map((toast) => (
636
+ <div key={toast.id} className="um-toast">
637
+ {toast.message}
638
+ </div>
639
+ ))}
640
+ </div>
641
+ )}
642
+ </RouterContext.Provider>
643
+ );
644
+ }
645
+
646
+ export function AppLink({
647
+ href,
648
+ className,
649
+ ariaCurrent,
650
+ title,
651
+ ariaLabel,
652
+ onAfterClick,
653
+ children,
654
+ }: {
655
+ href: string;
656
+ className?: string;
657
+ ariaCurrent?: "page";
658
+ title?: string;
659
+ ariaLabel?: string;
660
+ onAfterClick?: () => void;
661
+ children: ReactNode;
662
+ }) {
663
+ const { navigate } = useAppRouter();
664
+ return (
665
+ <a
666
+ href={href}
667
+ className={className}
668
+ aria-current={ariaCurrent}
669
+ title={title}
670
+ aria-label={ariaLabel}
671
+ onClick={(event) => {
672
+ if (
673
+ event.button !== 0 ||
674
+ event.metaKey ||
675
+ event.ctrlKey ||
676
+ event.shiftKey ||
677
+ event.altKey ||
678
+ !href.startsWith("/")
679
+ ) {
680
+ return;
681
+ }
682
+ event.preventDefault();
683
+ navigate(href);
684
+ onAfterClick?.();
685
+ }}
686
+ >
687
+ {children}
688
+ </a>
689
+ );
690
+ }
691
+
692
+ export function ShellIcon({ name, size = 16 }: { name?: string; size?: number }) {
693
+ const common = {
694
+ width: size,
695
+ height: size,
696
+ viewBox: "0 0 24 24",
697
+ fill: "none",
698
+ stroke: "currentColor",
699
+ strokeWidth: 2,
700
+ strokeLinecap: "round" as const,
701
+ strokeLinejoin: "round" as const,
702
+ "aria-hidden": true,
703
+ };
704
+ switch (name) {
705
+ case "search":
706
+ return (
707
+ <svg {...common}>
708
+ <circle cx="11" cy="11" r="8" />
709
+ <path d="m21 21-4.3-4.3" />
710
+ </svg>
711
+ );
712
+ case "x":
713
+ return (
714
+ <svg {...common}>
715
+ <path d="M18 6 6 18" />
716
+ <path d="m6 6 12 12" />
717
+ </svg>
718
+ );
719
+ case "menu":
720
+ return (
721
+ <svg {...common}>
722
+ <path d="M4 6h16M4 12h16M4 18h16" />
723
+ </svg>
724
+ );
725
+ case "panel-left":
726
+ return (
727
+ <svg {...common}>
728
+ <rect width="18" height="18" x="3" y="3" rx="2" />
729
+ <path d="M9 3v18" />
730
+ </svg>
731
+ );
732
+ case "chevron-left":
733
+ return (
734
+ <svg {...common}>
735
+ <path d="m15 18-6-6 6-6" />
736
+ </svg>
737
+ );
738
+ case "chevron-right":
739
+ return (
740
+ <svg {...common}>
741
+ <path d="m9 18 6-6-6-6" />
742
+ </svg>
743
+ );
744
+ case "sun":
745
+ return (
746
+ <svg {...common}>
747
+ <circle cx="12" cy="12" r="4" />
748
+ <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" />
749
+ </svg>
750
+ );
751
+ case "moon":
752
+ return (
753
+ <svg {...common}>
754
+ <path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
755
+ </svg>
756
+ );
757
+ case "settings":
758
+ return (
759
+ <svg {...common}>
760
+ <circle cx="12" cy="12" r="3" />
761
+ <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" />
762
+ </svg>
763
+ );
764
+ case "layout-dashboard":
765
+ return (
766
+ <svg {...common}>
767
+ <rect width="7" height="9" x="3" y="3" rx="1" />
768
+ <rect width="7" height="5" x="14" y="3" rx="1" />
769
+ <rect width="7" height="9" x="14" y="12" rx="1" />
770
+ <rect width="7" height="5" x="3" y="16" rx="1" />
771
+ </svg>
772
+ );
773
+ default:
774
+ return (
775
+ <svg {...common}>
776
+ <rect width="18" height="18" x="3" y="3" rx="3" />
777
+ <path d="M8 8h8M8 12h8M8 16h5" />
778
+ </svg>
779
+ );
780
+ }
781
+ }
782
+
783
+ function getByPath(source: Record<string, unknown>, keyPath: string): unknown {
784
+ const segments = keyPath.split(".");
785
+ let current: unknown = source;
786
+ for (const segment of segments) {
787
+ if (!current || typeof current !== "object") return undefined;
788
+ current = (current as Record<string, unknown>)[segment];
789
+ }
790
+ return current;
791
+ }
792
+
793
+ function setByPath(
794
+ source: Record<string, unknown>,
795
+ keyPath: string,
796
+ value: unknown,
797
+ ): Record<string, unknown> {
798
+ const segments = keyPath.split(".");
799
+ if (segments.length === 1) {
800
+ return { ...source, [keyPath]: value };
801
+ }
802
+ const head = segments[0] ?? keyPath;
803
+ const tail = segments.slice(1).join(".");
804
+ const nested =
805
+ source[head] && typeof source[head] === "object" && !Array.isArray(source[head])
806
+ ? (source[head] as Record<string, unknown>)
807
+ : {};
808
+ return { ...source, [head]: setByPath(nested, tail, value) };
809
+ }
810
+
811
+ export function resolveExpr(
812
+ expr: unknown,
813
+ state: Record<string, unknown>,
814
+ eventValue?: unknown,
815
+ ): unknown {
816
+ if (expr === null || expr === undefined) return expr;
817
+ if (Array.isArray(expr)) return expr.map((item) => resolveExpr(item, state, eventValue));
818
+ if (typeof expr !== "object") return expr;
819
+
820
+ const record = expr as Record<string, unknown>;
821
+ if (typeof record._state === "string") return getByPath(state, record._state);
822
+ if (typeof record._bindState === "string") return getByPath(state, record._bindState);
823
+ if (record._event !== undefined) {
824
+ if (typeof record._event === "string" && eventValue && typeof eventValue === "object") {
825
+ return getByPath(eventValue as Record<string, unknown>, record._event);
826
+ }
827
+ return eventValue;
828
+ }
829
+ if (Array.isArray(record._eq) && record._eq.length === 2) {
830
+ return (
831
+ resolveExpr(record._eq[0], state, eventValue) ===
832
+ resolveExpr(record._eq[1], state, eventValue)
833
+ );
834
+ }
835
+ if (Array.isArray(record._ne) && record._ne.length === 2) {
836
+ return (
837
+ resolveExpr(record._ne[0], state, eventValue) !==
838
+ resolveExpr(record._ne[1], state, eventValue)
839
+ );
840
+ }
841
+ if ("_not" in record) return !resolveExpr(record._not, state, eventValue);
842
+ if (Array.isArray(record._and)) {
843
+ return record._and.every((item) => Boolean(resolveExpr(item, state, eventValue)));
844
+ }
845
+ if (Array.isArray(record._or)) {
846
+ return record._or.some((item) => Boolean(resolveExpr(item, state, eventValue)));
847
+ }
848
+ if (record._if && typeof record._if === "object") {
849
+ const cond = record._if as { test?: unknown; then?: unknown; else?: unknown };
850
+ return resolveExpr(cond.test, state, eventValue)
851
+ ? resolveExpr(cond.then, state, eventValue)
852
+ : resolveExpr(cond.else, state, eventValue);
853
+ }
854
+
855
+ const resolved: Record<string, unknown> = {};
856
+ for (const [key, val] of Object.entries(record)) {
857
+ resolved[key] = resolveExpr(val, state, eventValue);
858
+ }
859
+ return resolved;
860
+ }
861
+
862
+ export function usePageRuntime(initialState: Record<string, unknown>) {
863
+ const [state, setState] = useState<Record<string, unknown>>(() => structuredClone(initialState));
864
+ const [collections, setCollections] = useState<Record<string, Record<string, unknown>[]>>(() =>
865
+ structuredClone(INITIAL_MOCK_COLLECTIONS),
866
+ );
867
+ const router = useAppRouter();
868
+
869
+ const updateKey = useCallback((key: string, value: unknown) => {
870
+ setState((prev) => setByPath(prev, key, value));
871
+ }, []);
872
+
873
+ const runActions = useCallback(
874
+ (actions: MaterializedAction[] | undefined, eventValue?: unknown) => {
875
+ if (!actions?.length) return;
876
+ for (const act of actions) {
877
+ const params = (resolveExpr(act.params ?? {}, state, eventValue) ?? {}) as Record<
878
+ string,
879
+ unknown
880
+ >;
881
+ if (act.action === "SetState") {
882
+ for (const [k, v] of Object.entries(params)) {
883
+ if (k === "path" && typeof v === "string" && "value" in params) {
884
+ updateKey(v, params.value);
885
+ } else if (k !== "value" || !("path" in params)) {
886
+ updateKey(k, v);
887
+ }
888
+ }
889
+ continue;
890
+ }
891
+ if (act.action === "ResetState") {
892
+ setState(structuredClone(initialState));
893
+ continue;
894
+ }
895
+ if (act.action === "Link" || act.action === "Navigate") {
896
+ const to = typeof params.to === "string" ? params.to : String(params.href ?? "/");
897
+ router.navigate(to);
898
+ continue;
899
+ }
900
+ if (act.action === "DisplayMessage" || act.action === "Toast") {
901
+ const msg =
902
+ typeof params.content === "string"
903
+ ? params.content
904
+ : typeof params.message === "string"
905
+ ? params.message
906
+ : typeof params.title === "string"
907
+ ? params.title
908
+ : "Action completed";
909
+ router.pushToast(msg);
910
+ continue;
911
+ }
912
+ if (act.action === "Request") {
913
+ const connectionId = typeof params.connectionId === "string" ? params.connectionId : "";
914
+ const operation = typeof params.operation === "string" ? params.operation : "FindPage";
915
+ const responsePath =
916
+ typeof params.responsePath === "string" ? params.responsePath : "rows";
917
+ const existing = collections[connectionId] ?? [];
918
+ if (operation === "FindPage" || operation === "list") {
919
+ updateKey(responsePath, existing);
920
+ } else if (operation === "InsertOne" || operation === "create") {
921
+ const payload =
922
+ params.payload && typeof params.payload === "object"
923
+ ? (params.payload as Record<string, unknown>)
924
+ : {};
925
+ const nextRows = [...existing, { id: \`row-\${Date.now()}\`, ...payload }];
926
+ setCollections((prev) => ({ ...prev, [connectionId]: nextRows }));
927
+ updateKey(responsePath, nextRows);
928
+ } else if (operation === "DeleteOne" || operation === "delete") {
929
+ const targetId = String(params.id ?? "");
930
+ const nextRows = existing.filter((row) => String(row.id ?? "") !== targetId);
931
+ setCollections((prev) => ({ ...prev, [connectionId]: nextRows }));
932
+ updateKey(responsePath, nextRows);
933
+ }
934
+ continue;
935
+ }
936
+ router.dispatchHostAction(act.action, params);
937
+ }
938
+ },
939
+ [collections, initialState, router, state, updateKey],
940
+ );
941
+
942
+ return { state, updateKey, runActions };
943
+ }
944
+
945
+ function asText(value: unknown, fallback = ""): string {
946
+ if (typeof value === "string") return value;
947
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
948
+ return fallback;
949
+ }
950
+
951
+ export function BlockList({
952
+ blocks,
953
+ state,
954
+ updateKey,
955
+ runActions,
956
+ }: {
957
+ blocks: MaterializedBlock[];
958
+ state: Record<string, unknown>;
959
+ updateKey: (key: string, value: unknown) => void;
960
+ runActions: (actions: MaterializedAction[] | undefined, eventValue?: unknown) => void;
961
+ }) {
962
+ return (
963
+ <>
964
+ {blocks.map((block, index) => (
965
+ <BlockItem
966
+ key={block.id ?? \`\${block.type}-\${index}\`}
967
+ block={block}
968
+ state={state}
969
+ updateKey={updateKey}
970
+ runActions={runActions}
971
+ />
972
+ ))}
973
+ </>
974
+ );
975
+ }
976
+
977
+ function TableBlock({
978
+ props,
979
+ }: {
980
+ props: Record<string, unknown>;
981
+ }) {
982
+ const [search, setSearch] = useState("");
983
+ const rawColumns = Array.isArray(props.columns) ? props.columns : [];
984
+ const rawRows = Array.isArray(props.rows)
985
+ ? props.rows
986
+ : Array.isArray(props.data)
987
+ ? props.data
988
+ : [];
989
+ const rows = rawRows.filter((row): row is Record<string, unknown> =>
990
+ Boolean(row && typeof row === "object"),
991
+ );
992
+ const columns =
993
+ rawColumns.length > 0
994
+ ? rawColumns.map((col) => {
995
+ if (typeof col === "string") return { key: col, label: col };
996
+ const obj = col as Record<string, unknown>;
997
+ const key = asText(obj.key, asText(obj.accessorKey, "id"));
998
+ return { key, label: asText(obj.label, asText(obj.header, key)) };
999
+ })
1000
+ : rows[0]
1001
+ ? Object.keys(rows[0]).map((key) => ({ key, label: key }))
1002
+ : [];
1003
+ const filtered = search.trim()
1004
+ ? rows.filter((row) =>
1005
+ Object.values(row).some((v) =>
1006
+ asText(v).toLowerCase().includes(search.trim().toLowerCase()),
1007
+ ),
1008
+ )
1009
+ : rows;
1010
+
1011
+ return (
1012
+ <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
1013
+ {props.searchable !== false && (
1014
+ <input
1015
+ type="search"
1016
+ className="um-input"
1017
+ style={{ maxWidth: 280 }}
1018
+ placeholder="Filter rows..."
1019
+ aria-label="Filter table rows"
1020
+ value={search}
1021
+ onChange={(event) => setSearch(event.target.value)}
1022
+ />
1023
+ )}
1024
+ <div className="um-table-wrap">
1025
+ <table className="um-table">
1026
+ <thead>
1027
+ <tr>
1028
+ {columns.map((col) => (
1029
+ <th key={col.key}>{col.label}</th>
1030
+ ))}
1031
+ </tr>
1032
+ </thead>
1033
+ <tbody>
1034
+ {filtered.map((row, idx) => (
1035
+ <tr key={asText(row.id, String(idx))}>
1036
+ {columns.map((col) => (
1037
+ <td key={col.key}>{asText(row[col.key], "\u2014")}</td>
1038
+ ))}
1039
+ </tr>
1040
+ ))}
1041
+ {filtered.length === 0 && (
1042
+ <tr>
1043
+ <td colSpan={Math.max(1, columns.length)} style={{ color: "var(--um-muted-fg)" }}>
1044
+ No matching records.
1045
+ </td>
1046
+ </tr>
1047
+ )}
1048
+ </tbody>
1049
+ </table>
1050
+ </div>
1051
+ </div>
1052
+ );
1053
+ }
1054
+
1055
+ function BlockItem({
1056
+ block,
1057
+ state,
1058
+ updateKey,
1059
+ runActions,
1060
+ }: {
1061
+ block: MaterializedBlock;
1062
+ state: Record<string, unknown>;
1063
+ updateKey: (key: string, value: unknown) => void;
1064
+ runActions: (actions: MaterializedAction[] | undefined, eventValue?: unknown) => void;
1065
+ }) {
1066
+ if (block.visible !== undefined && !resolveExpr(block.visible, state)) {
1067
+ return null;
1068
+ }
1069
+ const rawProps = block.props ?? {};
1070
+ const props = (resolveExpr(rawProps, state) ?? {}) as Record<string, unknown>;
1071
+ const children = block.children?.length ? (
1072
+ <BlockList
1073
+ blocks={block.children}
1074
+ state={state}
1075
+ updateKey={updateKey}
1076
+ runActions={runActions}
1077
+ />
1078
+ ) : null;
1079
+
1080
+ switch (block.type) {
1081
+ case "Heading": {
1082
+ const level = Number(props.level ?? 1);
1083
+ const text = asText(props.text, asText(props.title));
1084
+ if (level <= 1) return <h1 style={{ margin: 0, fontSize: 24, fontWeight: 700 }}>{text}</h1>;
1085
+ if (level === 2) return <h2 style={{ margin: 0, fontSize: 19, fontWeight: 600 }}>{text}</h2>;
1086
+ return <h3 style={{ margin: 0, fontSize: 16, fontWeight: 600 }}>{text}</h3>;
1087
+ }
1088
+ case "Paragraph":
1089
+ case "Text":
1090
+ case "Markdown":
1091
+ return (
1092
+ <p
1093
+ style={{
1094
+ margin: 0,
1095
+ color: props.muted ? "var(--um-muted-fg)" : "inherit",
1096
+ }}
1097
+ >
1098
+ {asText(props.text, asText(props.content))}
1099
+ </p>
1100
+ );
1101
+ case "Badge":
1102
+ return <span className="um-badge">{asText(props.text, asText(props.label))}</span>;
1103
+ case "Alert":
1104
+ return (
1105
+ <div className="um-alert" role="status">
1106
+ {typeof props.title === "string" && <strong>{props.title}</strong>}
1107
+ <div>{asText(props.description, asText(props.text, asText(props.message)))}</div>
1108
+ </div>
1109
+ );
1110
+ case "Divider":
1111
+ return <hr style={{ border: 0, borderTop: "1px solid var(--um-border)", width: "100%" }} />;
1112
+ case "Stat":
1113
+ case "StatCard":
1114
+ return (
1115
+ <div className="um-card">
1116
+ <span className="um-stat-label">{asText(props.label, asText(props.title))}</span>
1117
+ <span className="um-stat-value">{asText(props.value, "0")}</span>
1118
+ {(props.note !== undefined || props.delta !== undefined) && (
1119
+ <span className="um-card-desc">{asText(props.note, asText(props.delta))}</span>
1120
+ )}
1121
+ </div>
1122
+ );
1123
+ case "Card":
1124
+ return (
1125
+ <section className="um-card">
1126
+ {typeof props.title === "string" && <h3 className="um-card-title">{props.title}</h3>}
1127
+ {typeof props.description === "string" && (
1128
+ <p className="um-card-desc">{props.description}</p>
1129
+ )}
1130
+ {children}
1131
+ </section>
1132
+ );
1133
+ case "Box":
1134
+ case "Stack": {
1135
+ const direction = props.direction === "row" ? "row" : "column";
1136
+ return (
1137
+ <div style={{ display: "flex", flexDirection: direction, gap: 14, flexWrap: "wrap" }}>
1138
+ {children}
1139
+ </div>
1140
+ );
1141
+ }
1142
+ case "Grid":
1143
+ case "StatGrid": {
1144
+ const cols = Math.max(1, Math.min(4, Number(props.columns ?? 3)));
1145
+ return (
1146
+ <div
1147
+ style={{
1148
+ display: "grid",
1149
+ gridTemplateColumns: \`repeat(auto-fit, minmax(\${Math.floor(720 / cols)}px, 1fr))\`,
1150
+ gap: 14,
1151
+ }}
1152
+ >
1153
+ {children}
1154
+ </div>
1155
+ );
1156
+ }
1157
+ case "Button":
1158
+ return (
1159
+ <button
1160
+ type="button"
1161
+ className={
1162
+ props.variant === "outline" || props.variant === "secondary" || props.variant === "ghost"
1163
+ ? "um-btn um-btn-secondary"
1164
+ : "um-btn"
1165
+ }
1166
+ onClick={() => runActions(block.events?.onClick, { type: "click" })}
1167
+ >
1168
+ {asText(props.label, asText(props.text, "Button"))}
1169
+ </button>
1170
+ );
1171
+ case "Link":
1172
+ case "MenuLink":
1173
+ return (
1174
+ <AppLink href={asText(props.href, asText(props.to, "/"))} className="um-nav-link">
1175
+ {asText(props.label, asText(props.text, asText(props.href, "Link")))}
1176
+ </AppLink>
1177
+ );
1178
+ case "Table":
1179
+ case "DataTable":
1180
+ case "SearchableTable":
1181
+ return <TableBlock props={props} />;
1182
+ case "CollectionKanban": {
1183
+ const kRows = (Array.isArray(props.rows) ? props.rows : []).filter(
1184
+ (r): r is Record<string, unknown> => Boolean(r && typeof r === "object"),
1185
+ );
1186
+ const groupBy = asText(props.groupBy, "status");
1187
+ const titleField = asText(props.titleField, "title");
1188
+ const rawLanes = Array.isArray(props.lanes) ? props.lanes : [];
1189
+ const lanes = rawLanes
1190
+ .filter((l): l is Record<string, unknown> => Boolean(l && typeof l === "object"))
1191
+ .map((l) => ({ value: asText(l.value), label: asText(l.label, asText(l.value)) }));
1192
+ return (
1193
+ <div
1194
+ data-uibot-block="CollectionKanban"
1195
+ style={{
1196
+ display: "grid",
1197
+ gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))",
1198
+ gap: 14,
1199
+ }}
1200
+ >
1201
+ {lanes.map((lane) => {
1202
+ const laneRows = kRows.filter((row) => asText(row[groupBy]) === lane.value);
1203
+ return (
1204
+ <div key={lane.value} className="um-card" style={{ background: "var(--um-muted)" }}>
1205
+ <strong>
1206
+ {lane.label} ({laneRows.length})
1207
+ </strong>
1208
+ {laneRows.map((row, idx) => (
1209
+ <button
1210
+ key={asText(row.id, String(idx))}
1211
+ type="button"
1212
+ className="um-card"
1213
+ style={{ textAlign: "start", cursor: "pointer" }}
1214
+ onClick={() =>
1215
+ runActions(block.events?.onSelect, { values: { id: asText(row.id) } })
1216
+ }
1217
+ >
1218
+ <strong>{asText(row[titleField], asText(row.id))}</strong>
1219
+ {typeof row.description === "string" && (
1220
+ <span className="um-card-desc">{row.description}</span>
1221
+ )}
1222
+ </button>
1223
+ ))}
1224
+ </div>
1225
+ );
1226
+ })}
1227
+ </div>
1228
+ );
1229
+ }
1230
+ case "ItemGrid": {
1231
+ const items = (Array.isArray(props.items) ? props.items : []).filter(
1232
+ (r): r is Record<string, unknown> => Boolean(r && typeof r === "object"),
1233
+ );
1234
+ return (
1235
+ <div
1236
+ data-uibot-block="ItemGrid"
1237
+ style={{
1238
+ display: "grid",
1239
+ gridTemplateColumns: "repeat(auto-fit, minmax(240px, 1fr))",
1240
+ gap: 14,
1241
+ }}
1242
+ >
1243
+ {items.map((item, idx) => (
1244
+ <button
1245
+ key={asText(item.id, String(idx))}
1246
+ type="button"
1247
+ className="um-card"
1248
+ style={{ textAlign: "start", cursor: "pointer" }}
1249
+ onClick={() =>
1250
+ runActions(block.events?.onSelect, { values: { id: asText(item.id) } })
1251
+ }
1252
+ >
1253
+ <strong className="um-card-title">{asText(item.title, asText(item.id))}</strong>
1254
+ {typeof item.description === "string" && (
1255
+ <p className="um-card-desc">{item.description}</p>
1256
+ )}
1257
+ </button>
1258
+ ))}
1259
+ </div>
1260
+ );
1261
+ }
1262
+ case "RecordMasterDetail": {
1263
+ const mdRows = (Array.isArray(props.rows) ? props.rows : []).filter(
1264
+ (r): r is Record<string, unknown> => Boolean(r && typeof r === "object"),
1265
+ );
1266
+ const selectedId = asText(props.selectedId);
1267
+ const active = mdRows.find((r) => asText(r.id) === selectedId) ?? mdRows[0];
1268
+ const detailBlocks = block.slots?.detail ?? [];
1269
+ return (
1270
+ <div
1271
+ data-uibot-block="RecordMasterDetail"
1272
+ style={{
1273
+ display: "grid",
1274
+ gridTemplateColumns: "minmax(220px, 1fr) minmax(0, 2fr)",
1275
+ gap: 16,
1276
+ }}
1277
+ >
1278
+ <div className="um-card" style={{ gap: 6 }}>
1279
+ {mdRows.map((row, idx) => (
1280
+ <button
1281
+ key={asText(row.id, String(idx))}
1282
+ type="button"
1283
+ className="um-nav-link"
1284
+ aria-current={asText(row.id) === asText(active?.id) ? "page" : undefined}
1285
+ onClick={() =>
1286
+ runActions(block.events?.onSelect, { values: { id: asText(row.id) } })
1287
+ }
1288
+ >
1289
+ {asText(row.title, asText(row.id))}
1290
+ </button>
1291
+ ))}
1292
+ </div>
1293
+ <div className="um-card">
1294
+ {active && (
1295
+ <>
1296
+ <h3 className="um-card-title">{asText(active.title, asText(active.id))}</h3>
1297
+ {typeof active.description === "string" && (
1298
+ <p className="um-card-desc">{active.description}</p>
1299
+ )}
1300
+ </>
1301
+ )}
1302
+ {detailBlocks.length > 0 && (
1303
+ <BlockList
1304
+ blocks={detailBlocks}
1305
+ state={state}
1306
+ updateKey={updateKey}
1307
+ runActions={runActions}
1308
+ />
1309
+ )}
1310
+ </div>
1311
+ </div>
1312
+ );
1313
+ }
1314
+ case "Form": {
1315
+ const handleSubmit = (event: FormEvent) => {
1316
+ event.preventDefault();
1317
+ runActions(block.events?.onSubmit, state);
1318
+ };
1319
+ return (
1320
+ <form
1321
+ onSubmit={handleSubmit}
1322
+ style={{ display: "flex", flexDirection: "column", gap: 14, maxWidth: 560 }}
1323
+ >
1324
+ {children}
1325
+ </form>
1326
+ );
1327
+ }
1328
+ case "Form.Input":
1329
+ case "Field": {
1330
+ const bindKey =
1331
+ rawProps.value &&
1332
+ typeof rawProps.value === "object" &&
1333
+ typeof (rawProps.value as Record<string, unknown>)._bindState === "string"
1334
+ ? ((rawProps.value as Record<string, unknown>)._bindState as string)
1335
+ : typeof props.name === "string"
1336
+ ? props.name
1337
+ : "";
1338
+ const inputId = block.id ?? \`field-\${bindKey || "input"}\`;
1339
+ const val = asText(props.value);
1340
+ return (
1341
+ <div className="um-field">
1342
+ {typeof props.label === "string" && <label htmlFor={inputId}>{props.label}</label>}
1343
+ <input
1344
+ id={inputId}
1345
+ name={asText(props.name, bindKey)}
1346
+ type={asText(props.inputType, asText(props.type, "text"))}
1347
+ className="um-input"
1348
+ placeholder={asText(props.placeholder)}
1349
+ value={val}
1350
+ onChange={(event) => {
1351
+ if (bindKey) updateKey(bindKey, event.target.value);
1352
+ runActions(block.events?.onChange, { value: event.target.value });
1353
+ }}
1354
+ />
1355
+ </div>
1356
+ );
1357
+ }
1358
+ case "Form.TextArea": {
1359
+ const bindKey =
1360
+ rawProps.value &&
1361
+ typeof rawProps.value === "object" &&
1362
+ typeof (rawProps.value as Record<string, unknown>)._bindState === "string"
1363
+ ? ((rawProps.value as Record<string, unknown>)._bindState as string)
1364
+ : typeof props.name === "string"
1365
+ ? props.name
1366
+ : "";
1367
+ const inputId = block.id ?? \`textarea-\${bindKey || "input"}\`;
1368
+ return (
1369
+ <div className="um-field">
1370
+ {typeof props.label === "string" && <label htmlFor={inputId}>{props.label}</label>}
1371
+ <textarea
1372
+ id={inputId}
1373
+ className="um-textarea"
1374
+ rows={Number(props.rows ?? 4)}
1375
+ value={asText(props.value)}
1376
+ onChange={(event) => {
1377
+ if (bindKey) updateKey(bindKey, event.target.value);
1378
+ runActions(block.events?.onChange, { value: event.target.value });
1379
+ }}
1380
+ />
1381
+ </div>
1382
+ );
1383
+ }
1384
+ case "Form.Select": {
1385
+ const bindKey =
1386
+ rawProps.value &&
1387
+ typeof rawProps.value === "object" &&
1388
+ typeof (rawProps.value as Record<string, unknown>)._bindState === "string"
1389
+ ? ((rawProps.value as Record<string, unknown>)._bindState as string)
1390
+ : typeof props.name === "string"
1391
+ ? props.name
1392
+ : "";
1393
+ const inputId = block.id ?? \`select-\${bindKey || "input"}\`;
1394
+ const options = Array.isArray(props.options) ? props.options : [];
1395
+ return (
1396
+ <div className="um-field">
1397
+ {typeof props.label === "string" && <label htmlFor={inputId}>{props.label}</label>}
1398
+ <select
1399
+ id={inputId}
1400
+ className="um-select"
1401
+ value={asText(props.value)}
1402
+ onChange={(event) => {
1403
+ if (bindKey) updateKey(bindKey, event.target.value);
1404
+ runActions(block.events?.onChange, { value: event.target.value });
1405
+ }}
1406
+ >
1407
+ {options.map((opt) => {
1408
+ const obj =
1409
+ opt && typeof opt === "object"
1410
+ ? (opt as Record<string, unknown>)
1411
+ : { value: String(opt), label: String(opt) };
1412
+ const val = asText(obj.value);
1413
+ return (
1414
+ <option key={val} value={val}>
1415
+ {asText(obj.label, val)}
1416
+ </option>
1417
+ );
1418
+ })}
1419
+ </select>
1420
+ </div>
1421
+ );
1422
+ }
1423
+ case "Form.Checkbox": {
1424
+ const bindKey =
1425
+ rawProps.checked &&
1426
+ typeof rawProps.checked === "object" &&
1427
+ typeof (rawProps.checked as Record<string, unknown>)._bindState === "string"
1428
+ ? ((rawProps.checked as Record<string, unknown>)._bindState as string)
1429
+ : typeof props.name === "string"
1430
+ ? props.name
1431
+ : "";
1432
+ return (
1433
+ <label style={{ display: "inline-flex", alignItems: "center", gap: 8 }}>
1434
+ <input
1435
+ type="checkbox"
1436
+ checked={Boolean(props.checked ?? props.value)}
1437
+ onChange={(event) => {
1438
+ if (bindKey) updateKey(bindKey, event.target.checked);
1439
+ runActions(block.events?.onChange, { checked: event.target.checked });
1440
+ }}
1441
+ />
1442
+ <span>{asText(props.label, bindKey)}</span>
1443
+ </label>
1444
+ );
1445
+ }
1446
+ case "Form.Submit":
1447
+ return (
1448
+ <div>
1449
+ <button type="submit" className="um-btn">
1450
+ {asText(props.label, asText(props.text, "Submit"))}
1451
+ </button>
1452
+ </div>
1453
+ );
1454
+ case "PanelHeader":
1455
+ return (
1456
+ <div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
1457
+ <h2 style={{ margin: 0, fontSize: 20, fontWeight: 600 }}>{asText(props.title)}</h2>
1458
+ {typeof props.description === "string" && (
1459
+ <p className="um-card-desc">{props.description}</p>
1460
+ )}
1461
+ </div>
1462
+ );
1463
+ case "EmptyState":
1464
+ return (
1465
+ <div className="um-card" style={{ textAlign: "center", padding: 32 }}>
1466
+ <h3 className="um-card-title">{asText(props.title, "Empty")}</h3>
1467
+ {typeof props.description === "string" && (
1468
+ <p className="um-card-desc">{props.description}</p>
1469
+ )}
1470
+ {children}
1471
+ </div>
1472
+ );
1473
+ default:
1474
+ return (
1475
+ <div data-uibot-block={block.type} style={{ display: "flex", flexDirection: "column", gap: 10 }}>
1476
+ {typeof props.title === "string" && <h3 className="um-card-title">{props.title}</h3>}
1477
+ {typeof props.text === "string" && <p style={{ margin: 0 }}>{props.text}</p>}
1478
+ {children}
1479
+ </div>
1480
+ );
1481
+ }
1482
+ }
1483
+ `}function Ht(e){let t=JSON.stringify(e.navGroups,null,2);return`import { useEffect, useMemo, useState, type ReactNode } from "react";
1484
+ import { AppLink, ShellIcon, useAppRouter } from "../lib/runtime";
1485
+
1486
+ export type ShellVariant =
1487
+ | "admin-sidebar"
1488
+ | "console-drilldown"
1489
+ | "sidebar-floating"
1490
+ | "sidebar-inset"
1491
+ | "top-navbar"
1492
+ | "dual-pane";
1493
+
1494
+ export interface ShellNavItem {
1495
+ label: string;
1496
+ href: string;
1497
+ icon?: string;
1498
+ badge?: string;
1499
+ children?: Array<{ label: string; href: string }>;
1500
+ }
1501
+
1502
+ export interface ShellNavGroup {
1503
+ label: string;
1504
+ items: ShellNavItem[];
1505
+ }
1506
+
1507
+ export const DEFAULT_SHELL: ShellVariant = ${JSON.stringify(e.defaultShell)};
1508
+ export const DEFAULT_FOLDED = ${JSON.stringify(e.defaultFolded)};
1509
+ export const DEFAULT_CONTAINER = ${JSON.stringify(e.defaultContainer)};
1510
+ export const WORKSPACE_NAV_GROUPS: ShellNavGroup[] = ${t};
1511
+
1512
+ export interface WorkspaceShellProps {
1513
+ title?: string;
1514
+ shell?: ShellVariant;
1515
+ container?: string;
1516
+ folded?: boolean;
1517
+ navGroups?: ShellNavGroup[];
1518
+ children: ReactNode;
1519
+ }
1520
+
1521
+ export function WorkspaceShell({
1522
+ title = ${JSON.stringify(e.brand)},
1523
+ shell = DEFAULT_SHELL,
1524
+ container = DEFAULT_CONTAINER,
1525
+ folded: initialFolded = DEFAULT_FOLDED,
1526
+ navGroups = WORKSPACE_NAV_GROUPS,
1527
+ children,
1528
+ }: WorkspaceShellProps) {
1529
+ const { path } = useAppRouter();
1530
+ const [folded, setFolded] = useState(initialFolded);
1531
+ const [dark, setDark] = useState(false);
1532
+ const [drawerOpen, setDrawerOpen] = useState(false);
1533
+ const [searchOpen, setSearchOpen] = useState(false);
1534
+ const [query, setQuery] = useState("");
1535
+ const [drillGroup, setDrillGroup] = useState<string | null>(null);
1536
+ const [secondaryOpen, setSecondaryOpen] = useState(!initialFolded);
1537
+
1538
+ const flatItems = useMemo(() => {
1539
+ const list: Array<{ label: string; href: string; icon?: string }> = [];
1540
+ for (const group of navGroups) {
1541
+ for (const item of group.items) {
1542
+ list.push({ label: item.label, href: item.href, ...(item.icon ? { icon: item.icon } : {}) });
1543
+ for (const child of item.children ?? []) {
1544
+ list.push({ label: child.label, href: child.href });
1545
+ }
1546
+ }
1547
+ }
1548
+ return list;
1549
+ }, [navGroups]);
1550
+
1551
+ const filteredRoutes = useMemo(
1552
+ () =>
1553
+ flatItems.filter((item) =>
1554
+ item.label.toLowerCase().includes(query.trim().toLowerCase()),
1555
+ ),
1556
+ [flatItems, query],
1557
+ );
1558
+
1559
+ useEffect(() => {
1560
+ const onKey = (event: KeyboardEvent) => {
1561
+ if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
1562
+ event.preventDefault();
1563
+ setSearchOpen((prev) => !prev);
1564
+ } else if (event.key === "Escape") {
1565
+ setSearchOpen(false);
1566
+ setDrawerOpen(false);
1567
+ }
1568
+ };
1569
+ window.addEventListener("keydown", onKey);
1570
+ return () => window.removeEventListener("keydown", onKey);
1571
+ }, []);
1572
+
1573
+ const activeDrill = drillGroup ? navGroups.find((g) => g.label === drillGroup) : undefined;
1574
+
1575
+ const renderSidebarNav = (closeDrawer?: () => void) => {
1576
+ if (shell === "console-drilldown" && activeDrill) {
1577
+ return (
1578
+ <nav aria-label={activeDrill.label}>
1579
+ <button
1580
+ type="button"
1581
+ className="um-nav-link"
1582
+ onClick={() => setDrillGroup(null)}
1583
+ >
1584
+ <ShellIcon name="chevron-left" />
1585
+ <span className="um-nav-label">Back</span>
1586
+ </button>
1587
+ <div className="um-nav-group">
1588
+ <div className="um-nav-group-title">{activeDrill.label}</div>
1589
+ {activeDrill.items.map((item) => (
1590
+ <AppLink
1591
+ key={item.href}
1592
+ href={item.href}
1593
+ className="um-nav-link"
1594
+ ariaCurrent={path === item.href ? "page" : undefined}
1595
+ onAfterClick={closeDrawer}
1596
+ >
1597
+ <ShellIcon name={item.icon} />
1598
+ <span className="um-nav-label">{item.label}</span>
1599
+ </AppLink>
1600
+ ))}
1601
+ </div>
1602
+ </nav>
1603
+ );
1604
+ }
1605
+
1606
+ return (
1607
+ <nav aria-label="Main navigation">
1608
+ {navGroups.map((group) => (
1609
+ <div key={group.label} className="um-nav-group">
1610
+ <div className="um-nav-group-title">{group.label}</div>
1611
+ {shell === "console-drilldown" && navGroups.length > 1 ? (
1612
+ <button
1613
+ type="button"
1614
+ className="um-nav-link"
1615
+ onClick={() => setDrillGroup(group.label)}
1616
+ >
1617
+ <ShellIcon name="boxes" />
1618
+ <span className="um-nav-label">{group.label}</span>
1619
+ <ShellIcon name="chevron-right" size={14} />
1620
+ </button>
1621
+ ) : (
1622
+ group.items.map((item) => (
1623
+ <AppLink
1624
+ key={item.href}
1625
+ href={item.href}
1626
+ className="um-nav-link"
1627
+ ariaCurrent={path === item.href ? "page" : undefined}
1628
+ title={item.label}
1629
+ onAfterClick={closeDrawer}
1630
+ >
1631
+ <ShellIcon name={item.icon} />
1632
+ <span className="um-nav-label">{item.label}</span>
1633
+ {item.badge && <span className="um-badge">{item.badge}</span>}
1634
+ </AppLink>
1635
+ ))
1636
+ )}
1637
+ </div>
1638
+ ))}
1639
+ </nav>
1640
+ );
1641
+ };
1642
+
1643
+ const toolbar = (
1644
+ <div className="um-toolbar">
1645
+ <button
1646
+ type="button"
1647
+ className="um-icon-btn"
1648
+ aria-label="Search pages"
1649
+ onClick={() => setSearchOpen(true)}
1650
+ >
1651
+ <ShellIcon name="search" size={15} />
1652
+ <span>Search</span>
1653
+ <kbd>\u2318K</kbd>
1654
+ </button>
1655
+ <button
1656
+ type="button"
1657
+ className="um-icon-btn"
1658
+ aria-label={dark ? "Use light theme" : "Use dark theme"}
1659
+ onClick={() => setDark((prev) => !prev)}
1660
+ >
1661
+ <ShellIcon name={dark ? "moon" : "sun"} size={15} />
1662
+ </button>
1663
+ </div>
1664
+ );
1665
+
1666
+ const overlays = (
1667
+ <>
1668
+ {drawerOpen && (
1669
+ <div
1670
+ className="um-drawer-backdrop"
1671
+ role="dialog"
1672
+ aria-modal="true"
1673
+ aria-label="Navigation"
1674
+ onClick={(event) => {
1675
+ if (event.target === event.currentTarget) setDrawerOpen(false);
1676
+ }}
1677
+ >
1678
+ <div className="um-drawer-panel">
1679
+ <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
1680
+ <strong>{title}</strong>
1681
+ <button
1682
+ type="button"
1683
+ className="um-icon-btn"
1684
+ aria-label="Close navigation"
1685
+ onClick={() => setDrawerOpen(false)}
1686
+ >
1687
+ <ShellIcon name="x" />
1688
+ </button>
1689
+ </div>
1690
+ {renderSidebarNav(() => setDrawerOpen(false))}
1691
+ </div>
1692
+ </div>
1693
+ )}
1694
+ {searchOpen && (
1695
+ <div
1696
+ className="um-modal-backdrop"
1697
+ role="dialog"
1698
+ aria-modal="true"
1699
+ aria-label="Search pages"
1700
+ onClick={(event) => {
1701
+ if (event.target === event.currentTarget) setSearchOpen(false);
1702
+ }}
1703
+ >
1704
+ <div className="um-modal-card">
1705
+ <input
1706
+ type="search"
1707
+ autoFocus
1708
+ className="um-input"
1709
+ style={{ border: 0, borderBottom: "1px solid var(--um-border)", borderRadius: 0 }}
1710
+ placeholder="Jump to page..."
1711
+ aria-label="Jump to page"
1712
+ value={query}
1713
+ onChange={(event) => setQuery(event.target.value)}
1714
+ />
1715
+ <div style={{ padding: 10, display: "flex", flexDirection: "column", gap: 4 }}>
1716
+ {filteredRoutes.map((item) => (
1717
+ <AppLink
1718
+ key={item.href}
1719
+ href={item.href}
1720
+ className="um-nav-link"
1721
+ onAfterClick={() => {
1722
+ setSearchOpen(false);
1723
+ setQuery("");
1724
+ }}
1725
+ >
1726
+ <ShellIcon name={item.icon} />
1727
+ <span>{item.label}</span>
1728
+ </AppLink>
1729
+ ))}
1730
+ {filteredRoutes.length === 0 && (
1731
+ <p className="um-card-desc" style={{ padding: 8 }}>
1732
+ No pages found.
1733
+ </p>
1734
+ )}
1735
+ </div>
1736
+ </div>
1737
+ </div>
1738
+ )}
1739
+ </>
1740
+ );
1741
+
1742
+ if (shell === "top-navbar") {
1743
+ return (
1744
+ <div
1745
+ className={\`um-root \${dark ? "um-dark" : ""}\`}
1746
+ data-shell="top-navbar"
1747
+ data-container={container}
1748
+ >
1749
+ <header className="um-topbar">
1750
+ <button
1751
+ type="button"
1752
+ className="um-icon-btn um-mobile-only"
1753
+ aria-label="Open navigation"
1754
+ onClick={() => setDrawerOpen(true)}
1755
+ >
1756
+ <ShellIcon name="menu" />
1757
+ </button>
1758
+ <AppLink href="/" className="um-brand">
1759
+ <span className="um-brand-mark">
1760
+ <ShellIcon name="layout-dashboard" size={16} />
1761
+ </span>
1762
+ <span>{title}</span>
1763
+ </AppLink>
1764
+ <nav className="um-top-links" aria-label="Main navigation">
1765
+ {flatItems.map((item) => (
1766
+ <AppLink
1767
+ key={item.href}
1768
+ href={item.href}
1769
+ className="um-nav-link"
1770
+ ariaCurrent={path === item.href ? "page" : undefined}
1771
+ >
1772
+ {item.label}
1773
+ </AppLink>
1774
+ ))}
1775
+ </nav>
1776
+ {toolbar}
1777
+ </header>
1778
+ <main className="um-main">
1779
+ <div className="um-content">
1780
+ <div className="um-content-inner">{children}</div>
1781
+ </div>
1782
+ </main>
1783
+ {overlays}
1784
+ </div>
1785
+ );
1786
+ }
1787
+
1788
+ if (shell === "console-drilldown") {
1789
+ return (
1790
+ <div
1791
+ className={\`um-root \${dark ? "um-dark" : ""}\`}
1792
+ data-shell="console-drilldown"
1793
+ data-container={container}
1794
+ >
1795
+ <header className="um-topbar">
1796
+ <button
1797
+ type="button"
1798
+ className="um-icon-btn um-mobile-only"
1799
+ aria-label="Open navigation"
1800
+ onClick={() => setDrawerOpen(true)}
1801
+ >
1802
+ <ShellIcon name="menu" />
1803
+ </button>
1804
+ <AppLink href="/" className="um-brand">
1805
+ <span className="um-brand-mark">
1806
+ <ShellIcon name="layout-dashboard" size={16} />
1807
+ </span>
1808
+ <span>{title}</span>
1809
+ </AppLink>
1810
+ {toolbar}
1811
+ </header>
1812
+ <div className="um-body">
1813
+ <aside className="um-sidebar" aria-label="Console navigation">
1814
+ {renderSidebarNav()}
1815
+ </aside>
1816
+ <main className="um-main">
1817
+ <div className="um-content">
1818
+ <div className="um-content-inner">{children}</div>
1819
+ </div>
1820
+ </main>
1821
+ </div>
1822
+ {overlays}
1823
+ </div>
1824
+ );
1825
+ }
1826
+
1827
+ if (shell === "dual-pane") {
1828
+ return (
1829
+ <div
1830
+ className={\`um-root \${dark ? "um-dark" : ""}\`}
1831
+ data-shell="dual-pane"
1832
+ data-container={container}
1833
+ >
1834
+ <nav className="um-rail" aria-label="Primary sections">
1835
+ <AppLink href="/" className="um-brand-mark" ariaLabel={title} title={title}>
1836
+ <ShellIcon name="layout-dashboard" size={16} />
1837
+ </AppLink>
1838
+ {flatItems.slice(0, 8).map((item) => (
1839
+ <AppLink
1840
+ key={item.href}
1841
+ href={item.href}
1842
+ className="um-rail-btn"
1843
+ title={item.label}
1844
+ ariaLabel={item.label}
1845
+ ariaCurrent={path === item.href ? "page" : undefined}
1846
+ >
1847
+ <ShellIcon name={item.icon} size={17} />
1848
+ </AppLink>
1849
+ ))}
1850
+ </nav>
1851
+ {secondaryOpen && (
1852
+ <aside className="um-sidebar" aria-label="Workspace navigation">
1853
+ <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "4px 6px" }}>
1854
+ <strong>{title}</strong>
1855
+ <button
1856
+ type="button"
1857
+ className="um-icon-btn"
1858
+ aria-label="Collapse secondary pane"
1859
+ onClick={() => setSecondaryOpen(false)}
1860
+ >
1861
+ <ShellIcon name="panel-left" size={15} />
1862
+ </button>
1863
+ </div>
1864
+ {renderSidebarNav()}
1865
+ </aside>
1866
+ )}
1867
+ <div className="um-main">
1868
+ <header className="um-topbar">
1869
+ <button
1870
+ type="button"
1871
+ className="um-icon-btn um-mobile-only"
1872
+ aria-label="Open navigation"
1873
+ onClick={() => setDrawerOpen(true)}
1874
+ >
1875
+ <ShellIcon name="menu" />
1876
+ </button>
1877
+ {!secondaryOpen && (
1878
+ <button
1879
+ type="button"
1880
+ className="um-icon-btn"
1881
+ aria-label="Expand secondary pane"
1882
+ onClick={() => setSecondaryOpen(true)}
1883
+ >
1884
+ <ShellIcon name="panel-left" size={15} />
1885
+ </button>
1886
+ )}
1887
+ <strong>{title}</strong>
1888
+ {toolbar}
1889
+ </header>
1890
+ <main className="um-content">
1891
+ <div className="um-content-inner">{children}</div>
1892
+ </main>
1893
+ </div>
1894
+ {overlays}
1895
+ </div>
1896
+ );
1897
+ }
1898
+
1899
+ return (
1900
+ <div
1901
+ className={\`um-root \${dark ? "um-dark" : ""}\`}
1902
+ data-shell={shell}
1903
+ data-folded={folded ? "true" : "false"}
1904
+ data-container={container}
1905
+ >
1906
+ <aside className="um-sidebar" aria-label="Workspace navigation">
1907
+ <AppLink href="/" className="um-brand">
1908
+ <span className="um-brand-mark">
1909
+ <ShellIcon name="layout-dashboard" size={16} />
1910
+ </span>
1911
+ <span className="um-brand-text">{title}</span>
1912
+ </AppLink>
1913
+ {renderSidebarNav()}
1914
+ </aside>
1915
+ <div className="um-main">
1916
+ <header className="um-topbar">
1917
+ <button
1918
+ type="button"
1919
+ className="um-icon-btn um-mobile-only"
1920
+ aria-label="Open navigation"
1921
+ onClick={() => setDrawerOpen(true)}
1922
+ >
1923
+ <ShellIcon name="menu" />
1924
+ </button>
1925
+ <button
1926
+ type="button"
1927
+ className="um-icon-btn"
1928
+ aria-label="Toggle sidebar"
1929
+ aria-expanded={!folded}
1930
+ onClick={() => setFolded((prev) => !prev)}
1931
+ >
1932
+ <ShellIcon name="panel-left" size={15} />
1933
+ </button>
1934
+ <strong>{title}</strong>
1935
+ {toolbar}
1936
+ </header>
1937
+ <main className="um-content">
1938
+ <div className="um-content-inner">{children}</div>
1939
+ </main>
1940
+ </div>
1941
+ {overlays}
1942
+ </div>
1943
+ );
1944
+ }
1945
+ `}function qt(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)}
1946
+ `},{path:"index.html",content:`<!doctype html>
1947
+ <html lang="en">
1948
+ <head>
1949
+ <meta charset="UTF-8" />
1950
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
1951
+ <title>${e.replace(/[<>&"]/g,"")}</title>
1952
+ </head>
1953
+ <body>
1954
+ <div id="root"></div>
1955
+ <script type="module" src="/src/main.tsx"></script>
1956
+ </body>
1957
+ </html>
1958
+ `},{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)}
1959
+ `},{path:"vite.config.ts",content:`import { defineConfig } from "vite";
1960
+ import react from "@vitejs/plugin-react";
1961
+
1962
+ export default defineConfig({
1963
+ plugins: [react()],
1964
+ });
1965
+ `},{path:"src/main.tsx",content:`import { StrictMode } from "react";
1966
+ import { createRoot } from "react-dom/client";
1967
+ import { MaterializedApp } from "./uibot/App";
1968
+
1969
+ const root = document.getElementById("root");
1970
+ if (root) {
1971
+ createRoot(root).render(
1972
+ <StrictMode>
1973
+ <MaterializedApp />
1974
+ </StrictMode>,
1975
+ );
1976
+ }
1977
+ `}]}var hr="uibot.materialize.manifest.v1",br=new Set(["SetState","ResetState","Link","Navigate","DisplayMessage","Toast","Request"]);function kr(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((r)=>r.blocks.some((o)=>o.type==="PageLayout"&&o.props?.appearance==="console")))return"console-drilldown";return"admin-sidebar"}function xr(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(""),n=`Page${String(t+1).padStart(3,"0")}`;return o?`${n}_${o}`:n}function Z(e){let t=e?.trim();if(!t)return"/";return t.startsWith("/")?t:`/${t}`}function Kt(e){if(e.layout?.inherit===!1)return!0;let t=e.blocks.find((r)=>r.type==="PageLayout");if(!t)return!0;return t.props?.appearance==="standalone"}function vr(e){let t=e.blocks.find((r)=>r.type==="PageLayout");if(t&&t.props?.appearance!=="standalone")return t.children??[];if(t&&t.props?.appearance==="standalone")return t.children??[];return e.blocks}function Cr(e,t){let r=t,o="",n=[];for(let a of e.pages){let i=a.blocks.find((c)=>c.type==="PageLayout");if(i?.props){if(typeof i.props.title==="string"&&i.props.title.trim())r=i.props.title.trim();else if(typeof i.props.brand==="string"&&i.props.brand.trim())r=i.props.brand.trim();if(typeof i.props.subtitle==="string"&&i.props.subtitle.trim())o=i.props.subtitle.trim()}let s=i?.slots?.sidebar??[];for(let c of s)if(c.type==="AppNavigation"&&c.props){if(typeof c.props.brand==="string"&&c.props.brand.trim())r=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)&&n.length===0)for(let l of c.props.groups){if(!l||typeof l!=="object")continue;let p=l,u=typeof p.label==="string"?p.label:"Navigation",g=Array.isArray(p.items)?p.items.filter((d)=>Boolean(d&&typeof d==="object")).map((d)=>({label:typeof d.label==="string"?d.label:String(d.href??"/"),href:Z(typeof d.href==="string"?d.href:"/"),...typeof d.icon==="string"?{icon:d.icon}:{},...typeof d.badge==="string"?{badge:d.badge}:{},...Array.isArray(d.children)?{children:d.children.filter((f)=>Boolean(f&&typeof f==="object")).map((f)=>({label:typeof f.label==="string"?f.label:String(f.href??"/"),href:Z(typeof f.href==="string"?f.href:"/")}))}:{}})):[];if(g.length>0)n.push({label:u,items:g})}}}if(n.length===0&&e.menus?.items?.length){let a=[];for(let i of e.menus.items)if("items"in i&&Array.isArray(i.items)){let s=[];for(let c of i.items)if("path"in c&&typeof c.path==="string")s.push({label:c.label,href:Z(c.path),...c.icon?{icon:c.icon}:{}});if(s.length>0)n.push({label:i.label,items:s})}else if("path"in i&&typeof i.path==="string")a.push({label:i.label,href:Z(i.path),...i.icon?{icon:i.icon}:{}});if(a.length>0)n.unshift({label:"Workspace",items:a})}if(n.length===0){let a=e.pages.filter((s)=>!Kt(s)),i=a.length>0?a:e.pages;n.push({label:"Pages",items:i.map((s)=>({label:s.title??s.id,href:Z(s.path)}))})}return{brand:r,subtitle:o,navGroups:n}}function wr(e){let t=[],r={};for(let n of e.connections??[]){let a=n;if(a.bindings&&typeof a.bindings==="object")t.push({level:"warning",code:"stripped-connection-bindings",path:`connections.${n.id}.bindings`,message:`Connection "${n.id}" environment bindings are host-owned and omitted from materialized client source; wire them via the host data gateway.`});let i=a.mock?.seed;if(Array.isArray(i))r[n.id]=i.filter((s)=>Boolean(s&&typeof s==="object"));else r[n.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=(n,a)=>{for(let[i,s]of Object.entries(n.events??{})){if(!Array.isArray(s))continue;for(let c=0;c<s.length;c++){let l=s[c];if(l&&!br.has(l.action))t.push({level:"warning",code:"host-action-delegated",path:`${a}.events.${i}[${c}]`,message:`Action "${l.action}" is forwarded to MaterializedApp's \`onHostAction\` prop.`})}}for(let i=0;i<(n.children?.length??0);i++){let s=n.children?.[i];if(s)o(s,`${a}.children[${i}]`)}for(let[i,s]of Object.entries(n.slots??{}))for(let c=0;c<s.length;c++){let l=s[c];if(l)o(l,`${a}.slots.${i}[${c}]`)}};for(let n=0;n<e.pages.length;n++){let a=e.pages[n];if(!a)continue;for(let i=0;i<a.blocks.length;i++){let s=a.blocks[i];if(s)o(s,`pages[${n}].blocks[${i}]`)}}return{diagnostics:t,mockCollections:r}}function Ir(e){let t=structuredClone(e),r=[];if(t.connections)for(let o of t.connections){let n=o;if(n.bindings&&typeof n.bindings==="object")r.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 n.bindings}return{spec:t,strippedDiagnostics:r}}function Sr(e,t,r,o,n){let a=e.state??{},i=vr(e),s=e.layout?.container??n,c=e.layout?.shell??o,l=e.layout?.sidebar==="folded",p=JSON.stringify(i,null,2),u=JSON.stringify(a,null,2);if(r)return`import { BlockList, usePageRuntime, type MaterializedBlock } from "../lib/runtime";
1978
+
1979
+ export const PAGE_META = ${JSON.stringify({id:e.id,path:Z(e.path),title:e.title??e.id,standalone:!0},null,2)} as const;
1980
+
1981
+ const INITIAL_STATE: Record<string, unknown> = ${u};
1982
+ const PAGE_BLOCKS: MaterializedBlock[] = ${p};
1983
+
1984
+ export function ${t}() {
1985
+ const { state, updateKey, runActions } = usePageRuntime(INITIAL_STATE);
1986
+ return (
1987
+ <div className="um-standalone" data-container=${JSON.stringify(s)}>
1988
+ <div className="um-standalone-inner">
1989
+ <BlockList
1990
+ blocks={PAGE_BLOCKS}
1991
+ state={state}
1992
+ updateKey={updateKey}
1993
+ runActions={runActions}
1994
+ />
1995
+ </div>
1996
+ </div>
1997
+ );
1998
+ }
1999
+
2000
+ export default ${t};
2001
+ `;return`import { BlockList, usePageRuntime, type MaterializedBlock } from "../lib/runtime";
2002
+ import { WorkspaceShell } from "../shell/WorkspaceShell";
2003
+
2004
+ export const PAGE_META = ${JSON.stringify({id:e.id,path:Z(e.path),title:e.title??e.id,standalone:!1},null,2)} as const;
2005
+
2006
+ const INITIAL_STATE: Record<string, unknown> = ${u};
2007
+ const PAGE_BLOCKS: MaterializedBlock[] = ${p};
2008
+
2009
+ export function ${t}() {
2010
+ const { state, updateKey, runActions } = usePageRuntime(INITIAL_STATE);
2011
+ return (
2012
+ <WorkspaceShell
2013
+ shell=${JSON.stringify(c)}
2014
+ container=${JSON.stringify(s)}
2015
+ folded={${l?"true":"false"}}
2016
+ >
2017
+ <BlockList
2018
+ blocks={PAGE_BLOCKS}
2019
+ state={state}
2020
+ updateKey={updateKey}
2021
+ runActions={runActions}
2022
+ />
2023
+ </WorkspaceShell>
2024
+ );
2025
+ }
2026
+
2027
+ export default ${t};
2028
+ `}function Rr(e,t){let r=e.map((n)=>`import { ${n.componentName} } from "./pages/${n.componentName}";`).join(`
2029
+ `),o=e.map((n)=>` {
2030
+ pageId: ${JSON.stringify(n.pageId)},
2031
+ path: ${JSON.stringify(n.path)},
2032
+ title: ${JSON.stringify(n.title)},
2033
+ standalone: ${n.standalone?"true":"false"},
2034
+ Component: ${n.componentName},
2035
+ }`).join(`,
2036
+ `);return`import type { ComponentType } from "react";
2037
+ ${r}
2038
+
2039
+ export interface MaterializedRoute {
2040
+ pageId: string;
2041
+ path: string;
2042
+ title: string;
2043
+ standalone: boolean;
2044
+ Component: ComponentType;
2045
+ }
2046
+
2047
+ export const ENTRY_PATH = ${JSON.stringify(t)};
2048
+
2049
+ export const MATERIALIZED_ROUTES: MaterializedRoute[] = [
2050
+ ${o}
2051
+ ];
2052
+ `}function Pr(){return`import "./styles.css";
2053
+ import { AppLink, RouterProvider, useAppRouter } from "./lib/runtime";
2054
+ import { ENTRY_PATH, MATERIALIZED_ROUTES } from "./routes";
2055
+
2056
+ export interface MaterializedAppProps {
2057
+ initialPath?: string;
2058
+ onNavigate?: (nextPath: string) => void;
2059
+ onHostAction?: (action: string, params: Record<string, unknown>) => void;
2060
+ }
2061
+
2062
+ function ActiveRoute() {
2063
+ const { path } = useAppRouter();
2064
+ const matched =
2065
+ MATERIALIZED_ROUTES.find((route) => route.path === path) ??
2066
+ (path === "/" ? MATERIALIZED_ROUTES.find((route) => route.path === ENTRY_PATH) : undefined);
2067
+
2068
+ if (!matched) {
2069
+ return (
2070
+ <div className="um-standalone" data-container="boxed">
2071
+ <div className="um-standalone-inner">
2072
+ <section className="um-card">
2073
+ <h1 className="um-card-title">Page not found</h1>
2074
+ <p className="um-card-desc">No route matches {path}.</p>
2075
+ <AppLink href={ENTRY_PATH} className="um-btn">
2076
+ Back to workspace
2077
+ </AppLink>
2078
+ </section>
2079
+ </div>
2080
+ </div>
2081
+ );
2082
+ }
2083
+
2084
+ const PageComponent = matched.Component;
2085
+ return <PageComponent />;
2086
+ }
2087
+
2088
+ export function MaterializedApp({
2089
+ initialPath,
2090
+ onNavigate,
2091
+ onHostAction,
2092
+ }: MaterializedAppProps = {}) {
2093
+ return (
2094
+ <RouterProvider
2095
+ {...(initialPath !== undefined ? { initialPath } : {})}
2096
+ fallbackPath={ENTRY_PATH}
2097
+ onNavigate={onNavigate}
2098
+ onHostAction={onHostAction}
2099
+ >
2100
+ <ActiveRoute />
2101
+ </RouterProvider>
2102
+ );
2103
+ }
2104
+
2105
+ export default MaterializedApp;
2106
+ `}function H(e,t,r,o){let n=r.replace(/\\/g,"/").replace(/^\/+/,"");if(!n||n.includes("..")||n.includes("\x00")||t.has(n.toLowerCase()))throw Error(`invalid-or-colliding-materialized-path:${r}`);t.add(n.toLowerCase()),e.push({path:n,content:o,sha256:ae(o)})}function ya(e){let t=e.target??"react-tsx",r=e.scaffold??"none";if(r==="vite-react"&&t!=="react-tsx")throw Error("scaffold-requires-react-tsx-target");let o=Ir(e.spec),n=o.spec;if(e.shellVariant){if(!e.variantRegistry)throw Error("missing-variant-registry-for-shell-swap");n=te(e.variantRegistry,{spec:n,target:{kind:"shell"},targetVariantId:e.shellVariant}).spec}if(!Array.isArray(n.pages)||n.pages.length===0)throw Error("materialize-empty-spec-pages");let a=ae(JSON.stringify(n)),i=kr(n),s=n.layout?.sidebar==="folded",c=n.layout?.container??"fluid",l=e.appName?.trim()||"UIBot App",{brand:p,subtitle:u,navGroups:g}=Cr(n,l),{diagnostics:d,mockCollections:f}=wr(n),m=[...o.strippedDiagnostics,...d],y=r==="vite-react"?"src/uibot/":"",k=n.pages.map((I,_)=>{let C=xr(I.id,_);return{pageId:I.id,path:Z(I.path),title:I.title??I.id,componentName:C,filePath:t==="react-tsx"?`${y}pages/${C}.tsx`:"app.uibot.yaml",standalone:Kt(I)}}),b=k.find((I)=>I.path==="/")?.path??k.find((I)=>!I.standalone)?.path??k[0]?.path??"/",h=[],x=new Set;if(t==="uibot-yaml"){let I=e.stringifyYaml?e.stringifyYaml(n):`${JSON.stringify(n,null,2)}
2107
+ `;H(h,x,"app.uibot.yaml",I)}else{H(h,x,`${y}styles.css`,Ut()),H(h,x,`${y}styles.d.ts`,`declare module "*.css" {}
2108
+ `),H(h,x,`${y}lib/runtime.tsx`,zt(JSON.stringify(f,null,2))),H(h,x,`${y}shell/WorkspaceShell.tsx`,Ht({brand:p,subtitle:u,defaultShell:i,defaultFolded:s,defaultContainer:c,navGroups:g}));for(let I=0;I<n.pages.length;I++){let _=n.pages[I],C=k[I];if(!_||!C)continue;H(h,x,C.filePath,Sr(_,C.componentName,C.standalone,i,c))}if(H(h,x,`${y}routes.tsx`,Rr(k,b)),H(h,x,`${y}App.tsx`,Pr()),r==="vite-react")for(let I of qt(p))H(h,x,I.path,I.content)}let S={contract:hr,target:t,scaffold:r,appName:p,inputSpecSha256:a,effectiveShell:i,entryPath:b,routes:k,peerDependencies:t==="react-tsx"?{react:"^19.0.0","react-dom":"^19.0.0"}:{},files:h.map((I)=>({path:I.path,sha256:I.sha256})),diagnostics:m};return H(h,x,"materialize.manifest.json",`${JSON.stringify(S,null,2)}
2109
+ `),{spec:n,manifest:S,files:h,diagnostics:m}}export{ws as RESOURCE_INDEX_ERROR_CODES,Sn as RESOURCE_INDEX_SCHEMA_VERSION,Ts as RESOURCE_QUERY_ERROR_CODES,Jt as RESOURCE_QUERY_OPERATION_MANIFEST,He as RESOURCE_QUERY_SCORE_WEIGHTS,oe as ResourceIndexError,F as ResourceQueryError,hr as UIBOT_MATERIALIZE_MANIFEST_CONTRACT,ye as appendSolutionPages,$s as applySolutionUpgrade,sa as applySpecPatch,Vn as assertPublicResourceBundle,O as assertSolutionComposition,Is as buildExamplesFromL4Templates,Ss as buildResourceIndex,Ys as componentReplacementTargets,Dt as composeSolutionSpec,pa as composeSpecFromBlueprint,Se as configureSolutionSpec,Ms as createPublicResourceQueryService,Ot as createResourceQueryService,ta as createVariantRegistry,na as deriveComponentVariantFamilies,Ee as listVariantFamilies,ya as materializeSpec,E as normalizeResourceAlias,Kn as planSolutionUpgrade,Js as replaceCompatibleComponent,Ws as replaceSolutionPageFrames,Je as replaceSolutionPageFramesWithWarnings,ae as sha256Hex,w as solutionContentKey,j as summarizeVariantValue,te as swapVariant,K as toResourceId};