@webority/tokens 0.100.0 → 0.101.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/brand.d.ts CHANGED
@@ -6,15 +6,34 @@ export interface LibrarySources {
6
6
  modeDark: object;
7
7
  }
8
8
 
9
+ /** The brand file's email group as written (DTCG tokens). Each key is an email.json role key. */
10
+ export interface BrandEmailGroup {
11
+ /** <email colour role>: { $type: "color", $value: "#RRGGBB" | "{color.<meaning>}", $extensions.com.webority.dark?: "#RRGGBB" | "{color.<meaning>}" } */
12
+ color?: Record<string, object>;
13
+ /** <email type role>: { $value: { size, lineHeight, phoneSize, phoneLineHeight } } in whole px. */
14
+ type?: Record<string, object>;
15
+ /** <email space key>: { $type: "dimension", $value: { value, unit: "px" } }, or for a padding key { $value: "22px 24px" }. */
16
+ space?: Record<string, object>;
17
+ /** <email shape key>: { $type: "dimension", $value: { value, unit: "px" } } */
18
+ shape?: Record<string, object>;
19
+ /** radius: a dimension token; padding: { $value: "14px 28px" } */
20
+ button?: { radius?: object; padding?: object };
21
+ }
22
+
9
23
  /** A validated brand: base overrides every mode, dark overrides the dark context only. */
10
24
  export interface BrandLayer {
11
25
  name: string;
12
26
  base: object;
13
27
  dark: object;
28
+ /** The email group, kept outside base because the web model never reads it; null when the file has none. */
29
+ email: BrandEmailGroup | null;
14
30
  }
15
31
 
16
- /** The recorded deviations, keyed by slug (src/deviations.json). */
17
- export type Deviations = Readonly<Record<string, { reason: string }>>;
32
+ /** A brand group a recorded deviation can allow beyond palette, color, effect, font and radius. */
33
+ export type DeviationGroup = "space" | "text" | "shadow" | "section" | "component" | "email";
34
+
35
+ /** The recorded deviations, keyed by slug (src/deviations.json); groups lists the brand groups each one allows. */
36
+ export type Deviations = Readonly<Record<string, { reason: string; groups: readonly DeviationGroup[] }>>;
18
37
 
19
38
  /** Reads and validates a product brand file; throws one Error listing every problem. */
20
39
  export declare function loadBrand(path: string, library: LibrarySources, deviations: Deviations): BrandLayer;
package/dist/brand.js CHANGED
@@ -1,2 +1,2 @@
1
- import{readFileSync as e}from"node:fs";var t=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`}),n=`generated`,r=/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,i=[`palette`,`color`,`effect`,`font`,`radius`],a=[`space`,`text`,`shadow`,`section`,`component`];function o(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function s(e){return o(e)&&Object.hasOwn(e,`$value`)}function c(e,t){let n=[],r=(e,t)=>{for(let i of Object.keys(e)){if(i.startsWith(`$`))continue;let a=e[i],c=`${t}.${i}`;s(a)?n.push({path:c,node:a}):o(a)&&r(a,c)}};return r(e,t),n}function l(e,t){let n=e;for(let e of t.split(`.`)){if(!o(n)||!Object.hasOwn(n,e))return!1;n=n[e]}return s(n)}function u(e){let t=e?.$extensions?.[`com.webority`];return o(t)?t:{}}function d(e){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e)&&!/^[0-9]+$/.test(e)}function f(t,n,f){let p;try{p=JSON.parse(e(t,`utf8`))}catch(e){throw Error(`${t}: (file): cannot be read as JSON (${e.message}). Restore the file or fix the JSON`)}if(!o(p))throw Error(`${t}: (file): is not a JSON object. Write the brand as one object with the groups palette, color, effect, font and radius`);let m=[],h=(e,n,r)=>{let i=`${t}: ${e}: ${n}. ${r}`;m.includes(i)||m.push(i)},g=u(p);for(let e of Object.keys(g))e!==`brand`&&e!==`deviation`&&h(`$extensions.com.webority.${e}`,`is not a brand file key`,`Remove it`);let _=Object.hasOwn(g,`deviation`),v=_&&typeof g.deviation==`string`&&Object.hasOwn(f,g.deviation);_&&!v&&h(`$extensions.com.webority.deviation`,`${g.deviation} is not in deviations.json`,`Use a key of deviations.json`),(typeof g.brand!=`string`||!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(g.brand))&&h(`$extensions.com.webority.brand`,`is missing or not kebab case`,`Name the product in kebab case, such as capnix`);let y={};for(let e of Object.keys(p))if(!e.startsWith(`$`)){if(!i.includes(e)&&!a.includes(e)){h(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(a.includes(e)&&!v){h(e,`this group needs a recorded deviation`,`Add $extensions.com.webority.deviation naming an entry of deviations.json, or remove the group`);continue}if(!o(p[e])){h(e,`is not a group`,`Write it as an object of tokens`);continue}y[e]=p[e]}for(let[e,t]of Object.entries(y))for(let{path:n,node:r}of c(t,e)){let t=u(r);for(let e of Object.keys(t))e!==`platforms`&&e!==`dark`&&h(n,`$extensions.com.webority.${e} 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`)||h(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`&&h(n,`$extensions.com.webority.dark applies to colour and effect tokens only`,`Remove it`)}for(let{path:e,node:t}of c(y.palette??{},`palette`))e.split(`.`).slice(1).every(d)||h(e,`the step name is not kebab case`,`Name it such as primary-500`),typeof t.$value!=`string`&&h(e,`$value is not a string`,`Write the colour as text such as "#0F766E" or a reference such as "{palette.primary}"`);let b=(e,t,r)=>{let i=`${e}.${t}`,a=u(r),o=l(n.meaning,i);typeof r.$value!=`string`&&h(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`),o?l(n.modeDark,i)&&typeof a.dark!=`string`&&h(i,`needs $extensions.com.webority.dark because the meaning has a dark value`,`Add the dark value beside the light one`):(d(t)||h(i,`the name is not kebab case`,`Name it in kebab case`),(typeof r.$description!=`string`||r.$description===``)&&h(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(a,`dark`)&&typeof a.dark!=`string`&&h(i,`$extensions.com.webority.dark is not a string`,`Write a colour or a reference`)};for(let e of[`color`,`effect`]){let t=y[e]??{};for(let n of Object.keys(t))if(!n.startsWith(`$`)){if(!s(t[n])){h(`${e}.${n}`,`is not a token`,`Give it a $value`);continue}b(e,n,t[n])}}let x=Object.keys(n.scale.font??{}).filter(e=>s(n.scale.font[e]));for(let{path:e,node:t}of c(y.font??{},`font`)){l(n.scale,e)||h(e,`is not a fleet font`,`Use one of ${x.join(`, `)}`);let r=t.$value;(!Array.isArray(r)||r.length===0||!r.every(e=>typeof e==`string`))&&h(e,`$value is not a list of font family names`,`Write it as ["Webority Sans", "system-ui", "sans-serif"]`)}let S=Object.keys(n.scale.radius??{}).filter(e=>s(n.scale.radius[e]));for(let{path:e,node:t}of c(y.radius??{},`radius`)){l(n.scale,e)||h(e,`is not on the radius scale`,`Use one of ${S.join(`, `)}`);let r=t.$value;(!(o(r)&&typeof r.value==`number`&&Number.isFinite(r.value)&&r.value>=0)||r.unit!==`px`)&&h(e,`$value is not { value, unit }`,`Write it as { "value": 12, "unit": "px" }`)}let C=structuredClone(p);delete C.$extensions,delete C.$description;for(let e of[`color`,`effect`])for(let{node:t}of c(C[e]??{},e))Object.hasOwn(u(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 w=e=>l(C,e)||l(n.palette,e)||l(n.scale,e)||l(n.meaning,e);for(let e of Object.keys(y))for(let{path:t,node:n}of c(y[e],e)){let e=[n.$value,u(n).dark].filter(e=>typeof e==`string`);for(let n of e)for(let e of n.matchAll(r))w(e[1])||h(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(m.length>0)throw Error(m.join(`
2
- `));let T={};for(let e of[`color`,`effect`])for(let{path:t,node:n}of c(y[e]??{},e)){let r=u(n).dark;if(typeof r!=`string`)continue;let i=t.slice(e.length+1);T[e]??={},T[e][i]=n.$type===void 0?{$value:r}:{$value:r,$type:n.$type}}return{name:g.brand,base:C,dark:T}}export{t as BRAND_OUTPUT_FILES,n as HEAD_FOLDER,f as loadBrand};
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 e of Object.keys(t))e!==`platforms`&&e!==`dark`&&a(n,`$extensions.com.webority.${e} 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;(!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"]`)}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
+ `));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/build.js CHANGED
@@ -1,5 +1,5 @@
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(`
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{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(a(),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 r=v.resolve(e.root??process.cwd()),a=e.check===!0,{version:S}=JSON.parse(await g(x,`utf8`)),w=[],O=[],k=async(e,t)=>{if(a){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 t=v.resolve(r,e.out),i=await m(),a=c(i),s=[[v.join(t,`canvas`,n.web),T(a.web)],[v.join(t,`canvas`,n.web390),T(a.web390)],[v.join(t,`canvas`,n.phoneTheme),T(a.phone)],[v.join(t,`meanings.json`),T(l(i))],[v.join(t,`canvas`,`renames.json`),T(o)]];if(e.web){let t=p(i),n=v.resolve(r,e.web);s.push([n,t.tokens]),s.push([v.join(v.dirname(n),`_bootstrap.generated.scss`),t.bootstrap])}if(e.phone){let t=d({light:f(i,`light`),dark:f(i,`dark`)});s.push([v.resolve(r,e.phone),t.contents])}for(let[e,t]of s)await k(e,t);return{written:w,stale:O}}let A=v.join(r,`.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
+ `));if(M.tokens===void 0)throw Error(`${A}: /tokens: missing. Add tokens.brands to .webority/design.json.`);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 a of F){let o=F.length===1&&e.brand!==void 0?e.brand:a.source,l=F.length===1&&e.out!==void 0?e.out:a.export,d=v.resolve(r,o);try{let e=i(d,R,s),o=await m({brand:e}),h=c(o),g=p(o,{library:z}),_=u(B,{light:f(o,`light`),dark:f(o,`dark`)},{package:`@webority/tokens`,version:S,brand:e.name}),y=T(t(h.web,h.web390,e.email)),b={css:g.css,phone:_.contents,email:y},x=v.resolve(r,l),C=[[v.join(x,n.css),g.css],[v.join(x,n.bootstrap),g.variables],[v.join(x,n.web),T(h.web)],[v.join(x,n.web390),T(h.web390)],[v.join(x,n.phoneTheme),T(h.phone)],[v.join(x,n.phone),_.contents],[v.join(x,n.email),y]];V.push(...C);for(let e of I)e.brand===a.name&&V.push(E(r,e,b))}catch(e){for(let t of String(e?.message??e).split(`
4
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};
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,t,i){let a=v.resolve(e,t.path);return t.kind===`razor`?[v.join(a,`wwwroot`,r,n.css),i.css]:t.kind===`spa`?[v.join(a,`src`,r,n.css),i.css]:t.kind===`phone`?[v.join(a,r,n.phone),i.phone]:[v.join(a,r,n.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};
@@ -2,7 +2,7 @@
2
2
  "format": "webority-theme-tokens/2",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.100.0",
5
+ "version": "0.101.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.100.0",
5
+ "version": "0.101.0",
6
6
  "brand": null,
7
7
  "platform": "web",
8
8
  "width": 390
@@ -2,7 +2,7 @@
2
2
  "format": "webority-theme-tokens/2",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.100.0",
5
+ "version": "0.101.0",
6
6
  "brand": null,
7
7
  "platform": "web",
8
8
  "width": 1440
package/dist/check.js CHANGED
@@ -1,2 +1,2 @@
1
- import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{BRAND_OUTPUT_FILES as t}from"./brand.js";import{require__2020 as n}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{loadModel as r}from"./model/index.js";import{brand as i}from"./build.js";import{readFileSync as a,readdirSync as o}from"node:fs";import{join as s,resolve as c}from"node:path";import{spawnSync as l}from"node:child_process";var u=e(n(),1),d=`.webority/design.json`,f=c(import.meta.dirname,`../schema/design-map.schema.json`),p=new Set([`vite.config.js`,`vite.config.mjs`,`vite.config.cjs`,`vite.config.ts`,`vite.config.mts`,`vite.config.cts`]);async function m(e={},t={}){let{brand:n=i,repoChecks:a=w,loadModel:o=r}=t,s=e.root??process.cwd(),c=[],l=h(s,c);return l!==null&&(g(l,c),c.length===0&&v(l,s,c)),c.length===0&&(await b(l,s,o,c),await S(l,s,n,c)),await C(s,a,c),{findings:c}}function h(e,t){let n;try{n=a(s(e,d),`utf8`)}catch{return t.push({check:`design-map`,file:d,message:`Cannot read the file. Run webority check from the repo root and create the file.`}),null}try{return JSON.parse(n)}catch(e){return t.push({check:`design-map`,file:d,message:`${e.message}. Fix the file.`}),null}}function g(e,t){let n=new u.Ajv2020({allErrors:!0}).compile(JSON.parse(a(f,`utf8`)));if(!n(e))for(let r of n.errors)t.push({check:`design-map`,file:d,message:_(r,e)})}function _(e,t){let n=e.instancePath.split(`/`).filter(Boolean),r=n.length>0?n.join(`.`):`design.json`;if(e.keyword===`additionalProperties`)return r+=`.${e.params.additionalProperty}`,`${r}: is not a design map key, retired or misspelled. Remove it.`;if(e.keyword===`required`)return r+=`.${e.params.missingProperty}`,`${r}: is required. Add it.`;let i=n.reduce((e,t)=>e?.[t],t);return typeof i==`string`&&(i.startsWith(`--`)||i.includes(`var(`))?`${r}: a CSS variable is not a role. Use the meaning name, or <group>.<name> for a scale role.`:`${r}: ${e.message}. Fix the file.`}function v(e,t,n){let r=e.tokens.brands,i=e.tokens.heads??[],a=e=>n.push({check:`design-map`,file:d,message:e}),o=new Map;for(let e of r)o.set(e.name,(o.get(e.name)??0)+1);for(let[e,t]of o)t>1&&a(`tokens.brands: ${e} is listed more than once. Give each brand its own name.`);let c=new Set(r.map(e=>e.name));i.forEach((e,t)=>{c.has(e.brand)||a(`tokens.heads[${t}]: brand ${e.brand} is not in tokens.brands. Use a listed brand name.`)});let l=new Set(i.map(e=>e.brand));for(let e of r)e.source!==`library`&&!l.has(e.name)&&a(`tokens.brands: ${e.name} has no head. List a head for it or remove the brand.`);if(r.length>1)for(let e of r)e.source===`library`&&a(`tokens.brands: a library source cannot be combined with other brands. Keep one brand.`);i.forEach((e,n)=>{let r=y(s(t,e.path));r!==null&&(e.kind===`spa`&&r.some(e=>e.endsWith(`.csproj`))&&a(`tokens.heads[${n}]: ${e.path} holds a .csproj, so its kind is razor. Set kind razor.`),e.kind===`razor`&&r.some(e=>p.has(e))&&a(`tokens.heads[${n}]: ${e.path} holds a Vite project, so its kind is spa. Set kind spa.`))})}function y(e){try{return o(e)}catch{return null}}async function b(e,n,r,i){let a=e=>i.push({check:`design-map`,file:d,message:e});for(let r of e.tokens.brands){let i=r.source===`library`?`${r.export}/canvas`:r.export,o=x(s(n,i));if(o!==null)for(let[n,s]of Object.entries(e.color?.roles??{}))o.has(s)||a(`color.roles.${n}: ${s} is not a colour of brand ${r.name}. Use a name from ${i}/${t.web}.`)}let o=[];for(let[t,n]of Object.entries(e.scale??{})){for(let[e,r]of Object.entries(n.roles??{}))o.push([`scale.${t}.roles.${e}`,r]);for(let[e,r]of Object.entries(n.durations??{}))o.push([`scale.${t}.durations.${e}`,r])}for(let[t,n]of Object.entries(e.iconography?.sizes??{}))o.push([`iconography.sizes.${t}`,n]);if(o.length===0)return;let c;try{c=await r()}catch(e){i.push({check:`design-map`,file:null,message:`${e.message}. Fix the token source.`});return}let l=new Set;for(let e of c.tokens.values())l.add(`${e.group}.${e.name}`);for(let[e,t]of o)l.has(t)||a(`${e}: ${t} is not a token. Use a <group>.<name> the library defines.`)}function x(e){let n=new Set,r=!1;for(let i of[t.web,t.phoneTheme]){let t;try{t=JSON.parse(a(s(e,i),`utf8`))}catch{continue}r=!0;for(let e of Object.keys(t?.colors?.light??{}))n.add(e)}return r?n:null}async function S(e,t,n,r){let i=e.tokens.brands,a=i.length===1&&i[0].source===`library`,o;try{o=a?await n({root:t,library:!0,out:i[0].export,check:!0}):await n({root:t,check:!0})}catch(e){for(let t of String(e?.message??e).split(`
1
+ import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{BRAND_OUTPUT_FILES as t}from"./brand.js";import{require__2020 as n}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{loadModel as r}from"./model/index.js";import{brand as i}from"./build.js";import{readFileSync as a,readdirSync as o}from"node:fs";import{join as s,resolve as c}from"node:path";import{spawnSync as l}from"node:child_process";var u=e(n(),1),d=`.webority/design.json`,f=c(import.meta.dirname,`../schema/design-map.schema.json`),p=new Set([`vite.config.js`,`vite.config.mjs`,`vite.config.cjs`,`vite.config.ts`,`vite.config.mts`,`vite.config.cts`]);async function m(e={},t={}){let{brand:n=i,repoChecks:a=w,loadModel:o=r}=t,s=e.root??process.cwd(),c=[],l=h(s,c);return l!==null&&(g(l,c),c.length===0&&l.tokens!==void 0&&v(l,s,c)),c.length===0&&(await b(l,s,o,c),l.tokens!==void 0&&await S(l,s,n,c)),await C(s,a,c),{findings:c}}function h(e,t){let n;try{n=a(s(e,d),`utf8`)}catch{return t.push({check:`design-map`,file:d,message:`Cannot read the file. Run webority check from the repo root and create the file.`}),null}try{return JSON.parse(n)}catch(e){return t.push({check:`design-map`,file:d,message:`${e.message}. Fix the file.`}),null}}function g(e,t){let n=new u.Ajv2020({allErrors:!0}).compile(JSON.parse(a(f,`utf8`)));if(!n(e))for(let r of n.errors)t.push({check:`design-map`,file:d,message:_(r,e)})}function _(e,t){let n=e.instancePath.split(`/`).filter(Boolean),r=n.length>0?n.join(`.`):`design.json`;if(e.keyword===`additionalProperties`)return r+=`.${e.params.additionalProperty}`,`${r}: is not a design map key, retired or misspelled. Remove it.`;if(e.keyword===`required`)return r+=`.${e.params.missingProperty}`,`${r}: is required. Add it.`;let i=n.reduce((e,t)=>e?.[t],t);return typeof i==`string`&&(i.startsWith(`--`)||i.includes(`var(`))?`${r}: a CSS variable is not a role. Use the meaning name, or <group>.<name> for a scale role.`:`${r}: ${e.message}. Fix the file.`}function v(e,t,n){let r=e.tokens.brands,i=e.tokens.heads??[],a=e=>n.push({check:`design-map`,file:d,message:e}),o=new Map;for(let e of r)o.set(e.name,(o.get(e.name)??0)+1);for(let[e,t]of o)t>1&&a(`tokens.brands: ${e} is listed more than once. Give each brand its own name.`);let c=new Set(r.map(e=>e.name));i.forEach((e,t)=>{c.has(e.brand)||a(`tokens.heads[${t}]: brand ${e.brand} is not in tokens.brands. Use a listed brand name.`)});let l=new Set(i.map(e=>e.brand));for(let e of r)e.source!==`library`&&!l.has(e.name)&&a(`tokens.brands: ${e.name} has no head. List a head for it or remove the brand.`);if(r.length>1)for(let e of r)e.source===`library`&&a(`tokens.brands: a library source cannot be combined with other brands. Keep one brand.`);i.forEach((e,n)=>{let r=y(s(t,e.path));r!==null&&(e.kind===`spa`&&r.some(e=>e.endsWith(`.csproj`))&&a(`tokens.heads[${n}]: ${e.path} holds a .csproj, so its kind is razor. Set kind razor.`),e.kind===`razor`&&r.some(e=>p.has(e))&&a(`tokens.heads[${n}]: ${e.path} holds a Vite project, so its kind is spa. Set kind spa.`))})}function y(e){try{return o(e)}catch{return null}}async function b(e,n,r,i){let a=e=>i.push({check:`design-map`,file:d,message:e});if(e.tokens!==void 0)for(let r of e.tokens.brands){let i=r.source===`library`?`${r.export}/canvas`:r.export,o=x(s(n,i));if(o!==null)for(let[n,s]of Object.entries(e.color?.roles??{}))o.has(s)||a(`color.roles.${n}: ${s} is not a colour of brand ${r.name}. Use a name from ${i}/${t.web}.`)}let o=[];for(let[t,n]of Object.entries(e.scale??{})){for(let[e,r]of Object.entries(n.roles??{}))o.push([`scale.${t}.roles.${e}`,r]);for(let[e,r]of Object.entries(n.durations??{}))o.push([`scale.${t}.durations.${e}`,r])}for(let[t,n]of Object.entries(e.iconography?.sizes??{}))o.push([`iconography.sizes.${t}`,n]);if(o.length===0)return;let c;try{c=await r()}catch(e){i.push({check:`design-map`,file:null,message:`${e.message}. Fix the token source.`});return}let l=new Set;for(let e of c.tokens.values())l.add(`${e.group}.${e.name}`);for(let[e,t]of o)l.has(t)||a(`${e}: ${t} is not a token. Use a <group>.<name> the library defines.`)}function x(e){let n=new Set,r=!1;for(let i of[t.web,t.phoneTheme]){let t;try{t=JSON.parse(a(s(e,i),`utf8`))}catch{continue}r=!0;for(let e of Object.keys(t?.colors?.light??{}))n.add(e)}return r?n:null}async function S(e,t,n,r){let i=e.tokens.brands,a=i.length===1&&i[0].source===`library`,o;try{o=a?await n({root:t,library:!0,out:i[0].export,check:!0}):await n({root:t,check:!0})}catch(e){for(let t of String(e?.message??e).split(`
2
2
  `))t.trim()!==``&&r.push({check:`generated`,file:null,message:t});return}let s=a?`stale. Run webority brand --library --out ${i[0].export}`:`stale. Run webority brand`;for(let e of o.stale)r.push({check:`generated`,file:e,message:s})}async function C(e,t,n){let r;try{r=await t(e)}catch{n.push({check:`repo-checks`,file:null,message:`repo-checks did not run. Add @webority/repo-checks at the lockstep version.`});return}for(let e of r.new)n.push({check:`repo-checks`,file:e.pkg===`.`?null:e.pkg,message:`${e.id}: ${e.message}`})}function w(e){let t=l(`corepack pnpm exec webority-repo-checks --json`,{cwd:e,encoding:`utf8`,shell:!0,maxBuffer:64*1024*1024}),n;try{n=JSON.parse(t.stdout??``)}catch{throw Error(`repo-checks printed no JSON`)}if(!Array.isArray(n?.new))throw Error(`repo-checks printed no new array`);return n}export{m as check};
@@ -1 +1 @@
1
- var e={"operations/fleet-parity-deviation-register#website":{reason:`The public sites (webority.com, Government, Demo) keep their own fluid size scale by a recorded deviation.`},"decisions/D-016-tray-app-keeps-its-own-design-tokens":{reason:`The governor tray keeps its own token values with no portal stylesheet, written through the generator.`},"operations/fleet-parity-deviation-register#studio":{reason:`Webority Studio keeps its own colours, sizes, radii and fonts, written through the generator.`}};export{e as default};
1
+ var e={"operations/fleet-parity-deviation-register#website":{reason:`The public sites (webority.com, Government, Demo) keep their own fluid size scale by a recorded deviation.`,groups:[`space`,`text`,`shadow`,`section`,`component`]},"decisions/D-016-tray-app-keeps-its-own-design-tokens":{reason:`The governor tray keeps its own token values with no portal stylesheet, written through the generator.`,groups:[`space`,`text`,`shadow`,`section`,`component`]},"operations/fleet-parity-deviation-register#studio":{reason:`Webority Studio keeps its own colours, sizes, radii and fonts, written through the generator.`,groups:[`space`,`text`,`shadow`,`section`,`component`]},"operations/fleet-parity-deviation-register#lumex-email":{reason:`Lumex emails keep the sizes, gaps, corners and colours approved before the shared email theme, written through the generator.`,groups:[`email`]}};export{e as default};
@@ -1,2 +1,2 @@
1
- var e=[`light`,`dark`],t=new Set([`serif`,`sans-serif`,`monospace`,`cursive`,`fantasy`,`system-ui`,`ui-serif`,`ui-sans-serif`,`ui-monospace`]),n=[[`body`,`ui`],[`display`,`display`],[`mono`,`mono`]],r=Object.freeze({page:`bg`,canvas:`bg`,card:`surface`,panel:`bg-subtle`,"panel-alt":`bg-muted`,surface:`surface`,line:`border`,"line-strong":`border-strong`,"accent-tint-line":`primary-wash-strong`,heading:`text`,strong:`text`,text:`text-body`,secondary:`text-muted`,muted:`text-subtle`,accent:`primary`,"on-accent":`on-primary`,link:`link`,success:`success-text`,warning:`warning-text`,danger:`danger-text`,"accent-tint":`primary-wash`,"success-tint":`success-soft`,"warning-tint":`warning-soft`,"danger-tint":`danger-soft`,"figure-panel":`primary-wash`}),i=Object.freeze({eyebrow:{step:`xs`,leading:`body`},h1:{step:`2xl`,leading:`heading`},lede:{step:`lg`,leading:`body`},body:{step:`base`,leading:`body`},"body-large":{step:`lg`,leading:`body`},title:{step:`2xl`,leading:`heading`},item:{step:`base`,leading:`body`},label:{step:`sm`,leading:`body`},note:{step:`sm`,leading:`body`},"note-small":{step:`xs`,leading:`body`},figure:{step:`3xl`,leading:`display`},"figure-hero":{step:`4xl`,leading:`display`},"figure-sub":{step:`sm`,leading:`body`},range:{step:`sm`,leading:`body`},sign:{step:`base`,leading:`body`},foot:{step:`xs`,leading:`body`},num:{step:`base`,leading:`body`},"code-otp":{step:`2xl`,leading:`heading`},"code-id":{step:`base`,leading:`body`},button:{step:`base`,leading:`body`}}),a=Object.freeze({section:`2xl`,"section-phone":`xl`,tight:`md`,item:`sm`,"heading-after":`xl`,"eyebrow-after":`xxs`,"title-after":`md`,"callout-lead-after":`xs`,"paragraph-gap":`sm`,"sign-gap":`2xl`,"sign-gap-phone":`lg`,"signature-gap":`md`,"step-gap":`lg`,"step-gutter":`3xl`,"step-gutter-phone":`2xl`,"step-number-space":`md`,"step-number-space-phone":`sm`,"column-top":`lg`,"column-gap":`lg`,"row-padding":`sm`,"panel-padding":`lg`,"panel-padding-wide":`lg`,"details-padding":`lg`,"details-padding-wide":`lg`,"hero-padding":`xl lg`,"hero-padding-wide":`2xl lg`,"columns-padding":`none lg lg lg`,"columns-padding-wide":`xs lg lg lg`}),o=new Set([`panel-padding`,`panel-padding-wide`,`details-padding`,`details-padding-wide`,`hero-padding`,`hero-padding-wide`,`columns-padding`,`columns-padding-wide`]),s=Object.freeze({"panel-radius":`md`,"tint-radius":`md`,"code-radius":`md`,"details-radius":`md`}),c=Object.freeze({radius:`md`,padding:`md sm`});function l(e){return Math.floor(e+.5)}function u(e){if(typeof e!=`string`)return null;let t=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e);if(t===null)return null;let n=t[1];n.length===3&&(n=[...n].map(e=>e+e).join(``));let r=e=>Number.parseInt(n.slice(e,e+2),16);return{r:r(0),g:r(2),b:r(4),a:n.length===8?r(6)/255:1}}function d(e,t,n){return`#${[e,t,n].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`.toUpperCase()}function f(e,t){if(e.a===1)return d(e.r,e.g,e.b);if(t===null)return null;let n=(t,n)=>l(t*e.a+n*(1-e.a));return d(n(e.r,t.r),n(e.g,t.g),n(e.b,t.b))}function p(t,n){let i={},a={light:{},dark:{}};for(let o of e){let e=t.colors?.[o]?.surface;e===void 0&&n(`email role card needs meaning surface in ${o}`);let s=u(e);s!==null&&s.a<1&&n(`email card colour (meaning surface, ${o}) must be opaque`),i[o]=s;for(let[e,s]of Object.entries(r)){let r=t.colors?.[o]?.[s];if(r===void 0){n(`email role ${e} needs meaning ${s} in ${o}`);continue}let c=u(r);if(c===null){n(`email role ${e} (meaning ${s}, ${o}): cannot read colour ${r}`);continue}a[o][e]=f(c,i[o])}}return Object.fromEntries(Object.keys(r).map(e=>[e,{light:a.light[e],dark:a.dark[e]}]))}function m(e,t,n){let r={};for(let[a,{step:o,leading:s}]of Object.entries(i)){let i=e.text?.[o],c=t.text?.[o],u=e.typography?.leading?.[s],d=t.typography?.leading?.[s];i===void 0&&n(`email type role ${a} needs text step ${o}`),c===void 0&&n(`email type role ${a} needs text step ${o} in the 390 theme`),u===void 0&&n(`email type role ${a} needs leading ${s}`),d===void 0&&n(`email type role ${a} needs leading ${s} in the 390 theme`),!(i===void 0||c===void 0||u===void 0||d===void 0)&&(r[a]={size:l(i.size),lineHeight:l(i.size*u),phoneSize:l(c.size),phoneLineHeight:l(c.size*d)})}return r}function h(e,t,n,r){let i=[],a=!0;for(let o of t.split(/\s+/))typeof e.space?.[o]==`number`?i.push(e.space[o]):(r(n(o)),a=!1);return a?i.map(e=>`${e}px`).join(` `):null}function g(e,t,n,r){return/\s/.test(n)?(r(`email space role ${t} is a gap and takes one space step, not ${n}`),null):typeof e.space?.[n]==`number`?e.space[n]:(r(`email space role ${t} needs space step ${n}`),null)}function _(e,t){let n={};for(let[r,i]of Object.entries(a)){let a=o.has(r)?h(e,i,e=>`email space role ${r} needs space step ${e}`,t):g(e,r,i,t);a!==null&&(n[r]=a)}return n}function v(e,t){let n={};for(let[r,i]of Object.entries(s)){let a=e.radius?.[i];typeof a==`number`?n[r]=a:t(`email shape role ${r} needs radius step ${i}`)}return n}function y(e,t){let n=e.radius?.[c.radius];return typeof n!=`number`&&t(`email button needs radius step ${c.radius}`),{radius:n,padding:h(e,c.padding,e=>`email button needs space step ${e}`,t)}}function b(e){let t=e.trim();return t.length>=2&&t[0]===t.at(-1)&&(t[0]===`"`||t[0]===`'`)?t.slice(1,-1).trim():t}function x(e){return t.has(e.toLowerCase())||e.startsWith(`-`)?e:e.includes(` `)?`'${e}'`:e}function S(e,t,n){let r=[t.family,...t.fallback.split(`,`)].map(b).filter(e=>e.length>0),i=r.find(e=>/["';<>]/.test(e));return i===void 0?r.map(x).join(`, `):(n(`email font ${e} holds an unsafe character: ${i}`),null)}function C(e,t){let r={};for(let[i,a]of n){let n=e.fonts?.[a];if(typeof n?.family!=`string`||typeof n?.fallback!=`string`){t(`email fonts need font ${a}`);continue}r[i]=S(a,n,t)}return r}function w(e,t){if(e?.format!==`webority-theme-tokens/2`||e.source?.platform!==`web`)throw Error(`emitEmail: web must be the web theme tokens at width 1440`);if(e.source.width!==1440)throw Error(`emitEmail: web must be the 1440 theme`);if(t?.format!==`webority-theme-tokens/2`||t.source?.platform!==`web`||t.source?.width!==390)throw Error(`emitEmail: web390 must be the web theme tokens at width 390`);let n=[],r=e=>n.push(`emitEmail: ${e}`),i=p(e,r),a=m(e,t,r),o=_(e,r),s=v(e,r),c=y(e,r),l=C(e,r);if(n.length>0)throw Error(n.join(`
2
- `));return{format:`webority-email-theme/1`,source:{package:e.source.package,version:e.source.version,brand:e.source.brand},colors:i,fonts:l,type:a,space:o,shape:s,button:c}}export{c as EMAIL_BUTTON,r as EMAIL_COLOR_ROLES,s as EMAIL_SHAPE,a as EMAIL_SPACE,i as EMAIL_TYPE_ROLES,w as emitEmail};
1
+ var e=[`light`,`dark`],t=new Set([`serif`,`sans-serif`,`monospace`,`cursive`,`fantasy`,`system-ui`,`ui-serif`,`ui-sans-serif`,`ui-monospace`]),n=[[`body`,`ui`],[`display`,`display`],[`mono`,`mono`]],r=Object.freeze({page:`bg`,canvas:`bg`,card:`surface`,panel:`bg-subtle`,"panel-alt":`bg-muted`,surface:`surface`,line:`border`,"line-strong":`border-strong`,"accent-tint-line":`primary-wash-strong`,heading:`text`,strong:`text`,text:`text-body`,secondary:`text-muted`,muted:`text-subtle`,accent:`primary`,"on-accent":`on-primary`,link:`link`,success:`success-text`,warning:`warning-text`,danger:`danger-text`,"accent-tint":`primary-wash`,"success-tint":`success-soft`,"warning-tint":`warning-soft`,"danger-tint":`danger-soft`,"figure-panel":`primary-wash`}),i=Object.freeze({eyebrow:{step:`xs`,leading:`body`},h1:{step:`2xl`,leading:`heading`},lede:{step:`lg`,leading:`body`},body:{step:`base`,leading:`body`},"detail-value":{step:`sm`,leading:`body`},quote:{step:`base`,leading:`body`},"body-large":{step:`lg`,leading:`body`},title:{step:`2xl`,leading:`heading`},item:{step:`base`,leading:`body`},label:{step:`sm`,leading:`body`},note:{step:`sm`,leading:`body`},"note-small":{step:`xs`,leading:`body`},figure:{step:`3xl`,leading:`display`},"figure-hero":{step:`4xl`,leading:`display`},"figure-sub":{step:`sm`,leading:`body`},range:{step:`sm`,leading:`body`},sign:{step:`base`,leading:`body`},foot:{step:`xs`,leading:`body`},num:{step:`base`,leading:`body`},"code-otp":{step:`2xl`,leading:`heading`},"code-id":{step:`base`,leading:`body`},button:{step:`base`,leading:`body`}}),a=Object.freeze({section:`2xl`,"section-phone":`xl`,tight:`md`,item:`sm`,"heading-after":`xl`,"eyebrow-after":`xxs`,"title-after":`md`,"callout-lead-after":`xs`,"paragraph-gap":`sm`,"sign-gap":`2xl`,"sign-gap-phone":`lg`,"signature-gap":`md`,"step-gap":`lg`,"step-gutter":`3xl`,"step-gutter-phone":`2xl`,"step-number-space":`md`,"step-number-space-phone":`sm`,"column-top":`lg`,"column-gap":`lg`,"row-padding":`sm`,"panel-padding":`lg`,"panel-padding-wide":`lg`,"details-padding":`lg`,"details-padding-wide":`lg`,"hero-padding":`xl lg`,"hero-padding-wide":`2xl lg`,"columns-padding":`none lg lg lg`,"columns-padding-wide":`xs lg lg lg`}),o=new Set([`panel-padding`,`panel-padding-wide`,`details-padding`,`details-padding-wide`,`hero-padding`,`hero-padding-wide`,`columns-padding`,`columns-padding-wide`]),s=/^(0|\d+px)( (0|\d+px)){0,3}$/,c=Object.freeze({"panel-radius":`md`,"tint-radius":`md`,"code-radius":`md`,"details-radius":`md`}),l=Object.freeze({radius:`md`,padding:`md sm`});function u(e){return Math.floor(e+.5)}function d(e){if(typeof e!=`string`)return null;let t=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e);if(t===null)return null;let n=t[1];n.length===3&&(n=[...n].map(e=>e+e).join(``));let r=e=>Number.parseInt(n.slice(e,e+2),16);return{r:r(0),g:r(2),b:r(4),a:n.length===8?r(6)/255:1}}function f(e,t,n){return`#${[e,t,n].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`.toUpperCase()}function p(e,t){if(e.a===1)return f(e.r,e.g,e.b);if(t===null)return null;let n=(t,n)=>u(t*e.a+n*(1-e.a));return f(n(e.r,t.r),n(e.g,t.g),n(e.b,t.b))}function m(t,n){let i={},a={light:{},dark:{}};for(let o of e){let e=t.colors?.[o]?.surface;e===void 0&&n(`email role card needs meaning surface in ${o}`);let s=d(e);s!==null&&s.a<1&&n(`email card colour (meaning surface, ${o}) must be opaque`),i[o]=s;for(let[e,s]of Object.entries(r)){let r=t.colors?.[o]?.[s];if(r===void 0){n(`email role ${e} needs meaning ${s} in ${o}`);continue}let c=d(r);if(c===null){n(`email role ${e} (meaning ${s}, ${o}): cannot read colour ${r}`);continue}a[o][e]=p(c,i[o])}}return Object.fromEntries(Object.keys(r).map(e=>[e,{light:a.light[e],dark:a.dark[e]}]))}function h(e,t,n){let r={};for(let[a,{step:o,leading:s}]of Object.entries(i)){let i=e.text?.[o],c=t.text?.[o],l=e.typography?.leading?.[s],d=t.typography?.leading?.[s];i===void 0&&n(`email type role ${a} needs text step ${o}`),c===void 0&&n(`email type role ${a} needs text step ${o} in the 390 theme`),l===void 0&&n(`email type role ${a} needs leading ${s}`),d===void 0&&n(`email type role ${a} needs leading ${s} in the 390 theme`),!(i===void 0||c===void 0||l===void 0||d===void 0)&&(r[a]={size:u(i.size),lineHeight:u(i.size*l),phoneSize:u(c.size),phoneLineHeight:u(c.size*d)})}return r}function g(e,t,n,r){let i=[],a=!0;for(let o of t.split(/\s+/))typeof e.space?.[o]==`number`?i.push(e.space[o]):(r(n(o)),a=!1);return a?i.map(e=>`${e}px`).join(` `):null}function _(e,t,n,r){return/\s/.test(n)?(r(`email space role ${t} is a gap and takes one space step, not ${n}`),null):typeof e.space?.[n]==`number`?e.space[n]:(r(`email space role ${t} needs space step ${n}`),null)}function v(e,t){let n={};for(let[r,i]of Object.entries(a)){let a=o.has(r)?g(e,i,e=>`email space role ${r} needs space step ${e}`,t):_(e,r,i,t);a!==null&&(n[r]=a)}return n}function y(e,t){let n={};for(let[r,i]of Object.entries(c)){let a=e.radius?.[i];typeof a==`number`?n[r]=a:t(`email shape role ${r} needs radius step ${i}`)}return n}function b(e,t){let n=e.radius?.[l.radius];return typeof n!=`number`&&t(`email button needs radius step ${l.radius}`),{radius:n,padding:g(e,l.padding,e=>`email button needs space step ${e}`,t)}}function x(e){let t=e.trim();return t.length>=2&&t[0]===t.at(-1)&&(t[0]===`"`||t[0]===`'`)?t.slice(1,-1).trim():t}function S(e){return t.has(e.toLowerCase())||e.startsWith(`-`)?e:e.includes(` `)?`'${e}'`:e}function C(e,t,n){let r=[t.family,...t.fallback.split(`,`)].map(x).filter(e=>e.length>0),i=r.find(e=>/["';<>]/.test(e));return i===void 0?r.map(S).join(`, `):(n(`email font ${e} holds an unsafe character: ${i}`),null)}function w(e,t){let r={};for(let[i,a]of n){let n=e.fonts?.[a];if(typeof n?.family!=`string`||typeof n?.fallback!=`string`){t(`email fonts need font ${a}`);continue}r[i]=C(a,n,t)}return r}function T(e,t,n){return Number.isInteger(e?.value)&&e.value>=0&&e.unit===`px`?e.value:(n(`${t} needs a whole px value`),null)}function E(e,t,n){return typeof e==`string`&&s.test(e)?e:(n(`${t} needs CSS px padding`),null)}function D(e,t,n,r,i){let a=/^\{color\.([a-z0-9-]+)\}$/.exec(t)?.[1],o=a===void 0?t:e.colors?.[n]?.[a];if(o===void 0)return i(`email group role ${r} needs meaning ${a} in ${n}`),null;let s=d(o);if(s===null)return i(`email group role ${r} (${n}): cannot read colour ${o}`),null;let c=p(s,d(e.colors?.[n]?.surface));return c===null&&i(`email group role ${r} must be opaque in ${n}`),c}function O(e,t,n,s){let{colors:l,type:u,space:d,shape:f,button:p}=n,m=(e,t)=>s(`email group key email.${e}.${t} is not an email role`);for(let[n,i]of Object.entries(e.color??{})){if(!Object.hasOwn(r,n)){m(`color`,n);continue}l[n]={light:D(t,i.$value,`light`,n,s),dark:D(t,i.$extensions?.[`com.webority`]?.dark??i.$value,`dark`,n,s)}}for(let[t,n]of Object.entries(e.type??{})){if(!Object.hasOwn(i,t)){m(`type`,t);continue}let{size:e,lineHeight:r,phoneSize:a,phoneLineHeight:o}=n.$value??{};[e,r,a,o].every(e=>Number.isInteger(e)&&e>0)||s(`email group role ${t} needs size, lineHeight, phoneSize and phoneLineHeight in whole px`),u[t]={size:e,lineHeight:r,phoneSize:a,phoneLineHeight:o}}for(let[t,n]of Object.entries(e.space??{})){if(!Object.hasOwn(a,t)){m(`space`,t);continue}let e=`email group role ${t}`;d[t]=o.has(t)?E(n.$value,e,s):T(n.$value,e,s)}for(let[t,n]of Object.entries(e.shape??{})){if(!Object.hasOwn(c,t)){m(`shape`,t);continue}f[t]=T(n.$value,`email group role ${t}`,s)}for(let[t,n]of Object.entries(e.button??{}))t===`radius`?p.radius=T(n.$value,`email group role button radius`,s):t===`padding`?p.padding=E(n.$value,`email group role button padding`,s):m(`button`,t)}function k(e,t,n=null){if(e?.format!==`webority-theme-tokens/2`||e.source?.platform!==`web`)throw Error(`emitEmail: web must be the web theme tokens at width 1440`);if(e.source.width!==1440)throw Error(`emitEmail: web must be the 1440 theme`);if(t?.format!==`webority-theme-tokens/2`||t.source?.platform!==`web`||t.source?.width!==390)throw Error(`emitEmail: web390 must be the web theme tokens at width 390`);let r=[],i=e=>r.push(`emitEmail: ${e}`),a=m(e,i),o=h(e,t,i),s=v(e,i),c=y(e,i),l=b(e,i),u=w(e,i);if(n!==null&&O(n,e,{colors:a,type:o,space:s,shape:c,button:l},i),r.length>0)throw Error(r.join(`
2
+ `));return{format:`webority-email-theme/1`,source:{package:e.source.package,version:e.source.version,brand:e.source.brand},colors:a,fonts:u,type:o,space:s,shape:c,button:l}}export{l as EMAIL_BUTTON,r as EMAIL_COLOR_ROLES,s as EMAIL_PADDING_PATTERN,o as EMAIL_PADDING_ROLES,c as EMAIL_SHAPE,a as EMAIL_SPACE,i as EMAIL_TYPE_ROLES,k as emitEmail};
@@ -1,3 +1,3 @@
1
1
  var e=/^[A-Za-z_$][A-Za-z0-9_$]*$/,t=/^#([0-9a-fA-F]{6})([0-9a-fA-F]{2})?$/,n=/^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d.]+)\s*\)$/,r=[`xs`,`sm`,`md`,`lg`,`xl`],i=`must be component.<name>.<prop> or component.<name>.<size>.<prop>`,a=[`light`,`dark`],o={color:`colors`,space:`space`,radius:`radius`,text:`text`,weight:`weight`,leading:`leading`,"letter-spacing":`letter-spacing`,font:`font`,shadow:`shadow`,size:`size`,component:`components`},s=[{key:`colors`,constName:`COLOR_NAMES`,typeName:`ColorName`},{key:`space`,constName:`SPACE_NAMES`,typeName:`SpaceName`},{key:`radius`,constName:`RADIUS_NAMES`,typeName:`RadiusName`},{key:`text`,constName:`TEXT_NAMES`,typeName:`TextName`},{key:`weight`,constName:`WEIGHT_NAMES`,typeName:`WeightName`},{key:`leading`,constName:`LEADING_NAMES`,typeName:`LeadingName`},{key:`letter-spacing`,constName:`LETTER_SPACING_NAMES`,typeName:`LetterSpacingName`},{key:`font`,constName:`FONT_NAMES`,typeName:`FontName`},{key:`shadow`,constName:`SHADOW_NAMES`,typeName:`ShadowName`},{key:`motion.duration`,constName:`DURATION_NAMES`,typeName:`DurationName`},{key:`motion.ease`,constName:`EASE_NAMES`,typeName:`EaseName`},{key:`size`,constName:`SIZE_NAMES`,typeName:`SizeName`}],c={space:`SpaceName`,text:`TextName`,radius:`RadiusName`,px:`number`,number:`number`,ms:`number`},l=[`export type FontWeightValue = "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900";`,`/** Face name per weight; an empty object means the platform system font. */`,`export type FontFaces = Partial<Record<WeightName, string>>;`,`export interface PhoneShadow {`,` shadowColor: string;`,` shadowOffset: { width: number; height: number };`,` shadowOpacity: number;`,` shadowRadius: number;`,` elevation: number;`,`}`,`export type ComponentKind = "space" | "text" | "radius" | "px" | "number" | "ms";`,`type Sized<S extends string, T> = Record<S, T>;`,`type L3 = "sm" | "md" | "lg";`],u=[`export interface TokenSet {`,` mode: "light" | "dark";`,` colors: Record<ColorName, string>;`,` space: Record<SpaceName, number>;`,` radius: Record<RadiusName, number>;`,` text: Record<TextName, { size: number }>;`,` weight: Record<WeightName, FontWeightValue>;`,` leading: Record<LeadingName, number>;`,` "letter-spacing": Record<LetterSpacingName, number>;`,` font: Record<FontName, FontFaces>;`,` shadow: Record<ShadowName, PhoneShadow>;`,` motion: { duration: Record<DurationName, number>; ease: Record<EaseName, readonly [number, number, number, number]> };`,` size: Record<SizeName, number>;`,` components: ComponentTokens;`,`}`];function d(e,t){let n=e.contexts.find(e=>e.platform===`phone`&&e.mode===t);if(!n)throw Error(`phoneSets: the model has no ${t} phone context`);let r=[];for(let t of e.tokens.values()){if(!e.existsIn(t.path,n))continue;let i=e.resolvedIn(t.path,n);r.push({path:t.path.split(`.`),type:t.type,value:t.group===`text`?m(t.path,i):i,reference:e.referenceIn(t.path,n)??null,platforms:t.platforms,extensions:Object.keys(t.extensions).length>0?t.extensions:null})}return r}function f(e){let t=y(e.light),n=y(e.dark);D(t,n);let r=["// Generated by `webority brand --library` from packages/tokens/src/source. Do not edit: run `corepack pnpm --filter @webority/mobile-ui tokens`."];for(let e of s)r.push(...j(e,t.lists.get(e.key)));return r.push(...l),r.push(...I(t.components)),r.push(...L(t.components)),r.push(...u),r.push(...B(`lightTokens`,`light`,t)),r.push(...B(`darkTokens`,`dark`,n)),{name:`tokens.generated.ts`,contents:`${r.join(`
2
- `)}\n`}}function p(e,t,n){let r={colors:{light:{},dark:{}},radius:{},font:{}};for(let n of a){let i=y(e[n]).values,a=y(t[n]).values;for(let e of new Set([...i.keys(),...a.keys()])){let t=i.get(e),o=a.get(e);if(!t||!o)throw Error(k(e));if(JSON.stringify(t.value)===JSON.stringify(o.value))continue;let s=e.lastIndexOf(`.`),c=e.slice(0,s),l=e.slice(s+1);if(c===`radius`&&(l===`none`||l===`pill`))throw Error(`A brand cannot change radius none or pill`);if(c===`colors`)r.colors[n][l]=o.value;else if(c===`radius`)O(r.radius,l,o.value,e);else if(c===`font`)O(r.font,l,o.value,e);else throw Error(k(e))}}let i=Object.fromEntries(a.filter(e=>Object.keys(r.colors[e]).length>0).map(e=>[e,r.colors[e]])),o={};Object.keys(i).length>0&&(o.colors=i),Object.keys(r.radius).length>0&&(o.radius=r.radius),Object.keys(r.font).length>0&&(o.font=r.font);let s=[`// Generated by \`webority brand\` for ${n.brand} from ${n.package} ${n.version}. Do not edit.`,``,`/** @type {import("@webority/mobile-ui").BrandOverrides} */`];return Object.keys(o).length===0?s.push(`export const brand = {};`):s.push(`export const brand = {`,...Object.entries(o).flatMap(([e,t])=>H(e,t,` `)),`};`),{name:`brand.phone.js`,contents:`${s.join(`
2
+ `)}\n`}}function p(e,t,n){let r={colors:{light:{},dark:{}},radius:{},font:{}};for(let n of a){let i=y(e[n]).values,a=y(t[n]).values;for(let e of new Set([...i.keys(),...a.keys()])){let t=i.get(e),o=a.get(e);if(!t&&o&&e.startsWith(`colors.`))continue;if(!t||!o)throw Error(k(e));if(JSON.stringify(t.value)===JSON.stringify(o.value))continue;let s=e.lastIndexOf(`.`),c=e.slice(0,s),l=e.slice(s+1);if(c===`radius`&&(l===`none`||l===`pill`))throw Error(`A brand cannot change radius none or pill`);if(c===`colors`)r.colors[n][l]=o.value;else if(c===`radius`)O(r.radius,l,o.value,e);else if(c===`font`)O(r.font,l,o.value,e);else throw Error(k(e))}}let i=Object.fromEntries(a.filter(e=>Object.keys(r.colors[e]).length>0).map(e=>[e,r.colors[e]])),o={};Object.keys(i).length>0&&(o.colors=i),Object.keys(r.radius).length>0&&(o.radius=r.radius),Object.keys(r.font).length>0&&(o.font=r.font);let s=[`// Generated by \`webority brand\` for ${n.brand} from ${n.package} ${n.version}. Do not edit.`,``,`/** @type {import("@webority/mobile-ui").BrandOverrides} */`];return Object.keys(o).length===0?s.push(`export const brand = {};`):s.push(`export const brand = {`,...Object.entries(o).flatMap(([e,t])=>H(e,t,` `)),`};`),{name:`brand.phone.js`,contents:`${s.join(`
3
3
  `)}\n`}}function m(e,t){return{size:v(t,e)}}function h(e){return e.extensions?.internal===!0?!1:e.platforms===null||e.platforms.includes(`phone`)}function g(e,t){return Error(`Token group ${e} has no phone mapping; mark it web or add one to emit/phone.js (first: ${t})`)}function _(e){let[t,n]=e.path;if(t===`motion`){if(n===`duration`||n===`ease`)return`motion.${n}`;throw g(t,e.path.join(`.`))}if(!Object.hasOwn(o,t))throw g(t,e.path.join(`.`));return o[t]}function v(e,t){let n=typeof e==`object`&&e?e.value:e;if(!Number.isFinite(n))throw Error(`Token ${t} has no numeric value`);return n}function y(e){let t=new Map(s.map(e=>[e.key,[]])),n=new Map,r=new Map;for(let i of e){if(!h(i))continue;let e=i.path.join(`.`),a=_(i);if(i.value===void 0||i.value===null)throw Error(`Token ${e} has no phone value`);if(a===`components`){T(i,e,n,r);continue}let o=i.path.slice(a.startsWith(`motion.`)?2:1).join(`-`);n.set(`${a}.${o}`,{path:e,value:b(a,o,i,e)}),t.get(a).push(o)}return{lists:t,values:n,components:r}}function b(e,t,n,r){let{value:i}=n;switch(e){case`colors`:return i;case`space`:case`radius`:case`letter-spacing`:case`size`:case`leading`:case`motion.duration`:return v(i,r);case`text`:return{size:v(i.size,r)};case`weight`:return String(v(i,r));case`font`:return x(n,t);case`shadow`:return S(n,t,r);case`motion.ease`:return w(i,r)}}function x(e,t){if(Array.isArray(e.value)&&e.value.length===1&&e.value[0]===`System`)return{};if(!e.extensions?.faces)throw Error(`Font ${t} is not the system font and has no faces`);return e.extensions.faces}function S(e,t,n){let{color:r,offsetX:i,offsetY:a,blur:o}=e.value,{hex:s,opacity:c}=C(r,n),l=e.extensions?.elevation;if(!Number.isFinite(l))throw Error(`Shadow ${t} has no elevation`);return{shadowColor:s,shadowOffset:{width:v(i,n),height:v(a,n)},shadowOpacity:c,shadowRadius:v(o,n),elevation:l}}function C(e,r){let i=t.exec(e);if(i){let e=i[2]===void 0?1:Math.round(parseInt(i[2],16)/255*1e3)/1e3;return{hex:`#${i[1].toLowerCase()}`,opacity:e}}let a=n.exec(e);if(a)return{hex:`#${a.slice(1,4).map(e=>Number(e).toString(16).padStart(2,`0`)).join(``)}`,opacity:Number(a[4])};throw Error(`Shadow ${r} colour is not #RRGGBB, #RRGGBBAA or rgba(): ${e}`)}function w(e,t){if(!Array.isArray(e)||e.length!==4||!e.every(e=>Number.isFinite(e)))throw Error(`Token ${t} has no phone value`);return[...e]}function T(e,t,n,a){let o=e.path,s=o.length===4;if(o.length!==3&&!s||s&&!r.includes(o[2]))throw Error(`Component token ${t} ${i}`);let c=o[1],l=o[o.length-1],{kind:u,value:d}=E(e,t);a.has(c)||a.set(c,{props:new Map,sizes:new Map,free:new Map});let f=a.get(c);if(f.props.has(l)&&f.props.get(l)!==u)throw Error(`Component ${c} prop ${l} has two kinds`);if(f.props.set(l,u),s){let e=o[2];f.sizes.has(e)||f.sizes.set(e,new Map),f.sizes.get(e).set(l,d),n.set(`components.${c}.${e}.${l}`,{path:t,value:d})}else f.free.set(l,d),n.set(`components.${c}.${l}`,{path:t,value:d})}function E(e,t){let{reference:n}=e;for(let[e,t]of[[`space.`,`space`],[`text.`,`text`],[`radius.`,`radius`]])if(n?.startsWith(e))return{kind:t,value:n.slice(e.length)};if(!n){if(e.type===`dimension`)return{kind:`px`,value:v(e.value,t)};if(e.type===`number`)return{kind:`number`,value:v(e.value,t)};if(e.type===`duration`)return{kind:`ms`,value:v(e.value,t)}}throw Error(`Component token ${t} has an unsupported value`)}function D(e,t){for(let[n,{path:r}]of e.values)if(!t.values.has(n))throw Error(`Token ${r} exists in one mode only`);for(let[n,{path:r}]of t.values)if(!e.values.has(n))throw Error(`Token ${r} exists in one mode only`)}function O(e,t,n,r){if(Object.hasOwn(e,t)&&JSON.stringify(e[t])!==JSON.stringify(n))throw Error(`A brand sets ${r} differently in light and dark`);e[t]=n}function k(e){return`A brand overrides colours, radius and fonts only; ${e} differs`}function A(t){return e.test(t)?t:JSON.stringify(t)}function j(e,t){let n=`export type ${e.typeName} = (typeof ${e.constName})[number];`;return t.length<=12?[`export const ${e.constName} = [${t.map(e=>JSON.stringify(e)).join(`, `)}] as const;`,n]:[`export const ${e.constName} = [`,...t.map(e=>` ${JSON.stringify(e)},`),`] as const;`,n]}var M=140;function N(e,t){return t.map(t=>`${A(t)}: ${c[e.props.get(t)]}`)}function P(e){return e.split(/[^A-Za-z0-9]+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}function F(e,t){return[`export interface ${e} {`,...t.map(e=>` ${e};`),`}`]}function I(e){let t=[],n=[];for(let[i,a]of e){let e=N(a,[...a.free.keys()]),o=N(a,[...new Set([...a.sizes.values()].flatMap(e=>[...e.keys()]))]),s=r.filter(e=>a.sizes.has(e)),c=s.join()===`sm,md,lg`?`L3`:s.map(e=>JSON.stringify(e)).join(` | `),l=e=>`{ ${e.join(`; `)} }`,u=(t,n)=>o.length===0?n:`Sized<${c}, ${t}>${e.length>0?` & ${n}`:``}`,d=` ${A(i)}: ${u(l(o),l(e))};`;if(d.length<=M){n.push(d);continue}let f=P(i);o.length>0&&t.push(...F(`${f}SizeTokens`,o)),e.length>0&&t.push(...F(`${f}Tokens`,e)),n.push(` ${A(i)}: ${u(`${f}SizeTokens`,`${f}Tokens`)};`)}let i=[...t,`export interface ComponentTokens {`,...n];return i.push(`}`,`export type ComponentName = keyof ComponentTokens;`,`type SizeKeysOf<C extends ComponentName> = Extract<keyof ComponentTokens[C], "xs" | "sm" | "md" | "lg" | "xl">;`,`export type ComponentSizeTokens<C extends ComponentName> = ComponentTokens[C][SizeKeysOf<C>];`),i}function L(e){let t=[`export const COMPONENT_KINDS = {`];for(let[n,r]of e){let e=[...r.props].map(([e,t])=>`${A(e)}: ${JSON.stringify(t)}`),i=` ${A(n)}: { ${e.join(`, `)} },`;i.length<=M?t.push(i):t.push(` ${A(n)}: {`,...e.map(e=>` ${e},`),` },`)}return t.push(`} as const satisfies { readonly [C in ComponentName]: Readonly<Record<string, ComponentKind>> };`),t}function R(e){let t={};for(let[n,i]of e){let e={};for(let t of r)i.sizes.has(t)&&(e[t]=Object.fromEntries(i.sizes.get(t)));for(let[t,n]of i.free)e[t]=n;t[n]=e}return t}function z(e,t){let{lists:n}=t,r=(e,n)=>Object.fromEntries(n.map(n=>[n,t.values.get(`${e}.${n}`).value]));return{mode:e,colors:r(`colors`,n.get(`colors`)),space:r(`space`,n.get(`space`)),radius:r(`radius`,n.get(`radius`)),text:r(`text`,n.get(`text`)),weight:r(`weight`,n.get(`weight`)),leading:r(`leading`,n.get(`leading`)),"letter-spacing":r(`letter-spacing`,n.get(`letter-spacing`)),font:r(`font`,n.get(`font`)),shadow:r(`shadow`,n.get(`shadow`)),motion:{duration:r(`motion.duration`,n.get(`motion.duration`)),ease:r(`motion.ease`,n.get(`motion.ease`))},size:r(`size`,n.get(`size`)),components:R(t.components)}}function B(e,t,n){let r=z(t,n);return[`export const ${e}: TokenSet = {`,...Object.entries(r).flatMap(([e,t])=>H(e,t,` `)),`};`]}function V(e){return Array.isArray(e)?`[${e.map(e=>V(e)).join(`, `)}]`:JSON.stringify(e)}function H(e,t,n){let r=`${n}${A(e)}`;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.entries(t);return e.length===0?[`${r}: {},`]:[`${r}: {`,...e.flatMap(([e,t])=>H(e,t,`${n} `)),`${n}},`]}return[`${r}: ${V(t)},`]}export{p as emitPhoneBrand,f as emitPhoneTheme,d as phoneSets};
@@ -2,7 +2,7 @@
2
2
  "format": "webority-meanings/1",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.100.0"
5
+ "version": "0.101.0"
6
6
  },
7
7
  "color": {
8
8
  "bg": {
@@ -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},_=(e,t)=>{let n=g(t).reverse();for(let t of n){let n=t.get(e);if(n)return n}},v=(e,t)=>{let n=l.get(e);return n?n.platforms===null||n.platforms.includes(t.platform):!1},y=(e,t)=>{if(!v(e,t))throw Error(`model: ${e} does not exist on ${t.platform}`)},b=new Map,x=(t,r)=>{let a=`${s(r)}|${t}`;if(b.has(a))return b.get(a);y(t,r);let o=l.get(t),{value:u}=_(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=>S(e,r))}else d=i(u,(e,n)=>{let i=x(e,r);return n?i:c(i,e,t)});return b.set(a,d),d},S=(e,t)=>{let n=d.get(e);if(n===void 0||!v(n,t))return;if(l.get(n).type===`color`)return x(n,t);let{value:r}=_(n,t);return typeof r==`string`?r:void 0},C=()=>{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)}},w=()=>{for(let e of m){let n=new Map;for(let t of l.keys())v(t,e)&&n.set(t,a(_(t,e).value));for(let i of r(n)){let n=t(_(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)}}},T=()=>{for(let e of m)for(let n of l.keys()){if(!v(n,e))continue;let{file:r,value:i}=_(n,e);for(let o of a(i))if(l.has(o)&&!v(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)}}},E=()=>{for(let e of m)for(let n of l.keys())if(v(n,e))try{x(n,e)}catch(r){let i=t(_(n,e).file,n,r.message.replace(/\.$/,``),`Correct the value or the tokens it references.`);p.includes(i)||p.push(i)}},D=p.length;C();let O=p.length>D;if(O||w(),O||T(),p.length===0&&E(),p.length>0)throw Error(p.join(`
2
- `));return{tokens:l,contexts:o(),existsIn:(e,t)=>v(e,h(t)),valueIn:(e,t)=>{let n=h(t);return y(e,n),structuredClone(_(e,n).value)},resolvedIn:(e,t)=>{let n=h(t);return structuredClone(x(e,n))},referenceIn:(e,t)=>{let n=h(t);return y(e,n),a(_(e,n).value)[0]},source:f}}export{o as buildContexts,l as buildModel};
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(`
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/dist/outputs.d.ts CHANGED
@@ -74,6 +74,8 @@ export type EmailTypeRoleKey =
74
74
  | "eyebrow"
75
75
  | "lede"
76
76
  | "body"
77
+ | "detail-value"
78
+ | "quote"
77
79
  | "body-large"
78
80
  | "title"
79
81
  | "item"
@@ -1,2 +1,2 @@
1
1
  import e from"node:path";import{parse as t}from"@babel/parser";var n=new Set([`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`,`ObjectMethod`,`ClassMethod`]),r=new Set([`MemberExpression`,`OptionalMemberExpression`]),i=new Set([`CallExpression`,`OptionalCallExpression`]),a=new Set([`useTheme`,`getTheme`]),o=new Set([`loc`,`start`,`end`,`extra`,`comments`,`leadingComments`,`trailingComments`,`innerComments`]),s=new Map([[`.js`,[`jsx`]],[`.jsx`,[`jsx`]],[`.mjs`,[`jsx`]],[`.cjs`,[`jsx`]],[`.ts`,[`typescript`]],[`.tsx`,[`typescript`,`jsx`]]]),c=/^[A-Za-z_$][\w$]*$/,l=new Set([`lightOverrides`,`darkOverrides`]),u=`move the brand into theme/brand.tokens.json, list the app under tokens.heads.phone, run webority brand, pass brand and settings`,d=e=>typeof e==`object`&&!!e&&typeof e.type==`string`,f=(e,t,n=[])=>{if(Array.isArray(e)){for(let r of e)f(r,t,n);return}if(!d(e))return;t(e,n);let r=[...n,e];for(let[n,i]of Object.entries(e))!o.has(n)&&typeof i==`object`&&i&&f(i,t,r)},p=(n,r)=>{let i=s.get(e.extname(r).toLowerCase());return i===void 0?null:t(n,{sourceType:`module`,plugins:i})},m=(e,t,n)=>({text:e,hits:[],findings:[{file:t,line:1,path:``,message:`skipped, it does not parse (${(n instanceof Error?n.message:String(n)).split(`
2
- `)[0]})`}]}),h=(e,t,n)=>{let r=[...t].sort((e,t)=>e.start-t.start||e.end-t.end),i=0;for(let e of r){if(e.start<i)throw Error(`two edits overlap in ${n}; fix it by hand`);i=e.end}let a=e;for(let e of r.reverse())a=a.slice(0,e.start)+e.text+a.slice(e.end);return a},g=e=>e.replace(/\.$/,``).split(`.`),_=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),v=(e,t)=>e<t?-1:+(e>t),y=(e,t)=>{let n=t.at(-1);return n!==void 0&&r.has(n.type)&&n.object===e},b=e=>d(e)&&i.has(e.type)&&e.callee.type===`Identifier`&&a.has(e.callee.name),x=e=>{for(let t=e.length-1;t>=0;t--)if(n.has(e[t].type))return e[t];return e.find(e=>e.type===`Program`)},S=e=>{let t=new Map;return f(e,(e,n)=>{if(e.type!==`VariableDeclarator`||e.id.type!==`Identifier`||!b(e.init))return;let r=x(n);t.has(r)||t.set(r,new Set),t.get(r)?.add(e.id.name)}),t},C=(e,t,r)=>t.some(t=>(n.has(t.type)||t.type===`Program`)&&r.get(t)?.has(e)===!0),w=(e,t,n)=>e.type===`Identifier`?e.name===`theme`||C(e.name,t,n):b(e),T=e=>{if(e.computed!==!0&&e.property.type===`Identifier`)return e.property.name;if(e.computed===!0&&e.property.type===`StringLiteral`)return e.property.value};function E(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let i;try{i=p(e,t)}catch(n){return m(e,t,n)}if(i===null)return{text:e,hits:[],findings:[]};let a=S(i),o=n.filter(e=>e.kind===`path`||e.kind===`prefix`||e.kind===`gone`).sort((e,t)=>g(t.from).length-g(e.from).length),s=n.filter(e=>e.kind===`kebab`),d=[],b=[],x=[],C=new Set,E=(e,n)=>{let r=`${e}:${n}`;C.has(r)||(C.add(r),x.push({file:t,line:e,path:n,message:u}))},D=(e,n)=>{let i=[],l=e;for(;r.has(l.type);)i.unshift(l),l=l.object;if(!w(l,n,a))return;let u=[];for(let e of i){let t=T(e);if(t===void 0)break;u.push(t)}let f=u.length;if(f===0)return;let p=[...u];for(let e of o){let n=g(e.from),r=e.kind===`prefix`&&e.from.endsWith(`.`);if(!(f<n.length||r&&f===n.length)&&n.every((e,t)=>u[t]===e)){if(e.kind===`gone`){x.push({file:t,line:i[n.length-1].property.loc.start.line,path:n.join(`.`),message:`no longer exists; ${e.hint}`});return}if(e.kind===`path`||e.kind===`prefix`){p=[...g(e.to),...u.slice(n.length)];break}}}for(let e of s){let t=e.under.split(`.`),n=t.length;if(p.length<=n||!t.every((e,t)=>p[t]===e))continue;let r=p[n];Object.hasOwn(e.names,r)&&(p[n]=e.names[r]);for(let e=n+1;e<p.length;e++)/[A-Z]/.test(p[e])&&(p[e]=p[e].replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase())}if(_(p,u))return;let m=p.map((e,t)=>{let n=i[t]?.optional===!0;return c.test(e)?`${n?`?.`:`.`}${e}`:`${n?`?.`:``}["${e}"]`}).join(``);d.push({start:l.end,end:i[f-1].end,text:m}),b.push({line:i[0].property.loc.start.line,from:u.join(`.`),to:p.join(`.`)})};return f(i,(e,t)=>{r.has(e.type)&&!y(e,t)&&D(e,t),e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&l.has(e.name.name)&&E(e.loc.start.line,e.name.name),e.type===`Identifier`&&e.name===`ThemeOverrides`&&E(e.loc.start.line,e.name)}),b.sort((e,t)=>e.line-t.line||v(e.from,t.from)),x.sort((e,t)=>e.line-t.line||v(e.path,t.path)),{text:h(e,d,t),hits:b,findings:x}}var D=(e,t,n)=>{if(e.type===`JSXIdentifier`)return t.has(e.name);if(e.type===`JSXMemberExpression`){let t=e;for(;t.type===`JSXMemberExpression`;)t=t.object;return t.type===`JSXIdentifier`&&n.has(t.name)}return!1},O=e=>{if(e?.type===`StringLiteral`)return e;if(e?.type===`JSXExpressionContainer`&&e.expression.type===`StringLiteral`)return e.expression};function k(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let r;try{r=p(e,t)}catch(n){return m(e,t,n)}if(r===null)return{text:e,hits:[],findings:[]};let i=[],a=[];for(let t of n){let n=new Set,o=new Set;f(r,e=>{if(!(e.type!==`ImportDeclaration`||e.source.value!==t.package))for(let t of e.specifiers)t.type===`ImportNamespaceSpecifier`?o.add(t.local.name):n.add(t.local.name)});let s=new Set(t.props);f(r,r=>{if(!(r.type!==`JSXOpeningElement`||!D(r.name,n,o)))for(let n of r.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||!s.has(n.name.name))continue;let r=O(n.value);if(r===void 0||r.value!==t.from)continue;let o=e[r.start];i.push({start:r.start,end:r.end,text:`${o}${t.to}${o}`}),a.push({line:r.loc.start.line,from:`${n.name.name}="${t.from}"`,to:`${n.name.name}="${t.to}"`})}})}return a.sort((e,t)=>e.line-t.line||v(e.from,t.from)),{text:h(e,i,t),hits:a,findings:[]}}var A=(e,t)=>{let n=new Map,r=new Set;return f(e,e=>{if(!(e.type!==`ImportDeclaration`||e.source.value!==t))for(let t of e.specifiers)if(t.type===`ImportSpecifier`){let e=t.imported.type===`StringLiteral`?t.imported.value:t.imported.name;n.set(t.local.name,e)}else t.type===`ImportNamespaceSpecifier`&&r.add(t.local.name)}),{named:n,namespaces:r}},j=(e,t)=>{if(e.type===`JSXIdentifier`)return t.named.get(e.name);if(e.type===`JSXMemberExpression`&&e.object.type===`JSXIdentifier`&&t.namespaces.has(e.object.name))return e.property.name};function M(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let r;try{r=p(e,t)}catch(n){return m(e,t,n)}if(r===null)return{text:e,hits:[],findings:[]};let i=[],a=[],o=[];for(let s of n){let n=A(r,s.package);f(r,r=>{if(r.type!==`JSXOpeningElement`)return;let c=j(r.name,n);if(s.components.includes(c))for(let n of r.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==s.prop)continue;let r=n.value,l=n.loc.start.line,u=r?.type===`JSXExpressionContainer`?r.expression:void 0,d=r===null?!0:u?.type===`BooleanLiteral`?u.value:void 0,f;if(d!==void 0)f=`${s.prop}="${d?s.true:s.false}"`;else if(O(r)!==void 0)continue;else{o.push({file:t,line:l,path:`${c}.${s.prop}`,message:`${s.prop} takes a named value such as "${s.true}" or "${s.false}" now, not a boolean; set it by hand`});continue}i.push({start:n.start,end:n.end,text:f}),a.push({line:l,from:e.slice(n.start,n.end),to:f})}})}return a.sort((e,t)=>e.line-t.line||v(e.from,t.from)),o.sort((e,t)=>e.line-t.line||v(e.path,t.path)),{text:h(e,i,t),hits:a,findings:o}}function N(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let r;try{r=p(e,t)}catch(n){return m(e,t,n)}if(r===null)return{text:e,hits:[],findings:[]};let i=t=>e.slice(t.start,t.end),a=new Set([`ObjectExpression`,`Identifier`,`MemberExpression`,`OptionalMemberExpression`]),o=new Set([`SequenceExpression`,`AssignmentExpression`,`ConditionalExpression`,`YieldExpression`]),s=e=>{if(e?.type===`LogicalExpression`&&e.operator===`&&`)return{test:e.left,consequent:e.right};let t=e?.alternate;if(e?.type===`ConditionalExpression`&&(t.type===`NullLiteral`||t.type===`Identifier`&&t.name===`undefined`||t.type===`BooleanLiteral`&&t.value===!1))return{test:e.test,consequent:e.consequent}},c=e=>o.has(e.test.type)?`(${i(e.test)})`:i(e.test),l=[],u=[],d=[];for(let e of n){let n=A(r,e.package);f(r,r=>{if(r.type!==`JSXOpeningElement`)return;let o=j(r.name,n);if(!e.components.includes(o))return;let f=r.attributes.some(t=>t.type===`JSXAttribute`&&t.name.type===`JSXIdentifier`&&t.name.name===e.into);for(let n of r.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==e.prop)continue;let r=n.value,p=n.loc.start.line;if(O(r)!==void 0)continue;let m=`${o}.${e.prop}`;if(f){d.push({file:t,line:p,path:m,message:`already sets ${e.into}; set ${e.prop} to "${e.on}" or "${e.off}" by hand`});continue}let h=r?.type===`JSXExpressionContainer`?r.expression:void 0,g=r===null?!0:h?.type===`BooleanLiteral`?h.value:void 0,_=s(h),v;if(g!==void 0)v=`${e.prop}="${g?e.on:e.off}"`;else if(a.has(h?.type))v=`${e.prop}="${e.on}" ${e.into}={${i(h)}}`;else if(_!==void 0&&_.consequent.type===`BooleanLiteral`&&_.consequent.value===!0)v=`${e.prop}={${c(_)} ? "${e.on}" : "${e.off}"}`;else if(_!==void 0&&a.has(_.consequent.type))v=`${e.prop}={${c(_)} ? "${e.on}" : "${e.off}"} ${e.into}={${i(_.consequent)}}`;else{d.push({file:t,line:p,path:m,message:`${e.prop} takes "${e.on}" or "${e.off}" now, and its settings object moves to ${e.into}; set both by hand`});continue}l.push({start:n.start,end:n.end,text:v}),u.push({line:p,from:i(n),to:v})}})}return u.sort((e,t)=>e.line-t.line||v(e.from,t.from)),d.sort((e,t)=>e.line-t.line||v(e.path,t.path)),{text:h(e,l,t),hits:u,findings:d}}export{N as applyPropSplits,M as applyPropValues,k as applyProps,E as applyThemeReads};
2
+ `)[0]})`}]}),h=(e,t,n)=>{let r=[...t].sort((e,t)=>e.start-t.start||e.end-t.end),i=0;for(let e of r){if(e.start<i)throw Error(`two edits overlap in ${n}; fix it by hand`);i=e.end}let a=e;for(let e of r.reverse())a=a.slice(0,e.start)+e.text+a.slice(e.end);return a},g=e=>e.replace(/\.$/,``).split(`.`),_=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),v=(e,t)=>e<t?-1:+(e>t),y=(e,t)=>{let n=t.at(-1);return n!==void 0&&r.has(n.type)&&n.object===e},b=(e,t)=>d(e)&&i.has(e.type)&&e.callee.type===`Identifier`&&t.has(e.callee.name),x=e=>{for(let t=e.length-1;t>=0;t--)if(n.has(e[t].type))return e[t];return e.find(e=>e.type===`Program`)},S=(e,t)=>{let n=new Map;return f(e,(e,r)=>{if(e.type!==`VariableDeclarator`||e.id.type!==`Identifier`||!b(e.init,t))return;let i=x(r);n.has(i)||n.set(i,new Set),n.get(i)?.add(e.id.name)}),n},C=(e,t,r)=>t.some(t=>(n.has(t.type)||t.type===`Program`)&&r.get(t)?.has(e)===!0),w=(e,t,n,r)=>e.type===`Identifier`?e.name===`theme`&&r.size>0||C(e.name,t,n):b(e,r),T=e=>{if(e.computed!==!0&&e.property.type===`Identifier`)return e.property.name;if(e.computed===!0&&e.property.type===`StringLiteral`)return e.property.value};function E(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let i;try{i=p(e,t)}catch(n){return m(e,t,n)}if(i===null)return{text:e,hits:[],findings:[]};let o=new Set;f(i,e=>{if(!(e.type!==`ImportDeclaration`||!e.source.value.startsWith(`@webority/`)))for(let t of e.specifiers){if(t.type!==`ImportSpecifier`)continue;let e=t.imported.type===`StringLiteral`?t.imported.value:t.imported.name;a.has(e)&&o.add(t.local.name)}});let s=S(i,o),d=n.filter(e=>e.kind===`path`||e.kind===`prefix`||e.kind===`gone`).sort((e,t)=>g(t.from).length-g(e.from).length),b=n.filter(e=>e.kind===`kebab`),x=[],C=[],E=[],D=new Set,O=(e,n)=>{let r=`${e}:${n}`;D.has(r)||(D.add(r),E.push({file:t,line:e,path:n,message:u}))},k=(e,n)=>{let i=[],a=e;for(;r.has(a.type);)i.unshift(a),a=a.object;if(!w(a,n,s,o))return;let l=[];for(let e of i){let t=T(e);if(t===void 0)break;l.push(t)}let u=l.length;if(u===0)return;let f=[...l];for(let e of d){let n=g(e.from),r=e.kind===`prefix`&&e.from.endsWith(`.`);if(!(u<n.length||r&&u===n.length)&&n.every((e,t)=>l[t]===e)){if(e.kind===`gone`){E.push({file:t,line:i[n.length-1].property.loc.start.line,path:n.join(`.`),message:`no longer exists; ${e.hint}`});return}if(e.kind===`path`||e.kind===`prefix`){f=[...g(e.to),...l.slice(n.length)];break}}}for(let e of b){let t=e.under.split(`.`),n=t.length;if(f.length<=n||!t.every((e,t)=>f[t]===e))continue;let r=f[n];Object.hasOwn(e.names,r)&&(f[n]=e.names[r]);for(let e=n+1;e<f.length;e++)/[A-Z]/.test(f[e])&&(f[e]=f[e].replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase())}if(_(f,l))return;let p=f.map((e,t)=>{let n=i[t]?.optional===!0;return c.test(e)?`${n?`?.`:`.`}${e}`:`${n?`?.`:``}["${e}"]`}).join(``);x.push({start:a.end,end:i[u-1].end,text:p}),C.push({line:i[0].property.loc.start.line,from:l.join(`.`),to:f.join(`.`)})};return f(i,(e,t)=>{r.has(e.type)&&!y(e,t)&&k(e,t),e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&l.has(e.name.name)&&O(e.loc.start.line,e.name.name),e.type===`Identifier`&&e.name===`ThemeOverrides`&&O(e.loc.start.line,e.name)}),C.sort((e,t)=>e.line-t.line||v(e.from,t.from)),E.sort((e,t)=>e.line-t.line||v(e.path,t.path)),{text:h(e,x,t),hits:C,findings:E}}var D=(e,t,n)=>{if(e.type===`JSXIdentifier`)return t.has(e.name);if(e.type===`JSXMemberExpression`){let t=e;for(;t.type===`JSXMemberExpression`;)t=t.object;return t.type===`JSXIdentifier`&&n.has(t.name)}return!1},O=e=>{if(e?.type===`StringLiteral`)return e;if(e?.type===`JSXExpressionContainer`&&e.expression.type===`StringLiteral`)return e.expression};function k(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let r;try{r=p(e,t)}catch(n){return m(e,t,n)}if(r===null)return{text:e,hits:[],findings:[]};let i=[],a=[];for(let t of n){let n=new Set,o=new Set;f(r,e=>{if(!(e.type!==`ImportDeclaration`||e.source.value!==t.package))for(let t of e.specifiers)t.type===`ImportNamespaceSpecifier`?o.add(t.local.name):n.add(t.local.name)});let s=new Set(t.props);f(r,r=>{if(!(r.type!==`JSXOpeningElement`||!D(r.name,n,o)))for(let n of r.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||!s.has(n.name.name))continue;let r=O(n.value);if(r===void 0||r.value!==t.from)continue;let o=e[r.start];i.push({start:r.start,end:r.end,text:`${o}${t.to}${o}`}),a.push({line:r.loc.start.line,from:`${n.name.name}="${t.from}"`,to:`${n.name.name}="${t.to}"`})}})}return a.sort((e,t)=>e.line-t.line||v(e.from,t.from)),{text:h(e,i,t),hits:a,findings:[]}}var A=(e,t)=>{let n=new Map,r=new Set;return f(e,e=>{if(!(e.type!==`ImportDeclaration`||e.source.value!==t))for(let t of e.specifiers)if(t.type===`ImportSpecifier`){let e=t.imported.type===`StringLiteral`?t.imported.value:t.imported.name;n.set(t.local.name,e)}else t.type===`ImportNamespaceSpecifier`&&r.add(t.local.name)}),{named:n,namespaces:r}},j=(e,t)=>{if(e.type===`JSXIdentifier`)return t.named.get(e.name);if(e.type===`JSXMemberExpression`&&e.object.type===`JSXIdentifier`&&t.namespaces.has(e.object.name))return e.property.name};function M(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let r;try{r=p(e,t)}catch(n){return m(e,t,n)}if(r===null)return{text:e,hits:[],findings:[]};let i=[],a=[],o=[];for(let s of n){let n=A(r,s.package);f(r,r=>{if(r.type!==`JSXOpeningElement`)return;let c=j(r.name,n);if(s.components.includes(c))for(let n of r.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==s.prop)continue;let r=n.value,l=n.loc.start.line,u=r?.type===`JSXExpressionContainer`?r.expression:void 0,d=r===null?!0:u?.type===`BooleanLiteral`?u.value:void 0,f;if(d!==void 0)f=`${s.prop}="${d?s.true:s.false}"`;else if(O(r)!==void 0)continue;else{o.push({file:t,line:l,path:`${c}.${s.prop}`,message:`${s.prop} takes a named value such as "${s.true}" or "${s.false}" now, not a boolean; set it by hand`});continue}i.push({start:n.start,end:n.end,text:f}),a.push({line:l,from:e.slice(n.start,n.end),to:f})}})}return a.sort((e,t)=>e.line-t.line||v(e.from,t.from)),o.sort((e,t)=>e.line-t.line||v(e.path,t.path)),{text:h(e,i,t),hits:a,findings:o}}function N(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let r;try{r=p(e,t)}catch(n){return m(e,t,n)}if(r===null)return{text:e,hits:[],findings:[]};let i=t=>e.slice(t.start,t.end),a=new Set([`ObjectExpression`,`Identifier`,`MemberExpression`,`OptionalMemberExpression`]),o=new Set([`SequenceExpression`,`AssignmentExpression`,`ConditionalExpression`,`YieldExpression`]),s=e=>{if(e?.type===`LogicalExpression`&&e.operator===`&&`)return{test:e.left,consequent:e.right};let t=e?.alternate;if(e?.type===`ConditionalExpression`&&(t.type===`NullLiteral`||t.type===`Identifier`&&t.name===`undefined`||t.type===`BooleanLiteral`&&t.value===!1))return{test:e.test,consequent:e.consequent}},c=e=>o.has(e.test.type)?`(${i(e.test)})`:i(e.test),l=[],u=[],d=[];for(let e of n){let n=A(r,e.package);f(r,r=>{if(r.type!==`JSXOpeningElement`)return;let o=j(r.name,n);if(!e.components.includes(o))return;let f=r.attributes.some(t=>t.type===`JSXAttribute`&&t.name.type===`JSXIdentifier`&&t.name.name===e.into);for(let n of r.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==e.prop)continue;let r=n.value,p=n.loc.start.line;if(O(r)!==void 0)continue;let m=`${o}.${e.prop}`;if(f){d.push({file:t,line:p,path:m,message:`already sets ${e.into}; set ${e.prop} to "${e.on}" or "${e.off}" by hand`});continue}let h=r?.type===`JSXExpressionContainer`?r.expression:void 0,g=r===null?!0:h?.type===`BooleanLiteral`?h.value:void 0,_=s(h),v;if(g!==void 0)v=`${e.prop}="${g?e.on:e.off}"`;else if(a.has(h?.type))v=`${e.prop}="${e.on}" ${e.into}={${i(h)}}`;else if(_!==void 0&&_.consequent.type===`BooleanLiteral`&&_.consequent.value===!0)v=`${e.prop}={${c(_)} ? "${e.on}" : "${e.off}"}`;else if(_!==void 0&&a.has(_.consequent.type))v=`${e.prop}={${c(_)} ? "${e.on}" : "${e.off}"} ${e.into}={${i(_.consequent)}}`;else{d.push({file:t,line:p,path:m,message:`${e.prop} takes "${e.on}" or "${e.off}" now, and its settings object moves to ${e.into}; set both by hand`});continue}l.push({start:n.start,end:n.end,text:v}),u.push({line:p,from:i(n),to:v})}})}return u.sort((e,t)=>e.line-t.line||v(e.from,t.from)),d.sort((e,t)=>e.line-t.line||v(e.path,t.path)),{text:h(e,l,t),hits:u,findings:d}}export{N as applyPropSplits,M as applyPropValues,k as applyProps,E as applyThemeReads};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/tokens",
3
- "version": "0.100.0",
3
+ "version": "0.101.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",
@@ -4,11 +4,29 @@
4
4
  "title": "Webority design map",
5
5
  "description": "The machine contract of a repo's .webority/design.json. design-map.md stays its prose; webority check validates against this file, then checks that every head names a listed brand, that brand names are unique, and that every brand but the library one has a head.",
6
6
  "type": "object",
7
- "required": ["schemaVersion", "tokens", "color"],
7
+ "required": ["schemaVersion", "color"],
8
8
  "properties": {
9
9
  "$schema": { "type": "string" },
10
10
  "$comment": { "type": "string" },
11
11
  "schemaVersion": { "const": 1 },
12
+ "source": {
13
+ "description": "Where the product's screens are designed.",
14
+ "enum": ["canvas", "mockups", "figma", "none"]
15
+ },
16
+ "canvas": {
17
+ "description": "The Webority Canvas binding: the project, one file id per surface, and the component kit.",
18
+ "type": "object",
19
+ "required": ["project", "files", "kit"],
20
+ "properties": {
21
+ "project": { "type": "string" },
22
+ "files": {
23
+ "type": "object",
24
+ "additionalProperties": { "type": "string" }
25
+ },
26
+ "kit": { "type": "string" }
27
+ },
28
+ "additionalProperties": false
29
+ },
12
30
  "brandAuthority": { "type": "object" },
13
31
  "type": { "type": "object" },
14
32
  "color": {