@designid/tokens 1.0.0 → 1.0.1
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 +66 -52
- package/bin/watch.js +4 -4
- package/package.json +1 -1
package/bin/build.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var e0=Object.defineProperty;var $2=($,X)=>{for(var Y in X)e0($,Y,{get:X[Y],enumerable:!0,configurable:!0,set:(Z)=>X[Y]=()=>Z})};var N=($,X)=>()=>($&&(X=$($=0)),X);import t$ from"colorjs.io";function C($,X){if(!$)return $;if(X&&X.type!=="color")return $;if(typeof $==="string")$=new t$($);if(typeof $?.to!=="function")return $;return $.to("srgb").toString({format:"hex"})}function h($){try{if($)return new t$($),!0;return!1}catch{return!1}}var s=N(()=>{P()});var H$=N(()=>{P()});var L$=N(()=>{P()});import{spawnSync as W2}from"child_process";import{existsSync as v,mkdirSync as q2,readFileSync as U2,unlinkSync as K2,writeFileSync as q1}from"fs";import{resolve as K1,join as j,basename as G1,normalize as H1,relative as z1,sep as A1,dirname as G2}from"path";async function H2(){return`${(await M$()).$metaData?.tokenNamespace||"tokens"}.icons`}async function z2($){let Y=j($,"designid.config.ts");if(v(j($,"designid.config.js")))K2(j($,"designid.config.js"));if(v(Y)){let Z=W2("bun",["build",Y,"--outfile ./designid.config.js","--minify","--target","node","--packages","external"],{stdio:"inherit",cwd:".",shell:!0});if(Z.status!==0)console.error("Failed to compile designid.config.js with bun."),process.exit(Z.status??1);if(Z.status===0)return new Promise((W)=>W(!0))}}async function u($="json"){let{tokenNamespace:X}=await $$();return`${X}-design-system.tokens.svg${$==="d.ts"||$==="js"?".config":""}.${$}`}function Y0($){if(!v($))q2($,{recursive:!0})}async function R$($,X=!1){let Y=e(),Z;if(Y.endsWith(".json"))Z=JSON.parse(U2(Y,"utf8").trim()??"{}");else{$=$??G2(Y)+"/";let W=Z0($);if(W&&(X||!v(W)))await z2($);if(Z=await import(W),Z.default)Z=Z.default}return Z}async function t(){let{baseDir:$}=await d(),X=process.cwd(),Z=j(X,$),{buildDir:W,distDir:q}=await d();try{Y0(j(Z,W)),Y0(j(Z,q))}catch(U){console.error("Error creating directories:",U)}return Z}function Z0($){return $?j($,"designid.config.js"):j(process.cwd(),"designid.config.js")}function e(){let $=process.argv.find((K)=>K.startsWith("--config=")),[,X]=$?.split("=")??[];if(X)return X;let Y=process.cwd(),Z=Z0(Y),W=j(Y,"designid.config.ts"),q=v(Z),U=v(W);if(q)return Z;else if(U)return W;throw console.error("Config file not found"),Error("Config file not found")}async function d($=!1){let X=e(),Z=(await R$(process.cwd(),$)).$paths;if(!Z)throw console.error("Project paths not found"),Error("Project paths not found");return{configFile:X,...Z}}async function $$(){let X=(await R$(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 Y=await H2();return{...X,icons:X.icons??{objectPath:Y},dsNamespace:X.dsNamespace}}async function M$(){if(!_$){let $=e();_$=await R$(process.cwd()),W0=$}return _$}async function N$(){if(!w$){let X=(await M$()).$metaData;if(!X)throw console.error("Project metaData not found"),Error("Project metaData not found");if(!X.dsNamespace)X.dsNamespace=X.tokenNamespace;let Z=`${X.tokenNamespace||"tokens"}.icons`;w$={...X,icons:X.icons??{objectPath:Z},dsNamespace:X.dsNamespace}}return w$}async function q0($=!1){if(!O$){let Y=(await M$()).$paths;if(!Y)throw console.error("Project paths not found"),Error("Project paths not found");O$={configFile:W0,...Y}}return O$}async function T(){if(!Q$){let{distDir:$,assets:X,buildDir:Y}=await q0(!0),{fontNamespace:Z,tokenNamespace:W,icons:q}=await N$(),U=await t(),K=process.cwd(),G=j(K,$,"css");Q$={distDir:$,assets:X,fontNamespace:Z,__dirname:U,workspaceRoot:K,distCSSPath:G,buildDir:Y,tokenNamespace:W,icons:q}}return Q$}async function F$(){if(!I$){let{icons:$}=await N$();I$=$}return I$}var _$=null,W0=null,w$=null,O$=null,Q$=null,I$=null;var Y$=N(()=>{P()});var U0=N(()=>{Y$()});async function x$($){let X=await F$();$=$.replace(/<\?xml[^>]*\?>\s*/,""),$=$.replace(/<!DOCTYPE [^>]*>\s*/,"");let Y=$.match(/<svg[^>]*>/),Z=$.match(/viewBox="([\d\s.]+)"/),[W]=Y??[],q=W;if(W&&q){let K=X?.style?.fill,G=/id="[^"]*"/.test(W);if(!q.includes("xmlns="))q=q.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"');if(!G&&K)q=q.replace("<svg",`<svg id="${K}"`);else if(G&&K)q=q.replace(/id="[^"]*"/,`id="${K}"`)}if(Z&&W&&q){let K=Z[1].split(" ").map(Number),G=K[2],H=K[3],z=X?.size??24,A=G/H*z;$=$.replace(/height="[\d.]+px?"/,`height="${z}px"`),$=$.replace(/width="[\d.]+px?"/,`width="${A}px"`);let B=/width="[\d.]+(px)?"/.test(W),E=/height="[\d.]+(px)?"/.test(W);if(!B)q=q.replace("<svg",`<svg width="${A}px"`);else q=q.replace(/width="[\d.]+(px)?"/,`width="${A}px"`);if(!E)q=q.replace("<svg",`<svg height="${z}px"`);else q=q.replace(/height="[\d.]+(px)?"/,`height="${z}px"`);$=$.replace(W,q)}if(!$?.match(/data-style="([^"]*)"/)&&X?.style?.type)$=$.replace("<svg ",`<svg data-style="${X.style.type}" `);return $}var K0=N(()=>{P()});var A0=N(()=>{Y$();P()});import{copyFileSync as _2,existsSync as w2,mkdirSync as B0,statSync as O2}from"fs";import{writeFile as Q2}from"fs/promises";import{join as x,relative as I2}from"path";async function P$($,X){try{let{assets:Y,workspaceRoot:Z,distDir:W,__dirname:q}=await T(),U=Y?.fonts?.sourceDir?x(q,Y.fonts.sourceDir):null,K=x("assets","fonts"),G=x(Z,W),H=Y?.fonts?.distDir?x(G,Y.fonts.distDir.replace(/^\.\//,"")):x(G,K);if(!$||!U)return;let z="",A=X&&Y?.fonts?.distDir?x(X,Y.fonts.distDir.replace(/^\.\//,"")):H;for(let _ of $){if(!_)continue;if(z+=`/**** ${_.family} ${_.style} ****/
|
|
3
3
|
`,_.linkHref){let J=await(await fetch(_.linkHref)).text();z+=`${J.replace(/\s+/g," ").replace(/:\s+/g,":")}
|
|
4
|
-
`}else if(_?.src&&U){let
|
|
4
|
+
`}else if(_?.src&&U){let w=_.directory??_.family.toLowerCase().replace(/\s+/g,"-"),J=x(U,w,_.src);try{if(!w2(J)||!O2(J).isFile()){console.warn(`Font file not found: ${J}`);continue}}catch{console.warn(`Error accessing font file: ${J}`);continue}try{B0(x(A,w),{recursive:!0}),_2(x(U,w,_.src),x(A,w,_.src))}catch(Q){console.warn(`Error copying font file ${_.src}:`,Q instanceof Error?Q.message:Q);continue}let O;if(Y?.fonts?.cssImportPath)O=x(Y.fonts.cssImportPath,w,_.src).replace(/\\/g,"/");else{let{distCSSPath:Q}=await T(),I=X?x(X,"css"):Q,F=I2(I,A);O=x(F,w,_.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("${O}") format("${_.format}");
|
|
9
9
|
}
|
|
10
|
-
`}}let{distCSSPath:B}=await T(),E=X?x(X,"css"):B,L=`${E}/fonts.css`;
|
|
10
|
+
`}}let{distCSSPath:B}=await T(),E=X?x(X,"css"):B,L=`${E}/fonts.css`;B0(E,{recursive:!0}),await Q2(L,z,{flag:"w",encoding:"utf-8"})}catch(Y){console.error("Error appending typography tokens:",Y)}}var j$=N(()=>{P()});function k($){if(typeof $!=="string"||!$.startsWith("{")||!$.endsWith("}"))return!1;let X=$.slice(1,-1);return!X.includes("{")&&!X.includes("}")&&X.trim()!==""}function c($){if(typeof $!=="string")return!1;let X=/\{[^}]+\}/g,Y=$.match(X);return!!(Y&&Y.length>0&&$.length>Y.join("").length)}function X$($){let X=[],Y=/\{[^}]+\}/g,Z=0,W;while((W=Y.exec($))!==null){if(W.index>Z){let U=$.slice(Z,W.index);if(U)X.push({type:"literal",value:U})}let q=W[0];if(q.startsWith("{#/"))X.push({type:"reference",value:q,ref:{$ref:q.slice(2,-1)}});else X.push({type:"reference",value:q,ref:q});Z=W.index+W[0].length}if(Z<$.length){let q=$.slice(Z);if(q)X.push({type:"literal",value:q})}return X}function L0($){return!!$.$extensions?.$mode}function E0($){return!!($.$extensions?.$generators&&Array.isArray($.$extensions.$generators))}function _0($){return!!($.$extensions?.$breakpoints&&typeof $.$extensions.$breakpoints==="object")}function w0($,X){return`${$}${X}`}function O0($){return typeof $==="object"&&$!==null&&"$value"in $}function Q0($){return typeof $==="object"&&$!==null&&!("$value"in $)}var I0=()=>{};function J0($){if(typeof $!=="string")return!1;let X=$.trim();return X.startsWith("<svg")&&X.includes("</svg>")}function R0($){if(typeof $!=="string")return!1;return $.startsWith("data:image/png;base64,")||$.startsWith("iVBORw0KGgo")}function M0($){if(typeof $!=="string")return!1;return $.startsWith("data:image/jpeg;base64,")||$.startsWith("data:image/jpg;base64,")||$.startsWith("/9j/")}function R2($){let X=$.trim();return X=X.replace(/\s+/g," ").replace(/>\s+</g,"><").trim(),`data:image/svg+xml;base64,${Buffer.from(X,"utf-8").toString("base64")}`}function M2($){if($.startsWith("data:image/png;base64,"))return $;return`data:image/png;base64,${$}`}function N2($){if($.startsWith("data:image/jpeg;base64,")||$.startsWith("data:image/jpg;base64,"))return $;return`data:image/jpeg;base64,${$}`}function S$($){if(!$||typeof $!=="string")return $;if($.startsWith("data:"))return $;if(J0($))return R2($);else if(R0($))return M2($);else if(M0($))return N2($);return $}function F2($){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 y($){return J0($)||R0($)||M0($)||F2($)}import{readFileSync as x2,readdirSync as P2,statSync as j2}from"fs";import{join as S2}from"path";import F0 from"colorjs.io";function D$($){let X={};function Y(Z){let W=P2(Z);for(let q of W){let U=S2(Z,q);if(j2(U).isDirectory())Y(U);else if(q.endsWith(".tokens.json"))try{let G=x2(U,"utf-8");if(!G.trim())continue;let H=JSON.parse(G);x0(X,H)}catch(G){console.warn(`Failed to load token file: ${U}`,G)}}}return Y($),X}function x0($,X){for(let Y in X)if(X[Y]&&typeof X[Y]==="object"&&!Array.isArray(X[Y])){if(!$[Y])$[Y]={};x0($[Y],X[Y])}else $[Y]=X[Y]}function C$($,X={}){let Y=[];function Z(W,q=[]){for(let[U,K]of Object.entries(W)){if(U.startsWith("$"))continue;let G=[...q,U],H=G.join(".");if(O0(K)){let z={path:G,name:H,type:K.$type,value:K.$value,description:K.$description,extensions:K.$extensions?{mode:L0(K)?K.$extensions.$mode:K.$extensions.mode?K.$extensions.mode:void 0,generators:E0(K)?K.$extensions.$generators:K.$extensions.generators?K.$extensions.generators:void 0,breakpoints:_0(K)?K.$extensions.$breakpoints:K.$extensions.breakpoint?K.$extensions.breakpoint:void 0,...Object.fromEntries(Object.entries(K.$extensions).filter(([A])=>!["$mode","$generators","$breakpoints","mode","generators","breakpoint"].includes(A)))}:void 0,original:K};if(!X.namespace||H.startsWith(X.namespace))Y.push(z)}else if(Q0(K))Z(K,G)}}return Z($),Y}function b$($,X={}){let Y=[...$],Z=new Map($.map((K)=>[K.name,K]));if(X.generateModes||X.generateDerivedTokens||X.generateBreakpointTokens)for(let K of $){let G=N0(K,X,Z);if(Y.push(...G),X.generateModes){for(let H of G)if(H.extensions?.mode&&!H.name.match(/@(dark|light)$/)){let z=N0(H,X,Z);Y.push(...z)}}}let W={tokens:new Map(Y.map((K)=>[K.name,K])),mode:X.generateModes?"light":void 0,options:X,brokenReferences:[]},q=[];for(let K of Y){let G=K.name.endsWith("@dark")?"dark":K.name.endsWith("@light")?"light":X.generateModes?"light":void 0,H={...W,mode:G},z=D2(K,H);q.push(z)}if(X.failOnBrokenReferences!==!1&&W.brokenReferences.length>0){let K=[...new Set(W.brokenReferences)],G=`Token reference${K.length>1?"s":""} not found:
|
|
11
11
|
${K.map((H)=>` - ${H}`).join(`
|
|
12
|
-
`)}`;throw Error(G)}return q}function R0($,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`,O=Y?.get(L),J=Y?.has(_)||O?.extensions?.mode?.dark!==void 0||O&&(Array.isArray(O.value)||typeof O.value==="object"&&O.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=(O,J=new Set)=>{if(J.has(O))return!1;J.add(O);let w=Y?.get(O);if(!w){let Q=O.match(/^(.+)@([^@]+)$/);if(Q){let[,I,F]=Q,g=Y?.get(I);if(g){if(g.extensions?.mode?.dark!==void 0)return!0;if(g.extensions?.generators)return!0;return L(I,J)}}return!1}if(w.extensions?.mode?.dark!==void 0)return!0;if(Y?.has(`${O}@dark`))return!0;if(typeof w.value==="string"&&w.value.startsWith("{")&&w.value.endsWith("}")){let Q=w.value.slice(1,-1);return L(Q,J)}if(Array.isArray(w.value)||typeof w.value==="object"&&w.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(w.value))return w.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 w.value==="object")return Object.values(w.value).some((I)=>typeof I==="string"&&I.includes("{")&&L(I.slice(1,-1),new Set(J)))||Q(w.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,O=Y?.get(L);if(O){if(O.extensions?.mode?.dark!==void 0)return!0;if(O.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=E0($.name,q),{...G}=$.extensions;Z.push({...$,name:K,value:$.value,path:[...$.path,q],extensions:{...G,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 j2($,X){let Y=l($.value,X),Z=$.type;if(typeof $.value==="string"&&k($.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"&&c(U.value)){let K=X$(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"&&c($.value)){let q=X$($.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=b(Y,X);if($.extensions?.generator&&typeof $.extensions.generator==="object"&&"type"in $.extensions.generator&&"value"in $.extensions.generator)Y=P0($.value,$.extensions.generator.type,$.extensions.generator.value,X);let W=S2($.name,X.options);if(Z==="color"&&typeof Y==="string"&&h(Y))Y=C(Y,$);if(typeof Y==="string"&&y(Y))Y=S$(Y);return{...$,type:Z,value:Y,cssVar:W}}function b($,X){if(typeof $==="string"){if(k($))return V$($,X);else if(c($))return x0($,X)}if(Array.isArray($))return $.map((Y)=>b(Y,X));if(typeof $==="object"&&$!==null){if("$value"in $&&typeof $.$value==="string")return b($.$value,X);if("value"in $&&typeof $.value==="string"&&"$type"in $){if(X.mode&&$.$extensions?.mode?.[X.mode])return b($.$extensions.mode[X.mode],X);return b($.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)=>b(U,X)).join(W);return b($.value,X)}let Y={};for(let[Z,W]of Object.entries($))Y[Z]=b(W,X);return Y}return $}function l($,X){if(typeof $==="string"){if(c($))return x0($,X);else if(k($))return V$($,X)}else if(typeof $==="object"&&$!==null&&"$ref"in $)return F0($,X);return $}function V$($,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=P0(Z.value,Z.extensions.generator.type,Z.extensions.generator.value,X);else if(X.mode&&Z.extensions?.mode?.[X.mode])W=l(Z.extensions.mode[X.mode],X);else W=l(Z.value,X);if(Z.type==="color"&&typeof W==="string"&&h(W))W=C(W,Z);if(typeof W==="string"&&y(W))W=S$(W);return W}function F0($,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 l(W.value,X)}function x0($,X){let Y=X$($),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"&&k(U.ref)){K=V$(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=F0(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 P0($,X,Y,Z){let W=l($,Z);switch(X){case"alpha":if(typeof W==="string")return D2(W,Number(Y)/100);break;case"scale":if(typeof W==="string"&&W.match(/[\d.]+/))return C2(W,Number(Y));break;case"hue":if(typeof W==="string")return b2(W,Number(Y));break;default:return console.warn(`Unknown generator type: ${X}`),W}return W}function S2($,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 D2($,X){try{if(!h($))return $;let Y=new M0($);return Y.alpha=X,C(Y)}catch(Y){return console.warn(`Failed to apply alpha to color "${$}": ${Y}`),$}}function C2($,X){let Y=$.match(/([\d.]+)(\w+)/);if(Y){let[,Z,W]=Y;return`${parseFloat(Z)*X}${W}`}return $}function b2($,X){try{if(!h($))return $;let Z=new M0($).to("oklch");return Z.h=(Z.h+X)%360,C(Z)}catch(Y){return console.warn(`Failed to shift hue for color "${$}": ${Y}`),$}}var g$=N(()=>{w0();s()});function T$($){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$($,X={}){let{rootSelector:Y=":root",separateThemeFiles:Z=!1,generateMediaQueries:W=!1,customHeader:q}=X;if(Z)return g2($,X);let U=new Map,K=new Map;U.set("light",[]),U.set("dark",[]);for(let E of $){if(typeof E.value==="string"&&y(E.value))continue;if(T$(E))continue;let L=` ${E.cssVar}: ${S(E.value,E.type)};`;if(W&&E.name.includes("@media")){let O=q$(E);if(O){if(!K.has(O))K.set(O,[]);K.get(O).push(L);continue}}let _=E.name.match(/@(dark|light)$/);if(_){let O=_[1];U.get(O).push(L)}else U.get("light").push(L)}let G="";if(q)G+=`${q}
|
|
12
|
+
`)}`;throw Error(G)}return q}function N0($,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,g=Y?.get(I);if(g){if(g.extensions?.mode?.dark!==void 0)return!0;if(g.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=w0($.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 D2($,X){let Y=l($.value,X),Z=$.type;if(typeof $.value==="string"&&k($.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"&&c(U.value)){let K=X$(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"&&c($.value)){let q=X$($.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=b(Y,X);if($.extensions?.generator&&typeof $.extensions.generator==="object"&&"type"in $.extensions.generator&&"value"in $.extensions.generator)Y=S0($.value,$.extensions.generator.type,$.extensions.generator.value,X);let W=C2($.name,X.options);if(Z==="color"&&typeof Y==="string"&&h(Y))Y=C(Y,$);if(typeof Y==="string"&&y(Y))Y=S$(Y);return{...$,type:Z,value:Y,cssVar:W}}function b($,X){if(typeof $==="string"){if(k($))return V$($,X);else if(c($))return j0($,X)}if(Array.isArray($))return $.map((Y)=>b(Y,X));if(typeof $==="object"&&$!==null){if("$value"in $&&typeof $.$value==="string")return b($.$value,X);if("value"in $&&typeof $.value==="string"&&"$type"in $){if(X.mode&&$.$extensions?.mode?.[X.mode])return b($.$extensions.mode[X.mode],X);return b($.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)=>b(U,X)).join(W);return b($.value,X)}let Y={};for(let[Z,W]of Object.entries($))Y[Z]=b(W,X);return Y}return $}function l($,X){if(typeof $==="string"){if(c($))return j0($,X);else if(k($))return V$($,X)}else if(typeof $==="object"&&$!==null&&"$ref"in $)return P0($,X);return $}function V$($,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=S0(Z.value,Z.extensions.generator.type,Z.extensions.generator.value,X);else if(X.mode&&Z.extensions?.mode?.[X.mode])W=l(Z.extensions.mode[X.mode],X);else W=l(Z.value,X);if(Z.type==="color"&&typeof W==="string"&&h(W))W=C(W,Z);if(typeof W==="string"&&y(W))W=S$(W);return W}function P0($,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 l(W.value,X)}function j0($,X){let Y=X$($),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"&&k(U.ref)){K=V$(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=P0(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 S0($,X,Y,Z){let W=l($,Z);switch(X){case"alpha":if(typeof W==="string")return b2(W,Number(Y)/100);break;case"scale":if(typeof W==="string"&&W.match(/[\d.]+/))return V2(W,Number(Y));break;case"hue":if(typeof W==="string")return g2(W,Number(Y));break;default:return console.warn(`Unknown generator type: ${X}`),W}return W}function C2($,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 b2($,X){try{if(!h($))return $;let Y=new F0($);return Y.alpha=X,C(Y)}catch(Y){return console.warn(`Failed to apply alpha to color "${$}": ${Y}`),$}}function V2($,X){let Y=$.match(/([\d.]+)(\w+)/);if(Y){let[,Z,W]=Y;return`${parseFloat(Z)*X}${W}`}return $}function g2($,X){try{if(!h($))return $;let Z=new F0($).to("oklch");return Z.h=(Z.h+X)%360,C(Z)}catch(Y){return console.warn(`Failed to shift hue for color "${$}": ${Y}`),$}}var g$=N(()=>{I0();s()});function T$($){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$($,X={}){let{rootSelector:Y=":root",separateThemeFiles:Z=!1,generateMediaQueries:W=!1,customHeader:q}=X;if(Z)return y2($,X);let U=new Map,K=new Map;U.set("light",[]),U.set("dark",[]);for(let E of $){if(typeof E.value==="string"&&y(E.value))continue;if(T$(E))continue;let L=` ${E.cssVar}: ${S(E.value,E.type)};`;if(W&&E.name.includes("@media")){let w=q$(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}
|
|
13
13
|
|
|
14
14
|
`;let H=U.get("light")||[];if(H.length>0){H.sort(),G+=`${Y} {
|
|
15
15
|
${H.join(`
|
|
16
16
|
`)}
|
|
17
17
|
`;let E=U.get("dark")||[];if(E.length>0){E.sort();let L=X.themeSelector||"[data-theme]",_;if(L.startsWith("."))if(L===".")_=".dark";else _=`${L}-dark`;else if(L.startsWith("[")&&L.endsWith("]"))if(L.includes("="))_=L.replace(/="[^"]*"/,'="dark"');else _=L.replace("]",'="dark"]');else _=`${L}-dark`;G+=`
|
|
18
18
|
&${_} {
|
|
19
|
-
${E.map((
|
|
19
|
+
${E.map((w)=>` ${w}`).join(`
|
|
20
20
|
`)}
|
|
21
21
|
}
|
|
22
22
|
`}G+=`}
|
|
@@ -27,13 +27,13 @@ ${L.map((_)=>` ${_}`).join(`
|
|
|
27
27
|
`)}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
`;let z=[{fileName:"tokens.css",content:G}],A=
|
|
30
|
+
`;let z=[{fileName:"tokens.css",content:G}],A=b0($,X);z.push(...A);let B=g0($,X);return z.push(...B),z}function T2($,X){let Y=[];for(let W of $){let U=` ${W.cssVar||W$(W,X)}: ${S(W.value,W.type)};`;Y.push(U)}let Z="";if(X.customHeader)Z+=`${X.customHeader}
|
|
31
31
|
|
|
32
32
|
`;if(Y.length>0)Y.sort(),Z+=`${X.rootSelector||":root"} {
|
|
33
33
|
${Y.join(`
|
|
34
34
|
`)}
|
|
35
35
|
}
|
|
36
|
-
`;return{fileName:"theme.css",content:Z}}function
|
|
36
|
+
`;return{fileName:"theme.css",content:Z}}function y2($,X){let Y=[],Z=new Map,W=[],q=new Set(["dark","light"]);for(let H of $){if(q$(H))continue;if(typeof H.value==="string"&&y(H.value))continue;if(T$(H))continue;let z=H.name.match(/@(dark|light)$/);if(z){let A=z[1];if(q.has(A)){if(!Z.has(A))Z.set(A,[]);Z.get(A).push(H)}else W.push(H)}else W.push(H)}if(W.length>0){let H=Z$(W,{...X,separateThemeFiles:!1})[0];Y.push({...H,fileName:"tokens.css"})}for(let[H,z]of Z){let A=H==="light"?":root":`[data-theme="${H}"]`,B=T2(z,{...X,separateThemeFiles:!1,rootSelector:A});Y.push({...B,fileName:`tokens.${H}.css`,theme:H})}let U=f2($,X);Y.push(...U);let K=b0($,X);Y.push(...K);let G=g0($,X);return Y.push(...G),Y}function f2($,X){let Y=new Map;for(let q of $){let U=q$(q);if(U){let K=q.name.match(/@(dark|light)$/),G=K?K[1]:"light";if(!Y.has(U))Y.set(U,new Map);let H=Y.get(U);if(!H.has(G))H.set(G,[]);H.get(G).push(q)}}if(Y.size===0)return[];let Z=`/**
|
|
37
37
|
* Design System Tokens - Responsive Breakpoints
|
|
38
38
|
* Generated: ${new Date().toISOString()}
|
|
39
39
|
*
|
|
@@ -48,7 +48,7 @@ ${H.join(`
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
`}}return[{fileName:"tokens.breakpoints.css",content:Z.trim()}]}function
|
|
51
|
+
`}}return[{fileName:"tokens.breakpoints.css",content:Z.trim()}]}function b0($,X){let Y=new Map;for(let W of $)if(typeof W.value==="string"&&y(W.value)){let q=W.name.match(/@(dark|light)$/),U=q?q[1]:"light";if(!Y.has(U))Y.set(U,[]);Y.get(U).push(W)}let Z=[];if(Y.size===0)return[];if(Y.size===1){let[W,q]=Array.from(Y.entries())[0],U=D0(q,W,X);Z.push({fileName:"tokens.icons.css",content:U})}else for(let[W,q]of Y){let U=D0(q,W,X);Z.push({fileName:`tokens.icons.${W}.css`,content:U})}return Z}function D0($,X,Y){let Z=`/**
|
|
52
52
|
* Design System Tokens - Icons (${X})
|
|
53
53
|
* Generated: ${new Date().toISOString()}
|
|
54
54
|
*
|
|
@@ -60,7 +60,7 @@ ${H.join(`
|
|
|
60
60
|
${W.join(`
|
|
61
61
|
`)}
|
|
62
62
|
}
|
|
63
|
-
`}return Z}function W$($,X){let Z=$.name.split("@")[0].replace(/\.$/,"").replace(/\.+/g,"."),W=
|
|
63
|
+
`}return Z}function W$($,X){let Z=$.name.split("@")[0].replace(/\.$/,"").replace(/\.+/g,"."),W=V0(Z,X.hooks);return`--${X.prefix||r}-${W.replace(/\./g,"-")}`}function V0($,X,Y){if(!X?.shortenName?.enabled)return $;let Z=$;if(X.shortenName.prefix)for(let W of X.shortenName.prefix)Z=Z.replace(new RegExp(W.find,"g"),W.replace);if(X.shortenName.suffix){for(let W of X.shortenName.suffix)if(Z.endsWith(W.find))Z=Z.substring(0,Z.length-W.find.length)+W.replace}if(Y&&Y!=="light"){let W=`-${Y}`;if(Z.endsWith(W))Z=Z.slice(0,-W.length)}return Z}function g0($,X){let Y=new Map;for(let W of $)if(T$(W)){if(q$(W))continue;let q="light";if(W.name.includes("@")){if(W.name.endsWith("@dark")||W.name.includes("@dark@")||W.name.includes("@dark_"))q="dark";let U=W.name.split("@");if(U[U.length-1]==="dark")q="dark"}if(!Y.has(q))Y.set(q,[]);Y.get(q).push(W)}let Z=[];for(let[W,q]of Y.entries()){let U=h2(q,W,X);Z.push({fileName:`tokens.typography.${W}.css`,content:U})}return Z}function h2($,X,Y){let Z=`/**
|
|
64
64
|
* Design System Tokens - Typography (${X})
|
|
65
65
|
* Generated: ${new Date().toISOString()}
|
|
66
66
|
*
|
|
@@ -80,14 +80,14 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
80
80
|
}
|
|
81
81
|
`,Z+=`}
|
|
82
82
|
|
|
83
|
-
`}}return Z}function S($,X){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 S(Z.$value,Z.$type||X)}}let Y=String($);switch(X){case"color":return
|
|
83
|
+
`}}return Z}function S($,X){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 S(Z.$value,Z.$type||X)}}let Y=String($);switch(X){case"color":return v2(Y);case"dimension":return p2(Y);case"duration":return m2(Y);case"fontFamily":return d2(Y);case"fontWeight":return u2(Y);case"cubicBezier":return k2($);case"shadow":return c2($);case"border":return l2($);case"typography":return r2($);case"composition":return y$($);default:if(Y.startsWith("data:"))return`"${Y}"`;return Y}}function v2($){if($.startsWith("oklch(")||$.startsWith("rgb(")||$.startsWith("rgba(")||$.startsWith("hsl(")||$.startsWith("hsla(")||$.startsWith("#"))return $;return $}function p2($){if(/^\d+(\.\d+)?(px|rem|em|%|vh|vw|vmin|vmax)$/.test($))return $;if(/^\d+(\.\d+)?$/.test($))return`${$}rem`;return $}function m2($){if(/^\d+(\.\d+)?(s|ms)$/.test($))return $;if(/^\d+(\.\d+)?$/.test($))return`${$}ms`;return $}function d2($){if(($.includes(",")||$.includes(" "))&&!$.startsWith('"')&&!$.startsWith("'"))return`"${$}"`;return $}function u2($){return{thin:"100","extra-light":"200",light:"300",normal:"400",medium:"500","semi-bold":"600",bold:"700","extra-bold":"800",black:"900"}[$]||$}function k2($){if(Array.isArray($)&&$.length===4)return`cubic-bezier(${$.join(", ")})`;return String($)}function c2($){if(Array.isArray($))return $.map((X)=>C0(X)).join(", ");return C0($)}function C0($){if(typeof $==="object"&&$!==null){let X=$,Y=X.color||"transparent";if(typeof Y==="string"&&Y.includes("{")&&Y.includes("}")){console.warn(`Unresolved token reference in shadow color: ${Y}`);let W=Y.match(/\{([^}]+)\}/)?.[1];if(W)Y=`var(${`--${r}-${W.replace(/\./g,"-").replace(/@/g,"-")}`})`}let Z=[X.offsetX||"0",X.offsetY||"0",X.blur||"0",X.spread||"0",Y];if(X.inset)Z.unshift("inset");return Z.join(" ")}return String($)}function l2($){if(typeof $==="object"&&$!==null){let X=$;return`${X.width||"1px"} ${X.style||"solid"} ${X.color||"transparent"}`}return String($)}function r2($){if(typeof $==="object"&&$!==null){let X=$,Y=X.fontWeight||"normal",Z=X.fontSize||"1rem",W=X.lineHeight||"normal",q=X.fontFamily||"sans-serif";if(q.includes(" ")&&!q.startsWith('"')&&!q.startsWith("'"))q=`'${q}'`;let U;if(Z.includes("/"))U=Z;else U=`${Z}/${W}`;return`${Y} ${U} ${q}`}return String($)}function y$($){if(typeof $!=="object"||$===null)return String($);if(Array.isArray($))return $.map((Y)=>y$(Y)).join(", ");let X=$;if(X.offsetX!==void 0&&X.offsetY!==void 0)return T0(X);if(X.width!==void 0&&X.style!==void 0&&X.color!==void 0)return i2(X);if(X.blur!==void 0||X.saturate!==void 0||X.brightness!==void 0)return s2(X);if(X.fontSize!==void 0||X.fontFamily!==void 0)return a2(X);return n2(X)}function T0($){let X=[M($.offsetX)||"0",M($.offsetY)||"0",M($.blur)||"0",M($.spread)||"0",M($.color)||"transparent"];if($.inset&&M($.inset)==="true")X.unshift("inset");return X.join(" ")}function i2($){let X=M($.width)||"1px",Y=M($.style)||"solid",Z=M($.color)||"transparent";return`${X} ${Y} ${Z}`}function s2($){let X=[];if($.blur)X.push(M($.blur)||"blur(0)");if($.saturate)X.push(M($.saturate)||"saturate(100%)");if($.brightness)X.push(M($.brightness)||"brightness(100%)");if($.contrast)X.push(M($.contrast)||"contrast(100%)");if($.hueRotate)X.push(M($.hueRotate)||"hue-rotate(0deg)");return X.join(" ")||"none"}function a2($){let X=M($.fontWeight)||"normal",Y=M($.fontSize)||"1rem",Z=M($.lineHeight),W=M($.fontFamily)||"sans-serif";if(W.includes(" ")&&!W.startsWith('"')&&!W.startsWith("'"))W=`'${W}'`;if(Y.includes("/"))return`${X} ${Y} ${W}`;else return`${X} ${Y}/${Z||"normal"} ${W}`}function M($){if($===null||$===void 0)return"";if(typeof $==="string")return $;if(typeof $==="object"&&$.value!==void 0)return String($.value);return String($)}function n2($){let X=[];for(let[,W]of Object.entries($)){let q=W;if(typeof W==="object"&&W!==null&&q.$value&&typeof q.$value==="object"){let U=q.$value;if(U.offsetX!==void 0&&U.offsetY!==void 0){let K=T0(U);if(K)X.push(K)}else{let K=y$(U);if(K)X.push(K)}}else{let U=M(W);if(U)X.push(U)}}let Z=X.some((W)=>/^\d/.test(W)&&W.includes(" "))?", ":" ";return X.join(Z)||String($)}function q$($){if($.extensions?.mediaQuery&&typeof $.extensions.mediaQuery==="string"){let Y=$.extensions.mediaQuery;if(Y=Y.replace(/\{universe\.foundation\.breakpoint\.screen\.width\.lg\}/g,"64rem"),!Y.startsWith("@media"))Y=`@media ${Y}`;return Y}let X=$.name.match(/@(media[^@]+)/);if(X)return`@${X[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 U$($){let X=$?.$name||"Design System",Y=$?.$version||"1.0.0",Z=new Date().toISOString();return`/**
|
|
84
84
|
* ${X} - CSS Custom Properties
|
|
85
85
|
* Version: ${Y}
|
|
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 o2($){let X=$.replace(/\r?\n|\r/g,"").replace(/\s+/g," ").trim();return`data:image/svg+xml;base64,${Buffer.from(X,"utf8").toString("base64")}`}function f$($,X={}){let{customHeader:Y,objectPath:Z="universe.custom.path.icons"}=X,W="--"+Z.replace(/\./g,"-"),q="";if(Y)q+=Y+`
|
|
91
91
|
|
|
92
92
|
`;else q+=`/**
|
|
93
93
|
* Icon CSS - Base64 Encoded SVG Icons as CSS Custom Properties
|
|
@@ -104,28 +104,28 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
104
104
|
*/
|
|
105
105
|
|
|
106
106
|
`;q+=`:root {
|
|
107
|
-
`;let U=[...$].sort((K,G)=>K.name.localeCompare(G.name));for(let K of U){let G=K.name.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,""),H=`${W}-${K.category}-${G}`;if(X.hooks?.shortenName?.enabled)H=
|
|
107
|
+
`;let U=[...$].sort((K,G)=>K.name.localeCompare(G.name));for(let K of U){let G=K.name.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,""),H=`${W}-${K.category}-${G}`;if(X.hooks?.shortenName?.enabled)H=V0(H,X.hooks);let z=o2(K.value);q+=` ${H}: url("${z}");
|
|
108
108
|
`}return q+=`}
|
|
109
|
-
`,{fileName:"tokens.icons.css",content:q.trim()}}var K$=N(()=>{P()});import{readFileSync as
|
|
109
|
+
`,{fileName:"tokens.icons.css",content:q.trim()}}var K$=N(()=>{P()});import{readFileSync as t2}from"fs";import{join as y0}from"path";async function h$(){try{let{assets:$}=await d(!0),{icons:X}=await $$(),Y=await t(),Z=$?.icons?.distDir??"build",W=y0(Y,Z),q=y0(W,"tokens",await u("json")),U=JSON.parse(t2(q,"utf8")),K=X?.objectPath??"universe.icons",G=K.split("."),H=U;for(let A of G)if(H&&typeof H==="object"&&A in H)H=H[A];else throw Error(`Icon path ${K} not found in icons file`);let z=[];for(let[A,B]of Object.entries(H))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 v$($,X={}){let{generateTypes:Y=!0,generateConsts:Z=!0}=X,W=X.icons;if(!W)W=await h$();let q={...X,icons:W},U=[];if(Y)U.push({fileName:"tokens.types.ts",content:e2($,q),type:"types"});if(Z)U.push({fileName:"tokens.constants.ts",content:$Y($,q),type:"constants"});return U.push({fileName:"index.ts",content:YY(U),type:"index"}),U}function e2($,X){let{tokenInterface:Y="DesignTokens",includeJSDoc:Z=!0,icons:W=[]}=X,q=p$("Type Definitions");if(q+=XY($,Z),q+=ZY($,Z),W.length>0)q+=WY(W,Z);return q+=qY($,Y,Z),q+=KY($,Z),q}function $Y($,X){let{includeJSDoc:Y=!0,icons:Z=[]}=X,W=p$("Token Constants"),q="TokenPaths, CSSVariableNames";if(Z.length>0)q+=", IconNames, IconCategories, Icon";if(W+=`import type { ${q} } from './tokens.types';
|
|
110
110
|
|
|
111
|
-
`,W+=
|
|
111
|
+
`,W+=GY($,Y),W+=zY($,Y),Z.length>0)W+=HY(Z,Y);return W+=AY($,Y),W}function YY($){let X=p$("Main Export");if($.some((Y)=>Y.type==="types"))X+=`export type * from './tokens.types';
|
|
112
112
|
`;if($.some((Y)=>Y.type==="constants"))X+=`export * from './tokens.constants';
|
|
113
113
|
`;return X+=`
|
|
114
|
-
`,X}function
|
|
114
|
+
`,X}function XY($,X){let Y=$.map((W)=>`"${W.name}"`).join(`
|
|
115
115
|
| `),Z="";if(X)Z+=`/**
|
|
116
116
|
* All available token paths as string literals
|
|
117
117
|
*/
|
|
118
118
|
`;return Z+=`export type TokenPaths =
|
|
119
119
|
| ${Y};
|
|
120
120
|
|
|
121
|
-
`,Z}function
|
|
121
|
+
`,Z}function ZY($,X){let Y=BY($),Z="";for(let[W,q]of Y){let U=`${EY(W)}TokenValue`,K=new Set(q.map((H)=>i(H.value))),G=Array.from(K).join(`
|
|
122
122
|
| `);if(X)Z+=`/**
|
|
123
123
|
* Possible values for ${W} tokens
|
|
124
124
|
*/
|
|
125
125
|
`;Z+=`export type ${U} =
|
|
126
126
|
| ${G};
|
|
127
127
|
|
|
128
|
-
`}return Z}function
|
|
128
|
+
`}return Z}function WY($,X){let Y="",Z=$.map((U)=>`"${U.name}"`).join(`
|
|
129
129
|
| `);if(X)Y+=`/**
|
|
130
130
|
* All available icon names as string literals
|
|
131
131
|
*/
|
|
@@ -160,7 +160,7 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
160
160
|
`,Y+=` };
|
|
161
161
|
`,Y+=`}
|
|
162
162
|
|
|
163
|
-
`,Y}function
|
|
163
|
+
`,Y}function qY($,X,Y){let Z="";if(Y)Z+=`/**
|
|
164
164
|
* Design tokens interface with all token paths and their values
|
|
165
165
|
*/
|
|
166
166
|
`;Z+=`export interface ${X} {
|
|
@@ -168,20 +168,20 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
168
168
|
`;Z+=` "${W.name}": ${i(W.value)};
|
|
169
169
|
`}return Z+=`}
|
|
170
170
|
|
|
171
|
-
`,Z+=
|
|
171
|
+
`,Z+=UY($,`${X}Nested`,Y),Z}function UY($,X,Y){let Z=LY($),W="";if(Y)W+=`/**
|
|
172
172
|
* Design tokens interface with nested structure
|
|
173
173
|
*/
|
|
174
174
|
`;return W+=`export interface ${X} {
|
|
175
|
-
`,W+=
|
|
175
|
+
`,W+=f0(Z,1),W+=`}
|
|
176
176
|
|
|
177
|
-
`,W}function
|
|
177
|
+
`,W}function KY($,X){let Y=$.map((W)=>`"${W.cssVar}"`).join(`
|
|
178
178
|
| `),Z="";if(X)Z+=`/**
|
|
179
179
|
* All available CSS variable names
|
|
180
180
|
*/
|
|
181
181
|
`;return Z+=`export type CSSVariableNames =
|
|
182
182
|
| ${Y};
|
|
183
183
|
|
|
184
|
-
`,Z}function
|
|
184
|
+
`,Z}function GY($,X){let Y="";if(X)Y+=`/**
|
|
185
185
|
* Object containing all token values
|
|
186
186
|
*/
|
|
187
187
|
`;Y+=`export const tokenValues = {
|
|
@@ -189,7 +189,7 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
189
189
|
`;Y+=` "${Z.name}": ${JSON.stringify(Z.value)},
|
|
190
190
|
`}return Y+=`} as const;
|
|
191
191
|
|
|
192
|
-
`,Y}function
|
|
192
|
+
`,Y}function HY($,X){let Y="";if(X)Y+=`/**
|
|
193
193
|
* Array of all available icons
|
|
194
194
|
*/
|
|
195
195
|
`;Y+=`export const icons: Icon[] = [
|
|
@@ -231,14 +231,14 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
231
231
|
`,Y+=` return icons.filter(icon => icon.category === category);
|
|
232
232
|
`,Y+=`}
|
|
233
233
|
|
|
234
|
-
`,Y}function
|
|
234
|
+
`,Y}function zY($,X){let Y="";if(X)Y+=`/**
|
|
235
235
|
* Object mapping token paths to CSS variable names
|
|
236
236
|
*/
|
|
237
237
|
`;Y+=`export const cssVariableNames = {
|
|
238
238
|
`;for(let Z of $)Y+=` "${Z.name}": "${Z.cssVar}",
|
|
239
239
|
`;return Y+=`} as const;
|
|
240
240
|
|
|
241
|
-
`,Y}function
|
|
241
|
+
`,Y}function AY($,X){let Y="";if(X)Y+=`/**
|
|
242
242
|
* Get the value of a design token
|
|
243
243
|
*/
|
|
244
244
|
`;if(Y+=`export function getTokenValue<T extends TokenPaths>(tokenPath: T): typeof tokenValues[T] {
|
|
@@ -266,10 +266,10 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
266
266
|
return tokenPath in tokenValues;
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
`,Y}function
|
|
270
|
-
`,Y+=
|
|
269
|
+
`,Y}function BY($){let X=new Map;for(let Y of $){if(!X.has(Y.type))X.set(Y.type,[]);X.get(Y.type).push(Y)}return X}function LY($){let X={};for(let Y of $){if(Y.path.some((G)=>G.includes("@")||G.includes("-")||G.includes(".")))continue;let W=X,q=[...Y.path];for(let G=0;G<q.length-1;G++){let H=q[G];if(!W[H])W[H]={};W=W[H]}let U=q[q.length-1],K=i(Y.value);W[U]=K}return X}function f0($,X){let Y="",Z=" ".repeat(X);for(let[W,q]of Object.entries($)){let U=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(W)?W:`"${W}"`;if(typeof q==="object"&&!Array.isArray(q))Y+=`${Z}${U}: {
|
|
270
|
+
`,Y+=f0(q,X+1),Y+=`${Z}};
|
|
271
271
|
`;else Y+=`${Z}${U}: ${q};
|
|
272
|
-
`}return Y}function i($){if(typeof $==="string")return`"${$}"`;else if(typeof $==="number")return $.toString();else if(typeof $==="boolean")return $.toString();else if(Array.isArray($)){let X=new Set($.map((Z)=>i(Z)));return`Array<${Array.from(X).join(" | ")}>`}else if($===null)return"null";else if($===void 0)return"undefined";else if(typeof $==="object"&&$!==null)return`{ ${Object.entries($).map(([Z,W])=>`${Z}: ${i(W)}`).join("; ")} }`;else return"unknown"}function
|
|
272
|
+
`}return Y}function i($){if(typeof $==="string")return`"${$}"`;else if(typeof $==="number")return $.toString();else if(typeof $==="boolean")return $.toString();else if(Array.isArray($)){let X=new Set($.map((Z)=>i(Z)));return`Array<${Array.from(X).join(" | ")}>`}else if($===null)return"null";else if($===void 0)return"undefined";else if(typeof $==="object"&&$!==null)return`{ ${Object.entries($).map(([Z,W])=>`${Z}: ${i(W)}`).join("; ")} }`;else return"unknown"}function EY($){if(!$||typeof $!=="string")return"";return $.charAt(0).toUpperCase()+$.slice(1)}function p$($){let X=new Date().toISOString();return`/**
|
|
273
273
|
* ${$}
|
|
274
274
|
* Generated: ${X}
|
|
275
275
|
*
|
|
@@ -277,7 +277,7 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
277
277
|
* Do not edit this file directly - it will be overwritten.
|
|
278
278
|
*/
|
|
279
279
|
|
|
280
|
-
`}var m$=N(()=>{P()});var r="did";var P=N(()=>{s();H$();L$();s();Y$();
|
|
280
|
+
`}var m$=N(()=>{P()});var r="did";var P=N(()=>{s();H$();L$();s();Y$();U0();K0();A0();H$();L$();j$();g$();K$();m$();u$()});import{readFileSync as OY,mkdirSync as QY}from"fs";import{writeFile as v0,readdir as IY,mkdir as JY}from"fs/promises";import{resolve as RY,relative as p0,join as k$,dirname as MY}from"path";import NY from"lodash";async function m0($){let X=await IY($,{withFileTypes:!0}),Y=await Promise.all(X.map((Z)=>{let W=RY($,Z.name);return Z.isDirectory()?m0(W):W}));return Array.prototype.concat(...Y)}async function l$(){let{assets:$,icons:X,tokenNamespace:Y,__dirname:Z,buildDir:W}=await T(),q=k$(Z,$?.icons?.sourceDir??"icons"),U="build",K=$?.icons?.distDir??"build",G=k$(Z,K),H=k$(Z,W,"icons");if(!$?.icons?.sourceDir){console.error("Skipping icon build: iconsDir is not defined in the project paths.");return}let z=(await m0(q)).filter((O)=>O.endsWith(".svg")),E=(await Promise.all(z.map(async(O)=>{let Q=OY(O,"utf8").replace(/(\s+(?=(?:[^"]*"[^"]*")*[^"]*$))/g," ").trim()??"";Q=await x$(Q);let I=p0(q,O).split("/").pop(),F=(Q.match(/name="(.*?)"/)??[])[1]??I?.replace(".svg",""),g=(Q.match(/data-style="(.*?)"/)??[])[1],n0=(Q.match(/description="(.*?)"/)??[])[1],[o$]=Q.match(/<svg[^>]*>/)??[],[,o0]=o$?.match(/width="([\d.]+)(px)?"/)??[],[,t0]=o$?.match(/height="([\d.]+)(px)?"/)??[];if(g!=="animated"&&g!=="custom")return{path:O,folder:p0(q,O).split("/").slice(0,-1).concat(F),file:I,style:g,content:Q,name:F,dimensions:{width:Number(o0),height:Number(t0)},description:n0??""};return}))).filter((O)=>O!==void 0).reduce((O,Q)=>{if(Q?.style!=="animated"&&Q?.style!=="custom"&&Q)c$(O,Q.folder.join("."),{$type:"icon",$name:Q.name,$description:Q.description,$style:Q.style,$value:Q.content,$dimensions:Q.dimensions,...FY(O,Q.folder.join("."))});return O},{}),L=X?.objectPath??`${Y}.icons`;Object.keys(E).forEach(async(O)=>{let Q=`${H}/${O}`,I=`${Q}/svg.${O}.tokens.json`;await JY(Q,{recursive:!0});let F=c$({},`${L}${L?".":""}${O}`,E[O]);await v0(I,JSON.stringify(F,null,2),{flag:"w",encoding:"utf-8"})});let _=`${G}/tokens/${await u("json")}`,w=MY(_);QY(w,{recursive:!0});let J=c$({},L,E);await v0(_,JSON.stringify(J,null,2),{flag:"w",encoding:"utf-8"})}var c$,FY,V4;var d0=N(()=>{P();({set:c$,get:FY}=NY);V4=l$().catch(($)=>{console.error($),process.exit(1)})});function c0($,X={}){let Y=[],Z=X.typescript?"ts":"js",W=$.filter((U)=>U.extensions?.mediaQuery||U.name.includes("@screen")||U.name.includes("@_")),q=$.filter((U)=>!U.extensions?.mediaQuery&&!U.name.includes("@screen")&&!U.name.includes("@_"));if(X.separateThemeFiles){let U=q.filter((G)=>!G.name.includes("@dark")),K=q.filter((G)=>G.name.includes("@dark"));if(X.typescript){if(U.length>0){let G=i$(U,"light");Y.push({fileName:"light.d.ts",content:k0(G,X,"light")})}if(K.length>0){let G=i$(K,"dark");Y.push({fileName:"dark.d.ts",content:k0(G,X,"dark")})}}if(U.length>0)Y.push({fileName:`light.${Z}`,content:r$(U,{...X,theme:"light"}),theme:"light"});if(K.length>0)Y.push({fileName:`dark.${Z}`,content:r$(K,{...X,theme:"dark"}),theme:"dark"})}else Y.push({fileName:`tokens.${Z}`,content:r$(q,X)});if(W.length>0)Y.push({fileName:`breakpoints.${Z}`,content:xY(W,$,X)});if(X.separateThemeFiles&&Y.length>1)Y.push({fileName:`index.${Z}`,content:bY(Y,X)});return Y}function xY($,X,Y={}){let{typescript:Z,includeJSDoc:W,moduleType:q="es",customHeader:U}=Y,K=new Map(X.map((A)=>[A.name,A])),G={};for(let A of $){let B=A.extensions?.mediaQuery||PY(A.name),E=A.name.includes("@dark")?"dark":"light";if(typeof B==="string"&&B.includes("{")&&B.includes("}"))B=SY(B,K);if(!G[B])G[B]={};if(!G[B][E])G[B][E]={};let L=jY(A.name),_=DY(L,G$(A.value,K));G[B][E]={...G[B][E],..._}}let H=Object.keys(G).sort((A,B)=>{let E=u0(A),L=u0(B);return E-L}).reduce((A,B)=>{return A[B]=G[B],A},{}),z="";if(U)z+=`${U}
|
|
281
281
|
|
|
282
282
|
`;else z+=`/**
|
|
283
283
|
`,z+=` * Design Tokens - Breakpoints
|
|
@@ -285,7 +285,7 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
285
285
|
`,z+=` * Do not edit this file directly
|
|
286
286
|
`,z+=` */
|
|
287
287
|
|
|
288
|
-
`;if(Z)z+=
|
|
288
|
+
`;if(Z)z+=l0(H,W),z+=`
|
|
289
289
|
`;if(q==="es"){if(Z)z+=`const breakpoints: Tokens = ${f(H,W,0)};
|
|
290
290
|
|
|
291
291
|
`;else z+=`const breakpoints = ${f(H,W,0)};
|
|
@@ -295,7 +295,7 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
295
295
|
|
|
296
296
|
`,z+=`module.exports = breakpoints;
|
|
297
297
|
`,z+=`module.exports.default = breakpoints;
|
|
298
|
-
`;return z}function
|
|
298
|
+
`;return z}function PY($){if($.includes("@_max_width_")){let X=$.match(/@_max_width___(.+?)__/);if(X)return`screen and (max-width: {${X[1].replace(/_/g,".")}})`}if($.includes("@_min_width_")){let X=$.match(/@_min_width___(.+?)__/);if(X)return`screen and (min-width: {${X[1].replace(/_/g,".")}})`}return"screen"}function jY($){let X=$.replace(/@_.*?__/,"").replace(/@screen.*/,"").replace(/@dark/,"").replace(/^universe\./,"");return X=X.replace(/_universe_foundation_breakpoint_screen_width_[^_]+__?$/,""),X}function u0($){let X=$.match(/(\d+(?:\.\d+)?)/);return X?parseFloat(X[1]):0}function SY($,X){return $.replace(/\{([^}]+)\}/g,(Y,Z)=>{let W=X.get(Z);if(W){let q=W.value;if(typeof q==="object"&&q!==null&&"$value"in q)q=q.$value;return String(q)}return Y})}function DY($,X){let Y=$.split("."),Z={},W=Z;for(let q=0;q<Y.length-1;q++)W[Y[q]]={},W=W[Y[q]];return W[Y[Y.length-1]]=X,Z}function r$($,X={}){let{typescript:Y,includeJSDoc:Z,moduleType:W="es",customHeader:q,theme:U}=X,K="";if(q)K+=`${q}
|
|
299
299
|
|
|
300
300
|
`;else K+=`/**
|
|
301
301
|
`,K+=` * Design Tokens - ${U?`${U.charAt(0).toUpperCase()+U.slice(1)} Theme`:"All Tokens"}
|
|
@@ -303,7 +303,9 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
303
303
|
`,K+=` * Do not edit this file directly
|
|
304
304
|
`,K+=` */
|
|
305
305
|
|
|
306
|
-
`;let G=
|
|
306
|
+
`;let G=i$($,U);if(Y)if(X.separateThemeFiles&&U)K+=`import type { Tokens } from "./${U}.d";
|
|
307
|
+
|
|
308
|
+
`;else K+=l0(G,Z),K+=`
|
|
307
309
|
`;if(W==="es"){if(Y)K+=`const tokens: Tokens = ${f(G,Z,0)};
|
|
308
310
|
|
|
309
311
|
`;else K+=`const tokens = ${f(G,Z,0)};
|
|
@@ -316,16 +318,28 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
316
318
|
|
|
317
319
|
`,K+=`module.exports = tokens;
|
|
318
320
|
`,K+=`module.exports.default = tokens;
|
|
319
|
-
`;return K}function
|
|
321
|
+
`;return K}function i$($,X){let Y={},Z=new Map($.map((W)=>[W.name,W]));for(let W of $){let q=W.name;if(X){if(q.includes(`@${X}`))q=q.replace(`@${X}`,"")}else q=q.replace(/@(?:light|dark)$/,"");let U=q.split("."),K=Y;for(let H=0;H<U.length-1;H++){let z=U[H];if(!K[z])K[z]={};K=K[z]}let G=U[U.length-1];K[G]=G$(W.value,Z)}return Y}function G$($,X){if(typeof $==="object"&&$!==null&&!Array.isArray($)){let Y=$;if(Y.color&&typeof Y.color==="string"&&Y.color.includes("{")&&Y.color.includes("}")){let Z=S($,"shadow");if(typeof Z==="string"&&!Z.includes("{")){let W={...Y},q=Z.split(" "),U=q[q.length-1];if(U&&U.startsWith("#"))W.color=U;else W.color=S(Y.color,"color");return W}}}if(typeof $==="string"){if($.startsWith("{")&&$.endsWith("}")){let Y=$.slice(1,-1),Z=X.get(Y);if(Z)return Z.value;let W=S($,"color");if(W!==$)return W}return $}if(Array.isArray($))return $.map((Y)=>G$(Y,X));if(typeof $==="object"&&$!==null){let Y={};for(let[Z,W]of Object.entries($))Y[Z]=G$(W,X);return Y}return $}function l0($,X){let Y="";if(X)Y+=`/**
|
|
322
|
+
* Token object type definition
|
|
323
|
+
*/
|
|
324
|
+
`;return Y+=`type Tokens = ${s$($,0)};
|
|
325
|
+
`,Y}function k0($,X,Y){let{customHeader:Z,includeJSDoc:W}=X,q="";if(Z)q+=`${Z}
|
|
326
|
+
|
|
327
|
+
`;else{let U=Y?` - ${Y.charAt(0).toUpperCase()+Y.slice(1)} Theme`:"";q+=`/**
|
|
328
|
+
`,q+=` * Universe Design System Tokens - Type Definitions${U}
|
|
329
|
+
`,q+=` * Auto-generated from design token definitions
|
|
330
|
+
`,q+=` * Do not edit this file directly
|
|
331
|
+
`,q+=` */
|
|
332
|
+
|
|
333
|
+
`}if(W)q+=`/**
|
|
320
334
|
* Token object type definition
|
|
321
335
|
*/
|
|
322
|
-
`;return
|
|
323
|
-
`,
|
|
324
|
-
`;for(let[q,U]of Z){let K=
|
|
325
|
-
`}return W+=" ".repeat(X)+"}",W}function
|
|
336
|
+
`;return q+=`export type Tokens = ${s$($,0)};
|
|
337
|
+
`,q}function s$($,X){if(typeof $!=="object"||$===null)return typeof $==="string"?"string":typeof $==="number"?"number":typeof $==="boolean"?"boolean":"any";let Y=" ".repeat(X+1),Z=Object.entries($);if(Z.length===0)return"{}";let W=`{
|
|
338
|
+
`;for(let[q,U]of Z){let K=CY(q)?`"${q}"`:q;W+=`${Y}${K}: ${s$(U,X+1)};
|
|
339
|
+
`}return W+=" ".repeat(X)+"}",W}function CY($){return $.startsWith("@")||$.includes(" ")||$.includes("-")||$.includes("(")||$.includes(")")||$.includes("@")||$.includes(":")||!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test($)}function f($,X,Y=0){if(typeof $!=="object"||$===null)return JSON.stringify($);let Z=" ".repeat(Y),W=" ".repeat(Y+1),q=Object.entries($);if(q.length===0)return"{}";let U=`{
|
|
326
340
|
`;for(let K=0;K<q.length;K++){let[G,H]=q[K],z=K===q.length-1;if(X&&typeof H==="string")U+=`${W}/** Token value: ${JSON.stringify(H)} */
|
|
327
341
|
`;let A=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(G)?G:JSON.stringify(G),B=f(H,X,Y+1);U+=`${W}${A}: ${B}${z?"":","}
|
|
328
|
-
`}return U+=`${Z}}`,U}function
|
|
342
|
+
`}return U+=`${Z}}`,U}function bY($,X){let Y=X.typescript?"ts":"js",{moduleType:Z="es",customHeader:W}=X,q="";if(W)q+=`${W}
|
|
329
343
|
|
|
330
344
|
`;else q+=`/**
|
|
331
345
|
`,q+=` * Design Tokens - Index
|
|
@@ -340,7 +354,7 @@ ${K.sort().map((z)=>` ${z}`).join(`
|
|
|
340
354
|
`}q+=`
|
|
341
355
|
// Default export points to light theme
|
|
342
356
|
`,q+=`module.exports = require('./light');
|
|
343
|
-
`}return q}var
|
|
357
|
+
`}return q}var r0=N(()=>{K$()});var i0={};$2(i0,{validateCSSFiles:()=>VY,printValidationResults:()=>gY});import{readFileSync as a$,existsSync as p}from"fs";import{join as D}from"path";function VY($,X){let Y={isValid:!0,errors:[],warnings:[],checks:[]},Z=D($,"css"),W=D(Z,"tokens.css"),q=p(W);if(Y.checks.push({name:"CSS file exists: tokens.css",passed:q,message:q?void 0:"Missing required CSS file: tokens.css"}),!q)Y.errors.push("Missing required CSS file: tokens.css"),Y.isValid=!1;if(X.$metaData?.tokens?.css?.mediaQuery?.separateThemeFiles??!1){let A=D(Z,"tokens.dark.css"),B=p(A);if(Y.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)Y.errors.push("Missing required CSS file: tokens.dark.css (separateThemeFiles is enabled)"),Y.isValid=!1}let K=D(Z,"tokens.breakpoints.css");if(p(K))Y.checks.push({name:"CSS file exists: tokens.breakpoints.css",passed:!0,message:void 0});let H=X.$metaData?.tokens?.css?.hooks?.shortenName;if(H?.enabled&&p(D(Z,"tokens.css"))){let A=a$(D(Z,"tokens.css"),"utf8");if(H.prefix)for(let{find:B,replace:E}of H.prefix){let L=`--${r}-${B}`,_=`--${E}`,w=A.includes(L),J=A.includes(_);if(Y.checks.push({name:`Prefix hook applied: ${B} → ${E}`,passed:!w&&J,message:w?`Old prefix "${L}" still found in CSS, should be "${_}"`:void 0}),w)Y.errors.push(`Prefix transformation failed: "${L}" should be replaced with "${_}"`),Y.isValid=!1}if(H.suffix)for(let{find:B,replace:E}of H.suffix){let _=new RegExp(`--[^:]+${B.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}:`,"g").test(A);if(Y.checks.push({name:`Suffix hook applied: ${B} → ${E}`,passed:!_,message:_?`Old suffix "${B}" still found in CSS variable names`:void 0}),_)Y.errors.push(`Suffix transformation failed: "${B}" should be removed/replaced with "${E}"`),Y.isValid=!1}}if(p(D(Z,"tokens.css"))){let B=a$(D(Z,"tokens.css"),"utf8").match(/:\s*{[^}]+}/g);if(Y.checks.push({name:"No unresolved token references",passed:!B,message:B?`Found unresolved references: ${B.join(", ")}`:void 0}),B)Y.errors.push(`Unresolved token references found: ${B.join(", ")}`),Y.isValid=!1}let z=["tokens.css","tokens.dark.css","tokens.breakpoints.css"];for(let A of z){let B=D(Z,A);if(p(B)){let E=a$(B,"utf8"),L=(E.match(/\{/g)||[]).length-(E.match(/\}/g)||[]).length;if(Y.checks.push({name:`CSS syntax valid: ${A}`,passed:L===0,message:L!==0?`Mismatched braces in ${A}`:void 0}),L!==0)Y.errors.push(`CSS syntax error in ${A}: mismatched braces`),Y.isValid=!1}}return Y}function gY($){console.log(`
|
|
344
358
|
|
|
345
359
|
Build Validation Results:`),console.log("========================================================");for(let X of $.checks){let Y=X.passed?"✓":"✗";if(console.log(` ${Y} ${X.name}`),X.message)console.log(` ${X.message}`)}if($.warnings.length>0){console.log(`
|
|
346
360
|
⚠️ Warnings:`);for(let X of $.warnings)console.log(` ${X}`)}if($.errors.length>0){console.log(`
|
|
@@ -348,7 +362,7 @@ Build Validation Results:`),console.log("=======================================
|
|
|
348
362
|
Validation Summary:`),console.log(` - Checks: ${$.checks.filter((X)=>X.passed).length}/${$.checks.length} passed`),console.log(` - Errors: ${$.errors.length}`),console.log(` - Warnings: ${$.warnings.length}`),console.log(`
|
|
349
363
|
${$.isValid?"✅":"❌"} Build ${$.isValid?"passed":"failed"}`),console.log(`
|
|
350
364
|
========================================================
|
|
351
|
-
`)}var
|
|
365
|
+
`)}var s0=N(()=>{P()});import{writeFileSync as TY,mkdirSync as yY,existsSync as fY}from"fs";import{join as V,dirname as n$}from"path";function hY($,X,Y=!1,Z=!1){let W=[],q=[],U=[];for(let G of $)if(G.fileName.includes("breakpoint"))q.push(`@import url("./css/${G.fileName}");`);else U.push(`@import url("./css/${G.fileName}");`);if(W.push(...U),Y)W.push('@import url("./css/tokens.icons.css");');if(Z)W.push('@import url("./css/fonts.css");');W.push(...q);let K=`/**
|
|
352
366
|
* ${X} Design System - Main CSS Entry Point
|
|
353
367
|
* Generated: ${new Date().toISOString()}
|
|
354
368
|
*
|
|
@@ -360,18 +374,18 @@ ${$.isValid?"✅":"❌"} Build ${$.isValid?"passed":"failed"}`),console.log(`
|
|
|
360
374
|
|
|
361
375
|
${W.join(`
|
|
362
376
|
`)}
|
|
363
|
-
`;return{fileName:`${X}.design-system.tokens.css`,content:K,theme:void 0}}async function
|
|
364
|
-
Starting token build process...`,$.verbose),R("Loading token files...",$.verbose);let Z=D$($.tokensDir);R("Parsing tokens...",$.verbose);let W=
|
|
365
|
-
Generating CSS files...`,$.verbose);let G=
|
|
366
|
-
Generated icon tokens`,$.verbose)}catch(G){if($.verbose)console.warn("Could not build icon tokens:",G)}if($.generateCSS!==!1)try{let G=await h$();if(G.length>0){let H=
|
|
367
|
-
Generating TypeScript files...`,$.verbose);let G=
|
|
368
|
-
Generating JavaScript files...`,$.verbose);let G=
|
|
369
|
-
Generating JSON files...`,$.verbose);let G=
|
|
377
|
+
`;return{fileName:`${X}.design-system.tokens.css`,content:K,theme:void 0}}async function h0($){let X=Date.now(),Y={tokenCount:0,cssFiles:[],typescriptFiles:[],javascriptFiles:[],jsonFiles:[],duration:0,warnings:[],errors:[]};try{R(`
|
|
378
|
+
Starting token build process...`,$.verbose),R("Loading token files...",$.verbose);let Z=D$($.tokensDir);R("Parsing tokens...",$.verbose);let W=vY($.config),q=C$(Z,W);R(`Found ${q.length} tokens`,$.verbose),Y.tokenCount=q.length;let U=b$(q,W);if(R(`Resolved ${U.length} tokens`,$.verbose),$.generateCSS!==!1){R(`
|
|
379
|
+
Generating CSS files...`,$.verbose);let G=a0($.config,$.cssOptions),H=Z$(U,G);for(let z of H){let A=V($.outputDir,"css",z.fileName);m(A,z.content),R(` ✓ ${z.fileName}`,$.verbose)}Y.cssFiles=H}if($.generateCSS!==!1)try{await l$(),R(`
|
|
380
|
+
Generated icon tokens`,$.verbose)}catch(G){if($.verbose)console.warn("Could not build icon tokens:",G)}if($.generateCSS!==!1)try{let G=await h$();if(G.length>0){let H=a0($.config,$.cssOptions),z=f$(G,{customHeader:U$($.config),objectPath:$.config.$metaData?.icons?.objectPath||"universe.custom.path.icons",hooks:H.hooks}),A=V($.outputDir,"css",z.fileName);if(m(A,z.content),R(` ✓ Generated ${z.fileName}`,$.verbose),Y.cssFiles)Y.cssFiles.push(z);else Y.cssFiles=[z]}}catch(G){if($.verbose)console.warn("Could not generate icon CSS:",G)}let K=!1;if($.generateCSS!==!1)try{let G=$.config.$fonts;if(G&&G.length>0){await P$(G,$.outputDir),R(" ✓ Generated fonts.css",$.verbose),K=!0;let H={fileName:"fonts.css",content:"Generated by appendTypographyTokens",theme:void 0};if(Y.cssFiles)Y.cssFiles.push(H);else Y.cssFiles=[H]}}catch(G){if($.verbose)console.warn("Could not generate font CSS:",G)}if($.generateCSS!==!1&&Y.cssFiles.length>0){let G=$.config.$metaData?.tokenNamespace||"tokens",H=Y.cssFiles.some((B)=>B.fileName==="tokens.icons.css"),z=hY(Y.cssFiles.filter((B)=>B.fileName!=="tokens.icons.css"&&B.fileName!=="fonts.css"),G,H,K),A=V($.outputDir,z.fileName);m(A,z.content),R(` ✓ Generated ${z.fileName}`,$.verbose),Y.cssFiles.push(z)}if($.generateTypeScript!==!1){R(`
|
|
381
|
+
Generating TypeScript files...`,$.verbose);let G=pY($.config,$.typescriptOptions),H=await v$(U,G);for(let z of H){let A=V($.outputDir,"typescript",z.fileName);m(A,z.content),R(` ✓ Generated ${z.fileName}`,$.verbose)}Y.typescriptFiles=H}if($.generateJavaScript!==!1){R(`
|
|
382
|
+
Generating JavaScript files...`,$.verbose);let G=mY($.config,$.javascriptOptions),H=c0(U,G);for(let z of H){let A=V($.outputDir,"js",z.fileName);m(A,z.content),R(` ✓ Generated ${z.fileName}`,$.verbose)}Y.javascriptFiles=H}if($.generateJSON!==!1){R(`
|
|
383
|
+
Generating JSON files...`,$.verbose);let G=dY(U,q,$.config);for(let H of G){let z=V($.outputDir,"json",H.fileName);m(z,H.content),R(` ✓ Generated ${H.fileName}`,$.verbose)}Y.jsonFiles=G}Y.duration=Date.now()-X,R(`
|
|
370
384
|
Build completed in ${Y.duration}ms`,$.verbose)}catch(Z){let W=Z instanceof Error?Z.message:String(Z);Y.errors.push(W),R(`❌ Build failed: ${W}`,$.verbose)}if($.validate!==!1){R(`
|
|
371
|
-
Validating build output...`,$.verbose);let{validateCSSFiles:Z,printValidationResults:W}=await Promise.resolve().then(() => (
|
|
385
|
+
Validating build output...`,$.verbose);let{validateCSSFiles:Z,printValidationResults:W}=await Promise.resolve().then(() => (s0(),i0)),q=Z($.outputDir,$.config);if($.verbose||!q.isValid)W(q);if(!q.isValid)Y.errors.push(...q.errors)}return Y}function vY($){let X=$.$metaData;return{prefix:X.dsNamespace||X.tokenNamespace,namespace:X.tokenNamespace,generateModes:!0,generateDerivedTokens:!0,generateBreakpointTokens:!0,failOnBrokenReferences:!0,transformName:(Y)=>{let Z=X.tokens?.css?.hooks?.shortenName;if(Z?.enabled){let W=Y;if(Z.prefix)for(let{find:q,replace:U}of Z.prefix){let K=q.replace(/\./g,"-").replace(/-$/,""),G=U.replace(/\./g,"-").replace(/-$/,"");W=W.replace(K,G)}if(Z.suffix){for(let{find:q,replace:U}of Z.suffix)if(W.endsWith(q))W=W.substring(0,W.length-q.length)+U}return W}return Y}}}function a0($,X){let Z=$.$metaData.tokens?.css;return{...X,separateThemeFiles:Z?.mediaQuery?.separateThemeFiles??!1,rootSelector:":root",generateMediaQueries:!0,customHeader:U$($),themeSelector:Z?.mediaQuery?.match||"[data-theme]",hooks:Z?.hooks}}function pY($,X){let Y=$.$metaData;return{...X,tokenInterface:"DesignTokens",exportNamespace:Y.dsNamespace||Y.tokenNamespace,generateTypes:!0,generateConsts:!0,generateCSSVarMappings:!0,includeJSDoc:!0}}function mY($,X){return{...X,typescript:!0,separateThemeFiles:!0,includeJSDoc:!1,moduleType:"es",customHeader:`/**
|
|
372
386
|
* ${$.$name}
|
|
373
387
|
* Generated: ${new Date().toISOString()}
|
|
374
|
-
*/`}}function
|
|
388
|
+
*/`}}function dY($,X,Y){let Z=[],W=JSON.stringify({$schema:"https://schemas.designtokens.org/design-tokens.schema.json",$name:Y.$name,$version:Y.$version,tokens:X.reduce((K,G)=>{return K[G.name]={$type:G.type,$value:G.value,$description:G.description,$extensions:G.extensions},K},{})},null,2);Z.push({fileName:"tokens.raw.json",content:W});let q=JSON.stringify({$name:Y.$name,$version:Y.$version,tokens:$.reduce((K,G)=>{return K[G.name]={$type:G.type,$value:G.value,$description:G.description,cssVar:G.cssVar},K},{})},null,2);Z.push({fileName:"tokens.resolved.json",content:q});let U=JSON.stringify({$name:`${Y.$name} - CSS Variables`,$version:Y.$version,variables:$.reduce((K,G)=>{return K[G.cssVar]=G.value,K},{})},null,2);return Z.push({fileName:"css-variables.json",content:U}),Z}function m($,X){let Y=n$($);if(!fY(Y))yY(Y,{recursive:!0});TY($,X,"utf-8")}function R($,X){if(X!==!1)console.log($)}async function d$($,X){let Z=(await import($)).default,W=V(n$($),Z.$paths.baseDir,Z.$paths.tokensDir),q=X||V(n$($),Z.$paths.baseDir,Z.$paths.distDir);return h0({config:Z,tokensDir:W,outputDir:q,verbose:!0})}var u$=N(()=>{d0();K$();r0();g$();m$();j$()});u$();import{existsSync as uY}from"fs";import{resolve as kY}from"path";function cY($){let X={};for(let Y=0;Y<$.length;Y++){let Z=$[Y];switch(Z){case"--config":case"-c":X.config=$[++Y];break;case"--input":case"-i":X.input=$[++Y];break;case"--output":case"-o":X.output=$[++Y];break;case"--verbose":case"-v":X.verbose=!0;break;case"--no-css":X.css=!1;break;case"--no-typescript":X.typescript=!1;break;case"--no-json":X.json=!1;break;case"--help":case"-h":X.help=!0;break;default:if(Z.startsWith("-"))console.warn(`Unknown option: ${Z}`);break}}return X}function lY(){console.log(`
|
|
375
389
|
Design Tokens Builder - W3C compliant token processor
|
|
376
390
|
|
|
377
391
|
Usage: build-tokens [options]
|
|
@@ -405,11 +419,11 @@ Token Files:
|
|
|
405
419
|
- Include $type and $value properties
|
|
406
420
|
- Support token references with {token.path} syntax
|
|
407
421
|
- Support extensions for modes, generators, and breakpoints
|
|
408
|
-
`)}function
|
|
422
|
+
`)}function rY($){let X=[$,"./designid.config.ts","./designid.config.js","./tokens.config.ts","./tokens.config.js"].filter(Boolean);for(let Y of X){let Z=kY(Y);if(uY(Z))return Z}throw Error(`Config file not found. Tried: ${X.join(", ")}`)}async function iY(){let $=cY(process.argv.slice(2));if($.help){lY();return}try{let X=rY($.config);console.log(`Using config: ${X}`);let Y=await d$(X,$.output);if(Y.errors.length>0)console.log(`
|
|
409
423
|
❌ Build failed with ${Y.errors.length} error${Y.errors.length>1?"s":""}:`),Y.errors.forEach((Z)=>console.log(` - ${Z}`)),process.exit(1);if(console.log(`Processed ${Y.tokenCount} tokens`),console.log(`Duration: ${Y.duration}ms`),console.log(`Build completed successfully!
|
|
410
424
|
`),Y.cssFiles.length>0)console.log(`
|
|
411
425
|
Generated ${Y.cssFiles.length} CSS files:`),Y.cssFiles.forEach((Z)=>console.log(` - ${Z.fileName}`));if(Y.typescriptFiles.length>0)console.log(`
|
|
412
426
|
Generated ${Y.typescriptFiles.length} TypeScript files:`),Y.typescriptFiles.forEach((Z)=>console.log(` - ${Z.fileName}`));if(Y.javascriptFiles.length>0)console.log(`
|
|
413
427
|
Generated ${Y.javascriptFiles.length} JavaScript files:`),Y.javascriptFiles.forEach((Z)=>console.log(` - ${Z.fileName}`));if(Y.jsonFiles.length>0)console.log(`
|
|
414
428
|
Generated ${Y.jsonFiles.length} JSON files:`),Y.jsonFiles.forEach((Z)=>console.log(` - ${Z.fileName}`));if(Y.warnings.length>0)console.log(`
|
|
415
|
-
Warnings:`),Y.warnings.forEach((Z)=>console.log(` - ${Z}`))}catch(X){console.error("❌ Build failed:",X),process.exit(1)}}if(import.meta.url===`file://${process.argv[1]}`)
|
|
429
|
+
Warnings:`),Y.warnings.forEach((Z)=>console.log(` - ${Z}`))}catch(X){console.error("❌ Build failed:",X),process.exit(1)}}if(import.meta.url===`file://${process.argv[1]}`)iY().catch(($)=>{console.error("Unexpected error:",$),process.exit(1)});export{iY as runCLI};
|
package/bin/watch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var H=($,Y)=>()=>($&&(Y=$($=0)),Y);import J0 from"colorjs.io";var j=H(()=>{B()});var p=H(()=>{B()});var k=H(()=>{B()});import{spawnSync as h$}from"child_process";import{existsSync as R,mkdirSync as v$,readFileSync as p$,unlinkSync as m$,writeFileSync as C0}from"fs";import{resolve as V0,join as O,basename as g0,normalize as T0,relative as y0,sep as f0,dirname as d$}from"path";async function u$(){return`${(await e()).$metaData?.tokenNamespace||"tokens"}.icons`}async function k$($){let W=O($,"designid.config.ts");if(R(O($,"designid.config.js")))m$(O($,"designid.config.js"));if(R(W)){let X=h$("bun",["build",W,"--outfile ./designid.config.js","--minify","--target","node","--packages","external"],{stdio:"inherit",cwd:".",shell:!0});if(X.status!==0)console.error("Failed to compile designid.config.js with bun."),process.exit(X.status??1);if(X.status===0)return new Promise((q)=>q(!0))}}async function V($="json"){let{tokenNamespace:Y}=await t();return`${Y}-design-system.tokens.svg${$==="d.ts"||$==="js"?".config":""}.${$}`}function E$($){if(!R($))v$($,{recursive:!0})}async function o($,Y=!1){let W=g(),X;if(W.endsWith(".json"))X=JSON.parse(p$(W,"utf8").trim()??"{}");else{$=$??d$(W)+"/";let q=B$($);if(q&&(Y||!R(q)))await k$($);if(X=await import(q),X.default)X=X.default}return X}async function F(){let{baseDir:$}=await M(),Y=process.cwd(),X=O(Y,$),{buildDir:q,distDir:Z}=await M();try{E$(O(X,q)),E$(O(X,Z))}catch(w){console.error("Error creating directories:",w)}return X}function B$($){return $?O($,"designid.config.js"):O(process.cwd(),"designid.config.js")}function g(){let $=process.argv.find((z)=>z.startsWith("--config=")),[,Y]=$?.split("=")??[];if(Y)return Y;let W=process.cwd(),X=B$(W),q=O(W,"designid.config.ts"),Z=R(X),w=R(q);if(Z)return X;else if(w)return q;throw console.error("Config file not found"),Error("Config file not found")}async function M($=!1){let Y=g(),X=(await o(process.cwd(),$)).$paths;if(!X)throw console.error("Project paths not found"),Error("Project paths not found");return{configFile:Y,...X}}async function t(){let Y=(await o(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 W=await u$();return{...Y,icons:Y.icons??{objectPath:W},dsNamespace:Y.dsNamespace}}async function e(){if(!l){let $=g();l=await o(process.cwd()),L$=$}return l}async function $$(){if(!r){let Y=(await e()).$metaData;if(!Y)throw console.error("Project metaData not found"),Error("Project metaData not found");if(!Y.dsNamespace)Y.dsNamespace=Y.tokenNamespace;let X=`${Y.tokenNamespace||"tokens"}.icons`;r={...Y,icons:Y.icons??{objectPath:X},dsNamespace:Y.dsNamespace}}return r}async function O$($=!1){if(!s){let W=(await e()).$paths;if(!W)throw console.error("Project paths not found"),Error("Project paths not found");s={configFile:L$,...W}}return s}async function T(){if(!i){let{distDir:$,assets:Y,buildDir:W}=await O$(!0),{fontNamespace:X,tokenNamespace:q,icons:Z}=await $$(),w=await F(),z=process.cwd(),E=O(z,$,"css");i={distDir:$,assets:Y,fontNamespace:X,__dirname:w,workspaceRoot:z,distCSSPath:E,buildDir:W,tokenNamespace:q,icons:Z}}return i}async function Y$(){if(!a){let{icons:$}=await $$();a=$}return a}var l=null,L$=null,r=null,s=null,i=null,a=null;var y=H(()=>{B()});var _$=H(()=>{y()});async function X$($){let Y=await Y$();$=$.replace(/<\?xml[^>]*\?>\s*/,""),$=$.replace(/<!DOCTYPE [^>]*>\s*/,"");let W=$.match(/<svg[^>]*>/),X=$.match(/viewBox="([\d\s.]+)"/),[q]=W??[],Z=q;if(q&&Z){let z=Y?.style?.fill,E=/id="[^"]*"/.test(q);if(!Z.includes("xmlns="))Z=Z.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"');if(!E&&z)Z=Z.replace("<svg",`<svg id="${z}"`);else if(E&&z)Z=Z.replace(/id="[^"]*"/,`id="${z}"`)}if(X&&q&&Z){let z=X[1].split(" ").map(Number),E=z[2],_=z[3],U=Y?.size??24,Q=E/_*U;$=$.replace(/height="[\d.]+px?"/,`height="${U}px"`),$=$.replace(/width="[\d.]+px?"/,`width="${Q}px"`);let P=/width="[\d.]+(px)?"/.test(q),I=/height="[\d.]+(px)?"/.test(q);if(!P)Z=Z.replace("<svg",`<svg width="${Q}px"`);else Z=Z.replace(/width="[\d.]+(px)?"/,`width="${Q}px"`);if(!I)Z=Z.replace("<svg",`<svg height="${U}px"`);else Z=Z.replace(/height="[\d.]+(px)?"/,`height="${U}px"`);$=$.replace(q,Z)}if(!$?.match(/data-style="([^"]*)"/)&&Y?.style?.type)$=$.replace("<svg ",`<svg data-style="${Y.style.type}" `);return $}var w$=H(()=>{B()});var R$=H(()=>{y();B()});var Z$=H(()=>{B()});var M$=()=>{};import G2 from"colorjs.io";var W$=H(()=>{M$();j()});var f=H(()=>{B()});var q$=H(()=>{B()});import{readFileSync as o$,mkdirSync as t$}from"fs";import{writeFile as N$,readdir as e$,mkdir as $0}from"fs/promises";import{resolve as Y0,relative as x$,join as U$,dirname as X0}from"path";import Z0 from"lodash";async function F$($){let Y=await e$($,{withFileTypes:!0}),W=await Promise.all(Y.map((X)=>{let q=Y0($,X.name);return X.isDirectory()?F$(q):q}));return Array.prototype.concat(...W)}async function P$(){let{assets:$,icons:Y,tokenNamespace:W,__dirname:X,buildDir:q}=await T(),Z=U$(X,$?.icons?.sourceDir??"icons"),w="build",z=$?.icons?.distDir??"build",E=U$(X,z),_=U$(X,q,"icons");if(!$?.icons?.sourceDir){console.error("Skipping icon build: iconsDir is not defined in the project paths.");return}let U=(await F$(Z)).filter((G)=>G.endsWith(".svg")),I=(await Promise.all(U.map(async(G)=>{let K=o$(G,"utf8").replace(/(\s+(?=(?:[^"]*"[^"]*")*[^"]*$))/g," ").trim()??"";K=await X$(K);let A=x$(Z,G).split("/").pop(),S=(K.match(/name="(.*?)"/)??[])[1]??A?.replace(".svg",""),h=(K.match(/data-style="(.*?)"/)??[])[1],b$=(K.match(/description="(.*?)"/)??[])[1],[G$]=K.match(/<svg[^>]*>/)??[],[,V$]=G$?.match(/width="([\d.]+)(px)?"/)??[],[,g$]=G$?.match(/height="([\d.]+)(px)?"/)??[];if(h!=="animated"&&h!=="custom")return{path:G,folder:x$(Z,G).split("/").slice(0,-1).concat(S),file:A,style:h,content:K,name:S,dimensions:{width:Number(V$),height:Number(g$)},description:b$??""};return}))).filter((G)=>G!==void 0).reduce((G,K)=>{if(K?.style!=="animated"&&K?.style!=="custom"&&K)K$(G,K.folder.join("."),{$type:"icon",$name:K.name,$description:K.description,$style:K.style,$value:K.content,$dimensions:K.dimensions,...W0(G,K.folder.join("."))});return G},{}),N=Y?.objectPath??`${W}.icons`;Object.keys(I).forEach(async(G)=>{let K=`${_}/${G}`,A=`${K}/svg.${G}.tokens.json`;await $0(K,{recursive:!0});let S=K$({},`${N}${N?".":""}${G}`,I[G]);await N$(A,JSON.stringify(S,null,2),{flag:"w",encoding:"utf-8"})});let L=`${E}/tokens/${await V("json")}`,J=X0(L);t$(J,{recursive:!0});let x=K$({},N,I);await N$(L,JSON.stringify(x,null,2),{flag:"w",encoding:"utf-8"})}var K$,W0,x2;var S$=H(()=>{B();({set:K$,get:W0}=Z0);x2=P$().catch(($)=>{console.error($),process.exit(1)})});var j$=H(()=>{f()});var D$=H(()=>{S$();f();j$();W$();q$();Z$()});var B=H(()=>{j();p();k();j();y();_$();w$();R$();p();k();Z$();W$();f();q$();D$()});B();import{exec as O0}from"child_process";import{join as C$}from"path";import _0 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,9 +14,9 @@ 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 w0(){let $=await F(),{distDir:Y,buildDir:W}=await M(),X=[/node_modules/,/dist/,/build/,C$($,Y),C$($,W)],q=_0.watch(["**/*.tokens.json","designid.config.ts"],{ignored:X,persistent:!0}),Z,w=300,
|
|
18
|
-
`);let U=(()=>{let
|
|
19
|
-
❌ Build failed: ${
|
|
17
|
+
`),process.exit(0);async function w0(){let $=await F(),{distDir:Y,buildDir:W}=await M(),X=[/node_modules/,/dist/,/build/,C$($,Y),C$($,W)],q=_0.watch(["**/*.tokens.json","designid.config.ts"],{ignored:X,persistent:!0}),Z,w=300,z=!1,E=()=>{if(z){console.log(`[${new Date().toLocaleTimeString()}] Build already in progress, skipping...`);return}clearTimeout(Z),Z=setTimeout(()=>{z=!0,console.clear(),process.stdout.write("\x1Bc"),console.log(`[${new Date().toLocaleTimeString()}] Changes detected. Re-building tokens...
|
|
18
|
+
`);let U=(()=>{let L=process.argv.find((J)=>J.startsWith("--config="));return L?L.split("=")[1]:""})(),Q=(()=>{return process.argv.find((L)=>L==="--dev")??null})(),P=U?`--config=${U}`:"",I=U?`CONFIG=${U}`:"",N=Q?`make build ${I}`:`bun run build ${P}`;O0(N,{cwd:process.cwd()},(L,J,x)=>{if(z=!1,L){console.error(`
|
|
19
|
+
❌ Build failed: ${L.message}`);return}if(x&&x.trim())console.warn(`⚠️ Warnings:
|
|
20
20
|
${x}`);if(J&&J.trim()){let G=J.split(`
|
|
21
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(G.length>0)console.log(`
|
|
22
22
|
${G.join(`
|