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

@cobalt-ui/core

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cobalt-ui/core - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

dist/@types/token.d.ts

12

CHANGELOG.md
# @cobalt-ui/core
## 0.2.0
### Minor Changes
- 26bfb4c: Convert to JSON, follow design tokens spec
### Patch Changes
- Updated dependencies [26bfb4c]
- @cobalt-ui/utils@0.2.0
## 0.1.0
### Minor Changes

@@ -5,0 +17,0 @@

19

dist/index.d.ts
/// <reference types="node" />
import type { TokenType, ParseResult, Schema } from './parse.js';
export type { ColorToken, ConicGradientToken, CubicBezierToken, DimensionToken, FileToken, FontToken, Group, LinearGradientToken, Mode, ParsedMetadata, ParsedToken, ParseResult, RadialGradientToken, Schema, ShadowToken, Token, TokenBase, TokenOrGroup, TokenType, } from './parse.js';
import { parse } from './parse.js';
export { parse } from './parse.js';
import type { Group, ParsedToken, TokenType } from './@types/token';
export type { ColorToken, CubicBezierToken, DimensionToken, DurationToken, FileToken, FontToken, FontWeightName, GradientStop, GradientToken, Group, Mode, ParsedColorToken, ParsedCubicBezierToken, ParsedDimensionToken, ParsedDurationToken, ParsedFileToken, ParsedFontToken, ParsedGradientToken, ParsedShadowToken, ParsedToken, ParsedTransitionToken, ParsedTypographyToken, ParsedTypographyValue, ParsedURLToken, ShadowToken, ShadowValue, Token, TokenBase, TokenOrGroup, TokenType, TransitionToken, URLToken, } from './@types/token';
import { parse } from './parse/index.js';
export { parse, ParseResult } from './parse/index.js';
export interface BuildResult {

@@ -27,3 +27,3 @@ /** File to output inside config.outDir (ex: ./tokens.sass) */

}
export interface Config {
export interface ResolvedConfig {
tokens: URL;

@@ -37,10 +37,11 @@ outDir: URL;

/** (optional) load config */
config?: (config: Config) => void;
config?: (config: ResolvedConfig) => void;
/** main build fn */
build(options: {
schema: ParseResult['result'];
rawSchema: Schema;
tokens: ParsedToken[];
metadata: Record<string, unknown>;
rawSchema: Group;
}): Promise<BuildResult[]>;
}
export interface UserConfig {
export interface Config {
/** path to tokens.json (default: "./tokens.json") */

@@ -47,0 +48,0 @@ tokens?: string;

@@ -1,5 +0,6 @@

import { parse } from './parse.js';
export { parse } from './parse.js';
import { parse } from './parse/index.js';
export { parse } from './parse/index.js';
export default {
parse,
};
//# sourceMappingURL=index.js.map

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

function S(t,e){return e===void 0&&(e=15),+parseFloat(Number(t).toPrecision(e))}function y(t){var e=t.toString().split(/[eE]/),a=(e[0].split(".")[1]||"").length-+(e[1]||0);return a>0?a:0}function j(t){if(t.toString().indexOf("e")===-1)return Number(t.toString().replace(".",""));var e=y(t);return e>0?S(Number(t)*Math.pow(10,e)):Number(t)}function V(t){H&&(t>Number.MAX_SAFE_INTEGER||t<Number.MIN_SAFE_INTEGER)&&console.warn(t+" is beyond boundary when transfer to integer, the results may not be accurate")}function I(t,e){var a=t[0],r=t[1],i=t.slice(2),c=e(a,r);return i.forEach(function(l){c=e(c,l)}),c}function $(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(t.length>2)return I(t,$);var a=t[0],r=t[1],i=j(a),c=j(r),l=y(a)+y(r),n=i*c;return V(n),n/Math.pow(10,l)}function q(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(t.length>2)return I(t,q);var a=t[0],r=t[1],i=Math.pow(10,Math.max(y(a),y(r)));return($(a,i)+$(r,i))/i}function C(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(t.length>2)return I(t,C);var a=t[0],r=t[1],i=Math.pow(10,Math.max(y(a),y(r)));return($(a,i)-$(r,i))/i}function F(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(t.length>2)return I(t,F);var a=t[0],r=t[1],i=j(a),c=j(r);return V(i),V(c),$(i/c,S(Math.pow(10,y(r)-y(a))))}function ae(t,e){var a=Math.pow(10,e),r=F(Math.round(Math.abs($(t,a))),a);return t<0&&r!==0&&(r=$(r,-1)),r}var H=!0;function oe(t){t===void 0&&(t=!0),H=t}var se={strip:S,plus:q,minus:C,times:$,divide:F,round:ae,digitLength:y,float2Fixed:j,enableBoundaryChecking:oe},B=se,ie={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},P=ie;function R(t,e=2){let a=t;for(;a.length<e;)a=`0${a}`;return a}function g(t,e,a){return Math.min(Math.max(t,e),a)}B.enableBoundaryChecking(!1);var h=5,x="(\\s*,\\s*|\\s+)",m="-?[0-9]+(\\.[0-9]+)?",le=/^#?[0-9a-f]{3,8}$/i,z=new RegExp(["^rgba?\\(\\s*",`(?<R>${m}%?)`,x,`(?<G>${m}%?)`,x,`(?<B>${m}%?)`,`(${x}(?<A>${m}%?))?`,"\\s*\\)$"].join(""),"i"),U=new RegExp(["^hsla?\\(\\s*",`(?<H>${m})`,x,`(?<S>${m})%`,x,`(?<L>${m})%`,`(${x}(?<A>${m})%?)?`,"\\s*\\)$"].join(""),"i"),X=new RegExp(["^color\\(\\s*display-p3\\s+",`(?<R>${m}%?)`,"\\s+",`(?<G>${m}%?)`,"\\s+",`(?<B>${m}%?)`,`(\\s*\\/\\s*(?<A>${m}%?))?`,"\\s*\\)$"].join(""),"i"),{round:d,strip:K}=B;function M(t){let e=L(t);return{get hex(){return`#${e.map((a,r)=>r<3?R(d(a*255,0).toString(16),2):a<1?d(a*255,0).toString(16):"").join("")}`},get hexVal(){let a=e.map((r,i)=>i<3?R(d(r*255,0).toString(16),2):r<1?R((r*256).toString(16),2):"");return parseInt(`0x${a.join("")}`,16)},get rgb(){return e[3]==1?`rgb(${d(e[0]*255,0)}, ${d(e[1]*255,0)}, ${d(e[2]*255,0)})`:`rgba(${d(e[0]*255,0)}, ${d(e[1]*255,0)}, ${d(e[2]*255,0)}, ${d(e[3],h)})`},rgbVal:e,get rgba(){return`rgba(${d(e[0]*255,0)}, ${d(e[1]*255,0)}, ${d(e[2]*255,0)}, ${d(e[3],h)})`},rgbaVal:e,get hsl(){let[a,r,i,c]=N(e);return`hsl(${a}, ${K(r*100)}%, ${K(i*100)}%, ${d(c,h)})`},get hslVal(){return N(e)},get p3(){let[a,r,i,c]=e;return`color(display-p3 ${d(a,h)} ${d(r,h)} ${d(i,h)}${c<1?`/${d(c,h)}`:""})`}}}function G(t,e,a=.5,r=2.2){let i=g(a,0,1),c=1-i,l=i,n=1/r,s=r,o=M(t).rgbVal,u=M(e).rgbVal,f=o[0]**s,b=o[1]**s,p=o[2]**s,w=o[3],k=u[0]**s,v=u[1]**s,A=u[2]**s,E=u[3];return M([g((f**s*c+k**s*l)**n,0,1),g((b**s*c+v**s*l)**n,0,1),g((p**s*c+A**s*l)**n,0,1),w*c+E*l])}function L(t){function e(a){let r=R(g(a,0,4294967295).toString(16),6);return[parseInt(r.substring(0,2),16)/255,parseInt(r.substring(2,4),16)/255,parseInt(r.substring(4,6),16)/255,parseInt(r.substring(6,8)||"ff",16)/255]}if(Array.isArray(t)){if(t.some(a=>typeof a!="number"))throw new Error(`Color array must be numbers, received ${t}`);if(t.length<3||t.length>4)throw new Error(`Expected [R, G, B, A?], received ${t}`);return t.map(a=>g(a,0,1))}if(typeof t=="number")return e(t);if(typeof t=="string"){let a=t.trim();if(!a)throw new Error("Expected color, received empty string");if(typeof P[a.toLowerCase()]=="number")return e(P[a]);if(le.test(a)){let r=a.replace("#",""),i=parseInt(r.length<6?r.split("").map(c=>`${c}${c}`).join(""):r,16);return e(i)}if(z.test(a)){let r=z.exec(a).groups||{};if(![r.R,r.G,r.B].every(s=>s.includes("%")||!s.includes("%")))throw new Error("Mix of integers and %");let i=parseFloat(r.R)/(r.R.includes("%")?100:255),c=parseFloat(r.G)/(r.G.includes("%")?100:255),l=parseFloat(r.B)/(r.B.includes("%")?100:255),n=1;return r.A&&(n=parseFloat(r.A),r.A.includes("%")&&(n/=100)),[g(i,0,1),g(c,0,1),g(l,0,1),g(n,0,1)]}if(U.test(a)){let r=U.exec(a).groups||{},i=parseFloat(r.H),c=parseFloat(r.S)/100,l=parseFloat(r.L)/100,n=1;return r.A&&(n=parseFloat(r.A),r.A.includes("%")&&(n/=100)),Q([i,g(c,0,1),g(l,0,1),g(n,0,1)])}if(X.test(a)){let r=X.exec(a).groups||{},i=parseFloat(r.R);r.R.includes("%")&&(i/=100);let c=parseFloat(r.G);r.G.includes("%")&&(c/=100);let l=parseFloat(r.B);r.B.includes("%")&&(l/=100);let n=1;return r.A&&(n=parseFloat(r.A),r.A.includes("%")&&(n/=100)),[g(i,0,1),g(c,0,1),g(l,0,1),g(n,0,1)]}}throw new Error(`Unable to parse color "${t}"`)}function ue(t,e){let a=L(t);return M([a[0],a[1],a[2],g(e,0,1)])}function Y(t,e){let a=g(e,-1,1);return a>=0?G(t,[0,0,0,1],a):J(t,-a)}function J(t,e){let a=g(e,-1,1);return a>=0?G(t,[1,1,1,1],a):Y(t,-a)}function Q(t){let[e,a,r,i]=t;e=Math.abs(e%360);let c=a*(1-Math.abs(2*r-1)),l=c*(1-Math.abs(e/60%2-1)),n=0,s=0,o=0;0<=e&&e<60?(n=c,s=l):60<=e&&e<120?(n=l,s=c):120<=e&&e<180?(s=c,o=l):180<=e&&e<240?(s=l,o=c):240<=e&&e<300?(n=l,o=c):300<=e&&e<360&&(n=c,o=l);let u=r-c/2;return[d(n+u,h),d(s+u,h),d(o+u,h),d(i,h)]}function N(t){let[e,a,r,i]=t,c=Math.max(e,a,r),l=Math.min(e,a,r),n=0,s=0,o=(c+l)/2;if(c==l)return[n,s,B.round(o,4),i];let u=c-l;if(u!=0){switch(c){case e:n=60*(a-r)/u;break;case a:n=60*(2+(r-e)/u);break;case r:n=60*(4+(e-a)/u);break}for(;n<0;)n+=360}return o!=0&&o!=1&&(s=(c-o)/Math.min(o,1-o)),[d(n,h-2),d(s,h),d(o,h),i]}var W={alpha:ue,darken:Y,from:M,hslToRGB:Q,lighten:J,mix:G,parse:L,rgbToHSL:N};var ce=new Set(["name","version","metadata","tokens"]),D=/^\{.*\}$/;function _(t){let e=[],a=[],r={result:{metadata:{},tokens:[]}};if(!t||typeof t!="object"||Array.isArray(t))return e.push(`Invalid schema type. Expected object, received "${Array.isArray(t)?"Array":typeof t}"`),r.errors=e,r;for(let n of Object.keys(t))ce.has(n)?n!=="tokens"&&(r.result.metadata[n]=t[n]):e.push(`Invalid top-level name "${n}". Place arbitrary data inside "metadata".`);if(e.length)return r.errors=e,r;if(!t.tokens||typeof t.tokens!="object"||!Object.keys(t.tokens).length)return e.push('"tokens" is empty!'),r.errors=e,r;let i={};function c(n,s=[],o={modes:[]}){for(let[u,f]of Object.entries(n)){if(!f||Array.isArray(f)||typeof f!="object"){e.push(`${u}: unexpected token format "${f}"`);continue}if(u.includes(".")||u.includes("#")){e.push(`${u}: invalid name. Names can\u2019t include "." or "#".`);continue}if(f.type||o.type&&!!f.value){let p=s.concat(u).join("."),w=f.type||o.type;if(!f.value){e.push(`${p}: missing value`);continue}let k=f,v=k.mode||{};if((typeof v!="object"||Array.isArray(v))&&(e.push(`${p}: "mode" must be an object`),v={}),o.modes.length)for(let A of o.modes)v[A]||e.push(`${p}: missing mode "${A}" set on parent group`);for(let[A,E]of Object.entries(v))T(E)||e.push(`${p}#${A}: bad value "${E}"`);i[p]={id:p,...k,type:w,mode:v}}else{let{metadata:p,...w}=f,k={...o};p&&(p.type&&(k.type=p.type),Array.isArray(p.modes)&&(k.modes=p.modes)),Object.keys(w).length&&c(w,[...s,u],k)}}}if(c(t.tokens),e.length)return r.errors=e,r;let l={};for(let n of Object.values(i)){l[n.id]=n.value;for(let[s,o]of Object.entries(n.mode))l[`${n.id}#${s}`]=o}e:for(;Object.values(l).some(n=>typeof n=="string"&&D.test(n));)for(let[n,s]of Object.entries(l)){if(typeof s!="string"||!D.test(s))continue;let o=s.substring(1,s.length-1);if(!l[o]){e.push(`${n}: can\u2019t find ${s}`);break e}let u=l[o];if(typeof u=="string"&&D.test(u)&&o===u.substring(1,u.length-1)){e.push(`${n}: can\u2019t reference circular alias ${s}`);break e}l[n]=l[o]}if(e.length)return r.errors=e,r;for(;Object.values(l).some(n=>typeof n=="string"&&O(n).length||Array.isArray(n)&&n.some(s=>typeof s=="string"&&O(s).length));)for(let[n,s]of Object.entries(l)){if(typeof s=="string"){let o=s;for(let u of O(s)){let f=u.substring(1,u.length-1);l[n]=o.replace(u,l[f])}}Array.isArray(s)&&s.every(o=>typeof o=="string")&&(l[n]=s.map(o=>{let u=o;for(let f of O(o)){let b=f.substring(1,f.length-1);u=u.replace(f,l[b])}return u}))}for(let n of Object.keys(i)){let s=i[n];try{switch(s.type){case"dimension":case"file":case"linear-gradient":case"radial-gradient":case"conic-gradient":{let o=l[n];T(o)?i[n].value=o:e.push(`${n}: bad value "${o}"`);for(let u of Object.keys(s.mode)){let f=l[`${n}#${u}`];T(f)?i[n].mode[u]=f:e.push(`${n}: bad value "${f}"`)}break}case"color":{let o=l[n];Z(o)?i[n].value=o:e.push(`${n}: invalid color "${o}"`);for(let u of Object.keys(s.mode)){let f=l[`${n}#${u}`];Z(f)?i[n].mode[u]=f:e.push(`${n}: invalid color "${f}"`)}break}case"font":{let o=l[n],u=Array.isArray(o)?o:[o];te(u)?i[n].value=u:e.push(`${n}: expected string or array of strings, received ${typeof s.value}`);for(let f of Object.keys(s.mode)){let b=l[`${n}#${f}`],p=Array.isArray(b)?b:[b];te(p)?i[n].mode[f]=p:e.push(`${n}: expected string or array of strings, received ${typeof b}`)}break}case"cubic-bezier":{let o=l[n];ee(o)?(o[0]=Math.max(0,Math.min(1,o[0])),o[2]=Math.max(0,Math.min(1,o[2])),i[n].value=o):e.push(`${n}: expected [x1, y1, x2, y2], received "${o}"`);for(let u of Object.keys(s.mode)){let f=l[`${n}#${u}`];ee(f)?(f[0]=Math.max(0,Math.min(1,f[0])),f[2]=Math.max(0,Math.min(1,f[2])),i[n].mode[u]=f):e.push(`${n}: expected [x1, y1, x2, y2], received "${f}"`)}break}case"url":{let o=l[n];ne(o)?i[n].value=o:e.push(`${n}: invalid url "${o}" (if this is relative, use type: "file")`);for(let u of Object.keys(s.mode)){let f=l[`${n}#${u}`];ne(f)?i[n].mode[u]=f:e.push(`${n}: invalid url "${f}" (if this is relative, use type: "file")`)}break}case"shadow":{let o=l[n];re(o)?i[n].value=o:e.push(`${n}: expected array, received "${s.value}"`);for(let u of Object.keys(s.mode)){let f=l[`${n}#${u}`];re(f)?i[n].mode[u]=f:e.push(`${n}: expected array, received "${f}"`)}break}default:{i[n].value=l[n];for(let o of Object.keys(s.mode))i[n].mode[o]=l[`${n}#${o}`];break}}}catch(o){e.push(`${n}: ${o.message||o}`)}}return e.length&&(r.errors=e),a.length&&(r.warnings=a),r.result.tokens=Object.values(i),r}function Z(t){if(!t||typeof t!="string")return!1;try{return W.from(t),!0}catch{return!1}}function ee(t){return t?Array.isArray(t)&&t.length===4&&t.every(e=>typeof e=="number"&&!Number.isNaN(e)):!1}function T(t){return!!t&&typeof t=="string"}function te(t){return t?typeof t=="string"?!0:Array.isArray(t)&&t.every(e=>typeof e=="string"&&e.length):!1}function re(t){return t?Array.isArray(t)&&t.every(e=>typeof e=="string"&&e.length):!1}function ne(t){if(!t||typeof t!="string")return!1;try{return new URL(t),!0}catch{return!1}}function O(t){let e=[];if(!t.includes("{"))return e;let a=-1;for(let r=0;r<t.length;r++)switch(t[r]){case"\\":{(t[r+1]=="{"||t[r+1]=="}")&&(r+=1);break}case"{":{a=r;break}case"}":{if(a===-1)continue;e.push(t.substring(a,r+1)),a=-1;break}}return e}var he={parse:_};export{he as default,_ 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 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};
//# sourceMappingURL=index.min.js.map
{
"name": "@cobalt-ui/core",
"description": "Schemas and tools for managing design tokens",
"version": "0.1.0",
"version": "0.2.0",
"author": {

@@ -21,7 +21,8 @@ "name": "Drew Powers",

"dependencies": {
"@cobalt-ui/utils": "^0.1.0",
"better-color-tools": "^0.2.0",
"@cobalt-ui/utils": "^0.2.0",
"better-color-tools": "^0.3.0",
"undici": "^4.12.1"
},
"devDependencies": {
"@types/node": "^17.0.8",
"chai": "^4.3.4",

@@ -38,3 +39,3 @@ "mocha": "^9.1.3"

},
"readme": "# @cobalt-ui/core\n\nGenerate code from your design tokens, and sync your design tokens with Figma.\n\n## Install\n\n```\nnpm install @cobalt-ui/core\n```\n\n## Usage\n\n### Parse\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 schema = JSON.parse(co.parse(fs.readFileSync(\"./tokens.json\", \"utf8\")));\n```\n\n### Build\n\nGenerate code from `tokens.json` schema\n\n```js\nimport co from \"@cobalt-ui/core\";\nimport sass from \"@cobalt-ui/sass\";\nimport css from \"@cobalt-ui/css\";\nimport fs from \"fs\";\n\nconst schema = JSON.parse(co.parse(fs.readFileSync(\"./tokens.json\", \"utf8\")));\nconst files = co.build(schema, {\n plugins: [sass(), css()],\n});\n```\n\n### Sync\n\nSync `tokens.json` with Figma\n\n```js\nimport co from \"@cobalt-ui/core\";\nimport fs from \"fs\";\nimport deepmerge from 'deepmerge'\n\nconst schema = Jco.parse(JSON.parse(fs.readFileSync(\"./tokens.json\", \"utf8\")));\nconst updates = co.sync({\n 'https://figma.com/file/ABC123?node_id=123': {\n styles: {\n Black: {type: 'color', id: 'color.black'},\n },\n components: {\n 'Font / Body': {type: 'font', id: 'font.family.body'},\n },\n }\n});\n\nfs.writeFileSync('./tokens.json', deepmerge(schema, updates, {arrayMerge(a, b) => b}));\n```\n"
"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"
}
# @cobalt-ui/core
Generate code from your design tokens, and sync your design tokens with Figma.
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!
For building tokens and syncing with Figma, use `@cobalt-ui/cli`.
## Install

@@ -13,3 +16,3 @@

### Parse
This

@@ -19,46 +22,6 @@ Parse a `tokens.json` file into a JS object

```js
import co from "@cobalt-ui/core";
import fs from "fs";
import co from '@cobalt-ui/core';
import fs from 'fs';
const schema = JSON.parse(co.parse(fs.readFileSync("./tokens.json", "utf8")));
const { errors, warnings, result } = JSON.parse(co.parse(fs.readFileSync('./tokens.json', 'utf8')));
```
### Build
Generate code from `tokens.json` schema
```js
import co from "@cobalt-ui/core";
import sass from "@cobalt-ui/sass";
import css from "@cobalt-ui/css";
import fs from "fs";
const schema = JSON.parse(co.parse(fs.readFileSync("./tokens.json", "utf8")));
const files = co.build(schema, {
plugins: [sass(), css()],
});
```
### Sync
Sync `tokens.json` with Figma
```js
import co from "@cobalt-ui/core";
import fs from "fs";
import deepmerge from 'deepmerge'
const schema = Jco.parse(JSON.parse(fs.readFileSync("./tokens.json", "utf8")));
const updates = co.sync({
'https://figma.com/file/ABC123?node_id=123': {
styles: {
Black: {type: 'color', id: 'color.black'},
},
components: {
'Font / Body': {type: 'font', id: 'font.family.body'},
},
}
});
fs.writeFileSync('./tokens.json', deepmerge(schema, updates, {arrayMerge(a, b) => b}));
```

@@ -1,18 +0,29 @@

import type { TokenType, ParseResult, Schema } from './parse.js';
import type { Group, ParsedToken, TokenType } from './@types/token';
export type {
ColorToken,
ConicGradientToken,
CubicBezierToken,
DimensionToken,
DurationToken,
FileToken,
FontToken,
FontWeightName,
GradientStop,
GradientToken,
Group,
LinearGradientToken,
Mode,
ParsedMetadata,
ParsedColorToken,
ParsedCubicBezierToken,
ParsedDimensionToken,
ParsedDurationToken,
ParsedFileToken,
ParsedFontToken,
ParsedGradientToken,
ParsedShadowToken,
ParsedToken,
ParseResult,
RadialGradientToken,
Schema,
ParsedTransitionToken,
ParsedTypographyToken,
ParsedTypographyValue,
ParsedURLToken,
ShadowToken,
ShadowValue,
Token,

@@ -22,6 +33,9 @@ TokenBase,

TokenType,
} from './parse.js';
import { parse } from './parse.js';
export { parse } from './parse.js';
TransitionToken,
URLToken,
} from './@types/token';
import { parse } from './parse/index.js';
export { parse, ParseResult } from './parse/index.js';
export interface BuildResult {

@@ -52,3 +66,3 @@ /** File to output inside config.outDir (ex: ./tokens.sass) */

export interface Config {
export interface ResolvedConfig {
tokens: URL;

@@ -63,8 +77,8 @@ outDir: URL;

/** (optional) load config */
config?: (config: Config) => void;
config?: (config: ResolvedConfig) => void;
/** main build fn */
build(options: { schema: ParseResult['result']; rawSchema: Schema }): Promise<BuildResult[]>;
build(options: { tokens: ParsedToken[]; metadata: Record<string, unknown>; rawSchema: Group }): Promise<BuildResult[]>;
}
export interface UserConfig {
export interface Config {
/** path to tokens.json (default: "./tokens.json") */

@@ -71,0 +85,0 @@ tokens?: string;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc