Skip to content

Commit

Permalink
Fix(exporter-tokens): Use css-variable-prefix token instead of token-…
Browse files Browse the repository at this point in the history
…prefix
  • Loading branch information
crishpeen committed Nov 7, 2024
1 parent 8c17cae commit a4d33bd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion exporters/tokens/generated/exporter.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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?`
`:`
Expand Down
2 changes: 1 addition & 1 deletion exporters/tokens/src/helpers/findTokenPrefix.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion exporters/tokens/tests/fixtures/examplePrefixToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StringToken, Token, TokenType } from '@supernovaio/sdk-exporters';
export const examplePrefixToken = new Map<string, Token>();
examplePrefixToken.set('stringRef', {
id: 'stringRef',
name: 'token-prefix',
name: 'css-variable-prefix',
tokenType: TokenType.string,
parentGroupId: '1',
origin: null,
Expand Down

0 comments on commit a4d33bd

Please sign in to comment.