// @bun
var{defineProperty:p,getOwnPropertyNames:b,getOwnPropertyDescriptor:S}=Object,V=Object.prototype.hasOwnProperty;function w(t){return this[t]}var N=(t)=>{var e=(v??=new WeakMap).get(t),n;if(e)return e;if(e=p({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function"){for(var o of b(t))if(!V.call(e,o))p(e,o,{get:w.bind(t,o),enumerable:!(n=S(t,o))||n.enumerable})}return v.set(t,e),e},v;var O=(t)=>t;function M(t,e){this[t]=O.bind(null,e)}var P=(t,e)=>{for(var n in e)p(t,n,{get:e[n],enumerable:!0,configurable:!0,set:M.bind(e,n)})};var L=(t,e)=>()=>(t&&(e=t(t=0)),e);var x=new Set(["hex","rgb","hsl","oklch","css"]);class T extends Error{issues;constructor(t,e){super(t);this.issues=e;this.name="ThemeValidationError"}}function I(t){let e=[];return j(t,e),C(t,e),d(t.tokens,e,"tokens"),u(t.components,e,"components"),k(t.modes,e,"modes"),E(t.overrides,e),{valid:e.every((n)=>n.level!=="error"),issues:e}}function _(t){let e=I(t);if(!e.valid)throw new T(`Theme ${t.meta.key}.v${t.meta.version} is invalid`,e.issues)}function j(t,e){let{meta:n}=t;if(l(n.key,"Theme must have a non-empty key","meta.key",e),l(n.version,"Theme must have a non-empty version","meta.version",e),l(n.title,"Theme must have a non-empty title","meta.title",e),l(n.description,"Theme must have a non-empty description","meta.description",e),l(n.domain,"Theme must have a non-empty domain","meta.domain",e),!n.stability)e.push({level:"error",message:"Theme must declare a stability level",path:"meta.stability"});if(!n.owners.length)e.push({level:"error",message:"Theme must declare at least one owner",path:"meta.owners"});if(!n.tags.length)e.push({level:"error",message:"Theme must declare at least one tag",path:"meta.tags"});if(n.extends&&n.extends.key===n.key&&n.extends.version===n.version)e.push({level:"error",message:"Theme cannot extend itself",path:"meta.extends"})}function C(t,e){if(f(t.tokens)||g(t.components)||y(t.modes)||B(t.overrides))return;e.push({level:"error",message:"Theme must declare tokens, components, or overrides with material configuration",path:"tokens"})}function d(t,e,n){if(!t)return;for(let[o,r]of Object.entries(t)){if(r&&Object.keys(r).length===0)e.push({level:"warning",message:`Theme token group "${o}" is empty`,path:`${n}.${o}`});R(r,o,e,`${n}.${o}`)}}function R(t,e,n,o){if(!t||typeof t!=="object")return;let r=t;for(let[a,s]of Object.entries(r))if(e==="colors"&&s?.format&&!x.has(s.format))n.push({level:"warning",message:`Theme color token "${a}" declares unknown format "${s.format}"`,path:`${o}.${a}.format`})}function k(t,e,n){if(!t)return;for(let[o,r]of Object.entries(t)){let a=`${n}.${o}`;if(!o.trim()){e.push({level:"error",message:"Theme mode keys must be non-empty",path:n});continue}if(!$(r))e.push({level:"warning",message:`Theme mode "${o}" does not declare tokens or components`,path:a});d(r.tokens,e,`${a}.tokens`),u(r.components,e,`${a}.components`)}}function u(t,e,n){if(!t?.length)return;let o=new Set,r=new Map;t.forEach((a,s)=>{let h=`${n}[${s}]`,i=a.component.trim();if(!i){e.push({level:"error",message:"Theme component entries must declare a non-empty component key",path:`${h}.component`});return}if(o.has(i))e.push({level:"error",message:`Duplicate component "${i}" in theme`,path:`${h}.component`});o.add(i);let c=r.get(i)??new Set;for(let m of Object.keys(a.variants)){if(c.has(m))e.push({level:"error",message:`Duplicate variant "${m}" for component "${i}"`,path:`${h}.variants.${m}`});c.add(m),d(a.variants[m]?.tokens,e,`${h}.variants.${m}.tokens`)}r.set(i,c)})}function E(t,e){if(!t?.length)return;let n=new Set;t.forEach((o,r)=>{let a=`overrides[${r}]`,s=`${o.scope}:${o.target}`;if(!o.target.trim()){e.push({level:"error",message:"Theme override targets must be non-empty",path:`${a}.target`});return}if(n.has(s))e.push({level:"error",message:`Duplicate override for ${o.scope}:${o.target}`,path:a});if(n.add(s),D(o.scope,o.target))e.push({level:"warning",message:`Override target "${o.target}" does not look scoped for ${o.scope} overrides`,path:`${a}.target`});d(o.tokens,e,`${a}.tokens`),u(o.components,e,`${a}.components`),k(o.modes,e,`${a}.modes`)})}function f(t){if(!t)return!1;return Object.values(t).some((e)=>e!==void 0&&Object.keys(e).length>0)}function g(t){return Boolean(t?.length)}function $(t){return f(t?.tokens)||g(t?.components)}function y(t){return Boolean(Object.values(t??{}).some($))}function B(t){return Boolean(t?.some((e)=>f(e.tokens)||g(e.components)||y(e.modes)))}function D(t,e){if(t==="global")return!1;return!e.startsWith(`${t}:`)}function l(t,e,n,o){if(t?.trim())return;o.push({level:"error",message:e,path:n})}export{I as validateThemeSpec,_ as assertThemeSpecValid,T as ThemeValidationError};
