@cobalt-ui/core
Advanced tools
Comparing version
# @cobalt-ui/core | ||
## 0.5.0 | ||
### Minor Changes | ||
- 61a7892: Add ability to load JSON from npm package | ||
## 0.4.0 | ||
@@ -4,0 +10,0 @@ |
@@ -44,4 +44,4 @@ /// <reference types="node" /> | ||
name: string; | ||
/** (optional) load config */ | ||
config?(config: ResolvedConfig): void; | ||
/** (optional) read config, and optionally modify */ | ||
config?(config: ResolvedConfig): void | ResolvedConfig | undefined; | ||
/** main build fn */ | ||
@@ -48,0 +48,0 @@ build(options: { |
@@ -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 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}; | ||
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 q(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?q(Number(e)*Math.pow(10,r)):Number(e)}function D(e){me&&(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),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 I(e,j);var n=e[0],t=e[1],o=F(n),i=F(t),f=x(n)+x(t),l=o*i;return D(l),l/Math.pow(10,f)}function ue(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return I(e,ue);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 ce(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return I(e,ce);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 C(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(e.length>2)return I(e,C);var n=e[0],t=e[1],o=F(n),i=F(t);return D(o),D(i),j(o/i,q(Math.pow(10,x(t)-x(n))))}function ke(e,r){var n=Math.pow(10,r),t=C(Math.round(Math.abs(j(e,n))),n);return e<0&&t!==0&&(t=j(t,-1)),t}var me=!0;function Ee(e){e===void 0&&(e=!0),me=e}var xe={strip:q,plus:ue,minus:ce,times:j,divide:C,round:ke,digitLength:x,float2Fixed:F,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},re=Ae;function G(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 te(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}L.enableBoundaryChecking(!1);var w=5,R="(\\s*,\\s*|\\s+)",$="-?[0-9]+(\\.[0-9]+)?",je=/^#?[0-9a-f]{3,8}$/i,ne=new RegExp(["^rgba?\\(\\s*",`(?<R>${$}%?)`,R,`(?<G>${$}%?)`,R,`(?<B>${$}%?)`,`(${R}(?<A>${$}%?))?`,"\\s*\\)$"].join(""),"i"),oe=new RegExp(["^hsla?\\(\\s*",`(?<H>${$})`,R,`(?<S>${$})%`,R,`(?<L>${$})%`,`(${R}(?<A>${$})%?)?`,"\\s*\\)$"].join(""),"i"),ie=new RegExp(["^color\\(\\s*display-p3\\s+",`(?<R>${$}%?)`,"\\s+",`(?<G>${$}%?)`,"\\s+",`(?<B>${$}%?)`,`(\\s*\\/\\s*(?<A>${$}%?))?`,"\\s*\\)$"].join(""),"i"),ae=/^linear-gradient\((.*)\);?$/,se=/^radial-gradient\((.*)\);?$/,le=/^conic-gradient\((.*)\);?$/,Me=/\s[^\s]+$/,{round:d,strip:fe}=L;function M(e){let r=H(e);return{get hex(){return`#${r.map((n,t)=>t<3?G(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?G(d(t*255,0).toString(16),2):t<1?G((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]=N(r);return`hsl(${n}, ${fe(t*100)}%, ${fe(o*100)}%, ${d(i,w)})`},get hslVal(){return N(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 H(e){function r(n){let t=G(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 re[n.toLowerCase()]=="number")return r(re[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(ne.test(n)){let t=ne.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(oe.test(n)){let t=oe.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(ie.test(n)){let t=ie.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=H(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 N(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,L.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(ae.test(n))i=n.match(ae)[1].split(",").map(l=>l.trim()),(i[0].includes("deg")||i[0].includes("turn")||i[0].includes("to "))&&(o=i.shift());else if(se.test(n))t="radial-gradient",i=n.match(se)[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(le.test(n))t="conic-gradient",i=n.match(le)[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(!(te(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:te(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:H,rgbToHSL:N};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 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 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(;K(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 K(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)?K(t):!1),object:n=>K(n)}))}function be(e){let r=e.match(_);return r?r[1]:e}var dr={parse:Q};export{dr as default,Q as parse}; | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "@cobalt-ui/core", | ||
"description": "CLI for using the W3C design token format", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Drew Powers", |
@@ -84,4 +84,4 @@ import type SVGO from 'svgo'; | ||
name: string; | ||
/** (optional) load config */ | ||
config?(config: ResolvedConfig): void; | ||
/** (optional) read config, and optionally modify */ | ||
config?(config: ResolvedConfig): void | ResolvedConfig | undefined; | ||
/** main build fn */ | ||
@@ -88,0 +88,0 @@ build(options: { tokens: ParsedToken[]; metadata: Record<string, unknown>; rawSchema: Group }): Promise<BuildResult[]>; |
136945
0.14%