@sugarcube-org/core 0.0.1-alpha.9 → 0.1.0-alpha.19
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/LICENSE.md +5 -27
- package/README.md +9 -1
- package/dist/index.d.ts +449 -1162
- package/dist/index.js +19 -22
- package/package.json +4 -5
package/dist/index.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Ze=Object.defineProperty;var s=(e,t)=>Ze(e,"name",{value:t,configurable:!0});import{existsSync as z}from"node:fs";import Qe,{readFile as x,mkdir as ue,writeFile as fe}from"node:fs/promises";import{pathToFileURL as et}from"node:url";import{resolve as O,isAbsolute as C,dirname as J,relative as le}from"pathe";import{z as l}from"zod";const b={output:{cssRoot:"src/styles",components:"src/components/ui",themeAttribute:"data-theme"},transforms:{fluid:{min:320,max:1200},colorFallbackStrategy:"native"}},f={LOAD:{NO_FILES_FOUND:s(e=>`No files found matching pattern: ${e}.`,"NO_FILES_FOUND"),INVALID_JSON:s((e,t)=>`Invalid JSON in file ${e}: ${t}`,"INVALID_JSON"),GLOB_ERROR:s((e,t)=>`Error resolving glob pattern ${e}: ${t}`,"GLOB_ERROR")},FLATTEN:{INVALID_TOKEN_NAME:s(e=>`Invalid token name "${e}": Token names cannot contain dots (.), curly braces ({,}), or other special characters`,"INVALID_TOKEN_NAME"),MISSING_DOLLAR_PREFIX:s(e=>`Token at ${e} is using 'value' or 'type' without the required '$' prefix. Use '$value' and '$type' instead.`,"MISSING_DOLLAR_PREFIX"),INVALID_TOKEN_NESTING:s(e=>`Token at "${e}" cannot contain child tokens or groups. Only metadata properties (starting with $) are allowed.`,"INVALID_TOKEN_NESTING"),COMPOSITE_TOKEN_MISSING_TYPE:s(e=>`Composite token at '${e}' is missing the required "$type" property. Composite tokens (tokens with object values) must specify their type to define their structure.`,"COMPOSITE_TOKEN_MISSING_TYPE"),CONFLICT_TOKEN_VS_GROUP:s(e=>`Conflict at "${e}": token vs group. A token cannot be replaced by a group (or vice versa).`,"CONFLICT_TOKEN_VS_GROUP"),CONFLICT_INCOMPATIBLE_TYPES:s((e,t,n)=>`Type conflict at "${n}": expected ${e}, got ${t}`,"CONFLICT_INCOMPATIBLE_TYPES")},METADATA:{COLLECTION_ERROR:s(e=>`Error collecting metadata: ${e}`,"COLLECTION_ERROR"),INVALID_EXTENSIONS:s(e=>`Invalid extensions at ${e}: expected object, got ${typeof e}`,"INVALID_EXTENSIONS"),INVALID_DESCRIPTION:s(e=>`Invalid description at ${e}: expected string, got ${typeof e}`,"INVALID_DESCRIPTION")},VALIDATE:{MISSING_TYPE:s(e=>`Token at '${e}' is missing the "$type" property`,"MISSING_TYPE"),UNKNOWN_TOKEN_TYPE:s((e,t)=>`Unknown token type '${e}' at ${t}. Valid types are: color, dimension, fontFamily, fontWeight, duration, cubicBezier, strokeStyle, border, transition, shadow, gradient, typography`,"UNKNOWN_TOKEN_TYPE"),INVALID_COLOR:s((e,t)=>`Invalid color at ${t}: '${e}'. Color should be a valid hex value or W3C color object`,"INVALID_COLOR"),INVALID_DIMENSION:s((e,t)=>`Invalid dimension at '${t}': ${e}. Dimensions should have a numeric value and unit, like { "value": 16, "unit": "px" }`,"INVALID_DIMENSION"),INVALID_DIMENSION_UNIT:s((e,t)=>`Invalid unit at ${t}': '${e}'. Unit must be either "px" or "rem"`,"INVALID_DIMENSION_UNIT"),INVALID_FONT_FAMILY:s((e,t)=>`Invalid font family at '${t}': ${e}. Should be a string or array of strings, like "Arial" or ["Arial", "sans-serif"]`,"INVALID_FONT_FAMILY"),INVALID_FONT_WEIGHT:s((e,t)=>`Invalid font weight at '${t}': ${e}. Should be a number between 1-1000 or a keyword like "thin", "light", "normal", "bold"`,"INVALID_FONT_WEIGHT"),INVALID_DURATION:s((e,t)=>`Invalid duration at '${t}': ${e}. Should be like { "value": 300, "unit": "ms" }`,"INVALID_DURATION"),INVALID_DURATION_UNIT:s((e,t)=>`Invalid unit at ${t}: "${e}". Unit must be "ms" or "s"`,"INVALID_DURATION_UNIT"),INVALID_CUBIC_BEZIER:s((e,t)=>`Invalid cubic bezier at ${t}: "${e}". Should be an array of 4 numbers between 0 and 1`,"INVALID_CUBIC_BEZIER"),INVALID_STROKE_STYLE:s((e,t)=>`Invalid stroke style at ${t}: "${e}". Should be "solid", "dashed", "dotted", etc.`,"INVALID_STROKE_STYLE"),INVALID_STROKE_LINE_CAP:s((e,t)=>`Invalid line cap at ${t}: "${e}". Should be one of: round, butt, square`,"INVALID_STROKE_LINE_CAP"),INVALID_BORDER:s((e,t)=>`Invalid border at ${t}: "${e}". Should have color, width, and style properties`,"INVALID_BORDER"),INVALID_SHADOW:s((e,t)=>`Invalid shadow at ${t}: "${e}". Should have color, offsetX, offsetY properties (blur and spread are optional)`,"INVALID_SHADOW"),INVALID_SHADOW_INSET:s((e,t)=>`Invalid inset value at ${t}: "${e}". Should be true or false`,"INVALID_SHADOW_INSET"),INVALID_TRANSITION:s((e,t)=>`Invalid transition at ${t}: "${e}". Should have duration, delay, and timingFunction properties`,"INVALID_TRANSITION"),INVALID_GRADIENT:s((e,t)=>`Invalid gradient at ${t}: "${e}". Should be an array of color stops with position values between 0 and 1`,"INVALID_GRADIENT"),INVALID_GRADIENT_STOP_POSITION:s((e,t)=>`Invalid gradient stop position at ${t}: "${e}". Position must be between 0 and 1`,"INVALID_GRADIENT_STOP_POSITION"),INVALID_TYPOGRAPHY:s((e,t)=>`Invalid typography at ${t}: "${e}". Should have fontFamily and fontSize (fontWeight, letterSpacing, and lineHeight are optional)`,"INVALID_TYPOGRAPHY"),MISSING_REQUIRED_PROPERTY:s((e,t)=>`Missing required property '${e}' at ${t}`,"MISSING_REQUIRED_PROPERTY"),INVALID_NUMBER:s((e,t)=>`Invalid number at ${t}: "${e}". Expected a number value`,"INVALID_NUMBER"),INVALID_ARRAY:s((e,t)=>`Invalid array at ${t}: "${e}". Expected an array value`,"INVALID_ARRAY"),MISSING_FLUID_CONFIG:s(e=>`Missing fluid configuration. Token at ${e} requires fluid viewport settings.`,"MISSING_FLUID_CONFIG"),INVALID_FLUID_DIMENSION:s((e,t)=>`Invalid fluid dimension at ${t}: "${e}". Fluid dimensions should have min and max values, like { "min": { "value": 16, "unit": "px" }, "max": { "value": 24, "unit": "px" } }`,"INVALID_FLUID_DIMENSION"),INVALID_VIEWPORT_CONFIG:s((e,t)=>`Invalid viewport configuration at ${t}: "${e}". Viewport config should have min and max dimension values`,"INVALID_VIEWPORT_CONFIG"),MISMATCHED_UNITS:s((e,t,n)=>`Mismatched units at ${n}: min uses '${e}', max uses '${t}'. Both values must use the same unit`,"MISMATCHED_UNITS"),INVALID_FLUID_VALUE_RANGE:s(e=>`Invalid fluid value range at ${e}: min value must be less than max value`,"INVALID_FLUID_VALUE_RANGE"),INVALID_TOKEN_TYPE:s((e,t,n)=>`Invalid token type at ${n}: expected ${e}, got ${t}`,"INVALID_TOKEN_TYPE"),INVALID_TYPE:s((e,t,n)=>`Expected ${e}, received ${typeof t} at ${n}`,"INVALID_TYPE"),INVALID_ENUM_VALUE:s((e,t,n)=>`Expected value to be one of [${e.join(", ")}], but got ${String(t)} at ${n}`,"INVALID_ENUM_VALUE")},RESOLVE:{CIRCULAR_REFERENCE:s((e,t)=>`Circular reference detected: ${e} -> ${t}`,"CIRCULAR_REFERENCE"),REFERENCE_NOT_FOUND:s((e,t)=>`Reference not found: ${e} in ${t}. Does ${e} exist?`,"REFERENCE_NOT_FOUND"),TYPE_MISMATCH:s(e=>`Type mismatch in ${e}`,"TYPE_MISMATCH")},GENERATE:{INVALID_CSS_VALUE:s((e,t)=>`Invalid CSS value for property '${e}': ${t}`,"INVALID_CSS_VALUE"),INVALID_VARIABLE_NAME:s((e,t)=>`Invalid CSS variable name at '${e}': ${t}`,"INVALID_VARIABLE_NAME")},CONFIG:{INVALID_JSON:s(e=>`Invalid JSON in config file: ${e}`,"INVALID_JSON"),INVALID_CONFIG:s((e,t)=>`Invalid configuration at ${e}: ${t}`,"INVALID_CONFIG"),DUPLICATE_FILENAMES:s((e,t)=>`Duplicate filename "${e}":
|
|
2
|
+
${t.map(n=>` - ${n}`).join(`
|
|
3
|
+
`)}`,"DUPLICATE_FILENAMES"),FILE_NOT_FOUND:s(e=>e==="sugarcube.config.ts"?"Cannot find sugarcube config file. Please ensure you have a valid sugarcube.config.ts 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 X(e){const t=e.output?.cssRoot??b.output.cssRoot,n={resolver:e.resolver,transforms:{fluid:e.transforms?.fluid??b.transforms.fluid,colorFallbackStrategy:e.transforms?.colorFallbackStrategy??b.transforms.colorFallbackStrategy},output:{cssRoot:t,variables:e.output?.variables??`${t}/global`,utilities:e.output?.utilities??`${t}/utilities`,cube:e.output?.cube??t,themeAttribute:e.output?.themeAttribute??b.output.themeAttribute,defaultContext:e.output?.defaultContext}};return(e.output?.components!==void 0||b.output.components!==void 0)&&(n.output.components=e.output?.components??b.output.components),e.utilities&&(n.utilities=e.utilities),n}s(X,"fillDefaults");const pe=l.object({min:l.number(),max:l.number()}),de=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()}),me=l.union([de,l.array(de)]),tt=l.object({resolver:l.string().optional(),transforms:l.object({fluid:pe.optional(),colorFallbackStrategy:l.enum(["native","polyfill"]).optional()}).optional(),output:l.object({cssRoot:l.string().optional(),variables:l.string().optional(),utilities:l.string().optional(),cube:l.string().optional(),components:l.string().optional(),themeAttribute:l.string().optional(),defaultContext:l.string().optional()}).optional(),utilities:l.record(l.string(),me).optional()}),nt=l.object({resolver:l.string().optional(),transforms:l.object({fluid:pe,colorFallbackStrategy:l.enum(["native","polyfill"])}),output:l.object({cssRoot:l.string(),variables:l.string().optional(),utilities:l.string().optional(),cube:l.string().optional(),components:l.string().optional(),themeAttribute:l.string(),defaultContext:l.string().optional()}),utilities:l.record(l.string(),me).optional()});function Z(e){const t=tt.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
|
+
`))}return t.data}s(Z,"validateSugarcubeConfig");function he(e){const t=nt.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(he,"validateInternalConfig");function rt(e){const t=Z(e),n=X(t);return he(n)}s(rt,"validateConfig");function Ie(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(Ie,"findConfigFile");function ot(e="sugarcube.config"){return Ie(e)!==null}s(ot,"configFileExists");async function st(e){try{if(typeof globalThis.Bun<"u"){const i=et(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(st,"loadTSConfig");async function ye(e){if(e.endsWith(".ts")||e.endsWith(".js"))return await st(e);const n=await Qe.readFile(e,"utf-8");return JSON.parse(n)}s(ye,"loadConfigFile");function $e(e){if(e)return O(process.cwd(),e);const t=Ie();if(!t)throw new Error(f.CONFIG.FILE_NOT_FOUND("sugarcube.config.ts"));return t}s($e,"resolveConfigPath");async function it(e){const t=$e(e);try{const n=await ye(t);return{config:Z(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(it,"loadSugarcubeConfig");async function at(e){const t=$e(e);try{const n=await ye(t),r=Z(n),o=X(r);return{config:he(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(at,"loadInternalConfig");function h(e){return typeof e=="string"&&e.startsWith("{")&&e.endsWith("}")}s(h,"isReference$1");function ct(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(ct,"isCompositeToken");function ut(e){return e.$type==="typography"}s(ut,"isTypographyToken");function Q(e){return typeof e=="object"&&e!==null&&"$value"in e}s(Q,"isTokenNode");function ft(e,t,n){for(const[r,o]of Object.entries(t.tokens)){const i=e.tokens[r];if(!Q(o)){if(i&&Q(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(!Q(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(ft,"mergeFlattenedInto");function lt(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(lt,"looksLikeUnprefixedToken");function pt(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],E=y.join(".");if(lt(I)){r.push({path:E,source:t,message:f.FLATTEN.MISSING_DOLLAR_PREFIX(E)});continue}if(d.includes(".")||d.includes("{")||d.includes("}")){r.push({path:E,source:t,message:f.FLATTEN.INVALID_TOKEN_NAME(d)});continue}if("$value"in I){if(Object.keys(I).filter(Xe=>!Xe.startsWith("$")).length>0){r.push({path:E,source:t,message:f.FLATTEN.INVALID_TOKEN_NESTING(E)});continue}if(ct(I)&&!I.$type&&!m){r.push({path:E,source:t,message:f.FLATTEN.COMPOSITE_TOKEN_MISSING_TYPE(E)});continue}const ce=o(y),q=y.join(".");n.tokens[ce]={...I,...I.$type||m?{$type:I.$type||m}:{},$path:q,$source:{context:t.context,sourcePath:t.sourcePath},$originalPath:q},n.pathIndex.set(q,ce)}else i(I,y,m)}}return s(i,"processNode"),i(e),{tokens:n,errors:r}}s(pt,"flattenTree");function dt(e){const t={tokens:{},pathIndex:new Map},n=[];for(const r of e){const{tokens:o,errors:i}=pt(r.tokens,{context:r.context,sourcePath:r.sourcePath});n.push(...i),ft(t,o,n)}return{tokens:t,errors:n}}s(dt,"flatten");const V=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 '.'"),Ee=l.object({$ref:l.string().min(1,"$ref cannot be empty")}).passthrough(),ee=l.union([Ee,l.record(l.string(),l.unknown())]),mt=l.object({description:l.string().optional(),sources:l.array(ee),$extensions:l.record(l.string(),l.unknown()).optional()}),ge=l.record(l.string(),l.array(ee)),ht=l.object({description:l.string().optional(),contexts:ge,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"),It=l.object({type:l.literal("set"),name:V,sources:l.array(ee),description:l.string().optional(),$extensions:l.record(l.string(),l.unknown()).optional()}),yt=l.object({type:l.literal("modifier"),name:V,contexts:ge,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"),$t=l.union([Ee,It,yt]),Et=l.record(V,mt),gt=l.record(V,ht),Nt=l.object({version:l.literal("2025.10"),name:l.string().optional(),description:l.string().optional(),sets:Et.optional(),modifiers:gt.optional(),resolutionOrder:l.array($t),$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 Ne(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="set"}s(Ne,"isInlineSet");function L(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="modifier"}s(L,"isInlineModifier");async function Tt(e){const t=C(e)?e:O(process.cwd(),e),n=await St(t);if(n.error)return{document:F(),errors:[n.error]};const r=bt(n.content);if(r.error)return{document:F(),errors:[r.error]};const o=At(r.data);if(o.errors.length>0)return{document:F(),errors:o.errors};const i=[];return Ot(o.document,i),{document:o.document,errors:i}}s(Tt,"parseResolverDocument");async function St(e){try{return{content:await x(e,"utf-8")}}catch{return{error:{path:e,message:f.RESOLVER.FILE_NOT_FOUND(e)}}}}s(St,"loadFile");function bt(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(bt,"parseJson");function At(e){const t=Nt.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:F(),errors:n}}return{document:t.data,errors:[]}}s(At,"validateSchema$1");function Ot(e,t){Dt(e,t),Rt(e,t),Lt(e,t)}s(Ot,"validateDocument");function Dt(e,t){if(e.modifiers)for(const[n,r]of Object.entries(e.modifiers))Te(r,`modifiers.${n}`,t);for(let n=0;n<e.resolutionOrder.length;n++){const r=e.resolutionOrder[n];L(r)&&Te(r,`resolutionOrder[${n}]`,t)}}s(Dt,"validateModifierContexts");function Te(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(Te,"checkModifierContexts");function Rt(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(Rt,"validateNameUniqueness");function Lt(e,t){for(let n=0;n<e.resolutionOrder.length;n++){const r=e.resolutionOrder[n];if(D(r))_t(r.$ref,`resolutionOrder[${n}].$ref`,e,t);else if(Ne(r))w(r.sources,`resolutionOrder[${n}].sources`,t);else if(L(r))for(const[o,i]of Object.entries(r.contexts))w(i,`resolutionOrder[${n}].contexts.${o}`,t)}if(e.sets)for(const[n,r]of Object.entries(e.sets))w(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))w(i,`modifiers.${n}.contexts.${o}`,t)}s(Lt,"validateReferences");function w(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(w,"validateSourcesReferences");function _t(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(_t,"validateReference");function F(){return{version:"2025.10",resolutionOrder:[]}}s(F,"createEmptyDocument");function Se(e){if(typeof e!="object"||e===null)return!1;const t=e;return t.version==="2025.10"&&Array.isArray(t.resolutionOrder)}s(Se,"isResolverFormat");function be(e,t){return{document:e,basePath:t,visitedRefs:new Set,fileCache:new Map}}s(be,"createResolveContext");async function Ae(e,t){if(t.visitedRefs.has(e))return T({},f.RESOLVER.CIRCULAR_REFERENCE(e),e);t.visitedRefs.add(e);try{return e.startsWith("#/")?vt(e,t):e.includes("#/")?await Ct(e,t):await xt(e,t)}finally{t.visitedRefs.delete(e)}}s(Ae,"resolveReference");function vt(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(vt,"resolveSameDocumentRef");async function xt(e,t){const n=C(e)?e:O(t.basePath,e),r=t.fileCache.get(n);if(r)return Se(r)?T({},f.RESOLVER.RESOLVER_AS_TOKEN_SOURCE(n),n):{content:r,sourcePath:n,errors:[]};const o=await Oe(n);return o.error?T({},o.error,n):Se(o.content)?T({},f.RESOLVER.RESOLVER_AS_TOKEN_SOURCE(n),n):(t.fileCache.set(n,o.content),{content:o.content,sourcePath:n,errors:[]})}s(xt,"resolveFileRef");async function Ct(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 Oe(o);if(u.error)return T({},u.error,o);i=u.content,t.fileCache.set(o,i)}const a=r.startsWith("/")?r:`/${r}`,c=Vt(i,a);return c.error?T({},f.RESOLVER.INVALID_JSON_POINTER(a,c.error),o):{content:c.value,sourcePath:o,errors:[]}}s(Ct,"resolveFileFragmentRef");async function Oe(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(Oe,"loadJsonFile");function Vt(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(Vt,"resolveJsonPointer");async function De(e,t){const n=[],r=[];for(const o of e){if(!D(o)){n.push(o);continue}const i=await Ae(o.$ref,t);r.push(...i.errors),i.errors.length===0&&n.push(wt(i.content,o))}return{resolved:n,errors:r}}s(De,"resolveSources");function wt(e,t){const{$ref:n,...r}=t;return Object.keys(r).length===0?e:{...e,...r}}s(wt,"applyExtending");function T(e,t,n="#"){return{content:e,sourcePath:n,errors:[{path:n,message:t}]}}s(T,"errorResult");function Re(e){return typeof e=="object"&&e!==null&&"$value"in e}s(Re,"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(Re(o)){n[r]=o;continue}const i=n[r],a=i!==void 0&&typeof i=="object"&&i!==null&&typeof o=="object"&&o!==null&&!Re(i);n[r]=a?k(i,o):o}return n}s(k,"deepMerge");function Le(e){const t=[],n=new Set;for(const r of e.resolutionOrder){const o=Ft(r,e,n);o&&(t.push(o),n.add(o.name))}return t}s(Le,"extractModifiers");function Ft(e,t,n){return D(e)&&e.$ref.startsWith("#/modifiers/")?kt(e.$ref,t,n):L(e)?Mt(e,n):null}s(Ft,"extractModifierFromItem");function kt(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(kt,"extractReferencedModifier");function Mt(e,t){return t.has(e.name)?null:{name:e.name,contexts:Object.keys(e.contexts),default:e.default}}s(Mt,"extractInlineModifier");function jt(e,t={}){const n=[],r={},o=Le(e);if(o.length===0)return Pt(t,n),{valid:n.length===0,errors:n,resolvedInputs:r};const i=new Map(o.map(a=>[a.name,a]));return Ut(t,i,n,r),Gt(o,r,n),{valid:n.length===0,errors:n,resolvedInputs:r}}s(jt,"validateInputs$1");function Pt(e,t){for(const n of Object.keys(e))t.push({modifier:n,message:f.RESOLVER.UNKNOWN_MODIFIER(n)})}s(Pt,"validateNoModifiersCase");function Ut(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(Ut,"validateProvidedInputs");function Gt(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(Gt,"applyDefaults");async function _e(e,t,n={}){const r=jt(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=Wt();for(const a of e.resolutionOrder)await Bt(a,e,o,r.resolvedInputs,i);return{tokens:i.tokens,sources:i.sources,errors:i.errors}}s(_e,"processResolutionOrder");function Wt(){return{tokens:{},sources:[],errors:[]}}s(Wt,"createProcessingState");async function Bt(e,t,n,r,o){if(D(e)){await Yt(e,t,n,r,o);return}if(Ne(e)){await Ht(e,n,o);return}L(e)&&await Kt(e,n,r,o)}s(Bt,"processItem");async function Yt(e,t,n,r,o){const i=await Ae(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(Yt,"processReference");async function Ht(e,t,n){const r=await M(e.sources,t,{type:"set",name:e.name});j(r,n)}s(Ht,"processInlineSet");async function Kt(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(Kt,"processInlineModifier");async function M(e,t,n){const r=await De(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=Le(e),i={};for(const p of o)p.default&&(i[p.name]=p.default);const a=await _e(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 zt(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 zt(e,t,n,r,o,i){const a=Jt(e,r);if(!a)return{};const c=a.contexts[o];if(!c||c.length===0)return{};const u=await De(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;ve(p,"",m);const d=await _e(e,t,{[r]:o});i.push(...d.errors);const I={};for(const y of m){const E=Xt(d.tokens,y);E!==void 0&&Zt(I,y,E)}return I}s(zt,"processModifierContext");function Jt(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(Jt,"findModifierDefinition");function ve(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"&&ve(o,i,n)}}s(ve,"collectTokenPaths");function Xt(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(Xt,"getTokenAtPath");function Zt(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(Zt,"setTokenAtPath");async function Qt(e){const t=C(e)?e:O(process.cwd(),e),n=J(t),r=[],o=[],i=le(process.cwd(),t),a=await Tt(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(Qt,"loadFromResolver");async function en(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:le(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(en,"loadTreesFromMemory");function P(e,t,n,r){return typeof t=="string"&&h(t)?nn(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 xe(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 xe(o.$value,t)}}s(xe,"inferTypeFromReference");function tn(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=xe(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(tn,"resolve");function nn(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(nn,"resolveReferenceChain");function S(e){return{success:!0,value:e}}s(S,"success");function g(e){return{success:!1,error:e}}s(g,"error");function te(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(te,"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 rn(e){const t=U(e);return t.length>0?g(t.join(", ")):S(e)}s(rn,"validateDTCGColorValueResult");function on(e){const t=rn(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(on,"formatDTCGColorToOKLCH");const sn={isObject:s(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObject")};function $(e,t,n,r){if(h(t))return[];switch(e.type){case"object":return cn(e,t,n,r);case"union":return un(e,t,n,r);case"array":return fn(e,t,n,r);default:return an(e,t,n,r)}}s($,"validateSchema");function an(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(an,"validateSimpleValue");function cn(e,t,n,r){if(!sn.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(...$(c,i[a],`${n}.${a}`,r));return o}s(cn,"validateObject");function un(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=$(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(un,"validateUnion");function fn(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(fn,"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)=>te(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 ln(e,t,n){return $(G.schema,e,t,n)}s(ln,"validateColor");const W={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 pn(e,t,n){return $(W.schema,e,t,n)}s(pn,"validateNumber");const N={schema:{type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_DIMENSION(e,t),"errorMessage"),properties:{value:W.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 dn(e,t,n){return $(N.schema,e,t,n)}s(dn,"validateDimension");const mn=["solid","dashed","dotted","double","groove","ridge","outset","inset"],hn=["round","butt","square"],In={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(...$(N.schema,i,`${t}.${a}`,n))}),o},"validate")},lineCap:{type:"string",validate:s((e,t,n)=>hn.includes(e)?[]:[{path:t,message:f.VALIDATE.INVALID_STROKE_LINE_CAP(e,t),source:n}],"validate")}},required:["dashArray","lineCap"]},Ce={schema:{type:"union",oneOf:[{type:"string",validate:s((e,t,n)=>!mn.includes(e)&&typeof e=="string"?[{path:t,message:f.VALIDATE.INVALID_STROKE_STYLE(e,t),source:n}]:[],"validate")},In]}};function yn(e,t,n){return $(Ce.schema,e,t,n)}s(yn,"validateStrokeStyle");const $n={schema:{type:"object",properties:{color:G.schema,width:N.schema,style:Ce.schema},required:["color","width","style"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_BORDER(e,t),"errorMessage")}};function En(e,t,n){return $($n.schema,e,t,n)}s(En,"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 gn(e,t,n){return $(Ve.schema,e,t,n)}s(gn,"validateCubicBezier");const Nn=["ms","s"],ne={schema:{type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_DURATION(e,t),"errorMessage"),properties:{value:W.schema,unit:{type:"string",validate:s((e,t,n)=>Nn.includes(e)?[]:[{path:t,message:f.VALIDATE.INVALID_DURATION_UNIT(e,t),source:n}],"validate")}},required:["value","unit"]}};function Tn(e,t,n){return $(ne.schema,e,t,n)}s(Tn,"validateDuration");const Sn={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 bn(e,t,n){return $(Sn.schema,e,t,n)}s(bn,"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 An(e,t,n){return $(we.schema,e,t,n)}s(An,"validateFontFamily");const On=["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"],Fe={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)=>On.includes(e.toLowerCase())?[]:[{path:t,message:f.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}],"validate")}]}};function Dn(e,t,n){return $(Fe.schema,e,t,n)}s(Dn,"validateFontWeight");const Rn={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"]},Ln={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(...$(Rn,i,`${t}[${a}]`,n))}),o},"validate")}};function _n(e,t,n){return $(Ln.schema,e,t,n)}s(_n,"validateGradient");const ke={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 vn(e,t,n){const r=[];return Array.isArray(e)?(e.forEach((o,i)=>{r.push(...$(ke.schema,o,`${t}[${i}]`,n))}),r):$(ke.schema,e,t,n)}s(vn,"validateShadow");const xn={schema:{type:"object",properties:{duration:ne.schema,delay:ne.schema,timingFunction:Ve.schema},required:["duration","delay","timingFunction"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_TRANSITION(e,t),"errorMessage")}};function Cn(e,t,n){return $(xn.schema,e,t,n)}s(Cn,"validateTransition");const Vn={schema:{type:"object",properties:{fontFamily:we.schema,fontSize:N.schema,letterSpacing:N.schema,lineHeight:W.schema,fontWeight:Fe.schema},required:["fontFamily","fontSize"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_TYPOGRAPHY(e,t),"errorMessage")}};function wn(e,t,n){return $(Vn.schema,e,t,n)}s(wn,"validateTypography");const Fn={color:ln,dimension:dn,fluidDimension:bn,duration:Tn,cubicBezier:gn,fontFamily:An,fontWeight:Dn,number:pn,strokeStyle:yn,typography:wn,border:En,shadow:vn,gradient:_n,transition:Cn};function kn(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=Fn[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(kn,"validate");async function Mn(e){const{trees:t,modifiers:n,errors:r}=await jn(e),{tokens:o,errors:i}=dt(t),a=kn(o),{resolved:c,errors:u}=tn(o);return{trees:t,resolved:c,modifiers:n,errors:{load:r,flatten:i,validation:a,resolution:u}}}s(Mn,"loadAndResolveTokens");async function jn(e){switch(e.type){case"memory":{const t=await en(e.data);return{trees:t.trees,modifiers:[],errors:t.errors}}case"resolver":{const t=await Qt(e.resolverPath);return{trees:t.trees,modifiers:t.modifiers,errors:t.errors}}}}s(jn,"loadTokens");function Me(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(Me,"convertStrokeStyleToken");function Pn(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:Me(e.style).value;return{value:`${t} ${r} ${n}`}}s(Pn,"convertBorderToken");function je(e,t="native"){return te(e)?Un(e):S(e)}s(je,"convertColorToString");function Un(e){switch(e.colorSpace){case"oklch":return on(e);case"display-p3":return Gn(e);case"srgb":return Wn(e);case"hsl":return Bn(e);default:return g(`Unsupported color space: ${e.colorSpace}. Supported color spaces: oklch, display-p3, srgb, hsl.`)}}s(Un,"formatDTCGColorNative");function Gn(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(Gn,"formatDTCGColorToP3");function Wn(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(Wn,"formatDTCGColorToRGB");function Bn(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(Bn,"formatDTCGColorToHSL");function Yn(e,t){if(typeof e=="string"&&h(e))return{value:e};const n=t.colorFallbackStrategy;if(te(e))return Hn(e,n);const r=je(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(Yn,"convertColorToken");function Hn(e,t){const n=je(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:Kn(e.colorSpace),value:r}]}}s(Hn,"convertDTCGColorToken");function Kn(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(Kn,"getFeatureQuery");function qn(e){return h(e)?{value:e}:{value:`cubic-bezier(${e.join(", ")})`}}s(qn,"convertCubicBezierToken");function zn(e){return h(e)?{value:e}:{value:`${e.value}${e.unit}`}}s(zn,"convertDimensionToken");function Jn(e){return h(e)?{value:e}:{value:`${e.value}${e.unit}`}}s(Jn,"convertDurationToken");function Pe(e,t=16){return e.unit==="px"?e.value:e.value*t}s(Pe,"normalizeToPixels");function Xn(e,t){const{min:n,max:r}=e,o=t.fluidConfig,i=16,a=Pe(n,i),c=Pe(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,E=(d-m)/(y-I),ae=-1*I*E+m;return{value:`clamp(${m}rem, ${ae.toFixed(2)}rem + ${(E*100).toFixed(2)}vw, ${d}rem)`}}s(Xn,"convertFluidDimension");function Zn(e,t){return h(e)?{value:e}:Xn(e,t)}s(Zn,"convertFluidDimensionToken");function B(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(B,"quoteFont");function Qn(e){return h(e)?{value:e}:{value:Array.isArray(e)?e.map(n=>B(n)).join(", "):B(e)}}s(Qn,"convertFontFamilyToken");const er={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 Ue(e){return h(e)?{value:e}:typeof e=="number"?{value:e}:{value:er[e.toLowerCase()]??e}}s(Ue,"convertFontWeightToken");function tr(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(tr,"convertGradientToken");function nr(e){return h(e)?{value:e}:{value:e}}s(nr,"convertNumberToken");function Ge(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(Ge,"convertSingleShadow");function rr(e){return h(e)?{value:e}:Array.isArray(e)?{value:e.map(Ge).join(", ")}:{value:Ge(e)}}s(rr,"convertShadowToken");function We(e){return e?`${e.value}${e.unit}`:"0ms"}s(We,"formatDuration");function or(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(or,"convertTransitionToken");function sr(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=>B(n)).join(", "):B(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:Ue(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(sr,"convertTypographyToken");const Be={duration:Jn,number:nr,cubicBezier:qn,color:Yn,dimension:zn,fluidDimension:Zn,typography:sr,border:Pn,shadow:rr,gradient:tr,transition:or,strokeStyle:Me,fontFamily:Qn,fontWeight:Ue};function ir(e,t){const n=Be[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(ir,"convertSingleToken");function ar(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)||!Be[i.$type])continue;const a={fluidConfig:t.transforms.fluid,colorFallbackStrategy:t.transforms.colorFallbackStrategy,path:i.$path,resolvedTokens:e};r[o]=ir(i,a)}return r}s(ar,"convertTokens");function cr(e,t,n){const r={};for(const[o,i]of Object.entries(e))r[o]=ar(i,t,n);return r}s(cr,"convert");function ur(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(ur,"normalizeTokens");function fr(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(fr,"processTrees");async function lr(e,t,n,r){const o=fr(e,t),{tokens:i}=ur(o);return cr(i,n,r?u=>r.some(p=>p.path===u||p.path.startsWith(`${u}.`)):void 0)}s(lr,"processAndConvertTokens");function pr(e){return Object.entries(e).sort(([t],[n])=>t.localeCompare(n))}s(pr,"deterministicEntries");const Ye=new Map;function dr(e){const t=Ye.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 Ye.set(e,n),n}s(dr,"toKebabCase");function re(e){return e.split(".").join("-")}s(re,"formatCSSVarPath");function oe(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(dr).join("-")})`)}s(oe,"convertReferenceToCSSVar");function mr(e){const t=e.$cssProperties;if("value"in t)return{name:`--${re(e.$path)}`,value:oe(t.value)}}s(mr,"generateSingleVariable");function hr(e){return Object.entries(e.$cssProperties).filter(([t,n])=>n!==void 0).map(([t,n])=>({name:`--${re(e.$path)}-${t}`,value:oe(n)}))}s(hr,"generateTypographyVariables");function He(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:`--${re(e.$path)}`,value:oe(r.value)})}return Array.from(n.entries()).map(([r,o])=>({query:r,vars:o}))}s(He,"generateFeatureVariables");function Ke(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(`
|
|
2
6
|
`);t.push(n)}return t.push("}"),t.join(`
|
|
3
|
-
`)}s(
|
|
7
|
+
`)}s(Ke,"generateCSSBlock");function Ir(e){const t=[];e.root.vars.length>0&&t.push(Ke({selector:e.root.selector,vars:e.root.vars}));for(const n of e.features){const o=Ke({selector:e.root.selector,vars:n.vars}).split(`
|
|
4
8
|
`).map(i=>` ${i}`).join(`
|
|
5
9
|
`);t.push(`${n.query} {
|
|
6
|
-
${
|
|
10
|
+
${o}
|
|
7
11
|
}`)}return t.filter(Boolean).join(`
|
|
8
12
|
|
|
9
|
-
`)}s(
|
|
13
|
+
`)}s(Ir,"convertCSSVarsToString");function yr(e){if(ut(e))return{vars:hr(e),features:He(e)};const t=mr(e);return{vars:t?[t]:[],features:He(e)}}s(yr,"generateVariablesForToken");function $r(e,t,n){if(!e||e==="default")return":root";const r=e.indexOf(":");if(r!==-1){const o=e.slice(0,r),i=e.slice(r+1);return`[${t?.find(u=>u.name===o)?.attribute??`data-${o}`}="${i}"]`}return`[${n.output.themeAttribute}="${e}"]`}s($r,"buildSelector");async function Er(e,t,n){const r=pr(e).filter(([m,d])=>m!=="$extensions"&&"$type"in d).map(([m,d])=>yr(d)),o=$r(n.context,n.modifiers,t),i=r.flatMap(m=>m.vars),a=r.flatMap(m=>m.features||[]),c=new Map;for(const m of a){c.has(m.query)||c.set(m.query,[]);const d=c.get(m.query);d&&d.push(...m.vars)}const u=Array.from(c.entries()).map(([m,d])=>({query:m,vars:d})),p=Ir({root:{selector:o,vars:i},features:u});return p.trim()?{output:[{path:"tokens.variables.gen.css",css:gr(p)}]}:{output:[{path:"tokens.variables.gen.css",css:""}]}}s(Er,"generateCSS");function gr(e){return e.endsWith(`
|
|
10
14
|
`)?e:`${e}
|
|
11
|
-
`}s(
|
|
15
|
+
`}s(gr,"formatCSSVars");async function Nr(e,t,n){const r=t.output.variables,o=[],i=Object.entries(e).sort(([a],[c])=>!a||a==="default"?-1:!c||c==="default"?1:a.localeCompare(c));for(const[a,c]of i){const u=await Er(c,t,{context:a,modifiers:n});u.output[0].css.trim()&&o.push(u.output[0].css)}return o.length===0?[]:[{path:`${r}/tokens.variables.gen.css`,css:`${o.filter(Boolean).join(`
|
|
12
16
|
`).trim()}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
`)
|
|
16
|
-
1.
|
|
17
|
-
2. Configure utilities to be collection-specific: { source: "color.*", collection: "base" }`,"TOKEN_PATH_CONFLICT"),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"}};function re(e){return typeof e=="object"&&e!==null&&"$value"in e}s(re,"isTokenNode");function Et(e,t,n){for(const[o,r]of Object.entries(t.tokens)){const i=e.tokens[o];if(!re(r)){if(i&&re(i)){const f=i;n.push({path:f.$path,source:f.$source,message:d.FLATTEN.CONFLICT_TOKEN_VS_GROUP(f.$path)});continue}e.tokens[o]=r;continue}if(!i){e.tokens[o]=r;continue}if(!re(i)){n.push({path:r.$path,source:r.$source,message:d.FLATTEN.CONFLICT_TOKEN_VS_GROUP(r.$path)});continue}const c=r,u=i,l=!!c.$type,p=!!u.$type;if(l&&p&&c.$type!==u.$type){n.push({path:c.$path,source:c.$source,message:d.FLATTEN.CONFLICT_INCOMPATIBLE_TYPES(String(u.$type??"unknown"),String(c.$type??"unknown"),c.$path)});continue}e.tokens[o]=r}for(const[o,r]of t.pathIndex)e.pathIndex.set(o,r)}s(Et,"mergeFlattenedInto");function Nt(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 o=e.value;return typeof o=="string"||typeof o=="number"||Array.isArray(o)}return!1}s(Nt,"looksLikeUnprefixedToken");function St(e,t){const n={tokens:{},pathIndex:new Map},o=[];function r(a=[]){const c=[t.collection];return t.theme&&c.push(t.theme),t.mode&&c.push(t.mode),a.length>0&&c.push(a.join(".")),c.join(".")}s(r,"createLookupKey"),(e.$description||e.$extensions)&&(n.tokens[r()]={$description:e.$description,$extensions:e.$extensions});function i(a,c=[],u){if(c.join("."),c.length>0){const f=r(c);n.tokens[f]={$description:a.$description,$extensions:a.$extensions,$path:c.join("."),$source:{collection:t.collection,theme:t.theme,mode:t.mode,sourcePath:t.sourcePath}}}const l=Object.keys(a).filter(f=>!f.startsWith("$")),p=a.$type||u;for(const f of l){const h=a[f],m=[...c,f],I=m.join(".");if(Nt(h)){o.push({path:I,source:t,message:d.FLATTEN.MISSING_DOLLAR_PREFIX(I)});continue}if(f.includes(".")||f.includes("{")||f.includes("}")){o.push({path:I,source:t,message:d.FLATTEN.INVALID_TOKEN_NAME(f)});continue}if("$value"in h){if(Object.keys(h).filter(N=>!N.startsWith("$")).length>0){o.push({path:I,source:t,message:d.FLATTEN.INVALID_TOKEN_NESTING(I)});continue}if(ut(h)&&!h.$type&&!p){o.push({path:I,source:t,message:d.FLATTEN.COMPOSITE_TOKEN_MISSING_TYPE(I)});continue}const A=r(m),T=m.join(".");n.tokens[A]={...h,...h.$type||p?{$type:h.$type||p}:{},$path:T,$source:{collection:t.collection,theme:t.theme,mode:t.mode,sourcePath:t.sourcePath},$originalPath:T},n.pathIndex.set(T,A)}else i(h,m,p)}}return s(i,"processNode"),i(e),{tokens:n,errors:o}}s(St,"flattenTree");function Ot(e){const t={tokens:{},pathIndex:new Map},n=[];for(const o of e){const{tokens:r,errors:i}=St(o.tokens,{collection:o.collection,theme:o.theme,mode:o.mode,sourcePath:o.sourcePath});n.push(...i),Et(t,r,n)}return{tokens:t,errors:n}}s(Ot,"flatten");async function P(e){const t={files:[],errors:[]};for(const n of e)try{const o=!n.includes("*")&&!n.endsWith(".json")?L(n,"**/*.json"):n,r=await Z(o,{absolute:!0,onlyFiles:!0});if(r.length===0){t.errors.push({pattern:n,error:d.LOAD.NO_FILES_FOUND(n)});continue}t.files.push(...r)}catch(o){t.errors.push({pattern:n,error:d.LOAD.GLOB_ERROR(n,o instanceof Error?o.message:"Unknown error")})}return t}s(P,"resolveFiles");async function M(e){try{const t=await X(e,"utf-8");return JSON.parse(t)}catch(t){throw t instanceof Error&&t instanceof SyntaxError?new Error(d.LOAD.INVALID_JSON(e,t.message)):t}}s(M,"loadTree");function Lt(e){const t=new Set;if(e.modes)for(const n of Object.values(e.modes))for(const o of n)t.add(o);if(e.themes)for(const n of Object.values(e.themes))if(Array.isArray(n))for(const o of n)t.add(o);else{for(const o of n.source)t.add(o);if(n.modes)for(const o of Object.values(n.modes))for(const r of o)t.add(r)}return t}s(Lt,"collectVariantPaths");async function _t(e){const t=[],n=[];if(!e.tokens)return{trees:[],errors:[]};const o=Array.isArray(e.tokens)?{default:{source:e.tokens}}:"source"in e.tokens?{default:e.tokens}:e.tokens;if(!Object.values(o).some(i=>i.source.some(a=>{try{return Z.sync(a).length>0}catch{return!1}})))return{trees:[],errors:[{file:C,message:d.LOAD.NO_FILES_FOUND(Object.values(o).flatMap(i=>i.source).join(", "))}]};for(const[i,a]of Object.entries(o)){const c=Lt(a),{files:u,errors:l}=await P(Array.isArray(a.source)?a.source:[a.source]);if(l.length>0){t.push(...l.map(p=>({file:p.pattern,message:p.error})));continue}for(const p of u){const f=D(process.cwd(),p);if(!c.has(f))try{const h=await M(p),m={collection:i,tokens:h,sourcePath:f};n.push(m)}catch(h){t.push({file:p,message:h instanceof Error?h.message:"Unknown error"})}}if(a.modes)for(const[p,f]of Object.entries(a.modes))try{const{files:h,errors:m}=await P(f);if(m.length>0){t.push(...m.map(I=>({file:I.pattern,message:I.error})));continue}for(const I of h)try{const g=await M(I),A={collection:i,mode:p,tokens:g,sourcePath:D(process.cwd(),I)};n.push(A)}catch(g){t.push({file:I,message:g instanceof Error?g.message:"Unknown error"})}}catch(h){t.push({file:f.join(", "),message:h instanceof Error?h.message:"Unknown error"})}if(a.themes)for(const[p,f]of Object.entries(a.themes)){const h=Array.isArray(f)?f:f.source;try{const{files:m,errors:I}=await P(h);if(I.length>0){t.push(...I.map(g=>({file:g.pattern,message:g.error})));continue}for(const g of m)try{const A=await M(g),T={collection:i,theme:p,tokens:A,sourcePath:D(process.cwd(),g)};n.push(T)}catch(A){t.push({file:g,message:A instanceof Error?A.message:"Unknown error"})}}catch(m){t.push({file:h.join(", "),message:m instanceof Error?m.message:"Unknown error"})}if(!Array.isArray(f)&&f.modes)for(const[m,I]of Object.entries(f.modes))try{const{files:g,errors:A}=await P(I);if(A.length>0){t.push(...A.map(T=>({file:T.pattern,message:T.error})));continue}for(const T of g)try{const N=await M(T),nt={collection:i,theme:p,mode:m,tokens:N,sourcePath:D(process.cwd(),T)};n.push(nt)}catch(N){t.push({file:T,message:N instanceof Error?N.message:"Unknown error"})}}catch(g){t.push({file:I.join(", "),message:g instanceof Error?g.message:"Unknown error"})}}}return{trees:n,errors:t}}s(_t,"loadTreesFromConfig");async function Dt(e){const t=[],n=[],o=Object.entries(e);o.sort(([,r],[,i])=>{const a=!r.theme&&!r.mode,c=!i.theme&&!i.mode;return a&&!c?-1:!a&&c?1:0});for(const[r,{collection:i,theme:a,mode:c,content:u}]of o)try{const l=JSON.parse(u);t.push({collection:i,theme:a,mode:c,tokens:l,sourcePath:D(process.cwd(),r)})}catch(l){l instanceof Error?l instanceof SyntaxError?n.push({file:r,message:d.LOAD.INVALID_JSON(r,l.message)}):n.push({file:r,message:l.message}):n.push({file:r,message:"Unknown error"})}return{trees:t,errors:n}}s(Dt,"loadTreesFromMemory");function U(e,t,n,o){return typeof t=="string"&&$(t)?kt(e,t,n,o):Array.isArray(t)?t.map(r=>U(e,r,n,o)):typeof t=="object"&&t!==null?Object.entries(t).reduce((i,[a,c])=>Object.assign(i,{[a]:U(`${e}.${a}`,c,n,o)}),{}):t}s(U,"resolveValue");function Le(e,t){const n=e.slice(1,-1),o=t.pathIndex.get(n);if(!o)return;const r=t.tokens[o];if(!(!r||!("$value"in r))){if(r.$type)return r.$type;if(typeof r.$value=="string"&&$(r.$value))return Le(r.$value,t)}}s(Le,"inferTypeFromReference");function vt(e){const t={},n=new Set,o=[];for(const[r,i]of Object.entries(e.tokens))try{if(!("$value"in i)){t[r]=i;continue}const a=i;let c=a.$type;!c&&typeof a.$value=="string"&&$(a.$value)&&(c=Le(a.$value,e)),t[r]={...a,...c?{$type:c}:{},$resolvedValue:U(a.$path,a.$value,e,n)}}catch(a){const c=a instanceof Error?a.message:String(a),u=i,l=u.$path,p=u.$source;let f,h;c.includes("Circular reference detected")?(f="circular",h=c):c.includes("Reference not found")?(f="missing",h=c):(f="type-mismatch",h=d.RESOLVE.TYPE_MISMATCH(l)),o.push({type:f,path:l,source:p,message:h})}return{resolved:t,errors:o}}s(vt,"resolve");function kt(e,t,n,o){const r=t.slice(1,-1),i=n.pathIndex.get(r);if(!i)throw new Error(d.RESOLVE.REFERENCE_NOT_FOUND(r,e));if(o.has(i)){const u=n.tokens[i];throw!u||!("$path"in u)?new Error(d.RESOLVE.REFERENCE_NOT_FOUND(r,e)):new Error(d.RESOLVE.CIRCULAR_REFERENCE(e,u.$path))}const a=n.tokens[i];if(!a||!("$value"in a))throw new Error(d.RESOLVE.REFERENCE_NOT_FOUND(r,e));o.add(i);const c=U(i,a.$value,n,o);return o.delete(i),c}s(kt,"resolveReferenceChain");function O(e){return{success:!0,value:e}}s(O,"success");function E(e){return{success:!1,error:e}}s(E,"error");function se(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(o=>typeof o=="number"||o==="none")||t.alpha!==void 0&&typeof t.alpha!="number"||t.hex!==void 0&&typeof t.hex!="string")}s(se,"isW3CColorValue");function G(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((o,r)=>{o!=="none"&&(typeof o!="number"||!Number.isFinite(o))&&t.push(`Component ${r} must be a finite number or "none".`)}),e.colorSpace==="oklch"){const[o,r,i]=e.components;o!=="none"&&(o<0||o>1)&&t.push("OKLCH Lightness (L) must be between 0 and 1 or 'none'."),r!=="none"&&r<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[o,r,i]=e.components;o!=="none"&&(o<0||o>1)&&t.push("Display P3 Red component must be between 0 and 1 or 'none'."),r!=="none"&&(r<0||r>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[o,r,i]=e.components;o!=="none"&&(o<0||o>1)&&t.push("sRGB Red component must be between 0 and 1 or 'none'."),r!=="none"&&(r<0||r>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[o,r,i]=e.components;o!=="none"&&(o<0||o>=360)&&t.push("HSL Hue must be between 0 and 360 (exclusive) or 'none'."),r!=="none"&&(r<0||r>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(G,"validateW3CColorValue");function Ft(e){const t=G(e);return t.length>0?E(t.join(", ")):O(e)}s(Ft,"validateW3CColorValueResult");function Ct(e){const t=Ft(e);if(!t.success)return t;const[n,o,r]=e.components,i=e.alpha,a=n==="none"?"none":Number(n.toFixed(4)),c=o==="none"?"none":Number(o.toFixed(4)),u=r==="none"?"none":Number(r.toFixed(4));if(i!==void 0&&i!==1){const l=Number(i.toFixed(4));return O(`oklch(${a} ${c} ${u} / ${l})`)}return O(`oklch(${a} ${c} ${u})`)}s(Ct,"formatW3CColorToOKLCH");const wt={isObject:s(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObject")};function b(e,t,n,o){if($(t))return[];switch(e.type){case"object":return xt(e,t,n,o);case"union":return Rt(e,t,n,o);case"array":return jt(e,t,n,o);default:return Vt(e,t,n,o)}}s(b,"validateSchema");function Vt(e,t,n,o){return e.type!==typeof t?[{path:n,message:e.errorMessage?.(t,n)||d.VALIDATE.INVALID_TYPE(e.type,t,n),source:o}]:e.validate?.(t,n,o)??[]}s(Vt,"validateSimpleValue");function xt(e,t,n,o){if(!wt.isObject(t))return[{path:n,message:e.errorMessage?.(t,n)||d.VALIDATE.INVALID_TYPE("object",t,n),source:o}];const r=[],i=t;if(e.required)for(const a of e.required)a in i||r.push({path:`${n}.${a}`,message:d.VALIDATE.MISSING_REQUIRED_PROPERTY(a,n),source:o});for(const[a,c]of Object.entries(e.properties))a in i&&r.push(...b(c,i[a],`${n}.${a}`,o));return r}s(xt,"validateObject");function Rt(e,t,n,o){let r=[],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=b(a,t,n,o);if(c.length===0)return a.validate?.(t,n,o)??[];c.length<i&&(r=c,i=c.length)}return i===Number.POSITIVE_INFINITY?[{path:n,message:d.VALIDATE.INVALID_TYPE(e.oneOf.map(a=>a.type).join(" or "),t,n),source:o}]:r}s(Rt,"validateUnion");function jt(e,t,n,o){return Array.isArray(t)?e.validate?.(t,n,o)??[]:[{path:n,message:e.errorMessage?.(t,n)||d.VALIDATE.INVALID_TYPE("array",t,n),source:o}]}s(jt,"validateArray");const B={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:d.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)=>se(e)?G(e).map(r=>({path:t,message:`Invalid color at ${t}: ${r}`,source:n})):[{path:t,message:d.VALIDATE.INVALID_COLOR(e,t),source:n}],"validate")}]}};function Pt(e,t,n){return b(B.schema,e,t,n)}s(Pt,"validateColor");const W={schema:{type:"number",errorMessage:s((e,t)=>d.VALIDATE.INVALID_NUMBER(e,t),"errorMessage"),validate:s((e,t,n)=>typeof e!="number"||Number.isNaN(e)?[{path:t,message:d.VALIDATE.INVALID_NUMBER(e,t),source:n}]:[],"validate")}};function Mt(e,t,n){return b(W.schema,e,t,n)}s(Mt,"validateNumber");const S={schema:{type:"object",errorMessage:s((e,t)=>d.VALIDATE.INVALID_DIMENSION(e,t),"errorMessage"),properties:{value:W.schema,unit:{type:"string",validate:s((e,t,n)=>typeof e!="string"||!["px","rem"].includes(e)?[{path:t,message:d.VALIDATE.INVALID_DIMENSION_UNIT(e,t),source:n}]:[],"validate")}},required:["value","unit"]}};function Ut(e,t,n){return b(S.schema,e,t,n)}s(Ut,"validateDimension");const _e={schema:{type:"union",oneOf:[{type:"string",errorMessage:s((e,t)=>d.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")},{type:"array",errorMessage:s((e,t)=>d.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage"),validate:s((e,t,n)=>e.every(r=>typeof r=="string")?[]:[{path:t,message:d.VALIDATE.INVALID_FONT_FAMILY(e,t),source:n}],"validate")}],errorMessage:s((e,t)=>d.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")}};function Gt(e,t,n){return b(_e.schema,e,t,n)}s(Gt,"validateFontFamily");const Bt=["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"],De={schema:{type:"union",errorMessage:s((e,t)=>d.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),oneOf:[{type:"number",errorMessage:s((e,t)=>d.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:s((e,t,n)=>e<1||e>1e3?[{path:t,message:d.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}]:[],"validate")},{type:"string",errorMessage:s((e,t)=>d.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:s((e,t,n)=>Bt.includes(e.toLowerCase())?[]:[{path:t,message:d.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}],"validate")}]}};function Wt(e,t,n){return b(De.schema,e,t,n)}s(Wt,"validateFontWeight");const Yt=["ms","s"],ie={schema:{type:"object",errorMessage:s((e,t)=>d.VALIDATE.INVALID_DURATION(e,t),"errorMessage"),properties:{value:W.schema,unit:{type:"string",validate:s((e,t,n)=>Yt.includes(e)?[]:[{path:t,message:d.VALIDATE.INVALID_DURATION_UNIT(e,t),source:n}],"validate")}},required:["value","unit"]}};function Kt(e,t,n){return b(ie.schema,e,t,n)}s(Kt,"validateDuration");const ve={schema:{type:"array",errorMessage:s((e,t)=>d.VALIDATE.INVALID_CUBIC_BEZIER(e,t),"errorMessage"),validate:s((e,t,n)=>{const o=e;if(o.length!==4||!o.every(a=>typeof a=="number"))return[{path:t,message:d.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}];const[r,,i]=o;return r<0||r>1||i<0||i>1?[{path:t,message:d.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}]:[]},"validate")}};function Ht(e,t,n){return b(ve.schema,e,t,n)}s(Ht,"validateCubicBezier");const zt={schema:{type:"object",properties:{fontFamily:_e.schema,fontSize:S.schema,letterSpacing:S.schema,lineHeight:W.schema,fontWeight:De.schema},required:["fontFamily","fontSize"],errorMessage:s((e,t)=>d.VALIDATE.INVALID_TYPOGRAPHY(e,t),"errorMessage")}};function qt(e,t,n){return b(zt.schema,e,t,n)}s(qt,"validateTypography");const Jt=["solid","dashed","dotted","double","groove","ridge","outset","inset"],Xt=["round","butt","square"],Zt={type:"object",errorMessage:s((e,t)=>d.VALIDATE.INVALID_STROKE_STYLE(e,t),"errorMessage"),properties:{dashArray:{type:"array",validate:s((e,t,n)=>{const o=e,r=[];return o.forEach((i,a)=>{typeof i!="string"&&r.push(...b(S.schema,i,`${t}.${a}`,n))}),r},"validate")},lineCap:{type:"string",validate:s((e,t,n)=>Xt.includes(e)?[]:[{path:t,message:d.VALIDATE.INVALID_STROKE_LINE_CAP(e,t),source:n}],"validate")}},required:["dashArray","lineCap"]},ke={schema:{type:"union",oneOf:[{type:"string",validate:s((e,t,n)=>!Jt.includes(e)&&typeof e=="string"?[{path:t,message:d.VALIDATE.INVALID_STROKE_STYLE(e,t),source:n}]:[],"validate")},Zt]}};function Qt(e,t,n){return b(ke.schema,e,t,n)}s(Qt,"validateStrokeStyle");const en={schema:{type:"object",properties:{color:B.schema,width:S.schema,style:ke.schema},required:["color","width","style"],errorMessage:s((e,t)=>d.VALIDATE.INVALID_BORDER(e,t),"errorMessage")}};function tn(e,t,n){return b(en.schema,e,t,n)}s(tn,"validateBorder");const nn={schema:{type:"object",properties:{duration:ie.schema,delay:ie.schema,timingFunction:ve.schema},required:["duration","delay","timingFunction"],errorMessage:s((e,t)=>d.VALIDATE.INVALID_TRANSITION(e,t),"errorMessage")}};function on(e,t,n){return b(nn.schema,e,t,n)}s(on,"validateTransition");const Fe={schema:{type:"object",properties:{color:{type:"union",oneOf:[B.schema]},offsetX:S.schema,offsetY:S.schema,blur:S.schema,spread:S.schema,inset:{type:"boolean",errorMessage:s((e,t)=>d.VALIDATE.INVALID_SHADOW_INSET(e,t),"errorMessage")}},required:["color","offsetX","offsetY","blur","spread"],errorMessage:s((e,t)=>d.VALIDATE.INVALID_SHADOW(e,t),"errorMessage")}};function rn(e,t,n){const o=[];return Array.isArray(e)?(e.forEach((r,i)=>{o.push(...b(Fe.schema,r,`${t}[${i}]`,n))}),o):b(Fe.schema,e,t,n)}s(rn,"validateShadow");const sn={type:"object",errorMessage:s((e,t)=>d.VALIDATE.INVALID_GRADIENT(e,t),"errorMessage"),properties:{color:B.schema,position:{type:"number",validate:s((e,t,n)=>e<0||e>1?[{path:t,message:d.VALIDATE.INVALID_GRADIENT_STOP_POSITION(e,t),source:n}]:[],"validate")}},required:["color","position"]},an={schema:{type:"array",errorMessage:s((e,t)=>d.VALIDATE.INVALID_ARRAY(e,t),"errorMessage"),validate:s((e,t,n)=>{const o=e,r=[];return o.forEach((i,a)=>{r.push(...b(sn,i,`${t}[${a}]`,n))}),r},"validate")}};function cn(e,t,n){return b(an.schema,e,t,n)}s(cn,"validateGradient");const un={schema:{type:"object",errorMessage:s((e,t)=>d.VALIDATE.INVALID_FLUID_DIMENSION(e,t),"errorMessage"),properties:{min:S.schema,max:S.schema},required:["min","max"]}};function ln(e,t,n){return b(un.schema,e,t,n)}s(ln,"validateFluidDimension");const fn={color:Pt,dimension:Ut,fluidDimension:ln,duration:Kt,cubicBezier:Ht,fontFamily:Gt,fontWeight:Wt,number:Mt,strokeStyle:Qt,typography:qt,border:tn,shadow:rn,gradient:cn,transition:on};function pn(e){const t=[];for(const[n,o]of Object.entries(e.tokens)){if(typeof o!="object"||o===null||!("$type"in o)||!("$path"in o)||o.$path.startsWith("$"))continue;if(!("$value"in o)){t.push({path:o.$path,message:d.VALIDATE.MISSING_REQUIRED_PROPERTY("$value",o.$path),source:o.$source});continue}const r=fn[o.$type];if(!r){t.push({path:o.$path,message:d.VALIDATE.UNKNOWN_TOKEN_TYPE(o.$type,o.$path),source:o.$source});continue}const i=o;t.push(...r(i.$value,i.$path,i.$source))}return t}s(pn,"validate");async function dn(e){const{trees:t,errors:n}=await(e.type==="memory"?Dt(e.data):_t(e.config)),{tokens:o,errors:r}=Ot(t),i=pn(o),{resolved:a,errors:c}=vt(o);return{trees:t,resolved:a,errors:{load:n,flatten:r,validation:i,resolution:c}}}s(dn,"loadAndResolveTokens");function Ce(e){return $(e)?{value:e}:typeof e=="string"?{value:e}:{value:`${e.dashArray.map(n=>$(n)?n:`${n.value}${n.unit}`).join(" ")} ${e.lineCap}`}}s(Ce,"convertStrokeStyleToken");function hn(e){if($(e))return{value:e};const t=$(e.width)?e.width:`${e.width.value}${e.width.unit}`,n=($(e.color),e.color),o=typeof e.style=="string"?e.style:Ce(e.style).value;return{value:`${t} ${o} ${n}`}}s(hn,"convertBorderToken");function we(e,t="native"){return se(e)?mn(e):O(e)}s(we,"convertColorToString");function mn(e){switch(e.colorSpace){case"oklch":return Ct(e);case"display-p3":return yn(e);case"srgb":return In(e);case"hsl":return $n(e);default:return E(`Unsupported color space: ${e.colorSpace}. Supported color spaces: oklch, display-p3, srgb, hsl.`)}}s(mn,"formatW3CColorNative");function yn(e){if(e.colorSpace!=="display-p3")return E(`Expected display-p3 color space, got: ${e.colorSpace}`);if(!Array.isArray(e.components)||e.components.length!==3)return E("Display P3 components must be an array of exactly 3 numbers [R, G, B]");const[t,n,o]=e.components,r=e.alpha;if(t!=="none"&&(t<0||t>1))return E("Display P3 Red component must be between 0 and 1 or 'none'");if(n!=="none"&&(n<0||n>1))return E("Display P3 Green component must be between 0 and 1 or 'none'");if(o!=="none"&&(o<0||o>1))return E("Display P3 Blue component must be between 0 and 1 or 'none'");if(r!==void 0&&(r<0||r>1))return E("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=o==="none"?"none":Number(o.toFixed(4));if(r!==void 0&&r!==1){const u=Number(r.toFixed(4));return O(`color(display-p3 ${i} ${a} ${c} / ${u})`)}return O(`color(display-p3 ${i} ${a} ${c})`)}s(yn,"formatW3CColorToP3");function In(e){if(e.colorSpace!=="srgb")return E(`Expected srgb color space, got: ${e.colorSpace}`);const t=G(e);if(t.length>0)return E(`Invalid W3C color value: ${t.join(", ")}`);const[n,o,r]=e.components,i=e.alpha,a=n==="none"?"none":Math.round(n*255),c=o==="none"?"none":Math.round(o*255),u=r==="none"?"none":Math.round(r*255);if(i!==void 0&&i!==1){const l=Number(i.toFixed(4));return O(`rgb(${a} ${c} ${u} / ${l})`)}return O(`rgb(${a} ${c} ${u})`)}s(In,"formatW3CColorToRGB");function $n(e){if(e.colorSpace!=="hsl")return E(`Expected hsl color space, got: ${e.colorSpace}`);const t=G(e);if(t.length>0)return E(`Invalid W3C color value: ${t.join(", ")}`);const[n,o,r]=e.components,i=e.alpha,a=n==="none"?"none":Number(n.toFixed(1)),c=o==="none"?"none":Math.round(o),u=r==="none"?"none":Math.round(r);if(i!==void 0&&i!==1){const f=Number(i.toFixed(4)),h=c==="none"?"none":`${c}%`,m=u==="none"?"none":`${u}%`;return O(`hsl(${a} ${h} ${m} / ${f})`)}const l=c==="none"?"none":`${c}%`,p=u==="none"?"none":`${u}%`;return O(`hsl(${a} ${l} ${p})`)}s($n,"formatW3CColorToHSL");function gn(e,t){if(typeof e=="string"&&$(e))return{value:e};const n=t.colorFallbackStrategy;if(se(e))return An(e,n);const o=we(e,n);return o.success?{value:o.value}:(console.warn(`Failed to convert color ${typeof e=="string"?e:"W3C color object"}: ${o.error}`),{value:typeof e=="string"?e:"#000000"})}s(gn,"convertColorToken");function An(e,t){const n=we(e,t);if(!n.success)return console.warn(`Failed to convert W3C color: ${n.error}`),{value:"#000000"};const o=n.value;if(t==="native")return{value:o};if(e.colorSpace==="srgb"||e.colorSpace==="hsl")return{value:o};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:Tn(e.colorSpace),value:o}]}}s(An,"convertW3CColorToken");function Tn(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(Tn,"getFeatureQuery");function bn(e){return $(e)?{value:e}:{value:`cubic-bezier(${e.join(", ")})`}}s(bn,"convertCubicBezierToken");function En(e){return $(e)?{value:e}:{value:`${e.value}${e.unit}`}}s(En,"convertDimensionToken");function Nn(e){return $(e)?{value:e}:{value:`${e.value}${e.unit}`}}s(Nn,"convertDurationToken");function Ve(e,t=16){return e.unit==="px"?e.value:e.value*t}s(Ve,"normalizeToPixels");function Sn(e,t){const{min:n,max:o}=e,r=t.fluidConfig,i=16,a=Ve(n,i),c=Ve(o,i),u=r.min,l=r.max;if(a===c)return{value:`${a/i}rem`};const p=a/i,f=c/i,h=u/i,m=l/i,I=(f-p)/(m-h),g=-1*h*I+p;return{value:`clamp(${p}rem, ${g.toFixed(2)}rem + ${(I*100).toFixed(2)}vw, ${f}rem)`}}s(Sn,"convertFluidDimension");function On(e,t){return $(e)?{value:e}:Sn(e,t)}s(On,"convertFluidDimensionToken");function Y(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(Y,"quoteFont");function Ln(e){return $(e)?{value:e}:{value:Array.isArray(e)?e.map(n=>Y(n)).join(", "):Y(e)}}s(Ln,"convertFontFamilyToken");const _n={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 xe(e){return $(e)?{value:e}:typeof e=="number"?{value:e}:{value:_n[e.toLowerCase()]??e}}s(xe,"convertFontWeightToken");function Dn(e){return $(e)?{value:e}:{value:`linear-gradient(${e.map(n=>{const o=($(n.color),n.color),r=$(n.position)?n.position:`${n.position*100}`;return`${o} ${r}%`}).join(", ")})`}}s(Dn,"convertGradientToken");function vn(e){return $(e)?{value:e}:{value:e}}s(vn,"convertNumberToken");function Re(e){const t=$(e.offsetX)?e.offsetX:`${e.offsetX.value}${e.offsetX.unit}`,n=$(e.offsetY)?e.offsetY:`${e.offsetY.value}${e.offsetY.unit}`,o=$(e.blur)?e.blur:`${e.blur.value}${e.blur.unit}`,r=$(e.spread)?e.spread:`${e.spread.value}${e.spread.unit}`,i=($(e.color),e.color);return`${e.inset?"inset ":""}${t} ${n} ${o} ${r} ${i}`}s(Re,"convertSingleShadow");function kn(e){return $(e)?{value:e}:Array.isArray(e)?{value:e.map(Re).join(", ")}:{value:Re(e)}}s(kn,"convertShadowToken");function je(e){return e?`${e.value}${e.unit}`:"0ms"}s(je,"formatDuration");function Fn(e){if($(e))return{value:e};const t=$(e.duration)?e.duration:je(e.duration),n=$(e.timingFunction)?e.timingFunction:`cubic-bezier(${e.timingFunction.join(", ")})`,o=e.delay&&($(e.delay)?e.delay:je(e.delay));return{value:[t,n,o].filter(Boolean).join(" ")}}s(Fn,"convertTransitionToken");function Cn(e){if($(e))return{"font-family":e,"font-size":e};const t={"font-family":$(e.fontFamily)?e.fontFamily:Array.isArray(e.fontFamily)?e.fontFamily.map(n=>Y(n)).join(", "):Y(e.fontFamily),"font-size":$(e.fontSize)?e.fontSize:`${e.fontSize.value}${e.fontSize.unit}`};return e.fontWeight&&(t["font-weight"]=$(e.fontWeight)?e.fontWeight:xe(e.fontWeight).value),e.letterSpacing&&(t["letter-spacing"]=$(e.letterSpacing)?e.letterSpacing:`${e.letterSpacing.value}${e.letterSpacing.unit}`),e.lineHeight&&(t["line-height"]=($(e.lineHeight),e.lineHeight)),t}s(Cn,"convertTypographyToken");const Pe={duration:Nn,number:vn,cubicBezier:bn,color:gn,dimension:En,fluidDimension:On,typography:Cn,border:hn,shadow:kn,gradient:Dn,transition:Fn,strokeStyle:Ce,fontFamily:Ln,fontWeight:xe};function wn(e,t){const n=Pe[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(wn,"convertSingleToken");function ae(e,t,n){const o={};for(const[r,i]of Object.entries(e)){if(!i||typeof i!="object")continue;if(!("$type"in i)){o[r]={...i.$description?{$description:i.$description}:{},...i.$extensions?{$extensions:i.$extensions}:{}};continue}if(n?.(i.$path)){console.log(`[sugarcube] Skipping invalid token: ${i.$path} (has validation error)`);continue}if(!Pe[i.$type])continue;const a={fluidConfig:t.transforms.fluid,colorFallbackStrategy:t.transforms.colorFallbackStrategy,path:i.$path,resolvedTokens:e};o[r]=wn(i,a)}return o}s(ae,"convertTokens");function Vn(e,t,n){const o={};for(const[r,i]of Object.entries(e)){const a={default:{default:ae(i.default?.default||{},t,n)}};for(const[c,u]of Object.entries(i)){const l={default:ae(u?.default||{},t,n)};for(const[p,f]of Object.entries(u||{}))p!=="default"&&(l[p]=ae(f,t,n));a[c]=l}o[r]=a}return o}s(Vn,"convert");function xn(e){const t=new Set,n=new Map,o=new Map;for(const u of e){const{collection:l,theme:p="default",mode:f="default"}=u;t.add(l),n.has(l)||n.set(l,new Set),n.get(l)?.add(p);const h=`${l}:${p}`;o.has(h)||o.set(h,new Set),o.get(h)?.add(f)}const r={};function i(u){return r[u]||(r[u]={default:{default:{}}}),r[u]}s(i,"ensureCollection");function a(u,l){return u[l]||(u[l]={default:{}}),u[l]}s(a,"ensureTheme");function c(u,l){return u[l]||(u[l]={}),u[l]}s(c,"ensureMode");for(const u of t){const l=i(u),p=n.get(u);if(p)for(const f of p){const h=a(l,f),m=`${u}:${f}`,I=o.get(m);if(I)for(const g of I)c(h,g)}}for(const u of e){const{collection:l,theme:p="default",mode:f="default",tokens:h}=u,m=i(l),I=a(m,p),g=c(I,f);for(const[A,T]of Object.entries(h)){const N=A.replace(`${l}.`,"");g[N]=T}}return{tokens:r}}s(xn,"normalizeTokens");function ce(e,t){return`${e??""}:${t??""}`}s(ce,"createVariantKey");function Rn(e,t){const n=new Map;for(const[o,r]of Object.entries(t)){if(!("$source"in r)){for(const f of e){const h=f.collection;n.has(h)||n.set(h,new Map);const m=n.get(h);if(!m)continue;const I=ce(f.theme,f.mode);m.has(I)||m.set(I,{});const g=m.get(I);g&&(g[o]=r)}continue}const i=r.$source.collection,a=r.$source.theme,c=r.$source.mode,u=ce(a,c);n.has(i)||n.set(i,new Map);const l=n.get(i);if(!l)continue;l.has(u)||l.set(u,{});const p=l.get(u);p&&(p[o]=r)}return e.map(o=>{const r=n.get(o.collection);if(!r)return{collection:o.collection,theme:o.theme,mode:o.mode,tokens:{}};const i=ce(o.theme,o.mode),a=r.get(i)||{};return{collection:o.collection,theme:o.theme,mode:o.mode,tokens:a}})}s(Rn,"processTrees");async function jn(e,t,n,o){const r=Rn(e,t),{tokens:i}=xn(r);return Vn(i,n,o?u=>o.some(l=>l.path===u||l.path.startsWith(`${u}.`)):void 0)}s(jn,"processAndConvertTokens");const K=["reset","global","compositions","blocks","utilities"];async function ue(e,t){const n=[],o=await Z([L(e,"**/*.css"),L(e,"**/*.scss"),L(e,"**/*.sass"),L(e,"**/*.less")],{ignore:[L(e,R)]});for(const r of o){const i=Pn(r,e);if(i){const a=D(e,r);n.push({path:a,layer:i,relativePath:a})}}return n}s(ue,"discoverAllFiles");function Pn(e,t){const n=D(t,e);if(n.includes("global/")||n.startsWith("global/"))return Ae(e).includes("reset")?"reset":"global";if(n.includes("compositions/")||n.startsWith("compositions/"))return"compositions";if(n.includes("blocks/")||n.startsWith("blocks/"))return"blocks";if(n.includes("utilities/")||n.startsWith("utilities/"))return"utilities"}s(Pn,"categorizeFile");function Mn(e){return e.sort((t,n)=>{const o=K.indexOf(t.layer),r=K.indexOf(n.layer);return o!==r?o-r:t.path.localeCompare(n.path)})}s(Mn,"sortFilesByLayer");function Un(){return`@layer ${K.join(", ")};
|
|
18
|
-
`
|
|
19
|
-
`)}
|
|
17
|
+
`}]}s(Nr,"generateSingleFile");async function Tr(e,t,n){const r={};for(const[o,i]of Object.entries(e))Object.keys(i).length>0&&(r[o]=i);return{output:await Nr(r,t,n)}}s(Tr,"generate");async function Sr(e,t,n){const{output:r}=await Tr(e,t,n);return r}s(Sr,"generateCSSVariables");const _="--",A="-",br=["all","full"],Ar={top:"t",right:"r",bottom:"b",left:"l",x:"x",y:"y",full:"",all:""},Or={top:"block-start",right:"inline-end",bottom:"block-end",left:"inline-start",x:"inline",y:"block"};function Dr(e){return Ar[e]}s(Dr,"getDirectionAbbreviation");function qe(e,t){if(t==="full"||t==="all")return e;const n=Or[t];return n?`${e}${A}${n}`:e}s(qe,"getLogicalProperty");const Rr=["top","right","bottom","left","x","y","full"];function Lr(e){return(Array.isArray(e)?e:[e]).flatMap(n=>n==="all"?Rr:[n])}s(Lr,"expandDirections");function _r(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(_r,"isTokenTypeValidForProperty");const ze=new WeakMap,R=new Map;function vr(){R.clear()}s(vr,"clearMatchCache");function xr(e){const t=ze.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 ze.set(e,n),n}s(xr,"buildPathIndex");function Cr(e){if(e.default)return e.default;const t=Object.keys(e);return t.length>0&&t[0]?e[t[0]]:null}s(Cr,"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=Cr(n);if(!i)return R.set(r,null),null;const a=xr(i);for(const c of o){const u=a.get(c);if(u){if(t.property&&u.$type&&!_r(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 se(e,t){return t.stripDuplicates&&t.prefix&&e.startsWith(`${t.prefix}-`)?e.slice(t.prefix.length+1):e}s(se,"stripDuplicatePrefix");function H(e,t=""){const n=e??"",r=n||t?A:"";return new RegExp(`^${n}${t}${r}(.+)$`)}s(H,"createUtilityPattern");function ie(e,t,n){return[H(t.prefix),o=>{const i=o[1];if(!i)return{};const a=se(i,t),c={...t,property:e},u=Y(a,c,n);return u?{[e]:`var(${_}${u.join(A)})`}:{}}]}s(ie,"createSimpleRule");function Vr(e,t,n,r){if(n==="all")return ie(e,t,r);const o=Dr(n);return[H(t.prefix,o),a=>{const c=a[1];if(!c)return{};const u=se(c,t),p={...t,property:e},m=Y(u,p,r);return m?{[qe(e,n)]:`var(${_}${m.join(A)})`}:{}}]}s(Vr,"createDirectionalRule");function wr(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=se(o,a),m={...a,property:i},d=Y(p,m,u);if(d)return c?{[qe(i,c)]:`var(${_}${d.join(A)})`}:{[i]:`var(${_}${d.join(A)})`}}return{}}]}s(wr,"createSmartRule");function Fr(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(A)})`}:{}}]}s(Fr,"createDirectTokenPathRule");function kr(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(kr,"validateUtilityConfig");function Mr(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(Mr,"validateInputs");function jr(e,t){Mr(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(kr(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=Fr(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=Lr(u.directions);(Array.isArray(u.directions)?u.directions:[u.directions]).includes("all")&&n.push(ie(c,u,p));for(const y of m)br.includes(y)||n.push(Vr(c,u,y,p))}else n.push(ie(c,u,p))}else n.push(wr(o,i));return n}s(jr,"convertConfigToUnoRules");const v=process.env.SUGARCUBE_PERF==="true";class Pr{static{s(this,"PerfMonitor")}constructor(t=n=>void process.stderr.write(`${n}
|
|
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 Je 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 Ur=process.env.DEBUG==="true";class Gr{static{s(this,"Instrumentation")}constructor(t=n=>void process.stderr.write(`${n}
|
|
19
|
+
`)){this.defaultFlush=t}#n=new Je(()=>({value:0}));#t=new Je(()=>({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
|
+
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(`
|
|
21
|
+
${n.join(`
|
|
22
|
+
`)}
|
|
23
|
+
`)}[Symbol.dispose](){Ur&&this.report()}}const Wr=`/*!
|
|
20
24
|
* This file was automatically generated by sugarcube.
|
|
21
25
|
* You should NOT make any changes in this file as it will be overwritten.
|
|
22
26
|
* To make changes, edit your design token files instead.
|
|
@@ -24,7 +28,7 @@ ${n.map(o=>` - ${o}`).join(`
|
|
|
24
28
|
* to prevent it from being checked or modified.
|
|
25
29
|
*/
|
|
26
30
|
|
|
27
|
-
`,
|
|
31
|
+
`,Br=`/*!
|
|
28
32
|
* This file was automatically generated by sugarcube.
|
|
29
33
|
* You should NOT make any changes in this file as it will be overwritten.
|
|
30
34
|
* To make changes, edit your utilities configuration instead.
|
|
@@ -32,13 +36,6 @@ ${n.map(o=>` - ${o}`).join(`
|
|
|
32
36
|
* to prevent it from being checked or modified.
|
|
33
37
|
*/
|
|
34
38
|
|
|
35
|
-
`;function
|
|
39
|
+
`;function K(e){return e.replace(/\r\n/g,`
|
|
36
40
|
`).replace(/\r/g,`
|
|
37
|
-
`).trim()}s(
|
|
38
|
-
`))}return t.data}s(z,"validateUserConfig");function he(e){const t=Ke.safeParse(e);if(!t.success){const n=t.error.errors.map(o=>{const r=o.path.join(".");return d.CONFIG.INVALID_CONFIG(r||"root",o.message)});throw new Error(n.join(`
|
|
39
|
-
`))}return Zn(t.data),t.data}s(he,"validateInternalConfig");function He(e){const t=z(e),n=de(t);return he(n)}s(He,"validateConfig");function Xn(e){try{const t=JSON.parse(e);return He(t)}catch(t){throw t instanceof SyntaxError?new Error(d.CONFIG.INVALID_JSON(t.message)):t}}s(Xn,"parseAndValidateConfig");function Zn(e){if(typeof e.tokens=="object")for(const[t,n]of Object.entries(e.tokens)){if(!n.source?.length)continue;const o=new Map;for(const r of n.source){const i=Ae(r),a=o.get(i)||[];o.set(i,[...a,r])}for(const[r,i]of o)if(i.length>1)throw new Error(d.CONFIG.DUPLICATE_FILENAMES(t,r,i))}}s(Zn,"validateFileNames");function me(e="sugarcube.config"){const t=[".ts",".js"];for(const n of t){const o=be(process.cwd(),`${e}${n}`);if(F(o))return o}return null}s(me,"findConfigFile");function Qn(e="sugarcube.config"){return me(e)!==null}s(Qn,"configFileExists");async function ze(e){try{await import("tsx");const t=rt(e).href,o=await new Function("url","return import(url)")(t);if(o&&typeof o=="object"&&"default"in o)return o.default;throw new Error(d.CONFIG.INVALID_CONFIG("root","Config file must export a default object"))}catch(t){throw t instanceof Error?new Error(d.CONFIG.INVALID_CONFIG("root",t.message)):t}}s(ze,"loadTSConfig");async function qe(e){if(e.endsWith(".ts")||e.endsWith(".js"))return await ze(e);const n=await x.readFile(e,"utf-8");return JSON.parse(n)}s(qe,"loadConfigFile");function Je(e){if(e)return be(process.cwd(),e);const t=me();if(!t)throw new Error(d.CONFIG.FILE_NOT_FOUND(C));return t}s(Je,"resolveConfigPath");async function eo(e){const t=Je(e);try{const n=await qe(t);return{config:z(n),configPath:t}}catch(n){throw n instanceof Error&&"code"in n&&n.code==="ENOENT"?new Error(d.CONFIG.FILE_NOT_FOUND(t)):n instanceof SyntaxError?new Error(d.CONFIG.INVALID_JSON(n.message)):n}}s(eo,"loadUserConfig");async function to(e){const t=Je(e);try{const n=await qe(t),o=z(n),r=de(o);return{config:he(r),configPath:t}}catch(n){throw n instanceof Error&&"code"in n&&n.code==="ENOENT"?new Error(d.CONFIG.FILE_NOT_FOUND(t)):n instanceof SyntaxError?new Error(d.CONFIG.INVALID_JSON(n.message)):n}}s(to,"loadInternalConfig");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 no=process.env.DEBUG==="true";class oo{static{s(this,"Instrumentation")}constructor(t=n=>void process.stderr.write(`${n}
|
|
40
|
-
`)){this.defaultFlush=t}#t=new Xe(()=>({value:0}));#n=new Xe(()=>({value:0n}));#e=[];hit(t){this.#t.get(t).value++}start(t){const n=this.#e.map(r=>r.label).join("//"),o=`${n}${n.length===0?"":"//"}${t}`;this.#t.get(o).value++,this.#n.get(o),this.#e.push({id:o,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 o=this.#e.length-1,r=this.#e[o];if(!r)throw new Error("Timer stack is corrupted");if(r.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.#n.get(i.id).value+=a}report(t=this.defaultFlush){const n=[];let o=!1;for(let r=this.#e.length-1;r>=0;r--){const i=this.#e[r];i&&this.end(i.label)}for(const[r,{value:i}]of this.#t.entries()){if(this.#n.has(r))continue;n.length===0&&(o=!0,n.push("Hits:"));const a=r.split("//").length;n.push(`${" ".repeat(a)}${r} \xD7 ${i}`)}if(this.#n.size>0){o&&n.push(`
|
|
41
|
-
Timers:`);for(const[r,{value:i}]of this.#n){const a=r.split("//").length,c=`${(Number(i)/1e6).toFixed(2)}ms`;n.push(`${" ".repeat(a-1)}${r.split("//").pop()} [${c}] ${this.#t.get(r).value===1?"":`\xD7 ${this.#t.get(r).value}`}`.trimEnd())}}t(`
|
|
42
|
-
${n.join(`
|
|
43
|
-
`)}
|
|
44
|
-
`)}[Symbol.dispose](){no&&this.report()}}const V="--",k="-",ro=["all","full"],so={top:"t",right:"r",bottom:"b",left:"l",x:"x",y:"y",full:"",all:""},io={top:"block-start",right:"inline-end",bottom:"block-end",left:"inline-start",x:"inline",y:"block"};function ao(e){return so[e]}s(ao,"getDirectionAbbreviation");function Ze(e,t){if(t==="full"||t==="all")return e;const n=io[t];return n?`${e}${k}${n}`:e}s(Ze,"getLogicalProperty");const co=["top","right","bottom","left","x","y","full"];function uo(e){return(Array.isArray(e)?e:[e]).flatMap(n=>n==="all"?co:[n])}s(uo,"expandDirections");function Qe(e,t){const o={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 o?o.includes(e):!0}s(Qe,"isTokenTypeValidForProperty");const et=new WeakMap;function tt(e){const t=et.get(e);if(t)return t;const n=new Map;for(const o of Object.values(e)){if(!("$path"in o))continue;const r=o;n.set(r.$path,r)}return et.set(e,n),n}s(tt,"buildPathIndex");function q(e,t,n){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(".")}`)}}if(t.collection){const c=n[t.collection];if(!c)return null;const u=c[fe];if(!u)return null;const l=u[pe];if(!l)return null;const p=tt(l);for(const f of o){const h=p.get(f);if(h){if(t.property&&h.$type&&!Qe(h.$type,t.property))continue;return h.$path.split(".")}}return null}const r=[],i=Object.keys(n).sort();for(const c of i){const u=n[c];if(!u)continue;const l=u[fe];if(!l)continue;const p=l[pe];if(!p)continue;const f=tt(p);for(const h of o){const m=f.get(h);if(m){if(t.property&&m.$type&&!Qe(m.$type,t.property))continue;r.push({collection:c,token:m});break}}}if(r.length===0)return null;if(r.length>1){const c=r.map(p=>p.collection).join(", "),u=r[0];if(!u)return null;const l=u.token.$path;throw new Error(d.UTILITIES.TOKEN_PATH_CONFLICT(l,c))}const a=r[0];return a?a.token.$path.split("."):null}s(q,"findMatchingToken");function ye(e,t){return t.stripDuplicates&&t.prefix&&e.startsWith(`${t.prefix}-`)?e.slice(t.prefix.length+1):e}s(ye,"stripDuplicatePrefix");function J(e,t=""){const n=e??"",o=n||t?k:"";return new RegExp(`^${n}${t}${o}(.+)$`)}s(J,"createUtilityPattern");function Ie(e,t,n){return[J(t.prefix),r=>{const i=r[1];if(!i)return{};const a=ye(i,t),c={...t,property:e},u=q(a,c,n);return u?{[e]:`var(${V}${u.join(k)})`}:{}}]}s(Ie,"createSimpleRule");function lo(e,t,n,o){if(n==="all")return Ie(e,t,o);const r=ao(n);return[J(t.prefix,r),a=>{const c=a[1];if(!c)return{};const u=ye(c,t),l={...t,property:e},p=q(u,l,o);return p?{[Ze(e,n)]:`var(${V}${p.join(k)})`}:{}}]}s(lo,"createDirectionalRule");function fo(e,t){return[J(e),o=>{const r=o[1];if(!r)return{};for(const{property:i,config:a,direction:c,tokens:u}of t){const l=ye(r,a),p={...a,property:i},f=q(l,p,u);if(f)return c?{[Ze(i,c)]:`var(${V}${f.join(k)})`}:{[i]:`var(${V}${f.join(k)})`}}return{}}]}s(fo,"createSmartRule");function po(e,t,n){const o=t.source.indexOf("."),r=o!==-1?t.source.slice(0,o):t.source;return[J(r),a=>{const c=a[1];if(!c)return{};const u={...t,property:e},l=q(c,u,n);return l?{[e]:`var(${V}${l.join(k)})`}:{}}]}s(po,"createDirectTokenPathRule");function ho(e,t){if(!e?.source||typeof e.source!="string")throw new Error(d.UTILITIES.MISSING_SOURCE(t));if(e.source.includes("*")&&!e.source.endsWith(".*"))throw new Error(d.UTILITIES.INVALID_SOURCE_PATTERN(t,e.source));if(e.directions&&!Array.isArray(e.directions))throw new Error(d.UTILITIES.INVALID_DIRECTIONS(t))}s(ho,"validateUtilityConfig");function mo(e,t){if(!e||typeof e!="object")throw new Error(d.UTILITIES.INVALID_CONFIG_OBJECT);if(!t||typeof t!="object")throw new Error(d.UTILITIES.INVALID_TOKENS_OBJECT);const n=Object.keys(t);for(const[o,r]of Object.entries(e)){const i=Array.isArray(r)?r:[r];for(const a of i)if(a.collection&&!n.includes(a.collection))throw new Error(d.UTILITIES.INVALID_COLLECTION(o,a.collection,n))}}s(mo,"validateInputs");function yo(e,t){mo(e,t);const n=[],o={};for(const[r,i]of Object.entries(e)){const a=Array.isArray(i)?i:[i];for(const c of a)if(ho(c,r),c.prefix){const u=c.prefix;o[u]||(o[u]=[]),o[u].push({property:r,config:c,direction:null,tokens:t})}else{const u=po(r,c,t);n.push(u)}}for(const[r,i]of Object.entries(o))if(i.length===1){const a=i[0];if(!a)continue;const{property:c,config:u,tokens:l}=a;if(u.directions){const p=uo(u.directions);(Array.isArray(u.directions)?u.directions:[u.directions]).includes("all")&&n.push(Ie(c,u,l));for(const m of p)ro.includes(m)||n.push(lo(c,u,m,l))}else n.push(Ie(c,u,l))}else n.push(fo(r,i));return n}s(yo,"convertConfigToUnoRules");function Io(e){return"source"in e&&Array.isArray(e.source)}s(Io,"isSingleCollection");export{Jn as DEFAULT_COLLECTION,_ as DEFAULT_CONFIG,ct as DEFAULT_DESIGN_TOKENS_PATH,pe as DEFAULT_MODE,at as DEFAULT_STYLES_PATH,fe as DEFAULT_THEME,it as DEFAULT_UTILITIES_FILENAME,ee as DEFAULT_VARIABLES_FILENAME,d as ErrorMessages,Q as GLOBAL_DIR,oo as Instrumentation,C as SUGARCUBE_CONFIG_FILE,R as SUGARCUBE_FILE,st as UTILITIES_DIR,v as VARIABLES_FILE_SUFFIX,Qn as configFileExists,yo as convertConfigToUnoRules,ue as discoverAllFiles,de as fillDefaults,me as findConfigFile,bt as generateCSSVariables,Gn as generateIndex,Me as generateIndexContent,Ke as internalConfigSchema,Ee as isResolvedToken,ft as isResolvedTokenOfType,Io as isSingleCollection,dn as loadAndResolveTokens,to as loadInternalConfig,ze as loadTSConfig,eo as loadUserConfig,Xn as parseAndValidateConfig,jn as processAndConvertTokens,Bn as shouldRegenerateIndex,Ye as userConfigSchema,He as validateConfig,he as validateInternalConfig,z as validateUserConfig,zn as writeCSSUtilitiesToDisk,Hn as writeCSSVariablesToDisk};
|
|
41
|
+
`).trim()}s(K,"normalizeContent");function Yr(e){return Wr+e}s(Yr,"addWarningBanner");async function Hr(e){for(const t of e){const n=Yr(t.css);try{await ue(J(t.path),{recursive:!0});let r=!0;if(z(t.path))try{const o=await x(t.path,"utf-8");K(o)===K(n)&&(r=!1)}catch{}r&&await fe(t.path,n,"utf-8")}catch(r){throw new Error(`Failed to write CSS file ${t.path}: ${r instanceof Error?r.message:"Unknown error"}`)}}return e}s(Hr,"writeCSSVariablesToDisk");async function Kr(e){for(const t of e){const n=Br+t.css;try{await ue(J(t.path),{recursive:!0});let r=!0;if(z(t.path))try{const o=await x(t.path,"utf-8");K(o)===K(n)&&(r=!1)}catch{}r&&await fe(t.path,n,"utf-8")}catch(r){throw new Error(`Failed to write utility CSS file ${t.path}: ${r instanceof Error?r.message:"Unknown error"}`)}}return e}s(Kr,"writeCSSUtilitiesToDisk");export{b as DEFAULT_CONFIG,Gr as Instrumentation,Pr as PerfMonitor,vr as clearMatchCache,ot as configFileExists,jr as convertConfigToUnoRules,X as fillDefaults,Sr as generateCSSVariables,Mn as loadAndResolveTokens,at as loadInternalConfig,it as loadSugarcubeConfig,lr as processAndConvertTokens,rt as validateConfig,Kr as writeCSSUtilitiesToDisk,Hr as writeCSSVariablesToDisk};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sugarcube-org/core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0-alpha.19",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": false
|
|
7
7
|
},
|
|
8
8
|
"description": "Core functionality for sugarcube",
|
|
9
|
-
"license": "
|
|
9
|
+
"license": "MIT",
|
|
10
10
|
"main": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"type": "module",
|
|
@@ -25,10 +25,9 @@
|
|
|
25
25
|
"pkgroll": "2.5.1"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"
|
|
28
|
+
"jiti": "2.4.2",
|
|
29
29
|
"pathe": "2.0.3",
|
|
30
|
-
"
|
|
31
|
-
"zod": "3.21.4"
|
|
30
|
+
"zod": "^3.23.8"
|
|
32
31
|
},
|
|
33
32
|
"scripts": {
|
|
34
33
|
"build": "pkgroll --minify",
|