@designid/tokens 1.0.2 → 1.0.3
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/bin/build.js +228 -226
- package/bin/watch.js +8 -8
- package/package.json +1 -1
- package/types/utils.d.ts +1 -1
package/bin/build.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`,_.linkHref){let
|
|
4
|
-
`}else if(_?.src&&
|
|
2
|
+
var A2=Object.defineProperty;var W0=($,Y)=>{for(var X in Y)A2($,X,{get:Y[X],enumerable:!0,configurable:!0,set:(Z)=>Y[X]=()=>Z})};var F=($,Y)=>()=>($&&(Y=$($=0)),Y);var H0={};W0(H0,{transformColorValueAsync:()=>L2,transformColorValue:()=>x,transformColorToken:()=>O$,setAlpha:()=>q$,isColor:()=>b,initializeColorspace:()=>E2});import Q$ from"colorjs.io";async function K0(){if(Z$===null){let{colorspace:$}=await c();Z$=$||"hex"}return Z$}function B2(){return Z$||"hex"}async function E2(){await K0()}function q$($,Y){let X=new Q$($);if(Y||Y===0)X.alpha=Y/100;return x(X)}function G0($,Y){if(!$)return $;if(Y&&Y.type!=="color")return $;if(typeof $==="string")$=new Q$($);if(typeof $?.to!=="function")return $;let X=B2();try{switch(X){case"hex":return $.to("srgb").toString({format:"hex"});case"rgb":case"srgb":return $.to("srgb").toString();case"srgb-linear":return $.to("srgb-linear").toString();case"display-p3":case"p3":return $.to("p3").toString();case"a98rgb":case"a98-rgb":return $.to("a98rgb").toString();case"prophoto":case"prophoto-rgb":return $.to("prophoto").toString();case"rec2020":case"rec-2020":return $.to("rec2020").toString();case"xyz":case"xyz-d65":return $.to("xyz-d65").toString();case"xyz-d50":return $.to("xyz-d50").toString();case"lab":case"cielab":return $.to("lab").toString();case"lab-d65":return $.to("lab-d65").toString();case"oklab":return $.to("oklab").toString();case"lch":case"cielch":return $.to("lch").toString();case"oklch":return $.to("oklch").toString();case"hsl":return $.to("hsl").toString();case"hsv":case"hsb":return $.to("hsv").toString();case"hwb":return $.to("hwb").toString();case"luv":return $.to("luv").toString();case"lchuv":return $.to("lchuv").toString();case"jzazbz":return $.to("jzazbz").toString();case"jzczhz":return $.to("jzczhz").toString();case"ictcp":return $.to("ictcp").toString();default:return $.to(X).toString()}}catch(Z){return console.warn(`Unsupported colorspace '${X}', falling back to hex. Error:`,Z),$.to("srgb").toString({format:"hex"})}}async function L2($,Y){return await K0(),G0($,Y)}function x($,Y){return G0($,Y)}function O$($,Y,X,Z){try{if($=v(Y,Z),Y.$type==="color"&&Y.original?.$value&&Y.original?.$value!==Y.$value){if(p(Y.original.$value))$=k(Y.original.$value,X,Z,Y);else $=T(Y);if(!l(Z)&&Y.original?.$extensions?.mode?.[Z])$=Y.original.$extensions.mode[Z]}if(p($))$=k($,X,Z,Y);return x($)}catch{return $=v(Y,Z),x($)}}function b($){try{if($)return new Q$($),!0;return!1}catch{return!1}}var Z$=null;var s=F(()=>{S()});var I$=F(()=>{S()});function T($,Y){let{isIncludedOriginalValue:X=!1,fallbackValue:Z=null}=Y??{};if(X)return $?.original?.$value??$?.$value??$.value??Z;return $?.$value??$?.value??Z}function v($,Y){return Y&&($?.$extensions?.mode?.[Y]||typeof $?.$extensions?.mode?.[Y]==="number")?$.$extensions.mode[Y]:T($,{fallbackValue:$?.original?.$value??$?.$value??$?.value})??null}function z0($,Y){return Y.allTokens.find((X)=>X.path.join(".")===$)??null}function k($,Y,X,Z){let q=p($),U=null,K=$??T(Z),W=null;if(q){if(U=z0(q,Y),X&&U&&U?.$extensions?.mode?.[X]!==U.original?.$extensions?.mode?.[X])K=U.original?.$extensions?.mode?.[X],W=U.original?.$extensions?.alpha??W;else if(U?.$extensions?.mode?.[X])K=U.$extensions.mode[X],W=U.$extensions?.alpha??W;else if(U?.original?.$value)K=U?.original.$value??U?.$value,W=U?.original.$extensions?.alpha??W}if(K!==$&&p(K))K=k(K,Y,X,Z);if(K&&(W||Z?.$extensions?.alpha||W===0||Z?.original?.$extensions?.alpha===0))W=W??Z?.$extensions?.alpha??null,K=q$(K,W);return K=x(K,U??Z),K??$}function p($){if(typeof $!=="string")return null;let Y=/{[^}]+}/g,X=$.match(Y);if(X?.length!==1)return null;return X[0].slice(1,-1)}var N$=F(()=>{S()});import{spawnSync as Q2}from"child_process";import{existsSync as y,mkdirSync as O2,readFileSync as I2,unlinkSync as A0,writeFileSync as E4}from"fs";import{resolve as _4,join as P,basename as w4,normalize as Q4,relative as O4,sep as I4,dirname as B0}from"path";async function J2(){return`${(await g$()).$metaData?.tokenNamespace||"tokens"}.icons`}async function E0($){let X=P($,"designid.config.ts");if(y(P($,"designid.config.mjs")))A0(P($,"designid.config.mjs"));let Z=P($,"designid.config.js");if(y(Z))A0(Z);if(y(X)){let q=Q2("bun",["build",X,"--outfile ./designid.config.mjs","--minify","--target","node","--packages","external","--no-bundle"],{stdio:"inherit",cwd:$,shell:!0});if(q.status!==0)console.error("Failed to compile designid.config.mjs with bun."),process.exit(q.status??1);if(q.status===0)return new Promise((U)=>U(!0))}}async function t($="json"){let{tokenNamespace:Y}=await c();return`${Y}-design-system.tokens.svg${$==="d.ts"||$==="js"?".config":""}.${$}`}function a($){if(!y($))O2($,{recursive:!0})}async function V$($,Y=!1){let X=W$(),Z;if(X.endsWith(".json"))Z=JSON.parse(I2(X,"utf8").trim()??"{}");else if(X.endsWith(".ts"))if(typeof globalThis.Bun<"u"){if(Z=await import(X),Z.default)Z=Z.default}else{$=$??B0(X)+"/";let U=b$($);if(U&&(Y||!y(U)))await E0($);if(Z=await import(U),Z.default)Z=Z.default}else{$=$??B0(X)+"/";let q=b$($);if(q&&(Y||!y(q)))await E0($);if(Z=await import(q),Z.default)Z=Z.default}return Z}async function U$($=!1){let{baseDir:Y}=await n(),X=process.cwd(),q=P(X,Y),{buildDir:U,distDir:K}=await n();if($)try{a(P(q,U)),a(P(q,K))}catch(W){console.error("Error creating directories:",W)}return q}function b$($){return $?P($,"designid.config.mjs"):P(process.cwd(),"designid.config.mjs")}function W$(){let $=process.argv.find((W)=>W.startsWith("--config=")),[,Y]=$?.split("=")??[];if(Y)return Y;let X=process.cwd(),Z=b$(X),q=P(X,"designid.config.ts"),U=y(Z),K=y(q);if(U)return Z;else if(K)return q;throw console.error("Config file not found"),Error("Config file not found")}async function n($=!1){let Y=W$(),Z=(await V$(process.cwd(),$)).$paths;if(!Z)throw console.error("Project paths not found"),Error("Project paths not found");return{configFile:Y,...Z}}async function c(){let Y=(await V$(process.cwd())).$metaData;if(!Y)throw console.error("Project metaData not found"),Error("Project metaData not found");if(!Y.colorspace)Y.colorspace="hex";if(!Y.fontNamespace)Y.fontNamespace=`${Y.dsNamespace}.font`;if(!Y?.tokens?.css?.mediaQuery?.match)Y={...Y??{},tokens:{...Y.tokens??{},css:{...Y.tokens?.css??{},mediaQuery:{...Y.tokens?.css?.mediaQuery??{},match:"[data-theme]"}}}};if(Y?.tokens?.css?.mediaQuery&&typeof Y.tokens.css.mediaQuery.separateThemeFiles!=="boolean")Y.tokens.css.mediaQuery.separateThemeFiles=!1;if(!Y.dsNamespace)Y.dsNamespace=Y.tokenNamespace;let X=await J2();return{...Y,icons:Y.icons??{objectPath:X},dsNamespace:Y.dsNamespace}}async function g$(){if(!x$){let $=W$();x$=await V$(process.cwd()),_0=$}return x$}async function T$(){if(!j$){let Y=(await g$()).$metaData;if(!Y)throw console.error("Project metaData not found"),Error("Project metaData not found");if(!Y.dsNamespace)Y.dsNamespace=Y.tokenNamespace;let Z=`${Y.tokenNamespace||"tokens"}.icons`;j$={...Y,icons:Y.icons??{objectPath:Z},dsNamespace:Y.dsNamespace}}return j$}async function w0($=!1){if(!S$){let X=(await g$()).$paths;if(!X)throw console.error("Project paths not found"),Error("Project paths not found");S$={configFile:_0,...X}}return S$}async function m(){if(!P$){let{distDir:$,assets:Y,buildDir:X}=await w0(!0),{fontNamespace:Z,tokenNamespace:q,icons:U}=await T$(),K=await U$(),W=process.cwd(),H=P(W,$,"css");P$={distDir:$,assets:Y,fontNamespace:Z,__dirname:K,workspaceRoot:W,distCSSPath:H,buildDir:X,tokenNamespace:q,icons:U}}return P$}async function y$(){if(!D$){let{icons:$}=await T$();D$=$}return D$}var x$=null,_0=null,j$=null,S$=null,P$=null,D$=null;var K$=F(()=>{S()});function l($){return $===f$}var f$="light";var Q0=F(()=>{K$()});async function h$($){let Y=await y$();$=$.replace(/<\?xml[^>]*\?>\s*/,""),$=$.replace(/<!DOCTYPE [^>]*>\s*/,"");let X=$.match(/<svg[^>]*>/),Z=$.match(/viewBox="([\d\s.]+)"/),[q]=X??[],U=q;if(q&&U){let W=Y?.style?.fill,H=/id="[^"]*"/.test(q);if(!U.includes("xmlns="))U=U.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"');if(!H&&W)U=U.replace("<svg",`<svg id="${W}"`);else if(H&&W)U=U.replace(/id="[^"]*"/,`id="${W}"`)}if(Z&&q&&U){let W=Z[1].split(" ").map(Number),H=W[2],G=W[3],z=Y?.size??24,A=H/G*z;$=$.replace(/height="[\d.]+px?"/,`height="${z}px"`),$=$.replace(/width="[\d.]+px?"/,`width="${A}px"`);let B=/width="[\d.]+(px)?"/.test(q),E=/height="[\d.]+(px)?"/.test(q);if(!B)U=U.replace("<svg",`<svg width="${A}px"`);else U=U.replace(/width="[\d.]+(px)?"/,`width="${A}px"`);if(!E)U=U.replace("<svg",`<svg height="${z}px"`);else U=U.replace(/height="[\d.]+(px)?"/,`height="${z}px"`);$=$.replace(q,U)}if(!$?.match(/data-style="([^"]*)"/)&&Y?.style?.type)$=$.replace("<svg ",`<svg data-style="${Y.style.type}" `);return $}var O0=F(()=>{S()});var M0=F(()=>{K$();S()});import{copyFileSync as F2,existsSync as x2,mkdirSync as N0,statSync as j2}from"fs";import{writeFile as S2}from"fs/promises";import{join as j,relative as P2}from"path";async function v$($,Y){try{let{assets:X,workspaceRoot:Z,distDir:q,__dirname:U}=await m(),K=X?.fonts?.sourceDir?j(U,X.fonts.sourceDir):null,W=j("assets","fonts"),H=j(Z,q),G=X?.fonts?.distDir?j(H,X.fonts.distDir.replace(/^\.\//,"")):j(H,W);if(!$||!K)return;let z="",A=Y&&X?.fonts?.distDir?j(Y,X.fonts.distDir.replace(/^\.\//,"")):G;for(let _ of $){if(!_)continue;if(z+=`/**** ${_.family} ${_.style} ****/
|
|
3
|
+
`,_.linkHref){let O=await(await fetch(_.linkHref)).text();z+=`${O.replace(/\s+/g," ").replace(/:\s+/g,":")}
|
|
4
|
+
`}else if(_?.src&&K){let J=_.directory??_.family.toLowerCase().replace(/\s+/g,"-"),O=j(K,J,_.src);try{if(!x2(O)||!j2(O).isFile()){console.warn(`Font file not found: ${O}`);continue}}catch{console.warn(`Error accessing font file: ${O}`);continue}try{N0(j(A,J),{recursive:!0}),F2(j(K,J,_.src),j(A,J,_.src))}catch(w){console.warn(`Error copying font file ${_.src}:`,w instanceof Error?w.message:w);continue}let Q;if(X?.fonts?.cssImportPath)Q=j(X.fonts.cssImportPath,J,_.src).replace(/\\/g,"/");else{let{distCSSPath:w}=await m(),I=Y?j(Y,"css"):w,N=P2(I,A);Q=j(N,J,_.src).replace(/\\/g,"/")}z+=`@font-face {
|
|
5
5
|
font-family: "${_.family}";
|
|
6
6
|
font-style: ${_.faceStyle};
|
|
7
7
|
font-weight: ${_.weight};
|
|
8
|
-
src: url("${
|
|
8
|
+
src: url("${Q}") format("${_.format}");
|
|
9
9
|
}
|
|
10
|
-
`}}let{distCSSPath:B}=await
|
|
11
|
-
${
|
|
12
|
-
`)}`;throw Error(G)}return q}function V0($,X,Y){let Z=[];if(X.generateModes&&$.extensions?.mode){for(let[W,q]of Object.entries($.extensions.mode))if(q!==void 0)Z.push({...$,name:`${$.name}@${W}`,value:q,path:[...$.path,`@${W}`]})}if(X.generateModes&&!$.extensions?.mode&&(Array.isArray($.value)||typeof $.value==="object"&&$.value!==null)){let W=!1,q=!1,U=(K)=>{if(typeof K!=="object"||K===null)return!1;if(K.$extensions?.mode)return!0;return Object.values(K).some((G)=>{if(typeof G==="object"&&G!==null)return U(G);return!1})};if(Array.isArray($.value))W=$.value.some((K)=>typeof K==="string"&&K.includes("{")||typeof K==="object"&&K!==null&&Object.values(K).some((G)=>typeof G==="string"&&G.includes("{"))),q=$.value.some((K)=>U(K));else W=Object.values($.value).some((K)=>typeof K==="string"&&K.includes("{")),q=U($.value);if(W||q){if(["color","shadow","border","background","surface","composition"].includes($.type)){let H;if(Array.isArray($.value))H=$.value.map((z)=>{if(typeof z==="string"&&z.startsWith("{")&&z.endsWith("}")){let A=z.slice(1,-1);if(!A.includes("@dark"))return`{${A}@dark}`;return z}else if(typeof z==="object"&&z!==null){let A={};for(let[B,E]of Object.entries(z))if(typeof E==="string"&&E.startsWith("{")&&E.endsWith("}")){let L=E.slice(1,-1),_=`${L}@dark`,w=Y?.get(L),J=Y?.has(_)||w?.extensions?.mode?.dark!==void 0||w&&(Array.isArray(w.value)||typeof w.value==="object"&&w.value!==null);if(!L.includes("@dark")&&J)A[B]=`{${_}}`;else A[B]=E}else A[B]=E;return A}return z});else if(typeof $.value==="object"&&$.value!==null){H={};let z=(A)=>{if(typeof A==="string"){if(A.startsWith("{")&&A.endsWith("}")){let B=A.slice(1,-1),E=`${B}@dark`,L=(w,J=new Set)=>{if(J.has(w))return!1;J.add(w);let O=Y?.get(w);if(!O){let Q=w.match(/^(.+)@([^@]+)$/);if(Q){let[,I,F]=Q,T=Y?.get(I);if(T){if(T.extensions?.mode?.dark!==void 0)return!0;if(T.extensions?.generators)return!0;return L(I,J)}}return!1}if(O.extensions?.mode?.dark!==void 0)return!0;if(Y?.has(`${w}@dark`))return!0;if(typeof O.value==="string"&&O.value.startsWith("{")&&O.value.endsWith("}")){let Q=O.value.slice(1,-1);return L(Q,J)}if(Array.isArray(O.value)||typeof O.value==="object"&&O.value!==null){let Q=(I)=>{if(typeof I!=="object"||I===null)return!1;if(I.$extensions?.mode)return!0;return Object.values(I).some((F)=>{if(typeof F==="object"&&F!==null)return Q(F);return!1})};if(Array.isArray(O.value))return O.value.some((I)=>typeof I==="string"&&I.includes("{")&&L(I.slice(1,-1),new Set(J))||typeof I==="object"&&I!==null&&(Object.values(I).some((F)=>typeof F==="string"&&F.includes("{")&&L(F.slice(1,-1),new Set(J)))||Q(I)));else if(typeof O.value==="object")return Object.values(O.value).some((I)=>typeof I==="string"&&I.includes("{")&&L(I.slice(1,-1),new Set(J)))||Q(O.value)}return!1},_=L(B);if(!B.includes("@dark")&&_)return`{${E}}`}return A}if(typeof A==="object"&&A!==null){if(A.$extensions?.mode?.dark)return A.$extensions.mode.dark;let B={};for(let[E,L]of Object.entries(A))B[E]=z(L);return B}return A};for(let[A,B]of Object.entries($.value))H[A]=z(B)}Z.push({...$,name:`${$.name}@dark`,value:H,path:[...$.path,"@dark"],extensions:{...$.extensions,autoGenerated:!0}})}}}if(X.generateModes&&!$.extensions?.mode&&typeof $.value==="string"&&$.value.startsWith("{")&&$.value.endsWith("}")){let W=$.value.slice(1,-1),q=(z,A=new Set)=>{if(A.has(z))return!1;A.add(z);let B=Y?.get(z);if(!B){let E=z.match(/^(.+)@([^@]+)$/);if(E){let[,L,_]=E,w=Y?.get(L);if(w){if(w.extensions?.mode?.dark!==void 0)return!0;if(w.extensions?.generators)return!0;return q(L,A)}}return!1}if(B.extensions?.mode?.dark!==void 0)return!0;if(Y?.has(`${z}@dark`))return!0;if(typeof B.value==="string"&&B.value.startsWith("{")&&B.value.endsWith("}")){let E=B.value.slice(1,-1);return q(E,A)}if(Array.isArray(B.value)||typeof B.value==="object"&&B.value!==null){let E=(L)=>{if(typeof L!=="object"||L===null)return!1;if(L.$extensions?.mode)return!0;return Object.values(L).some((_)=>{if(typeof _==="object"&&_!==null)return E(_);return!1})};if(Array.isArray(B.value))return B.value.some((L)=>typeof L==="string"&&L.includes("{")&&q(L.slice(1,-1),new Set(A))||typeof L==="object"&&L!==null&&(Object.values(L).some((_)=>typeof _==="string"&&_.includes("{")&&q(_.slice(1,-1),new Set(A)))||E(L)));else if(typeof B.value==="object")return Object.values(B.value).some((L)=>typeof L==="string"&&L.includes("{")&&q(L.slice(1,-1),new Set(A)))||E(B.value)}return!1},U=q(W);if(["color","shadow","border","background","surface","composition"].includes($.type)&&U&&U&&!W.includes("@dark")){let z=`{${W}@dark}`;Z.push({...$,name:`${$.name}@dark`,value:z,path:[...$.path,"@dark"],extensions:{...$.extensions,autoGenerated:!0}})}}if(X.generateDerivedTokens&&$.extensions?.generators)for(let W of $.extensions.generators)for(let[q,U]of Object.entries(W.value)){let K=x0($.name,q),{generators:G,...H}=$.extensions;Z.push({...$,name:K,value:$.value,path:[...$.path,q],extensions:{...H,generator:{type:W.type,value:U}}})}if(X.generateBreakpointTokens&&$.extensions?.breakpoints)for(let[W,q]of Object.entries($.extensions.breakpoints)){let U=`${$.name}@${W.replace(/[^a-zA-Z0-9]/g,"_")}`,K=q.$value||q.value;if(K&&typeof K==="object"&&"$value"in K)K=K.$value;else if(!K&&typeof q==="object"){let{...z}=q;if(Object.keys(z).length>0)K=z}let G=q.$extensions||q.$extensions,H=q.$type;if(!H&&q.value&&typeof q.value==="object")H=q.value.$type;Z.push({...$,name:U,value:K,path:[...$.path,`@${W}`],type:H||$.type,extensions:{mediaQuery:W,...G?{mode:G.mode||G.$mode,generators:G.generators||G.$generators,...Object.fromEntries(Object.entries(G).filter(([z])=>!["mode","$mode","generators","$generators"].includes(z)))}:{}}})}return Z}function v2($,X){let Y=t($.value,X),Z=$.type;if(typeof $.value==="string"&&n($.value)){let q=$.value.slice(1,-1),U=X.tokens.get(q);if(U){if(["border","shadow","typography","composition"].includes(U.type))Z=U.type;else if(typeof U.value==="string"&&o(U.value)){let K=U$(U.value),G=new Set;for(let H of K)if(H.type==="reference"&&H.ref&&typeof H.ref==="string"){let z=H.ref.slice(1,-1),A=X.tokens.get(z);if(A&&["border","shadow","typography","composition"].includes(A.type))G.add(A.type)}if(G.size===1)Z=Array.from(G)[0]}}}if(typeof $.value==="string"&&o($.value)){let q=U$($.value),U=new Set;for(let K of q)if(K.type==="reference"&&K.ref&&typeof K.ref==="string"){let G=K.ref.slice(1,-1),H=X.tokens.get(G);if(H&&["border","shadow","typography","composition"].includes(H.type))U.add(H.type)}if(U.size===1)Z=Array.from(U)[0]}if(typeof Y==="object"&&Y!==null&&["border","shadow","typography","composition"].includes(Z))Y=V(Y,X);if($.extensions?.generator&&typeof $.extensions.generator==="object"&&"type"in $.extensions.generator&&"value"in $.extensions.generator)Y=h0($.value,$.extensions.generator.type,$.extensions.generator.value,X);let W=p2($.name,X.options);if(Z==="color"&&typeof Y==="string"&&h(Y))Y=P(Y,$);if(typeof Y==="string"&&p(Y))Y=y$(Y);return{...$,type:Z,value:Y,cssVar:W}}function V($,X){if(typeof $==="string"){if(n($))return p$($,X);else if(o($))return f0($,X)}if(Array.isArray($))return $.map((Y)=>V(Y,X));if(typeof $==="object"&&$!==null){if("$value"in $&&typeof $.$value==="string")return V($.$value,X);if("value"in $&&typeof $.value==="string"&&"$type"in $){if(X.mode&&$.$extensions?.mode?.[X.mode])return V($.$extensions.mode[X.mode],X);return V($.value,X)}if("value"in $&&typeof $.value==="object"&&"$type"in $){let Z=$.value,W=$.$extensions?.delimiter?.character||" ";if($.$type==="composition"&&Z&&typeof Z==="object")return Object.values(Z).map((U)=>V(U,X)).join(W);return V($.value,X)}let Y={};for(let[Z,W]of Object.entries($))Y[Z]=V(W,X);return Y}return $}function t($,X){if(typeof $==="string"){if(o($))return f0($,X);else if(n($))return p$($,X)}else if(typeof $==="object"&&$!==null&&"$ref"in $)return y0($,X);return $}function p$($,X){let Y=$.slice(1,-1),Z=X.tokens.get(Y);if(!Z)return console.warn(`Token reference not found: ${$}`),X.brokenReferences.push($),$;let W;if(Z.extensions?.generator&&typeof Z.extensions.generator==="object"&&"type"in Z.extensions.generator&&"value"in Z.extensions.generator)W=h0(Z.value,Z.extensions.generator.type,Z.extensions.generator.value,X);else if(X.mode&&Z.extensions?.mode?.[X.mode])W=t(Z.extensions.mode[X.mode],X);else W=t(Z.value,X);if(Z.type==="color"&&typeof W==="string"&&h(W))W=P(W,Z);if(typeof W==="string"&&p(W))W=y$(W);return W}function y0($,X){let Z=$.$ref.slice(2).replace(/\//g,"."),W=X.tokens.get(Z);if(!W)return console.warn(`JSON Pointer reference not found: ${$.$ref}`),X.brokenReferences.push($.$ref),$.$ref;return t(W.value,X)}function f0($,X){let Y=U$($),Z=Y.some((U)=>U.value.includes(",")),W=!0,q=[];for(let U of Y){let K;if(U.type==="reference"&&U.ref){if(typeof U.ref==="string"&&n(U.ref)){K=p$(U.ref,X);let G=U.ref.slice(1,-1),H=X.tokens.get(G);if(!H||!["border","shadow","typography","composition"].includes(H.type))W=!1}else if(typeof U.ref==="object"&&"$ref"in U.ref)K=y0(U.ref,X)}else if(K=U.value,U.value.trim()&&U.value.trim()!==",")W=!1;q.push(K)}if(Z&&W)return q.filter((U)=>typeof U==="object"&&U!==null&&typeof U!=="string");return q.map((U)=>String(U)).join("")}function h0($,X,Y,Z){let W=t($,Z);switch(X){case"alpha":if(typeof W==="string")return m2(W,Number(Y)/100);break;case"scale":if(typeof W==="string"&&W.match(/[\d.]+/))return d2(W,Number(Y));break;case"hue":if(typeof W==="string")return u2(W,Number(Y));break;default:return console.warn(`Unknown generator type: ${X}`),W}return W}function p2($,X,Y){let Z=$.replace(/\./g,"-");Z=Z.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),Z=Z.replace(/@[^@]*(?:screen|width|height|min|max|orientation).*$/i,""),Z=Z.replace(/-@/g,"-").replace(/@/g,"-"),Z=Z.replace(/-(?:dark|light)$/,"");let W=Z,q=!0,U=X.prefix||"";if(X.transformName){if(W=X.transformName(Z),W=W.replace(/-+$/,""),W!==Z)q=!1}let K=q&&U?`${U}-${W}`:W,G=Y?`-${Y}`:"";return`--${K}${G}`.replace(/[^a-zA-Z0-9-_]/g,"-")}function m2($,X){try{if(!h($))return $;let Y=new g0($);return Y.alpha=X,P(Y)}catch(Y){return console.warn(`Failed to apply alpha to color "${$}": ${Y}`),$}}function d2($,X){let Y=$.match(/([\d.]+)(\w+)/);if(Y){let[,Z,W]=Y;return`${parseFloat(Z)*X}${W}`}return $}function u2($,X){try{if(!h($))return $;let Z=new g0($).to("oklch");return Z.h=(Z.h+X)%360,P(Z)}catch(Y){return console.warn(`Failed to shift hue for color "${$}": ${Y}`),$}}var m$=N(()=>{S0();i()});function d$($){if($.type==="typography"||$.type==="fontWeight"||$.type==="fontFamily")return!0;if($.type==="dimension"&&$.name.includes("typography"))return!0;if($.name.includes("typography")||$.name.includes("font"))return!0;return!1}function K$($,X={}){let{rootSelector:Y=":root",separateThemeFiles:Z=!1,generateMediaQueries:W=!1,customHeader:q}=X;if(Z)return c2($,X);let U=new Map,K=new Map;U.set("light",[]),U.set("dark",[]);for(let E of $){if(typeof E.value==="string"&&p(E.value))continue;if(d$(E))continue;let L=` ${E.cssVar}: ${D(E.value,E.type)};`;if(W&&E.name.includes("@media")){let w=H$(E);if(w){if(!K.has(w))K.set(w,[]);K.get(w).push(L);continue}}let _=E.name.match(/@(dark|light)$/);if(_){let w=_[1];U.get(w).push(L)}else U.get("light").push(L)}let G="";if(q)G+=`${q}
|
|
10
|
+
`}}let{distCSSPath:B}=await m(),E=Y?j(Y,"css"):B,L=`${E}/fonts.css`;N0(E,{recursive:!0}),await S2(L,z,{flag:"w",encoding:"utf-8"})}catch(X){console.error("Error appending typography tokens:",X)}}var p$=F(()=>{S()});function o($){if(typeof $!=="string"||!$.startsWith("{")||!$.endsWith("}"))return!1;let Y=$.slice(1,-1);return!Y.includes("{")&&!Y.includes("}")&&Y.trim()!==""}function e($){if(typeof $!=="string")return!1;let Y=/\{[^}]+\}/g,X=$.match(Y);return!!(X&&X.length>0&&$.length>X.join("").length)}function G$($){let Y=[],X=/\{[^}]+\}/g,Z=0,q;while((q=X.exec($))!==null){if(q.index>Z){let K=$.slice(Z,q.index);if(K)Y.push({type:"literal",value:K})}let U=q[0];if(U.startsWith("{#/"))Y.push({type:"reference",value:U,ref:{$ref:U.slice(2,-1)}});else Y.push({type:"reference",value:U,ref:U});Z=q.index+q[0].length}if(Z<$.length){let U=$.slice(Z);if(U)Y.push({type:"literal",value:U})}return Y}function F0($){return!!$.$extensions?.$mode}function x0($){return!!($.$extensions?.$generators&&Array.isArray($.$extensions.$generators))}function j0($){return!!($.$extensions?.$breakpoints&&typeof $.$extensions.$breakpoints==="object")}function S0($,Y){return`${$}${Y}`}function P0($){return typeof $==="object"&&$!==null&&"$value"in $}function D0($){return typeof $==="object"&&$!==null&&!("$value"in $)}var b0=()=>{};function C0($){if(typeof $!=="string")return!1;let Y=$.trim();return Y.startsWith("<svg")&&Y.includes("</svg>")}function V0($){if(typeof $!=="string")return!1;return $.startsWith("data:image/png;base64,")||$.startsWith("iVBORw0KGgo")}function g0($){if(typeof $!=="string")return!1;return $.startsWith("data:image/jpeg;base64,")||$.startsWith("data:image/jpg;base64,")||$.startsWith("/9j/")}function b2($){let Y=$.trim();return Y=Y.replace(/\s+/g," ").replace(/>\s+</g,"><").trim(),`data:image/svg+xml;base64,${Buffer.from(Y,"utf-8").toString("base64")}`}function C2($){if($.startsWith("data:image/png;base64,"))return $;return`data:image/png;base64,${$}`}function V2($){if($.startsWith("data:image/jpeg;base64,")||$.startsWith("data:image/jpg;base64,"))return $;return`data:image/jpeg;base64,${$}`}function $$($){if(!$||typeof $!=="string")return $;if($.startsWith("data:"))return $;if(C0($))return b2($);else if(V0($))return C2($);else if(g0($))return V2($);return $}function g2($){if(typeof $!=="string")return!1;return $.startsWith("data:image/svg+xml;")||$.startsWith("data:image/png;")||$.startsWith("data:image/jpeg;")||$.startsWith("data:image/jpg;")||$.startsWith("data:image/gif;")||$.startsWith("data:image/webp;")}function C($){return C0($)||V0($)||g0($)||g2($)}import{readFileSync as T2,readdirSync as y2,statSync as f2}from"fs";import{join as h2}from"path";import y0 from"colorjs.io";function d$($){let Y={};function X(Z){let q=y2(Z);for(let U of q){let K=h2(Z,U);if(f2(K).isDirectory())X(K);else if(U.endsWith(".tokens.json"))try{let H=T2(K,"utf-8");if(!H.trim())continue;let G=JSON.parse(H);f0(Y,G)}catch(H){console.warn(`Failed to load token file: ${K}`,H)}}}return X($),Y}function f0($,Y){for(let X in Y)if(Y[X]&&typeof Y[X]==="object"&&!Array.isArray(Y[X])){if(!$[X])$[X]={};f0($[X],Y[X])}else $[X]=Y[X]}function u$($,Y={}){let X=[];function Z(q,U=[]){for(let[K,W]of Object.entries(q)){if(K.startsWith("$"))continue;let H=[...U,K],G=H.join(".");if(P0(W)){let z={path:H,name:G,type:W.$type,value:W.$value,description:W.$description,extensions:W.$extensions?{mode:F0(W)?W.$extensions.$mode:W.$extensions.mode?W.$extensions.mode:void 0,generators:x0(W)?W.$extensions.$generators:W.$extensions.generators?W.$extensions.generators:void 0,breakpoints:j0(W)?W.$extensions.$breakpoints:W.$extensions.breakpoint?W.$extensions.breakpoint:void 0,...Object.fromEntries(Object.entries(W.$extensions).filter(([A])=>!["$mode","$generators","$breakpoints","mode","generators","breakpoint"].includes(A)))}:void 0,original:W};if(!Y.namespace||G.startsWith(Y.namespace))X.push(z)}else if(D0(W))Z(W,H)}}return Z($),X}function k$($,Y={}){let X=[...$],Z=new Map($.map((G)=>[G.name,G]));if(Y.generateModes||Y.generateDerivedTokens||Y.generateBreakpointTokens)for(let G of $){let z=T0(G,Y,Z);if(X.push(...z),Y.generateModes){for(let A of z)if(A.extensions?.mode&&!A.name.includes("#")){let B=T0(A,Y,Z);X.push(...B)}}}let q=Y.modes||[],U=q.length>0?q[0]:void 0,K={tokens:new Map(X.map((G)=>[G.name,G])),mode:Y.generateModes?U:void 0,options:Y,brokenReferences:[]},W=[];for(let G of X){let z=void 0;for(let E of q)if(G.name.endsWith(`#${E}`)){z=E;break}if(!z&&Y.generateModes)z=U;let A={...K,mode:z},B=v2(G,A);W.push(B)}if(Y.failOnBrokenReferences!==!1&&K.brokenReferences.length>0){let G=[...new Set(K.brokenReferences)],z=`Token reference${G.length>1?"s":""} not found:
|
|
11
|
+
${G.map((A)=>` - ${A}`).join(`
|
|
12
|
+
`)}`;throw Error(z)}return W}function T0($,Y,X){let Z=[];if(Y.generateModes&&$.extensions?.mode){for(let[q,U]of Object.entries($.extensions.mode))if(U!==void 0)Z.push({...$,name:`${$.name}#${q}`,value:U,path:[...$.path,`#${q}`]})}if(Y.generateModes&&!$.extensions?.mode&&(Array.isArray($.value)||typeof $.value==="object"&&$.value!==null)){let q=!1,U=!1,K=(W)=>{if(typeof W!=="object"||W===null)return!1;if(W.$extensions?.mode)return!0;return Object.values(W).some((H)=>{if(typeof H==="object"&&H!==null)return K(H);return!1})};if(Array.isArray($.value))q=$.value.some((W)=>typeof W==="string"&&W.includes("{")||typeof W==="object"&&W!==null&&Object.values(W).some((H)=>typeof H==="string"&&H.includes("{"))),U=$.value.some((W)=>K(W));else q=Object.values($.value).some((W)=>typeof W==="string"&&W.includes("{")),U=K($.value);if(q||U){if(["color","shadow","border","background","surface","composition"].includes($.type)){let G;if(Array.isArray($.value))G=$.value.map((z)=>{if(typeof z==="string"&&z.startsWith("{")&&z.endsWith("}")){let A=z.slice(1,-1);if(!A.includes("#dark")&&!A.includes("@dark"))return`{${A}#dark}`;return z}else if(typeof z==="object"&&z!==null){let A={};for(let[B,E]of Object.entries(z))if(typeof E==="string"&&E.startsWith("{")&&E.endsWith("}")){let L=E.slice(1,-1),_=`${L}#dark`,J=X?.get(L),O=X?.has(_)||J?.extensions?.mode?.dark!==void 0||J&&(Array.isArray(J.value)||typeof J.value==="object"&&J.value!==null);if(!L.includes("#dark")&&!L.includes("@dark")&&O)A[B]=`{${_}}`;else A[B]=E}else A[B]=E;return A}return z});else if(typeof $.value==="object"&&$.value!==null){G={};let z=(A)=>{if(typeof A==="string"){if(A.startsWith("{")&&A.endsWith("}")){let B=A.slice(1,-1),E=`${B}#dark`,L=(J,O=new Set)=>{if(O.has(J))return!1;O.add(J);let Q=X?.get(J);if(!Q){let w=J.match(/^(.+)@([^@]+)$/);if(w){let[,I,N]=w,h=X?.get(I);if(h){if(h.extensions?.mode?.dark!==void 0)return!0;if(h.extensions?.generators)return!0;return L(I,O)}}return!1}if(Q.extensions?.mode?.dark!==void 0)return!0;if(X?.has(`${J}#dark`))return!0;if(typeof Q.value==="string"&&Q.value.startsWith("{")&&Q.value.endsWith("}")){let w=Q.value.slice(1,-1);return L(w,O)}if(Array.isArray(Q.value)||typeof Q.value==="object"&&Q.value!==null){let w=(I)=>{if(typeof I!=="object"||I===null)return!1;if(I.$extensions?.mode)return!0;return Object.values(I).some((N)=>{if(typeof N==="object"&&N!==null)return w(N);return!1})};if(Array.isArray(Q.value))return Q.value.some((I)=>typeof I==="string"&&I.includes("{")&&L(I.slice(1,-1),new Set(O))||typeof I==="object"&&I!==null&&(Object.values(I).some((N)=>typeof N==="string"&&N.includes("{")&&L(N.slice(1,-1),new Set(O)))||w(I)));else if(typeof Q.value==="object")return Object.values(Q.value).some((I)=>typeof I==="string"&&I.includes("{")&&L(I.slice(1,-1),new Set(O)))||w(Q.value)}return!1},_=L(B);if(!B.includes("#dark")&&!B.includes("@dark")&&_)return`{${E}}`}return A}if(typeof A==="object"&&A!==null){if(A.$extensions?.mode?.dark)return A.$extensions.mode.dark;let B={};for(let[E,L]of Object.entries(A))B[E]=z(L);return B}return A};for(let[A,B]of Object.entries($.value))G[A]=z(B)}Z.push({...$,name:`${$.name}#dark`,value:G,path:[...$.path,"#dark"],extensions:{...$.extensions,autoGenerated:!0}})}}}if(Y.generateModes&&!$.extensions?.mode&&typeof $.value==="string"&&$.value.startsWith("{")&&$.value.endsWith("}")){let q=$.value.slice(1,-1),U=(z,A=new Set)=>{if(A.has(z))return!1;A.add(z);let B=X?.get(z);if(!B){let E=z.match(/^(.+)@([^@]+)$/);if(E){let[,L,_]=E,J=X?.get(L);if(J){if(J.extensions?.mode?.dark!==void 0)return!0;if(J.extensions?.generators)return!0;return U(L,A)}}return!1}if(B.extensions?.mode?.dark!==void 0)return!0;if(X?.has(`${z}#dark`))return!0;if(typeof B.value==="string"&&B.value.startsWith("{")&&B.value.endsWith("}")){let E=B.value.slice(1,-1);return U(E,A)}if(Array.isArray(B.value)||typeof B.value==="object"&&B.value!==null){let E=(L)=>{if(typeof L!=="object"||L===null)return!1;if(L.$extensions?.mode)return!0;return Object.values(L).some((_)=>{if(typeof _==="object"&&_!==null)return E(_);return!1})};if(Array.isArray(B.value))return B.value.some((L)=>typeof L==="string"&&L.includes("{")&&U(L.slice(1,-1),new Set(A))||typeof L==="object"&&L!==null&&(Object.values(L).some((_)=>typeof _==="string"&&_.includes("{")&&U(_.slice(1,-1),new Set(A)))||E(L)));else if(typeof B.value==="object")return Object.values(B.value).some((L)=>typeof L==="string"&&L.includes("{")&&U(L.slice(1,-1),new Set(A)))||E(B.value)}return!1},K=U(q);if(["color","shadow","border","background","surface","composition"].includes($.type)&&K&&K&&!q.includes("#dark")&&!q.includes("@dark")){let z=`{${q}#dark}`;Z.push({...$,name:`${$.name}#dark`,value:z,path:[...$.path,"#dark"],extensions:{...$.extensions,autoGenerated:!0}})}}if(Y.generateDerivedTokens&&$.extensions?.generators)for(let q of $.extensions.generators)for(let[U,K]of Object.entries(q.value)){let W=S0($.name,U),{generators:H,...G}=$.extensions;Z.push({...$,name:W,value:$.value,path:[...$.path,U],extensions:{...G,generator:{type:q.type,value:K}}})}if(Y.generateBreakpointTokens&&$.extensions?.breakpoints)for(let[q,U]of Object.entries($.extensions.breakpoints)){let K=`${$.name}@${q.replace(/[^a-zA-Z0-9]/g,"_")}`,W=U.$value||U.value;if(W&&typeof W==="object"&&"$value"in W)W=W.$value;else if(!W&&typeof U==="object"){let{...z}=U;if(Object.keys(z).length>0)W=z}let H=U.$extensions||U.$extensions,G=U.$type;if(!G&&U.value&&typeof U.value==="object")G=U.value.$type;Z.push({...$,name:K,value:W,path:[...$.path,`@${q}`],type:G||$.type,extensions:{mediaQuery:q,...H?{mode:H.mode||H.$mode,generators:H.generators||H.$generators,...Object.fromEntries(Object.entries(H).filter(([z])=>!["mode","$mode","generators","$generators"].includes(z)))}:{}}})}return Z}function v2($,Y){let X=d($.value,Y),Z=$.type;if(typeof $.value==="string"&&o($.value)){let U=$.value.slice(1,-1),K=Y.tokens.get(U);if(K){if(["border","shadow","typography","composition"].includes(K.type))Z=K.type;else if(typeof K.value==="string"&&e(K.value)){let W=G$(K.value),H=new Set;for(let G of W)if(G.type==="reference"&&G.ref&&typeof G.ref==="string"){let z=G.ref.slice(1,-1),A=Y.tokens.get(z);if(A&&["border","shadow","typography","composition"].includes(A.type))H.add(A.type)}if(H.size===1)Z=Array.from(H)[0]}}}if(typeof $.value==="string"&&e($.value)){let U=G$($.value),K=new Set;for(let W of U)if(W.type==="reference"&&W.ref&&typeof W.ref==="string"){let H=W.ref.slice(1,-1),G=Y.tokens.get(H);if(G&&["border","shadow","typography","composition"].includes(G.type))K.add(G.type)}if(K.size===1)Z=Array.from(K)[0]}if(typeof X==="object"&&X!==null&&["border","shadow","typography","composition"].includes(Z))X=f(X,Y);if($.extensions?.generator&&typeof $.extensions.generator==="object"&&"type"in $.extensions.generator&&"value"in $.extensions.generator)X=H$($.value,$.extensions.generator.type,$.extensions.generator.value,Y);let q=p2($.name,Y.options);if(Z==="color"&&typeof X==="string"&&b(X))X=x(X,$);if(typeof X==="string"&&C(X))X=$$(X);return{...$,type:Z,value:X,cssVar:q}}function f($,Y){if(typeof $==="string"){if(o($))return c$($,Y);else if(e($))return v0($,Y)}if(Array.isArray($))return $.map((X)=>f(X,Y));if(typeof $==="object"&&$!==null){if("$value"in $&&typeof $.$value==="string")return f($.$value,Y);if("value"in $&&typeof $.value==="string"&&"$type"in $){if(Y.mode&&$.$extensions?.mode?.[Y.mode])return f($.$extensions.mode[Y.mode],Y);return f($.value,Y)}if("value"in $&&typeof $.value==="object"&&"$type"in $){let Z=$.value,q=$.$extensions?.delimiter?.character||" ";if($.$type==="composition"&&Z&&typeof Z==="object")return Object.values(Z).map((K)=>f(K,Y)).join(q);return f($.value,Y)}let X={};for(let[Z,q]of Object.entries($))X[Z]=f(q,Y);return X}return $}function d($,Y){if(typeof $==="string"){if(e($))return v0($,Y);else if(o($))return c$($,Y)}else if(typeof $==="object"&&$!==null&&"$ref"in $)return h0($,Y);return $}function c$($,Y){let X=$.slice(1,-1),Z=Y.tokens.get(X),q=Y.options.modes||[];if(!Z){if(q.length>0){for(let W of q)if(X.endsWith(`@${W}`)){let H=X.slice(0,-W.length-1)+`#${W}`;if(Z=Y.tokens.get(H),Z)return m$(Z,Y);break}}let K=X.match(/#([^#@]+)$/);if(K){let W=X.substring(0,K.index),H=K[1];if(Z=Y.tokens.get(W),Z){if(Z.extensions?.mode?.[H]){let G=Z.extensions.mode[H],z=d(G,{...Y,mode:H});if(Z.extensions?.generator&&typeof Z.extensions.generator==="object"&&"type"in Z.extensions.generator&&"value"in Z.extensions.generator)z=H$(z,Z.extensions.generator.type,Z.extensions.generator.value,Y);if(Z.type==="color"&&typeof z==="string"&&b(z))z=x(z,Z);if(typeof z==="string"&&C(z))z=$$(z);return z}}}if(q.length>0)for(let W of q){let H=new RegExp(`(@[^@]+)@${W}$`);if(H.test(X)){let G=X.replace(H,`$1#${W}`);if(Z=Y.tokens.get(G),!Z){let z=G.match(/#([^#@]+)$/);if(z){let A=G.substring(0,z.index),B=z[1];if(Z=Y.tokens.get(A),Z&&Z.extensions?.mode?.[B]){let E=Z.extensions.mode[B],L=d(E,{...Y,mode:B});if(Z.extensions?.generator&&typeof Z.extensions.generator==="object"&&"type"in Z.extensions.generator&&"value"in Z.extensions.generator)L=H$(L,Z.extensions.generator.type,Z.extensions.generator.value,Y);if(Z.type==="color"&&typeof L==="string"&&b(L))L=x(L,Z);if(typeof L==="string"&&C(L))L=$$(L);return L}}}else return m$(Z,Y);break}}}if(!Z)return console.warn(`Token reference not found: ${$}`),Y.brokenReferences.push($),$;return m$(Z,Y)}function m$($,Y){let X;if($.extensions?.generator&&typeof $.extensions.generator==="object"&&"type"in $.extensions.generator&&"value"in $.extensions.generator)X=H$($.value,$.extensions.generator.type,$.extensions.generator.value,Y);else if(Y.mode&&$.extensions?.mode?.[Y.mode])X=d($.extensions.mode[Y.mode],Y);else X=d($.value,Y);if($.type==="color"&&typeof X==="string"&&b(X))X=x(X,$);if(typeof X==="string"&&C(X))X=$$(X);return X}function h0($,Y){let Z=$.$ref.slice(2).replace(/\//g,"."),q=Y.tokens.get(Z);if(!q)return console.warn(`JSON Pointer reference not found: ${$.$ref}`),Y.brokenReferences.push($.$ref),$.$ref;return d(q.value,Y)}function v0($,Y){let X=G$($),Z=X.some((K)=>K.value.includes(",")),q=!0,U=[];for(let K of X){let W;if(K.type==="reference"&&K.ref){if(typeof K.ref==="string"&&o(K.ref)){W=c$(K.ref,Y);let H=K.ref.slice(1,-1),G=Y.tokens.get(H);if(!G||!["border","shadow","typography","composition"].includes(G.type))q=!1}else if(typeof K.ref==="object"&&"$ref"in K.ref)W=h0(K.ref,Y)}else if(W=K.value,K.value.trim()&&K.value.trim()!==",")q=!1;U.push(W)}if(Z&&q)return U.filter((K)=>typeof K==="object"&&K!==null&&typeof K!=="string");return U.map((K)=>String(K)).join("")}function H$($,Y,X,Z){let q=d($,Z);switch(Y){case"alpha":if(typeof q==="string")return m2(q,Number(X)/100);break;case"scale":if(typeof q==="string"&&q.match(/[\d.]+/))return d2(q,Number(X));break;case"hue":if(typeof q==="string")return u2(q,Number(X));break;default:return console.warn(`Unknown generator type: ${Y}`),q}return q}function p2($,Y,X){let Z=$.replace(/\./g,"-");Z=Z.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),Z=Z.replace(/@[^@#]*(?:screen|width|height|min|max|orientation).*$/i,""),Z=Z.replace(/#[^#]*$/,""),Z=Z.replace(/-@/g,"-").replace(/@/g,"-");let q=Z,U=!0,K=Y.prefix||"";if(Y.transformName){if(q=Y.transformName(Z),q=q.replace(/-+$/,""),q!==Z)U=!1}let W=U&&K?`${K}-${q}`:q,H=X?`-${X}`:"";return`--${W}${H}`.replace(/[^a-zA-Z0-9-_]/g,"-")}function m2($,Y){try{if(!b($))return $;let X=new y0($);return X.alpha=Y,x(X)}catch(X){return console.warn(`Failed to apply alpha to color "${$}": ${X}`),$}}function d2($,Y){let X=$.match(/([\d.]+)(\w+)/);if(X){let[,Z,q]=X;return`${parseFloat(Z)*Y}${q}`}return $}function u2($,Y){try{if(!b($))return $;let Z=new y0($).to("oklch");return Z.h=(Z.h+Y)%360,x(Z)}catch(X){return console.warn(`Failed to shift hue for color "${$}": ${X}`),$}}var l$=F(()=>{b0();s()});function i$($){if($.type==="typography"||$.type==="fontWeight"||$.type==="fontFamily")return!0;if($.type==="dimension"&&$.name.includes("typography"))return!0;if($.name.includes("typography")||$.name.includes("font"))return!0;return!1}function z$($,Y={}){let{rootSelector:X=":root",separateThemeFiles:Z=!1,generateMediaQueries:q=!1,customHeader:U,modes:K=["light","dark"]}=Y;if(Z)return c2($,Y);let W=new Map,H=new Map;for(let O of K)W.set(O,[]);let G=K.join("|"),z=new RegExp(`#(${G})$`);for(let O of $){if(typeof O.value==="string"&&C(O.value))continue;if(i$(O))continue;let Q=` ${O.cssVar}: ${D(O.value,O.type)};`;if(q&&O.name.includes("@media")){let I=B$(O);if(I){if(!H.has(I))H.set(I,[]);H.get(I).push(Q);continue}}let w=O.name.match(z);if(w){let I=w[1];if(!W.has(I))W.set(I,[]);W.get(I).push(Q)}else{let I=K[0]||"light";W.get(I).push(Q)}}let A="";if(U)A+=`${U}
|
|
13
13
|
|
|
14
|
-
`;let
|
|
15
|
-
${
|
|
14
|
+
`;let B=K[0]||"light",E=W.get(B)||[];if(E.length>0){E.sort(),A+=`${X} {
|
|
15
|
+
${E.join(`
|
|
16
16
|
`)}
|
|
17
|
-
`;let
|
|
18
|
-
&${
|
|
19
|
-
${
|
|
17
|
+
`;for(let O of K){if(O===B)continue;let Q=W.get(O)||[];if(Q.length>0){Q.sort();let w=Y.themeSelector||"[data-theme]",I;if(w.startsWith("."))if(w===".")I=`.${O}`;else I=`${w}-${O}`;else if(w.startsWith("[")&&w.endsWith("]"))if(w.includes("="))I=w.replace(/="[^"]*"/,`="${O}"`);else I=w.replace("]",`="${O}"]`);else I=`${w}-${O}`;A+=`
|
|
18
|
+
&${I} {
|
|
19
|
+
${Q.map((N)=>` ${N}`).join(`
|
|
20
20
|
`)}
|
|
21
21
|
}
|
|
22
|
-
`}
|
|
23
|
-
`}if(
|
|
24
|
-
${
|
|
25
|
-
${
|
|
26
|
-
${
|
|
22
|
+
`}}A+=`}
|
|
23
|
+
`}if(q&&H.size>0)for(let[O,Q]of H)Q.sort(),A+=`
|
|
24
|
+
${O} {
|
|
25
|
+
${X} {
|
|
26
|
+
${Q.map((w)=>` ${w}`).join(`
|
|
27
27
|
`)}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
`;let
|
|
30
|
+
`;let L=[{fileName:"tokens.css",content:A}],_=d0($,Y);L.push(..._);let J=k0($,Y);return L.push(...J),L}function k2($,Y){let X=[];for(let q of $){let K=` ${q.cssVar||A$(q,Y)}: ${D(q.value,q.type)};`;X.push(K)}let Z="";if(Y.customHeader)Z+=`${Y.customHeader}
|
|
31
31
|
|
|
32
|
-
`;if(
|
|
33
|
-
${
|
|
32
|
+
`;if(X.length>0)X.sort(),Z+=`${Y.rootSelector||":root"} {
|
|
33
|
+
${X.join(`
|
|
34
34
|
`)}
|
|
35
35
|
}
|
|
36
|
-
`;return{fileName:"theme.css",content:Z}}function c2($,
|
|
36
|
+
`;return{fileName:"theme.css",content:Z}}function c2($,Y){let X=[],Z=new Map,q=[],U=Y.modes||["light","dark"],K=new Set(U),W=U.join("|"),H=new RegExp(`#(${W})$`);for(let E of $){if(B$(E))continue;if(typeof E.value==="string"&&C(E.value))continue;if(i$(E))continue;let L=E.name.match(H);if(L){let _=L[1];if(K.has(_)){if(!Z.has(_))Z.set(_,[]);Z.get(_).push(E)}else q.push(E)}else q.push(E)}if(q.length>0){let E=z$(q,{...Y,separateThemeFiles:!1})[0];X.push({...E,fileName:"tokens.css"})}let G=U.length>0?U[0]:"default";for(let[E,L]of Z){let _=E===G?":root":`[data-theme="${E}"]`,J=k2(L,{...Y,separateThemeFiles:!1,rootSelector:_});X.push({...J,fileName:`tokens.${E}.css`,theme:E})}let z=l2($,Y);X.push(...z);let A=d0($,Y);X.push(...A);let B=k0($,Y);return X.push(...B),X}function l2($,Y){let X=new Map;for(let U of $){let K=B$(U);if(K){let W=U.name.match(/@(dark|light)$/),H=W?W[1]:"light";if(!X.has(K))X.set(K,new Map);let G=X.get(K);if(!G.has(H))G.set(H,[]);G.get(H).push(U)}}if(X.size===0)return[];let Z=`/**
|
|
37
37
|
* Design System Tokens - Responsive Breakpoints
|
|
38
38
|
* Generated: ${new Date().toISOString()}
|
|
39
39
|
*
|
|
@@ -41,55 +41,55 @@ ${Y.join(`
|
|
|
41
41
|
* Each media query section overrides tokens for specific screen sizes.
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
|
-
`,
|
|
45
|
-
[data-theme="${
|
|
46
|
-
${
|
|
44
|
+
`,q=Array.from(X.keys()).sort();for(let U of q){let K=X.get(U);for(let[W,H]of K){let G=[];for(let z of H){let B=` ${z.cssVar||A$(z,Y)}: ${D(z.value,z.type)};`;G.push(B)}if(G.length>0)G.sort(),Z+=`${U} {
|
|
45
|
+
[data-theme="${W}"] {
|
|
46
|
+
${G.join(`
|
|
47
47
|
`)}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
`}}return[{fileName:"tokens.breakpoints.css",content:Z.trim()}]}function
|
|
52
|
-
* Design System Tokens - Icons (${
|
|
51
|
+
`}}return[{fileName:"tokens.breakpoints.css",content:Z.trim()}]}function d0($,Y){let X=new Map;for(let q of $)if(typeof q.value==="string"&&C(q.value)){let U=q.name.match(/@(dark|light)$/),K=U?U[1]:"light";if(!X.has(K))X.set(K,[]);X.get(K).push(q)}let Z=[];if(X.size===0)return[];if(X.size===1){let[q,U]=Array.from(X.entries())[0],K=p0(U,q,Y);Z.push({fileName:"tokens.icons.css",content:K})}else for(let[q,U]of X){let K=p0(U,q,Y);Z.push({fileName:`tokens.icons.${q}.css`,content:K})}return Z}function p0($,Y,X){let Z=`/**
|
|
52
|
+
* Design System Tokens - Icons (${Y})
|
|
53
53
|
* Generated: ${new Date().toISOString()}
|
|
54
54
|
*
|
|
55
55
|
* This file contains CSS custom properties for icon tokens.
|
|
56
56
|
* Icons are provided as data URIs for direct embedding.
|
|
57
57
|
*/
|
|
58
58
|
|
|
59
|
-
`,
|
|
60
|
-
${
|
|
59
|
+
`,q=[];for(let U of $){let W=` ${U.cssVar||A$(U,X)}: ${D(U.value,U.type)};`;q.push(W)}if(q.length>0){q.sort();let U=Y==="light"?":root":`[data-theme="${Y}"]`;Z+=`${U} {
|
|
60
|
+
${q.join(`
|
|
61
61
|
`)}
|
|
62
62
|
}
|
|
63
|
-
`}return Z}function
|
|
64
|
-
* Design System Tokens - Typography (${
|
|
63
|
+
`}return Z}function A$($,Y){let Z=$.name.split("@")[0].replace(/\.$/,"").replace(/\.+/g,"."),q=u0(Z,Y.hooks);return`--${Y.prefix||X$}-${q.replace(/\./g,"-")}`}function u0($,Y,X){if(!Y?.shortenName?.enabled)return $;let Z=$;if(Y.shortenName.prefix)for(let q of Y.shortenName.prefix)Z=Z.replace(new RegExp(q.find,"g"),q.replace);if(Y.shortenName.suffix){for(let q of Y.shortenName.suffix)if(Z.endsWith(q.find))Z=Z.substring(0,Z.length-q.find.length)+q.replace}if(X&&X!=="light"){let q=`-${X}`;if(Z.endsWith(q))Z=Z.slice(0,-q.length)}return Z}function k0($,Y){let X=new Map,Z=Y.modes||[];for(let U of $)if(i$(U)){if(B$(U))continue;let W=Z.length>0?Z[0]:"default";if(U.name.includes("#")){let H=U.name.split("#"),G=H[H.length-1];if(Z.includes(G))W=G}if(!X.has(W))X.set(W,[]);X.get(W).push(U)}let q=[];for(let[U,K]of X.entries()){let W=i2(K,U,Y,Z);q.push({fileName:`tokens.typography.${U}.css`,content:W})}return q}function i2($,Y,X,Z){let q=`/**
|
|
64
|
+
* Design System Tokens - Typography (${Y})
|
|
65
65
|
* Generated: ${new Date().toISOString()}
|
|
66
66
|
*
|
|
67
67
|
* This file contains CSS custom properties for typography tokens.
|
|
68
68
|
* Includes fontSize, fontWeight, fontFamily, lineHeight, and typography compositions.
|
|
69
69
|
*/
|
|
70
70
|
|
|
71
|
-
`,
|
|
72
|
-
${
|
|
71
|
+
`,U=new Map;for(let K of $){let W="default";if(K.name.includes("@")){let H=K.name.split("@");for(let G of H)if(G.includes("screen_")||G.includes("min_width")||G.includes("max_width")){W=G.replace(/screen_and__/g,"").replace(/min_width__(\d+)px_/g,"min-width: $1px").replace(/max_width__(\d+)px_/g,"max-width: $1px").replace(/_/g," ");break}}if(!U.has(W))U.set(W,[]);U.get(W).push(K)}for(let[K,W]of U.entries()){let H=[];for(let G of W){let A=` ${G.cssVar||A$(G,X)}: ${D(G.value,G.type)};`;H.push(A)}if(H.length>0)if(K==="default"){let G=Y==="light"?":root":`[data-theme="${Y}"]`;H.sort(),q+=`${G} {
|
|
72
|
+
${H.join(`
|
|
73
73
|
`)}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
`}else{let G=
|
|
77
|
-
`;let
|
|
78
|
-
${
|
|
76
|
+
`}else{let G=K.startsWith("(")?K:`(${K})`;q+=`@media ${G} {
|
|
77
|
+
`;let z=Y==="light"?":root":`[data-theme="${Y}"]`;q+=` ${z} {
|
|
78
|
+
${H.sort().map((A)=>` ${A}`).join(`
|
|
79
79
|
`)}
|
|
80
80
|
}
|
|
81
|
-
`,
|
|
81
|
+
`,q+=`}
|
|
82
82
|
|
|
83
|
-
`}}return
|
|
84
|
-
* ${
|
|
85
|
-
* Version: ${
|
|
83
|
+
`}}return q}function D($,Y){if($===null||$===void 0)return"";if(typeof $==="object"&&$!==null&&!Array.isArray($)){let Z=$;if(Z.$value!==void 0){if(typeof Z.$value==="string")return Z.$value;return D(Z.$value,Z.$type||Y)}}let X=String($);switch(Y){case"color":return r2(X);case"dimension":return s2(X);case"duration":return a2(X);case"fontFamily":return n2(X);case"fontWeight":return t2(X);case"cubicBezier":return o2($);case"shadow":return e2($);case"border":return $1($);case"typography":return X1($);case"composition":return r$($);default:if(X.startsWith("data:"))return`"${X}"`;return X}}function r2($){if($.startsWith("oklch(")||$.startsWith("rgb(")||$.startsWith("rgba(")||$.startsWith("hsl(")||$.startsWith("hsla(")||$.startsWith("#"))return $;return $}function s2($){if(/^\d+(\.\d+)?(px|rem|em|%|vh|vw|vmin|vmax)$/.test($))return $;if(/^\d+(\.\d+)?$/.test($))return`${$}rem`;return $}function a2($){if(/^\d+(\.\d+)?(s|ms)$/.test($))return $;if(/^\d+(\.\d+)?$/.test($))return`${$}ms`;return $}function n2($){if(($.includes(",")||$.includes(" "))&&!$.startsWith('"')&&!$.startsWith("'"))return`"${$}"`;return $}function t2($){return{thin:"100","extra-light":"200",light:"300",normal:"400",medium:"500","semi-bold":"600",bold:"700","extra-bold":"800",black:"900"}[$]||$}function o2($){if(Array.isArray($)&&$.length===4)return`cubic-bezier(${$.join(", ")})`;return String($)}function e2($){if(Array.isArray($))return $.map((Y)=>m0(Y)).join(", ");return m0($)}function m0($){if(typeof $==="object"&&$!==null){let Y=$,X=Y.color||"transparent";if(typeof X==="string"&&X.includes("{")&&X.includes("}")){console.warn(`Unresolved token reference in shadow color: ${X}`);let q=X.match(/\{([^}]+)\}/)?.[1];if(q)X=`var(${`--${X$}-${q.replace(/\./g,"-").replace(/@/g,"-")}`})`}let Z=[Y.offsetX||"0",Y.offsetY||"0",Y.blur||"0",Y.spread||"0",X];if(Y.inset)Z.unshift("inset");return Z.join(" ")}return String($)}function $1($){if(typeof $==="object"&&$!==null){let Y=$;return`${Y.width||"1px"} ${Y.style||"solid"} ${Y.color||"transparent"}`}return String($)}function X1($){if(typeof $==="object"&&$!==null){let Y=$,X=Y.fontWeight||"normal",Z=Y.fontSize||"1rem",q=Y.lineHeight||"normal",U=Y.fontFamily||"sans-serif";if(U.includes(" ")&&!U.startsWith('"')&&!U.startsWith("'"))U=`'${U}'`;let K;if(Z.includes("/"))K=Z;else K=`${Z}/${q}`;return`${X} ${K} ${U}`}return String($)}function r$($){if(typeof $!=="object"||$===null)return String($);if(Array.isArray($))return $.map((X)=>r$(X)).join(", ");let Y=$;if(Y.offsetX!==void 0&&Y.offsetY!==void 0)return c0(Y);if(Y.width!==void 0&&Y.style!==void 0&&Y.color!==void 0)return Y1(Y);if(Y.blur!==void 0||Y.saturate!==void 0||Y.brightness!==void 0)return Z1(Y);if(Y.fontSize!==void 0||Y.fontFamily!==void 0)return q1(Y);return U1(Y)}function c0($){let Y=[M($.offsetX)||"0",M($.offsetY)||"0",M($.blur)||"0",M($.spread)||"0",M($.color)||"transparent"];if($.inset&&M($.inset)==="true")Y.unshift("inset");return Y.join(" ")}function Y1($){let Y=M($.width)||"1px",X=M($.style)||"solid",Z=M($.color)||"transparent";return`${Y} ${X} ${Z}`}function Z1($){let Y=[];if($.blur)Y.push(M($.blur)||"blur(0)");if($.saturate)Y.push(M($.saturate)||"saturate(100%)");if($.brightness)Y.push(M($.brightness)||"brightness(100%)");if($.contrast)Y.push(M($.contrast)||"contrast(100%)");if($.hueRotate)Y.push(M($.hueRotate)||"hue-rotate(0deg)");return Y.join(" ")||"none"}function q1($){let Y=M($.fontWeight)||"normal",X=M($.fontSize)||"1rem",Z=M($.lineHeight),q=M($.fontFamily)||"sans-serif";if(q.includes(" ")&&!q.startsWith('"')&&!q.startsWith("'"))q=`'${q}'`;if(X.includes("/"))return`${Y} ${X} ${q}`;else return`${Y} ${X}/${Z||"normal"} ${q}`}function M($){if($===null||$===void 0)return"";if(typeof $==="string")return $;if(typeof $==="object"&&$.value!==void 0)return String($.value);return String($)}function U1($){let Y=[];for(let[,q]of Object.entries($)){let U=q;if(typeof q==="object"&&q!==null&&U.$value&&typeof U.$value==="object"){let K=U.$value;if(K.offsetX!==void 0&&K.offsetY!==void 0){let W=c0(K);if(W)Y.push(W)}else{let W=r$(K);if(W)Y.push(W)}}else{let K=M(q);if(K)Y.push(K)}}let Z=Y.some((q)=>/^\d/.test(q)&&q.includes(" "))?", ":" ";return Y.join(Z)||String($)}function B$($){if($.extensions?.mediaQuery&&typeof $.extensions.mediaQuery==="string"){let X=$.extensions.mediaQuery;if(X=X.replace(/\{universe\.foundation\.breakpoint\.screen\.width\.lg\}/g,"64rem"),!X.startsWith("@media"))X=`@media ${X}`;return X}let Y=$.name.match(/@(media[^@]+)/);if(Y)return`@${Y[1].replace(/_/g," ")}`;if($.name.includes("@screen_and__min_width__300px_"))return"@media screen and (min-width: 300px)";if($.name.includes("@screen_and__min_width__600px_"))return"@media screen and (min-width: 600px)";if($.name.includes("@")&&$.name.includes("_"))return"@media (unknown-breakpoint)";return null}function E$($){let Y=$?.$name||"Design System",X=$?.$version||"1.0.0",Z=new Date().toISOString();return`/**
|
|
84
|
+
* ${Y} - CSS Custom Properties
|
|
85
|
+
* Version: ${X}
|
|
86
86
|
* Generated: ${Z}
|
|
87
87
|
*
|
|
88
88
|
* This file contains CSS custom properties (CSS variables) generated from design tokens.
|
|
89
89
|
* Do not edit this file directly - it will be overwritten.
|
|
90
|
-
*/`}function
|
|
90
|
+
*/`}function W1($){let Y=$.replace(/\r?\n|\r/g,"").replace(/\s+/g," ").trim();return`data:image/svg+xml;base64,${Buffer.from(Y,"utf8").toString("base64")}`}function s$($,Y={}){let{customHeader:X,objectPath:Z="universe.custom.path.icons"}=Y,q="--"+Z.replace(/\./g,"-"),U="";if(X)U+=X+`
|
|
91
91
|
|
|
92
|
-
`;else
|
|
92
|
+
`;else U+=`/**
|
|
93
93
|
* Icon CSS - Base64 Encoded SVG Icons as CSS Custom Properties
|
|
94
94
|
* Generated: ${new Date().toISOString()}
|
|
95
95
|
*
|
|
@@ -103,267 +103,269 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
103
103
|
* Do not edit this file directly - it will be overwritten.
|
|
104
104
|
*/
|
|
105
105
|
|
|
106
|
-
`;
|
|
107
|
-
`;let
|
|
108
|
-
`}return
|
|
109
|
-
`,{fileName:"tokens.icons.css",content:
|
|
106
|
+
`;U+=`:root {
|
|
107
|
+
`;let K=[...$].sort((W,H)=>W.name.localeCompare(H.name));for(let W of K){let H=W.name.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,""),G=`${q}-${W.category}-${H}`;if(Y.hooks?.shortenName?.enabled)G=u0(G,Y.hooks);let z=W1(W.value);U+=` ${G}: url("${z}");
|
|
108
|
+
`}return U+=`}
|
|
109
|
+
`,{fileName:"tokens.icons.css",content:U.trim()}}var L$=F(()=>{S()});import{readFileSync as K1}from"fs";import{join as l0}from"path";async function a$(){try{let{assets:$}=await n(!0),{icons:Y}=await c(),X=await U$(),Z=$?.icons?.distDir??"build",q=l0(X,Z),U=l0(q,"tokens",await t("json")),K=JSON.parse(K1(U,"utf8")),W=Y?.objectPath??"universe.icons",H=W.split("."),G=K;for(let A of H)if(G&&typeof G==="object"&&A in G)G=G[A];else throw Error(`Icon path ${W} not found in icons file`);let z=[];for(let[A,B]of Object.entries(G))if(typeof B==="object"&&B!==null){for(let[E,L]of Object.entries(B))if(typeof L==="object"&&L!==null){let _=L;z.push({name:E,category:A,value:_.$value||"",description:_.$description||"",style:_.$style||"",dimensions:_.$dimensions})}}return z}catch($){return console.warn("Could not load icon data:",$),[]}}async function n$($,Y={}){let{generateTypes:X=!0,generateConsts:Z=!0}=Y,q=Y.icons;if(!q)q=await a$();let U={...Y,icons:q},K=[];if(X)K.push({fileName:"tokens.types.ts",content:G1($,U),type:"types"});if(Z)K.push({fileName:"tokens.constants.ts",content:H1($,U),type:"constants"});return K.push({fileName:"index.ts",content:z1(K),type:"index"}),K}function G1($,Y){let{tokenInterface:X="DesignTokens",includeJSDoc:Z=!0,icons:q=[]}=Y,U=t$("Type Definitions");if(U+=A1($,Z),U+=B1($,Z),q.length>0)U+=E1(q,Z);return U+=L1($,X,Z),U+=w1($,Z),U}function H1($,Y){let{includeJSDoc:X=!0,icons:Z=[]}=Y,q=t$("Token Constants"),U="TokenPaths, CSSVariableNames";if(Z.length>0)U+=", IconNames, IconCategories, Icon";if(q+=`import type { ${U} } from './tokens.types';
|
|
110
110
|
|
|
111
|
-
`,
|
|
112
|
-
`;if($.some((
|
|
113
|
-
`;return
|
|
114
|
-
`,
|
|
115
|
-
| `),Z="";if(
|
|
111
|
+
`,q+=Q1($,X),q+=I1($,X),Z.length>0)q+=O1(Z,X);return q+=J1($,X),q}function z1($){let Y=t$("Main Export");if($.some((X)=>X.type==="types"))Y+=`export type * from './tokens.types';
|
|
112
|
+
`;if($.some((X)=>X.type==="constants"))Y+=`export * from './tokens.constants';
|
|
113
|
+
`;return Y+=`
|
|
114
|
+
`,Y}function A1($,Y){let X=$.map((q)=>`"${q.name}"`).join(`
|
|
115
|
+
| `),Z="";if(Y)Z+=`/**
|
|
116
116
|
* All available token paths as string literals
|
|
117
117
|
*/
|
|
118
118
|
`;return Z+=`export type TokenPaths =
|
|
119
|
-
| ${
|
|
119
|
+
| ${X};
|
|
120
120
|
|
|
121
|
-
`,Z}function
|
|
122
|
-
| `);if(
|
|
123
|
-
* Possible values for ${
|
|
121
|
+
`,Z}function B1($,Y){let X=R1($),Z="";for(let[q,U]of X){let K=`${N1(q)}TokenValue`,W=new Set(U.map((G)=>Y$(G.value))),H=Array.from(W).join(`
|
|
122
|
+
| `);if(Y)Z+=`/**
|
|
123
|
+
* Possible values for ${q} tokens
|
|
124
124
|
*/
|
|
125
|
-
`;Z+=`export type ${
|
|
126
|
-
| ${
|
|
125
|
+
`;Z+=`export type ${K} =
|
|
126
|
+
| ${H};
|
|
127
127
|
|
|
128
|
-
`}return Z}function
|
|
129
|
-
| `);if(X
|
|
128
|
+
`}return Z}function E1($,Y){let X="",Z=$.map((K)=>`"${K.name}"`).join(`
|
|
129
|
+
| `);if(Y)X+=`/**
|
|
130
130
|
* All available icon names as string literals
|
|
131
131
|
*/
|
|
132
|
-
`;
|
|
132
|
+
`;X+=`export type IconNames =
|
|
133
133
|
| ${Z};
|
|
134
134
|
|
|
135
|
-
`;let
|
|
136
|
-
| `);if(X
|
|
135
|
+
`;let U=[...new Set($.map((K)=>K.category))].map((K)=>`"${K}"`).join(`
|
|
136
|
+
| `);if(Y)X+=`/**
|
|
137
137
|
* All available icon categories
|
|
138
138
|
*/
|
|
139
|
-
`;if(
|
|
140
|
-
| ${
|
|
139
|
+
`;if(X+=`export type IconCategories =
|
|
140
|
+
| ${U};
|
|
141
141
|
|
|
142
|
-
`,X
|
|
142
|
+
`,Y)X+=`/**
|
|
143
143
|
* Icon data structure
|
|
144
144
|
*/
|
|
145
|
-
`;return
|
|
146
|
-
`,
|
|
147
|
-
`,
|
|
148
|
-
`,
|
|
149
|
-
`,
|
|
150
|
-
`,
|
|
151
|
-
`,
|
|
152
|
-
`,
|
|
153
|
-
`,
|
|
154
|
-
`,
|
|
155
|
-
`,
|
|
156
|
-
`,
|
|
157
|
-
`,
|
|
158
|
-
`,
|
|
159
|
-
`,
|
|
160
|
-
`,
|
|
161
|
-
`,
|
|
162
|
-
|
|
163
|
-
`,
|
|
145
|
+
`;return X+=`export interface Icon {
|
|
146
|
+
`,X+=` /** Icon name */
|
|
147
|
+
`,X+=` name: string;
|
|
148
|
+
`,X+=` /** Icon category */
|
|
149
|
+
`,X+=` category: string;
|
|
150
|
+
`,X+=` /** SVG content */
|
|
151
|
+
`,X+=` value: string;
|
|
152
|
+
`,X+=` /** Icon description */
|
|
153
|
+
`,X+=` description?: string;
|
|
154
|
+
`,X+=` /** Icon style */
|
|
155
|
+
`,X+=` style?: string;
|
|
156
|
+
`,X+=` /** Icon dimensions */
|
|
157
|
+
`,X+=` dimensions?: {
|
|
158
|
+
`,X+=` width: number;
|
|
159
|
+
`,X+=` height: number;
|
|
160
|
+
`,X+=` };
|
|
161
|
+
`,X+=`}
|
|
162
|
+
|
|
163
|
+
`,X}function L1($,Y,X){let Z="";if(X)Z+=`/**
|
|
164
164
|
* Design tokens interface with all token paths and their values
|
|
165
165
|
*/
|
|
166
|
-
`;Z+=`export interface ${
|
|
167
|
-
`;for(let
|
|
168
|
-
`;Z+=` "${
|
|
166
|
+
`;Z+=`export interface ${Y} {
|
|
167
|
+
`;for(let q of $){if(X&&q.description)Z+=` /** ${q.description} */
|
|
168
|
+
`;Z+=` "${q.name}": ${Y$(q.value)};
|
|
169
169
|
`}return Z+=`}
|
|
170
170
|
|
|
171
|
-
`,Z+=
|
|
171
|
+
`,Z+=_1($,`${Y}Nested`,X),Z}function _1($,Y,X){let Z=M1($),q="";if(X)q+=`/**
|
|
172
172
|
* Design tokens interface with nested structure
|
|
173
173
|
*/
|
|
174
|
-
`;return
|
|
175
|
-
`,
|
|
174
|
+
`;return q+=`export interface ${Y} {
|
|
175
|
+
`,q+=i0(Z,1),q+=`}
|
|
176
176
|
|
|
177
|
-
`,
|
|
178
|
-
| `),
|
|
177
|
+
`,q}function w1($,Y){let Z=Array.from(new Set($.map((U)=>U.cssVar))).map((U)=>`"${U}"`).join(`
|
|
178
|
+
| `),q="";if(Y)q+=`/**
|
|
179
179
|
* All available CSS variable names
|
|
180
180
|
*/
|
|
181
|
-
`;return
|
|
182
|
-
| ${
|
|
181
|
+
`;return q+=`export type CSSVariableNames =
|
|
182
|
+
| ${Z};
|
|
183
183
|
|
|
184
|
-
`,
|
|
184
|
+
`,q}function Q1($,Y){let X="";if(Y)X+=`/**
|
|
185
185
|
* Object containing all token values
|
|
186
186
|
*/
|
|
187
|
-
`;
|
|
188
|
-
`;for(let Z of $){if(
|
|
189
|
-
`;
|
|
190
|
-
`}return
|
|
187
|
+
`;X+=`export const tokenValues = {
|
|
188
|
+
`;for(let Z of $){if(Y&&Z.description)X+=` /** ${Z.description} */
|
|
189
|
+
`;X+=` "${Z.name}": ${JSON.stringify(Z.value)},
|
|
190
|
+
`}return X+=`} as const;
|
|
191
191
|
|
|
192
|
-
`,
|
|
192
|
+
`,X}function O1($,Y){let X="";if(Y)X+=`/**
|
|
193
193
|
* Array of all available icons
|
|
194
194
|
*/
|
|
195
|
-
`;
|
|
196
|
-
`;for(let
|
|
197
|
-
`,
|
|
198
|
-
`,
|
|
199
|
-
`,
|
|
200
|
-
`,
|
|
201
|
-
`;if(
|
|
202
|
-
`;if(
|
|
203
|
-
`;
|
|
204
|
-
`}if(
|
|
205
|
-
|
|
206
|
-
`,X
|
|
195
|
+
`;X+=`export const icons: Icon[] = [
|
|
196
|
+
`;for(let q of $){if(X+=` {
|
|
197
|
+
`,X+=` name: "${q.name}",
|
|
198
|
+
`,X+=` category: "${q.category}",
|
|
199
|
+
`,X+=` value: ${JSON.stringify(q.value)},
|
|
200
|
+
`,q.description)X+=` description: ${JSON.stringify(q.description)},
|
|
201
|
+
`;if(q.style)X+=` style: "${q.style}",
|
|
202
|
+
`;if(q.dimensions)X+=` dimensions: { width: ${q.dimensions.width}, height: ${q.dimensions.height} },
|
|
203
|
+
`;X+=` },
|
|
204
|
+
`}if(X+=`];
|
|
205
|
+
|
|
206
|
+
`,Y)X+=`/**
|
|
207
207
|
* Array of all icon names
|
|
208
208
|
*/
|
|
209
|
-
`;
|
|
210
|
-
`;for(let
|
|
211
|
-
`;
|
|
209
|
+
`;X+=`export const iconNames: IconNames[] = [
|
|
210
|
+
`;for(let q of $)X+=` "${q.name}",
|
|
211
|
+
`;X+=`] as const;
|
|
212
212
|
|
|
213
|
-
`;let Z=[...new Set($.map((
|
|
213
|
+
`;let Z=[...new Set($.map((q)=>q.category))];if(Y)X+=`/**
|
|
214
214
|
* Array of all icon categories
|
|
215
215
|
*/
|
|
216
|
-
`;
|
|
217
|
-
`;for(let
|
|
218
|
-
`;if(
|
|
216
|
+
`;X+=`export const iconCategories: IconCategories[] = [
|
|
217
|
+
`;for(let q of Z)X+=` "${q}",
|
|
218
|
+
`;if(X+=`] as const;
|
|
219
219
|
|
|
220
|
-
`,X
|
|
220
|
+
`,Y)X+=`/**
|
|
221
221
|
* Get icon by name
|
|
222
222
|
*/
|
|
223
|
-
`;if(
|
|
224
|
-
`,
|
|
225
|
-
`,
|
|
223
|
+
`;if(X+=`export function getIcon(name: IconNames): Icon | undefined {
|
|
224
|
+
`,X+=` return icons.find(icon => icon.name === name);
|
|
225
|
+
`,X+=`}
|
|
226
226
|
|
|
227
|
-
`,X
|
|
227
|
+
`,Y)X+=`/**
|
|
228
228
|
* Get icons by category
|
|
229
229
|
*/
|
|
230
|
-
`;return
|
|
231
|
-
`,
|
|
232
|
-
`,
|
|
230
|
+
`;return X+=`export function getIconsByCategory(category: IconCategories): Icon[] {
|
|
231
|
+
`,X+=` return icons.filter(icon => icon.category === category);
|
|
232
|
+
`,X+=`}
|
|
233
233
|
|
|
234
|
-
`,
|
|
234
|
+
`,X}function I1($,Y){let X="";if(Y)X+=`/**
|
|
235
235
|
* Object mapping token paths to CSS variable names
|
|
236
236
|
*/
|
|
237
|
-
`;
|
|
238
|
-
`;for(let Z of $)
|
|
239
|
-
`;return
|
|
237
|
+
`;X+=`export const cssVariableNames = {
|
|
238
|
+
`;for(let Z of $)X+=` "${Z.name}": "${Z.cssVar}",
|
|
239
|
+
`;return X+=`} as const;
|
|
240
240
|
|
|
241
|
-
`,
|
|
241
|
+
`,X}function J1($,Y){let X="";if(Y)X+=`/**
|
|
242
242
|
* Get the value of a design token
|
|
243
243
|
*/
|
|
244
|
-
`;if(
|
|
244
|
+
`;if(X+=`export function getTokenValue<T extends TokenPaths>(tokenPath: T): typeof tokenValues[T] {
|
|
245
245
|
return tokenValues[tokenPath];
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
`,X
|
|
248
|
+
`,Y)X+=`/**
|
|
249
249
|
* Get the CSS variable name for a design token
|
|
250
250
|
*/
|
|
251
|
-
`;if(
|
|
251
|
+
`;if(X+=`export function getCSSVariableName<T extends TokenPaths>(tokenPath: T): typeof cssVariableNames[T] {
|
|
252
252
|
return cssVariableNames[tokenPath];
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
`,X
|
|
255
|
+
`,Y)X+=`/**
|
|
256
256
|
* Get a CSS var() reference for a design token
|
|
257
257
|
*/
|
|
258
|
-
`;if(
|
|
258
|
+
`;if(X+=`export function getCSSVariableReference<T extends TokenPaths>(tokenPath: T): string {
|
|
259
259
|
return \`var(\${cssVariableNames[tokenPath]})\`;
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
`,X
|
|
262
|
+
`,Y)X+=`/**
|
|
263
263
|
* Check if a token path exists
|
|
264
264
|
*/
|
|
265
|
-
`;return
|
|
265
|
+
`;return X+=`export function hasToken(tokenPath: string): tokenPath is TokenPaths {
|
|
266
266
|
return tokenPath in tokenValues;
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
`,
|
|
270
|
-
`,
|
|
271
|
-
`;else
|
|
272
|
-
`}return
|
|
269
|
+
`,X}function R1($){let Y=new Map;for(let X of $){if(!Y.has(X.type))Y.set(X.type,[]);Y.get(X.type).push(X)}return Y}function M1($){let Y={};for(let X of $){if(X.path.some((H)=>H.includes("@")||H.includes("#")||H.includes("-")||H.includes(".")))continue;let q=Y,U=[...X.path];for(let H=0;H<U.length-1;H++){let G=U[H];if(!q[G])q[G]={};q=q[G]}let K=U[U.length-1],W=Y$(X.value);q[K]=W}return Y}function i0($,Y){let X="",Z=" ".repeat(Y);for(let[q,U]of Object.entries($)){let K=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(q)?q:`"${q}"`;if(typeof U==="object"&&!Array.isArray(U))X+=`${Z}${K}: {
|
|
270
|
+
`,X+=i0(U,Y+1),X+=`${Z}};
|
|
271
|
+
`;else X+=`${Z}${K}: ${U};
|
|
272
|
+
`}return X}function Y$($){if(typeof $==="string")return`"${$}"`;else if(typeof $==="number")return $.toString();else if(typeof $==="boolean")return $.toString();else if(Array.isArray($)){let Y=new Set($.map((Z)=>Y$(Z)));return`Array<${Array.from(Y).join(" | ")}>`}else if($===null)return"null";else if($===void 0)return"undefined";else if(typeof $==="object"&&$!==null)return`{ ${Object.entries($).map(([Z,q])=>`${Z}: ${Y$(q)}`).join("; ")} }`;else return"unknown"}function N1($){if(!$||typeof $!=="string")return"";return $.charAt(0).toUpperCase()+$.slice(1)}function t$($){let Y=new Date().toISOString();return`/**
|
|
273
273
|
* ${$}
|
|
274
|
-
* Generated: ${
|
|
274
|
+
* Generated: ${Y}
|
|
275
275
|
*
|
|
276
276
|
* This file is auto-generated from design tokens.
|
|
277
277
|
* Do not edit this file directly - it will be overwritten.
|
|
278
278
|
*/
|
|
279
279
|
|
|
280
|
-
`}var
|
|
280
|
+
`}var o$=F(()=>{S()});var X$="did";var S=F(()=>{s();I$();N$();s();K$();Q0();O0();M0();I$();N$();p$();l$();L$();o$();$0()});import{readFileSync as x1,mkdirSync as j1}from"fs";import{writeFile as s0,readdir as S1,mkdir as P1}from"fs/promises";import{resolve as D1,relative as a0,join as _$,dirname as b1}from"path";import C1 from"lodash";async function n0($){let Y=await S1($,{withFileTypes:!0}),X=await Promise.all(Y.map((Z)=>{let q=D1($,Z.name);return Z.isDirectory()?n0(q):q}));return Array.prototype.concat(...X)}async function Y0(){let{assets:$,icons:Y,tokenNamespace:X,__dirname:Z,buildDir:q}=await m(),U=_$(Z,$?.icons?.sourceDir??"icons"),K="build",W=$?.icons?.distDir??"build",H=_$(Z,W),G=_$(Z,q,"icons");if(!$?.icons?.sourceDir){console.error("Skipping icon build: iconsDir is not defined in the project paths.");return}a(_$(Z,q));let z=(await n0(U)).filter((Q)=>Q.endsWith(".svg")),E=(await Promise.all(z.map(async(Q)=>{let w=x1(Q,"utf8").replace(/(\s+(?=(?:[^"]*"[^"]*")*[^"]*$))/g," ").trim()??"";w=await h$(w);let I=a0(U,Q).split("/").pop(),N=(w.match(/name="(.*?)"/)??[])[1]??I?.replace(".svg",""),h=(w.match(/data-style="(.*?)"/)??[])[1],G2=(w.match(/description="(.*?)"/)??[])[1],[U0]=w.match(/<svg[^>]*>/)??[],[,H2]=U0?.match(/width="([\d.]+)(px)?"/)??[],[,z2]=U0?.match(/height="([\d.]+)(px)?"/)??[];if(h!=="animated"&&h!=="custom")return{path:Q,folder:a0(U,Q).split("/").slice(0,-1).concat(N),file:I,style:h,content:w,name:N,dimensions:{width:Number(H2),height:Number(z2)},description:G2??""};return}))).filter((Q)=>Q!==void 0).reduce((Q,w)=>{if(w?.style!=="animated"&&w?.style!=="custom"&&w)X0(Q,w.folder.join("."),{$type:"icon",$name:w.name,$description:w.description,$style:w.style,$value:w.content,$dimensions:w.dimensions,...V1(Q,w.folder.join("."))});return Q},{}),L=Y?.objectPath??`${X}.icons`;Object.keys(E).forEach(async(Q)=>{let w=`${G}/${Q}`,I=`${w}/svg.${Q}.tokens.json`;await P1(w,{recursive:!0});let N=X0({},`${L}${L?".":""}${Q}`,E[Q]);await s0(I,JSON.stringify(N,null,2),{flag:"w",encoding:"utf-8"})});let _=`${H}/tokens/${await t("json")}`,J=b1(_);j1(J,{recursive:!0});let O=X0({},L,E);await s0(_,JSON.stringify(O,null,2),{flag:"w",encoding:"utf-8"})}var X0,V1,pX;var t0=F(()=>{S();({set:X0,get:V1}=C1);pX=Y0().catch(($)=>{console.error($),process.exit(1)})});function $2($,Y={}){let X=[],Z=Y.typescript?"ts":"js",q=Y.modes||[],U=$.filter((W)=>W.extensions?.mediaQuery||W.name.includes("@screen")||W.name.includes("@_")),K=$.filter((W)=>!W.extensions?.mediaQuery&&!W.name.includes("@screen")&&!W.name.includes("@_"));if(Y.separateThemeFiles&&q.length>0){let W=q.join("|"),H=new RegExp(`#(${W})$`),G=new Map;for(let z of q)G.set(z,[]);for(let z of K){let A=z.name.match(H);if(A){let B=A[1];G.get(B).push(z)}else{let B=q[0];G.get(B).push(z)}}for(let z of q){let A=G.get(z)||[];if(A.length>0){if(Y.typescript){let B=X2(A,z);X.push({fileName:`${z}.d.ts`,content:v1(B,Y,z),theme:z})}X.push({fileName:`${z}.${Z}`,content:e0(A,{...Y,theme:z}),theme:z})}}}else X.push({fileName:`tokens.${Z}`,content:e0(K,Y)});if(U.length>0)X.push({fileName:`breakpoints.${Z}`,content:g1(U,$,Y)});if(Y.separateThemeFiles&&X.length>1)X.push({fileName:`index.${Z}`,content:m1(X,Y)});return X}function g1($,Y,X={}){let{typescript:Z,includeJSDoc:q,moduleType:U="es",customHeader:K,modes:W=[]}=X,H=new Map(Y.map((B)=>[B.name,B])),G={};for(let B of $){let E=B.extensions?.mediaQuery||T1(B.name),L=W.length>0?W[0]:"default";for(let O of W)if(B.name.includes(`#${O}`)){L=O;break}if(typeof E==="string"&&E.includes("{")&&E.includes("}"))E=f1(E,H);if(!G[E])G[E]={};if(!G[E][L])G[E][L]={};let _=y1(B.name),J=h1(_,w$(B.value,H));G[E][L]={...G[E][L],...J}}let z=Object.keys(G).sort((B,E)=>{let L=o0(B),_=o0(E);return L-_}).reduce((B,E)=>{return B[E]=G[E],B},{}),A="";if(K)A+=`${K}
|
|
281
281
|
|
|
282
|
-
`;else
|
|
283
|
-
`,
|
|
284
|
-
`,
|
|
285
|
-
`,
|
|
286
|
-
`,
|
|
282
|
+
`;else A+=`/**
|
|
283
|
+
`,A+=` * Design Tokens - Breakpoints
|
|
284
|
+
`,A+=` * Auto-generated from design token definitions
|
|
285
|
+
`,A+=` * Do not edit this file directly
|
|
286
|
+
`,A+=` */
|
|
287
287
|
|
|
288
|
-
`;if(Z)z
|
|
289
|
-
`;if(
|
|
288
|
+
`;if(Z)A+=Y2(z,q),A+=`
|
|
289
|
+
`;if(U==="es"){if(Z)A+=`const breakpoints: Tokens = ${u(z,q,0)};
|
|
290
290
|
|
|
291
|
-
`;else
|
|
291
|
+
`;else A+=`const breakpoints = ${u(z,q,0)};
|
|
292
292
|
|
|
293
|
-
`;
|
|
294
|
-
`}else
|
|
293
|
+
`;A+=`export default breakpoints;
|
|
294
|
+
`}else A+=`const breakpoints = ${u(z,q,0)};
|
|
295
295
|
|
|
296
|
-
`,
|
|
297
|
-
`,
|
|
298
|
-
`;return
|
|
296
|
+
`,A+=`module.exports = breakpoints;
|
|
297
|
+
`,A+=`module.exports.default = breakpoints;
|
|
298
|
+
`;return A}function T1($){if($.includes("@_max_width_")){let Y=$.match(/@_max_width___(.+?)__/);if(Y)return`screen and (max-width: {${Y[1].replace(/_/g,".")}})`}if($.includes("@_min_width_")){let Y=$.match(/@_min_width___(.+?)__/);if(Y)return`screen and (min-width: {${Y[1].replace(/_/g,".")}})`}return"screen"}function y1($){let Y=$.replace(/@_.*?__/,"").replace(/@screen.*/,"").replace(/#[^#]*$/,"").replace(/^universe\./,"");return Y=Y.replace(/_universe_foundation_breakpoint_screen_width_[^_]+__?$/,""),Y}function o0($){let Y=$.match(/(\d+(?:\.\d+)?)/);return Y?parseFloat(Y[1]):0}function f1($,Y){return $.replace(/\{([^}]+)\}/g,(X,Z)=>{let q=Y.get(Z);if(q){let U=q.value;if(typeof U==="object"&&U!==null&&"$value"in U)U=U.$value;return String(U)}return X})}function h1($,Y){let X=$.split("."),Z={},q=Z;for(let U=0;U<X.length-1;U++)q[X[U]]={},q=q[X[U]];return q[X[X.length-1]]=Y,Z}function e0($,Y={}){let{typescript:X,includeJSDoc:Z,moduleType:q="es",customHeader:U,theme:K}=Y,W="";if(U)W+=`${U}
|
|
299
299
|
|
|
300
|
-
`;else
|
|
301
|
-
`,
|
|
302
|
-
`,
|
|
303
|
-
`,
|
|
304
|
-
`,
|
|
300
|
+
`;else W+=`/**
|
|
301
|
+
`,W+=` * Design Tokens - ${K?`${K.charAt(0).toUpperCase()+K.slice(1)} Theme`:"All Tokens"}
|
|
302
|
+
`,W+=` * Auto-generated from design token definitions
|
|
303
|
+
`,W+=` * Do not edit this file directly
|
|
304
|
+
`,W+=` */
|
|
305
305
|
|
|
306
|
-
`;let
|
|
306
|
+
`;let H=X2($,K);if(X)if(Y.separateThemeFiles&&K)W+=`import type { Tokens } from "./${K}.d";
|
|
307
307
|
|
|
308
|
-
`;else
|
|
309
|
-
`;if(
|
|
308
|
+
`;else W+=Y2(H,Z),W+=`
|
|
309
|
+
`;if(q==="es"){if(X)W+=`const tokens: Tokens = ${u(H,Z,0)};
|
|
310
310
|
|
|
311
|
-
`;else
|
|
311
|
+
`;else W+=`const tokens = ${u(H,Z,0)};
|
|
312
312
|
|
|
313
|
-
`;
|
|
314
|
-
`;let
|
|
313
|
+
`;W+=`export default tokens;
|
|
314
|
+
`;let G=Object.keys(H);if(G.length>0){W+=`
|
|
315
315
|
// Named exports for convenience
|
|
316
|
-
`;for(let z of
|
|
317
|
-
`}}else
|
|
316
|
+
`;for(let z of G)W+=`export const ${z} = tokens.${z};
|
|
317
|
+
`}}else W+=`const tokens = ${u(H,Z,0)};
|
|
318
318
|
|
|
319
|
-
`,
|
|
320
|
-
`,
|
|
321
|
-
`;return
|
|
319
|
+
`,W+=`module.exports = tokens;
|
|
320
|
+
`,W+=`module.exports.default = tokens;
|
|
321
|
+
`;return W}function X2($,Y){let X={},Z=new Map($.map((q)=>[q.name,q]));for(let q of $){let U=q.name;if(Y){if(U.includes(`#${Y}`))U=U.replace(`#${Y}`,"")}else U=U.replace(/#[^#]*$/,"");let K=U.split("."),W=X;for(let G=0;G<K.length-1;G++){let z=K[G];if(!W[z])W[z]={};W=W[z]}let H=K[K.length-1];W[H]=w$(q.value,Z)}return X}function w$($,Y){if(typeof $==="object"&&$!==null&&!Array.isArray($)){let X=$;if(X.color&&typeof X.color==="string"&&X.color.includes("{")&&X.color.includes("}")){let Z=D($,"shadow");if(typeof Z==="string"&&!Z.includes("{")){let q={...X},U=Z.split(" "),K=U[U.length-1];if(K&&K.startsWith("#"))q.color=K;else q.color=D(X.color,"color");return q}}}if(typeof $==="string"){if($.startsWith("{")&&$.endsWith("}")){let X=$.slice(1,-1),Z=Y.get(X);if(Z)return Z.value;let q=D($,"color");if(q!==$)return q}return $}if(Array.isArray($))return $.map((X)=>w$(X,Y));if(typeof $==="object"&&$!==null){let X={};for(let[Z,q]of Object.entries($))X[Z]=w$(q,Y);return X}return $}function Y2($,Y){let X="";if(Y)X+=`/**
|
|
322
322
|
* Token object type definition
|
|
323
323
|
*/
|
|
324
|
-
`;return
|
|
325
|
-
`,
|
|
324
|
+
`;return X+=`type Tokens = ${Z0($,0)};
|
|
325
|
+
`,X}function v1($,Y,X){let{customHeader:Z,includeJSDoc:q}=Y,U="";if(Z)U+=`${Z}
|
|
326
326
|
|
|
327
|
-
`;else{let
|
|
328
|
-
`,
|
|
329
|
-
`,
|
|
330
|
-
`,
|
|
331
|
-
`,
|
|
327
|
+
`;else{let K=X?` - ${X.charAt(0).toUpperCase()+X.slice(1)} Theme`:"";U+=`/**
|
|
328
|
+
`,U+=` * Universe Design System Tokens - Type Definitions${K}
|
|
329
|
+
`,U+=` * Auto-generated from design token definitions
|
|
330
|
+
`,U+=` * Do not edit this file directly
|
|
331
|
+
`,U+=` */
|
|
332
332
|
|
|
333
|
-
`}if(
|
|
333
|
+
`}if(q)U+=`/**
|
|
334
334
|
* Token object type definition
|
|
335
335
|
*/
|
|
336
|
-
`;return
|
|
337
|
-
`,
|
|
338
|
-
`;for(let[
|
|
339
|
-
`}return
|
|
340
|
-
`;for(let
|
|
341
|
-
`;let A=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(
|
|
342
|
-
`}return
|
|
343
|
-
|
|
344
|
-
`;else
|
|
345
|
-
`,
|
|
346
|
-
`,
|
|
347
|
-
`,
|
|
348
|
-
|
|
349
|
-
`;if(Z==="es"){for(let
|
|
350
|
-
`}
|
|
336
|
+
`;return U+=`export type Tokens = ${Z0($,0)};
|
|
337
|
+
`,U}function Z0($,Y){if(typeof $!=="object"||$===null)return typeof $==="string"?"string":typeof $==="number"?"number":typeof $==="boolean"?"boolean":"any";let X=" ".repeat(Y+1),Z=Object.entries($);if(Z.length===0)return"{}";let q=`{
|
|
338
|
+
`;for(let[U,K]of Z){let W=p1(U)?`"${U}"`:U;q+=`${X}${W}: ${Z0(K,Y+1)};
|
|
339
|
+
`}return q+=" ".repeat(Y)+"}",q}function p1($){return $.startsWith("@")||$.includes(" ")||$.includes("-")||$.includes("(")||$.includes(")")||$.includes("@")||$.includes(":")||!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test($)}function u($,Y,X=0){if(typeof $!=="object"||$===null)return JSON.stringify($);let Z=" ".repeat(X),q=" ".repeat(X+1),U=Object.entries($);if(U.length===0)return"{}";let K=`{
|
|
340
|
+
`;for(let W=0;W<U.length;W++){let[H,G]=U[W],z=W===U.length-1;if(Y&&typeof G==="string")K+=`${q}/** Token value: ${JSON.stringify(G)} */
|
|
341
|
+
`;let A=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(H)?H:JSON.stringify(H),B=u(G,Y,X+1);K+=`${q}${A}: ${B}${z?"":","}
|
|
342
|
+
`}return K+=`${Z}}`,K}function m1($,Y){let X=Y.typescript?"ts":"js",{moduleType:Z="es",customHeader:q}=Y,U=(W)=>{return W.replace(/-([a-z])/g,(H,G)=>G.toUpperCase())},K="";if(q)K+=`${q}
|
|
343
|
+
|
|
344
|
+
`;else K+=`/**
|
|
345
|
+
`,K+=` * Design Tokens - Index
|
|
346
|
+
`,K+=` * Exports all token themes for convenient importing
|
|
347
|
+
`,K+=` */
|
|
348
|
+
|
|
349
|
+
`;if(Z==="es"){for(let W of $){if(W.fileName===`index.${X}`)continue;if(!W.fileName.endsWith(".d.ts"))continue;let H=W.fileName.replace(".d.ts",""),G=U(W.theme||H);K+=`export type { Tokens as ${G.charAt(0).toUpperCase()+G.slice(1)}Tokens } from './${H}.d';
|
|
350
|
+
`}K+=`
|
|
351
|
+
`;for(let W of $){if(W.fileName===`index.${X}`)continue;if(W.fileName.endsWith(".d.ts"))continue;let H=W.fileName.replace(`.${X}`,""),G=U(W.theme||H);K+=`export { default as ${G} } from './${H}${Y.typescript?"":".js"}';
|
|
352
|
+
`}K+=`
|
|
351
353
|
// Convenience re-exports
|
|
352
|
-
`,
|
|
353
|
-
`}else{for(let
|
|
354
|
-
`}
|
|
354
|
+
`,K+=`export { default } from './light${Y.typescript?"":".js"}';
|
|
355
|
+
`}else{for(let W of $){if(W.fileName===`index.${X}`)continue;if(W.fileName.endsWith(".d.ts"))continue;let H=W.fileName.replace(`.${X}`,""),G=U(W.theme||H);K+=`exports.${G} = require('./${H}');
|
|
356
|
+
`}K+=`
|
|
355
357
|
// Default export points to light theme
|
|
356
|
-
`,
|
|
357
|
-
`}return
|
|
358
|
+
`,K+=`module.exports = require('./light');
|
|
359
|
+
`}return K}var Z2=F(()=>{L$()});var q2={};W0(q2,{validateCSSFiles:()=>d1,printValidationResults:()=>u1});import{readFileSync as q0,existsSync as i}from"fs";import{join as V}from"path";function d1($,Y){let X={isValid:!0,errors:[],warnings:[],checks:[]},Z=V($,"css"),q=V(Z,"tokens.css"),U=i(q);if(X.checks.push({name:"CSS file exists: tokens.css",passed:U,message:U?void 0:"Missing required CSS file: tokens.css"}),!U)X.errors.push("Missing required CSS file: tokens.css"),X.isValid=!1;if(Y.$metaData?.tokens?.css?.mediaQuery?.separateThemeFiles??!1){let A=V(Z,"tokens.dark.css"),B=i(A);if(X.checks.push({name:"CSS file exists: tokens.dark.css",passed:B,message:B?void 0:"Missing required CSS file: tokens.dark.css (separateThemeFiles is enabled)"}),!B)X.errors.push("Missing required CSS file: tokens.dark.css (separateThemeFiles is enabled)"),X.isValid=!1}let W=V(Z,"tokens.breakpoints.css");if(i(W))X.checks.push({name:"CSS file exists: tokens.breakpoints.css",passed:!0,message:void 0});let G=Y.$metaData?.tokens?.css?.hooks?.shortenName;if(G?.enabled&&i(V(Z,"tokens.css"))){let A=q0(V(Z,"tokens.css"),"utf8");if(G.prefix)for(let{find:B,replace:E}of G.prefix){let L=`--${X$}-${B}`,_=`--${E}`,J=A.includes(L),O=A.includes(_);if(X.checks.push({name:`Prefix hook applied: ${B} → ${E}`,passed:!J&&O,message:J?`Old prefix "${L}" still found in CSS, should be "${_}"`:void 0}),J)X.errors.push(`Prefix transformation failed: "${L}" should be replaced with "${_}"`),X.isValid=!1}if(G.suffix)for(let{find:B,replace:E}of G.suffix){let _=new RegExp(`--[^:]+${B.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}:`,"g").test(A);if(X.checks.push({name:`Suffix hook applied: ${B} → ${E}`,passed:!_,message:_?`Old suffix "${B}" still found in CSS variable names`:void 0}),_)X.errors.push(`Suffix transformation failed: "${B}" should be removed/replaced with "${E}"`),X.isValid=!1}}if(i(V(Z,"tokens.css"))){let B=q0(V(Z,"tokens.css"),"utf8").match(/:\s*{[^}]+}/g);if(X.checks.push({name:"No unresolved token references",passed:!B,message:B?`Found unresolved references: ${B.join(", ")}`:void 0}),B)X.errors.push(`Unresolved token references found: ${B.join(", ")}`),X.isValid=!1}let z=["tokens.css","tokens.dark.css","tokens.breakpoints.css"];for(let A of z){let B=V(Z,A);if(i(B)){let E=q0(B,"utf8"),L=(E.match(/\{/g)||[]).length-(E.match(/\}/g)||[]).length;if(X.checks.push({name:`CSS syntax valid: ${A}`,passed:L===0,message:L!==0?`Mismatched braces in ${A}`:void 0}),L!==0)X.errors.push(`CSS syntax error in ${A}: mismatched braces`),X.isValid=!1}}return X}function u1($){console.log(`
|
|
358
360
|
|
|
359
|
-
Build Validation Results:`),console.log("========================================================");for(let
|
|
360
|
-
⚠️ Warnings:`);for(let
|
|
361
|
-
❌ Errors:`);for(let
|
|
362
|
-
Validation Summary:`),console.log(` - Checks: ${$.checks.filter((
|
|
361
|
+
Build Validation Results:`),console.log("========================================================");for(let Y of $.checks){let X=Y.passed?"✓":"✗";if(console.log(` ${X} ${Y.name}`),Y.message)console.log(` ${Y.message}`)}if($.warnings.length>0){console.log(`
|
|
362
|
+
⚠️ Warnings:`);for(let Y of $.warnings)console.log(` ${Y}`)}if($.errors.length>0){console.log(`
|
|
363
|
+
❌ Errors:`);for(let Y of $.errors)console.log(` ${Y}`)}console.log(`
|
|
364
|
+
Validation Summary:`),console.log(` - Checks: ${$.checks.filter((Y)=>Y.passed).length}/${$.checks.length} passed`),console.log(` - Errors: ${$.errors.length}`),console.log(` - Warnings: ${$.warnings.length}`),console.log(`
|
|
363
365
|
${$.isValid?"✅":"❌"} Build ${$.isValid?"passed":"failed"}`),console.log(`
|
|
364
366
|
========================================================
|
|
365
|
-
`)}var
|
|
366
|
-
* ${
|
|
367
|
+
`)}var U2=F(()=>{S()});import{writeFileSync as k1,mkdirSync as c1,existsSync as l1}from"fs";import{join as g,dirname as K2}from"path";function i1($,Y,X=!1,Z=!1){let q=[],U=[],K=[];for(let H of $)if(H.fileName.includes("breakpoint"))U.push(`@import url("./css/${H.fileName}");`);else K.push(`@import url("./css/${H.fileName}");`);if(q.push(...K),X)q.push('@import url("./css/tokens.icons.css");');if(Z)q.push('@import url("./css/fonts.css");');q.push(...U);let W=`/**
|
|
368
|
+
* ${Y} Design System - Main CSS Entry Point
|
|
367
369
|
* Generated: ${new Date().toISOString()}
|
|
368
370
|
*
|
|
369
371
|
* This file imports all generated CSS files for the design system.
|
|
@@ -372,20 +374,20 @@ ${$.isValid?"✅":"❌"} Build ${$.isValid?"passed":"failed"}`),console.log(`
|
|
|
372
374
|
* Do not edit this file directly - it will be overwritten.
|
|
373
375
|
*/
|
|
374
376
|
|
|
375
|
-
${
|
|
377
|
+
${q.join(`
|
|
376
378
|
`)}
|
|
377
|
-
`;return{fileName:`${
|
|
378
|
-
Starting token build process...`,$.verbose);let{initializeColorspace:Z}=await Promise.resolve().then(() => (
|
|
379
|
-
Generating CSS files...`,$.verbose);let
|
|
380
|
-
Generated icon tokens`,$.verbose)}catch(
|
|
381
|
-
Generating TypeScript files...`,$.verbose);let
|
|
382
|
-
Generating JavaScript files...`,$.verbose);let
|
|
383
|
-
Generating JSON files...`,$.verbose);let
|
|
384
|
-
Build completed in ${
|
|
385
|
-
Validating build output...`,$.verbose);let{validateCSSFiles:Z,printValidationResults:
|
|
379
|
+
`;return{fileName:`${Y}.design-system.tokens.css`,content:W,theme:void 0}}async function r0($){let Y=Date.now(),X={tokenCount:0,cssFiles:[],typescriptFiles:[],javascriptFiles:[],jsonFiles:[],duration:0,warnings:[],errors:[]};try{R(`
|
|
380
|
+
Starting token build process...`,$.verbose);let{initializeColorspace:Z}=await Promise.resolve().then(() => (s(),H0));await Z(),R("Loading token files...",$.verbose);let q=d$($.tokensDir);R("Parsing tokens...",$.verbose);let U=r1($.config),K=u$(q,U);if(R(`Found ${K.length} tokens`,$.verbose),X.tokenCount=K.length,K.length===0&&U.namespace){let G=Object.keys(q).filter((z)=>!z.startsWith("$"));if(G.length>0)X.warnings.push(`⚠️ No tokens found matching tokenNamespace "${U.namespace}". Found root keys: ${G.join(", ")}. Please check if your $metaData.tokenNamespace in designid.config.ts matches.`)}let W=k$(K,U);if(R(`Resolved ${W.length} tokens`,$.verbose),$.generateCSS!==!1){R(`
|
|
381
|
+
Generating CSS files...`,$.verbose);let G=W2($.config,$.cssOptions),z=z$(W,G);for(let A of z){let B=g($.outputDir,"css",A.fileName);r(B,A.content),R(` ✓ ${A.fileName}`,$.verbose)}X.cssFiles=z}if($.generateCSS!==!1)try{await Y0(),R(`
|
|
382
|
+
Generated icon tokens`,$.verbose)}catch(G){if($.verbose)console.warn("Could not build icon tokens:",G)}if($.generateCSS!==!1)try{let G=await a$();if(G.length>0){let z=W2($.config,$.cssOptions),A=s$(G,{customHeader:E$($.config),objectPath:$.config.$metaData?.icons?.objectPath||"universe.custom.path.icons",hooks:z.hooks}),B=g($.outputDir,"css",A.fileName);if(r(B,A.content),R(` ✓ Generated ${A.fileName}`,$.verbose),X.cssFiles)X.cssFiles.push(A);else X.cssFiles=[A]}}catch(G){if($.verbose)console.warn("Could not generate icon CSS:",G)}let H=!1;if($.generateCSS!==!1)try{let G=$.config.$fonts;if(G&&G.length>0){await v$(G,$.outputDir),R(" ✓ Generated fonts.css",$.verbose),H=!0;let z={fileName:"fonts.css",content:"Generated by appendTypographyTokens",theme:void 0};if(X.cssFiles)X.cssFiles.push(z);else X.cssFiles=[z]}}catch(G){if($.verbose)console.warn("Could not generate font CSS:",G)}if($.generateCSS!==!1&&X.cssFiles.length>0){let G=$.config.$metaData?.tokenNamespace||"tokens",z=X.cssFiles.some((E)=>E.fileName==="tokens.icons.css"),A=i1(X.cssFiles.filter((E)=>E.fileName!=="tokens.icons.css"&&E.fileName!=="fonts.css"),G,z,H),B=g($.outputDir,A.fileName);r(B,A.content),R(` ✓ Generated ${A.fileName}`,$.verbose),X.cssFiles.push(A)}if($.generateTypeScript!==!1){R(`
|
|
383
|
+
Generating TypeScript files...`,$.verbose);let G=s1($.config,$.typescriptOptions),z=await n$(W,G);for(let A of z){let B=g($.outputDir,"typescript",A.fileName);r(B,A.content),R(` ✓ Generated ${A.fileName}`,$.verbose)}X.typescriptFiles=z}if($.generateJavaScript!==!1){R(`
|
|
384
|
+
Generating JavaScript files...`,$.verbose);let G=a1($.config,$.javascriptOptions),z=$2(W,G);for(let A of z){let B=g($.outputDir,"js",A.fileName);r(B,A.content),R(` ✓ Generated ${A.fileName}`,$.verbose)}X.javascriptFiles=z}if($.generateJSON!==!1){R(`
|
|
385
|
+
Generating JSON files...`,$.verbose);let G=n1(W,K,$.config);for(let z of G){let A=g($.outputDir,"json",z.fileName);r(A,z.content),R(` ✓ Generated ${z.fileName}`,$.verbose)}X.jsonFiles=G}X.duration=Date.now()-Y,R(`
|
|
386
|
+
Build completed in ${X.duration}ms`,$.verbose)}catch(Z){let q=Z instanceof Error?Z.message:String(Z);X.errors.push(q),R(`❌ Build failed: ${q}`,$.verbose)}if($.validate!==!1){R(`
|
|
387
|
+
Validating build output...`,$.verbose);let{validateCSSFiles:Z,printValidationResults:q}=await Promise.resolve().then(() => (U2(),q2)),U=Z($.outputDir,$.config);if($.verbose||!U.isValid)q(U);if(!U.isValid)X.errors.push(...U.errors)}return X}function r1($){let Y=$.$metaData,X=$.$modes?[...Object.values($.$modes)]:[];return{prefix:Y.dsNamespace||Y.tokenNamespace,namespace:Y.tokenNamespace,generateModes:!0,modes:X,generateDerivedTokens:!0,generateBreakpointTokens:!0,failOnBrokenReferences:!0,transformName:(Z)=>{let q=Y.tokens?.css?.hooks?.shortenName;if(q?.enabled){let U=Z;if(q.prefix)for(let{find:K,replace:W}of q.prefix){let H=K.replace(/\./g,"-").replace(/-$/,""),G=W.replace(/\./g,"-").replace(/-$/,"");U=U.replace(H,G)}if(q.suffix){for(let{find:K,replace:W}of q.suffix)if(U.endsWith(K))U=U.substring(0,U.length-K.length)+W}return U}return Z}}}function W2($,Y){let Z=$.$metaData.tokens?.css,q=$.$modes?[...Object.values($.$modes)]:["light","dark"];return{...Y,separateThemeFiles:Z?.mediaQuery?.separateThemeFiles??!1,rootSelector:":root",generateMediaQueries:!0,customHeader:E$($),themeSelector:Z?.mediaQuery?.match||"[data-theme]",modes:q,hooks:Z?.hooks}}function s1($,Y){let X=$.$metaData;return{...Y,tokenInterface:"DesignTokens",exportNamespace:X.dsNamespace||X.tokenNamespace,generateTypes:!0,generateConsts:!0,generateCSSVarMappings:!0,includeJSDoc:!0}}function a1($,Y){let X=$.$modes?[...Object.values($.$modes)]:["light","dark"];return{...Y,modes:X,typescript:!0,separateThemeFiles:!0,includeJSDoc:!1,moduleType:"es",customHeader:`/**
|
|
386
388
|
* ${$.$name}
|
|
387
389
|
* Generated: ${new Date().toISOString()}
|
|
388
|
-
*/`}}function
|
|
390
|
+
*/`}}function n1($,Y,X){let Z=[],q=JSON.stringify({$schema:"https://schemas.designtokens.org/design-tokens.schema.json",$name:X.$name,$version:X.$version,tokens:Y.reduce((W,H)=>{return W[H.name]={$type:H.type,$value:H.value,$description:H.description,$extensions:H.extensions},W},{})},null,2);Z.push({fileName:"tokens.raw.json",content:q});let U=JSON.stringify({$name:X.$name,$version:X.$version,tokens:$.reduce((W,H)=>{return W[H.name]={$type:H.type,$value:H.value,$description:H.description,cssVar:H.cssVar},W},{})},null,2);Z.push({fileName:"tokens.resolved.json",content:U});let K=JSON.stringify({$name:`${X.$name} - CSS Variables`,$version:X.$version,variables:$.reduce((W,H)=>{return W[H.cssVar]=H.value,W},{})},null,2);return Z.push({fileName:"css-variables.json",content:K}),Z}function r($,Y){let X=K2($);if(!l1(X))c1(X,{recursive:!0});k1($,Y,"utf-8")}function R($,Y){if(Y!==!1)console.log($)}async function e$($,Y){let Z=(await import($)).default,q=K2($),U=(H)=>{if(H.startsWith("../"))return g(q,H);return g(q,Z.$paths.baseDir,H)},K=g(q,Z.$paths.baseDir,Z.$paths.tokensDir),W=Y||U(Z.$paths.distDir);return r0({config:Z,tokensDir:K,outputDir:W,verbose:!0})}var $0=F(()=>{t0();L$();Z2();l$();o$();p$()});$0();import{existsSync as t1}from"fs";import{resolve as o1}from"path";function e1($){let Y={};for(let X=0;X<$.length;X++){let Z=$[X];switch(Z){case"--config":case"-c":Y.config=$[++X];break;case"--input":case"-i":Y.input=$[++X];break;case"--output":case"-o":Y.output=$[++X];break;case"--verbose":case"-v":Y.verbose=!0;break;case"--no-css":Y.css=!1;break;case"--no-typescript":Y.typescript=!1;break;case"--no-json":Y.json=!1;break;case"--help":case"-h":Y.help=!0;break;default:if(Z.startsWith("-"))console.warn(`Unknown option: ${Z}`);break}}return Y}function $4(){console.log(`
|
|
389
391
|
Design Tokens Builder - W3C compliant token processor
|
|
390
392
|
|
|
391
393
|
Usage: build-tokens [options]
|
|
@@ -419,11 +421,11 @@ Token Files:
|
|
|
419
421
|
- Include $type and $value properties
|
|
420
422
|
- Support token references with {token.path} syntax
|
|
421
423
|
- Support extensions for modes, generators, and breakpoints
|
|
422
|
-
`)}function
|
|
423
|
-
❌ Build failed with ${
|
|
424
|
-
`),
|
|
425
|
-
Generated ${
|
|
426
|
-
Generated ${
|
|
427
|
-
Generated ${
|
|
428
|
-
Generated ${
|
|
429
|
-
Warnings:`),
|
|
424
|
+
`)}function X4($){let Y=[$,"./designid.config.ts","./designid.config.mjs","./designid.config.js","./tokens.config.ts","./tokens.config.js"].filter(Boolean);for(let X of Y){let Z=o1(X);if(t1(Z))return Z}throw Error(`Config file not found. Tried: ${Y.join(", ")}`)}async function Y4(){let $=e1(process.argv.slice(2));if($.help){$4();return}try{let Y=X4($.config);console.log(`Using config: ${Y}`);let X=await e$(Y,$.output);if(X.errors.length>0)console.log(`
|
|
425
|
+
❌ Build failed with ${X.errors.length} error${X.errors.length>1?"s":""}:`),X.errors.forEach((Z)=>console.log(` - ${Z}`)),process.exit(1);if(console.log(`Processed ${X.tokenCount} tokens`),console.log(`Duration: ${X.duration}ms`),console.log(`Build completed successfully!
|
|
426
|
+
`),X.cssFiles.length>0)console.log(`
|
|
427
|
+
Generated ${X.cssFiles.length} CSS files:`),X.cssFiles.forEach((Z)=>console.log(` - ${Z.fileName}`));if(X.typescriptFiles.length>0)console.log(`
|
|
428
|
+
Generated ${X.typescriptFiles.length} TypeScript files:`),X.typescriptFiles.forEach((Z)=>console.log(` - ${Z.fileName}`));if(X.javascriptFiles.length>0)console.log(`
|
|
429
|
+
Generated ${X.javascriptFiles.length} JavaScript files:`),X.javascriptFiles.forEach((Z)=>console.log(` - ${Z.fileName}`));if(X.jsonFiles.length>0)console.log(`
|
|
430
|
+
Generated ${X.jsonFiles.length} JSON files:`),X.jsonFiles.forEach((Z)=>console.log(` - ${Z.fileName}`));if(X.warnings.length>0)console.log(`
|
|
431
|
+
Warnings:`),X.warnings.forEach((Z)=>console.log(` - ${Z}`))}catch(Y){console.error("❌ Build failed:",Y),process.exit(1)}}if(import.meta.url===`file://${process.argv[1]}`)Y4().catch(($)=>{console.error("Unexpected error:",$),process.exit(1)});export{Y4 as runCLI};
|
package/bin/watch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var z=($,
|
|
2
|
+
var z=($,X)=>()=>($&&(X=$($=0)),X);import J0 from"colorjs.io";var D=z(()=>{B()});var u=z(()=>{B()});var s=z(()=>{B()});import{spawnSync as m$}from"child_process";import{existsSync as I,mkdirSync as d$,readFileSync as u$,unlinkSync as B$,writeFileSync as C0}from"fs";import{resolve as V0,join as L,basename as g0,normalize as T0,relative as y0,sep as f0,dirname as L$}from"path";async function k$(){return`${(await Y$()).$metaData?.tokenNamespace||"tokens"}.icons`}async function O$($){let U=L($,"designid.config.ts");if(I(L($,"designid.config.mjs")))B$(L($,"designid.config.mjs"));let Y=L($,"designid.config.js");if(I(Y))B$(Y);if(I(U)){let q=m$("bun",["build",U,"--outfile ./designid.config.mjs","--minify","--target","node","--packages","external","--no-bundle"],{stdio:"inherit",cwd:$,shell:!0});if(q.status!==0)console.error("Failed to compile designid.config.mjs with bun."),process.exit(q.status??1);if(q.status===0)return new Promise((Z)=>Z(!0))}}async function T($="json"){let{tokenNamespace:X}=await V();return`${X}-design-system.tokens.svg${$==="d.ts"||$==="js"?".config":""}.${$}`}function x($){if(!I($))d$($,{recursive:!0})}async function X$($,X=!1){let U=y(),Y;if(U.endsWith(".json"))Y=JSON.parse(u$(U,"utf8").trim()??"{}");else if(U.endsWith(".ts"))if(typeof globalThis.Bun<"u"){if(Y=await import(U),Y.default)Y=Y.default}else{$=$??L$(U)+"/";let Z=e($);if(Z&&(X||!I(Z)))await O$($);if(Y=await import(Z),Y.default)Y=Y.default}else{$=$??L$(U)+"/";let q=e($);if(q&&(X||!I(q)))await O$($);if(Y=await import(q),Y.default)Y=Y.default}return Y}async function S($=!1){let{baseDir:X}=await N(),U=process.cwd(),q=L(U,X),{buildDir:Z,distDir:_}=await N();if($)try{x(L(q,Z)),x(L(q,_))}catch(G){console.error("Error creating directories:",G)}return q}function e($){return $?L($,"designid.config.mjs"):L(process.cwd(),"designid.config.mjs")}function y(){let $=process.argv.find((G)=>G.startsWith("--config=")),[,X]=$?.split("=")??[];if(X)return X;let U=process.cwd(),Y=e(U),q=L(U,"designid.config.ts"),Z=I(Y),_=I(q);if(Z)return Y;else if(_)return q;throw console.error("Config file not found"),Error("Config file not found")}async function N($=!1){let X=y(),Y=(await X$(process.cwd(),$)).$paths;if(!Y)throw console.error("Project paths not found"),Error("Project paths not found");return{configFile:X,...Y}}async function V(){let X=(await X$(process.cwd())).$metaData;if(!X)throw console.error("Project metaData not found"),Error("Project metaData not found");if(!X.colorspace)X.colorspace="hex";if(!X.fontNamespace)X.fontNamespace=`${X.dsNamespace}.font`;if(!X?.tokens?.css?.mediaQuery?.match)X={...X??{},tokens:{...X.tokens??{},css:{...X.tokens?.css??{},mediaQuery:{...X.tokens?.css?.mediaQuery??{},match:"[data-theme]"}}}};if(X?.tokens?.css?.mediaQuery&&typeof X.tokens.css.mediaQuery.separateThemeFiles!=="boolean")X.tokens.css.mediaQuery.separateThemeFiles=!1;if(!X.dsNamespace)X.dsNamespace=X.tokenNamespace;let U=await k$();return{...X,icons:X.icons??{objectPath:U},dsNamespace:X.dsNamespace}}async function Y$(){if(!r){let $=y();r=await X$(process.cwd()),_$=$}return r}async function Z$(){if(!a){let X=(await Y$()).$metaData;if(!X)throw console.error("Project metaData not found"),Error("Project metaData not found");if(!X.dsNamespace)X.dsNamespace=X.tokenNamespace;let Y=`${X.tokenNamespace||"tokens"}.icons`;a={...X,icons:X.icons??{objectPath:Y},dsNamespace:X.dsNamespace}}return a}async function Q$($=!1){if(!n){let U=(await Y$()).$paths;if(!U)throw console.error("Project paths not found"),Error("Project paths not found");n={configFile:_$,...U}}return n}async function f(){if(!t){let{distDir:$,assets:X,buildDir:U}=await Q$(!0),{fontNamespace:Y,tokenNamespace:q,icons:Z}=await Z$(),_=await S(),G=process.cwd(),E=L(G,$,"css");t={distDir:$,assets:X,fontNamespace:Y,__dirname:_,workspaceRoot:G,distCSSPath:E,buildDir:U,tokenNamespace:q,icons:Z}}return t}async function q$(){if(!o){let{icons:$}=await Z$();o=$}return o}var r=null,_$=null,a=null,n=null,t=null,o=null;var h=z(()=>{B()});var I$=z(()=>{h()});async function U$($){let X=await q$();$=$.replace(/<\?xml[^>]*\?>\s*/,""),$=$.replace(/<!DOCTYPE [^>]*>\s*/,"");let U=$.match(/<svg[^>]*>/),Y=$.match(/viewBox="([\d\s.]+)"/),[q]=U??[],Z=q;if(q&&Z){let G=X?.style?.fill,E=/id="[^"]*"/.test(q);if(!Z.includes("xmlns="))Z=Z.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"');if(!E&&G)Z=Z.replace("<svg",`<svg id="${G}"`);else if(E&&G)Z=Z.replace(/id="[^"]*"/,`id="${G}"`)}if(Y&&q&&Z){let G=Y[1].split(" ").map(Number),E=G[2],w=G[3],W=X?.size??24,Q=E/w*W;$=$.replace(/height="[\d.]+px?"/,`height="${W}px"`),$=$.replace(/width="[\d.]+px?"/,`width="${Q}px"`);let j=/width="[\d.]+(px)?"/.test(q),J=/height="[\d.]+(px)?"/.test(q);if(!j)Z=Z.replace("<svg",`<svg width="${Q}px"`);else Z=Z.replace(/width="[\d.]+(px)?"/,`width="${Q}px"`);if(!J)Z=Z.replace("<svg",`<svg height="${W}px"`);else Z=Z.replace(/height="[\d.]+(px)?"/,`height="${W}px"`);$=$.replace(q,Z)}if(!$?.match(/data-style="([^"]*)"/)&&X?.style?.type)$=$.replace("<svg ",`<svg data-style="${X.style.type}" `);return $}var J$=z(()=>{B()});var F$=z(()=>{h();B()});var W$=z(()=>{B()});var x$=()=>{};import G2 from"colorjs.io";var K$=z(()=>{x$();D()});var v=z(()=>{B()});var G$=z(()=>{B()});import{readFileSync as t$,mkdirSync as o$}from"fs";import{writeFile as S$,readdir as e$,mkdir as $0}from"fs/promises";import{resolve as X0,relative as j$,join as p,dirname as Y0}from"path";import Z0 from"lodash";async function P$($){let X=await e$($,{withFileTypes:!0}),U=await Promise.all(X.map((Y)=>{let q=X0($,Y.name);return Y.isDirectory()?P$(q):q}));return Array.prototype.concat(...U)}async function D$(){let{assets:$,icons:X,tokenNamespace:U,__dirname:Y,buildDir:q}=await f(),Z=p(Y,$?.icons?.sourceDir??"icons"),_="build",G=$?.icons?.distDir??"build",E=p(Y,G),w=p(Y,q,"icons");if(!$?.icons?.sourceDir){console.error("Skipping icon build: iconsDir is not defined in the project paths.");return}x(p(Y,q));let W=(await P$(Z)).filter((H)=>H.endsWith(".svg")),J=(await Promise.all(W.map(async(H)=>{let K=t$(H,"utf8").replace(/(\s+(?=(?:[^"]*"[^"]*")*[^"]*$))/g," ").trim()??"";K=await U$(K);let A=j$(Z,H).split("/").pop(),P=(K.match(/name="(.*?)"/)??[])[1]??A?.replace(".svg",""),m=(K.match(/data-style="(.*?)"/)??[])[1],T$=(K.match(/description="(.*?)"/)??[])[1],[z$]=K.match(/<svg[^>]*>/)??[],[,y$]=z$?.match(/width="([\d.]+)(px)?"/)??[],[,f$]=z$?.match(/height="([\d.]+)(px)?"/)??[];if(m!=="animated"&&m!=="custom")return{path:H,folder:j$(Z,H).split("/").slice(0,-1).concat(P),file:A,style:m,content:K,name:P,dimensions:{width:Number(y$),height:Number(f$)},description:T$??""};return}))).filter((H)=>H!==void 0).reduce((H,K)=>{if(K?.style!=="animated"&&K?.style!=="custom"&&K)H$(H,K.folder.join("."),{$type:"icon",$name:K.name,$description:K.description,$style:K.style,$value:K.content,$dimensions:K.dimensions,...q0(H,K.folder.join("."))});return H},{}),M=X?.objectPath??`${U}.icons`;Object.keys(J).forEach(async(H)=>{let K=`${w}/${H}`,A=`${K}/svg.${H}.tokens.json`;await $0(K,{recursive:!0});let P=H$({},`${M}${M?".":""}${H}`,J[H]);await S$(A,JSON.stringify(P,null,2),{flag:"w",encoding:"utf-8"})});let O=`${E}/tokens/${await T("json")}`,R=Y0(O);o$(R,{recursive:!0});let F=H$({},M,J);await S$(O,JSON.stringify(F,null,2),{flag:"w",encoding:"utf-8"})}var H$,q0,F2;var C$=z(()=>{B();({set:H$,get:q0}=Z0);F2=D$().catch(($)=>{console.error($),process.exit(1)})});var b$=z(()=>{v()});var V$=z(()=>{C$();v();b$();K$();G$();W$()});var B=z(()=>{D();u();s();D();h();I$();J$();F$();u();s();W$();K$();v();G$();V$()});B();import{exec as O0}from"child_process";import{join as g$}from"path";import w0 from"chokidar";if(process.argv.includes("--help")||process.argv.includes("-h"))console.log(`
|
|
3
3
|
Watch Tokens - File watcher for design token changes
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
@@ -14,13 +14,13 @@ Example:
|
|
|
14
14
|
bun src/scripts/watch-tokens.ts
|
|
15
15
|
bun src/scripts/watch-tokens.ts --config=./custom-config.ts
|
|
16
16
|
bun src/scripts/watch-tokens.ts --dev
|
|
17
|
-
`),process.exit(0);async function
|
|
18
|
-
`);let
|
|
19
|
-
❌ Build failed: ${
|
|
20
|
-
${
|
|
21
|
-
`).filter((K)=>{let A=K.trim();return A&&(A.includes("✅")||A.includes("❌")||A.includes("Generated")||A.includes("Build completed")||A.includes("PASSED")||A.includes("FAILED"))});if(
|
|
22
|
-
${
|
|
17
|
+
`),process.exit(0);async function _0(){let $=await S(),{distDir:X,buildDir:U}=await N(),Y=[/node_modules/,/dist/,/build/,g$($,X),g$($,U)],q=w0.watch(["**/*.tokens.json","designid.config.ts"],{ignored:Y,persistent:!0}),Z,_=300,G=!1,E=()=>{if(G){console.log(`[${new Date().toLocaleTimeString()}] Build already in progress, skipping...`);return}clearTimeout(Z),Z=setTimeout(()=>{G=!0,console.clear(),process.stdout.write("\x1Bc"),console.log(`[${new Date().toLocaleTimeString()}] Changes detected. Re-building tokens...
|
|
18
|
+
`);let W=(()=>{let O=process.argv.find((R)=>R.startsWith("--config="));return O?O.split("=")[1]:""})(),Q=(()=>{return process.argv.find((O)=>O==="--dev")??null})(),j=W?`--config=${W}`:"",J=W?`CONFIG=${W}`:"",M=Q?`make build ${J}`:`bun run build ${j}`;O0(M,{cwd:process.cwd()},(O,R,F)=>{if(G=!1,O){console.error(`
|
|
19
|
+
❌ Build failed: ${O.message}`);return}if(F&&F.trim())console.warn(`⚠️ Warnings:
|
|
20
|
+
${F}`);if(R&&R.trim()){let H=R.split(`
|
|
21
|
+
`).filter((K)=>{let A=K.trim();return A&&(A.includes("✅")||A.includes("❌")||A.includes("Generated")||A.includes("Build completed")||A.includes("PASSED")||A.includes("FAILED"))});if(H.length>0)console.log(`
|
|
22
|
+
${H.join(`
|
|
23
23
|
`)}`)}console.log(`
|
|
24
24
|
✅ Build completed at ${new Date().toLocaleTimeString()}
|
|
25
25
|
`)})},300)};q.on("ready",()=>{console.log("Watching for changes in .tokens.json files and designid.config.ts..."),console.log(`Working directory: ${process.cwd()}`),console.log(`Press Ctrl+C to stop watching
|
|
26
|
-
`)}).on("change",(
|
|
26
|
+
`)}).on("change",(W)=>{console.log(`Changed: ${W}`),E()}).on("add",(W)=>{console.log(`Added: ${W}`),E()}).on("unlink",(W)=>{console.log(`Deleted: ${W}`),E()}).on("error",(W)=>{console.error(`Watcher error: ${W}`)});let w=()=>{clearTimeout(Z),q.close().then(()=>{console.log("File watcher closed successfully"),process.exit(0)}).catch((W)=>{console.error("Error closing file watcher:",W),process.exit(1)})};process.on("SIGINT",w),process.on("SIGTERM",w),process.on("SIGHUP",w),process.on("uncaughtException",(W)=>{console.error("Uncaught Exception:",W),w()}),process.on("unhandledRejection",(W,Q)=>{console.error("Unhandled Rejection at:",Q,"reason:",W),w()})}_0().catch(($)=>{console.error("Error starting watch process:",$),process.exit(1)});
|
package/package.json
CHANGED
package/types/utils.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { TFont } from "./typography.ts";
|
|
|
3
3
|
import type { TransformedToken } from "style-dictionary/types";
|
|
4
4
|
|
|
5
5
|
export type TDictionary = Dictionary;
|
|
6
|
-
export type TTheme = "light" | "dark";
|
|
6
|
+
export type TTheme = "light" | "dark" | string;
|
|
7
7
|
|
|
8
8
|
export type TTransformationConfig = File;
|
|
9
9
|
|