@cobalt-ui/core
Advanced tools
Comparing version 0.6.0 to 0.6.1
# @cobalt-ui/core | ||
## 0.6.1 | ||
### Patch Changes | ||
- ed21d56: Bump deps, add config type to docs | ||
- Updated dependencies [a2a9d62] | ||
- Updated dependencies [ed21d56] | ||
- @cobalt-ui/utils@0.4.0 | ||
## 0.6.0 | ||
@@ -4,0 +13,0 @@ |
@@ -1,6 +0,6 @@ | ||
function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function J(e){return e==null?!0:typeof e=="string"||Array.isArray(e)?e.length===0:k(e)?Object.keys(e).length===0:!1}function R(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 q(e,r=2){let o=e;for(;o.length<r;)o=`0${o}`;return o}function le(e){return e*(Math.PI/180)}function fe(e){return e*(180/Math.PI)}function d(e,r,o){return Math.min(Math.max(e,r),o)}function _(e,r){return`color(${e} ${A(r[0],5)} ${A(r[1],5)} ${A(r[2],5)}${r[3]<1?`/${A(r[3],5)}`:""})`}function V(e,r){let o=[...e];for(let t=0;t<r.length;t++){let s=0;for(let i=0;i<r[0].length;i++)s+=e[i]*r[t][i];o[t]=s}return o}function A(e,r=2){let o=10**r;return Math.round(e*o)/o}function Q(e){let r=`${Math.round(e[0]*255)}, ${Math.round(e[1]*255)}, ${Math.round(e[2]*255)}`;return e[3]!==1?`rgba(${r}, ${A(e[3],5)})`:`rgb(${r})`}var ue=[[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],ce=[[4.0767416621,-3.3077115913,.2309699292],[-1.2684380046,2.6097574011,-.3413193965],[-.0041960863,-.7034186147,1.707614701]],me=[[.4122214708,.5363325363,.0514459929],[.2119034982,.6806995451,.1073969566],[.0883024619,.2817188376,.6299787005]],de=[[1,.3963377774,.2158037573],[1,-.1055613458,-.0638541728],[1,-.0894841775,-1.291485548]],he=[[3.2406,-1.5372,-.4986],[-.9689,1.8758,.0415],[.0557,-.204,1.057]];function ge(e){let[r,o,t,s]=e;r=Math.abs(r%360);let i=o*(1-Math.abs(2*t-1)),l=i*(1-Math.abs(r/60%2-1)),u=0,a=0,c=0;0<=r&&r<60?(u=i,a=l):60<=r&&r<120?(u=l,a=i):120<=r&&r<180?(a=i,c=l):180<=r&&r<240?(a=l,c=i):240<=r&&r<300?(u=l,c=i):300<=r&&r<360&&(u=i,c=l);let h=t-i/2;return[u+h,a+h,c+h,s]}function pe(e){let[r,o,t,s]=e,i=o===0&&t===0?0:fe(Math.atan2(t,o));return[r,Math.sqrt(o**2+t**2),i<0?i+360:i,s]}function ye(e){let[r,o,t,s]=e,i=le(t);return[r,o*Math.cos(i),o*Math.sin(i),s]}function be(e){let r=Math.cbrt(e[0]),o=Math.cbrt(e[1]),t=Math.cbrt(e[2]),s=e[3];return V([r,o,t,s],ue)}function we(e){let[r,o,t,s]=V(e,ce);return[Math.max(0,r),Math.max(0,o),Math.max(0,t),Math.max(0,s)]}function I(e){return e.map((r,o)=>o===3?d(r,0,1):r<=.0031308?d(r*12.92,0,1):d(1.055*r**(1/2.4)-.055,0,1))}function ke(e){return V(e,me)}function $e(e){let[r,o,t,s]=e,i=[0,0,0,s],l=o/(13*r),u=t/(13*r);return i[1]=r<=8?r*(3/29)**3:((r+16)/116)**3,i[0]=i[1]*(9/4)*l,i[2]=i[1]*((12-3*l-20*u)/4*u),i}function xe(e){return I(Me($e(e)))}function Ee(e){let r=V(e,de);return[r[0]**3,r[1]**3,r[2]**3,r[3]]}function T(e){return I(we(Ee(e)))}function ee(e){return T(ye(e))}function G(e){return e.map((r,o)=>o===3?r:r<=.04045?r/12.92:((r+.055)/1.055)**2.4)}function B(e){return be(ke(G(e)))}function C(e){return pe(B(e))}function Me(e){return V(e,he)}var Ae={black:[0,0,0,1],silver:[.75,.75,.75,1],gray:[.5,.5,.5,1],white:[1,1,1,1],maroon:[.5,0,0,1],red:[1,0,0,1],purple:[.5,0,.5,1],fuchsia:[1,0,1,1],green:[0,.5,0,1],lime:[0,1,0,1],olive:[.5,.5,0,1],yellow:[1,1,0,1],navy:[0,0,.5,1],blue:[0,0,1,1],teal:[0,.5,.5,1],aqua:[0,1,1,1],orange:[1,.6470588235294118,0,1],aliceblue:[.9411764705882353,.9725490196078431,1,1],antiquewhite:[.9803921568627451,.9215686274509803,.8431372549019608,1],aquamarine:[.4980392156862745,1,.8313725490196079,1],azure:[.9411764705882353,1,1,1],beige:[.9607843137254902,.9607843137254902,.8627450980392157,1],bisque:[1,.8941176470588236,.7686274509803922,1],blanchedalmond:[1,.9215686274509803,.803921568627451,1],blueviolet:[.5411764705882353,.16862745098039217,.8862745098039215,1],brown:[.6470588235294118,.16470588235294117,.16470588235294117,1],burlywood:[.8705882352941177,.7215686274509804,.5294117647058824,1],cadetblue:[.37254901960784315,.6196078431372549,.6274509803921569,1],chartreuse:[.4980392156862745,1,0,1],chocolate:[.8235294117647058,.4117647058823529,.11764705882352941,1],coral:[1,.4980392156862745,.3137254901960784,1],cornflowerblue:[.39215686274509803,.5843137254901961,.9294117647058824,1],cornsilk:[1,.9725490196078431,.8627450980392157,1],crimson:[.8627450980392157,.0784313725490196,.23529411764705882,1],cyan:[0,1,1,1],darkblue:[0,0,.5450980392156862,1],darkcyan:[0,.5450980392156862,.5450980392156862,1],darkgoldenrod:[.7215686274509804,.5254901960784314,.043137254901960784,1],darkgray:[.6627450980392157,.6627450980392157,.6627450980392157,1],darkgreen:[0,.39215686274509803,0,1],darkgrey:[.6627450980392157,.6627450980392157,.6627450980392157,1],darkkhaki:[.7411764705882353,.7176470588235294,.4196078431372549,1],darkmagenta:[.5450980392156862,0,.5450980392156862,1],darkolivegreen:[.3333333333333333,.4196078431372549,.1843137254901961,1],darkorange:[1,.5490196078431373,0,1],darkorchard:[.6,.19607843137254902,.8,1],darkred:[.5450980392156862,0,0,1],darksalmon:[.9137254901960784,.5882352941176471,.47843137254901963,1],darkseagreen:[.5607843137254902,.7372549019607844,.5607843137254902,1],darkslateblue:[.2823529411764706,.23921568627450981,.5450980392156862,1],darkslategray:[.1843137254901961,.30980392156862746,.30980392156862746,1],darkslategrey:[.1843137254901961,.30980392156862746,.30980392156862746,1],darkturquoise:[.1843137254901961,.30980392156862746,.30980392156862746,1],darkviolet:[.5803921568627451,0,.8274509803921568,1],deeppink:[1,.0784313725490196,.5764705882352941,1],deepskyblue:[0,.7490196078431373,1,1],dimgray:[.4117647058823529,.4117647058823529,.4117647058823529,1],dimgrey:[.4117647058823529,.4117647058823529,.4117647058823529,1],dodgerblue:[.11764705882352941,.5647058823529412,1,1],firebrick:[.6980392156862745,.13333333333333333,.13333333333333333,1],floralwhite:[1,.9803921568627451,.9411764705882353,1],forestgreen:[.13333333333333333,.5450980392156862,.13333333333333333,1],gainsboro:[.8627450980392157,.8627450980392157,.8627450980392157,1],ghostwhite:[.9725490196078431,.9725490196078431,1,1],gold:[1,.8431372549019608,0,1],goldenrod:[.8549019607843137,.6470588235294118,.12549019607843137,1],greenyellow:[.6784313725490196,1,.1843137254901961,1],grey:[.5019607843137255,.5019607843137255,.5019607843137255,1],honeydew:[.9411764705882353,1,.9411764705882353,1],hotpink:[1,.4117647058823529,.7058823529411765,1],indianred:[.803921568627451,.3607843137254902,.3607843137254902,1],indigo:[.29411764705882354,0,.5098039215686274,1],ivory:[1,1,.9411764705882353,1],khaki:[.9411764705882353,.9019607843137255,.5490196078431373,1],lavendar:[.9019607843137255,.9019607843137255,.9803921568627451,1],lavenderblush:[1,.9411764705882353,.9607843137254902,1],lawngreen:[.48627450980392156,.9882352941176471,0,1],lemonchiffon:[1,.9803921568627451,.803921568627451,1],lightblue:[.6784313725490196,.8470588235294118,.9019607843137255,1],lightcoral:[.9411764705882353,.5019607843137255,.5019607843137255,1],lightcyan:[.8784313725490196,1,1,1],lightgoldenrodyellow:[.9803921568627451,.9803921568627451,.8235294117647058,1],lightgray:[.8274509803921568,.8274509803921568,.8274509803921568,1],lightgreen:[.5647058823529412,.9333333333333333,.5647058823529412,1],lightgrey:[.8274509803921568,.8274509803921568,.8274509803921568,1],lightpink:[1,.7137254901960784,.7568627450980392,1],lightsalmon:[1,.6274509803921569,.47843137254901963,1],lightseagreen:[.12549019607843137,.6980392156862745,.6666666666666666,1],lightskyblue:[.5294117647058824,.807843137254902,.9803921568627451,1],lightslategray:[.4666666666666667,.5333333333333333,.6,1],lightslategrey:[.4666666666666667,.5333333333333333,.6,1],lightsteelblue:[.6901960784313725,.7686274509803922,.8705882352941177,1],lightyellow:[1,1,.8784313725490196,1],limegreen:[.19607843137254902,.803921568627451,.19607843137254902,1],linen:[.9803921568627451,.9411764705882353,.9019607843137255,1],magenta:[1,0,1,1],mediumaquamarine:[.4,.803921568627451,.6666666666666666,1],mediumblue:[0,0,.803921568627451,1],mediumorchid:[.7294117647058823,.3333333333333333,.8274509803921568,1],mediumpurple:[.5764705882352941,.4392156862745098,.8588235294117647,1],mediumseagreen:[.23529411764705882,.7019607843137254,.44313725490196076,1],mediumslateblue:[.4823529411764706,.40784313725490196,.9333333333333333,1],mediumspringgreen:[0,.9803921568627451,.6039215686274509,1],mediumturquoise:[.2823529411764706,.8196078431372549,.8,1],mediumvioletred:[.7803921568627451,.08235294117647059,.5215686274509804,1],midnightblue:[.09803921568627451,.09803921568627451,.4392156862745098,1],mintcream:[.9607843137254902,1,.9803921568627451,1],mistyrose:[1,.8941176470588236,.8823529411764706,1],moccasin:[1,.8941176470588236,.7098039215686275,1],navajowhite:[1,.8705882352941177,.6784313725490196,1],oldlace:[.9921568627450981,.9607843137254902,.9019607843137255,1],olivedrab:[.4196078431372549,.5568627450980392,.13725490196078433,1],orangered:[1,.27058823529411763,0,1],orchid:[.8549019607843137,.4392156862745098,.8392156862745098,1],palegoldenrod:[.9333333333333333,.9098039215686274,.6666666666666666,1],palegreen:[.596078431372549,.984313725490196,.596078431372549,1],paleturquoise:[.6862745098039216,.9333333333333333,.9333333333333333,1],palevioletred:[.8588235294117647,.4392156862745098,.5764705882352941,1],papayawhip:[1,.9372549019607843,.8352941176470589,1],peachpuff:[1,.8549019607843137,.7254901960784313,1],peru:[.803921568627451,.5215686274509804,.24705882352941178,1],pink:[1,.7529411764705882,.796078431372549,1],plum:[.8666666666666667,.6274509803921569,.8666666666666667,1],powderblue:[.6901960784313725,.8784313725490196,.9019607843137255,1],rosybrown:[.7372549019607844,.5607843137254902,.5607843137254902,1],royalblue:[.2549019607843137,.4117647058823529,.8823529411764706,1],saddlebrown:[.5450980392156862,.27058823529411763,.07450980392156863,1],salmon:[.9803921568627451,.5019607843137255,.4470588235294118,1],sandybrown:[.9568627450980393,.6431372549019608,.3764705882352941,1],seagreen:[.1803921568627451,.5450980392156862,.3411764705882353,1],seashell:[1,.9607843137254902,.9333333333333333,1],sienna:[.6274509803921569,.3215686274509804,.17647058823529413,1],skyblue:[.5294117647058824,.807843137254902,.9215686274509803,1],slateblue:[.41568627450980394,.35294117647058826,.803921568627451,1],slategray:[.4392156862745098,.5019607843137255,.5647058823529412,1],slategrey:[.4392156862745098,.5019607843137255,.5647058823529412,1],snow:[1,.9803921568627451,.9803921568627451,1],springgreen:[0,1,.4980392156862745,1],steelblue:[.27450980392156865,.5098039215686274,.7058823529411765,1],tan:[.8235294117647058,.7058823529411765,.5490196078431373,1],thistle:[.8470588235294118,.7490196078431373,.8470588235294118,1],tomato:[1,.38823529411764707,.2784313725490196,1],turquoise:[.25098039215686274,.8784313725490196,.8156862745098039,1],violet:[.9333333333333333,.5098039215686274,.9333333333333333,1],wheat:[.9607843137254902,.8705882352941177,.7019607843137254,1],whitesmoke:[.9607843137254902,.9607843137254902,.9607843137254902,1],yellowgreen:[.6039215686274509,.803921568627451,.19607843137254902,1],rebeccapurple:[.4,.2,.6,1]},Z=Ae,ze=/-?[0-9.]+%?/g,Ve=/^#?[0-9a-f]{3,8}$/i,je=256**2,Oe=256,Se=0;function M(e){let r=De(e),o={get hex(){let t="#";return t+=q(Math.round(r[0]*255).toString(16),2),t+=q(Math.round(r[1]*255).toString(16),2),t+=q(Math.round(r[2]*255).toString(16),2),r[3]<1&&(t+=q(Math.round(r[3]*255).toString(16),2)),t},get hexVal(){let t=Math.round(r[0]*255),s=Math.round(r[1]*255),i=Math.round(r[2]*255),l=Math.round(r[3]*255);return r[3]<1?t+256**3+s+256**2+i+256+l:t+256**2+s+256+i},get rgb(){return Q(r)},rgbVal:r,get rgba(){return Q(r)},rgbaVal:r,get linearRGB(){return G(r)},get p3(){return _("display-p3",r)},p3Val:r,get oklab(){return _("oklab",B(r))},get oklabVal(){return B(r)},get oklch(){return _("oklch",C(r))},get oklchVal(){return C(r)}};return o.toString=()=>o.hex,o}function De(e){function r(t){let s=Math.max(t-je,0)/256,i=Math.max(t-Oe,0)/256,l=Math.max(t-Se,0)/256;return[s,i,l,1]}function o(t,s){let i=t.match(ze);if(!i)throw new Error(`Unexpected color format: ${t}`);let l=[0,0,0,1];return i.forEach((u,a)=>{u.includes("%")?l[a]=parseFloat(u)/100:s[a]===1/0?l[a]=parseFloat(u):l[a]=parseFloat(u)/(s[a]||1)}),l}if(Array.isArray(e)){if(e.some(t=>typeof t!="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[d(e[0],0,1),d(e[1],0,1),d(e[2],0,1),typeof e[3]=="number"?d(e[3],0,1):1]}if(typeof e=="number")return r(e);if(typeof e=="string"){let t=e.trim();if(!t)throw new Error("Expected color, received empty string");if(Z[t.toLowerCase()])return Z[t.toLowerCase()];if(Ve.test(t)){let l=t.replace("#",""),u=[0,0,0,1];if(l.length>=6)for(let a=0;a<l.length/2;a++){let c=a*2,h=c+2,n=l.substring(c,h);u[a]=parseInt(n,16)/255}else for(let a=0;a<l.length;a++){let c=l.charAt(a);u[a]=parseInt(`${c}${c}`,16)/255}return u}let[s,i]=t.split("(");if(s==="color"){let l=i.indexOf(" ");s=i.substring(0,l),i=i.substring(l)}switch(s){case"rgb":case"rgba":case"srgb":{let[l,u,a,c]=o(i,[255,255,255,1]);return[d(l,0,1),d(u,0,1),d(a,0,1),d(c,0,1)]}case"srgb-linear":{let[l,u,a,c]=o(i,[255,255,255,1]);return I([d(l,0,1),d(u,0,1),d(a,0,1),d(c,0,1)])}case"hsl":{let[l,u,a,c]=o(i,[1/0,1,1,1]);return ge([l,d(u,0,1),d(a,0,1),d(c,0,1)])}case"p3":case"display-p3":{let[l,u,a,c]=o(i,[1,1,1,1]);return[d(l,0,1),d(u,0,1),d(a,0,1),d(c,0,1)]}case"luv":return xe(o(i,[1,1,1,1]));case"oklab":return T(o(i,[1,1,1,1]));case"oklch":return ee(o(i,[1,1,1/0,1]))}}throw new Error(`Unable to parse color "${e}"`)}function qe(e){return A(M(e).oklabVal[0],5)}function v(e,r,o=.5,t="oklab"){let s=d(o,0,1);if(o===0)return M(e);if(o===1)return M(r);let i=1-s,l=s,u={oklch:C,oklab:B,linearRGB:G,sRGB:F=>F},a={oklch:ee,oklab:T,linearRGB:I,sRGB:F=>F},c=u[t],h=a[t];if(!c)throw new Error(`Unknown color space "${t}", try "oklab", "oklch", "linearRGB", or "sRGB"`);let n=M(e).rgbVal,p=M(r).rgbVal;t==="oklch"&&(n[0]===n[1]&&n[1]===n[2]||p[0]===p[1]&&p[1]===p[2])&&(c=u.oklab,h=a.oklab);let[f,m,g,y]=c(n),[H,$,x,b]=c(p);return t==="oklch"&&Math.abs(x-g)>180&&(Math.max(g,x)===x?x-=360:g-=360),M(h([f*i+H*l,m*i+$*l,g*i+x*l,y*i+b*l]))}function re(e,r,o="oklab"){let t=d(r,-1,1);return t>=0?v(e,"black",t,o):te(e,-t)}function te(e,r,o="oklab"){let t=d(r,-1,1);return t>=0?v(e,"white",t,o):re(e,-t)}var ne={darken:re,from:M,lighten:te,lightness:qe,mix:v};function E(e){if(!e)throw new Error("missing value");if(typeof e=="string"||typeof e=="number")try{return ne.from(e).hex}catch{throw new Error(`invalid color "${e}"`)}throw new Error(`expected string, received ${typeof e}`)}function j(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 Be=/^\d+(\.\d+)?(ms|s)$/;function z(e){if(typeof e=="number")return`${e}ms`;if(typeof e=="string"){if(parseFloat(e)===0)return"0ms";if(Be.test(e))return e;throw new Error(`invalid duration "${e}"`)}throw new Error(`expected string, received ${typeof e}`)}function w(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}`)}var oe=new Set(["solid","dashed","dotted","double","groove","ridge","outset","inset"]);function S(e){if(!oe.has(e))throw new Error(`Unsupported stroke type "${e}", must be one of: | ||
- ${[...oe].join(` | ||
- `)}`);return e}function L(e){if(!k(e))throw new Error(`Expected object, received ${Array.isArray(e)?"array":typeof e}`);let r={};if(!Object.keys(e).length)throw new Error("Must specify at least 1 property for border");for(let o of Object.keys(e))switch(o){case"color":{r.color=E(e.color);break}case"width":{r.width=w(e.width);break}case"style":{r.style=S(e.style);break}default:throw new Error(`Unknown property "${o}" on border token`)}return r}var Ie=[.25,.1,.25,1];function W(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:z(r.duration||"0"),delay:z(r.delay||"0"),timingFunction:O(r.timingFunction||Ie)}}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["offsetX","offsetX","blur","spread","color"].forEach(o=>{if(typeof r[o]=="number"&&r[o]>0)throw new Error(`${o} missing units`);if((o==="offsetX"||o==="offsetY")&&typeof r[o]!="string"&&r[o]!==0)throw new Error(`missing ${o}`)}),{offsetX:w(r.offsetX||"0"),offsetY:w(r.offsetY||"0"),blur:w(r.blur||"0"),spread:w(r.spread||"0"),color:E(r.color)}}function Y(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:E(r.color),position:typeof r.position=="number"?Math.max(0,Math.min(1,r.position)):void 0}))}var Fe=/[-_]+[^-_]/g,ie=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 K(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[o,t]of Object.entries(e)){let s=o.replace(Fe,i=>i.charAt(i.length-1).toUpperCase());switch(s){case"fontName":case"fontFamily":{r.fontFamily=j(t);break}case"fontWeight":{if(typeof t=="string"){let i=ie.get(t);if(i)r.fontWeight=i;else throw new Error(`invalid font weight "${t}", use number (1-999) or any of: | ||
- ${[...ie.values()].join(` | ||
- `)}`)}else typeof t=="number"&&(r.fontWeight=Math.max(1,Math.min(999,t)));break}default:{r[s]=typeof t=="string"&&parseFloat(t)>=0?w(t):t;break}}}return r}var D=/^\{([^}]+)\}$/,ae=new Set(["$description","$name","$type","$value","$extensions"]);function P(e){let r=[],o=[],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;let s={};function i(n,p=[],f={$extensions:{requiredModes:[]}}){if(!(!n||!k(n)))for(let[m,g]of Object.entries(n)){if(!g||!k(g)){r.push(`${m}: unexpected token format "${g}"`);continue}if(m.includes(".")||m.includes("{")||m.includes("}")||m.includes("#")){r.push(`${m}: IDs can\u2019t include any of the following: .{}#`);continue}Object.keys(g).length||r.push(`${m}: groups can\u2019t be empty`);let y={_original:{...g},_group:{id:p.join(".")||".",...f||{}},id:p.concat(m).join("."),$type:g.$type||f.$type,...g};if(y.hasOwnProperty("$value")){if(m.startsWith("$")){r.push(`${m}: token ID can\u2019t start with the $ character`);continue}if(J(y.$value)){r.push(`${y.id}: missing "$value"`);continue}if(!!y.$extensions&&y.$extensions.mode&&!k(y.$extensions.mode)&&r.push(`${y.id}: "mode" must be an object`),f.$extensions.requiredModes.length)for(let $ of f.$extensions.requiredModes)(!y.$extensions||!y.$extensions.mode||!y.$extensions.mode[$])&&r.push(`${y.id}: missing mode "${$}" required from parent group`);s[y.id]=y}else{let $={...f},x={};for(let b of Object.keys(g))b.startsWith("$")?(b==="$extensions"?$.$extensions={...$.$extensions,...g.$extensions}:$[b]=g[b],ae.has(b)||(t.warnings||(t.warnings=[]),t.warnings.push(`Unknown property "${b}"`))):x[b]=g[b];if(Object.values(x).every(b=>k(b)))i(x,[...p,m],$);else throw new Error(`${m}: missing $type`)}}}let l={$extensions:{requiredModes:[]}},u={};for(let n of Object.keys(e))n.startsWith("$")?(n==="$extensions"?l.$extensions={...l.$extensions,...e.$extensions}:l[n]=e[n],ae.has(n)||(t.warnings||(t.warnings=[]),t.warnings.push(`Unknown property "${n}"`)),t.result.metadata[n]=e[n]):u[n]=e[n];if(i(u,[],l),r.length)return t.errors=r,t;let a={};for(let n of Object.values(s))if(a[n.id]=n.$value,n.$extensions&&n.$extensions.mode)for(let[p,f]of Object.entries(n.$extensions.mode||{}))a[`${n.id}#${p}`]=f;function c(n,p){return R(p,{default(f){return f},string(f){if(!D.test(f))return f;let m=se(f);if(!a[m])throw new Error(`${n}: can\u2019t find ${f}`);let g=a[m];if(typeof g=="string"&&D.test(g)&&n===se(g))throw new Error(`${n}: can\u2019t reference circular alias ${f}`);return a[m]},array(f){return f.map(m=>c(n,m))},object(f){for(let m of Object.keys(f))f[m]=c(n,f[m]);return f}})}for(;N(a);)try{for(let[n,p]of Object.entries(a))a[n]=c(n,p)}catch(n){r.push(n.message||n);break}if(r.length)return t.errors=r,t;function h(n,p){let f=s[n];if(!(!f.$extensions||!f.$extensions.mode))for(let m of Object.keys(f.$extensions.mode||{}))s[n].$extensions.mode[m]=p(a[`${n}#${m}`])}for(let[n,p]of Object.entries(s))try{switch(p.$type){case"color":s[n].$value=E(a[n]),h(n,E);break;case"dimension":s[n].$value=w(a[n]),h(n,w);break;case"font":s[n].$value=j(a[n]),h(n,j);break;case"duration":s[n].$value=z(a[n]),h(n,z);break;case"cubicBezier":s[n].$value=O(a[n]),h(n,O);break;case"link":s[n].$value=U(a[n]),h(n,U);break;case"strokeStyle":s[n].$value=S(a[n]),h(n,S);break;case"border":s[n].$value=L(a[n]),h(n,L);break;case"transition":s[n].$value=W(a[n]),h(n,W);break;case"shadow":s[n].$value=X(a[n]),h(n,X);break;case"gradient":s[n].$value=Y(a[n]),h(n,Y);break;case"typography":s[n].$value=K(a[n]),h(n,K);break;default:s[n].value=a[n],h(n,f=>f);break}}catch(f){r.push(`${n}: ${f.message||f}`)}return r.length&&(t.errors=r),o.length&&(t.warnings=o),t.result.tokens=Object.values(s),t}function N(e){return Object.values(e).some(r=>R(r,{default:()=>!1,string:o=>D.test(o),array:o=>o.some(t=>typeof t=="string"?D.test(t):k(t)?N(t):!1),object:o=>N(o)}))}function se(e){let r=e.match(D);return r?r[1]:e}var Er={parse:P};export{Er as default,P as parse}; | ||
function M(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function dr(r){return r==null?!0:typeof r=="string"||Array.isArray(r)?r.length===0:M(r)?Object.keys(r).length===0:!1}function X(r,e){if(r==null&&e.undefined)return e.undefined(r);if(typeof r=="string"&&e.string)return e.string(r);if(typeof r=="number"&&e.number)return e.number(r);if(Array.isArray(r)&&e.array)return e.array(r);if(M(r)&&e.object)return e.object(r);if(e.default)return e.default(r)}function N(r,e=2){let t=r;for(;t.length<e;)t=`0${t}`;return t}function Br(r){return r*(Math.PI/180)}function Sr(r){return r*(180/Math.PI)}function m(r,e,t){return Math.min(Math.max(r,e),t)}function _(r,e){let[t,o,n,a]=e,s=a<1?`/${A(a,5)}`:"";switch(r){case"rgb":case"rgba":return a<1?`rgba(${Math.round(t*255)}, ${Math.round(o*255)}, ${Math.round(n*255)}, ${A(a,5)})`:`rgb(${Math.round(t*255)}, ${Math.round(o*255)}, ${Math.round(n*255)})`;case"oklab":case"oklch":return`${r}(${A(t*100,6)}% ${A(o,6)} ${A(n,6)}${s})`;default:return`color(${r} ${A(t,6)} ${A(o,6)} ${A(n,6)}${s})`}}function G(r,e){let t=[...r];for(let o=0;o<e.length;o++){let n=0;for(let a=0;a<e[o].length;a++)n+=r[a]*e[o][a];t[o]=n}return t}function A(r,e=2){let t=10**e;return Math.round(r*t)/t}var Dr=[[.4123907992659593,.357584339383878,.1804807884018343],[.2126390058715102,.715168678767756,.0721923153607337],[.0193308187155918,.11919477979462,.9505321522496607]],Tr=[[3.240969941904522,-1.537383177570094,-.4986107602930034],[-.9692436362808793,1.8759675015077202,.0415550574071756],[.0556300796969937,-.2039769588889766,1.0569715142428782]],Ir=[[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],b=[[4.0767416621,-3.3077115913,.2309699292],[-1.2684380046,2.6097574011,-.3413193965],[-.0041960863,-.7034186147,1.707614701]],Fr=[[.4122214708,.5363325363,.0514459929],[.2119034982,.6806995451,.1073969566],[.0883024619,.2817188376,.6299787005]],qr=[[1,.39633779217376774,.2158037580607588],[1,-.10556134232365633,-.0638541747717059],[1,-.08948418209496574,-1.2914855378640917]];function Nr(r,e){let t=[1/0,1/0,1/0,1/0,1/0],o=1/0,n=1/0,a=1/0;-1.88170328*r-.80936493*e>1?(t=[1.19086277,1.76576728,.59662641,.75515197,.56771245],o=4.0767416621,n=-3.3077115913,a=.2309699292):1.81444104*r-1.19445276*e>1?(t=[.73956515,-.45954404,.08285427,.1254107,.14503204],o=-1.2684380046,n=2.6097574011,a=-.3413193965):(t=[1.35733652,-.00915799,-1.1513021,-.50559606,.00692167],o=-.0041960863,n=-.7034186147,a=1.707614701);let s=t[0]+t[1]*r+t[2]*e+t[3]*r*r+t[4]*r*e,h=.3963377774*r+.2158037573*e,l=-.1055613458*r-.0638541728*e,u=-.0894841775*r-1.291485548*e;{let p=1+s*h,i=1+s*l,g=1+s*u,f=p**3,d=i**3,y=g**3,w=3*h*p**2,O=3*l*i**2,$=3*u*g**2,k=6*h**2*p,c=6*l**2*i,x=6*u**2*g,C=o*f+n*d+a*y,S=o*w+n*O+a*$,q=o*k+n*c+a*x;s=s-C*S/(S*S-.5*C*q)}return s}function vr(r,e){let t=Nr(r,e),o=v(Z([1,t*r,t*e,1])),n=Math.cbrt(1/Math.max(o[0],o[1],o[3])),a=n*t;return{L:n,C:a}}function Ur(r,e,t,o,n){let a=vr(r,e);if((t-n)*a.C-(a.L-n)*o<=0)return a.C*n/(o*a.L+a.C*(n-t));let s=a.C*(n-1)/(o*(a.L-1)+a.C*(n-t)),h=t-n,l=o,u=.3963377774*r+.2158037573*e,p=-.1055613458*r-.0638541728*e,i=-.0894841775*r-1.291485548*e,g=h+l*u,f=h+l*p,d=h+l*i,y=n*(1-s)+s*t,w=s*o,O=y+w*u,$=y+w*p,k=y+w*i,c=[[O**3,$**3,k**3],[3*g*O**2,3*f*$**2,3*d*k**2],[6*g**2*O,6*f**2*$,6*d**2*k]],x=b[0][0]*c[0][0]+b[0][1]*c[0][1]+b[0][2]*c[0][2]-1,C=b[0][0]*c[1][0]+b[0][1]*c[1][1]+b[0][2]*c[1][2],S=b[0][0]*c[2][0]+b[0][1]*c[2][1]+b[0][2]*c[2][2],q=C/(C*C-.5*x*S),_r=q>=0?-x*q:1/0,fr=b[1][0]*c[0][0]+b[1][1]*c[0][1]+b[1][2]*c[0][2]-1,K=b[1][0]*c[1][0]+b[1][1]*c[1][1]+b[1][2]*c[1][2],jr=b[1][0]*c[2][0]+b[1][1]*c[2][1]+b[1][2]*c[2][2],mr=K/(K*K-.5*fr*jr),Rr=mr>=0?-fr*mr:1/0,hr=b[2][0]*c[0][0]+b[2][1]*c[0][1]+b[2][2]*c[0][2]-1,P=b[2][0]*c[1][0]+b[2][1]*c[1][1]+b[2][2]*c[1][2],Cr=b[2][0]*c[2][0]+b[2][1]*c[2][1]+b[2][2]*c[2][2],pr=P/(P*P-.5*hr*Cr),Gr=pr>=0?-hr*pr:1/0;return s+Math.min(_r,Rr,Gr)}function H(r){let[e,t,o,n]=r;e=Math.abs(e%360);let a=t*(1-Math.abs(2*o-1)),s=a*(1-Math.abs(e/60%2-1)),h=0,l=0,u=0;0<=e&&e<60?(h=a,l=s):60<=e&&e<120?(h=s,l=a):120<=e&&e<180?(l=a,u=s):180<=e&&e<240?(l=s,u=a):240<=e&&e<300?(h=s,u=a):300<=e&&e<360&&(h=a,u=s);let p=o-a/2;return[h+p,l+p,u+p,n]}function br(r){let[e,t,o,n]=r;if(t+o>=1){let s=t/(t+o);return[s,s,s,n]}let a=H([e,100,50,n]);for(let s=0;s<3;s++)a[s]*=1-t-o,a[s]+=t;return a}function Wr(r,e=2e-4){let[t,o,n,a]=r,s=Math.abs(o)<e&&Math.abs(n)<e?0:Sr(Math.atan2(n,o));for(;s<0;)s+=360;for(;s>=360;)s-=360;return[t,Math.sqrt(o**2+n**2),s,a]}function Yr(r){let[e,t,o,n]=r;if(e===0)return[0,0,0,r[3]];for(;o<0;)o+=360;for(;o>=360;)o-=360;let a=Br(o);return[e,Math.cos(a)*t,Math.sin(a)*t,n]}function Kr(r){return G(r,Ir)}function v(r){let[e,t,o,n]=G([r[0]**3,r[1]**3,r[2]**3,r[3]],b);return[e,t,o,n]}function R(r,e=2.4){let t=Math.abs(r[0]),o=Math.abs(r[1]),n=Math.abs(r[2]);return[t<.0031308?r[0]*12.92:1.055*Math.pow(t,1/e)-.055,o<.0031308?r[1]*12.92:1.055*Math.pow(o,1/e)-.055,n<.0031308?r[2]*12.92:1.055*Math.pow(n,1/e)-.055,r[3]]}function kr(r){let e=G(r,Fr);return[Math.cbrt(e[0]),Math.cbrt(e[1]),Math.cbrt(e[2]),e[3]]}function gr(r){return G(r,Dr)}function Z(r){return G(r,qr)}function U(r){let e=R(v(Z(r)));if(e[0]>1.001||e[0]<-.001||e[1]>1.001||e[1]<-.001||e[2]>1.001||e[2]<-.001){let[t,o,n,a]=r,s=Math.max(1e-5,Math.sqrt(o**2+n**2)),h=m(t,0,1),l=o/s,u=n/s,p=Ur(l,u,t,s,h);return R(v(Z([h*(1-p)+p*t,l*(p*s),u*(p*s),a])))}return e}function J(r){return U(Yr(r))}function j(r,e=2.4){let t=Math.abs(r[0]),o=Math.abs(r[1]),n=Math.abs(r[2]);return[t<.04045?r[0]/12.92:((t+.055)/1.055)**e,o<.04045?r[1]/12.92:((o+.055)/1.055)**e,n<.04045?r[2]/12.92:((n+.055)/1.055)**e,r[3]]}function W(r){return Kr(kr(j(r)))}function Q(r){return Wr(W(r))}function yr(r){return G(r,Tr)}var Pr={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,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,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,lavender: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},wr=Pr,Xr=/-?[0-9.]+%?/g,Hr=/^#?[0-9a-f]{3,8}$/i,Zr=16**6,rr=16**4,er=16**2;function V(r){let e=Jr(r),t={get hex(){let o="#";return o+=N(Math.round(m(e[0]*255,0,255)).toString(16),2),o+=N(Math.round(m(e[1]*255,0,255)).toString(16),2),o+=N(Math.round(m(e[2]*255,0,255)).toString(16),2),e[3]<1&&(o+=N(Math.round(e[3]*255).toString(16),2)),o},get hexVal(){e[3]<1&&console.warn(`hexVal converted a semi-transparent color (${e[3]*100}%) to fully opaque`);let o=Math.round(m(e[0]*255,0,255)),n=Math.round(m(e[1]*255,0,255)),a=Math.round(m(e[2]*255,0,255));return o*rr+n*er+a},get rgb(){return _("rgb",e)},rgbVal:e,get rgba(){return _("rgb",e)},rgbaVal:e,get linearRGB(){return _("srgb-linear",j(e))},get linearRGBVal(){return j(e)},get p3(){return _("display-p3",e)},p3Val:e,get oklab(){return _("oklab",W(e))},get oklabVal(){return W(e)},get oklch(){return _("oklch",Q(e))},get oklchVal(){return Q(e)},get xyz(){return _("xyz-d65",gr(j(e)))},get xyzVal(){return gr(j(e))}};return t.toString=()=>t.hex,t}function $r(r){if(r>Zr)throw new Error("8-digit hex values (with transparency) aren\u2019t supported");let e=r,t=Math.floor(e/rr);e-=t*rr;let o=Math.floor(e/er);e-=o*er;let n=e;return[t/255,o/255,n/255,1]}function L(r,e){let t=r.match(Xr);if(!t)throw new Error(`Unexpected color format: ${r}`);let o=[0,0,0,1];return t.forEach((n,a)=>{n.includes("%")?o[a]=parseFloat(n)/100:e[a]===1/0||e[a]===0||e[a]===1?o[a]=parseFloat(n):o[a]=parseFloat(n)/e[a]}),o}function Jr(r){let e=new Error(`Unable to parse color "${r}"`);if(r==null||r==null)throw e;if(Array.isArray(r)){if(typeof r[0]!="number"||typeof r[1]!="number"||typeof r[2]!="number")throw new Error(`Color array must be numbers, received ${r}`);if(r.length<3||r.length>4)throw new Error(`Expected [R, G, B, A?], received ${r}`);return[m(r[0],0,1),m(r[1],0,1),m(r[2],0,1),typeof r[3]=="number"?m(r[3],0,1):1]}if(typeof r=="object"){let t={...r},o=1;for(let n of Object.keys(t))n==="alpha"?o=m(t[n],0,1):t[n.toLowerCase()]=t[n];if("r"in t&&"g"in t&&"b"in t)return[m(t.r||t.R,0,1),m(t.r||t.R,0,1),m(t.r||t.R,0,1),o];if("h"in t&&"s"in t&&"l"in t)return H([t.h,m(t.s,0,1),m(t.l,0,1),o]);if("h"in t&&"w"in t&&"b"in t)return br([t.h,m(t.w,0,1),m(t.b,0,1),o]);if("l"in t&&"a"in t&&"b"in t)return U([t.l,t.a,t.b,o]);if("l"in t&&"c"in t&&"h"in t)return J([t.l,t.c,t.h,o]);if("x"in t&&"y"in t&&"z"in t)return R(yr([t.x,t.y,t.z,o]));throw e}if(typeof r=="number")return $r(r);if(typeof r=="string"){let t=r.trim();if(!t)throw new Error("Expected color, received empty string");let o=t.toLowerCase();if(typeof wr[o]=="number")return $r(wr[o]);if(Hr.test(t)){let s=t.replace("#",""),h=[0,0,0,1];if(s.length>=6)for(let l=0;l<s.length/2;l++){let u=l*2,p=u+2,i=s.substring(u,p);h[l]=parseInt(i,16)/255}else for(let l=0;l<s.length;l++){let u=s.charAt(l);h[l]=parseInt(`${u}${u}`,16)/255}return h}let[n,a]=t.split("(");if(n==="color"){let s=a.indexOf(" ");n=a.substring(0,s),a=a.substring(s)}switch(n){case"rgb":case"rgba":case"srgb":{let[s,h,l,u]=L(a,[255,255,255,1]);return[m(s,0,1),m(h,0,1),m(l,0,1),m(u,0,1)]}case"linear-rgb":case"linear-srgb":case"rgb-linear":case"srgb-linear":{let s=L(a,[255,255,255,1]);return R(s)}case"hsl":case"hsla":{let[s,h,l,u]=L(a,[1,1,1,1]);return H([s,m(h,0,1),m(l,0,1),m(u,0,1)])}case"hwb":case"hwba":{let[s,h,l,u]=L(a,[1,1,1,1]);return br([s,m(h,0,1),m(l,0,1),m(u,0,1)])}case"p3":case"display-p3":{let[s,h,l,u]=L(a,[1,1,1,1]);return[m(s,0,1),m(h,0,1),m(l,0,1),m(u,0,1)]}case"oklab":return U(L(a,[1,1,1,1]));case"oklch":return J(L(a,[1,1,1,1]));case"xyz":case"xyz-d65":return R(yr(L(a,[1,1,1,1])))}}throw e}function tr(r,e,t=.5,o="oklab"){let n=m(t,0,1);if(t===0)return V(r);if(t===1)return V(e);let a=1-n,s=n,h={oklch:Q,oklab:W,lms:x=>j(kr(x)),linearRGB:j,sRGB:x=>x},l={oklch:J,oklab:U,lms:x=>v(R(x)),linearRGB:R,sRGB:x=>x},u=h[o],p=l[o];if(!u)throw new Error(`Unknown color space "${o}", try "oklab", "oklch", "linearRGB", or "sRGB"`);let i=V(r).rgbVal,g=V(e).rgbVal;o==="oklch"&&(i[0]===i[1]&&i[1]===i[2]||g[0]===g[1]&&g[1]===g[2])&&(u=h.oklab,p=l.oklab);let[f,d,y,w]=u(i),[O,$,k,c]=u(g);return o==="oklch"&&Math.abs(k-y)>180&&(Math.max(y,k)===k?k-=360:y-=360),V(p([f*a+O*s,d*a+$*s,y*a+k*s,w*a+c*s]))}function xr(r,e,t="oklab"){let o=m(e,-1,1);return o>=0?tr(r,"black",o,t):Er(r,-o)}function Er(r,e,t="oklab"){let o=m(e,-1,1);return o>=0?tr(r,"white",o,t):xr(r,-o)}function Y(r){return V(r).xyzVal[1]}function Qr(r){return A(V(r).oklabVal[0],5)}function re(r){return Y(r)<.36?"dark":"light"}function ee(r,e){let t=Y(r),o=Y(e),n=Math.max(t,o),a=Math.min(t,o),s=(n+.05)/(a+.05);return{ratio:s,AA:s>=4.5,AAA:s>=7}}var Mr={contrastRatio:ee,darken:xr,from:V,lighten:Er,lightness:Qr,lightOrDark:re,luminance:Y,mix:tr};function z(r){if(!r)throw new Error("missing value");if(typeof r=="string"||typeof r=="number")try{return Mr.from(r).hex}catch{throw new Error(`invalid color "${r}"`)}throw new Error(`expected string, received ${typeof r}`)}function D(r){if(!r)throw new Error("missing value");if(typeof r=="string")return[r];if(Array.isArray(r)){if(r.every(e=>!!e&&typeof e=="string"))return r;throw new Error("expected array of strings")}throw new Error(`expected string or array of strings, received ${typeof r}`)}var te=/^\d+(\.\d+)?(ms|s)$/;function B(r){if(typeof r=="number")return`${r}ms`;if(typeof r=="string"){if(parseFloat(r)===0)return"0ms";if(te.test(r))return r;throw new Error(`invalid duration "${r}"`)}throw new Error(`expected string, received ${typeof r}`)}function E(r){if(typeof r=="number"){if(r===0)return"0";throw new Error("missing units")}if(typeof r=="string")return parseFloat(r)===0?"0":r;throw new Error(`expected string, received ${typeof r}`)}function T(r){if(!r)throw new Error("missing value");if(!Array.isArray(r)||r.length!==4||r.some(e=>typeof e!="number"))throw new Error(`expected [\u{1D465}1, \u{1D466}1, \u{1D465}2, \u{1D466}2], received ${r}`);return[Math.max(0,Math.min(1,r[0])),r[1],Math.max(0,Math.min(1,r[2])),r[3]]}function or(r){if(!r)throw new Error("missing value");if(typeof r=="string")return r;throw new Error(`expected string, received ${typeof r}`)}var Ar=new Set(["solid","dashed","dotted","double","groove","ridge","outset","inset"]);function I(r){if(!Ar.has(r))throw new Error(`Unsupported stroke type "${r}", must be one of: | ||
- ${[...Ar].join(` | ||
- `)}`);return r}function nr(r){if(!M(r))throw new Error(`Expected object, received ${Array.isArray(r)?"array":typeof r}`);let e={};if(!Object.keys(r).length)throw new Error("Must specify at least 1 property for border");for(let t of Object.keys(r))switch(t){case"color":{e.color=z(r.color);break}case"width":{e.width=E(r.width);break}case"style":{e.style=I(r.style);break}default:throw new Error(`Unknown property "${t}" on border token`)}return e}var oe=[.25,.1,.25,1];function ir(r){if(!r)throw new Error("missing value");if(typeof r!="object"||Array.isArray(r))throw new Error("invalid transition format, e");if(!Object.keys(r).length)throw new Error("At least 1 transition property is required");let e=r;return{duration:B(e.duration||"0"),delay:B(e.delay||"0"),timingFunction:T(e.timingFunction||oe)}}function ar(r){if(!r)throw new Error("missing value");if(typeof r!="object"||Array.isArray(r))throw new Error("invalid shadow");let e=r;return["offsetX","offsetX","blur","spread","color"].forEach(t=>{if(typeof e[t]=="number"&&e[t]>0)throw new Error(`${t} missing units`);if((t==="offsetX"||t==="offsetY")&&typeof e[t]!="string"&&e[t]!==0)throw new Error(`missing ${t}`)}),{offsetX:E(e.offsetX||"0"),offsetY:E(e.offsetY||"0"),blur:E(e.blur||"0"),spread:E(e.spread||"0"),color:z(e.color)}}function sr(r){if(!r)throw new Error("missing value");if(!Array.isArray(r))throw new Error(`expected array of gradient stops, received ${typeof r}`);if(r.some(e=>!e||!e.color))throw new Error("all gradient stops must have color");return r.map(e=>({color:z(e.color),position:typeof e.position=="number"?Math.max(0,Math.min(1,e.position)):void 0}))}var Le=!process.env.NODE_DISABLE_COLORS&&(!process.env.NO_COLOR||process.env.NO_COLOR=="0");var ne=/[^-_\.\s][-_\.\s]+[^-_\.\s]/g;function zr(r){return r.replace(ne,e=>`${e[0].toLocaleLowerCase()}${e[e.length-1].toLocaleUpperCase()}`)}var Or=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 lr(r){if(!r)throw new Error("missing value");if(typeof r!="object"||Array.isArray(r))throw new Error(`expected object, received ${Array.isArray(r)?"array":typeof r}`);if(!Object.keys(r).length)throw new Error("must specify at least 1 font property");let e={};for(let[t,o]of Object.entries(r)){let n=zr(t);switch(n){case"fontName":case"fontFamily":{e.fontFamily=D(o);break}case"fontWeight":{if(typeof o=="string"){let a=Or.get(o);if(a)e.fontWeight=a;else throw new Error(`invalid font weight "${o}", use number (1-999) or any of: | ||
- ${[...Or.values()].join(` | ||
- `)}`)}else typeof o=="number"&&(e.fontWeight=Math.max(1,Math.min(999,o)));break}default:{e[n]=typeof o=="string"&&parseFloat(o)>=0?E(o):o;break}}}return e}var F=/^\{([^}]+)\}$/,Lr=new Set(["$description","$name","$type","$value","$extensions"]);function ur(r){let e=[],t=[],o={result:{metadata:{},tokens:[]}};if(!r||typeof r!="object"||Array.isArray(r))return e.push(`Invalid schema type. Expected object, received "${Array.isArray(r)?"Array":typeof r}"`),o.errors=e,o;let n={};function a(i,g=[],f={$extensions:{requiredModes:[]}}){if(!(!i||!M(i)))for(let[d,y]of Object.entries(i)){if(!y||!M(y)){e.push(`${d}: unexpected token format "${y}"`);continue}if(d.includes(".")||d.includes("{")||d.includes("}")||d.includes("#")){e.push(`${d}: IDs can\u2019t include any of the following: .{}#`);continue}Object.keys(y).length||e.push(`${d}: groups can\u2019t be empty`);let w={_original:{...y},_group:{id:g.join(".")||".",...f||{}},id:g.concat(d).join("."),$type:y.$type||f.$type,...y};if(w.hasOwnProperty("$value")){if(d.startsWith("$")){e.push(`${d}: token ID can\u2019t start with the $ character`);continue}if(dr(w.$value)){e.push(`${w.id}: missing "$value"`);continue}if(!!w.$extensions&&w.$extensions.mode&&!M(w.$extensions.mode)&&e.push(`${w.id}: "mode" must be an object`),f.$extensions.requiredModes.length)for(let $ of f.$extensions.requiredModes)(!w.$extensions||!w.$extensions.mode||!w.$extensions.mode[$])&&e.push(`${w.id}: missing mode "${$}" required from parent group`);n[w.id]=w}else{let $={...f},k={};for(let c of Object.keys(y))c.startsWith("$")?(c==="$extensions"?$.$extensions={...$.$extensions,...y.$extensions}:$[c]=y[c],Lr.has(c)||(o.warnings||(o.warnings=[]),o.warnings.push(`Unknown property "${c}"`))):k[c]=y[c];if(Object.values(k).every(c=>M(c)))a(k,[...g,d],$);else throw new Error(`${d}: missing $type`)}}}let s={$extensions:{requiredModes:[]}},h={};for(let i of Object.keys(r))i.startsWith("$")?(i==="$extensions"?s.$extensions={...s.$extensions,...r.$extensions}:s[i]=r[i],Lr.has(i)||(o.warnings||(o.warnings=[]),o.warnings.push(`Unknown property "${i}"`)),o.result.metadata[i]=r[i]):h[i]=r[i];if(a(h,[],s),e.length)return o.errors=e,o;let l={};for(let i of Object.values(n))if(l[i.id]=i.$value,i.$extensions&&i.$extensions.mode)for(let[g,f]of Object.entries(i.$extensions.mode||{}))l[`${i.id}#${g}`]=f;function u(i,g){return X(g,{default(f){return f},string(f){if(!F.test(f))return f;let d=Vr(f);if(!l[d])throw new Error(`${i}: can\u2019t find ${f}`);let y=l[d];if(typeof y=="string"&&F.test(y)&&i===Vr(y))throw new Error(`${i}: can\u2019t reference circular alias ${f}`);return l[d]},array(f){return f.map(d=>u(i,d))},object(f){for(let d of Object.keys(f))f[d]=u(i,f[d]);return f}})}for(;cr(l);)try{for(let[i,g]of Object.entries(l))l[i]=u(i,g)}catch(i){e.push(i.message||i);break}if(e.length)return o.errors=e,o;function p(i,g){let f=n[i];if(!(!f.$extensions||!f.$extensions.mode))for(let d of Object.keys(f.$extensions.mode||{}))n[i].$extensions.mode[d]=g(l[`${i}#${d}`])}for(let[i,g]of Object.entries(n))try{switch(g.$type){case"color":n[i].$value=z(l[i]),p(i,z);break;case"dimension":n[i].$value=E(l[i]),p(i,E);break;case"font":n[i].$value=D(l[i]),p(i,D);break;case"duration":n[i].$value=B(l[i]),p(i,B);break;case"cubicBezier":n[i].$value=T(l[i]),p(i,T);break;case"link":n[i].$value=or(l[i]),p(i,or);break;case"strokeStyle":n[i].$value=I(l[i]),p(i,I);break;case"border":n[i].$value=nr(l[i]),p(i,nr);break;case"transition":n[i].$value=ir(l[i]),p(i,ir);break;case"shadow":n[i].$value=ar(l[i]),p(i,ar);break;case"gradient":n[i].$value=sr(l[i]),p(i,sr);break;case"typography":n[i].$value=lr(l[i]),p(i,lr);break;default:n[i].value=l[i],p(i,f=>f);break}}catch(f){e.push(`${i}: ${f.message||f}`)}return e.length&&(o.errors=e),t.length&&(o.warnings=t),o.result.tokens=Object.values(n),o}function cr(r){return Object.values(r).some(e=>X(e,{default:()=>!1,string:t=>F.test(t),array:t=>t.some(o=>typeof o=="string"?F.test(o):M(o)?cr(o):!1),object:t=>cr(t)}))}function Vr(r){let e=r.match(F);return e?e[1]:r}var et={parse:ur};export{et as default,ur as parse}; | ||
//# sourceMappingURL=index.min.js.map |
@@ -0,4 +1,4 @@ | ||
import { camelize } from '@cobalt-ui/utils'; | ||
import { normalizeFontValue } from './font.js'; | ||
import { normalizeDimensionValue } from './dimension.js'; | ||
const KEBAB_CASE_RE = /[-_]+[^-_]/g; | ||
const VALID_WEIGHT_NAMES = new Map([ | ||
@@ -47,3 +47,3 @@ ['thin', 100], | ||
for (const [k, v] of Object.entries(value)) { | ||
const property = k.replace(KEBAB_CASE_RE, (letter) => letter.charAt(letter.length - 1).toUpperCase()); | ||
const property = camelize(k); | ||
switch (property) { | ||
@@ -50,0 +50,0 @@ case 'fontName': |
{ | ||
"name": "@cobalt-ui/core", | ||
"description": "CLI for using the W3C design token format", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"author": { | ||
@@ -21,10 +21,10 @@ "name": "Drew Powers", | ||
"dependencies": { | ||
"@cobalt-ui/utils": "^0.3.0", | ||
"@types/svgo": "^2.6.1", | ||
"better-color-tools": "^0.6.1" | ||
"@cobalt-ui/utils": "^0.4.0", | ||
"better-color-tools": "^0.9.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17.0.12", | ||
"@types/node": "^17.0.45", | ||
"@types/svgo": "^2.6.3", | ||
"chai": "^4.3.6", | ||
"mocha": "^9.2.0" | ||
"mocha": "^10.0.0" | ||
}, | ||
@@ -38,4 +38,3 @@ "scripts": { | ||
"test": "mocha --parallel" | ||
}, | ||
"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" | ||
} | ||
} |
import type { ParsedTypographyValue, FontWeightName } from '../../@types/token'; | ||
import { camelize } from '@cobalt-ui/utils'; | ||
import { normalizeFontValue } from './font.js'; | ||
import { normalizeDimensionValue } from './dimension.js'; | ||
const KEBAB_CASE_RE = /[-_]+[^-_]/g; | ||
const VALID_WEIGHT_NAMES = new Map<FontWeightName, number>([ | ||
@@ -48,3 +48,3 @@ ['thin', 100], | ||
for (const [k, v] of Object.entries(value)) { | ||
const property = k.replace(KEBAB_CASE_RE, (letter) => letter.charAt(letter.length - 1).toUpperCase()); | ||
const property = camelize(k); | ||
switch (property) { | ||
@@ -51,0 +51,0 @@ case 'fontName': |
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
168487
2
4
2272
+ Added@cobalt-ui/utils@0.4.0(transitive)
+ Addedbetter-color-tools@0.9.1(transitive)
- Removed@types/svgo@^2.6.1
- Removed@cobalt-ui/utils@0.3.0(transitive)
- Removed@types/node@22.10.5(transitive)
- Removed@types/svgo@2.6.4(transitive)
- Removedbetter-color-tools@0.6.3(transitive)
- Removedundici-types@6.20.0(transitive)
Updated@cobalt-ui/utils@^0.4.0
Updatedbetter-color-tools@^0.9.1