@sugarcube-org/core 0.0.1-alpha.5 → 0.0.1-alpha.6
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 +9 -0
- package/README.md +28 -2
- package/dist/index.d.ts +1334 -415
- package/dist/index.js +32 -19
- package/package.json +6 -2
package/dist/index.js
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
1
|
-
var
|
|
2
|
-
${n.map(
|
|
3
|
-
`)}`,"DUPLICATE_FILENAMES"),FILE_NOT_FOUND:
|
|
1
|
+
var je=Object.defineProperty;var r=(e,t)=>je(e,"name",{value:t,configurable:!0});import{converter as P,formatHex8 as Me,formatHex as ne}from"culori";import _,{readFile as U,mkdir as oe,writeFile as re}from"node:fs/promises";import D,{relative as G}from"node:path";import B from"fast-glob";import{z as l}from"zod";import{existsSync as O}from"node:fs";import{normalize as se,join as E,relative as Y,basename as Pe}from"pathe";function I(e){return typeof e=="string"&&e.startsWith("{")&&e.endsWith("}")}r(I,"isReference");function Ue(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}r(Ue,"isCompositeToken");function ie(e){return I(e)?{value:e}:typeof e=="string"?{value:e}:{value:`${e.dashArray.map(n=>I(n)?n:`${n.value}${n.unit}`).join(" ")} ${e.lineCap}`}}r(ie,"convertStrokeStyleToken");function Ge(e){if(I(e))return{value:e};const t=I(e.width)?e.width:`${e.width.value}${e.width.unit}`,n=(I(e.color),e.color),o=typeof e.style=="string"?e.style:ie(e.style).value;return{value:`${t} ${o} ${n}`}}r(Ge,"convertBorderToken");function W(e){return e===1?"1":e===0?"0":e.toFixed(2)}r(W,"formatAlpha");function z(e,t){try{const n=t==="rgba"?"rgb":t==="hsla"?"hsl":t,o=P(n==="hex"?"rgb":n)(e);if(!o)throw new Error(`Failed to convert color ${e} to ${t}`);switch(n){case"hsl":{if(o.mode!=="hsl")throw new Error("Unexpected color mode");const s=Math.round(o.h??0),i=Math.round((o.s??0)*100),a=Math.round((o.l??0)*100),c=o.alpha;return c!==void 0?`hsl(${s} ${i}% ${a}% / ${W(c)})`:`hsl(${s} ${i}% ${a}%)`}case"oklch":{if(o.mode!=="oklch")throw new Error("Unexpected color mode");const s=o.l??0,i=o.c??0,a=o.h??0,c=o.alpha;return c!==void 0?`oklch(${s.toFixed(3)} ${i.toFixed(3)} ${a.toFixed(1)} / ${c.toFixed(2)})`:`oklch(${s.toFixed(3)} ${i.toFixed(3)} ${a.toFixed(1)})`}case"rgb":{if(o.mode!=="rgb")throw new Error("Unexpected color mode");const s=Math.round((o.r??0)*255),i=Math.round((o.g??0)*255),a=Math.round((o.b??0)*255),c=o.alpha;return c!==void 0?`rgb(${s} ${i} ${a} / ${W(c)})`:`rgb(${s} ${i} ${a})`}case"p3":{if(o.mode!=="p3")throw new Error("Unexpected color mode");const s=o.r??0,i=o.g??0,a=o.b??0,c=o.alpha;return c!==void 0?`color(display-p3 ${s.toFixed(6)} ${i.toFixed(6)} ${a.toFixed(6)} / ${W(c)})`:`color(display-p3 ${s.toFixed(6)} ${i.toFixed(6)} ${a.toFixed(6)})`}default:{const s=P("rgb")(o);return s?s.alpha!==void 0?Me(s):ne(s):e}}}catch{const o=P("rgb")(e);return console.warn(`Failed to convert color ${e} to ${t}, falling back to hex`),o?ne(o):e}}r(z,"convertHexToColorString");function Be(e,t){if(I(e))return{value:e};const n=t.colorFormat||"hex";try{const o=z(e,n);return n==="p3"?{value:z(e,"hex")||e,featureValues:[{query:"@supports (color: color(display-p3 1 1 1))",value:o||e}]}:{value:o||e}}catch{return console.warn(`Failed to convert color ${e} to ${n}, falling back to hex`),{value:z(e,"hex")}}}r(Be,"convertColorToken");function Ye(e){return I(e)?{value:e}:{value:`cubic-bezier(${e.join(", ")})`}}r(Ye,"convertCubicBezierToken");function We(e){return I(e)?{value:e}:{value:`${e.value}${e.unit}`}}r(We,"convertDimensionToken");function ze(e){return I(e)?{value:e}:{value:`${e.value}${e.unit}`}}r(ze,"convertDurationToken");const F="_sugarcube.css",H="global",ae="utilities",b=".variables.css",He=".tokens.json",K="tokens",ce="utilities.css",Ke="src/styles",qe="src/design-tokens",S="sugarcube.config.json",u={LOAD:{NO_FILES_FOUND:r(e=>`No files found matching pattern: ${e}.`,"NO_FILES_FOUND"),INVALID_JSON:r((e,t)=>`Invalid JSON in file ${e}: ${t}`,"INVALID_JSON"),GLOB_ERROR:r((e,t)=>`Error resolving glob pattern ${e}: ${t}`,"GLOB_ERROR")},FLATTEN:{INVALID_TOKEN_NAME:r(e=>`Invalid token name "${e}": Token names cannot contain dots (.), curly braces ({,}), or other special characters`,"INVALID_TOKEN_NAME"),MISSING_DOLLAR_PREFIX:r(e=>`Token at ${e} is using 'value' or 'type' without the required '$' prefix. Use '$value' and '$type' instead.`,"MISSING_DOLLAR_PREFIX"),INVALID_TOKEN_NESTING:r(e=>`Token at "${e}" cannot contain child tokens or groups. Only metadata properties (starting with $) are allowed.`,"INVALID_TOKEN_NESTING"),COMPOSITE_TOKEN_MISSING_TYPE:r(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")},METADATA:{COLLECTION_ERROR:r(e=>`Error collecting metadata: ${e}`,"COLLECTION_ERROR"),INVALID_EXTENSIONS:r(e=>`Invalid extensions at ${e}: expected object, got ${typeof e}`,"INVALID_EXTENSIONS"),INVALID_DESCRIPTION:r(e=>`Invalid description at ${e}: expected string, got ${typeof e}`,"INVALID_DESCRIPTION")},VALIDATE:{MISSING_TYPE:r(e=>`Token at '${e}' is missing the "$type" property`,"MISSING_TYPE"),UNKNOWN_TOKEN_TYPE:r((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:r((e,t)=>`Invalid color at ${t}: '${e}'. Color should be a valid hex value`,"INVALID_COLOR"),INVALID_DIMENSION:r((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:r((e,t)=>`Invalid unit at ${t}': '${e}'. Unit must be either "px" or "rem"`,"INVALID_DIMENSION_UNIT"),INVALID_FONT_FAMILY:r((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:r((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:r((e,t)=>`Invalid duration at '${t}': ${e}. Should be like { "value": 300, "unit": "ms" }`,"INVALID_DURATION"),INVALID_DURATION_UNIT:r((e,t)=>`Invalid unit at ${t}: "${e}". Unit must be "ms" or "s"`,"INVALID_DURATION_UNIT"),INVALID_CUBIC_BEZIER:r((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:r((e,t)=>`Invalid stroke style at ${t}: "${e}". Should be "solid", "dashed", "dotted", etc.`,"INVALID_STROKE_STYLE"),INVALID_STROKE_LINE_CAP:r((e,t)=>`Invalid line cap at ${t}: "${e}". Should be one of: round, butt, square`,"INVALID_STROKE_LINE_CAP"),INVALID_BORDER:r((e,t)=>`Invalid border at ${t}: "${e}". Should have color, width, and style properties`,"INVALID_BORDER"),INVALID_SHADOW:r((e,t)=>`Invalid shadow at ${t}: "${e}". Should have color, offsetX, offsetY properties (blur and spread are optional)`,"INVALID_SHADOW"),INVALID_SHADOW_INSET:r((e,t)=>`Invalid inset value at ${t}: "${e}". Should be true or false`,"INVALID_SHADOW_INSET"),INVALID_TRANSITION:r((e,t)=>`Invalid transition at ${t}: "${e}". Should have duration, delay, and timingFunction properties`,"INVALID_TRANSITION"),INVALID_GRADIENT:r((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:r((e,t)=>`Invalid gradient stop position at ${t}: "${e}". Position must be between 0 and 1`,"INVALID_GRADIENT_STOP_POSITION"),INVALID_TYPOGRAPHY:r((e,t)=>`Invalid typography at ${t}: "${e}". Should have fontFamily and fontSize (fontWeight, letterSpacing, and lineHeight are optional)`,"INVALID_TYPOGRAPHY"),MISSING_REQUIRED_PROPERTY:r((e,t)=>`Missing required property '${e}' at ${t}`,"MISSING_REQUIRED_PROPERTY"),INVALID_NUMBER:r((e,t)=>`Invalid number at ${t}: "${e}". Expected a number value`,"INVALID_NUMBER"),INVALID_ARRAY:r((e,t)=>`Invalid array at ${t}: "${e}". Expected an array value`,"INVALID_ARRAY"),MISSING_FLUID_CONFIG:r(e=>`Missing fluid configuration. Token at ${e} requires fluid viewport settings.`,"MISSING_FLUID_CONFIG"),INVALID_FLUID_DIMENSION:r((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:r((e,t)=>`Invalid viewport configuration at ${t}: "${e}". Viewport config should have min and max dimension values`,"INVALID_VIEWPORT_CONFIG"),MISMATCHED_UNITS:r((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:r(e=>`Invalid fluid value range at ${e}: min value must be less than max value`,"INVALID_FLUID_VALUE_RANGE"),INVALID_TOKEN_TYPE:r((e,t,n)=>`Invalid token type at ${n}: expected ${e}, got ${t}`,"INVALID_TOKEN_TYPE"),INVALID_TYPE:r((e,t,n)=>`Expected ${e}, received ${typeof t} at ${n}`,"INVALID_TYPE"),INVALID_ENUM_VALUE:r((e,t,n)=>`Expected value to be one of [${e.join(", ")}], but got ${String(t)} at ${n}`,"INVALID_ENUM_VALUE")},RESOLVE:{CIRCULAR_REFERENCE:r((e,t)=>`Circular reference detected: ${e} -> ${t}`,"CIRCULAR_REFERENCE"),REFERENCE_NOT_FOUND:r((e,t)=>`Reference not found: ${e} in ${t}`,"REFERENCE_NOT_FOUND"),TYPE_MISMATCH:r(e=>`Type mismatch in ${e}`,"TYPE_MISMATCH")},GENERATE:{INVALID_CSS_VALUE:r((e,t)=>`Invalid CSS value for property '${e}': ${t}`,"INVALID_CSS_VALUE"),INVALID_VARIABLE_NAME:r((e,t)=>`Invalid CSS variable name at '${e}': ${t}`,"INVALID_VARIABLE_NAME")},CONFIG:{INVALID_JSON:r(e=>`Invalid JSON in config file: ${e}`,"INVALID_JSON"),INVALID_CONFIG:r((e,t)=>`Invalid configuration at ${e}: ${t}`,"INVALID_CONFIG"),DUPLICATE_FILENAMES:r((e,t,n)=>`Duplicate filename "${t}" found in collection "${e}":
|
|
2
|
+
${n.map(o=>` - ${o}`).join(`
|
|
3
|
+
`)}`,"DUPLICATE_FILENAMES"),FILE_NOT_FOUND:r(e=>e===S?`Cannot find sugarcube config file. Please ensure you have a valid ${S} 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:r((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:r((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:r(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:r((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")}};function le(e,t=16){return e.unit==="px"?e.value:e.value*t}r(le,"normalizeToPixels");function Xe(e,t){const{min:n,max:o}=e,s=t.fluidConfig;if(!s)throw new Error(u.VALIDATE.MISSING_FLUID_CONFIG(t.path??""));const i=16,a=le(n,i),c=le(o,i),f=s.min,d=s.max;if(a===c)return{value:`${a/i}rem`};const p=a/i,h=c/i,m=f/i,$=d/i,g=(h-p)/($-m),T=-1*m*g+p;return{value:`clamp(${p}rem, ${T.toFixed(2)}rem + ${(g*100).toFixed(2)}vw, ${h}rem)`}}r(Xe,"convertFluidDimension");function Je(e,t){if(I(e))return{value:e};if(!t.fluidConfig)throw new Error(u.VALIDATE.MISSING_FLUID_CONFIG(t.path??""));return Xe(e,t)}r(Je,"convertFluidDimensionToken");function v(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}r(v,"quoteFont");function Ze(e){return I(e)?{value:e}:{value:Array.isArray(e)?e.map(n=>v(n)).join(", "):v(e)}}r(Ze,"convertFontFamilyToken");const Qe={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 I(e)?{value:e}:typeof e=="number"?{value:e}:{value:Qe[e.toLowerCase()]??e}}r(ue,"convertFontWeightToken");function et(e){return I(e)?{value:e}:{value:`linear-gradient(${e.map(n=>{const o=(I(n.color),n.color),s=I(n.position)?n.position:`${n.position*100}`;return`${o} ${s}%`}).join(", ")})`}}r(et,"convertGradientToken");function tt(e){return I(e)?{value:e}:{value:e}}r(tt,"convertNumberToken");function fe(e){const t=I(e.offsetX)?e.offsetX:`${e.offsetX.value}${e.offsetX.unit}`,n=I(e.offsetY)?e.offsetY:`${e.offsetY.value}${e.offsetY.unit}`,o=I(e.blur)?e.blur:`${e.blur.value}${e.blur.unit}`,s=I(e.spread)?e.spread:`${e.spread.value}${e.spread.unit}`,i=(I(e.color),e.color);return`${e.inset?"inset ":""}${t} ${n} ${o} ${s} ${i}`}r(fe,"convertSingleShadow");function nt(e){return I(e)?{value:e}:Array.isArray(e)?{value:e.map(fe).join(", ")}:{value:fe(e)}}r(nt,"convertShadowToken");function pe(e){return e?`${e.value}${e.unit}`:"0ms"}r(pe,"formatDuration");function ot(e){if(I(e))return{value:e};const t=I(e.duration)?e.duration:pe(e.duration),n=I(e.timingFunction)?e.timingFunction:`cubic-bezier(${e.timingFunction.join(", ")})`,o=e.delay&&(I(e.delay)?e.delay:pe(e.delay));return{value:[t,n,o].filter(Boolean).join(" ")}}r(ot,"convertTransitionToken");function rt(e){if(I(e))return{"font-family":e,"font-size":e};const t={"font-family":I(e.fontFamily)?e.fontFamily:Array.isArray(e.fontFamily)?e.fontFamily.map(n=>v(n)).join(", "):v(e.fontFamily),"font-size":I(e.fontSize)?e.fontSize:`${e.fontSize.value}${e.fontSize.unit}`};return e.fontWeight&&(t["font-weight"]=I(e.fontWeight)?e.fontWeight:ue(e.fontWeight).value),e.letterSpacing&&(t["letter-spacing"]=I(e.letterSpacing)?e.letterSpacing:`${e.letterSpacing.value}${e.letterSpacing.unit}`),e.lineHeight&&(t["line-height"]=(I(e.lineHeight),e.lineHeight)),t}r(rt,"convertTypographyToken");const he={duration:ze,number:tt,cubicBezier:Ye,color:Be,dimension:We,fluidDimension:Je,typography:rt,border:Ge,shadow:nt,gradient:et,transition:ot,strokeStyle:ie,fontFamily:Ze,fontWeight:ue};function st(e,t){const n=he[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)}}r(st,"convertSingleToken");function de(e,t){const n={};for(const[o,s]of Object.entries(e)){if(!s||typeof s!="object")continue;if(!("$type"in s)){n[o]={...s.$description?{$description:s.$description}:{},...s.$extensions?{$extensions:s.$extensions}:{}};continue}if(!he[s.$type])continue;const i={fluidConfig:t.transforms?.fluid??{min:320,max:1200},colorFormat:t.transforms?.colorFormat,path:s.$path};n[o]=st(s,i)}return n}r(de,"convertTokens");function it(e,t){const n={};for(const[o,s]of Object.entries(e)){const i={default:de(s.default,t)};for(const[a,c]of Object.entries(s))a!=="default"&&(i[a]=de(c,t));n[o]=i}return n}r(it,"convert");function at(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}r(at,"looksLikeUnprefixedToken");function ct(e,t){const n={tokens:{},pathIndex:new Map},o=[];function s(a=[]){const c=[t.collection];return t.theme&&c.push(t.theme),a.length>0&&c.push(a.join(".")),c.join(".")}r(s,"createLookupKey"),(e.$description||e.$extensions)&&(n.tokens[s()]={$description:e.$description,$extensions:e.$extensions});function i(a,c=[],f){if(c.join("."),c.length>0){const h=s(c);n.tokens[h]={$description:a.$description,$extensions:a.$extensions,$path:c.join("."),$source:{collection:t.collection,theme:t.theme,sourcePath:t.sourcePath}}}const d=Object.keys(a).filter(h=>!h.startsWith("$")),p=a.$type||f;for(const h of d){const m=a[h],$=[...c,h],g=$.join(".");if(at(m)){o.push({path:g,source:t,message:u.FLATTEN.MISSING_DOLLAR_PREFIX(g)});continue}if(h.includes(".")||h.includes("{")||h.includes("}")){o.push({path:g,source:t,message:u.FLATTEN.INVALID_TOKEN_NAME(h)});continue}if("$value"in m){if(Object.keys(m).filter(Re=>!Re.startsWith("$")).length>0){o.push({path:g,source:t,message:u.FLATTEN.INVALID_TOKEN_NESTING(g)});continue}if(Ue(m)&&!m.$type&&!p){o.push({path:g,source:t,message:u.FLATTEN.COMPOSITE_TOKEN_MISSING_TYPE(g)});continue}const L=s($),M=$.join(".");n.tokens[L]={...m,...m.$type||p?{$type:m.$type||p}:{},$path:M,$source:{collection:t.collection,theme:t.theme,sourcePath:t.sourcePath},$originalPath:M},n.pathIndex.set(M,L)}else i(m,$,p)}}return r(i,"processNode"),i(e),{tokens:n,errors:o}}r(ct,"flattenTree");function lt(e){const t={tokens:{},pathIndex:new Map},n=[];for(const o of e){const{tokens:s,errors:i}=ct(o.tokens,{collection:o.collection,theme:o.theme,sourcePath:o.sourcePath});Object.assign(t.tokens,s.tokens);for(const[a,c]of s.pathIndex)t.pathIndex.set(a,c);n.push(...i)}return{tokens:t,errors:n}}r(lt,"flatten");const me=new Map;function ut(e){const t=me.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 me.set(e,n),n}r(ut,"toKebabCase");const Ie="@supports (color: color(display-p3 1 1 1))";function ft(e){return e.$type==="typography"}r(ft,"isTypographyToken");function q(e){return e.split(".").join("-")}r(q,"formatCSSVarPath");function $e(e){return typeof e=="number"?e:typeof e!="string"?(console.warn("Unexpected value type in convertReferenceToCSSVar, got:",e),String(e)):e.replace(/\{([^}]+)\}/g,(t,n)=>`var(--${n.split(".").map(ut).join("-")})`)}r($e,"convertReferenceToCSSVar");function pt(e){const t=e.$cssProperties;if("value"in t)return{name:`--${q(e.$path)}`,value:$e(t.value)}}r(pt,"generateSingleVariable");function ht(e){return Object.entries(e.$cssProperties).filter(([t,n])=>n!==void 0).map(([t,n])=>({name:`--${q(e.$path)}-${t}`,value:$e(n)}))}r(ht,"generateTypographyVariables");function ge(e){if(e.$type!=="color")return[];const t=e.$cssProperties;return"featureValues"in t?t.featureValues?.filter(n=>n.query===Ie).map(n=>({name:`--${q(e.$path)}`,value:n.value}))??[]:[]}r(ge,"generateFeatureVariables");function ye(e){const t=[`${e.selector} {`];if(e.comment&&t.push(` /* ${e.comment} */`),e.vars.length>0){const n=e.vars.map(o=>` ${o.name}: ${o.value};`).join(`
|
|
4
4
|
`);t.push(n)}return t.push("}"),t.join(`
|
|
5
|
-
`)}
|
|
5
|
+
`)}r(ye,"generateCSSBlock");function dt(e){const t=[];e.root.vars.length>0&&t.push(ye({selector:e.root.selector,vars:e.root.vars}));for(const n of e.features){const s=ye({selector:e.root.selector,vars:n.vars}).split(`
|
|
6
6
|
`).map(i=>` ${i}`).join(`
|
|
7
7
|
`);t.push(`${n.query} {
|
|
8
8
|
${s}
|
|
9
9
|
}`)}return t.filter(Boolean).join(`
|
|
10
10
|
|
|
11
|
-
`)}
|
|
11
|
+
`)}r(dt,"convertCSSVarsToString");function mt(e){if(ft(e))return{vars:ht(e),features:ge(e)};const t=pt(e);return{vars:t?[t]:[],features:ge(e)}}r(mt,"generateVariablesForToken");async function X(e,t={}){const n=Object.entries(e).filter(([c,f])=>c!=="$extensions"&&"$type"in f).map(([c,f])=>mt(f));let o=":root";t.theme&&t.theme!=="default"&&(o=`[data-theme="${t.theme}"]`);const s=n.flatMap(c=>c.vars),i=n.flatMap(c=>c.features||[]),a=dt({root:{selector:o,vars:s},features:i.length?[{query:Ie,vars:i}]:[]});return a.trim()?{output:[{path:"tokens.variables.css",css:It(a)}]}:{output:[{path:"tokens.variables.css",css:""}]}}r(X,"generateCSS");function It(e){return e.endsWith(`
|
|
12
12
|
`)?e:`${e}
|
|
13
|
-
`}
|
|
13
|
+
`}r(It,"formatCSSVars");async function $t(e,t){const o=`${t.output?.css||"src/styles"}/${H}`,s=[];for(const[i,a]of Object.entries(e)){const c=[];for(const[f,d]of Object.entries(a)){const p=await X(d,{theme:f!=="default"?f:void 0});p.output[0].css.trim()&&c.push(p.output[0].css)}c.length>0&&s.push({path:i==="default"?`${o}/${K}${b}`:`${o}/${i}/${K}${b}`,css:`${c.filter(Boolean).join(`
|
|
14
14
|
`).trim()}
|
|
15
|
-
`})}return r}o(Be,"generateSingleFile");async function He(e,t){const n=`${t.output.directories.css}/global/variables`,r=[];for(const[s,i]of Object.entries(e))if(Object.keys(i).length!==0){for(const[a,c]of Object.entries(i))if(Object.keys(c).length!==0)if(a==="default"){const l=new Map;for(const[f,p]of Object.entries(c)){if(!("$type"in p))continue;const I=p.$source.sourcePath;l.has(I)||l.set(I,{}),l.get(I)[f]=p}for(const[f,p]of l){if(Object.keys(p).length===0)continue;const d=f.split("/").pop()?.replace(/\.json$/,"")??"tokens",g=(await w(p,{})).output[0].css;g.trim()&&r.push({path:v({collection:s,filename:d,separate:!0,baseDir:n}),css:g})}}else{const f=(await w(c,{theme:a})).output[0].css;f.trim()&&r.push({path:v({collection:s,filename:a,separate:!0,baseDir:n}),css:f})}}return r}o(He,"generateSeparateFiles");async function Q(e,t){const n={};for(const[r,s]of Object.entries(e)){n[r]={default:{}},s.default&&(n[r].default=s.default);for(const[i,a]of Object.entries(s))i!=="default"&&a&&(n[r][i]=a);Object.keys(n[r].default).length===0&&Object.keys(n[r]).length===1&&delete n[r]}return t.output.css.separate?{output:await He(n,t)}:{output:await Be(n,t)}}o(Q,"generate");async function ee(e){const t={files:[],errors:[]};for(const n of e)try{const r=!n.includes("*")&&!n.endsWith(".json")?N.join(n,"**/*.json"):n,s=await Ee(r,{absolute:!0,onlyFiles:!0});if(s.length===0){t.errors.push({pattern:n,error:u.LOAD.NO_FILES_FOUND(n)});continue}t.files.push(...s)}catch(r){t.errors.push({pattern:n,error:u.LOAD.GLOB_ERROR(n,r instanceof Error?r.message:"Unknown error")})}return t}o(ee,"resolveFiles");async function te(e){try{const t=await _(e,"utf-8");return JSON.parse(t)}catch(t){throw t instanceof Error&&t instanceof SyntaxError?new Error(u.LOAD.INVALID_JSON(e,t.message)):t}}o(te,"loadTree");function qe(e){const t=new Set;if(e.themes)for(const n of Object.values(e.themes))for(const r of n)t.add(r);return t}o(qe,"collectThemePaths");async function ne(e){const t=[],n=[],r=Array.isArray(e.tokens)?{default:{source:e.tokens,type:"custom"}}:"source"in e.tokens?{default:e.tokens}:e.tokens;for(const[s,i]of Object.entries(r)){const a=qe(i),{files:c,errors:l}=await ee(Array.isArray(i.source)?i.source:[i.source]);if(l.length>0){t.push(...l.map(f=>({file:f.pattern,message:f.error})));continue}for(const f of c){const p=O(process.cwd(),f);if(!a.has(p))try{const d=await te(f),I={collection:s,tokens:d,sourcePath:p};n.push(I)}catch(d){t.push({file:f,message:d instanceof Error?d.message:"Unknown error"})}}if(i.themes)for(const[f,p]of Object.entries(i.themes))try{const{files:d,errors:I}=await ee(p);if(I.length>0){t.push(...I.map(g=>({file:g.pattern,message:g.error})));continue}for(const g of d)try{const y=await te(g),A={collection:s,theme:f,tokens:y,sourcePath:O(process.cwd(),g)};n.push(A)}catch(y){t.push({file:g,message:y instanceof Error?y.message:"Unknown error"})}}catch(d){t.push({file:p.join(", "),message:d instanceof Error?d.message:"Unknown error"})}}return{trees:n,errors:t}}o(ne,"loadTreesFromConfig");async function re(e){const t=[],n=[],r=new Map;for(const[s,{collection:i,theme:a,content:c}]of Object.entries(e)){r.has(i)||r.set(i,new Map);const l=r.get(i);l.has(a)||l.set(a,[]),l.get(a)?.push({content:c,path:s})}for(const[s,i]of r)for(const[a,c]of i)for(const{content:l,path:f}of c)try{const p=JSON.parse(l);t.push({collection:s,theme:a,tokens:p,sourcePath:O(process.cwd(),f)})}catch(p){p instanceof Error?p instanceof SyntaxError?n.push({file:f,message:u.LOAD.INVALID_JSON(f,p.message)}):n.push({file:f,message:p.message}):n.push({file:f,message:"Unknown error"})}return{trees:t,errors:n}}o(re,"loadTreesFromMemory");function oe(e){const t=[],n=[],r=new Set,s=new Map;for(const c of e){const{collection:l,theme:f="default"}=c;r.add(l),s.has(l)||s.set(l,new Set),s.get(l)?.add(f)}const i={};function a(c){const l={default:{}};i[c]=l;const f=s.get(c);if(f)for(const p of f)l[p]={};return l}o(a,"addCollection");for(const c of r)a(c);for(const c of e){const{collection:l,theme:f="default",tokens:p}=c,d=i[l]||a(l);let I=d[f];I||(I=d[f]={});for(const[g,y]of Object.entries(p)){const A=g.replace(`${l}.`,"");I[A]=y}}return{tokens:i,errors:n,warnings:t}}o(oe,"normalizeTokens");function se(e,t){const n=new Map;for(const[r,s]of Object.entries(t)){if(!("$source"in s)){for(const l of e){const f=l.collection;n.has(f)||n.set(f,new Map);const p=n.get(f),d=l.theme;p.has(d)||p.set(d,{}),p.get(d)[r]=s}continue}const i=s.$source.collection,a=s.$source.theme;n.has(i)||n.set(i,new Map);const c=n.get(i);c.has(void 0)||c.set(void 0,{}),a||(c.get(void 0)[r]=s),a&&(c.has(a)||c.set(a,{}),c.get(a)[r]=s)}return e.map(r=>{const s=n.get(r.collection);if(!s)return{collection:r.collection,theme:r.theme,tokens:{}};if(r.theme){const a=s.get(r.theme)||{};return{collection:r.collection,theme:r.theme,tokens:a}}const i=s.get(void 0)||{};return{collection:r.collection,theme:r.theme,tokens:i}})}o(se,"processTrees");function b(e,t,n,r){return typeof t=="string"&&h(t)?Ke(e,t,n,r):Array.isArray(t)?t.map(s=>b(e,s,n,r)):typeof t=="object"&&t!==null?Object.entries(t).reduce((i,[a,c])=>Object.assign(i,{[a]:b(`${e}.${a}`,c,n,r)}),{}):t}o(b,"resolveValue");function ie(e){const t={},n=new Set,r=[];for(const[s,i]of Object.entries(e.tokens))try{if(!("$value"in i)){t[s]=i;continue}const a=i;t[s]={...a,$resolvedValue:b(a.$path,a.$value,e,n)}}catch(a){const c=a instanceof Error?a.message:String(a),l=i,f=l.$path,p=l.$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=u.RESOLVE.TYPE_MISMATCH(f)),r.push({type:d,path:f,source:p,message:I})}return{resolved:t,errors:r}}o(ie,"resolve");function Ke(e,t,n,r){const s=t.slice(1,-1),i=n.pathIndex.get(s);if(!i)throw new Error(u.RESOLVE.REFERENCE_NOT_FOUND(s,e));if(r.has(i)){const l=n.tokens[i];throw!l||!("$path"in l)?new Error(u.RESOLVE.REFERENCE_NOT_FOUND(s,e)):new Error(u.RESOLVE.CIRCULAR_REFERENCE(e,l.$path))}const a=n.tokens[i];if(!a||!("$value"in a))throw new Error(u.RESOLVE.REFERENCE_NOT_FOUND(s,e));r.add(i);const c=b(i,a.$value,n,r);return r.delete(i),c}o(Ke,"resolveReferenceChain");const Xe={isObject:o(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 Ze(e,t,n,r);case"union":return Qe(e,t,n,r);case"array":return et(e,t,n,r);default:return Je(e,t,n,r)}}o($,"validateSchema");function Je(e,t,n,r){return e.type!==typeof t?[{path:n,message:e.errorMessage?.(t,n)||u.VALIDATE.INVALID_TYPE(e.type,t,n),source:r}]:e.validate?.(t,n,r)??[]}o(Je,"validateSimpleValue");function Ze(e,t,n,r){if(!Xe.isObject(t))return[{path:n,message:e.errorMessage?.(t,n)||u.VALIDATE.INVALID_TYPE("object",t,n),source:r}];const s=[],i=t;if(e.required)for(const a of e.required)a in i||s.push({path:`${n}.${a}`,message:u.VALIDATE.MISSING_REQUIRED_PROPERTY(a,n),source:r});for(const[a,c]of Object.entries(e.properties))a in i&&s.push(...$(c,i[a],`${n}.${a}`,r));return s}o(Ze,"validateObject");function Qe(e,t,n,r){let s=[],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 e.validate?.(t,n,r)??[];c.length<i&&(s=c,i=c.length)}return i===Number.POSITIVE_INFINITY?[{path:n,message:u.VALIDATE.INVALID_TYPE(e.oneOf.map(a=>a.type).join(" or "),t,n),source:r}]:s}o(Qe,"validateUnion");function et(e,t,n,r){return Array.isArray(t)?e.validate?.(t,n,r)??[]:[{path:n,message:e.errorMessage?.(t,n)||u.VALIDATE.INVALID_TYPE("array",t,n),source:r}]}o(et,"validateArray");const S={schema:{type:"string",errorMessage:o((e,t)=>u.VALIDATE.INVALID_COLOR(e,t),"errorMessage"),validate:o((e,t,n)=>/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(e)?[]:[{path:t,message:u.VALIDATE.INVALID_COLOR(e,t),source:n}],"validate")}};function tt(e,t,n){return $(S.schema,e,t,n)}o(tt,"validateColor");const L={schema:{type:"number",errorMessage:o((e,t)=>u.VALIDATE.INVALID_NUMBER(e,t),"errorMessage"),validate:o((e,t,n)=>typeof e!="number"||Number.isNaN(e)?[{path:t,message:u.VALIDATE.INVALID_NUMBER(e,t),source:n}]:[],"validate")}};function nt(e,t,n){return $(L.schema,e,t,n)}o(nt,"validateNumber");const E={schema:{type:"object",errorMessage:o((e,t)=>u.VALIDATE.INVALID_DIMENSION(e,t),"errorMessage"),properties:{value:L.schema,unit:{type:"string",validate:o((e,t,n)=>typeof e!="string"||!["px","rem"].includes(e)?[{path:t,message:u.VALIDATE.INVALID_DIMENSION_UNIT(e,t),source:n}]:[],"validate")}},required:["value","unit"]}};function rt(e,t,n){return $(E.schema,e,t,n)}o(rt,"validateDimension");const ae={schema:{type:"union",oneOf:[{type:"string",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")},{type:"array",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage"),validate:o((e,t,n)=>e.every(s=>typeof s=="string")?[]:[{path:t,message:u.VALIDATE.INVALID_FONT_FAMILY(e,t),source:n}],"validate")}],errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")}};function ot(e,t,n){return $(ae.schema,e,t,n)}o(ot,"validateFontFamily");const st=["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"],ce={schema:{type:"union",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),oneOf:[{type:"number",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:o((e,t,n)=>e<1||e>1e3?[{path:t,message:u.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}]:[],"validate")},{type:"string",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:o((e,t,n)=>st.includes(e.toLowerCase())?[]:[{path:t,message:u.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}],"validate")}]}};function it(e,t,n){return $(ce.schema,e,t,n)}o(it,"validateFontWeight");const at=["ms","s"],x={schema:{type:"object",errorMessage:o((e,t)=>u.VALIDATE.INVALID_DURATION(e,t),"errorMessage"),properties:{value:L.schema,unit:{type:"string",validate:o((e,t,n)=>at.includes(e)?[]:[{path:t,message:u.VALIDATE.INVALID_DURATION_UNIT(e,t),source:n}],"validate")}},required:["value","unit"]}};function ct(e,t,n){return $(x.schema,e,t,n)}o(ct,"validateDuration");const le={schema:{type:"array",errorMessage:o((e,t)=>u.VALIDATE.INVALID_CUBIC_BEZIER(e,t),"errorMessage"),validate:o((e,t,n)=>{const r=e;if(r.length!==4||!r.every(a=>typeof a=="number"))return[{path:t,message:u.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}];const[s,,i]=r;return s<0||s>1||i<0||i>1?[{path:t,message:u.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}]:[]},"validate")}};function lt(e,t,n){return $(le.schema,e,t,n)}o(lt,"validateCubicBezier");const ut={schema:{type:"object",properties:{fontFamily:ae.schema,fontSize:E.schema,letterSpacing:E.schema,lineHeight:L.schema,fontWeight:ce.schema},required:["fontFamily","fontSize"],errorMessage:o((e,t)=>u.VALIDATE.INVALID_TYPOGRAPHY(e,t),"errorMessage")}};function ft(e,t,n){return $(ut.schema,e,t,n)}o(ft,"validateTypography");const dt=["solid","dashed","dotted","double","groove","ridge","outset","inset"],pt=["round","butt","square"],ht={type:"object",errorMessage:o((e,t)=>u.VALIDATE.INVALID_STROKE_STYLE(e,t),"errorMessage"),properties:{dashArray:{type:"array",validate:o((e,t,n)=>{const r=e,s=[];return r.forEach((i,a)=>{typeof i!="string"&&s.push(...$(E.schema,i,`${t}.${a}`,n))}),s},"validate")},lineCap:{type:"string",validate:o((e,t,n)=>pt.includes(e)?[]:[{path:t,message:u.VALIDATE.INVALID_STROKE_LINE_CAP(e,t),source:n}],"validate")}},required:["dashArray","lineCap"]},ue={schema:{type:"union",oneOf:[{type:"string",validate:o((e,t,n)=>!dt.includes(e)&&typeof e=="string"?[{path:t,message:u.VALIDATE.INVALID_STROKE_STYLE(e,t),source:n}]:[],"validate")},ht]}};function mt(e,t,n){return $(ue.schema,e,t,n)}o(mt,"validateStrokeStyle");const It={schema:{type:"object",properties:{color:S.schema,width:E.schema,style:ue.schema},required:["color","width","style"],errorMessage:o((e,t)=>u.VALIDATE.INVALID_BORDER(e,t),"errorMessage")}};function gt(e,t,n){return $(It.schema,e,t,n)}o(gt,"validateBorder");const $t={schema:{type:"object",properties:{duration:x.schema,delay:x.schema,timingFunction:le.schema},required:["duration","delay","timingFunction"],errorMessage:o((e,t)=>u.VALIDATE.INVALID_TRANSITION(e,t),"errorMessage")}};function yt(e,t,n){return $($t.schema,e,t,n)}o(yt,"validateTransition");const fe={schema:{type:"object",properties:{color:S.schema,offsetX:E.schema,offsetY:E.schema,blur:E.schema,spread:E.schema,inset:{type:"boolean",errorMessage:o((e,t)=>u.VALIDATE.INVALID_SHADOW_INSET(e,t),"errorMessage")}},required:["color","offsetX","offsetY","blur","spread"],errorMessage:o((e,t)=>u.VALIDATE.INVALID_SHADOW(e,t),"errorMessage")}};function At(e,t,n){const r=[];return Array.isArray(e)?(e.forEach((s,i)=>{r.push(...$(fe.schema,s,`${t}[${i}]`,n))}),r):$(fe.schema,e,t,n)}o(At,"validateShadow");const Et={type:"object",errorMessage:o((e,t)=>u.VALIDATE.INVALID_GRADIENT(e,t),"errorMessage"),properties:{color:{type:"string",validate:S.schema.validate},position:{type:"number",validate:o((e,t,n)=>e<0||e>1?[{path:t,message:u.VALIDATE.INVALID_GRADIENT_STOP_POSITION(e,t),source:n}]:[],"validate")}},required:["color","position"]},Nt={schema:{type:"array",errorMessage:o((e,t)=>u.VALIDATE.INVALID_ARRAY(e,t),"errorMessage"),validate:o((e,t,n)=>{const r=e,s=[];return r.forEach((i,a)=>{s.push(...$(Et,i,`${t}[${a}]`,n))}),s},"validate")}};function Tt(e,t,n){return $(Nt.schema,e,t,n)}o(Tt,"validateGradient");const bt={schema:{type:"object",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FLUID_DIMENSION(e,t),"errorMessage"),properties:{min:E.schema,max:E.schema},required:["min","max"]}};function St(e,t,n){return $(bt.schema,e,t,n)}o(St,"validateFluidDimension");const Lt={color:tt,dimension:rt,fluidDimension:St,duration:ct,cubicBezier:lt,fontFamily:ot,fontWeight:it,number:nt,strokeStyle:mt,typography:ft,border:gt,shadow:At,gradient:Tt,transition:yt};function de(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:u.VALIDATE.MISSING_REQUIRED_PROPERTY("$value",r.$path),source:r.$source});continue}const s=Lt[r.$type];if(!s){t.push({path:r.$path,message:u.VALIDATE.UNKNOWN_TOKEN_TYPE(r.$type,r.$path),source:r.$source});continue}const i=r;t.push(...s(i.$value,i.$path,i.$source))}return t}o(de,"validate");async function Dt(e,t){const n={load:[],flatten:[],validation:[],resolution:[]},r={normalization:[]},{trees:s,errors:i}=await(t?.loader?.type==="memory"?re(t.loader.data):ne(e));n.load.push(...i);const{tokens:a,errors:c}=H(s);n.flatten.push(...c);const l=de(a);if(n.validation.push(...l),l.length>0)return{output:[],trees:s,errors:n,warnings:r};const{resolved:f,errors:p}=ie(a);n.resolution.push(...p);const d=se(s,f),{tokens:I,warnings:g}=oe(d);r.normalization.push(...g);const y=B(I,e),{output:A}=await Q(y,e);return{output:A,trees:s,errors:n,warnings:r}}o(Dt,"tokensToCSSPipeline");async function _t(e,t){const{trees:n,errors:r}=await(t.loader.type==="memory"?re(t.loader.data):ne(t.loader.paths)),{tokens:s,errors:i}=H(n),a=de(s),{resolved:c,errors:l}=ie(s);return{trees:n,flattenedTokens:s,resolved:c,errors:{load:r,flatten:i,validation:a,resolution:l}}}o(_t,"validationPipeline");async function Ot(e,t,n){const r={normalization:[]},s=se(e,t),{tokens:i,warnings:a}=oe(s);r.normalization.push(...a);const c=B(i,n),{output:l}=await Q(c,n);return{output:l,warnings:r}}o(Ot,"generationPipeline");const pe=m.object({tokens:m.union([m.object({source:m.array(m.string()),type:m.enum(["starter-kit","custom"]),themes:m.record(m.array(m.string())).optional()}),m.record(m.string(),m.object({source:m.array(m.string()),type:m.enum(["starter-kit","custom"]),themes:m.record(m.array(m.string())).optional()}))]),options:m.object({fluid:m.object({min:m.number(),max:m.number()}).strict().optional(),prefix:m.string().optional(),color:m.enum(["hex","rgb","rgba","hsl","hsla","oklch","p3"]).optional()}).optional(),output:m.object({directories:m.object({tokens:m.string(),components:m.string().optional(),css:m.string()}),css:m.object({separate:m.boolean(),manageIndex:m.boolean().optional(),format:m.enum(["css","scss","less"]).optional()})})});function he(e){const t=pe.safeParse(e);if(!t.success){const n=t.error.errors.map(r=>{const s=r.path.join(".");return u.CONFIG.INVALID_CONFIG(s||"root",r.message)});throw new Error(n.join(`
|
|
16
|
-
`))}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* For more information, see: https://sugarcube.style/docs/generated-files
|
|
24
|
-
*/
|
|
15
|
+
`})}return s}r($t,"generateSingleFile");async function gt(e,t){const o=`${t.output?.css||"src/styles"}/${H}`,s=[];for(const[i,a]of Object.entries(e))if(Object.keys(a).length!==0){for(const[c,f]of Object.entries(a))if(Object.keys(f).length!==0)if(c==="default"){const d=new Map;for(const[p,h]of Object.entries(f)){if(!("$type"in h))continue;const $=h.$source.sourcePath;d.has($)||d.set($,{}),d.get($)[p]=h}for(const[p,h]of d){if(Object.keys(h).length===0)continue;const m=p.split("/").pop()?.replace(/\.json$/,"")??"tokens",g=(await X(h,{})).output[0].css;g.trim()&&s.push({path:i==="default"?`${o}/${m}${b}`:`${o}/${i}/${m}${b}`,css:g})}}else{const p=(await X(f,{theme:c})).output[0].css;p.trim()&&s.push({path:i==="default"?`${o}/${c}${b}`:`${o}/${i}/${c}${b}`,css:p})}}return s}r(gt,"generateSeparateFiles");async function yt(e,t){const n={};for(const[o,s]of Object.entries(e)){n[o]={default:{}},s.default&&(n[o].default=s.default);for(const[i,a]of Object.entries(s))i!=="default"&&a&&(n[o][i]=a);Object.keys(n[o].default).length===0&&Object.keys(n[o]).length===1&&delete n[o]}return t.output?.separate?{output:await gt(n,t)}:{output:await $t(n,t)}}r(yt,"generate");async function Ae(e){const t={files:[],errors:[]};for(const n of e)try{const o=!n.includes("*")&&!n.endsWith(".json")?D.join(n,"**/*.json"):n,s=await B(o,{absolute:!0,onlyFiles:!0});if(s.length===0){t.errors.push({pattern:n,error:u.LOAD.NO_FILES_FOUND(n)});continue}t.files.push(...s)}catch(o){t.errors.push({pattern:n,error:u.LOAD.GLOB_ERROR(n,o instanceof Error?o.message:"Unknown error")})}return t}r(Ae,"resolveFiles");async function Ee(e){try{const t=await U(e,"utf-8");return JSON.parse(t)}catch(t){throw t instanceof Error&&t instanceof SyntaxError?new Error(u.LOAD.INVALID_JSON(e,t.message)):t}}r(Ee,"loadTree");function At(e){const t=new Set;if(e.themes)for(const n of Object.values(e.themes))for(const o of n)t.add(o);return t}r(At,"collectThemePaths");async function Et(e){const t=[],n=[],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 B.sync(a).length>0}catch{return!1}})))return{trees:[],errors:[{file:S,message:u.LOAD.NO_FILES_FOUND(Object.values(o).flatMap(i=>i.source).join(", "))}]};for(const[i,a]of Object.entries(o)){const c=At(a),{files:f,errors:d}=await Ae(Array.isArray(a.source)?a.source:[a.source]);if(d.length>0){t.push(...d.map(p=>({file:p.pattern,message:p.error})));continue}for(const p of f){const h=G(process.cwd(),p);if(!c.has(h))try{const m=await Ee(p),$={collection:i,tokens:m,sourcePath:h};n.push($)}catch(m){t.push({file:p,message:m instanceof Error?m.message:"Unknown error"})}}if(a.themes)for(const[p,h]of Object.entries(a.themes))try{const{files:m,errors:$}=await Ae(h);if($.length>0){t.push(...$.map(g=>({file:g.pattern,message:g.error})));continue}for(const g of m)try{const T=await Ee(g),L={collection:i,theme:p,tokens:T,sourcePath:G(process.cwd(),g)};n.push(L)}catch(T){t.push({file:g,message:T instanceof Error?T.message:"Unknown error"})}}catch(m){t.push({file:h.join(", "),message:m instanceof Error?m.message:"Unknown error"})}}return{trees:n,errors:t}}r(Et,"loadTreesFromConfig");async function Tt(e){const t=[],n=[],o=new Map;for(const[s,{collection:i,theme:a,content:c}]of Object.entries(e)){o.has(i)||o.set(i,new Map);const f=o.get(i);f.has(a)||f.set(a,[]),f.get(a)?.push({content:c,path:s})}for(const[s,i]of o)for(const[a,c]of i)for(const{content:f,path:d}of c)try{const p=JSON.parse(f);t.push({collection:s,theme:a,tokens:p,sourcePath:G(process.cwd(),d)})}catch(p){p instanceof Error?p instanceof SyntaxError?n.push({file:d,message:u.LOAD.INVALID_JSON(d,p.message)}):n.push({file:d,message:p.message}):n.push({file:d,message:"Unknown error"})}return{trees:t,errors:n}}r(Tt,"loadTreesFromMemory");function bt(e){const t=new Set,n=new Map;for(const i of e){const{collection:a,theme:c="default"}=i;t.add(a),n.has(a)||n.set(a,new Set),n.get(a)?.add(c)}const o={};function s(i){const a={default:{}};o[i]=a;const c=n.get(i);if(c)for(const f of c)a[f]={};return a}r(s,"addCollection");for(const i of t)s(i);for(const i of e){const{collection:a,theme:c="default",tokens:f}=i,d=o[a]||s(a);let p=d[c];p||(p=d[c]={});for(const[h,m]of Object.entries(f)){const $=h.replace(`${a}.`,"");p[$]=m}}return{tokens:o}}r(bt,"normalizeTokens");function Nt(e,t){const n=new Map;for(const[o,s]of Object.entries(t)){if(!("$source"in s)){for(const f of e){const d=f.collection;n.has(d)||n.set(d,new Map);const p=n.get(d),h=f.theme;p.has(h)||p.set(h,{}),p.get(h)[o]=s}continue}const i=s.$source.collection,a=s.$source.theme;n.has(i)||n.set(i,new Map);const c=n.get(i);c.has(void 0)||c.set(void 0,{}),a||(c.get(void 0)[o]=s),a&&(c.has(a)||c.set(a,{}),c.get(a)[o]=s)}return e.map(o=>{const s=n.get(o.collection);if(!s)return{collection:o.collection,theme:o.theme,tokens:{}};if(o.theme){const a=s.get(o.theme)||{};return{collection:o.collection,theme:o.theme,tokens:a}}const i=s.get(void 0)||{};return{collection:o.collection,theme:o.theme,tokens:i}})}r(Nt,"processTrees");function k(e,t,n,o){return typeof t=="string"&&I(t)?Lt(e,t,n,o):Array.isArray(t)?t.map(s=>k(e,s,n,o)):typeof t=="object"&&t!==null?Object.entries(t).reduce((i,[a,c])=>Object.assign(i,{[a]:k(`${e}.${a}`,c,n,o)}),{}):t}r(k,"resolveValue");function Te(e,t){const n=e.slice(1,-1),o=t.pathIndex.get(n);if(!o)return;const s=t.tokens[o];if(!(!s||!("$value"in s))){if(s.$type)return s.$type;if(typeof s.$value=="string"&&I(s.$value))return Te(s.$value,t)}}r(Te,"inferTypeFromReference");function St(e){const t={},n=new Set,o=[];for(const[s,i]of Object.entries(e.tokens))try{if(!("$value"in i)){t[s]=i;continue}const a=i;let c=a.$type;!c&&typeof a.$value=="string"&&I(a.$value)&&(c=Te(a.$value,e)),t[s]={...a,...c?{$type:c}:{},$resolvedValue:k(a.$path,a.$value,e,n)}}catch(a){const c=a instanceof Error?a.message:String(a),f=i,d=f.$path,p=f.$source;let h,m;c.includes("Circular reference detected")?(h="circular",m=c):c.includes("Reference not found")?(h="missing",m=c):(h="type-mismatch",m=u.RESOLVE.TYPE_MISMATCH(d)),o.push({type:h,path:d,source:p,message:m})}return{resolved:t,errors:o}}r(St,"resolve");function Lt(e,t,n,o){const s=t.slice(1,-1),i=n.pathIndex.get(s);if(!i)throw new Error(u.RESOLVE.REFERENCE_NOT_FOUND(s,e));if(o.has(i)){const f=n.tokens[i];throw!f||!("$path"in f)?new Error(u.RESOLVE.REFERENCE_NOT_FOUND(s,e)):new Error(u.RESOLVE.CIRCULAR_REFERENCE(e,f.$path))}const a=n.tokens[i];if(!a||!("$value"in a))throw new Error(u.RESOLVE.REFERENCE_NOT_FOUND(s,e));o.add(i);const c=k(i,a.$value,n,o);return o.delete(i),c}r(Lt,"resolveReferenceChain");const _t={isObject:r(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObject")};function y(e,t,n,o){if(I(t))return[];switch(e.type){case"object":return Ot(e,t,n,o);case"union":return Ft(e,t,n,o);case"array":return vt(e,t,n,o);default:return Dt(e,t,n,o)}}r(y,"validateSchema");function Dt(e,t,n,o){return e.type!==typeof t?[{path:n,message:e.errorMessage?.(t,n)||u.VALIDATE.INVALID_TYPE(e.type,t,n),source:o}]:e.validate?.(t,n,o)??[]}r(Dt,"validateSimpleValue");function Ot(e,t,n,o){if(!_t.isObject(t))return[{path:n,message:e.errorMessage?.(t,n)||u.VALIDATE.INVALID_TYPE("object",t,n),source:o}];const s=[],i=t;if(e.required)for(const a of e.required)a in i||s.push({path:`${n}.${a}`,message:u.VALIDATE.MISSING_REQUIRED_PROPERTY(a,n),source:o});for(const[a,c]of Object.entries(e.properties))a in i&&s.push(...y(c,i[a],`${n}.${a}`,o));return s}r(Ot,"validateObject");function Ft(e,t,n,o){let s=[],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=y(a,t,n,o);if(c.length===0)return e.validate?.(t,n,o)??[];c.length<i&&(s=c,i=c.length)}return i===Number.POSITIVE_INFINITY?[{path:n,message:u.VALIDATE.INVALID_TYPE(e.oneOf.map(a=>a.type).join(" or "),t,n),source:o}]:s}r(Ft,"validateUnion");function vt(e,t,n,o){return Array.isArray(t)?e.validate?.(t,n,o)??[]:[{path:n,message:e.errorMessage?.(t,n)||u.VALIDATE.INVALID_TYPE("array",t,n),source:o}]}r(vt,"validateArray");const w={schema:{type:"string",errorMessage:r((e,t)=>u.VALIDATE.INVALID_COLOR(e,t),"errorMessage"),validate:r((e,t,n)=>/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(e)?[]:[{path:t,message:u.VALIDATE.INVALID_COLOR(e,t),source:n}],"validate")}};function kt(e,t,n){return y(w.schema,e,t,n)}r(kt,"validateColor");const V={schema:{type:"number",errorMessage:r((e,t)=>u.VALIDATE.INVALID_NUMBER(e,t),"errorMessage"),validate:r((e,t,n)=>typeof e!="number"||Number.isNaN(e)?[{path:t,message:u.VALIDATE.INVALID_NUMBER(e,t),source:n}]:[],"validate")}};function wt(e,t,n){return y(V.schema,e,t,n)}r(wt,"validateNumber");const A={schema:{type:"object",errorMessage:r((e,t)=>u.VALIDATE.INVALID_DIMENSION(e,t),"errorMessage"),properties:{value:V.schema,unit:{type:"string",validate:r((e,t,n)=>typeof e!="string"||!["px","rem"].includes(e)?[{path:t,message:u.VALIDATE.INVALID_DIMENSION_UNIT(e,t),source:n}]:[],"validate")}},required:["value","unit"]}};function Vt(e,t,n){return y(A.schema,e,t,n)}r(Vt,"validateDimension");const be={schema:{type:"union",oneOf:[{type:"string",errorMessage:r((e,t)=>u.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")},{type:"array",errorMessage:r((e,t)=>u.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage"),validate:r((e,t,n)=>e.every(s=>typeof s=="string")?[]:[{path:t,message:u.VALIDATE.INVALID_FONT_FAMILY(e,t),source:n}],"validate")}],errorMessage:r((e,t)=>u.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")}};function xt(e,t,n){return y(be.schema,e,t,n)}r(xt,"validateFontFamily");const Ct=["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"],Ne={schema:{type:"union",errorMessage:r((e,t)=>u.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),oneOf:[{type:"number",errorMessage:r((e,t)=>u.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:r((e,t,n)=>e<1||e>1e3?[{path:t,message:u.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}]:[],"validate")},{type:"string",errorMessage:r((e,t)=>u.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:r((e,t,n)=>Ct.includes(e.toLowerCase())?[]:[{path:t,message:u.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}],"validate")}]}};function Rt(e,t,n){return y(Ne.schema,e,t,n)}r(Rt,"validateFontWeight");const jt=["ms","s"],J={schema:{type:"object",errorMessage:r((e,t)=>u.VALIDATE.INVALID_DURATION(e,t),"errorMessage"),properties:{value:V.schema,unit:{type:"string",validate:r((e,t,n)=>jt.includes(e)?[]:[{path:t,message:u.VALIDATE.INVALID_DURATION_UNIT(e,t),source:n}],"validate")}},required:["value","unit"]}};function Mt(e,t,n){return y(J.schema,e,t,n)}r(Mt,"validateDuration");const Se={schema:{type:"array",errorMessage:r((e,t)=>u.VALIDATE.INVALID_CUBIC_BEZIER(e,t),"errorMessage"),validate:r((e,t,n)=>{const o=e;if(o.length!==4||!o.every(a=>typeof a=="number"))return[{path:t,message:u.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}];const[s,,i]=o;return s<0||s>1||i<0||i>1?[{path:t,message:u.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}]:[]},"validate")}};function Pt(e,t,n){return y(Se.schema,e,t,n)}r(Pt,"validateCubicBezier");const Ut={schema:{type:"object",properties:{fontFamily:be.schema,fontSize:A.schema,letterSpacing:A.schema,lineHeight:V.schema,fontWeight:Ne.schema},required:["fontFamily","fontSize"],errorMessage:r((e,t)=>u.VALIDATE.INVALID_TYPOGRAPHY(e,t),"errorMessage")}};function Gt(e,t,n){return y(Ut.schema,e,t,n)}r(Gt,"validateTypography");const Bt=["solid","dashed","dotted","double","groove","ridge","outset","inset"],Yt=["round","butt","square"],Wt={type:"object",errorMessage:r((e,t)=>u.VALIDATE.INVALID_STROKE_STYLE(e,t),"errorMessage"),properties:{dashArray:{type:"array",validate:r((e,t,n)=>{const o=e,s=[];return o.forEach((i,a)=>{typeof i!="string"&&s.push(...y(A.schema,i,`${t}.${a}`,n))}),s},"validate")},lineCap:{type:"string",validate:r((e,t,n)=>Yt.includes(e)?[]:[{path:t,message:u.VALIDATE.INVALID_STROKE_LINE_CAP(e,t),source:n}],"validate")}},required:["dashArray","lineCap"]},Le={schema:{type:"union",oneOf:[{type:"string",validate:r((e,t,n)=>!Bt.includes(e)&&typeof e=="string"?[{path:t,message:u.VALIDATE.INVALID_STROKE_STYLE(e,t),source:n}]:[],"validate")},Wt]}};function zt(e,t,n){return y(Le.schema,e,t,n)}r(zt,"validateStrokeStyle");const Ht={schema:{type:"object",properties:{color:w.schema,width:A.schema,style:Le.schema},required:["color","width","style"],errorMessage:r((e,t)=>u.VALIDATE.INVALID_BORDER(e,t),"errorMessage")}};function Kt(e,t,n){return y(Ht.schema,e,t,n)}r(Kt,"validateBorder");const qt={schema:{type:"object",properties:{duration:J.schema,delay:J.schema,timingFunction:Se.schema},required:["duration","delay","timingFunction"],errorMessage:r((e,t)=>u.VALIDATE.INVALID_TRANSITION(e,t),"errorMessage")}};function Xt(e,t,n){return y(qt.schema,e,t,n)}r(Xt,"validateTransition");const _e={schema:{type:"object",properties:{color:w.schema,offsetX:A.schema,offsetY:A.schema,blur:A.schema,spread:A.schema,inset:{type:"boolean",errorMessage:r((e,t)=>u.VALIDATE.INVALID_SHADOW_INSET(e,t),"errorMessage")}},required:["color","offsetX","offsetY","blur","spread"],errorMessage:r((e,t)=>u.VALIDATE.INVALID_SHADOW(e,t),"errorMessage")}};function Jt(e,t,n){const o=[];return Array.isArray(e)?(e.forEach((s,i)=>{o.push(...y(_e.schema,s,`${t}[${i}]`,n))}),o):y(_e.schema,e,t,n)}r(Jt,"validateShadow");const Zt={type:"object",errorMessage:r((e,t)=>u.VALIDATE.INVALID_GRADIENT(e,t),"errorMessage"),properties:{color:{type:"string",validate:w.schema.validate},position:{type:"number",validate:r((e,t,n)=>e<0||e>1?[{path:t,message:u.VALIDATE.INVALID_GRADIENT_STOP_POSITION(e,t),source:n}]:[],"validate")}},required:["color","position"]},Qt={schema:{type:"array",errorMessage:r((e,t)=>u.VALIDATE.INVALID_ARRAY(e,t),"errorMessage"),validate:r((e,t,n)=>{const o=e,s=[];return o.forEach((i,a)=>{s.push(...y(Zt,i,`${t}[${a}]`,n))}),s},"validate")}};function en(e,t,n){return y(Qt.schema,e,t,n)}r(en,"validateGradient");const tn={schema:{type:"object",errorMessage:r((e,t)=>u.VALIDATE.INVALID_FLUID_DIMENSION(e,t),"errorMessage"),properties:{min:A.schema,max:A.schema},required:["min","max"]}};function nn(e,t,n){return y(tn.schema,e,t,n)}r(nn,"validateFluidDimension");const on={color:kt,dimension:Vt,fluidDimension:nn,duration:Mt,cubicBezier:Pt,fontFamily:xt,fontWeight:Rt,number:wt,strokeStyle:zt,typography:Gt,border:Kt,shadow:Jt,gradient:en,transition:Xt};function rn(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:u.VALIDATE.MISSING_REQUIRED_PROPERTY("$value",o.$path),source:o.$source});continue}const s=on[o.$type];if(!s){t.push({path:o.$path,message:u.VALIDATE.UNKNOWN_TOKEN_TYPE(o.$type,o.$path),source:o.$source});continue}const i=o;t.push(...s(i.$value,i.$path,i.$source))}return t}r(rn,"validate");async function sn(e){const{trees:t,errors:n}=await(e.type==="memory"?Tt(e.data):Et(e.config)),{tokens:o,errors:s}=lt(t),i=rn(o),{resolved:a,errors:c}=St(o);return{trees:t,resolved:a,errors:{load:n,flatten:s,validation:i,resolution:c}}}r(sn,"tokenProcessingPipeline");const x=l.array(l.string()).min(1,"At least one file path must be specified"),Z=l.object({source:x,themes:l.record(x).optional()}),De=l.record(l.string(),Z),Oe=l.object({min:l.number(),max:l.number()}),C=l.object({typeMap:l.record(l.enum(["color","dimension","fluidDimension","duration","cubicBezier","fontFamily","fontWeight","number","border","shadow","gradient","transition","strokeStyle"]),x).optional(),directions:l.union([l.enum(["top","right","bottom","left","x","y","full"]),l.array(l.enum(["top","right","bottom","left","x","y","full"]))]).optional(),properties:x.optional(),prefix:l.string().optional(),stripLevels:l.number().optional(),custom:l.record(l.string(),l.string()).optional()}),Q=l.object({tokens:l.union([Z,De]),transforms:l.object({fluid:Oe.optional(),colorFormat:l.enum(["hex","rgb","rgba","hsl","hsla","oklch","p3"]).optional(),prefix:l.string().optional()}).optional(),output:l.object({css:l.string().optional(),tokens:l.string().optional(),components:l.string().optional(),separate:l.boolean().optional()}).optional(),utilities:l.object({core:l.boolean().optional()}).catchall(l.union([C,l.array(C)])).optional(),components:l.object({framework:l.enum(["react","astro"]).optional(),installed:l.array(l.string()).optional()}).optional(),plugins:l.array(l.string()).optional()}),Fe=l.object({tokens:l.union([Z,De]),transforms:l.object({fluid:Oe.optional(),colorFormat:l.enum(["hex","rgb","rgba","hsl","hsla","oklch","p3"]).optional(),prefix:l.string().optional()}).optional(),output:l.object({css:l.string(),tokens:l.string(),components:l.string(),separate:l.boolean()}),utilities:l.object({core:l.boolean().optional()}).catchall(l.union([C,l.array(C)])).optional(),components:l.object({framework:l.enum(["react","astro"]).optional(),installed:l.array(l.string()).optional()}).optional(),plugins:l.array(l.string()).optional()}),an=Q,N={output:{css:"src/styles",tokens:"src/design-tokens",components:"src/ui/components",separate:!1}};function ve(e){const t={tokens:e.tokens,output:{css:e.output?.css??N.output.css,tokens:e.output?.tokens??N.output.tokens,separate:e.output?.separate??N.output.separate}};return(e.output?.components!==void 0||N.output.components!==void 0)&&(t.output.components=e.output?.components??N.output.components),e.transforms&&(t.transforms=e.transforms),e.utilities&&(t.utilities=e.utilities),e.components&&(t.components=e.components),e.plugins&&(t.plugins=e.plugins),t}r(ve,"normalizeConfig");function ke(e){const t=Q.safeParse(e);if(!t.success){const s=t.error.errors.map(i=>{const a=i.path.join(".");return u.CONFIG.INVALID_CONFIG(a||"root",i.message)});throw new Error(s.join(`
|
|
16
|
+
`))}const n=ve(t.data),o=Fe.safeParse(n);if(!o.success){const s=o.error.errors.map(i=>{const a=i.path.join(".");return u.CONFIG.INVALID_CONFIG(a||"root",i.message)});throw new Error(s.join(`
|
|
17
|
+
`))}return cn(o.data),o.data}r(ke,"validateConfig");function we(e){try{const t=JSON.parse(e);return ke(t)}catch(t){throw t instanceof SyntaxError?new Error(u.CONFIG.INVALID_JSON(t.message)):t}}r(we,"parseAndValidateConfig");function cn(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 s of n.source){const i=D.basename(s),a=o.get(i)||[];o.set(i,[...a,s])}for(const[s,i]of o)if(i.length>1)throw new Error(u.CONFIG.DUPLICATE_FILENAMES(t,s,i))}}r(cn,"validateFileNames");async function ln(e=S){try{const t=await _.readFile(e,"utf-8");return{config:we(t),configPath:e}}catch(t){throw t instanceof Error&&"code"in t&&t.code==="ENOENT"?new Error(u.CONFIG.FILE_NOT_FOUND(e)):t}}r(ln,"loadConfig");function un(e){return"source"in e&&Array.isArray(e.source)}r(un,"isSingleCollection");function fn(e){return`/**
|
|
18
|
+
* THIS FILE IS AUTOMATICALLY GENERATED BY SUGARCUBE FROM YOUR DESIGN TOKENS
|
|
19
|
+
* To make changes to it, edit your token files instead.
|
|
20
|
+
*
|
|
21
|
+
* For more information, see: https://sugarcube.style/docs/design-tokens
|
|
22
|
+
*/
|
|
25
23
|
|
|
26
|
-
${e}`}
|
|
27
|
-
|
|
24
|
+
${e}`}r(fn,"addWarningBanner");function pn(e){return un(e.tokens)?e.tokens.source.map(se):Object.values(e.tokens).flatMap(t=>"source"in t?t.source.map(se):[])}r(pn,"getTokenPathsFromConfig");async function hn(e){for(const t of e){const n=fn(t.css);try{await oe(D.dirname(t.path),{recursive:!0});let o=!0;if(O(t.path))try{await U(t.path,"utf-8")===n&&(o=!1)}catch{}o&&await re(t.path,n,"utf-8")}catch(o){throw new Error(`Failed to write CSS file ${t.path}: ${o instanceof Error?o.message:"Unknown error"}`)}}return e}r(hn,"writeCSSVariablesToDisk");async function dn(e){const t=`/**
|
|
25
|
+
* THIS FILE IS AUTOMATICALLY GENERATED BY SUGARCUBE FROM YOUR UTILITIES CONFIGURATION
|
|
26
|
+
* To make changes to it, edit your utilities configuration.
|
|
27
|
+
*
|
|
28
|
+
* For more information on configuration, see: https://sugarcube.style/docs/configuration
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
`;for(const n of e){const o=t+n.css;try{await oe(D.dirname(n.path),{recursive:!0});let s=!0;if(O(n.path))try{await U(n.path,"utf-8")===o&&(s=!1)}catch{}s&&await re(n.path,o,"utf-8")}catch(s){throw new Error(`Failed to write utility CSS file ${n.path}: ${s instanceof Error?s.message:"Unknown error"}`)}}return e}r(dn,"writeCSSUtilitiesToDisk");function mn(e,t){if(!t)return[];const n=[],o=t[e];o&&(Array.isArray(o)?n.push(...o):n.push(o));for(const[s,i]of Object.entries(t))if(s.endsWith("*")){const a=s.slice(0,-1);e.startsWith(a)&&(Array.isArray(i)?n.push(...i):n.push(i))}return n}r(mn,"findMatchingConfig");function R(e,t,n){return`${e} {
|
|
32
|
+
${t}: ${n};
|
|
33
|
+
}`}r(R,"generateCSSRule");function ee(e){return e.charAt(0)}r(ee,"getAbbreviatedName");function Ve(e,t,n,o){if(t==="full"){const i=`${ee(e)}-${n}`;return o.prefix?`${o.prefix}-${i}`:i}if(t){const s=ee(e),i=ee(t),a=`${s}${i}-${n}`;return o.prefix?`${o.prefix}-${a}`:a}return o.prefix?`${o.prefix}-${n}`:n}r(Ve,"generateClassName");function In(e,t){return t==="full"?e:`${e}-${{top:"block-start",right:"inline-end",bottom:"block-end",left:"inline-start",x:"inline",y:"block"}[t]}`}r(In,"getLogicalProperty");function $n(e,t,n,o){return o.directions?(Array.isArray(o.directions)?o.directions:[o.directions]).map(i=>R(`.${Ve(e,i,t,o)}`,In(e,i),`var(--${n.join("-")})`)):[]}r($n,"generateDirectionalCSS");function gn(e,t){if(e.$type&&t.typeMap){const n=t.typeMap[e.$type];if(n)return n}return t.properties?t.properties:[]}r(gn,"getPropertiesForToken");const yn={"w-full":"width: 100%;","h-full":"height: 100%;","w-fit-content":"width: fit-content;","h-fit-content":"height: fit-content;","w-auto":"width: auto;","h-auto":"height: auto;","w-min-content":"width: min-content;","h-min-content":"height: min-content;","w-max-content":"width: max-content;","h-max-content":"height: max-content;",block:"display: block;",inline:"display: inline;","inline-block":"display: inline-block;",hidden:"display: none;","text-left":"text-align: left;","text-center":"text-align: center;","text-right":"text-align: right;","text-justify":"text-align: justify;",uppercase:"text-transform: uppercase;",lowercase:"text-transform: lowercase;",capitalize:"text-transform: capitalize;","normal-case":"text-transform: none;",relative:"position: relative;",absolute:"position: absolute;",fixed:"position: fixed;",sticky:"position: sticky;",static:"position: static;","overflow-auto":"overflow: auto;","overflow-hidden":"overflow: hidden;","overflow-visible":"overflow: visible;","overflow-scroll":"overflow: scroll;","cursor-pointer":"cursor: pointer;","cursor-default":"cursor: default;","cursor-not-allowed":"cursor: not-allowed;","select-none":"user-select: none;","select-text":"user-select: text;","select-all":"user-select: all;","list-none":"list-style: none;","list-disc":"list-style: disc;","list-decimal":"list-style: decimal;","list-inside":"list-style: inside;","mx-auto":"margin-inline: auto;","ml-auto":"margin-inline-start: auto;","mr-auto":"margin-inline-end: auto;","mt-auto":"margin-block-start: auto;","mb-auto":"margin-block-end: auto;"};function An(e,t){const n=new Set;if(t.utilities?.core)for(const[i,a]of Object.entries(yn)){const[c,f]=a.split(": ");if(c&&f){const d=f.replace(";","");n.add(R(`.${i}`,c,d))}}if(t.utilities)for(const[i,a]of Object.entries(t.utilities)){if(i==="core"||typeof a=="boolean")continue;const c=Array.isArray(a)?a:[a];for(const f of c)if(f.custom&&f.properties)for(const[d,p]of Object.entries(f.custom))for(const h of f.properties){const m=f.prefix?`${f.prefix}-${i}-${d}`:`${i}-${d}`;n.add(R(`.${m}`,h,p))}}for(const[i,a]of Object.entries(e)){if(!("$path"in a))continue;const c=mn(a.$path,t.utilities);if(c.length!==0)for(const f of c){if(f.custom)continue;const d=gn(a,f);if(d.length===0)continue;const p=a.$path.split("."),m=(f.stripLevels?p.slice(f.stripLevels):p).join("-");for(const $ of d)if(f.directions)for(const g of $n($,m,p,f))n.add(g);else n.add(R(`.${Ve($,void 0,m,f)}`,$,`var(--${p.join("-")})`))}}const o=Array.from(n);o.sort();const s=o.join(`
|
|
34
|
+
|
|
35
|
+
`);return{output:[{path:`${t.output.css}/${ae}/${ce}`,css:s}],errors:[]}}r(An,"generateCSSUtilityClasses");async function En(e,t,n){const o=Nt(e,t),{tokens:s}=bt(o),i=it(s,n),{output:a}=await yt(i,n);return{output:a}}r(En,"generateCSSVariables");const j=["reset","global","compositions","blocks","utilities"];async function te(e,t){const n=[],o=await B([E(e,"**/*.css"),E(e,"**/*.scss"),E(e,"**/*.sass"),E(e,"**/*.less")],{ignore:[E(e,F)]});for(const s of o){const i=Tn(s,e);if(i){const a=Y(e,s);n.push({path:a,layer:i,relativePath:a})}}return n}r(te,"discoverAllFiles");function Tn(e,t){const n=Y(t,e);if(n.includes("global/")||n.startsWith("global/"))return Pe(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"}r(Tn,"categorizeFile");function bn(e){return e.sort((t,n)=>{const o=j.indexOf(t.layer),s=j.indexOf(n.layer);return o!==s?o-s:t.path.localeCompare(n.path)})}r(bn,"sortFilesByLayer");function Nn(){return`@layer ${j.join(", ")};
|
|
36
|
+
`}r(Nn,"getLayerDefinitions");function xe(e){const t=[];t.push(Nn());const n=e.reduce((o,s)=>{const i=o[s.layer]??[];return o[s.layer]=[...i,s],o},{});for(const o of j){const s=n[o];if(!(!s||s.length===0))for(const i of s)t.push(`@import "${i.path}" layer(${i.layer});`)}return t.join(`
|
|
37
|
+
`)}r(xe,"generateIndexContent");async function Sn(e,t){const n=E(e,F),o=await te(e),s=bn(o),i=xe(s);return await _.writeFile(n,i),Y(process.cwd(),n)}r(Sn,"generateIndex");async function Ln(e,t){const n=E(e,F);if(!O(n))return!0;try{const o=await _.stat(n),s=await te(e,t);for(const i of s){const a=E(e,i.path);if(O(a)&&(await _.stat(a)).mtime>o.mtime)return!0}return!1}catch{return!0}}r(Ln,"shouldRegenerateIndex");class Ce extends Map{static{r(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 _n=process.env.DEBUG==="true";class Dn{static{r(this,"Instrumentation")}constructor(t=n=>void process.stderr.write(`${n}
|
|
38
|
+
`)){this.defaultFlush=t}#t=new Ce(()=>({value:0}));#n=new Ce(()=>({value:0n}));#e=[];hit(t){this.#t.get(t).value++}start(t){const n=this.#e.map(s=>s.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,s=this.#e[o];if(!s)throw new Error("Timer stack is corrupted");if(s.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 s=this.#e.length-1;s>=0;s--){const i=this.#e[s];i&&this.end(i.label)}for(const[s,{value:i}]of this.#t.entries()){if(this.#n.has(s))continue;n.length===0&&(o=!0,n.push("Hits:"));const a=s.split("//").length;n.push(`${" ".repeat(a)}${s} \xD7 ${i}`)}if(this.#n.size>0){o&&n.push(`
|
|
39
|
+
Timers:`);for(const[s,{value:i}]of this.#n){const a=s.split("//").length,c=`${(Number(i)/1e6).toFixed(2)}ms`;n.push(`${" ".repeat(a-1)}${s.split("//").pop()} [${c}] ${this.#t.get(s).value===1?"":`\xD7 ${this.#t.get(s).value}`}`.trimEnd())}}t(`
|
|
40
|
+
${n.join(`
|
|
28
41
|
`)}
|
|
29
|
-
`}
|
|
42
|
+
`)}[Symbol.dispose](){_n&&this.report()}}export{N as DEFAULT_CONFIG,qe as DEFAULT_DESIGN_TOKENS_PATH,Ke as DEFAULT_STYLES_PATH,ce as DEFAULT_UTILITIES_FILENAME,K as DEFAULT_VARIABLES_FILENAME,H as GLOBAL_DIR,Dn as Instrumentation,S as SUGARCUBE_CONFIG_FILE,F as SUGARCUBE_FILE,He as TOKENS_FILE_SUFFIX,ae as UTILITIES_DIR,b as VARIABLES_FILE_SUFFIX,an as configSchema,te as discoverAllFiles,An as generateCSSUtilityClasses,En as generateCSSVariables,Sn as generateIndex,xe as generateIndexContent,pn as getTokenPathsFromConfig,Fe as internalConfigSchema,ln as loadConfig,ve as normalizeConfig,we as parseAndValidateConfig,Ln as shouldRegenerateIndex,sn as tokenProcessingPipeline,Q as userConfigSchema,ke as validateConfig,dn as writeCSSUtilitiesToDisk,hn as writeCSSVariablesToDisk};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sugarcube-org/core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"description": "Core functionality for sugarcube",
|
|
8
|
-
"license": "
|
|
8
|
+
"license": "UNLICENSED",
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"type": "module",
|
|
@@ -27,15 +27,19 @@
|
|
|
27
27
|
"@types/culori": "^2.1.1",
|
|
28
28
|
"culori": "^4.0.1",
|
|
29
29
|
"fast-glob": "^3.3.2",
|
|
30
|
+
"pathe": "^2.0.3",
|
|
30
31
|
"zod": "^3.21.4"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "pkgroll --minify",
|
|
35
|
+
"build:clean": "rm -rf dist && pkgroll --minify",
|
|
34
36
|
"dev": "pkgroll --watch",
|
|
35
37
|
"test": "vitest run",
|
|
36
38
|
"test:watch": "vitest",
|
|
37
39
|
"test:coverage": "vitest run --coverage",
|
|
38
40
|
"test:bench": "vitest bench --no-watch",
|
|
41
|
+
"test:bench:save": "vitest bench --no-watch --outputJson benchmarks/$(date +%Y-%m-%d)-results.json",
|
|
42
|
+
"test:bench:compare": "./scripts/bench-compare.sh",
|
|
39
43
|
"type-check": "tsc --noEmit"
|
|
40
44
|
}
|
|
41
45
|
}
|