@taprootio/espalier 7.1.1 → 7.3.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 (102) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/custom-elements.json +11675 -20250
  3. package/dist/badge/esp-badge.d.ts +7 -0
  4. package/dist/badge/esp-badge.js +11 -5
  5. package/dist/breadcrumbs/breadcrumb-separators.d.ts +4 -0
  6. package/dist/breadcrumbs/breadcrumb-separators.js +1 -0
  7. package/dist/breadcrumbs/esp-breadcrumb.d.ts +13 -14
  8. package/dist/breadcrumbs/esp-breadcrumb.js +6 -7
  9. package/dist/breadcrumbs/esp-breadcrumbs.d.ts +16 -9
  10. package/dist/breadcrumbs/esp-breadcrumbs.js +9 -6
  11. package/dist/button/paint-registration.js +1 -0
  12. package/dist/cli/theme-check.js +2 -2
  13. package/dist/font-picker/esp-font-picker.d.ts +11 -14
  14. package/dist/font-picker/esp-font-picker.js +5 -5
  15. package/dist/footer/esp-footer-link-group.js +1 -1
  16. package/dist/footer/esp-footer.d.ts +5 -0
  17. package/dist/footer/esp-footer.js +10 -4
  18. package/dist/footer/paint-registration.js +1 -0
  19. package/dist/header/esp-header-button.js +5 -1
  20. package/dist/header/esp-header.js +12 -8
  21. package/dist/header/header-geometry-controller.js +1 -1
  22. package/dist/header/is-tall-header-paint.d.ts +7 -0
  23. package/dist/header/is-tall-header-paint.js +1 -0
  24. package/dist/header/paint-registration.js +1 -0
  25. package/dist/index.d.ts +4 -2
  26. package/dist/index.js +1 -1
  27. package/dist/menu/esp-menu-group.js +8 -8
  28. package/dist/menu/esp-menu-item.js +8 -8
  29. package/dist/menu/esp-menu.js +10 -6
  30. package/dist/menu/navigation-focus-outline.js +8 -0
  31. package/dist/menu/navigation-paint.js +1 -0
  32. package/dist/menu/paint-registration.js +1 -0
  33. package/dist/pickers/esp-picker-item.js +1 -1
  34. package/dist/root/esp-root.d.ts +8 -1
  35. package/dist/root/esp-root.js +47 -10
  36. package/dist/root/helpers/compute-semantic-properties.js +1 -1
  37. package/dist/root/helpers/compute-theme-properties.js +1 -1
  38. package/dist/root/helpers/data-companion-properties.js +1 -1
  39. package/dist/root/helpers/lightness-ramp-properties.js +1 -1
  40. package/dist/shared/blockquote-styles.d.ts +3 -0
  41. package/dist/shared/blockquote-styles.js +4 -4
  42. package/dist/shared/color-engine.js +1 -1
  43. package/dist/shared/component-property-compiler.js +1 -0
  44. package/dist/shared/component-property-diagnostics.js +1 -0
  45. package/dist/shared/component-property-normalizer.js +1 -0
  46. package/dist/shared/component-property-resets.js +1 -0
  47. package/dist/shared/composed-dom.js +1 -0
  48. package/dist/shared/configured-brand-color.js +1 -0
  49. package/dist/shared/configured-brand.js +5 -5
  50. package/dist/shared/css-named-colors.js +1 -0
  51. package/dist/shared/document-sprite.js +1 -1
  52. package/dist/shared/esp-element-base.d.ts +3 -0
  53. package/dist/shared/esp-element-base.js +3 -3
  54. package/dist/shared/font-helpers.d.ts +3 -3
  55. package/dist/shared/font-helpers.js +1 -1
  56. package/dist/shared/font-plan.d.ts +1 -1
  57. package/dist/shared/governing-root.d.ts +24 -0
  58. package/dist/shared/governing-root.js +1 -0
  59. package/dist/shared/intent-values.js +1 -1
  60. package/dist/shared/paint-catalog.d.ts +27 -0
  61. package/dist/shared/paint-catalog.js +1 -0
  62. package/dist/shared/paint-color.d.ts +25 -0
  63. package/dist/shared/paint-color.js +1 -0
  64. package/dist/shared/paint-fit.js +1 -0
  65. package/dist/shared/paint-identity.js +1 -0
  66. package/dist/shared/paint-types.d.ts +88 -0
  67. package/dist/shared/paint-types.js +0 -0
  68. package/dist/shared/public-token-catalog.generated.js +1 -0
  69. package/dist/shared/root-event-subscription.d.ts +11 -0
  70. package/dist/shared/scoped-style-declarations.js +1 -0
  71. package/dist/shared/semantic-color-names.d.ts +16 -0
  72. package/dist/shared/semantic-color-names.js +1 -0
  73. package/dist/shared/settable-component-properties.js +1 -0
  74. package/dist/shared/theme-core.d.ts +808 -0
  75. package/dist/shared/theme-core.js +1 -0
  76. package/dist/shared/theme-fit-report.d.ts +39 -5
  77. package/dist/shared/theme-fit-report.js +1 -1
  78. package/dist/shared/theme-mapping-grammar.d.ts +16 -0
  79. package/dist/shared/theme-mapping-grammar.js +1 -0
  80. package/dist/shared/theme-properties.d.ts +3 -1
  81. package/dist/shared/theme-properties.js +1 -1
  82. package/dist/shared/theme-validation.d.ts +52 -0
  83. package/dist/shared/theme-validation.js +1 -0
  84. package/dist/shared/theme.d.ts +6 -899
  85. package/dist/shared/theme.js +1 -1
  86. package/dist/shared/token-pairings.d.ts +25 -0
  87. package/dist/shared/token-pairings.js +1 -0
  88. package/dist/shared/wcag-contrast.d.ts +14 -0
  89. package/dist/shared/wcag-contrast.js +1 -0
  90. package/dist/testing/index.d.ts +7 -0
  91. package/dist/testing/index.js +1 -0
  92. package/dist/testing/observe-paint.d.ts +29 -0
  93. package/dist/testing/observe-paint.iife.js +3 -0
  94. package/dist/testing/observe-paint.js +3 -0
  95. package/dist/testing/paint-bands.js +1 -0
  96. package/dist/testing/paint-coverage.d.ts +14 -0
  97. package/dist/testing/paint-coverage.js +1 -0
  98. package/dist/testing/paint-dom.js +1 -0
  99. package/dist/testing/svg-paint.js +1 -0
  100. package/espalier.css-data.json +62 -2
  101. package/espalier.token-manifest.json +5724 -29
  102. package/package.json +10 -1
