@webority/tokens 0.101.0 → 0.101.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/brand.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{EMAIL_COLOR_ROLES as e,EMAIL_PADDING_PATTERN as t,EMAIL_PADDING_ROLES as n,EMAIL_SHAPE as r,EMAIL_SPACE as i,EMAIL_TYPE_ROLES as a}from"./emit/email.js";import{readFileSync as o}from"node:fs";var s=Object.freeze({css:`brand.css`,bootstrap:`_brand-variables.scss`,web:`webority-web.json`,web390:`webority-web-390.json`,phoneTheme:`webority-phone.json`,phone:`brand.phone.js`,email:`email.json`}),c=`generated`,l=/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,u=[`palette`,`color`,`effect`,`font`,`radius`],d=[`space`,`text`,`shadow`,`section`,`component`,`email`],f=[`radius`,`padding`],p=[`size`,`lineHeight`,`phoneSize`,`phoneLineHeight`],m=/^(#[0-9a-fA-F]{6}|\{color\.[a-z0-9-]+\})$/;function h(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function g(e){return h(e)&&Object.hasOwn(e,`$value`)}function _(e,t){let n=[],r=(e,t)=>{for(let i of Object.keys(e)){if(i.startsWith(`$`))continue;let a=e[i],o=`${t}.${i}`;g(a)?n.push({path:o,node:a}):h(a)&&r(a,o)}};return r(e,t),n}function v(e,t){let n=e;for(let e of t.split(`.`)){if(!h(n)||!Object.hasOwn(n,e))return!1;n=n[e]}return g(n)}function y(e){let t=e?.$extensions?.[`com.webority`];return h(t)?t:{}}function b(e){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e)&&!/^[0-9]+$/.test(e)}function x(e){return typeof e==`string`&&m.test(e)}function S(e){return h(e)&&Number.isInteger(e.value)&&e.value>=0&&e.unit===`px`}function C(e,t){return e===`space`?n.has(t):e===`button`&&t===`padding`}function w(e,n,r,i,a){let o=y(r);for(let t of Object.keys(o))(e!==`color`||t!==`dark`)&&a(i,`$extensions.com.webority.${t} is not allowed on this token`,`Remove it`);if(e===`color`)x(r.$value)||a(i,`$value is not a colour`,`Write "#RRGGBB" or a reference such as "{color.primary}"`),Object.hasOwn(o,`dark`)&&!x(o.dark)&&a(i,`$extensions.com.webority.dark is not a colour`,`Write "#RRGGBB" or a reference such as "{color.primary}"`);else if(e===`type`){let e=r.$value;h(e)&&Object.keys(e).length===p.length&&p.every(t=>Number.isInteger(e[t])&&e[t]>0)||a(i,`$value is not { size, lineHeight, phoneSize, phoneLineHeight } in whole px`,`Write it as { "size": 16, "lineHeight": 24, "phoneSize": 15, "phoneLineHeight": 22 }`)}else C(e,n)?(typeof r.$value!=`string`||!t.test(r.$value))&&a(i,`$value is not CSS px padding`,`Write it as "22px 24px", one to four px values or 0`):S(r.$value)||a(i,`$value is not { value, unit }`,`Write it as { "value": 12, "unit": "px" }`)}function T(t,n){let o={color:Object.keys(e),type:Object.keys(a),space:Object.keys(i),shape:Object.keys(r),button:f};for(let e of Object.keys(t))if(!e.startsWith(`$`)){if(!Object.hasOwn(o,e)){n(`email.${e}`,`is not an email group`,`Use one of ${Object.keys(o).join(`, `)}`);continue}if(!h(t[e])){n(`email.${e}`,`is not a group`,`Write it as an object of tokens`);continue}for(let r of Object.keys(t[e])){if(r.startsWith(`$`))continue;let i=`email.${e}.${r}`;if(!o[e].includes(r)){n(i,`is not an email role`,`Use one of ${o[e].join(`, `)}`);continue}let a=t[e][r];if(!g(a)){n(i,`is not a token`,`Give it a $value`);continue}w(e,r,a,i,n)}}}function E(e,t,n){let r;try{r=JSON.parse(o(e,`utf8`))}catch(t){throw Error(`${e}: (file): cannot be read as JSON (${t.message}). Restore the file or fix the JSON`)}if(!h(r))throw Error(`${e}: (file): is not a JSON object. Write the brand as one object with the groups palette, color, effect, font and radius`);let i=[],a=(t,n,r)=>{let a=`${e}: ${t}: ${n}. ${r}`;i.includes(a)||i.push(a)},s=y(r);for(let e of Object.keys(s))e!==`brand`&&e!==`deviation`&&a(`$extensions.com.webority.${e}`,`is not a brand file key`,`Remove it`);let c=Object.hasOwn(s,`deviation`),f=c&&typeof s.deviation==`string`&&Object.hasOwn(n,s.deviation);c&&!f&&a(`$extensions.com.webority.deviation`,`${s.deviation} is not in deviations.json`,`Use a key of deviations.json`),(typeof s.brand!=`string`||!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(s.brand))&&a(`$extensions.com.webority.brand`,`is missing or not kebab case`,`Name the product in kebab case, such as capnix`);let p=f?n[s.deviation].groups:[],m={},x=null;for(let e of Object.keys(r))if(!e.startsWith(`$`)){if(!u.includes(e)&&!d.includes(e)){a(e,`is not a brand group`,`A brand file holds only palette, color, effect, font and radius, plus the groups a recorded deviation allows`);continue}if(d.includes(e)&&!p.includes(e)){a(e,`this group needs a recorded deviation`,`Add $extensions.com.webority.deviation naming an entry of deviations.json, or remove the group`);continue}if(!h(r[e])){a(e,`is not a group`,`Write it as an object of tokens`);continue}if(e===`email`){x=r[e];continue}m[e]=r[e]}for(let[e,t]of Object.entries(m))for(let{path:n,node:r}of _(t,e)){let t=y(r);for(let
|
|
1
|
+
import{EMAIL_COLOR_ROLES as e,EMAIL_PADDING_PATTERN as t,EMAIL_PADDING_ROLES as n,EMAIL_SHAPE as r,EMAIL_SPACE as i,EMAIL_TYPE_ROLES as a}from"./emit/email.js";import{readFileSync as o}from"node:fs";var s=Object.freeze({css:`brand.css`,bootstrap:`_brand-variables.scss`,web:`webority-web.json`,web390:`webority-web-390.json`,phoneTheme:`webority-phone.json`,phone:`brand.phone.js`,email:`email.json`}),c=`generated`,l=/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,u=[`palette`,`color`,`effect`,`font`,`radius`],d=[`space`,`text`,`shadow`,`section`,`component`,`email`],f=[`radius`,`padding`],p=[`size`,`lineHeight`,`phoneSize`,`phoneLineHeight`],m=/^(#[0-9a-fA-F]{6}|\{color\.[a-z0-9-]+\})$/;function h(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function g(e){return h(e)&&Object.hasOwn(e,`$value`)}function _(e,t){let n=[],r=(e,t)=>{for(let i of Object.keys(e)){if(i.startsWith(`$`))continue;let a=e[i],o=`${t}.${i}`;g(a)?n.push({path:o,node:a}):h(a)&&r(a,o)}};return r(e,t),n}function v(e,t){let n=e;for(let e of t.split(`.`)){if(!h(n)||!Object.hasOwn(n,e))return!1;n=n[e]}return g(n)}function y(e){let t=e?.$extensions?.[`com.webority`];return h(t)?t:{}}function b(e){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e)&&!/^[0-9]+$/.test(e)}function x(e){return typeof e==`string`&&m.test(e)}function S(e){return h(e)&&Number.isInteger(e.value)&&e.value>=0&&e.unit===`px`}function C(e,t){return e===`space`?n.has(t):e===`button`&&t===`padding`}function w(e,n,r,i,a){let o=y(r);for(let t of Object.keys(o))(e!==`color`||t!==`dark`)&&a(i,`$extensions.com.webority.${t} is not allowed on this token`,`Remove it`);if(e===`color`)x(r.$value)||a(i,`$value is not a colour`,`Write "#RRGGBB" or a reference such as "{color.primary}"`),Object.hasOwn(o,`dark`)&&!x(o.dark)&&a(i,`$extensions.com.webority.dark is not a colour`,`Write "#RRGGBB" or a reference such as "{color.primary}"`);else if(e===`type`){let e=r.$value;h(e)&&Object.keys(e).length===p.length&&p.every(t=>Number.isInteger(e[t])&&e[t]>0)||a(i,`$value is not { size, lineHeight, phoneSize, phoneLineHeight } in whole px`,`Write it as { "size": 16, "lineHeight": 24, "phoneSize": 15, "phoneLineHeight": 22 }`)}else C(e,n)?(typeof r.$value!=`string`||!t.test(r.$value))&&a(i,`$value is not CSS px padding`,`Write it as "22px 24px", one to four px values or 0`):S(r.$value)||a(i,`$value is not { value, unit }`,`Write it as { "value": 12, "unit": "px" }`)}function T(t,n){let o={color:Object.keys(e),type:Object.keys(a),space:Object.keys(i),shape:Object.keys(r),button:f};for(let e of Object.keys(t))if(!e.startsWith(`$`)){if(!Object.hasOwn(o,e)){n(`email.${e}`,`is not an email group`,`Use one of ${Object.keys(o).join(`, `)}`);continue}if(!h(t[e])){n(`email.${e}`,`is not a group`,`Write it as an object of tokens`);continue}for(let r of Object.keys(t[e])){if(r.startsWith(`$`))continue;let i=`email.${e}.${r}`;if(!o[e].includes(r)){n(i,`is not an email role`,`Use one of ${o[e].join(`, `)}`);continue}let a=t[e][r];if(!g(a)){n(i,`is not a token`,`Give it a $value`);continue}w(e,r,a,i,n)}}}function E(e,t,n){let r;try{r=JSON.parse(o(e,`utf8`))}catch(t){throw Error(`${e}: (file): cannot be read as JSON (${t.message}). Restore the file or fix the JSON`)}if(!h(r))throw Error(`${e}: (file): is not a JSON object. Write the brand as one object with the groups palette, color, effect, font and radius`);let i=[],a=(t,n,r)=>{let a=`${e}: ${t}: ${n}. ${r}`;i.includes(a)||i.push(a)},s=y(r);for(let e of Object.keys(s))e!==`brand`&&e!==`deviation`&&a(`$extensions.com.webority.${e}`,`is not a brand file key`,`Remove it`);let c=Object.hasOwn(s,`deviation`),f=c&&typeof s.deviation==`string`&&Object.hasOwn(n,s.deviation);c&&!f&&a(`$extensions.com.webority.deviation`,`${s.deviation} is not in deviations.json`,`Use a key of deviations.json`),(typeof s.brand!=`string`||!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(s.brand))&&a(`$extensions.com.webority.brand`,`is missing or not kebab case`,`Name the product in kebab case, such as capnix`);let p=f?n[s.deviation].groups:[],m={},x=null;for(let e of Object.keys(r))if(!e.startsWith(`$`)){if(!u.includes(e)&&!d.includes(e)){a(e,`is not a brand group`,`A brand file holds only palette, color, effect, font and radius, plus the groups a recorded deviation allows`);continue}if(d.includes(e)&&!p.includes(e)){a(e,`this group needs a recorded deviation`,`Add $extensions.com.webority.deviation naming an entry of deviations.json, or remove the group`);continue}if(!h(r[e])){a(e,`is not a group`,`Write it as an object of tokens`);continue}if(e===`email`){x=r[e];continue}m[e]=r[e]}for(let[e,t]of Object.entries(m))for(let{path:n,node:r}of _(t,e)){let t=y(r);for(let r of Object.keys(t))r!==`platforms`&&r!==`dark`&&!(r===`faces`&&e===`font`)&&a(n,`$extensions.com.webority.${r} is not allowed on a token`,`Remove it`);if(Object.hasOwn(t,`platforms`)){let e=t.platforms;Array.isArray(e)&&e.length>0&&e.every(e=>e===`web`||e===`phone`)||a(n,`$extensions.com.webority.platforms is not a list of web and phone`,`Write it as ["phone"], ["web"] or both`)}Object.hasOwn(t,`dark`)&&e!==`color`&&e!==`effect`&&a(n,`$extensions.com.webority.dark applies to colour and effect tokens only`,`Remove it`)}for(let{path:e,node:t}of _(m.palette??{},`palette`))e.split(`.`).slice(1).every(b)||a(e,`the step name is not kebab case`,`Name it such as primary-500`),typeof t.$value!=`string`&&a(e,`$value is not a string`,`Write the colour as text such as "#0F766E" or a reference such as "{palette.primary}"`);let S=(e,n,r)=>{let i=`${e}.${n}`,o=y(r),s=v(t.meaning,i);typeof r.$value!=`string`&&a(i,`$value is not a string`,e===`color`?`Write a colour or a reference such as "{palette.primary}"`:`Write the effect as text such as a filter, colour or gradient`),s?v(t.modeDark,i)&&typeof o.dark!=`string`&&a(i,`needs $extensions.com.webority.dark because the meaning has a dark value`,`Add the dark value beside the light one`):(b(n)||a(i,`the name is not kebab case`,`Name it in kebab case`),(typeof r.$description!=`string`||r.$description===``)&&a(i,`is not a fleet meaning and has no $description`,`Add a $description saying what the colour is for, or use a meaning the library defines`)),Object.hasOwn(o,`dark`)&&typeof o.dark!=`string`&&a(i,`$extensions.com.webority.dark is not a string`,`Write a colour or a reference`)};for(let e of[`color`,`effect`]){let t=m[e]??{};for(let n of Object.keys(t))if(!n.startsWith(`$`)){if(!g(t[n])){a(`${e}.${n}`,`is not a token`,`Give it a $value`);continue}S(e,n,t[n])}}let C=Object.keys(t.scale.font??{}).filter(e=>g(t.scale.font[e]));for(let{path:e,node:n}of _(m.font??{},`font`)){v(t.scale,e)||a(e,`is not a fleet font`,`Use one of ${C.join(`, `)}`);let r=n.$value;if((!Array.isArray(r)||r.length===0||!r.every(e=>typeof e==`string`))&&a(e,`$value is not a list of font family names`,`Write it as ["Webority Sans", "system-ui", "sans-serif"]`),Object.hasOwn(y(n),`faces`)){let t=y(n).faces,r=[`normal`,`medium`,`semibold`,`bold`];h(t)&&Object.keys(t).length>0&&Object.keys(t).every(e=>r.includes(e))&&Object.values(t).every(e=>typeof e==`string`&&e!==``)||a(e,`faces is not a map of weight to font file name`,`Write it as { "normal": "AcmeSans-Regular", "semibold": "AcmeSans-SemiBold" }`)}}let w=Object.keys(t.scale.radius??{}).filter(e=>g(t.scale.radius[e]));for(let{path:e,node:n}of _(m.radius??{},`radius`)){v(t.scale,e)||a(e,`is not on the radius scale`,`Use one of ${w.join(`, `)}`);let r=n.$value;(!(h(r)&&typeof r.value==`number`&&Number.isFinite(r.value)&&r.value>=0)||r.unit!==`px`)&&a(e,`$value is not { value, unit }`,`Write it as { "value": 12, "unit": "px" }`)}x!==null&&T(x,a);let E=structuredClone(r);delete E.$extensions,delete E.$description,delete E.email;for(let e of[`color`,`effect`])for(let{node:t}of _(E[e]??{},e))Object.hasOwn(y(t),`dark`)&&(delete t.$extensions[`com.webority`].dark,Object.keys(t.$extensions[`com.webority`]).length===0&&delete t.$extensions[`com.webority`],Object.keys(t.$extensions).length===0&&delete t.$extensions);let D=e=>v(E,e)||v(t.palette,e)||v(t.scale,e)||v(t.meaning,e);for(let e of Object.keys(m))for(let{path:t,node:n}of _(m[e],e)){let e=[n.$value,y(n).dark].filter(e=>typeof e==`string`);for(let n of e)for(let e of n.matchAll(l))D(e[1])||a(t,`references {${e[1]}}, which no palette step, meaning, scale step or brand token defines`,`Name an existing token or add it to the brand file`)}if(i.length>0)throw Error(i.join(`
|
|
2
2
|
`));let O={};for(let e of[`color`,`effect`])for(let{path:t,node:n}of _(m[e]??{},e)){let r=y(n).dark;if(typeof r!=`string`)continue;let i=t.slice(e.length+1);O[e]??={},O[e][i]=n.$type===void 0?{$value:r}:{$value:r,$type:n.$type}}return{name:s.brand,base:E,dark:O,email:x}}export{s as BRAND_OUTPUT_FILES,c as HEAD_FOLDER,E as loadBrand};
|
package/dist/meanings.json
CHANGED
package/dist/model/resolve.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{cssVarOfPath as e}from"../names.js";import{line as t}from"./load.js";import{resolveColour as n}from"./colour.js";import{findCycles as r,mapReferences as i,referencesIn as a}from"./references.js";function o(){return[{mode:`light`,platform:`web`,width:1440},{mode:`dark`,platform:`web`,width:1440},{mode:`light`,platform:`web`,width:390},{mode:`dark`,platform:`web`,width:390},{mode:`light`,platform:`phone`,width:null},{mode:`dark`,platform:`phone`,width:null}]}function s(e){return`${e.mode}|${e.platform}|${e.width}`}function c(e,t,n){if(typeof e==`string`)return e;if(typeof e==`number`)return String(e);if(typeof e==`object`&&e&&`value`in e&&`unit`in e)return`${e.value}${e.unit}`;throw Error(`model: ${t} cannot sit inside the text of ${n}`)}function l({tokens:l,layers:u,cssNames:d,source:f,refusals:p}){let m=o(),h=e=>{let t=m.find(t=>t.mode===e.mode&&t.platform===e.platform&&t.width===e.width);if(!t)throw Error(`model: ${JSON.stringify(e)} is not one of the model's contexts`);return t},g=e=>{let t=[u.base];return e.mode===`dark`&&t.push(u.dark),e.platform===`phone`&&t.push(u.phone),e.platform===`web`&&e.width===390&&t.push(u.width390),t.push(u.brandBase),e.mode===`dark`&&t.push(u.brandDark),t},_=new Set([u.brandBase,u.brandDark]),v=(e,t,n)=>n.platform===`phone`&&_.has(e)&&t.startsWith(`font.`),y=(e,t)=>{let n=g(t).reverse();for(let r of n){if(v(r,e,t))continue;let n=r.get(e);if(n)return n}},b=(e,t)=>{let n=l.get(e);return n?n.platforms===null||n.platforms.includes(t.platform):!1},x=(e,t)=>{if(!b(e,t))throw Error(`model: ${e} does not exist on ${t.platform}`)},S=new Map,C=(t,r)=>{let a=`${s(r)}|${t}`;if(S.has(a))return S.get(a);x(t,r);let o=l.get(t),{value:u}=y(t,r),d;if(o.type===`color`){if(typeof u!=`string`)throw Error(`model: ${t} is a colour with a value that is not text`);if(o.extensions.derive)throw Error(`model: ${t} uses derive, which is removed; set the colour itself`);d=n(i(u,t=>`var(${e(t)})`),e=>w(e,r))}else d=i(u,(e,n)=>{let i=C(e,r);return n?i:c(i,e,t)});return S.set(a,d),d},w=(e,t)=>{let n=d.get(e);if(n===void 0||!b(n,t))return;if(l.get(n).type===`color`)return C(n,t);let{value:r}=y(n,t);return typeof r==`string`?r:void 0},T=()=>{for(let e of Object.values(u))for(let[n,r]of e)for(let e of a(r.value))if(!l.has(e)){let i=t(r.file,n,`references ${e}, which no token declares`,`Declare ${e} or correct the name.`);p.includes(i)||p.push(i)}},E=()=>{for(let e of m){let n=new Map;for(let t of l.keys())b(t,e)&&n.set(t,a(y(t,e).value));for(let i of r(n)){let n=t(y(i[0],e).file,i[0],`reference cycle ${i.join(` -> `)}`,`Point one of these tokens at a value instead.`);p.includes(n)||p.push(n)}}},D=()=>{for(let e of m)for(let n of l.keys()){if(!b(n,e))continue;let{file:r,value:i}=y(n,e);for(let o of a(i))if(l.has(o)&&!b(o,e)){let i=t(r,n,`references ${o}, which does not exist on ${e.platform}`,`Mark ${n} for the platform that has ${o}, or give ${n} a ${e.platform} override.`);p.includes(i)||p.push(i)}}},O=()=>{for(let e of m)for(let n of l.keys())if(b(n,e))try{C(n,e)}catch(r){let i=t(y(n,e).file,n,r.message.replace(/\.$/,``),`Correct the value or the tokens it references.`);p.includes(i)||p.push(i)}},k=p.length;T();let A=p.length>k;if(A||E(),A||D(),p.length===0&&O(),p.length>0)throw Error(p.join(`
|
|
1
|
+
import{cssVarOfPath as e}from"../names.js";import{line as t}from"./load.js";import{resolveColour as n}from"./colour.js";import{findCycles as r,mapReferences as i,referencesIn as a}from"./references.js";function o(){return[{mode:`light`,platform:`web`,width:1440},{mode:`dark`,platform:`web`,width:1440},{mode:`light`,platform:`web`,width:390},{mode:`dark`,platform:`web`,width:390},{mode:`light`,platform:`phone`,width:null},{mode:`dark`,platform:`phone`,width:null}]}function s(e){return`${e.mode}|${e.platform}|${e.width}`}function c(e,t,n){if(typeof e==`string`)return e;if(typeof e==`number`)return String(e);if(typeof e==`object`&&e&&`value`in e&&`unit`in e)return`${e.value}${e.unit}`;throw Error(`model: ${t} cannot sit inside the text of ${n}`)}function l({tokens:l,layers:u,cssNames:d,source:f,refusals:p}){let m=o(),h=e=>{let t=m.find(t=>t.mode===e.mode&&t.platform===e.platform&&t.width===e.width);if(!t)throw Error(`model: ${JSON.stringify(e)} is not one of the model's contexts`);return t},g=e=>{let t=[u.base];return e.mode===`dark`&&t.push(u.dark),e.platform===`phone`&&t.push(u.phone),e.platform===`web`&&e.width===390&&t.push(u.width390),t.push(u.brandBase),e.mode===`dark`&&t.push(u.brandDark),t},_=new Set([u.brandBase,u.brandDark]),v=(e,t,n)=>n.platform===`phone`&&_.has(e)&&t.startsWith(`font.`)&&!l.get(t).extensions.faces,y=(e,t)=>{let n=g(t).reverse();for(let r of n){if(v(r,e,t))continue;let n=r.get(e);if(n)return n}},b=(e,t)=>{let n=l.get(e);return n?n.platforms===null||n.platforms.includes(t.platform):!1},x=(e,t)=>{if(!b(e,t))throw Error(`model: ${e} does not exist on ${t.platform}`)},S=new Map,C=(t,r)=>{let a=`${s(r)}|${t}`;if(S.has(a))return S.get(a);x(t,r);let o=l.get(t),{value:u}=y(t,r),d;if(o.type===`color`){if(typeof u!=`string`)throw Error(`model: ${t} is a colour with a value that is not text`);if(o.extensions.derive)throw Error(`model: ${t} uses derive, which is removed; set the colour itself`);d=n(i(u,t=>`var(${e(t)})`),e=>w(e,r))}else d=i(u,(e,n)=>{let i=C(e,r);return n?i:c(i,e,t)});return S.set(a,d),d},w=(e,t)=>{let n=d.get(e);if(n===void 0||!b(n,t))return;if(l.get(n).type===`color`)return C(n,t);let{value:r}=y(n,t);return typeof r==`string`?r:void 0},T=()=>{for(let e of Object.values(u))for(let[n,r]of e)for(let e of a(r.value))if(!l.has(e)){let i=t(r.file,n,`references ${e}, which no token declares`,`Declare ${e} or correct the name.`);p.includes(i)||p.push(i)}},E=()=>{for(let e of m){let n=new Map;for(let t of l.keys())b(t,e)&&n.set(t,a(y(t,e).value));for(let i of r(n)){let n=t(y(i[0],e).file,i[0],`reference cycle ${i.join(` -> `)}`,`Point one of these tokens at a value instead.`);p.includes(n)||p.push(n)}}},D=()=>{for(let e of m)for(let n of l.keys()){if(!b(n,e))continue;let{file:r,value:i}=y(n,e);for(let o of a(i))if(l.has(o)&&!b(o,e)){let i=t(r,n,`references ${o}, which does not exist on ${e.platform}`,`Mark ${n} for the platform that has ${o}, or give ${n} a ${e.platform} override.`);p.includes(i)||p.push(i)}}},O=()=>{for(let e of m)for(let n of l.keys())if(b(n,e))try{C(n,e)}catch(r){let i=t(y(n,e).file,n,r.message.replace(/\.$/,``),`Correct the value or the tokens it references.`);p.includes(i)||p.push(i)}},k=p.length;T();let A=p.length>k;if(A||E(),A||D(),p.length===0&&O(),p.length>0)throw Error(p.join(`
|
|
2
2
|
`));return{tokens:l,contexts:o(),existsIn:(e,t)=>b(e,h(t)),valueIn:(e,t)=>{let n=h(t);return x(e,n),structuredClone(y(e,n).value)},resolvedIn:(e,t)=>{let n=h(t);return structuredClone(C(e,n))},referenceIn:(e,t)=>{let n=h(t);return x(e,n),a(y(e,n).value)[0]},source:f}}export{o as buildContexts,l as buildModel};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/tokens",
|
|
3
|
-
"version": "0.101.
|
|
3
|
+
"version": "0.101.1",
|
|
4
4
|
"description": "The Webority design tokens in one W3C Design Tokens source (palette, scale, meaning and component tiers, with light and dark, web and phone, and 390 and 1440 widths), and the webority command that brands a product, upgrades it between releases and checks it against the token source.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|