@webority/tokens 0.122.0 → 0.125.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.
Files changed (52) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +1 -1
  2. package/dist/brand.js +1 -1
  3. package/dist/build.js +2 -2
  4. package/dist/canvas/webority-phone.json +1 -1
  5. package/dist/canvas/webority-web-390.json +1 -1
  6. package/dist/canvas/webority-web.json +1 -1
  7. package/dist/check.js +2 -2
  8. package/dist/cli.d.ts +7 -3
  9. package/dist/cli.js +4 -2
  10. package/dist/emit/canvas.js +1 -1
  11. package/dist/emit/email.js +1 -1
  12. package/dist/emit/web.js +10 -10
  13. package/dist/index.js +1 -1
  14. package/dist/meanings.json +1 -1
  15. package/dist/model/index.js +1 -1
  16. package/dist/model/load.js +1 -1
  17. package/dist/model/references.js +1 -1
  18. package/dist/model/resolve.js +1 -1
  19. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js +1 -1
  20. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/index.js +2 -2
  21. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/index.js +1 -1
  22. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/util.js +1 -1
  23. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/boolSchema.js +1 -1
  24. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/dataType.js +1 -1
  25. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/index.js +1 -1
  26. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/keyword.js +1 -1
  27. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/core.js +1 -1
  28. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +1 -1
  29. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +1 -1
  30. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/index.js +1 -1
  31. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items.js +1 -1
  32. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items2020.js +1 -1
  33. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +1 -1
  34. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/properties.js +1 -1
  35. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/ref.js +1 -1
  36. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/discriminator/index.js +1 -1
  37. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/recursiveAnchor.js +1 -1
  38. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js +1 -1
  39. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/pattern.js +1 -1
  40. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/required.js +1 -1
  41. package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +1 -1
  42. package/dist/node_modules/.pnpm/fast-uri@3.1.9/node_modules/fast-uri/index.js +1 -1
  43. package/dist/node_modules/.pnpm/fast-uri@3.1.9/node_modules/fast-uri/lib/schemes.js +1 -1
  44. package/dist/node_modules/.pnpm/fast-uri@3.1.9/node_modules/fast-uri/lib/utils.js +1 -1
  45. package/dist/source/mode.dark.tokens.json +65 -0
  46. package/dist/upgrade/components.js +2 -2
  47. package/dist/upgrade/index.js +2 -2
  48. package/dist/upgrade/razorAttributes.js +2 -2
  49. package/dist/upgrade/razorTags.js +2 -2
  50. package/dist/upgrade/tagScan.js +1 -0
  51. package/dist/upgrade/themeReads.js +1 -1
  52. package/package.json +1 -1
@@ -1 +1 @@
1
- import"node:module";var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},s=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),c=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},l=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},u=(n,r,a)=>(a=n==null?{}:e(i(n)),l(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),d=e=>a.call(e,`module.exports`)?e[`module.exports`]:l(t({},`__esModule`,{value:!0}),e);export{s as __commonJSMin,o as __esmMin,c as __exportAll,d as __toCommonJS,u as __toESM};
1
+ import"node:module";var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},s=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),c=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},l=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},u=(n,r,o)=>(o=n==null?{}:e(i(n)),l(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n)),d=e=>a.call(e,`module.exports`)?e[`module.exports`]:l(t({},`__esModule`,{value:!0}),e);export{s as __commonJSMin,o as __esmMin,c as __exportAll,d as __toCommonJS,u as __toESM};
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=[`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 acme`);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(`
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(`, `)}`);else if(!g(t[e]))n(`email.${e}`,`is not a group`,`Write it as an object of tokens`);else 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];_(a)?T(e,r,a,i,n):n(i,`is not a token`,`Give it a $value`)}}}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 acme`);let p=f?n[s.deviation].groups:[],m={},h=null;for(let e of Object.keys(r))e.startsWith(`$`)||(!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`):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`):g(r[e])?e===`email`?h=r[e]:m[e]=r[e]:a(e,`is not a group`,`Write it as an object of tokens`));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))n.startsWith(`$`)||(_(t[n])?S(e,n,t[n]):a(`${e}.${n}`,`is not a token`,`Give it a $value`))}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
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/build.js CHANGED
@@ -1,5 +1,5 @@
1
- import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{emitEmail as t}from"./emit/email.js";import{BRAND_OUTPUT_FILES as n,HEAD_FOLDER as r,loadBrand as i}from"./brand.js";import{require__2020 as a}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import o from"./canvas-renames.js";import s from"./deviations.js";import{emitCanvas as c}from"./emit/canvas.js";import{emitMeanings as l}from"./emit/meanings.js";import{emitPhoneBrand as u,emitPhoneTheme as d,phoneSets as f}from"./emit/phone.js";import{emitWeb as p}from"./emit/web.js";import{phonePairLayer as m}from"./model/contrast.js";import{loadModel as h}from"./model/index.js";import{mkdir as g,readFile as _,writeFile as v}from"node:fs/promises";import y from"node:path";var b=e(a(),1),x=new URL(`../schema/design-map.schema.json`,import.meta.url),S=new URL(`../package.json`,import.meta.url),C={palette:`palette.tokens.json`,scale:`scale.tokens.json`,meaning:`meaning.tokens.json`,modeDark:`mode.dark.tokens.json`},w=/^.+: \S+: .+\. .+$/;async function T(e){let r=y.resolve(e.root??process.cwd()),a=e.check===!0,{version:C}=JSON.parse(await _(S,`utf8`)),T=[],k=[],A=async(e,t)=>{if(a){let n=null;try{n=await _(e,`utf8`)}catch(e){if(e.code!==`ENOENT`)throw e}n!==t&&k.push(e);return}await g(y.dirname(e),{recursive:!0}),await v(e,t,`utf8`),T.push(e)};if(e.library===!0){if(e.brand!==void 0)throw Error(`brand: --brand: not allowed with --library. Remove it.`);if(!e.out)throw Error(`brand: --out: required with --library. Pass --out <dir>.`);let t=y.resolve(r,e.out),i=await h(),a=c(i),s=[[y.join(t,`canvas`,n.web),E(a.web)],[y.join(t,`canvas`,n.web390),E(a.web390)],[y.join(t,`canvas`,n.phoneTheme),E(a.phone)],[y.join(t,`meanings.json`),E(l(i))],[y.join(t,`canvas`,`renames.json`),E(o)]];if(e.web){let t=p(i),n=y.resolve(r,e.web);s.push([n,t.tokens]),s.push([y.join(y.dirname(n),`_bootstrap.generated.scss`),t.bootstrap])}if(e.phone){let t=d({light:f(i,`light`),dark:f(i,`dark`)});s.push([y.resolve(r,e.phone),t.contents])}for(let[e,t]of s)await A(e,t);return{written:T,stale:k}}let j=y.join(r,`.webority`,`design.json`),M;try{M=await _(j,`utf8`)}catch(e){throw e.code===`ENOENT`?Error(`${j}: file missing. Run from the repo root or create the design map.`):e}let N;try{N=JSON.parse(M)}catch(e){throw Error(`${j}: /: ${e.message}. Fix the design map.`)}let P=JSON.parse(await _(x,`utf8`)),F=new b.Ajv2020({allErrors:!0,strict:!1}).compile(P);if(!F(N))throw Error(F.errors.map(e=>`${j}: ${e.instancePath||`/`}: ${e.message}. Fix the design map.`).join(`
1
+ import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{require__2020 as t}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{BRAND_OUTPUT_FILES as n,HEAD_FOLDER as r,loadBrand as i}from"./brand.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{phonePairLayer as m}from"./model/contrast.js";import{loadModel as h}from"./model/index.js";import{mkdir as g,readFile as _,writeFile as v}from"node:fs/promises";import y from"node:path";var b=e(t(),1),x=new URL(`../schema/design-map.schema.json`,import.meta.url),S=new URL(`../package.json`,import.meta.url),C={palette:`palette.tokens.json`,scale:`scale.tokens.json`,meaning:`meaning.tokens.json`,modeDark:`mode.dark.tokens.json`},w=/^.+: \S+: .+\. .+$/;async function T(e){let t=y.resolve(e.root??process.cwd()),r=e.check===!0,{version:C}=JSON.parse(await _(S,`utf8`)),T=[],k=[],A=async(e,t)=>{if(r){let n=null;try{n=await _(e,`utf8`)}catch(e){if(e.code!==`ENOENT`)throw e}n!==t&&k.push(e)}else await g(y.dirname(e),{recursive:!0}),await v(e,t,`utf8`),T.push(e)};if(e.library===!0){if(e.brand!==void 0)throw Error(`brand: --brand: not allowed with --library. Remove it.`);if(!e.out)throw Error(`brand: --out: required with --library. Pass --out <dir>.`);let r=y.resolve(t,e.out),i=await h(),o=s(i),c=[[y.join(r,`canvas`,n.web),E(o.web)],[y.join(r,`canvas`,n.web390),E(o.web390)],[y.join(r,`canvas`,n.phoneTheme),E(o.phone)],[y.join(r,`meanings.json`),E(l(i))],[y.join(r,`canvas`,`renames.json`),E(a)]];if(e.web){let n=p(i),r=y.resolve(t,e.web);c.push([r,n.tokens]),c.push([y.join(y.dirname(r),`_bootstrap.generated.scss`),n.bootstrap])}if(e.phone){let n={light:f(i,`light`),dark:f(i,`dark`)},r=d(n);c.push([y.resolve(t,e.phone),r.contents])}for(let[e,t]of c)await A(e,t);return{written:T,stale:k}}let j=y.join(t,`.webority`,`design.json`),M;try{M=await _(j,`utf8`)}catch(e){throw e.code===`ENOENT`?Error(`${j}: file missing. Run from the repo root or create the design map.`):e}let N;try{N=JSON.parse(M)}catch(e){throw Error(`${j}: /: ${e.message}. Fix the design map.`)}let P=JSON.parse(await _(x,`utf8`)),F=new b.Ajv2020({allErrors:!0,strict:!1}).compile(P);if(!F(N))throw Error(F.errors.map(e=>`${j}: ${e.instancePath||`/`}: ${e.message}. Fix the design map.`).join(`
2
2
  `));if(N.tokens===void 0)throw Error(`${j}: /tokens: missing. Add tokens.brands to .webority/design.json.`);let I=N.tokens.brands,L=N.tokens.heads??[];if((e.brand!==void 0||e.out!==void 0)&&I.length>1)throw Error(`brand: --brand/--out: the repo has ${I.length} brands. Remove the flag to build every brand.`);let R=[];if(I.forEach((e,t)=>{e.source===`library`&&R.push(`${j}: tokens.brands[${t}].source: "library" is built with --library. Run webority brand --library --out <dir>.`)}),L.forEach((e,t)=>{I.some(t=>t.name===e.brand)||R.push(`${j}: tokens.heads[${t}].brand: no brand named ${e.brand}. Add it to tokens.brands.`)}),R.length>0)throw Error(R.join(`
3
- `));let z=await O(),B=await h(),V={light:f(B,`light`),dark:f(B,`dark`)},H=[];for(let a of I){let o=I.length===1&&e.brand!==void 0?e.brand:a.source,l=I.length===1&&e.out!==void 0?e.out:a.export,d=y.resolve(r,o);try{let e=i(d,z,s),o=await h({brand:e}),g=m(o,B),_=Object.keys(g.light).length+Object.keys(g.dark).length>0?await h({brand:{...e,phone:g}}):o,v=c(_),b=p(_,{library:B}),x=u(V,{light:f(_,`light`),dark:f(_,`dark`)},{package:`@webority/tokens`,version:C,brand:e.name}),S=E(t(v.web,v.web390,e.email)),w={css:b.css,phone:x.contents,email:S},T=y.resolve(r,l),O=[[y.join(T,n.css),b.css],[y.join(T,n.bootstrap),b.variables],[y.join(T,n.web),E(v.web)],[y.join(T,n.web390),E(v.web390)],[y.join(T,n.phoneTheme),E(v.phone)],[y.join(T,n.phone),x.contents],[y.join(T,n.email),S]];H.push(...O);for(let e of L)e.brand===a.name&&H.push(D(r,e,w))}catch(e){for(let t of String(e?.message??e).split(`
3
+ `));let z=await O(),B=await h(),V={light:f(B,`light`),dark:f(B,`dark`)},H=[];for(let r of I){let a=I.length===1&&e.brand!==void 0?e.brand:r.source,l=I.length===1&&e.out!==void 0?e.out:r.export,d=y.resolve(t,a);try{let e=i(d,z,o),a=await h({brand:e}),g=m(a,B),_=Object.keys(g.light).length+Object.keys(g.dark).length>0?await h({brand:{...e,phone:g}}):a,v=s(_),b=p(_,{library:B}),x={light:f(_,`light`),dark:f(_,`dark`)},S=u(V,x,{package:`@webority/tokens`,version:C,brand:e.name}),w=E(c(v.web,v.web390,e.email)),T={css:b.css,phone:S.contents,email:w},O=y.resolve(t,l),k=[[y.join(O,n.css),b.css],[y.join(O,n.bootstrap),b.variables],[y.join(O,n.web),E(v.web)],[y.join(O,n.web390),E(v.web390)],[y.join(O,n.phoneTheme),E(v.phone)],[y.join(O,n.phone),S.contents],[y.join(O,n.email),w]];H.push(...k);for(let e of L)e.brand===r.name&&H.push(D(t,e,T))}catch(e){for(let t of String(e?.message??e).split(`
4
4
  `))t.length!==0&&R.push(w.test(t)?t:`${d}: -: ${t}. Fix the source.`)}}if(R.length>0)throw Error(R.join(`