@@ -0,0 +1 @@
1
+ import{isSafeKey as l}from"./unsafe-keys.js";import{apcaContrast as I,deltaEOK as _n,deriveSemantic as D,parseCssColor as T,parseOklch as In,serializeOklch as Pn}from"./color-engine.js";import{computeVariants as G,parseAnchorSource as Bn,resolveAnchorColor as Ln,resolveMappingSource as w}from"./variant-engine.js";import{DATA_SERIES_KEYS as Nn,DEFAULT_DATA_PALETTE as $}from"./data-colors.js";import{TOKEN_PAIRINGS as nn}from"./token-pairings.js";import{SEMANTIC_COLOR_NAMES as P}from"./semantic-color-names.js";import{ANCHOR_SLUG_PATTERN as W,LIGHTNESS_KEYS as A,isLightnessKey as en,isObjectRecord as p,isThemeTone as jn,toneReferenceName as tn}from"./theme-mapping-grammar.js";import{getComponentPropertyAnalysis as Hn}from"./component-property-normalizer.js";import{ANCHOR_SLUG_PATTERN as He,COLOR_SOURCES as De,LIGHTNESS_KEYS as we,isLightnessKey as We,isObjectRecord as Fe,toneReferenceName as Ke}from"./theme-mapping-grammar.js";import{isSemanticColorName as ze,semanticToCSS as Ge,SEMANTIC_COLOR_NAMES as $e}from"./semantic-color-names.js";import{TOKEN_PAIRINGS as Ye}from"./token-pairings.js";function Dn(n){return Bn(n)}function wn(n,e){return Ln(n,e)}function Ce(n,e){const o=Dn(n);if(o){const t=wn(e,o);return t&&T(t)?t:null}return T(n)?n:null}const V=["canvas","ink","accent","action","structure"],Y={canvas:{color:[["background","surface"],["layer1","raised1"],["layer2","raised2"],["layer3","raised3"],["layer4","raised4"]]},ink:{color:[["text","text"],["typeOverline","text"],["typeLabel","text"],["typeLead","text"],["typeCaption","text"],["inputSelection","text"]],heading:[["headings","muted"],["headingsHover","ink"]]},accent:{color:[["linkHoverBg","raised2"],["inputSelectionBg","raised2"],["inputCaret","ink"]],text:[["link","accent"]],hover:[["linkHover","text"]]},action:{color:[["actionBackground","muted"]],ink:[["actionText","surface"]]},structure:{color:[["border","border"],["shadow","shadow"]]}},Wn=new Set(["action.color"]),Fn=new Set(["action.ink"]),Kn={canvas:"background",ink:"text",accent:"link",action:"actionBackground",structure:"border"},on={"action.ink":{role:"canvas",slot:"color"}},Un=.45,zn=.045;function rn(n,e,o){const t=nn.actionText,r=[...A].sort((g,h)=>n[g]-n[h]||A.indexOf(g)-A.indexOf(h)),s=e?r.filter(g=>e(g)>=t.targetLc):r,i=o?s.filter(g=>o(g)>=zn):s,c=i.length>0?i:s,a=c.length>0?c:r;let u,f=1/0;for(const g of a){const h=Math.abs(n[g]-Un);h<f&&(f=h,u=g)}return u??"muted"}function Gn(n){const e={l:n,c:0,h:0};return Math.abs(I({l:0,c:0,h:0},e))>=Math.abs(I({l:1,c:0,h:0},e))?"dark":"light"}function $n(n,e,o,t){const r=cn(e,o,n),s=(t??Gn)(r)==="dark";let i=A[0];for(const c of A)(s?e[c]<e[i]:e[c]>e[i])&&(i=c);return i}const Vn={"accent.hover":"text"};function S(n,e){if(n===void 0)return;if(typeof n=="string")return e==="color"?n:void 0;const o=n[e];return typeof o=="string"?o:void 0}function sn(n,e,o,t={}){const r={};for(const s of V){const i=n[s];if(i!==void 0)for(const[c,a]of Object.entries(Y[s])){const u=on[`${s}.${c}`];let f=S(i,c),g=!1;if(f===void 0){u&&(f=S(n[u.role],u.slot),f??=o[Kn[u.role]]?.source,g=f!==void 0);const h=Vn[`${s}.${c}`];h!==void 0&&(f??=S(i,h)),f??=S(i,"color")}if(f!==void 0)for(const[h,R]of a){let k=R;if(Wn.has(`${s}.${c}`))k=rn(e,t.actionSurfaceContrast?M=>t.actionSurfaceContrast(f,M):void 0,t.actionSurfaceSeparation?M=>t.actionSurfaceSeparation(f,M):void 0);else if(u&&(g||Fn.has(`${s}.${c}`))){const M=nn[h],N=M?t.explicitMappings?.[M.bg]:void 0,j=N?.lightness??rn(e,t.actionSurfaceContrast?O=>t.actionSurfaceContrast(S(i,"color"),O):void 0,t.actionSurfaceSeparation?O=>t.actionSurfaceSeparation(S(i,"color"),O):void 0),x=N?.source??S(i,"color");k=$n(j,e,t.tones??{},t.actionSurfacePole&&x!==void 0?O=>t.actionSurfacePole(x,O):void 0)}r[h]={source:f,lightness:k}}}}return r}function Re(n){const e={};for(const o of Object.keys(on)){const t=o.indexOf("."),r=o.slice(0,t),s=o.slice(t+1),i=n[r];if(i===void 0)continue;const c=S(i,s)!==void 0?"declared":"derived";for(const[a]of Y[r][s]??[])e[a]=c}return e}const Yn=["typeOverline","typeLabel","typeLead","typeCaption"],Jn=["danger","success","warning","info"],_e=["analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning","info"];function cn(n,e,o){if(en(o))return n[o];const t=tn(o);return t===null?n.surface:e?.[t]??n.surface}const vn={surface:.99,raised1:.97,raised2:.9,raised3:.8,raised4:.72,accent:.5,muted:.45,text:.35,border:.3,ink:.25,shadow:.2},Xn={surface:.15,raised1:.2,raised2:.3,raised3:.4,raised4:.36,accent:.6,muted:.75,text:.85,border:.7,ink:.95,shadow:.6},an={background:{source:"primary",lightness:"surface"},layer1:{source:"primary",lightness:"raised1"},layer2:{source:"primary",lightness:"raised2"},layer3:{source:"primary",lightness:"raised3"},layer4:{source:"primary",lightness:"raised4"},actionBackground:{source:"primary",lightness:"muted"},actionText:{source:"primary",lightness:"ink"},border:{source:"primary",lightness:"border"},shadow:{source:"primary",lightness:"shadow"},text:{source:"primary",lightness:"text"},typeOverline:{source:"primary",lightness:"text"},typeLabel:{source:"primary",lightness:"text"},typeLead:{source:"primary",lightness:"text"},typeCaption:{source:"primary",lightness:"text"},dangerText:{source:"danger",lightness:"text"},headings:{source:"primary",lightness:"muted"},headingsHover:{source:"primary",lightness:"text"},link:{source:"complementary",lightness:"accent"},linkHover:{source:"complementary",lightness:"text"},linkHoverBg:{source:"triadic-left",lightness:"raised2"},inputCaret:{source:"triadic-right",lightness:"ink"},inputSelection:{source:"complementary",lightness:"text"},inputSelectionBg:{source:"triadic-left",lightness:"raised2"}},qn={light:"muted",dark:"raised3"};function fn(n){return{...an,actionBackground:{source:"primary",lightness:qn[n]}}}const Qn=.4;function J(){const n={};for(const e of P)n[e]={min:0,max:Qn};return n}const pn="system-ui, sans-serif",un="monospace",ln={seedColor:"oklch(0.7 0.125 216)",fontBody:pn,fontHeadings:"",fontBrand:"",fontMenu:"",fontMonospace:un,fontWeightBody:"normal",fontWeightHeadings:"bold",fontWeightBrand:"bold",fontWeightMenu:"bold",fontWeightMonospace:"normal",stylesheets:[],rootFontSize:16,typeRatio:1.25,spaceRatio:1.618,borderRadius:.2,viewportMin:320,viewportMax:1200,angles:{analogous:30,complementary:180,splitComplementary:30,triadic:120},semanticHues:{danger:27,success:150,warning:90,info:244},variantChroma:{},intents:{},tones:{},chroma:J(),semanticMappings:{...an},explicitMappingTokens:[],anchors:{},roles:{},contexts:{},dataPalette:{...$},dataRamps:{}},Zn={...ln,chroma:J(),semanticMappings:fn("light"),anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...$},dataRamps:{},lightness:{...vn}},ne={...ln,chroma:J(),semanticMappings:fn("dark"),anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...$},dataRamps:{},lightness:{...Xn}},F=new WeakMap;F.set(Zn,new Set),F.set(ne,new Set);function ee(n,e){if(n==="root"&&e==="contexts")return"contexts";if(n==="contexts")return"context";if((n==="root"||n==="context")&&e==="componentProperties")return"properties"}function te(n){const e=[{value:n,position:"root"}];for(;e.length>0;){const{value:o,position:t}=e.pop();if(Array.isArray(o))for(const r of o)r!==null&&typeof r=="object"&&e.push({value:r});else if(p(o))for(const[r,s]of Object.entries(o))l(r)?(p(s)||Array.isArray(s))&&(t==="properties"&&p(s)&&Object.keys(s).some(i=>!l(i))?o[r]={}:e.push({value:s,position:ee(t,r)})):delete o[r]}}function K(n){const e=n.explicitMappingTokens;if(!Array.isArray(e)||e.some(t=>typeof t!="string"||!P.includes(t)))return;const o=new Set(e);if(o.size===e.length&&!(o.size>0&&(!p(n.semanticMappings)||[...o].some(t=>!Object.prototype.hasOwnProperty.call(n.semanticMappings,t)))))return o}function gn(n){return P.filter(e=>n.has(e))}function oe(n){try{const e=se(n),o=JSON.parse(e);return p(o)?(te(o),o):null}catch{return null}}const v="\xEF\xBB\xBF";function re(n){if(/^[\u0000-\u007f]*$/.test(n))return btoa(n);const e=new TextEncoder().encode(n);let o=v;for(const t of e)o+=String.fromCharCode(t);return btoa(o)}function se(n){const e=atob(n);if(!e.startsWith(v))return e;const o=Uint8Array.from(e.slice(v.length),t=>t.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(o)}function X(n){return re(JSON.stringify(n))}function ie(n){const e={};for(const o of Jn){const t=n[o];typeof t=="string"&&(e[o]=t.startsWith("anchor:")?t:B(t))}return e}function B(n){if(In(n))return n;const e=T(n);return e?Pn(e):n}function dn(n,e){const o={};for(const[t,r]of Object.entries(n))l(t)&&(o[t]=r);if(!e)return o;for(const[t,r]of Object.entries(e)){if(r===void 0||!l(t))continue;const s=o[t];if(s!==void 0&&typeof r=="object"&&r!==null){const i={};if(typeof s=="string")i.color=s;else for(const[c,a]of Object.entries(s))l(c)&&(i[c]=a);for(const[c,a]of Object.entries(r))a!==void 0&&l(c)&&(i[c]=a);o[t]=i;continue}o[t]=r}return o}function q(n){const e={};if(!p(n))return e;for(const[o,t]of Object.entries(n))jn(o,t)&&(e[o]=t);return e}function ce(n,e){return{...q(n),...q(e)}}function ae(n,e){const o={...n};if(!p(e))return o;for(const t of A){const r=e[t];typeof r=="number"&&Number.isFinite(r)&&r>=0&&r<=1&&(o[t]=r)}return o}function mn(n){if(typeof n!="object"||n===null||Array.isArray(n))return null;const e=n,o={};for(const t of V){const r=e[t];r!==void 0&&(o[t]=r)}if(typeof e.lightness=="object"&&e.lightness!==null&&!Array.isArray(e.lightness)){const t={};for(const r of A){const s=e.lightness[r];s!==void 0&&(t[r]=s)}o.lightness=t}if(e.tones!==void 0){const t=q(e.tones);Object.keys(t).length>0&&(o.tones=t)}if(typeof e.semanticMappings=="object"&&e.semanticMappings!==null&&!Array.isArray(e.semanticMappings)){const t={};for(const[r,s]of Object.entries(e.semanticMappings)){if(!l(r)||!P.includes(r)||typeof s!="object"||s===null||Array.isArray(s))continue;const{source:i,lightness:c}=s;typeof i=="string"&&(typeof c!="string"||!en(c)&&tn(c)===null||(t[r]={source:i,lightness:c}))}Object.keys(t).length>0&&(o.semanticMappings=t)}return e.componentProperties!==void 0&&(o.componentProperties=E(void 0,e.componentProperties)),o}function fe(n,e){const o={};for(const[t,r]of Object.entries(n)){if(!l(t)||!W.test(t))continue;const s=mn(r);s&&(o[t]=s)}if(!e)return o;for(const[t,r]of Object.entries(e)){if(!l(t)||!W.test(t)||r===void 0)continue;const s=mn(r);if(!s)continue;const i=o[t],c=E(i?.componentProperties,s.componentProperties);o[t]={...i??{},...s,...i?.lightness||s.lightness?{lightness:{...i?.lightness,...s.lightness}}:{},...i?.tones||s.tones?{tones:{...i?.tones,...s.tones}}:{},...c===void 0?{}:{componentProperties:c},...i?.semanticMappings||s.semanticMappings?{semanticMappings:{...i?.semanticMappings,...s.semanticMappings}}:{}}}return o}function m(n){const e={};for(const[o,t]of Object.entries(n))t!==void 0&&l(o)&&(e[o]=t);return e}function E(n,e){return e===void 0?p(n)?m(n):n:p(e)?{...p(n)?m(n):{},...m(e)}:e}function hn(n){if(!p(n))return n;const e=m(n);return p(n.lightness)&&(e.lightness=m(n.lightness)),p(n.tones)&&(e.tones=m(n.tones)),n.componentProperties!==void 0&&(e.componentProperties=E(void 0,n.componentProperties)),e}function pe(n,e){const o={};for(const[t,r]of Object.entries(n))l(t)&&(o[t]=hn(r));if(!e)return o;for(const[t,r]of Object.entries(e)){if(!l(t)||r===void 0)continue;const s=o[t];if(!p(s)||!p(r)){o[t]=hn(r);continue}const i={...m(s),...m(r)};p(s.lightness)&&p(r.lightness)?i.lightness={...m(s.lightness),...m(r.lightness)}:p(r.lightness)&&(i.lightness=m(r.lightness)),p(s.tones)&&p(r.tones)?i.tones={...m(s.tones),...m(r.tones)}:p(r.tones)&&(i.tones=m(r.tones)),p(s.semanticMappings)&&p(r.semanticMappings)?i.semanticMappings={...m(s.semanticMappings),...m(r.semanticMappings)}:p(r.semanticMappings)&&(i.semanticMappings=m(r.semanticMappings));const c=E(s.componentProperties,r.componentProperties);c!==void 0&&(i.componentProperties=c),o[t]=i}return o}function ue(n){const e={};for(const[o,t]of Object.entries(n)){if(!l(o))continue;if(typeof t=="string"){e[o]=B(t);continue}const r={};for(const[s,i]of Object.entries(t))l(s)&&(r[s]=typeof i=="string"?B(i):i);e[o]=r}return e}function L(n){return typeof n!="string"?"":n.startsWith("anchor:")?n:B(n)}function le(n){const e={};for(const o of Nn)e[o]=L(n[o]);return e}function yn(n,e){const o={};for(const[t,r]of Object.entries(n))l(t)&&W.test(t)&&r&&typeof r=="object"&&!Array.isArray(r)&&(o[t]={...r});if(!e)return o;for(const[t,r]of Object.entries(e)){if(!l(t)||!W.test(t)||!r||typeof r!="object"||Array.isArray(r))continue;const s=o[t],i=s!==void 0&&r.type!==void 0&&r.type!==s.type;o[t]={...i?{}:s??{},...r}}return o}function ge(n){const e={};for(const[o,t]of Object.entries(n))if(l(o)){if(t.type==="sequential"&&typeof t.source=="string"){e[o]={...t,source:L(t.source)};continue}if(t.type==="diverging"&&typeof t.start=="string"&&typeof t.end=="string"){e[o]={...t,start:L(t.start),end:L(t.end),...typeof t.neutral=="string"?{neutral:L(t.neutral)}:{}};continue}e[o]={...t}}return e}function xn(n){const e=T(n.seedColor);if(!e)return;const o=G(e,n);return(t,r)=>{const s=w(t,o,n.anchors)??o.primary,i=n.chroma.actionBackground,c=D(s,n.lightness[r],i.min,i.max),a={l:c.l>.5?0:1,c:0,h:0};return Math.abs(I(a,c))}}function Sn(n){const e=T(n.seedColor);if(!e)return;const o=G(e,n);return(t,r)=>{const s=w(t,o,n.anchors)??o.primary,i=n.chroma.actionBackground,c=D(s,r,i.min,i.max);return Math.abs(I({l:0,c:0,h:0},c))>=Math.abs(I({l:1,c:0,h:0},c))?"dark":"light"}}function de(n,e,o){if(e?.background)return e.background;const t=S(n.canvas,"color");if(t!==void 0){const r=Y.canvas.color?.find(([s])=>s==="background");if(r)return{source:t,lightness:r[1]}}return o.background}function kn(n,e){const o=T(n.seedColor);if(!o||!e)return;const t=G(o,n),r=w(e.source,t,n.anchors)??t.primary,s=n.chroma.background,i=D(r,cn(n.lightness,n.tones,e.lightness),s.min,s.max);return(c,a)=>{const u=w(c,t,n.anchors)??t.primary,f=n.chroma.actionBackground,g=D(u,n.lightness[a],f.min,f.max);return _n(g,i)}}function me(n){const e=F.get(n);if(e)return new Set(e);const o=K(n);if(o)return o;const t=new Set,r=sn(n.roles,n.lightness,n.semanticMappings,{tones:n.tones,actionSurfaceContrast:xn(n),actionSurfacePole:Sn(n),actionSurfaceSeparation:kn(n,n.semanticMappings.background)});for(const[s,i]of Object.entries(r)){const c=n.semanticMappings[s];(c.source!==i.source||c.lightness!==i.lightness)&&t.add(s)}return t}function he(n,e){const o={...n.roles,...e.roles},t=fe(n.contexts,e.contexts),r=ae(n.lightness,e.lightness),s=ce(n.tones,e.tones),i=ue(dn(n.anchors,e.anchors)),c=typeof e.seedColor=="string"?B(e.seedColor):n.seedColor,a=e.semanticMappings,u={...n.angles,...e.angles},f={...n.semanticHues,...e.semanticHues},g={...n.variantChroma,...e.variantChroma},h=ie({...n.intents,...e.intents}),R=e.chroma,k=C(n.chroma,R),M=le(C(n.dataPalette,e.dataPalette)),N=ge(yn(n.dataRamps,e.dataRamps)),j=me(n),x=new Set(j),O=K(e),b={};for(const d of j)b[d]=n.semanticMappings[d];for(const[d,_]of Object.entries(a??{}))_!==void 0&&(O===void 0||O.has(d)?(x.add(d),b[d]=_):(x.delete(d),delete b[d]));const H=C(n.semanticMappings,b),U={angles:u,anchors:i,chroma:k,intents:h,lightness:r,tones:s,seedColor:c,semanticHues:f,variantChroma:g},An=xn(U),Tn=Sn(U),En=kn(U,de(o,b,H)),Cn=sn(o,r,H,{explicitMappings:b,tones:s,actionSurfaceContrast:An,actionSurfacePole:Tn,actionSurfaceSeparation:En}),z={};for(const[d,_]of Object.entries(Cn))x.has(d)||(z[d]=_);const Q={};for(const d of Yn)!x.has(d)&&z[d]===void 0&&(Q[d]={source:H.text.source,lightness:H.text.lightness},R?.text!==void 0&&R[d]===void 0&&(k[d]={...k.text}));const Rn=C(C(C(n.semanticMappings,Q),z),b),y={...n,seedColor:c,fontBody:e.fontBody||n.fontBody||pn,fontHeadings:e.fontHeadings??n.fontHeadings,fontBrand:e.fontBrand??n.fontBrand,fontMenu:e.fontMenu??n.fontMenu,fontMonospace:e.fontMonospace||n.fontMonospace||un,fontWeightBody:String(e.fontWeightBody??n.fontWeightBody),fontWeightHeadings:String(e.fontWeightHeadings??n.fontWeightHeadings),fontWeightBrand:String(e.fontWeightBrand??n.fontWeightBrand),fontWeightMenu:String(e.fontWeightMenu??n.fontWeightMenu),fontWeightMonospace:String(e.fontWeightMonospace??n.fontWeightMonospace),stylesheets:e.stylesheets??[...n.stylesheets],rootFontSize:e.rootFontSize??n.rootFontSize,typeRatio:e.typeRatio??n.typeRatio,spaceRatio:e.spaceRatio??n.spaceRatio,borderRadius:e.borderRadius??n.borderRadius,viewportMin:e.viewportMin??n.viewportMin,viewportMax:e.viewportMax??n.viewportMax,angles:u,semanticHues:f,variantChroma:g,intents:h,lightness:r,tones:s,chroma:k,semanticMappings:Rn,explicitMappingTokens:gn(x),anchors:i,roles:o,contexts:t,dataPalette:M,dataRamps:N},Z=E(n.componentProperties,e.componentProperties);return Z!==void 0&&(y.componentProperties=Z),e.pageBackgroundImage!==void 0&&(y.pageBackgroundImage=e.pageBackgroundImage),e.pageBackgroundImageOpacity!==void 0&&(y.pageBackgroundImageOpacity=e.pageBackgroundImageOpacity),e.boxBackgroundImage!==void 0&&(y.boxBackgroundImage=e.boxBackgroundImage),e.boxBackgroundImageOpacity!==void 0&&(y.boxBackgroundImageOpacity=e.boxBackgroundImageOpacity),e.vellumOpacity!==void 0&&(y.vellumOpacity=e.vellumOpacity),e.vellumBackgroundImage!==void 0&&(y.vellumBackgroundImage=e.vellumBackgroundImage),e.vellumBackgroundImageOpacity!==void 0&&(y.vellumBackgroundImageOpacity=e.vellumBackgroundImageOpacity),F.set(y,new Set(x)),y}const Mn=new WeakMap;function Ie(n,e){const o=n.contexts&&Object.prototype.hasOwnProperty.call(n.contexts,e)?n.contexts[e]:void 0;if(!o)return null;let t=Mn.get(n);const r=t?.get(e);if(r)return r;const s={};for(const c of V){const a=o[c];a!==void 0&&(s[c]=a)}const i=he(n,{lightness:o.lightness,tones:o.tones,roles:s,semanticMappings:o.semanticMappings});if(n.componentProperties!==void 0||o.componentProperties!==void 0){const c=Hn(n).contexts.get(e);c?.supplied&&(i.componentProperties=Object.fromEntries(Object.entries(c.values).map(([a,u])=>[a,typeof u=="string"?u:{...u}])))}return t||(t=new Map,Mn.set(n,t)),t.set(e,i),i}function C(n,e){if(!e)return{...n};const o={...n};for(const t of Object.keys(e)){const r=e[t];r!==void 0&&(o[t]=r)}return o}const ye=["anchors","angles","componentProperties","contexts","dataPalette","dataRamps","intents","roles","chroma","lightness","tones","semanticHues","semanticMappings","variantChroma"];function xe(n,e){const o={};for(const[s,i]of Object.entries(n))l(s)&&(o[s]=i);for(const[s,i]of Object.entries(e))i!==void 0&&l(s)&&(o[s]=i);for(const s of ye){const i=n[s],c=e[s];if(s==="componentProperties"){const a=E(i,c);a===void 0?delete o[s]:o[s]=a;continue}if(i&&typeof i=="object"&&!Array.isArray(i)&&c&&typeof c=="object"&&!Array.isArray(c)){if(s==="anchors"){o[s]=dn(i,c);continue}if(s==="contexts"){o[s]=pe(i,c);continue}if(s==="dataRamps"){o[s]=yn(i,c);continue}const a={};for(const[u,f]of Object.entries(i))l(u)&&(a[u]=f);for(const[u,f]of Object.entries(c))f!==void 0&&l(u)&&(a[u]=f);o[s]=a}}const t=K(n),r=K(e);if(t!==void 0||r!==void 0){const s=t??new Set(Object.keys(n.semanticMappings??{}).filter(i=>P.includes(i)));for(const i of Object.keys(e.semanticMappings??{}))r===void 0||r.has(i)?s.add(i):s.delete(i);o.explicitMappingTokens=gn(s)}return o}function Pe(...n){let e={};for(const o of n){if(!o)continue;const t=oe(o);t&&(e=xe(e,t))}return X(e)}function On(n){return n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r")}const bn={borderRadius:.1,fontBody:'"Noto Sans", sans-serif',fontWeightBody:"normal",fontHeadings:'"Inika", serif',fontWeightHeadings:"normal",fontBrand:'"Inika", serif',fontWeightBrand:"normal",fontMonospace:'"JetBrains Mono", monospace',fontWeightMonospace:"normal",seedColor:"oklch(.07 0.15 216)"};function Be(n){return X({...bn,pageBackgroundImage:`url("${On(n)}")`,pageBackgroundImageOpacity:.5})}function Le(n){return X({...bn,pageBackgroundImage:`url("${On(n)}")`,pageBackgroundImageOpacity:.55})}export{He as ANCHOR_SLUG_PATTERN,De as COLOR_SOURCES,pn as DEFAULT_BODY_FONT_FAMILY,Xn as DEFAULT_DARK_LIGHTNESS,ne as DEFAULT_DARK_THEME,vn as DEFAULT_LIGHT_LIGHTNESS,Zn as DEFAULT_LIGHT_THEME,un as DEFAULT_MONOSPACE_FONT_FAMILY,an as DEFAULT_SEMANTIC_MAPPINGS,we as LIGHTNESS_KEYS,Qn as MAX_CHROMA,ye as NESTED_THEME_KEYS,Fn as ROLE_DERIVED_INK,Wn as ROLE_DERIVED_SURFACE,V as ROLE_NAMES,on as ROLE_PAIRED_INK,Y as ROLE_TOKEN_PLAN,$e as SEMANTIC_COLOR_NAMES,Jn as STATUS_COLOR_SOURCES,Ye as TOKEN_PAIRINGS,_e as VARIANT_COLOR_SOURCES,Le as buildTaprootDarkTheme,Be as buildTaprootLightTheme,sn as compileRoles,se as decodeThemeJson,X as encodeTheme,me as explicitMappingTokens,We as isLightnessKey,Fe as isObjectRecord,ze as isSemanticColorName,Pe as layerThemes,xe as mergePartials,he as mergeTheme,Dn as parseAnchorSource,oe as parseTheme,wn as resolveAnchorColor,Ie as resolveContextTheme,Ce as resolveDataColorSource,cn as resolveLightnessReference,Re as roleInkProvenance,Ge as semanticToCSS,Ke as toneReferenceName};
@@ -49,7 +49,8 @@
49
49
  * ```
50
50
  */
51
51
  import { type ColorVisionSimulation, type DataPalette, type DataSeriesKey } from "./data-colors.js";
52
- import { type EspalierTheme, type LightnessReference, type MappingSource, type PartialTheme, type SemanticColorName } from "./theme.js";
52
+ import { type ComponentPropertyValue, type EspalierTheme, type LightnessReference, type MappingSource, type PartialTheme, type SemanticColorName } from "./theme.js";
53
+ import type { PaintEntriesByRole, PaintFitReport, PaintFitSurface } from "./paint-types.js";
53
54
  /** What APCA enforcement did to one token. */
54
55
  export interface ThemeFitApcaAction {
55
56
  /** The requested value, as an `oklch()` string. */
@@ -128,6 +129,26 @@ export interface ThemeFitToken {
128
129
  */
129
130
  pairing?: "declared" | "derived";
130
131
  }
132
+ /** Contrast of a component ink against the ground the surface emitted. */
133
+ export interface ThemeFitComponentApca {
134
+ against: string;
135
+ againstColor: string;
136
+ fromLc: number;
137
+ toLc: number;
138
+ }
139
+ /** The compiled value and authorship of one settable property on a surface. */
140
+ export interface ThemeFitComponentProperty {
141
+ name: string;
142
+ surface: string;
143
+ /** Null identifies an unset ink fitted against an authored ground. */
144
+ authored: ComponentPropertyValue | null;
145
+ resolved: string;
146
+ overridesRoot: boolean;
147
+ requested?: string;
148
+ adjusted?: boolean;
149
+ apca?: ThemeFitComponentApca;
150
+ targetLc?: number;
151
+ }
131
152
  /**
132
153
  * A theme's fit report — the stable JSON shape the docs site renders.
133
154
  */
@@ -143,6 +164,8 @@ export interface ThemeFitReport {
143
164
  anchors: Record<string, string>;
144
165
  /** Every semantic token, in the pipeline's derivation order. */
145
166
  tokens: ThemeFitToken[];
167
+ /** Settable values the selected surface emits, including fitted default inks. */
168
+ componentProperties: ThemeFitComponentProperty[];
146
169
  /** The tokens APCA enforcement moved — the headline of the report. */
147
170
  adjustedTokens: SemanticColorName[];
148
171
  }
@@ -200,8 +223,8 @@ export interface ThemeFitLint {
200
223
  id: "action-anchor-inversion" | "action-canvas-separation" | "apca-target-unmet" | "link-hover-ordering";
201
224
  /** Lints describe design-quality hazards, not validation failures. */
202
225
  severity: "warning";
203
- /** The tokens the finding is about, recommended retune target first. */
204
- tokens: SemanticColorName[];
226
+ /** Semantic token IDs or settable property names, recommended retune target first. */
227
+ tokens: string[];
205
228
  /** The measured number the lint fired on (ΔE-OK, or an Lc deficit). */
206
229
  measured: number;
207
230
  /** Human-readable finding, with the remedy phrased as a retune. */
@@ -225,7 +248,7 @@ export interface ThemeFitDataPaletteLint {
225
248
  message: string;
226
249
  }
227
250
  /** Runtime validation/comparison vocabulary used by the exported field descriptors. */
228
- export type ThemeFitFieldKind = "anchor" | "anchor-record" | "apca" | "boolean" | "data-palette-record" | "explicit" | "fit-lint-id" | "lint-array" | "message" | "number" | "pairing" | "palette-lint-id" | "palette-lint-record" | "report-array" | "scheme" | "semantic" | "semantic-array" | "series-pair" | "simulation" | "string" | "string-array" | "token-array" | "warning";
251
+ export type ThemeFitFieldKind = "anchor" | "anchor-record" | "apca" | "boolean" | "component-apca" | "component-property-array" | "component-property-name" | "component-property-value" | "contrast-ground" | "data-palette-record" | "explicit" | "fit-lint-id" | "fit-lint-token-array" | "lint-array" | "message" | "number" | "paint-record" | "pairing" | "palette-lint-id" | "palette-lint-record" | "report-array" | "scheme" | "semantic" | "semantic-array" | "series-pair" | "simulation" | "string" | "string-array" | "token-array" | "warning";
229
252
  /** One runtime field descriptor used by fit-suite validation and comparison. */
230
253
  export interface ThemeFitFieldDescriptor<Field extends PropertyKey = PropertyKey> {
231
254
  readonly field: Field;
@@ -250,6 +273,10 @@ export declare const THEME_FIT_TOKEN_FIELDS: readonly ThemeFitFieldDescriptor<ke
250
273
  export declare const THEME_FIT_ANCHOR_FIELDS: readonly ThemeFitFieldDescriptor<keyof ThemeFitAnchor>[];
251
274
  /** Runtime schema for every APCA-detail field. */
252
275
  export declare const THEME_FIT_APCA_FIELDS: readonly ThemeFitFieldDescriptor<keyof ThemeFitApcaAction>[];
276
+ /** Runtime schema for component contrast details. */
277
+ export declare const THEME_FIT_COMPONENT_APCA_FIELDS: readonly ThemeFitFieldDescriptor<keyof ThemeFitComponentApca>[];
278
+ /** Runtime schema for every component property field. */
279
+ export declare const THEME_FIT_COMPONENT_PROPERTY_FIELDS: readonly ThemeFitFieldDescriptor<keyof ThemeFitComponentProperty>[];
253
280
  /** Runtime schema for every surface-lint field. */
254
281
  export declare const THEME_FIT_LINT_FIELDS: readonly ThemeFitFieldDescriptor<keyof ThemeFitLint>[];
255
282
  /** Runtime schema for every categorical-palette lint field. */
@@ -322,6 +349,13 @@ export interface ThemeFitSuite {
322
349
  light: ThemeFitSurfaceReport[];
323
350
  /** One report per surface the dark theme defines. */
324
351
  dark: ThemeFitSurfaceReport[];
352
+ /** WCAG measurements of enabled component paint for explicitly requested roles. */
353
+ paint?: PaintFitReport;
354
+ }
355
+ /** Optional component paint measurements to add to the APCA fit suite. */
356
+ export interface ThemeFitSuiteOptions {
357
+ paintSurfaces?: readonly PaintFitSurface[];
358
+ extraEntries?: PaintEntriesByRole;
325
359
  }
326
360
  /** Runtime schema for every surface-report field. */
327
361
  export declare const THEME_FIT_REPORT_FIELDS: readonly ThemeFitFieldDescriptor<keyof ThemeFitSurfaceReport>[];
@@ -343,5 +377,5 @@ export declare const THEME_FIT_SUITE_FIELDS: readonly ThemeFitFieldDescriptor<ke
343
377
  * seed color is unparseable), because the required palette snapshot cannot be
344
378
  * produced. {@link themeFitReport} retains its narrower empty-report behavior.
345
379
  */
346
- export declare function themeFitReportSuite(lightPartial: PartialTheme, darkPartial: PartialTheme): ThemeFitSuite;
380
+ export declare function themeFitReportSuite(lightPartial: PartialTheme, darkPartial: PartialTheme, options?: ThemeFitSuiteOptions): ThemeFitSuite;
347
381
  export {};
@@ -1 +1 @@
1
- import{apcaContrast as T,deltaEOK as x,parseOklch as _,serializeOklch as $}from"./color-engine.js";import{DATA_SERIES_KEYS as C,auditDataPalette as q,describePaletteCollision as K}from"./data-colors.js";import{DEFAULT_DARK_THEME as G,DEFAULT_LIGHT_THEME as Y,explicitMappingTokens as W,mergeTheme as j,parseAnchorSource as X,resolveContextTheme as J,roleInkProvenance as Q}from"./theme.js";import{computeThemeProperties as Z}from"../root/helpers/compute-theme-properties.js";function ke(e,t,o={}){return H(e,t,o).report}function H(e,t,o={}){let n=e,c=null;if(o.context!==void 0){const s=J(e,o.context);if(!s)throw new Error(`themeFitReport: context "${o.context}" is not defined by the theme.`);n=s,c=new Set(Object.keys(e.contexts[o.context]?.semanticMappings??{}))}const p=[],v=Z(n,t,p),L=W(n),f=Q(n.roles),E=p.map(s=>{const a=ie(s);if(L.has(a.token))a.explicit=c===null||c.has(a.token)?"declared":"inherited";else{const i=f[a.token];i!==void 0&&(a.pairing=i)}return a});return{properties:v,report:{scheme:t,seedColor:n.seedColor,anchors:ce(n.anchors),tokens:E,adjustedTokens:E.filter(s=>s.adjusted).map(s=>s.token)}}}function ee(e){return e.tokens.map(t=>({token:t.token,source:t.source,requested:t.requested,resolved:t.resolved,apca:de(t),anchor:le(t)}))}function ge(e){const t=e.adjustedTokens.length>0?`APCA moved ${e.adjustedTokens.join(", ")}`:"APCA moved nothing";console.info(`Espalier theme fit \u2014 ${e.scheme} scheme, seed ${e.seedColor}. ${t}.`),console.table(ee(e))}function I(e){const t=Object.entries(e).map(([o,n])=>Object.freeze({field:o,kind:n.kind,compared:n.compared}));return Object.freeze(t)}const te={"action-anchor-inversion":!0,"action-canvas-separation":!0,"apca-target-unmet":!0,"link-hover-ordering":!0},fe=Object.freeze(Object.keys(te)),re={"data-palette-cvd-collision":!0},Ee=Object.freeze(Object.keys(re)),ne={declared:!0,inherited:!0},Te=Object.freeze(Object.keys(ne)),oe={declared:!0,derived:!0},_e=Object.freeze(Object.keys(oe)),ae={warning:!0},ve=Object.freeze(Object.keys(ae)),Le=I({token:{kind:"semantic",compared:!0},property:{kind:"string",compared:!0},source:{kind:"string",compared:!0},lightness:{kind:"string",compared:!0},requested:{kind:"string",compared:!0},resolved:{kind:"string",compared:!0},adjusted:{kind:"boolean",compared:!0},sourceResolved:{kind:"boolean",compared:!0},anchor:{kind:"anchor",compared:!0},apca:{kind:"apca",compared:!0},explicit:{kind:"explicit",compared:!0},pairing:{kind:"pairing",compared:!0}}),Ie=I({reference:{kind:"string",compared:!0},color:{kind:"string",compared:!0},deltaE:{kind:"number",compared:!0}}),be=I({from:{kind:"string",compared:!0},to:{kind:"string",compared:!0},targetLc:{kind:"number",compared:!0},against:{kind:"semantic",compared:!0},againstColor:{kind:"string",compared:!0},fromLc:{kind:"number",compared:!0},toLc:{kind:"number",compared:!0}}),Re=I({id:{kind:"fit-lint-id",compared:!0},severity:{kind:"warning",compared:!0},tokens:{kind:"semantic-array",compared:!0},measured:{kind:"number",compared:!0},message:{kind:"message",compared:!0}}),Me=I({id:{kind:"palette-lint-id",compared:!0},severity:{kind:"warning",compared:!0},series:{kind:"series-pair",compared:!0},simulation:{kind:"simulation",compared:!0},measured:{kind:"number",compared:!0},threshold:{kind:"number",compared:!0},message:{kind:"message",compared:!0}}),D=.045,N=.045,M=75,y={l:0,c:0,h:0},P={l:1,c:0,h:0},B=.5,F=75,se=.045;function V(e){const t=[],o=new Map(e.tokens.map(r=>[r.token,r.resolved])),n=r=>{const d=o.get(r);return d===void 0?null:_(d)},c=n("background"),p=n("actionBackground");if(c&&p){const r=x(p,c);if(r<D){const d=u(r,4);t.push({id:"action-canvas-separation",severity:"warning",tokens:["actionBackground","background"],measured:d,message:`actionBackground sits \u0394E ${d} from background (floor ${D}) \u2014 filled actions vanish into this canvas. Retune the surface apart: move the background stop, or pin actionBackground to a separated stop.`})}}const v=n("link"),L=n("linkHover"),f=n("linkHoverBg");if(c&&v&&L&&f){const r=Math.abs(T(v,c)),d=Math.abs(T(L,f));x(f,c)>=se?d+B<F&&t.push({id:"link-hover-ordering",severity:"warning",tokens:["linkHoverBg","linkHover"],measured:u(F-d,1),message:`linkHover reaches only Lc ${u(d,1)} on the linkHoverBg wash it actually paints (tier ${F}) \u2014 retune linkHoverBg before changing linkHover; the wash has one consumer while the ink has many.`}):d+B<r&&t.push({id:"link-hover-ordering",severity:"warning",tokens:["linkHover","link"],measured:u(r-d,1),message:`linkHover reads weaker than link on the same canvas (Lc ${u(d,1)} vs ${u(r,1)}) \u2014 a dimming hover feels disabled. Retune linkHover toward more contrast than the resting link.`})}const E=r=>Math.abs(T(y,r))>=Math.abs(T(P,r))?"dark":"light",s=e.tokens.find(r=>r.token==="actionBackground"),a=e.tokens.find(r=>r.token==="actionText"),i=[],l=[];let m=0;const h=a?.anchor?_(a.anchor.color):null,g=a?_(a.resolved):null,k=s?.anchor?_(s.anchor.color):null,b=s?_(s.resolved):null,O=g&&b?g.l>b.l?"light":"dark":null;s?.anchor&&k&&b&&O&&s.anchor.deltaE>=N&&E(k)!==O&&(i.push("actionBackground"),m=Math.max(m,s.anchor.deltaE),l.push(`"${s.anchor.reference}" wants ${E(k)} ink but actionBackground renders carrying a ${O} label (\u0394E ${u(s.anchor.deltaE,4)})`)),a?.anchor&&a.pairing!=="derived"&&h&&g&&k&&b&&a.anchor.deltaE>=N&&k.l!==h.l&&Math.sign(k.l-h.l)!==Math.sign(b.l-g.l)&&(i.push("actionText"),m=Math.max(m,a.anchor.deltaE),l.push(`the declared pair puts "${s.anchor.reference}" ${k.l>h.l?"above":"below"} "${a.anchor.reference}" in lightness and the rendered pair puts it ${b.l>g.l?"above":"below"} (\u0394E ${u(a.anchor.deltaE,4)})`)),i.length>0&&t.push({id:"action-anchor-inversion",severity:"warning",tokens:i,measured:u(m,4),message:`The filled action renders the opposite way round from the swatches it names: ${l.join("; ")}. `+(s?.explicit===void 0?"A filled action's ramp stop is chosen by the engine near its mid-band target, so seating the ramp cannot move it the way it moves every other anchored token. Retune by pinning semanticMappings.actionBackground to a stop that carries the swatch":"semanticMappings.actionBackground is already pinned, so the engine did not place this \u2014 retune the stop that pin names")+" \u2014 and check the pair still clears its tier there, because a swatch this far off the band often cannot hold a label at its own lightness."});const A=e.tokens.filter(r=>r.apca!==void 0&&r.apca.toLc<Math.min(r.apca.targetLc,M)).sort((r,d)=>Math.min(d.apca.targetLc,M)-d.apca.toLc-(Math.min(r.apca.targetLc,M)-r.apca.toLc)||(r.token<d.token?-1:r.token>d.token?1:0));if(A.length>0){const r=A[0].apca,d=A.map(R=>`${R.token} reaches Lc ${u(R.apca.toLc,1)} on ${R.apca.against} (floor ${Math.min(R.apca.targetLc,M)})`),w=_(r.againstColor),U=w!==null&&Math.max(Math.abs(T(y,w)),Math.abs(T(P,w)))>=Math.min(r.targetLc,M);t.push({id:"apca-target-unmet",severity:"warning",tokens:A.map(R=>R.token),measured:u(Math.min(r.targetLc,M)-r.toLc,1),message:`${d.join(", ")} \u2014 enforcement moved the ink as far as this ramp allows and the pair still falls short. `+(U?"The opposite ink pole does clear the floor on that ground, so the emitted ink is on the weaker side rather than the ground being impossible \u2014 check the pairing before retuning the ground.":"No ink reaches the floor on that ground, so retune the ground each pair reads against toward a lightness that can carry it.")})}return t}const S=":root",Ae=I({scheme:{kind:"scheme",compared:!0},seedColor:{kind:"string",compared:!0},anchors:{kind:"anchor-record",compared:!0},tokens:{kind:"token-array",compared:!0},adjustedTokens:{kind:"semantic-array",compared:!0},surface:{kind:"string",compared:!0},lints:{kind:"lint-array",compared:!0}}),we=I({surfaces:{kind:"string-array",compared:!0},dataPalette:{kind:"data-palette-record",compared:!0},paletteLints:{kind:"palette-lint-record",compared:!0},light:{kind:"report-array",compared:!0},dark:{kind:"report-array",compared:!0}});function Oe(e,t){const o=j(Y,e),n=j(G,t),c=[S,...[...new Set([...Object.keys(o.contexts),...Object.keys(n.contexts)])].sort()],p=a=>{const i={};for(let l=0;l<C.length;l+=1){const m=C[l],h=`--esp-color-series-${l+1}`,g=a[h];if(g===void 0)throw new Error(`Theme fit report did not emit required property ${h}.`);i[m]=g}return i},v=a=>q(a).map(i=>{const l=u(i.distance,4);return{id:"data-palette-cvd-collision",severity:"warning",series:i.series,simulation:i.simulation,measured:l,threshold:i.threshold,message:K(i)}}),L=(a,i)=>{const l=H(a,i);if(Object.keys(l.properties).length===0)throw new Error(`themeFitReportSuite: ${i} root emitted no properties for seed "${a.seedColor}".`);const m=[{...l.report,surface:S,lints:V(l.report)}];for(const h of c){if(h===S||!(h in a.contexts))continue;const k=H(a,i,{context:h}).report;m.push({...k,surface:h,lints:V(k)})}return{dataPalette:p(l.properties),reports:m}},f=L(o,"light"),E=L(n,"dark"),s={light:f.dataPalette,dark:E.dataPalette};return{surfaces:c,dataPalette:s,paletteLints:{light:v(s.light),dark:v(s.dark)},light:f.reports,dark:E.reports}}function u(e,t){const o=Math.pow(10,t);return Math.round(e*o)/o}function z(e,t){return t===void 0?e:`${e}.${t}`}function ce(e){const t={};for(const[o,n]of Object.entries(e)){if(typeof n=="string"){t[o]=n;continue}for(const[c,p]of Object.entries(n))t[c==="color"?o:z(o,c)]=p}return t}function ie(e){const t=_(e.resolved),o=e.requested===void 0?e.resolved:$(e.requested),n={token:e.token,property:e.property,source:e.source,lightness:e.lightness,requested:o,resolved:e.resolved,adjusted:o!==e.resolved,sourceResolved:e.sourceResolved},c=X(e.source);if(c&&e.sourceResolved&&(n.anchor={reference:z(c.name,c.slot),color:$(e.base),deltaE:u(x(e.base,t),4)}),e.contrast){const p=e.contrast.background;n.apca={from:o,to:e.resolved,targetLc:e.contrast.targetLc,against:e.contrast.against,againstColor:$(p),fromLc:u(Math.abs(T(_(o),p)),1),toLc:u(Math.abs(T(t,p)),1)}}return n}function de(e){if(!e.apca)return"";const{targetLc:t,against:o,fromLc:n,toLc:c}=e.apca;return e.adjusted?`Lc ${t} vs ${o} \u2014 pushed from Lc ${n} to Lc ${c}`:`Lc ${t} vs ${o} \u2014 met at Lc ${n}`}function le(e){return e.anchor?`${e.anchor.reference} \u0394E ${e.anchor.deltaE}`:e.sourceResolved?"":"unresolved \u2014 seed used"}export{S as ROOT_SURFACE,Ie as THEME_FIT_ANCHOR_FIELDS,be as THEME_FIT_APCA_FIELDS,Me as THEME_FIT_DATA_PALETTE_LINT_FIELDS,Ee as THEME_FIT_DATA_PALETTE_LINT_IDS,Te as THEME_FIT_EXPLICIT_VALUES,Re as THEME_FIT_LINT_FIELDS,fe as THEME_FIT_LINT_IDS,ve as THEME_FIT_LINT_SEVERITIES,_e as THEME_FIT_PAIRING_VALUES,Ae as THEME_FIT_REPORT_FIELDS,we as THEME_FIT_SUITE_FIELDS,Le as THEME_FIT_TOKEN_FIELDS,ge as printThemeFitReport,V as themeFitLints,ke as themeFitReport,Oe as themeFitReportSuite,ee as themeFitRows};
1
+ import{apcaContrast as I,BLACK_INK as S,deltaEOK as w,parseOklch as b,serializeOklch as $,WHITE_INK as P}from"./color-engine.js";import{DATA_SERIES_KEYS as C,auditDataPalette as X,describePaletteCollision as J}from"./data-colors.js";import{DEFAULT_DARK_THEME as Q,DEFAULT_LIGHT_THEME as Z,explicitMappingTokens as ee,mergeTheme as y,parseAnchorSource as te,resolveContextTheme as re,roleInkProvenance as ne}from"./theme.js";import{getComponentPropertyAnalysis as oe}from"./component-property-normalizer.js";import{measurePaintSurfaces as ae}from"./paint-fit.js";import{computeThemeProperties as se}from"../root/helpers/compute-theme-properties.js";function Re(e,t,n={}){return F(e,t,n).report}function F(e,t,n={}){let o=e,c=null;if(n.context!==void 0){const s=re(e,n.context);if(!s)throw new Error(`themeFitReport: context "${n.context}" is not defined by the theme.`);o=s,c=new Set(Object.keys(e.contexts[n.context]?.semanticMappings??{}))}const m=[],L=[],_=oe(e),g=n.context===void 0?_.root:_.contexts.get(n.context),v=se(o,t,m,void 0,g?{surface:g,trace:L}:void 0),d=ee(o),u=ne(o.roles),l=m.map(s=>{const i=fe(s);if(d.has(i.token))i.explicit=c===null||c.has(i.token)?"declared":"inherited";else{const k=u[i.token];k!==void 0&&(i.pairing=k)}return i});return{properties:v,report:{scheme:t,seedColor:o.seedColor,anchors:ke(o.anchors),tokens:l,componentProperties:L.map(({context:s,...i})=>({...i,surface:s??x})),adjustedTokens:l.filter(s=>s.adjusted).map(s=>s.token)}}}function ie(e){return e.tokens.map(t=>({token:t.token,source:t.source,requested:t.requested,resolved:t.resolved,apca:ge(t),anchor:Ee(t)}))}function Me(e){const t=e.adjustedTokens.length>0?`APCA moved ${e.adjustedTokens.join(", ")}`:"APCA moved nothing";console.info(`Espalier theme fit \u2014 ${e.scheme} scheme, seed ${e.seedColor}. ${t}.`),console.table(ie(e))}function T(e){const t=Object.entries(e).map(([n,o])=>Object.freeze({field:n,kind:o.kind,compared:o.compared}));return Object.freeze(t)}const ce={"action-anchor-inversion":!0,"action-canvas-separation":!0,"apca-target-unmet":!0,"link-hover-ordering":!0},Ae=Object.freeze(Object.keys(ce)),de={"data-palette-cvd-collision":!0},xe=Object.freeze(Object.keys(de)),ue={declared:!0,inherited:!0},Oe=Object.freeze(Object.keys(ue)),le={declared:!0,derived:!0},we=Object.freeze(Object.keys(le)),pe={warning:!0},$e=Object.freeze(Object.keys(pe)),Fe=T({token:{kind:"semantic",compared:!0},property:{kind:"string",compared:!0},source:{kind:"string",compared:!0},lightness:{kind:"string",compared:!0},requested:{kind:"string",compared:!0},resolved:{kind:"string",compared:!0},adjusted:{kind:"boolean",compared:!0},sourceResolved:{kind:"boolean",compared:!0},anchor:{kind:"anchor",compared:!0},apca:{kind:"apca",compared:!0},explicit:{kind:"explicit",compared:!0},pairing:{kind:"pairing",compared:!0}}),He=T({reference:{kind:"string",compared:!0},color:{kind:"string",compared:!0},deltaE:{kind:"number",compared:!0}}),Se=T({from:{kind:"string",compared:!0},to:{kind:"string",compared:!0},targetLc:{kind:"number",compared:!0},against:{kind:"semantic",compared:!0},againstColor:{kind:"string",compared:!0},fromLc:{kind:"number",compared:!0},toLc:{kind:"number",compared:!0}}),Pe=T({against:{kind:"contrast-ground",compared:!0},againstColor:{kind:"string",compared:!0},fromLc:{kind:"number",compared:!0},toLc:{kind:"number",compared:!0}}),Ce=T({name:{kind:"component-property-name",compared:!0},surface:{kind:"string",compared:!0},authored:{kind:"component-property-value",compared:!0},resolved:{kind:"string",compared:!0},overridesRoot:{kind:"boolean",compared:!0},requested:{kind:"string",compared:!0},adjusted:{kind:"boolean",compared:!0},apca:{kind:"component-apca",compared:!0},targetLc:{kind:"number",compared:!0}}),ye=T({id:{kind:"fit-lint-id",compared:!0},severity:{kind:"warning",compared:!0},tokens:{kind:"fit-lint-token-array",compared:!0},measured:{kind:"number",compared:!0},message:{kind:"message",compared:!0}}),je=T({id:{kind:"palette-lint-id",compared:!0},severity:{kind:"warning",compared:!0},series:{kind:"series-pair",compared:!0},simulation:{kind:"simulation",compared:!0},measured:{kind:"number",compared:!0},threshold:{kind:"number",compared:!0},message:{kind:"message",compared:!0}}),j=.045,N=.045,he=75,D=.5,H=75,me=.045;function B(e){const t=[],n=new Map(e.tokens.map(r=>[r.token,r.resolved])),o=r=>{const a=n.get(r);return a===void 0?null:b(a)},c=o("background"),m=o("actionBackground");if(c&&m){const r=w(m,c);if(r<j){const a=h(r,4);t.push({id:"action-canvas-separation",severity:"warning",tokens:["actionBackground","background"],measured:a,message:`actionBackground sits \u0394E ${a} from background (floor ${j}) \u2014 filled actions vanish into this canvas. Retune the surface apart: move the background stop, or pin actionBackground to a separated stop.`})}}const L=o("link"),_=o("linkHover"),g=o("linkHoverBg");if(c&&L&&_&&g){const r=Math.abs(I(L,c)),a=Math.abs(I(_,g));w(g,c)>=me?a+D<H&&t.push({id:"link-hover-ordering",severity:"warning",tokens:["linkHoverBg","linkHover"],measured:h(H-a,1),message:`linkHover reaches only Lc ${h(a,1)} on the linkHoverBg wash it actually paints (tier ${H}) \u2014 retune linkHoverBg before changing linkHover; the wash has one consumer while the ink has many.`}):a+D<r&&t.push({id:"link-hover-ordering",severity:"warning",tokens:["linkHover","link"],measured:h(r-a,1),message:`linkHover reads weaker than link on the same canvas (Lc ${h(a,1)} vs ${h(r,1)}) \u2014 a dimming hover feels disabled. Retune linkHover toward more contrast than the resting link.`})}const v=r=>Math.abs(I(S,r))>=Math.abs(I(P,r))?"dark":"light",d=e.tokens.find(r=>r.token==="actionBackground"),u=e.tokens.find(r=>r.token==="actionText"),l=[],s=[];let i=0;const k=u?.anchor?b(u.anchor.color):null,f=u?b(u.resolved):null,p=d?.anchor?b(d.anchor.color):null,E=d?b(d.resolved):null,M=f&&E?f.l>E.l?"light":"dark":null;d?.anchor&&p&&E&&M&&d.anchor.deltaE>=N&&v(p)!==M&&(l.push("actionBackground"),i=Math.max(i,d.anchor.deltaE),s.push(`"${d.anchor.reference}" wants ${v(p)} ink but actionBackground renders carrying a ${M} label (\u0394E ${h(d.anchor.deltaE,4)})`)),u?.anchor&&u.pairing!=="derived"&&k&&f&&p&&E&&u.anchor.deltaE>=N&&p.l!==k.l&&Math.sign(p.l-k.l)!==Math.sign(E.l-f.l)&&(l.push("actionText"),i=Math.max(i,u.anchor.deltaE),s.push(`the declared pair puts "${d.anchor.reference}" ${p.l>k.l?"above":"below"} "${u.anchor.reference}" in lightness and the rendered pair puts it ${E.l>f.l?"above":"below"} (\u0394E ${h(u.anchor.deltaE,4)})`)),l.length>0&&t.push({id:"action-anchor-inversion",severity:"warning",tokens:l,measured:h(i,4),message:`The filled action renders the opposite way round from the swatches it names: ${s.join("; ")}. `+(d?.explicit===void 0?"A filled action's ramp stop is chosen by the engine near its mid-band target, so seating the ramp cannot move it the way it moves every other anchored token. Retune by pinning semanticMappings.actionBackground to a stop that carries the swatch":"semanticMappings.actionBackground is already pinned, so the engine did not place this \u2014 retune the stop that pin names")+" \u2014 and check the pair still clears its tier there, because a swatch this far off the band often cannot hold a label at its own lightness."});const q=e.tokens.flatMap(({token:r,apca:a})=>a?[{...a,token:r,threshold:Math.min(a.targetLc,he),component:!1}]:[]),z=(e.componentProperties??[]).flatMap(({name:r,apca:a,targetLc:R})=>a&&R!==void 0?[{...a,token:r,threshold:R,component:!0}]:[]),A=[...q,...z].filter(({toLc:r,threshold:a})=>r<a).sort((r,a)=>a.threshold-a.toLc-(r.threshold-r.toLc)||(r.token<a.token?-1:r.token>a.token?1:0));if(A.length>0){const r=A[0],a=A.map(({token:O,toLc:K,against:G,threshold:Y,component:W})=>`${O} reaches Lc ${h(K,1)} on ${G} (${W?"target":"floor"} ${Y})`),R=b(r.againstColor),U=R!==null&&Math.max(Math.abs(I(S,R)),Math.abs(I(P,R)))>=r.threshold;t.push({id:"apca-target-unmet",severity:"warning",tokens:A.map(O=>O.token),measured:h(r.threshold-r.toLc,1),message:r.component?`${a.join(", ")}. The stronger ink pole falls short against the reported ground. Retune the component ground to a lightness that can carry the target.`:`${a.join(", ")} \u2014 enforcement moved the ink as far as this ramp allows and the pair still falls short. `+(U?"The opposite ink pole does clear the floor on that ground, so the emitted ink is on the weaker side rather than the ground being impossible \u2014 check the pairing before retuning the ground.":"No ink reaches the floor on that ground, so retune the ground each pair reads against toward a lightness that can carry it.")})}return t}const x=":root",Ne=T({scheme:{kind:"scheme",compared:!0},seedColor:{kind:"string",compared:!0},anchors:{kind:"anchor-record",compared:!0},tokens:{kind:"token-array",compared:!0},componentProperties:{kind:"component-property-array",compared:!0},adjustedTokens:{kind:"semantic-array",compared:!0},surface:{kind:"string",compared:!0},lints:{kind:"lint-array",compared:!0}}),De=T({surfaces:{kind:"string-array",compared:!0},dataPalette:{kind:"data-palette-record",compared:!0},paletteLints:{kind:"palette-lint-record",compared:!0},light:{kind:"report-array",compared:!0},dark:{kind:"report-array",compared:!0},paint:{kind:"paint-record",compared:!1}});function Be(e,t,n={}){const o=y(Z,e),c=y(Q,t),m=[x,...[...new Set([...Object.keys(o.contexts),...Object.keys(c.contexts)])].sort()],L=l=>{const s={};for(let i=0;i<C.length;i+=1){const k=C[i],f=`--esp-color-series-${i+1}`,p=l[f];if(p===void 0)throw new Error(`Theme fit report did not emit required property ${f}.`);s[k]=p}return s},_=l=>X(l).map(s=>{const i=h(s.distance,4);return{id:"data-palette-cvd-collision",severity:"warning",series:s.series,simulation:s.simulation,measured:i,threshold:s.threshold,message:J(s)}}),g=(l,s)=>{const i=F(l,s);if(Object.keys(i.properties).length===0)throw new Error(`themeFitReportSuite: ${s} root emitted no properties for seed "${l.seedColor}".`);const k=new Map;n.paintSurfaces!==void 0&&k.set(null,i.properties);const f=[{...i.report,surface:x,lints:B(i.report)}];for(const p of m){if(p===x||!(p in l.contexts))continue;const E=F(l,s,{context:p});n.paintSurfaces!==void 0&&k.set(p,E.properties);const M=E.report;f.push({...M,surface:p,lints:B(M)})}return{dataPalette:L(i.properties),reports:f,paintProperties:k}},v=g(o,"light"),d=g(c,"dark"),u={light:v.dataPalette,dark:d.dataPalette};return{surfaces:m,dataPalette:u,paletteLints:{light:_(u.light),dark:_(u.dark)},light:v.reports,dark:d.reports,...n.paintSurfaces===void 0?{}:{paint:ae({light:v.paintProperties,dark:d.paintProperties},n.paintSurfaces,n.extraEntries)}}}function h(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}function V(e,t){return t===void 0?e:`${e}.${t}`}function ke(e){const t={};for(const[n,o]of Object.entries(e)){if(typeof o=="string"){t[n]=o;continue}for(const[c,m]of Object.entries(o))t[c==="color"?n:V(n,c)]=m}return t}function fe(e){const t=b(e.resolved),n=e.requested===void 0?e.resolved:$(e.requested),o={token:e.token,property:e.property,source:e.source,lightness:e.lightness,requested:n,resolved:e.resolved,adjusted:n!==e.resolved,sourceResolved:e.sourceResolved},c=te(e.source);if(c&&e.sourceResolved&&(o.anchor={reference:V(c.name,c.slot),color:$(e.base),deltaE:h(w(e.base,t),4)}),e.contrast){const m=e.contrast.background;o.apca={from:n,to:e.resolved,targetLc:e.contrast.targetLc,against:e.contrast.against,againstColor:$(m),fromLc:h(Math.abs(I(b(n),m)),1),toLc:h(Math.abs(I(t,m)),1)}}return o}function ge(e){if(!e.apca)return"";const{targetLc:t,against:n,fromLc:o,toLc:c}=e.apca;return e.adjusted?`Lc ${t} vs ${n} \u2014 pushed from Lc ${o} to Lc ${c}`:`Lc ${t} vs ${n} \u2014 met at Lc ${o}`}function Ee(e){return e.anchor?`${e.anchor.reference} \u0394E ${e.anchor.deltaE}`:e.sourceResolved?"":"unresolved \u2014 seed used"}export{x as ROOT_SURFACE,He as THEME_FIT_ANCHOR_FIELDS,Se as THEME_FIT_APCA_FIELDS,Pe as THEME_FIT_COMPONENT_APCA_FIELDS,Ce as THEME_FIT_COMPONENT_PROPERTY_FIELDS,je as THEME_FIT_DATA_PALETTE_LINT_FIELDS,xe as THEME_FIT_DATA_PALETTE_LINT_IDS,Oe as THEME_FIT_EXPLICIT_VALUES,ye as THEME_FIT_LINT_FIELDS,Ae as THEME_FIT_LINT_IDS,$e as THEME_FIT_LINT_SEVERITIES,we as THEME_FIT_PAIRING_VALUES,Ne as THEME_FIT_REPORT_FIELDS,De as THEME_FIT_SUITE_FIELDS,Fe as THEME_FIT_TOKEN_FIELDS,Me as printThemeFitReport,B as themeFitLints,Re as themeFitReport,Be as themeFitReportSuite,ie as themeFitRows};
@@ -0,0 +1,16 @@
1
+ import type { ColorSource, LightnessKey } from "./theme-core.js";
2
+ /** Anchor names and slot names share one slug grammar. */
3
+ export declare const ANCHOR_SLUG_PATTERN: RegExp;
4
+ /** Valid color-source identifiers for {@link SemanticMapping.source}. */
5
+ export declare const COLOR_SOURCES: readonly ColorSource[];
6
+ /** Valid keys for the lightness ramp. */
7
+ export declare const LIGHTNESS_KEYS: readonly LightnessKey[];
8
+ /** Return the custom tone name carried by a valid `tone:<slug>` reference. */
9
+ export declare function toneReferenceName(reference: unknown): string | null;
10
+ /** True when a string names one of the eleven engine-owned ramp stops. */
11
+ export declare function isLightnessKey(reference: unknown): reference is LightnessKey;
12
+ /** True for an ordinary record whose entries can be merged by key. */
13
+ export declare function isObjectRecord(value: unknown): value is Record<string, unknown>;
14
+ export declare function isThemeSlug(name: string): boolean;
15
+ export declare function isThemeTone(name: string, tone: unknown): tone is number;
16
+ export declare function isColorSource(value: unknown): value is ColorSource;
@@ -0,0 +1 @@
1
+ import{isSafeKey as i}from"./unsafe-keys.js";const o=/^[a-z][a-z0-9-]*$/,s=["primary","analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning","info"],u=["surface","raised1","raised2","raised3","raised4","accent","muted","text","border","ink","shadow"],e="tone:";function l(t){if(typeof t!="string"||!t.startsWith(e))return null;const r=t.slice(e.length);return n(r)?r:null}function c(t){return typeof t!="string"?!1:u.includes(t)}function p(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function n(t){return i(t)&&o.test(t)}function f(t,r){return n(t)&&!c(t)&&typeof r=="number"&&Number.isFinite(r)&&r>=0&&r<=1}function m(t){return typeof t=="string"&&s.includes(t)}export{o as ANCHOR_SLUG_PATTERN,s as COLOR_SOURCES,u as LIGHTNESS_KEYS,m as isColorSource,c as isLightnessKey,p as isObjectRecord,n as isThemeSlug,f as isThemeTone,l as toneReferenceName};
@@ -17,7 +17,7 @@
17
17
  * The module is side-effect free: importing it registers no custom element and
18
18
  * touches no DOM.
19
19
  */
20
- import type { EspalierTheme } from "./theme.js";
20
+ import type { EspalierTheme } from "./theme-core.js";
21
21
  /** The two color schemes a theme resolves for. */
22
22
  export type ThemeScheme = "light" | "dark";
23
23
  /** Optional instance-level scale preview settings; no DOM measurement is performed. */
@@ -35,6 +35,8 @@ export interface ThemePropertyOptions {
35
35
  * data colors, the lightness ramp, APCA-enforced semantic colors, data
36
36
  * companions, the type and space scales, font families and weights, and the
37
37
  * optional background-image and vellum properties a theme declares.
38
+ * Valid component properties are computed for the supplied surface. Pass
39
+ * a theme returned by `resolveContextTheme` to compute a named context.
38
40
  *
39
41
  * Pass a **resolved** theme — one merged over `DEFAULT_LIGHT_THEME` or
40
42
  * `DEFAULT_DARK_THEME` with `mergeTheme` from `./shared/theme`. An unparseable
@@ -1 +1 @@
1
- import{computeThemeProperties as t}from"../root/helpers/compute-theme-properties.js";function p(e,r,o={}){return t(e,r,void 0,o)}export{p as computeThemeProperties};
1
+ import{computeThemeProperties as t}from"../root/helpers/compute-theme-properties.js";import{getComponentPropertyAnalysis as p}from"./component-property-normalizer.js";function s(e,o,r={}){const n=e.componentProperties===void 0?void 0:{surface:p(e).root};return t(e,o,void 0,r,n)}export{s as computeThemeProperties};
@@ -0,0 +1,52 @@
1
+ /** Structural validation and advisory audits for encoded themes. */
2
+ import type { ThemeScheme } from "./theme-properties.js";
3
+ /** One invalid component-property declaration in an encoded theme pair. */
4
+ export interface ComponentPropertyFinding {
5
+ scheme: ThemeScheme;
6
+ /** Null identifies the root of the scheme. */
7
+ context: string | null;
8
+ /** Null identifies a malformed componentProperties map. */
9
+ property: string | null;
10
+ code: "unknown" | "not_settable" | "private" | "bad_value";
11
+ /** Closest settable property for an unknown name. */
12
+ nearest: string | null;
13
+ /** Accepted syntax or values for a malformed declaration. */
14
+ accepted: string | null;
15
+ }
16
+ /** Validation result returned by {@link validateTheme}. */
17
+ export interface ThemeValidationResult {
18
+ /** `true` when there are zero errors (warnings are allowed). */
19
+ valid: boolean;
20
+ /** Hard failures — the theme should not be applied. */
21
+ errors: string[];
22
+ /** Soft issues — the theme will work but values are unusual. */
23
+ warnings: string[];
24
+ }
25
+ /**
26
+ * Validate component-property declarations in a light and dark theme.
27
+ * A payload that cannot be decoded has no declarations to inspect; use
28
+ * validateThemePair for decode errors and other theme validation.
29
+ */
30
+ export declare function validateComponentProperties(lightBase64: string, darkBase64: string): ComponentPropertyFinding[];
31
+ /**
32
+ * Validate a single encoded theme partial.
33
+ *
34
+ * Structural grammar aside, the advisory checks (the status-collision
35
+ * warning and chroma-band provenance) resolve the partial against
36
+ * {@link DEFAULT_LIGHT_THEME}. A partial written for the dark side of a
37
+ * pair should be validated through {@link validateThemePair}, which
38
+ * audits it against the dark defaults instead.
39
+ */
40
+ export declare function validateTheme(base64: string): ThemeValidationResult;
41
+ /**
42
+ * Validate the light and dark partials that form one scheme-paired theme.
43
+ *
44
+ * Each side runs the same validation as {@link validateTheme}, with one
45
+ * scheme-aware difference: the dark partial's advisory checks resolve
46
+ * against {@link DEFAULT_DARK_THEME}, so a collision that only appears
47
+ * through the dark ramp is caught. Once both sides are structurally
48
+ * valid, their context-name sets must match exactly so a stable
49
+ * `context` attribute cannot silently change meaning when the scheme
50
+ * changes.
51
+ */
52
+ export declare function validateThemePair(lightBase64: string, darkBase64: string): ThemeValidationResult;
@@ -0,0 +1 @@
1
+ import{isSafeKey as G}from"./unsafe-keys.js";import{classifyComponentPropertyName as Oe,describeAcceptedComponentPropertyValue as Ee,nearestSettableComponentProperty as _e}from"./component-property-diagnostics.js";import{normalizeComponentProperties as Pe}from"./component-property-normalizer.js";import{SETTABLE_COMPONENT_PROPERTIES as Be}from"./settable-component-properties.js";import{isColorSource as Ne}from"./theme-mapping-grammar.js";import{ACCEPTED_COLOR_FORMS as X,clampChannel as ne,deriveSemantic as Le,gamutMapToSRGB as se,linearRgbToOklab as De,oklchToSRGB as Fe,parseCssColor as W,serializeOklch as oe,srgbToLinearRGB as Ie}from"./color-engine.js";import{auditColorDistances as $e,auditDataPalette as He,describePaletteCollision as We,DATA_SERIES_KEYS as re,DEFAULT_DATA_RAMP_STEPS as Ke,MAX_DATA_RAMP_STEPS as ae,MIN_DATA_RAMP_LIGHTNESS_STEP as ye,MIN_DATA_RAMP_STEPS as ie}from"./data-colors.js";import{computeVariants as Ge,resolveMappingSource as Ue}from"./variant-engine.js";import{ANCHOR_SLUG_PATTERN as U,COLOR_SOURCES as be,DEFAULT_DARK_THEME as Je,DEFAULT_LIGHT_THEME as ve,LIGHTNESS_KEYS as ee,MAX_CHROMA as J,ROLE_NAMES as Ae,ROLE_TOKEN_PLAN as Ve,SEMANTIC_COLOR_NAMES as q,STATUS_COLOR_SOURCES as Q,VARIANT_COLOR_SOURCES as ze,decodeThemeJson as qe,isLightnessKey as ce,isObjectRecord as Se,mergeTheme as ue,parseAnchorSource as ke,resolveAnchorColor as Ye,resolveContextTheme as we,resolveDataColorSource as Xe,resolveLightnessReference as Qe,toneReferenceName as Ze}from"./theme-core.js";function je(n,u){const t=new Map;try{const c=ue(u,n),g=(p,d,S,y)=>{const v=ke(d),P=v?Ye(y,v):null,B=P===null?null:W(P),N=t.get(p)??[];N.some(L=>L.source===d&&L.chroma===B?.c)||(N.push({source:d,where:S,chroma:B?.c}),t.set(p,N))};for(const[p,d]of Object.entries(c.semanticMappings))d.source.startsWith("anchor:")&&g(p,d.source,"the root table",c.anchors);for(const p of Object.keys(c.contexts)){const d=we(c,p);if(d)for(const[S,y]of Object.entries(d.semanticMappings))y.source.startsWith("anchor:")&&g(S,y.source,`contexts.${p}`,d.anchors)}}catch{return new Map}return t}function Z(n){let u;try{u=qe(n)}catch{return{error:"Failed to decode Base64 string."}}let t;try{t=JSON.parse(u)}catch{return{error:"Decoded string is not valid JSON."}}return typeof t!="object"||t===null||Array.isArray(t)?{error:"Theme must be a JSON object."}:{value:t}}function j(n,u){const t=Pe(n,u);return t.findings.map(c=>{const{context:g,property:p}=c;if(c.code==="bad_value")return{scheme:t.scheme,context:g,property:p,code:"bad_value",nearest:null,accepted:Ee(p===null?void 0:Be[p])};const d=Oe(c.property),S=d==="settable"?"unknown":d;return{scheme:t.scheme,context:g,property:p,code:S,nearest:S==="unknown"?_e(c.property)??null:null,accepted:null}})}function xe(n){const{scheme:u,context:t,property:c,code:g,nearest:p,accepted:d}=n,S=t===null?"":`contexts.${t}.`,y=`${u}: ${S}componentProperties${c===null?"":`.${c}`}`;switch(g){case"bad_value":return`${y} must be ${d}.`;case"private":return`${y} is a private component property.`;case"not_settable":return`${y} is a public token that themes cannot set as a component property.`;case"unknown":return`${y} is an unknown component property.${p?` Did you mean ${p}?`:""}`}}function mt(n,u){const t=Z(n),c=Z(u);return[...t.value?j(t.value,"light"):[],...c.value?j(c.value,"dark"):[]]}function pt(n){const u=Z(n);if(u.error!==void 0)return{valid:!1,errors:[u.error],warnings:[]};const t=le(u.value),c=[...t.errors,...j(u.value,"light").map(xe)];return{...t,errors:c,valid:c.length===0}}function le(n,u=ve){const t=[],c=[];"seedColor"in n&&(typeof n.seedColor!="string"?t.push("seedColor must be a string."):W(n.seedColor)||t.push(`seedColor is not a valid CSS color: "${n.seedColor}". Accepted forms: ${X}.`));for(const e of["fontBody","fontHeadings","fontBrand","fontMenu","fontMonospace"])e in n&&typeof n[e]!="string"&&t.push(`${e} must be a string.`);const g=["normal","bold","lighter","bolder"],p=["inherit","initial","unset","revert","revert-layer"];for(const e of["fontWeightBody","fontWeightHeadings","fontWeightBrand","fontWeightMenu","fontWeightMonospace"])if(e in n){const s=n[e];if(typeof s=="number")(s<1||s>1e3)&&t.push(`${e} numeric value must be 1\u20131000 (got ${s}).`);else if(typeof s=="string"){const o=g.includes(s)||p.includes(s);if(/^\d+$/.test(s)){const i=Number(s);(i<1||i>1e3)&&t.push(`${e} numeric value must be 1\u20131000 (got "${s}").`)}else o||c.push(`${e} = "${s}" is not a standard font-weight value.`)}else t.push(`${e} must be a string or number.`)}"stylesheets"in n&&(Array.isArray(n.stylesheets)?n.stylesheets.some(e=>typeof e!="string")&&t.push("Every entry in stylesheets must be a string."):t.push("stylesheets must be an array of strings."));const d=[["rootFontSize",1,100],["borderRadius",0,10],["viewportMin",100,1e4],["viewportMax",200,1e4]];for(const[e,s,o]of d)if(e in n)if(typeof n[e]!="number"||!isFinite(n[e]))t.push(`${e} must be a finite number.`);else{const a=n[e];s!==void 0&&a<s&&t.push(`${e} must be \u2265 ${s} (got ${a}).`),o!==void 0&&a>o&&c.push(`${e} = ${a} is unusually high (max ${o}).`)}for(const e of["typeRatio","spaceRatio"])if(e in n)if(typeof n[e]!="number"||!isFinite(n[e]))t.push(`${e} must be a finite number.`);else{const s=n[e];s<=1&&t.push(`${e} must be > 1 (got ${s}).`);const o=e==="typeRatio"?1.3:2;s>o&&c.push(`${e} = ${s} is very high (max ${o}); scales may be extreme.`)}if("viewportMin"in n&&"viewportMax"in n){const e=n.viewportMin,s=n.viewportMax;typeof e=="number"&&typeof s=="number"&&e>=s&&t.push(`viewportMin (${e}) must be less than viewportMax (${s}).`)}if("angles"in n)if(typeof n.angles!="object"||n.angles===null)t.push("angles must be an object.");else{const e=n.angles;for(const s of["analogous","complementary","splitComplementary","triadic"])if(s in e)if(typeof e[s]!="number"||!isFinite(e[s]))t.push(`angles.${s} must be a finite number.`);else{const o=e[s];(o<0||o>360)&&c.push(`angles.${s} = ${o} is outside 0\u2013360.`)}}if("semanticHues"in n)if(typeof n.semanticHues!="object"||n.semanticHues===null)t.push("semanticHues must be an object.");else{const e=n.semanticHues;for(const s of["danger","success","warning","info"])if(s in e)if(typeof e[s]!="number"||!isFinite(e[s]))t.push(`semanticHues.${s} must be a finite number.`);else{const o=e[s];(o<0||o>360)&&c.push(`semanticHues.${s} = ${o} is outside 0\u2013360.`)}}if("variantChroma"in n)if(typeof n.variantChroma!="object"||n.variantChroma===null)t.push("variantChroma must be an object.");else{const e=n.variantChroma;for(const s of ze)if(s in e)if(typeof e[s]!="number"||!isFinite(e[s]))t.push(`variantChroma["${s}"] must be a finite number.`);else{const o=e[s];o<0&&t.push(`variantChroma["${s}"] must be \u2265 0 (got ${o}).`),o>J&&c.push(`variantChroma["${s}"] = ${o} exceeds ${J}.`)}}function S(e,s){if(typeof e!="object"||e===null||Array.isArray(e)){t.push(`${s} must be an object.`);return}const o=e;for(const a of Object.keys(o))(!G(a)||!ce(a))&&t.push(`${s}.${a} is not a built-in lightness stop; expected one of: ${ee.join(", ")}.`);for(const a of ee)if(a in o)if(typeof o[a]!="number"||!isFinite(o[a]))t.push(`${s}.${a} must be a finite number.`);else{const i=o[a];(i<0||i>1)&&t.push(`${s}.${a} must be 0\u20131 (got ${i}).`)}}"lightness"in n&&S(n.lightness,"lightness");function y(e,s){const o=new Set;if(!Se(e))return t.push(`${s} must be an object.`),o;for(const[a,i]of Object.entries(e)){if(!G(a)||!U.test(a)){t.push(`${s}.${a} must be a lowercase slug matching ${U.source}.`);continue}if(ce(a)){t.push(`${s}.${a} conflicts with the built-in "${a}" lightness stop; choose a distinct custom tone name.`);continue}o.add(a),typeof i!="number"||!Number.isFinite(i)?t.push(`${s}.${a} must be a finite number.`):(i<0||i>1)&&t.push(`${s}.${a} must be 0\u20131 (got ${i}).`)}return o}const v=new Set(Object.keys(u.tones??{}));if("tones"in n)for(const e of y(n.tones,"tones"))v.add(e);if("chroma"in n)if(typeof n.chroma!="object"||n.chroma===null)t.push("chroma must be an object.");else{const e=n.chroma,s=je(n,u);for(const o of q)if(o in e){const a=e[o];if(typeof a!="object"||a===null){t.push(`chroma.${o} must be { min, max }.`);continue}const i=a;for(const r of s.get(o)??[])r.chroma!==void 0&&typeof i.min=="number"&&typeof i.max=="number"&&(r.chroma<i.min-1e-9||r.chroma>i.max+1e-9)&&c.push(`chroma.${o} clamps the anchor-sourced token ${o} ("${r.source}", effective in ${r.where}) and moves it off its declared swatch. Remove the band if that is unintended \u2014 anchors otherwise keep their own chroma.`);const l=a;(typeof l.min!="number"||l.min<0)&&t.push(`chroma.${o}.min must be \u2265 0.`),(typeof l.max!="number"||l.max<0||l.max>J)&&t.push(`chroma.${o}.max must be 0\u2013${J}.`),typeof l.min=="number"&&typeof l.max=="number"&&l.min>l.max&&t.push(`chroma.${o}.min (${l.min}) must be \u2264 max (${l.max}).`)}}if("anchors"in n)if(typeof n.anchors!="object"||n.anchors===null||Array.isArray(n.anchors))t.push("anchors must be an object of named colors.");else for(const[e,s]of Object.entries(n.anchors))if(G(e)?U.test(e)||t.push(`anchors: "${e}" is not a valid anchor name; use a lowercase slug (letters, digits, hyphens).`):t.push(`anchors: "${e}" is a reserved JavaScript property name and cannot be an anchor name; rename it.`),be.includes(e)&&t.push(`anchors: "${e}" collides with a reserved color source name.`),typeof s=="string")W(s)||t.push(`anchors.${e} is not a valid CSS color: "${s}". Accepted forms: ${X}.`);else if(typeof s=="object"&&s!==null&&!Array.isArray(s)){const o=s;typeof o.color!="string"&&t.push(`anchors.${e} must declare its base "color".`);for(const[a,i]of Object.entries(o))G(a)?a!=="color"&&!U.test(a)&&t.push(`anchors.${e}: "${a}" is not a valid slot name; use a lowercase slug.`):t.push(`anchors.${e}: "${a}" is a reserved JavaScript property name and cannot be a slot name; rename it.`),typeof i!="string"?t.push(`anchors.${e}.${a} must be a CSS color string.`):W(i)||t.push(`anchors.${e}.${a} is not a valid CSS color: "${i}". Accepted forms: ${X}.`)}else t.push(`anchors.${e} must be a color string or a { color, \u2026slots } object.`);const P=new Map;if("anchors"in n&&typeof n.anchors=="object"&&n.anchors!==null&&!Array.isArray(n.anchors))for(const[e,s]of Object.entries(n.anchors))P.set(e,s);function B(e,s){const o=ke(e);if(!o){t.push(`${s} "${e}" is not valid anchor syntax; use anchor:<name> or anchor:<name>.<slot>.`);return}if(!P.has(o.name)){const a=[...P.keys()];t.push(`${s} references undeclared anchor "${o.name}". Declared anchors: ${a.length>0?a.join(", "):"(none)"}.`);return}if(o.slot!==void 0){const a=P.get(o.name);if(typeof(typeof a=="object"&&a!==null&&!Array.isArray(a)?a[o.slot]:void 0)!="string"){const l=typeof a=="object"&&a!==null?Object.keys(a).filter(r=>r!=="color"):[];t.push(`${s} references unknown slot "${o.slot}" on anchor "${o.name}". Declared slots: ${l.length>0?l.join(", "):"(none)"}.`)}}}function N(e,s){if(e.startsWith("anchor:")){B(e,s);return}Ne(e)||t.push(`${s} must be one of: ${be.join(", ")}, or a declared anchor as anchor:<name> / anchor:<name>.<slot>.`)}if("intents"in n)if(typeof n.intents!="object"||n.intents===null||Array.isArray(n.intents))t.push("intents must be an object.");else for(const[e,s]of Object.entries(n.intents)){const o=`intents.${e}`;if(!Q.includes(e)){t.push(`${o} is not a status family; expected one of: ${Q.join(", ")}.`);continue}if(typeof s!="string"){t.push(`${o} must be a string (a CSS color or an anchor: reference).`);continue}if(s.startsWith("anchor:")){B(s,o);continue}W(s)||t.push(`${o} "${s}" is not a supported color form or anchor: reference. Accepted forms: ${X}, or anchor:<name> / anchor:<name>.<slot>. An override retunes a family with a declared color; it never points one family at another \u2014 retune, never reassign.`)}function L(e,s){if(e.startsWith("anchor:")){B(e,s);return}W(e)||t.push(`${s} is not a valid CSS color: "${e}". Accepted forms: ${X}, or a declared anchor as anchor:<name> / anchor:<name>.<slot>.`)}if("dataPalette"in n)if(typeof n.dataPalette!="object"||n.dataPalette===null||Array.isArray(n.dataPalette))t.push("dataPalette must be an object with series1\u2013series8 color values.");else{const e=n.dataPalette;for(const[s,o]of Object.entries(e)){if(!re.includes(s)){t.push(`dataPalette.${s} is not a series slot; expected one of: ${re.join(", ")}.`);continue}typeof o!="string"?t.push(`dataPalette.${s} must be a CSS color or anchor reference string.`):L(o,`dataPalette.${s}`)}}if("dataRamps"in n)if(typeof n.dataRamps!="object"||n.dataRamps===null||Array.isArray(n.dataRamps))t.push("dataRamps must be an object of named ramp declarations.");else for(const[e,s]of Object.entries(n.dataRamps)){if(G(e)?U.test(e)||t.push(`dataRamps: "${e}" is not a valid ramp name; use a lowercase slug (letters, digits, hyphens).`):t.push(`dataRamps: "${e}" is a reserved JavaScript property name and cannot be a ramp name; rename it.`),typeof s!="object"||s===null||Array.isArray(s)){t.push(`dataRamps.${e} must be a sequential or diverging ramp object.`);continue}const o=s,a=o.steps??Ke;if((typeof a!="number"||!Number.isInteger(a)||a<ie||a>ae)&&t.push(`dataRamps.${e}.steps must be an integer from ${ie} through ${ae}.`),o.type==="sequential"){typeof o.source!="string"?t.push(`dataRamps.${e}.source must be a CSS color or anchor reference string.`):L(o.source,`dataRamps.${e}.source`);const i=o.lightnessStart??.95,l=o.lightnessEnd??.25;for(const[r,f]of[["lightnessStart",i],["lightnessEnd",l]])(typeof f!="number"||!Number.isFinite(f)||f<0||f>1)&&t.push(`dataRamps.${e}.${r} must be a finite number from 0 through 1.`);typeof i=="number"&&typeof l=="number"&&i<=l?t.push(`dataRamps.${e}.lightnessStart must be greater than lightnessEnd.`):typeof i=="number"&&Number.isFinite(i)&&typeof l=="number"&&Number.isFinite(l)&&typeof a=="number"&&Number.isInteger(a)&&a>=ie&&a<=ae&&(i-l)/(a-1)<=ye&&t.push(`dataRamps.${e} lightness bounds must leave more than ${ye} lightness between serialized stops.`);continue}if(o.type==="diverging"){typeof a=="number"&&Number.isInteger(a)&&a%2===0&&t.push(`dataRamps.${e}.steps must be odd so the neutral is the exact midpoint.`);for(const i of["start","end"])typeof o[i]!="string"?t.push(`dataRamps.${e}.${i} must be a CSS color or anchor reference string.`):L(o[i],`dataRamps.${e}.${i}`);"neutral"in o&&(typeof o.neutral!="string"?t.push(`dataRamps.${e}.neutral must be a CSS color or anchor reference string.`):L(o.neutral,`dataRamps.${e}.neutral`));continue}t.push(`dataRamps.${e}.type must be "sequential" or "diverging".`)}if("dataPalette"in n&&t.length===0){const e=ue(ve,n),s={};let o=!0;for(const a of re){const i=Xe(e.dataPalette[a],e.anchors);if(!i){o=!1;break}s[a]=i}if(o)for(const a of He(s))c.push(We(a))}function Y(e,s){if(typeof e!="object"||e===null||Array.isArray(e)){t.push(`${s} must be an object.`);return}const o=e;for(const[a,i]of Object.entries(o)){const l=`${s}.${a}`;if(!Ae.includes(a)){t.push(`${l} is not a role; expected one of: ${Ae.join(", ")}. (The status family is reserved and is not a role.)`);continue}const r=a,f=Ve[r];if(typeof i=="string"){N(i,l);continue}if(typeof i!="object"||i===null||Array.isArray(i)){t.push(`${l} must be a color source or a { color, \u2026slots } object.`);continue}const m=i;typeof m.color!="string"&&t.push(`${l} must declare its base "color".`);for(const[h,k]of Object.entries(m)){if(!Object.prototype.hasOwnProperty.call(f,h)||!G(h)){const b=Object.keys(f).filter(R=>R!=="color");t.push(`${l}.${h} is not a slot of the ${r} role. Declared slots: ${b.length>0?b.join(", "):"(none)"}.`);continue}typeof k!="string"?t.push(`${l}.${h} must be a color source string.`):N(k,`${l}.${h}`)}}}if("roles"in n&&Y(n.roles,"roles"),"contexts"in n)if(typeof n.contexts!="object"||n.contexts===null||Array.isArray(n.contexts))t.push("contexts must be an object.");else for(const[e,s]of Object.entries(n.contexts)){if(!G(e)||!U.test(e)){t.push(`contexts.${e} must be a lowercase slug matching ${U.source}.`);continue}if(typeof s!="object"||s===null||Array.isArray(s)){Y(s,`contexts.${e}`);continue}const o=s,a=Object.fromEntries(Object.entries(o).filter(([l])=>l!=="lightness"&&l!=="tones"&&l!=="semanticMappings"&&l!=="componentProperties"));Y(a,`contexts.${e}`),"lightness"in o&&S(o.lightness,`contexts.${e}.lightness`);const i=new Set(v);if("tones"in o)for(const l of y(o.tones,`contexts.${e}.tones`))i.add(l);"semanticMappings"in o&&F(o.semanticMappings,`contexts.${e}.semanticMappings`,i)}function F(e,s,o){if(typeof e!="object"||e===null||Array.isArray(e)){t.push(`${s} must be an object.`);return}const a=e;for(const i of Object.keys(a))q.includes(i)||t.push(`${s}.${i} is not a semantic token; expected one of: ${q.join(", ")}.`);for(const i of q)if(i in a){const l=a[i];if(typeof l!="object"||l===null){t.push(`${s}.${i} must be { source, lightness }.`);continue}const r=l;if(typeof r.source!="string"?t.push(`${s}.${i}.source must be a string.`):N(r.source,`${s}.${i}.source`),typeof r.lightness!="string")t.push(`${s}.${i}.lightness must be one of: ${ee.join(", ")}, or a declared tone:<name>.`);else if(!ce(r.lightness)){const f=Ze(r.lightness);if(f===null)t.push(`${s}.${i}.lightness must be one of: ${ee.join(", ")}, or a declared tone:<name>.`);else if(!o.has(f)){const m=[...o].sort();t.push(`${s}.${i}.lightness references undeclared tone "${f}". Declared tones: ${m.length>0?m.join(", "):"(none)"}.`)}}}}if("semanticMappings"in n&&F(n.semanticMappings,"semanticMappings",v),"explicitMappingTokens"in n)if(!Array.isArray(n.explicitMappingTokens))t.push("explicitMappingTokens must be an array of semantic token names.");else{const e=new Set,s=Se(n.semanticMappings)?n.semanticMappings:void 0;for(const o of n.explicitMappingTokens){if(typeof o!="string"||!q.includes(o)){t.push(`explicitMappingTokens entries must be one of: ${q.join(", ")}.`);continue}e.has(o)&&t.push(`explicitMappingTokens contains duplicate token "${o}".`),e.add(o),(!s||!Object.prototype.hasOwnProperty.call(s,o))&&t.push(`explicitMappingTokens names "${o}" without a semanticMappings entry.`)}}for(const e of["pageBackgroundImage","boxBackgroundImage","vellumBackgroundImage"])e in n&&typeof n[e]!="string"&&t.push(`${e} must be a string.`);for(const e of["pageBackgroundImageOpacity","boxBackgroundImageOpacity","vellumOpacity","vellumBackgroundImageOpacity"])if(e in n)if(typeof n[e]!="number"||!isFinite(n[e]))t.push(`${e} must be a finite number.`);else{const s=n[e];(s<0||s>1)&&t.push(`${e} must be 0\u20131 (got ${s}).`)}return c.push(...et(n,u)),{valid:t.length===0,errors:t,warnings:c}}const x=.045;function et(n,u){try{return tt(n,u)}catch{return[]}}function tt(n,u){const t=ue(u,n),c=Ce(t),g=[...c],p=new Set(c);for(const d of Object.keys(t.contexts)){const S=we(t,d);if(S)for(const y of Ce(S))p.has(y)||g.push(`contexts.${d}: ${y}`)}return g}function nt(n){const u=Fe(se(n)),t=Ie(u);return De({r:ne(t.r),g:ne(t.g),b:ne(t.b)})}function V(n,u){return Math.hypot(n.L-u.L,n.a-u.a,n.b-u.b)}function K(n){return nt(W(oe(se(n))))}function Me(n){return(Math.floor(n*1e4)/1e4).toFixed(4)}const z=2,Re=1e-4;function Ce(n){const u=W(n.seedColor);if(!u)return[];const t=Ge(u,n),c=n.semanticMappings.actionBackground,g=n.chroma.actionBackground,p=Qe(n.lightness,n.tones,c.lightness),d=(r,f,m,h)=>se(Le(r,f,m,h)),S=Q.map(r=>({name:r,base:t[r]})),y=[];if(Q.includes(c.source))y.push(`actionBackground is sourced from the "${c.source}" status family: ordinary and ${c.source}-intent action surfaces render identically (their labels may still differ). Remap the action to a non-status source \u2014 retuning "${c.source}" via intents moves both colors together.`);else{const r=Ue(c.source,t,n.anchors);r&&S.push({name:"action",base:r})}const v=$e(S.map(({name:r,base:f})=>[r,oe(d(f,p,g.min,g.max))]),x,["normal"]);if(v.length===0)return y;const P=new Map,B=(r,f)=>{const m=`${r}:${f}`;let h=P.get(m);if(!h){h=[];for(let k=0;k<360;k+=z)h.push(K({l:r,c:f,h:k}));P.set(m,h)}return h},N=x-.002,L=(r,f,m,h)=>{const k=Math.hypot(r.a,r.b),b=Math.atan2(r.b,r.a)*180/Math.PI+180;let R=0;for(const M of m===h?[h]:[m,h]){if(M+k<x-1e-4)continue;let O=b,w=V(K({l:f,c:M,h:b}),r);if(w>=x)return w;const _=B(f,M);for(let A=0;A<_.length;A+=1){const $=V(_[A],r);if($>=x)return $;$>w&&(w=$,O=A*z)}let E=O;for(let A=O-z;A<=O+z;A+=.1){const $=V(K({l:f,c:M,h:A}),r);if($>=x)return $;$>w&&(w=$,E=A)}if(w>=N)for(let A=E-.1;A<=E+.1;A+=.001){const $=V(K({l:f,c:M,h:A}),r);if($>=x)return $;$>w&&(w=$)}w>R&&(R=w)}return R},Y=(r,f,m)=>{const h=f===m?[m]:[f,m];let k=0;for(const b of h)for(const R of h){if(b+R<x-1e-4)continue;const M=B(r,b),O=B(r,R);let w=0,_=0,E=-1;for(let T=0;T<M.length;T+=1)for(let D=0;D<O.length;D+=1){const I=V(M[T],O[D]);if(I>=x)return I;I>E&&(E=I,w=T*z,_=D*z)}const A=(T,D,I,fe)=>{const he=[];for(let H=D-I;H<=D+I;H+=fe)he.push({h:H,lab:K({l:r,c:R,h:H})});let te=-1,me=T,pe=D;for(let H=T-I;H<=T+I;H+=fe){const Te=K({l:r,c:b,h:H});for(const de of he){const ge=V(Te,de.lab);ge>te&&(te=ge,me=H,pe=de.h)}}return{distance:te,hueA:me,hueB:pe}},$=A(w,_,z,.1);if($.distance>=x)return $.distance;let C=Math.max(E,$.distance);if(C>=N){const T=A($.hueA,$.hueB,.1,.001);if(T.distance>C&&(C=T.distance),C>=x)return C}C>k&&(k=C)}return k},F=r=>Q.includes(r),e=(r,f,m,h,k)=>{const b=K(d(r.base,m,h,k)),R=K(d(f.base,m,h,k));if(V(b,R)>=x)return{outcome:"direct"};const M=F(r.name)&&F(f.name),O=[r,f].filter(E=>F(E.name)),w=M?"one of them":`"${F(r.name)?r.name:f.name}"`;let _;for(const E of O){const A=L(E===r?R:b,m,h,k);if(A>=x)return{outcome:"retune",target:w};A>=x-Re&&(_=_??w)}if(M){const E=Y(m,h,k);if(E>=x)return{outcome:"retune",target:"both"};E>=x-Re&&(_=_??"both")}return _!==void 0?{outcome:"near",target:_}:{outcome:"no"}},s=r=>r.outcome==="direct"?4:r.outcome==="retune"?r.target==="both"?2:3:r.outcome==="near"?1:0,o=r=>[...r].sort().join("|"),a=new Set($e(S.map(({name:r,base:f})=>[r,oe(d(f,p,0,J))]),x,["normal"]).map(r=>o(r.pair))),i=new Map(S.map(r=>[r.name,r])),l=new Map;for(const{pair:r,distance:f}of v){const m=i.get(r[0]),h=i.get(r[1]),k=F(m.name)&&F(h.name),b=e(m,h,p,g.min,g.max);if(b.outcome==="direct"||b.outcome==="retune"){const C=b.target??(k?"one of them":`"${F(m.name)?m.name:h.name}"`);a.has(o(r))?y.push(`Status colors "${r[0]}" and "${r[1]}" are hard to distinguish under normal vision (distance ${Me(f)} < ${x}); status meanings must stay distinguishable \u2014 retune ${C} via intents.`):y.push(`Status colors "${r[0]}" and "${r[1]}" are hard to distinguish as rendered (distance ${Me(f)} < ${x}); the actionBackground chroma band ({ min: ${g.min}, max: ${g.max} }) pushes them together \u2014 widen the band, or retune ${C} via intents.`);continue}const R=e(m,h,p,0,J);let M={outcome:"no"};for(let C=1;C<=19&&M.outcome!=="direct";C+=1){const T=C*.05;if(Math.abs(T-p)<.001)continue;const D=e(m,h,T,g.min,g.max);s(D)>s(M)&&(M=D)}let O={outcome:"no"};const w=R.outcome==="direct"||R.outcome==="retune",_=M.outcome==="direct"||M.outcome==="retune";if(!w&&!_)for(let C=1;C<=19&&O.outcome!=="direct";C+=1){const T=e(m,h,C*.05,0,J);s(T)>s(O)&&(O=T)}const E=st(R,M,O),A=`${b.outcome}|${E}`;let $=l.get(A);$||($=[],l.set(A,$)),$.push(r)}for(const[r,f]of l){const m=r.indexOf("|"),h=r.slice(0,m),k=r.slice(m+1),b=f.map(([O,w])=>`"${O}"/"${w}"`),R=b.length>1?`${b.slice(0,-1).join(", ")} and ${b[b.length-1]}`:b[0],M=h==="near"?`Status colors ${R} may not separate by retuning as rendered: at the action stop's lightness (${p}) with the actionBackground chroma band ({ min: ${g.min}, max: ${g.max} }), the closest reachable retune found comes within the audit's search margin of the ${x} threshold`:`Status colors ${R} cannot be separated as rendered: at the action stop's lightness (${p}) with the actionBackground chroma band ({ min: ${g.min}, max: ${g.max} }), no intent retuning can pull ${f.length>1?"these pairs":"the pair"} ${x} apart`;y.push(M+k)}return y}function st(n,u,t){if(n.outcome==="direct"&&u.outcome==="direct")return" \u2014 widen the chroma band or move the action lightness stop.";if(n.outcome==="direct")return u.outcome==="no"?"; no other action lightness stop can help while the band holds \u2014 widen the chroma band.":" \u2014 widen the chroma band.";if(u.outcome==="direct")return n.outcome==="no"?"; no wider chroma band can help at this lightness \u2014 move the action lightness stop.":" \u2014 move the action lightness stop.";if(n.outcome==="retune"&&u.outcome==="retune")return` \u2014 widen the chroma band or move the action lightness stop, then retune ${n.target} via intents.`;if(n.outcome==="retune")return u.outcome==="no"?`; no other action lightness stop can help while the band holds \u2014 widen the chroma band, then retune ${n.target} via intents.`:` \u2014 widen the chroma band, then retune ${n.target} via intents.`;if(u.outcome==="retune")return n.outcome==="no"?`; no wider chroma band can help at this lightness \u2014 move the action lightness stop, then retune ${u.target} via intents.`:` \u2014 move the action lightness stop, then retune ${u.target} via intents.`;const c=n.outcome==="no"&&u.outcome==="no"?"; neither a wider chroma band alone nor another stop alone can help":"; neither a wider chroma band alone nor another stop alone provably helps";return t.outcome==="direct"?`${c} \u2014 change the band and the stop together.`:t.outcome==="retune"?`${c} \u2014 change the band and the stop together, then retune ${t.target} via intents.`:"; no explored band or stop change provably separates this pair."}function dt(n,u){const t=Z(n),c=Z(u),g=t.error!==void 0?{valid:!1,errors:[t.error],warnings:[]}:le(t.value),p=c.error!==void 0?{valid:!1,errors:[c.error],warnings:[]}:le(c.value,Je),d=[...g.errors.map(v=>`light: ${v}`),...p.errors.map(v=>`dark: ${v}`)],S=[...g.warnings.map(v=>`light: ${v}`),...p.warnings.map(v=>`dark: ${v}`)];if(g.valid&&p.valid){const v=new Set(Object.keys(t.value?.contexts??{})),P=new Set(Object.keys(c.value?.contexts??{})),B=[...P].filter(L=>!v.has(L)).sort(),N=[...v].filter(L=>!P.has(L)).sort();(B.length>0||N.length>0)&&d.push(`contexts must declare the same names in both schemes. Missing from light: ${B.join(", ")||"(none)"}. Missing from dark: ${N.join(", ")||"(none)"}.`)}const y=[...t.value?j(t.value,"light"):[],...c.value?j(c.value,"dark"):[]];for(const v of y)d.push(xe(v));return{valid:d.length===0,errors:d,warnings:S}}export{mt as validateComponentProperties,pt as validateTheme,dt as validateThemePair};