@sugarcube-org/core 0.0.1-alpha.6 → 0.0.1-alpha.7
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 +27 -5
- package/README.md +3 -31
- package/dist/index.d.ts +776 -1351
- package/dist/index.js +31 -29
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,42 +1,44 @@
|
|
|
1
|
-
var
|
|
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(`
|
|
1
|
+
var et=Object.defineProperty;var s=(e,t)=>et(e,"name",{value:t,configurable:!0});import C,{readFile as K,mkdir as fe,writeFile as pe}from"node:fs/promises";import z from"fast-glob";import{join as N,relative as _,basename as de,dirname as he,resolve as me}from"pathe";import{existsSync as D}from"node:fs";import{pathToFileURL as tt}from"node:url";import{z as m}from"zod";const w="_sugarcube.css",q="global",nt="utilities",S=".variables.gen.css",J="tokens",ot="utilities.gen.css",rt="src/styles",st="src/design-tokens",F="sugarcube.config.ts";function I(e){return typeof e=="string"&&e.startsWith("{")&&e.endsWith("}")}s(I,"isReference");function it(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(it,"isCompositeToken");function at(e){return e.$type==="typography"}s(at,"isTypographyToken");function Ie(e){return typeof e=="object"&&e!==null&&"$path"in e&&"$type"in e&&"$resolvedValue"in e}s(Ie,"isResolvedToken");function ct(e,t){return Ie(e)&&e.$type===t}s(ct,"isResolvedTokenOfType");function V(e){return Object.entries(e).sort(([t],[n])=>t.localeCompare(n))}s(V,"deterministicEntries");const ye=new Map;function lt(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(lt,"toKebabCase");function X(e){return e.split(".").join("-")}s(X,"formatCSSVarPath");function Z(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(lt).join("-")})`)}s(Z,"convertReferenceToCSSVar");function ut(e){const t=e.$cssProperties;if("value"in t)return{name:`--${X(e.$path)}`,value:Z(t.value)}}s(ut,"generateSingleVariable");function ft(e){return Object.entries(e.$cssProperties).filter(([t,n])=>n!==void 0).map(([t,n])=>({name:`--${X(e.$path)}-${t}`,value:Z(n)}))}s(ft,"generateTypographyVariables");function $e(e){if(e.$type!=="color")return[];const t=e.$cssProperties;if(!("featureValues"in t))return[];const n=new Map;for(const o of t.featureValues||[]){n.has(o.query)||n.set(o.query,[]);const r=n.get(o.query);r&&r.push({name:`--${X(e.$path)}`,value:Z(o.value)})}return Array.from(n.entries()).map(([o,r])=>({query:o,vars:r}))}s($e,"generateFeatureVariables");function ge(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
2
|
`);t.push(n)}return t.push("}"),t.join(`
|
|
5
|
-
`)}
|
|
3
|
+
`)}s(ge,"generateCSSBlock");function pt(e){const t=[];e.root.vars.length>0&&t.push(ge({selector:e.root.selector,vars:e.root.vars}));for(const n of e.features){const r=ge({selector:e.root.selector,vars:n.vars}).split(`
|
|
6
4
|
`).map(i=>` ${i}`).join(`
|
|
7
5
|
`);t.push(`${n.query} {
|
|
8
|
-
${
|
|
6
|
+
${r}
|
|
9
7
|
}`)}return t.filter(Boolean).join(`
|
|
10
8
|
|
|
11
|
-
`)}
|
|
9
|
+
`)}s(pt,"convertCSSVarsToString");function dt(e){if(at(e))return{vars:ft(e),features:$e(e)};const t=ut(e);return{vars:t?[t]:[],features:$e(e)}}s(dt,"generateVariablesForToken");async function Q(e,t={}){const n=V(e).filter(([u,p])=>u!=="$extensions"&&"$type"in p).map(([u,p])=>dt(p));let o=":root";t.theme&&t.theme!=="default"&&(o=`[data-theme="${t.theme}"]`);const r=n.flatMap(u=>u.vars),i=n.flatMap(u=>u.features||[]),a=new Map;for(const u of i){a.has(u.query)||a.set(u.query,[]);const p=a.get(u.query);p&&p.push(...u.vars)}const c=Array.from(a.entries()).map(([u,p])=>({query:u,vars:p})),l=pt({root:{selector:o,vars:r},features:c});return l.trim()?{output:[{path:"tokens.variables.gen.css",css:ht(l),collection:t.collection??"default"}]}:{output:[{path:"tokens.variables.gen.css",css:"",collection:t.collection??"default"}]}}s(Q,"generateCSS");function ht(e){return e.endsWith(`
|
|
12
10
|
`)?e:`${e}
|
|
13
|
-
`}
|
|
11
|
+
`}s(ht,"formatCSSVars");async function mt(e,t){const o=`${t.output?.css||"src/styles"}/${q}`,r=[];for(const[i,a]of V(e)){const c=[],l=Object.entries(a).sort(([u],[p])=>u==="default"?-1:p==="default"?1:u.localeCompare(p));for(const[u,p]of l){const d=await Q(p,{theme:u!=="default"?u:void 0,collection:i!=="default"?i:void 0});d.output[0].css.trim()&&c.push(d.output[0].css)}c.length>0&&r.push({path:i==="default"?`${o}/${J}${S}`:`${o}/${i}/${J}${S}`,css:`${c.filter(Boolean).join(`
|
|
14
12
|
`).trim()}
|
|
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
|
-
|
|
17
|
-
`)
|
|
18
|
-
|
|
19
|
-
* To make changes to it, edit your token files instead.
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
`,collection:i})}return r}s(mt,"generateSingleFile");async function It(e,t){const o=`${t.output?.css||"src/styles"}/${q}`,r=[];for(const[i,a]of V(e)){if(Object.keys(a).length===0)continue;const c=Object.entries(a).sort(([l],[u])=>l==="default"?-1:u==="default"?1:l.localeCompare(u));for(const[l,u]of c)if(Object.keys(u).length!==0)if(l==="default"){const p=new Map;for(const[d,h]of V(u)){if(!("$type"in h))continue;const $=h.$source.sourcePath;p.has($)||p.set($,{}),p.get($)[d]=h}for(const[d,h]of Array.from(p.entries()).sort(([y],[$])=>y.localeCompare($))){if(Object.keys(h).length===0)continue;const y=d.split("/").pop()?.replace(/\.json$/,"")??"tokens",A=(await Q(h,{collection:i==="default"?void 0:i})).output[0].css;A.trim()&&r.push({path:i==="default"?`${o}/${y}${S}`:`${o}/${i}/${y}${S}`,css:A,collection:i})}}else{const d=(await Q(u,{theme:l,collection:i==="default"?void 0:i})).output[0].css;d.trim()&&r.push({path:i==="default"?`${o}/${l}${S}`:`${o}/${i}/${l}${S}`,css:d,collection:i})}}return r}s(It,"generateSeparateFiles");async function yt(e,t){const n={};for(const[o,r]of Object.entries(e)){n[o]={default:{}},r.default&&(n[o].default=r.default);for(const[i,a]of Object.entries(r))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 It(n,t)}:{output:await mt(n,t)}}s(yt,"generate");async function $t(e,t){const{output:n}=await yt(e,t);return n}s($t,"generateCSSVariables");const 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,n)=>`Duplicate filename "${t}" found in collection "${e}":
|
|
14
|
+
${n.map(o=>` - ${o}`).join(`
|
|
15
|
+
`)}`,"DUPLICATE_FILENAMES"),FILE_NOT_FOUND:s(e=>e===F?`Cannot find sugarcube config file. Please ensure you have a valid ${F} 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"),INVALID_COLLECTION:s((e,t,n)=>`Utility config for '${e}' specifies collection '${t}', but this collection does not exist. Available collections: ${n.join(", ")||"none"}`,"INVALID_COLLECTION"),TOKEN_PATH_CONFLICT:s((e,t)=>`Token path conflict: "${e}" exists in multiple collections (${t}). To resolve this conflict, either:
|
|
16
|
+
1. Use unique token paths per collection
|
|
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 ee(e){return typeof e=="object"&&e!==null&&"$value"in e}s(ee,"isTokenNode");function gt(e,t,n){for(const[o,r]of Object.entries(t.tokens)){const i=e.tokens[o];if(!ee(r)){if(i&&ee(i)){const d=i;n.push({path:d.$path,source:d.$source,message:f.FLATTEN.CONFLICT_TOKEN_VS_GROUP(d.$path)});continue}e.tokens[o]=r;continue}if(!i){e.tokens[o]=r;continue}if(!ee(i)){n.push({path:r.$path,source:r.$source,message:f.FLATTEN.CONFLICT_TOKEN_VS_GROUP(r.$path)});continue}const c=r,l=i,u=!!c.$type,p=!!l.$type;if(u&&p&&c.$type!==l.$type){n.push({path:c.$path,source:c.$source,message:f.FLATTEN.CONFLICT_INCOMPATIBLE_TYPES(String(l.$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(gt,"mergeFlattenedInto");function Tt(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(Tt,"looksLikeUnprefixedToken");function Et(e,t){const n={tokens:{},pathIndex:new Map},o=[];function r(a=[]){const c=[t.collection];return t.theme&&c.push(t.theme),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=[],l){if(c.join("."),c.length>0){const d=r(c);n.tokens[d]={$description:a.$description,$extensions:a.$extensions,$path:c.join("."),$source:{collection:t.collection,theme:t.theme,sourcePath:t.sourcePath}}}const u=Object.keys(a).filter(d=>!d.startsWith("$")),p=a.$type||l;for(const d of u){const h=a[d],y=[...c,d],$=y.join(".");if(Tt(h)){o.push({path:$,source:t,message:f.FLATTEN.MISSING_DOLLAR_PREFIX($)});continue}if(d.includes(".")||d.includes("{")||d.includes("}")){o.push({path:$,source:t,message:f.FLATTEN.INVALID_TOKEN_NAME(d)});continue}if("$value"in h){if(Object.keys(h).filter(Qe=>!Qe.startsWith("$")).length>0){o.push({path:$,source:t,message:f.FLATTEN.INVALID_TOKEN_NESTING($)});continue}if(it(h)&&!h.$type&&!p){o.push({path:$,source:t,message:f.FLATTEN.COMPOSITE_TOKEN_MISSING_TYPE($)});continue}const v=r(y),H=y.join(".");n.tokens[v]={...h,...h.$type||p?{$type:h.$type||p}:{},$path:H,$source:{collection:t.collection,theme:t.theme,sourcePath:t.sourcePath},$originalPath:H},n.pathIndex.set(H,v)}else i(h,y,p)}}return s(i,"processNode"),i(e),{tokens:n,errors:o}}s(Et,"flattenTree");function At(e){const t={tokens:{},pathIndex:new Map},n=[];for(const o of e){const{tokens:r,errors:i}=Et(o.tokens,{collection:o.collection,theme:o.theme,sourcePath:o.sourcePath});n.push(...i),gt(t,r,n)}return{tokens:t,errors:n}}s(At,"flatten");async function Te(e){const t={files:[],errors:[]};for(const n of e)try{const o=!n.includes("*")&&!n.endsWith(".json")?N(n,"**/*.json"):n,r=await z(o,{absolute:!0,onlyFiles:!0});if(r.length===0){t.errors.push({pattern:n,error:f.LOAD.NO_FILES_FOUND(n)});continue}t.files.push(...r)}catch(o){t.errors.push({pattern:n,error:f.LOAD.GLOB_ERROR(n,o instanceof Error?o.message:"Unknown error")})}return t}s(Te,"resolveFiles");async function Ee(e){try{const t=await K(e,"utf-8");return JSON.parse(t)}catch(t){throw t instanceof Error&&t instanceof SyntaxError?new Error(f.LOAD.INVALID_JSON(e,t.message)):t}}s(Ee,"loadTree");function bt(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}s(bt,"collectThemePaths");async function Nt(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:F,message:f.LOAD.NO_FILES_FOUND(Object.values(o).flatMap(i=>i.source).join(", "))}]};for(const[i,a]of Object.entries(o)){const c=bt(a),{files:l,errors:u}=await Te(Array.isArray(a.source)?a.source:[a.source]);if(u.length>0){t.push(...u.map(p=>({file:p.pattern,message:p.error})));continue}for(const p of l){const d=_(process.cwd(),p);if(!c.has(d))try{const h=await Ee(p),y={collection:i,tokens:h,sourcePath:d};n.push(y)}catch(h){t.push({file:p,message:h instanceof Error?h.message:"Unknown error"})}}if(a.themes)for(const[p,d]of Object.entries(a.themes))try{const{files:h,errors:y}=await Te(d);if(y.length>0){t.push(...y.map($=>({file:$.pattern,message:$.error})));continue}for(const $ of h)try{const A=await Ee($),v={collection:i,theme:p,tokens:A,sourcePath:_(process.cwd(),$)};n.push(v)}catch(A){t.push({file:$,message:A instanceof Error?A.message:"Unknown error"})}}catch(h){t.push({file:d.join(", "),message:h instanceof Error?h.message:"Unknown error"})}}return{trees:n,errors:t}}s(Nt,"loadTreesFromConfig");async function St(e){const t=[],n=[],o=new Map;for(const[r,{collection:i,theme:a,content:c}]of Object.entries(e)){o.has(i)||o.set(i,new Map);const l=o.get(i);l.has(a)||l.set(a,[]),l.get(a)?.push({content:c,path:r})}for(const[r,i]of o)for(const[a,c]of i)for(const{content:l,path:u}of c)try{const p=JSON.parse(l);t.push({collection:r,theme:a,tokens:p,sourcePath:_(process.cwd(),u)})}catch(p){p instanceof Error?p instanceof SyntaxError?n.push({file:u,message:f.LOAD.INVALID_JSON(u,p.message)}):n.push({file:u,message:p.message}):n.push({file:u,message:"Unknown error"})}return{trees:t,errors:n}}s(St,"loadTreesFromMemory");function x(e,t,n,o){return typeof t=="string"&&I(t)?Ot(e,t,n,o):Array.isArray(t)?t.map(r=>x(e,r,n,o)):typeof t=="object"&&t!==null?Object.entries(t).reduce((i,[a,c])=>Object.assign(i,{[a]:x(`${e}.${a}`,c,n,o)}),{}):t}s(x,"resolveValue");function Ae(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"&&I(r.$value))return Ae(r.$value,t)}}s(Ae,"inferTypeFromReference");function Lt(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"&&I(a.$value)&&(c=Ae(a.$value,e)),t[r]={...a,...c?{$type:c}:{},$resolvedValue:x(a.$path,a.$value,e,n)}}catch(a){const c=a instanceof Error?a.message:String(a),l=i,u=l.$path,p=l.$source;let d,h;c.includes("Circular reference detected")?(d="circular",h=c):c.includes("Reference not found")?(d="missing",h=c):(d="type-mismatch",h=f.RESOLVE.TYPE_MISMATCH(u)),o.push({type:d,path:u,source:p,message:h})}return{resolved:t,errors:o}}s(Lt,"resolve");function Ot(e,t,n,o){const r=t.slice(1,-1),i=n.pathIndex.get(r);if(!i)throw new Error(f.RESOLVE.REFERENCE_NOT_FOUND(r,e));if(o.has(i)){const l=n.tokens[i];throw!l||!("$path"in l)?new Error(f.RESOLVE.REFERENCE_NOT_FOUND(r,e)):new Error(f.RESOLVE.CIRCULAR_REFERENCE(e,l.$path))}const a=n.tokens[i];if(!a||!("$value"in a))throw new Error(f.RESOLVE.REFERENCE_NOT_FOUND(r,e));o.add(i);const c=x(i,a.$value,n,o);return o.delete(i),c}s(Ot,"resolveReferenceChain");function b(e){return{success:!0,value:e}}s(b,"success");function T(e){return{success:!1,error:e}}s(T,"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(o=>typeof o=="number"||o==="none")||t.alpha!==void 0&&typeof t.alpha!="number"||t.hex!==void 0&&typeof t.hex!="string")}s(te,"isW3CColorValue");function R(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(R,"validateW3CColorValue");function _t(e){const t=R(e);return t.length>0?T(t.join(", ")):b(e)}s(_t,"validateW3CColorValueResult");function Dt(e){const t=_t(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)),l=r==="none"?"none":Number(r.toFixed(4));if(i!==void 0&&i!==1){const u=Number(i.toFixed(4));return b(`oklch(${a} ${c} ${l} / ${u})`)}return b(`oklch(${a} ${c} ${l})`)}s(Dt,"formatW3CColorToOKLCH");const Ft={isObject:s(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObject")};function g(e,t,n,o){if(I(t))return[];switch(e.type){case"object":return vt(e,t,n,o);case"union":return Ct(e,t,n,o);case"array":return wt(e,t,n,o);default:return kt(e,t,n,o)}}s(g,"validateSchema");function kt(e,t,n,o){return e.type!==typeof t?[{path:n,message:e.errorMessage?.(t,n)||f.VALIDATE.INVALID_TYPE(e.type,t,n),source:o}]:e.validate?.(t,n,o)??[]}s(kt,"validateSimpleValue");function vt(e,t,n,o){if(!Ft.isObject(t))return[{path:n,message:e.errorMessage?.(t,n)||f.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:f.VALIDATE.MISSING_REQUIRED_PROPERTY(a,n),source:o});for(const[a,c]of Object.entries(e.properties))a in i&&r.push(...g(c,i[a],`${n}.${a}`,o));return r}s(vt,"validateObject");function Ct(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=g(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:f.VALIDATE.INVALID_TYPE(e.oneOf.map(a=>a.type).join(" or "),t,n),source:o}]:r}s(Ct,"validateUnion");function wt(e,t,n,o){return Array.isArray(t)?e.validate?.(t,n,o)??[]:[{path:n,message:e.errorMessage?.(t,n)||f.VALIDATE.INVALID_TYPE("array",t,n),source:o}]}s(wt,"validateArray");const j={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)?R(e).map(r=>({path:t,message:`Invalid color at ${t}: ${r}`,source:n})):[{path:t,message:f.VALIDATE.INVALID_COLOR(e,t),source:n}],"validate")}]}};function Vt(e,t,n){return g(j.schema,e,t,n)}s(Vt,"validateColor");const P={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 xt(e,t,n){return g(P.schema,e,t,n)}s(xt,"validateNumber");const E={schema:{type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_DIMENSION(e,t),"errorMessage"),properties:{value:P.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 Rt(e,t,n){return g(E.schema,e,t,n)}s(Rt,"validateDimension");const be={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(r=>typeof r=="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 jt(e,t,n){return g(be.schema,e,t,n)}s(jt,"validateFontFamily");const Pt=["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: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)=>Pt.includes(e.toLowerCase())?[]:[{path:t,message:f.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}],"validate")}]}};function Mt(e,t,n){return g(Ne.schema,e,t,n)}s(Mt,"validateFontWeight");const Ut=["ms","s"],ne={schema:{type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_DURATION(e,t),"errorMessage"),properties:{value:P.schema,unit:{type:"string",validate:s((e,t,n)=>Ut.includes(e)?[]:[{path:t,message:f.VALIDATE.INVALID_DURATION_UNIT(e,t),source:n}],"validate")}},required:["value","unit"]}};function Gt(e,t,n){return g(ne.schema,e,t,n)}s(Gt,"validateDuration");const Se={schema:{type:"array",errorMessage:s((e,t)=>f.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:f.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}];const[r,,i]=o;return r<0||r>1||i<0||i>1?[{path:t,message:f.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}]:[]},"validate")}};function Wt(e,t,n){return g(Se.schema,e,t,n)}s(Wt,"validateCubicBezier");const Bt={schema:{type:"object",properties:{fontFamily:be.schema,fontSize:E.schema,letterSpacing:E.schema,lineHeight:P.schema,fontWeight:Ne.schema},required:["fontFamily","fontSize"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_TYPOGRAPHY(e,t),"errorMessage")}};function Yt(e,t,n){return g(Bt.schema,e,t,n)}s(Yt,"validateTypography");const Ht=["solid","dashed","dotted","double","groove","ridge","outset","inset"],Kt=["round","butt","square"],zt={type:"object",errorMessage:s((e,t)=>f.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(...g(E.schema,i,`${t}.${a}`,n))}),r},"validate")},lineCap:{type:"string",validate:s((e,t,n)=>Kt.includes(e)?[]:[{path:t,message:f.VALIDATE.INVALID_STROKE_LINE_CAP(e,t),source:n}],"validate")}},required:["dashArray","lineCap"]},Le={schema:{type:"union",oneOf:[{type:"string",validate:s((e,t,n)=>!Ht.includes(e)&&typeof e=="string"?[{path:t,message:f.VALIDATE.INVALID_STROKE_STYLE(e,t),source:n}]:[],"validate")},zt]}};function qt(e,t,n){return g(Le.schema,e,t,n)}s(qt,"validateStrokeStyle");const Jt={schema:{type:"object",properties:{color:j.schema,width:E.schema,style:Le.schema},required:["color","width","style"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_BORDER(e,t),"errorMessage")}};function Xt(e,t,n){return g(Jt.schema,e,t,n)}s(Xt,"validateBorder");const Zt={schema:{type:"object",properties:{duration:ne.schema,delay:ne.schema,timingFunction:Se.schema},required:["duration","delay","timingFunction"],errorMessage:s((e,t)=>f.VALIDATE.INVALID_TRANSITION(e,t),"errorMessage")}};function Qt(e,t,n){return g(Zt.schema,e,t,n)}s(Qt,"validateTransition");const Oe={schema:{type:"object",properties:{color:{type:"union",oneOf:[j.schema]},offsetX:E.schema,offsetY:E.schema,blur:E.schema,spread:E.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 en(e,t,n){const o=[];return Array.isArray(e)?(e.forEach((r,i)=>{o.push(...g(Oe.schema,r,`${t}[${i}]`,n))}),o):g(Oe.schema,e,t,n)}s(en,"validateShadow");const tn={type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_GRADIENT(e,t),"errorMessage"),properties:{color:j.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"]},nn={schema:{type:"array",errorMessage:s((e,t)=>f.VALIDATE.INVALID_ARRAY(e,t),"errorMessage"),validate:s((e,t,n)=>{const o=e,r=[];return o.forEach((i,a)=>{r.push(...g(tn,i,`${t}[${a}]`,n))}),r},"validate")}};function on(e,t,n){return g(nn.schema,e,t,n)}s(on,"validateGradient");const rn={schema:{type:"object",errorMessage:s((e,t)=>f.VALIDATE.INVALID_FLUID_DIMENSION(e,t),"errorMessage"),properties:{min:E.schema,max:E.schema},required:["min","max"]}};function sn(e,t,n){return g(rn.schema,e,t,n)}s(sn,"validateFluidDimension");const an={color:Vt,dimension:Rt,fluidDimension:sn,duration:Gt,cubicBezier:Wt,fontFamily:jt,fontWeight:Mt,number:xt,strokeStyle:qt,typography:Yt,border:Xt,shadow:en,gradient:on,transition:Qt};function cn(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:f.VALIDATE.MISSING_REQUIRED_PROPERTY("$value",o.$path),source:o.$source});continue}const r=an[o.$type];if(!r){t.push({path:o.$path,message:f.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(cn,"validate");async function ln(e){const{trees:t,errors:n}=await(e.type==="memory"?St(e.data):Nt(e.config)),{tokens:o,errors:r}=At(t),i=cn(o),{resolved:a,errors:c}=Lt(o);return{trees:t,resolved:a,errors:{load:n,flatten:r,validation:i,resolution:c}}}s(ln,"loadAndResolveTokens");function _e(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}`}}s(_e,"convertStrokeStyleToken");function un(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:_e(e.style).value;return{value:`${t} ${o} ${n}`}}s(un,"convertBorderToken");function De(e,t="native"){return te(e)?fn(e):b(e)}s(De,"convertColorToString");function fn(e){switch(e.colorSpace){case"oklch":return Dt(e);case"display-p3":return pn(e);case"srgb":return dn(e);case"hsl":return hn(e);default:return T(`Unsupported color space: ${e.colorSpace}. Supported color spaces: oklch, display-p3, srgb, hsl.`)}}s(fn,"formatW3CColorNative");function pn(e){if(e.colorSpace!=="display-p3")return T(`Expected display-p3 color space, got: ${e.colorSpace}`);if(!Array.isArray(e.components)||e.components.length!==3)return T("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 T("Display P3 Red component must be between 0 and 1 or 'none'");if(n!=="none"&&(n<0||n>1))return T("Display P3 Green component must be between 0 and 1 or 'none'");if(o!=="none"&&(o<0||o>1))return T("Display P3 Blue component must be between 0 and 1 or 'none'");if(r!==void 0&&(r<0||r>1))return T("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 l=Number(r.toFixed(4));return b(`color(display-p3 ${i} ${a} ${c} / ${l})`)}return b(`color(display-p3 ${i} ${a} ${c})`)}s(pn,"formatW3CColorToP3");function dn(e){if(e.colorSpace!=="srgb")return T(`Expected srgb color space, got: ${e.colorSpace}`);const t=R(e);if(t.length>0)return T(`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),l=r==="none"?"none":Math.round(r*255);if(i!==void 0&&i!==1){const u=Number(i.toFixed(4));return b(`rgb(${a} ${c} ${l} / ${u})`)}return b(`rgb(${a} ${c} ${l})`)}s(dn,"formatW3CColorToRGB");function hn(e){if(e.colorSpace!=="hsl")return T(`Expected hsl color space, got: ${e.colorSpace}`);const t=R(e);if(t.length>0)return T(`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),l=r==="none"?"none":Math.round(r);if(i!==void 0&&i!==1){const d=Number(i.toFixed(4)),h=c==="none"?"none":`${c}%`,y=l==="none"?"none":`${l}%`;return b(`hsl(${a} ${h} ${y} / ${d})`)}const u=c==="none"?"none":`${c}%`,p=l==="none"?"none":`${l}%`;return b(`hsl(${a} ${u} ${p})`)}s(hn,"formatW3CColorToHSL");function mn(e,t){if(typeof e=="string"&&I(e))return{value:e};const n=t.colorFallbackStrategy;if(te(e))return In(e,n);const o=De(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(mn,"convertColorToken");function In(e,t){const n=De(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:yn(e.colorSpace),value:o}]}}s(In,"convertW3CColorToken");function yn(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(yn,"getFeatureQuery");function $n(e){return I(e)?{value:e}:{value:`cubic-bezier(${e.join(", ")})`}}s($n,"convertCubicBezierToken");function gn(e){return I(e)?{value:e}:{value:`${e.value}${e.unit}`}}s(gn,"convertDimensionToken");function Tn(e){return I(e)?{value:e}:{value:`${e.value}${e.unit}`}}s(Tn,"convertDurationToken");function Fe(e,t=16){return e.unit==="px"?e.value:e.value*t}s(Fe,"normalizeToPixels");function En(e,t){const{min:n,max:o}=e,r=t.fluidConfig,i=16,a=Fe(n,i),c=Fe(o,i),l=r.min,u=r.max;if(a===c)return{value:`${a/i}rem`};const p=a/i,d=c/i,h=l/i,y=u/i,$=(d-p)/(y-h),A=-1*h*$+p;return{value:`clamp(${p}rem, ${A.toFixed(2)}rem + ${($*100).toFixed(2)}vw, ${d}rem)`}}s(En,"convertFluidDimension");function An(e,t){return I(e)?{value:e}:En(e,t)}s(An,"convertFluidDimensionToken");function M(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(M,"quoteFont");function bn(e){return I(e)?{value:e}:{value:Array.isArray(e)?e.map(n=>M(n)).join(", "):M(e)}}s(bn,"convertFontFamilyToken");const Nn={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 ke(e){return I(e)?{value:e}:typeof e=="number"?{value:e}:{value:Nn[e.toLowerCase()]??e}}s(ke,"convertFontWeightToken");function Sn(e){return I(e)?{value:e}:{value:`linear-gradient(${e.map(n=>{const o=(I(n.color),n.color),r=I(n.position)?n.position:`${n.position*100}`;return`${o} ${r}%`}).join(", ")})`}}s(Sn,"convertGradientToken");function Ln(e){return I(e)?{value:e}:{value:e}}s(Ln,"convertNumberToken");function ve(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}`,r=I(e.spread)?e.spread:`${e.spread.value}${e.spread.unit}`,i=(I(e.color),e.color);return`${e.inset?"inset ":""}${t} ${n} ${o} ${r} ${i}`}s(ve,"convertSingleShadow");function On(e){return I(e)?{value:e}:Array.isArray(e)?{value:e.map(ve).join(", ")}:{value:ve(e)}}s(On,"convertShadowToken");function Ce(e){return e?`${e.value}${e.unit}`:"0ms"}s(Ce,"formatDuration");function _n(e){if(I(e))return{value:e};const t=I(e.duration)?e.duration:Ce(e.duration),n=I(e.timingFunction)?e.timingFunction:`cubic-bezier(${e.timingFunction.join(", ")})`,o=e.delay&&(I(e.delay)?e.delay:Ce(e.delay));return{value:[t,n,o].filter(Boolean).join(" ")}}s(_n,"convertTransitionToken");function Dn(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=>M(n)).join(", "):M(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:ke(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}s(Dn,"convertTypographyToken");const we={duration:Tn,number:Ln,cubicBezier:$n,color:mn,dimension:gn,fluidDimension:An,typography:Dn,border:un,shadow:On,gradient:Sn,transition:_n,strokeStyle:_e,fontFamily:bn,fontWeight:ke};function Fn(e,t){const n=we[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(Fn,"convertSingleToken");function Ve(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(!we[i.$type])continue;const a={fluidConfig:t.transforms.fluid,colorFallbackStrategy:t.transforms.colorFallbackStrategy,path:i.$path,resolvedTokens:e};o[r]=Fn(i,a)}return o}s(Ve,"convertTokens");function kn(e,t,n){const o={};for(const[r,i]of Object.entries(e)){const a={default:Ve(i.default,t,n)};for(const[c,l]of Object.entries(i))c!=="default"&&(a[c]=Ve(l,t,n));o[r]=a}return o}s(kn,"convert");function vn(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 r(i){const a={default:{}};o[i]=a;const c=n.get(i);if(c)for(const l of c)a[l]={};return a}s(r,"addCollection");for(const i of t)r(i);for(const i of e){const{collection:a,theme:c="default",tokens:l}=i,u=o[a]||r(a);let p=u[c];p||(p=u[c]={});for(const[d,h]of Object.entries(l)){const y=d.replace(`${a}.`,"");p[y]=h}}return{tokens:o}}s(vn,"normalizeTokens");function Cn(e,t){const n=new Map;for(const[o,r]of Object.entries(t)){if(!("$source"in r)){for(const l of e){const u=l.collection;n.has(u)||n.set(u,new Map);const p=n.get(u),d=l.theme;p.has(d)||p.set(d,{}),p.get(d)[o]=r}continue}const i=r.$source.collection,a=r.$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]=r),a&&(c.has(a)||c.set(a,{}),c.get(a)[o]=r)}return e.map(o=>{const r=n.get(o.collection);if(!r)return{collection:o.collection,theme:o.theme,tokens:{}};if(o.theme){const a=r.get(o.theme)||{};return{collection:o.collection,theme:o.theme,tokens:a}}const i=r.get(void 0)||{};return{collection:o.collection,theme:o.theme,tokens:i}})}s(Cn,"processTrees");async function wn(e,t,n,o){const r=Cn(e,t),{tokens:i}=vn(r);return kn(i,n,o?l=>o.some(u=>u.path===l||u.path.startsWith(`${l}.`)):void 0)}s(wn,"processAndConvertTokens");const U=["reset","global","compositions","blocks","utilities"];async function oe(e,t){const n=[],o=await z([N(e,"**/*.css"),N(e,"**/*.scss"),N(e,"**/*.sass"),N(e,"**/*.less")],{ignore:[N(e,w)]});for(const r of o){const i=Vn(r,e);if(i){const a=_(e,r);n.push({path:a,layer:i,relativePath:a})}}return n}s(oe,"discoverAllFiles");function Vn(e,t){const n=_(t,e);if(n.includes("global/")||n.startsWith("global/"))return de(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(Vn,"categorizeFile");function xn(e){return e.sort((t,n)=>{const o=U.indexOf(t.layer),r=U.indexOf(n.layer);return o!==r?o-r:t.path.localeCompare(n.path)})}s(xn,"sortFilesByLayer");function Rn(){return`@layer ${U.join(", ")};
|
|
18
|
+
`}s(Rn,"getLayerDefinitions");function xe(e){const t=[];t.push(Rn());const n=e.reduce((o,r)=>{const i=o[r.layer]??[];return o[r.layer]=[...i,r],o},{});for(const o of U){const r=n[o];if(!(!r||r.length===0))for(const i of r)t.push(`@import "${i.path}" layer(${i.layer});`)}return t.join(`
|
|
19
|
+
`)}s(xe,"generateIndexContent");async function jn(e,t){const n=N(e,w),o=await oe(e),r=xn(o),i=xe(r);return await C.writeFile(n,i),_(process.cwd(),n)}s(jn,"generateIndex");async function Pn(e,t){const n=N(e,w);if(!D(n))return!0;try{const o=await C.stat(n),r=await oe(e,t);for(const i of r){const a=N(e,i.path);if(D(a)&&(await C.stat(a)).mtime>o.mtime)return!0}return!1}catch{return!0}}s(Pn,"shouldRegenerateIndex");const Mn=`/*!
|
|
20
|
+
* This file was automatically generated by sugarcube.
|
|
21
|
+
* You should NOT make any changes in this file as it will be overwritten.
|
|
22
|
+
* To make changes, edit your design token files instead.
|
|
23
|
+
* Additionally, you should exclude this file from your linter and/or formatter
|
|
24
|
+
* to prevent it from being checked or modified.
|
|
22
25
|
*/
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
`,Un=`/*!
|
|
28
|
+
* This file was automatically generated by sugarcube.
|
|
29
|
+
* You should NOT make any changes in this file as it will be overwritten.
|
|
30
|
+
* To make changes, edit your utilities configuration instead.
|
|
31
|
+
* Additionally, you should exclude this file from your linter and/or formatter
|
|
32
|
+
* to prevent it from being checked or modified.
|
|
29
33
|
*/
|
|
30
34
|
|
|
31
|
-
`;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
`)
|
|
36
|
-
`}
|
|
37
|
-
|
|
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(`
|
|
35
|
+
`;function G(e){return e.replace(/\r\n/g,`
|
|
36
|
+
`).replace(/\r/g,`
|
|
37
|
+
`).trim()}s(G,"normalizeContent");function Gn(e){return Mn+e}s(Gn,"addWarningBanner");async function Wn(e){for(const t of e){const n=Gn(t.css);try{await fe(he(t.path),{recursive:!0});let o=!0;if(D(t.path))try{const r=await K(t.path,"utf-8");G(r)===G(n)&&(o=!1)}catch{}o&&await pe(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}s(Wn,"writeCSSVariablesToDisk");async function Bn(e){for(const t of e){const n=Un+t.css;try{await fe(he(t.path),{recursive:!0});let o=!0;if(D(t.path))try{const r=await K(t.path,"utf-8");G(r)===G(n)&&(o=!1)}catch{}o&&await pe(t.path,n,"utf-8")}catch(o){throw new Error(`Failed to write utility CSS file ${t.path}: ${o instanceof Error?o.message:"Unknown error"}`)}}return e}s(Bn,"writeCSSUtilitiesToDisk");const Re=m.array(m.string()).min(1,"At least one file path must be specified"),re=m.object({source:Re,themes:m.record(Re).optional()}),je=m.record(m.string(),re),Pe=m.object({min:m.number(),max:m.number()}),Me=m.object({source:m.string(),directions:m.union([m.enum(["top","right","bottom","left","x","y","full","all"]),m.array(m.enum(["top","right","bottom","left","x","y","full","all"]))]).optional(),prefix:m.string().optional(),stripDuplicates:m.boolean().optional(),collection:m.string().optional()}),Ue=m.union([Me,m.array(Me)]),Ge=m.object({tokens:m.union([je,re]).optional(),transforms:m.object({fluid:Pe.optional(),colorFallbackStrategy:m.enum(["native","polyfill"]).optional()}).optional(),output:m.object({css:m.string().optional(),components:m.string().optional(),separate:m.boolean().optional()}).optional(),utilities:m.record(m.string(),Ue).optional()}),We=m.object({tokens:m.union([je,re]).optional(),transforms:m.object({fluid:Pe,colorFallbackStrategy:m.enum(["native","polyfill"])}),output:m.object({css:m.string(),components:m.string(),separate:m.boolean()}),utilities:m.record(m.string(),Ue).optional()}),L={output:{css:"src/styles",components:"src/components/ui",separate:!1},transforms:{fluid:{min:320,max:1200},colorFallbackStrategy:"native"}},Yn="default",se="default";function ie(e){const t={tokens:e.tokens,transforms:{fluid:e.transforms?.fluid??L.transforms.fluid,colorFallbackStrategy:e.transforms?.colorFallbackStrategy??L.transforms.colorFallbackStrategy},output:{css:e.output?.css??L.output.css,separate:e.output?.separate??L.output.separate}};return(e.output?.components!==void 0||L.output.components!==void 0)&&(t.output.components=e.output?.components??L.output.components),e.utilities&&(t.utilities=e.utilities),t}s(ie,"fillDefaults");function W(e){const t=Ge.safeParse(e);if(!t.success){const n=t.error.errors.map(o=>{const r=o.path.join(".");return f.CONFIG.INVALID_CONFIG(r||"root",o.message)});throw new Error(n.join(`
|
|
38
|
+
`))}return t.data}s(W,"validateUserConfig");function ae(e){const t=We.safeParse(e);if(!t.success){const n=t.error.errors.map(o=>{const r=o.path.join(".");return f.CONFIG.INVALID_CONFIG(r||"root",o.message)});throw new Error(n.join(`
|
|
39
|
+
`))}return Kn(t.data),t.data}s(ae,"validateInternalConfig");function Be(e){const t=W(e),n=ie(t);return ae(n)}s(Be,"validateConfig");function Hn(e){try{const t=JSON.parse(e);return Be(t)}catch(t){throw t instanceof SyntaxError?new Error(f.CONFIG.INVALID_JSON(t.message)):t}}s(Hn,"parseAndValidateConfig");function Kn(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=de(r),a=o.get(i)||[];o.set(i,[...a,r])}for(const[r,i]of o)if(i.length>1)throw new Error(f.CONFIG.DUPLICATE_FILENAMES(t,r,i))}}s(Kn,"validateFileNames");function ce(e="sugarcube.config"){const t=[".ts",".js"];for(const n of t){const o=me(process.cwd(),`${e}${n}`);if(D(o))return o}return null}s(ce,"findConfigFile");function zn(e="sugarcube.config"){return ce(e)!==null}s(zn,"configFileExists");async function Ye(e){try{await import("tsx");const t=tt(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(f.CONFIG.INVALID_CONFIG("root","Config file must export a default object"))}catch(t){throw t instanceof Error?new Error(f.CONFIG.INVALID_CONFIG("root",t.message)):t}}s(Ye,"loadTSConfig");async function He(e){if(e.endsWith(".ts")||e.endsWith(".js"))return await Ye(e);const n=await C.readFile(e,"utf-8");return JSON.parse(n)}s(He,"loadConfigFile");function Ke(e){if(e)return me(process.cwd(),e);const t=ce();if(!t)throw new Error(f.CONFIG.FILE_NOT_FOUND(F));return t}s(Ke,"resolveConfigPath");async function qn(e){const t=Ke(e);try{const n=await He(t);return{config:W(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(qn,"loadUserConfig");async function Jn(e){const t=Ke(e);try{const n=await He(t),o=W(n),r=ie(o);return{config:ae(r),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(Jn,"loadInternalConfig");class ze 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 Xn=process.env.DEBUG==="true";class Zn{static{s(this,"Instrumentation")}constructor(t=n=>void process.stderr.write(`${n}
|
|
40
|
+
`)){this.defaultFlush=t}#t=new ze(()=>({value:0}));#n=new ze(()=>({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(`
|
|
40
42
|
${n.join(`
|
|
41
43
|
`)}
|
|
42
|
-
`)}[Symbol.dispose](){
|
|
44
|
+
`)}[Symbol.dispose](){Xn&&this.report()}}const k="--",O="-",Qn=["all","full"],eo={top:"t",right:"r",bottom:"b",left:"l",x:"x",y:"y",full:"",all:""},to={top:"block-start",right:"inline-end",bottom:"block-end",left:"inline-start",x:"inline",y:"block"};function no(e){return eo[e]}s(no,"getDirectionAbbreviation");function qe(e,t){if(t==="full"||t==="all")return e;const n=to[t];return n?`${e}${O}${n}`:e}s(qe,"getLogicalProperty");const oo=["top","right","bottom","left","x","y","full"];function ro(e){return(Array.isArray(e)?e:[e]).flatMap(n=>n==="all"?oo:[n])}s(ro,"expandDirections");function Je(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(Je,"isTokenTypeValidForProperty");const Xe=new WeakMap;function Ze(e){const t=Xe.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 Xe.set(e,n),n}s(Ze,"buildPathIndex");function B(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 l=t.source.slice(0,c);l&&o.push(`${l}.${t.prefix}.${e}`,`${l}.${t.prefix}.${e.split("-").join(".")}`)}}if(t.collection){const c=n[t.collection];if(!c)return null;const l=c[se];if(!l)return null;const u=Ze(l);for(const p of o){const d=u.get(p);if(d){if(t.property&&d.$type&&!Je(d.$type,t.property))continue;return d.$path.split(".")}}return null}const r=[],i=Object.keys(n).sort();for(const c of i){const l=n[c];if(!l)continue;const u=l[se];if(!u)continue;const p=Ze(u);for(const d of o){const h=p.get(d);if(h){if(t.property&&h.$type&&!Je(h.$type,t.property))continue;r.push({collection:c,token:h});break}}}if(r.length===0)return null;if(r.length>1){const c=r.map(p=>p.collection).join(", "),l=r[0];if(!l)return null;const u=l.token.$path;throw new Error(f.UTILITIES.TOKEN_PATH_CONFLICT(u,c))}const a=r[0];return a?a.token.$path.split("."):null}s(B,"findMatchingToken");function le(e,t){return t.stripDuplicates&&t.prefix&&e.startsWith(`${t.prefix}-`)?e.slice(t.prefix.length+1):e}s(le,"stripDuplicatePrefix");function Y(e,t=""){const n=e??"",o=n||t?O:"";return new RegExp(`^${n}${t}${o}(.+)$`)}s(Y,"createUtilityPattern");function ue(e,t,n){return[Y(t.prefix),r=>{const i=r[1];if(!i)return{};const a=le(i,t),c={...t,property:e},l=B(a,c,n);return l?{[e]:`var(${k}${l.join(O)})`}:{}}]}s(ue,"createSimpleRule");function so(e,t,n,o){if(n==="all")return ue(e,t,o);const r=no(n);return[Y(t.prefix,r),a=>{const c=a[1];if(!c)return{};const l=le(c,t),u={...t,property:e},p=B(l,u,o);return p?{[qe(e,n)]:`var(${k}${p.join(O)})`}:{}}]}s(so,"createDirectionalRule");function io(e,t){return[Y(e),o=>{const r=o[1];if(!r)return{};for(const{property:i,config:a,direction:c,tokens:l}of t){const u=le(r,a),p={...a,property:i},d=B(u,p,l);if(d)return c?{[qe(i,c)]:`var(${k}${d.join(O)})`}:{[i]:`var(${k}${d.join(O)})`}}return{}}]}s(io,"createSmartRule");function ao(e,t,n){const o=t.source.indexOf("."),r=o!==-1?t.source.slice(0,o):t.source;return[Y(r),a=>{const c=a[1];if(!c)return{};const l={...t,property:e},u=B(c,l,n);return u?{[e]:`var(${k}${u.join(O)})`}:{}}]}s(ao,"createDirectTokenPathRule");function co(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(co,"validateUtilityConfig");function lo(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);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(f.UTILITIES.INVALID_COLLECTION(o,a.collection,n))}}s(lo,"validateInputs");function uo(e,t){lo(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(co(c,r),c.prefix){const l=c.prefix;o[l]||(o[l]=[]),o[l].push({property:r,config:c,direction:null,tokens:t})}else{const l=ao(r,c,t);n.push(l)}}for(const[r,i]of Object.entries(o))if(i.length===1){const a=i[0];if(!a)continue;const{property:c,config:l,tokens:u}=a;if(l.directions){const p=ro(l.directions);(Array.isArray(l.directions)?l.directions:[l.directions]).includes("all")&&n.push(ue(c,l,u));for(const y of p)Qn.includes(y)||n.push(so(c,l,y,u))}else n.push(ue(c,l,u))}else n.push(io(r,i));return n}s(uo,"convertConfigToUnoRules");function fo(e){return"source"in e&&Array.isArray(e.source)}s(fo,"isSingleCollection");export{Yn as DEFAULT_COLLECTION,L as DEFAULT_CONFIG,st as DEFAULT_DESIGN_TOKENS_PATH,rt as DEFAULT_STYLES_PATH,se as DEFAULT_THEME,ot as DEFAULT_UTILITIES_FILENAME,J as DEFAULT_VARIABLES_FILENAME,f as ErrorMessages,q as GLOBAL_DIR,Zn as Instrumentation,F as SUGARCUBE_CONFIG_FILE,w as SUGARCUBE_FILE,nt as UTILITIES_DIR,S as VARIABLES_FILE_SUFFIX,zn as configFileExists,uo as convertConfigToUnoRules,oe as discoverAllFiles,ie as fillDefaults,ce as findConfigFile,$t as generateCSSVariables,jn as generateIndex,xe as generateIndexContent,We as internalConfigSchema,Ie as isResolvedToken,ct as isResolvedTokenOfType,fo as isSingleCollection,ln as loadAndResolveTokens,Jn as loadInternalConfig,Ye as loadTSConfig,qn as loadUserConfig,Hn as parseAndValidateConfig,wn as processAndConvertTokens,Pn as shouldRegenerateIndex,Ge as userConfigSchema,Be as validateConfig,ae as validateInternalConfig,W as validateUserConfig,Bn as writeCSSUtilitiesToDisk,Wn as writeCSSVariablesToDisk};
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sugarcube-org/core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.7",
|
|
4
4
|
"publishConfig": {
|
|
5
|
-
"access": "public"
|
|
5
|
+
"access": "public",
|
|
6
|
+
"provenance": false
|
|
6
7
|
},
|
|
7
8
|
"description": "Core functionality for sugarcube",
|
|
8
|
-
"license": "
|
|
9
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
9
10
|
"main": "./dist/index.js",
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
12
|
"type": "module",
|
|
@@ -17,18 +18,17 @@
|
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
19
20
|
"dist",
|
|
20
|
-
"README.md"
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE.md"
|
|
21
23
|
],
|
|
22
24
|
"devDependencies": {
|
|
23
|
-
"pkgroll": "
|
|
24
|
-
"tsx": "^4.19.2"
|
|
25
|
+
"pkgroll": "2.5.1"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"zod": "^3.21.4"
|
|
28
|
+
"fast-glob": "3.3.2",
|
|
29
|
+
"pathe": "2.0.3",
|
|
30
|
+
"tsx": "4.19.2",
|
|
31
|
+
"zod": "3.21.4"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "pkgroll --minify",
|