5
5
  `));for(let[e,t]of H)await A(e,t);return{written:T,stale:k}}function E(e){return`${JSON.stringify(e,null,4)}\n`}function D(e,t,i){let a=y.resolve(e,t.path);return t.kind===`razor`?[y.join(a,`wwwroot`,r,n.css),i.css]:t.kind===`spa`?[y.join(a,`src`,r,n.css),i.css]:t.kind===`phone`?[y.join(a,r,n.phone),i.phone]:[y.join(a,r,n.email),i.email]}async function O(){let e={};for(let[t,n]of Object.entries(C))e[t]=JSON.parse(await _(new URL(`./source/${n}`,import.meta.url),`utf8`));return e}export{T as brand};
@@ -2,7 +2,7 @@
2
2
  "format": "webority-theme-tokens/2",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.122.0",
5
+ "version": "0.125.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.122.0",
5
+ "version": "0.125.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.122.0",
5
+ "version": "0.125.0",
6
6
  "brand": null,
7
7
  "platform": "web",
8
8
  "width": 1440
package/dist/check.js CHANGED
@@ -1,4 +1,4 @@
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
- `))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){return T(l(`corepack pnpm exec webority-repo-checks --json`,{cwd:e,encoding:`utf8`,shell:!0,maxBuffer:64*1024*1024}).stdout??``)}function T(e){let t=e.split(`
1
+ import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{require__2020 as t}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{BRAND_OUTPUT_FILES as n}from"./brand.js";import{brand as r}from"./build.js";import{loadModel as i}from"./model/index.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(t(),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=r,repoChecks:a=w,loadModel:o=i}=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,t,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(t,i));if(o!==null)for(let[t,s]of Object.entries(e.color?.roles??{}))o.has(s)||a(`color.roles.${t}: ${s} is not a colour of brand ${r.name}. Use a name from ${i}/${n.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 t=new Set,r=!1;for(let i of[n.web,n.phoneTheme]){let n;try{n=JSON.parse(a(s(e,i),`utf8`))}catch{continue}r=!0;for(let e of Object.keys(n?.colors?.light??{}))t.add(e)}return r?t: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
+ `))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){return T(l(`corepack pnpm exec webority-repo-checks --json`,{cwd:e,encoding:`utf8`,shell:!0,maxBuffer:67108864}).stdout??``)}function T(e){let t=e.split(`
3
3
  `),n=t.findIndex(e=>e.startsWith(`{`)),r;try{if(n===-1)throw Error(`no JSON line`);r=JSON.parse(t.slice(n).join(`
4
4
  `))}catch{throw Error(`repo-checks printed no JSON`)}if(!Array.isArray(r?.new))throw Error(`repo-checks printed no new array`);return r}export{m as check,T as parseRepoChecksOutput};
package/dist/cli.d.ts CHANGED
@@ -31,15 +31,19 @@ export interface BrandResult {
31
31
  }
32
32
 
33
33
  /**
34
- * webority upgrade <version> [--dry-run] [--path <p>]...
34
+ * webority upgrade <version> [--dry-run] [--app <folder>] [--path <p>]...
35
35
  *
36
36
  * With no --path, moves every pin in the lockstep list to <version>, installs, applies every rename table from the
37
- * installed version up to <version> in order, then runs brand. With --path (repeatable), applies the tables to those
38
- * paths only, with no pin move, install or brand run; webority-ui uses it on itself.
37
+ * installed version up to <version> in order, then runs brand. With --app, the same run covers one app folder inside
38
+ * the repo: the design map is read from the repo root, and the pins, install (pnpm or npm, by the folder's lockfile)
39
+ * and tables are the app's. With --path (repeatable), applies the tables to those paths only, with no pin move,
40
+ * install or brand run; webority-ui uses it on itself.
39
41
  */
40
42
  export interface UpgradeOptions {
41
43
  version: string;
42
44
  dryRun?: boolean;
45
+ /** An app folder inside the repo, relative to root. */
46
+ app?: string;
43
47
  paths?: string[];
44
48
  /** Defaults to process.cwd(). */
45
49
  root?: string;
package/dist/cli.js CHANGED
@@ -1,2 +1,4 @@
1
- import{brand as e}from"./build.js";import{check as t}from"./check.js";import{upgrade as n}from"./upgrade/index.js";var r=[`Usage: webority <command>`,` brand [--brand <file>] [--library] [--out <dir>] [--web <scss>] [--phone <ts>] [--check]`,` upgrade <version> [--dry-run] [--path <p>]...`,` check`].join(`
2
- `),i=[`brand`,`upgrade`,`check`],a=[`generated`,`design-map`,`repo-checks`],o={"--brand":`brand`,"--out":`out`,"--web":`web`,"--phone":`phone`},s=class extends Error{};function c(e){return console.error(e),console.error(r),2}function l(e){if(!(e instanceof Error))throw e;return console.error(e.message),1}function u(e,t,n){let r=[],i={},a=new Set;for(let o=0;o<e.length;o+=1){let c=e[o];if(t.includes(c)){let t=e[o+1];if(t===void 0||t.startsWith(`--`))throw new s(`${c} needs a value.`);i[c]=[...i[c]??[],t],o+=1}else if(n.includes(c))a.add(c);else if(c.startsWith(`--`))throw new s(`Unknown flag ${c}.`);else r.push(c)}return{positionals:r,values:i,flags:a}}function d(e,t){if(e===`brand`){let{positionals:e,values:n,flags:r}=u(t,Object.keys(o),[`--library`,`--check`]);if(e.length>0)throw new s(`brand takes no argument, got ${e[0]}.`);let i={};for(let[e,t]of Object.entries(o))n[e]!==void 0&&(i[t]=n[e].at(-1));return r.has(`--library`)&&(i.library=!0),r.has(`--check`)&&(i.check=!0),{kind:`brand`,options:i}}if(e===`upgrade`){let{positionals:e,values:n,flags:r}=u(t,[`--path`],[`--dry-run`]);if(e.length===0)throw new s(`upgrade needs a <version>.`);if(e.length>1)throw new s(`Unexpected argument ${e[1]}.`);let i={version:e[0]};return r.has(`--dry-run`)&&(i.dryRun=!0),n[`--path`]!==void 0&&(i.paths=n[`--path`]),{kind:`upgrade`,options:i}}if(t.length>0)throw new s(`check takes no arguments, got ${t[0]}.`);return{kind:`check`}}async function f(o,u={brand:e,upgrade:n,check:t}){if(o.includes(`--help`)||o.includes(`-h`))return console.log(r),0;if(o.length===0)return console.error(r),2;let[f,...p]=o;if(!i.includes(f))return c(`Unknown command ${f}. Commands: brand, upgrade, check.`);let m;try{m=d(f,p)}catch(e){if(e instanceof s)return c(e.message);throw e}if(m.kind===`brand`){let e;try{e=await u.brand(m.options)}catch(e){return l(e)}for(let t of e.written)console.log(`wrote ${t}`);if(!m.options.check)return 0;for(let t of e.stale)console.log(`stale ${t}`);return+(e.stale.length>0)}if(m.kind===`upgrade`){let e;try{e=await u.upgrade(m.options)}catch(e){return l(e)}for(let t of e.hits)console.log(`${t.file}:${t.line} ${t.from} -> ${t.to}`);for(let t of e.choose)console.log(`choose ${t.file}:${t.line} ${t.name}: ${t.hint}`);return+(e.choose.length>0)}let h;try{h=await u.check()}catch(e){return l(e)}for(let e of a)h.findings.some(t=>t.check===e)||console.log(`ok ${e}`);for(let e of h.findings){let t=e.file?`${e.file}: `:``;console.log(`FAIL ${e.check}: ${t}${e.message}`)}return+(h.findings.length>0)}export{e as brand,t as check,f as run,n as upgrade};
1
+ import{brand as e}from"./build.js";import{check as t}from"./check.js";import{upgrade as n}from"./upgrade/index.js";var r=`Usage: webority <command>
2
+ brand [--brand <file>] [--library] [--out <dir>] [--web <scss>] [--phone <ts>] [--check]
3
+ upgrade <version> [--dry-run] [--app <folder>] [--path <p>]...
4
+ check`,i=[`brand`,`upgrade`,`check`],a=[`generated`,`design-map`,`repo-checks`],o={"--brand":`brand`,"--out":`out`,"--web":`web`,"--phone":`phone`},s=class extends Error{};function c(e){return console.error(e),console.error(r),2}function l(e){if(!(e instanceof Error))throw e;return console.error(e.message),1}function u(e,t,n){let r=[],i={},a=new Set;for(let o=0;o<e.length;o+=1){let c=e[o];if(t.includes(c)){let t=e[o+1];if(t===void 0||t.startsWith(`--`))throw new s(`${c} needs a value.`);i[c]=[...i[c]??[],t],o+=1}else if(n.includes(c))a.add(c);else if(c.startsWith(`--`))throw new s(`Unknown flag ${c}.`);else r.push(c)}return{positionals:r,values:i,flags:a}}function d(e,t){if(e===`brand`){let{positionals:e,values:n,flags:r}=u(t,Object.keys(o),[`--library`,`--check`]);if(e.length>0)throw new s(`brand takes no argument, got ${e[0]}.`);let i={};for(let[e,t]of Object.entries(o))n[e]!==void 0&&(i[t]=n[e].at(-1));return r.has(`--library`)&&(i.library=!0),r.has(`--check`)&&(i.check=!0),{kind:`brand`,options:i}}if(e===`upgrade`){let{positionals:e,values:n,flags:r}=u(t,[`--path`,`--app`],[`--dry-run`]);if(e.length===0)throw new s(`upgrade needs a <version>.`);if(e.length>1)throw new s(`Unexpected argument ${e[1]}.`);let i={version:e[0]};if(r.has(`--dry-run`)&&(i.dryRun=!0),n[`--app`]!==void 0){if(n[`--app`].length>1)throw new s(`--app takes one folder.`);if(n[`--path`]!==void 0)throw new s(`--app and --path cannot be combined.`);i.app=n[`--app`][0]}return n[`--path`]!==void 0&&(i.paths=n[`--path`]),{kind:`upgrade`,options:i}}if(t.length>0)throw new s(`check takes no arguments, got ${t[0]}.`);return{kind:`check`}}async function f(o,u={brand:e,upgrade:n,check:t}){if(o.includes(`--help`)||o.includes(`-h`))return console.log(r),0;if(o.length===0)return console.error(r),2;let[f,...p]=o;if(!i.includes(f))return c(`Unknown command ${f}. Commands: brand, upgrade, check.`);let m;try{m=d(f,p)}catch(e){if(e instanceof s)return c(e.message);throw e}if(m.kind===`brand`){let e;try{e=await u.brand(m.options)}catch(e){return l(e)}for(let t of e.written)console.log(`wrote ${t}`);if(!m.options.check)return 0;for(let t of e.stale)console.log(`stale ${t}`);return+(e.stale.length>0)}if(m.kind===`upgrade`){let e;try{e=await u.upgrade(m.options)}catch(e){return l(e)}for(let t of e.hits)console.log(`${t.file}:${t.line} ${t.from} -> ${t.to}`);for(let t of e.choose)console.log(`choose ${t.file}:${t.line} ${t.name}: ${t.hint}`);return+(e.choose.length>0)}let h;try{h=await u.check()}catch(e){return l(e)}for(let e of a)h.findings.some(t=>t.check===e)||console.log(`ok ${e}`);for(let e of h.findings){let t=e.file?`${e.file}: `:``;console.log(`FAIL ${e.check}: ${t}${e.message}`)}return+(h.findings.length>0)}export{e as brand,t as check,f as run,n as upgrade};
@@ -1 +1 @@
1
- function e(e){return{web:t(e,`web`,1440),web390:t(e,`web`,390),phone:t(e,`phone`,null)}}function t(e,t,a){let o=n(e,`light`,t,a),s=n(e,`dark`,t,a),c={format:`webority-theme-tokens/2`,source:{package:e.source.package,version:e.source.version,brand:e.source.brand,platform:t,width:a},modes:[`light`,`dark`],colors:{light:{},dark:{}},space:{},radius:{},text:{},typography:{fontWeight:{},leading:{}},fonts:{},shadow:{},components:{}};for(let t of e.tokens.values())t.group===`color`?i(c,e,t,o,s):e.existsIn(t.path,o)&&r(c,e,t,o);return c}function n(e,t,n,r){let i=e.contexts.find(e=>e.mode===t&&e.platform===n&&e.width===r);if(!i){let e=r===null?``:` ${r}`;throw Error(`emitCanvas: the model has no ${t} ${n}${e} context`)}return i}function r(e,t,n,r){let{path:i,name:o}=n;switch(n.group){case`space`:e.space[o]=s(t,i,r);break;case`radius`:e.radius[o]=s(t,i,r);break;case`text`:e.text[o]={size:s(t,i,r)};break;case`weight`:e.typography.fontWeight[o]=c(t,i,r);break;case`leading`:e.typography.leading[o]=c(t,i,r);break;case`font`:e.fonts[o]=l(t,i,r);break;case`shadow`:e.shadow[o]=u(t,i,r);break;case`component`:a(e,t,i,r);break}}function i(e,t,n,r,i){let a=t.existsIn(n.path,r);if(a!==t.existsIn(n.path,i))throw Error(`emitCanvas: ${n.path} is present in one mode only`);if(a&&(e.colors.light[n.name]=o(t,n.path,r),e.colors.dark[n.name]=o(t,n.path,i),n.brandOwn)){if(typeof n.description!=`string`||n.description===``)throw Error(`emitCanvas: ${n.path} is a brand colour and needs a description`);e.colorMeanings??={},e.colorMeanings[n.name]=n.description}}function a(e,t,n,r){let i=n.split(`.`);if(i.length!==3&&i.length!==4)throw Error(`emitCanvas: ${n} must be component.<name>.<prop> or component.<name>.<size>.<prop>`);let a=i[1],o=i[i.length-1];e.components[a]??={base:{},sizes:{}};let s=e.components[a].base;i.length===4&&(e.components[a].sizes[i[2]]??={},s=e.components[a].sizes[i[2]]),s[o]=f(t,n,r)}function o(e,t,n){let r=e.resolvedIn(t,n);if(typeof r!=`string`)throw Error(`emitCanvas: ${t} is not a colour string`);return r}function s(e,t,n){let r=e.resolvedIn(t,n);if(typeof r==`number`)return r;if(typeof r==`object`&&r&&r.unit===`px`&&typeof r.value==`number`)return r.value;throw Error(`emitCanvas: ${t} is not a px length`)}function c(e,t,n){let r=e.resolvedIn(t,n);if(typeof r!=`number`)throw Error(`emitCanvas: ${t} is not a number`);return r}function l(e,t,n){let r=e.resolvedIn(t,n);if(!Array.isArray(r)||r.length===0)throw Error(`emitCanvas: ${t} is not a font family list`);return{family:r[0],fallback:r.slice(1).join(`, `)}}function u(e,t,n){let r=e.resolvedIn(t,n);if(r===`none`)return null;if(typeof r!=`object`||!r||typeof r.color!=`string`)throw Error(`emitCanvas: ${t} is not a shadow`);let[i,a,o,s]=[`offsetX`,`offsetY`,`blur`,`spread`].map(e=>d(t,r[e])),c={x:i,y:a,blur:o,spread:s,color:r.color},l=e.tokens.get(t)?.extensions?.elevation;return Number.isFinite(l)&&(c.elevation=l),c}function d(e,t){let n=typeof t==`number`?t:t?.value;if(typeof n!=`number`)throw Error(`emitCanvas: ${e} has a shadow length that is not a number`);return n}function f(e,t,n){let r=e.resolvedIn(t,n);if(typeof r==`string`||typeof r==`number`)return String(r);if(typeof r==`object`&&r&&typeof r.unit==`string`)return`${r.value}${r.unit}`;throw Error(`emitCanvas: ${t} is not a component value`)}export{e as emitCanvas};
1
+ function e(e){return{web:t(e,`web`,1440),web390:t(e,`web`,390),phone:t(e,`phone`,null)}}function t(e,t,a){let o=n(e,`light`,t,a),s=n(e,`dark`,t,a),c={format:`webority-theme-tokens/2`,source:{package:e.source.package,version:e.source.version,brand:e.source.brand,platform:t,width:a},modes:[`light`,`dark`],colors:{light:{},dark:{}},space:{},radius:{},text:{},typography:{fontWeight:{},leading:{}},fonts:{},shadow:{},components:{}};for(let t of e.tokens.values())t.group===`color`?i(c,e,t,o,s):e.existsIn(t.path,o)&&r(c,e,t,o);return c}function n(e,t,n,r){let i=e.contexts.find(e=>e.mode===t&&e.platform===n&&e.width===r);if(!i){let e=r===null?``:` ${r}`;throw Error(`emitCanvas: the model has no ${t} ${n}${e} context`)}return i}function r(e,t,n,r){let{path:i,name:o}=n;switch(n.group){case`space`:e.space[o]=s(t,i,r);break;case`radius`:e.radius[o]=s(t,i,r);break;case`text`:e.text[o]={size:s(t,i,r)};break;case`weight`:e.typography.fontWeight[o]=c(t,i,r);break;case`leading`:e.typography.leading[o]=c(t,i,r);break;case`font`:e.fonts[o]=l(t,i,r);break;case`shadow`:e.shadow[o]=u(t,i,r);break;case`component`:a(e,t,i,r)}}function i(e,t,n,r,i){let a=t.existsIn(n.path,r);if(a!==t.existsIn(n.path,i))throw Error(`emitCanvas: ${n.path} is present in one mode only`);if(a&&(e.colors.light[n.name]=o(t,n.path,r),e.colors.dark[n.name]=o(t,n.path,i),n.brandOwn)){if(typeof n.description!=`string`||n.description===``)throw Error(`emitCanvas: ${n.path} is a brand colour and needs a description`);e.colorMeanings??={},e.colorMeanings[n.name]=n.description}}function a(e,t,n,r){let i=n.split(`.`);if(i.length!==3&&i.length!==4)throw Error(`emitCanvas: ${n} must be component.<name>.<prop> or component.<name>.<size>.<prop>`);let a=i[1],o=i[i.length-1];e.components[a]??={base:{},sizes:{}};let s=e.components[a].base;i.length===4&&(e.components[a].sizes[i[2]]??={},s=e.components[a].sizes[i[2]]),s[o]=f(t,n,r)}function o(e,t,n){let r=e.resolvedIn(t,n);if(typeof r!=`string`)throw Error(`emitCanvas: ${t} is not a colour string`);return r}function s(e,t,n){let r=e.resolvedIn(t,n);if(typeof r==`number`)return r;if(typeof r==`object`&&r&&r.unit===`px`&&typeof r.value==`number`)return r.value;throw Error(`emitCanvas: ${t} is not a px length`)}function c(e,t,n){let r=e.resolvedIn(t,n);if(typeof r!=`number`)throw Error(`emitCanvas: ${t} is not a number`);return r}function l(e,t,n){let r=e.resolvedIn(t,n);if(!Array.isArray(r)||r.length===0)throw Error(`emitCanvas: ${t} is not a font family list`);return{family:r[0],fallback:r.slice(1).join(`, `)}}function u(e,t,n){let r=e.resolvedIn(t,n);if(r===`none`)return null;if(typeof r!=`object`||!r||typeof r.color!=`string`)throw Error(`emitCanvas: ${t} is not a shadow`);let[i,a,o,s]=[`offsetX`,`offsetY`,`blur`,`spread`].map(e=>d(t,r[e])),c={x:i,y:a,blur:o,spread:s,color:r.color},l=e.tokens.get(t)?.extensions?.elevation;return Number.isFinite(l)&&(c.elevation=l),c}function d(e,t){let n=typeof t==`number`?t:t?.value;if(typeof n!=`number`)throw Error(`emitCanvas: ${e} has a shadow length that is not a number`);return n}function f(e,t,n){let r=e.resolvedIn(t,n);if(typeof r==`string`||typeof r==`number`)return String(r);if(typeof r==`object`&&r&&typeof r.unit==`string`)return`${r.value}${r.unit}`;throw Error(`emitCanvas: ${t} is not a component value`)}export{e as emitCanvas};
@@ -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,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(`
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);c===null?n(`email role ${e} (meaning ${s}, ${o}): cannot read colour ${r}`):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];typeof n?.family!=`string`||typeof n?.fallback!=`string`?t(`email fonts need font ${a}`):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??{}))Object.hasOwn(r,n)?l[n]={light:D(t,i.$value,`light`,n,s),dark:D(t,i.$extensions?.[`com.webority`]?.dark??i.$value,`dark`,n,s)}:m(`color`,n);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??{}))Object.hasOwn(c,t)?f[t]=T(n.$value,`email group role ${t}`,s):m(`shape`,t);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/emit/web.js CHANGED
@@ -1,20 +1,20 @@
1
- import{BREAKPOINT_PX as e,TOUCH_MEDIA as t,breakpointRules as n,fluidLength as r,touchValue as i}from"../model/length.js";import{cssVarOfPath as a}from"../names.js";var o={mode:`light`,platform:`web`,width:1440},s={mode:`dark`,platform:`web`,width:1440},c={mode:`light`,platform:`web`,width:390},l=/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,u=/^\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}$/,d=/^#[0-9a-f]{6}$/i,f=[[`--bs-body-color`,`text`],[`--bs-emphasis-color`,`text`],[`--bs-secondary-color`,`text-muted`],[`--bs-tertiary-color`,`text-subtle`],[`--bs-body-bg`,`bg`],[`--bs-border-color`,`border`],[`--bs-secondary-bg`,`surface`],[`--bs-tertiary-bg`,`bg-muted`],[`--bs-primary`,`primary`]],p=[[`--bs-body-bg-rgb`,`bg`],[`--bs-primary-rgb`,`primary`],[`--bs-body-color-rgb`,`text`],[`--bs-emphasis-color-rgb`,`text`],[`--bs-secondary-color-rgb`,`text-muted`],[`--bs-tertiary-color-rgb`,`text-subtle`],[`--bs-secondary-bg-rgb`,`surface`],[`--bs-tertiary-bg-rgb`,`bg-muted`],[`--bs-border-color-rgb`,`border`]],m=[[`$body-color`,`color.text-body`],[`$body-secondary-color`,`color.text-muted`],[`$body-tertiary-color`,`color.text-subtle`],[`$body-secondary-bg`,`color.bg-subtle`],[`$body-tertiary-bg`,`color.bg-muted`],[`$border-color`,`color.border`],[`$border-color-translucent`,null],[`$border-radius`,`radius.md`],[`$border-radius-sm`,`radius.sm`],[`$border-radius-lg`,`radius.lg`],[`$border-radius-pill`,`radius.pill`],[`$wui-shadow-overlay`,`shadow.popover`],[`$wui-shadow-overlay-lg`,`shadow.modal`],[`$link-color`,`color.link`],[`$line-height-base`,`leading.body`],[`$headings-line-height`,`leading.heading`],[`$display-line-height`,`leading.display`]],h=[[`$primary`,`color.primary`]],g={"$border-color-translucent":`rgba(13, 24, 43, 0.08)`},_=[`color.link`,`color.primary-hover`],v=`:root[data-theme="dark"],
1
+ import{BREAKPOINT_PX as e,TOUCH_MEDIA as t,breakpointRules as n,fluidLength as r,touchValue as i}from"../model/length.js";import{cssVarOfPath as a}from"../names.js";var o={mode:`light`,platform:`web`,width:1440},s={mode:`dark`,platform:`web`,width:1440},c={mode:`light`,platform:`web`,width:390},l=/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,u=/^\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}$/,d=/^#[0-9a-f]{6}$/i,f=[[`--bs-body-color`,`text`],[`--bs-emphasis-color`,`text`],[`--bs-secondary-color`,`text-muted`],[`--bs-tertiary-color`,`text-subtle`],[`--bs-heading-color`,`text`],[`--bs-body-bg`,`bg`],[`--bs-border-color`,`border`],[`--bs-secondary-bg`,`surface`],[`--bs-tertiary-bg`,`bg-muted`],[`--bs-primary`,`primary`]],p=[[`--bs-body-bg-rgb`,`bg`],[`--bs-primary-rgb`,`primary`],[`--bs-body-color-rgb`,`text`],[`--bs-emphasis-color-rgb`,`text`],[`--bs-secondary-color-rgb`,`text-muted`],[`--bs-tertiary-color-rgb`,`text-subtle`],[`--bs-secondary-bg-rgb`,`surface`],[`--bs-tertiary-bg-rgb`,`bg-muted`],[`--bs-border-color-rgb`,`border`]],m=[[`$body-color`,`color.text-body`],[`$body-secondary-color`,`color.text-muted`],[`$body-tertiary-color`,`color.text-subtle`],[`$body-secondary-bg`,`color.bg-subtle`],[`$body-tertiary-bg`,`color.bg-muted`],[`$border-color`,`color.border`],[`$border-color-translucent`,null],[`$border-radius`,`radius.md`],[`$border-radius-sm`,`radius.sm`],[`$border-radius-lg`,`radius.lg`],[`$border-radius-pill`,`radius.pill`],[`$wui-shadow-overlay`,`shadow.popover`],[`$wui-shadow-overlay-lg`,`shadow.modal`],[`$link-color`,`color.link`],[`$line-height-base`,`leading.body`],[`$headings-line-height`,`leading.heading`],[`$display-line-height`,`leading.display`]],h=[[`$primary`,`color.primary`]],g={"$border-color-translucent":`rgba(13, 24, 43, 0.08)`},_=[`color.link`,`color.primary-hover`],v=`:root[data-theme="dark"],
2
2
  :root[data-bs-theme="dark"]`,y=`[data-theme="dark"]:not(:root),
