From a4d33bd9eec3e2058e8fa9d2326e66972d9ac76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kry=C5=A1p=C3=ADn?= Date: Thu, 7 Nov 2024 09:25:03 +0100 Subject: [PATCH] Fix(exporter-tokens): Use css-variable-prefix token instead of token-prefix --- exporters/tokens/generated/exporter.cjs | 2 +- exporters/tokens/src/helpers/findTokenPrefix.ts | 2 +- exporters/tokens/tests/fixtures/examplePrefixToken.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/exporters/tokens/generated/exporter.cjs b/exporters/tokens/generated/exporter.cjs index 3c3ec19d50..313d0310fd 100644 --- a/exporters/tokens/generated/exporter.cjs +++ b/exporters/tokens/generated/exporter.cjs @@ -38,7 +38,7 @@ ${i} }, `}return a===u?`${a}, `:`${a}: ${u}, -`}).join("").slice(0,-1),qt=n=>n.length===4?n.filter((a,u)=>u!==1).join("-"):n.join("-"),Xt=n=>n.length===4?n[1]:"mobile",Zt=(n,a)=>{var y;let u;const i=(y=n.name.match(/\d+/))==null?void 0:y[0],m=zt(n.name.toLowerCase());return n.tokenType!==v.TokenType.color&&i?u=i:u=a?_(m):m,u},Qt=(n,a,u)=>{if(a===v.TokenType.color){const i=`${n.toLowerCase()}${U}`;return u?_(i):`$${i}`}return u?K(n.toLowerCase()):`$${K(n.toLowerCase())}`},fe=/#([A-Fa-f0-9]{6,8})\b/g,Jt=8,ge=4,eo=3,to=n=>n.length%2===0&&[...Array(n.length/2)].every((a,u)=>n[2*u]===n[2*u+1]),oo=n=>n.split("").map((a,u)=>u%2===0?a:"").join(""),ro=n=>n.length===Jt&&n.endsWith("ff")?n.slice(0,-2):n.length===ge&&n.endsWith("f")?n.slice(0,-1):n,Se=n=>{const a=[eo,ge].includes(n.length);let u;return a?u=n:to(n)?u=oo(n):u=n,u=ro(u),`#${u}`},Z=n=>n.replace(fe,a=>Se(a.slice(1))),Q=(n,a,u,i)=>{let m=1;const y=i?`${i}-`:"";return a.split(",").map(r=>r.replace(fe,t=>{const o=`var(--${u}color-${y}${n}-color-${m.toString().padStart(2,"0")}, ${t})`;return m+=1,o})).join(",").replace(/0px/g,"0")},no=(n,a,u,i,m,y)=>{var r,t,o,e;const f=s=>{const{tokenType:T}=n;return T===s};if(f(v.TokenType.dimension)){const s=n,T=I(s,u,m);let c=(r=s.value)==null?void 0:r.measure;c=H(T,c);const p=P.CSSHelper.unitToCSS((t=s.value)==null?void 0:t.unit);return F(T,c,y,p)}if(f(v.TokenType.string)){const s=n,T=I(s,u,m);let c=s.value.text;return c=H(T,c),F(T,c,y)}if(f(v.TokenType.color)){const s=n,T=I(s,u,m);let c=P.CSSHelper.colorTokenValueToCSS(s.value,a,{allowReferences:!0,decimals:3,colorFormat:P.ColorFormat.hex8,tokenToVariableRef:()=>""});return c=Se(c),c=H(T,c),F(T,c,y)}if(f(v.TokenType.shadow)){const s=n,T=I(n,u,m),{value:c,origin:p}=s;let l=P.CSSHelper.shadowTokenValueToCSS(c,a,{allowReferences:!0,decimals:3,colorFormat:P.ColorFormat.hashHex8,tokenToVariableRef:()=>""});const d=m||(o=p==null?void 0:p.name)==null?void 0:o.split("/")[0].toLowerCase();return l=Q(T,l,i,d),l=Z(l),F(T,l,y)}if(f(v.TokenType.gradient)){const s=n,T=I(n,u,m),{value:c,origin:p}=s;let l=P.CSSHelper.gradientTokenValueToCSS(c,a,{allowReferences:!0,colorFormat:P.ColorFormat.hashHex8,decimals:3,tokenToVariableRef:()=>""});l=Rt(l);const d=m||(e=p==null?void 0:p.name)==null?void 0:e.split("/")[0].toLowerCase();return l=Q(T,l,i,d),l=Z(l),F(T,l,y)}return null},ao=(n,a,u,i,m,y,f,r=!1)=>{const o=Dt(n,u,y,m,f).map(e=>({css:no(e,a,u,i,y,r),parentGroupId:e.parentGroupId}));return Nt(o)},io="token-prefix",so=n=>{var i;const a=n.find(m=>m.tokenType===v.TokenType.string&&m.name===io);return((i=a==null?void 0:a.value)==null?void 0:i.text)??""},co=n=>`/* This file was generated by Supernova, don't change manually */ +`}).join("").slice(0,-1),qt=n=>n.length===4?n.filter((a,u)=>u!==1).join("-"):n.join("-"),Xt=n=>n.length===4?n[1]:"mobile",Zt=(n,a)=>{var y;let u;const i=(y=n.name.match(/\d+/))==null?void 0:y[0],m=zt(n.name.toLowerCase());return n.tokenType!==v.TokenType.color&&i?u=i:u=a?_(m):m,u},Qt=(n,a,u)=>{if(a===v.TokenType.color){const i=`${n.toLowerCase()}${U}`;return u?_(i):`$${i}`}return u?K(n.toLowerCase()):`$${K(n.toLowerCase())}`},fe=/#([A-Fa-f0-9]{6,8})\b/g,Jt=8,ge=4,eo=3,to=n=>n.length%2===0&&[...Array(n.length/2)].every((a,u)=>n[2*u]===n[2*u+1]),oo=n=>n.split("").map((a,u)=>u%2===0?a:"").join(""),ro=n=>n.length===Jt&&n.endsWith("ff")?n.slice(0,-2):n.length===ge&&n.endsWith("f")?n.slice(0,-1):n,Se=n=>{const a=[eo,ge].includes(n.length);let u;return a?u=n:to(n)?u=oo(n):u=n,u=ro(u),`#${u}`},Z=n=>n.replace(fe,a=>Se(a.slice(1))),Q=(n,a,u,i)=>{let m=1;const y=i?`${i}-`:"";return a.split(",").map(r=>r.replace(fe,t=>{const o=`var(--${u}color-${y}${n}-color-${m.toString().padStart(2,"0")}, ${t})`;return m+=1,o})).join(",").replace(/0px/g,"0")},no=(n,a,u,i,m,y)=>{var r,t,o,e;const f=s=>{const{tokenType:T}=n;return T===s};if(f(v.TokenType.dimension)){const s=n,T=I(s,u,m);let c=(r=s.value)==null?void 0:r.measure;c=H(T,c);const p=P.CSSHelper.unitToCSS((t=s.value)==null?void 0:t.unit);return F(T,c,y,p)}if(f(v.TokenType.string)){const s=n,T=I(s,u,m);let c=s.value.text;return c=H(T,c),F(T,c,y)}if(f(v.TokenType.color)){const s=n,T=I(s,u,m);let c=P.CSSHelper.colorTokenValueToCSS(s.value,a,{allowReferences:!0,decimals:3,colorFormat:P.ColorFormat.hex8,tokenToVariableRef:()=>""});return c=Se(c),c=H(T,c),F(T,c,y)}if(f(v.TokenType.shadow)){const s=n,T=I(n,u,m),{value:c,origin:p}=s;let l=P.CSSHelper.shadowTokenValueToCSS(c,a,{allowReferences:!0,decimals:3,colorFormat:P.ColorFormat.hashHex8,tokenToVariableRef:()=>""});const d=m||(o=p==null?void 0:p.name)==null?void 0:o.split("/")[0].toLowerCase();return l=Q(T,l,i,d),l=Z(l),F(T,l,y)}if(f(v.TokenType.gradient)){const s=n,T=I(n,u,m),{value:c,origin:p}=s;let l=P.CSSHelper.gradientTokenValueToCSS(c,a,{allowReferences:!0,colorFormat:P.ColorFormat.hashHex8,decimals:3,tokenToVariableRef:()=>""});l=Rt(l);const d=m||(e=p==null?void 0:p.name)==null?void 0:e.split("/")[0].toLowerCase();return l=Q(T,l,i,d),l=Z(l),F(T,l,y)}return null},ao=(n,a,u,i,m,y,f,r=!1)=>{const o=Dt(n,u,y,m,f).map(e=>({css:no(e,a,u,i,y,r),parentGroupId:e.parentGroupId}));return Nt(o)},io="css-variable-prefix",so=n=>{var i;const a=n.find(m=>m.tokenType===v.TokenType.string&&m.name===io);return((i=a==null?void 0:a.value)==null?void 0:i.text)??""},co=n=>`/* This file was generated by Supernova, don't change manually */ ${n}`,lo=(n,a,u)=>n.filter(i=>{var r,t;const m=i.tokenType===a,y=(t=(r=i.origin)==null?void 0:r.name)==null?void 0:t.includes(u),f=!(i.tokenType===v.TokenType.typography&&i.name.includes("-Underline"));return m&&y&&f}),be=(n,a)=>n!==a-1?` `:` diff --git a/exporters/tokens/src/helpers/findTokenPrefix.ts b/exporters/tokens/src/helpers/findTokenPrefix.ts index 1c8376d9c2..48cb8b0b7f 100644 --- a/exporters/tokens/src/helpers/findTokenPrefix.ts +++ b/exporters/tokens/src/helpers/findTokenPrefix.ts @@ -1,6 +1,6 @@ import { StringToken, Token, TokenType } from '@supernovaio/sdk-exporters'; -const TOKEN_PREFIX_NAME = 'token-prefix'; +const TOKEN_PREFIX_NAME = 'css-variable-prefix'; export const findTokenPrefix = (tokens: Token[]): string => { const prefixToken = tokens.find( diff --git a/exporters/tokens/tests/fixtures/examplePrefixToken.ts b/exporters/tokens/tests/fixtures/examplePrefixToken.ts index 3dd97c703d..581579ca45 100644 --- a/exporters/tokens/tests/fixtures/examplePrefixToken.ts +++ b/exporters/tokens/tests/fixtures/examplePrefixToken.ts @@ -3,7 +3,7 @@ import { StringToken, Token, TokenType } from '@supernovaio/sdk-exporters'; export const examplePrefixToken = new Map(); examplePrefixToken.set('stringRef', { id: 'stringRef', - name: 'token-prefix', + name: 'css-variable-prefix', tokenType: TokenType.string, parentGroupId: '1', origin: null,