Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cobalt-ui/core

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cobalt-ui/core - npm Package Compare versions

Comparing version 0.3.4 to 0.4.0

10

CHANGELOG.md
# @cobalt-ui/core
## 0.4.0
### Minor Changes
- 8845084: Use kebab-case properties for typography tokens, allow all CSS properties
### Patch Changes
- Fix token value 0
## 0.3.4

@@ -4,0 +14,0 @@

15

dist/@types/token.d.ts

@@ -115,11 +115,12 @@ export declare type Group = {

export interface TypographyValue {
fontName: FontToken['value'];
fontSize: DimensionToken['value'];
fontStyle: string;
fontWeight: number | FontWeightName;
letterSpacing: DimensionToken['value'];
lineHeight: string | number;
'font-family': FontToken['value'];
'font-size': DimensionToken['value'];
'font-style': string;
'font-weight': number | FontWeightName;
'letter-spacing': DimensionToken['value'];
'line-height': string | number;
'text-transform': string;
}
export interface ParsedTypographyValue extends TypographyValue {
fontName: ParsedFontToken['value'];
'font-family': ParsedFontToken['value'];
}

@@ -126,0 +127,0 @@ export interface TypographyToken extends TokenBase<Partial<TypographyValue>> {

@@ -1,3 +0,3 @@

function E(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ee(e){return e==null?!0:typeof e=="string"||Array.isArray(e)?e.length===0:E(e)?Object.keys(e).length===0:!1}function T(e,r){if(e==null&&r.undefined)return r.undefined(e);if(typeof e=="string"&&r.string)return r.string(e);if(typeof e=="number"&&r.number)return r.number(e);if(Array.isArray(e)&&r.array)return r.array(e);if(E(e)&&r.object)return r.object(e);if(r.default)return r.default(e)}function B(e,r){return r===void 0&&(r=15),+parseFloat(Number(e).toPrecision(r))}function x(e){var r=e.toString().split(/[eE]/),n=(r[0].split(".")[1]||"").length-+(r[1]||0);return n>0?n:0}function V(e){if(e.toString().indexOf("e")===-1)return Number(e.toString().replace(".",""));var r=x(e);return r>0?B(Number(e)*Math.pow(10,r)):Number(e)}function D(e){ne&&(e>Number.MAX_SAFE_INTEGER||e<Number.MIN_SAFE_INTEGER)&&console.warn(e+" is beyond boundary when transfer to integer, the results may not be accurate")}function O(e,r){var n=e[0],t=e[1],o=e.slice(2),a=r(n,t);return o.forEach(function(f){a=r(a,f)}),a}function z(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return O(e,z);var n=e[0],t=e[1],o=V(n),a=V(t),f=x(n)+x(t),l=o*a;return D(l),l/Math.pow(10,f)}function re(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return O(e,re);var n=e[0],t=e[1],o=Math.pow(10,Math.max(x(n),x(t)));return(z(n,o)+z(t,o))/o}function te(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return O(e,te);var n=e[0],t=e[1],o=Math.pow(10,Math.max(x(n),x(t)));return(z(n,o)-z(t,o))/o}function q(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return O(e,q);var n=e[0],t=e[1],o=V(n),a=V(t);return D(o),D(a),z(o/a,B(Math.pow(10,x(t)-x(n))))}function ke(e,r){var n=Math.pow(10,r),t=q(Math.round(Math.abs(z(e,n))),n);return e<0&&t!==0&&(t=z(t,-1)),t}var ne=!0;function Ee(e){e===void 0&&(e=!0),ne=e}var xe={strip:B,plus:re,minus:te,times:z,divide:q,round:ke,digitLength:x,float2Fixed:V,enableBoundaryChecking:Ee},L=xe,Ae={black:0,silver:12632256,gray:8421504,white:16777215,maroon:8388608,red:16711680,purple:8388736,fuchsia:16711935,green:32768,lime:65280,olive:8421376,yellow:16776960,navy:128,blue:255,teal:32896,aqua:65535,orange:16753920,aliceblue:15792383,antiquewhite:16444375,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,blanchedalmond:16772045,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchard:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:3100495,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavendar:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,limegreen:3329330,linen:16445670,magenta:16711935,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,oldlace:16643558,olivedrab:7048739,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,whitesmoke:16119285,yellowgreen:10145074,rebeccapurple:6697881},oe=Ae;function I(e,r=2){let n=e;for(;n.length<r;)n=`0${n}`;return n}function p(e,r,n){return Math.min(Math.max(e,r),n)}function ie(e,r,n=.5){if(!e||!e&&!r)return;let t=typeof e=="number"?e:0,o;typeof e=="string"&&(t=parseFloat(e),o=e.replace(t.toString(),""));let a=typeof r=="number"?r:0,f;if(typeof r=="string"&&(a=parseFloat(r),f=r.replace(a.toString(),"")),o&&f&&o!==f)return;let l=t*(1-n)+a*n;return o||f?`${l}${o||f}`:l}L.enableBoundaryChecking(!1);var w=5,R="(\\s*,\\s*|\\s+)",$="-?[0-9]+(\\.[0-9]+)?",ze=/^#?[0-9a-f]{3,8}$/i,ae=new RegExp(["^rgba?\\(\\s*",`(?<R>${$}%?)`,R,`(?<G>${$}%?)`,R,`(?<B>${$}%?)`,`(${R}(?<A>${$}%?))?`,"\\s*\\)$"].join(""),"i"),se=new RegExp(["^hsla?\\(\\s*",`(?<H>${$})`,R,`(?<S>${$})%`,R,`(?<L>${$})%`,`(${R}(?<A>${$})%?)?`,"\\s*\\)$"].join(""),"i"),le=new RegExp(["^color\\(\\s*display-p3\\s+",`(?<R>${$}%?)`,"\\s+",`(?<G>${$}%?)`,"\\s+",`(?<B>${$}%?)`,`(\\s*\\/\\s*(?<A>${$}%?))?`,"\\s*\\)$"].join(""),"i"),fe=/^linear-gradient\((.*)\);?$/,ue=/^radial-gradient\((.*)\);?$/,ce=/^conic-gradient\((.*)\);?$/,je=/\s[^\s]+$/,{round:d,strip:me}=L;function j(e){let r=C(e);return{get hex(){return`#${r.map((n,t)=>t<3?I(d(n*255,0).toString(16),2):n<1?d(n*255,0).toString(16):"").join("")}`},get hexVal(){let n=r.map((t,o)=>o<3?I(d(t*255,0).toString(16),2):t<1?I((t*256).toString(16),2):"");return parseInt(`0x${n.join("")}`,16)},get rgb(){return r[3]==1?`rgb(${d(r[0]*255,0)}, ${d(r[1]*255,0)}, ${d(r[2]*255,0)})`:`rgba(${d(r[0]*255,0)}, ${d(r[1]*255,0)}, ${d(r[2]*255,0)}, ${d(r[3],w)})`},rgbVal:r,get rgba(){return`rgba(${d(r[0]*255,0)}, ${d(r[1]*255,0)}, ${d(r[2]*255,0)}, ${d(r[3],w)})`},rgbaVal:r,get hsl(){let[n,t,o,a]=H(r);return`hsl(${n}, ${me(t*100)}%, ${me(o*100)}%, ${d(a,w)})`},get hslVal(){return H(r)},get p3(){let[n,t,o,a]=r;return`color(display-p3 ${d(n,w)} ${d(t,w)} ${d(o,w)}${a<1?`/${d(a,w)}`:""})`}}}function N(e,r,n=.5,t=2.2){let o=p(n,0,1),a=1-o,f=o,l=1/t,s=t,m=j(e).rgbVal,c=j(r).rgbVal,i=m[0]**s,y=m[1]**s,u=m[2]**s,g=m[3],h=c[0]**s,b=c[1]**s,v=c[2]**s,k=c[3];return j([p((i**s*a+h**s*f)**l,0,1),p((y**s*a+b**s*f)**l,0,1),p((u**s*a+v**s*f)**l,0,1),g*a+k*f])}function C(e){function r(n){let t=I(p(n,0,4294967295).toString(16),6);return[parseInt(t.substring(0,2),16)/255,parseInt(t.substring(2,4),16)/255,parseInt(t.substring(4,6),16)/255,parseInt(t.substring(6,8)||"ff",16)/255]}if(Array.isArray(e)){if(e.some(n=>typeof n!="number"))throw new Error(`Color array must be numbers, received ${e}`);if(e.length<3||e.length>4)throw new Error(`Expected [R, G, B, A?], received ${e}`);return e.map(n=>p(n,0,1))}if(typeof e=="number")return r(e);if(typeof e=="string"){let n=e.trim();if(!n)throw new Error("Expected color, received empty string");if(typeof oe[n.toLowerCase()]=="number")return r(oe[n]);if(ze.test(n)){let t=n.replace("#",""),o=parseInt(t.length<6?t.split("").map(a=>`${a}${a}`).join(""):t,16);return r(o)}if(ae.test(n)){let t=ae.exec(n).groups||{};if(![t.R,t.G,t.B].every(s=>s.includes("%")||!s.includes("%")))throw new Error("Mix of integers and %");let o=parseFloat(t.R)/(t.R.includes("%")?100:255),a=parseFloat(t.G)/(t.G.includes("%")?100:255),f=parseFloat(t.B)/(t.B.includes("%")?100:255),l=1;return t.A&&(l=parseFloat(t.A),t.A.includes("%")&&(l/=100)),[p(o,0,1),p(a,0,1),p(f,0,1),p(l,0,1)]}if(se.test(n)){let t=se.exec(n).groups||{},o=parseFloat(t.H),a=parseFloat(t.S)/100,f=parseFloat(t.L)/100,l=1;return t.A&&(l=parseFloat(t.A),t.A.includes("%")&&(l/=100)),pe([o,p(a,0,1),p(f,0,1),p(l,0,1)])}if(le.test(n)){let t=le.exec(n).groups||{},o=parseFloat(t.R);t.R.includes("%")&&(o/=100);let a=parseFloat(t.G);t.G.includes("%")&&(a/=100);let f=parseFloat(t.B);t.B.includes("%")&&(f/=100);let l=1;return t.A&&(l=parseFloat(t.A),t.A.includes("%")&&(l/=100)),[p(o,0,1),p(a,0,1),p(f,0,1),p(l,0,1)]}}throw new Error(`Unable to parse color "${e}"`)}function Me(e,r){let n=C(e);return j([n[0],n[1],n[2],p(r,0,1)])}function de(e,r){let n=p(r,-1,1);return n>=0?N(e,[0,0,0,1],n):ge(e,-n)}function ge(e,r){let n=p(r,-1,1);return n>=0?N(e,[1,1,1,1],n):de(e,-n)}function pe(e){let[r,n,t,o]=e;r=Math.abs(r%360);let a=n*(1-Math.abs(2*t-1)),f=a*(1-Math.abs(r/60%2-1)),l=0,s=0,m=0;0<=r&&r<60?(l=a,s=f):60<=r&&r<120?(l=f,s=a):120<=r&&r<180?(s=a,m=f):180<=r&&r<240?(s=f,m=a):240<=r&&r<300?(l=f,m=a):300<=r&&r<360&&(l=a,m=f);let c=t-a/2;return[d(l+c,w),d(s+c,w),d(m+c,w),d(o,w)]}function H(e){let[r,n,t,o]=e,a=Math.max(r,n,t),f=Math.min(r,n,t),l=0,s=0,m=(a+f)/2;if(a==f)return[l,s,L.round(m,4),o];let c=a-f;if(c!=0){switch(a){case r:l=60*(n-t)/c;break;case n:l=60*(2+(t-r)/c);break;case t:l=60*(4+(r-n)/c);break}for(;l<0;)l+=360}return m!=0&&m!=1&&(s=(a-m)/Math.min(m,1-m)),[d(l,w-2),d(s,w),d(m,w),o]}function Re(e,r=!1){let n=e.trim(),t="linear-gradient",o,a=[];if(fe.test(n))a=n.match(fe)[1].split(",").map(l=>l.trim()),(a[0].includes("deg")||a[0].includes("turn")||a[0].includes("to "))&&(o=a.shift());else if(ue.test(n))t="radial-gradient",a=n.match(ue)[1].split(",").map(l=>l.trim()),(a[0].includes("circle")||a[0].includes("ellipse")||a[0].includes("closest-")||a[0].includes("farthest-"))&&(o=a.shift());else if(ce.test(n))t="conic-gradient",a=n.match(ce)[1].split(",").map(l=>l.trim()),a[0].includes("from")&&(o=a.shift());else throw new Error(`Unable to parse gradient "${e}"`);let f=[];for(let l of a){let s="",m=l,c=l.match(je);if(c&&(s=c[0].trim(),m=l.replace(s,"").trim()),f.length){let y=f[f.length-1],{pos:u,color:g}=y;if(!(ie(u,s)<=0||j(g).hex===j(m).hex))for(let h=1;h<=3;h++){let b=.25*h,v=N(g,m,b);f.push({color:r?v.p3:v.hex,pos:ie(u||0,s,b)})}}let i=j(m);f.push({color:r?i.p3:i.hex,pos:s})}return`${t}(${[...o?[o]:[],...f.map(({color:l,pos:s})=>`${l}${s?` ${s}`:""}`)].join(",")})`}var he={alpha:Me,darken:de,from:j,gammaGradient:Re,hslToRGB:pe,lighten:ge,mix:N,parse:C,rgbToHSL:H};function M(e){if(!e)throw new Error("missing value");if(typeof e=="string"||typeof e=="number")try{return he.from(e).hex}catch{throw new Error(`invalid color "${e}"`)}throw new Error(`expected string, received ${typeof e}`)}function F(e){if(!e)throw new Error("missing value");if(typeof e=="string")return[e];if(Array.isArray(e)){if(e.every(r=>!!r&&typeof r=="string"))return e;throw new Error("expected array of strings")}throw new Error(`expected string or array of strings, received ${typeof e}`)}var Se=/^\d+(\.\d+)?(ms|s)$/;function S(e){if(typeof e=="number")return`${e}ms`;if(typeof e=="string"){if(parseFloat(e)===0)return"0ms";if(Se.test(e))return e;throw new Error(`invalid duration "${e}"`)}throw new Error(`expected string, received ${typeof e}`)}function A(e){if(typeof e=="number"){if(e===0)return"0";throw new Error("missing units")}if(typeof e=="string")return parseFloat(e)===0?"0":e;throw new Error(`expected string, received ${typeof e}`)}function _(e){if(!e)throw new Error("missing value");if(!Array.isArray(e)||e.length!==4||e.some(r=>typeof r!="number"))throw new Error(`expected [\u{1D465}1, \u{1D466}1, \u{1D465}2, \u{1D466}2], received ${e}`);return[Math.max(0,Math.min(1,e[0])),e[1],Math.max(0,Math.min(1,e[2])),e[3]]}function W(e){if(!e)throw new Error("missing value");if(typeof e=="string")return e;throw new Error(`expected string, received ${typeof e}`)}function U(e){if(!e)throw new Error("missing value");if(typeof e=="string")try{return e}catch{throw new Error(`Invalid URL "${e}" (use "type": "file" for local paths)`)}throw new Error(`expected string, received ${typeof e}`)}function P(e){if(!e)throw new Error("missing value");if(typeof e!="object"||Array.isArray(e))throw new Error("invalid shadow");let r=e;return["offset-x","offset-y","blur","spread","color"].forEach(n=>{if(typeof r[n]=="number"&&r[n]>0)throw new Error(`${n} missing units`);if((n==="offset-x"||n==="offset-y")&&typeof r[n]!="string"&&r[n]!==0)throw new Error(`missing ${n}`)}),{"offset-x":A(r["offset-x"]||"0"),"offset-y":A(r["offset-y"]||"0"),blur:A(r.blur||"0"),spread:A(r.spread||"0"),color:M(r.color)}}function X(e){if(!e)throw new Error("missing value");if(!Array.isArray(e))throw new Error(`expected array of gradient stops, received ${typeof e}`);if(e.some(r=>!r||!r.color))throw new Error("all gradient stops must have color");return e.map(r=>({color:M(r.color),position:typeof r.position=="number"?Math.max(0,Math.min(1,r.position)):void 0}))}var ye=new Map([["thin",100],["hairline",100],["extra-light",200],["ultra-light",200],["light",300],["normal",400],["regular",400],["book",400],["medium",500],["semi-bold",600],["demi-bold",600],["bold",700],["extra-bold",800],["ultra-bold",800],["black",900],["heavy",900],["extra-black",950],["ultra-black",950]]);function J(e){if(!e)throw new Error("missing value");if(typeof e!="object"||Array.isArray(e))throw new Error(`expected object, received ${Array.isArray(e)?"array":typeof e}`);if(!Object.keys(e).length)throw new Error("must specify at least 1 font property");let r=e,n;if(typeof r.fontWeight=="string"){let o=ye.get(r.fontWeight);if(o)n=o;else throw new Error(`invalid font weight "${r.fontWeight}", use number (1-999) or any of the following names: ${[...ye.values()].join(`
- `)}`)}else typeof r.fontWeight=="number"&&(n=Math.max(0,Math.min(999,r.fontWeight)));let t={};return r.fontName&&(t.fontName=F(r.fontName)),r.fontSize&&(t.fontSize=A(r.fontSize)),r.fontStyle&&(t.fontStyle=r.fontStyle),n&&(t.fontWeight=n),r.letterSpacing&&(t.letterSpacing=r.letterSpacing),r.lineHeight&&(t.lineHeight=r.lineHeight),t}var ve=[.25,.1,.25,1];function K(e){if(!e)throw new Error("missing value");if(typeof e!="object"||Array.isArray(e))throw new Error("invalid transition format, e");if(!Object.keys(e).length)throw new Error("At least 1 transition property is required");let r=e;return{duration:S(r.duration||"0"),delay:S(r.delay||"0"),"timing-function":_(r["timing-function"]||ve)}}var G=/^\{([^}]+)\}$/;function Q(e){let r=[],n=[],t={result:{metadata:{},tokens:[]}};if(!e||typeof e!="object"||Array.isArray(e))return r.push(`Invalid schema type. Expected object, received "${Array.isArray(e)?"Array":typeof e}"`),t.errors=r,t;e.metadata&&E(e.metadata)&&(t.result.metadata=e.metadata);let o={};function a(i,y=[],u={requiredModes:[]}){if(!(!i||!E(i)))for(let[g,h]of Object.entries(i)){if(!h||!E(h)){r.push(`${g}: unexpected token format "${h}"`);continue}if(g.includes(".")||g.includes("#")){r.push(`${g}: invalid name. Names can\u2019t include "." or "#".`);continue}Object.keys(h).length||r.push(`${g}: groups can\u2019t be empty`);let b={_original:{...h},_group:{id:y.join(".")||".",...u||{}},id:y.concat(g).join("."),type:h.type||u.type,...h};if(!!b.value){if(ee(b.value)){r.push(`${b.id}: missing value`);continue}if(!!b.mode&&!E(b.mode)&&r.push(`${b.id}: "mode" must be an object`),u.requiredModes.length)for(let k of u.requiredModes)(b.mode||{})[k]||r.push(`${b.id}: missing mode "${k}" required from parent group`);o[b.id]=b}else{let{metadata:k,...Z}=h,we={...u,...k||{}};if(!!k&&!E(k)&&r.push(`${g}: "metadata" must be an object, received ${Array.isArray(k)?"array":typeof k}`),Object.values(Z).every($e=>E($e))){a(Z,[...y,g],we);continue}throw new Error(`${g}: missing type`)}}}let{metadata:f,...l}=e;if(a(l,[],{requiredModes:[],...f||[]}),r.length)return t.errors=r,t;let s={};for(let i of Object.values(o)){s[i.id]=i.value;for(let[y,u]of Object.entries(i.mode||{}))s[`${i.id}#${y}`]=u}function m(i,y){return T(y,{default(u){return u},string(u){if(!G.test(u))return u;let g=be(u);if(!s[g])throw new Error(`${i}: can\u2019t find ${u}`);let h=s[g];if(typeof h=="string"&&G.test(h)&&i===be(h))throw new Error(`${i}: can\u2019t reference circular alias ${u}`);return s[g]},array(u){return u.map(g=>m(i,g))},object(u){for(let g of Object.keys(u))u[g]=m(i,u[g]);return u}})}for(;Y(s);)try{for(let[i,y]of Object.entries(s))s[i]=m(i,y)}catch(i){r.push(i.message||i);break}if(r.length)return t.errors=r,t;function c(i,y){if(!!o[i].mode)for(let u of Object.keys(o[i].mode||{}))o[i].mode[u]=y(s[`${i}#${u}`])}for(let[i,y]of Object.entries(o))try{switch(y.type){case"color":o[i].value=M(s[i]),c(i,M);break;case"dimension":o[i].value=A(s[i]),c(i,A);break;case"font":o[i].value=F(s[i]),c(i,F);break;case"duration":o[i].value=S(s[i]),c(i,S);break;case"cubic-bezier":o[i].value=_(s[i]),c(i,_);break;case"file":o[i].value=W(s[i]),c(i,W);break;case"url":o[i].value=U(s[i]),c(i,U);break;case"transition":o[i].value=K(s[i]),c(i,K);break;case"shadow":o[i].value=P(s[i]),c(i,P);break;case"gradient":o[i].value=X(s[i]),c(i,X);break;case"typography":o[i].value=J(s[i]),c(i,J);break;default:o[i].value=s[i],c(i,u=>u);break}}catch(u){r.push(`${i}: ${u.message||u}`)}return r.length&&(t.errors=r),n.length&&(t.warnings=n),t.result.tokens=Object.values(o),t}function Y(e){return Object.values(e).some(r=>T(r,{default:()=>!1,string:n=>G.test(n),array:n=>n.some(t=>typeof t=="string"?G.test(t):E(t)?Y(t):!1),object:n=>Y(n)}))}function be(e){let r=e.match(G);return r?r[1]:e}var mr={parse:Q};export{mr as default,Q as parse};
function E(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ee(e){return e==null?!0:typeof e=="string"||Array.isArray(e)?e.length===0:E(e)?Object.keys(e).length===0:!1}function B(e,r){if(e==null&&r.undefined)return r.undefined(e);if(typeof e=="string"&&r.string)return r.string(e);if(typeof e=="number"&&r.number)return r.number(e);if(Array.isArray(e)&&r.array)return r.array(e);if(E(e)&&r.object)return r.object(e);if(r.default)return r.default(e)}function D(e,r){return r===void 0&&(r=15),+parseFloat(Number(e).toPrecision(r))}function x(e){var r=e.toString().split(/[eE]/),n=(r[0].split(".")[1]||"").length-+(r[1]||0);return n>0?n:0}function F(e){if(e.toString().indexOf("e")===-1)return Number(e.toString().replace(".",""));var r=x(e);return r>0?D(Number(e)*Math.pow(10,r)):Number(e)}function N(e){ne&&(e>Number.MAX_SAFE_INTEGER||e<Number.MIN_SAFE_INTEGER)&&console.warn(e+" is beyond boundary when transfer to integer, the results may not be accurate")}function G(e,r){var n=e[0],t=e[1],o=e.slice(2),i=r(n,t);return o.forEach(function(f){i=r(i,f)}),i}function j(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return G(e,j);var n=e[0],t=e[1],o=F(n),i=F(t),f=x(n)+x(t),l=o*i;return N(l),l/Math.pow(10,f)}function re(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return G(e,re);var n=e[0],t=e[1],o=Math.pow(10,Math.max(x(n),x(t)));return(j(n,o)+j(t,o))/o}function te(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return G(e,te);var n=e[0],t=e[1],o=Math.pow(10,Math.max(x(n),x(t)));return(j(n,o)-j(t,o))/o}function q(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return G(e,q);var n=e[0],t=e[1],o=F(n),i=F(t);return N(o),N(i),j(o/i,D(Math.pow(10,x(t)-x(n))))}function ke(e,r){var n=Math.pow(10,r),t=q(Math.round(Math.abs(j(e,n))),n);return e<0&&t!==0&&(t=j(t,-1)),t}var ne=!0;function Ee(e){e===void 0&&(e=!0),ne=e}var xe={strip:D,plus:re,minus:te,times:j,divide:q,round:ke,digitLength:x,float2Fixed:F,enableBoundaryChecking:Ee},C=xe,Ae={black:0,silver:12632256,gray:8421504,white:16777215,maroon:8388608,red:16711680,purple:8388736,fuchsia:16711935,green:32768,lime:65280,olive:8421376,yellow:16776960,navy:128,blue:255,teal:32896,aqua:65535,orange:16753920,aliceblue:15792383,antiquewhite:16444375,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,blanchedalmond:16772045,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchard:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:3100495,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavendar:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,limegreen:3329330,linen:16445670,magenta:16711935,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,oldlace:16643558,olivedrab:7048739,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,whitesmoke:16119285,yellowgreen:10145074,rebeccapurple:6697881},oe=Ae;function I(e,r=2){let n=e;for(;n.length<r;)n=`0${n}`;return n}function g(e,r,n){return Math.min(Math.max(e,r),n)}function ie(e,r,n=.5){if(!e||!e&&!r)return;let t=typeof e=="number"?e:0,o;typeof e=="string"&&(t=parseFloat(e),o=e.replace(t.toString(),""));let i=typeof r=="number"?r:0,f;if(typeof r=="string"&&(i=parseFloat(r),f=r.replace(i.toString(),"")),o&&f&&o!==f)return;let l=t*(1-n)+i*n;return o||f?`${l}${o||f}`:l}C.enableBoundaryChecking(!1);var w=5,R="(\\s*,\\s*|\\s+)",$="-?[0-9]+(\\.[0-9]+)?",je=/^#?[0-9a-f]{3,8}$/i,ae=new RegExp(["^rgba?\\(\\s*",`(?<R>${$}%?)`,R,`(?<G>${$}%?)`,R,`(?<B>${$}%?)`,`(${R}(?<A>${$}%?))?`,"\\s*\\)$"].join(""),"i"),se=new RegExp(["^hsla?\\(\\s*",`(?<H>${$})`,R,`(?<S>${$})%`,R,`(?<L>${$})%`,`(${R}(?<A>${$})%?)?`,"\\s*\\)$"].join(""),"i"),le=new RegExp(["^color\\(\\s*display-p3\\s+",`(?<R>${$}%?)`,"\\s+",`(?<G>${$}%?)`,"\\s+",`(?<B>${$}%?)`,`(\\s*\\/\\s*(?<A>${$}%?))?`,"\\s*\\)$"].join(""),"i"),fe=/^linear-gradient\((.*)\);?$/,ue=/^radial-gradient\((.*)\);?$/,ce=/^conic-gradient\((.*)\);?$/,Me=/\s[^\s]+$/,{round:d,strip:me}=C;function M(e){let r=L(e);return{get hex(){return`#${r.map((n,t)=>t<3?I(d(n*255,0).toString(16),2):n<1?d(n*255,0).toString(16):"").join("")}`},get hexVal(){let n=r.map((t,o)=>o<3?I(d(t*255,0).toString(16),2):t<1?I((t*256).toString(16),2):"");return parseInt(`0x${n.join("")}`,16)},get rgb(){return r[3]==1?`rgb(${d(r[0]*255,0)}, ${d(r[1]*255,0)}, ${d(r[2]*255,0)})`:`rgba(${d(r[0]*255,0)}, ${d(r[1]*255,0)}, ${d(r[2]*255,0)}, ${d(r[3],w)})`},rgbVal:r,get rgba(){return`rgba(${d(r[0]*255,0)}, ${d(r[1]*255,0)}, ${d(r[2]*255,0)}, ${d(r[3],w)})`},rgbaVal:r,get hsl(){let[n,t,o,i]=H(r);return`hsl(${n}, ${me(t*100)}%, ${me(o*100)}%, ${d(i,w)})`},get hslVal(){return H(r)},get p3(){let[n,t,o,i]=r;return`color(display-p3 ${d(n,w)} ${d(t,w)} ${d(o,w)}${i<1?`/${d(i,w)}`:""})`}}}function T(e,r,n=.5,t=2.2){let o=g(n,0,1),i=1-o,f=o,l=1/t,s=t,m=M(e).rgbVal,c=M(r).rgbVal,a=m[0]**s,y=m[1]**s,u=m[2]**s,p=m[3],h=c[0]**s,b=c[1]**s,V=c[2]**s,k=c[3];return M([g((a**s*i+h**s*f)**l,0,1),g((y**s*i+b**s*f)**l,0,1),g((u**s*i+V**s*f)**l,0,1),p*i+k*f])}function L(e){function r(n){let t=I(g(n,0,4294967295).toString(16),6);return[parseInt(t.substring(0,2),16)/255,parseInt(t.substring(2,4),16)/255,parseInt(t.substring(4,6),16)/255,parseInt(t.substring(6,8)||"ff",16)/255]}if(Array.isArray(e)){if(e.some(n=>typeof n!="number"))throw new Error(`Color array must be numbers, received ${e}`);if(e.length<3||e.length>4)throw new Error(`Expected [R, G, B, A?], received ${e}`);return e.map(n=>g(n,0,1))}if(typeof e=="number")return r(e);if(typeof e=="string"){let n=e.trim();if(!n)throw new Error("Expected color, received empty string");if(typeof oe[n.toLowerCase()]=="number")return r(oe[n]);if(je.test(n)){let t=n.replace("#",""),o=parseInt(t.length<6?t.split("").map(i=>`${i}${i}`).join(""):t,16);return r(o)}if(ae.test(n)){let t=ae.exec(n).groups||{};if(![t.R,t.G,t.B].every(s=>s.includes("%")||!s.includes("%")))throw new Error("Mix of integers and %");let o=parseFloat(t.R)/(t.R.includes("%")?100:255),i=parseFloat(t.G)/(t.G.includes("%")?100:255),f=parseFloat(t.B)/(t.B.includes("%")?100:255),l=1;return t.A&&(l=parseFloat(t.A),t.A.includes("%")&&(l/=100)),[g(o,0,1),g(i,0,1),g(f,0,1),g(l,0,1)]}if(se.test(n)){let t=se.exec(n).groups||{},o=parseFloat(t.H),i=parseFloat(t.S)/100,f=parseFloat(t.L)/100,l=1;return t.A&&(l=parseFloat(t.A),t.A.includes("%")&&(l/=100)),ge([o,g(i,0,1),g(f,0,1),g(l,0,1)])}if(le.test(n)){let t=le.exec(n).groups||{},o=parseFloat(t.R);t.R.includes("%")&&(o/=100);let i=parseFloat(t.G);t.G.includes("%")&&(i/=100);let f=parseFloat(t.B);t.B.includes("%")&&(f/=100);let l=1;return t.A&&(l=parseFloat(t.A),t.A.includes("%")&&(l/=100)),[g(o,0,1),g(i,0,1),g(f,0,1),g(l,0,1)]}}throw new Error(`Unable to parse color "${e}"`)}function ze(e,r){let n=L(e);return M([n[0],n[1],n[2],g(r,0,1)])}function de(e,r){let n=g(r,-1,1);return n>=0?T(e,[0,0,0,1],n):pe(e,-n)}function pe(e,r){let n=g(r,-1,1);return n>=0?T(e,[1,1,1,1],n):de(e,-n)}function ge(e){let[r,n,t,o]=e;r=Math.abs(r%360);let i=n*(1-Math.abs(2*t-1)),f=i*(1-Math.abs(r/60%2-1)),l=0,s=0,m=0;0<=r&&r<60?(l=i,s=f):60<=r&&r<120?(l=f,s=i):120<=r&&r<180?(s=i,m=f):180<=r&&r<240?(s=f,m=i):240<=r&&r<300?(l=f,m=i):300<=r&&r<360&&(l=i,m=f);let c=t-i/2;return[d(l+c,w),d(s+c,w),d(m+c,w),d(o,w)]}function H(e){let[r,n,t,o]=e,i=Math.max(r,n,t),f=Math.min(r,n,t),l=0,s=0,m=(i+f)/2;if(i==f)return[l,s,C.round(m,4),o];let c=i-f;if(c!=0){switch(i){case r:l=60*(n-t)/c;break;case n:l=60*(2+(t-r)/c);break;case t:l=60*(4+(r-n)/c);break}for(;l<0;)l+=360}return m!=0&&m!=1&&(s=(i-m)/Math.min(m,1-m)),[d(l,w-2),d(s,w),d(m,w),o]}function Re(e,r=!1){let n=e.trim(),t="linear-gradient",o,i=[];if(fe.test(n))i=n.match(fe)[1].split(",").map(l=>l.trim()),(i[0].includes("deg")||i[0].includes("turn")||i[0].includes("to "))&&(o=i.shift());else if(ue.test(n))t="radial-gradient",i=n.match(ue)[1].split(",").map(l=>l.trim()),(i[0].includes("circle")||i[0].includes("ellipse")||i[0].includes("closest-")||i[0].includes("farthest-"))&&(o=i.shift());else if(ce.test(n))t="conic-gradient",i=n.match(ce)[1].split(",").map(l=>l.trim()),i[0].includes("from")&&(o=i.shift());else throw new Error(`Unable to parse gradient "${e}"`);let f=[];for(let l of i){let s="",m=l,c=l.match(Me);if(c&&(s=c[0].trim(),m=l.replace(s,"").trim()),f.length){let y=f[f.length-1],{pos:u,color:p}=y;if(!(ie(u,s)<=0||M(p).hex===M(m).hex))for(let h=1;h<=3;h++){let b=.25*h,V=T(p,m,b);f.push({color:r?V.p3:V.hex,pos:ie(u||0,s,b)})}}let a=M(m);f.push({color:r?a.p3:a.hex,pos:s})}return`${t}(${[...o?[o]:[],...f.map(({color:l,pos:s})=>`${l}${s?` ${s}`:""}`)].join(",")})`}var he={alpha:ze,darken:de,from:M,gammaGradient:Re,hslToRGB:ge,lighten:pe,mix:T,parse:L,rgbToHSL:H};function z(e){if(!e)throw new Error("missing value");if(typeof e=="string"||typeof e=="number")try{return he.from(e).hex}catch{throw new Error(`invalid color "${e}"`)}throw new Error(`expected string, received ${typeof e}`)}function S(e){if(!e)throw new Error("missing value");if(typeof e=="string")return[e];if(Array.isArray(e)){if(e.every(r=>!!r&&typeof r=="string"))return e;throw new Error("expected array of strings")}throw new Error(`expected string or array of strings, received ${typeof e}`)}var ve=/^\d+(\.\d+)?(ms|s)$/;function v(e){if(typeof e=="number")return`${e}ms`;if(typeof e=="string"){if(parseFloat(e)===0)return"0ms";if(ve.test(e))return e;throw new Error(`invalid duration "${e}"`)}throw new Error(`expected string, received ${typeof e}`)}function A(e){if(typeof e=="number"){if(e===0)return"0";throw new Error("missing units")}if(typeof e=="string")return parseFloat(e)===0?"0":e;throw new Error(`expected string, received ${typeof e}`)}function O(e){if(!e)throw new Error("missing value");if(!Array.isArray(e)||e.length!==4||e.some(r=>typeof r!="number"))throw new Error(`expected [\u{1D465}1, \u{1D466}1, \u{1D465}2, \u{1D466}2], received ${e}`);return[Math.max(0,Math.min(1,e[0])),e[1],Math.max(0,Math.min(1,e[2])),e[3]]}function U(e){if(!e)throw new Error("missing value");if(typeof e=="string")return e;throw new Error(`expected string, received ${typeof e}`)}function P(e){if(!e)throw new Error("missing value");if(typeof e=="string")try{return e}catch{throw new Error(`Invalid URL "${e}" (use "type": "file" for local paths)`)}throw new Error(`expected string, received ${typeof e}`)}function X(e){if(!e)throw new Error("missing value");if(typeof e!="object"||Array.isArray(e))throw new Error("invalid shadow");let r=e;return["offset-x","offset-y","blur","spread","color"].forEach(n=>{if(typeof r[n]=="number"&&r[n]>0)throw new Error(`${n} missing units`);if((n==="offset-x"||n==="offset-y")&&typeof r[n]!="string"&&r[n]!==0)throw new Error(`missing ${n}`)}),{"offset-x":A(r["offset-x"]||"0"),"offset-y":A(r["offset-y"]||"0"),blur:A(r.blur||"0"),spread:A(r.spread||"0"),color:z(r.color)}}function W(e){if(!e)throw new Error("missing value");if(!Array.isArray(e))throw new Error(`expected array of gradient stops, received ${typeof e}`);if(e.some(r=>!r||!r.color))throw new Error("all gradient stops must have color");return e.map(r=>({color:z(r.color),position:typeof r.position=="number"?Math.max(0,Math.min(1,r.position)):void 0}))}var Ve=/([a-z])([A-Z])/g,ye=new Map([["thin",100],["hairline",100],["extra-light",200],["ultra-light",200],["light",300],["normal",400],["regular",400],["book",400],["medium",500],["semi-bold",600],["demi-bold",600],["bold",700],["extra-bold",800],["ultra-bold",800],["black",900],["heavy",900],["extra-black",950],["ultra-black",950]]);function Z(e){if(!e)throw new Error("missing value");if(typeof e!="object"||Array.isArray(e))throw new Error(`expected object, received ${Array.isArray(e)?"array":typeof e}`);if(!Object.keys(e).length)throw new Error("must specify at least 1 font property");let r={};for(let[n,t]of Object.entries(e)){let o=n.replace(Ve,"$1-$2").toLowerCase();switch(o){case"font-name":case"font-family":{r["font-family"]=S(t);break}case"font-weight":{if(typeof t=="string"){let i=ye.get(t);if(i)r["font-weight"]=i;else throw new Error(`invalid font weight "${t}", use number (1-999) or any of the following names: ${[...ye.values()].join(`
- `)}`)}else typeof t=="number"&&(r["font-weight"]=Math.max(1,Math.min(999,t)));break}default:{r[o]=typeof t=="string"&&parseFloat(t)>=0?A(t):t;break}}}return r}var Fe=[.25,.1,.25,1];function J(e){if(!e)throw new Error("missing value");if(typeof e!="object"||Array.isArray(e))throw new Error("invalid transition format, e");if(!Object.keys(e).length)throw new Error("At least 1 transition property is required");let r=e;return{duration:v(r.duration||"0"),delay:v(r.delay||"0"),"timing-function":O(r["timing-function"]||Fe)}}var _=/^\{([^}]+)\}$/;function K(e){let r=[],n=[],t={result:{metadata:{},tokens:[]}};if(!e||typeof e!="object"||Array.isArray(e))return r.push(`Invalid schema type. Expected object, received "${Array.isArray(e)?"Array":typeof e}"`),t.errors=r,t;e.metadata&&E(e.metadata)&&(t.result.metadata=e.metadata);let o={};function i(a,y=[],u={requiredModes:[]}){if(!(!a||!E(a)))for(let[p,h]of Object.entries(a)){if(!h||!E(h)){r.push(`${p}: unexpected token format "${h}"`);continue}if(p.includes(".")||p.includes("#")){r.push(`${p}: invalid name. Names can\u2019t include "." or "#".`);continue}Object.keys(h).length||r.push(`${p}: groups can\u2019t be empty`);let b={_original:{...h},_group:{id:y.join(".")||".",...u||{}},id:y.concat(p).join("."),type:h.type||u.type,...h};if(b.hasOwnProperty("value")){if(ee(b.value)){r.push(`${b.id}: missing value`);continue}if(!!b.mode&&!E(b.mode)&&r.push(`${b.id}: "mode" must be an object`),u.requiredModes.length)for(let k of u.requiredModes)(b.mode||{})[k]||r.push(`${b.id}: missing mode "${k}" required from parent group`);o[b.id]=b}else{let{metadata:k,...Y}=h,we={...u,...k||{}};if(!!k&&!E(k)&&r.push(`${p}: "metadata" must be an object, received ${Array.isArray(k)?"array":typeof k}`),Object.values(Y).every($e=>E($e))){i(Y,[...y,p],we);continue}throw new Error(`${p}: missing type`)}}}let{metadata:f,...l}=e;if(i(l,[],{requiredModes:[],...f||[]}),r.length)return t.errors=r,t;let s={};for(let a of Object.values(o)){s[a.id]=a.value;for(let[y,u]of Object.entries(a.mode||{}))s[`${a.id}#${y}`]=u}function m(a,y){return B(y,{default(u){return u},string(u){if(!_.test(u))return u;let p=be(u);if(!s[p])throw new Error(`${a}: can\u2019t find ${u}`);let h=s[p];if(typeof h=="string"&&_.test(h)&&a===be(h))throw new Error(`${a}: can\u2019t reference circular alias ${u}`);return s[p]},array(u){return u.map(p=>m(a,p))},object(u){for(let p of Object.keys(u))u[p]=m(a,u[p]);return u}})}for(;Q(s);)try{for(let[a,y]of Object.entries(s))s[a]=m(a,y)}catch(a){r.push(a.message||a);break}if(r.length)return t.errors=r,t;function c(a,y){if(!!o[a].mode)for(let u of Object.keys(o[a].mode||{}))o[a].mode[u]=y(s[`${a}#${u}`])}for(let[a,y]of Object.entries(o))try{switch(y.type){case"color":o[a].value=z(s[a]),c(a,z);break;case"dimension":o[a].value=A(s[a]),c(a,A);break;case"font":o[a].value=S(s[a]),c(a,S);break;case"duration":o[a].value=v(s[a]),c(a,v);break;case"cubic-bezier":o[a].value=O(s[a]),c(a,O);break;case"file":o[a].value=U(s[a]),c(a,U);break;case"url":o[a].value=P(s[a]),c(a,P);break;case"transition":o[a].value=J(s[a]),c(a,J);break;case"shadow":o[a].value=X(s[a]),c(a,X);break;case"gradient":o[a].value=W(s[a]),c(a,W);break;case"typography":o[a].value=Z(s[a]),c(a,Z);break;default:o[a].value=s[a],c(a,u=>u);break}}catch(u){r.push(`${a}: ${u.message||u}`)}return r.length&&(t.errors=r),n.length&&(t.warnings=n),t.result.tokens=Object.values(o),t}function Q(e){return Object.values(e).some(r=>B(r,{default:()=>!1,string:n=>_.test(n),array:n=>n.some(t=>typeof t=="string"?_.test(t):E(t)?Q(t):!1),object:n=>Q(n)}))}function be(e){let r=e.match(_);return r?r[1]:e}var dr={parse:K};export{dr as default,K as parse};
//# sourceMappingURL=index.min.js.map