3
3
  [data-bs-theme="dark"]:not(:root)`,b=`:root[data-theme="auto"]`,x=`[data-theme="dark"]:not(:root) [data-theme="light"],
4
4
  [data-theme="dark"]:not(:root) [data-bs-theme="light"],
5
5
  [data-bs-theme="dark"]:not(:root) [data-theme="light"],
6
- [data-bs-theme="dark"]:not(:root) [data-bs-theme="light"]`,S=`// var() resolves where a name is declared, so the html copies keep the light values for a light box.`,C=`/* var() resolves where a name is declared, so the html copies keep the light values for a light box. */`,w=`// Zero specificity, so a component's own class on a themed section or inside it keeps its colour.`,T=`/* Zero specificity, so a component's own class on a themed section or inside it keeps its colour. */`;function E(e){return String(Number(e.toFixed(4)))}function D(e,t){if(typeof t==`string`)return t.replace(l,(e,t)=>`var(${a(t)})`);if(typeof t==`number`)return E(t);if(Array.isArray(t)){if(e.type===`cubicBezier`&&t.length===4&&t.every(e=>typeof e==`number`))return`cubic-bezier(${t.map(e=>E(e)).join(`, `)})`;if(e.type===`fontFamily`&&t.every(e=>typeof e==`string`))return t.map(e=>/\s/.test(e)?`"${e}"`:e).join(`, `)}else if(t&&typeof t==`object`){if(`unit`in t&&typeof t.value==`number`)return`${E(t.value)}${t.unit}`;if(`color`in t)return[t.offsetX,t.offsetY,t.blur,t.spread,t.color].map(t=>D(e,t)).join(` `)}throw Error(`emitWeb: ${e.path}: cannot write a ${e.type} value as CSS.`)}function O(e,t,n){return D(e.tokens.get(t),e.valueIn(t,n))}function k(e,t){if(t&&typeof t==`object`&&t.unit===`px`&&typeof t.value==`number`)return t.value;throw Error(`emitWeb: ${e}: a text size must be a px dimension.`)}function A(e,t){let i=e.tokens.get(t),s=a(t);if(i.group===`text`){if(n(i).length>0)throw Error(`emitWeb: ${t}: a text size cannot carry breakpoints.`);let a=k(t,e.valueIn(t,c)),l=k(t,e.valueIn(t,o)),u=i.extensions?.fluidUntil;if(a!==l&&u===void 0)throw Error(`emitWeb: ${t}: the 390 and 1440 sizes differ but no fluidUntil is recorded.`);return{path:t,name:s,root:r(a,l,u??1440),tiers:[]}}let l=n(i);return l.length>0?{path:t,name:s,root:O(e,t,c),tiers:l.map(e=>({tier:e.tier,text:D(i,e.value)}))}:{path:t,name:s,root:O(e,t,o),tiers:[]}}function j(e){let t=[];for(let n of e.tokens.keys())e.existsIn(n,o)&&t.push(A(e,n));return t}function M(e,t){let r=[];for(let[i,c]of e.tokens){if(!e.existsIn(i,s)||!e.existsIn(i,o)||n(c).length>0)continue;let l=O(e,i,s);if(c.group===`text`){if(l!==O(e,i,o))throw Error(`emitWeb: ${i}: a text size cannot change with the mode.`);continue}t(i,l)&&r.push({path:i,name:a(i),text:l})}return r}function N(e){let t=Number.parseInt(e.slice(1),16);return`${t>>16&255}, ${t>>8&255}, ${t&255}`}function P(e,t){let n=[];for(let[r,i]of p){let a=`color.${i}`,o=e.resolvedIn(a,s);if(!d.test(o))throw Error(`emitWeb: ${a}: a Bootstrap rgb triplet needs an opaque colour.`);t(a,o)&&n.push({name:r,text:N(o)})}return n}function F(e,t,n){return!e.tokens.has(`color.primary`)||!t.tokens.has(`color.primary`)||e.resolvedIn(`color.primary`,n)===t.resolvedIn(`color.primary`,n)?[]:I(e,n)}function I(e,t){let n=z(e,`color.primary`,t);return[{name:`--bs-primary`,text:n},{name:`--bs-primary-rgb`,text:N(n)}]}function L(e,t,n){return!_.every(n=>e.tokens.has(n)&&t.tokens.has(n))||e.resolvedIn(`color.link`,n)===t.resolvedIn(`color.link`,n)?[]:R(e,n)}function R(e,t){let n=z(e,`color.link`,t),r=z(e,`color.primary-hover`,t);return[{name:`--bs-link-color`,text:n},{name:`--bs-link-color-rgb`,text:N(n)},{name:`--bs-link-hover-color`,text:r},{name:`--bs-link-hover-color-rgb`,text:N(r)}]}function z(e,t,n){let r=e.resolvedIn(t,n);if(!d.test(r))throw Error(`emitWeb: ${t}: a Bootstrap rgb triplet needs an opaque colour.`);return r}function B(e,t){let n=M(e,t?(e,n)=>!t.tokens.has(e)||!t.existsIn(e,s)||n!==O(t,e,s):(t,n)=>n!==O(e,t,o)),r=P(e,t?(e,n)=>n!==t.resolvedIn(e,s):()=>!0);if(t){let i=L(e,t,o).length>0?R(e,s):L(e,t,s);return[...n,...r,...i]}let i=f.map(([e,t])=>({name:e,text:`var(${a(`color.${t}`)})`}));return[...n,...i,...r]}function V(e,t){return`${e} {\n${t.join(`
6
+ [data-bs-theme="dark"]:not(:root) [data-bs-theme="light"]`,S=`// var() resolves where a name is declared, so the html copies keep the light values for a light box.`,C=`/* var() resolves where a name is declared, so the html copies keep the light values for a light box. */`,w=`// Zero specificity, so a component's own class on a themed section or inside it keeps its colour.`,T=`/* Zero specificity, so a component's own class on a themed section or inside it keeps its colour. */`;function E(e){return String(Number(e.toFixed(4)))}function D(e,t){if(typeof t==`string`)return t.replace(l,(e,t)=>`var(${a(t)})`);if(typeof t==`number`)return E(t);if(Array.isArray(t)){if(e.type===`cubicBezier`&&t.length===4&&t.every(e=>typeof e==`number`))return`cubic-bezier(${t.map(e=>E(e)).join(`, `)})`;if(e.type===`fontFamily`&&t.every(e=>typeof e==`string`))return t.map(e=>/\s/.test(e)?`"${e}"`:e).join(`, `)}else if(t&&typeof t==`object`){if(`unit`in t&&typeof t.value==`number`)return`${E(t.value)}${t.unit}`;if(`color`in t)return[t.offsetX,t.offsetY,t.blur,t.spread,t.color].map(t=>D(e,t)).join(` `)}throw Error(`emitWeb: ${e.path}: cannot write a ${e.type} value as CSS.`)}function O(e,t,n){return D(e.tokens.get(t),e.valueIn(t,n))}function k(e,t){if(t&&typeof t==`object`&&t.unit===`px`&&typeof t.value==`number`)return t.value;throw Error(`emitWeb: ${e}: a text size must be a px dimension.`)}function A(e,t){let i=e.tokens.get(t),s=a(t);if(i.group===`text`){if(n(i).length>0)throw Error(`emitWeb: ${t}: a text size cannot carry breakpoints.`);let a=k(t,e.valueIn(t,c)),l=k(t,e.valueIn(t,o)),u=i.extensions?.fluidUntil;if(a!==l&&u===void 0)throw Error(`emitWeb: ${t}: the 390 and 1440 sizes differ but no fluidUntil is recorded.`);return{path:t,name:s,root:r(a,l,u??1440),tiers:[]}}let l=n(i);return l.length>0?{path:t,name:s,root:O(e,t,c),tiers:l.map(e=>({tier:e.tier,text:D(i,e.value)}))}:{path:t,name:s,root:O(e,t,o),tiers:[]}}function j(e){let t=[];for(let n of e.tokens.keys())e.existsIn(n,o)&&t.push(A(e,n));return t}function M(e,t){let r=[];for(let[i,c]of e.tokens){if(!e.existsIn(i,s)||!e.existsIn(i,o)||n(c).length>0)continue;let l=O(e,i,s);if(c.group===`text`){if(l!==O(e,i,o))throw Error(`emitWeb: ${i}: a text size cannot change with the mode.`)}else t(i,l)&&r.push({path:i,name:a(i),text:l})}return r}function N(e){let t=Number.parseInt(e.slice(1),16);return`${t>>16&255}, ${t>>8&255}, ${t&255}`}function P(e,t){let n=[];for(let[r,i]of p){let a=`color.${i}`,o=e.resolvedIn(a,s);if(!d.test(o))throw Error(`emitWeb: ${a}: a Bootstrap rgb triplet needs an opaque colour.`);t(a,o)&&n.push({name:r,text:N(o)})}return n}function F(e,t,n){return!e.tokens.has(`color.primary`)||!t.tokens.has(`color.primary`)||e.resolvedIn(`color.primary`,n)===t.resolvedIn(`color.primary`,n)?[]:I(e,n)}function I(e,t){let n=z(e,`color.primary`,t);return[{name:`--bs-primary`,text:n},{name:`--bs-primary-rgb`,text:N(n)}]}function L(e,t,n){return!_.every(n=>e.tokens.has(n)&&t.tokens.has(n))||e.resolvedIn(`color.link`,n)===t.resolvedIn(`color.link`,n)?[]:R(e,n)}function R(e,t){let n=z(e,`color.link`,t),r=z(e,`color.primary-hover`,t);return[{name:`--bs-link-color`,text:n},{name:`--bs-link-color-rgb`,text:N(n)},{name:`--bs-link-hover-color`,text:r},{name:`--bs-link-hover-color-rgb`,text:N(r)}]}function z(e,t,n){let r=e.resolvedIn(t,n);if(!d.test(r))throw Error(`emitWeb: ${t}: a Bootstrap rgb triplet needs an opaque colour.`);return r}function B(e,t){let n=M(e,t?(e,n)=>!t.tokens.has(e)||!t.existsIn(e,s)||n!==O(t,e,s):(t,n)=>n!==O(e,t,o)),r=P(e,t?(e,n)=>n!==t.resolvedIn(e,s):()=>!0);if(t){let i=L(e,t,o).length>0?R(e,s):L(e,t,s);return[...n,...r,...i]}let i=f.map(([e,t])=>({name:e,text:`var(${a(`color.${t}`)})`}));return[...n,...i,...r]}function V(e,t,n){return e.tokens.has(n)&&t.tokens.has(n)&&e.resolvedIn(n,o)!==t.resolvedIn(n,o)}function H(e,t){let n=f.filter(([n,r])=>n!==`--bs-primary`&&V(e,t,`color.${r}`)).map(([e,t])=>({name:e,text:`var(${a(`color.${t}`)})`})),r=p.filter(([n,r])=>n!==`--bs-primary-rgb`&&V(e,t,`color.${r}`)).map(([t,n])=>({name:t,text:N(z(e,`color.${n}`,o))}));return[...n,...r]}function U(e,t){return`${e} {\n${t.join(`
7
7
  `).split(`
8
8
  `).map(e=>e===``?e:` ${e}`).join(`
9
- `)}\n}`}function H(e){return e.split(`,
9
+ `)}\n}`}function W(e){return e.split(`,
10
10
  `).map(e=>`:where(${e})`).join(`,
11
- `)}function U(e){let t=[];for(let n=0;n<e.length;n+=6)t.push(e.slice(n,n+6).join(`, `));return[`$wui-dark-layer-names: (\n${t.map((e,n)=>` ${e}${n<t.length-1?`,`:``}`).join(`
12
- `)}\n);`,S,V(`html`,[`@each $name in $wui-dark-layer-names {`,` --wui-light-#{$name}: var(--#{$name});`,`}`]),V(x,[`@each $name in $wui-dark-layer-names {`,` --#{$name}: var(--wui-light-#{$name});`,`}`]),V(H(x),[`color-scheme: light;`,`color: var(--color-text);`])].join(`
11
+ `)}function G(e){let t=[];for(let n=0;n<e.length;n+=6)t.push(e.slice(n,n+6).join(`, `));return[`$wui-dark-layer-names: (\n${t.map((e,n)=>` ${e}${n<t.length-1?`,`:``}`).join(`
12
+ `)}\n);`,S,U(`html`,[`@each $name in $wui-dark-layer-names {`,` --wui-light-#{$name}: var(--#{$name});`,`}`]),U(x,[`@each $name in $wui-dark-layer-names {`,` --#{$name}: var(--wui-light-#{$name});`,`}`]),U(W(x),[`color-scheme: light;`,`color: var(--color-text);`])].join(`
13
13
 
14
- `)}function W(e){return[C,V(`html`,e.map(e=>`--wui-light-${e}: var(--${e});`)),V(x,e.map(e=>`--${e}: var(--wui-light-${e});`)),V(H(x),[`color-scheme: light;`,`color: var(--color-text);`])].join(`
14
+ `)}function K(e){return[C,U(`html`,e.map(e=>`--wui-light-${e}: var(--${e});`)),U(x,e.map(e=>`--${e}: var(--wui-light-${e});`)),U(W(x),[`color-scheme: light;`,`color: var(--color-text);`])].join(`
15
15
 
16
- `)}function G(e,t,n=!1){let{package:r,version:i,brand:a}=e.source,o=t?`Generated by ${r} ${i} for the ${a} brand. Do not edit; run webority brand.`:`Generated by ${r} ${i} from its token source. Do not edit; run webority brand --library.`;return n?`/* ${o} */`:`// ${o}`}function K(n,r){let a=j(n),s=new Map((r?j(r):[]).map(e=>[e.path,e])),c=[],l=a.filter(e=>s.get(e.path)?.root!==e.root).map(e=>`${e.name}: ${e.root};`);r&&(l.push(...F(n,r,o).map(e=>`${e.name}: ${e.text};`)),l.push(...L(n,r,o).map(e=>`${e.name}: ${e.text};`))),l.length>0&&c.push(V(`:root`,l));for(let[t,n]of Object.entries(e)){let e=[];for(let n of a)for(let r of n.tiers)r.tier===t&&s.get(n.path)?.tiers.find(e=>e.tier===t)?.text!==r.text&&e.push(`${n.name}: ${r.text};`);e.length>0&&c.push(V(`@media (min-width: ${n}px)`,[V(`:root`,e)]))}let u=[];for(let e of a){let t=n.tokens.get(e.path),a=i(t);if(a===null)continue;let o=D(t,a),s=r?.tokens.get(e.path),c=s?i(s):null;c!==null&&D(s,c)===o||u.push(`${e.name}: ${o};`)}u.length>0&&c.push(V(`@media ${t}`,[V(`:root`,u)]));let d=B(n,r);if(d.length>0){let e=d.map(e=>`${e.name}: ${e.text};`),t=r?T:w;c.push(V(v,[...e,`color-scheme: dark;`]),V(y,e),`${t}\n${V(H(y),[`color-scheme: dark;`,`color: var(--color-text);`])}`);let n=d.map(e=>e.name.slice(2));if(r){let e=new Set(B(r,null).map(e=>e.name.slice(2))),t=n.filter(t=>!e.has(t));t.length>0&&c.push(W(t))}else c.push(U(n));c.push(V(`@media (prefers-color-scheme: dark)`,[V(b,[...e,`color-scheme: dark;`])]))}return`${[G(n,r!==null,r!==null),...c].join(`
16
+ `)}function q(e,t,n=!1){let{package:r,version:i,brand:a}=e.source,o=t?`Generated by ${r} ${i} for the ${a} brand. Do not edit; run webority brand.`:`Generated by ${r} ${i} from its token source. Do not edit; run webority brand --library.`;return n?`/* ${o} */`:`// ${o}`}function J(n,r){let a=j(n),s=new Map((r?j(r):[]).map(e=>[e.path,e])),c=[],l=a.filter(e=>s.get(e.path)?.root!==e.root).map(e=>`${e.name}: ${e.root};`);r&&(l.push(...F(n,r,o).map(e=>`${e.name}: ${e.text};`)),l.push(...L(n,r,o).map(e=>`${e.name}: ${e.text};`)),l.push(...H(n,r).map(e=>`${e.name}: ${e.text};`))),l.length>0&&c.push(U(`:root`,l));for(let[t,n]of Object.entries(e)){let e=[];for(let n of a)for(let r of n.tiers)r.tier===t&&s.get(n.path)?.tiers.find(e=>e.tier===t)?.text!==r.text&&e.push(`${n.name}: ${r.text};`);e.length>0&&c.push(U(`@media (min-width: ${n}px)`,[U(`:root`,e)]))}let u=[];for(let e of a){let t=n.tokens.get(e.path),a=i(t);if(a===null)continue;let o=D(t,a),s=r?.tokens.get(e.path),c=s?i(s):null;(c===null||D(s,c)!==o)&&u.push(`${e.name}: ${o};`)}u.length>0&&c.push(U(`@media ${t}`,[U(`:root`,u)]));let d=B(n,r);if(d.length>0){let e=d.map(e=>`${e.name}: ${e.text};`),t=r?T:w;c.push(U(v,[...e,`color-scheme: dark;`]),U(y,e),`${t}\n${U(W(y),[`color-scheme: dark;`,`color: var(--color-text);`])}`);let n=d.map(e=>e.name.slice(2));if(r){let e=new Set(B(r,null).map(e=>e.name.slice(2))),t=n.filter(t=>!e.has(t));t.length>0&&c.push(K(t))}else c.push(G(n));c.push(U(`@media (prefers-color-scheme: dark)`,[U(b,[...e,`color-scheme: dark;`])]))}return`${[q(n,r!==null,r!==null),...c].join(`
17
17
 
18
- `)}\n`}function q(e,t){let n=e.tokens.get(t);if(n.type===`color`)return e.resolvedIn(t,o);let r=e.valueIn(t,o),i=typeof r==`string`?u.exec(r):null;if(i)return q(e,i[1]);let a=D(n,r);if(a.includes(`var(`))throw Error(`emitWeb: ${t}: a Bootstrap variable needs a literal.`);return a}function J(e,t,n){return n===null?g[t]:q(e,n)}function Y(e){let t=m.map(([t,n])=>`${t}: ${J(e,t,n)} !default;`);return`${[G(e,!1),...t].join(`
19
- `)}\n`}function X(e,t){let n=[...h,...m].filter(([n,r])=>J(e,n,r)!==J(t,n,r)).map(([t,n])=>`${t}: ${J(e,t,n)};`);return`${[G(e,!0),...n].join(`
20
- `)}\n`}function Z(e,t){return t===void 0?{tokens:K(e,null),bootstrap:Y(e)}:{css:K(e,t.library),variables:X(e,t.library)}}export{Z as emitWeb};
18
+ `)}\n`}function Y(e,t){let n=e.tokens.get(t);if(n.type===`color`)return e.resolvedIn(t,o);let r=e.valueIn(t,o),i=typeof r==`string`?u.exec(r):null;if(i)return Y(e,i[1]);let a=D(n,r);if(a.includes(`var(`))throw Error(`emitWeb: ${t}: a Bootstrap variable needs a literal.`);return a}function X(e,t,n){return n===null?g[t]:Y(e,n)}function Z(e){let t=m.map(([t,n])=>`${t}: ${X(e,t,n)} !default;`);return`${[q(e,!1),...t].join(`
19
+ `)}\n`}function Q(e,t){let n=[...h,...m].filter(([n,r])=>X(e,n,r)!==X(t,n,r)).map(([t,n])=>`${t}: ${X(e,t,n)};`);return`${[q(e,!0),...n].join(`
20
+ `)}\n`}function $(e,t){return t===void 0?{tokens:J(e,null),bootstrap:Z(e)}:{css:J(e,t.library),variables:Q(e,t.library)}}export{$ as emitWeb};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{BRAND_OUTPUT_FILES as e,HEAD_FOLDER as t,loadBrand as n}from"./brand.js";import{cssVar as r}from"./names.js";import{brand as i}from"./build.js";import{check as a}from"./check.js";import{upgrade as o}from"./upgrade/index.js";import{run as s}from"./cli.js";export{e as BRAND_OUTPUT_FILES,t as HEAD_FOLDER,i as brand,a as check,r as cssVar,n as loadBrand,s as run,o as upgrade};
1
+ import{BRAND_OUTPUT_FILES as e,HEAD_FOLDER as t,loadBrand as n}from"./brand.js";import{run as r}from"./cli.js";import{brand as i}from"./build.js";import{check as a}from"./check.js";import{upgrade as o}from"./upgrade/index.js";import{cssVar as s}from"./names.js";export{e as BRAND_OUTPUT_FILES,t as HEAD_FOLDER,i as brand,a as check,s as cssVar,n as loadBrand,r as run,o as upgrade};
@@ -2,7 +2,7 @@
2
2
  "format": "webority-meanings/1",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.122.0"
