@webority/tokens 0.94.1 → 0.96.0

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/build.js CHANGED
@@ -1,5 +1,6 @@
1
- import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{BRAND_OUTPUT_FILES as t,HEAD_FOLDER as n,loadBrand as r}from"./brand.js";import{require__2020 as i}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import a from"./canvas-renames.js";import o from"./deviations.js";import{emitCanvas as s}from"./emit/canvas.js";import{emitEmail as c}from"./emit/email.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{loadModel as m}from"./model/index.js";import{mkdir as h,readFile as g,writeFile as _}from"node:fs/promises";import v from"node:path";var y=e(i(),1),b=new URL(`../schema/design-map.schema.json`,import.meta.url),x=new URL(`../package.json`,import.meta.url),S={palette:`palette.tokens.json`,scale:`scale.tokens.json`,meaning:`meaning.tokens.json`,modeDark:`mode.dark.tokens.json`},C=/^.+: \S+: .+\. .+$/;async function w(e){let n=v.resolve(e.root??process.cwd()),i=e.check===!0,{version:S}=JSON.parse(await g(x,`utf8`)),w=[],O=[],k=async(e,t)=>{if(i){let n=null;try{n=await g(e,`utf8`)}catch(e){if(e.code!==`ENOENT`)throw e}n!==t&&O.push(e);return}await h(v.dirname(e),{recursive:!0}),await _(e,t,`utf8`),w.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 r=v.resolve(n,e.out),i=await m(),o=s(i),c=[[v.join(r,`canvas`,t.web),T(o.web)],[v.join(r,`canvas`,t.web390),T(o.web390)],[v.join(r,`canvas`,t.phoneTheme),T(o.phone)],[v.join(r,`meanings.json`),T(l(i))],[v.join(r,`canvas`,`renames.json`),T(a)]];if(e.web){let t=p(i),r=v.resolve(n,e.web);c.push([r,t.tokens]),c.push([v.join(v.dirname(r),`_bootstrap.generated.scss`),t.bootstrap])}if(e.phone){let t=d({light:f(i,`light`),dark:f(i,`dark`)});c.push([v.resolve(n,e.phone),t.contents])}for(let[e,t]of c)await k(e,t);return{written:w,stale:O}}let A=v.join(n,`.webority`,`design.json`),j;try{j=await g(A,`utf8`)}catch(e){throw e.code===`ENOENT`?Error(`${A}: file missing. Run from the repo root or create the design map.`):e}let M;try{M=JSON.parse(j)}catch(e){throw Error(`${A}: /: ${e.message}. Fix the design map.`)}let N=JSON.parse(await g(b,`utf8`)),P=new y.Ajv2020({allErrors:!0,strict:!1}).compile(N);if(!P(M))throw Error(P.errors.map(e=>`${A}: ${e.instancePath||`/`}: ${e.message}. Fix the design map.`).join(`
2
- `));let F=M.tokens.brands,I=M.tokens.heads??[];if((e.brand!==void 0||e.out!==void 0)&&F.length>1)throw Error(`brand: --brand/--out: the repo has ${F.length} brands. Remove the flag to build every brand.`);let L=[];if(F.forEach((e,t)=>{e.source===`library`&&L.push(`${A}: tokens.brands[${t}].source: "library" is built with --library. Run webority brand --library --out <dir>.`)}),I.forEach((e,t)=>{F.some(t=>t.name===e.brand)||L.push(`${A}: tokens.heads[${t}].brand: no brand named ${e.brand}. Add it to tokens.brands.`)}),L.length>0)throw Error(L.join(`
3
- `));let R=await D(),z=await m(),B={light:f(z,`light`),dark:f(z,`dark`)},V=[];for(let i of F){let a=F.length===1&&e.brand!==void 0?e.brand:i.source,l=F.length===1&&e.out!==void 0?e.out:i.export,d=v.resolve(n,a);try{let e=r(d,R,o),a=await m({brand:e}),h=s(a),g=p(a,{library:z}),_=u(B,{light:f(a,`light`),dark:f(a,`dark`)},{package:`@webority/tokens`,version:S,brand:e.name}),y=T(c(h.web,h.web390)),b={css:g.css,phone:_.contents,email:y},x=v.resolve(n,l),C=[[v.join(x,t.css),g.css],[v.join(x,t.bootstrap),g.variables],[v.join(x,t.web),T(h.web)],[v.join(x,t.web390),T(h.web390)],[v.join(x,t.phoneTheme),T(h.phone)],[v.join(x,t.phone),_.contents],[v.join(x,t.email),y]];V.push(...C);for(let e of I)e.brand===i.name&&V.push(E(n,e,b))}catch(e){for(let t of String(e?.message??e).split(`
4
- `))t.length!==0&&L.push(C.test(t)?t:`${d}: -: ${t}. Fix the source.`)}}if(L.length>0)throw Error(L.join(`
5
- `));for(let[e,t]of V)await k(e,t);return{written:w,stale:O}}function T(e){return`${JSON.stringify(e,null,4)}\n`}function E(e,r,i){let a=v.resolve(e,r.path);return r.kind===`razor`?[v.join(a,`wwwroot`,n,t.css),i.css]:r.kind===`spa`?[v.join(a,`src`,n,t.css),i.css]:r.kind===`phone`?[v.join(a,n,t.phone),i.phone]:[v.join(a,n,t.email),i.email]}async function D(){let e={};for(let[t,n]of Object.entries(S))e[t]=JSON.parse(await g(new URL(`./source/${n}`,import.meta.url),`utf8`));return e}export{w as brand};
1
+ import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{BRAND_OUTPUT_FILES as t,HEAD_FOLDER as n,loadBrand as r}from"./brand.js";import{require__2020 as i}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import a from"./canvas-renames.js";import o from"./deviations.js";import{emitCanvas as s}from"./emit/canvas.js";import{emitEmail as c}from"./emit/email.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{FLOOR as m,contrast as h}from"./model/derive.js";import{loadModel as g}from"./model/index.js";import{mkdir as _,readFile as v,writeFile as y}from"node:fs/promises";import b from"node:path";var x=e(i(),1),S=new URL(`../schema/design-map.schema.json`,import.meta.url),C=new URL(`../package.json`,import.meta.url),w={palette:`palette.tokens.json`,scale:`scale.tokens.json`,meaning:`meaning.tokens.json`,modeDark:`mode.dark.tokens.json`},T=/^.+: \S+: .+\. .+$/;async function E(e){let n=b.resolve(e.root??process.cwd()),i=e.check===!0,{version:m}=JSON.parse(await v(C,`utf8`)),h=[],w=[],E=async(e,t)=>{if(i){let n=null;try{n=await v(e,`utf8`)}catch(e){if(e.code!==`ENOENT`)throw e}n!==t&&w.push(e);return}await _(b.dirname(e),{recursive:!0}),await y(e,t,`utf8`),h.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 r=b.resolve(n,e.out),i=await g();A(i);let o=s(i),c=[[b.join(r,`canvas`,t.web),D(o.web)],[b.join(r,`canvas`,t.web390),D(o.web390)],[b.join(r,`canvas`,t.phoneTheme),D(o.phone)],[b.join(r,`meanings.json`),D(l(i))],[b.join(r,`canvas`,`renames.json`),D(a)]];if(e.web){let t=p(i),r=b.resolve(n,e.web);c.push([r,t.tokens]),c.push([b.join(b.dirname(r),`_bootstrap.generated.scss`),t.bootstrap])}if(e.phone){let t=d({light:f(i,`light`),dark:f(i,`dark`)});c.push([b.resolve(n,e.phone),t.contents])}for(let[e,t]of c)await E(e,t);return{written:h,stale:w}}let O=b.join(n,`.webority`,`design.json`),k;try{k=await v(O,`utf8`)}catch(e){throw e.code===`ENOENT`?Error(`${O}: file missing. Run from the repo root or create the design map.`):e}let N;try{N=JSON.parse(k)}catch(e){throw Error(`${O}: /: ${e.message}. Fix the design map.`)}let P=JSON.parse(await v(S,`utf8`)),F=new x.Ajv2020({allErrors:!0,strict:!1}).compile(P);if(!F(N))throw Error(F.errors.map(e=>`${O}: ${e.instancePath||`/`}: ${e.message}. Fix the design map.`).join(`
2
+ `));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(`${O}: 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(`${O}: 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 M(),B=await g(),V={light:f(B,`light`),dark:f(B,`dark`)},H=[],U=[];for(let i of I){let a=I.length===1&&e.brand!==void 0?e.brand:i.source,l=I.length===1&&e.out!==void 0?e.out:i.export,d=b.resolve(n,a);try{let e=r(d,z,o),a=await g({brand:e});U.push(a);let h=s(a),_=p(a,{library:B}),v=u(V,{light:f(a,`light`),dark:f(a,`dark`)},{package:`@webority/tokens`,version:m,brand:e.name}),y=D(c(h.web,h.web390)),x={css:_.css,phone:v.contents,email:y},S=b.resolve(n,l),C=[[b.join(S,t.css),_.css],[b.join(S,t.bootstrap),_.variables],[b.join(S,t.web),D(h.web)],[b.join(S,t.web390),D(h.web390)],[b.join(S,t.phoneTheme),D(h.phone)],[b.join(S,t.phone),v.contents],[b.join(S,t.email),y]];H.push(...C);for(let e of L)e.brand===i.name&&H.push(j(n,e,x))}catch(e){for(let t of String(e?.message??e).split(`
4
+ `))t.length!==0&&R.push(T.test(t)?t:`${d}: -: ${t}. Fix the source.`)}}if(R.length>0)throw Error(R.join(`
5
+ `));for(let e of U)A(e);for(let[e,t]of H)await E(e,t);return{written:h,stale:w}}function D(e){return`${JSON.stringify(e,null,4)}\n`}var O=[{context:{mode:`light`,platform:`web`,width:1440},texts:[`text-heading`,`text-1`,`text-2`,`text-3`],backgrounds:[`bg-page`,`bg-light`,`bg-elevated`,`bg-muted`]},{context:{mode:`dark`,platform:`web`,width:1440},texts:[`dark-text`,`dark-text-muted`,`dark-text-subtle`],backgrounds:[`dark-bg-page`,`dark-bg-surface`,`dark-bg-muted`]}];function k(e){let t=Number.parseInt(e.slice(1),16);return{r:t>>16&255,g:t>>8&255,b:t&255}}function A(e){let t=[];for(let{context:n,texts:r,backgrounds:i}of O)for(let a of r)for(let r of i){let i=h(k(e.resolvedIn(`palette.${a}`,n)),k(e.resolvedIn(`palette.${r}`,n)));i<4.5&&t.push(`${a} on ${r}: ${i.toFixed(2)}:1 (needs ${m}:1)`)}if(t.length>0)throw Error(t.join(`
6
+ `))}function j(e,r,i){let a=b.resolve(e,r.path);return r.kind===`razor`?[b.join(a,`wwwroot`,n,t.css),i.css]:r.kind===`spa`?[b.join(a,`src`,n,t.css),i.css]:r.kind===`phone`?[b.join(a,n,t.phone),i.phone]:[b.join(a,n,t.email),i.email]}async function M(){let e={};for(let[t,n]of Object.entries(w))e[t]=JSON.parse(await v(new URL(`./source/${n}`,import.meta.url),`utf8`));return e}export{E as brand};
@@ -2,7 +2,7 @@
2
2
  "format": "webority-theme-tokens/2",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.94.1",
5
+ "version": "0.96.0",
6
6
  "brand": null,
7
7
  "platform": "phone",
8
8
  "width": null
@@ -2,7 +2,7 @@
2
2
  "format": "webority-theme-tokens/2",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.94.1",
5
+ "version": "0.96.0",
6
6
  "brand": null,
7
7
  "platform": "web",
8
8
  "width": 390
@@ -23,7 +23,7 @@
23
23
  "text": "#071437",
24
24
  "text-body": "#252f4a",
25
25
  "text-muted": "#4b5675",
26
- "text-subtle": "#687088",
26
+ "text-subtle": "#626a82",
27
27
  "text-inverse": "#ffffff",
28
28
  "link": "#4f46e5",
29
29
  "border": "#ebedf3",
@@ -53,7 +53,7 @@
53
53
  "neutral": "#07143714",
54
54
  "neutral-hover": "#0714371f",
55
55
  "neutral-pressed": "#07143729",
56
- "neutral-soft": "#68708829",
56
+ "neutral-soft": "#626a8229",
57
57
  "neutral-text": "#4b5675",
58
58
  "on-neutral": "#071437",
59
59
  "success": "#04b440",
@@ -115,7 +115,7 @@
115
115
  "chart-neutral": "#99a1b7",
116
116
  "chart-grid": "#ebedf3",
117
117
  "chart-axis": "#c4cada",
118
- "chart-label": "#687088"
118
+ "chart-label": "#626a82"
119
119
  },
120
120
  "dark": {
121
121
  "bg": "#0f1117",
@@ -2,7 +2,7 @@
2
2
  "format": "webority-theme-tokens/2",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.94.1",
5
+ "version": "0.96.0",
6
6
  "brand": null,
7
7
  "platform": "web",
8
8
  "width": 1440
@@ -23,7 +23,7 @@
23
23
  "text": "#071437",
24
24
  "text-body": "#252f4a",
25
25
  "text-muted": "#4b5675",
26
- "text-subtle": "#687088",
26
+ "text-subtle": "#626a82",
27
27
  "text-inverse": "#ffffff",
28
28
  "link": "#4f46e5",
29
29
  "border": "#ebedf3",
@@ -53,7 +53,7 @@
53
53
  "neutral": "#07143714",
54
54
  "neutral-hover": "#0714371f",
55
55
  "neutral-pressed": "#07143729",
56
- "neutral-soft": "#68708829",
56
+ "neutral-soft": "#626a8229",
57
57
  "neutral-text": "#4b5675",
58
58
  "on-neutral": "#071437",
59
59
  "success": "#04b440",
@@ -115,7 +115,7 @@
115
115
  "chart-neutral": "#99a1b7",
116
116
  "chart-grid": "#ebedf3",
117
117
  "chart-axis": "#c4cada",
118
- "chart-label": "#687088"
118
+ "chart-label": "#626a82"
119
119
  },
120
120
  "dark": {
121
121
  "bg": "#0f1117",
@@ -2,7 +2,7 @@
2
2
  "format": "webority-meanings/1",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.94.1"
5
+ "version": "0.96.0"
6
6
  },
7
7
  "color": {
8
8
  "bg": {
@@ -1 +1 @@
1
- var e=4.5,t=[`#FFFFFF`,`#F4F6F8`,`#F5F6FA`,`#F9FBFC`],n=[`#0F1117`,`#0D0F15`,`#232733`,`#181B23`],r=`#181B23`,i=`#232733`,a=`#0F0F0F`,o=`#FFFFFF`,s=`#000000`,c=50,l={"on-fill":_,"aa-ink":v,"dark-aa-ink":y,"dark-hover":b};function u(e,t){if(!Object.hasOwn(l,e))throw Error(`Unknown derive rule: ${e}`);return l[e](t)}function d(e){let t=/^#([0-9a-f]{6})$/i.exec(e);if(!t)throw Error(`Not a #rrggbb colour: ${e}`);let n=Number.parseInt(t[1],16);return{r:n>>16&255,g:n>>8&255,b:n&255}}function f(e){return`#${[e.r,e.g,e.b].map(e=>Math.round(e).toString(16).padStart(2,`0`)).join(``)}`}function p(e,t,n){return{r:n*e.r+(1-n)*t.r,g:n*e.g+(1-n)*t.g,b:n*e.b+(1-n)*t.b}}function m(e){let t=e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4};return .2126*t(e.r)+.7152*t(e.g)+.0722*t(e.b)}function h(e,t){let n=m(e),r=m(t);return(Math.max(n,r)+.05)/(Math.min(n,r)+.05)}function g(e,t){let n=21;for(let r of t)n=Math.min(n,h(e,r));return n}function _({primary:t}){let n=d(t);return f(h(d(o),n)>=e?d(o):d(a))}function v({primary:n}){let r=d(n),i=[...t.map(d),p(r,d(o),.15)],a=r,l=0;for(;g(a,i)<e&&l<c;)l+=1,a=p(d(s),r,l*.02);return f(a)}function y({primary:t}){let s=d(t),l=n.map(d),u=d(a),m=s,h=0;for(;g(m,[...l,p(m,d(r),.15),p(s,d(i),.2),u])<e&&h<c;)h+=1,m=p(d(o),s,h*.02);return f(m)}function b({darkPrimary:e}){if(!e)throw Error(`dark-hover needs darkPrimary, the rounded hex that dark-aa-ink returned.`);return f(p(d(o),d(e),.12))}export{u as derive};
1
+ var e=4.5,t=[`#FFFFFF`,`#F4F6F8`,`#F5F6FA`,`#F9FBFC`],n=[`#0F1117`,`#0D0F15`,`#232733`,`#181B23`],r=`#181B23`,i=`#232733`,a=`#0F0F0F`,o=`#FFFFFF`,s=`#000000`,c=50,l={"on-fill":_,"aa-ink":v,"dark-aa-ink":y,"dark-hover":b};function u(e,t){if(!Object.hasOwn(l,e))throw Error(`Unknown derive rule: ${e}`);return l[e](t)}function d(e){let t=/^#([0-9a-f]{6})$/i.exec(e);if(!t)throw Error(`Not a #rrggbb colour: ${e}`);let n=Number.parseInt(t[1],16);return{r:n>>16&255,g:n>>8&255,b:n&255}}function f(e){return`#${[e.r,e.g,e.b].map(e=>Math.round(e).toString(16).padStart(2,`0`)).join(``)}`}function p(e,t,n){return{r:n*e.r+(1-n)*t.r,g:n*e.g+(1-n)*t.g,b:n*e.b+(1-n)*t.b}}function m(e){let t=e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4};return .2126*t(e.r)+.7152*t(e.g)+.0722*t(e.b)}function h(e,t){let n=m(e),r=m(t);return(Math.max(n,r)+.05)/(Math.min(n,r)+.05)}function g(e,t){let n=21;for(let r of t)n=Math.min(n,h(e,r));return n}function _({primary:e}){let t=d(e);return f(h(d(o),t)>=4.5?d(o):d(a))}function v({primary:e}){let n=d(e),r=[...t.map(d),p(n,d(o),.15)],i=n,a=0;for(;g(i,r)<4.5&&a<c;)a+=1,i=p(d(s),n,a*.02);return f(i)}function y({primary:e}){let t=d(e),s=n.map(d),l=d(a),u=t,m=0;for(;g(u,[...s,p(u,d(r),.15),p(t,d(i),.2),l])<4.5&&m<c;)m+=1,u=p(d(o),t,m*.02);return f(u)}function b({darkPrimary:e}){if(!e)throw Error(`dark-hover needs darkPrimary, the rounded hex that dark-aa-ink returned.`);return f(p(d(o),d(e),.12))}export{e as FLOOR,h as contrast,u as derive};
@@ -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{derive as r}from"./derive.js";import{findCycles as i,mapReferences as a,referencesIn as o}from"./references.js";function s(){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 c(e){return`${e.mode}|${e.platform}|${e.width}`}function l(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 u({tokens:u,layers:d,cssNames:f,source:p,refusals:m}){let h=s(),g=e=>{let t=h.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},_=e=>{let t=[d.base];return e.mode===`dark`&&t.push(d.dark),e.platform===`phone`&&t.push(d.phone),e.platform===`web`&&e.width===390&&t.push(d.width390),t.push(d.brandBase),e.mode===`dark`&&t.push(d.brandDark),t},v=(e,t)=>{let n=_(t).reverse();for(let t of n){let n=t.get(e);if(n)return n}},y=(e,t)=>{let n=u.get(e);return n?n.platforms===null||n.platforms.includes(t.platform):!1},b=(e,t)=>{if(!y(e,t))throw Error(`model: ${e} does not exist on ${t.platform}`)},x=new Map,S=(t,i)=>{let s=`${c(i)}|${t}`;if(x.has(s))return x.get(s);b(t,i);let d=u.get(t),{value:f}=v(t,i),p;if(d.type===`color`){if(typeof f!=`string`)throw Error(`model: ${t} is a colour with a value that is not text`);let s=d.extensions.derive;if(s){let e=o(f);if(e.length!==1||f.trim()!==`{${e[0]}}`)throw Error(`model: ${t} derives with ${s}, so its value must be one reference to the colour it derives from`);let n=e[0],a=S(n,i);if(!/^#[0-9a-f]{6}$/i.test(a))throw Error(`model: ${t} derives from ${n}, which is not an opaque #rrggbb colour`);p=s===`dark-hover`?r(s,{primary:a,darkPrimary:a}):r(s,{primary:a})}else p=n(a(f,t=>`var(${e(t)})`),e=>C(e,i))}else p=a(f,(e,n)=>{let r=S(e,i);return n?r:l(r,e,t)});return x.set(s,p),p},C=(e,t)=>{let n=f.get(e);if(n===void 0||!y(n,t))return;if(u.get(n).type===`color`)return S(n,t);let{value:r}=v(n,t);return typeof r==`string`?r:void 0},w=()=>{for(let e of Object.values(d))for(let[n,r]of e)for(let e of o(r.value))if(!u.has(e)){let i=t(r.file,n,`references ${e}, which no token declares`,`Declare ${e} or correct the name.`);m.includes(i)||m.push(i)}},T=()=>{for(let e of h){let n=new Map;for(let t of u.keys())y(t,e)&&n.set(t,o(v(t,e).value));for(let r of i(n)){let n=t(v(r[0],e).file,r[0],`reference cycle ${r.join(` -> `)}`,`Point one of these tokens at a value instead.`);m.includes(n)||m.push(n)}}},E=()=>{for(let e of h)for(let n of u.keys()){if(!y(n,e))continue;let{file:r,value:i}=v(n,e);for(let a of o(i))if(u.has(a)&&!y(a,e)){let i=t(r,n,`references ${a}, which does not exist on ${e.platform}`,`Mark ${n} for the platform that has ${a}, or give ${n} a ${e.platform} override.`);m.includes(i)||m.push(i)}}},D=()=>{for(let e of h)for(let n of u.keys())if(y(n,e))try{S(n,e)}catch(r){let i=t(v(n,e).file,n,r.message.replace(/\.$/,``),`Correct the value or the tokens it references.`);m.includes(i)||m.push(i)}},O=m.length;w();let k=m.length>O;if(k||T(),k||E(),m.length===0&&D(),m.length>0)throw Error(m.join(`
1
+ import{cssVarOfPath as e}from"../names.js";import{derive as t}from"./derive.js";import{line as n}from"./load.js";import{resolveColour as r}from"./colour.js";import{findCycles as i,mapReferences as a,referencesIn as o}from"./references.js";function s(){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 c(e){return`${e.mode}|${e.platform}|${e.width}`}function l(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 u({tokens:u,layers:d,cssNames:f,source:p,refusals:m}){let h=s(),g=e=>{let t=h.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},_=e=>{let t=[d.base];return e.mode===`dark`&&t.push(d.dark),e.platform===`phone`&&t.push(d.phone),e.platform===`web`&&e.width===390&&t.push(d.width390),t.push(d.brandBase),e.mode===`dark`&&t.push(d.brandDark),t},v=(e,t)=>{let n=_(t).reverse();for(let t of n){let n=t.get(e);if(n)return n}},y=(e,t)=>{let n=u.get(e);return n?n.platforms===null||n.platforms.includes(t.platform):!1},b=(e,t)=>{if(!y(e,t))throw Error(`model: ${e} does not exist on ${t.platform}`)},x=new Map,S=(n,i)=>{let s=`${c(i)}|${n}`;if(x.has(s))return x.get(s);b(n,i);let d=u.get(n),{value:f}=v(n,i),p;if(d.type===`color`){if(typeof f!=`string`)throw Error(`model: ${n} is a colour with a value that is not text`);let s=d.extensions.derive;if(s){let e=o(f);if(e.length!==1||f.trim()!==`{${e[0]}}`)throw Error(`model: ${n} derives with ${s}, so its value must be one reference to the colour it derives from`);let r=e[0],a=S(r,i);if(!/^#[0-9a-f]{6}$/i.test(a))throw Error(`model: ${n} derives from ${r}, which is not an opaque #rrggbb colour`);p=s===`dark-hover`?t(s,{primary:a,darkPrimary:a}):t(s,{primary:a})}else p=r(a(f,t=>`var(${e(t)})`),e=>C(e,i))}else p=a(f,(e,t)=>{let r=S(e,i);return t?r:l(r,e,n)});return x.set(s,p),p},C=(e,t)=>{let n=f.get(e);if(n===void 0||!y(n,t))return;if(u.get(n).type===`color`)return S(n,t);let{value:r}=v(n,t);return typeof r==`string`?r:void 0},w=()=>{for(let e of Object.values(d))for(let[t,r]of e)for(let e of o(r.value))if(!u.has(e)){let i=n(r.file,t,`references ${e}, which no token declares`,`Declare ${e} or correct the name.`);m.includes(i)||m.push(i)}},T=()=>{for(let e of h){let t=new Map;for(let n of u.keys())y(n,e)&&t.set(n,o(v(n,e).value));for(let r of i(t)){let t=n(v(r[0],e).file,r[0],`reference cycle ${r.join(` -> `)}`,`Point one of these tokens at a value instead.`);m.includes(t)||m.push(t)}}},E=()=>{for(let e of h)for(let t of u.keys()){if(!y(t,e))continue;let{file:r,value:i}=v(t,e);for(let a of o(i))if(u.has(a)&&!y(a,e)){let i=n(r,t,`references ${a}, which does not exist on ${e.platform}`,`Mark ${t} for the platform that has ${a}, or give ${t} a ${e.platform} override.`);m.includes(i)||m.push(i)}}},D=()=>{for(let e of h)for(let t of u.keys())if(y(t,e))try{S(t,e)}catch(r){let i=n(v(t,e).file,t,r.message.replace(/\.$/,``),`Correct the value or the tokens it references.`);m.includes(i)||m.push(i)}},O=m.length;w();let k=m.length>O;if(k||T(),k||E(),m.length===0&&D(),m.length>0)throw Error(m.join(`
2
2
  `));return{tokens:u,contexts:s(),existsIn:(e,t)=>y(e,g(t)),valueIn:(e,t)=>{let n=g(t);return b(e,n),structuredClone(v(e,n).value)},resolvedIn:(e,t)=>{let n=g(t);return structuredClone(S(e,n))},referenceIn:(e,t)=>{let n=g(t);return b(e,n),o(v(e,n).value)[0]},source:p}}export{s as buildContexts,u as buildModel};
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "text-3": {
70
70
  "$type": "color",
71
- "$value": "#687088",
71
+ "$value": "#626A82",
72
72
  "$description": "Tertiary text for hints, captions, labels, timestamps and placeholders."
73
73
  },
74
74
  "text-4": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/tokens",
3
- "version": "0.94.1",
3
+ "version": "0.96.0",
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",