@webority/tokens 0.109.9 → 0.110.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.d.ts +2 -0
- package/dist/build.js +5 -5
- package/dist/canvas/webority-phone.json +1 -1
- package/dist/canvas/webority-web-390.json +1 -1
- package/dist/canvas/webority-web.json +1 -1
- package/dist/emit/web.js +12 -12
- package/dist/meanings.json +1 -1
- package/dist/model/contrast.js +1 -0
- package/dist/model/load.js +1 -1
- package/dist/model/resolve.js +1 -1
- package/package.json +1 -1
package/dist/brand.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface BrandLayer {
|
|
|
27
27
|
dark: object;
|
|
28
28
|
/** The email group, kept outside base because the web model never reads it; null when the file has none. */
|
|
29
29
|
email: BrandEmailGroup | null;
|
|
30
|
+
/** Phone-only overrides the brand tool derives for a readable primary pair (color.primary per mode); loadBrand never sets it. */
|
|
31
|
+
phone?: { light: object; dark: object };
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
/** A brand group a recorded deviation can allow beyond palette, color, effect, font and radius. */
|
package/dist/build.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{emitEmail as t}from"./emit/email.js";import{BRAND_OUTPUT_FILES as n,HEAD_FOLDER as r,loadBrand as i}from"./brand.js";import{require__2020 as a}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import o from"./canvas-renames.js";import s from"./deviations.js";import{emitCanvas as c}from"./emit/canvas.js";import{emitMeanings as l}from"./emit/meanings.js";import{emitPhoneBrand as u,emitPhoneTheme as d,phoneSets as f}from"./emit/phone.js";import{emitWeb as p}from"./emit/web.js";import{
|
|
2
|
-
`));if(
|
|
3
|
-
`));let
|
|
4
|
-
`))t.length!==0&&
|
|
5
|
-
`));for(let[e,t]of
|
|
1
|
+
import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{emitEmail as t}from"./emit/email.js";import{BRAND_OUTPUT_FILES as n,HEAD_FOLDER as r,loadBrand as i}from"./brand.js";import{require__2020 as a}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import o from"./canvas-renames.js";import s from"./deviations.js";import{emitCanvas as c}from"./emit/canvas.js";import{emitMeanings as l}from"./emit/meanings.js";import{emitPhoneBrand as u,emitPhoneTheme as d,phoneSets as f}from"./emit/phone.js";import{emitWeb as p}from"./emit/web.js";import{phonePairLayer as m}from"./model/contrast.js";import{loadModel as h}from"./model/index.js";import{mkdir as g,readFile as _,writeFile as v}from"node:fs/promises";import y from"node:path";var b=e(a(),1),x=new URL(`../schema/design-map.schema.json`,import.meta.url),S=new URL(`../package.json`,import.meta.url),C={palette:`palette.tokens.json`,scale:`scale.tokens.json`,meaning:`meaning.tokens.json`,modeDark:`mode.dark.tokens.json`},w=/^.+: \S+: .+\. .+$/;async function T(e){let r=y.resolve(e.root??process.cwd()),a=e.check===!0,{version:C}=JSON.parse(await _(S,`utf8`)),T=[],k=[],A=async(e,t)=>{if(a){let n=null;try{n=await _(e,`utf8`)}catch(e){if(e.code!==`ENOENT`)throw e}n!==t&&k.push(e);return}await g(y.dirname(e),{recursive:!0}),await v(e,t,`utf8`),T.push(e)};if(e.library===!0){if(e.brand!==void 0)throw Error(`brand: --brand: not allowed with --library. Remove it.`);if(!e.out)throw Error(`brand: --out: required with --library. Pass --out <dir>.`);let t=y.resolve(r,e.out),i=await h(),a=c(i),s=[[y.join(t,`canvas`,n.web),E(a.web)],[y.join(t,`canvas`,n.web390),E(a.web390)],[y.join(t,`canvas`,n.phoneTheme),E(a.phone)],[y.join(t,`meanings.json`),E(l(i))],[y.join(t,`canvas`,`renames.json`),E(o)]];if(e.web){let t=p(i),n=y.resolve(r,e.web);s.push([n,t.tokens]),s.push([y.join(y.dirname(n),`_bootstrap.generated.scss`),t.bootstrap])}if(e.phone){let t=d({light:f(i,`light`),dark:f(i,`dark`)});s.push([y.resolve(r,e.phone),t.contents])}for(let[e,t]of s)await A(e,t);return{written:T,stale:k}}let j=y.join(r,`.webority`,`design.json`),M;try{M=await _(j,`utf8`)}catch(e){throw e.code===`ENOENT`?Error(`${j}: file missing. Run from the repo root or create the design map.`):e}let N;try{N=JSON.parse(M)}catch(e){throw Error(`${j}: /: ${e.message}. Fix the design map.`)}let P=JSON.parse(await _(x,`utf8`)),F=new b.Ajv2020({allErrors:!0,strict:!1}).compile(P);if(!F(N))throw Error(F.errors.map(e=>`${j}: ${e.instancePath||`/`}: ${e.message}. Fix the design map.`).join(`
|
|
2
|
+
`));if(N.tokens===void 0)throw Error(`${j}: /tokens: missing. Add tokens.brands to .webority/design.json.`);let I=N.tokens.brands,L=N.tokens.heads??[];if((e.brand!==void 0||e.out!==void 0)&&I.length>1)throw Error(`brand: --brand/--out: the repo has ${I.length} brands. Remove the flag to build every brand.`);let R=[];if(I.forEach((e,t)=>{e.source===`library`&&R.push(`${j}: tokens.brands[${t}].source: "library" is built with --library. Run webority brand --library --out <dir>.`)}),L.forEach((e,t)=>{I.some(t=>t.name===e.brand)||R.push(`${j}: tokens.heads[${t}].brand: no brand named ${e.brand}. Add it to tokens.brands.`)}),R.length>0)throw Error(R.join(`
|
|
3
|
+
`));let z=await O(),B=await h(),V={light:f(B,`light`),dark:f(B,`dark`)},H=[];for(let a of I){let o=I.length===1&&e.brand!==void 0?e.brand:a.source,l=I.length===1&&e.out!==void 0?e.out:a.export,d=y.resolve(r,o);try{let e=i(d,z,s),o=await h({brand:e}),g=m(o,B),_=Object.keys(g.light).length+Object.keys(g.dark).length>0?await h({brand:{...e,phone:g}}):o,v=c(_),b=p(_,{library:B}),x=u(V,{light:f(_,`light`),dark:f(_,`dark`)},{package:`@webority/tokens`,version:C,brand:e.name}),S=E(t(v.web,v.web390,e.email)),w={css:b.css,phone:x.contents,email:S},T=y.resolve(r,l),O=[[y.join(T,n.css),b.css],[y.join(T,n.bootstrap),b.variables],[y.join(T,n.web),E(v.web)],[y.join(T,n.web390),E(v.web390)],[y.join(T,n.phoneTheme),E(v.phone)],[y.join(T,n.phone),x.contents],[y.join(T,n.email),S]];H.push(...O);for(let e of L)e.brand===a.name&&H.push(D(r,e,w))}catch(e){for(let t of String(e?.message??e).split(`
|
|
4
|
+
`))t.length!==0&&R.push(w.test(t)?t:`${d}: -: ${t}. Fix the source.`)}}if(R.length>0)throw Error(R.join(`
|
|
5
|
+
`));for(let[e,t]of H)await A(e,t);return{written:T,stale:k}}function E(e){return`${JSON.stringify(e,null,4)}\n`}function D(e,t,i){let a=y.resolve(e,t.path);return t.kind===`razor`?[y.join(a,`wwwroot`,r,n.css),i.css]:t.kind===`spa`?[y.join(a,`src`,r,n.css),i.css]:t.kind===`phone`?[y.join(a,r,n.phone),i.phone]:[y.join(a,r,n.email),i.email]}async function O(){let e={};for(let[t,n]of Object.entries(C))e[t]=JSON.parse(await _(new URL(`./source/${n}`,import.meta.url),`utf8`));return e}export{T as brand};
|
package/dist/emit/web.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import{BREAKPOINT_PX as e,TOUCH_MEDIA as t,breakpointRules as n,fluidLength as r,touchValue as i}from"../model/length.js";import{cssVarOfPath as a}from"../names.js";var o={mode:`light`,platform:`web`,width:1440},s={mode:`dark`,platform:`web`,width:1440},c={mode:`light`,platform:`web`,width:390},l=/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,u=/^\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}$/,d=/^#[0-9a-f]{6}$/i,f=[[`--bs-body-color`,`text`],[`--bs-emphasis-color`,`text`],[`--bs-secondary-color`,`text-muted`],[`--bs-tertiary-color`,`text-subtle`],[`--bs-body-bg`,`bg`],[`--bs-border-color`,`border`],[`--bs-secondary-bg`,`surface`],[`--bs-tertiary-bg`,`bg-muted`],[`--bs-primary`,`primary`]],p=[[`--bs-body-bg-rgb`,`bg`],[`--bs-primary-rgb`,`primary`],[`--bs-body-color-rgb`,`text`],[`--bs-emphasis-color-rgb`,`text`],[`--bs-secondary-color-rgb`,`text-muted`],[`--bs-tertiary-color-rgb`,`text-subtle`],[`--bs-secondary-bg-rgb`,`surface`],[`--bs-tertiary-bg-rgb`,`bg-muted`],[`--bs-border-color-rgb`,`border`]],m=[[`$body-color`,`color.text-body`],[`$body-secondary-color`,`color.text-muted`],[`$body-tertiary-color`,`color.text-subtle`],[`$body-secondary-bg`,`color.bg-subtle`],[`$body-tertiary-bg`,`color.bg-muted`],[`$border-color`,`color.border`],[`$border-color-translucent`,null],[`$border-radius`,`radius.md`],[`$border-radius-sm`,`radius.sm`],[`$border-radius-lg`,`radius.lg`],[`$border-radius-pill`,`radius.pill`],[`$wui-shadow-overlay`,`shadow.popover`],[`$wui-shadow-overlay-lg`,`shadow.modal`],[`$link-color`,`color.link`],[`$line-height-base`,`leading.body`],[`$headings-line-height`,`leading.heading`],[`$display-line-height`,`leading.display`]],h={"$border-color-translucent":`rgba(13, 24, 43, 0.08)`},
|
|
2
|
-
:root[data-bs-theme="dark"]`,
|
|
3
|
-
[data-bs-theme="dark"]:not(:root)`,
|
|
1
|
+
import{BREAKPOINT_PX as e,TOUCH_MEDIA as t,breakpointRules as n,fluidLength as r,touchValue as i}from"../model/length.js";import{cssVarOfPath as a}from"../names.js";var o={mode:`light`,platform:`web`,width:1440},s={mode:`dark`,platform:`web`,width:1440},c={mode:`light`,platform:`web`,width:390},l=/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,u=/^\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}$/,d=/^#[0-9a-f]{6}$/i,f=[[`--bs-body-color`,`text`],[`--bs-emphasis-color`,`text`],[`--bs-secondary-color`,`text-muted`],[`--bs-tertiary-color`,`text-subtle`],[`--bs-body-bg`,`bg`],[`--bs-border-color`,`border`],[`--bs-secondary-bg`,`surface`],[`--bs-tertiary-bg`,`bg-muted`],[`--bs-primary`,`primary`]],p=[[`--bs-body-bg-rgb`,`bg`],[`--bs-primary-rgb`,`primary`],[`--bs-body-color-rgb`,`text`],[`--bs-emphasis-color-rgb`,`text`],[`--bs-secondary-color-rgb`,`text-muted`],[`--bs-tertiary-color-rgb`,`text-subtle`],[`--bs-secondary-bg-rgb`,`surface`],[`--bs-tertiary-bg-rgb`,`bg-muted`],[`--bs-border-color-rgb`,`border`]],m=[[`$body-color`,`color.text-body`],[`$body-secondary-color`,`color.text-muted`],[`$body-tertiary-color`,`color.text-subtle`],[`$body-secondary-bg`,`color.bg-subtle`],[`$body-tertiary-bg`,`color.bg-muted`],[`$border-color`,`color.border`],[`$border-color-translucent`,null],[`$border-radius`,`radius.md`],[`$border-radius-sm`,`radius.sm`],[`$border-radius-lg`,`radius.lg`],[`$border-radius-pill`,`radius.pill`],[`$wui-shadow-overlay`,`shadow.popover`],[`$wui-shadow-overlay-lg`,`shadow.modal`],[`$link-color`,`color.link`],[`$line-height-base`,`leading.body`],[`$headings-line-height`,`leading.heading`],[`$display-line-height`,`leading.display`]],h=[[`$primary`,`color.primary`]],g={"$border-color-translucent":`rgba(13, 24, 43, 0.08)`},_=[`color.link`,`color.primary-hover`],v=`:root[data-theme="dark"],
|
|
2
|
+
:root[data-bs-theme="dark"]`,y=`[data-theme="dark"]:not(:root),
|
|
3
|
+
[data-bs-theme="dark"]:not(:root)`,b=`:root[data-theme="auto"]`,x=`[data-theme="dark"]:not(:root) [data-theme="light"],
|
|
4
4
|
[data-theme="dark"]:not(:root) [data-bs-theme="light"],
|
|
5
5
|
[data-bs-theme="dark"]:not(:root) [data-theme="light"],
|
|
6
|
-
[data-bs-theme="dark"]:not(:root) [data-bs-theme="light"]`,
|
|
6
|
+
[data-bs-theme="dark"]:not(:root) [data-bs-theme="light"]`,S=`// var() resolves where a name is declared, so the html copies keep the light values for a light box.`,C=`/* var() resolves where a name is declared, so the html copies keep the light values for a light box. */`,w=`// Zero specificity, so a component's own class on a themed section or inside it keeps its colour.`,T=`/* Zero specificity, so a component's own class on a themed section or inside it keeps its colour. */`;function E(e){return String(Number(e.toFixed(4)))}function D(e,t){if(typeof t==`string`)return t.replace(l,(e,t)=>`var(${a(t)})`);if(typeof t==`number`)return E(t);if(Array.isArray(t)){if(e.type===`cubicBezier`&&t.length===4&&t.every(e=>typeof e==`number`))return`cubic-bezier(${t.map(e=>E(e)).join(`, `)})`;if(e.type===`fontFamily`&&t.every(e=>typeof e==`string`))return t.map(e=>/\s/.test(e)?`"${e}"`:e).join(`, `)}else if(t&&typeof t==`object`){if(`unit`in t&&typeof t.value==`number`)return`${E(t.value)}${t.unit}`;if(`color`in t)return[t.offsetX,t.offsetY,t.blur,t.spread,t.color].map(t=>D(e,t)).join(` `)}throw Error(`emitWeb: ${e.path}: cannot write a ${e.type} value as CSS.`)}function O(e,t,n){return D(e.tokens.get(t),e.valueIn(t,n))}function k(e,t){if(t&&typeof t==`object`&&t.unit===`px`&&typeof t.value==`number`)return t.value;throw Error(`emitWeb: ${e}: a text size must be a px dimension.`)}function A(e,t){let i=e.tokens.get(t),s=a(t);if(i.group===`text`){if(n(i).length>0)throw Error(`emitWeb: ${t}: a text size cannot carry breakpoints.`);let a=k(t,e.valueIn(t,c)),l=k(t,e.valueIn(t,o)),u=i.extensions?.fluidUntil;if(a!==l&&u===void 0)throw Error(`emitWeb: ${t}: the 390 and 1440 sizes differ but no fluidUntil is recorded.`);return{path:t,name:s,root:r(a,l,u??1440),tiers:[]}}let l=n(i);return l.length>0?{path:t,name:s,root:O(e,t,c),tiers:l.map(e=>({tier:e.tier,text:D(i,e.value)}))}:{path:t,name:s,root:O(e,t,o),tiers:[]}}function j(e){let t=[];for(let n of e.tokens.keys())e.existsIn(n,o)&&t.push(A(e,n));return t}function M(e,t){let r=[];for(let[i,c]of e.tokens){if(!e.existsIn(i,s)||!e.existsIn(i,o)||n(c).length>0)continue;let l=O(e,i,s);if(c.group===`text`){if(l!==O(e,i,o))throw Error(`emitWeb: ${i}: a text size cannot change with the mode.`);continue}t(i,l)&&r.push({path:i,name:a(i),text:l})}return r}function N(e){let t=Number.parseInt(e.slice(1),16);return`${t>>16&255}, ${t>>8&255}, ${t&255}`}function P(e,t){let n=[];for(let[r,i]of p){let a=`color.${i}`,o=e.resolvedIn(a,s);if(!d.test(o))throw Error(`emitWeb: ${a}: a Bootstrap rgb triplet needs an opaque colour.`);t(a,o)&&n.push({name:r,text:N(o)})}return n}function F(e,t,n){return!e.tokens.has(`color.primary`)||!t.tokens.has(`color.primary`)||e.resolvedIn(`color.primary`,n)===t.resolvedIn(`color.primary`,n)?[]:I(e,n)}function I(e,t){let n=z(e,`color.primary`,t);return[{name:`--bs-primary`,text:n},{name:`--bs-primary-rgb`,text:N(n)}]}function L(e,t,n){return!_.every(n=>e.tokens.has(n)&&t.tokens.has(n))||e.resolvedIn(`color.link`,n)===t.resolvedIn(`color.link`,n)?[]:R(e,n)}function R(e,t){let n=z(e,`color.link`,t),r=z(e,`color.primary-hover`,t);return[{name:`--bs-link-color`,text:n},{name:`--bs-link-color-rgb`,text:N(n)},{name:`--bs-link-hover-color`,text:r},{name:`--bs-link-hover-color-rgb`,text:N(r)}]}function z(e,t,n){let r=e.resolvedIn(t,n);if(!d.test(r))throw Error(`emitWeb: ${t}: a Bootstrap rgb triplet needs an opaque colour.`);return r}function B(e,t){let n=M(e,t?(e,n)=>!t.tokens.has(e)||!t.existsIn(e,s)||n!==O(t,e,s):(t,n)=>n!==O(e,t,o)),r=P(e,t?(e,n)=>n!==t.resolvedIn(e,s):()=>!0);if(t){let i=L(e,t,o).length>0?R(e,s):L(e,t,s);return[...n,...r,...i]}let i=f.map(([e,t])=>({name:e,text:`var(${a(`color.${t}`)})`}));return[...n,...i,...r]}function V(e,t){return`${e} {\n${t.join(`
|
|
7
7
|
`).split(`
|
|
8
8
|
`).map(e=>e===``?e:` ${e}`).join(`
|
|
9
|
-
`)}\n}`}function
|
|
9
|
+
`)}\n}`}function H(e){return e.split(`,
|
|
10
10
|
`).map(e=>`:where(${e})`).join(`,
|
|
11
|
-
`)}function
|
|
12
|
-
`)}\n);`,
|
|
11
|
+
`)}function U(e){let t=[];for(let n=0;n<e.length;n+=6)t.push(e.slice(n,n+6).join(`, `));return[`$wui-dark-layer-names: (\n${t.map((e,n)=>` ${e}${n<t.length-1?`,`:``}`).join(`
|
|
12
|
+
`)}\n);`,S,V(`html`,[`@each $name in $wui-dark-layer-names {`,` --wui-light-#{$name}: var(--#{$name});`,`}`]),V(x,[`@each $name in $wui-dark-layer-names {`,` --#{$name}: var(--wui-light-#{$name});`,`}`]),V(H(x),[`color-scheme: light;`,`color: var(--color-text);`])].join(`
|
|
13
13
|
|
|
14
|
-
`)}function
|
|
14
|
+
`)}function W(e){return[C,V(`html`,e.map(e=>`--wui-light-${e}: var(--${e});`)),V(x,e.map(e=>`--${e}: var(--wui-light-${e});`)),V(H(x),[`color-scheme: light;`,`color: var(--color-text);`])].join(`
|
|
15
15
|
|
|
16
|
-
`)}function
|
|
16
|
+
`)}function G(e,t,n=!1){let{package:r,version:i,brand:a}=e.source,o=t?`Generated by ${r} ${i} for the ${a} brand. Do not edit; run webority brand.`:`Generated by ${r} ${i} from its token source. Do not edit; run webority brand --library.`;return n?`/* ${o} */`:`// ${o}`}function K(n,r){let a=j(n),s=new Map((r?j(r):[]).map(e=>[e.path,e])),c=[],l=a.filter(e=>s.get(e.path)?.root!==e.root).map(e=>`${e.name}: ${e.root};`);r&&(l.push(...F(n,r,o).map(e=>`${e.name}: ${e.text};`)),l.push(...L(n,r,o).map(e=>`${e.name}: ${e.text};`))),l.length>0&&c.push(V(`:root`,l));for(let[t,n]of Object.entries(e)){let e=[];for(let n of a)for(let r of n.tiers)r.tier===t&&s.get(n.path)?.tiers.find(e=>e.tier===t)?.text!==r.text&&e.push(`${n.name}: ${r.text};`);e.length>0&&c.push(V(`@media (min-width: ${n}px)`,[V(`:root`,e)]))}let u=[];for(let e of a){let t=n.tokens.get(e.path),a=i(t);if(a===null)continue;let o=D(t,a),s=r?.tokens.get(e.path),c=s?i(s):null;c!==null&&D(s,c)===o||u.push(`${e.name}: ${o};`)}u.length>0&&c.push(V(`@media ${t}`,[V(`:root`,u)]));let d=B(n,r);if(d.length>0){let e=d.map(e=>`${e.name}: ${e.text};`),t=r?T:w;c.push(V(v,[...e,`color-scheme: dark;`]),V(y,e),`${t}\n${V(H(y),[`color-scheme: dark;`,`color: var(--color-text);`])}`);let n=d.map(e=>e.name.slice(2));if(r){let e=new Set(B(r,null).map(e=>e.name.slice(2))),t=n.filter(t=>!e.has(t));t.length>0&&c.push(W(t))}else c.push(U(n));c.push(V(`@media (prefers-color-scheme: dark)`,[V(b,[...e,`color-scheme: dark;`])]))}return`${[G(n,r!==null,r!==null),...c].join(`
|
|
17
17
|
|
|
18
|
-
`)}\n`}function
|
|
19
|
-
`)}\n`}function
|
|
20
|
-
`)}\n`}function
|
|
18
|
+
`)}\n`}function q(e,t){let n=e.tokens.get(t);if(n.type===`color`)return e.resolvedIn(t,o);let r=e.valueIn(t,o),i=typeof r==`string`?u.exec(r):null;if(i)return q(e,i[1]);let a=D(n,r);if(a.includes(`var(`))throw Error(`emitWeb: ${t}: a Bootstrap variable needs a literal.`);return a}function J(e,t,n){return n===null?g[t]:q(e,n)}function Y(e){let t=m.map(([t,n])=>`${t}: ${J(e,t,n)} !default;`);return`${[G(e,!1),...t].join(`
|
|
19
|
+
`)}\n`}function X(e,t){let n=[...h,...m].filter(([n,r])=>J(e,n,r)!==J(t,n,r)).map(([t,n])=>`${t}: ${J(e,t,n)};`);return`${[G(e,!0),...n].join(`
|
|
20
|
+
`)}\n`}function Z(e,t){return t===void 0?{tokens:K(e,null),bootstrap:Y(e)}:{css:K(e,t.library),variables:X(e,t.library)}}export{Z as emitWeb};
|
package/dist/meanings.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=4.55,t=/^#[0-9a-f]{6}$/i,n=.0025,r=e=>{let t=Number.parseInt(e.slice(1,7),16);return[t>>16&255,t>>8&255,t&255]},i=e=>{let[t,n,i]=r(e).map(e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4});return .2126*t+.7152*n+.0722*i},a=e=>{let[t,n,i]=r(e).map(e=>e/255),a=Math.max(t,n,i),o=Math.min(t,n,i),s=a-o,c=(a+o)/2;if(s===0)return[0,0,c];let l=c>.5?s/(2-a-o):s/(a+o);return[(a===t?((n-i)/s+6)%6:a===n?(i-t)/s+2:(t-n)/s+4)*60,l,c]},o=([e,t,n])=>{let r=t*Math.min(n,1-n),i=t=>{let i=(t+e/30)%12,a=n-r*Math.max(-1,Math.min(i-3,9-i,1));return Math.round(a*255).toString(16).padStart(2,`0`)};return`#${i(0)}${i(8)}${i(4)}`.toUpperCase()},s=(e,t,r)=>{let[i,s,c]=a(e),l=e;for(let e=c+t*n;e>=0&&e<=1;e+=t*n)if(l=o([i,s,e]),r(l))return l;return l};function c(e,t){let[n,r]=[i(e),i(t)].sort((e,t)=>t-e);return(n+.05)/(r+.05)}function l(n,r){if(!t.test(n)||!t.test(r))return n;let a=t=>c(t,r)>=e;return a(n)?n.toLowerCase():s(n,i(r)>i(n)?-1:1,a).toLowerCase()}function u(e,t){let n={};for(let r of[`light`,`dark`]){let i={mode:r,platform:`phone`,width:null};if(![`color.primary`,`color.on-primary`].every(n=>e.existsIn(n,i)&&t.existsIn(n,i)))continue;let a=e.resolvedIn(`color.primary`,i),o=e.resolvedIn(`color.on-primary`,i);if(a===t.resolvedIn(`color.primary`,i)&&o===t.resolvedIn(`color.on-primary`,i))continue;let s=l(a,o);s!==String(a).toLowerCase()&&(n[r]={color:{primary:{$type:`color`,$value:s}}})}return{light:n.light??{},dark:n.dark??{}}}export{e as READABLE_TARGET,c as contrastRatio,l as deriveSolidFill,u as phonePairLayer};
|
package/dist/model/load.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__toESM as e}from"../_virtual/_rolldown/runtime.js";import{require__2020 as t}from"../node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{STEPS as n,cssVarOfPath as r}from"../names.js";import{readFile as i}from"node:fs/promises";import{basename as a,dirname as o,resolve as s}from"node:path";var c=e(t(),1),l=new URL(`../../package.json`,import.meta.url),u=new URL(`../../schema/webority-tokens.schema.json`,import.meta.url),d=`Declare each token in one source file.`;function f(e,t,n,r){return`${e}: ${t}: ${n}. ${r}`}function p(e,t){e.includes(t)||e.push(t)}function m(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function h(e){return m(e)&&typeof e.$ref==`string`}function g(e){let t=[],n=(e,r,i)=>{for(let[a,o]of Object.entries(e)){if(a.startsWith(`$`)||!m(o))continue;let e=[...r,a];`$value`in o?t.push({path:e.join(`.`),token:o,type:o.$type??i.type,extensions:{...i.extensions,...o.$extensions?.[`com.webority`]??{}}}):n(o,e,{type:o.$type??i.type,extensions:{...i.extensions,...o.$extensions?.[`com.webority`]??{}}})}};return n(e,[],{type:void 0,extensions:{}}),t}function _(e){let[t,...n]=e.path.split(`.`),r=e.extensions;return{path:e.path,group:t,name:n.join(`-`),type:e.type??``,description:e.token.$description??null,platforms:r.platforms??null,internal:r.internal===!0,brandOwn:!1,extensions:r}}function v(e,t,i,a){let{path:o,group:s,name:c,type:l}=e;l===``&&p(i,f(t,o,`has no $type`,`Add $type to the token or to its group.`));let u;try{u=r(o)}catch{p(i,f(t,o,`its group ${s} has no CSS prefix`,`Add the group to PREFIX in names.js.`))}let d=n[s];if(d&&!d.includes(c)&&p(i,f(t,o,`"${c}" is not a step of ${s}`,`Use one of: ${d.join(`, `)}.`)),u!==void 0){let e=a.get(u);e===void 0?a.set(u,o):e!==o&&p(i,f(t,o,`its CSS name ${u} is also the name of ${e}`,`Rename one of the two tokens.`))}}function y(e,t,n,r){let i={...e.extensions};return(i.platforms!==void 0||i.internal!==void 0)&&(p(r,f(t,e.path,`changes the platforms or internal mark`,`Set marks in the base set only.`)),delete i.platforms,delete i.internal),Object.assign(n.extensions,i),{value:e.token.$value,file:t}}function b(e,t,n){p(e,f(t,n,`overrides a token the base set does not declare`,`Declare ${n} in the base set first.`))}function x(e,t,n){let r=new Map;for(let{ref:i,data:a}of e)if(a)for(let e of g(a)){let a=t.get(e.path);if(!a){b(n,i,e.path);continue}r.set(e.path,y(e,i,a,n))}return r}async function S(e,t){let n=a(e),r=[],S=o(e),C;try{C=JSON.parse(await i(e,`utf8`))}catch(e){throw Error(f(n,`(file)`,`cannot be read as JSON (${e.message})`,`Restore the file or correct its path.`))}if(!Array.isArray(C.sets)||C.sets.length===0||!C.sets.every(e=>Array.isArray(e?.sources)&&e.sources.every(h)))throw Error(f(n,`sets`,`must be a non-empty array of { sources: [{ "$ref": string }] }`,`Match the resolver of the library source.`));if(!Array.isArray(C.modifiers))throw Error(f(n,`modifiers`,`must be an array`,`Match the resolver of the library source.`));let w=[[`mode`,[`light`,`dark`]],[`platform`,[`web`,`phone`]],[`width`,[`1440`,`390`]]];if(C.modifiers.length!==w.length)throw Error(f(n,`modifiers`,`must hold the mode, platform and width modifiers, in that order`,`Match the resolver of the library source.`));w.forEach(([e,t],r)=>{let i=C.modifiers[r],a=m(i?.contexts)?Object.keys(i.contexts).sort().join(`,`):``;if(!(i?.name===e&&a===[...t].sort().join(`,`)&&t.every(e=>Array.isArray(i.contexts[e])&&i.contexts[e].every(h))&&i.contexts[t[0]].length===0))throw Error(f(n,`modifiers.${e}`,`is not the ${e} modifier with the contexts ${t.join(`, `)} and an empty list for ${t[0]}`,`Match the resolver of the library source, whose default context lists no file.`))});let T=(e,t)=>C.modifiers.find(t=>t.name===e).contexts[t],E=C.sets.flatMap(e=>e.sources.map(e=>e.$ref)),D=T(`mode`,`dark`).map(e=>e.$ref),O=T(`platform`,`phone`).map(e=>e.$ref),k=T(`width`,`390`).map(e=>e.$ref),A=JSON.parse(await i(u,`utf8`)),j=new c.default({allErrors:!0,strict:!1});j.addSchema(A);let M=j.compile(A),N=j.getSchema(`${A.$id}#/$defs/sourceMeaning`),P=new Map,F=async e=>{let t=s(S,e);if(P.has(t))return P.get(t);let n=null;try{n=JSON.parse(await i(t,`utf8`))}catch(n){return p(r,f(e,`(file)`,`cannot be read as JSON (${n.message})`,`Restore the file or correct its $ref in the resolver.`)),P.set(t,null),null}let o=[];M(n)||o.push(...M.errors),a(t)===`meaning.tokens.json`&&!N(n)&&o.push(...N.errors);for(let t of o){if(t.keyword===`if`)continue;let n=t.instancePath.slice(1).split(`/`).filter(e=>e!==``),i=n.length===0?`(file)`:n.map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)).join(`.`),a=t.params?.additionalProperty??t.params?.propertyName,o=a===void 0?t.message:`${t.message} "${a}"`;p(r,f(e,i,o,`Correct it against schema/webority-tokens.schema.json.`))}return P.set(t,n),n},I=async e=>Promise.all(e.map(async e=>({ref:e,data:await F(e)}))),L=await I(E),R=await I(D),z=await I(O),B=await I(k),V=new Map,H=new Map,U=new Map;for(let{ref:e,data:t}of L)if(t)for(let n of g(t)){if(V.has(n.path)){p(r,f(e,n.path,`is already declared in ${U.get(n.path).file}`,d));continue}let t=_(n);v(t,e,r,H),V.set(n.path,t),U.set(n.path,{value:n.token.$value,file:e})}let W=x(R,V,r),G=x(z,V,r),K=x(B,V,r),q=new Map,J=new Map;if(t){let e=`brand ${t.name}`;for(let n of g(t.base)){let t=V.get(n.path);if(t){q.set(n.path,y(n,e,t,r));continue}let i=_(n);v(i,e,r,H),i.brandOwn=!0,V.set(n.path,i),q.set(n.path,{value:n.token.$value,file:e})}for(let n of g(t.dark)){let t=V.get(n.path);if(!t){b(r,e,n.path);continue}J.set(n.path,y(n,e,t,r))}}let
|
|
1
|
+
import{__toESM as e}from"../_virtual/_rolldown/runtime.js";import{require__2020 as t}from"../node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{STEPS as n,cssVarOfPath as r}from"../names.js";import{readFile as i}from"node:fs/promises";import{basename as a,dirname as o,resolve as s}from"node:path";var c=e(t(),1),l=new URL(`../../package.json`,import.meta.url),u=new URL(`../../schema/webority-tokens.schema.json`,import.meta.url),d=`Declare each token in one source file.`;function f(e,t,n,r){return`${e}: ${t}: ${n}. ${r}`}function p(e,t){e.includes(t)||e.push(t)}function m(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function h(e){return m(e)&&typeof e.$ref==`string`}function g(e){let t=[],n=(e,r,i)=>{for(let[a,o]of Object.entries(e)){if(a.startsWith(`$`)||!m(o))continue;let e=[...r,a];`$value`in o?t.push({path:e.join(`.`),token:o,type:o.$type??i.type,extensions:{...i.extensions,...o.$extensions?.[`com.webority`]??{}}}):n(o,e,{type:o.$type??i.type,extensions:{...i.extensions,...o.$extensions?.[`com.webority`]??{}}})}};return n(e,[],{type:void 0,extensions:{}}),t}function _(e){let[t,...n]=e.path.split(`.`),r=e.extensions;return{path:e.path,group:t,name:n.join(`-`),type:e.type??``,description:e.token.$description??null,platforms:r.platforms??null,internal:r.internal===!0,brandOwn:!1,extensions:r}}function v(e,t,i,a){let{path:o,group:s,name:c,type:l}=e;l===``&&p(i,f(t,o,`has no $type`,`Add $type to the token or to its group.`));let u;try{u=r(o)}catch{p(i,f(t,o,`its group ${s} has no CSS prefix`,`Add the group to PREFIX in names.js.`))}let d=n[s];if(d&&!d.includes(c)&&p(i,f(t,o,`"${c}" is not a step of ${s}`,`Use one of: ${d.join(`, `)}.`)),u!==void 0){let e=a.get(u);e===void 0?a.set(u,o):e!==o&&p(i,f(t,o,`its CSS name ${u} is also the name of ${e}`,`Rename one of the two tokens.`))}}function y(e,t,n,r){let i={...e.extensions};return(i.platforms!==void 0||i.internal!==void 0)&&(p(r,f(t,e.path,`changes the platforms or internal mark`,`Set marks in the base set only.`)),delete i.platforms,delete i.internal),Object.assign(n.extensions,i),{value:e.token.$value,file:t}}function b(e,t,n){p(e,f(t,n,`overrides a token the base set does not declare`,`Declare ${n} in the base set first.`))}function x(e,t,n){let r=new Map;for(let{ref:i,data:a}of e)if(a)for(let e of g(a)){let a=t.get(e.path);if(!a){b(n,i,e.path);continue}r.set(e.path,y(e,i,a,n))}return r}async function S(e,t){let n=a(e),r=[],S=o(e),C;try{C=JSON.parse(await i(e,`utf8`))}catch(e){throw Error(f(n,`(file)`,`cannot be read as JSON (${e.message})`,`Restore the file or correct its path.`))}if(!Array.isArray(C.sets)||C.sets.length===0||!C.sets.every(e=>Array.isArray(e?.sources)&&e.sources.every(h)))throw Error(f(n,`sets`,`must be a non-empty array of { sources: [{ "$ref": string }] }`,`Match the resolver of the library source.`));if(!Array.isArray(C.modifiers))throw Error(f(n,`modifiers`,`must be an array`,`Match the resolver of the library source.`));let w=[[`mode`,[`light`,`dark`]],[`platform`,[`web`,`phone`]],[`width`,[`1440`,`390`]]];if(C.modifiers.length!==w.length)throw Error(f(n,`modifiers`,`must hold the mode, platform and width modifiers, in that order`,`Match the resolver of the library source.`));w.forEach(([e,t],r)=>{let i=C.modifiers[r],a=m(i?.contexts)?Object.keys(i.contexts).sort().join(`,`):``;if(!(i?.name===e&&a===[...t].sort().join(`,`)&&t.every(e=>Array.isArray(i.contexts[e])&&i.contexts[e].every(h))&&i.contexts[t[0]].length===0))throw Error(f(n,`modifiers.${e}`,`is not the ${e} modifier with the contexts ${t.join(`, `)} and an empty list for ${t[0]}`,`Match the resolver of the library source, whose default context lists no file.`))});let T=(e,t)=>C.modifiers.find(t=>t.name===e).contexts[t],E=C.sets.flatMap(e=>e.sources.map(e=>e.$ref)),D=T(`mode`,`dark`).map(e=>e.$ref),O=T(`platform`,`phone`).map(e=>e.$ref),k=T(`width`,`390`).map(e=>e.$ref),A=JSON.parse(await i(u,`utf8`)),j=new c.default({allErrors:!0,strict:!1});j.addSchema(A);let M=j.compile(A),N=j.getSchema(`${A.$id}#/$defs/sourceMeaning`),P=new Map,F=async e=>{let t=s(S,e);if(P.has(t))return P.get(t);let n=null;try{n=JSON.parse(await i(t,`utf8`))}catch(n){return p(r,f(e,`(file)`,`cannot be read as JSON (${n.message})`,`Restore the file or correct its $ref in the resolver.`)),P.set(t,null),null}let o=[];M(n)||o.push(...M.errors),a(t)===`meaning.tokens.json`&&!N(n)&&o.push(...N.errors);for(let t of o){if(t.keyword===`if`)continue;let n=t.instancePath.slice(1).split(`/`).filter(e=>e!==``),i=n.length===0?`(file)`:n.map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)).join(`.`),a=t.params?.additionalProperty??t.params?.propertyName,o=a===void 0?t.message:`${t.message} "${a}"`;p(r,f(e,i,o,`Correct it against schema/webority-tokens.schema.json.`))}return P.set(t,n),n},I=async e=>Promise.all(e.map(async e=>({ref:e,data:await F(e)}))),L=await I(E),R=await I(D),z=await I(O),B=await I(k),V=new Map,H=new Map,U=new Map;for(let{ref:e,data:t}of L)if(t)for(let n of g(t)){if(V.has(n.path)){p(r,f(e,n.path,`is already declared in ${U.get(n.path).file}`,d));continue}let t=_(n);v(t,e,r,H),V.set(n.path,t),U.set(n.path,{value:n.token.$value,file:e})}let W=x(R,V,r),G=x(z,V,r),K=x(B,V,r),q=new Map,J=new Map,Y=new Map,X=new Map;if(t){let e=`brand ${t.name}`;for(let n of g(t.base)){let t=V.get(n.path);if(t){q.set(n.path,y(n,e,t,r));continue}let i=_(n);v(i,e,r,H),i.brandOwn=!0,V.set(n.path,i),q.set(n.path,{value:n.token.$value,file:e})}for(let n of g(t.dark)){let t=V.get(n.path);if(!t){b(r,e,n.path);continue}J.set(n.path,y(n,e,t,r))}for(let[n,i]of[[t.phone?.light,Y],[t.phone?.dark,X]])if(m(n))for(let t of g(n)){let n=V.get(t.path);if(!n){b(r,e,t.path);continue}i.set(t.path,y(t,e,n,r))}}let Z=JSON.parse(await i(l,`utf8`)),Q={package:Z.name,version:Z.version,brand:t?.name??null};return{tokens:V,layers:{base:U,dark:W,phone:G,width390:K,brandBase:q,brandDark:J,brandPhoneLight:Y,brandPhoneDark:X},cssNames:H,source:Q,refusals:r}}export{f as line,S as readSources};
|
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.`)&&!l.get(t).extensions.faces,y=(e,t)=>{let n=g(t).reverse();for(let r of n){if(v(r,e,t)||r===u.brandBase&&t.mode===`dark`&&u.dark.has(e))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),e.platform===`phone`&&t.push(e.mode===`dark`?u.brandPhoneDark:u.brandPhoneLight),t},_=new Set([u.brandBase,u.brandDark,u.brandPhoneLight,u.brandPhoneDark]),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)||r===u.brandBase&&t.mode===`dark`&&u.dark.has(e))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.
|
|
3
|
+
"version": "0.110.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",
|