@@ -54,3 +54,3 @@ import { isEmpty, isObj, splitType } from '../util.js';

};
const isToken = !!token.value;
const isToken = token.hasOwnProperty('value');
if (isToken) {

@@ -57,0 +57,0 @@ if (isEmpty(token.value)) {

@@ -7,9 +7,10 @@ import type { ParsedTypographyValue } from '../../@types/token';

* "value": {
* "fontName": "Roboto",
* "fontSize": "42px",
* "fontWeight": "700",
* "letterSpacing": "0.1px",
* "lineHeight": "1.2"
* "font-family": "Roboto",
* "font-size": "42px",
* "font-weight": "700",
* "letter-spacing": "0.1px",
* "line-height": "1.2",
* "text-transform": "none"
* }
*/
export declare function normalizeTypographyValue(value: unknown): Partial<ParsedTypographyValue>;
import { normalizeFontValue } from './font.js';
import { normalizeDimensionValue } from './dimension.js';
const CAMELCASE_RE = /([a-z])([A-Z])/g;
const VALID_WEIGHT_NAMES = new Map([

@@ -28,7 +29,8 @@ ['thin', 100],

* "value": {
* "fontName": "Roboto",
* "fontSize": "42px",
* "fontWeight": "700",
* "letterSpacing": "0.1px",
* "lineHeight": "1.2"
* "font-family": "Roboto",
* "font-size": "42px",
* "font-weight": "700",
* "letter-spacing": "0.1px",
* "line-height": "1.2",
* "text-transform": "none"
* }

@@ -43,31 +45,34 @@ */

throw new Error('must specify at least 1 font property');
const v = value;
let fontWeight;
if (typeof v.fontWeight === 'string') {
const wgt = VALID_WEIGHT_NAMES.get(v.fontWeight);
if (wgt) {
fontWeight = wgt;
const normalized = {};
for (const [k, v] of Object.entries(value)) {
const property = k.replace(CAMELCASE_RE, '$1-$2').toLowerCase();
switch (property) {
case 'font-name':
case 'font-family': {
normalized['font-family'] = normalizeFontValue(v);
break;
}
case 'font-weight': {
if (typeof v === 'string') {
const wgt = VALID_WEIGHT_NAMES.get(v);
if (wgt) {
normalized['font-weight'] = wgt;
}
else {
throw new Error(`invalid font weight "${v}", use number (1-999) or any of the following names: ${[...VALID_WEIGHT_NAMES.values()].join('\n - ')}`);
}
}
else if (typeof v === 'number') {
normalized['font-weight'] = Math.max(1, Math.min(999, v));
}
break;
}
default: {
normalized[property] = typeof v === 'string' && parseFloat(v) >= 0 ? normalizeDimensionValue(v) : v;
break;
}
}
else {
throw new Error(`invalid font weight "${v.fontWeight}", use number (1-999) or any of the following names: ${[...VALID_WEIGHT_NAMES.values()].join('\n - ')}`);
}
}
else if (typeof v.fontWeight === 'number') {
fontWeight = Math.max(0, Math.min(999, v.fontWeight));
}
const normalized = {};
if (v.fontName)
normalized.fontName = normalizeFontValue(v.fontName);
if (v.fontSize)
normalized.fontSize = normalizeDimensionValue(v.fontSize);
if (v.fontStyle)
normalized.fontStyle = v.fontStyle;
if (fontWeight)
normalized.fontWeight = fontWeight;
if (v.letterSpacing)
normalized.letterSpacing = v.letterSpacing;
if (v.lineHeight)
normalized.lineHeight = v.lineHeight;
return normalized;
}
//# sourceMappingURL=typography.js.map
{
"name": "@cobalt-ui/core",
"description": "CLI for using the W3C design token format",
"version": "0.3.4",
"version": "0.4.0",
"author": {

@@ -6,0 +6,0 @@ "name": "Drew Powers",

@@ -195,11 +195,12 @@ // Base

export interface TypographyValue {
fontName: FontToken['value'];
fontSize: DimensionToken['value'];
fontStyle: string;
fontWeight: number | FontWeightName;
letterSpacing: DimensionToken['value'];
lineHeight: string | number;
'font-family': FontToken['value'];
'font-size': DimensionToken['value'];
'font-style': string;
'font-weight': number | FontWeightName;
'letter-spacing': DimensionToken['value'];
'line-height': string | number;
'text-transform': string;
}
export interface ParsedTypographyValue extends TypographyValue {
fontName: ParsedFontToken['value'];
'font-family': ParsedFontToken['value'];
}

@@ -206,0 +207,0 @@ export interface TypographyToken extends TokenBase<Partial<TypographyValue>> {

@@ -72,3 +72,3 @@ import type { Group, ParsedToken, TokenType, TokenOrGroup } from '../@types/token';

} as ParsedToken;
const isToken = !!token.value;
const isToken = token.hasOwnProperty('value');
if (isToken) {

@@ -75,0 +75,0 @@ if (isEmpty(token.value)) {

@@ -5,2 +5,3 @@ import type { ParsedTypographyValue, FontWeightName } from '../../@types/token';

const CAMELCASE_RE = /([a-z])([A-Z])/g;
const VALID_WEIGHT_NAMES = new Map<FontWeightName, number>([

@@ -32,7 +33,8 @@ ['thin', 100],

* "value": {
* "fontName": "Roboto",
* "fontSize": "42px",
* "fontWeight": "700",
* "letterSpacing": "0.1px",
* "lineHeight": "1.2"
* "font-family": "Roboto",
* "font-size": "42px",
* "font-weight": "700",
* "letter-spacing": "0.1px",
* "line-height": "1.2",
* "text-transform": "none"
* }

@@ -44,24 +46,32 @@ */

if (!Object.keys(value).length) throw new Error('must specify at least 1 font property');
const v = value as any;
let fontWeight: number | undefined;
if (typeof v.fontWeight === 'string') {
const wgt = VALID_WEIGHT_NAMES.get(v.fontWeight);
if (wgt) {
fontWeight = wgt;
} else {
throw new Error(
`invalid font weight "${v.fontWeight}", use number (1-999) or any of the following names: ${[...VALID_WEIGHT_NAMES.values()].join('\n - ')}`
);
const normalized = {} as ParsedTypographyValue;
for (const [k, v] of Object.entries(value)) {
const property = k.replace(CAMELCASE_RE, '$1-$2').toLowerCase();
switch (property) {
case 'font-name':
case 'font-family': {
normalized['font-family'] = normalizeFontValue(v);
break;
}
case 'font-weight': {
if (typeof v === 'string') {
const wgt = VALID_WEIGHT_NAMES.get(v as any);
if (wgt) {
normalized['font-weight'] = wgt;
} else {
throw new Error(`invalid font weight "${v}", use number (1-999) or any of the following names: ${[...VALID_WEIGHT_NAMES.values()].join('\n - ')}`);
}
} else if (typeof v === 'number') {
normalized['font-weight'] = Math.max(1, Math.min(999, v));
}
break;
}
default: {
(normalized as any)[property] = typeof v === 'string' && parseFloat(v) >= 0 ? normalizeDimensionValue(v) : v;
break;
}
}
} else if (typeof v.fontWeight === 'number') {
fontWeight = Math.max(0, Math.min(999, v.fontWeight));
}
const normalized = {} as ParsedTypographyValue;
if (v.fontName) normalized.fontName = normalizeFontValue(v.fontName);
if (v.fontSize) normalized.fontSize = normalizeDimensionValue(v.fontSize);
if (v.fontStyle) normalized.fontStyle = v.fontStyle;
if (fontWeight) normalized.fontWeight = fontWeight;
if (v.letterSpacing) normalized.letterSpacing = v.letterSpacing;
if (v.lineHeight) normalized.lineHeight = v.lineHeight;
return normalized;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc