@webority/tokens 0.101.1 → 0.101.3
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 +1 -1
- package/dist/brand.js +2 -2
- package/dist/canvas/webority-phone.json +1 -1
- package/dist/canvas/webority-web-390.json +1 -1
- package/dist/canvas/webority-web.json +1 -1
- package/dist/emit/email.js +1 -1
- package/dist/meanings.json +1 -1
- package/dist/outputs.d.ts +5 -2
- package/package.json +1 -1
package/dist/brand.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface LibrarySources {
|
|
|
10
10
|
export interface BrandEmailGroup {
|
|
11
11
|
/** <email colour role>: { $type: "color", $value: "#RRGGBB" | "{color.<meaning>}", $extensions.com.webority.dark?: "#RRGGBB" | "{color.<meaning>}" } */
|
|
12
12
|
color?: Record<string, object>;
|
|
13
|
-
/** <email type role>: { $value: { size, lineHeight, phoneSize, phoneLineHeight } } in whole px. */
|
|
13
|
+
/** <email type role>: { $value: { size, lineHeight, phoneSize, phoneLineHeight, narrowSize?, narrowLineHeight? } } in whole px; the narrow pair is both or neither. */
|
|
14
14
|
type?: Record<string, object>;
|
|
15
15
|
/** <email space key>: { $type: "dimension", $value: { value, unit: "px" } }, or for a padding key { $value: "22px 24px" }. */
|
|
16
16
|
space?: Record<string, object>;
|
package/dist/brand.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{EMAIL_COLOR_ROLES as e,EMAIL_PADDING_PATTERN as t,EMAIL_PADDING_ROLES as n,EMAIL_SHAPE as r,EMAIL_SPACE as i,EMAIL_TYPE_ROLES as a}from"./emit/email.js";import{readFileSync as o}from"node:fs";var s=Object.freeze({css:`brand.css`,bootstrap:`_brand-variables.scss`,web:`webority-web.json`,web390:`webority-web-390.json`,phoneTheme:`webority-phone.json`,phone:`brand.phone.js`,email:`email.json`}),c=`generated`,l=/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,u=[`palette`,`color`,`effect`,`font`,`radius`],d=[`space`,`text`,`shadow`,`section`,`component`,`email`],f=[`radius`,`padding`],p=[`size`,`lineHeight`,`phoneSize`,`phoneLineHeight`],m=/^(#[0-9a-fA-F]{6}|\{color\.[a-z0-9-]+\})$/;function
|
|
2
|
-
`));let O={};for(let e of[`color`,`effect`])for(let{path:t,node:n}of
|
|
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=[`narrowSize`,`narrowLineHeight`],h=/^(#[0-9a-fA-F]{6}|\{color\.[a-z0-9-]+\})$/;function g(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _(e){return g(e)&&Object.hasOwn(e,`$value`)}function v(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}`;_(a)?n.push({path:o,node:a}):g(a)&&r(a,o)}};return r(e,t),n}function y(e,t){let n=e;for(let e of t.split(`.`)){if(!g(n)||!Object.hasOwn(n,e))return!1;n=n[e]}return _(n)}function b(e){let t=e?.$extensions?.[`com.webority`];return g(t)?t:{}}function x(e){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e)&&!/^[0-9]+$/.test(e)}function S(e){return typeof e==`string`&&h.test(e)}function C(e){return g(e)&&Number.isInteger(e.value)&&e.value>=0&&e.unit===`px`}function w(e,t){return e===`space`?n.has(t):e===`button`&&t===`padding`}function T(e,n,r,i,a){let o=b(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`)S(r.$value)||a(i,`$value is not a colour`,`Write "#RRGGBB" or a reference such as "{color.primary}"`),Object.hasOwn(o,`dark`)&&!S(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,t=g(e)?Object.keys(e):[],n=t.includes(`narrowSize`)||t.includes(`narrowLineHeight`)?[...p,...m]:p;g(e)&&t.length===n.length&&n.every(t=>Number.isInteger(e[t])&&e[t]>0)||a(i,`$value is not { size, lineHeight, phoneSize, phoneLineHeight } (optionally narrowSize, narrowLineHeight) in whole px`,`Write it as { "size": 16, "lineHeight": 24, "phoneSize": 15, "phoneLineHeight": 22 }`)}else w(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`):C(r.$value)||a(i,`$value is not { value, unit }`,`Write it as { "value": 12, "unit": "px" }`)}function E(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(!g(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(!_(a)){n(i,`is not a token`,`Give it a $value`);continue}T(e,r,a,i,n)}}}function D(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(!g(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=b(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={},h=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(!g(r[e])){a(e,`is not a group`,`Write it as an object of tokens`);continue}if(e===`email`){h=r[e];continue}m[e]=r[e]}for(let[e,t]of Object.entries(m))for(let{path:n,node:r}of v(t,e)){let t=b(r);for(let r of Object.keys(t))r!==`platforms`&&r!==`dark`&&!(r===`faces`&&e===`font`)&&a(n,`$extensions.com.webority.${r} is not allowed on a token`,`Remove it`);if(Object.hasOwn(t,`platforms`)){let e=t.platforms;Array.isArray(e)&&e.length>0&&e.every(e=>e===`web`||e===`phone`)||a(n,`$extensions.com.webority.platforms is not a list of web and phone`,`Write it as ["phone"], ["web"] or both`)}Object.hasOwn(t,`dark`)&&e!==`color`&&e!==`effect`&&a(n,`$extensions.com.webority.dark applies to colour and effect tokens only`,`Remove it`)}for(let{path:e,node:t}of v(m.palette??{},`palette`))e.split(`.`).slice(1).every(x)||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=b(r),s=y(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?y(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`):(x(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(!_(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=>_(t.scale.font[e]));for(let{path:e,node:n}of v(m.font??{},`font`)){y(t.scale,e)||a(e,`is not a fleet font`,`Use one of ${C.join(`, `)}`);let r=n.$value;if((!Array.isArray(r)||r.length===0||!r.every(e=>typeof e==`string`))&&a(e,`$value is not a list of font family names`,`Write it as ["Webority Sans", "system-ui", "sans-serif"]`),Object.hasOwn(b(n),`faces`)){let t=b(n).faces,r=[`normal`,`medium`,`semibold`,`bold`];g(t)&&Object.keys(t).length>0&&Object.keys(t).every(e=>r.includes(e))&&Object.values(t).every(e=>typeof e==`string`&&e!==``)||a(e,`faces is not a map of weight to font file name`,`Write it as { "normal": "AcmeSans-Regular", "semibold": "AcmeSans-SemiBold" }`)}}let w=Object.keys(t.scale.radius??{}).filter(e=>_(t.scale.radius[e]));for(let{path:e,node:n}of v(m.radius??{},`radius`)){y(t.scale,e)||a(e,`is not on the radius scale`,`Use one of ${w.join(`, `)}`);let r=n.$value;(!(g(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" }`)}h!==null&&E(h,a);let T=structuredClone(r);delete T.$extensions,delete T.$description,delete T.email;for(let e of[`color`,`effect`])for(let{node:t}of v(T[e]??{},e))Object.hasOwn(b(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=>y(T,e)||y(t.palette,e)||y(t.scale,e)||y(t.meaning,e);for(let e of Object.keys(m))for(let{path:t,node:n}of v(m[e],e)){let e=[n.$value,b(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 v(m[e]??{},e)){let r=b(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:T,dark:O,email:h}}export{s as BRAND_OUTPUT_FILES,c as HEAD_FOLDER,D as loadBrand};
|
package/dist/emit/email.js
CHANGED
|
@@ -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`},"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(`
|
|
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,narrowSize:c,narrowLineHeight:l}=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]=c===void 0?{size:e,lineHeight:r,phoneSize:a,phoneLineHeight:o}:{size:e,lineHeight:r,phoneSize:a,phoneLineHeight:o,narrowSize:c,narrowLineHeight:l}}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
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};
|
package/dist/meanings.json
CHANGED
package/dist/outputs.d.ts
CHANGED
|
@@ -132,8 +132,11 @@ export interface EmailThemeTokensV1 {
|
|
|
132
132
|
colors: Record<EmailColorRoleKey, Record<Mode, string>>;
|
|
133
133
|
/** CSS font-family lists; a name with spaces is in single quotes. */
|
|
134
134
|
fonts: { body: string; display: string; mono: string };
|
|
135
|
-
/** Whole pixels: size and line height at 1440, phone values at 390. */
|
|
136
|
-
type: Record<
|
|
135
|
+
/** Whole pixels: size and line height at 1440, phone values at 390, and an optional narrow-phone pair a brand sets. */
|
|
136
|
+
type: Record<
|
|
137
|
+
EmailTypeRoleKey,
|
|
138
|
+
{ size: number; lineHeight: number; phoneSize: number; phoneLineHeight: number; narrowSize?: number; narrowLineHeight?: number }
|
|
139
|
+
>;
|
|
137
140
|
/** Px at 1440; a padding entry is a CSS shorthand of px values, such as "24px 16px". */
|
|
138
141
|
space: Record<EmailSpaceKey, number | string>;
|
|
139
142
|
/** Px at 1440. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/tokens",
|
|
3
|
-
"version": "0.101.
|
|
3
|
+
"version": "0.101.3",
|
|
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",
|