@greensight/gts 1.0.0-alpha.14 → 1.0.0-alpha.16
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/index.cjs +10 -10
- package/index.mjs +141 -138
- package/modules/colors/colorsFromTokenManager/module.d.ts.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var D=Object.defineProperty;var H=(n,e,t)=>e in n?D(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var y=(n,e,t)=>H(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("path"),U=require("ts-import"),j=require("node:fs"),m=require("node:fs/promises"),M=require("node:path"),h=class h{static resolveReadPath(e){if(!e||!e.trim())throw new Error("File path must be a non-empty string");return M.resolve(h.baseDir,e)}static resolveWritePath(e,t){const r=M.resolve(h.baseDir,t??"");return{targetDir:r,targetPath:M.resolve(r,e)}}static handleReadError(e,t){throw e.code==="ENOENT"?new Error(`File not found: ${t}`):new Error(`Failed to read file "${t}": ${e.message??String(e)}`)}static async read(e,t="utf8"){const r=h.resolveReadPath(e);try{return await m.readFile(r,{encoding:t})}catch(o){h.handleReadError(o,r)}}static async readBuffer(e){const t=h.resolveReadPath(e);try{return await m.readFile(t)}catch(r){h.handleReadError(r,t)}}static async readJson(e){const t=h.resolveReadPath(e);try{const r=await m.readFile(t,{encoding:"utf8"});try{return JSON.parse(r)}catch(o){throw new Error(`Failed to parse JSON from "${t}": ${o.message}`)}}catch(r){h.handleReadError(r,t)}}static async write(e,t="",r={}){const{directory:o,overwrite:s=!0}=r,{targetDir:a,targetPath:i}=h.resolveWritePath(e,o);if(!s&&j.existsSync(i))throw new Error(`File ${i} already exists`);return await m.mkdir(a,{recursive:!0}),await m.writeFile(i,t,{encoding:"utf8"}),i}static async writeWithExtension(e,t,r="",o){const s=t.startsWith(".")?t:`.${t}`,a=`${e}${s}`;return h.write(a,r,o)}static exists(e){const t=h.resolveReadPath(e);return j.existsSync(t)}static async delete(e,t){const{targetPath:r}=h.resolveWritePath(e,t);j.existsSync(r)&&await m.rm(r,{force:!0})}};y(h,"baseDir",process.cwd());let f=h;const k=class k{static async create(){if(f.exists(k.configFileName))throw new Error("The file already exists");await f.write(k.configFileName,"",{overwrite:!1})}async load(){try{const e=await U.tsImport.compile(`${b.resolve(process.cwd(),k.configFileName)}`);if(!e)throw new Error;return e.default}catch(e){console.error("Cannot find module gts.config.ts",e)}}};y(k,"configFileName","gts.config.ts");let S=k;const Q=n=>{const e=new URLSearchParams;return Object.keys(n).forEach(t=>{Array.isArray(n[t])?n[t].forEach(r=>e.append(`${t}[]`,r)):e.append(t,n[t])}),e},X=(n,e=50)=>{const t=[];for(let r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t};class v{constructor(e,t){y(this,"figmaToken");y(this,"fileId");y(this,"onTimeMeasureHandler");this.figmaToken=e,this.fileId=t}setOnTimeMeasureHandler(e){this.onTimeMeasureHandler=e}static async returnJSON(e){const t=await e.json();if(!e.ok){let r="Request failed";throw new Error(r)}return t}async performControlledRequest(e,{params:t={},timeout:r=3e4,abortController:o=new AbortController}={}){var p;if(!this.figmaToken||!this.fileId)throw new Error("Добавьте figmaToken и figmaId");const s=Object.entries(t).reduce((w,[K,C])=>typeof C<"u"?{...w,[K]:C}:w,{}),a=`https://api.figma.com/v1${e}${s&&Object.keys(s).length?`?${Q(s)}`:""}`;console.log("endpoinWithParams=",a);const i=setTimeout(()=>o.abort(),r),l={"Content-Type":"application/json",...this.figmaToken&&{"X-Figma-Token":this.figmaToken}},c={method:"GET",headers:l,signal:o.signal},u=performance.now(),g=await fetch(`${a}`,c);clearTimeout(i);const d=performance.now()-u;return(p=this.onTimeMeasureHandler)==null||p.call(this,a,l,d),g}async request(e,t){var o;const r=await this.performControlledRequest(e,{...t});return(o=r.headers.get("content-type"))!=null&&o.includes("application/json")?v.returnJSON(r):r}async getComponents(){return this.request(`/files/${this.fileId}/components`)}async getStyles(){return this.request(`/files/${this.fileId}/styles`)}async getNodes(e){const t=X(e).map(s=>this.request(`/files/${this.fileId}/nodes`,{params:{ids:s.join(",")}})),r=await Promise.all(t);return{...r[0],nodes:r.reduce((s,a)=>({...s,...a.nodes}),{})}}}const Y=(n,e)=>{const t=Array.isArray(e)?e:e.split(".");let r=n;for(const o of t){if(r==null||typeof r!="object")return;r=r[o]}return r},L=(n,e)=>{if(!e||typeof e!="object")return n;if(!n||typeof n!="object")return e;const t={...n};for(const r in e)e.hasOwnProperty(r)&&(typeof e[r]=="object"&&e[r]!==null&&typeof t[r]=="object"&&t[r]!==null?t[r]=L(t[r],e[r]):t[r]=e[r]);return t};function F(n,e){if(n===e)return!0;if(n==null||e==null)return n===e;if(typeof n!=typeof e)return!1;if(n instanceof Date&&e instanceof Date)return n.getTime()===e.getTime();if(n instanceof RegExp&&e instanceof RegExp)return n.toString()===e.toString();if(Array.isArray(n)&&Array.isArray(e)){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!F(n[t],e[t]))return!1;return!0}if(typeof n=="object"&&typeof e=="object"){const t=Object.keys(n),r=Object.keys(e);if(t.length!==r.length)return!1;for(const o of t)if(!r.includes(o)||!F(n[o],e[o]))return!1;return!0}return!1}const O={color:{},effect:{},text:{},grid:{}};class A{constructor(e){y(this,"tokensDir");y(this,"manifestPath");y(this,"variables");y(this,"styles");y(this,"loaded",!1);this.tokensDir=e||"",this.manifestPath=b.join(this.tokensDir,"manifest.json")}isLoaded(){return this.loaded&&!!this.variables&&!!this.styles}normalizeKey(e){const t=e.trim();return t&&t.replace(/[-_\s]+/g," ").split(" ").filter(r=>r.length).map((r,o)=>{const s=r.charAt(0),a=r.slice(1);return o===0?r.toLowerCase():s.toUpperCase()+a}).join("")}parseVariableString(e){if(typeof e!="string")return e;const t=/^\{(.+)\}$/,r=e.match(t);if(r){const o=r[1].trim();return`{${this.normalizeKey(o)}}`}return e}createVariableFileList(e){return Object.entries(e).flatMap(([t,r])=>Object.entries(r.modes).flatMap(([o,s])=>s.map(a=>({fileName:a,modeName:this.normalizeKey(o.trim()),collectionName:t}))))}parseValue(e){return e&&(typeof e=="string"?this.parseVariableString(e):typeof e!="object"?e:Array.isArray(e)?e.map(t=>this.parseValue(t)):Object.entries(e).reduce((t,[r,o])=>({...t,[r]:this.parseValue(o)}),{}))}getTokensFromFile(e,t){return Object.entries(e).reduce((r,[o,s])=>"$type"in s&&"$value"in s?{...r,[this.normalizeKey(o)]:{type:s.$type,description:s.$description,value:t?{[this.normalizeKey(t)]:this.parseValue(s.$value)}:this.parseValue(s.$value)}}:{...r,[this.normalizeKey(o)]:this.getTokensFromFile(s,t)},{})}processTokensFile(e,t,r){const o=this.normalizeKey(r),s=this.getTokensFromFile(e,t);return{[o]:s}}async loadVariableFiles(e){return Promise.all(e.map(async({fileName:t,modeName:r,collectionName:o})=>{try{const s=b.join(this.tokensDir,t),a=await f.readJson(s);return this.processTokensFile(a,r,o)}catch(s){return console.warn(`Failed to load variable file: ${b.join(this.tokensDir,t)}`,s),{}}}))}mergeVariables(e){return e.reduce((t,r)=>L(t,r),{})}async loadTokenVariables(e){try{const t=this.createVariableFileList(e),r=await this.loadVariableFiles(t);return this.mergeVariables(r)}catch(t){throw new Error(`Failed to load token variables from ${this.tokensDir}: ${t}`)}}createStyleFileList(e){return Object.entries(e).flatMap(([t,r])=>(r==null?void 0:r.map(o=>({styleType:t,fileName:o})))||[])}async loadStyleFiles(e){return(await Promise.all(e.map(async({styleType:r,fileName:o})=>{try{const s=b.join(this.tokensDir,o),a=await f.readJson(s);return{styleType:r,styleTokens:a}}catch(s){return console.warn(`Failed to load style file: ${b.join(this.tokensDir,o)}`,s),{styleType:r,styleTokens:{}}}}))).reduce((r,o)=>({...r,[o.styleType]:this.getTokensFromFile(o.styleTokens,"")}),{...O})}async loadStyles(e){if(!e)return{...O};const t=this.createStyleFileList(e);return await this.loadStyleFiles(t)}async load(){if(this.loaded)return;const e=await f.readJson(this.manifestPath);if(!e)throw new Error(`Failed to load manifest file from: ${this.manifestPath}`);this.variables=await this.loadTokenVariables(e.collections),this.styles=await this.loadStyles(e.styles),this.loaded=!0}getVariables(){if(!this.loaded||!this.variables)throw new Error("Tokens not loaded. Call load() first.");return this.variables}getStyles(){if(!this.loaded||!this.styles)throw new Error("Tokens not loaded. Call load() first.");return this.styles}isVariableReference(e){return typeof e!="string"?!1:/^\{.+\}$/.test(e)}getVariablePath(e){return e.slice(1,-1)}resolveVariableValue(e){if(typeof e=="object")return Object.keys(e).reduce((t,r)=>{const o=e[r],s=this.resolveVariableValueString(o,r);return s&&(t[r]=s),t},{})}resolveVariableValueString(e,t){if(!this.isVariableReference(e))return e;const r=this.getVariablePath(e),o=this.getToken(r,t);if(o)return this.resolveVariableValueString(o,t)}getToken(e,t){if(!this.loaded||!this.variables)throw new Error("Tokens not loaded. Call load() first.");for(const r of Object.values(this.variables)){const o=Y(r,e);if(o!=null&&o.value&&typeof o.value=="object"){if(t)return o.value[t];{const s=Object.keys(o.value)[0];return o.value[s]}}}}}const Z=async()=>{const e=await new S().load();if(!e)throw new Error("Заполнить ошибку через нейронку");const{figmaToken:t,fileId:r,modules:o,manifest:s}=e,a=new v(t,r),i=new A(s);s&&f.exists(s)&&await i.load(),await Promise.all(o.map(l=>l.executor({figmaApiClient:a,tokenManagerClient:i})))},_=async()=>{await S.create(),console.log("\x1B[32m%s\x1B[0m","✔️ Configuration file created gts.config.ts")},E=["xxxl","xxl","xl","lg","md","sm","xs","xxs","xxxs"],ee=n=>parseInt(n.value,10),R=n=>n.reduce((e,t)=>({...e,[t.name]:ee(t)}),{}),te=async(n,e)=>{await f.delete(n,e)},re=async(n,e,t)=>{await f.write(n,e,{directory:t})},$=async(n,e,t)=>{await te(n,t),await re(n,e,t)},ne=(n,e)=>{if(!e.length)return"";const t=e.map(r=>` ${r}`).join(`
|
|
2
2
|
`);return`${n} {
|
|
3
3
|
${t}
|
|
4
|
-
}`},
|
|
5
|
-
`):"",
|
|
4
|
+
}`},oe=n=>n.length?n.join(`
|
|
5
|
+
`):"",se=n=>`--${n}`,ae=n=>`$${n}`,ie=n=>n.map(e=>`${se(e.name)}: ${e.value}px;`),le=n=>n.map(e=>`${ae(e.name)}: ${e.value}px;`),ce=n=>ne(":root",n),ue=n=>oe(n),de=n=>{const e=R(n);return JSON.stringify(e)},ge=async(n,e,t,r,o,s,a,i)=>{const l=[];l.push($(s,n,r)),a&&e&&l.push($(a,e,o)),i&&t&&l.push($(i,t,o)),await Promise.all(l)},fe=async({breakpointTokens:n,jsonDir:e,stylesDir:t,jsonFileName:r,stylesFileName:o,extensions:s})=>{const a=ie(n),i=le(n),l=s.includes("css")?ce(a):null,c=s.includes("scss")?ue(i):null,u=s.includes("css")?`${o}.css`:null,g=s.includes("scss")?`${o}.scss`:null,d=de(n);await ge(d,l,c,e,t,r,u,g)},pe=(n,e)=>{const t=Object.keys(n).filter(s=>!isNaN(Number(s))).sort((s,a)=>Number(s)-Number(a));if(t.length>e.length)throw new Error(`Not enough breakpoint names provided. Found ${t.length} breakpoints in data, but only ${e.length} names specified: ${e.join(", ")}`);const o=Object.keys(n).filter(s=>isNaN(Number(s)));if(o.length>0)throw new Error(`Found non-numeric breakpoint keys in grid data: ${o.join(", ")}. All breakpoint keys must be numeric values.`);return t.map((s,a)=>({name:e[e.length-1-a]||`bp-${s}`,value:s}))},he=({input:n={},output:{jsonDir:e,stylesDir:t,jsonFileName:r="breakpoints.json",stylesFileName:o="breakpoints"}})=>({name:"breakpoints/tokenManager",executor:async({tokenManagerClient:s})=>{try{console.log("[breakpoints/tokenManager] Generating breakpoints from TokenManager...");const{extensions:a=["css"],names:i=E}=n;if(!s.isLoaded())throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");const l=s.getStyles();if(!l.grid)throw new Error("No grid styles found in TokenManager. Grid tokens must be loaded.");console.log("[breakpoints/tokenManager] Extracting breakpoints from grid styles...");const c=pe(l.grid,i);if(!c.length){console.warn("[breakpoints/tokenManager] No breakpoints found in grid styles.");return}console.log(`[breakpoints/tokenManager] Found ${c.length} breakpoints: ${c.map(u=>u.name).join(", ")}`),await fe({breakpointTokens:c,jsonDir:e,stylesDir:t,jsonFileName:r,stylesFileName:o,extensions:a}),console.log("[breakpoints/tokenManager] Breakpoints generated successfully.")}catch(a){throw console.error("[breakpoints/tokenManager] Error:",a),a}}}),ye=n=>{const e=R(n),t=Object.entries(e).map(([o,s])=>` ${o}: ${s}`).join(`,
|
|
6
6
|
`),r=n.length>0?n[n.length-1].name:"xxxl";return`$breakpointList: (
|
|
7
7
|
${t}
|
|
8
8
|
);
|
|
9
|
-
$defaultBreakpoint: '${r}';`},
|
|
9
|
+
$defaultBreakpoint: '${r}';`},me=async(n,e,t)=>{await $(t,n,e)},be=async({breakpointTokens:n,stylesDir:e,fileName:t})=>{const r=ye(n);await me(r,e,`${t}.scss`)},ke=(n,e)=>{const t=Object.keys(n).filter(r=>!isNaN(Number(r))).sort((r,o)=>Number(r)-Number(o));if(t.length>e.length)throw new Error(`Not enough breakpoint names provided. Found ${t.length} breakpoints in data, but only ${e.length} names specified: ${e.join(", ")}`);return t.map((r,o)=>({name:e[e.length-1-o]||`bp-${r}`,value:r}))},we=({input:n={},output:{stylesDir:e,fileName:t="breakpointList"}})=>({name:"breakpointsList/tokenManager",executor:async({tokenManagerClient:r})=>{try{console.log("[breakpointsList/tokenManager] Generating SCSS breakpoint map...");const{names:o=E}=n;if(!r.isLoaded())throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");const s=r.getStyles();if(!s.grid)throw new Error("No grid styles found in TokenManager. Grid tokens must be loaded.");console.log("[breakpointsList/tokenManager] Extracting breakpoints for SCSS map...");const a=ke(s.grid,o);if(!a.length){console.warn("[breakpointsList/tokenManager] No breakpoints found in grid styles.");return}console.log(`[breakpointsList/tokenManager] Found ${a.length} breakpoints for map: ${a.map(i=>i.name).join(", ")}`),await be({breakpointTokens:a,stylesDir:e,fileName:t}),console.log("[breakpointsList/tokenManager] SCSS breakpoint map generated successfully.")}catch(o){throw console.error("[breakpointsList/tokenManager] Error:",o),o}}}),V=(n,e)=>{if(!e.length)return"";const t=e.map(r=>` ${r}`).join(`
|
|
10
10
|
`);return`${n} {
|
|
11
11
|
${t}
|
|
12
|
-
}`}
|
|
12
|
+
}`},$e=n=>`.${n.replace(/\s+/g,"-").toLowerCase()}`,G=n=>`--${n}`,Se=n=>n.reduce((e,t)=>{const r=G(t.name);return typeof t.value=="object"?Object.entries(t.value).forEach(([o,s])=>{e[o]||(e[o]=[]),e[o].push(`${r}: ${s};`)}):e.root.push(`${r}: ${t.value};`),e},{root:[]}),Te=n=>{const e=V(".default-colors",n.root),t=Object.entries(n).reduce((r,[o,s])=>{if(o==="root"||!s.length)return r;const a=V($e(`${o}-colors`),s);return a&&r.push(a),r},[]).join(`
|
|
13
13
|
|
|
14
14
|
`);return[e,t].filter(Boolean).join(`
|
|
15
15
|
|
|
16
|
-
`)},
|
|
16
|
+
`)},je=n=>{const e=n.reduce((t,r)=>({...t,[r.name]:`var(${G(r.name)})`}),{});return JSON.stringify(e)},Me=async(n,e,t,r,o,s)=>{await Promise.all([f.delete(o,t),f.delete(s,r)]);const a=f.write(o,n,{directory:t}),i=f.write(s,e,{directory:r});await Promise.all([a,i])},Fe=async({colorTokens:n,jsonDir:e,stylesDir:t,jsonFileName:r,cssFileName:o})=>{const s=Se(n),a=Te(s),i=je(n);await Me(i,a,e,t,r,o)},T=n=>n.reduce((e,t)=>{const r=Number((t.position*100).toFixed(1));return[...e,`${t.color}${r>0&&r<100?` ${r}%`:""}`]},[]).join(", "),ve=n=>{const e=T(n.stops);return`linear-gradient(${n.angle}deg, ${e})`},Ee=n=>`radial-gradient(circle, ${T(n.stops)})`,Ce=n=>{const e=T(n.stops);return`conic-gradient(from ${n.angle}deg, ${e})`},Oe=n=>{const e=T(n.stops);return`linear-gradient(${n.angle}deg, ${e})`},P=n=>typeof n=="string"?n:n.type==="linear"?ve(n):n.type==="radial"?Ee(n):n.type==="conic"?Ce(n):n.type==="diamond"?Oe(n):"",I=(n,e)=>Object.keys(n).reduce((t,r)=>{const o=n[r],s=e?`${e}-${r}`:r;if(o&&typeof o=="object"&&"type"in o&&"value"in o){const i=Object.keys(o.value),l=i.length>1?o.value:o.value[i[0]],c=typeof l=="object"?Object.keys(l).reduce((g,d)=>({...g,[d]:P(l[d])}),{}):P(l),u={[s]:c};return{...t,...u}}const a=I(o,s);return{...t,...a}},{}),Ve=n=>`cl-${n}`,J=(n,e)=>Object.keys(n).reduce((t,r)=>{const o=n[r];if(o.type&&o.type!=="color")return t;if(o.type&&o.value){const a=typeof o.value=="string"?e.resolveVariableValueString(o.value,r):e.resolveVariableValue(o.value);return a?{...t,[r]:{...o,value:a}}:t}const s=J(o,e);return s?{...t,[r]:s}:t},{}),Pe=({input:n={},output:{jsonDir:e,stylesDir:t,jsonFileName:r="colors.json",cssFileName:o="colors.css"}})=>({name:"colors/tokenManager",executor:async({tokenManagerClient:s})=>{try{console.log("[colors/tokenManager] Generating colors from TokenManager...");const{includeVariables:a,includeStyles:i=!0}=n;if(!(a!=null&&a.length)&&!i)throw new Error("Either includeVariables or includeStyles must be enabled");if(!s.isLoaded())throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");const l=[],c=s.getVariables();if(i){const g=s.getStyles();console.log("[colors/tokenManager] Processing styles for colors..."),g.color&&l.push(g.color)}if(a!=null&&a.length){console.log(`[colors/tokenManager] Processing ${a.length} variable groups...`);const g=a.map(d=>c[d]).filter(Boolean);l.push(...g)}const u=l.map(g=>J(g,s)).flatMap(g=>Object.entries(I(g,"")).reduce((d,[p,w])=>[...d,{name:Ve(p),value:w}],[]));if(u.length===0){console.warn("[colors/tokenManager] No color tokens generated");return}console.log(`[colors/tokenManager] Generated ${u.length} color tokens`),console.log(`[colors/tokenManager] Writing files to ${e} and ${t}...`),await Fe({colorTokens:u,jsonDir:e,stylesDir:t,jsonFileName:r,cssFileName:o}),console.log("[colors/tokenManager] ✅ Successfully generated color files")}catch(a){const i=a instanceof Error?a.message:String(a);throw console.error("[colors/tokenManager] ❌ Failed to generate colors:",i),a instanceof Error&&a.stack&&console.error("[colors/tokenManager] Stack trace:",a.stack),a}}}),xe=(n,e)=>{if(!e.length)return"";const t=e.map(r=>` ${r}`).join(`
|
|
17
17
|
`);return`${n} {
|
|
18
18
|
${t}
|
|
19
19
|
}`},Ne=(n,e)=>{if(!e.length)return"";const t=n-1,r=e.map(o=>` ${o}`).join(`
|
|
20
20
|
`);return`@media (max-width: ${t}px) {
|
|
21
21
|
${r}
|
|
22
|
-
}`},Be=(n,e)=>{const t=[];n.forEach((a,i)=>{const l=parseInt(a.name.split("_")[0]),c=[],u=i>0?n[i-1]:null;if(a.value.alignment==="center"&&a.value.width&&(c.push(`max-width: ${a.value.width};`),c.push("margin-left: auto;"),c.push("margin-right: auto;"),u&&u.value.alignment!=="center"&&(c.push("padding-left: 0;"),c.push("padding-right: 0;"))),a.value.alignment==="stretch"&&u&&u.value.alignment!=="stretch"&&(c.push("max-width: none;"),c.push("margin-left: 0;"),c.push("margin-right: 0;")),a.value.alignment==="stretch"&&(c.push(`padding-left: ${a.value.margin};`),c.push(`padding-right: ${a.value.margin};`)),c.length>0){const
|
|
22
|
+
}`},Be=(n,e)=>{const t=[];n.forEach((a,i)=>{const l=parseInt(a.name.split("_")[0]),c=[],u=i>0?n[i-1]:null;if(a.value.alignment==="center"&&a.value.width&&(c.push(`max-width: ${a.value.width};`),c.push("margin-left: auto;"),c.push("margin-right: auto;"),u&&u.value.alignment!=="center"&&(c.push("padding-left: 0;"),c.push("padding-right: 0;"))),a.value.alignment==="stretch"&&u&&u.value.alignment!=="stretch"&&(c.push("max-width: none;"),c.push("margin-left: 0;"),c.push("margin-right: 0;")),a.value.alignment==="stretch"&&(c.push(`padding-left: ${a.value.margin};`),c.push(`padding-right: ${a.value.margin};`)),c.length>0){const d=xe(".container",c);if(i===0)t.push(d);else{const p=Ne(l,[d]);t.push(p)}}});const o=t.filter(Boolean).join(`
|
|
23
23
|
|
|
24
24
|
`).replace(/^/gm," ");return`@layer ${e||"components"} {
|
|
25
25
|
${o}
|
|
26
|
-
}`},Le=async(n,e,t)=>{await Ae(t,n,e)},Ae=async(n,e,t)=>{await
|
|
26
|
+
}`},Le=async(n,e,t)=>{await Ae(t,n,e)},Ae=async(n,e,t)=>{await f.delete(n,t),await f.write(n,e,{directory:t})},Re=async({containerTokens:n,stylesDir:e,fileName:t,layer:r,isModule:o=!0})=>{const s=Be(n,r),a=`${t}${o?".module":""}.css`;await Le(s,e,a)},Ge=(n,e,t)=>{const r=[];return Object.keys(n).forEach(a=>{const i=n[a];i&&i.value&&Array.isArray(i.value)&&i.value.filter(c=>c.pattern==="columns"&&(c.alignment==="center"||c.alignment==="stretch")).forEach(c=>{if(c.alignment==="center"&&r.push({name:a,value:{alignment:"center",width:t.width,margin:"auto"}}),c.alignment==="stretch"){const u=e.resolveVariableValueString(c.offset);if(!u)return;r.push({name:a,value:{alignment:"stretch",margin:u}})}})}),r.sort((a,i)=>{const l=parseInt(a.name);return parseInt(i.name)-l}).reduce((a,i)=>{const l=a[a.length-1];return l&&F(l.value,i.value)||a.push(i),a},[])},Ie=({input:n={},output:{stylesDir:e,fileName:t="container"}})=>({name:"container/tokenManager",executor:async({tokenManagerClient:r})=>{try{console.log("[container/tokenManager] Generating container styles...");const{containerWidth:o=1440,layer:s,isModule:a=!0}=n;if(!r.isLoaded())throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");console.log("[container/tokenManager] Extracting container tokens...");const i=r.getStyles();if(!i.grid)throw new Error("No grid styles found in TokenManager. Grid tokens must be loaded.");const l=Ge(i.grid,r,{width:o});if(!l.length){console.warn("[container/tokenManager] No container tokens found.");return}console.log(`[container/tokenManager] Found ${l.length} container tokens: ${l.map(c=>c.name).join(", ")}`),await Re({containerTokens:l,stylesDir:e,fileName:t,layer:s,isModule:a}),console.log("[container/tokenManager] Container styles generated successfully.")}catch(o){throw console.error("[container/tokenManager] Error:",o),o}}}),x=(n,e)=>{if(!e.length)return"";const t=e.map(r=>` ${r}`).join(`
|
|
27
27
|
`);return`${n} {
|
|
28
28
|
${t}
|
|
29
|
-
}`},Je=n=>`.${n.replace(/\s+/g,"-").toLowerCase()}`,We=n=>`--${n}`,qe=({offsetX:n,offsetY:e,blur:t,spread:r,color:o})=>`${n} ${e} ${t} ${r} ${o}`,ze=n=>n.reduce((e,t)=>{const r=We(t.name);return typeof t.value=="object"?Object.entries(t.value).forEach(([o,s])=>{e[o]||(e[o]=[]),e[o].push(`${r}: ${s};`)}):e.root.push(`${r}: ${t.value};`),e},{root:[]}),Ke=n=>{const e=
|
|
29
|
+
}`},Je=n=>`.${n.replace(/\s+/g,"-").toLowerCase()}`,We=n=>`--${n}`,qe=({offsetX:n,offsetY:e,blur:t,spread:r,color:o})=>`${n} ${e} ${t} ${r} ${o}`,ze=n=>n.reduce((e,t)=>{const r=We(t.name);return typeof t.value=="object"?Object.entries(t.value).forEach(([o,s])=>{e[o]||(e[o]=[]),e[o].push(`${r}: ${s};`)}):e.root.push(`${r}: ${t.value};`),e},{root:[]}),Ke=n=>{const e=x(":root",n.root),t=Object.entries(n).reduce((r,[o,s])=>{if(o==="root"||!s.length)return r;const a=x(Je(o),s);return a&&r.push(a),r},[]).join(`
|
|
30
30
|
|
|
31
31
|
`);return[e,t].filter(Boolean).join(`
|
|
32
32
|
|
|
33
|
-
`)},De=n=>{const e=n.reduce((t,r)=>({...t,[r.name]:r.value}),{});return JSON.stringify(e)},He=async(n,e,t,r,o,s)=>{await Promise.all([
|
|
33
|
+
`)},De=n=>{const e=n.reduce((t,r)=>({...t,[r.name]:r.value}),{});return JSON.stringify(e)},He=async(n,e,t,r,o,s)=>{await Promise.all([f.delete(o,t),f.delete(s,r)]);const a=f.write(o,n,{directory:t}),i=f.write(s,e,{directory:r});await Promise.all([a,i])},Ue=async({shadowTokens:n,jsonDir:e,stylesDir:t,jsonFileName:r,cssFileName:o})=>{const s=ze(n),a=Ke(s),i=De(n);await He(i,a,e,t,r,o)},W=(n,e)=>Object.keys(n).reduce((t,r)=>{const o=n[r],s=e?`${e}-${r}`:r;if(o&&typeof o=="object"&&"type"in o&&"value"in o){const i={[s]:o.value.map(qe).join(", ")};return{...t,...i}}const a=W(o,s);return{...t,...a}},{}),Qe=n=>`sh-${n}`,Xe=({input:n={},output:{jsonDir:e,stylesDir:t,jsonFileName:r="shadows.json",cssFileName:o="shadows.css"}})=>({name:"shadows/tokenManager",executor:async({tokenManagerClient:s})=>{try{console.log("[shadows/tokenManager] Generating shadows from TokenManager...");const{includeVariables:a,includeStyles:i=!0}=n;if(!(a!=null&&a.length)&&!i)throw new Error("Either includeVariables or includeStyles must be enabled");if(!s.isLoaded())throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");const l=[];if(i){const u=s.getStyles();console.log("[shadows/tokenManager] Processing styles for shadows..."),u.effect&&l.push(u.effect)}const c=l.flatMap(u=>Object.entries(W(u,"")).reduce((g,[d,p])=>[...g,{name:Qe(d),value:p}],[]));if(console.log("shadowTokens=",c),c.length===0){console.warn("[shadows/tokenManager] No shadow tokens generated");return}console.log(`[shadows/tokenManager] Generated ${c.length} shadow tokens`),console.log(`[shadows/tokenManager] Writing files to ${e} and ${t}...`),await Ue({shadowTokens:c,jsonDir:e,stylesDir:t,jsonFileName:r,cssFileName:o}),console.log("[shadows/tokenManager] ✅ Successfully generated shadow files")}catch(a){const i=a instanceof Error?a.message:String(a);throw console.error("[shadows/tokenManager] ❌ Failed to generate shadows:",i),a instanceof Error&&a.stack&&console.error("[shadows/tokenManager] Stack trace:",a.stack),a}}}),N=n=>{const e={};return Object.entries(n).forEach(([t,r])=>{const o=t.replace(/([A-Z])/g,"-$1").toLowerCase();e[o]=r}),e},Ye=(n,e)=>{const t=Object.keys(n.breakpoints),r=N(n.base);return t.reduce((o,s,a)=>{const i=N(n.breakpoints[s]);return a?[...o,{breakpoint:Number(e[s]),css:i}]:[{breakpoint:null,css:{...r,...i}}]},[{breakpoint:null,css:r}])},B=n=>Object.keys(n).reduce((e,t)=>{const r=n[t],o=Object.keys(r).map(s=>`${s}: ${r[s]}`).join(";");return e+`.${t}Typography { ${o} }`},""),Ze=(n,e)=>{const t=n.reduce((s,a)=>(Ye(a.value,e).forEach(({breakpoint:l,css:c})=>{l?(s.breakpoints[l]||(s.breakpoints[l]={}),s.breakpoints[l][a.name]=c):s.base[a.name]=c}),s),{base:{},breakpoints:{}}),r=B(t.base),o=Object.keys(t.breakpoints).reduce((s,a)=>{const i=t.breakpoints[a];return s+`@media (max-width: ${a}px) { ${B(i)} }`},"");return r+o},_e=n=>{const e=n.reduce((t,r)=>({...t,[r.name]:r.value}),{});return JSON.stringify(e)},et=async(n,e,t,r,o,s)=>{await Promise.all([f.delete(o,t),f.delete(s,r)]);const a=f.write(o,n,{directory:t}),i=f.write(s,e,{directory:r});await Promise.all([a,i])},tt=async({typographyTokens:n,jsonDir:e,stylesDir:t,jsonFileName:r,cssFileName:o,breakpoints:s,isModule:a})=>{const i=Ze(n,s),l=_e(n),c=`${o}${a?".module":""}.css`,u=`${r}.json`;await et(l,i,e,t,u,c)},q=(n,e,t)=>Object.keys(n).reduce((r,o)=>{const s=n[o];if(typeof s!="object"||Array.isArray(s))return r;if(!("type"in s)||!("value"in s))return{...r,[o]:q(s,e,t)};if(s.type!=="typography")return r;const a=s.value,i=Object.entries(a).reduce((l,[c,u])=>{const g=Object.keys(t.breakpoints);if(g.length)g.forEach(d=>{const p=e.resolveVariableValueString(u,d);p&&(p===u?l.base={...l.base,[c]:p}:l.breakpoints[d]={...l.breakpoints[d],[c]:p})});else{const d=e.resolveVariableValueString(u);d&&(l.base={...l.base,[c]:d})}return l},{base:{},breakpoints:{}});return{...r,[o]:{type:"typography",value:i}}},{}),z=(n,e)=>Object.keys(n).reduce((t,r)=>{const o=e?`${e}-${r}`:r,s=n[r];if(!("type"in s)||!("value"in s))return{...t,...z(s,o)};const a=s.value;return{...t,[o]:a}},{}),rt=({input:n,output:{jsonDir:e,stylesDir:t,jsonFileName:r="typography",cssFileName:o="typography"}})=>({name:"typography/tokenManager",executor:async({tokenManagerClient:s})=>{try{console.log("[typography/tokenManager] Generating typography from TokenManager...");const{breakpoints:a,isModule:i}=n;if(!s.isLoaded())throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");const l=[],c=s.getStyles();console.log("[typography/tokenManager] Processing styles for typography..."),c.text&&l.push(c.text);const u=l.reduce((d,p)=>({...d,...q(p,s,{breakpoints:n.breakpoints})}),{}),g=Object.entries(z(u)).map(([d,p])=>({name:d,value:p}));if(g.length===0){console.warn("[typography/tokenManager] No typography tokens generated");return}console.log(`[typography/tokenManager] Generated ${g.length} typography tokens`),console.log(`[typography/tokenManager] Writing files to ${e} and ${t}...`),await tt({typographyTokens:g,jsonDir:e,stylesDir:t,jsonFileName:r,cssFileName:o,breakpoints:a,isModule:i}),console.log("[typography/tokenManager] ✅ Successfully generated typography files")}catch(a){const i=a instanceof Error?a.message:String(a);throw console.error("[typography/tokenManager] ❌ Failed to generate typography:",i),a instanceof Error&&a.stack&&console.error("[typography/tokenManager] Stack trace:",a.stack),a}}});exports.BREAKPOINTS_NAMES=E;exports.TokenManager=A;exports.breakpointsFromTokenManager=he;exports.breakpointsListFromTokenManager=we;exports.colorsFromTokenManager=Pe;exports.containerFromTokenManager=Ie;exports.generate=Z;exports.init=_;exports.shadowsFromTokenManager=Xe;exports.typographyFromTokenManager=rt;
|
package/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var y = (n, e, t) =>
|
|
1
|
+
var q = Object.defineProperty;
|
|
2
|
+
var D = (n, e, t) => e in n ? q(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var y = (n, e, t) => D(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import m from "path";
|
|
5
|
-
import { tsImport as
|
|
5
|
+
import { tsImport as H } from "ts-import";
|
|
6
6
|
import { existsSync as j } from "node:fs";
|
|
7
|
-
import { readFile as T, mkdir as
|
|
7
|
+
import { readFile as T, mkdir as U, writeFile as Q, rm as X } from "node:fs/promises";
|
|
8
8
|
import { resolve as M } from "node:path";
|
|
9
9
|
const h = class h {
|
|
10
10
|
static resolveReadPath(e) {
|
|
@@ -57,7 +57,7 @@ const h = class h {
|
|
|
57
57
|
const { directory: o, overwrite: s = !0 } = r, { targetDir: a, targetPath: i } = h.resolveWritePath(e, o);
|
|
58
58
|
if (!s && j(i))
|
|
59
59
|
throw new Error(`File ${i} already exists`);
|
|
60
|
-
return await
|
|
60
|
+
return await U(a, { recursive: !0 }), await Q(i, t, { encoding: "utf8" }), i;
|
|
61
61
|
}
|
|
62
62
|
static async writeWithExtension(e, t, r = "", o) {
|
|
63
63
|
const s = t.startsWith(".") ? t : `.${t}`, a = `${e}${s}`;
|
|
@@ -69,20 +69,20 @@ const h = class h {
|
|
|
69
69
|
}
|
|
70
70
|
static async delete(e, t) {
|
|
71
71
|
const { targetPath: r } = h.resolveWritePath(e, t);
|
|
72
|
-
j(r) && await
|
|
72
|
+
j(r) && await X(r, { force: !0 });
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
y(h, "baseDir", process.cwd());
|
|
76
|
-
let
|
|
76
|
+
let f = h;
|
|
77
77
|
const b = class b {
|
|
78
78
|
static async create() {
|
|
79
|
-
if (
|
|
79
|
+
if (f.exists(b.configFileName))
|
|
80
80
|
throw new Error("The file already exists");
|
|
81
|
-
await
|
|
81
|
+
await f.write(b.configFileName, "", { overwrite: !1 });
|
|
82
82
|
}
|
|
83
83
|
async load() {
|
|
84
84
|
try {
|
|
85
|
-
const e = await
|
|
85
|
+
const e = await H.compile(
|
|
86
86
|
`${m.resolve(process.cwd(), b.configFileName)}`
|
|
87
87
|
);
|
|
88
88
|
if (!e) throw new Error();
|
|
@@ -94,18 +94,18 @@ const b = class b {
|
|
|
94
94
|
};
|
|
95
95
|
y(b, "configFileName", "gts.config.ts");
|
|
96
96
|
let $ = b;
|
|
97
|
-
const
|
|
97
|
+
const Y = (n) => {
|
|
98
98
|
const e = new URLSearchParams();
|
|
99
99
|
return Object.keys(n).forEach((t) => {
|
|
100
100
|
Array.isArray(n[t]) ? n[t].forEach((r) => e.append(`${t}[]`, r)) : e.append(t, n[t]);
|
|
101
101
|
}), e;
|
|
102
|
-
},
|
|
102
|
+
}, Z = (n, e = 50) => {
|
|
103
103
|
const t = [];
|
|
104
104
|
for (let r = 0; r < n.length; r += e)
|
|
105
105
|
t.push(n.slice(r, r + e));
|
|
106
106
|
return t;
|
|
107
107
|
};
|
|
108
|
-
class
|
|
108
|
+
class v {
|
|
109
109
|
constructor(e, t) {
|
|
110
110
|
y(this, "figmaToken");
|
|
111
111
|
y(this, "fileId");
|
|
@@ -127,7 +127,7 @@ class C {
|
|
|
127
127
|
var p;
|
|
128
128
|
if (!this.figmaToken || !this.fileId)
|
|
129
129
|
throw new Error("Добавьте figmaToken и figmaId");
|
|
130
|
-
const s = Object.entries(t).reduce((k, [
|
|
130
|
+
const s = Object.entries(t).reduce((k, [K, C]) => typeof C < "u" ? { ...k, [K]: C } : k, {}), a = `https://api.figma.com/v1${e}${s && Object.keys(s).length ? `?${Y(s)}` : ""}`;
|
|
131
131
|
console.log("endpoinWithParams=", a);
|
|
132
132
|
const i = setTimeout(() => o.abort(), r), l = {
|
|
133
133
|
"Content-Type": "application/json",
|
|
@@ -136,17 +136,17 @@ class C {
|
|
|
136
136
|
method: "GET",
|
|
137
137
|
headers: l,
|
|
138
138
|
signal: o.signal
|
|
139
|
-
}, u = performance.now(),
|
|
139
|
+
}, u = performance.now(), g = await fetch(`${a}`, c);
|
|
140
140
|
clearTimeout(i);
|
|
141
|
-
const
|
|
142
|
-
return (p = this.onTimeMeasureHandler) == null || p.call(this, a, l,
|
|
141
|
+
const d = performance.now() - u;
|
|
142
|
+
return (p = this.onTimeMeasureHandler) == null || p.call(this, a, l, d), g;
|
|
143
143
|
}
|
|
144
144
|
async request(e, t) {
|
|
145
145
|
var o;
|
|
146
146
|
const r = await this.performControlledRequest(e, {
|
|
147
147
|
...t
|
|
148
148
|
});
|
|
149
|
-
return (o = r.headers.get("content-type")) != null && o.includes("application/json") ?
|
|
149
|
+
return (o = r.headers.get("content-type")) != null && o.includes("application/json") ? v.returnJSON(r) : r;
|
|
150
150
|
}
|
|
151
151
|
async getComponents() {
|
|
152
152
|
return this.request(`/files/${this.fileId}/components`);
|
|
@@ -155,7 +155,7 @@ class C {
|
|
|
155
155
|
return this.request(`/files/${this.fileId}/styles`);
|
|
156
156
|
}
|
|
157
157
|
async getNodes(e) {
|
|
158
|
-
const t =
|
|
158
|
+
const t = Z(e).map(
|
|
159
159
|
(s) => this.request(`/files/${this.fileId}/nodes`, { params: { ids: s.join(",") } })
|
|
160
160
|
), r = await Promise.all(t);
|
|
161
161
|
return {
|
|
@@ -164,7 +164,7 @@ class C {
|
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
const
|
|
167
|
+
const _ = (n, e) => {
|
|
168
168
|
const t = Array.isArray(e) ? e : e.split(".");
|
|
169
169
|
let r = n;
|
|
170
170
|
for (const o of t) {
|
|
@@ -172,12 +172,12 @@ const Y = (n, e) => {
|
|
|
172
172
|
r = r[o];
|
|
173
173
|
}
|
|
174
174
|
return r;
|
|
175
|
-
},
|
|
175
|
+
}, B = (n, e) => {
|
|
176
176
|
if (!e || typeof e != "object") return n;
|
|
177
177
|
if (!n || typeof n != "object") return e;
|
|
178
178
|
const t = { ...n };
|
|
179
179
|
for (const r in e)
|
|
180
|
-
e.hasOwnProperty(r) && (typeof e[r] == "object" && e[r] !== null && typeof t[r] == "object" && t[r] !== null ? t[r] =
|
|
180
|
+
e.hasOwnProperty(r) && (typeof e[r] == "object" && e[r] !== null && typeof t[r] == "object" && t[r] !== null ? t[r] = B(t[r], e[r]) : t[r] = e[r]);
|
|
181
181
|
return t;
|
|
182
182
|
};
|
|
183
183
|
function E(n, e) {
|
|
@@ -216,7 +216,7 @@ const F = {
|
|
|
216
216
|
text: {},
|
|
217
217
|
grid: {}
|
|
218
218
|
};
|
|
219
|
-
class
|
|
219
|
+
class ee {
|
|
220
220
|
constructor(e) {
|
|
221
221
|
// files
|
|
222
222
|
y(this, "tokensDir");
|
|
@@ -289,7 +289,7 @@ class Z {
|
|
|
289
289
|
return Promise.all(
|
|
290
290
|
e.map(async ({ fileName: t, modeName: r, collectionName: o }) => {
|
|
291
291
|
try {
|
|
292
|
-
const s = m.join(this.tokensDir, t), a = await
|
|
292
|
+
const s = m.join(this.tokensDir, t), a = await f.readJson(s);
|
|
293
293
|
return this.processTokensFile(a, r, o);
|
|
294
294
|
} catch (s) {
|
|
295
295
|
return console.warn(`Failed to load variable file: ${m.join(this.tokensDir, t)}`, s), {};
|
|
@@ -298,7 +298,7 @@ class Z {
|
|
|
298
298
|
);
|
|
299
299
|
}
|
|
300
300
|
mergeVariables(e) {
|
|
301
|
-
return e.reduce((t, r) =>
|
|
301
|
+
return e.reduce((t, r) => B(t, r), {});
|
|
302
302
|
}
|
|
303
303
|
/**
|
|
304
304
|
* Loads and processes all token variables from manifest collections
|
|
@@ -329,7 +329,7 @@ class Z {
|
|
|
329
329
|
return (await Promise.all(
|
|
330
330
|
e.map(async ({ styleType: r, fileName: o }) => {
|
|
331
331
|
try {
|
|
332
|
-
const s = m.join(this.tokensDir, o), a = await
|
|
332
|
+
const s = m.join(this.tokensDir, o), a = await f.readJson(s);
|
|
333
333
|
return { styleType: r, styleTokens: a };
|
|
334
334
|
} catch (s) {
|
|
335
335
|
return console.warn(`Failed to load style file: ${m.join(this.tokensDir, o)}`, s), { styleType: r, styleTokens: {} };
|
|
@@ -352,7 +352,7 @@ class Z {
|
|
|
352
352
|
}
|
|
353
353
|
async load() {
|
|
354
354
|
if (this.loaded) return;
|
|
355
|
-
const e = await
|
|
355
|
+
const e = await f.readJson(this.manifestPath);
|
|
356
356
|
if (!e)
|
|
357
357
|
throw new Error(`Failed to load manifest file from: ${this.manifestPath}`);
|
|
358
358
|
this.variables = await this.loadTokenVariables(e.collections), this.styles = await this.loadStyles(e.styles), this.loaded = !0;
|
|
@@ -423,7 +423,7 @@ class Z {
|
|
|
423
423
|
if (!this.loaded || !this.variables)
|
|
424
424
|
throw new Error("Tokens not loaded. Call load() first.");
|
|
425
425
|
for (const r of Object.values(this.variables)) {
|
|
426
|
-
const o =
|
|
426
|
+
const o = _(r, e);
|
|
427
427
|
if (o != null && o.value && typeof o.value == "object") {
|
|
428
428
|
if (t) return o.value[t];
|
|
429
429
|
{
|
|
@@ -438,8 +438,8 @@ const ot = async () => {
|
|
|
438
438
|
const e = await new $().load();
|
|
439
439
|
if (!e)
|
|
440
440
|
throw new Error("Заполнить ошибку через нейронку");
|
|
441
|
-
const { figmaToken: t, fileId: r, modules: o, manifest: s } = e, a = new
|
|
442
|
-
s &&
|
|
441
|
+
const { figmaToken: t, fileId: r, modules: o, manifest: s } = e, a = new v(t, r), i = new ee(s);
|
|
442
|
+
s && f.exists(s) && await i.load(), await Promise.all(
|
|
443
443
|
// [
|
|
444
444
|
// colorsFromTokenManager({
|
|
445
445
|
// input: {
|
|
@@ -509,33 +509,33 @@ const ot = async () => {
|
|
|
509
509
|
);
|
|
510
510
|
}, st = async () => {
|
|
511
511
|
await $.create(), console.log("\x1B[32m%s\x1B[0m", "✔️ Configuration file created gts.config.ts");
|
|
512
|
-
},
|
|
512
|
+
}, L = ["xxxl", "xxl", "xl", "lg", "md", "sm", "xs", "xxs", "xxxs"], te = (n) => parseInt(n.value, 10), A = (n) => n.reduce(
|
|
513
513
|
(e, t) => ({
|
|
514
514
|
...e,
|
|
515
|
-
[t.name]:
|
|
515
|
+
[t.name]: te(t)
|
|
516
516
|
}),
|
|
517
517
|
{}
|
|
518
|
-
),
|
|
519
|
-
await
|
|
520
|
-
},
|
|
521
|
-
await
|
|
518
|
+
), re = async (n, e) => {
|
|
519
|
+
await f.delete(n, e);
|
|
520
|
+
}, ne = async (n, e, t) => {
|
|
521
|
+
await f.write(n, e, { directory: t });
|
|
522
522
|
}, w = async (n, e, t) => {
|
|
523
|
-
await
|
|
524
|
-
},
|
|
523
|
+
await re(n, t), await ne(n, e, t);
|
|
524
|
+
}, oe = (n, e) => {
|
|
525
525
|
if (!e.length) return "";
|
|
526
526
|
const t = e.map((r) => ` ${r}`).join(`
|
|
527
527
|
`);
|
|
528
528
|
return `${n} {
|
|
529
529
|
${t}
|
|
530
530
|
}`;
|
|
531
|
-
},
|
|
532
|
-
`) : "",
|
|
533
|
-
const e =
|
|
531
|
+
}, se = (n) => n.length ? n.join(`
|
|
532
|
+
`) : "", ae = (n) => `--${n}`, ie = (n) => `$${n}`, le = (n) => n.map((e) => `${ae(e.name)}: ${e.value}px;`), ce = (n) => n.map((e) => `${ie(e.name)}: ${e.value}px;`), ue = (n) => oe(":root", n), de = (n) => se(n), ge = (n) => {
|
|
533
|
+
const e = A(n);
|
|
534
534
|
return JSON.stringify(e);
|
|
535
|
-
},
|
|
535
|
+
}, fe = async (n, e, t, r, o, s, a, i) => {
|
|
536
536
|
const l = [];
|
|
537
537
|
l.push(w(s, n, r)), a && e && l.push(w(a, e, o)), i && t && l.push(w(i, t, o)), await Promise.all(l);
|
|
538
|
-
},
|
|
538
|
+
}, pe = async ({
|
|
539
539
|
breakpointTokens: n,
|
|
540
540
|
jsonDir: e,
|
|
541
541
|
stylesDir: t,
|
|
@@ -543,18 +543,18 @@ ${t}
|
|
|
543
543
|
stylesFileName: o,
|
|
544
544
|
extensions: s
|
|
545
545
|
}) => {
|
|
546
|
-
const a =
|
|
547
|
-
await
|
|
548
|
-
|
|
546
|
+
const a = le(n), i = ce(n), l = s.includes("css") ? ue(a) : null, c = s.includes("scss") ? de(i) : null, u = s.includes("css") ? `${o}.css` : null, g = s.includes("scss") ? `${o}.scss` : null, d = ge(n);
|
|
547
|
+
await fe(
|
|
548
|
+
d,
|
|
549
549
|
l,
|
|
550
550
|
c,
|
|
551
551
|
e,
|
|
552
552
|
t,
|
|
553
553
|
r,
|
|
554
554
|
u,
|
|
555
|
-
|
|
555
|
+
g
|
|
556
556
|
);
|
|
557
|
-
},
|
|
557
|
+
}, he = (n, e) => {
|
|
558
558
|
const t = Object.keys(n).filter((s) => !isNaN(Number(s))).sort((s, a) => Number(s) - Number(a));
|
|
559
559
|
if (t.length > e.length)
|
|
560
560
|
throw new Error(
|
|
@@ -577,21 +577,21 @@ ${t}
|
|
|
577
577
|
executor: async ({ tokenManagerClient: s }) => {
|
|
578
578
|
try {
|
|
579
579
|
console.log("[breakpoints/tokenManager] Generating breakpoints from TokenManager...");
|
|
580
|
-
const { extensions: a = ["css"], names: i =
|
|
580
|
+
const { extensions: a = ["css"], names: i = L } = n;
|
|
581
581
|
if (!s.isLoaded())
|
|
582
582
|
throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
|
|
583
583
|
const l = s.getStyles();
|
|
584
584
|
if (!l.grid)
|
|
585
585
|
throw new Error("No grid styles found in TokenManager. Grid tokens must be loaded.");
|
|
586
586
|
console.log("[breakpoints/tokenManager] Extracting breakpoints from grid styles...");
|
|
587
|
-
const c =
|
|
587
|
+
const c = he(l.grid, i);
|
|
588
588
|
if (!c.length) {
|
|
589
589
|
console.warn("[breakpoints/tokenManager] No breakpoints found in grid styles.");
|
|
590
590
|
return;
|
|
591
591
|
}
|
|
592
592
|
console.log(
|
|
593
593
|
`[breakpoints/tokenManager] Found ${c.length} breakpoints: ${c.map((u) => u.name).join(", ")}`
|
|
594
|
-
), await
|
|
594
|
+
), await pe({
|
|
595
595
|
breakpointTokens: c,
|
|
596
596
|
jsonDir: e,
|
|
597
597
|
stylesDir: t,
|
|
@@ -603,23 +603,23 @@ ${t}
|
|
|
603
603
|
throw console.error("[breakpoints/tokenManager] Error:", a), a;
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
|
-
}),
|
|
607
|
-
const e =
|
|
606
|
+
}), ye = (n) => {
|
|
607
|
+
const e = A(n), t = Object.entries(e).map(([o, s]) => ` ${o}: ${s}`).join(`,
|
|
608
608
|
`), r = n.length > 0 ? n[n.length - 1].name : "xxxl";
|
|
609
609
|
return `$breakpointList: (
|
|
610
610
|
${t}
|
|
611
611
|
);
|
|
612
612
|
$defaultBreakpoint: '${r}';`;
|
|
613
|
-
},
|
|
613
|
+
}, me = async (n, e, t) => {
|
|
614
614
|
await w(t, n, e);
|
|
615
|
-
},
|
|
615
|
+
}, be = async ({
|
|
616
616
|
breakpointTokens: n,
|
|
617
617
|
stylesDir: e,
|
|
618
618
|
fileName: t
|
|
619
619
|
}) => {
|
|
620
|
-
const r =
|
|
621
|
-
await
|
|
622
|
-
},
|
|
620
|
+
const r = ye(n);
|
|
621
|
+
await me(r, e, `${t}.scss`);
|
|
622
|
+
}, ke = (n, e) => {
|
|
623
623
|
const t = Object.keys(n).filter((r) => !isNaN(Number(r))).sort((r, o) => Number(r) - Number(o));
|
|
624
624
|
if (t.length > e.length)
|
|
625
625
|
throw new Error(
|
|
@@ -637,21 +637,21 @@ $defaultBreakpoint: '${r}';`;
|
|
|
637
637
|
executor: async ({ tokenManagerClient: r }) => {
|
|
638
638
|
try {
|
|
639
639
|
console.log("[breakpointsList/tokenManager] Generating SCSS breakpoint map...");
|
|
640
|
-
const { names: o =
|
|
640
|
+
const { names: o = L } = n;
|
|
641
641
|
if (!r.isLoaded())
|
|
642
642
|
throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
|
|
643
643
|
const s = r.getStyles();
|
|
644
644
|
if (!s.grid)
|
|
645
645
|
throw new Error("No grid styles found in TokenManager. Grid tokens must be loaded.");
|
|
646
646
|
console.log("[breakpointsList/tokenManager] Extracting breakpoints for SCSS map...");
|
|
647
|
-
const a =
|
|
647
|
+
const a = ke(s.grid, o);
|
|
648
648
|
if (!a.length) {
|
|
649
649
|
console.warn("[breakpointsList/tokenManager] No breakpoints found in grid styles.");
|
|
650
650
|
return;
|
|
651
651
|
}
|
|
652
652
|
console.log(
|
|
653
653
|
`[breakpointsList/tokenManager] Found ${a.length} breakpoints for map: ${a.map((i) => i.name).join(", ")}`
|
|
654
|
-
), await
|
|
654
|
+
), await be({
|
|
655
655
|
breakpointTokens: a,
|
|
656
656
|
stylesDir: e,
|
|
657
657
|
fileName: t
|
|
@@ -667,18 +667,18 @@ $defaultBreakpoint: '${r}';`;
|
|
|
667
667
|
return `${n} {
|
|
668
668
|
${t}
|
|
669
669
|
}`;
|
|
670
|
-
},
|
|
670
|
+
}, we = (n) => `.${n.replace(/\s+/g, "-").toLowerCase()}`, R = (n) => `--${n}`, $e = (n) => n.reduce(
|
|
671
671
|
(e, t) => {
|
|
672
|
-
const r =
|
|
672
|
+
const r = R(t.name);
|
|
673
673
|
return typeof t.value == "object" ? Object.entries(t.value).forEach(([o, s]) => {
|
|
674
674
|
e[o] || (e[o] = []), e[o].push(`${r}: ${s};`);
|
|
675
675
|
}) : e.root.push(`${r}: ${t.value};`), e;
|
|
676
676
|
},
|
|
677
677
|
{ root: [] }
|
|
678
|
-
),
|
|
679
|
-
const e = V("
|
|
678
|
+
), Se = (n) => {
|
|
679
|
+
const e = V(".default-colors", n.root), t = Object.entries(n).reduce((r, [o, s]) => {
|
|
680
680
|
if (o === "root" || !s.length) return r;
|
|
681
|
-
const a = V(
|
|
681
|
+
const a = V(we(`${o}-colors`), s);
|
|
682
682
|
return a && r.push(a), r;
|
|
683
683
|
}, []).join(`
|
|
684
684
|
|
|
@@ -686,52 +686,59 @@ ${t}
|
|
|
686
686
|
return [e, t].filter(Boolean).join(`
|
|
687
687
|
|
|
688
688
|
`);
|
|
689
|
-
},
|
|
690
|
-
const e = n.reduce((t, r) => ({ ...t, [r.name]: r.
|
|
689
|
+
}, je = (n) => {
|
|
690
|
+
const e = n.reduce((t, r) => ({ ...t, [r.name]: `var(${R(r.name)})` }), {});
|
|
691
691
|
return JSON.stringify(e);
|
|
692
|
-
},
|
|
693
|
-
await Promise.all([
|
|
694
|
-
const a =
|
|
692
|
+
}, Te = async (n, e, t, r, o, s) => {
|
|
693
|
+
await Promise.all([f.delete(o, t), f.delete(s, r)]);
|
|
694
|
+
const a = f.write(o, n, { directory: t }), i = f.write(s, e, { directory: r });
|
|
695
695
|
await Promise.all([a, i]);
|
|
696
|
-
},
|
|
696
|
+
}, Me = async ({
|
|
697
697
|
colorTokens: n,
|
|
698
698
|
jsonDir: e,
|
|
699
699
|
stylesDir: t,
|
|
700
700
|
jsonFileName: r,
|
|
701
701
|
cssFileName: o
|
|
702
702
|
}) => {
|
|
703
|
-
const s =
|
|
704
|
-
await
|
|
703
|
+
const s = $e(n), a = Se(s), i = je(n);
|
|
704
|
+
await Te(i, a, e, t, r, o);
|
|
705
705
|
}, S = (n) => n.reduce((e, t) => {
|
|
706
706
|
const r = Number((t.position * 100).toFixed(1));
|
|
707
707
|
return [...e, `${t.color}${r > 0 && r < 100 ? ` ${r}%` : ""}`];
|
|
708
|
-
}, []).join(", "),
|
|
708
|
+
}, []).join(", "), Ee = (n) => {
|
|
709
709
|
const e = S(n.stops);
|
|
710
710
|
return `linear-gradient(${n.angle}deg, ${e})`;
|
|
711
|
-
},
|
|
711
|
+
}, ve = (n) => `radial-gradient(circle, ${S(n.stops)})`, Ce = (n) => {
|
|
712
712
|
const e = S(n.stops);
|
|
713
713
|
return `conic-gradient(from ${n.angle}deg, ${e})`;
|
|
714
|
-
},
|
|
714
|
+
}, Fe = (n) => {
|
|
715
715
|
const e = S(n.stops);
|
|
716
716
|
return `linear-gradient(${n.angle}deg, ${e})`;
|
|
717
|
-
},
|
|
717
|
+
}, O = (n) => typeof n == "string" ? n : n.type === "linear" ? Ee(n) : n.type === "radial" ? ve(n) : n.type === "conic" ? Ce(n) : n.type === "diamond" ? Fe(n) : "", G = (n, e) => Object.keys(n).reduce(
|
|
718
718
|
(t, r) => {
|
|
719
719
|
const o = n[r], s = e ? `${e}-${r}` : r;
|
|
720
720
|
if (o && typeof o == "object" && "type" in o && "value" in o) {
|
|
721
|
-
const i = Object.keys(o.value), l = i.length > 1 ? o.value : o.value[i[0]], c =
|
|
722
|
-
|
|
721
|
+
const i = Object.keys(o.value), l = i.length > 1 ? o.value : o.value[i[0]], c = typeof l == "object" ? Object.keys(l).reduce(
|
|
722
|
+
(g, d) => ({
|
|
723
|
+
...g,
|
|
724
|
+
[d]: O(l[d])
|
|
725
|
+
}),
|
|
726
|
+
{}
|
|
727
|
+
) : O(l), u = { [s]: c };
|
|
728
|
+
return { ...t, ...u };
|
|
723
729
|
}
|
|
724
|
-
const a =
|
|
730
|
+
const a = G(o, s);
|
|
725
731
|
return { ...t, ...a };
|
|
726
732
|
},
|
|
727
733
|
{}
|
|
728
|
-
), Ve = (n) => `cl-${n}`,
|
|
734
|
+
), Ve = (n) => `cl-${n}`, I = (n, e) => Object.keys(n).reduce((t, r) => {
|
|
729
735
|
const o = n[r];
|
|
736
|
+
if (o.type && o.type !== "color") return t;
|
|
730
737
|
if (o.type && o.value) {
|
|
731
738
|
const a = typeof o.value == "string" ? e.resolveVariableValueString(o.value, r) : e.resolveVariableValue(o.value);
|
|
732
739
|
return a ? { ...t, [r]: { ...o, value: a } } : t;
|
|
733
740
|
}
|
|
734
|
-
const s =
|
|
741
|
+
const s = I(o, e);
|
|
735
742
|
return s ? { ...t, [r]: s } : t;
|
|
736
743
|
}, {}), lt = ({
|
|
737
744
|
input: n = {},
|
|
@@ -748,21 +755,17 @@ ${t}
|
|
|
748
755
|
throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
|
|
749
756
|
const l = [], c = s.getVariables();
|
|
750
757
|
if (i) {
|
|
751
|
-
const
|
|
752
|
-
console.log("[colors/tokenManager] Processing styles for colors..."),
|
|
758
|
+
const g = s.getStyles();
|
|
759
|
+
console.log("[colors/tokenManager] Processing styles for colors..."), g.color && l.push(g.color);
|
|
753
760
|
}
|
|
754
761
|
if (a != null && a.length) {
|
|
755
762
|
console.log(`[colors/tokenManager] Processing ${a.length} variable groups...`);
|
|
756
|
-
const
|
|
757
|
-
|
|
758
|
-
if (p.type === "color")
|
|
759
|
-
return p;
|
|
760
|
-
}).filter(Boolean);
|
|
761
|
-
l.push(...f);
|
|
763
|
+
const g = a.map((d) => c[d]).filter(Boolean);
|
|
764
|
+
l.push(...g);
|
|
762
765
|
}
|
|
763
|
-
const u = l.map((
|
|
764
|
-
(
|
|
765
|
-
(
|
|
766
|
+
const u = l.map((g) => I(g, s)).flatMap(
|
|
767
|
+
(g) => Object.entries(G(g, "")).reduce(
|
|
768
|
+
(d, [p, k]) => [...d, { name: Ve(p), value: k }],
|
|
766
769
|
[]
|
|
767
770
|
)
|
|
768
771
|
);
|
|
@@ -770,7 +773,7 @@ ${t}
|
|
|
770
773
|
console.warn("[colors/tokenManager] No color tokens generated");
|
|
771
774
|
return;
|
|
772
775
|
}
|
|
773
|
-
console.log(`[colors/tokenManager] Generated ${u.length} color tokens`), console.log(`[colors/tokenManager] Writing files to ${e} and ${t}...`), await
|
|
776
|
+
console.log(`[colors/tokenManager] Generated ${u.length} color tokens`), console.log(`[colors/tokenManager] Writing files to ${e} and ${t}...`), await Me({
|
|
774
777
|
colorTokens: u,
|
|
775
778
|
jsonDir: e,
|
|
776
779
|
stylesDir: t,
|
|
@@ -801,11 +804,11 @@ ${r}
|
|
|
801
804
|
n.forEach((a, i) => {
|
|
802
805
|
const l = parseInt(a.name.split("_")[0]), c = [], u = i > 0 ? n[i - 1] : null;
|
|
803
806
|
if (a.value.alignment === "center" && a.value.width && (c.push(`max-width: ${a.value.width};`), c.push("margin-left: auto;"), c.push("margin-right: auto;"), u && u.value.alignment !== "center" && (c.push("padding-left: 0;"), c.push("padding-right: 0;"))), a.value.alignment === "stretch" && u && u.value.alignment !== "stretch" && (c.push("max-width: none;"), c.push("margin-left: 0;"), c.push("margin-right: 0;")), a.value.alignment === "stretch" && (c.push(`padding-left: ${a.value.margin};`), c.push(`padding-right: ${a.value.margin};`)), c.length > 0) {
|
|
804
|
-
const
|
|
807
|
+
const d = Oe(".container", c);
|
|
805
808
|
if (i === 0)
|
|
806
|
-
t.push(
|
|
809
|
+
t.push(d);
|
|
807
810
|
else {
|
|
808
|
-
const p = Pe(l, [
|
|
811
|
+
const p = Pe(l, [d]);
|
|
809
812
|
t.push(p);
|
|
810
813
|
}
|
|
811
814
|
}
|
|
@@ -819,7 +822,7 @@ ${o}
|
|
|
819
822
|
}, Ne = async (n, e, t) => {
|
|
820
823
|
await Be(t, n, e);
|
|
821
824
|
}, Be = async (n, e, t) => {
|
|
822
|
-
await
|
|
825
|
+
await f.delete(n, t), await f.write(n, e, { directory: t });
|
|
823
826
|
}, Le = async ({
|
|
824
827
|
containerTokens: n,
|
|
825
828
|
stylesDir: e,
|
|
@@ -895,7 +898,7 @@ ${o}
|
|
|
895
898
|
throw console.error("[container/tokenManager] Error:", o), o;
|
|
896
899
|
}
|
|
897
900
|
}
|
|
898
|
-
}),
|
|
901
|
+
}), P = (n, e) => {
|
|
899
902
|
if (!e.length) return "";
|
|
900
903
|
const t = e.map((r) => ` ${r}`).join(`
|
|
901
904
|
`);
|
|
@@ -911,9 +914,9 @@ ${t}
|
|
|
911
914
|
},
|
|
912
915
|
{ root: [] }
|
|
913
916
|
), We = (n) => {
|
|
914
|
-
const e =
|
|
917
|
+
const e = P(":root", n.root), t = Object.entries(n).reduce((r, [o, s]) => {
|
|
915
918
|
if (o === "root" || !s.length) return r;
|
|
916
|
-
const a =
|
|
919
|
+
const a = P(Re(o), s);
|
|
917
920
|
return a && r.push(a), r;
|
|
918
921
|
}, []).join(`
|
|
919
922
|
|
|
@@ -925,8 +928,8 @@ ${t}
|
|
|
925
928
|
const e = n.reduce((t, r) => ({ ...t, [r.name]: r.value }), {});
|
|
926
929
|
return JSON.stringify(e);
|
|
927
930
|
}, Ke = async (n, e, t, r, o, s) => {
|
|
928
|
-
await Promise.all([
|
|
929
|
-
const a =
|
|
931
|
+
await Promise.all([f.delete(o, t), f.delete(s, r)]);
|
|
932
|
+
const a = f.write(o, n, { directory: t }), i = f.write(s, e, { directory: r });
|
|
930
933
|
await Promise.all([a, i]);
|
|
931
934
|
}, qe = async ({
|
|
932
935
|
shadowTokens: n,
|
|
@@ -937,7 +940,7 @@ ${t}
|
|
|
937
940
|
}) => {
|
|
938
941
|
const s = Je(n), a = We(s), i = ze(n);
|
|
939
942
|
await Ke(i, a, e, t, r, o);
|
|
940
|
-
},
|
|
943
|
+
}, J = (n, e) => Object.keys(n).reduce(
|
|
941
944
|
(t, r) => {
|
|
942
945
|
const o = n[r], s = e ? `${e}-${r}` : r;
|
|
943
946
|
if (o && typeof o == "object" && "type" in o && "value" in o) {
|
|
@@ -946,7 +949,7 @@ ${t}
|
|
|
946
949
|
};
|
|
947
950
|
return { ...t, ...i };
|
|
948
951
|
}
|
|
949
|
-
const a =
|
|
952
|
+
const a = J(o, s);
|
|
950
953
|
return { ...t, ...a };
|
|
951
954
|
},
|
|
952
955
|
{}
|
|
@@ -969,8 +972,8 @@ ${t}
|
|
|
969
972
|
console.log("[shadows/tokenManager] Processing styles for shadows..."), u.effect && l.push(u.effect);
|
|
970
973
|
}
|
|
971
974
|
const c = l.flatMap(
|
|
972
|
-
(u) => Object.entries(
|
|
973
|
-
(
|
|
975
|
+
(u) => Object.entries(J(u, "")).reduce(
|
|
976
|
+
(g, [d, p]) => [...g, { name: De(d), value: p }],
|
|
974
977
|
[]
|
|
975
978
|
)
|
|
976
979
|
);
|
|
@@ -990,17 +993,17 @@ ${t}
|
|
|
990
993
|
throw console.error("[shadows/tokenManager] ❌ Failed to generate shadows:", i), a instanceof Error && a.stack && console.error("[shadows/tokenManager] Stack trace:", a.stack), a;
|
|
991
994
|
}
|
|
992
995
|
}
|
|
993
|
-
}),
|
|
996
|
+
}), x = (n) => {
|
|
994
997
|
const e = {};
|
|
995
998
|
return Object.entries(n).forEach(([t, r]) => {
|
|
996
999
|
const o = t.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
997
1000
|
e[o] = r;
|
|
998
1001
|
}), e;
|
|
999
1002
|
}, He = (n, e) => {
|
|
1000
|
-
const t = Object.keys(n.breakpoints), r =
|
|
1003
|
+
const t = Object.keys(n.breakpoints), r = x(n.base);
|
|
1001
1004
|
return t.reduce(
|
|
1002
1005
|
(o, s, a) => {
|
|
1003
|
-
const i =
|
|
1006
|
+
const i = x(n.breakpoints[s]);
|
|
1004
1007
|
return a ? [...o, { breakpoint: Number(e[s]), css: i }] : [
|
|
1005
1008
|
{
|
|
1006
1009
|
breakpoint: null,
|
|
@@ -1018,7 +1021,7 @@ ${t}
|
|
|
1018
1021
|
}
|
|
1019
1022
|
]
|
|
1020
1023
|
);
|
|
1021
|
-
},
|
|
1024
|
+
}, N = (n) => Object.keys(n).reduce((e, t) => {
|
|
1022
1025
|
const r = n[t], o = Object.keys(r).map((s) => `${s}: ${r[s]}`).join(";");
|
|
1023
1026
|
return e + `.${t}Typography { ${o} }`;
|
|
1024
1027
|
}, ""), Ue = (n, e) => {
|
|
@@ -1027,17 +1030,17 @@ ${t}
|
|
|
1027
1030
|
l ? (s.breakpoints[l] || (s.breakpoints[l] = {}), s.breakpoints[l][a.name] = c) : s.base[a.name] = c;
|
|
1028
1031
|
}), s),
|
|
1029
1032
|
{ base: {}, breakpoints: {} }
|
|
1030
|
-
), r =
|
|
1033
|
+
), r = N(t.base), o = Object.keys(t.breakpoints).reduce((s, a) => {
|
|
1031
1034
|
const i = t.breakpoints[a];
|
|
1032
|
-
return s + `@media (max-width: ${a}px) { ${
|
|
1035
|
+
return s + `@media (max-width: ${a}px) { ${N(i)} }`;
|
|
1033
1036
|
}, "");
|
|
1034
1037
|
return r + o;
|
|
1035
1038
|
}, Qe = (n) => {
|
|
1036
1039
|
const e = n.reduce((t, r) => ({ ...t, [r.name]: r.value }), {});
|
|
1037
1040
|
return JSON.stringify(e);
|
|
1038
1041
|
}, Xe = async (n, e, t, r, o, s) => {
|
|
1039
|
-
await Promise.all([
|
|
1040
|
-
const a =
|
|
1042
|
+
await Promise.all([f.delete(o, t), f.delete(s, r)]);
|
|
1043
|
+
const a = f.write(o, n, { directory: t }), i = f.write(s, e, { directory: r });
|
|
1041
1044
|
await Promise.all([a, i]);
|
|
1042
1045
|
}, Ye = async ({
|
|
1043
1046
|
typographyTokens: n,
|
|
@@ -1050,33 +1053,33 @@ ${t}
|
|
|
1050
1053
|
}) => {
|
|
1051
1054
|
const i = Ue(n, s), l = Qe(n), c = `${o}${a ? ".module" : ""}.css`, u = `${r}.json`;
|
|
1052
1055
|
await Xe(l, i, e, t, u, c);
|
|
1053
|
-
},
|
|
1056
|
+
}, W = (n, e, t) => Object.keys(n).reduce((r, o) => {
|
|
1054
1057
|
const s = n[o];
|
|
1055
1058
|
if (typeof s != "object" || Array.isArray(s)) return r;
|
|
1056
1059
|
if (!("type" in s) || !("value" in s))
|
|
1057
|
-
return { ...r, [o]:
|
|
1060
|
+
return { ...r, [o]: W(s, e, t) };
|
|
1058
1061
|
if (s.type !== "typography") return r;
|
|
1059
1062
|
const a = s.value, i = Object.entries(a).reduce(
|
|
1060
1063
|
(l, [c, u]) => {
|
|
1061
|
-
const
|
|
1062
|
-
if (
|
|
1063
|
-
|
|
1064
|
-
const p = e.resolveVariableValueString(u,
|
|
1065
|
-
p && (p === u ? l.base = { ...l.base, [c]: p } : l.breakpoints[
|
|
1064
|
+
const g = Object.keys(t.breakpoints);
|
|
1065
|
+
if (g.length)
|
|
1066
|
+
g.forEach((d) => {
|
|
1067
|
+
const p = e.resolveVariableValueString(u, d);
|
|
1068
|
+
p && (p === u ? l.base = { ...l.base, [c]: p } : l.breakpoints[d] = { ...l.breakpoints[d], [c]: p });
|
|
1066
1069
|
});
|
|
1067
1070
|
else {
|
|
1068
|
-
const
|
|
1069
|
-
|
|
1071
|
+
const d = e.resolveVariableValueString(u);
|
|
1072
|
+
d && (l.base = { ...l.base, [c]: d });
|
|
1070
1073
|
}
|
|
1071
1074
|
return l;
|
|
1072
1075
|
},
|
|
1073
1076
|
{ base: {}, breakpoints: {} }
|
|
1074
1077
|
);
|
|
1075
1078
|
return { ...r, [o]: { type: "typography", value: i } };
|
|
1076
|
-
}, {}),
|
|
1079
|
+
}, {}), z = (n, e) => Object.keys(n).reduce((t, r) => {
|
|
1077
1080
|
const o = e ? `${e}-${r}` : r, s = n[r];
|
|
1078
1081
|
if (!("type" in s) || !("value" in s))
|
|
1079
|
-
return { ...t, ...
|
|
1082
|
+
return { ...t, ...z(s, o) };
|
|
1080
1083
|
const a = s.value;
|
|
1081
1084
|
return { ...t, [o]: a };
|
|
1082
1085
|
}, {}), dt = ({
|
|
@@ -1093,20 +1096,20 @@ ${t}
|
|
|
1093
1096
|
const l = [], c = s.getStyles();
|
|
1094
1097
|
console.log("[typography/tokenManager] Processing styles for typography..."), c.text && l.push(c.text);
|
|
1095
1098
|
const u = l.reduce(
|
|
1096
|
-
(
|
|
1097
|
-
...
|
|
1098
|
-
...
|
|
1099
|
+
(d, p) => ({
|
|
1100
|
+
...d,
|
|
1101
|
+
...W(p, s, { breakpoints: n.breakpoints })
|
|
1099
1102
|
}),
|
|
1100
1103
|
{}
|
|
1101
|
-
),
|
|
1102
|
-
([
|
|
1104
|
+
), g = Object.entries(z(u)).map(
|
|
1105
|
+
([d, p]) => ({ name: d, value: p })
|
|
1103
1106
|
);
|
|
1104
|
-
if (
|
|
1107
|
+
if (g.length === 0) {
|
|
1105
1108
|
console.warn("[typography/tokenManager] No typography tokens generated");
|
|
1106
1109
|
return;
|
|
1107
1110
|
}
|
|
1108
|
-
console.log(`[typography/tokenManager] Generated ${
|
|
1109
|
-
typographyTokens:
|
|
1111
|
+
console.log(`[typography/tokenManager] Generated ${g.length} typography tokens`), console.log(`[typography/tokenManager] Writing files to ${e} and ${t}...`), await Ye({
|
|
1112
|
+
typographyTokens: g,
|
|
1110
1113
|
jsonDir: e,
|
|
1111
1114
|
stylesDir: t,
|
|
1112
1115
|
jsonFileName: r,
|
|
@@ -1121,8 +1124,8 @@ ${t}
|
|
|
1121
1124
|
}
|
|
1122
1125
|
});
|
|
1123
1126
|
export {
|
|
1124
|
-
|
|
1125
|
-
|
|
1127
|
+
L as BREAKPOINTS_NAMES,
|
|
1128
|
+
ee as TokenManager,
|
|
1126
1129
|
at as breakpointsFromTokenManager,
|
|
1127
1130
|
it as breakpointsListFromTokenManager,
|
|
1128
1131
|
lt as colorsFromTokenManager,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../src/modules/colors/colorsFromTokenManager/module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../src/modules/colors/colorsFromTokenManager/module.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,WAAW,4BAA4B;IACzC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,6BAA6B;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,6BAA6B;IAC1C,KAAK,CAAC,EAAE,4BAA4B,CAAC;IACrC,MAAM,EAAE,6BAA6B,CAAC;CACzC;AAiED,eAAO,MAAM,sBAAsB,GAAI,uEAGpC,6BAA6B,KAAG,OAyEjC,CAAC"}
|