5
+ "version": "0.125.0"
6
6
  },
7
7
  "color": {
8
8
  "bg": {
@@ -1 +1 @@
1
- import{readSources as e}from"./load.js";import{buildModel as t}from"./resolve.js";import{fileURLToPath as n}from"node:url";async function r(r={}){return t(await e(r.resolverPath??n(new URL(`../webority.resolver.json`,import.meta.url)),r.brand))}export{r as loadModel};
1
+ import{readSources as e}from"./load.js";import{buildModel as t}from"./resolve.js";import{fileURLToPath as n}from"node:url";async function r(r={}){let i=r.resolverPath??n(new URL(`../webority.resolver.json`,import.meta.url));return t(await e(i,r.brand))}export{r as loadModel};
@@ -1 +1 @@
1
- import{__toESM as e}from"../_virtual/_rolldown/runtime.js";import{require__2020 as t}from"../node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{STEPS as n,cssVarOfPath as r}from"../names.js";import{readFile as i}from"node:fs/promises";import{basename as a,dirname as o,resolve as s}from"node:path";var c=e(t(),1),l=new URL(`../../package.json`,import.meta.url),u=new URL(`../../schema/webority-tokens.schema.json`,import.meta.url),d=`Declare each token in one source file.`;function f(e,t,n,r){return`${e}: ${t}: ${n}. ${r}`}function p(e,t){e.includes(t)||e.push(t)}function m(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function h(e){return m(e)&&typeof e.$ref==`string`}function g(e){let t=[],n=(e,r,i)=>{for(let[a,o]of Object.entries(e)){if(a.startsWith(`$`)||!m(o))continue;let e=[...r,a];`$value`in o?t.push({path:e.join(`.`),token:o,type:o.$type??i.type,extensions:{...i.extensions,...o.$extensions?.[`com.webority`]??{}}}):n(o,e,{type:o.$type??i.type,extensions:{...i.extensions,...o.$extensions?.[`com.webority`]??{}}})}};return n(e,[],{type:void 0,extensions:{}}),t}function _(e){let[t,...n]=e.path.split(`.`),r=e.extensions;return{path:e.path,group:t,name:n.join(`-`),type:e.type??``,description:e.token.$description??null,platforms:r.platforms??null,internal:r.internal===!0,brandOwn:!1,extensions:r}}function v(e,t,i,a){let{path:o,group:s,name:c,type:l}=e;l===``&&p(i,f(t,o,`has no $type`,`Add $type to the token or to its group.`));let u;try{u=r(o)}catch{p(i,f(t,o,`its group ${s} has no CSS prefix`,`Add the group to PREFIX in names.js.`))}let d=n[s];if(d&&!d.includes(c)&&p(i,f(t,o,`"${c}" is not a step of ${s}`,`Use one of: ${d.join(`, `)}.`)),u!==void 0){let e=a.get(u);e===void 0?a.set(u,o):e!==o&&p(i,f(t,o,`its CSS name ${u} is also the name of ${e}`,`Rename one of the two tokens.`))}}function y(e,t,n,r){let i={...e.extensions};return(i.platforms!==void 0||i.internal!==void 0)&&(p(r,f(t,e.path,`changes the platforms or internal mark`,`Set marks in the base set only.`)),delete i.platforms,delete i.internal),Object.assign(n.extensions,i),{value:e.token.$value,file:t}}function b(e,t,n){p(e,f(t,n,`overrides a token the base set does not declare`,`Declare ${n} in the base set first.`))}function x(e,t,n){let r=new Map;for(let{ref:i,data:a}of e)if(a)for(let e of g(a)){let a=t.get(e.path);if(!a){b(n,i,e.path);continue}r.set(e.path,y(e,i,a,n))}return r}async function S(e,t){let n=a(e),r=[],S=o(e),C;try{C=JSON.parse(await i(e,`utf8`))}catch(e){throw Error(f(n,`(file)`,`cannot be read as JSON (${e.message})`,`Restore the file or correct its path.`))}if(!Array.isArray(C.sets)||C.sets.length===0||!C.sets.every(e=>Array.isArray(e?.sources)&&e.sources.every(h)))throw Error(f(n,`sets`,`must be a non-empty array of { sources: [{ "$ref": string }] }`,`Match the resolver of the library source.`));if(!Array.isArray(C.modifiers))throw Error(f(n,`modifiers`,`must be an array`,`Match the resolver of the library source.`));let w=[[`mode`,[`light`,`dark`]],[`platform`,[`web`,`phone`]],[`width`,[`1440`,`390`]]];if(C.modifiers.length!==w.length)throw Error(f(n,`modifiers`,`must hold the mode, platform and width modifiers, in that order`,`Match the resolver of the library source.`));w.forEach(([e,t],r)=>{let i=C.modifiers[r],a=m(i?.contexts)?Object.keys(i.contexts).sort().join(`,`):``;if(!(i?.name===e&&a===[...t].sort().join(`,`)&&t.every(e=>Array.isArray(i.contexts[e])&&i.contexts[e].every(h))&&i.contexts[t[0]].length===0))throw Error(f(n,`modifiers.${e}`,`is not the ${e} modifier with the contexts ${t.join(`, `)} and an empty list for ${t[0]}`,`Match the resolver of the library source, whose default context lists no file.`))});let T=(e,t)=>C.modifiers.find(t=>t.name===e).contexts[t],E=C.sets.flatMap(e=>e.sources.map(e=>e.$ref)),D=T(`mode`,`dark`).map(e=>e.$ref),O=T(`platform`,`phone`).map(e=>e.$ref),k=T(`width`,`390`).map(e=>e.$ref),A=JSON.parse(await i(u,`utf8`)),j=new c.default({allErrors:!0,strict:!1});j.addSchema(A);let M=j.compile(A),N=j.getSchema(`${A.$id}#/$defs/sourceMeaning`),P=new Map,F=async e=>{let t=s(S,e);if(P.has(t))return P.get(t);let n=null;try{n=JSON.parse(await i(t,`utf8`))}catch(n){return p(r,f(e,`(file)`,`cannot be read as JSON (${n.message})`,`Restore the file or correct its $ref in the resolver.`)),P.set(t,null),null}let o=[];M(n)||o.push(...M.errors),a(t)===`meaning.tokens.json`&&!N(n)&&o.push(...N.errors);for(let t of o){if(t.keyword===`if`)continue;let n=t.instancePath.slice(1).split(`/`).filter(e=>e!==``),i=n.length===0?`(file)`:n.map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)).join(`.`),a=t.params?.additionalProperty??t.params?.propertyName,o=a===void 0?t.message:`${t.message} "${a}"`;p(r,f(e,i,o,`Correct it against schema/webority-tokens.schema.json.`))}return P.set(t,n),n},I=async e=>Promise.all(e.map(async e=>({ref:e,data:await F(e)}))),L=await I(E),R=await I(D),z=await I(O),B=await I(k),V=new Map,H=new Map,U=new Map;for(let{ref:e,data:t}of L)if(t)for(let n of g(t)){if(V.has(n.path)){p(r,f(e,n.path,`is already declared in ${U.get(n.path).file}`,d));continue}let t=_(n);v(t,e,r,H),V.set(n.path,t),U.set(n.path,{value:n.token.$value,file:e})}let W=x(R,V,r),G=x(z,V,r),K=x(B,V,r),q=new Map,J=new Map,Y=new Map,X=new Map;if(t){let e=`brand ${t.name}`;for(let n of g(t.base)){let t=V.get(n.path);if(t){q.set(n.path,y(n,e,t,r));continue}let i=_(n);v(i,e,r,H),i.brandOwn=!0,V.set(n.path,i),q.set(n.path,{value:n.token.$value,file:e})}for(let n of g(t.dark)){let t=V.get(n.path);if(!t){b(r,e,n.path);continue}J.set(n.path,y(n,e,t,r))}for(let[n,i]of[[t.phone?.light,Y],[t.phone?.dark,X]])if(m(n))for(let t of g(n)){let n=V.get(t.path);if(!n){b(r,e,t.path);continue}i.set(t.path,y(t,e,n,r))}}let Z=JSON.parse(await i(l,`utf8`)),Q={package:Z.name,version:Z.version,brand:t?.name??null};return{tokens:V,layers:{base:U,dark:W,phone:G,width390:K,brandBase:q,brandDark:J,brandPhoneLight:Y,brandPhoneDark:X},cssNames:H,source:Q,refusals:r}}export{f as line,S as readSources};
1
+ import{__toESM as e}from"../_virtual/_rolldown/runtime.js";import{require__2020 as t}from"../node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{STEPS as n,cssVarOfPath as r}from"../names.js";import{readFile as i}from"node:fs/promises";import{basename as a,dirname as o,resolve as s}from"node:path";var c=e(t(),1),l=new URL(`../../package.json`,import.meta.url),u=new URL(`../../schema/webority-tokens.schema.json`,import.meta.url),d=`Declare each token in one source file.`;function f(e,t,n,r){return`${e}: ${t}: ${n}. ${r}`}function p(e,t){e.includes(t)||e.push(t)}function m(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function h(e){return m(e)&&typeof e.$ref==`string`}function g(e){let t=[],n=(e,r,i)=>{for(let[a,o]of Object.entries(e)){if(a.startsWith(`$`)||!m(o))continue;let e=[...r,a];`$value`in o?t.push({path:e.join(`.`),token:o,type:o.$type??i.type,extensions:{...i.extensions,...o.$extensions?.[`com.webority`]??{}}}):n(o,e,{type:o.$type??i.type,extensions:{...i.extensions,...o.$extensions?.[`com.webority`]??{}}})}};return n(e,[],{type:void 0,extensions:{}}),t}function _(e){let[t,...n]=e.path.split(`.`),r=e.extensions;return{path:e.path,group:t,name:n.join(`-`),type:e.type??``,description:e.token.$description??null,platforms:r.platforms??null,internal:r.internal===!0,brandOwn:!1,extensions:r}}function v(e,t,i,a){let{path:o,group:s,name:c,type:l}=e;l===``&&p(i,f(t,o,`has no $type`,`Add $type to the token or to its group.`));let u;try{u=r(o)}catch{p(i,f(t,o,`its group ${s} has no CSS prefix`,`Add the group to PREFIX in names.js.`))}let d=n[s];if(d&&!d.includes(c)&&p(i,f(t,o,`"${c}" is not a step of ${s}`,`Use one of: ${d.join(`, `)}.`)),u!==void 0){let e=a.get(u);e===void 0?a.set(u,o):e!==o&&p(i,f(t,o,`its CSS name ${u} is also the name of ${e}`,`Rename one of the two tokens.`))}}function y(e,t,n,r){let i={...e.extensions};return(i.platforms!==void 0||i.internal!==void 0)&&(p(r,f(t,e.path,`changes the platforms or internal mark`,`Set marks in the base set only.`)),delete i.platforms,delete i.internal),Object.assign(n.extensions,i),{value:e.token.$value,file:t}}function b(e,t,n){p(e,f(t,n,`overrides a token the base set does not declare`,`Declare ${n} in the base set first.`))}function x(e,t,n){let r=new Map;for(let{ref:i,data:a}of e)if(a)for(let e of g(a)){let a=t.get(e.path);a?r.set(e.path,y(e,i,a,n)):b(n,i,e.path)}return r}async function S(e,t){let n=a(e),r=[],S=o(e),C;try{C=JSON.parse(await i(e,`utf8`))}catch(e){throw Error(f(n,`(file)`,`cannot be read as JSON (${e.message})`,`Restore the file or correct its path.`))}if(!Array.isArray(C.sets)||C.sets.length===0||!C.sets.every(e=>Array.isArray(e?.sources)&&e.sources.every(h)))throw Error(f(n,`sets`,`must be a non-empty array of { sources: [{ "$ref": string }] }`,`Match the resolver of the library source.`));if(!Array.isArray(C.modifiers))throw Error(f(n,`modifiers`,`must be an array`,`Match the resolver of the library source.`));let w=[[`mode`,[`light`,`dark`]],[`platform`,[`web`,`phone`]],[`width`,[`1440`,`390`]]];if(C.modifiers.length!==w.length)throw Error(f(n,`modifiers`,`must hold the mode, platform and width modifiers, in that order`,`Match the resolver of the library source.`));w.forEach(([e,t],r)=>{let i=C.modifiers[r],a=m(i?.contexts)?Object.keys(i.contexts).sort().join(`,`):``;if(!(i?.name===e&&a===[...t].sort().join(`,`)&&t.every(e=>Array.isArray(i.contexts[e])&&i.contexts[e].every(h))&&i.contexts[t[0]].length===0))throw Error(f(n,`modifiers.${e}`,`is not the ${e} modifier with the contexts ${t.join(`, `)} and an empty list for ${t[0]}`,`Match the resolver of the library source, whose default context lists no file.`))});let T=(e,t)=>C.modifiers.find(t=>t.name===e).contexts[t],E=C.sets.flatMap(e=>e.sources.map(e=>e.$ref)),D=T(`mode`,`dark`).map(e=>e.$ref),O=T(`platform`,`phone`).map(e=>e.$ref),k=T(`width`,`390`).map(e=>e.$ref),A=JSON.parse(await i(u,`utf8`)),j=new c.default({allErrors:!0,strict:!1});j.addSchema(A);let M=j.compile(A),N=j.getSchema(`${A.$id}#/$defs/sourceMeaning`),P=new Map,F=async e=>{let t=s(S,e);if(P.has(t))return P.get(t);let n=null;try{n=JSON.parse(await i(t,`utf8`))}catch(n){return p(r,f(e,`(file)`,`cannot be read as JSON (${n.message})`,`Restore the file or correct its $ref in the resolver.`)),P.set(t,null),null}let o=[];M(n)||o.push(...M.errors),a(t)===`meaning.tokens.json`&&!N(n)&&o.push(...N.errors);for(let t of o){if(t.keyword===`if`)continue;let n=t.instancePath.slice(1).split(`/`).filter(e=>e!==``),i=n.length===0?`(file)`:n.map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)).join(`.`),a=t.params?.additionalProperty??t.params?.propertyName,o=a===void 0?t.message:`${t.message} "${a}"`;p(r,f(e,i,o,`Correct it against schema/webority-tokens.schema.json.`))}return P.set(t,n),n},I=async e=>Promise.all(e.map(async e=>({ref:e,data:await F(e)}))),L=await I(E),R=await I(D),z=await I(O),B=await I(k),V=new Map,H=new Map,U=new Map;for(let{ref:e,data:t}of L)if(t)for(let n of g(t)){if(V.has(n.path)){p(r,f(e,n.path,`is already declared in ${U.get(n.path).file}`,d));continue}let t=_(n);v(t,e,r,H),V.set(n.path,t),U.set(n.path,{value:n.token.$value,file:e})}let W=x(R,V,r),G=x(z,V,r),K=x(B,V,r),q=new Map,J=new Map,Y=new Map,X=new Map;if(t){let e=`brand ${t.name}`;for(let n of g(t.base)){let t=V.get(n.path);if(t){q.set(n.path,y(n,e,t,r));continue}let i=_(n);v(i,e,r,H),i.brandOwn=!0,V.set(n.path,i),q.set(n.path,{value:n.token.$value,file:e})}for(let n of g(t.dark)){let t=V.get(n.path);t?J.set(n.path,y(n,e,t,r)):b(r,e,n.path)}for(let[n,i]of[[t.phone?.light,Y],[t.phone?.dark,X]])if(m(n))for(let t of g(n)){let n=V.get(t.path);n?i.set(t.path,y(t,e,n,r)):b(r,e,t.path)}}let Z=JSON.parse(await i(l,`utf8`)),Q={package:Z.name,version:Z.version,brand:t?.name??null};return{tokens:V,layers:{base:U,dark:W,phone:G,width390:K,brandBase:q,brandDark:J,brandPhoneLight:Y,brandPhoneDark:X},cssNames:H,source:Q,refusals:r}}export{f as line,S as readSources};
@@ -1 +1 @@
1
- function e(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function t(n){return typeof n==`string`?[...n.matchAll(/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g)].map(e=>e[1]):Array.isArray(n)?n.flatMap(t):e(n)?Object.values(n).flatMap(t):[]}function n(t,r){if(typeof t==`string`){let e=/^\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}$/.exec(t);return e?r(e[1],!0):t.replace(/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,(e,t)=>String(r(t,!1)))}return Array.isArray(t)?t.map(e=>n(e,r)):e(t)?Object.fromEntries(Object.entries(t).map(([e,t])=>[e,n(t,r)])):t}function r(e){let t=[],n=new Set,r=new Set,i=[],a=new Set,o=s=>{i.push(s),a.add(s);for(let c of e.get(s)??[])if(e.has(c))if(a.has(c)){let e=[...i.slice(i.indexOf(c)),c],r=[...new Set(e)].sort().join(`,`);n.has(r)||(n.add(r),t.push(e))}else r.has(c)||o(c);i.pop(),a.delete(s),r.add(s)};for(let t of e.keys())r.has(t)||o(t);return t}export{r as findCycles,n as mapReferences,t as referencesIn};
1
+ function e(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function t(n){return typeof n==`string`?[...n.matchAll(/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g)].map(e=>e[1]):Array.isArray(n)?n.flatMap(t):e(n)?Object.values(n).flatMap(t):[]}function n(t,r){if(typeof t==`string`){let e=/^\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}$/.exec(t);return e?r(e[1],!0):t.replace(/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,(e,t)=>String(r(t,!1)))}return Array.isArray(t)?t.map(e=>n(e,r)):e(t)?Object.fromEntries(Object.entries(t).map(([e,t])=>[e,n(t,r)])):t}function r(e){let t=[],n=new Set,r=new Set,i=[],a=new Set,o=s=>{i.push(s),a.add(s);for(let c of e.get(s)??[])if(e.has(c)){if(a.has(c)){let e=[...i.slice(i.indexOf(c)),c],r=[...new Set(e)].sort().join(`,`);n.has(r)||(n.add(r),t.push(e))}else r.has(c)||o(c)}i.pop(),a.delete(s),r.add(s)};for(let t of e.keys())r.has(t)||o(t);return t}export{r as findCycles,n as mapReferences,t as referencesIn};
@@ -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),e.platform===`phone`&&t.push(e.mode===`dark`?u.brandPhoneDark:u.brandPhoneLight),t},_=new Set([u.brandBase,u.brandDark,u.brandPhoneLight,u.brandPhoneDark]),v=(e,t,n)=>n.platform===`phone`&&_.has(e)&&t.startsWith(`font.`)&&!l.get(t).extensions.faces,y=(e,t)=>{let n=g(t).reverse();for(let r of n){if(v(r,e,t)||r===u.brandBase&&t.mode===`dark`&&u.dark.has(e))continue;let n=r.get(e);if(n)return n}},b=(e,t)=>{let n=l.get(e);return n?n.platforms===null||n.platforms.includes(t.platform):!1},x=(e,t)=>{if(!b(e,t))throw Error(`model: ${e} does not exist on ${t.platform}`)},S=new Map,C=(t,r)=>{let a=`${s(r)}|${t}`;if(S.has(a))return S.get(a);x(t,r);let o=l.get(t),{value:u}=y(t,r),d;if(o.type===`color`){if(typeof u!=`string`)throw Error(`model: ${t} is a colour with a value that is not text`);if(o.extensions.derive)throw Error(`model: ${t} uses derive, which is removed; set the colour itself`);d=n(i(u,t=>`var(${e(t)})`),e=>w(e,r))}else d=i(u,(e,n)=>{let i=C(e,r);return n?i:c(i,e,t)});return S.set(a,d),d},w=(e,t)=>{let n=d.get(e);if(n===void 0||!b(n,t))return;if(l.get(n).type===`color`)return C(n,t);let{value:r}=y(n,t);return typeof r==`string`?r:void 0},T=()=>{for(let e of Object.values(u))for(let[n,r]of e)for(let e of a(r.value))if(!l.has(e)){let i=t(r.file,n,`references ${e}, which no token declares`,`Declare ${e} or correct the name.`);p.includes(i)||p.push(i)}},E=()=>{for(let e of m){let n=new Map;for(let t of l.keys())b(t,e)&&n.set(t,a(y(t,e).value));for(let i of r(n)){let n=t(y(i[0],e).file,i[0],`reference cycle ${i.join(` -> `)}`,`Point one of these tokens at a value instead.`);p.includes(n)||p.push(n)}}},D=()=>{for(let e of m)for(let n of l.keys()){if(!b(n,e))continue;let{file:r,value:i}=y(n,e);for(let o of a(i))if(l.has(o)&&!b(o,e)){let i=t(r,n,`references ${o}, which does not exist on ${e.platform}`,`Mark ${n} for the platform that has ${o}, or give ${n} a ${e.platform} override.`);p.includes(i)||p.push(i)}}},O=()=>{for(let e of m)for(let n of l.keys())if(b(n,e))try{C(n,e)}catch(r){let i=t(y(n,e).file,n,r.message.replace(/\.$/,``),`Correct the value or the tokens it references.`);p.includes(i)||p.push(i)}},k=p.length;T();let A=p.length>k;if(A||E(),A||D(),p.length===0&&O(),p.length>0)throw Error(p.join(`
1
+ import{cssVarOfPath as e}from"../names.js";import{resolveColour as t}from"./colour.js";import{line as n}from"./load.js";import{findCycles as r,mapReferences as i,referencesIn as a}from"./references.js";function o(){return[{mode:`light`,platform:`web`,width:1440},{mode:`dark`,platform:`web`,width:1440},{mode:`light`,platform:`web`,width:390},{mode:`dark`,platform:`web`,width:390},{mode:`light`,platform:`phone`,width:null},{mode:`dark`,platform:`phone`,width:null}]}function s(e){return`${e.mode}|${e.platform}|${e.width}`}function c(e,t,n){if(typeof e==`string`)return e;if(typeof e==`number`)return String(e);if(typeof e==`object`&&e&&`value`in e&&`unit`in e)return`${e.value}${e.unit}`;throw Error(`model: ${t} cannot sit inside the text of ${n}`)}function l({tokens:l,layers:u,cssNames:d,source:f,refusals:p}){let m=o(),h=e=>{let t=m.find(t=>t.mode===e.mode&&t.platform===e.platform&&t.width===e.width);if(!t)throw Error(`model: ${JSON.stringify(e)} is not one of the model's contexts`);return t},g=e=>{let t=[u.base];return e.mode===`dark`&&t.push(u.dark),e.platform===`phone`&&t.push(u.phone),e.platform===`web`&&e.width===390&&t.push(u.width390),t.push(u.brandBase),e.mode===`dark`&&t.push(u.brandDark),e.platform===`phone`&&t.push(e.mode===`dark`?u.brandPhoneDark:u.brandPhoneLight),t},_=new Set([u.brandBase,u.brandDark,u.brandPhoneLight,u.brandPhoneDark]),v=(e,t,n)=>n.platform===`phone`&&_.has(e)&&t.startsWith(`font.`)&&!l.get(t).extensions.faces,y=(e,t)=>{let n=g(t).reverse();for(let r of n){if(v(r,e,t)||r===u.brandBase&&t.mode===`dark`&&u.dark.has(e))continue;let n=r.get(e);if(n)return n}},b=(e,t)=>{let n=l.get(e);return n?n.platforms===null||n.platforms.includes(t.platform):!1},x=(e,t)=>{if(!b(e,t))throw Error(`model: ${e} does not exist on ${t.platform}`)},S=new Map,C=(n,r)=>{let a=`${s(r)}|${n}`;if(S.has(a))return S.get(a);x(n,r);let o=l.get(n),{value:u}=y(n,r),d;if(o.type===`color`){if(typeof u!=`string`)throw Error(`model: ${n} is a colour with a value that is not text`);if(o.extensions.derive)throw Error(`model: ${n} uses derive, which is removed; set the colour itself`);let a=i(u,t=>`var(${e(t)})`);d=t(a,e=>w(e,r))}else d=i(u,(e,t)=>{let i=C(e,r);return t?i:c(i,e,n)});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[t,r]of e)for(let e of a(r.value))if(!l.has(e)){let i=n(r.file,t,`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 t=new Map;for(let n of l.keys())b(n,e)&&t.set(n,a(y(n,e).value));for(let i of r(t)){let t=n(y(i[0],e).file,i[0],`reference cycle ${i.join(` -> `)}`,`Point one of these tokens at a value instead.`);p.includes(t)||p.push(t)}}},D=()=>{for(let e of m)for(let t of l.keys()){if(!b(t,e))continue;let{file:r,value:i}=y(t,e);for(let o of a(i))if(l.has(o)&&!b(o,e)){let i=n(r,t,`references ${o}, which does not exist on ${e.platform}`,`Mark ${t} for the platform that has ${o}, or give ${t} a ${e.platform} override.`);p.includes(i)||p.push(i)}}},O=()=>{for(let e of m)for(let t of l.keys())if(b(t,e))try{C(t,e)}catch(r){let i=n(y(t,e).file,t,r.message.replace(/\.$/,``),`Correct the value or the tokens it references.`);p.includes(i)||p.push(i)}},k=p.length;T();let A=p.length>k;if(A||E(),A||D(),p.length===0&&O(),p.length>0)throw Error(p.join(`
2
2
  `));return{tokens:l,contexts:o(),existsIn:(e,t)=>b(e,h(t)),valueIn:(e,t)=>{let n=h(t);return x(e,n),structuredClone(y(e,n).value)},resolvedIn:(e,t)=>{let n=h(t);return structuredClone(C(e,n))},referenceIn:(e,t)=>{let n=h(t);return x(e,n),a(y(e,n).value)[0]},source:f}}export{o as buildContexts,l as buildModel};
@@ -1 +1 @@
1
- import{__commonJSMin as e}from"../../../../../../_virtual/_rolldown/runtime.js";import{require_codegen as t}from"./compile/codegen/index.js";import{require_validate as n}from"./compile/validate/index.js";import{require_validation_error as r}from"./runtime/validation_error.js";import{require_ref_error as i}from"./compile/ref_error.js";import{require_core as a}from"./core.js";import{require_draft2020 as o}from"./vocabularies/draft2020.js";import{require_discriminator as s}from"./vocabularies/discriminator/index.js";import{require_json_schema_2020_12 as c}from"./refs/json-schema-2020-12/index.js";var l=e(((e,l)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MissingRefError=e.ValidationError=e.CodeGen=e.Name=e.nil=e.stringify=e.str=e._=e.KeywordCxt=e.Ajv2020=void 0;var u=a(),d=o(),f=s(),p=c(),m=`https://json-schema.org/draft/2020-12/schema`,h=class extends u.default{constructor(e={}){super({...e,dynamicRef:!0,next:!0,unevaluated:!0})}_addVocabularies(){super._addVocabularies(),d.default.forEach(e=>this.addVocabulary(e)),this.opts.discriminator&&this.addKeyword(f.default)}_addDefaultMetaSchema(){super._addDefaultMetaSchema();let{$data:e,meta:t}=this.opts;t&&(p.default.call(this,e),this.refs[`http://json-schema.org/schema`]=m)}defaultMeta(){return this.opts.defaultMeta=super.defaultMeta()||(this.getSchema(m)?m:void 0)}};e.Ajv2020=h,l.exports=e=h,l.exports.Ajv2020=h,Object.defineProperty(e,"__esModule",{value:!0}),e.default=h;var g=n();Object.defineProperty(e,"KeywordCxt",{enumerable:!0,get:function(){return g.KeywordCxt}});var _=t();Object.defineProperty(e,"_",{enumerable:!0,get:function(){return _._}}),Object.defineProperty(e,"str",{enumerable:!0,get:function(){return _.str}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return _.stringify}}),Object.defineProperty(e,"nil",{enumerable:!0,get:function(){return _.nil}}),Object.defineProperty(e,"Name",{enumerable:!0,get:function(){return _.Name}}),Object.defineProperty(e,"CodeGen",{enumerable:!0,get:function(){return _.CodeGen}});var v=r();Object.defineProperty(e,"ValidationError",{enumerable:!0,get:function(){return v.default}});var y=i();Object.defineProperty(e,"MissingRefError",{enumerable:!0,get:function(){return y.default}})}));export default l();export{l as require__2020};
1
+ import{__commonJSMin as e}from"../../../../../../_virtual/_rolldown/runtime.js";import{require_core as t}from"./core.js";import{require_draft2020 as n}from"./vocabularies/draft2020.js";import{require_discriminator as r}from"./vocabularies/discriminator/index.js";import{require_json_schema_2020_12 as i}from"./refs/json-schema-2020-12/index.js";import{require_validate as a}from"./compile/validate/index.js";import{require_codegen as o}from"./compile/codegen/index.js";import{require_validation_error as s}from"./runtime/validation_error.js";import{require_ref_error as c}from"./compile/ref_error.js";var l=e(((e,l)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MissingRefError=e.ValidationError=e.CodeGen=e.Name=e.nil=e.stringify=e.str=e._=e.KeywordCxt=e.Ajv2020=void 0;var u=t(),d=n(),f=r(),p=i(),m=`https://json-schema.org/draft/2020-12/schema`,h=class extends u.default{constructor(e={}){super({...e,dynamicRef:!0,next:!0,unevaluated:!0})}_addVocabularies(){super._addVocabularies(),d.default.forEach(e=>this.addVocabulary(e)),this.opts.discriminator&&this.addKeyword(f.default)}_addDefaultMetaSchema(){super._addDefaultMetaSchema();let{$data:e,meta:t}=this.opts;t&&(p.default.call(this,e),this.refs[`http://json-schema.org/schema`]=m)}defaultMeta(){return this.opts.defaultMeta=super.defaultMeta()||(this.getSchema(m)?m:void 0)}};e.Ajv2020=h,l.exports=e=h,l.exports.Ajv2020=h,Object.defineProperty(e,"__esModule",{value:!0}),e.default=h;var g=a();Object.defineProperty(e,"KeywordCxt",{enumerable:!0,get:function(){return g.KeywordCxt}});var _=o();Object.defineProperty(e,"_",{enumerable:!0,get:function(){return _._}}),Object.defineProperty(e,"str",{enumerable:!0,get:function(){return _.str}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return _.stringify}}),Object.defineProperty(e,"nil",{enumerable:!0,get:function(){return _.nil}}),Object.defineProperty(e,"Name",{enumerable:!0,get:function(){return _.Name}}),Object.defineProperty(e,"CodeGen",{enumerable:!0,get:function(){return _.CodeGen}});var v=s();Object.defineProperty(e,"ValidationError",{enumerable:!0,get:function(){return v.default}});var y=c();Object.defineProperty(e,"MissingRefError",{enumerable:!0,get:function(){return y.default}})}));export default l();export{l as require__2020};
@@ -1,2 +1,2 @@
1
- import{__commonJSMin as e}from"../../../../../../../../_virtual/_rolldown/runtime.js";import{require_code as t}from"./code.js";import{require_scope as n}from"./scope.js";var r=e((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.or=e.and=e.not=e.CodeGen=e.operators=e.varKinds=e.ValueScopeName=e.ValueScope=e.Scope=e.Name=e.regexpCode=e.stringify=e.getProperty=e.nil=e.strConcat=e.str=e._=void 0;var r=t(),i=n(),a=t();Object.defineProperty(e,"_",{enumerable:!0,get:function(){return a._}}),Object.defineProperty(e,"str",{enumerable:!0,get:function(){return a.str}}),Object.defineProperty(e,"strConcat",{enumerable:!0,get:function(){return a.strConcat}}),Object.defineProperty(e,"nil",{enumerable:!0,get:function(){return a.nil}}),Object.defineProperty(e,"getProperty",{enumerable:!0,get:function(){return a.getProperty}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return a.stringify}}),Object.defineProperty(e,"regexpCode",{enumerable:!0,get:function(){return a.regexpCode}}),Object.defineProperty(e,"Name",{enumerable:!0,get:function(){return a.Name}});var o=n();Object.defineProperty(e,"Scope",{enumerable:!0,get:function(){return o.Scope}}),Object.defineProperty(e,"ValueScope",{enumerable:!0,get:function(){return o.ValueScope}}),Object.defineProperty(e,"ValueScopeName",{enumerable:!0,get:function(){return o.ValueScopeName}}),Object.defineProperty(e,"varKinds",{enumerable:!0,get:function(){return o.varKinds}}),e.operators={GT:new r._Code(`>`),GTE:new r._Code(`>=`),LT:new r._Code(`<`),LTE:new r._Code(`<=`),EQ:new r._Code(`===`),NEQ:new r._Code(`!==`),NOT:new r._Code(`!`),OR:new r._Code(`||`),AND:new r._Code(`&&`),ADD:new r._Code(`+`)};var s=class{optimizeNodes(){return this}optimizeNames(e,t){return this}},c=class extends s{constructor(e,t,n){super(),this.varKind=e,this.name=t,this.rhs=n}render({es5:e,_n:t}){let n=e?i.varKinds.var:this.varKind,r=this.rhs===void 0?``:` = ${this.rhs}`;return`${n} ${this.name}${r};`+t}optimizeNames(e,t){if(e[this.name.str])return this.rhs&&=j(this.rhs,e,t),this}get names(){return this.rhs instanceof r._CodeOrName?this.rhs.names:{}}},l=class extends s{constructor(e,t,n){super(),this.lhs=e,this.rhs=t,this.sideEffects=n}render({_n:e}){return`${this.lhs} = ${this.rhs};`+e}optimizeNames(e,t){if(!(this.lhs instanceof r.Name&&!e[this.lhs.str]&&!this.sideEffects))return this.rhs=j(this.rhs,e,t),this}get names(){return A(this.lhs instanceof r.Name?{}:{...this.lhs.names},this.rhs)}},u=class extends l{constructor(e,t,n,r){super(e,n,r),this.op=t}render({_n:e}){return`${this.lhs} ${this.op}= ${this.rhs};`+e}},d=class extends s{constructor(e){super(),this.label=e,this.names={}}render({_n:e}){return`${this.label}:`+e}},f=class extends s{constructor(e){super(),this.label=e,this.names={}}render({_n:e}){return`break${this.label?` ${this.label}`:``};`+e}},p=class extends s{constructor(e){super(),this.error=e}render({_n:e}){return`throw ${this.error};`+e}get names(){return this.error.names}},m=class extends s{constructor(e){super(),this.code=e}render({_n:e}){return`${this.code};`+e}optimizeNodes(){return`${this.code}`?this:void 0}optimizeNames(e,t){return this.code=j(this.code,e,t),this}get names(){return this.code instanceof r._CodeOrName?this.code.names:{}}},h=class extends s{constructor(e=[]){super(),this.nodes=e}render(e){return this.nodes.reduce((t,n)=>t+n.render(e),``)}optimizeNodes(){let{nodes:e}=this,t=e.length;for(;t--;){let n=e[t].optimizeNodes();Array.isArray(n)?e.splice(t,1,...n):n?e[t]=n:e.splice(t,1)}return e.length>0?this:void 0}optimizeNames(e,t){let{nodes:n}=this,r=n.length;for(;r--;){let i=n[r];i.optimizeNames(e,t)||(M(e,i.names),n.splice(r,1))}return n.length>0?this:void 0}get names(){return this.nodes.reduce((e,t)=>k(e,t.names),{})}},g=class extends h{render(e){return`{`+e._n+super.render(e)+`}`+e._n}},_=class extends h{},v=class extends g{};v.kind=`else`;var y=class e extends g{constructor(e,t){super(t),this.condition=e}render(e){let t=`if(${this.condition})`+super.render(e);return this.else&&(t+=`else `+this.else.render(e)),t}optimizeNodes(){super.optimizeNodes();let t=this.condition;if(t===!0)return this.nodes;let n=this.else;if(n){let e=n.optimizeNodes();n=this.else=Array.isArray(e)?new v(e):e}if(n)return t===!1?n instanceof e?n:n.nodes:this.nodes.length?this:new e(N(t),n instanceof e?[n]:n.nodes);if(!(t===!1||!this.nodes.length))return this}optimizeNames(e,t){if(this.else=this.else?.optimizeNames(e,t),super.optimizeNames(e,t)||this.else)return this.condition=j(this.condition,e,t),this}get names(){let e=super.names;return A(e,this.condition),this.else&&k(e,this.else.names),e}};y.kind=`if`;var b=class extends g{};b.kind=`for`;var x=class extends b{constructor(e){super(),this.iteration=e}render(e){return`for(${this.iteration})`+super.render(e)}optimizeNames(e,t){if(super.optimizeNames(e,t))return this.iteration=j(this.iteration,e,t),this}get names(){return k(super.names,this.iteration.names)}},S=class extends b{constructor(e,t,n,r){super(),this.varKind=e,this.name=t,this.from=n,this.to=r}render(e){let t=e.es5?i.varKinds.var:this.varKind,{name:n,from:r,to:a}=this;return`for(${t} ${n}=${r}; ${n}<${a}; ${n}++)`+super.render(e)}get names(){return A(A(super.names,this.from),this.to)}},C=class extends b{constructor(e,t,n,r){super(),this.loop=e,this.varKind=t,this.name=n,this.iterable=r}render(e){return`for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})`+super.render(e)}optimizeNames(e,t){if(super.optimizeNames(e,t))return this.iterable=j(this.iterable,e,t),this}get names(){return k(super.names,this.iterable.names)}},w=class extends g{constructor(e,t,n){super(),this.name=e,this.args=t,this.async=n}render(e){return`${this.async?`async `:``}function ${this.name}(${this.args})`+super.render(e)}};w.kind=`func`;var T=class extends h{render(e){return`return `+super.render(e)}};T.kind=`return`;var E=class extends g{render(e){let t=`try`+super.render(e);return this.catch&&(t+=this.catch.render(e)),this.finally&&(t+=this.finally.render(e)),t}optimizeNodes(){var e,t;return super.optimizeNodes(),(e=this.catch)==null||e.optimizeNodes(),(t=this.finally)==null||t.optimizeNodes(),this}optimizeNames(e,t){var n,r;return super.optimizeNames(e,t),(n=this.catch)==null||n.optimizeNames(e,t),(r=this.finally)==null||r.optimizeNames(e,t),this}get names(){let e=super.names;return this.catch&&k(e,this.catch.names),this.finally&&k(e,this.finally.names),e}},D=class extends g{constructor(e){super(),this.error=e}render(e){return`catch(${this.error})`+super.render(e)}};D.kind=`catch`;var O=class extends g{render(e){return`finally`+super.render(e)}};O.kind=`finally`,e.CodeGen=class{constructor(e,t={}){this._values={},this._blockStarts=[],this._constants={},this.opts={...t,_n:t.lines?`
2
- `:``},this._extScope=e,this._scope=new i.Scope({parent:e}),this._nodes=[new _]}toString(){return this._root.render(this.opts)}name(e){return this._scope.name(e)}scopeName(e){return this._extScope.name(e)}scopeValue(e,t){let n=this._extScope.value(e,t);return(this._values[n.prefix]||(this._values[n.prefix]=new Set)).add(n),n}getScopeValue(e,t){return this._extScope.getValue(e,t)}scopeRefs(e){return this._extScope.scopeRefs(e,this._values)}scopeCode(){return this._extScope.scopeCode(this._values)}_def(e,t,n,r){let i=this._scope.toName(t);return n!==void 0&&r&&(this._constants[i.str]=n),this._leafNode(new c(e,i,n)),i}const(e,t,n){return this._def(i.varKinds.const,e,t,n)}let(e,t,n){return this._def(i.varKinds.let,e,t,n)}var(e,t,n){return this._def(i.varKinds.var,e,t,n)}assign(e,t,n){return this._leafNode(new l(e,t,n))}add(t,n){return this._leafNode(new u(t,e.operators.ADD,n))}code(e){return typeof e==`function`?e():e!==r.nil&&this._leafNode(new m(e)),this}object(...e){let t=[`{`];for(let[n,i]of e)t.length>1&&t.push(`,`),t.push(n),(n!==i||this.opts.es5)&&(t.push(`:`),(0,r.addCodeArg)(t,i));return t.push(`}`),new r._Code(t)}if(e,t,n){if(this._blockNode(new y(e)),t&&n)this.code(t).else().code(n).endIf();else if(t)this.code(t).endIf();else if(n)throw Error(`CodeGen: "else" body without "then" body`);return this}elseIf(e){return this._elseNode(new y(e))}else(){return this._elseNode(new v)}endIf(){return this._endBlockNode(y,v)}_for(e,t){return this._blockNode(e),t&&this.code(t).endFor(),this}for(e,t){return this._for(new x(e),t)}forRange(e,t,n,r,a=this.opts.es5?i.varKinds.var:i.varKinds.let){let o=this._scope.toName(e);return this._for(new S(a,o,t,n),()=>r(o))}forOf(e,t,n,a=i.varKinds.const){let o=this._scope.toName(e);if(this.opts.es5){let e=t instanceof r.Name?t:this.var(`_arr`,t);return this.forRange(`_i`,0,(0,r._)`${e}.length`,t=>{this.var(o,(0,r._)`${e}[${t}]`),n(o)})}return this._for(new C(`of`,a,o,t),()=>n(o))}forIn(e,t,n,a=this.opts.es5?i.varKinds.var:i.varKinds.const){if(this.opts.ownProperties)return this.forOf(e,(0,r._)`Object.keys(${t})`,n);let o=this._scope.toName(e);return this._for(new C(`in`,a,o,t),()=>n(o))}endFor(){return this._endBlockNode(b)}label(e){return this._leafNode(new d(e))}break(e){return this._leafNode(new f(e))}return(e){let t=new T;if(this._blockNode(t),this.code(e),t.nodes.length!==1)throw Error(`CodeGen: "return" should have one node`);return this._endBlockNode(T)}try(e,t,n){if(!t&&!n)throw Error(`CodeGen: "try" without "catch" and "finally"`);let r=new E;if(this._blockNode(r),this.code(e),t){let e=this.name(`e`);this._currNode=r.catch=new D(e),t(e)}return n&&(this._currNode=r.finally=new O,this.code(n)),this._endBlockNode(D,O)}throw(e){return this._leafNode(new p(e))}block(e,t){return this._blockStarts.push(this._nodes.length),e&&this.code(e).endBlock(t),this}endBlock(e){let t=this._blockStarts.pop();if(t===void 0)throw Error(`CodeGen: not in self-balancing block`);let n=this._nodes.length-t;if(n<0||e!==void 0&&n!==e)throw Error(`CodeGen: wrong number of nodes: ${n} vs ${e} expected`);return this._nodes.length=t,this}func(e,t=r.nil,n,i){return this._blockNode(new w(e,t,n)),i&&this.code(i).endFunc(),this}endFunc(){return this._endBlockNode(w)}optimize(e=1){for(;e-->0;)this._root.optimizeNodes(),this._root.optimizeNames(this._root.names,this._constants)}_leafNode(e){return this._currNode.nodes.push(e),this}_blockNode(e){this._currNode.nodes.push(e),this._nodes.push(e)}_endBlockNode(e,t){let n=this._currNode;if(n instanceof e||t&&n instanceof t)return this._nodes.pop(),this;throw Error(`CodeGen: not in block "${t?`${e.kind}/${t.kind}`:e.kind}"`)}_elseNode(e){let t=this._currNode;if(!(t instanceof y))throw Error(`CodeGen: "else" without "if"`);return this._currNode=t.else=e,this}get _root(){return this._nodes[0]}get _currNode(){let e=this._nodes;return e[e.length-1]}set _currNode(e){let t=this._nodes;t[t.length-1]=e}};function k(e,t){for(let n in t)e[n]=(e[n]||0)+(t[n]||0);return e}function A(e,t){return t instanceof r._CodeOrName?k(e,t.names):e}function j(e,t,n){if(e instanceof r.Name)return i(e);if(!a(e))return e;return new r._Code(e._items.reduce((e,t)=>(t instanceof r.Name&&(t=i(t)),t instanceof r._Code?e.push(...t._items):e.push(t),e),[]));function i(e){let r=n[e.str];return r===void 0||t[e.str]!==1?e:(delete t[e.str],r)}function a(e){return e instanceof r._Code&&e._items.some(e=>e instanceof r.Name&&t[e.str]===1&&n[e.str]!==void 0)}}function M(e,t){for(let n in t)e[n]=(e[n]||0)-(t[n]||0)}function N(e){return typeof e==`boolean`||typeof e==`number`||e===null?!e:(0,r._)`!${z(e)}`}e.not=N;var P=R(e.operators.AND);function F(...e){return e.reduce(P)}e.and=F;var I=R(e.operators.OR);function L(...e){return e.reduce(I)}e.or=L;function R(e){return(t,n)=>t===r.nil?n:n===r.nil?t:(0,r._)`${z(t)} ${e} ${z(n)}`}function z(e){return e instanceof r.Name?e:(0,r._)`(${e})`}}));export default r();export{r as require_codegen};
1
+ import{__commonJSMin as e}from"../../../../../../../../_virtual/_rolldown/runtime.js";import{require_code as t}from"./code.js";import{require_scope as n}from"./scope.js";var r=e((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.or=e.and=e.not=e.CodeGen=e.operators=e.varKinds=e.ValueScopeName=e.ValueScope=e.Scope=e.Name=e.regexpCode=e.stringify=e.getProperty=e.nil=e.strConcat=e.str=e._=void 0;var r=t(),i=n(),a=t();Object.defineProperty(e,"_",{enumerable:!0,get:function(){return a._}}),Object.defineProperty(e,"str",{enumerable:!0,get:function(){return a.str}}),Object.defineProperty(e,"strConcat",{enumerable:!0,get:function(){return a.strConcat}}),Object.defineProperty(e,"nil",{enumerable:!0,get:function(){return a.nil}}),Object.defineProperty(e,"getProperty",{enumerable:!0,get:function(){return a.getProperty}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return a.stringify}}),Object.defineProperty(e,"regexpCode",{enumerable:!0,get:function(){return a.regexpCode}}),Object.defineProperty(e,"Name",{enumerable:!0,get:function(){return a.Name}});var o=n();Object.defineProperty(e,"Scope",{enumerable:!0,get:function(){return o.Scope}}),Object.defineProperty(e,"ValueScope",{enumerable:!0,get:function(){return o.ValueScope}}),Object.defineProperty(e,"ValueScopeName",{enumerable:!0,get:function(){return o.ValueScopeName}}),Object.defineProperty(e,"varKinds",{enumerable:!0,get:function(){return o.varKinds}}),e.operators={GT:new r._Code(`>`),GTE:new r._Code(`>=`),LT:new r._Code(`<`),LTE:new r._Code(`<=`),EQ:new r._Code(`===`),NEQ:new r._Code(`!==`),NOT:new r._Code(`!`),OR:new r._Code(`||`),AND:new r._Code(`&&`),ADD:new r._Code(`+`)};var s=class{optimizeNodes(){return this}optimizeNames(e,t){return this}},c=class extends s{constructor(e,t,n){super(),this.varKind=e,this.name=t,this.rhs=n}render({es5:e,_n:t}){let n=e?i.varKinds.var:this.varKind,r=this.rhs===void 0?``:` = ${this.rhs}`;return`${n} ${this.name}${r};`+t}optimizeNames(e,t){if(e[this.name.str])return this.rhs&&=j(this.rhs,e,t),this}get names(){return this.rhs instanceof r._CodeOrName?this.rhs.names:{}}},l=class extends s{constructor(e,t,n){super(),this.lhs=e,this.rhs=t,this.sideEffects=n}render({_n:e}){return`${this.lhs} = ${this.rhs};`+e}optimizeNames(e,t){if(!(this.lhs instanceof r.Name&&!e[this.lhs.str]&&!this.sideEffects))return this.rhs=j(this.rhs,e,t),this}get names(){return A(this.lhs instanceof r.Name?{}:{...this.lhs.names},this.rhs)}},u=class extends l{constructor(e,t,n,r){super(e,n,r),this.op=t}render({_n:e}){return`${this.lhs} ${this.op}= ${this.rhs};`+e}},d=class extends s{constructor(e){super(),this.label=e,this.names={}}render({_n:e}){return`${this.label}:`+e}},f=class extends s{constructor(e){super(),this.label=e,this.names={}}render({_n:e}){return`break${this.label?` ${this.label}`:``};`+e}},p=class extends s{constructor(e){super(),this.error=e}render({_n:e}){return`throw ${this.error};`+e}get names(){return this.error.names}},m=class extends s{constructor(e){super(),this.code=e}render({_n:e}){return`${this.code};`+e}optimizeNodes(){return`${this.code}`?this:void 0}optimizeNames(e,t){return this.code=j(this.code,e,t),this}get names(){return this.code instanceof r._CodeOrName?this.code.names:{}}},h=class extends s{constructor(e=[]){super(),this.nodes=e}render(e){return this.nodes.reduce((t,n)=>t+n.render(e),``)}optimizeNodes(){let{nodes:e}=this,t=e.length;for(;t--;){let n=e[t].optimizeNodes();Array.isArray(n)?e.splice(t,1,...n):n?e[t]=n:e.splice(t,1)}return e.length>0?this:void 0}optimizeNames(e,t){let{nodes:n}=this,r=n.length;for(;r--;){let i=n[r];i.optimizeNames(e,t)||(M(e,i.names),n.splice(r,1))}return n.length>0?this:void 0}get names(){return this.nodes.reduce((e,t)=>k(e,t.names),{})}},g=class extends h{render(e){return`{`+e._n+super.render(e)+`}`+e._n}},_=class extends h{},v=class extends g{};v.kind=`else`;var y=class e extends g{constructor(e,t){super(t),this.condition=e}render(e){let t=`if(${this.condition})`+super.render(e);return this.else&&(t+=`else `+this.else.render(e)),t}optimizeNodes(){super.optimizeNodes();let t=this.condition;if(t===!0)return this.nodes;let n=this.else;if(n){let e=n.optimizeNodes();n=this.else=Array.isArray(e)?new v(e):e}if(n)return t===!1?n instanceof e?n:n.nodes:this.nodes.length?this:new e(N(t),n instanceof e?[n]:n.nodes);if(t!==!1&&this.nodes.length)return this}optimizeNames(e,t){if(this.else=this.else?.optimizeNames(e,t),super.optimizeNames(e,t)||this.else)return this.condition=j(this.condition,e,t),this}get names(){let e=super.names;return A(e,this.condition),this.else&&k(e,this.else.names),e}};y.kind=`if`;var b=class extends g{};b.kind=`for`;var x=class extends b{constructor(e){super(),this.iteration=e}render(e){return`for(${this.iteration})`+super.render(e)}optimizeNames(e,t){if(super.optimizeNames(e,t))return this.iteration=j(this.iteration,e,t),this}get names(){return k(super.names,this.iteration.names)}},S=class extends b{constructor(e,t,n,r){super(),this.varKind=e,this.name=t,this.from=n,this.to=r}render(e){let t=e.es5?i.varKinds.var:this.varKind,{name:n,from:r,to:a}=this;return`for(${t} ${n}=${r}; ${n}<${a}; ${n}++)`+super.render(e)}get names(){return A(A(super.names,this.from),this.to)}},C=class extends b{constructor(e,t,n,r){super(),this.loop=e,this.varKind=t,this.name=n,this.iterable=r}render(e){return`for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})`+super.render(e)}optimizeNames(e,t){if(super.optimizeNames(e,t))return this.iterable=j(this.iterable,e,t),this}get names(){return k(super.names,this.iterable.names)}},w=class extends g{constructor(e,t,n){super(),this.name=e,this.args=t,this.async=n}render(e){return`${this.async?`async `:``}function ${this.name}(${this.args})`+super.render(e)}};w.kind=`func`;var T=class extends h{render(e){return`return `+super.render(e)}};T.kind=`return`;var E=class extends g{render(e){let t=`try`+super.render(e);return this.catch&&(t+=this.catch.render(e)),this.finally&&(t+=this.finally.render(e)),t}optimizeNodes(){var e,t;return super.optimizeNodes(),(e=this.catch)==null||e.optimizeNodes(),(t=this.finally)==null||t.optimizeNodes(),this}optimizeNames(e,t){var n,r;return super.optimizeNames(e,t),(n=this.catch)==null||n.optimizeNames(e,t),(r=this.finally)==null||r.optimizeNames(e,t),this}get names(){let e=super.names;return this.catch&&k(e,this.catch.names),this.finally&&k(e,this.finally.names),e}},D=class extends g{constructor(e){super(),this.error=e}render(e){return`catch(${this.error})`+super.render(e)}};D.kind=`catch`;var O=class extends g{render(e){return`finally`+super.render(e)}};O.kind=`finally`,e.CodeGen=class{constructor(e,t={}){this._values={},this._blockStarts=[],this._constants={},this.opts={...t,_n:t.lines?`
2
+ `:``},this._extScope=e,this._scope=new i.Scope({parent:e}),this._nodes=[new _]}toString(){return this._root.render(this.opts)}name(e){return this._scope.name(e)}scopeName(e){return this._extScope.name(e)}scopeValue(e,t){let n=this._extScope.value(e,t);return(this._values[n.prefix]||(this._values[n.prefix]=new Set)).add(n),n}getScopeValue(e,t){return this._extScope.getValue(e,t)}scopeRefs(e){return this._extScope.scopeRefs(e,this._values)}scopeCode(){return this._extScope.scopeCode(this._values)}_def(e,t,n,r){let i=this._scope.toName(t);return n!==void 0&&r&&(this._constants[i.str]=n),this._leafNode(new c(e,i,n)),i}const(e,t,n){return this._def(i.varKinds.const,e,t,n)}let(e,t,n){return this._def(i.varKinds.let,e,t,n)}var(e,t,n){return this._def(i.varKinds.var,e,t,n)}assign(e,t,n){return this._leafNode(new l(e,t,n))}add(t,n){return this._leafNode(new u(t,e.operators.ADD,n))}code(e){return typeof e==`function`?e():e!==r.nil&&this._leafNode(new m(e)),this}object(...e){let t=[`{`];for(let[n,i]of e)t.length>1&&t.push(`,`),t.push(n),(n!==i||this.opts.es5)&&(t.push(`:`),(0,r.addCodeArg)(t,i));return t.push(`}`),new r._Code(t)}if(e,t,n){if(this._blockNode(new y(e)),t&&n)this.code(t).else().code(n).endIf();else if(t)this.code(t).endIf();else if(n)throw Error(`CodeGen: "else" body without "then" body`);return this}elseIf(e){return this._elseNode(new y(e))}else(){return this._elseNode(new v)}endIf(){return this._endBlockNode(y,v)}_for(e,t){return this._blockNode(e),t&&this.code(t).endFor(),this}for(e,t){return this._for(new x(e),t)}forRange(e,t,n,r,a=this.opts.es5?i.varKinds.var:i.varKinds.let){let o=this._scope.toName(e);return this._for(new S(a,o,t,n),()=>r(o))}forOf(e,t,n,a=i.varKinds.const){let o=this._scope.toName(e);if(this.opts.es5){let e=t instanceof r.Name?t:this.var(`_arr`,t);return this.forRange(`_i`,0,(0,r._)`${e}.length`,t=>{this.var(o,(0,r._)`${e}[${t}]`),n(o)})}return this._for(new C(`of`,a,o,t),()=>n(o))}forIn(e,t,n,a=this.opts.es5?i.varKinds.var:i.varKinds.const){if(this.opts.ownProperties)return this.forOf(e,(0,r._)`Object.keys(${t})`,n);let o=this._scope.toName(e);return this._for(new C(`in`,a,o,t),()=>n(o))}endFor(){return this._endBlockNode(b)}label(e){return this._leafNode(new d(e))}break(e){return this._leafNode(new f(e))}return(e){let t=new T;if(this._blockNode(t),this.code(e),t.nodes.length!==1)throw Error(`CodeGen: "return" should have one node`);return this._endBlockNode(T)}try(e,t,n){if(!t&&!n)throw Error(`CodeGen: "try" without "catch" and "finally"`);let r=new E;if(this._blockNode(r),this.code(e),t){let e=this.name(`e`);this._currNode=r.catch=new D(e),t(e)}return n&&(this._currNode=r.finally=new O,this.code(n)),this._endBlockNode(D,O)}throw(e){return this._leafNode(new p(e))}block(e,t){return this._blockStarts.push(this._nodes.length),e&&this.code(e).endBlock(t),this}endBlock(e){let t=this._blockStarts.pop();if(t===void 0)throw Error(`CodeGen: not in self-balancing block`);let n=this._nodes.length-t;if(n<0||e!==void 0&&n!==e)throw Error(`CodeGen: wrong number of nodes: ${n} vs ${e} expected`);return this._nodes.length=t,this}func(e,t=r.nil,n,i){return this._blockNode(new w(e,t,n)),i&&this.code(i).endFunc(),this}endFunc(){return this._endBlockNode(w)}optimize(e=1){for(;e-->0;)this._root.optimizeNodes(),this._root.optimizeNames(this._root.names,this._constants)}_leafNode(e){return this._currNode.nodes.push(e),this}_blockNode(e){this._currNode.nodes.push(e),this._nodes.push(e)}_endBlockNode(e,t){let n=this._currNode;if(n instanceof e||t&&n instanceof t)return this._nodes.pop(),this;throw Error(`CodeGen: not in block "${t?`${e.kind}/${t.kind}`:e.kind}"`)}_elseNode(e){let t=this._currNode;if(!(t instanceof y))throw Error(`CodeGen: "else" without "if"`);return this._currNode=t.else=e,this}get _root(){return this._nodes[0]}get _currNode(){let e=this._nodes;return e[e.length-1]}set _currNode(e){let t=this._nodes;t[t.length-1]=e}};function k(e,t){for(let n in t)e[n]=(e[n]||0)+(t[n]||0);return e}function A(e,t){return t instanceof r._CodeOrName?k(e,t.names):e}function j(e,t,n){return e instanceof r.Name?i(e):a(e)?new r._Code(e._items.reduce((e,t)=>(t instanceof r.Name&&(t=i(t)),t instanceof r._Code?e.push(...t._items):e.push(t),e),[])):e;function i(e){let r=n[e.str];return r===void 0||t[e.str]!==1?e:(delete t[e.str],r)}function a(e){return e instanceof r._Code&&e._items.some(e=>e instanceof r.Name&&t[e.str]===1&&n[e.str]!==void 0)}}function M(e,t){for(let n in t)e[n]=(e[n]||0)-(t[n]||0)}function N(e){return typeof e==`boolean`||typeof e==`number`||e===null?!e:(0,r._)`!${z(e)}`}e.not=N;var P=R(e.operators.AND);function F(...e){return e.reduce(P)}e.and=F;var I=R(e.operators.OR);function L(...e){return e.reduce(I)}e.or=L;function R(e){return(t,n)=>t===r.nil?n:n===r.nil?t:(0,r._)`${z(t)} ${e} ${z(n)}`}function z(e){return e instanceof r.Name?e:(0,r._)`(${e})`}}));export default r();export{r as require_codegen};
@@ -1 +1 @@
1
- import{__commonJSMin as e}from"../../../../../../../_virtual/_rolldown/runtime.js";import{require_codegen as t}from"./codegen/index.js";import{require_util as n}from"./util.js";import{require_names as r}from"./names.js";import{require_resolve as i}from"./resolve.js";import{require_validate as a}from"./validate/index.js";import{require_validation_error as o}from"../runtime/validation_error.js";var s=e((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.resolveSchema=e.getCompilingSchema=e.resolveRef=e.compileSchema=e.SchemaEnv=void 0;var s=t(),c=o(),l=r(),u=i(),d=n(),f=a(),p=class{constructor(e){this.refs={},this.dynamicAnchors={};let t;typeof e.schema==`object`&&(t=e.schema),this.schema=e.schema,this.schemaId=e.schemaId,this.root=e.root||this,this.baseId=e.baseId??(0,u.normalizeId)(t?.[e.schemaId||`$id`]),this.schemaPath=e.schemaPath,this.localRefs=e.localRefs,this.meta=e.meta,this.$async=t?.$async,this.refs={}}};e.SchemaEnv=p;function m(e){let t=_.call(this,e);if(t)return t;let n=(0,u.getFullPath)(this.opts.uriResolver,e.root.baseId),{es5:r,lines:i}=this.opts.code,{ownProperties:a}=this.opts,o=new s.CodeGen(this.scope,{es5:r,lines:i,ownProperties:a}),d;e.$async&&(d=o.scopeValue(`Error`,{ref:c.default,code:(0,s._)`require("ajv/dist/runtime/validation_error").default`}));let p=o.scopeName(`validate`);e.validateName=p;let m={gen:o,allErrors:this.opts.allErrors,data:l.default.data,parentData:l.default.parentData,parentDataProperty:l.default.parentDataProperty,dataNames:[l.default.data],dataPathArr:[s.nil],dataLevel:0,dataTypes:[],definedProperties:new Set,topSchemaRef:o.scopeValue(`schema`,this.opts.code.source===!0?{ref:e.schema,code:(0,s.stringify)(e.schema)}:{ref:e.schema}),validateName:p,ValidationError:d,schema:e.schema,schemaEnv:e,rootId:n,baseId:e.baseId||n,schemaPath:s.nil,errSchemaPath:e.schemaPath||(this.opts.jtd?``:`#`),errorPath:(0,s._)`""`,opts:this.opts,self:this},h;try{this._compilations.add(e),(0,f.validateFunctionCode)(m),o.optimize(this.opts.code.optimize);let t=o.toString();h=`${o.scopeRefs(l.default.scope)}return ${t}`,this.opts.code.process&&(h=this.opts.code.process(h,e));let n=Function(`${l.default.self}`,`${l.default.scope}`,h)(this,this.scope.get());if(this.scope.value(p,{ref:n}),n.errors=null,n.schema=e.schema,n.schemaEnv=e,e.$async&&(n.$async=!0),this.opts.code.source===!0&&(n.source={validateName:p,validateCode:t,scopeValues:o._values}),this.opts.unevaluated){let{props:e,items:t}=m;n.evaluated={props:e instanceof s.Name?void 0:e,items:t instanceof s.Name?void 0:t,dynamicProps:e instanceof s.Name,dynamicItems:t instanceof s.Name},n.source&&(n.source.evaluated=(0,s.stringify)(n.evaluated))}return e.validate=n,e}catch(t){throw delete e.validate,delete e.validateName,h&&this.logger.error(`Error compiling schema, function code:`,h),t}finally{this._compilations.delete(e)}}e.compileSchema=m;function h(e,t,n){n=(0,u.resolveUrl)(this.opts.uriResolver,t,n);let r=e.refs[n];if(r)return r;let i=y.call(this,e,n);if(i===void 0){let r=e.localRefs?.[n],{schemaId:a}=this.opts;r&&(i=new p({schema:r,schemaId:a,root:e,baseId:t}))}if(i!==void 0)return e.refs[n]=g.call(this,i)}e.resolveRef=h;function g(e){return(0,u.inlineRef)(e.schema,this.opts.inlineRefs)?e.schema:e.validate?e:m.call(this,e)}function _(e){for(let t of this._compilations)if(v(t,e))return t}e.getCompilingSchema=_;function v(e,t){return e.schema===t.schema&&e.root===t.root&&e.baseId===t.baseId}function y(e,t){let n;for(;typeof(n=this.refs[t])==`string`;)t=n;return n||this.schemas[t]||b.call(this,e,t)}function b(e,t){let n=this.opts.uriResolver.parse(t),r=(0,u._getFullPath)(this.opts.uriResolver,n),i=(0,u.getFullPath)(this.opts.uriResolver,e.baseId,void 0);if(Object.keys(e.schema).length>0&&r===i)return S.call(this,n,e);let a=(0,u.normalizeId)(r),o=this.refs[a]||this.schemas[a];if(typeof o==`string`){let t=b.call(this,e,o);return typeof t?.schema==`object`?S.call(this,n,t):void 0}if(typeof o?.schema==`object`){if(o.validate||m.call(this,o),a===(0,u.normalizeId)(t)){let{schema:t}=o,{schemaId:n}=this.opts,r=t[n];return r&&(i=(0,u.resolveUrl)(this.opts.uriResolver,i,r)),new p({schema:t,schemaId:n,root:e,baseId:i})}return S.call(this,n,o)}}e.resolveSchema=b;var x=new Set([`properties`,`patternProperties`,`enum`,`dependencies`,`definitions`]);function S(e,{baseId:t,schema:n,root:r}){if(e.fragment?.[0]!==`/`)return;for(let r of e.fragment.slice(1).split(`/`)){if(typeof n==`boolean`)return;let e=n[(0,d.unescapeFragment)(r)];if(e===void 0)return;n=e;let i=typeof n==`object`&&n[this.opts.schemaId];!x.has(r)&&i&&(t=(0,u.resolveUrl)(this.opts.uriResolver,t,i))}let i;if(typeof n!=`boolean`&&n.$ref&&!(0,d.schemaHasRulesButRef)(n,this.RULES)){let e=(0,u.resolveUrl)(this.opts.uriResolver,t,n.$ref);i=b.call(this,r,e)}let{schemaId:a}=this.opts;if(i||=new p({schema:n,schemaId:a,root:r,baseId:t}),i.schema!==i.root.schema)return i}}));export default s();export{s as require_compile};
1
+ import{__commonJSMin as e}from"../../../../../../../_virtual/_rolldown/runtime.js";import{require_codegen as t}from"./codegen/index.js";import{require_validation_error as n}from"../runtime/validation_error.js";import{require_names as r}from"./names.js";import{require_resolve as i}from"./resolve.js";import{require_util as a}from"./util.js";import{require_validate as o}from"./validate/index.js";var s=e((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.resolveSchema=e.getCompilingSchema=e.resolveRef=e.compileSchema=e.SchemaEnv=void 0;var s=t(),c=n(),l=r(),u=i(),d=a(),f=o(),p=class{constructor(e){this.refs={},this.dynamicAnchors={};let t;typeof e.schema==`object`&&(t=e.schema),this.schema=e.schema,this.schemaId=e.schemaId,this.root=e.root||this,this.baseId=e.baseId??(0,u.normalizeId)(t?.[e.schemaId||`$id`]),this.schemaPath=e.schemaPath,this.localRefs=e.localRefs,this.meta=e.meta,this.$async=t?.$async,this.refs={}}};e.SchemaEnv=p;function m(e){let t=_.call(this,e);if(t)return t;let n=(0,u.getFullPath)(this.opts.uriResolver,e.root.baseId),{es5:r,lines:i}=this.opts.code,{ownProperties:a}=this.opts,o=new s.CodeGen(this.scope,{es5:r,lines:i,ownProperties:a}),d;e.$async&&(d=o.scopeValue(`Error`,{ref:c.default,code:(0,s._)`require("ajv/dist/runtime/validation_error").default`}));let p=o.scopeName(`validate`);e.validateName=p;let m={gen:o,allErrors:this.opts.allErrors,data:l.default.data,parentData:l.default.parentData,parentDataProperty:l.default.parentDataProperty,dataNames:[l.default.data],dataPathArr:[s.nil],dataLevel:0,dataTypes:[],definedProperties:new Set,topSchemaRef:o.scopeValue(`schema`,this.opts.code.source===!0?{ref:e.schema,code:(0,s.stringify)(e.schema)}:{ref:e.schema}),validateName:p,ValidationError:d,schema:e.schema,schemaEnv:e,rootId:n,baseId:e.baseId||n,schemaPath:s.nil,errSchemaPath:e.schemaPath||(this.opts.jtd?``:`#`),errorPath:(0,s._)`""`,opts:this.opts,self:this},h;try{this._compilations.add(e),(0,f.validateFunctionCode)(m),o.optimize(this.opts.code.optimize);let t=o.toString();h=`${o.scopeRefs(l.default.scope)}return ${t}`,this.opts.code.process&&(h=this.opts.code.process(h,e));let n=Function(`${l.default.self}`,`${l.default.scope}`,h)(this,this.scope.get());if(this.scope.value(p,{ref:n}),n.errors=null,n.schema=e.schema,n.schemaEnv=e,e.$async&&(n.$async=!0),this.opts.code.source===!0&&(n.source={validateName:p,validateCode:t,scopeValues:o._values}),this.opts.unevaluated){let{props:e,items:t}=m;n.evaluated={props:e instanceof s.Name?void 0:e,items:t instanceof s.Name?void 0:t,dynamicProps:e instanceof s.Name,dynamicItems:t instanceof s.Name},n.source&&(n.source.evaluated=(0,s.stringify)(n.evaluated))}return e.validate=n,e}catch(t){throw delete e.validate,delete e.validateName,h&&this.logger.error(`Error compiling schema, function code:`,h),t}finally{this._compilations.delete(e)}}e.compileSchema=m;function h(e,t,n){n=(0,u.resolveUrl)(this.opts.uriResolver,t,n);let r=e.refs[n];if(r)return r;let i=y.call(this,e,n);if(i===void 0){let r=e.localRefs?.[n],{schemaId:a}=this.opts;r&&(i=new p({schema:r,schemaId:a,root:e,baseId:t}))}if(i!==void 0)return e.refs[n]=g.call(this,i)}e.resolveRef=h;function g(e){return(0,u.inlineRef)(e.schema,this.opts.inlineRefs)?e.schema:e.validate?e:m.call(this,e)}function _(e){for(let t of this._compilations)if(v(t,e))return t}e.getCompilingSchema=_;function v(e,t){return e.schema===t.schema&&e.root===t.root&&e.baseId===t.baseId}function y(e,t){let n;for(;typeof(n=this.refs[t])==`string`;)t=n;return n||this.schemas[t]||b.call(this,e,t)}function b(e,t){let n=this.opts.uriResolver.parse(t),r=(0,u._getFullPath)(this.opts.uriResolver,n),i=(0,u.getFullPath)(this.opts.uriResolver,e.baseId,void 0);if(Object.keys(e.schema).length>0&&r===i)return S.call(this,n,e);let a=(0,u.normalizeId)(r),o=this.refs[a]||this.schemas[a];if(typeof o==`string`){let t=b.call(this,e,o);return typeof t?.schema==`object`?S.call(this,n,t):void 0}if(typeof o?.schema==`object`){if(o.validate||m.call(this,o),a===(0,u.normalizeId)(t)){let{schema:t}=o,{schemaId:n}=this.opts,r=t[n];return r&&(i=(0,u.resolveUrl)(this.opts.uriResolver,i,r)),new p({schema:t,schemaId:n,root:e,baseId:i})}return S.call(this,n,o)}}e.resolveSchema=b;var x=new Set([`properties`,`patternProperties`,`enum`,`dependencies`,`definitions`]);function S(e,{baseId:t,schema:n,root:r}){if(e.fragment?.[0]!==`/`)return;for(let r of e.fragment.slice(1).split(`/`)){if(typeof n==`boolean`)return;let e=n[(0,d.unescapeFragment)(r)];if(e===void 0)return;n=e;let i=typeof n==`object`&&n[this.opts.schemaId];!x.has(r)&&i&&(t=(0,u.resolveUrl)(this.opts.uriResolver,t,i))}let i;if(typeof n!=`boolean`&&n.$ref&&!(0,d.schemaHasRulesButRef)(n,this.RULES)){let e=(0,u.resolveUrl)(this.opts.uriResolver,t,n.$ref);i=b.call(this,r,e)}let{schemaId:a}=this.opts;if(i||=new p({schema:n,schemaId:a,root:r,baseId:t}),i.schema!==i.root.schema)return i}}));export default s();export{s as require_compile};
@@ -1 +1 @@
1
- import{__commonJSMin as e}from"../../../../../../../_virtual/_rolldown/runtime.js";import{require_code as t}from"./codegen/code.js";import{require_codegen as n}from"./codegen/index.js";var r=e((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.checkStrictMode=e.getErrorPath=e.Type=e.useFunc=e.setEvaluated=e.evaluatedPropsToName=e.mergeEvaluated=e.eachItem=e.unescapeJsonPointer=e.escapeJsonPointer=e.escapeFragment=e.unescapeFragment=e.schemaRefOrVal=e.schemaHasRulesButRef=e.schemaHasRules=e.checkUnknownRules=e.alwaysValidSchema=e.toHash=void 0;var r=n(),i=t();function a(e){let t={};for(let n of e)t[n]=!0;return t}e.toHash=a;function o(e,t){return typeof t==`boolean`?t:Object.keys(t).length===0?!0:(s(e,t),!c(t,e.self.RULES.all))}e.alwaysValidSchema=o;function s(e,t=e.schema){let{opts:n,self:r}=e;if(!n.strictSchema||typeof t==`boolean`)return;let i=r.RULES.keywords;for(let n in t)i[n]||C(e,`unknown keyword: "${n}"`)}e.checkUnknownRules=s;function c(e,t){if(typeof e==`boolean`)return!e;for(let n in e)if(t[n])return!0;return!1}e.schemaHasRules=c;function l(e,t){if(typeof e==`boolean`)return!e;for(let n in e)if(n!==`$ref`&&t.all[n])return!0;return!1}e.schemaHasRulesButRef=l;function u({topSchemaRef:e,schemaPath:t},n,i,a){if(!a){if(typeof n==`number`||typeof n==`boolean`)return n;if(typeof n==`string`)return(0,r._)`${n}`}return(0,r._)`${e}${t}${(0,r.getProperty)(i)}`}e.schemaRefOrVal=u;function d(e){return m(decodeURIComponent(e))}e.unescapeFragment=d;function f(e){return encodeURIComponent(p(e))}e.escapeFragment=f;function p(e){return typeof e==`number`?`${e}`:e.replace(/~/g,`~0`).replace(/\//g,`~1`)}e.escapeJsonPointer=p;function m(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}e.unescapeJsonPointer=m;function h(e,t){if(Array.isArray(e))for(let n of e)t(n);else t(e)}e.eachItem=h;function g({mergeNames:e,mergeToName:t,mergeValues:n,resultToName:i}){return(a,o,s,c)=>{let l=s===void 0?o:s instanceof r.Name?(o instanceof r.Name?e(a,o,s):t(a,o,s),s):o instanceof r.Name?(t(a,s,o),o):n(o,s);return c===r.Name&&!(l instanceof r.Name)?i(a,l):l}}e.mergeEvaluated={props:g({mergeNames:(e,t,n)=>e.if((0,r._)`${n} !== true && ${t} !== undefined`,()=>{e.if((0,r._)`${t} === true`,()=>e.assign(n,!0),()=>e.assign(n,(0,r._)`${n} || {}`).code((0,r._)`Object.assign(${n}, ${t})`))}),mergeToName:(e,t,n)=>e.if((0,r._)`${n} !== true`,()=>{t===!0?e.assign(n,!0):(e.assign(n,(0,r._)`${n} || {}`),v(e,n,t))}),mergeValues:(e,t)=>e===!0||{...e,...t},resultToName:_}),items:g({mergeNames:(e,t,n)=>e.if((0,r._)`${n} !== true && ${t} !== undefined`,()=>e.assign(n,(0,r._)`${t} === true ? true : ${n} > ${t} ? ${n} : ${t}`)),mergeToName:(e,t,n)=>e.if((0,r._)`${n} !== true`,()=>e.assign(n,t===!0||(0,r._)`${n} > ${t} ? ${n} : ${t}`)),mergeValues:(e,t)=>e===!0||Math.max(e,t),resultToName:(e,t)=>e.var(`items`,t)})};function _(e,t){if(t===!0)return e.var(`props`,!0);let n=e.var(`props`,(0,r._)`{}`);return t!==void 0&&v(e,n,t),n}e.evaluatedPropsToName=_;function v(e,t,n){Object.keys(n).forEach(n=>e.assign((0,r._)`${t}${(0,r.getProperty)(n)}`,!0))}e.setEvaluated=v;var y={};function b(e,t){return e.scopeValue(`func`,{ref:t,code:y[t.code]||(y[t.code]=new i._Code(t.code))})}e.useFunc=b;var x;(function(e){e[e.Num=0]=`Num`,e[e.Str=1]=`Str`})(x||(e.Type=x={}));function S(e,t,n){if(e instanceof r.Name){let i=t===x.Num;return n?i?(0,r._)`"[" + ${e} + "]"`:(0,r._)`"['" + ${e} + "']"`:i?(0,r._)`"/" + ${e}`:(0,r._)`"/" + ${e}.replace(/~/g, "~0").replace(/\\//g, "~1")`}return n?(0,r.getProperty)(e).toString():`/`+p(e)}e.getErrorPath=S;function C(e,t,n=e.opts.strictSchema){if(n){if(t=`strict mode: ${t}`,n===!0)throw Error(t);e.self.logger.warn(t)}}e.checkStrictMode=C}));export default r();export{r as require_util};
1
+ import{__commonJSMin as e}from"../../../../../../../_virtual/_rolldown/runtime.js";import{require_codegen as t}from"./codegen/index.js";import{require_code as n}from"./codegen/code.js";var r=e((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.checkStrictMode=e.getErrorPath=e.Type=e.useFunc=e.setEvaluated=e.evaluatedPropsToName=e.mergeEvaluated=e.eachItem=e.unescapeJsonPointer=e.escapeJsonPointer=e.escapeFragment=e.unescapeFragment=e.schemaRefOrVal=e.schemaHasRulesButRef=e.schemaHasRules=e.checkUnknownRules=e.alwaysValidSchema=e.toHash=void 0;var r=t(),i=n();function a(e){let t={};for(let n of e)t[n]=!0;return t}e.toHash=a;function o(e,t){return typeof t==`boolean`?t:Object.keys(t).length===0||(s(e,t),!c(t,e.self.RULES.all))}e.alwaysValidSchema=o;function s(e,t=e.schema){let{opts:n,self:r}=e;if(!n.strictSchema||typeof t==`boolean`)return;let i=r.RULES.keywords;for(let n in t)i[n]||C(e,`unknown keyword: "${n}"`)}e.checkUnknownRules=s;function c(e,t){if(typeof e==`boolean`)return!e;for(let n in e)if(t[n])return!0;return!1}e.schemaHasRules=c;function l(e,t){if(typeof e==`boolean`)return!e;for(let n in e)if(n!==`$ref`&&t.all[n])return!0;return!1}e.schemaHasRulesButRef=l;function u({topSchemaRef:e,schemaPath:t},n,i,a){if(!a){if(typeof n==`number`||typeof n==`boolean`)return n;if(typeof n==`string`)return(0,r._)`${n}`}return(0,r._)`${e}${t}${(0,r.getProperty)(i)}`}e.schemaRefOrVal=u;function d(e){return m(decodeURIComponent(e))}e.unescapeFragment=d;function f(e){return encodeURIComponent(p(e))}e.escapeFragment=f;function p(e){return typeof e==`number`?`${e}`:e.replace(/~/g,`~0`).replace(/\//g,`~1`)}e.escapeJsonPointer=p;function m(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}e.unescapeJsonPointer=m;function h(e,t){if(Array.isArray(e))for(let n of e)t(n);else t(e)}e.eachItem=h;function g({mergeNames:e,mergeToName:t,mergeValues:n,resultToName:i}){return(a,o,s,c)=>{let l=s===void 0?o:s instanceof r.Name?(o instanceof r.Name?e(a,o,s):t(a,o,s),s):o instanceof r.Name?(t(a,s,o),o):n(o,s);return c===r.Name&&!(l instanceof r.Name)?i(a,l):l}}e.mergeEvaluated={props:g({mergeNames:(e,t,n)=>e.if((0,r._)`${n} !== true && ${t} !== undefined`,()=>{e.if((0,r._)`${t} === true`,()=>e.assign(n,!0),()=>e.assign(n,(0,r._)`${n} || {}`).code((0,r._)`Object.assign(${n}, ${t})`))}),mergeToName:(e,t,n)=>e.if((0,r._)`${n} !== true`,()=>{t===!0?e.assign(n,!0):(e.assign(n,(0,r._)`${n} || {}`),v(e,n,t))}),mergeValues:(e,t)=>e===!0||{...e,...t},resultToName:_}),items:g({mergeNames:(e,t,n)=>e.if((0,r._)`${n} !== true && ${t} !== undefined`,()=>e.assign(n,(0,r._)`${t} === true ? true : ${n} > ${t} ? ${n} : ${t}`)),mergeToName:(e,t,n)=>e.if((0,r._)`${n} !== true`,()=>e.assign(n,t===!0||(0,r._)`${n} > ${t} ? ${n} : ${t}`)),mergeValues:(e,t)=>e===!0||Math.max(e,t),resultToName:(e,t)=>e.var(`items`,t)})};function _(e,t){if(t===!0)return e.var(`props`,!0);let n=e.var(`props`,(0,r._)`{}`);return t!==void 0&&v(e,n,t),n}e.evaluatedPropsToName=_;function v(e,t,n){Object.keys(n).forEach(n=>e.assign((0,r._)`${t}${(0,r.getProperty)(n)}`,!0))}e.setEvaluated=v;var y={};function b(e,t){return e.scopeValue(`func`,{ref:t,code:y[t.code]||(y[t.code]=new i._Code(t.code))})}e.useFunc=b;var x;(function(e){e[e.Num=0]=`Num`,e[e.Str=1]=`Str`})(x||(e.Type=x={}));function S(e,t,n){if(e instanceof r.Name){let i=t===x.Num;return n?i?(0,r._)`"[" + ${e} + "]"`:(0,r._)`"['" + ${e} + "']"`:i?(0,r._)`"/" + ${e}`:(0,r._)`"/" + ${e}.replace(/~/g, "~0").replace(/\\//g, "~1")`}return n?(0,r.getProperty)(e).toString():`/`+p(e)}e.getErrorPath=S;function C(e,t,n=e.opts.strictSchema){if(n){if(t=`strict mode: ${t}`,n===!0)throw Error(t);e.self.logger.warn(t)}}e.checkStrictMode=C}));export default r();export{r as require_util};
@@ -1 +1 @@
1
- import{__commonJSMin as e}from"../../../../../../../../_virtual/_rolldown/runtime.js";import{require_codegen as t}from"../codegen/index.js";import{require_names as n}from"../names.js";import{require_errors as r}from"../errors.js";var i=e((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.boolOrEmptySchema=e.topBoolOrEmptySchema=void 0;var i=r(),a=t(),o=n(),s={message:`boolean schema is false`};function c(e){let{gen:t,schema:n,validateName:r}=e;n===!1?u(e,!1):typeof n==`object`&&n.$async===!0?t.return(o.default.data):(t.assign((0,a._)`${r}.errors`,null),t.return(!0))}e.topBoolOrEmptySchema=c;function l(e,t){let{gen:n,schema:r}=e;r===!1?(n.var(t,!1),u(e)):n.var(t,!0)}e.boolOrEmptySchema=l;function u(e,t){let{gen:n,data:r}=e,a={gen:n,keyword:`false schema`,data:r,schema:!1,schemaCode:!1,schemaValue:!1,params:{},it:e};(0,i.reportError)(a,s,void 0,t)}}));export default i();export{i as require_boolSchema};
1
+ import{__commonJSMin as e}from"../../../../../../../../_virtual/_rolldown/runtime.js";import{require_errors as t}from"../errors.js";import{require_codegen as n}from"../codegen/index.js";import{require_names as r}from"../names.js";var i=e((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.boolOrEmptySchema=e.topBoolOrEmptySchema=void 0;var i=t(),a=n(),o=r(),s={message:`boolean schema is false`};function c(e){let{gen:t,schema:n,validateName:r}=e;n===!1?u(e,!1):typeof n==`object`&&n.$async===!0?t.return(o.default.data):(t.assign((0,a._)`${r}.errors`,null),t.return(!0))}e.topBoolOrEmptySchema=c;function l(e,t){let{gen:n,schema:r}=e;r===!1?(n.var(t,!1),u(e)):n.var(t,!0)}e.boolOrEmptySchema=l;function u(e,t){let{gen:n,data:r}=e,a={gen:n,keyword:`false schema`,data:r,schema:!1,schemaCode:!1,schemaValue:!1,params:{},it:e};(0,i.reportError)(a,s,void 0,t)}}));export default i();export{i as require_boolSchema};
@@ -1,4 +1,4 @@
1
- import{__commonJSMin as e}from"../../../../../../../../_virtual/_rolldown/runtime.js";import{require_codegen as t}from"../codegen/index.js";import{require_util as n}from"../util.js";import{require_errors as r}from"../errors.js";import{require_rules as i}from"../rules.js";import{require_applicability as a}from"./applicability.js";var o=e((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.reportTypeError=e.checkDataTypes=e.checkDataType=e.coerceAndCheckDataType=e.getJSONTypes=e.getSchemaTypes=e.DataType=void 0;var o=i(),s=a(),c=r(),l=t(),u=n(),d;(function(e){e[e.Correct=0]=`Correct`,e[e.Wrong=1]=`Wrong`})(d||(e.DataType=d={}));function f(e){let t=p(e.type);if(t.includes(`null`)){if(e.nullable===!1)throw Error(`type: null contradicts nullable: false`)}else{if(!t.length&&e.nullable!==void 0)throw Error(`"nullable" cannot be used without "type"`);e.nullable===!0&&t.push(`null`)}return t}e.getSchemaTypes=f;function p(e){let t=Array.isArray(e)?e:e?[e]:[];if(t.every(o.isJSONType))return t;throw Error(`type must be JSONType or JSONType[]: `+t.join(`,`))}e.getJSONTypes=p;function m(e,t){let{gen:n,data:r,opts:i}=e,a=g(t,i.coerceTypes),o=t.length>0&&!(a.length===0&&t.length===1&&(0,s.schemaHasRulesForType)(e,t[0]));if(o){let o=b(t,r,i.strictNumbers,d.Wrong);n.if(o,()=>{a.length?_(e,t,a):S(e)})}return o}e.coerceAndCheckDataType=m;var h=new Set([`string`,`number`,`integer`,`boolean`,`null`]);function g(e,t){return t?e.filter(e=>h.has(e)||t===`array`&&e===`array`):[]}function _(e,t,n){let{gen:r,data:i,opts:a}=e,o=r.let(`dataType`,(0,l._)`typeof ${i}`),s=r.let(`coerced`,(0,l._)`undefined`);a.coerceTypes===`array`&&r.if((0,l._)`${o} == 'object' && Array.isArray(${i}) && ${i}.length == 1`,()=>r.assign(i,(0,l._)`${i}[0]`).assign(o,(0,l._)`typeof ${i}`).if(b(t,i,a.strictNumbers),()=>r.assign(s,i))),r.if((0,l._)`${s} !== undefined`);for(let e of n)(h.has(e)||e===`array`&&a.coerceTypes===`array`)&&c(e);r.else(),S(e),r.endIf(),r.if((0,l._)`${s} !== undefined`,()=>{r.assign(i,s),v(e,s)});function c(e){switch(e){case`string`:r.elseIf((0,l._)`${o} == "number" || ${o} == "boolean"`).assign(s,(0,l._)`"" + ${i}`).elseIf((0,l._)`${i} === null`).assign(s,(0,l._)`""`);return;case`number`:r.elseIf((0,l._)`${o} == "boolean" || ${i} === null
1
+ import{__commonJSMin as e}from"../../../../../../../../_virtual/_rolldown/runtime.js";import{require_rules as t}from"../rules.js";import{require_applicability as n}from"./applicability.js";import{require_errors as r}from"../errors.js";import{require_codegen as i}from"../codegen/index.js";import{require_util as a}from"../util.js";var o=e((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.reportTypeError=e.checkDataTypes=e.checkDataType=e.coerceAndCheckDataType=e.getJSONTypes=e.getSchemaTypes=e.DataType=void 0;var o=t(),s=n(),c=r(),l=i(),u=a(),d;(function(e){e[e.Correct=0]=`Correct`,e[e.Wrong=1]=`Wrong`})(d||(e.DataType=d={}));function f(e){let t=p(e.type);if(t.includes(`null`)){if(e.nullable===!1)throw Error(`type: null contradicts nullable: false`)}else{if(!t.length&&e.nullable!==void 0)throw Error(`"nullable" cannot be used without "type"`);e.nullable===!0&&t.push(`null`)}return t}e.getSchemaTypes=f;function p(e){let t=Array.isArray(e)?e:e?[e]:[];if(t.every(o.isJSONType))return t;throw Error(`type must be JSONType or JSONType[]: `+t.join(`,`))}e.getJSONTypes=p;function m(e,t){let{gen:n,data:r,opts:i}=e,a=g(t,i.coerceTypes),o=t.length>0&&!(a.length===0&&t.length===1&&(0,s.schemaHasRulesForType)(e,t[0]));if(o){let o=b(t,r,i.strictNumbers,d.Wrong);n.if(o,()=>{a.length?_(e,t,a):S(e)})}return o}e.coerceAndCheckDataType=m;var h=new Set([`string`,`number`,`integer`,`boolean`,`null`]);function g(e,t){return t?e.filter(e=>h.has(e)||t===`array`&&e===`array`):[]}function _(e,t,n){let{gen:r,data:i,opts:a}=e,o=r.let(`dataType`,(0,l._)`typeof ${i}`),s=r.let(`coerced`,(0,l._)`undefined`);a.coerceTypes===`array`&&r.if((0,l._)`${o} == 'object' && Array.isArray(${i}) && ${i}.length == 1`,()=>r.assign(i,(0,l._)`${i}[0]`).assign(o,(0,l._)`typeof ${i}`).if(b(t,i,a.strictNumbers),()=>r.assign(s,i))),r.if((0,l._)`${s} !== undefined`);for(let e of n)(h.has(e)||e===`array`&&a.coerceTypes===`array`)&&c(e);r.else(),S(e),r.endIf(),r.if((0,l._)`${s} !== undefined`,()=>{r.assign(i,s),v(e,s)});function c(e){switch(e){case`string`:r.elseIf((0,l._)`${o} == "number" || ${o} == "boolean"`).assign(s,(0,l._)`"" + ${i}`).elseIf((0,l._)`${i} === null`).assign(s,(0,l._)`""`);return;case`number`:r.elseIf((0,l._)`${o} == "boolean" || ${i} === null
2
2
  || (${o} == "string" && ${i} && ${i} == +${i})`).assign(s,(0,l._)`+${i}`);return;case`integer`:r.elseIf((0,l._)`${o} === "boolean" || ${i} === null
3
3
  || (${o} === "string" && ${i} && ${i} == +${i} && !(${i} % 1))`).assign(s,(0,l._)`+${i}`);return;case`boolean`:r.elseIf((0,l._)`${i} === "false" || ${i} === 0 || ${i} === null`).assign(s,!1).elseIf((0,l._)`${i} === "true" || ${i} === 1`).assign(s,!0);return;case`null`:r.elseIf((0,l._)`${i} === "" || ${i} === 0 || ${i} === false`),r.assign(s,null);return;case`array`:r.elseIf((0,l._)`${o} === "string" || ${o} === "number"
4
4
  || ${o} === "boolean" || ${i} === null`).assign(s,(0,l._)`[${i}]`)}}}function v({gen:e,parentData:t,parentDataProperty:n},r){e.if((0,l._)`${t} !== undefined`,()=>e.assign((0,l._)`${t}[${n}]`,r))}function y(e,t,n,r=d.Correct){let i=r===d.Correct?l.operators.EQ:l.operators.NEQ,a;switch(e){case`null`:return(0,l._)`${t} ${i} null`;case`array`:a=(0,l._)`Array.isArray(${t})`;break;case`object`:a=(0,l._)`${t} && typeof ${t} == "object" && !Array.isArray(${t})`;break;case`integer`:a=o((0,l._)`!(${t} % 1) && !isNaN(${t})`);break;case`number`:a=o();break;default:return(0,l._)`typeof ${t} ${i} ${e}`}return r===d.Correct?a:(0,l.not)(a);function o(e=l.nil){return(0,l.and)((0,l._)`typeof ${t} == "number"`,e,n?(0,l._)`isFinite(${t})`:l.nil)}}e.checkDataType=y;function b(e,t,n,r){if(e.length===1)return y(e[0],t,n,r);let i,a=(0,u.toHash)(e);if(a.array&&a.object){let e=(0,l._)`typeof ${t} != "object"`;i=a.null?e:(0,l._)`!${t} || ${e}`,delete a.null,delete a.array,delete a.object}else i=l.nil;a.number&&delete a.integer;for(let e in a)i=(0,l.and)(i,y(e,t,n,r));return i}e.checkDataTypes=b;var x={message:({schema:e})=>`must be ${e}`,params:({schema:e,schemaValue:t})=>typeof e==`string`?(0,l._)`{type: ${e}}`:(0,l._)`{type: ${t}}`};function S(e){let t=C(e);(0,c.reportError)(t,x)}e.reportTypeError=S;function C(e){let{gen:t,data:n,schema:r}=e,i=(0,u.schemaRefOrVal)(e,r,`type`);return{gen:t,keyword:`type`,data:n,schema:r.type,schemaCode:i,schemaValue:i,parentSchema:r,params:{},it:e}}}));export default o();export{o as require_dataType};