@cobalt-ui/core
Advanced tools
Comparing version 0.3.0 to 0.3.1
# @cobalt-ui/core | ||
## 0.3.1 | ||
### Patch Changes | ||
- 1170d8b: Improve value normalization for duration, dimension, and transition token types | ||
## 0.3.0 | ||
@@ -4,0 +10,0 @@ |
@@ -91,4 +91,4 @@ export declare type Group = { | ||
'offset-y': DimensionToken['value']; | ||
blur?: DimensionToken['value']; | ||
spread?: DimensionToken['value']; | ||
blur: DimensionToken['value']; | ||
spread: DimensionToken['value']; | ||
color: ColorToken['value']; | ||
@@ -95,0 +95,0 @@ } |
@@ -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 I(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 A(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return I(e,A);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 I(e,re);var n=e[0],t=e[1],o=Math.pow(10,Math.max(x(n),x(t)));return(A(n,o)+A(t,o))/o}function te(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return I(e,te);var n=e[0],t=e[1],o=Math.pow(10,Math.max(x(n),x(t)));return(A(n,o)-A(t,o))/o}function q(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return I(e,q);var n=e[0],t=e[1],o=V(n),a=V(t);return D(o),D(a),A(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(A(e,n))),n);return e<0&&t!==0&&(t=A(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:A,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 O(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\((.*)\);?$/,Me=/\s[^\s]+$/,{round:d,strip:me}=L;function z(e){let r=C(e);return{get hex(){return`#${r.map((n,t)=>t<3?O(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?O(d(t*255,0).toString(16),2):t<1?O((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=z(e).rgbVal,c=z(r).rgbVal,i=m[0]**s,h=m[1]**s,u=m[2]**s,g=m[3],y=c[0]**s,b=c[1]**s,S=c[2]**s,k=c[3];return z([p((i**s*a+y**s*f)**l,0,1),p((h**s*a+b**s*f)**l,0,1),p((u**s*a+S**s*f)**l,0,1),g*a+k*f])}function C(e){function r(n){let t=O(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 je(e,r){let n=C(e);return z([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=[];return a.forEach((l,s)=>{let m="",c=l,i=l.match(Me);if(i&&(m=i[0].trim(),c=l.replace(m,"").trim()),s>0){let u=f[s-1].pos,g=f[s-1].color;if(!(ie(u,m)<=0||z(g).hex===z(c).hex))for(let y=1;y<=3;y++){let b=.25*y,S=N(g,c,b);f.push({color:r?S.p3:S.hex,pos:ie(u||0,m,b)})}}let h=z(c);f.push({color:r?h.p3:h.hex,pos:m})}),`${t}(${[...o?[o]:[],...f.map(({color:l,pos:s})=>`${l}${s?` ${s}`:""}`)].join(",")})`}var he={alpha:je,darken:de,from:z,gammaGradient:Re,hslToRGB:pe,lighten:ge,mix:N,parse:C,rgbToHSL:H};function j(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 ve=/^\d+(\.\d+)?(ms|s)$/;function v(e){if(typeof e=="number")return`${e}ms`;if(typeof e=="string"){if(ve.test(e))return e;throw new Error(`invalid duration "${e}"`)}throw new Error(`expected string, received ${typeof e}`)}function M(e){if(typeof e=="number"){if(e===0)return"0";throw new Error("missing units")}if(typeof e=="string")return 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((n==="offset-x"||n==="offset-y")&&typeof r[n]!="string"&&r[n]!==0)throw new Error(`missing ${n}`);if(r[n]>0)throw new Error(`${n} missing units`)}),{"offset-x":M(r["offset-x"]),"offset-y":M(r["offset-y"]),blur:r.blur,spread:r.spread,color:j(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:j(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=M(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}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:r.duration?v(r.duration):void 0,delay:r.delay?v(r.delay):void 0,"timing-function":r["timing-function"]?_(r["timing-function"]):void 0}}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,h=[],u={requiredModes:[]}){if(!(!i||!E(i)))for(let[g,y]of Object.entries(i)){if(!y||!E(y)){r.push(`${g}: unexpected token format "${y}"`);continue}if(g.includes(".")||g.includes("#")){r.push(`${g}: invalid name. Names can\u2019t include "." or "#".`);continue}let b={_original:{...y},_group:{id:h.join(".")||".",...u||{}},id:h.concat(g).join("."),type:y.type||u.type,...y};if(!!b.type){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}=y,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,[...h,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[h,u]of Object.entries(i.mode||{}))s[`${i.id}#${h}`]=u}function m(i,h){return T(h,{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 y=s[g];if(typeof y=="string"&&G.test(y)&&i===be(y))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,h]of Object.entries(s))s[i]=m(i,h)}catch(i){r.push(i.message||i);break}if(r.length)return t.errors=r,t;function c(i,h){if(!!o[i].mode)for(let u of Object.keys(o[i].mode||{}))o[i].mode[u]=h(s[`${i}#${u}`])}for(let[i,h]of Object.entries(o))try{switch(h.type){case"color":o[i].value=j(s[i]),c(i,j);break;case"dimension":o[i].value=M(s[i]),c(i,M);break;case"font":o[i].value=F(s[i]),c(i,F);break;case"duration":o[i].value=v(s[i]),c(i,v);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 cr={parse:Q};export{cr as default,Q as parse}; | ||
function k(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:k(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(k(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 G(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 G(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 G(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 G(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 G(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 Ee(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 ke(e){e===void 0&&(e=!0),ne=e}var xe={strip:B,plus:re,minus:te,times:z,divide:q,round:Ee,digitLength:x,float2Fixed:V,enableBoundaryChecking:ke},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 O(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\((.*)\);?$/,Me=/\s[^\s]+$/,{round:d,strip:me}=L;function M(e){let r=C(e);return{get hex(){return`#${r.map((n,t)=>t<3?O(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?O(d(t*255,0).toString(16),2):t<1?O((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=M(e).rgbVal,c=M(r).rgbVal,i=m[0]**s,h=m[1]**s,u=m[2]**s,g=m[3],y=c[0]**s,b=c[1]**s,v=c[2]**s,E=c[3];return M([p((i**s*a+y**s*f)**l,0,1),p((h**s*a+b**s*f)**l,0,1),p((u**s*a+v**s*f)**l,0,1),g*a+E*f])}function C(e){function r(n){let t=O(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 je(e,r){let n=C(e);return M([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=[];return a.forEach((l,s)=>{let m="",c=l,i=l.match(Me);if(i&&(m=i[0].trim(),c=l.replace(m,"").trim()),s>0){let u=f[s-1].pos,g=f[s-1].color;if(!(ie(u,m)<=0||M(g).hex===M(c).hex))for(let y=1;y<=3;y++){let b=.25*y,v=N(g,c,b);f.push({color:r?v.p3:v.hex,pos:ie(u||0,m,b)})}}let h=M(c);f.push({color:r?h.p3:h.hex,pos:m})}),`${t}(${[...o?[o]:[],...f.map(({color:l,pos:s})=>`${l}${s?` ${s}`:""}`)].join(",")})`}var he={alpha:je,darken:de,from:M,gammaGradient:Re,hslToRGB:pe,lighten:ge,mix:N,parse:C,rgbToHSL:H};function j(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(parseInt(e,10)===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 parseInt(e,10)===0?"0":e;throw new Error(`expected string, received ${typeof e}`)}function I(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:j(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:j(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":I(r["timing-function"]||ve)}}var _=/^\{([^}]+)\}$/;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&&k(e.metadata)&&(t.result.metadata=e.metadata);let o={};function a(i,h=[],u={requiredModes:[]}){if(!(!i||!k(i)))for(let[g,y]of Object.entries(i)){if(!y||!k(y)){r.push(`${g}: unexpected token format "${y}"`);continue}if(g.includes(".")||g.includes("#")){r.push(`${g}: invalid name. Names can\u2019t include "." or "#".`);continue}let b={_original:{...y},_group:{id:h.join(".")||".",...u||{}},id:h.concat(g).join("."),type:y.type||u.type,...y};if(!!b.type){if(ee(b.value)){r.push(`${b.id}: missing value`);continue}if(!!b.mode&&!k(b.mode)&&r.push(`${b.id}: "mode" must be an object`),u.requiredModes.length)for(let E of u.requiredModes)(b.mode||{})[E]||r.push(`${b.id}: missing mode "${E}" required from parent group`);o[b.id]=b}else{let{metadata:E,...Z}=y,we={...u,...E||{}};if(!!E&&!k(E)&&r.push(`${g}: "metadata" must be an object, received ${Array.isArray(E)?"array":typeof E}`),Object.values(Z).every($e=>k($e))){a(Z,[...h,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[h,u]of Object.entries(i.mode||{}))s[`${i.id}#${h}`]=u}function m(i,h){return T(h,{default(u){return u},string(u){if(!_.test(u))return u;let g=be(u);if(!s[g])throw new Error(`${i}: can\u2019t find ${u}`);let y=s[g];if(typeof y=="string"&&_.test(y)&&i===be(y))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,h]of Object.entries(s))s[i]=m(i,h)}catch(i){r.push(i.message||i);break}if(r.length)return t.errors=r,t;function c(i,h){if(!!o[i].mode)for(let u of Object.keys(o[i].mode||{}))o[i].mode[u]=h(s[`${i}#${u}`])}for(let[i,h]of Object.entries(o))try{switch(h.type){case"color":o[i].value=j(s[i]),c(i,j);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=I(s[i]),c(i,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=>_.test(n),array:n=>n.some(t=>typeof t=="string"?_.test(t):k(t)?Y(t):!1),object:n=>Y(n)}))}function be(e){let r=e.match(_);return r?r[1]:e}var mr={parse:Q};export{mr as default,Q as parse}; | ||
//# sourceMappingURL=index.min.js.map |
@@ -20,2 +20,4 @@ /** | ||
if (typeof value === 'string') { | ||
if (parseInt(value, 10) === 0) | ||
return '0'; | ||
return value; | ||
@@ -22,0 +24,0 @@ } |
@@ -19,2 +19,4 @@ const DURATION_RE = /^\d+(\.\d+)?(ms|s)$/; | ||
if (typeof value === 'string') { | ||
if (parseInt(value, 10) === 0) | ||
return '0ms'; // allow '0', but throw on everything else | ||
if (DURATION_RE.test(value)) { | ||
@@ -21,0 +23,0 @@ return value; |
@@ -23,12 +23,14 @@ import { normalizeColorValue } from './color.js'; | ||
['offset-x', 'offset-y', 'blur', 'spread', 'color'].forEach((k) => { | ||
if ((k === 'offset-x' || k === 'offset-y') && typeof v[k] !== 'string' && v[k] !== 0) | ||
throw new Error(`missing ${k}`); | ||
if (v[k] > 0) | ||
if (typeof v[k] === 'number' && v[k] > 0) | ||
throw new Error(`${k} missing units`); | ||
if (k === 'offset-x' || k === 'offset-y') { | ||
if (typeof v[k] !== 'string' && v[k] !== 0) | ||
throw new Error(`missing ${k}`); | ||
} | ||
}); | ||
return { | ||
'offset-x': normalizeDimensionValue(v['offset-x']), | ||
'offset-y': normalizeDimensionValue(v['offset-y']), | ||
blur: v.blur, | ||
spread: v.spread, | ||
'offset-x': normalizeDimensionValue(v['offset-x'] || '0'), | ||
'offset-y': normalizeDimensionValue(v['offset-y'] || '0'), | ||
blur: normalizeDimensionValue(v.blur || '0'), | ||
spread: normalizeDimensionValue(v.spread || '0'), | ||
color: normalizeColorValue(v.color), | ||
@@ -35,0 +37,0 @@ // extra values are discarded rather than throwing an error |
import { normalizeDurationValue } from './duration.js'; | ||
import { normalizeCubicBezierValue } from './cubic-bezier.js'; | ||
const EASE = [0.25, 0.1, 0.25, 1]; | ||
/** | ||
@@ -24,7 +25,7 @@ * 9.? Transition | ||
return { | ||
duration: v.duration ? normalizeDurationValue(v.duration) : undefined, | ||
delay: v.delay ? normalizeDurationValue(v.delay) : undefined, | ||
'timing-function': v['timing-function'] ? normalizeCubicBezierValue(v['timing-function']) : undefined, | ||
duration: normalizeDurationValue(v.duration || '0'), | ||
delay: normalizeDurationValue(v.delay || '0'), | ||
'timing-function': normalizeCubicBezierValue(v['timing-function'] || EASE), | ||
}; | ||
} | ||
//# sourceMappingURL=transition.js.map |
{ | ||
"name": "@cobalt-ui/core", | ||
"description": "Schemas and tools for managing design tokens", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"author": { | ||
@@ -23,4 +23,3 @@ "name": "Drew Powers", | ||
"@types/svgo": "^2.6.1", | ||
"better-color-tools": "^0.3.0", | ||
"undici": "^4.12.1" | ||
"better-color-tools": "^0.3.0" | ||
}, | ||
@@ -40,3 +39,3 @@ "devDependencies": { | ||
}, | ||
"readme": "# @cobalt-ui/core\n\nJS-only tool to parse a `tokens.json` schema, validate it for errors, and return tokens as a\nnormalized, flattened array. Works both in Node and the browser!\n\nFor building tokens and syncing with Figma, use `@cobalt-ui/cli`.\n\n## Install\n\n```\nnpm install @cobalt-ui/core\n```\n\n## Usage\n\nThis\n\nParse a `tokens.json` file into a JS object\n\n```js\nimport co from '@cobalt-ui/core';\nimport fs from 'fs';\n\nconst { errors, warnings, result } = JSON.parse(co.parse(fs.readFileSync('./tokens.json', 'utf8')));\n```\n" | ||
"readme": "# @cobalt-ui/core\n\nParse a `tokens.json` schema, validate it for errors, and return tokens as a\nnormalized, flattened array.\n\nUse `@cobalt-ui/core` in the browser or in Node.js.\n\nFor building tokens and syncing with Figma, use `@cobalt-ui/cli`.\n\n## Install\n\n```\nnpm install @cobalt-ui/core\n```\n\n## Usage\n\nParse a `tokens.json` file into a JS object\n\n```js\nimport co from '@cobalt-ui/core';\n\nconst designTokens = {\n color: {\n red: { type: 'color', value: '#e34850' },\n green: { type: 'color', value: '#2d9d78' },\n blue: { type: 'color', value: '#2680eb' },\n },\n};\n\nconst { errors, warnings, result } = co.parse(designTokens);\n```\n\n| Name | Type | Description |\n| :--------- | :------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------ |\n| `result` | Token[] | Flattened array of all parsed tokens in the schema (this may be incomplete if `errors` present) |\n| `errors` | `string[]` \\| `undefined` | If present, unrecoverable errors were encountered (you should probably `throw` with these messages). |\n| `warnings` | `string[]` \\| `undefined` | If present, the parser found schema issues that are likely undesirable, but the schema is still usable (you should probably show the user). |\n" | ||
} |
# @cobalt-ui/core | ||
JS-only tool to parse a `tokens.json` schema, validate it for errors, and return tokens as a | ||
normalized, flattened array. Works both in Node and the browser! | ||
Parse a `tokens.json` schema, validate it for errors, and return tokens as a | ||
normalized, flattened array. | ||
Use `@cobalt-ui/core` in the browser or in Node.js. | ||
For building tokens and syncing with Figma, use `@cobalt-ui/cli`. | ||
@@ -16,4 +18,2 @@ | ||
This | ||
Parse a `tokens.json` file into a JS object | ||
@@ -23,5 +23,18 @@ | ||
import co from '@cobalt-ui/core'; | ||
import fs from 'fs'; | ||
const { errors, warnings, result } = JSON.parse(co.parse(fs.readFileSync('./tokens.json', 'utf8'))); | ||
const designTokens = { | ||
color: { | ||
red: { type: 'color', value: '#e34850' }, | ||
green: { type: 'color', value: '#2d9d78' }, | ||
blue: { type: 'color', value: '#2680eb' }, | ||
}, | ||
}; | ||
const { errors, warnings, result } = co.parse(designTokens); | ||
``` | ||
| Name | Type | Description | | ||
| :--------- | :------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| `result` | Token[] | Flattened array of all parsed tokens in the schema (this may be incomplete if `errors` present) | | ||
| `errors` | `string[]` \| `undefined` | If present, unrecoverable errors were encountered (you should probably `throw` with these messages). | | ||
| `warnings` | `string[]` \| `undefined` | If present, the parser found schema issues that are likely undesirable, but the schema is still usable (you should probably show the user). | |
@@ -147,4 +147,4 @@ // Base | ||
'offset-y': DimensionToken['value']; | ||
blur?: DimensionToken['value']; | ||
spread?: DimensionToken['value']; | ||
blur: DimensionToken['value']; | ||
spread: DimensionToken['value']; | ||
color: ColorToken['value']; | ||
@@ -151,0 +151,0 @@ } |
@@ -21,2 +21,3 @@ import type { ParsedDimensionToken } from '../../@types/token'; | ||
if (typeof value === 'string') { | ||
if (parseInt(value, 10) === 0) return '0'; | ||
return value; | ||
@@ -23,0 +24,0 @@ } |
@@ -22,2 +22,3 @@ import type { ParsedDurationToken } from '../../@types/token'; | ||
if (typeof value === 'string') { | ||
if (parseInt(value, 10) === 0) return '0ms'; // allow '0', but throw on everything else | ||
if (DURATION_RE.test(value)) { | ||
@@ -24,0 +25,0 @@ return value; |
@@ -23,10 +23,12 @@ import type { ShadowValue } from '../../@types/token'; | ||
['offset-x', 'offset-y', 'blur', 'spread', 'color'].forEach((k) => { | ||
if ((k === 'offset-x' || k === 'offset-y') && typeof v[k] !== 'string' && v[k] !== 0) throw new Error(`missing ${k}`); | ||
if (v[k] > 0) throw new Error(`${k} missing units`); | ||
if (typeof v[k] === 'number' && v[k] > 0) throw new Error(`${k} missing units`); | ||
if (k === 'offset-x' || k === 'offset-y') { | ||
if (typeof v[k] !== 'string' && v[k] !== 0) throw new Error(`missing ${k}`); | ||
} | ||
}); | ||
return { | ||
'offset-x': normalizeDimensionValue(v['offset-x']), | ||
'offset-y': normalizeDimensionValue(v['offset-y']), | ||
blur: v.blur, | ||
spread: v.spread, | ||
'offset-x': normalizeDimensionValue(v['offset-x'] || '0'), | ||
'offset-y': normalizeDimensionValue(v['offset-y'] || '0'), | ||
blur: normalizeDimensionValue(v.blur || '0'), | ||
spread: normalizeDimensionValue(v.spread || '0'), | ||
color: normalizeColorValue(v.color), | ||
@@ -33,0 +35,0 @@ // extra values are discarded rather than throwing an error |
@@ -1,5 +0,7 @@ | ||
import type { ParsedTransitionToken } from '../../@types/token'; | ||
import type { CubicBezierToken, ParsedTransitionToken } from '../../@types/token'; | ||
import { normalizeDurationValue } from './duration.js'; | ||
import { normalizeCubicBezierValue } from './cubic-bezier.js'; | ||
const EASE: CubicBezierToken['value'] = [0.25, 0.1, 0.25, 1]; | ||
/** | ||
@@ -23,6 +25,6 @@ * 9.? Transition | ||
return { | ||
duration: v.duration ? normalizeDurationValue(v.duration) : undefined, | ||
delay: v.delay ? normalizeDurationValue(v.delay) : undefined, | ||
'timing-function': v['timing-function'] ? normalizeCubicBezierValue(v['timing-function']) : undefined, | ||
duration: normalizeDurationValue(v.duration || '0'), | ||
delay: normalizeDurationValue(v.delay || '0'), | ||
'timing-function': normalizeCubicBezierValue(v['timing-function'] || EASE), | ||
}; | ||
} |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135285
3
1983
39
- Removedundici@^4.12.1
- Removedundici@4.16.0(transitive)