@sugarcube-org/core 0.0.1-alpha.16 → 0.0.1-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,15 +6,9 @@
6
6
  <a href="https://github.com/sugarcube-org/sugarcube/blob/main/LICENSE.md"><img src="https://img.shields.io/badge/license-see%20LICENSE-blue" alt="License"></a>
7
7
  </p>
8
8
 
9
- > **Alpha** — This project is in early development.
10
-
11
9
  Core token processing and CSS generation for [sugarcube](https://sugarcube.sh).
12
10
 
13
- ---
14
-
15
- ## Documentation
16
-
17
- For full documentation, visit [sugarcube.sh](https://sugarcube.sh).
11
+ This is an internal package. You probably want [`make-sugarcube`](https://www.npmjs.com/package/make-sugarcube) or [`@sugarcube-org/vite`](https://www.npmjs.com/package/@sugarcube-org/vite) instead.
18
12
 
19
13
  ## License
20
14
 
package/dist/index.d.ts CHANGED
@@ -133,11 +133,33 @@ type LoadedConfig = {
133
133
  /** The absolute path to the config file that was loaded. */
134
134
  configPath: string;
135
135
  };
136
+ /**
137
+ * Checks if a sugarcube configuration file exists.
138
+ *
139
+ * @param basePath - Base path without extension (default: "sugarcube.config")
140
+ * @returns True if a .ts or .js config file exists
141
+ */
136
142
  declare function configFileExists(basePath?: string): boolean;
143
+ /**
144
+ * Loads and validates a sugarcube configuration file.
145
+ * Returns the user-facing config without internal defaults applied.
146
+ *
147
+ * @param configPath - Optional path to config file. If omitted, searches for sugarcube.config.ts/js
148
+ * @returns The validated config and its resolved path
149
+ * @throws Error if config file not found or invalid
150
+ */
137
151
  declare function loadSugarcubeConfig(configPath?: string): Promise<{
138
152
  config: SugarcubeConfig;
139
153
  configPath: string;
140
154
  }>;
155
+ /**
156
+ * Loads, validates, and normalizes a sugarcube configuration file.
157
+ * Returns a complete internal config with all defaults applied.
158
+ *
159
+ * @param configPath - Optional path to config file. If omitted, searches for sugarcube.config.ts/js
160
+ * @returns The normalized config with defaults and its resolved path
161
+ * @throws Error if config file not found or invalid
162
+ */
141
163
  declare function loadInternalConfig(configPath?: string): Promise<LoadedConfig>;
142
164
 
143
165
  /**
@@ -550,9 +572,24 @@ declare function processAndConvertTokens(trees: TokenTree[], resolved: ResolvedT
550
572
  declare function generateCSSVariables(convertedTokens: NormalizedConvertedTokens, config: InternalConfig, modifiers?: ModifierMeta[]): Promise<CSSFileOutput>;
551
573
 
552
574
  type CSSObject = Record<string, string | number | undefined>;
575
+ /**
576
+ * Clears the token matching cache.
577
+ * Call this when tokens change (e.g., on hot reload in dev mode).
578
+ */
553
579
  declare function clearMatchCache(): void;
580
+ /**
581
+ * Converts a utilities configuration into UnoCSS dynamic rules.
582
+ *
583
+ * @param utilitiesConfig - The utilities configuration from sugarcube.config
584
+ * @param tokens - The converted tokens to generate rules for
585
+ * @returns Array of UnoCSS dynamic rules [pattern, handler]
586
+ */
554
587
  declare function convertConfigToUnoRules(utilitiesConfig: UtilitiesConfig, tokens: NormalizedConvertedTokens): Array<[RegExp, (m: RegExpMatchArray) => CSSObject]>;
555
588
 
589
+ /**
590
+ * Performance monitor for tracking memory usage and watcher events.
591
+ * Only active when SUGARCUBE_PERF=true environment variable is set.
592
+ */
556
593
  declare class PerfMonitor implements Disposable {
557
594
  #private;
558
595
  private defaultFlush;
@@ -566,6 +603,11 @@ declare class PerfMonitor implements Disposable {
566
603
  [Symbol.dispose](): void;
567
604
  }
568
605
 
606
+ /**
607
+ * Instrumentation for tracking function call counts and execution times.
608
+ * Only active when DEBUG=true environment variable is set.
609
+ * Inspired by Tailwind CSS instrumentation.
610
+ */
569
611
  declare class Instrumentation implements Disposable {
570
612
  #private;
571
613
  private defaultFlush;
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ var Qe=Object.defineProperty;var s=(e,t)=>Qe(e,"name",{value:t,configurable:!0})
2
2
  ${t.map(n=>` - ${n}`).join(`
3
3
  `)}`,"DUPLICATE_FILENAMES"),FILE_NOT_FOUND:s(e=>e===X?`Cannot find sugarcube config file. Please ensure you have a valid ${X} file in your project root.`:`Cannot find sugarcube config file at "${e}". Please check the path and file permissions.`,"FILE_NOT_FOUND")},UTILITIES:{RESERVED_PREFIX:s((e,t)=>`Cannot use reserved prefix "${e}" for ${t} token type. This prefix is reserved for default utility classes. Please use a custom prefix instead.`,"RESERVED_PREFIX"),DUPLICATE_CLASS_NAME:s((e,t)=>`Ambiguous utility class "${e}" would be generated from multiple token paths: ${t.join(", ")}. This would make it impossible to know which token value should be used when this class is applied in HTML. To fix this, configure one or more paths with custom prefixes to make the intent clear.`,"DUPLICATE_CLASS_NAME"),INVALID_PROPERTY_MAPPING:s(e=>`Invalid property mapping for ${e} token type. When mapping multiple properties, each mapping must include a unique prefix to avoid class name collisions.`,"INVALID_PROPERTY_MAPPING"),DUPLICATE_PREFIX:s((e,t)=>`Duplicate prefix "${e}" found in property mappings for ${t} token type. Each property mapping must have a unique prefix to avoid class name collisions.`,"DUPLICATE_PREFIX"),MISSING_SOURCE:s(e=>`Utility config for '${e}' must have a valid 'source' property`,"MISSING_SOURCE"),INVALID_SOURCE_PATTERN:s((e,t)=>`Utility config for '${e}' has invalid source pattern '${t}'. Only patterns ending with '.*' are supported (e.g., 'color.*', 'font.weight.*').`,"INVALID_SOURCE_PATTERN"),INVALID_DIRECTIONS:s(e=>`Utility config for '${e}' must have 'directions' as an array`,"INVALID_DIRECTIONS"),INVALID_CONFIG_OBJECT:"utilitiesConfig must be an object",INVALID_TOKENS_OBJECT:"tokens must be an object"},RESOLVER:{FILE_NOT_FOUND:s(e=>`Cannot read resolver file at "${e}". Please check the path and file permissions.`,"FILE_NOT_FOUND"),INVALID_JSON:s(e=>`Invalid JSON in resolver file: ${e}`,"INVALID_JSON"),INVALID_REFERENCE:s(e=>`Invalid reference "${e}". References must use format #/sets/<name> or #/modifiers/<name>.`,"INVALID_REFERENCE"),INVALID_SOURCE_REFERENCE:s(e=>`Invalid source reference "${e}". Sources can only reference sets (#/sets/<name>), not modifiers.`,"INVALID_SOURCE_REFERENCE"),UNDEFINED_SET:s(e=>`Reference to undefined set "${e}". Define it in the "sets" section first.`,"UNDEFINED_SET"),UNDEFINED_MODIFIER:s(e=>`Reference to undefined modifier "${e}". Define it in the "modifiers" section first.`,"UNDEFINED_MODIFIER"),CIRCULAR_REFERENCE:s(e=>`Circular reference detected at "${e}".`,"CIRCULAR_REFERENCE"),EXTERNAL_FILE_NOT_FOUND:s(e=>`Referenced file not found: ${e}`,"EXTERNAL_FILE_NOT_FOUND"),EXTERNAL_FILE_ERROR:s((e,t)=>`Failed to load "${e}": ${t}`,"EXTERNAL_FILE_ERROR"),INVALID_JSON_POINTER:s((e,t)=>`Invalid JSON pointer "${e}": ${t}`,"INVALID_JSON_POINTER"),DUPLICATE_NAME:s(e=>`Duplicate name "${e}" in resolutionOrder.`,"DUPLICATE_NAME"),MODIFIER_NEEDS_CONTEXTS:"Modifier must have at least one context defined.",MODIFIER_SINGLE_CONTEXT:"Modifier has only one context. Consider using a set instead, or add more contexts.",INVALID_DEFAULT:s((e,t)=>`Default context "${e}" is not defined. Valid contexts: ${t.join(", ")}`,"INVALID_DEFAULT"),UNKNOWN_MODIFIER:s(e=>`Unknown modifier "${e}".`,"UNKNOWN_MODIFIER"),INVALID_CONTEXT:s((e,t,n)=>`Invalid context "${e}" for modifier "${t}". Valid contexts: ${n.join(", ")}`,"INVALID_CONTEXT"),MISSING_REQUIRED_INPUT:s(e=>`Missing required input for modifier "${e}". No default value is defined.`,"MISSING_REQUIRED_INPUT"),INVALID_INPUT_TYPE:s(e=>`Input for modifier "${e}" must be a string.`,"INVALID_INPUT_TYPE"),MALFORMED_REFERENCE:s((e,t)=>`Malformed source reference: { "${e}": "${t}" }. Did you mean { "$ref": "${t}" }?`,"MALFORMED_REFERENCE"),RESOLVER_AS_TOKEN_SOURCE:s(e=>`File "${e}" is a resolver document, not a token file. Resolver documents (version: "2025.10") cannot be used as token sources. Did you mean to reference a specific token file instead?`,"RESOLVER_AS_TOKEN_SOURCE")}};function Z(e){const t={resolver:e.resolver,transforms:{fluid:e.transforms?.fluid??A.transforms.fluid,colorFallbackStrategy:e.transforms?.colorFallbackStrategy??A.transforms.colorFallbackStrategy},output:{css:e.output?.css??A.output.css,themeAttribute:e.output?.themeAttribute??A.output.themeAttribute,defaultContext:e.output?.defaultContext}};return(e.output?.components!==void 0||A.output.components!==void 0)&&(t.output.components=e.output?.components??A.output.components),e.utilities&&(t.utilities=e.utilities),t}s(Z,"fillDefaults");const de=l.object({min:l.number(),max:l.number()}),me=l.object({source:l.string(),directions:l.union([l.enum(["top","right","bottom","left","x","y","full","all"]),l.array(l.enum(["top","right","bottom","left","x","y","full","all"]))]).optional(),prefix:l.string().optional(),stripDuplicates:l.boolean().optional()}),he=l.union([me,l.array(me)]),it=l.object({resolver:l.string().optional(),transforms:l.object({fluid:de.optional(),colorFallbackStrategy:l.enum(["native","polyfill"]).optional()}).optional(),output:l.object({css:l.string().optional(),components:l.string().optional(),themeAttribute:l.string().optional(),defaultContext:l.string().optional()}).optional(),utilities:l.record(l.string(),he).optional()}),at=l.object({resolver:l.string().optional(),transforms:l.object({fluid:de,colorFallbackStrategy:l.enum(["native","polyfill"])}),output:l.object({css:l.string(),components:l.string().optional(),themeAttribute:l.string(),defaultContext:l.string().optional()}),utilities:l.record(l.string(),he).optional()});function Q(e){const t=it.safeParse(e);if(!t.success){const n=t.error.errors.map(r=>{const o=r.path.join(".");return f.CONFIG.INVALID_CONFIG(o||"root",r.message)});throw new Error(n.join(`
4
4
  `))}return t.data}s(Q,"validateSugarcubeConfig");function Ie(e){const t=at.safeParse(e);if(!t.success){const n=t.error.errors.map(r=>{const o=r.path.join(".");return f.CONFIG.INVALID_CONFIG(o||"root",r.message)});throw new Error(n.join(`
5
- `))}return t.data}s(Ie,"validateInternalConfig");function ct(e){const t=Q(e),n=Z(t);return Ie(n)}s(ct,"validateConfig");function ye(e="sugarcube.config"){const t=[".ts",".js"],n=process.cwd();for(const r of t){const o=O(n,`${e}${r}`);if(z(o))return o}return null}s(ye,"findConfigFile");function ut(e="sugarcube.config"){return ye(e)!==null}s(ut,"configFileExists");async function ft(e){try{if(typeof globalThis.Bun<"u"){const i=tt(e).href,c=await new Function("url","return import(url)")(i);if(c&&typeof c=="object"&&"default"in c)return c.default;throw new Error(f.CONFIG.INVALID_CONFIG("root","Config file must export a default object"))}const{createJiti:n}=await import("jiti"),o=await n(import.meta.url,{interopDefault:!0}).import(e);return o&&typeof o=="object"&&"default"in o?o.default:o}catch(t){throw t instanceof Error?new Error(f.CONFIG.INVALID_CONFIG("root",t.message)):t}}s(ft,"loadTSConfig");async function Ee(e){if(e.endsWith(".ts")||e.endsWith(".js"))return await ft(e);const n=await et.readFile(e,"utf-8");return JSON.parse(n)}s(Ee,"loadConfigFile");function $e(e){if(e)return O(process.cwd(),e);const t=ye();if(!t)throw new Error(f.CONFIG.FILE_NOT_FOUND(X));return t}s($e,"resolveConfigPath");async function lt(e){const t=$e(e);try{const n=await Ee(t);return{config:Q(n),configPath:t}}catch(n){throw n instanceof Error&&"code"in n&&n.code==="ENOENT"?new Error(f.CONFIG.FILE_NOT_FOUND(t)):n instanceof SyntaxError?new Error(f.CONFIG.INVALID_JSON(n.message)):n}}s(lt,"loadSugarcubeConfig");async function pt(e){const t=$e(e);try{const n=await Ee(t),r=Q(n),o=Z(r);return{config:Ie(o),configPath:t}}catch(n){throw n instanceof Error&&"code"in n&&n.code==="ENOENT"?new Error(f.CONFIG.FILE_NOT_FOUND(t)):n instanceof SyntaxError?new Error(f.CONFIG.INVALID_JSON(n.message)):n}}s(pt,"loadInternalConfig");function h(e){return typeof e=="string"&&e.startsWith("{")&&e.endsWith("}")}s(h,"isReference$1");function dt(e){if(typeof e!="object"||e===null||!("$value"in e))return!1;const t=e.$value;return typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.keys(t).length>0}s(dt,"isCompositeToken");function mt(e){return e.$type==="typography"}s(mt,"isTypographyToken");function ee(e){return typeof e=="object"&&e!==null&&"$value"in e}s(ee,"isTokenNode");function ht(e,t,n){for(const[r,o]of Object.entries(t.tokens)){const i=e.tokens[r];if(!ee(o)){if(i&&ee(i)){const d=i;n.push({path:d.$path,source:d.$source,message:f.FLATTEN.CONFLICT_TOKEN_VS_GROUP(d.$path)});continue}e.tokens[r]=o;continue}if(!i){e.tokens[r]=o;continue}if(!ee(i)){n.push({path:o.$path,source:o.$source,message:f.FLATTEN.CONFLICT_TOKEN_VS_GROUP(o.$path)});continue}const c=o,u=i,p=!!c.$type,m=!!u.$type;if(p&&m&&c.$type!==u.$type){n.push({path:c.$path,source:c.$source,message:f.FLATTEN.CONFLICT_INCOMPATIBLE_TYPES(String(u.$type??"unknown"),String(c.$type??"unknown"),c.$path)});continue}e.tokens[r]=o}for(const[r,o]of t.pathIndex)e.pathIndex.set(r,o)}s(ht,"mergeFlattenedInto");function It(e){if(typeof e!="object"||e===null||"$value"in e)return!1;const t="value"in e,n="type"in e;if(t&&n)return!0;if(t){const r=e.value;return typeof r=="string"||typeof r=="number"||Array.isArray(r)}return!1}s(It,"looksLikeUnprefixedToken");function yt(e,t){const n={tokens:{},pathIndex:new Map},r=[];function o(a=[]){const c=[];return t.context&&c.push(t.context),a.length>0&&c.push(a.join(".")),c.length>0?c.join("."):""}s(o,"createLookupKey"),(e.$description||e.$extensions)&&(n.tokens[o()]={$description:e.$description,$extensions:e.$extensions});function i(a,c=[],u){if(c.join("."),c.length>0){const d=o(c);n.tokens[d]={$description:a.$description,$extensions:a.$extensions,$path:c.join("."),$source:{context:t.context,sourcePath:t.sourcePath}}}const p=Object.keys(a).filter(d=>!d.startsWith("$")),m=a.$type||u;for(const d of p){const I=a[d],y=[...c,d],$=y.join(".");if(It(I)){r.push({path:$,source:t,message:f.FLATTEN.MISSING_DOLLAR_PREFIX($)});continue}if(d.includes(".")||d.includes("{")||d.includes("}")){r.push({path:$,source:t,message:f.FLATTEN.INVALID_TOKEN_NAME(d)});continue}if("$value"in I){if(Object.keys(I).filter(Ze=>!Ze.startsWith("$")).length>0){r.push({path:$,source:t,message:f.FLATTEN.INVALID_TOKEN_NESTING($)});continue}if(dt(I)&&!I.$type&&!m){r.push({path:$,source:t,message:f.FLATTEN.COMPOSITE_TOKEN_MISSING_TYPE($)});continue}const ue=o(y),q=y.join(".");n.tokens[ue]={...I,...I.$type||m?{$type:I.$type||m}:{},$path:q,$source:{context:t.context,sourcePath:t.sourcePath},$originalPath:q},n.pathIndex.set(q,ue)}else i(I,y,m)}}return s(i,"processNode"),i(e),{tokens:n,errors:r}}s(yt,"flattenTree");function Et(e){const t={tokens:{},pathIndex:new Map},n=[];for(const r of e){const{tokens:o,errors:i}=yt(r.tokens,{context:r.context,sourcePath:r.sourcePath});n.push(...i),ht(t,o,n)}return{tokens:t,errors:n}}s(Et,"flatten");const F=l.string().min(1,"Name cannot be empty").refine(e=>!e.startsWith("$"),"Names must not start with '$' (reserved prefix)").refine(e=>!e.includes("{"),"Names must not contain '{'").refine(e=>!e.includes("}"),"Names must not contain '}'").refine(e=>!e.includes("."),"Names must not contain '.'"),ge=l.object({$ref:l.string().min(1,"$ref cannot be empty")}).passthrough(),te=l.union([ge,l.record(l.string(),l.unknown())]),$t=l.object({description:l.string().optional(),sources:l.array(te),$extensions:l.record(l.string(),l.unknown()).optional()}),Ne=l.record(l.string(),l.array(te)),gt=l.object({description:l.string().optional(),contexts:Ne,default:l.string().optional(),$extensions:l.record(l.string(),l.unknown()).optional()}).refine(e=>Object.keys(e.contexts).length>=1,"Modifier must have at least 1 context"),Nt=l.object({type:l.literal("set"),name:F,sources:l.array(te),description:l.string().optional(),$extensions:l.record(l.string(),l.unknown()).optional()}),Tt=l.object({type:l.literal("modifier"),name:F,contexts:Ne,description:l.string().optional(),default:l.string().optional(),$extensions:l.record(l.string(),l.unknown()).optional()}).refine(e=>Object.keys(e.contexts).length>=1,"Modifier must have at least 1 context"),St=l.union([ge,Nt,Tt]),At=l.record(F,$t),bt=l.record(F,gt),Ot=l.object({version:l.literal("2025.10"),name:l.string().optional(),description:l.string().optional(),sets:At.optional(),modifiers:bt.optional(),resolutionOrder:l.array(St),$schema:l.string().optional(),$extensions:l.record(l.string(),l.unknown()).optional(),$defs:l.record(l.string(),l.unknown()).optional()});function D(e){return typeof e=="object"&&e!==null&&"$ref"in e&&typeof e.$ref=="string"}s(D,"isReference");function Te(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="set"}s(Te,"isInlineSet");function L(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="modifier"}s(L,"isInlineModifier");async function Dt(e){const t=C(e)?e:O(process.cwd(),e),n=await Rt(t);if(n.error)return{document:w(),errors:[n.error]};const r=Lt(n.content);if(r.error)return{document:w(),errors:[r.error]};const o=_t(r.data);if(o.errors.length>0)return{document:w(),errors:o.errors};const i=[];return vt(o.document,i),{document:o.document,errors:i}}s(Dt,"parseResolverDocument");async function Rt(e){try{return{content:await x(e,"utf-8")}}catch{return{error:{path:e,message:f.RESOLVER.FILE_NOT_FOUND(e)}}}}s(Rt,"loadFile");function Lt(e){try{return{data:JSON.parse(e)}}catch(t){const n=t instanceof Error?t.message:"Unknown error";return{error:{path:"resolver",message:f.RESOLVER.INVALID_JSON(n)}}}}s(Lt,"parseJson");function _t(e){const t=Ot.safeParse(e);if(!t.success){const n=t.error.errors.map(r=>{const o=r.path.join(".")||"resolver";return{path:o,message:`Resolver error at ${o}: ${r.message}. See https://sugarcube.sh/docs/resolver`}});return{document:w(),errors:n}}return{document:t.data,errors:[]}}s(_t,"validateSchema$1");function vt(e,t){xt(e,t),Ct(e,t),Ft(e,t)}s(vt,"validateDocument");function xt(e,t){if(e.modifiers)for(const[n,r]of Object.entries(e.modifiers))Se(r,`modifiers.${n}`,t);for(let n=0;n<e.resolutionOrder.length;n++){const r=e.resolutionOrder[n];L(r)&&Se(r,`resolutionOrder[${n}]`,t)}}s(xt,"validateModifierContexts");function Se(e,t,n){const r=Object.keys(e.contexts).length;if(r===0){n.push({path:`${t}.contexts`,message:f.RESOLVER.MODIFIER_NEEDS_CONTEXTS});return}r===1&&n.push({path:`${t}.contexts`,message:f.RESOLVER.MODIFIER_SINGLE_CONTEXT}),e.default&&!e.contexts[e.default]&&n.push({path:`${t}.default`,message:f.RESOLVER.INVALID_DEFAULT(e.default,Object.keys(e.contexts))})}s(Se,"checkModifierContexts");function Ct(e,t){const n=new Set;for(let r=0;r<e.resolutionOrder.length;r++){const o=e.resolutionOrder[r];if(D(o))continue;const i=o.name;n.has(i)&&t.push({path:`resolutionOrder[${r}].name`,message:f.RESOLVER.DUPLICATE_NAME(i)}),n.add(i)}}s(Ct,"validateNameUniqueness");function Ft(e,t){for(let n=0;n<e.resolutionOrder.length;n++){const r=e.resolutionOrder[n];if(D(r))Vt(r.$ref,`resolutionOrder[${n}].$ref`,e,t);else if(Te(r))V(r.sources,`resolutionOrder[${n}].sources`,t);else if(L(r))for(const[o,i]of Object.entries(r.contexts))V(i,`resolutionOrder[${n}].contexts.${o}`,t)}if(e.sets)for(const[n,r]of Object.entries(e.sets))V(r.sources,`sets.${n}.sources`,t);if(e.modifiers)for(const[n,r]of Object.entries(e.modifiers))for(const[o,i]of Object.entries(r.contexts))V(i,`modifiers.${n}.contexts.${o}`,t)}s(Ft,"validateReferences");function V(e,t,n){for(let r=0;r<e.length;r++){const o=e[r];if(!o)continue;if(!D(o)){const a=Object.keys(o);if(a.length===1){const c=a[0],u=o[c];typeof u=="string"&&(u.includes("/")||u.endsWith(".json"))&&n.push({path:`${t}[${r}]`,message:f.RESOLVER.MALFORMED_REFERENCE(c,u)})}continue}const i=o.$ref;i.startsWith("#/")&&(i.match(/^#\/sets\/[^/]+$/)||n.push({path:`${t}[${r}].$ref`,message:f.RESOLVER.INVALID_SOURCE_REFERENCE(i)}))}}s(V,"validateSourcesReferences");function Vt(e,t,n,r){if(!e.startsWith("#/"))return;const o=e.slice(2).split("/"),[i,a]=o;if(o.length!==2||!i||!a){r.push({path:t,message:f.RESOLVER.INVALID_REFERENCE(e)});return}if(i==="sets"){n.sets?.[a]||r.push({path:t,message:f.RESOLVER.UNDEFINED_SET(a)});return}if(i==="modifiers"){n.modifiers?.[a]||r.push({path:t,message:f.RESOLVER.UNDEFINED_MODIFIER(a)});return}r.push({path:t,message:f.RESOLVER.INVALID_REFERENCE(e)})}s(Vt,"validateReference");function w(){return{version:"2025.10",resolutionOrder:[]}}s(w,"createEmptyDocument");function Ae(e){if(typeof e!="object"||e===null)return!1;const t=e;return t.version==="2025.10"&&Array.isArray(t.resolutionOrder)}s(Ae,"isResolverFormat");function be(e,t){return{document:e,basePath:t,visitedRefs:new Set,fileCache:new Map}}s(be,"createResolveContext");async function Oe(e,t){if(t.visitedRefs.has(e))return T({},f.RESOLVER.CIRCULAR_REFERENCE(e),e);t.visitedRefs.add(e);try{return e.startsWith("#/")?wt(e,t):e.includes("#/")?await Mt(e,t):await kt(e,t)}finally{t.visitedRefs.delete(e)}}s(Oe,"resolveReference");function wt(e,t){const n=e.slice(2),[r,o]=n.split("/");if(!r||!o||n.split("/").length!==2)return T({sources:[]},f.RESOLVER.INVALID_REFERENCE(e));if(r==="sets"){const i=t.document.sets?.[o];return i?{content:i,sourcePath:"#",errors:[]}:T({sources:[]},f.RESOLVER.UNDEFINED_SET(o))}if(r==="modifiers"){const i=t.document.modifiers?.[o];return i?{content:i,sourcePath:"#",errors:[]}:T({contexts:{}},f.RESOLVER.UNDEFINED_MODIFIER(o))}return T({sources:[]},f.RESOLVER.INVALID_REFERENCE(e))}s(wt,"resolveSameDocumentRef");async function kt(e,t){const n=C(e)?e:O(t.basePath,e),r=t.fileCache.get(n);if(r)return Ae(r)?T({},f.RESOLVER.RESOLVER_AS_TOKEN_SOURCE(n),n):{content:r,sourcePath:n,errors:[]};const o=await De(n);return o.error?T({},o.error,n):Ae(o.content)?T({},f.RESOLVER.RESOLVER_AS_TOKEN_SOURCE(n),n):(t.fileCache.set(n,o.content),{content:o.content,sourcePath:n,errors:[]})}s(kt,"resolveFileRef");async function Mt(e,t){const[n="",r=""]=e.split("#"),o=C(n)?n:O(t.basePath,n);let i=t.fileCache.get(o);if(!i){const u=await De(o);if(u.error)return T({},u.error,o);i=u.content,t.fileCache.set(o,i)}const a=r.startsWith("/")?r:`/${r}`,c=jt(i,a);return c.error?T({},f.RESOLVER.INVALID_JSON_POINTER(a,c.error),o):{content:c.value,sourcePath:o,errors:[]}}s(Mt,"resolveFileFragmentRef");async function De(e){try{const t=await x(e,"utf-8");return{content:JSON.parse(t)}}catch(t){if(t.code==="ENOENT")return{error:f.RESOLVER.EXTERNAL_FILE_NOT_FOUND(e)};const n=t instanceof Error?t.message:"Unknown error";return{error:f.RESOLVER.EXTERNAL_FILE_ERROR(e,n)}}}s(De,"loadJsonFile");function jt(e,t){if(t===""||t==="/")return{value:e};const n=t.slice(1).split("/").map(o=>o.replace(/~1/g,"/").replace(/~0/g,"~"));let r=e;for(const o of n){if(r===null||typeof r!="object")return{error:"cannot navigate into non-object"};if(Array.isArray(r)){const a=Number.parseInt(o,10);if(Number.isNaN(a)||a<0||a>=r.length)return{error:`invalid array index "${o}"`};r=r[a];continue}const i=r;if(!(o in i))return{error:`property "${o}" not found`};r=i[o]}return{value:r}}s(jt,"resolveJsonPointer");async function Re(e,t){const n=[],r=[];for(const o of e){if(!D(o)){n.push(o);continue}const i=await Oe(o.$ref,t);r.push(...i.errors),i.errors.length===0&&n.push(Pt(i.content,o))}return{resolved:n,errors:r}}s(Re,"resolveSources");function Pt(e,t){const{$ref:n,...r}=t;return Object.keys(r).length===0?e:{...e,...r}}s(Pt,"applyExtending");function T(e,t,n="#"){return{content:e,sourcePath:n,errors:[{path:n,message:t}]}}s(T,"errorResult");function Le(e){return typeof e=="object"&&e!==null&&"$value"in e}s(Le,"isToken");function k(e,t){const n={...e};for(const[r,o]of Object.entries(t)){if(o===void 0)continue;if(r.startsWith("$")){n[r]=o;continue}if(Le(o)){n[r]=o;continue}const i=n[r],a=i!==void 0&&typeof i=="object"&&i!==null&&typeof o=="object"&&o!==null&&!Le(i);n[r]=a?k(i,o):o}return n}s(k,"deepMerge");function _e(e){const t=[],n=new Set;for(const r of e.resolutionOrder){const o=Ut(r,e,n);o&&(t.push(o),n.add(o.name))}return t}s(_e,"extractModifiers");function Ut(e,t,n){return D(e)&&e.$ref.startsWith("#/modifiers/")?Gt(e.$ref,t,n):L(e)?Bt(e,n):null}s(Ut,"extractModifierFromItem");function Gt(e,t,n){const r=e.split("/")[2];if(!r||n.has(r))return null;const o=t.modifiers?.[r];return o?{name:r,contexts:Object.keys(o.contexts),default:o.default}:null}s(Gt,"extractReferencedModifier");function Bt(e,t){return t.has(e.name)?null:{name:e.name,contexts:Object.keys(e.contexts),default:e.default}}s(Bt,"extractInlineModifier");function Wt(e,t={}){const n=[],r={},o=_e(e);if(o.length===0)return Yt(t,n),{valid:n.length===0,errors:n,resolvedInputs:r};const i=new Map(o.map(a=>[a.name,a]));return Ht(t,i,n,r),Kt(o,r,n),{valid:n.length===0,errors:n,resolvedInputs:r}}s(Wt,"validateInputs$1");function Yt(e,t){for(const n of Object.keys(e))t.push({modifier:n,message:f.RESOLVER.UNKNOWN_MODIFIER(n)})}s(Yt,"validateNoModifiersCase");function Ht(e,t,n,r){for(const[o,i]of Object.entries(e)){const a=t.get(o);if(!a){n.push({modifier:o,message:f.RESOLVER.UNKNOWN_MODIFIER(o)});continue}if(typeof i!="string"){n.push({modifier:o,message:f.RESOLVER.INVALID_INPUT_TYPE(o)});continue}if(!a.contexts.includes(i)){n.push({modifier:o,message:f.RESOLVER.INVALID_CONTEXT(i,o,a.contexts)});continue}r[o]=i}}s(Ht,"validateProvidedInputs");function Kt(e,t,n){for(const r of e)t[r.name]===void 0&&(r.default!==void 0?t[r.name]=r.default:n.push({modifier:r.name,message:f.RESOLVER.MISSING_REQUIRED_INPUT(r.name)}))}s(Kt,"applyDefaults");async function ve(e,t,n={}){const r=Wt(e,n);if(!r.valid)return{tokens:{},sources:[],errors:r.errors.map(a=>({path:a.modifier||"inputs",message:a.message}))};const o=be(e,t),i=qt();for(const a of e.resolutionOrder)await zt(a,e,o,r.resolvedInputs,i);return{tokens:i.tokens,sources:i.sources,errors:i.errors}}s(ve,"processResolutionOrder");function qt(){return{tokens:{},sources:[],errors:[]}}s(qt,"createProcessingState");async function zt(e,t,n,r,o){if(D(e)){await Jt(e,t,n,r,o);return}if(Te(e)){await Xt(e,n,o);return}L(e)&&await Zt(e,n,r,o)}s(zt,"processItem");async function Jt(e,t,n,r,o){const i=await Oe(e.$ref,n);if(i.errors.length>0){o.errors.push(...i.errors);return}const a=e.$ref.split("/")[2];if(a){if(e.$ref.startsWith("#/sets/")){const c=await M(i.content.sources,n,{type:"set",name:a});j(c,o);return}if(e.$ref.startsWith("#/modifiers/")){const c=r[a];if(!c)return;const p=i.content.contexts[c];if(!p)return;const m=await M(p,n,{type:"modifier",name:a,context:c});j(m,o)}}}s(Jt,"processReference");async function Xt(e,t,n){const r=await M(e.sources,t,{type:"set",name:e.name});j(r,n)}s(Xt,"processInlineSet");async function Zt(e,t,n,r){const o=n[e.name];if(!o)return;const i=e.contexts[o];if(!i)return;const a=await M(i,t,{type:"modifier",name:e.name,context:o});j(a,r)}s(Zt,"processInlineModifier");async function M(e,t,n){const r=await Re(e,t);let o={};for(const i of r.resolved)o=k(o,i);return{tokens:o,source:{path:"#",...n},errors:r.errors}}s(M,"mergeSources");function j(e,t){t.errors.push(...e.errors),t.tokens=k(t.tokens,e.tokens),t.sources.push(e.source)}s(j,"applyResult");async function Qt(e,t){const n=[],r=be(e,t),o=_e(e),i={};for(const p of o)p.default&&(i[p.name]=p.default);const a=await ve(e,t,i);n.push(...a.errors);const c=a.tokens,u=[];for(const p of o){const m=new Map,d=p.default??p.contexts[0]??"default";for(const I of p.contexts){if(I===d)continue;const y=await en(e,t,r,p.name,I,n);Object.keys(y).length>0&&m.set(I,y)}u.push({name:p.name,defaultContext:d,contexts:m})}return{base:c,modifiers:u,errors:n}}s(Qt,"processForLayeredCSS");async function en(e,t,n,r,o,i){const a=tn(e,r);if(!a)return{};const c=a.contexts[o];if(!c||c.length===0)return{};const u=await Re(c,n);i.push(...u.errors.map(y=>({path:y.path,message:y.message})));let p={};for(const y of u.resolved)p=k(p,y);const m=new Set;xe(p,"",m);const d=await ve(e,t,{[r]:o});i.push(...d.errors);const I={};for(const y of m){const $=nn(d.tokens,y);$!==void 0&&rn(I,y,$)}return I}s(en,"processModifierContext");function tn(e,t){if(e.modifiers?.[t])return e.modifiers[t];for(const n of e.resolutionOrder)if(L(n)&&n.name===t)return n}s(tn,"findModifierDefinition");function xe(e,t,n){for(const[r,o]of Object.entries(e)){if(r.startsWith("$"))continue;const i=t?`${t}.${r}`:r;o&&typeof o=="object"&&"$value"in o?n.add(i):o&&typeof o=="object"&&xe(o,i,n)}}s(xe,"collectTokenPaths");function nn(e,t){const n=t.split(".");let r=e;for(const o of n){if(r===null||typeof r!="object")return;r=r[o]}return r}s(nn,"getTokenAtPath");function rn(e,t,n){const r=t.split(".");let o=e;for(let a=0;a<r.length-1;a++){const c=r[a];c&&(c in o||(o[c]={}),o=o[c])}const i=r[r.length-1];i&&(o[i]=n)}s(rn,"setTokenAtPath");async function on(e){const t=C(e)?e:O(process.cwd(),e),n=J(t),r=[],o=[],i=pe(process.cwd(),t),a=await Dt(t);if(a.errors.length>0)return{trees:[],modifiers:[],errors:a.errors.map(p=>({file:p.path,message:p.message}))};const c=await Qt(a.document,n);for(const p of c.errors)r.push({file:p.path,message:p.message});Object.keys(c.base).length>0&&o.push({context:void 0,tokens:c.base,sourcePath:i});const u=[];for(const p of c.modifiers){const m=[];for(const[d,I]of p.contexts)Object.keys(I).length>0&&(o.push({context:`${p.name}:${d}`,tokens:I,sourcePath:i}),m.push(d));u.push({name:p.name,attribute:`data-${p.name}`,defaultContext:p.defaultContext,contexts:m})}return{trees:o,modifiers:u,errors:r}}s(on,"loadFromResolver");async function sn(e){const t=[],n=[],r=Object.entries(e);r.sort(([,o],[,i])=>{const a=!o.context,c=!i.context;return a&&!c?-1:!a&&c?1:0});for(const[o,{context:i,content:a}]of r)try{const c=JSON.parse(a);t.push({context:i,tokens:c,sourcePath:pe(process.cwd(),o)})}catch(c){c instanceof Error?c instanceof SyntaxError?n.push({file:o,message:f.LOAD.INVALID_JSON(o,c.message)}):n.push({file:o,message:c.message}):n.push({file:o,message:"Unknown error"})}return{trees:t,errors:n}}s(sn,"loadTreesFromMemory");function P(e,t,n,r){return typeof t=="string"&&h(t)?cn(e,t,n,r):Array.isArray(t)?t.map(o=>P(e,o,n,r)):typeof t=="object"&&t!==null?Object.entries(t).reduce((i,[a,c])=>Object.assign(i,{[a]:P(`${e}.${a}`,c,n,r)}),{}):t}s(P,"resolveValue");function Ce(e,t){const n=e.slice(1,-1),r=t.pathIndex.get(n);if(!r)return;const o=t.tokens[r];if(!(!o||!("$value"in o))){if(o.$type)return o.$type;if(typeof o.$value=="string"&&h(o.$value))return Ce(o.$value,t)}}s(Ce,"inferTypeFromReference");function an(e){const t={},n=new Set,r=[];for(const[o,i]of Object.entries(e.tokens))try{if(!("$value"in i)){t[o]=i;continue}const a=i;let c=a.$type;!c&&typeof a.$value=="string"&&h(a.$value)&&(c=Ce(a.$value,e)),t[o]={...a,...c?{$type:c}:{},$resolvedValue:P(a.$path,a.$value,e,n)}}catch(a){const c=a instanceof Error?a.message:String(a),u=i,p=u.$path,m=u.$source;let d,I;c.includes("Circular reference detected")?(d="circular",I=c):c.includes("Reference not found")?(d="missing",I=c):(d="type-mismatch",I=f.RESOLVE.TYPE_MISMATCH(p)),r.push({type:d,path:p,source:m,message:I})}return{resolved:t,errors:r}}s(an,"resolve");function cn(e,t,n,r){const o=t.slice(1,-1),i=n.pathIndex.get(o);if(!i)throw new Error(f.RESOLVE.REFERENCE_NOT_FOUND(o,e));if(r.has(i)){const u=n.tokens[i];throw!u||!("$path"in u)?new Error(f.RESOLVE.REFERENCE_NOT_FOUND(o,e)):new Error(f.RESOLVE.CIRCULAR_REFERENCE(e,u.$path))}const a=n.tokens[i];if(!a||!("$value"in a))throw new Error(f.RESOLVE.REFERENCE_NOT_FOUND(o,e));r.add(i);const c=P(i,a.$value,n,r);return r.delete(i),c}s(cn,"resolveReferenceChain");function S(e){return{success:!0,value:e}}s(S,"success");function g(e){return{success:!1,error:e}}s(g,"error");function ne(e){if(typeof e!="object"||e===null)return!1;const t=e;return!(typeof t.colorSpace!="string"||!["oklch","display-p3","srgb","hsl"].includes(t.colorSpace)||!Array.isArray(t.components)||t.components.length!==3||!t.components.every(r=>typeof r=="number"||r==="none")||t.alpha!==void 0&&typeof t.alpha!="number"||t.hex!==void 0&&typeof t.hex!="string")}s(ne,"isDTCGColorValue");function U(e){const t=[],n=["oklch","display-p3","srgb","hsl"];if(n.includes(e.colorSpace)||t.push(`Unsupported colorSpace: "${e.colorSpace}". Supported color spaces: ${n.join(", ")}.`),!Array.isArray(e.components)||e.components.length!==3)t.push("Components must be an array of exactly 3 numbers.");else if(e.components.forEach((r,o)=>{r!=="none"&&(typeof r!="number"||!Number.isFinite(r))&&t.push(`Component ${o} must be a finite number or "none".`)}),e.colorSpace==="oklch"){const[r,o,i]=e.components;r!=="none"&&(r<0||r>1)&&t.push("OKLCH Lightness (L) must be between 0 and 1 or 'none'."),o!=="none"&&o<0&&t.push("OKLCH Chroma (C) must be >= 0 or 'none'."),i!=="none"&&(i<0||i>=360)&&t.push("OKLCH Hue (H) must be between 0 and 360 (exclusive) or 'none'.")}else if(e.colorSpace==="display-p3"){const[r,o,i]=e.components;r!=="none"&&(r<0||r>1)&&t.push("Display P3 Red component must be between 0 and 1 or 'none'."),o!=="none"&&(o<0||o>1)&&t.push("Display P3 Green component must be between 0 and 1 or 'none'."),i!=="none"&&(i<0||i>1)&&t.push("Display P3 Blue component must be between 0 and 1 or 'none'.")}else if(e.colorSpace==="srgb"){const[r,o,i]=e.components;r!=="none"&&(r<0||r>1)&&t.push("sRGB Red component must be between 0 and 1 or 'none'."),o!=="none"&&(o<0||o>1)&&t.push("sRGB Green component must be between 0 and 1 or 'none'."),i!=="none"&&(i<0||i>1)&&t.push("sRGB Blue component must be between 0 and 1 or 'none'.")}else if(e.colorSpace==="hsl"){const[r,o,i]=e.components;r!=="none"&&(r<0||r>=360)&&t.push("HSL Hue must be between 0 and 360 (exclusive) or 'none'."),o!=="none"&&(o<0||o>100)&&t.push("HSL Saturation must be between 0 and 100 or 'none'."),i!=="none"&&(i<0||i>100)&&t.push("HSL Lightness must be between 0 and 100 or 'none'.")}return e.alpha!==void 0&&(typeof e.alpha!="number"||!Number.isFinite(e.alpha)?t.push("Alpha must be a finite number."):(e.alpha<0||e.alpha>1)&&t.push("Alpha must be between 0 and 1.")),t}s(U,"validateDTCGColorValue");function un(e){const t=U(e);return t.length>0?g(t.join(", ")):S(e)}s(un,"validateDTCGColorValueResult");function fn(e){const t=un(e);if(!t.success)return t;const[n,r,o]=e.components,i=e.alpha,a=n==="none"?"none":Number(n.toFixed(4)),c=r==="none"?"none":Number(r.toFixed(4)),u=o==="none"?"none":Number(o.toFixed(4));if(i!==void 0&&i!==1){const p=Number(i.toFixed(4));return S(`oklch(${a} ${c} ${u} / ${p})`)}return S(`oklch(${a} ${c} ${u})`)}s(fn,"formatDTCGColorToOKLCH");const ln={isObject:s(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObject")};function E(e,t,n,r){if(h(t))return[];switch(e.type){case"object":return dn(e,t,n,r);case"union":return mn(e,t,n,r);case"array":return hn(e,t,n,r);default:return pn(e,t,n,r)}}s(E,"validateSchema");function pn(e,t,n,r){return e.type!==typeof t?[{path:n,message:e.errorMessage?.(t,n)||f.VALIDATE.INVALID_TYPE(e.type,t,n),source:r}]:e.validate?.(t,n,r)??[]}s(pn,"validateSimpleValue");function dn(e,t,n,r){if(!ln.isObject(t))return[{path:n,message:e.errorMessage?.(t,n)||f.VALIDATE.INVALID_TYPE("object",t,n),source:r}];const o=[],i=t;if(e.required)for(const a of e.required)a in i||o.push({path:`${n}.${a}`,message:f.VALIDATE.MISSING_REQUIRED_PROPERTY(a,n),source:r});for(const[a,c]of Object.entries(e.properties))a in i&&o.push(...E(c,i[a],`${n}.${a}`,r));return o}s(dn,"validateObject");function mn(e,t,n,r){let o=[],i=Number.POSITIVE_INFINITY;for(const a of e.oneOf){if(a.type==="string"&&typeof t!="string"||a.type==="object"&&typeof t!="object")continue;const c=E(a,t,n,r);if(c.length===0)return a.validate?.(t,n,r)??[];c.length<i&&(o=c,i=c.length)}return i===Number.POSITIVE_INFINITY?[{path:n,message:f.VALIDATE.INVALID_TYPE(e.oneOf.map(a=>a.type).join(" or "),t,n),source:r}]:o}s(mn,"validateUnion");function hn(e,t,n,r){return Array.isArray(t)?e.validate?.(t,n,r)??[]:[{path:n,message:e.errorMessage?.(t,n)||f.VALIDATE.INVALID_TYPE("array",t,n),source:r}]}s(hn,"validateArray");const G={schema:{type:"union",oneOf:[{type:"string",validate:s((e,t,n)=>/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(e)?[]:[{path:t,message:f.VALIDATE.INVALID_COLOR(e,t),source:n}],"validate")},{type:"object",required:["colorSpace","components"],properties:{colorSpace:{type:"string"},components:{type:"array"},alpha:{type:"number"},hex:{type:"string"}},validate:s((e,t,n)=>ne(e)?U(e).map(o=>({path:t,message:`Invalid color at ${t}: ${o}`,source:n})):[{path:t,message:f.VALIDATE.INVALID_COLOR(e,t),source:n}],"validate")}]}};function In(e,t,n){return E(G.schema,e,t,n)}s(In,"validateColor");const B={schema:{type:"number",errorMessage:s((e,t)=>f.VALIDATE.INVALID_NUMBER(e,t),"errorMessage"),validate:s((e,t,n)=>typeof e!="number"||Number.isNaN(e)?[{path:t,message:f.VALIDATE.INVALID_NUMBER(e,t),source:n}]:[],"validate")}};function yn(e,t,n){return E(B.schema,e,t,n)}s(yn,"validateNumber");const N={schema:{type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_DIMENSION(e,t),"errorMessage"),properties:{value:B.schema,unit:{type:"string",validate:s((e,t,n)=>typeof e!="string"||!["px","rem"].includes(e)?[{path:t,message:f.VALIDATE.INVALID_DIMENSION_UNIT(e,t),source:n}]:[],"validate")}},required:["value","unit"]}};function En(e,t,n){return E(N.schema,e,t,n)}s(En,"validateDimension");const $n=["solid","dashed","dotted","double","groove","ridge","outset","inset"],gn=["round","butt","square"],Nn={type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_STROKE_STYLE(e,t),"errorMessage"),properties:{dashArray:{type:"array",validate:s((e,t,n)=>{const r=e,o=[];return r.forEach((i,a)=>{typeof i!="string"&&o.push(...E(N.schema,i,`${t}.${a}`,n))}),o},"validate")},lineCap:{type:"string",validate:s((e,t,n)=>gn.includes(e)?[]:[{path:t,message:f.VALIDATE.INVALID_STROKE_LINE_CAP(e,t),source:n}],"validate")}},required:["dashArray","lineCap"]},Fe={schema:{type:"union",oneOf:[{type:"string",validate:s((e,t,n)=>!$n.includes(e)&&typeof e=="string"?[{path:t,message:f.VALIDATE.INVALID_STROKE_STYLE(e,t),source:n}]:[],"validate")},Nn]}};function Tn(e,t,n){return E(Fe.schema,e,t,n)}s(Tn,"validateStrokeStyle");const Sn={schema:{type:"object",properties:{color:G.schema,width:N.schema,style:Fe.schema},required:["color","width","style"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_BORDER(e,t),"errorMessage")}};function An(e,t,n){return E(Sn.schema,e,t,n)}s(An,"validateBorder");const Ve={schema:{type:"array",errorMessage:s((e,t)=>f.VALIDATE.INVALID_CUBIC_BEZIER(e,t),"errorMessage"),validate:s((e,t,n)=>{const r=e;if(r.length!==4||!r.every(a=>typeof a=="number"))return[{path:t,message:f.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}];const[o,,i]=r;return o<0||o>1||i<0||i>1?[{path:t,message:f.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}]:[]},"validate")}};function bn(e,t,n){return E(Ve.schema,e,t,n)}s(bn,"validateCubicBezier");const On=["ms","s"],re={schema:{type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_DURATION(e,t),"errorMessage"),properties:{value:B.schema,unit:{type:"string",validate:s((e,t,n)=>On.includes(e)?[]:[{path:t,message:f.VALIDATE.INVALID_DURATION_UNIT(e,t),source:n}],"validate")}},required:["value","unit"]}};function Dn(e,t,n){return E(re.schema,e,t,n)}s(Dn,"validateDuration");const Rn={schema:{type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FLUID_DIMENSION(e,t),"errorMessage"),properties:{min:N.schema,max:N.schema},required:["min","max"]}};function Ln(e,t,n){return E(Rn.schema,e,t,n)}s(Ln,"validateFluidDimension");const we={schema:{type:"union",oneOf:[{type:"string",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")},{type:"array",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage"),validate:s((e,t,n)=>e.every(o=>typeof o=="string")?[]:[{path:t,message:f.VALIDATE.INVALID_FONT_FAMILY(e,t),source:n}],"validate")}],errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")}};function _n(e,t,n){return E(we.schema,e,t,n)}s(_n,"validateFontFamily");const vn=["thin","hairline","extra-light","ultra-light","light","normal","regular","book","medium","semi-bold","demi-bold","bold","extra-bold","ultra-bold","black","heavy","extra-black","ultra-black"],ke={schema:{type:"union",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),oneOf:[{type:"number",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:s((e,t,n)=>e<1||e>1e3?[{path:t,message:f.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}]:[],"validate")},{type:"string",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:s((e,t,n)=>vn.includes(e.toLowerCase())?[]:[{path:t,message:f.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}],"validate")}]}};function xn(e,t,n){return E(ke.schema,e,t,n)}s(xn,"validateFontWeight");const Cn={type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_GRADIENT(e,t),"errorMessage"),properties:{color:G.schema,position:{type:"number",validate:s((e,t,n)=>e<0||e>1?[{path:t,message:f.VALIDATE.INVALID_GRADIENT_STOP_POSITION(e,t),source:n}]:[],"validate")}},required:["color","position"]},Fn={schema:{type:"array",errorMessage:s((e,t)=>f.VALIDATE.INVALID_ARRAY(e,t),"errorMessage"),validate:s((e,t,n)=>{const r=e,o=[];return r.forEach((i,a)=>{o.push(...E(Cn,i,`${t}[${a}]`,n))}),o},"validate")}};function Vn(e,t,n){return E(Fn.schema,e,t,n)}s(Vn,"validateGradient");const Me={schema:{type:"object",properties:{color:{type:"union",oneOf:[G.schema]},offsetX:N.schema,offsetY:N.schema,blur:N.schema,spread:N.schema,inset:{type:"boolean",errorMessage:s((e,t)=>f.VALIDATE.INVALID_SHADOW_INSET(e,t),"errorMessage")}},required:["color","offsetX","offsetY","blur","spread"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_SHADOW(e,t),"errorMessage")}};function wn(e,t,n){const r=[];return Array.isArray(e)?(e.forEach((o,i)=>{r.push(...E(Me.schema,o,`${t}[${i}]`,n))}),r):E(Me.schema,e,t,n)}s(wn,"validateShadow");const kn={schema:{type:"object",properties:{duration:re.schema,delay:re.schema,timingFunction:Ve.schema},required:["duration","delay","timingFunction"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_TRANSITION(e,t),"errorMessage")}};function Mn(e,t,n){return E(kn.schema,e,t,n)}s(Mn,"validateTransition");const jn={schema:{type:"object",properties:{fontFamily:we.schema,fontSize:N.schema,letterSpacing:N.schema,lineHeight:B.schema,fontWeight:ke.schema},required:["fontFamily","fontSize"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_TYPOGRAPHY(e,t),"errorMessage")}};function Pn(e,t,n){return E(jn.schema,e,t,n)}s(Pn,"validateTypography");const Un={color:In,dimension:En,fluidDimension:Ln,duration:Dn,cubicBezier:bn,fontFamily:_n,fontWeight:xn,number:yn,strokeStyle:Tn,typography:Pn,border:An,shadow:wn,gradient:Vn,transition:Mn};function Gn(e){const t=[];for(const[n,r]of Object.entries(e.tokens)){if(typeof r!="object"||r===null||!("$type"in r)||!("$path"in r)||r.$path.startsWith("$"))continue;if(!("$value"in r)){t.push({path:r.$path,message:f.VALIDATE.MISSING_REQUIRED_PROPERTY("$value",r.$path),source:r.$source});continue}const o=Un[r.$type];if(!o){t.push({path:r.$path,message:f.VALIDATE.UNKNOWN_TOKEN_TYPE(r.$type,r.$path),source:r.$source});continue}const i=r;t.push(...o(i.$value,i.$path,i.$source))}return t}s(Gn,"validate");async function Bn(e){const{trees:t,modifiers:n,errors:r}=await Wn(e),{tokens:o,errors:i}=Et(t),a=Gn(o),{resolved:c,errors:u}=an(o);return{trees:t,resolved:c,modifiers:n,errors:{load:r,flatten:i,validation:a,resolution:u}}}s(Bn,"loadAndResolveTokens");async function Wn(e){switch(e.type){case"memory":{const t=await sn(e.data);return{trees:t.trees,modifiers:[],errors:t.errors}}case"resolver":{const t=await on(e.resolverPath);return{trees:t.trees,modifiers:t.modifiers,errors:t.errors}}}}s(Wn,"loadTokens");function je(e){return h(e)?{value:e}:typeof e=="string"?{value:e}:{value:`${e.dashArray.map(n=>h(n)?n:`${n.value}${n.unit}`).join(" ")} ${e.lineCap}`}}s(je,"convertStrokeStyleToken");function Yn(e){if(h(e))return{value:e};const t=h(e.width)?e.width:`${e.width.value}${e.width.unit}`,n=(h(e.color),e.color),r=typeof e.style=="string"?e.style:je(e.style).value;return{value:`${t} ${r} ${n}`}}s(Yn,"convertBorderToken");function Pe(e,t="native"){return ne(e)?Hn(e):S(e)}s(Pe,"convertColorToString");function Hn(e){switch(e.colorSpace){case"oklch":return fn(e);case"display-p3":return Kn(e);case"srgb":return qn(e);case"hsl":return zn(e);default:return g(`Unsupported color space: ${e.colorSpace}. Supported color spaces: oklch, display-p3, srgb, hsl.`)}}s(Hn,"formatDTCGColorNative");function Kn(e){if(e.colorSpace!=="display-p3")return g(`Expected display-p3 color space, got: ${e.colorSpace}`);if(!Array.isArray(e.components)||e.components.length!==3)return g("Display P3 components must be an array of exactly 3 numbers [R, G, B]");const[t,n,r]=e.components,o=e.alpha;if(t!=="none"&&(t<0||t>1))return g("Display P3 Red component must be between 0 and 1 or 'none'");if(n!=="none"&&(n<0||n>1))return g("Display P3 Green component must be between 0 and 1 or 'none'");if(r!=="none"&&(r<0||r>1))return g("Display P3 Blue component must be between 0 and 1 or 'none'");if(o!==void 0&&(o<0||o>1))return g("Alpha must be between 0 and 1");const i=t==="none"?"none":Number(t.toFixed(4)),a=n==="none"?"none":Number(n.toFixed(4)),c=r==="none"?"none":Number(r.toFixed(4));if(o!==void 0&&o!==1){const u=Number(o.toFixed(4));return S(`color(display-p3 ${i} ${a} ${c} / ${u})`)}return S(`color(display-p3 ${i} ${a} ${c})`)}s(Kn,"formatDTCGColorToP3");function qn(e){if(e.colorSpace!=="srgb")return g(`Expected srgb color space, got: ${e.colorSpace}`);const t=U(e);if(t.length>0)return g(`Invalid DTCG color value: ${t.join(", ")}`);const[n,r,o]=e.components,i=e.alpha,a=n==="none"?"none":Math.round(n*255),c=r==="none"?"none":Math.round(r*255),u=o==="none"?"none":Math.round(o*255);if(i!==void 0&&i!==1){const p=Number(i.toFixed(4));return S(`rgb(${a} ${c} ${u} / ${p})`)}return S(`rgb(${a} ${c} ${u})`)}s(qn,"formatDTCGColorToRGB");function zn(e){if(e.colorSpace!=="hsl")return g(`Expected hsl color space, got: ${e.colorSpace}`);const t=U(e);if(t.length>0)return g(`Invalid DTCG color value: ${t.join(", ")}`);const[n,r,o]=e.components,i=e.alpha,a=n==="none"?"none":Number(n.toFixed(1)),c=r==="none"?"none":Math.round(r),u=o==="none"?"none":Math.round(o);if(i!==void 0&&i!==1){const d=Number(i.toFixed(4)),I=c==="none"?"none":`${c}%`,y=u==="none"?"none":`${u}%`;return S(`hsl(${a} ${I} ${y} / ${d})`)}const p=c==="none"?"none":`${c}%`,m=u==="none"?"none":`${u}%`;return S(`hsl(${a} ${p} ${m})`)}s(zn,"formatDTCGColorToHSL");function Jn(e,t){if(typeof e=="string"&&h(e))return{value:e};const n=t.colorFallbackStrategy;if(ne(e))return Xn(e,n);const r=Pe(e,n);return r.success?{value:r.value}:(console.warn(`Failed to convert color ${typeof e=="string"?e:"DTCG color object"}: ${r.error}`),{value:typeof e=="string"?e:"#000000"})}s(Jn,"convertColorToken");function Xn(e,t){const n=Pe(e,t);if(!n.success)return console.warn(`Failed to convert DTCG color: ${n.error}`),{value:"#000000"};const r=n.value;if(t==="native")return{value:r};if(e.colorSpace==="srgb"||e.colorSpace==="hsl")return{value:r};if(!e.hex)throw new Error(`${e.colorSpace} colors require a 'hex' fallback when using 'polyfill' strategy. Tip: Switch to 'native' strategy if targeting modern browsers only.`);return{value:e.hex,featureValues:[{query:Zn(e.colorSpace),value:r}]}}s(Xn,"convertDTCGColorToken");function Zn(e){switch(e){case"oklch":return"@supports (color: oklch(0 0 0))";case"display-p3":return"@supports (color: color(display-p3 1 1 1))";default:throw new Error(`No feature query defined for color space: ${e}`)}}s(Zn,"getFeatureQuery");function Qn(e){return h(e)?{value:e}:{value:`cubic-bezier(${e.join(", ")})`}}s(Qn,"convertCubicBezierToken");function er(e){return h(e)?{value:e}:{value:`${e.value}${e.unit}`}}s(er,"convertDimensionToken");function tr(e){return h(e)?{value:e}:{value:`${e.value}${e.unit}`}}s(tr,"convertDurationToken");function Ue(e,t=16){return e.unit==="px"?e.value:e.value*t}s(Ue,"normalizeToPixels");function nr(e,t){const{min:n,max:r}=e,o=t.fluidConfig,i=16,a=Ue(n,i),c=Ue(r,i),u=o.min,p=o.max;if(a===c)return{value:`${a/i}rem`};const m=a/i,d=c/i,I=u/i,y=p/i,$=(d-m)/(y-I),ce=-1*I*$+m;return{value:`clamp(${m}rem, ${ce.toFixed(2)}rem + ${($*100).toFixed(2)}vw, ${d}rem)`}}s(nr,"convertFluidDimension");function rr(e,t){return h(e)?{value:e}:nr(e,t)}s(rr,"convertFluidDimensionToken");function W(e){return["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","emoji","math","fangsong"].includes(e.toLowerCase())?e:/[\s'"!@#$%^&*()=+[\]{};:|\\/,.<>?~]/.test(e)?`"${e}"`:e}s(W,"quoteFont");function or(e){return h(e)?{value:e}:{value:Array.isArray(e)?e.map(n=>W(n)).join(", "):W(e)}}s(or,"convertFontFamilyToken");const sr={thin:100,hairline:100,"extra-light":200,"ultra-light":200,light:300,normal:400,regular:400,book:400,medium:500,"semi-bold":600,"demi-bold":600,bold:700,"extra-bold":800,"ultra-bold":800,black:900,heavy:900,"extra-black":950,"ultra-black":950};function Ge(e){return h(e)?{value:e}:typeof e=="number"?{value:e}:{value:sr[e.toLowerCase()]??e}}s(Ge,"convertFontWeightToken");function ir(e){return h(e)?{value:e}:{value:`linear-gradient(${e.map(n=>{const r=(h(n.color),n.color),o=h(n.position)?n.position:`${n.position*100}`;return`${r} ${o}%`}).join(", ")})`}}s(ir,"convertGradientToken");function ar(e){return h(e)?{value:e}:{value:e}}s(ar,"convertNumberToken");function Be(e){const t=h(e.offsetX)?e.offsetX:`${e.offsetX.value}${e.offsetX.unit}`,n=h(e.offsetY)?e.offsetY:`${e.offsetY.value}${e.offsetY.unit}`,r=h(e.blur)?e.blur:`${e.blur.value}${e.blur.unit}`,o=h(e.spread)?e.spread:`${e.spread.value}${e.spread.unit}`,i=(h(e.color),e.color);return`${e.inset?"inset ":""}${t} ${n} ${r} ${o} ${i}`}s(Be,"convertSingleShadow");function cr(e){return h(e)?{value:e}:Array.isArray(e)?{value:e.map(Be).join(", ")}:{value:Be(e)}}s(cr,"convertShadowToken");function We(e){return e?`${e.value}${e.unit}`:"0ms"}s(We,"formatDuration");function ur(e){if(h(e))return{value:e};const t=h(e.duration)?e.duration:We(e.duration),n=h(e.timingFunction)?e.timingFunction:`cubic-bezier(${e.timingFunction.join(", ")})`,r=e.delay&&(h(e.delay)?e.delay:We(e.delay));return{value:[t,n,r].filter(Boolean).join(" ")}}s(ur,"convertTransitionToken");function fr(e){if(h(e))return{"font-family":e,"font-size":e};const t={"font-family":h(e.fontFamily)?e.fontFamily:Array.isArray(e.fontFamily)?e.fontFamily.map(n=>W(n)).join(", "):W(e.fontFamily),"font-size":h(e.fontSize)?e.fontSize:`${e.fontSize.value}${e.fontSize.unit}`};return e.fontWeight&&(t["font-weight"]=h(e.fontWeight)?e.fontWeight:Ge(e.fontWeight).value),e.letterSpacing&&(t["letter-spacing"]=h(e.letterSpacing)?e.letterSpacing:`${e.letterSpacing.value}${e.letterSpacing.unit}`),e.lineHeight&&(t["line-height"]=(h(e.lineHeight),e.lineHeight)),t}s(fr,"convertTypographyToken");const Ye={duration:tr,number:ar,cubicBezier:Qn,color:Jn,dimension:er,fluidDimension:rr,typography:fr,border:Yn,shadow:cr,gradient:ir,transition:ur,strokeStyle:je,fontFamily:or,fontWeight:Ge};function lr(e,t){const n=Ye[e.$type];return{...e.$description?{$description:e.$description}:{},...e.$extensions?{$extensions:e.$extensions}:{},$type:e.$type,$value:e.$value,$path:e.$path,$source:e.$source,$originalPath:e.$originalPath,$resolvedValue:e.$resolvedValue,$cssProperties:n(e.$value,t)}}s(lr,"convertSingleToken");function pr(e,t,n){const r={};for(const[o,i]of Object.entries(e)){if(!i||typeof i!="object")continue;if(!("$type"in i)){r[o]={...i.$description?{$description:i.$description}:{},...i.$extensions?{$extensions:i.$extensions}:{}};continue}if(n?.(i.$path)){console.warn(`[sugarcube] Skipping invalid token: ${i.$path} (has validation error)`);continue}if(!Ye[i.$type])continue;const a={fluidConfig:t.transforms.fluid,colorFallbackStrategy:t.transforms.colorFallbackStrategy,path:i.$path,resolvedTokens:e};r[o]=lr(i,a)}return r}s(pr,"convertTokens");function dr(e,t,n){const r={};for(const[o,i]of Object.entries(e))r[o]=pr(i,t,n);return r}s(dr,"convert");function mr(e,t){const n={},r=new Set;for(const o of e){const i=o.context??"default";r.add(i)}for(const o of r)n[o]={};for(const o of e){const{context:i,tokens:a}=o,c=i??"default";n[c]||(n[c]={});for(const[u,p]of Object.entries(a))n[c][u]=p}return{tokens:n,defaultContext:t}}s(mr,"normalizeTokens");function hr(e,t){const n=new Map;for(const[r,o]of Object.entries(t)){if(!("$source"in o)){for(const c of e){const u=c.context??"";n.has(u)||n.set(u,{});const p=n.get(u);p&&(p[r]=o)}continue}const i=o.$source.context??"";n.has(i)||n.set(i,{});const a=n.get(i);a&&(a[r]=o)}return e.map(r=>{const o=r.context??"",i=n.get(o)||{};return{context:r.context,tokens:i}})}s(hr,"processTrees");async function Ir(e,t,n,r){const o=hr(e,t),{tokens:i}=mr(o);return dr(i,n,r?u=>r.some(p=>p.path===u||p.path.startsWith(`${u}.`)):void 0)}s(Ir,"processAndConvertTokens");function yr(e){return Object.entries(e).sort(([t],[n])=>t.localeCompare(n))}s(yr,"deterministicEntries");const He=new Map;function Er(e){const t=He.get(e);if(t)return t;const n=e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase();return He.set(e,n),n}s(Er,"toKebabCase");function oe(e){return e.split(".").join("-")}s(oe,"formatCSSVarPath");function se(e){return typeof e=="number"?e:typeof e!="string"?(console.warn("Unexpected value type in convertReferenceToCSSVar, got:",e),String(e)):e.replace(/\{([^}]+)\}/g,(t,n)=>`var(--${n.split(".").map(Er).join("-")})`)}s(se,"convertReferenceToCSSVar");function $r(e){const t=e.$cssProperties;if("value"in t)return{name:`--${oe(e.$path)}`,value:se(t.value)}}s($r,"generateSingleVariable");function gr(e){return Object.entries(e.$cssProperties).filter(([t,n])=>n!==void 0).map(([t,n])=>({name:`--${oe(e.$path)}-${t}`,value:se(n)}))}s(gr,"generateTypographyVariables");function Ke(e){if(e.$type!=="color")return[];const t=e.$cssProperties;if(!("featureValues"in t))return[];const n=new Map;for(const r of t.featureValues||[]){n.has(r.query)||n.set(r.query,[]);const o=n.get(r.query);o&&o.push({name:`--${oe(e.$path)}`,value:se(r.value)})}return Array.from(n.entries()).map(([r,o])=>({query:r,vars:o}))}s(Ke,"generateFeatureVariables");function qe(e){const t=[`${e.selector} {`];if(e.comment&&t.push(` /* ${e.comment} */`),e.vars.length>0){const n=e.vars.map(r=>` ${r.name}: ${r.value};`).join(`
5
+ `))}return t.data}s(Ie,"validateInternalConfig");function ct(e){const t=Q(e),n=Z(t);return Ie(n)}s(ct,"validateConfig");function ye(e="sugarcube.config"){const t=[".ts",".js"],n=process.cwd();for(const r of t){const o=O(n,`${e}${r}`);if(z(o))return o}return null}s(ye,"findConfigFile");function ut(e="sugarcube.config"){return ye(e)!==null}s(ut,"configFileExists");async function ft(e){try{if(typeof globalThis.Bun<"u"){const i=tt(e).href,c=await new Function("url","return import(url)")(i);if(c&&typeof c=="object"&&"default"in c)return c.default;throw new Error(f.CONFIG.INVALID_CONFIG("root","Config file must export a default object"))}const{createJiti:n}=await import("jiti"),o=await n(import.meta.url,{interopDefault:!0}).import(e);return o&&typeof o=="object"&&"default"in o?o.default:o}catch(t){throw t instanceof Error?new Error(f.CONFIG.INVALID_CONFIG("root",t.message)):t}}s(ft,"loadTSConfig");async function Ee(e){if(e.endsWith(".ts")||e.endsWith(".js"))return await ft(e);const n=await et.readFile(e,"utf-8");return JSON.parse(n)}s(Ee,"loadConfigFile");function $e(e){if(e)return O(process.cwd(),e);const t=ye();if(!t)throw new Error(f.CONFIG.FILE_NOT_FOUND(X));return t}s($e,"resolveConfigPath");async function lt(e){const t=$e(e);try{const n=await Ee(t);return{config:Q(n),configPath:t}}catch(n){throw n instanceof Error&&"code"in n&&n.code==="ENOENT"?new Error(f.CONFIG.FILE_NOT_FOUND(t)):n instanceof SyntaxError?new Error(f.CONFIG.INVALID_JSON(n.message)):n}}s(lt,"loadSugarcubeConfig");async function pt(e){const t=$e(e);try{const n=await Ee(t),r=Q(n),o=Z(r);return{config:Ie(o),configPath:t}}catch(n){throw n instanceof Error&&"code"in n&&n.code==="ENOENT"?new Error(f.CONFIG.FILE_NOT_FOUND(t)):n instanceof SyntaxError?new Error(f.CONFIG.INVALID_JSON(n.message)):n}}s(pt,"loadInternalConfig");function h(e){return typeof e=="string"&&e.startsWith("{")&&e.endsWith("}")}s(h,"isReference$1");function dt(e){if(typeof e!="object"||e===null||!("$value"in e))return!1;const t=e.$value;return typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.keys(t).length>0}s(dt,"isCompositeToken");function mt(e){return e.$type==="typography"}s(mt,"isTypographyToken");function ee(e){return typeof e=="object"&&e!==null&&"$value"in e}s(ee,"isTokenNode");function ht(e,t,n){for(const[r,o]of Object.entries(t.tokens)){const i=e.tokens[r];if(!ee(o)){if(i&&ee(i)){const d=i;n.push({path:d.$path,source:d.$source,message:f.FLATTEN.CONFLICT_TOKEN_VS_GROUP(d.$path)});continue}e.tokens[r]=o;continue}if(!i){e.tokens[r]=o;continue}if(!ee(i)){n.push({path:o.$path,source:o.$source,message:f.FLATTEN.CONFLICT_TOKEN_VS_GROUP(o.$path)});continue}const c=o,u=i,p=!!c.$type,m=!!u.$type;if(p&&m&&c.$type!==u.$type){n.push({path:c.$path,source:c.$source,message:f.FLATTEN.CONFLICT_INCOMPATIBLE_TYPES(String(u.$type??"unknown"),String(c.$type??"unknown"),c.$path)});continue}e.tokens[r]=o}for(const[r,o]of t.pathIndex)e.pathIndex.set(r,o)}s(ht,"mergeFlattenedInto");function It(e){if(typeof e!="object"||e===null||"$value"in e)return!1;const t="value"in e,n="type"in e;if(t&&n)return!0;if(t){const r=e.value;return typeof r=="string"||typeof r=="number"||Array.isArray(r)}return!1}s(It,"looksLikeUnprefixedToken");function yt(e,t){const n={tokens:{},pathIndex:new Map},r=[];function o(a=[]){const c=[];return t.context&&c.push(t.context),a.length>0&&c.push(a.join(".")),c.length>0?c.join("."):""}s(o,"createLookupKey"),(e.$description||e.$extensions)&&(n.tokens[o()]={$description:e.$description,$extensions:e.$extensions});function i(a,c=[],u){if(c.join("."),c.length>0){const d=o(c);n.tokens[d]={$description:a.$description,$extensions:a.$extensions,$path:c.join("."),$source:{context:t.context,sourcePath:t.sourcePath}}}const p=Object.keys(a).filter(d=>!d.startsWith("$")),m=a.$type||u;for(const d of p){const I=a[d],y=[...c,d],$=y.join(".");if(It(I)){r.push({path:$,source:t,message:f.FLATTEN.MISSING_DOLLAR_PREFIX($)});continue}if(d.includes(".")||d.includes("{")||d.includes("}")){r.push({path:$,source:t,message:f.FLATTEN.INVALID_TOKEN_NAME(d)});continue}if("$value"in I){if(Object.keys(I).filter(Ze=>!Ze.startsWith("$")).length>0){r.push({path:$,source:t,message:f.FLATTEN.INVALID_TOKEN_NESTING($)});continue}if(dt(I)&&!I.$type&&!m){r.push({path:$,source:t,message:f.FLATTEN.COMPOSITE_TOKEN_MISSING_TYPE($)});continue}const ue=o(y),q=y.join(".");n.tokens[ue]={...I,...I.$type||m?{$type:I.$type||m}:{},$path:q,$source:{context:t.context,sourcePath:t.sourcePath},$originalPath:q},n.pathIndex.set(q,ue)}else i(I,y,m)}}return s(i,"processNode"),i(e),{tokens:n,errors:r}}s(yt,"flattenTree");function Et(e){const t={tokens:{},pathIndex:new Map},n=[];for(const r of e){const{tokens:o,errors:i}=yt(r.tokens,{context:r.context,sourcePath:r.sourcePath});n.push(...i),ht(t,o,n)}return{tokens:t,errors:n}}s(Et,"flatten");const F=l.string().min(1,"Name cannot be empty").refine(e=>!e.startsWith("$"),"Names must not start with '$' (reserved prefix)").refine(e=>!e.includes("{"),"Names must not contain '{'").refine(e=>!e.includes("}"),"Names must not contain '}'").refine(e=>!e.includes("."),"Names must not contain '.'"),ge=l.object({$ref:l.string().min(1,"$ref cannot be empty")}).passthrough(),te=l.union([ge,l.record(l.string(),l.unknown())]),$t=l.object({description:l.string().optional(),sources:l.array(te),$extensions:l.record(l.string(),l.unknown()).optional()}),Ne=l.record(l.string(),l.array(te)),gt=l.object({description:l.string().optional(),contexts:Ne,default:l.string().optional(),$extensions:l.record(l.string(),l.unknown()).optional()}).refine(e=>Object.keys(e.contexts).length>=1,"Modifier must have at least 1 context"),Nt=l.object({type:l.literal("set"),name:F,sources:l.array(te),description:l.string().optional(),$extensions:l.record(l.string(),l.unknown()).optional()}),Tt=l.object({type:l.literal("modifier"),name:F,contexts:Ne,description:l.string().optional(),default:l.string().optional(),$extensions:l.record(l.string(),l.unknown()).optional()}).refine(e=>Object.keys(e.contexts).length>=1,"Modifier must have at least 1 context"),St=l.union([ge,Nt,Tt]),At=l.record(F,$t),bt=l.record(F,gt),Ot=l.object({version:l.literal("2025.10"),name:l.string().optional(),description:l.string().optional(),sets:At.optional(),modifiers:bt.optional(),resolutionOrder:l.array(St),$schema:l.string().optional(),$extensions:l.record(l.string(),l.unknown()).optional(),$defs:l.record(l.string(),l.unknown()).optional()});function D(e){return typeof e=="object"&&e!==null&&"$ref"in e&&typeof e.$ref=="string"}s(D,"isReference");function Te(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="set"}s(Te,"isInlineSet");function L(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="modifier"}s(L,"isInlineModifier");async function Dt(e){const t=C(e)?e:O(process.cwd(),e),n=await Rt(t);if(n.error)return{document:w(),errors:[n.error]};const r=Lt(n.content);if(r.error)return{document:w(),errors:[r.error]};const o=_t(r.data);if(o.errors.length>0)return{document:w(),errors:o.errors};const i=[];return vt(o.document,i),{document:o.document,errors:i}}s(Dt,"parseResolverDocument");async function Rt(e){try{return{content:await x(e,"utf-8")}}catch{return{error:{path:e,message:f.RESOLVER.FILE_NOT_FOUND(e)}}}}s(Rt,"loadFile");function Lt(e){try{return{data:JSON.parse(e)}}catch(t){const n=t instanceof Error?t.message:"Unknown error";return{error:{path:"resolver",message:f.RESOLVER.INVALID_JSON(n)}}}}s(Lt,"parseJson");function _t(e){const t=Ot.safeParse(e);if(!t.success){const n=t.error.errors.map(r=>{const o=r.path.join(".")||"resolver";return{path:o,message:`Resolver error at ${o}: ${r.message}. See https://sugarcube.sh/docs/resolver`}});return{document:w(),errors:n}}return{document:t.data,errors:[]}}s(_t,"validateSchema$1");function vt(e,t){xt(e,t),Ct(e,t),Ft(e,t)}s(vt,"validateDocument");function xt(e,t){if(e.modifiers)for(const[n,r]of Object.entries(e.modifiers))Se(r,`modifiers.${n}`,t);for(let n=0;n<e.resolutionOrder.length;n++){const r=e.resolutionOrder[n];L(r)&&Se(r,`resolutionOrder[${n}]`,t)}}s(xt,"validateModifierContexts");function Se(e,t,n){const r=Object.keys(e.contexts).length;if(r===0){n.push({path:`${t}.contexts`,message:f.RESOLVER.MODIFIER_NEEDS_CONTEXTS});return}r===1&&n.push({path:`${t}.contexts`,message:f.RESOLVER.MODIFIER_SINGLE_CONTEXT}),e.default&&!e.contexts[e.default]&&n.push({path:`${t}.default`,message:f.RESOLVER.INVALID_DEFAULT(e.default,Object.keys(e.contexts))})}s(Se,"checkModifierContexts");function Ct(e,t){const n=new Set;for(let r=0;r<e.resolutionOrder.length;r++){const o=e.resolutionOrder[r];if(D(o))continue;const i=o.name;n.has(i)&&t.push({path:`resolutionOrder[${r}].name`,message:f.RESOLVER.DUPLICATE_NAME(i)}),n.add(i)}}s(Ct,"validateNameUniqueness");function Ft(e,t){for(let n=0;n<e.resolutionOrder.length;n++){const r=e.resolutionOrder[n];if(D(r))Vt(r.$ref,`resolutionOrder[${n}].$ref`,e,t);else if(Te(r))V(r.sources,`resolutionOrder[${n}].sources`,t);else if(L(r))for(const[o,i]of Object.entries(r.contexts))V(i,`resolutionOrder[${n}].contexts.${o}`,t)}if(e.sets)for(const[n,r]of Object.entries(e.sets))V(r.sources,`sets.${n}.sources`,t);if(e.modifiers)for(const[n,r]of Object.entries(e.modifiers))for(const[o,i]of Object.entries(r.contexts))V(i,`modifiers.${n}.contexts.${o}`,t)}s(Ft,"validateReferences");function V(e,t,n){for(let r=0;r<e.length;r++){const o=e[r];if(!o)continue;if(!D(o)){const a=Object.keys(o);if(a.length===1){const c=a[0],u=o[c];typeof u=="string"&&(u.includes("/")||u.endsWith(".json"))&&n.push({path:`${t}[${r}]`,message:f.RESOLVER.MALFORMED_REFERENCE(c,u)})}continue}const i=o.$ref;i.startsWith("#/")&&(i.match(/^#\/sets\/[^/]+$/)||n.push({path:`${t}[${r}].$ref`,message:f.RESOLVER.INVALID_SOURCE_REFERENCE(i)}))}}s(V,"validateSourcesReferences");function Vt(e,t,n,r){if(!e.startsWith("#/"))return;const o=e.slice(2).split("/"),[i,a]=o;if(o.length!==2||!i||!a){r.push({path:t,message:f.RESOLVER.INVALID_REFERENCE(e)});return}if(i==="sets"){n.sets?.[a]||r.push({path:t,message:f.RESOLVER.UNDEFINED_SET(a)});return}if(i==="modifiers"){n.modifiers?.[a]||r.push({path:t,message:f.RESOLVER.UNDEFINED_MODIFIER(a)});return}r.push({path:t,message:f.RESOLVER.INVALID_REFERENCE(e)})}s(Vt,"validateReference");function w(){return{version:"2025.10",resolutionOrder:[]}}s(w,"createEmptyDocument");function Ae(e){if(typeof e!="object"||e===null)return!1;const t=e;return t.version==="2025.10"&&Array.isArray(t.resolutionOrder)}s(Ae,"isResolverFormat");function be(e,t){return{document:e,basePath:t,visitedRefs:new Set,fileCache:new Map}}s(be,"createResolveContext");async function Oe(e,t){if(t.visitedRefs.has(e))return T({},f.RESOLVER.CIRCULAR_REFERENCE(e),e);t.visitedRefs.add(e);try{return e.startsWith("#/")?wt(e,t):e.includes("#/")?await Mt(e,t):await kt(e,t)}finally{t.visitedRefs.delete(e)}}s(Oe,"resolveReference");function wt(e,t){const n=e.slice(2),[r,o]=n.split("/");if(!r||!o||n.split("/").length!==2)return T({sources:[]},f.RESOLVER.INVALID_REFERENCE(e));if(r==="sets"){const i=t.document.sets?.[o];return i?{content:i,sourcePath:"#",errors:[]}:T({sources:[]},f.RESOLVER.UNDEFINED_SET(o))}if(r==="modifiers"){const i=t.document.modifiers?.[o];return i?{content:i,sourcePath:"#",errors:[]}:T({contexts:{}},f.RESOLVER.UNDEFINED_MODIFIER(o))}return T({sources:[]},f.RESOLVER.INVALID_REFERENCE(e))}s(wt,"resolveSameDocumentRef");async function kt(e,t){const n=C(e)?e:O(t.basePath,e),r=t.fileCache.get(n);if(r)return Ae(r)?T({},f.RESOLVER.RESOLVER_AS_TOKEN_SOURCE(n),n):{content:r,sourcePath:n,errors:[]};const o=await De(n);return o.error?T({},o.error,n):Ae(o.content)?T({},f.RESOLVER.RESOLVER_AS_TOKEN_SOURCE(n),n):(t.fileCache.set(n,o.content),{content:o.content,sourcePath:n,errors:[]})}s(kt,"resolveFileRef");async function Mt(e,t){const[n="",r=""]=e.split("#"),o=C(n)?n:O(t.basePath,n);let i=t.fileCache.get(o);if(!i){const u=await De(o);if(u.error)return T({},u.error,o);i=u.content,t.fileCache.set(o,i)}const a=r.startsWith("/")?r:`/${r}`,c=jt(i,a);return c.error?T({},f.RESOLVER.INVALID_JSON_POINTER(a,c.error),o):{content:c.value,sourcePath:o,errors:[]}}s(Mt,"resolveFileFragmentRef");async function De(e){try{const t=await x(e,"utf-8");return{content:JSON.parse(t)}}catch(t){if(t.code==="ENOENT")return{error:f.RESOLVER.EXTERNAL_FILE_NOT_FOUND(e)};const n=t instanceof Error?t.message:"Unknown error";return{error:f.RESOLVER.EXTERNAL_FILE_ERROR(e,n)}}}s(De,"loadJsonFile");function jt(e,t){if(t===""||t==="/")return{value:e};const n=t.slice(1).split("/").map(o=>o.replace(/~1/g,"/").replace(/~0/g,"~"));let r=e;for(const o of n){if(r===null||typeof r!="object")return{error:"cannot navigate into non-object"};if(Array.isArray(r)){const a=Number.parseInt(o,10);if(Number.isNaN(a)||a<0||a>=r.length)return{error:`invalid array index "${o}"`};r=r[a];continue}const i=r;if(!(o in i))return{error:`property "${o}" not found`};r=i[o]}return{value:r}}s(jt,"resolveJsonPointer");async function Re(e,t){const n=[],r=[];for(const o of e){if(!D(o)){n.push(o);continue}const i=await Oe(o.$ref,t);r.push(...i.errors),i.errors.length===0&&n.push(Pt(i.content,o))}return{resolved:n,errors:r}}s(Re,"resolveSources");function Pt(e,t){const{$ref:n,...r}=t;return Object.keys(r).length===0?e:{...e,...r}}s(Pt,"applyExtending");function T(e,t,n="#"){return{content:e,sourcePath:n,errors:[{path:n,message:t}]}}s(T,"errorResult");function Le(e){return typeof e=="object"&&e!==null&&"$value"in e}s(Le,"isToken");function k(e,t){const n={...e};for(const[r,o]of Object.entries(t)){if(o===void 0)continue;if(r.startsWith("$")){n[r]=o;continue}if(Le(o)){n[r]=o;continue}const i=n[r],a=i!==void 0&&typeof i=="object"&&i!==null&&typeof o=="object"&&o!==null&&!Le(i);n[r]=a?k(i,o):o}return n}s(k,"deepMerge");function _e(e){const t=[],n=new Set;for(const r of e.resolutionOrder){const o=Ut(r,e,n);o&&(t.push(o),n.add(o.name))}return t}s(_e,"extractModifiers");function Ut(e,t,n){return D(e)&&e.$ref.startsWith("#/modifiers/")?Gt(e.$ref,t,n):L(e)?Bt(e,n):null}s(Ut,"extractModifierFromItem");function Gt(e,t,n){const r=e.split("/")[2];if(!r||n.has(r))return null;const o=t.modifiers?.[r];return o?{name:r,contexts:Object.keys(o.contexts),default:o.default}:null}s(Gt,"extractReferencedModifier");function Bt(e,t){return t.has(e.name)?null:{name:e.name,contexts:Object.keys(e.contexts),default:e.default}}s(Bt,"extractInlineModifier");function Wt(e,t={}){const n=[],r={},o=_e(e);if(o.length===0)return Yt(t,n),{valid:n.length===0,errors:n,resolvedInputs:r};const i=new Map(o.map(a=>[a.name,a]));return Ht(t,i,n,r),Kt(o,r,n),{valid:n.length===0,errors:n,resolvedInputs:r}}s(Wt,"validateInputs$1");function Yt(e,t){for(const n of Object.keys(e))t.push({modifier:n,message:f.RESOLVER.UNKNOWN_MODIFIER(n)})}s(Yt,"validateNoModifiersCase");function Ht(e,t,n,r){for(const[o,i]of Object.entries(e)){const a=t.get(o);if(!a){n.push({modifier:o,message:f.RESOLVER.UNKNOWN_MODIFIER(o)});continue}if(typeof i!="string"){n.push({modifier:o,message:f.RESOLVER.INVALID_INPUT_TYPE(o)});continue}if(!a.contexts.includes(i)){n.push({modifier:o,message:f.RESOLVER.INVALID_CONTEXT(i,o,a.contexts)});continue}r[o]=i}}s(Ht,"validateProvidedInputs");function Kt(e,t,n){for(const r of e)t[r.name]===void 0&&(r.default!==void 0?t[r.name]=r.default:n.push({modifier:r.name,message:f.RESOLVER.MISSING_REQUIRED_INPUT(r.name)}))}s(Kt,"applyDefaults");async function ve(e,t,n={}){const r=Wt(e,n);if(!r.valid)return{tokens:{},sources:[],errors:r.errors.map(a=>({path:a.modifier||"inputs",message:a.message}))};const o=be(e,t),i=qt();for(const a of e.resolutionOrder)await zt(a,e,o,r.resolvedInputs,i);return{tokens:i.tokens,sources:i.sources,errors:i.errors}}s(ve,"processResolutionOrder");function qt(){return{tokens:{},sources:[],errors:[]}}s(qt,"createProcessingState");async function zt(e,t,n,r,o){if(D(e)){await Jt(e,t,n,r,o);return}if(Te(e)){await Xt(e,n,o);return}L(e)&&await Zt(e,n,r,o)}s(zt,"processItem");async function Jt(e,t,n,r,o){const i=await Oe(e.$ref,n);if(i.errors.length>0){o.errors.push(...i.errors);return}const a=e.$ref.split("/")[2];if(a){if(e.$ref.startsWith("#/sets/")){const c=await M(i.content.sources,n,{type:"set",name:a});j(c,o);return}if(e.$ref.startsWith("#/modifiers/")){const c=r[a];if(!c)return;const p=i.content.contexts[c];if(!p)return;const m=await M(p,n,{type:"modifier",name:a,context:c});j(m,o)}}}s(Jt,"processReference");async function Xt(e,t,n){const r=await M(e.sources,t,{type:"set",name:e.name});j(r,n)}s(Xt,"processInlineSet");async function Zt(e,t,n,r){const o=n[e.name];if(!o)return;const i=e.contexts[o];if(!i)return;const a=await M(i,t,{type:"modifier",name:e.name,context:o});j(a,r)}s(Zt,"processInlineModifier");async function M(e,t,n){const r=await Re(e,t);let o={};for(const i of r.resolved)o=k(o,i);return{tokens:o,source:{path:"#",...n},errors:r.errors}}s(M,"mergeSources");function j(e,t){t.errors.push(...e.errors),t.tokens=k(t.tokens,e.tokens),t.sources.push(e.source)}s(j,"applyResult");async function Qt(e,t){const n=[],r=be(e,t),o=_e(e),i={};for(const p of o)p.default&&(i[p.name]=p.default);const a=await ve(e,t,i);n.push(...a.errors);const c=a.tokens,u=[];for(const p of o){const m=new Map,d=p.default??p.contexts[0]??"default";for(const I of p.contexts){if(I===d)continue;const y=await en(e,t,r,p.name,I,n);Object.keys(y).length>0&&m.set(I,y)}u.push({name:p.name,defaultContext:d,contexts:m})}return{base:c,modifiers:u,errors:n}}s(Qt,"processForLayeredCSS");async function en(e,t,n,r,o,i){const a=tn(e,r);if(!a)return{};const c=a.contexts[o];if(!c||c.length===0)return{};const u=await Re(c,n);i.push(...u.errors.map(y=>({path:y.path,message:y.message})));let p={};for(const y of u.resolved)p=k(p,y);const m=new Set;xe(p,"",m);const d=await ve(e,t,{[r]:o});i.push(...d.errors);const I={};for(const y of m){const $=nn(d.tokens,y);$!==void 0&&rn(I,y,$)}return I}s(en,"processModifierContext");function tn(e,t){if(e.modifiers?.[t])return e.modifiers[t];for(const n of e.resolutionOrder)if(L(n)&&n.name===t)return n}s(tn,"findModifierDefinition");function xe(e,t,n){for(const[r,o]of Object.entries(e)){if(r.startsWith("$"))continue;const i=t?`${t}.${r}`:r;o&&typeof o=="object"&&"$value"in o?n.add(i):o&&typeof o=="object"&&xe(o,i,n)}}s(xe,"collectTokenPaths");function nn(e,t){const n=t.split(".");let r=e;for(const o of n){if(r===null||typeof r!="object")return;r=r[o]}return r}s(nn,"getTokenAtPath");function rn(e,t,n){const r=t.split(".");let o=e;for(let a=0;a<r.length-1;a++){const c=r[a];c&&(c in o||(o[c]={}),o=o[c])}const i=r[r.length-1];i&&(o[i]=n)}s(rn,"setTokenAtPath");async function on(e){const t=C(e)?e:O(process.cwd(),e),n=J(t),r=[],o=[],i=pe(process.cwd(),t),a=await Dt(t);if(a.errors.length>0)return{trees:[],modifiers:[],errors:a.errors.map(p=>({file:p.path,message:p.message}))};const c=await Qt(a.document,n);for(const p of c.errors)r.push({file:p.path,message:p.message});Object.keys(c.base).length>0&&o.push({context:void 0,tokens:c.base,sourcePath:i});const u=[];for(const p of c.modifiers){const m=[];for(const[d,I]of p.contexts)Object.keys(I).length>0&&(o.push({context:`${p.name}:${d}`,tokens:I,sourcePath:i}),m.push(d));u.push({name:p.name,attribute:`data-${p.name}`,defaultContext:p.defaultContext,contexts:m})}return{trees:o,modifiers:u,errors:r}}s(on,"loadFromResolver");async function sn(e){const t=[],n=[],r=Object.entries(e);r.sort(([,o],[,i])=>{const a=!o.context,c=!i.context;return a&&!c?-1:!a&&c?1:0});for(const[o,{context:i,content:a}]of r)try{const c=JSON.parse(a);t.push({context:i,tokens:c,sourcePath:pe(process.cwd(),o)})}catch(c){c instanceof Error?c instanceof SyntaxError?n.push({file:o,message:f.LOAD.INVALID_JSON(o,c.message)}):n.push({file:o,message:c.message}):n.push({file:o,message:"Unknown error"})}return{trees:t,errors:n}}s(sn,"loadTreesFromMemory");function P(e,t,n,r){return typeof t=="string"&&h(t)?cn(e,t,n,r):Array.isArray(t)?t.map(o=>P(e,o,n,r)):typeof t=="object"&&t!==null?Object.entries(t).reduce((i,[a,c])=>Object.assign(i,{[a]:P(`${e}.${a}`,c,n,r)}),{}):t}s(P,"resolveValue");function Ce(e,t){const n=e.slice(1,-1),r=t.pathIndex.get(n);if(!r)return;const o=t.tokens[r];if(!(!o||!("$value"in o))){if(o.$type)return o.$type;if(typeof o.$value=="string"&&h(o.$value))return Ce(o.$value,t)}}s(Ce,"inferTypeFromReference");function an(e){const t={},n=new Set,r=[];for(const[o,i]of Object.entries(e.tokens))try{if(!("$value"in i)){t[o]=i;continue}const a=i;let c=a.$type;!c&&typeof a.$value=="string"&&h(a.$value)&&(c=Ce(a.$value,e)),t[o]={...a,...c?{$type:c}:{},$resolvedValue:P(a.$path,a.$value,e,n)}}catch(a){const c=a instanceof Error?a.message:String(a),u=i,p=u.$path,m=u.$source;let d,I;c.includes("Circular reference detected")?(d="circular",I=c):c.includes("Reference not found")?(d="missing",I=c):(d="type-mismatch",I=f.RESOLVE.TYPE_MISMATCH(p)),r.push({type:d,path:p,source:m,message:I})}return{resolved:t,errors:r}}s(an,"resolve");function cn(e,t,n,r){const o=t.slice(1,-1),i=n.pathIndex.get(o);if(!i)throw new Error(f.RESOLVE.REFERENCE_NOT_FOUND(o,e));if(r.has(i)){const u=n.tokens[i];throw!u||!("$path"in u)?new Error(f.RESOLVE.REFERENCE_NOT_FOUND(o,e)):new Error(f.RESOLVE.CIRCULAR_REFERENCE(e,u.$path))}const a=n.tokens[i];if(!a||!("$value"in a))throw new Error(f.RESOLVE.REFERENCE_NOT_FOUND(o,e));r.add(i);const c=P(i,a.$value,n,r);return r.delete(i),c}s(cn,"resolveReferenceChain");function S(e){return{success:!0,value:e}}s(S,"success");function g(e){return{success:!1,error:e}}s(g,"error");function ne(e){if(typeof e!="object"||e===null)return!1;const t=e;return!(typeof t.colorSpace!="string"||!["oklch","display-p3","srgb","hsl"].includes(t.colorSpace)||!Array.isArray(t.components)||t.components.length!==3||!t.components.every(r=>typeof r=="number"||r==="none")||t.alpha!==void 0&&typeof t.alpha!="number"||t.hex!==void 0&&typeof t.hex!="string")}s(ne,"isDTCGColorValue");function U(e){const t=[],n=["oklch","display-p3","srgb","hsl"];if(n.includes(e.colorSpace)||t.push(`Unsupported colorSpace: "${e.colorSpace}". Supported color spaces: ${n.join(", ")}.`),!Array.isArray(e.components)||e.components.length!==3)t.push("Components must be an array of exactly 3 numbers.");else if(e.components.forEach((r,o)=>{r!=="none"&&(typeof r!="number"||!Number.isFinite(r))&&t.push(`Component ${o} must be a finite number or "none".`)}),e.colorSpace==="oklch"){const[r,o,i]=e.components;r!=="none"&&(r<0||r>1)&&t.push("OKLCH Lightness (L) must be between 0 and 1 or 'none'."),o!=="none"&&o<0&&t.push("OKLCH Chroma (C) must be >= 0 or 'none'."),i!=="none"&&(i<0||i>=360)&&t.push("OKLCH Hue (H) must be between 0 and 360 (exclusive) or 'none'.")}else if(e.colorSpace==="display-p3"){const[r,o,i]=e.components;r!=="none"&&(r<0||r>1)&&t.push("Display P3 Red component must be between 0 and 1 or 'none'."),o!=="none"&&(o<0||o>1)&&t.push("Display P3 Green component must be between 0 and 1 or 'none'."),i!=="none"&&(i<0||i>1)&&t.push("Display P3 Blue component must be between 0 and 1 or 'none'.")}else if(e.colorSpace==="srgb"){const[r,o,i]=e.components;r!=="none"&&(r<0||r>1)&&t.push("sRGB Red component must be between 0 and 1 or 'none'."),o!=="none"&&(o<0||o>1)&&t.push("sRGB Green component must be between 0 and 1 or 'none'."),i!=="none"&&(i<0||i>1)&&t.push("sRGB Blue component must be between 0 and 1 or 'none'.")}else if(e.colorSpace==="hsl"){const[r,o,i]=e.components;r!=="none"&&(r<0||r>=360)&&t.push("HSL Hue must be between 0 and 360 (exclusive) or 'none'."),o!=="none"&&(o<0||o>100)&&t.push("HSL Saturation must be between 0 and 100 or 'none'."),i!=="none"&&(i<0||i>100)&&t.push("HSL Lightness must be between 0 and 100 or 'none'.")}return e.alpha!==void 0&&(typeof e.alpha!="number"||!Number.isFinite(e.alpha)?t.push("Alpha must be a finite number."):(e.alpha<0||e.alpha>1)&&t.push("Alpha must be between 0 and 1.")),t}s(U,"validateDTCGColorValue");function un(e){const t=U(e);return t.length>0?g(t.join(", ")):S(e)}s(un,"validateDTCGColorValueResult");function fn(e){const t=un(e);if(!t.success)return t;const[n,r,o]=e.components,i=e.alpha,a=n==="none"?"none":Number(n.toFixed(4)),c=r==="none"?"none":Number(r.toFixed(4)),u=o==="none"?"none":Number(o.toFixed(4));if(i!==void 0&&i!==1){const p=Number(i.toFixed(4));return S(`oklch(${a} ${c} ${u} / ${p})`)}return S(`oklch(${a} ${c} ${u})`)}s(fn,"formatDTCGColorToOKLCH");const ln={isObject:s(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObject")};function E(e,t,n,r){if(h(t))return[];switch(e.type){case"object":return dn(e,t,n,r);case"union":return mn(e,t,n,r);case"array":return hn(e,t,n,r);default:return pn(e,t,n,r)}}s(E,"validateSchema");function pn(e,t,n,r){return e.type!==typeof t?[{path:n,message:e.errorMessage?.(t,n)||f.VALIDATE.INVALID_TYPE(e.type,t,n),source:r}]:e.validate?.(t,n,r)??[]}s(pn,"validateSimpleValue");function dn(e,t,n,r){if(!ln.isObject(t))return[{path:n,message:e.errorMessage?.(t,n)||f.VALIDATE.INVALID_TYPE("object",t,n),source:r}];const o=[],i=t;if(e.required)for(const a of e.required)a in i||o.push({path:`${n}.${a}`,message:f.VALIDATE.MISSING_REQUIRED_PROPERTY(a,n),source:r});for(const[a,c]of Object.entries(e.properties))a in i&&o.push(...E(c,i[a],`${n}.${a}`,r));return o}s(dn,"validateObject");function mn(e,t,n,r){let o=[],i=Number.POSITIVE_INFINITY;for(const a of e.oneOf){if(a.type==="string"&&typeof t!="string"||a.type==="object"&&typeof t!="object")continue;const c=E(a,t,n,r);if(c.length===0)return a.validate?.(t,n,r)??[];c.length<i&&(o=c,i=c.length)}return i===Number.POSITIVE_INFINITY?[{path:n,message:f.VALIDATE.INVALID_TYPE(e.oneOf.map(a=>a.type).join(" or "),t,n),source:r}]:o}s(mn,"validateUnion");function hn(e,t,n,r){return Array.isArray(t)?e.validate?.(t,n,r)??[]:[{path:n,message:e.errorMessage?.(t,n)||f.VALIDATE.INVALID_TYPE("array",t,n),source:r}]}s(hn,"validateArray");const G={schema:{type:"union",oneOf:[{type:"string",validate:s((e,t,n)=>/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(e)?[]:[{path:t,message:f.VALIDATE.INVALID_COLOR(e,t),source:n}],"validate")},{type:"object",required:["colorSpace","components"],properties:{colorSpace:{type:"string"},components:{type:"array"},alpha:{type:"number"},hex:{type:"string"}},validate:s((e,t,n)=>ne(e)?U(e).map(o=>({path:t,message:`Invalid color at ${t}: ${o}`,source:n})):[{path:t,message:f.VALIDATE.INVALID_COLOR(e,t),source:n}],"validate")}]}};function In(e,t,n){return E(G.schema,e,t,n)}s(In,"validateColor");const B={schema:{type:"number",errorMessage:s((e,t)=>f.VALIDATE.INVALID_NUMBER(e,t),"errorMessage"),validate:s((e,t,n)=>typeof e!="number"||Number.isNaN(e)?[{path:t,message:f.VALIDATE.INVALID_NUMBER(e,t),source:n}]:[],"validate")}};function yn(e,t,n){return E(B.schema,e,t,n)}s(yn,"validateNumber");const N={schema:{type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_DIMENSION(e,t),"errorMessage"),properties:{value:B.schema,unit:{type:"string",validate:s((e,t,n)=>typeof e!="string"||!["px","rem"].includes(e)?[{path:t,message:f.VALIDATE.INVALID_DIMENSION_UNIT(e,t),source:n}]:[],"validate")}},required:["value","unit"]}};function En(e,t,n){return E(N.schema,e,t,n)}s(En,"validateDimension");const $n=["solid","dashed","dotted","double","groove","ridge","outset","inset"],gn=["round","butt","square"],Nn={type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_STROKE_STYLE(e,t),"errorMessage"),properties:{dashArray:{type:"array",validate:s((e,t,n)=>{const r=e,o=[];return r.forEach((i,a)=>{typeof i!="string"&&o.push(...E(N.schema,i,`${t}.${a}`,n))}),o},"validate")},lineCap:{type:"string",validate:s((e,t,n)=>gn.includes(e)?[]:[{path:t,message:f.VALIDATE.INVALID_STROKE_LINE_CAP(e,t),source:n}],"validate")}},required:["dashArray","lineCap"]},Fe={schema:{type:"union",oneOf:[{type:"string",validate:s((e,t,n)=>!$n.includes(e)&&typeof e=="string"?[{path:t,message:f.VALIDATE.INVALID_STROKE_STYLE(e,t),source:n}]:[],"validate")},Nn]}};function Tn(e,t,n){return E(Fe.schema,e,t,n)}s(Tn,"validateStrokeStyle");const Sn={schema:{type:"object",properties:{color:G.schema,width:N.schema,style:Fe.schema},required:["color","width","style"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_BORDER(e,t),"errorMessage")}};function An(e,t,n){return E(Sn.schema,e,t,n)}s(An,"validateBorder");const Ve={schema:{type:"array",errorMessage:s((e,t)=>f.VALIDATE.INVALID_CUBIC_BEZIER(e,t),"errorMessage"),validate:s((e,t,n)=>{const r=e;if(r.length!==4||!r.every(a=>typeof a=="number"))return[{path:t,message:f.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}];const[o,,i]=r;return o<0||o>1||i<0||i>1?[{path:t,message:f.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}]:[]},"validate")}};function bn(e,t,n){return E(Ve.schema,e,t,n)}s(bn,"validateCubicBezier");const On=["ms","s"],re={schema:{type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_DURATION(e,t),"errorMessage"),properties:{value:B.schema,unit:{type:"string",validate:s((e,t,n)=>On.includes(e)?[]:[{path:t,message:f.VALIDATE.INVALID_DURATION_UNIT(e,t),source:n}],"validate")}},required:["value","unit"]}};function Dn(e,t,n){return E(re.schema,e,t,n)}s(Dn,"validateDuration");const Rn={schema:{type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FLUID_DIMENSION(e,t),"errorMessage"),properties:{min:N.schema,max:N.schema},required:["min","max"]}};function Ln(e,t,n){return E(Rn.schema,e,t,n)}s(Ln,"validateFluidDimension");const we={schema:{type:"union",oneOf:[{type:"string",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")},{type:"array",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage"),validate:s((e,t,n)=>e.every(o=>typeof o=="string")?[]:[{path:t,message:f.VALIDATE.INVALID_FONT_FAMILY(e,t),source:n}],"validate")}],errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")}};function _n(e,t,n){return E(we.schema,e,t,n)}s(_n,"validateFontFamily");const vn=["thin","hairline","extra-light","ultra-light","light","normal","regular","book","medium","semi-bold","demi-bold","bold","extra-bold","ultra-bold","black","heavy","extra-black","ultra-black"],ke={schema:{type:"union",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),oneOf:[{type:"number",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:s((e,t,n)=>e<1||e>1e3?[{path:t,message:f.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}]:[],"validate")},{type:"string",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:s((e,t,n)=>vn.includes(e.toLowerCase())?[]:[{path:t,message:f.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}],"validate")}]}};function xn(e,t,n){return E(ke.schema,e,t,n)}s(xn,"validateFontWeight");const Cn={type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_GRADIENT(e,t),"errorMessage"),properties:{color:G.schema,position:{type:"number",validate:s((e,t,n)=>e<0||e>1?[{path:t,message:f.VALIDATE.INVALID_GRADIENT_STOP_POSITION(e,t),source:n}]:[],"validate")}},required:["color","position"]},Fn={schema:{type:"array",errorMessage:s((e,t)=>f.VALIDATE.INVALID_ARRAY(e,t),"errorMessage"),validate:s((e,t,n)=>{const r=e,o=[];return r.forEach((i,a)=>{o.push(...E(Cn,i,`${t}[${a}]`,n))}),o},"validate")}};function Vn(e,t,n){return E(Fn.schema,e,t,n)}s(Vn,"validateGradient");const Me={schema:{type:"object",properties:{color:{type:"union",oneOf:[G.schema]},offsetX:N.schema,offsetY:N.schema,blur:N.schema,spread:N.schema,inset:{type:"boolean",errorMessage:s((e,t)=>f.VALIDATE.INVALID_SHADOW_INSET(e,t),"errorMessage")}},required:["color","offsetX","offsetY","blur","spread"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_SHADOW(e,t),"errorMessage")}};function wn(e,t,n){const r=[];return Array.isArray(e)?(e.forEach((o,i)=>{r.push(...E(Me.schema,o,`${t}[${i}]`,n))}),r):E(Me.schema,e,t,n)}s(wn,"validateShadow");const kn={schema:{type:"object",properties:{duration:re.schema,delay:re.schema,timingFunction:Ve.schema},required:["duration","delay","timingFunction"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_TRANSITION(e,t),"errorMessage")}};function Mn(e,t,n){return E(kn.schema,e,t,n)}s(Mn,"validateTransition");const jn={schema:{type:"object",properties:{fontFamily:we.schema,fontSize:N.schema,letterSpacing:N.schema,lineHeight:B.schema,fontWeight:ke.schema},required:["fontFamily","fontSize"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_TYPOGRAPHY(e,t),"errorMessage")}};function Pn(e,t,n){return E(jn.schema,e,t,n)}s(Pn,"validateTypography");const Un={color:In,dimension:En,fluidDimension:Ln,duration:Dn,cubicBezier:bn,fontFamily:_n,fontWeight:xn,number:yn,strokeStyle:Tn,typography:Pn,border:An,shadow:wn,gradient:Vn,transition:Mn};function Gn(e){const t=[];for(const[n,r]of Object.entries(e.tokens)){if(typeof r!="object"||r===null||!("$type"in r)||!("$path"in r)||r.$path.startsWith("$"))continue;if(!("$value"in r)){t.push({path:r.$path,message:f.VALIDATE.MISSING_REQUIRED_PROPERTY("$value",r.$path),source:r.$source});continue}const o=Un[r.$type];if(!o){t.push({path:r.$path,message:f.VALIDATE.UNKNOWN_TOKEN_TYPE(r.$type,r.$path),source:r.$source});continue}const i=r;t.push(...o(i.$value,i.$path,i.$source))}return t}s(Gn,"validate");async function Bn(e){const{trees:t,modifiers:n,errors:r}=await Wn(e),{tokens:o,errors:i}=Et(t),a=Gn(o),{resolved:c,errors:u}=an(o);return{trees:t,resolved:c,modifiers:n,errors:{load:r,flatten:i,validation:a,resolution:u}}}s(Bn,"loadAndResolveTokens");async function Wn(e){switch(e.type){case"memory":{const t=await sn(e.data);return{trees:t.trees,modifiers:[],errors:t.errors}}case"resolver":{const t=await on(e.resolverPath);return{trees:t.trees,modifiers:t.modifiers,errors:t.errors}}}}s(Wn,"loadTokens");function je(e){return h(e)?{value:e}:typeof e=="string"?{value:e}:{value:`${e.dashArray.map(n=>h(n)?n:`${n.value}${n.unit}`).join(" ")} ${e.lineCap}`}}s(je,"convertStrokeStyleToken");function Yn(e){if(h(e))return{value:e};const t=h(e.width)?e.width:`${e.width.value}${e.width.unit}`,n=(h(e.color),e.color),r=typeof e.style=="string"?e.style:je(e.style).value;return{value:`${t} ${r} ${n}`}}s(Yn,"convertBorderToken");function Pe(e,t="native"){return ne(e)?Hn(e):S(e)}s(Pe,"convertColorToString");function Hn(e){switch(e.colorSpace){case"oklch":return fn(e);case"display-p3":return Kn(e);case"srgb":return qn(e);case"hsl":return zn(e);default:return g(`Unsupported color space: ${e.colorSpace}. Supported color spaces: oklch, display-p3, srgb, hsl.`)}}s(Hn,"formatDTCGColorNative");function Kn(e){if(e.colorSpace!=="display-p3")return g(`Expected display-p3 color space, got: ${e.colorSpace}`);if(!Array.isArray(e.components)||e.components.length!==3)return g("Display P3 components must be an array of exactly 3 numbers [R, G, B]");const[t,n,r]=e.components,o=e.alpha;if(t!=="none"&&(t<0||t>1))return g("Display P3 Red component must be between 0 and 1 or 'none'");if(n!=="none"&&(n<0||n>1))return g("Display P3 Green component must be between 0 and 1 or 'none'");if(r!=="none"&&(r<0||r>1))return g("Display P3 Blue component must be between 0 and 1 or 'none'");if(o!==void 0&&(o<0||o>1))return g("Alpha must be between 0 and 1");const i=t==="none"?"none":Number(t.toFixed(4)),a=n==="none"?"none":Number(n.toFixed(4)),c=r==="none"?"none":Number(r.toFixed(4));if(o!==void 0&&o!==1){const u=Number(o.toFixed(4));return S(`color(display-p3 ${i} ${a} ${c} / ${u})`)}return S(`color(display-p3 ${i} ${a} ${c})`)}s(Kn,"formatDTCGColorToP3");function qn(e){if(e.colorSpace!=="srgb")return g(`Expected srgb color space, got: ${e.colorSpace}`);const t=U(e);if(t.length>0)return g(`Invalid DTCG color value: ${t.join(", ")}`);const[n,r,o]=e.components,i=e.alpha,a=n==="none"?"none":Math.round(n*255),c=r==="none"?"none":Math.round(r*255),u=o==="none"?"none":Math.round(o*255);if(i!==void 0&&i!==1){const p=Number(i.toFixed(4));return S(`rgb(${a} ${c} ${u} / ${p})`)}return S(`rgb(${a} ${c} ${u})`)}s(qn,"formatDTCGColorToRGB");function zn(e){if(e.colorSpace!=="hsl")return g(`Expected hsl color space, got: ${e.colorSpace}`);const t=U(e);if(t.length>0)return g(`Invalid DTCG color value: ${t.join(", ")}`);const[n,r,o]=e.components,i=e.alpha,a=n==="none"?"none":Number(n.toFixed(1)),c=r==="none"?"none":Math.round(r),u=o==="none"?"none":Math.round(o);if(i!==void 0&&i!==1){const d=Number(i.toFixed(4)),I=c==="none"?"none":`${c}%`,y=u==="none"?"none":`${u}%`;return S(`hsl(${a} ${I} ${y} / ${d})`)}const p=c==="none"?"none":`${c}%`,m=u==="none"?"none":`${u}%`;return S(`hsl(${a} ${p} ${m})`)}s(zn,"formatDTCGColorToHSL");function Jn(e,t){if(typeof e=="string"&&h(e))return{value:e};const n=t.colorFallbackStrategy;if(ne(e))return Xn(e,n);const r=Pe(e,n);return r.success?{value:r.value}:(console.warn(`[sugarcube] Failed to convert color ${typeof e=="string"?e:"DTCG color object"}: ${r.error}`),{value:typeof e=="string"?e:"#000000"})}s(Jn,"convertColorToken");function Xn(e,t){const n=Pe(e,t);if(!n.success)return console.warn(`[sugarcube] Failed to convert DTCG color: ${n.error}`),{value:"#000000"};const r=n.value;if(t==="native")return{value:r};if(e.colorSpace==="srgb"||e.colorSpace==="hsl")return{value:r};if(!e.hex)throw new Error(`${e.colorSpace} colors require a 'hex' fallback when using 'polyfill' strategy. Tip: Switch to 'native' strategy if targeting modern browsers only.`);return{value:e.hex,featureValues:[{query:Zn(e.colorSpace),value:r}]}}s(Xn,"convertDTCGColorToken");function Zn(e){switch(e){case"oklch":return"@supports (color: oklch(0 0 0))";case"display-p3":return"@supports (color: color(display-p3 1 1 1))";default:throw new Error(`No feature query defined for color space: ${e}`)}}s(Zn,"getFeatureQuery");function Qn(e){return h(e)?{value:e}:{value:`cubic-bezier(${e.join(", ")})`}}s(Qn,"convertCubicBezierToken");function er(e){return h(e)?{value:e}:{value:`${e.value}${e.unit}`}}s(er,"convertDimensionToken");function tr(e){return h(e)?{value:e}:{value:`${e.value}${e.unit}`}}s(tr,"convertDurationToken");function Ue(e,t=16){return e.unit==="px"?e.value:e.value*t}s(Ue,"normalizeToPixels");function nr(e,t){const{min:n,max:r}=e,o=t.fluidConfig,i=16,a=Ue(n,i),c=Ue(r,i),u=o.min,p=o.max;if(a===c)return{value:`${a/i}rem`};const m=a/i,d=c/i,I=u/i,y=p/i,$=(d-m)/(y-I),ce=-1*I*$+m;return{value:`clamp(${m}rem, ${ce.toFixed(2)}rem + ${($*100).toFixed(2)}vw, ${d}rem)`}}s(nr,"convertFluidDimension");function rr(e,t){return h(e)?{value:e}:nr(e,t)}s(rr,"convertFluidDimensionToken");function W(e){return["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","emoji","math","fangsong"].includes(e.toLowerCase())?e:/[\s'"!@#$%^&*()=+[\]{};:|\\/,.<>?~]/.test(e)?`"${e}"`:e}s(W,"quoteFont");function or(e){return h(e)?{value:e}:{value:Array.isArray(e)?e.map(n=>W(n)).join(", "):W(e)}}s(or,"convertFontFamilyToken");const sr={thin:100,hairline:100,"extra-light":200,"ultra-light":200,light:300,normal:400,regular:400,book:400,medium:500,"semi-bold":600,"demi-bold":600,bold:700,"extra-bold":800,"ultra-bold":800,black:900,heavy:900,"extra-black":950,"ultra-black":950};function Ge(e){return h(e)?{value:e}:typeof e=="number"?{value:e}:{value:sr[e.toLowerCase()]??e}}s(Ge,"convertFontWeightToken");function ir(e){return h(e)?{value:e}:{value:`linear-gradient(${e.map(n=>{const r=(h(n.color),n.color),o=h(n.position)?n.position:`${n.position*100}`;return`${r} ${o}%`}).join(", ")})`}}s(ir,"convertGradientToken");function ar(e){return h(e)?{value:e}:{value:e}}s(ar,"convertNumberToken");function Be(e){const t=h(e.offsetX)?e.offsetX:`${e.offsetX.value}${e.offsetX.unit}`,n=h(e.offsetY)?e.offsetY:`${e.offsetY.value}${e.offsetY.unit}`,r=h(e.blur)?e.blur:`${e.blur.value}${e.blur.unit}`,o=h(e.spread)?e.spread:`${e.spread.value}${e.spread.unit}`,i=(h(e.color),e.color);return`${e.inset?"inset ":""}${t} ${n} ${r} ${o} ${i}`}s(Be,"convertSingleShadow");function cr(e){return h(e)?{value:e}:Array.isArray(e)?{value:e.map(Be).join(", ")}:{value:Be(e)}}s(cr,"convertShadowToken");function We(e){return e?`${e.value}${e.unit}`:"0ms"}s(We,"formatDuration");function ur(e){if(h(e))return{value:e};const t=h(e.duration)?e.duration:We(e.duration),n=h(e.timingFunction)?e.timingFunction:`cubic-bezier(${e.timingFunction.join(", ")})`,r=e.delay&&(h(e.delay)?e.delay:We(e.delay));return{value:[t,n,r].filter(Boolean).join(" ")}}s(ur,"convertTransitionToken");function fr(e){if(h(e))return{"font-family":e,"font-size":e};const t={"font-family":h(e.fontFamily)?e.fontFamily:Array.isArray(e.fontFamily)?e.fontFamily.map(n=>W(n)).join(", "):W(e.fontFamily),"font-size":h(e.fontSize)?e.fontSize:`${e.fontSize.value}${e.fontSize.unit}`};return e.fontWeight&&(t["font-weight"]=h(e.fontWeight)?e.fontWeight:Ge(e.fontWeight).value),e.letterSpacing&&(t["letter-spacing"]=h(e.letterSpacing)?e.letterSpacing:`${e.letterSpacing.value}${e.letterSpacing.unit}`),e.lineHeight&&(t["line-height"]=(h(e.lineHeight),e.lineHeight)),t}s(fr,"convertTypographyToken");const Ye={duration:tr,number:ar,cubicBezier:Qn,color:Jn,dimension:er,fluidDimension:rr,typography:fr,border:Yn,shadow:cr,gradient:ir,transition:ur,strokeStyle:je,fontFamily:or,fontWeight:Ge};function lr(e,t){const n=Ye[e.$type];return{...e.$description?{$description:e.$description}:{},...e.$extensions?{$extensions:e.$extensions}:{},$type:e.$type,$value:e.$value,$path:e.$path,$source:e.$source,$originalPath:e.$originalPath,$resolvedValue:e.$resolvedValue,$cssProperties:n(e.$value,t)}}s(lr,"convertSingleToken");function pr(e,t,n){const r={};for(const[o,i]of Object.entries(e)){if(!i||typeof i!="object")continue;if(!("$type"in i)){r[o]={...i.$description?{$description:i.$description}:{},...i.$extensions?{$extensions:i.$extensions}:{}};continue}if(n?.(i.$path)||!Ye[i.$type])continue;const a={fluidConfig:t.transforms.fluid,colorFallbackStrategy:t.transforms.colorFallbackStrategy,path:i.$path,resolvedTokens:e};r[o]=lr(i,a)}return r}s(pr,"convertTokens");function dr(e,t,n){const r={};for(const[o,i]of Object.entries(e))r[o]=pr(i,t,n);return r}s(dr,"convert");function mr(e,t){const n={},r=new Set;for(const o of e){const i=o.context??"default";r.add(i)}for(const o of r)n[o]={};for(const o of e){const{context:i,tokens:a}=o,c=i??"default";n[c]||(n[c]={});for(const[u,p]of Object.entries(a))n[c][u]=p}return{tokens:n,defaultContext:t}}s(mr,"normalizeTokens");function hr(e,t){const n=new Map;for(const[r,o]of Object.entries(t)){if(!("$source"in o)){for(const c of e){const u=c.context??"";n.has(u)||n.set(u,{});const p=n.get(u);p&&(p[r]=o)}continue}const i=o.$source.context??"";n.has(i)||n.set(i,{});const a=n.get(i);a&&(a[r]=o)}return e.map(r=>{const o=r.context??"",i=n.get(o)||{};return{context:r.context,tokens:i}})}s(hr,"processTrees");async function Ir(e,t,n,r){const o=hr(e,t),{tokens:i}=mr(o);return dr(i,n,r?u=>r.some(p=>p.path===u||p.path.startsWith(`${u}.`)):void 0)}s(Ir,"processAndConvertTokens");function yr(e){return Object.entries(e).sort(([t],[n])=>t.localeCompare(n))}s(yr,"deterministicEntries");const He=new Map;function Er(e){const t=He.get(e);if(t)return t;const n=e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase();return He.set(e,n),n}s(Er,"toKebabCase");function oe(e){return e.split(".").join("-")}s(oe,"formatCSSVarPath");function se(e){return typeof e=="number"?e:typeof e!="string"?(console.warn("[sugarcube] Unexpected value type in convertReferenceToCSSVar:",e),String(e)):e.replace(/\{([^}]+)\}/g,(t,n)=>`var(--${n.split(".").map(Er).join("-")})`)}s(se,"convertReferenceToCSSVar");function $r(e){const t=e.$cssProperties;if("value"in t)return{name:`--${oe(e.$path)}`,value:se(t.value)}}s($r,"generateSingleVariable");function gr(e){return Object.entries(e.$cssProperties).filter(([t,n])=>n!==void 0).map(([t,n])=>({name:`--${oe(e.$path)}-${t}`,value:se(n)}))}s(gr,"generateTypographyVariables");function Ke(e){if(e.$type!=="color")return[];const t=e.$cssProperties;if(!("featureValues"in t))return[];const n=new Map;for(const r of t.featureValues||[]){n.has(r.query)||n.set(r.query,[]);const o=n.get(r.query);o&&o.push({name:`--${oe(e.$path)}`,value:se(r.value)})}return Array.from(n.entries()).map(([r,o])=>({query:r,vars:o}))}s(Ke,"generateFeatureVariables");function qe(e){const t=[`${e.selector} {`];if(e.comment&&t.push(` /* ${e.comment} */`),e.vars.length>0){const n=e.vars.map(r=>` ${r.name}: ${r.value};`).join(`
6
6
  `);t.push(n)}return t.push("}"),t.join(`
7
7
  `)}s(qe,"generateCSSBlock");function Nr(e){const t=[];e.root.vars.length>0&&t.push(qe({selector:e.root.selector,vars:e.root.vars}));for(const n of e.features){const o=qe({selector:e.root.selector,vars:n.vars}).split(`
8
8
  `).map(i=>` ${i}`).join(`
@@ -14,7 +14,7 @@ ${o}
14
14
  `)?e:`${e}
15
15
  `}s(br,"formatCSSVars");async function Or(e,t,n){const o=`${t.output?.css||"src/styles"}/${nt}`,i=[],a=Object.entries(e).sort(([c],[u])=>!c||c==="default"?-1:!u||u==="default"?1:c.localeCompare(u));for(const[c,u]of a){const p=await Ar(u,t,{context:c,modifiers:n});p.output[0].css.trim()&&i.push(p.output[0].css)}return i.length===0?[]:[{path:`${o}/${ot}${rt}`,css:`${i.filter(Boolean).join(`
16
16
  `).trim()}
17
- `}]}s(Or,"generateSingleFile");async function Dr(e,t,n){const r={};for(const[o,i]of Object.entries(e))Object.keys(i).length>0&&(r[o]=i);return{output:await Or(r,t,n)}}s(Dr,"generate");async function Rr(e,t,n){const{output:r}=await Dr(e,t,n);return r}s(Rr,"generateCSSVariables");const _="--",b="-",Lr=["all","full"],_r={top:"t",right:"r",bottom:"b",left:"l",x:"x",y:"y",full:"",all:""},vr={top:"block-start",right:"inline-end",bottom:"block-end",left:"inline-start",x:"inline",y:"block"};function xr(e){return _r[e]}s(xr,"getDirectionAbbreviation");function ze(e,t){if(t==="full"||t==="all")return e;const n=vr[t];return n?`${e}${b}${n}`:e}s(ze,"getLogicalProperty");const Cr=["top","right","bottom","left","x","y","full"];function Fr(e){return(Array.isArray(e)?e:[e]).flatMap(n=>n==="all"?Cr:[n])}s(Fr,"expandDirections");function Vr(e,t){const r={color:["color"],"background-color":["color"],"border-color":["color"],"font-size":["dimension","fluidDimension"],"font-weight":["fontWeight"],"line-height":["number"],"border-radius":["dimension","fluidDimension"],"border-width":["dimension","fluidDimension"],padding:["dimension","fluidDimension"],margin:["dimension","fluidDimension"],width:["dimension","fluidDimension"],height:["dimension","fluidDimension"],gap:["dimension","fluidDimension"],"font-family":["fontFamily"],"transition-duration":["duration"],"transition-timing-function":["cubicBezier"],"border-style":["strokeStyle"],"box-shadow":["shadow"],"text-shadow":["shadow"],"background-image":["gradient"],opacity:["number"]}[t];return r?r.includes(e):!0}s(Vr,"isTokenTypeValidForProperty");const Je=new WeakMap,R=new Map;function wr(){R.clear()}s(wr,"clearMatchCache");function kr(e){const t=Je.get(e);if(t)return t;const n=new Map;for(const r of Object.values(e)){if(!("$path"in r))continue;const o=r;n.set(o.$path,o)}return Je.set(e,n),n}s(kr,"buildPathIndex");function Mr(e){if(e.default)return e.default;const t=Object.keys(e);return t.length>0&&t[0]?e[t[0]]:null}s(Mr,"getDefaultContextTokens");function Y(e,t,n){const r=`${t.source}:${t.prefix??""}:${t.property??""}:${e}`;if(R.has(r))return R.get(r)??null;const o=[t.source.replace("*",e),t.source.replace("*",e.split("-").join("."))];if(t.stripDuplicates&&t.prefix){const c=t.source.lastIndexOf(".*");if(c!==-1){const u=t.source.slice(0,c);u&&o.push(`${u}.${t.prefix}.${e}`,`${u}.${t.prefix}.${e.split("-").join(".")}`)}}const i=Mr(n);if(!i)return R.set(r,null),null;const a=kr(i);for(const c of o){const u=a.get(c);if(u){if(t.property&&u.$type&&!Vr(u.$type,t.property))continue;const p=u.$path.split(".");return R.set(r,p),p}}return R.set(r,null),null}s(Y,"findMatchingToken");function ie(e,t){return t.stripDuplicates&&t.prefix&&e.startsWith(`${t.prefix}-`)?e.slice(t.prefix.length+1):e}s(ie,"stripDuplicatePrefix");function H(e,t=""){const n=e??"",r=n||t?b:"";return new RegExp(`^${n}${t}${r}(.+)$`)}s(H,"createUtilityPattern");function ae(e,t,n){return[H(t.prefix),o=>{const i=o[1];if(!i)return{};const a=ie(i,t),c={...t,property:e},u=Y(a,c,n);return u?{[e]:`var(${_}${u.join(b)})`}:{}}]}s(ae,"createSimpleRule");function jr(e,t,n,r){if(n==="all")return ae(e,t,r);const o=xr(n);return[H(t.prefix,o),a=>{const c=a[1];if(!c)return{};const u=ie(c,t),p={...t,property:e},m=Y(u,p,r);return m?{[ze(e,n)]:`var(${_}${m.join(b)})`}:{}}]}s(jr,"createDirectionalRule");function Pr(e,t){return[H(e),r=>{const o=r[1];if(!o)return{};for(const{property:i,config:a,direction:c,tokens:u}of t){const p=ie(o,a),m={...a,property:i},d=Y(p,m,u);if(d)return c?{[ze(i,c)]:`var(${_}${d.join(b)})`}:{[i]:`var(${_}${d.join(b)})`}}return{}}]}s(Pr,"createSmartRule");function Ur(e,t,n){const r=t.source.indexOf("."),o=r!==-1?t.source.slice(0,r):t.source;return[H(o),a=>{const c=a[1];if(!c)return{};const u={...t,property:e},p=Y(c,u,n);return p?{[e]:`var(${_}${p.join(b)})`}:{}}]}s(Ur,"createDirectTokenPathRule");function Gr(e,t){if(!e?.source||typeof e.source!="string")throw new Error(f.UTILITIES.MISSING_SOURCE(t));if(e.source.includes("*")&&!e.source.endsWith(".*"))throw new Error(f.UTILITIES.INVALID_SOURCE_PATTERN(t,e.source));if(e.directions&&!Array.isArray(e.directions))throw new Error(f.UTILITIES.INVALID_DIRECTIONS(t))}s(Gr,"validateUtilityConfig");function Br(e,t){if(!e||typeof e!="object")throw new Error(f.UTILITIES.INVALID_CONFIG_OBJECT);if(!t||typeof t!="object")throw new Error(f.UTILITIES.INVALID_TOKENS_OBJECT)}s(Br,"validateInputs");function Wr(e,t){Br(e,t);const n=[],r={};for(const[o,i]of Object.entries(e)){const a=Array.isArray(i)?i:[i];for(const c of a)if(Gr(c,o),c.prefix){const u=c.prefix;r[u]||(r[u]=[]),r[u].push({property:o,config:c,direction:null,tokens:t})}else{const u=Ur(o,c,t);n.push(u)}}for(const[o,i]of Object.entries(r))if(i.length===1){const a=i[0];if(!a)continue;const{property:c,config:u,tokens:p}=a;if(u.directions){const m=Fr(u.directions);(Array.isArray(u.directions)?u.directions:[u.directions]).includes("all")&&n.push(ae(c,u,p));for(const y of m)Lr.includes(y)||n.push(jr(c,u,y,p))}else n.push(ae(c,u,p))}else n.push(Pr(o,i));return n}s(Wr,"convertConfigToUnoRules");const v=process.env.SUGARCUBE_PERF==="1";class Yr{static{s(this,"PerfMonitor")}constructor(t=n=>void process.stderr.write(`${n}
17
+ `}]}s(Or,"generateSingleFile");async function Dr(e,t,n){const r={};for(const[o,i]of Object.entries(e))Object.keys(i).length>0&&(r[o]=i);return{output:await Or(r,t,n)}}s(Dr,"generate");async function Rr(e,t,n){const{output:r}=await Dr(e,t,n);return r}s(Rr,"generateCSSVariables");const _="--",b="-",Lr=["all","full"],_r={top:"t",right:"r",bottom:"b",left:"l",x:"x",y:"y",full:"",all:""},vr={top:"block-start",right:"inline-end",bottom:"block-end",left:"inline-start",x:"inline",y:"block"};function xr(e){return _r[e]}s(xr,"getDirectionAbbreviation");function ze(e,t){if(t==="full"||t==="all")return e;const n=vr[t];return n?`${e}${b}${n}`:e}s(ze,"getLogicalProperty");const Cr=["top","right","bottom","left","x","y","full"];function Fr(e){return(Array.isArray(e)?e:[e]).flatMap(n=>n==="all"?Cr:[n])}s(Fr,"expandDirections");function Vr(e,t){const r={color:["color"],"background-color":["color"],"border-color":["color"],"font-size":["dimension","fluidDimension"],"font-weight":["fontWeight"],"line-height":["number"],"border-radius":["dimension","fluidDimension"],"border-width":["dimension","fluidDimension"],padding:["dimension","fluidDimension"],margin:["dimension","fluidDimension"],width:["dimension","fluidDimension"],height:["dimension","fluidDimension"],gap:["dimension","fluidDimension"],"font-family":["fontFamily"],"transition-duration":["duration"],"transition-timing-function":["cubicBezier"],"border-style":["strokeStyle"],"box-shadow":["shadow"],"text-shadow":["shadow"],"background-image":["gradient"],opacity:["number"]}[t];return r?r.includes(e):!0}s(Vr,"isTokenTypeValidForProperty");const Je=new WeakMap,R=new Map;function wr(){R.clear()}s(wr,"clearMatchCache");function kr(e){const t=Je.get(e);if(t)return t;const n=new Map;for(const r of Object.values(e)){if(!("$path"in r))continue;const o=r;n.set(o.$path,o)}return Je.set(e,n),n}s(kr,"buildPathIndex");function Mr(e){if(e.default)return e.default;const t=Object.keys(e);return t.length>0&&t[0]?e[t[0]]:null}s(Mr,"getDefaultContextTokens");function Y(e,t,n){const r=`${t.source}:${t.prefix??""}:${t.property??""}:${e}`;if(R.has(r))return R.get(r)??null;const o=[t.source.replace("*",e),t.source.replace("*",e.split("-").join("."))];if(t.stripDuplicates&&t.prefix){const c=t.source.lastIndexOf(".*");if(c!==-1){const u=t.source.slice(0,c);u&&o.push(`${u}.${t.prefix}.${e}`,`${u}.${t.prefix}.${e.split("-").join(".")}`)}}const i=Mr(n);if(!i)return R.set(r,null),null;const a=kr(i);for(const c of o){const u=a.get(c);if(u){if(t.property&&u.$type&&!Vr(u.$type,t.property))continue;const p=u.$path.split(".");return R.set(r,p),p}}return R.set(r,null),null}s(Y,"findMatchingToken");function ie(e,t){return t.stripDuplicates&&t.prefix&&e.startsWith(`${t.prefix}-`)?e.slice(t.prefix.length+1):e}s(ie,"stripDuplicatePrefix");function H(e,t=""){const n=e??"",r=n||t?b:"";return new RegExp(`^${n}${t}${r}(.+)$`)}s(H,"createUtilityPattern");function ae(e,t,n){return[H(t.prefix),o=>{const i=o[1];if(!i)return{};const a=ie(i,t),c={...t,property:e},u=Y(a,c,n);return u?{[e]:`var(${_}${u.join(b)})`}:{}}]}s(ae,"createSimpleRule");function jr(e,t,n,r){if(n==="all")return ae(e,t,r);const o=xr(n);return[H(t.prefix,o),a=>{const c=a[1];if(!c)return{};const u=ie(c,t),p={...t,property:e},m=Y(u,p,r);return m?{[ze(e,n)]:`var(${_}${m.join(b)})`}:{}}]}s(jr,"createDirectionalRule");function Pr(e,t){return[H(e),r=>{const o=r[1];if(!o)return{};for(const{property:i,config:a,direction:c,tokens:u}of t){const p=ie(o,a),m={...a,property:i},d=Y(p,m,u);if(d)return c?{[ze(i,c)]:`var(${_}${d.join(b)})`}:{[i]:`var(${_}${d.join(b)})`}}return{}}]}s(Pr,"createSmartRule");function Ur(e,t,n){const r=t.source.indexOf("."),o=r!==-1?t.source.slice(0,r):t.source;return[H(o),a=>{const c=a[1];if(!c)return{};const u={...t,property:e},p=Y(c,u,n);return p?{[e]:`var(${_}${p.join(b)})`}:{}}]}s(Ur,"createDirectTokenPathRule");function Gr(e,t){if(!e?.source||typeof e.source!="string")throw new Error(f.UTILITIES.MISSING_SOURCE(t));if(e.source.includes("*")&&!e.source.endsWith(".*"))throw new Error(f.UTILITIES.INVALID_SOURCE_PATTERN(t,e.source));if(e.directions&&!Array.isArray(e.directions))throw new Error(f.UTILITIES.INVALID_DIRECTIONS(t))}s(Gr,"validateUtilityConfig");function Br(e,t){if(!e||typeof e!="object")throw new Error(f.UTILITIES.INVALID_CONFIG_OBJECT);if(!t||typeof t!="object")throw new Error(f.UTILITIES.INVALID_TOKENS_OBJECT)}s(Br,"validateInputs");function Wr(e,t){Br(e,t);const n=[],r={};for(const[o,i]of Object.entries(e)){const a=Array.isArray(i)?i:[i];for(const c of a)if(Gr(c,o),c.prefix){const u=c.prefix;r[u]||(r[u]=[]),r[u].push({property:o,config:c,direction:null,tokens:t})}else{const u=Ur(o,c,t);n.push(u)}}for(const[o,i]of Object.entries(r))if(i.length===1){const a=i[0];if(!a)continue;const{property:c,config:u,tokens:p}=a;if(u.directions){const m=Fr(u.directions);(Array.isArray(u.directions)?u.directions:[u.directions]).includes("all")&&n.push(ae(c,u,p));for(const y of m)Lr.includes(y)||n.push(jr(c,u,y,p))}else n.push(ae(c,u,p))}else n.push(Pr(o,i));return n}s(Wr,"convertConfigToUnoRules");const v=process.env.SUGARCUBE_PERF==="true";class Yr{static{s(this,"PerfMonitor")}constructor(t=n=>void process.stderr.write(`${n}
18
18
  `)){this.defaultFlush=t}#n=0;#t=0;#e=Date.now();#r=null;#o=0;#s(){return Math.round(process.memoryUsage().heapUsed/1024/1024)}#i(){return new Date().toISOString().split("T")[1]?.slice(0,-1)??""}log(t,n){if(!v)return;const r=this.#i(),o=this.#s(),i=o-this.#n;this.#n=o,this.defaultFlush(`[perf ${r}] ${t} ${n?JSON.stringify(n):""} | heap: ${o}MB (${i>=0?"+":""}${i}MB)`)}trackWatcherEvent(t,n){if(!v)return;this.#t++;const r=Date.now(),o=t.split("/").slice(-3).join("/");this.log(`WATCHER EVENT #${this.#t}: ${o}`),r-this.#e>1e4&&(this.log("WATCHER STATS (last 10s)",{events:this.#t,moduleGraphSize:n}),this.#t=0,this.#e=r)}logWatcherSetup(t,n){v&&this.log("WATCHER SETUP: Adding watch pattern",{pattern:t,dir:n})}logModuleGraphStats(t,n,r){v&&this.log(`MODULE GRAPH (${r})`,{modules:t,urls:n})}startMemoryMonitor(){!v||this.#r||(this.log("PERF MONITORING ENABLED - Starting memory monitor"),this.#o=this.#s(),this.#r=setInterval(()=>{const t=this.#s(),n=t-this.#o;Math.abs(n)>5&&(this.log("MEMORY CHANGE",{from:this.#o,to:t,delta:n}),this.#o=t)},5e3))}stopMemoryMonitor(){this.#r&&(clearInterval(this.#r),this.#r=null)}[Symbol.dispose](){this.stopMemoryMonitor()}}class Xe extends Map{static{s(this,"DefaultMap")}constructor(t){super(),this.factory=t}get(t){let n=super.get(t);return n===void 0&&(n=this.factory(t,this),this.set(t,n)),n}}const Hr=process.env.DEBUG==="true";class Kr{static{s(this,"Instrumentation")}constructor(t=n=>void process.stderr.write(`${n}
19
19
  `)){this.defaultFlush=t}#n=new Xe(()=>({value:0}));#t=new Xe(()=>({value:0n}));#e=[];hit(t){this.#n.get(t).value++}start(t){const n=this.#e.map(o=>o.label).join("//"),r=`${n}${n.length===0?"":"//"}${t}`;this.#n.get(r).value++,this.#t.get(r),this.#e.push({id:r,label:t,namespace:n,value:process.hrtime.bigint()})}end(t){const n=process.hrtime.bigint();if(this.#e.length===0)throw new Error("Timer stack is empty");const r=this.#e.length-1,o=this.#e[r];if(!o)throw new Error("Timer stack is corrupted");if(o.label!==t)throw new Error(`Mismatched timer label: ${t}`);const i=this.#e.pop();if(!i)throw new Error("Timer stack is empty");const a=n-i.value;this.#t.get(i.id).value+=a}report(t=this.defaultFlush){const n=[];let r=!1;for(let o=this.#e.length-1;o>=0;o--){const i=this.#e[o];i&&this.end(i.label)}for(const[o,{value:i}]of this.#n.entries()){if(this.#t.has(o))continue;n.length===0&&(r=!0,n.push("Hits:"));const a=o.split("//").length;n.push(`${" ".repeat(a)}${o} \xD7 ${i}`)}if(this.#t.size>0){r&&n.push(`
20
20
  Timers:`);for(const[o,{value:i}]of this.#t){const a=o.split("//").length,c=`${(Number(i)/1e6).toFixed(2)}ms`;n.push(`${" ".repeat(a-1)}${o.split("//").pop()} [${c}] ${this.#n.get(o).value===1?"":`\xD7 ${this.#n.get(o).value}`}`.trimEnd())}}t(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarcube-org/core",
3
- "version": "0.0.1-alpha.16",
3
+ "version": "0.0.1-alpha.17",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": false