@taprootio/espalier 7.1.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/custom-elements.json +14088 -11749
- package/dist/button/esp-button.js +7 -4
- package/dist/button/paint-registration.js +1 -0
- package/dist/cli/theme-check.js +2 -2
- package/dist/footer/paint-registration.js +1 -0
- package/dist/header/esp-header-button.js +6 -2
- package/dist/header/esp-header.js +8 -4
- package/dist/header/header-geometry-controller.js +1 -1
- package/dist/header/is-tall-header-paint.d.ts +7 -0
- package/dist/header/is-tall-header-paint.js +1 -0
- package/dist/header/paint-registration.js +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/menu/esp-menu-group.js +8 -8
- package/dist/menu/esp-menu-item.js +8 -8
- package/dist/menu/esp-menu.js +13 -6
- package/dist/menu/navigation-focus-outline.js +8 -0
- package/dist/menu/navigation-paint.js +1 -0
- package/dist/menu/paint-registration.js +1 -0
- package/dist/shared/color-engine.js +1 -1
- package/dist/shared/composed-dom.js +1 -0
- package/dist/shared/configured-brand-color.js +1 -0
- package/dist/shared/configured-brand.js +5 -5
- package/dist/shared/css-named-colors.js +1 -0
- package/dist/shared/esp-element-base.js +1 -1
- package/dist/shared/paint-catalog.d.ts +27 -0
- package/dist/shared/paint-catalog.js +1 -0
- package/dist/shared/paint-color.d.ts +25 -0
- package/dist/shared/paint-color.js +1 -0
- package/dist/shared/paint-fit.js +1 -0
- package/dist/shared/paint-identity.js +1 -0
- package/dist/shared/paint-types.d.ts +88 -0
- package/dist/shared/paint-types.js +0 -0
- package/dist/shared/theme-fit-report.d.ts +10 -2
- package/dist/shared/theme-fit-report.js +1 -1
- package/dist/shared/theme.d.ts +3 -24
- package/dist/shared/theme.js +1 -1
- package/dist/shared/token-pairings.d.ts +25 -0
- package/dist/shared/token-pairings.js +1 -0
- package/dist/shared/wcag-contrast.d.ts +14 -0
- package/dist/shared/wcag-contrast.js +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/observe-paint.d.ts +29 -0
- package/dist/testing/observe-paint.iife.js +3 -0
- package/dist/testing/observe-paint.js +3 -0
- package/dist/testing/paint-bands.js +1 -0
- package/dist/testing/paint-coverage.d.ts +14 -0
- package/dist/testing/paint-coverage.js +1 -0
- package/dist/testing/paint-dom.js +1 -0
- package/dist/testing/svg-paint.js +1 -0
- package/package.json +6 -1
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
*/
|
|
51
51
|
import { type ColorVisionSimulation, type DataPalette, type DataSeriesKey } from "./data-colors.js";
|
|
52
52
|
import { 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. */
|
|
@@ -225,7 +226,7 @@ export interface ThemeFitDataPaletteLint {
|
|
|
225
226
|
message: string;
|
|
226
227
|
}
|
|
227
228
|
/** 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";
|
|
229
|
+
export type ThemeFitFieldKind = "anchor" | "anchor-record" | "apca" | "boolean" | "data-palette-record" | "explicit" | "fit-lint-id" | "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
230
|
/** One runtime field descriptor used by fit-suite validation and comparison. */
|
|
230
231
|
export interface ThemeFitFieldDescriptor<Field extends PropertyKey = PropertyKey> {
|
|
231
232
|
readonly field: Field;
|
|
@@ -322,6 +323,13 @@ export interface ThemeFitSuite {
|
|
|
322
323
|
light: ThemeFitSurfaceReport[];
|
|
323
324
|
/** One report per surface the dark theme defines. */
|
|
324
325
|
dark: ThemeFitSurfaceReport[];
|
|
326
|
+
/** WCAG measurements of enabled component paint for explicitly requested roles. */
|
|
327
|
+
paint?: PaintFitReport;
|
|
328
|
+
}
|
|
329
|
+
/** Optional component paint measurements to add to the APCA fit suite. */
|
|
330
|
+
export interface ThemeFitSuiteOptions {
|
|
331
|
+
paintSurfaces?: readonly PaintFitSurface[];
|
|
332
|
+
extraEntries?: PaintEntriesByRole;
|
|
325
333
|
}
|
|
326
334
|
/** Runtime schema for every surface-report field. */
|
|
327
335
|
export declare const THEME_FIT_REPORT_FIELDS: readonly ThemeFitFieldDescriptor<keyof ThemeFitSurfaceReport>[];
|
|
@@ -343,5 +351,5 @@ export declare const THEME_FIT_SUITE_FIELDS: readonly ThemeFitFieldDescriptor<ke
|
|
|
343
351
|
* seed color is unparseable), because the required palette snapshot cannot be
|
|
344
352
|
* produced. {@link themeFitReport} retains its narrower empty-report behavior.
|
|
345
353
|
*/
|
|
346
|
-
export declare function themeFitReportSuite(lightPartial: PartialTheme, darkPartial: PartialTheme): ThemeFitSuite;
|
|
354
|
+
export declare function themeFitReportSuite(lightPartial: PartialTheme, darkPartial: PartialTheme, options?: ThemeFitSuiteOptions): ThemeFitSuite;
|
|
347
355
|
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 _,deltaEOK as O,parseOklch as v,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{measurePaintSurfaces as Z}from"./paint-fit.js";import{computeThemeProperties as ee}from"../root/helpers/compute-theme-properties.js";function fe(e,t,n={}){return H(e,t,n).report}function H(e,t,n={}){let o=e,s=null;if(n.context!==void 0){const a=J(e,n.context);if(!a)throw new Error(`themeFitReport: context "${n.context}" is not defined by the theme.`);o=a,s=new Set(Object.keys(e.contexts[n.context]?.semanticMappings??{}))}const m=[],b=ee(o,t,m),L=W(o),T=Q(o.roles),f=m.map(a=>{const i=de(a);if(L.has(i.token))i.explicit=s===null||s.has(i.token)?"declared":"inherited";else{const l=T[i.token];l!==void 0&&(i.pairing=l)}return i});return{properties:b,report:{scheme:t,seedColor:o.seedColor,anchors:ce(o.anchors),tokens:f,adjustedTokens:f.filter(a=>a.adjusted).map(a=>a.token)}}}function te(e){return e.tokens.map(t=>({token:t.token,source:t.source,requested:t.requested,resolved:t.resolved,apca:le(t),anchor:ue(t)}))}function Ee(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(te(e))}function I(e){const t=Object.entries(e).map(([n,o])=>Object.freeze({field:n,kind:o.kind,compared:o.compared}));return Object.freeze(t)}const re={"action-anchor-inversion":!0,"action-canvas-separation":!0,"apca-target-unmet":!0,"link-hover-ordering":!0},Te=Object.freeze(Object.keys(re)),ne={"data-palette-cvd-collision":!0},_e=Object.freeze(Object.keys(ne)),oe={declared:!0,inherited:!0},ve=Object.freeze(Object.keys(oe)),ae={declared:!0,derived:!0},Le=Object.freeze(Object.keys(ae)),se={warning:!0},Ie=Object.freeze(Object.keys(se)),be=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}}),Me=I({reference:{kind:"string",compared:!0},color:{kind:"string",compared:!0},deltaE:{kind:"number",compared:!0}}),Re=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}}),Ae=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}}),we=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,A=75,P={l:0,c:0,h:0},y={l:1,c:0,h:0},B=.5,S=75,ie=.045;function V(e){const t=[],n=new Map(e.tokens.map(r=>[r.token,r.resolved])),o=r=>{const c=n.get(r);return c===void 0?null:v(c)},s=o("background"),m=o("actionBackground");if(s&&m){const r=O(m,s);if(r<D){const c=h(r,4);t.push({id:"action-canvas-separation",severity:"warning",tokens:["actionBackground","background"],measured:c,message:`actionBackground sits \u0394E ${c} 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 b=o("link"),L=o("linkHover"),T=o("linkHoverBg");if(s&&b&&L&&T){const r=Math.abs(_(b,s)),c=Math.abs(_(L,T));O(T,s)>=ie?c+B<S&&t.push({id:"link-hover-ordering",severity:"warning",tokens:["linkHoverBg","linkHover"],measured:h(S-c,1),message:`linkHover reaches only Lc ${h(c,1)} on the linkHoverBg wash it actually paints (tier ${S}) \u2014 retune linkHoverBg before changing linkHover; the wash has one consumer while the ink has many.`}):c+B<r&&t.push({id:"link-hover-ordering",severity:"warning",tokens:["linkHover","link"],measured:h(r-c,1),message:`linkHover reads weaker than link on the same canvas (Lc ${h(c,1)} vs ${h(r,1)}) \u2014 a dimming hover feels disabled. Retune linkHover toward more contrast than the resting link.`})}const f=r=>Math.abs(_(P,r))>=Math.abs(_(y,r))?"dark":"light",a=e.tokens.find(r=>r.token==="actionBackground"),i=e.tokens.find(r=>r.token==="actionText"),l=[],u=[];let d=0;const g=i?.anchor?v(i.anchor.color):null,k=i?v(i.resolved):null,p=a?.anchor?v(a.anchor.color):null,E=a?v(a.resolved):null,M=k&&E?k.l>E.l?"light":"dark":null;a?.anchor&&p&&E&&M&&a.anchor.deltaE>=N&&f(p)!==M&&(l.push("actionBackground"),d=Math.max(d,a.anchor.deltaE),u.push(`"${a.anchor.reference}" wants ${f(p)} ink but actionBackground renders carrying a ${M} label (\u0394E ${h(a.anchor.deltaE,4)})`)),i?.anchor&&i.pairing!=="derived"&&g&&k&&p&&E&&i.anchor.deltaE>=N&&p.l!==g.l&&Math.sign(p.l-g.l)!==Math.sign(E.l-k.l)&&(l.push("actionText"),d=Math.max(d,i.anchor.deltaE),u.push(`the declared pair puts "${a.anchor.reference}" ${p.l>g.l?"above":"below"} "${i.anchor.reference}" in lightness and the rendered pair puts it ${E.l>k.l?"above":"below"} (\u0394E ${h(i.anchor.deltaE,4)})`)),l.length>0&&t.push({id:"action-anchor-inversion",severity:"warning",tokens:l,measured:h(d,4),message:`The filled action renders the opposite way round from the swatches it names: ${u.join("; ")}. `+(a?.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 w=e.tokens.filter(r=>r.apca!==void 0&&r.apca.toLc<Math.min(r.apca.targetLc,A)).sort((r,c)=>Math.min(c.apca.targetLc,A)-c.apca.toLc-(Math.min(r.apca.targetLc,A)-r.apca.toLc)||(r.token<c.token?-1:r.token>c.token?1:0));if(w.length>0){const r=w[0].apca,c=w.map(R=>`${R.token} reaches Lc ${h(R.apca.toLc,1)} on ${R.apca.against} (floor ${Math.min(R.apca.targetLc,A)})`),x=v(r.againstColor),U=x!==null&&Math.max(Math.abs(_(P,x)),Math.abs(_(y,x)))>=Math.min(r.targetLc,A);t.push({id:"apca-target-unmet",severity:"warning",tokens:w.map(R=>R.token),measured:h(Math.min(r.targetLc,A)-r.toLc,1),message:`${c.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 F=":root",xe=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}}),Oe=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},paint:{kind:"paint-record",compared:!1}});function $e(e,t,n={}){const o=j(Y,e),s=j(G,t),m=[F,...[...new Set([...Object.keys(o.contexts),...Object.keys(s.contexts)])].sort()],b=l=>{const u={};for(let d=0;d<C.length;d+=1){const g=C[d],k=`--esp-color-series-${d+1}`,p=l[k];if(p===void 0)throw new Error(`Theme fit report did not emit required property ${k}.`);u[g]=p}return u},L=l=>q(l).map(u=>{const d=h(u.distance,4);return{id:"data-palette-cvd-collision",severity:"warning",series:u.series,simulation:u.simulation,measured:d,threshold:u.threshold,message:K(u)}}),T=(l,u)=>{const d=H(l,u);if(Object.keys(d.properties).length===0)throw new Error(`themeFitReportSuite: ${u} root emitted no properties for seed "${l.seedColor}".`);const g=new Map;n.paintSurfaces!==void 0&&g.set(null,d.properties);const k=[{...d.report,surface:F,lints:V(d.report)}];for(const p of m){if(p===F||!(p in l.contexts))continue;const E=H(l,u,{context:p});n.paintSurfaces!==void 0&&g.set(p,E.properties);const M=E.report;k.push({...M,surface:p,lints:V(M)})}return{dataPalette:b(d.properties),reports:k,paintProperties:g}},f=T(o,"light"),a=T(s,"dark"),i={light:f.dataPalette,dark:a.dataPalette};return{surfaces:m,dataPalette:i,paletteLints:{light:L(i.light),dark:L(i.dark)},light:f.reports,dark:a.reports,...n.paintSurfaces===void 0?{}:{paint:Z({light:f.paintProperties,dark:a.paintProperties},n.paintSurfaces,n.extraEntries)}}}function h(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}function z(e,t){return t===void 0?e:`${e}.${t}`}function ce(e){const t={};for(const[n,o]of Object.entries(e)){if(typeof o=="string"){t[n]=o;continue}for(const[s,m]of Object.entries(o))t[s==="color"?n:z(n,s)]=m}return t}function de(e){const t=v(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},s=X(e.source);if(s&&e.sourceResolved&&(o.anchor={reference:z(s.name,s.slot),color:$(e.base),deltaE:h(O(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(_(v(n),m)),1),toLc:h(Math.abs(_(t,m)),1)}}return o}function le(e){if(!e.apca)return"";const{targetLc:t,against:n,fromLc:o,toLc:s}=e.apca;return e.adjusted?`Lc ${t} vs ${n} \u2014 pushed from Lc ${o} to Lc ${s}`:`Lc ${t} vs ${n} \u2014 met at Lc ${o}`}function ue(e){return e.anchor?`${e.anchor.reference} \u0394E ${e.anchor.deltaE}`:e.sourceResolved?"":"unresolved \u2014 seed used"}export{F as ROOT_SURFACE,Me as THEME_FIT_ANCHOR_FIELDS,Re as THEME_FIT_APCA_FIELDS,we as THEME_FIT_DATA_PALETTE_LINT_FIELDS,_e as THEME_FIT_DATA_PALETTE_LINT_IDS,ve as THEME_FIT_EXPLICIT_VALUES,Ae as THEME_FIT_LINT_FIELDS,Te as THEME_FIT_LINT_IDS,Ie as THEME_FIT_LINT_SEVERITIES,Le as THEME_FIT_PAIRING_VALUES,xe as THEME_FIT_REPORT_FIELDS,Oe as THEME_FIT_SUITE_FIELDS,be as THEME_FIT_TOKEN_FIELDS,Ee as printThemeFitReport,V as themeFitLints,fe as themeFitReport,$e as themeFitReportSuite,te as themeFitRows};
|
package/dist/shared/theme.d.ts
CHANGED
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
import { type DataPalette, type DataRamps, type PartialDataRamps } from "./data-colors.js";
|
|
34
|
+
export { isTallHeaderPaint } from "../header/is-tall-header-paint.js";
|
|
35
|
+
export { TOKEN_PAIRINGS } from "./token-pairings.js";
|
|
36
|
+
export { AA_LARGE_RATIO, AA_NON_TEXT_RATIO, AA_TEXT_RATIO, wcagRatio } from "./wcag-contrast.js";
|
|
34
37
|
/** A key in the lightness ramp. Each maps to a perceptual role. */
|
|
35
38
|
export type LightnessKey = "surface" | "raised1" | "raised2" | "raised3" | "raised4" | "accent" | "muted" | "text" | "border" | "ink" | "shadow";
|
|
36
39
|
/** Lightness values (0–1) for every ramp position. */
|
|
@@ -629,29 +632,6 @@ export interface ThemeValidationResult {
|
|
|
629
632
|
/** Soft issues — the theme will work but values are unusual. */
|
|
630
633
|
warnings: string[];
|
|
631
634
|
}
|
|
632
|
-
/**
|
|
633
|
-
* Which semantic tokens are ink, what surface each sits on, and the
|
|
634
|
-
* APCA contrast each must clear.
|
|
635
|
-
*
|
|
636
|
-
* This pairing lived as an identical hardcoded table inside both
|
|
637
|
-
* `compute-theme-properties.ts` and `esp-element-base.ts` — invisible to
|
|
638
|
-
* themes and duplicated in exactly the way this repository's adoption
|
|
639
|
-
* rules exist to prevent. It belongs to the model: every serious system
|
|
640
|
-
* makes the surface/ink pair the unit designers see (Material's
|
|
641
|
-
* `on-primary`, shadcn's `-foreground`), and the roles layer derives an
|
|
642
|
-
* action's ink from it rather than asking a designer to hand-pick a
|
|
643
|
-
* legible color.
|
|
644
|
-
*
|
|
645
|
-
* Lc targets follow the APCA guidelines (ADR-002):
|
|
646
|
-
* 90 → body text at any size
|
|
647
|
-
* 75 → 16 px+ text (UI labels, links, body)
|
|
648
|
-
* 60 → 24 px+ bold / 28 px+ normal (headings, carets, decorative)
|
|
649
|
-
*/
|
|
650
|
-
type TokenPairing = Readonly<{
|
|
651
|
-
bg: SemanticColorName;
|
|
652
|
-
targetLc: number;
|
|
653
|
-
}>;
|
|
654
|
-
export declare const TOKEN_PAIRINGS: Readonly<Record<"actionText", TokenPairing> & Partial<Record<SemanticColorName, TokenPairing>>>;
|
|
655
635
|
/** Ordered list of all semantic color token names. */
|
|
656
636
|
export declare const SEMANTIC_COLOR_NAMES: readonly SemanticColorName[];
|
|
657
637
|
/** `true` when `value` is one of the stable semantic color token names. */
|
|
@@ -896,4 +876,3 @@ export declare function buildTaprootLightTheme(backgroundImageUrl: string): stri
|
|
|
896
876
|
* @returns A Base64-encoded {@link PartialTheme}.
|
|
897
877
|
*/
|
|
898
878
|
export declare function buildTaprootDarkTheme(backgroundImageUrl: string): string;
|
|
899
|
-
export {};
|
package/dist/shared/theme.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{UNSAFE_KEYS as yt,isSafeKey as M}from"./unsafe-keys.js";import{ACCEPTED_COLOR_FORMS as oe,apcaContrast as se,clampChannel as be,deltaEOK as bt,deriveSemantic as re,gamutMapToSRGB as $e,linearRgbToOklab as $t,oklchToSRGB as kt,parseCssColor as W,parseOklch as xt,serializeOklch as fe,srgbToLinearRGB as St}from"./color-engine.js";import{computeVariants as le,parseAnchorSource as At,resolveAnchorColor as Mt,resolveMappingSource as ie}from"./variant-engine.js";import{auditColorDistances as Fe,auditDataPalette as Ot,describePaletteCollision as Tt,DATA_SERIES_KEYS as pe,DEFAULT_DATA_PALETTE as ke,DEFAULT_DATA_RAMP_STEPS as Ct,MAX_DATA_RAMP_STEPS as xe,MIN_DATA_RAMP_LIGHTNESS_STEP as We,MIN_DATA_RAMP_STEPS as Se}from"./data-colors.js";const K=/^[a-z][a-z0-9-]*$/;function Ae(e){return At(e)}function je(e,n){return Mt(e,n)}function Rt(e,n){const t=Ae(e);if(t){const o=je(n,t);return o&&W(o)?o:null}return W(e)?e:null}const ae=["canvas","ink","accent","action","structure"],de={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"]]}},vt=new Set(["action.color"]),Et=new Set(["action.ink"]),wt={canvas:"background",ink:"text",accent:"link",action:"actionBackground",structure:"border"},Ke={"action.ink":{role:"canvas",slot:"color"}},Bt=.45,_t=.045;function ze(e,n,t){const o=Ge.actionText,i=[...U].sort((S,A)=>e[S]-e[A]||U.indexOf(S)-U.indexOf(A)),a=n?i.filter(S=>n(S)>=o.targetLc):i,u=t?a.filter(S=>t(S)>=_t):a,d=u.length>0?u:a,m=d.length>0?d:i;let x,b=1/0;for(const S of m){const A=Math.abs(e[S]-Bt);A<b&&(b=A,x=S)}return x??"muted"}function Lt(e){const n={l:e,c:0,h:0};return Math.abs(se({l:0,c:0,h:0},n))>=Math.abs(se({l:1,c:0,h:0},n))?"dark":"light"}function It(e,n,t,o){const i=Te(n,t,e),a=(o??Lt)(i)==="dark";let u=U[0];for(const d of U)(a?n[d]<n[u]:n[d]>n[u])&&(u=d);return u}const Nt={"accent.hover":"text"};function Pt(e,n){const t=new Map;try{const o=he(n,e),i=(a,u,d,m)=>{const x=Ae(u),b=x?je(m,x):null,S=b===null?null:W(b),A=t.get(a)??[];A.some(D=>D.source===u&&D.chroma===S?.c)||(A.push({source:u,where:d,chroma:S?.c}),t.set(a,A))};for(const[a,u]of Object.entries(o.semanticMappings))u.source.startsWith("anchor:")&&i(a,u.source,"the root table",o.anchors);for(const a of Object.keys(o.contexts)){const u=ft(o,a);if(u)for(const[d,m]of Object.entries(u.semanticMappings))m.source.startsWith("anchor:")&&i(d,m.source,`contexts.${a}`,u.anchors)}}catch{return new Map}return t}function Y(e,n){if(e===void 0)return;if(typeof e=="string")return n==="color"?e:void 0;const t=e[n];return typeof t=="string"?t:void 0}function Ue(e,n,t,o={}){const i={};for(const a of ae){const u=e[a];if(u!==void 0)for(const[d,m]of Object.entries(de[a])){const x=Ke[`${a}.${d}`];let b=Y(u,d),S=!1;if(b===void 0){x&&(b=Y(e[x.role],x.slot),b??=t[wt[x.role]]?.source,S=b!==void 0);const A=Nt[`${a}.${d}`];A!==void 0&&(b??=Y(u,A)),b??=Y(u,"color")}if(b!==void 0)for(const[A,D]of m){let F=D;if(vt.has(`${a}.${d}`))F=ze(n,o.actionSurfaceContrast?L=>o.actionSurfaceContrast(b,L):void 0,o.actionSurfaceSeparation?L=>o.actionSurfaceSeparation(b,L):void 0);else if(x&&(S||Et.has(`${a}.${d}`))){const L=Ge[A],s=L?o.explicitMappings?.[L.bg]:void 0,r=s?.lightness??ze(n,o.actionSurfaceContrast?f=>o.actionSurfaceContrast(Y(u,"color"),f):void 0,o.actionSurfaceSeparation?f=>o.actionSurfaceSeparation(Y(u,"color"),f):void 0),c=s?.source??Y(u,"color");F=It(r,n,o.tones??{},o.actionSurfacePole&&c!==void 0?f=>o.actionSurfacePole(c,f):void 0)}i[A]={source:b,lightness:F}}}}return i}function dn(e){const n={};for(const t of Object.keys(Ke)){const o=t.indexOf("."),i=t.slice(0,o),a=t.slice(o+1),u=e[i];if(u===void 0)continue;const d=Y(u,a)!==void 0?"declared":"derived";for(const[m]of de[i][a]??[])n[m]=d}return n}const Ge={text:{bg:"background",targetLc:75},typeOverline:{bg:"background",targetLc:90},typeLabel:{bg:"background",targetLc:75},typeLead:{bg:"background",targetLc:75},typeCaption:{bg:"background",targetLc:90},dangerText:{bg:"background",targetLc:75},headings:{bg:"background",targetLc:60},headingsHover:{bg:"background",targetLc:60},link:{bg:"background",targetLc:75},linkHover:{bg:"linkHoverBg",targetLc:75},actionText:{bg:"actionBackground",targetLc:75},inputCaret:{bg:"layer2",targetLc:60},inputSelection:{bg:"inputSelectionBg",targetLc:60}},z=["background","layer1","layer2","layer3","layer4","actionBackground","actionText","border","shadow","text","typeOverline","typeLabel","typeLead","typeCaption","dangerText","headings","headingsHover","link","linkHover","linkHoverBg","inputCaret","inputSelection","inputSelectionBg"];function mn(e){return typeof e=="string"&&z.includes(e)}const Ht=["typeOverline","typeLabel","typeLead","typeCaption"],Me=["primary","analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning","info"],ee=["danger","success","warning","info"],Dt=["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"],Ve="tone:";function Oe(e){if(typeof e!="string"||!e.startsWith(Ve))return null;const n=e.slice(Ve.length);return M(n)&&K.test(n)?n:null}function te(e){return typeof e!="string"?!1:U.includes(e)}function Te(e,n,t){if(te(t))return e[t];const o=Oe(t);return o===null?e.surface:n?.[o]??e.surface}const Ft={surface:.99,raised1:.97,raised2:.9,raised3:.8,raised4:.72,accent:.5,muted:.45,text:.35,border:.3,ink:.25,shadow:.2},Wt={surface:.15,raised1:.2,raised2:.3,raised3:.4,raised4:.36,accent:.6,muted:.75,text:.85,border:.7,ink:.95,shadow:.6},Je={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"}},jt={light:"muted",dark:"raised3"};function Ye(e){return{...Je,actionBackground:{source:"primary",lightness:jt[e]}}}const q=.4;function Ce(){const e={};for(const n of z)e[n]={min:0,max:q};return e}const qe="system-ui, sans-serif",Xe="monospace",Ze={seedColor:"oklch(0.7 0.125 216)",fontBody:qe,fontHeadings:"",fontBrand:"",fontMenu:"",fontMonospace:Xe,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:Ce(),semanticMappings:{...Je},explicitMappingTokens:[],anchors:{},roles:{},contexts:{},dataPalette:{...ke},dataRamps:{}},Re={...Ze,chroma:Ce(),semanticMappings:Ye("light"),anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...ke},dataRamps:{},lightness:{...Ft}},Qe={...Ze,chroma:Ce(),semanticMappings:Ye("dark"),anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...ke},dataRamps:{},lightness:{...Wt}},me=new WeakMap;me.set(Re,new Set),me.set(Qe,new Set);function Kt(e,n){return yt.has(e)?void 0:n}function ge(e){const n=e.explicitMappingTokens;if(!Array.isArray(n)||n.some(o=>typeof o!="string"||!z.includes(o)))return;const t=new Set(n);if(t.size===n.length&&!(t.size>0&&(!I(e.semanticMappings)||[...t].some(o=>!Object.prototype.hasOwnProperty.call(e.semanticMappings,o)))))return t}function et(e){return z.filter(n=>e.has(n))}function gn(e){return`--esp-color-${e.replace(/([A-Z])/g,"-$1").replace(/(\d)/g,"-$1").toLowerCase()}`}function zt(e){try{const n=tt(e),t=JSON.parse(n,Kt);return typeof t!="object"||t===null||Array.isArray(t)?null:t}catch{return null}}const ve="\xEF\xBB\xBF";function Ut(e){if(/^[\u0000-\u007f]*$/.test(e))return btoa(e);const n=new TextEncoder().encode(e);let t=ve;for(const o of n)t+=String.fromCharCode(o);return btoa(t)}function tt(e){const n=atob(e);if(!n.startsWith(ve))return n;const t=Uint8Array.from(n.slice(ve.length),o=>o.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(t)}function Ee(e){return Ut(JSON.stringify(e))}function Gt(e){const n={};for(const t of ee){const o=e[t];typeof o=="string"&&(n[t]=o.startsWith("anchor:")?o:ce(o))}return n}function ce(e){if(xt(e))return e;const n=W(e);return n?fe(n):e}function nt(e,n){const t={};for(const[o,i]of Object.entries(e))M(o)&&(t[o]=i);if(!n)return t;for(const[o,i]of Object.entries(n)){if(i===void 0||!M(o))continue;const a=t[o];if(a!==void 0&&typeof i=="object"&&i!==null){const u={};if(typeof a=="string")u.color=a;else for(const[d,m]of Object.entries(a))M(d)&&(u[d]=m);for(const[d,m]of Object.entries(i))m!==void 0&&M(d)&&(u[d]=m);t[o]=u;continue}t[o]=i}return t}function we(e){const n={};if(!I(e))return n;for(const[t,o]of Object.entries(e))M(t)&&K.test(t)&&!te(t)&&typeof o=="number"&&Number.isFinite(o)&&o>=0&&o<=1&&(n[t]=o);return n}function Vt(e,n){return{...we(e),...we(n)}}function Jt(e,n){const t={...e};if(!I(n))return t;for(const o of U){const i=n[o];typeof i=="number"&&Number.isFinite(i)&&i>=0&&i<=1&&(t[o]=i)}return t}function ot(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const n=e,t={};for(const o of ae){const i=n[o];i!==void 0&&(t[o]=i)}if(typeof n.lightness=="object"&&n.lightness!==null&&!Array.isArray(n.lightness)){const o={};for(const i of U){const a=n.lightness[i];a!==void 0&&(o[i]=a)}t.lightness=o}if(n.tones!==void 0){const o=we(n.tones);Object.keys(o).length>0&&(t.tones=o)}if(typeof n.semanticMappings=="object"&&n.semanticMappings!==null&&!Array.isArray(n.semanticMappings)){const o={};for(const[i,a]of Object.entries(n.semanticMappings)){if(!M(i)||!z.includes(i)||typeof a!="object"||a===null||Array.isArray(a))continue;const{source:u,lightness:d}=a;typeof u=="string"&&(typeof d!="string"||!te(d)&&Oe(d)===null||(o[i]={source:u,lightness:d}))}Object.keys(o).length>0&&(t.semanticMappings=o)}return t}function Yt(e,n){const t={};for(const[o,i]of Object.entries(e)){if(!M(o)||!K.test(o))continue;const a=ot(i);a&&(t[o]=a)}if(!n)return t;for(const[o,i]of Object.entries(n)){if(!M(o)||!K.test(o)||i===void 0)continue;const a=ot(i);if(!a)continue;const u=t[o];t[o]={...u??{},...a,...u?.lightness||a.lightness?{lightness:{...u?.lightness,...a.lightness}}:{},...u?.tones||a.tones?{tones:{...u?.tones,...a.tones}}:{},...u?.semanticMappings||a.semanticMappings?{semanticMappings:{...u?.semanticMappings,...a.semanticMappings}}:{}}}return t}function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function j(e){const n={};for(const[t,o]of Object.entries(e))o!==void 0&&M(t)&&(n[t]=o);return n}function st(e){if(!I(e))return e;const n=j(e);return I(e.lightness)&&(n.lightness=j(e.lightness)),I(e.tones)&&(n.tones=j(e.tones)),n}function qt(e,n){const t={};for(const[o,i]of Object.entries(e))M(o)&&(t[o]=st(i));if(!n)return t;for(const[o,i]of Object.entries(n)){if(!M(o)||i===void 0)continue;const a=t[o];if(!I(a)||!I(i)){t[o]=st(i);continue}const u={...j(a),...j(i)};I(a.lightness)&&I(i.lightness)?u.lightness={...j(a.lightness),...j(i.lightness)}:I(i.lightness)&&(u.lightness=j(i.lightness)),I(a.tones)&&I(i.tones)?u.tones={...j(a.tones),...j(i.tones)}:I(i.tones)&&(u.tones=j(i.tones)),I(a.semanticMappings)&&I(i.semanticMappings)?u.semanticMappings={...j(a.semanticMappings),...j(i.semanticMappings)}:I(i.semanticMappings)&&(u.semanticMappings=j(i.semanticMappings)),t[o]=u}return t}function Xt(e){const n={};for(const[t,o]of Object.entries(e)){if(!M(t))continue;if(typeof o=="string"){n[t]=ce(o);continue}const i={};for(const[a,u]of Object.entries(o))M(a)&&(i[a]=typeof u=="string"?ce(u):u);n[t]=i}return n}function ue(e){return typeof e!="string"?"":e.startsWith("anchor:")?e:ce(e)}function Zt(e){const n={};for(const t of pe)n[t]=ue(e[t]);return n}function rt(e,n){const t={};for(const[o,i]of Object.entries(e))M(o)&&K.test(o)&&i&&typeof i=="object"&&!Array.isArray(i)&&(t[o]={...i});if(!n)return t;for(const[o,i]of Object.entries(n)){if(!M(o)||!K.test(o)||!i||typeof i!="object"||Array.isArray(i))continue;const a=t[o],u=a!==void 0&&i.type!==void 0&&i.type!==a.type;t[o]={...u?{}:a??{},...i}}return t}function Qt(e){const n={};for(const[t,o]of Object.entries(e))if(M(t)){if(o.type==="sequential"&&typeof o.source=="string"){n[t]={...o,source:ue(o.source)};continue}if(o.type==="diverging"&&typeof o.start=="string"&&typeof o.end=="string"){n[t]={...o,start:ue(o.start),end:ue(o.end),...typeof o.neutral=="string"?{neutral:ue(o.neutral)}:{}};continue}n[t]={...o}}return n}function it(e){const n=W(e.seedColor);if(!n)return;const t=le(n,e);return(o,i)=>{const a=ie(o,t,e.anchors)??t.primary,u=e.chroma.actionBackground,d=re(a,e.lightness[i],u.min,u.max),m={l:d.l>.5?0:1,c:0,h:0};return Math.abs(se(m,d))}}function at(e){const n=W(e.seedColor);if(!n)return;const t=le(n,e);return(o,i)=>{const a=ie(o,t,e.anchors)??t.primary,u=e.chroma.actionBackground,d=re(a,i,u.min,u.max);return Math.abs(se({l:0,c:0,h:0},d))>=Math.abs(se({l:1,c:0,h:0},d))?"dark":"light"}}function en(e,n,t){if(n?.background)return n.background;const o=Y(e.canvas,"color");if(o!==void 0){const i=de.canvas.color?.find(([a])=>a==="background");if(i)return{source:o,lightness:i[1]}}return t.background}function ct(e,n){const t=W(e.seedColor);if(!t||!n)return;const o=le(t,e),i=ie(n.source,o,e.anchors)??o.primary,a=e.chroma.background,u=re(i,Te(e.lightness,e.tones,n.lightness),a.min,a.max);return(d,m)=>{const x=ie(d,o,e.anchors)??o.primary,b=e.chroma.actionBackground,S=re(x,e.lightness[m],b.min,b.max);return bt(S,u)}}function tn(e){const n=me.get(e);if(n)return new Set(n);const t=ge(e);if(t)return t;const o=new Set,i=Ue(e.roles,e.lightness,e.semanticMappings,{tones:e.tones,actionSurfaceContrast:it(e),actionSurfacePole:at(e),actionSurfaceSeparation:ct(e,e.semanticMappings.background)});for(const[a,u]of Object.entries(i)){const d=e.semanticMappings[a];(d.source!==u.source||d.lightness!==u.lightness)&&o.add(a)}return o}function he(e,n){const t={...e.roles,...n.roles},o=Yt(e.contexts,n.contexts),i=Jt(e.lightness,n.lightness),a=Vt(e.tones,n.tones),u=Xt(nt(e.anchors,n.anchors)),d=typeof n.seedColor=="string"?ce(n.seedColor):e.seedColor,m=n.semanticMappings,x={...e.angles,...n.angles},b={...e.semanticHues,...n.semanticHues},S={...e.variantChroma,...n.variantChroma},A=Gt({...e.intents,...n.intents}),D=n.chroma,F=ne(e.chroma,D),L=Zt(ne(e.dataPalette,n.dataPalette)),s=Qt(rt(e.dataRamps,n.dataRamps)),r=tn(e),c=new Set(r),f=ge(n),p={};for(const y of r)p[y]=e.semanticMappings[y];for(const[y,_]of Object.entries(m??{}))_!==void 0&&(f===void 0||f.has(y)?(c.add(y),p[y]=_):(c.delete(y),delete p[y]));const g=ne(e.semanticMappings,p),l={angles:x,anchors:u,chroma:F,intents:A,lightness:i,tones:a,seedColor:d,semanticHues:b,variantChroma:S},h=it(l),k=at(l),$=ct(l,en(t,p,g)),R=Ue(t,i,g,{explicitMappings:p,tones:a,actionSurfaceContrast:h,actionSurfacePole:k,actionSurfaceSeparation:$}),O={};for(const[y,_]of Object.entries(R))c.has(y)||(O[y]=_);const v={};for(const y of Ht)!c.has(y)&&O[y]===void 0&&(v[y]={source:g.text.source,lightness:g.text.lightness},D?.text!==void 0&&D[y]===void 0&&(F[y]={...F.text}));const E=ne(ne(ne(e.semanticMappings,v),O),p),T={...e,seedColor:d,fontBody:n.fontBody||e.fontBody||qe,fontHeadings:n.fontHeadings??e.fontHeadings,fontBrand:n.fontBrand??e.fontBrand,fontMenu:n.fontMenu??e.fontMenu,fontMonospace:n.fontMonospace||e.fontMonospace||Xe,fontWeightBody:String(n.fontWeightBody??e.fontWeightBody),fontWeightHeadings:String(n.fontWeightHeadings??e.fontWeightHeadings),fontWeightBrand:String(n.fontWeightBrand??e.fontWeightBrand),fontWeightMenu:String(n.fontWeightMenu??e.fontWeightMenu),fontWeightMonospace:String(n.fontWeightMonospace??e.fontWeightMonospace),stylesheets:n.stylesheets??[...e.stylesheets],rootFontSize:n.rootFontSize??e.rootFontSize,typeRatio:n.typeRatio??e.typeRatio,spaceRatio:n.spaceRatio??e.spaceRatio,borderRadius:n.borderRadius??e.borderRadius,viewportMin:n.viewportMin??e.viewportMin,viewportMax:n.viewportMax??e.viewportMax,angles:x,semanticHues:b,variantChroma:S,intents:A,lightness:i,tones:a,chroma:F,semanticMappings:E,explicitMappingTokens:et(c),anchors:u,roles:t,contexts:o,dataPalette:L,dataRamps:s};return n.pageBackgroundImage!==void 0&&(T.pageBackgroundImage=n.pageBackgroundImage),n.pageBackgroundImageOpacity!==void 0&&(T.pageBackgroundImageOpacity=n.pageBackgroundImageOpacity),n.boxBackgroundImage!==void 0&&(T.boxBackgroundImage=n.boxBackgroundImage),n.boxBackgroundImageOpacity!==void 0&&(T.boxBackgroundImageOpacity=n.boxBackgroundImageOpacity),n.vellumOpacity!==void 0&&(T.vellumOpacity=n.vellumOpacity),n.vellumBackgroundImage!==void 0&&(T.vellumBackgroundImage=n.vellumBackgroundImage),n.vellumBackgroundImageOpacity!==void 0&&(T.vellumBackgroundImageOpacity=n.vellumBackgroundImageOpacity),me.set(T,new Set(c)),T}const ut=new WeakMap;function ft(e,n){const t=e.contexts&&Object.prototype.hasOwnProperty.call(e.contexts,n)?e.contexts[n]:void 0;if(!t)return null;let o=ut.get(e);const i=o?.get(n);if(i)return i;const a={};for(const d of ae){const m=t[d];m!==void 0&&(a[d]=m)}const u=he(e,{lightness:t.lightness,tones:t.tones,roles:a,semanticMappings:t.semanticMappings});return o||(o=new Map,ut.set(e,o)),o.set(n,u),u}function ne(e,n){if(!n)return{...e};const t={...e};for(const o of Object.keys(n)){const i=n[o];i!==void 0&&(t[o]=i)}return t}function Be(e){let n;try{n=tt(e)}catch{return{error:"Failed to decode Base64 string."}}let t;try{t=JSON.parse(n)}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 hn(e){const n=Be(e);return n.error!==void 0?{valid:!1,errors:[n.error],warnings:[]}:_e(n.value)}function _e(e,n=Re){const t=[],o=[];"seedColor"in e&&(typeof e.seedColor!="string"?t.push("seedColor must be a string."):W(e.seedColor)||t.push(`seedColor is not a valid CSS color: "${e.seedColor}". Accepted forms: ${oe}.`));for(const s of["fontBody","fontHeadings","fontBrand","fontMenu","fontMonospace"])s in e&&typeof e[s]!="string"&&t.push(`${s} must be a string.`);const i=["normal","bold","lighter","bolder"],a=["inherit","initial","unset","revert","revert-layer"];for(const s of["fontWeightBody","fontWeightHeadings","fontWeightBrand","fontWeightMenu","fontWeightMonospace"])if(s in e){const r=e[s];if(typeof r=="number")(r<1||r>1e3)&&t.push(`${s} numeric value must be 1\u20131000 (got ${r}).`);else if(typeof r=="string"){const c=i.includes(r)||a.includes(r);if(/^\d+$/.test(r)){const p=Number(r);(p<1||p>1e3)&&t.push(`${s} numeric value must be 1\u20131000 (got "${r}").`)}else c||o.push(`${s} = "${r}" is not a standard font-weight value.`)}else t.push(`${s} must be a string or number.`)}"stylesheets"in e&&(Array.isArray(e.stylesheets)?e.stylesheets.some(s=>typeof s!="string")&&t.push("Every entry in stylesheets must be a string."):t.push("stylesheets must be an array of strings."));const u=[["rootFontSize",1,100],["borderRadius",0,10],["viewportMin",100,1e4],["viewportMax",200,1e4]];for(const[s,r,c]of u)if(s in e)if(typeof e[s]!="number"||!isFinite(e[s]))t.push(`${s} must be a finite number.`);else{const f=e[s];r!==void 0&&f<r&&t.push(`${s} must be \u2265 ${r} (got ${f}).`),c!==void 0&&f>c&&o.push(`${s} = ${f} is unusually high (max ${c}).`)}for(const s of["typeRatio","spaceRatio"])if(s in e)if(typeof e[s]!="number"||!isFinite(e[s]))t.push(`${s} must be a finite number.`);else{const r=e[s];r<=1&&t.push(`${s} must be > 1 (got ${r}).`);const c=s==="typeRatio"?1.3:2;r>c&&o.push(`${s} = ${r} is very high (max ${c}); scales may be extreme.`)}if("viewportMin"in e&&"viewportMax"in e){const s=e.viewportMin,r=e.viewportMax;typeof s=="number"&&typeof r=="number"&&s>=r&&t.push(`viewportMin (${s}) must be less than viewportMax (${r}).`)}if("angles"in e)if(typeof e.angles!="object"||e.angles===null)t.push("angles must be an object.");else{const s=e.angles;for(const r of["analogous","complementary","splitComplementary","triadic"])if(r in s)if(typeof s[r]!="number"||!isFinite(s[r]))t.push(`angles.${r} must be a finite number.`);else{const c=s[r];(c<0||c>360)&&o.push(`angles.${r} = ${c} is outside 0\u2013360.`)}}if("semanticHues"in e)if(typeof e.semanticHues!="object"||e.semanticHues===null)t.push("semanticHues must be an object.");else{const s=e.semanticHues;for(const r of["danger","success","warning","info"])if(r in s)if(typeof s[r]!="number"||!isFinite(s[r]))t.push(`semanticHues.${r} must be a finite number.`);else{const c=s[r];(c<0||c>360)&&o.push(`semanticHues.${r} = ${c} is outside 0\u2013360.`)}}if("variantChroma"in e)if(typeof e.variantChroma!="object"||e.variantChroma===null)t.push("variantChroma must be an object.");else{const s=e.variantChroma;for(const r of Dt)if(r in s)if(typeof s[r]!="number"||!isFinite(s[r]))t.push(`variantChroma["${r}"] must be a finite number.`);else{const c=s[r];c<0&&t.push(`variantChroma["${r}"] must be \u2265 0 (got ${c}).`),c>q&&o.push(`variantChroma["${r}"] = ${c} exceeds ${q}.`)}}function d(s,r){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const c=s;for(const f of Object.keys(c))(!M(f)||!te(f))&&t.push(`${r}.${f} is not a built-in lightness stop; expected one of: ${U.join(", ")}.`);for(const f of U)if(f in c)if(typeof c[f]!="number"||!isFinite(c[f]))t.push(`${r}.${f} must be a finite number.`);else{const p=c[f];(p<0||p>1)&&t.push(`${r}.${f} must be 0\u20131 (got ${p}).`)}}"lightness"in e&&d(e.lightness,"lightness");function m(s,r){const c=new Set;if(!I(s))return t.push(`${r} must be an object.`),c;for(const[f,p]of Object.entries(s)){if(!M(f)||!K.test(f)){t.push(`${r}.${f} must be a lowercase slug matching ${K.source}.`);continue}if(te(f)){t.push(`${r}.${f} conflicts with the built-in "${f}" lightness stop; choose a distinct custom tone name.`);continue}c.add(f),typeof p!="number"||!Number.isFinite(p)?t.push(`${r}.${f} must be a finite number.`):(p<0||p>1)&&t.push(`${r}.${f} must be 0\u20131 (got ${p}).`)}return c}const x=new Set(Object.keys(n.tones??{}));if("tones"in e)for(const s of m(e.tones,"tones"))x.add(s);if("chroma"in e)if(typeof e.chroma!="object"||e.chroma===null)t.push("chroma must be an object.");else{const s=e.chroma,r=Pt(e,n);for(const c of z)if(c in s){const f=s[c];if(typeof f!="object"||f===null){t.push(`chroma.${c} must be { min, max }.`);continue}const p=f;for(const l of r.get(c)??[])l.chroma!==void 0&&typeof p.min=="number"&&typeof p.max=="number"&&(l.chroma<p.min-1e-9||l.chroma>p.max+1e-9)&&o.push(`chroma.${c} clamps the anchor-sourced token ${c} ("${l.source}", effective in ${l.where}) and moves it off its declared swatch. Remove the band if that is unintended \u2014 anchors otherwise keep their own chroma.`);const g=f;(typeof g.min!="number"||g.min<0)&&t.push(`chroma.${c}.min must be \u2265 0.`),(typeof g.max!="number"||g.max<0||g.max>q)&&t.push(`chroma.${c}.max must be 0\u2013${q}.`),typeof g.min=="number"&&typeof g.max=="number"&&g.min>g.max&&t.push(`chroma.${c}.min (${g.min}) must be \u2264 max (${g.max}).`)}}if("anchors"in e)if(typeof e.anchors!="object"||e.anchors===null||Array.isArray(e.anchors))t.push("anchors must be an object of named colors.");else for(const[s,r]of Object.entries(e.anchors))if(M(s)?K.test(s)||t.push(`anchors: "${s}" is not a valid anchor name; use a lowercase slug (letters, digits, hyphens).`):t.push(`anchors: "${s}" is a reserved JavaScript property name and cannot be an anchor name; rename it.`),Me.includes(s)&&t.push(`anchors: "${s}" collides with a reserved color source name.`),typeof r=="string")W(r)||t.push(`anchors.${s} is not a valid CSS color: "${r}". Accepted forms: ${oe}.`);else if(typeof r=="object"&&r!==null&&!Array.isArray(r)){const c=r;typeof c.color!="string"&&t.push(`anchors.${s} must declare its base "color".`);for(const[f,p]of Object.entries(c))M(f)?f!=="color"&&!K.test(f)&&t.push(`anchors.${s}: "${f}" is not a valid slot name; use a lowercase slug.`):t.push(`anchors.${s}: "${f}" is a reserved JavaScript property name and cannot be a slot name; rename it.`),typeof p!="string"?t.push(`anchors.${s}.${f} must be a CSS color string.`):W(p)||t.push(`anchors.${s}.${f} is not a valid CSS color: "${p}". Accepted forms: ${oe}.`)}else t.push(`anchors.${s} must be a color string or a { color, \u2026slots } object.`);const b=new Map;if("anchors"in e&&typeof e.anchors=="object"&&e.anchors!==null&&!Array.isArray(e.anchors))for(const[s,r]of Object.entries(e.anchors))b.set(s,r);function S(s,r){const c=Ae(s);if(!c){t.push(`${r} "${s}" is not valid anchor syntax; use anchor:<name> or anchor:<name>.<slot>.`);return}if(!b.has(c.name)){const f=[...b.keys()];t.push(`${r} references undeclared anchor "${c.name}". Declared anchors: ${f.length>0?f.join(", "):"(none)"}.`);return}if(c.slot!==void 0){const f=b.get(c.name);if(typeof(typeof f=="object"&&f!==null&&!Array.isArray(f)?f[c.slot]:void 0)!="string"){const g=typeof f=="object"&&f!==null?Object.keys(f).filter(l=>l!=="color"):[];t.push(`${r} references unknown slot "${c.slot}" on anchor "${c.name}". Declared slots: ${g.length>0?g.join(", "):"(none)"}.`)}}}function A(s,r){if(s.startsWith("anchor:")){S(s,r);return}Me.includes(s)||t.push(`${r} must be one of: ${Me.join(", ")}, or a declared anchor as anchor:<name> / anchor:<name>.<slot>.`)}if("intents"in e)if(typeof e.intents!="object"||e.intents===null||Array.isArray(e.intents))t.push("intents must be an object.");else for(const[s,r]of Object.entries(e.intents)){const c=`intents.${s}`;if(!ee.includes(s)){t.push(`${c} is not a status family; expected one of: ${ee.join(", ")}.`);continue}if(typeof r!="string"){t.push(`${c} must be a string (a CSS color or an anchor: reference).`);continue}if(r.startsWith("anchor:")){S(r,c);continue}W(r)||t.push(`${c} "${r}" is not a supported color form or anchor: reference. Accepted forms: ${oe}, 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 D(s,r){if(s.startsWith("anchor:")){S(s,r);return}W(s)||t.push(`${r} is not a valid CSS color: "${s}". Accepted forms: ${oe}, or a declared anchor as anchor:<name> / anchor:<name>.<slot>.`)}if("dataPalette"in e)if(typeof e.dataPalette!="object"||e.dataPalette===null||Array.isArray(e.dataPalette))t.push("dataPalette must be an object with series1\u2013series8 color values.");else{const s=e.dataPalette;for(const[r,c]of Object.entries(s)){if(!pe.includes(r)){t.push(`dataPalette.${r} is not a series slot; expected one of: ${pe.join(", ")}.`);continue}typeof c!="string"?t.push(`dataPalette.${r} must be a CSS color or anchor reference string.`):D(c,`dataPalette.${r}`)}}if("dataRamps"in e)if(typeof e.dataRamps!="object"||e.dataRamps===null||Array.isArray(e.dataRamps))t.push("dataRamps must be an object of named ramp declarations.");else for(const[s,r]of Object.entries(e.dataRamps)){if(M(s)?K.test(s)||t.push(`dataRamps: "${s}" is not a valid ramp name; use a lowercase slug (letters, digits, hyphens).`):t.push(`dataRamps: "${s}" is a reserved JavaScript property name and cannot be a ramp name; rename it.`),typeof r!="object"||r===null||Array.isArray(r)){t.push(`dataRamps.${s} must be a sequential or diverging ramp object.`);continue}const c=r,f=c.steps??Ct;if((typeof f!="number"||!Number.isInteger(f)||f<Se||f>xe)&&t.push(`dataRamps.${s}.steps must be an integer from ${Se} through ${xe}.`),c.type==="sequential"){typeof c.source!="string"?t.push(`dataRamps.${s}.source must be a CSS color or anchor reference string.`):D(c.source,`dataRamps.${s}.source`);const p=c.lightnessStart??.95,g=c.lightnessEnd??.25;for(const[l,h]of[["lightnessStart",p],["lightnessEnd",g]])(typeof h!="number"||!Number.isFinite(h)||h<0||h>1)&&t.push(`dataRamps.${s}.${l} must be a finite number from 0 through 1.`);typeof p=="number"&&typeof g=="number"&&p<=g?t.push(`dataRamps.${s}.lightnessStart must be greater than lightnessEnd.`):typeof p=="number"&&Number.isFinite(p)&&typeof g=="number"&&Number.isFinite(g)&&typeof f=="number"&&Number.isInteger(f)&&f>=Se&&f<=xe&&(p-g)/(f-1)<=We&&t.push(`dataRamps.${s} lightness bounds must leave more than ${We} lightness between serialized stops.`);continue}if(c.type==="diverging"){typeof f=="number"&&Number.isInteger(f)&&f%2===0&&t.push(`dataRamps.${s}.steps must be odd so the neutral is the exact midpoint.`);for(const p of["start","end"])typeof c[p]!="string"?t.push(`dataRamps.${s}.${p} must be a CSS color or anchor reference string.`):D(c[p],`dataRamps.${s}.${p}`);"neutral"in c&&(typeof c.neutral!="string"?t.push(`dataRamps.${s}.neutral must be a CSS color or anchor reference string.`):D(c.neutral,`dataRamps.${s}.neutral`));continue}t.push(`dataRamps.${s}.type must be "sequential" or "diverging".`)}if("dataPalette"in e&&t.length===0){const s=he(Re,e),r={};let c=!0;for(const f of pe){const p=Rt(s.dataPalette[f],s.anchors);if(!p){c=!1;break}r[f]=p}if(c)for(const f of Ot(r))o.push(Tt(f))}function F(s,r){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const c=s;for(const[f,p]of Object.entries(c)){const g=`${r}.${f}`;if(!ae.includes(f)){t.push(`${g} is not a role; expected one of: ${ae.join(", ")}. (The status family is reserved and is not a role.)`);continue}const l=f,h=de[l];if(typeof p=="string"){A(p,g);continue}if(typeof p!="object"||p===null||Array.isArray(p)){t.push(`${g} must be a color source or a { color, \u2026slots } object.`);continue}const k=p;typeof k.color!="string"&&t.push(`${g} must declare its base "color".`);for(const[$,R]of Object.entries(k)){if(!Object.prototype.hasOwnProperty.call(h,$)||!M($)){const O=Object.keys(h).filter(v=>v!=="color");t.push(`${g}.${$} is not a slot of the ${l} role. Declared slots: ${O.length>0?O.join(", "):"(none)"}.`);continue}typeof R!="string"?t.push(`${g}.${$} must be a color source string.`):A(R,`${g}.${$}`)}}}if("roles"in e&&F(e.roles,"roles"),"contexts"in e)if(typeof e.contexts!="object"||e.contexts===null||Array.isArray(e.contexts))t.push("contexts must be an object.");else for(const[s,r]of Object.entries(e.contexts)){if(!M(s)||!K.test(s)){t.push(`contexts.${s} must be a lowercase slug matching ${K.source}.`);continue}if(typeof r!="object"||r===null||Array.isArray(r)){F(r,`contexts.${s}`);continue}const c=r,f=Object.fromEntries(Object.entries(c).filter(([g])=>g!=="lightness"&&g!=="tones"&&g!=="semanticMappings"));F(f,`contexts.${s}`),"lightness"in c&&d(c.lightness,`contexts.${s}.lightness`);const p=new Set(x);if("tones"in c)for(const g of m(c.tones,`contexts.${s}.tones`))p.add(g);"semanticMappings"in c&&L(c.semanticMappings,`contexts.${s}.semanticMappings`,p)}function L(s,r,c){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const f=s;for(const p of Object.keys(f))z.includes(p)||t.push(`${r}.${p} is not a semantic token; expected one of: ${z.join(", ")}.`);for(const p of z)if(p in f){const g=f[p];if(typeof g!="object"||g===null){t.push(`${r}.${p} must be { source, lightness }.`);continue}const l=g;if(typeof l.source!="string"?t.push(`${r}.${p}.source must be a string.`):A(l.source,`${r}.${p}.source`),typeof l.lightness!="string")t.push(`${r}.${p}.lightness must be one of: ${U.join(", ")}, or a declared tone:<name>.`);else if(!te(l.lightness)){const h=Oe(l.lightness);if(h===null)t.push(`${r}.${p}.lightness must be one of: ${U.join(", ")}, or a declared tone:<name>.`);else if(!c.has(h)){const k=[...c].sort();t.push(`${r}.${p}.lightness references undeclared tone "${h}". Declared tones: ${k.length>0?k.join(", "):"(none)"}.`)}}}}if("semanticMappings"in e&&L(e.semanticMappings,"semanticMappings",x),"explicitMappingTokens"in e)if(!Array.isArray(e.explicitMappingTokens))t.push("explicitMappingTokens must be an array of semantic token names.");else{const s=new Set,r=I(e.semanticMappings)?e.semanticMappings:void 0;for(const c of e.explicitMappingTokens){if(typeof c!="string"||!z.includes(c)){t.push(`explicitMappingTokens entries must be one of: ${z.join(", ")}.`);continue}s.has(c)&&t.push(`explicitMappingTokens contains duplicate token "${c}".`),s.add(c),(!r||!Object.prototype.hasOwnProperty.call(r,c))&&t.push(`explicitMappingTokens names "${c}" without a semanticMappings entry.`)}}for(const s of["pageBackgroundImage","boxBackgroundImage","vellumBackgroundImage"])s in e&&typeof e[s]!="string"&&t.push(`${s} must be a string.`);for(const s of["pageBackgroundImageOpacity","boxBackgroundImageOpacity","vellumOpacity","vellumBackgroundImageOpacity"])if(s in e)if(typeof e[s]!="number"||!isFinite(e[s]))t.push(`${s} must be a finite number.`);else{const r=e[s];(r<0||r>1)&&t.push(`${s} must be 0\u20131 (got ${r}).`)}return o.push(...nn(e,n)),{valid:t.length===0,errors:t,warnings:o}}const B=.045;function nn(e,n){try{return on(e,n)}catch{return[]}}function on(e,n){const t=he(n,e),o=dt(t),i=[...o],a=new Set(o);for(const u of Object.keys(t.contexts)){const d=ft(t,u);if(d)for(const m of dt(d))a.has(m)||i.push(`contexts.${u}: ${m}`)}return i}function sn(e){const n=kt($e(e)),t=St(n);return $t({r:be(t.r),g:be(t.g),b:be(t.b)})}function Z(e,n){return Math.hypot(e.L-n.L,e.a-n.a,e.b-n.b)}function X(e){return sn(W(fe($e(e))))}function lt(e){return(Math.floor(e*1e4)/1e4).toFixed(4)}const Q=2,pt=1e-4;function dt(e){const n=W(e.seedColor);if(!n)return[];const t=le(n,e),o=e.semanticMappings.actionBackground,i=e.chroma.actionBackground,a=Te(e.lightness,e.tones,o.lightness),u=(l,h,k,$)=>$e(re(l,h,k,$)),d=ee.map(l=>({name:l,base:t[l]})),m=[];if(ee.includes(o.source))m.push(`actionBackground is sourced from the "${o.source}" status family: ordinary and ${o.source}-intent action surfaces render identically (their labels may still differ). Remap the action to a non-status source \u2014 retuning "${o.source}" via intents moves both colors together.`);else{const l=ie(o.source,t,e.anchors);l&&d.push({name:"action",base:l})}const x=Fe(d.map(({name:l,base:h})=>[l,fe(u(h,a,i.min,i.max))]),B,["normal"]);if(x.length===0)return m;const b=new Map,S=(l,h)=>{const k=`${l}:${h}`;let $=b.get(k);if(!$){$=[];for(let R=0;R<360;R+=Q)$.push(X({l,c:h,h:R}));b.set(k,$)}return $},A=B-.002,D=(l,h,k,$)=>{const R=Math.hypot(l.a,l.b),O=Math.atan2(l.b,l.a)*180/Math.PI+180;let v=0;for(const E of k===$?[$]:[k,$]){if(E+R<B-1e-4)continue;let T=O,y=Z(X({l:h,c:E,h:O}),l);if(y>=B)return y;const _=S(h,E);for(let w=0;w<_.length;w+=1){const C=Z(_[w],l);if(C>=B)return C;C>y&&(y=C,T=w*Q)}let H=T;for(let w=T-Q;w<=T+Q;w+=.1){const C=Z(X({l:h,c:E,h:w}),l);if(C>=B)return C;C>y&&(y=C,H=w)}if(y>=A)for(let w=H-.1;w<=H+.1;w+=.001){const C=Z(X({l:h,c:E,h:w}),l);if(C>=B)return C;C>y&&(y=C)}y>v&&(v=y)}return v},F=(l,h,k)=>{const $=h===k?[k]:[h,k];let R=0;for(const O of $)for(const v of $){if(O+v<B-1e-4)continue;const E=S(l,O),T=S(l,v);let y=0,_=0,H=-1;for(let P=0;P<E.length;P+=1)for(let G=0;G<T.length;G+=1){const V=Z(E[P],T[G]);if(V>=B)return V;V>H&&(H=V,y=P*Q,_=G*Q)}const w=(P,G,V,Le)=>{const Ie=[];for(let J=G-V;J<=G+V;J+=Le)Ie.push({h:J,lab:X({l,c:v,h:J})});let ye=-1,Ne=P,Pe=G;for(let J=P-V;J<=P+V;J+=Le){const ht=X({l,c:O,h:J});for(const He of Ie){const De=Z(ht,He.lab);De>ye&&(ye=De,Ne=J,Pe=He.h)}}return{distance:ye,hueA:Ne,hueB:Pe}},C=w(y,_,Q,.1);if(C.distance>=B)return C.distance;let N=Math.max(H,C.distance);if(N>=A){const P=w(C.hueA,C.hueB,.1,.001);if(P.distance>N&&(N=P.distance),N>=B)return N}N>R&&(R=N)}return R},L=l=>ee.includes(l),s=(l,h,k,$,R)=>{const O=X(u(l.base,k,$,R)),v=X(u(h.base,k,$,R));if(Z(O,v)>=B)return{outcome:"direct"};const E=L(l.name)&&L(h.name),T=[l,h].filter(H=>L(H.name)),y=E?"one of them":`"${L(l.name)?l.name:h.name}"`;let _;for(const H of T){const w=D(H===l?v:O,k,$,R);if(w>=B)return{outcome:"retune",target:y};w>=B-pt&&(_=_??y)}if(E){const H=F(k,$,R);if(H>=B)return{outcome:"retune",target:"both"};H>=B-pt&&(_=_??"both")}return _!==void 0?{outcome:"near",target:_}:{outcome:"no"}},r=l=>l.outcome==="direct"?4:l.outcome==="retune"?l.target==="both"?2:3:l.outcome==="near"?1:0,c=l=>[...l].sort().join("|"),f=new Set(Fe(d.map(({name:l,base:h})=>[l,fe(u(h,a,0,q))]),B,["normal"]).map(l=>c(l.pair))),p=new Map(d.map(l=>[l.name,l])),g=new Map;for(const{pair:l,distance:h}of x){const k=p.get(l[0]),$=p.get(l[1]),R=L(k.name)&&L($.name),O=s(k,$,a,i.min,i.max);if(O.outcome==="direct"||O.outcome==="retune"){const N=O.target??(R?"one of them":`"${L(k.name)?k.name:$.name}"`);f.has(c(l))?m.push(`Status colors "${l[0]}" and "${l[1]}" are hard to distinguish under normal vision (distance ${lt(h)} < ${B}); status meanings must stay distinguishable \u2014 retune ${N} via intents.`):m.push(`Status colors "${l[0]}" and "${l[1]}" are hard to distinguish as rendered (distance ${lt(h)} < ${B}); the actionBackground chroma band ({ min: ${i.min}, max: ${i.max} }) pushes them together \u2014 widen the band, or retune ${N} via intents.`);continue}const v=s(k,$,a,0,q);let E={outcome:"no"};for(let N=1;N<=19&&E.outcome!=="direct";N+=1){const P=N*.05;if(Math.abs(P-a)<.001)continue;const G=s(k,$,P,i.min,i.max);r(G)>r(E)&&(E=G)}let T={outcome:"no"};const y=v.outcome==="direct"||v.outcome==="retune",_=E.outcome==="direct"||E.outcome==="retune";if(!y&&!_)for(let N=1;N<=19&&T.outcome!=="direct";N+=1){const P=s(k,$,N*.05,0,q);r(P)>r(T)&&(T=P)}const H=rn(v,E,T),w=`${O.outcome}|${H}`;let C=g.get(w);C||(C=[],g.set(w,C)),C.push(l)}for(const[l,h]of g){const k=l.indexOf("|"),$=l.slice(0,k),R=l.slice(k+1),O=h.map(([T,y])=>`"${T}"/"${y}"`),v=O.length>1?`${O.slice(0,-1).join(", ")} and ${O[O.length-1]}`:O[0],E=$==="near"?`Status colors ${v} may not separate by retuning as rendered: at the action stop's lightness (${a}) with the actionBackground chroma band ({ min: ${i.min}, max: ${i.max} }), the closest reachable retune found comes within the audit's search margin of the ${B} threshold`:`Status colors ${v} cannot be separated as rendered: at the action stop's lightness (${a}) with the actionBackground chroma band ({ min: ${i.min}, max: ${i.max} }), no intent retuning can pull ${h.length>1?"these pairs":"the pair"} ${B} apart`;m.push(E+R)}return m}function rn(e,n,t){if(e.outcome==="direct"&&n.outcome==="direct")return" \u2014 widen the chroma band or move the action lightness stop.";if(e.outcome==="direct")return n.outcome==="no"?"; no other action lightness stop can help while the band holds \u2014 widen the chroma band.":" \u2014 widen the chroma band.";if(n.outcome==="direct")return e.outcome==="no"?"; no wider chroma band can help at this lightness \u2014 move the action lightness stop.":" \u2014 move the action lightness stop.";if(e.outcome==="retune"&&n.outcome==="retune")return` \u2014 widen the chroma band or move the action lightness stop, then retune ${e.target} via intents.`;if(e.outcome==="retune")return n.outcome==="no"?`; no other action lightness stop can help while the band holds \u2014 widen the chroma band, then retune ${e.target} via intents.`:` \u2014 widen the chroma band, then retune ${e.target} via intents.`;if(n.outcome==="retune")return e.outcome==="no"?`; no wider chroma band can help at this lightness \u2014 move the action lightness stop, then retune ${n.target} via intents.`:` \u2014 move the action lightness stop, then retune ${n.target} via intents.`;const o=e.outcome==="no"&&n.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"?`${o} \u2014 change the band and the stop together.`:t.outcome==="retune"?`${o} \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 yn(e,n){const t=Be(e),o=Be(n),i=t.error!==void 0?{valid:!1,errors:[t.error],warnings:[]}:_e(t.value),a=o.error!==void 0?{valid:!1,errors:[o.error],warnings:[]}:_e(o.value,Qe),u=[...i.errors.map(m=>`light: ${m}`),...a.errors.map(m=>`dark: ${m}`)],d=[...i.warnings.map(m=>`light: ${m}`),...a.warnings.map(m=>`dark: ${m}`)];if(i.valid&&a.valid){const m=new Set(Object.keys(t.value?.contexts??{})),x=new Set(Object.keys(o.value?.contexts??{})),b=[...x].filter(A=>!m.has(A)).sort(),S=[...m].filter(A=>!x.has(A)).sort();(b.length>0||S.length>0)&&u.push(`contexts must declare the same names in both schemes. Missing from light: ${b.join(", ")||"(none)"}. Missing from dark: ${S.join(", ")||"(none)"}.`)}return{valid:u.length===0,errors:u,warnings:d}}const an=["anchors","angles","contexts","dataPalette","dataRamps","intents","roles","chroma","lightness","tones","semanticHues","semanticMappings","variantChroma"];function cn(e,n){const t={};for(const[a,u]of Object.entries(e))M(a)&&(t[a]=u);for(const[a,u]of Object.entries(n))u!==void 0&&M(a)&&(t[a]=u);for(const a of an){const u=e[a],d=n[a];if(u&&typeof u=="object"&&!Array.isArray(u)&&d&&typeof d=="object"&&!Array.isArray(d)){if(a==="anchors"){t[a]=nt(u,d);continue}if(a==="contexts"){t[a]=qt(u,d);continue}if(a==="dataRamps"){t[a]=rt(u,d);continue}const m={};for(const[x,b]of Object.entries(u))M(x)&&(m[x]=b);for(const[x,b]of Object.entries(d))b!==void 0&&M(x)&&(m[x]=b);t[a]=m}}const o=ge(e),i=ge(n);if(o!==void 0||i!==void 0){const a=o??new Set(Object.keys(e.semanticMappings??{}).filter(u=>z.includes(u)));for(const u of Object.keys(n.semanticMappings??{}))i===void 0||i.has(u)?a.add(u):a.delete(u);t.explicitMappingTokens=et(a)}return t}function bn(...e){let n={};for(const t of e){if(!t)continue;const o=zt(t);o&&(n=cn(n,o))}return Ee(n)}function mt(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r")}const gt={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 $n(e){return Ee({...gt,pageBackgroundImage:`url("${mt(e)}")`,pageBackgroundImageOpacity:.5})}function kn(e){return Ee({...gt,pageBackgroundImage:`url("${mt(e)}")`,pageBackgroundImageOpacity:.55})}export{K as ANCHOR_SLUG_PATTERN,Me as COLOR_SOURCES,qe as DEFAULT_BODY_FONT_FAMILY,Wt as DEFAULT_DARK_LIGHTNESS,Qe as DEFAULT_DARK_THEME,Ft as DEFAULT_LIGHT_LIGHTNESS,Re as DEFAULT_LIGHT_THEME,Xe as DEFAULT_MONOSPACE_FONT_FAMILY,Je as DEFAULT_SEMANTIC_MAPPINGS,U as LIGHTNESS_KEYS,an as NESTED_THEME_KEYS,Et as ROLE_DERIVED_INK,ae as ROLE_NAMES,Ke as ROLE_PAIRED_INK,de as ROLE_TOKEN_PLAN,z as SEMANTIC_COLOR_NAMES,ee as STATUS_COLOR_SOURCES,Ge as TOKEN_PAIRINGS,Dt as VARIANT_COLOR_SOURCES,kn as buildTaprootDarkTheme,$n as buildTaprootLightTheme,Ue as compileRoles,Ee as encodeTheme,tn as explicitMappingTokens,te as isLightnessKey,I as isObjectRecord,mn as isSemanticColorName,bn as layerThemes,cn as mergePartials,he as mergeTheme,Ae as parseAnchorSource,zt as parseTheme,je as resolveAnchorColor,ft as resolveContextTheme,Rt as resolveDataColorSource,Te as resolveLightnessReference,dn as roleInkProvenance,gn as semanticToCSS,Oe as toneReferenceName,hn as validateTheme,yn as validateThemePair};
|
|
1
|
+
import{UNSAFE_KEYS as yt,isSafeKey as M}from"./unsafe-keys.js";import{ACCEPTED_COLOR_FORMS as oe,apcaContrast as se,clampChannel as be,deltaEOK as bt,deriveSemantic as re,gamutMapToSRGB as $e,linearRgbToOklab as $t,oklchToSRGB as xt,parseCssColor as W,parseOklch as kt,serializeOklch as fe,srgbToLinearRGB as St}from"./color-engine.js";import{computeVariants as le,parseAnchorSource as At,resolveAnchorColor as Mt,resolveMappingSource as ie}from"./variant-engine.js";import{auditColorDistances as Fe,auditDataPalette as Ot,describePaletteCollision as Tt,DATA_SERIES_KEYS as pe,DEFAULT_DATA_PALETTE as xe,DEFAULT_DATA_RAMP_STEPS as Rt,MAX_DATA_RAMP_STEPS as ke,MIN_DATA_RAMP_LIGHTNESS_STEP as We,MIN_DATA_RAMP_STEPS as Se}from"./data-colors.js";import{TOKEN_PAIRINGS as je}from"./token-pairings.js";import{isTallHeaderPaint as Mn}from"../header/is-tall-header-paint.js";import{TOKEN_PAIRINGS as Tn}from"./token-pairings.js";import{AA_LARGE_RATIO as Cn,AA_NON_TEXT_RATIO as vn,AA_TEXT_RATIO as En,wcagRatio as wn}from"./wcag-contrast.js";const K=/^[a-z][a-z0-9-]*$/;function Ae(e){return At(e)}function Ke(e,n){return Mt(e,n)}function Ct(e,n){const t=Ae(e);if(t){const o=Ke(n,t);return o&&W(o)?o:null}return W(e)?e:null}const ae=["canvas","ink","accent","action","structure"],de={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"]]}},vt=new Set(["action.color"]),Et=new Set(["action.ink"]),wt={canvas:"background",ink:"text",accent:"link",action:"actionBackground",structure:"border"},ze={"action.ink":{role:"canvas",slot:"color"}},Bt=.45,_t=.045;function Ue(e,n,t){const o=je.actionText,i=[...U].sort((S,A)=>e[S]-e[A]||U.indexOf(S)-U.indexOf(A)),a=n?i.filter(S=>n(S)>=o.targetLc):i,u=t?a.filter(S=>t(S)>=_t):a,d=u.length>0?u:a,m=d.length>0?d:i;let k,b=1/0;for(const S of m){const A=Math.abs(e[S]-Bt);A<b&&(b=A,k=S)}return k??"muted"}function It(e){const n={l:e,c:0,h:0};return Math.abs(se({l:0,c:0,h:0},n))>=Math.abs(se({l:1,c:0,h:0},n))?"dark":"light"}function Nt(e,n,t,o){const i=Te(n,t,e),a=(o??It)(i)==="dark";let u=U[0];for(const d of U)(a?n[d]<n[u]:n[d]>n[u])&&(u=d);return u}const Lt={"accent.hover":"text"};function Pt(e,n){const t=new Map;try{const o=ge(n,e),i=(a,u,d,m)=>{const k=Ae(u),b=k?Ke(m,k):null,S=b===null?null:W(b),A=t.get(a)??[];A.some(H=>H.source===u&&H.chroma===S?.c)||(A.push({source:u,where:d,chroma:S?.c}),t.set(a,A))};for(const[a,u]of Object.entries(o.semanticMappings))u.source.startsWith("anchor:")&&i(a,u.source,"the root table",o.anchors);for(const a of Object.keys(o.contexts)){const u=ft(o,a);if(u)for(const[d,m]of Object.entries(u.semanticMappings))m.source.startsWith("anchor:")&&i(d,m.source,`contexts.${a}`,u.anchors)}}catch{return new Map}return t}function Y(e,n){if(e===void 0)return;if(typeof e=="string")return n==="color"?e:void 0;const t=e[n];return typeof t=="string"?t:void 0}function Ge(e,n,t,o={}){const i={};for(const a of ae){const u=e[a];if(u!==void 0)for(const[d,m]of Object.entries(de[a])){const k=ze[`${a}.${d}`];let b=Y(u,d),S=!1;if(b===void 0){k&&(b=Y(e[k.role],k.slot),b??=t[wt[k.role]]?.source,S=b!==void 0);const A=Lt[`${a}.${d}`];A!==void 0&&(b??=Y(u,A)),b??=Y(u,"color")}if(b!==void 0)for(const[A,H]of m){let F=H;if(vt.has(`${a}.${d}`))F=Ue(n,o.actionSurfaceContrast?I=>o.actionSurfaceContrast(b,I):void 0,o.actionSurfaceSeparation?I=>o.actionSurfaceSeparation(b,I):void 0);else if(k&&(S||Et.has(`${a}.${d}`))){const I=je[A],s=I?o.explicitMappings?.[I.bg]:void 0,r=s?.lightness??Ue(n,o.actionSurfaceContrast?f=>o.actionSurfaceContrast(Y(u,"color"),f):void 0,o.actionSurfaceSeparation?f=>o.actionSurfaceSeparation(Y(u,"color"),f):void 0),c=s?.source??Y(u,"color");F=Nt(r,n,o.tones??{},o.actionSurfacePole&&c!==void 0?f=>o.actionSurfacePole(c,f):void 0)}i[A]={source:b,lightness:F}}}}return i}function mn(e){const n={};for(const t of Object.keys(ze)){const o=t.indexOf("."),i=t.slice(0,o),a=t.slice(o+1),u=e[i];if(u===void 0)continue;const d=Y(u,a)!==void 0?"declared":"derived";for(const[m]of de[i][a]??[])n[m]=d}return n}const z=["background","layer1","layer2","layer3","layer4","actionBackground","actionText","border","shadow","text","typeOverline","typeLabel","typeLead","typeCaption","dangerText","headings","headingsHover","link","linkHover","linkHoverBg","inputCaret","inputSelection","inputSelectionBg"];function hn(e){return typeof e=="string"&&z.includes(e)}const Dt=["typeOverline","typeLabel","typeLead","typeCaption"],Me=["primary","analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning","info"],ee=["danger","success","warning","info"],Ht=["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"],Ve="tone:";function Oe(e){if(typeof e!="string"||!e.startsWith(Ve))return null;const n=e.slice(Ve.length);return M(n)&&K.test(n)?n:null}function te(e){return typeof e!="string"?!1:U.includes(e)}function Te(e,n,t){if(te(t))return e[t];const o=Oe(t);return o===null?e.surface:n?.[o]??e.surface}const Ft={surface:.99,raised1:.97,raised2:.9,raised3:.8,raised4:.72,accent:.5,muted:.45,text:.35,border:.3,ink:.25,shadow:.2},Wt={surface:.15,raised1:.2,raised2:.3,raised3:.4,raised4:.36,accent:.6,muted:.75,text:.85,border:.7,ink:.95,shadow:.6},Je={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"}},jt={light:"muted",dark:"raised3"};function Ye(e){return{...Je,actionBackground:{source:"primary",lightness:jt[e]}}}const X=.4;function Re(){const e={};for(const n of z)e[n]={min:0,max:X};return e}const Xe="system-ui, sans-serif",qe="monospace",Ze={seedColor:"oklch(0.7 0.125 216)",fontBody:Xe,fontHeadings:"",fontBrand:"",fontMenu:"",fontMonospace:qe,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:Re(),semanticMappings:{...Je},explicitMappingTokens:[],anchors:{},roles:{},contexts:{},dataPalette:{...xe},dataRamps:{}},Ce={...Ze,chroma:Re(),semanticMappings:Ye("light"),anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...xe},dataRamps:{},lightness:{...Ft}},Qe={...Ze,chroma:Re(),semanticMappings:Ye("dark"),anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...xe},dataRamps:{},lightness:{...Wt}},me=new WeakMap;me.set(Ce,new Set),me.set(Qe,new Set);function Kt(e,n){return yt.has(e)?void 0:n}function he(e){const n=e.explicitMappingTokens;if(!Array.isArray(n)||n.some(o=>typeof o!="string"||!z.includes(o)))return;const t=new Set(n);if(t.size===n.length&&!(t.size>0&&(!N(e.semanticMappings)||[...t].some(o=>!Object.prototype.hasOwnProperty.call(e.semanticMappings,o)))))return t}function et(e){return z.filter(n=>e.has(n))}function gn(e){return`--esp-color-${e.replace(/([A-Z])/g,"-$1").replace(/(\d)/g,"-$1").toLowerCase()}`}function zt(e){try{const n=tt(e),t=JSON.parse(n,Kt);return typeof t!="object"||t===null||Array.isArray(t)?null:t}catch{return null}}const ve="\xEF\xBB\xBF";function Ut(e){if(/^[\u0000-\u007f]*$/.test(e))return btoa(e);const n=new TextEncoder().encode(e);let t=ve;for(const o of n)t+=String.fromCharCode(o);return btoa(t)}function tt(e){const n=atob(e);if(!n.startsWith(ve))return n;const t=Uint8Array.from(n.slice(ve.length),o=>o.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(t)}function Ee(e){return Ut(JSON.stringify(e))}function Gt(e){const n={};for(const t of ee){const o=e[t];typeof o=="string"&&(n[t]=o.startsWith("anchor:")?o:ce(o))}return n}function ce(e){if(kt(e))return e;const n=W(e);return n?fe(n):e}function nt(e,n){const t={};for(const[o,i]of Object.entries(e))M(o)&&(t[o]=i);if(!n)return t;for(const[o,i]of Object.entries(n)){if(i===void 0||!M(o))continue;const a=t[o];if(a!==void 0&&typeof i=="object"&&i!==null){const u={};if(typeof a=="string")u.color=a;else for(const[d,m]of Object.entries(a))M(d)&&(u[d]=m);for(const[d,m]of Object.entries(i))m!==void 0&&M(d)&&(u[d]=m);t[o]=u;continue}t[o]=i}return t}function we(e){const n={};if(!N(e))return n;for(const[t,o]of Object.entries(e))M(t)&&K.test(t)&&!te(t)&&typeof o=="number"&&Number.isFinite(o)&&o>=0&&o<=1&&(n[t]=o);return n}function Vt(e,n){return{...we(e),...we(n)}}function Jt(e,n){const t={...e};if(!N(n))return t;for(const o of U){const i=n[o];typeof i=="number"&&Number.isFinite(i)&&i>=0&&i<=1&&(t[o]=i)}return t}function ot(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const n=e,t={};for(const o of ae){const i=n[o];i!==void 0&&(t[o]=i)}if(typeof n.lightness=="object"&&n.lightness!==null&&!Array.isArray(n.lightness)){const o={};for(const i of U){const a=n.lightness[i];a!==void 0&&(o[i]=a)}t.lightness=o}if(n.tones!==void 0){const o=we(n.tones);Object.keys(o).length>0&&(t.tones=o)}if(typeof n.semanticMappings=="object"&&n.semanticMappings!==null&&!Array.isArray(n.semanticMappings)){const o={};for(const[i,a]of Object.entries(n.semanticMappings)){if(!M(i)||!z.includes(i)||typeof a!="object"||a===null||Array.isArray(a))continue;const{source:u,lightness:d}=a;typeof u=="string"&&(typeof d!="string"||!te(d)&&Oe(d)===null||(o[i]={source:u,lightness:d}))}Object.keys(o).length>0&&(t.semanticMappings=o)}return t}function Yt(e,n){const t={};for(const[o,i]of Object.entries(e)){if(!M(o)||!K.test(o))continue;const a=ot(i);a&&(t[o]=a)}if(!n)return t;for(const[o,i]of Object.entries(n)){if(!M(o)||!K.test(o)||i===void 0)continue;const a=ot(i);if(!a)continue;const u=t[o];t[o]={...u??{},...a,...u?.lightness||a.lightness?{lightness:{...u?.lightness,...a.lightness}}:{},...u?.tones||a.tones?{tones:{...u?.tones,...a.tones}}:{},...u?.semanticMappings||a.semanticMappings?{semanticMappings:{...u?.semanticMappings,...a.semanticMappings}}:{}}}return t}function N(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function j(e){const n={};for(const[t,o]of Object.entries(e))o!==void 0&&M(t)&&(n[t]=o);return n}function st(e){if(!N(e))return e;const n=j(e);return N(e.lightness)&&(n.lightness=j(e.lightness)),N(e.tones)&&(n.tones=j(e.tones)),n}function Xt(e,n){const t={};for(const[o,i]of Object.entries(e))M(o)&&(t[o]=st(i));if(!n)return t;for(const[o,i]of Object.entries(n)){if(!M(o)||i===void 0)continue;const a=t[o];if(!N(a)||!N(i)){t[o]=st(i);continue}const u={...j(a),...j(i)};N(a.lightness)&&N(i.lightness)?u.lightness={...j(a.lightness),...j(i.lightness)}:N(i.lightness)&&(u.lightness=j(i.lightness)),N(a.tones)&&N(i.tones)?u.tones={...j(a.tones),...j(i.tones)}:N(i.tones)&&(u.tones=j(i.tones)),N(a.semanticMappings)&&N(i.semanticMappings)?u.semanticMappings={...j(a.semanticMappings),...j(i.semanticMappings)}:N(i.semanticMappings)&&(u.semanticMappings=j(i.semanticMappings)),t[o]=u}return t}function qt(e){const n={};for(const[t,o]of Object.entries(e)){if(!M(t))continue;if(typeof o=="string"){n[t]=ce(o);continue}const i={};for(const[a,u]of Object.entries(o))M(a)&&(i[a]=typeof u=="string"?ce(u):u);n[t]=i}return n}function ue(e){return typeof e!="string"?"":e.startsWith("anchor:")?e:ce(e)}function Zt(e){const n={};for(const t of pe)n[t]=ue(e[t]);return n}function rt(e,n){const t={};for(const[o,i]of Object.entries(e))M(o)&&K.test(o)&&i&&typeof i=="object"&&!Array.isArray(i)&&(t[o]={...i});if(!n)return t;for(const[o,i]of Object.entries(n)){if(!M(o)||!K.test(o)||!i||typeof i!="object"||Array.isArray(i))continue;const a=t[o],u=a!==void 0&&i.type!==void 0&&i.type!==a.type;t[o]={...u?{}:a??{},...i}}return t}function Qt(e){const n={};for(const[t,o]of Object.entries(e))if(M(t)){if(o.type==="sequential"&&typeof o.source=="string"){n[t]={...o,source:ue(o.source)};continue}if(o.type==="diverging"&&typeof o.start=="string"&&typeof o.end=="string"){n[t]={...o,start:ue(o.start),end:ue(o.end),...typeof o.neutral=="string"?{neutral:ue(o.neutral)}:{}};continue}n[t]={...o}}return n}function it(e){const n=W(e.seedColor);if(!n)return;const t=le(n,e);return(o,i)=>{const a=ie(o,t,e.anchors)??t.primary,u=e.chroma.actionBackground,d=re(a,e.lightness[i],u.min,u.max),m={l:d.l>.5?0:1,c:0,h:0};return Math.abs(se(m,d))}}function at(e){const n=W(e.seedColor);if(!n)return;const t=le(n,e);return(o,i)=>{const a=ie(o,t,e.anchors)??t.primary,u=e.chroma.actionBackground,d=re(a,i,u.min,u.max);return Math.abs(se({l:0,c:0,h:0},d))>=Math.abs(se({l:1,c:0,h:0},d))?"dark":"light"}}function en(e,n,t){if(n?.background)return n.background;const o=Y(e.canvas,"color");if(o!==void 0){const i=de.canvas.color?.find(([a])=>a==="background");if(i)return{source:o,lightness:i[1]}}return t.background}function ct(e,n){const t=W(e.seedColor);if(!t||!n)return;const o=le(t,e),i=ie(n.source,o,e.anchors)??o.primary,a=e.chroma.background,u=re(i,Te(e.lightness,e.tones,n.lightness),a.min,a.max);return(d,m)=>{const k=ie(d,o,e.anchors)??o.primary,b=e.chroma.actionBackground,S=re(k,e.lightness[m],b.min,b.max);return bt(S,u)}}function tn(e){const n=me.get(e);if(n)return new Set(n);const t=he(e);if(t)return t;const o=new Set,i=Ge(e.roles,e.lightness,e.semanticMappings,{tones:e.tones,actionSurfaceContrast:it(e),actionSurfacePole:at(e),actionSurfaceSeparation:ct(e,e.semanticMappings.background)});for(const[a,u]of Object.entries(i)){const d=e.semanticMappings[a];(d.source!==u.source||d.lightness!==u.lightness)&&o.add(a)}return o}function ge(e,n){const t={...e.roles,...n.roles},o=Yt(e.contexts,n.contexts),i=Jt(e.lightness,n.lightness),a=Vt(e.tones,n.tones),u=qt(nt(e.anchors,n.anchors)),d=typeof n.seedColor=="string"?ce(n.seedColor):e.seedColor,m=n.semanticMappings,k={...e.angles,...n.angles},b={...e.semanticHues,...n.semanticHues},S={...e.variantChroma,...n.variantChroma},A=Gt({...e.intents,...n.intents}),H=n.chroma,F=ne(e.chroma,H),I=Zt(ne(e.dataPalette,n.dataPalette)),s=Qt(rt(e.dataRamps,n.dataRamps)),r=tn(e),c=new Set(r),f=he(n),p={};for(const y of r)p[y]=e.semanticMappings[y];for(const[y,_]of Object.entries(m??{}))_!==void 0&&(f===void 0||f.has(y)?(c.add(y),p[y]=_):(c.delete(y),delete p[y]));const h=ne(e.semanticMappings,p),l={angles:k,anchors:u,chroma:F,intents:A,lightness:i,tones:a,seedColor:d,semanticHues:b,variantChroma:S},g=it(l),x=at(l),$=ct(l,en(t,p,h)),C=Ge(t,i,h,{explicitMappings:p,tones:a,actionSurfaceContrast:g,actionSurfacePole:x,actionSurfaceSeparation:$}),O={};for(const[y,_]of Object.entries(C))c.has(y)||(O[y]=_);const v={};for(const y of Dt)!c.has(y)&&O[y]===void 0&&(v[y]={source:h.text.source,lightness:h.text.lightness},H?.text!==void 0&&H[y]===void 0&&(F[y]={...F.text}));const E=ne(ne(ne(e.semanticMappings,v),O),p),T={...e,seedColor:d,fontBody:n.fontBody||e.fontBody||Xe,fontHeadings:n.fontHeadings??e.fontHeadings,fontBrand:n.fontBrand??e.fontBrand,fontMenu:n.fontMenu??e.fontMenu,fontMonospace:n.fontMonospace||e.fontMonospace||qe,fontWeightBody:String(n.fontWeightBody??e.fontWeightBody),fontWeightHeadings:String(n.fontWeightHeadings??e.fontWeightHeadings),fontWeightBrand:String(n.fontWeightBrand??e.fontWeightBrand),fontWeightMenu:String(n.fontWeightMenu??e.fontWeightMenu),fontWeightMonospace:String(n.fontWeightMonospace??e.fontWeightMonospace),stylesheets:n.stylesheets??[...e.stylesheets],rootFontSize:n.rootFontSize??e.rootFontSize,typeRatio:n.typeRatio??e.typeRatio,spaceRatio:n.spaceRatio??e.spaceRatio,borderRadius:n.borderRadius??e.borderRadius,viewportMin:n.viewportMin??e.viewportMin,viewportMax:n.viewportMax??e.viewportMax,angles:k,semanticHues:b,variantChroma:S,intents:A,lightness:i,tones:a,chroma:F,semanticMappings:E,explicitMappingTokens:et(c),anchors:u,roles:t,contexts:o,dataPalette:I,dataRamps:s};return n.pageBackgroundImage!==void 0&&(T.pageBackgroundImage=n.pageBackgroundImage),n.pageBackgroundImageOpacity!==void 0&&(T.pageBackgroundImageOpacity=n.pageBackgroundImageOpacity),n.boxBackgroundImage!==void 0&&(T.boxBackgroundImage=n.boxBackgroundImage),n.boxBackgroundImageOpacity!==void 0&&(T.boxBackgroundImageOpacity=n.boxBackgroundImageOpacity),n.vellumOpacity!==void 0&&(T.vellumOpacity=n.vellumOpacity),n.vellumBackgroundImage!==void 0&&(T.vellumBackgroundImage=n.vellumBackgroundImage),n.vellumBackgroundImageOpacity!==void 0&&(T.vellumBackgroundImageOpacity=n.vellumBackgroundImageOpacity),me.set(T,new Set(c)),T}const ut=new WeakMap;function ft(e,n){const t=e.contexts&&Object.prototype.hasOwnProperty.call(e.contexts,n)?e.contexts[n]:void 0;if(!t)return null;let o=ut.get(e);const i=o?.get(n);if(i)return i;const a={};for(const d of ae){const m=t[d];m!==void 0&&(a[d]=m)}const u=ge(e,{lightness:t.lightness,tones:t.tones,roles:a,semanticMappings:t.semanticMappings});return o||(o=new Map,ut.set(e,o)),o.set(n,u),u}function ne(e,n){if(!n)return{...e};const t={...e};for(const o of Object.keys(n)){const i=n[o];i!==void 0&&(t[o]=i)}return t}function Be(e){let n;try{n=tt(e)}catch{return{error:"Failed to decode Base64 string."}}let t;try{t=JSON.parse(n)}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 yn(e){const n=Be(e);return n.error!==void 0?{valid:!1,errors:[n.error],warnings:[]}:_e(n.value)}function _e(e,n=Ce){const t=[],o=[];"seedColor"in e&&(typeof e.seedColor!="string"?t.push("seedColor must be a string."):W(e.seedColor)||t.push(`seedColor is not a valid CSS color: "${e.seedColor}". Accepted forms: ${oe}.`));for(const s of["fontBody","fontHeadings","fontBrand","fontMenu","fontMonospace"])s in e&&typeof e[s]!="string"&&t.push(`${s} must be a string.`);const i=["normal","bold","lighter","bolder"],a=["inherit","initial","unset","revert","revert-layer"];for(const s of["fontWeightBody","fontWeightHeadings","fontWeightBrand","fontWeightMenu","fontWeightMonospace"])if(s in e){const r=e[s];if(typeof r=="number")(r<1||r>1e3)&&t.push(`${s} numeric value must be 1\u20131000 (got ${r}).`);else if(typeof r=="string"){const c=i.includes(r)||a.includes(r);if(/^\d+$/.test(r)){const p=Number(r);(p<1||p>1e3)&&t.push(`${s} numeric value must be 1\u20131000 (got "${r}").`)}else c||o.push(`${s} = "${r}" is not a standard font-weight value.`)}else t.push(`${s} must be a string or number.`)}"stylesheets"in e&&(Array.isArray(e.stylesheets)?e.stylesheets.some(s=>typeof s!="string")&&t.push("Every entry in stylesheets must be a string."):t.push("stylesheets must be an array of strings."));const u=[["rootFontSize",1,100],["borderRadius",0,10],["viewportMin",100,1e4],["viewportMax",200,1e4]];for(const[s,r,c]of u)if(s in e)if(typeof e[s]!="number"||!isFinite(e[s]))t.push(`${s} must be a finite number.`);else{const f=e[s];r!==void 0&&f<r&&t.push(`${s} must be \u2265 ${r} (got ${f}).`),c!==void 0&&f>c&&o.push(`${s} = ${f} is unusually high (max ${c}).`)}for(const s of["typeRatio","spaceRatio"])if(s in e)if(typeof e[s]!="number"||!isFinite(e[s]))t.push(`${s} must be a finite number.`);else{const r=e[s];r<=1&&t.push(`${s} must be > 1 (got ${r}).`);const c=s==="typeRatio"?1.3:2;r>c&&o.push(`${s} = ${r} is very high (max ${c}); scales may be extreme.`)}if("viewportMin"in e&&"viewportMax"in e){const s=e.viewportMin,r=e.viewportMax;typeof s=="number"&&typeof r=="number"&&s>=r&&t.push(`viewportMin (${s}) must be less than viewportMax (${r}).`)}if("angles"in e)if(typeof e.angles!="object"||e.angles===null)t.push("angles must be an object.");else{const s=e.angles;for(const r of["analogous","complementary","splitComplementary","triadic"])if(r in s)if(typeof s[r]!="number"||!isFinite(s[r]))t.push(`angles.${r} must be a finite number.`);else{const c=s[r];(c<0||c>360)&&o.push(`angles.${r} = ${c} is outside 0\u2013360.`)}}if("semanticHues"in e)if(typeof e.semanticHues!="object"||e.semanticHues===null)t.push("semanticHues must be an object.");else{const s=e.semanticHues;for(const r of["danger","success","warning","info"])if(r in s)if(typeof s[r]!="number"||!isFinite(s[r]))t.push(`semanticHues.${r} must be a finite number.`);else{const c=s[r];(c<0||c>360)&&o.push(`semanticHues.${r} = ${c} is outside 0\u2013360.`)}}if("variantChroma"in e)if(typeof e.variantChroma!="object"||e.variantChroma===null)t.push("variantChroma must be an object.");else{const s=e.variantChroma;for(const r of Ht)if(r in s)if(typeof s[r]!="number"||!isFinite(s[r]))t.push(`variantChroma["${r}"] must be a finite number.`);else{const c=s[r];c<0&&t.push(`variantChroma["${r}"] must be \u2265 0 (got ${c}).`),c>X&&o.push(`variantChroma["${r}"] = ${c} exceeds ${X}.`)}}function d(s,r){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const c=s;for(const f of Object.keys(c))(!M(f)||!te(f))&&t.push(`${r}.${f} is not a built-in lightness stop; expected one of: ${U.join(", ")}.`);for(const f of U)if(f in c)if(typeof c[f]!="number"||!isFinite(c[f]))t.push(`${r}.${f} must be a finite number.`);else{const p=c[f];(p<0||p>1)&&t.push(`${r}.${f} must be 0\u20131 (got ${p}).`)}}"lightness"in e&&d(e.lightness,"lightness");function m(s,r){const c=new Set;if(!N(s))return t.push(`${r} must be an object.`),c;for(const[f,p]of Object.entries(s)){if(!M(f)||!K.test(f)){t.push(`${r}.${f} must be a lowercase slug matching ${K.source}.`);continue}if(te(f)){t.push(`${r}.${f} conflicts with the built-in "${f}" lightness stop; choose a distinct custom tone name.`);continue}c.add(f),typeof p!="number"||!Number.isFinite(p)?t.push(`${r}.${f} must be a finite number.`):(p<0||p>1)&&t.push(`${r}.${f} must be 0\u20131 (got ${p}).`)}return c}const k=new Set(Object.keys(n.tones??{}));if("tones"in e)for(const s of m(e.tones,"tones"))k.add(s);if("chroma"in e)if(typeof e.chroma!="object"||e.chroma===null)t.push("chroma must be an object.");else{const s=e.chroma,r=Pt(e,n);for(const c of z)if(c in s){const f=s[c];if(typeof f!="object"||f===null){t.push(`chroma.${c} must be { min, max }.`);continue}const p=f;for(const l of r.get(c)??[])l.chroma!==void 0&&typeof p.min=="number"&&typeof p.max=="number"&&(l.chroma<p.min-1e-9||l.chroma>p.max+1e-9)&&o.push(`chroma.${c} clamps the anchor-sourced token ${c} ("${l.source}", effective in ${l.where}) and moves it off its declared swatch. Remove the band if that is unintended \u2014 anchors otherwise keep their own chroma.`);const h=f;(typeof h.min!="number"||h.min<0)&&t.push(`chroma.${c}.min must be \u2265 0.`),(typeof h.max!="number"||h.max<0||h.max>X)&&t.push(`chroma.${c}.max must be 0\u2013${X}.`),typeof h.min=="number"&&typeof h.max=="number"&&h.min>h.max&&t.push(`chroma.${c}.min (${h.min}) must be \u2264 max (${h.max}).`)}}if("anchors"in e)if(typeof e.anchors!="object"||e.anchors===null||Array.isArray(e.anchors))t.push("anchors must be an object of named colors.");else for(const[s,r]of Object.entries(e.anchors))if(M(s)?K.test(s)||t.push(`anchors: "${s}" is not a valid anchor name; use a lowercase slug (letters, digits, hyphens).`):t.push(`anchors: "${s}" is a reserved JavaScript property name and cannot be an anchor name; rename it.`),Me.includes(s)&&t.push(`anchors: "${s}" collides with a reserved color source name.`),typeof r=="string")W(r)||t.push(`anchors.${s} is not a valid CSS color: "${r}". Accepted forms: ${oe}.`);else if(typeof r=="object"&&r!==null&&!Array.isArray(r)){const c=r;typeof c.color!="string"&&t.push(`anchors.${s} must declare its base "color".`);for(const[f,p]of Object.entries(c))M(f)?f!=="color"&&!K.test(f)&&t.push(`anchors.${s}: "${f}" is not a valid slot name; use a lowercase slug.`):t.push(`anchors.${s}: "${f}" is a reserved JavaScript property name and cannot be a slot name; rename it.`),typeof p!="string"?t.push(`anchors.${s}.${f} must be a CSS color string.`):W(p)||t.push(`anchors.${s}.${f} is not a valid CSS color: "${p}". Accepted forms: ${oe}.`)}else t.push(`anchors.${s} must be a color string or a { color, \u2026slots } object.`);const b=new Map;if("anchors"in e&&typeof e.anchors=="object"&&e.anchors!==null&&!Array.isArray(e.anchors))for(const[s,r]of Object.entries(e.anchors))b.set(s,r);function S(s,r){const c=Ae(s);if(!c){t.push(`${r} "${s}" is not valid anchor syntax; use anchor:<name> or anchor:<name>.<slot>.`);return}if(!b.has(c.name)){const f=[...b.keys()];t.push(`${r} references undeclared anchor "${c.name}". Declared anchors: ${f.length>0?f.join(", "):"(none)"}.`);return}if(c.slot!==void 0){const f=b.get(c.name);if(typeof(typeof f=="object"&&f!==null&&!Array.isArray(f)?f[c.slot]:void 0)!="string"){const h=typeof f=="object"&&f!==null?Object.keys(f).filter(l=>l!=="color"):[];t.push(`${r} references unknown slot "${c.slot}" on anchor "${c.name}". Declared slots: ${h.length>0?h.join(", "):"(none)"}.`)}}}function A(s,r){if(s.startsWith("anchor:")){S(s,r);return}Me.includes(s)||t.push(`${r} must be one of: ${Me.join(", ")}, or a declared anchor as anchor:<name> / anchor:<name>.<slot>.`)}if("intents"in e)if(typeof e.intents!="object"||e.intents===null||Array.isArray(e.intents))t.push("intents must be an object.");else for(const[s,r]of Object.entries(e.intents)){const c=`intents.${s}`;if(!ee.includes(s)){t.push(`${c} is not a status family; expected one of: ${ee.join(", ")}.`);continue}if(typeof r!="string"){t.push(`${c} must be a string (a CSS color or an anchor: reference).`);continue}if(r.startsWith("anchor:")){S(r,c);continue}W(r)||t.push(`${c} "${r}" is not a supported color form or anchor: reference. Accepted forms: ${oe}, 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 H(s,r){if(s.startsWith("anchor:")){S(s,r);return}W(s)||t.push(`${r} is not a valid CSS color: "${s}". Accepted forms: ${oe}, or a declared anchor as anchor:<name> / anchor:<name>.<slot>.`)}if("dataPalette"in e)if(typeof e.dataPalette!="object"||e.dataPalette===null||Array.isArray(e.dataPalette))t.push("dataPalette must be an object with series1\u2013series8 color values.");else{const s=e.dataPalette;for(const[r,c]of Object.entries(s)){if(!pe.includes(r)){t.push(`dataPalette.${r} is not a series slot; expected one of: ${pe.join(", ")}.`);continue}typeof c!="string"?t.push(`dataPalette.${r} must be a CSS color or anchor reference string.`):H(c,`dataPalette.${r}`)}}if("dataRamps"in e)if(typeof e.dataRamps!="object"||e.dataRamps===null||Array.isArray(e.dataRamps))t.push("dataRamps must be an object of named ramp declarations.");else for(const[s,r]of Object.entries(e.dataRamps)){if(M(s)?K.test(s)||t.push(`dataRamps: "${s}" is not a valid ramp name; use a lowercase slug (letters, digits, hyphens).`):t.push(`dataRamps: "${s}" is a reserved JavaScript property name and cannot be a ramp name; rename it.`),typeof r!="object"||r===null||Array.isArray(r)){t.push(`dataRamps.${s} must be a sequential or diverging ramp object.`);continue}const c=r,f=c.steps??Rt;if((typeof f!="number"||!Number.isInteger(f)||f<Se||f>ke)&&t.push(`dataRamps.${s}.steps must be an integer from ${Se} through ${ke}.`),c.type==="sequential"){typeof c.source!="string"?t.push(`dataRamps.${s}.source must be a CSS color or anchor reference string.`):H(c.source,`dataRamps.${s}.source`);const p=c.lightnessStart??.95,h=c.lightnessEnd??.25;for(const[l,g]of[["lightnessStart",p],["lightnessEnd",h]])(typeof g!="number"||!Number.isFinite(g)||g<0||g>1)&&t.push(`dataRamps.${s}.${l} must be a finite number from 0 through 1.`);typeof p=="number"&&typeof h=="number"&&p<=h?t.push(`dataRamps.${s}.lightnessStart must be greater than lightnessEnd.`):typeof p=="number"&&Number.isFinite(p)&&typeof h=="number"&&Number.isFinite(h)&&typeof f=="number"&&Number.isInteger(f)&&f>=Se&&f<=ke&&(p-h)/(f-1)<=We&&t.push(`dataRamps.${s} lightness bounds must leave more than ${We} lightness between serialized stops.`);continue}if(c.type==="diverging"){typeof f=="number"&&Number.isInteger(f)&&f%2===0&&t.push(`dataRamps.${s}.steps must be odd so the neutral is the exact midpoint.`);for(const p of["start","end"])typeof c[p]!="string"?t.push(`dataRamps.${s}.${p} must be a CSS color or anchor reference string.`):H(c[p],`dataRamps.${s}.${p}`);"neutral"in c&&(typeof c.neutral!="string"?t.push(`dataRamps.${s}.neutral must be a CSS color or anchor reference string.`):H(c.neutral,`dataRamps.${s}.neutral`));continue}t.push(`dataRamps.${s}.type must be "sequential" or "diverging".`)}if("dataPalette"in e&&t.length===0){const s=ge(Ce,e),r={};let c=!0;for(const f of pe){const p=Ct(s.dataPalette[f],s.anchors);if(!p){c=!1;break}r[f]=p}if(c)for(const f of Ot(r))o.push(Tt(f))}function F(s,r){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const c=s;for(const[f,p]of Object.entries(c)){const h=`${r}.${f}`;if(!ae.includes(f)){t.push(`${h} is not a role; expected one of: ${ae.join(", ")}. (The status family is reserved and is not a role.)`);continue}const l=f,g=de[l];if(typeof p=="string"){A(p,h);continue}if(typeof p!="object"||p===null||Array.isArray(p)){t.push(`${h} must be a color source or a { color, \u2026slots } object.`);continue}const x=p;typeof x.color!="string"&&t.push(`${h} must declare its base "color".`);for(const[$,C]of Object.entries(x)){if(!Object.prototype.hasOwnProperty.call(g,$)||!M($)){const O=Object.keys(g).filter(v=>v!=="color");t.push(`${h}.${$} is not a slot of the ${l} role. Declared slots: ${O.length>0?O.join(", "):"(none)"}.`);continue}typeof C!="string"?t.push(`${h}.${$} must be a color source string.`):A(C,`${h}.${$}`)}}}if("roles"in e&&F(e.roles,"roles"),"contexts"in e)if(typeof e.contexts!="object"||e.contexts===null||Array.isArray(e.contexts))t.push("contexts must be an object.");else for(const[s,r]of Object.entries(e.contexts)){if(!M(s)||!K.test(s)){t.push(`contexts.${s} must be a lowercase slug matching ${K.source}.`);continue}if(typeof r!="object"||r===null||Array.isArray(r)){F(r,`contexts.${s}`);continue}const c=r,f=Object.fromEntries(Object.entries(c).filter(([h])=>h!=="lightness"&&h!=="tones"&&h!=="semanticMappings"));F(f,`contexts.${s}`),"lightness"in c&&d(c.lightness,`contexts.${s}.lightness`);const p=new Set(k);if("tones"in c)for(const h of m(c.tones,`contexts.${s}.tones`))p.add(h);"semanticMappings"in c&&I(c.semanticMappings,`contexts.${s}.semanticMappings`,p)}function I(s,r,c){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const f=s;for(const p of Object.keys(f))z.includes(p)||t.push(`${r}.${p} is not a semantic token; expected one of: ${z.join(", ")}.`);for(const p of z)if(p in f){const h=f[p];if(typeof h!="object"||h===null){t.push(`${r}.${p} must be { source, lightness }.`);continue}const l=h;if(typeof l.source!="string"?t.push(`${r}.${p}.source must be a string.`):A(l.source,`${r}.${p}.source`),typeof l.lightness!="string")t.push(`${r}.${p}.lightness must be one of: ${U.join(", ")}, or a declared tone:<name>.`);else if(!te(l.lightness)){const g=Oe(l.lightness);if(g===null)t.push(`${r}.${p}.lightness must be one of: ${U.join(", ")}, or a declared tone:<name>.`);else if(!c.has(g)){const x=[...c].sort();t.push(`${r}.${p}.lightness references undeclared tone "${g}". Declared tones: ${x.length>0?x.join(", "):"(none)"}.`)}}}}if("semanticMappings"in e&&I(e.semanticMappings,"semanticMappings",k),"explicitMappingTokens"in e)if(!Array.isArray(e.explicitMappingTokens))t.push("explicitMappingTokens must be an array of semantic token names.");else{const s=new Set,r=N(e.semanticMappings)?e.semanticMappings:void 0;for(const c of e.explicitMappingTokens){if(typeof c!="string"||!z.includes(c)){t.push(`explicitMappingTokens entries must be one of: ${z.join(", ")}.`);continue}s.has(c)&&t.push(`explicitMappingTokens contains duplicate token "${c}".`),s.add(c),(!r||!Object.prototype.hasOwnProperty.call(r,c))&&t.push(`explicitMappingTokens names "${c}" without a semanticMappings entry.`)}}for(const s of["pageBackgroundImage","boxBackgroundImage","vellumBackgroundImage"])s in e&&typeof e[s]!="string"&&t.push(`${s} must be a string.`);for(const s of["pageBackgroundImageOpacity","boxBackgroundImageOpacity","vellumOpacity","vellumBackgroundImageOpacity"])if(s in e)if(typeof e[s]!="number"||!isFinite(e[s]))t.push(`${s} must be a finite number.`);else{const r=e[s];(r<0||r>1)&&t.push(`${s} must be 0\u20131 (got ${r}).`)}return o.push(...nn(e,n)),{valid:t.length===0,errors:t,warnings:o}}const B=.045;function nn(e,n){try{return on(e,n)}catch{return[]}}function on(e,n){const t=ge(n,e),o=dt(t),i=[...o],a=new Set(o);for(const u of Object.keys(t.contexts)){const d=ft(t,u);if(d)for(const m of dt(d))a.has(m)||i.push(`contexts.${u}: ${m}`)}return i}function sn(e){const n=xt($e(e)),t=St(n);return $t({r:be(t.r),g:be(t.g),b:be(t.b)})}function Z(e,n){return Math.hypot(e.L-n.L,e.a-n.a,e.b-n.b)}function q(e){return sn(W(fe($e(e))))}function lt(e){return(Math.floor(e*1e4)/1e4).toFixed(4)}const Q=2,pt=1e-4;function dt(e){const n=W(e.seedColor);if(!n)return[];const t=le(n,e),o=e.semanticMappings.actionBackground,i=e.chroma.actionBackground,a=Te(e.lightness,e.tones,o.lightness),u=(l,g,x,$)=>$e(re(l,g,x,$)),d=ee.map(l=>({name:l,base:t[l]})),m=[];if(ee.includes(o.source))m.push(`actionBackground is sourced from the "${o.source}" status family: ordinary and ${o.source}-intent action surfaces render identically (their labels may still differ). Remap the action to a non-status source \u2014 retuning "${o.source}" via intents moves both colors together.`);else{const l=ie(o.source,t,e.anchors);l&&d.push({name:"action",base:l})}const k=Fe(d.map(({name:l,base:g})=>[l,fe(u(g,a,i.min,i.max))]),B,["normal"]);if(k.length===0)return m;const b=new Map,S=(l,g)=>{const x=`${l}:${g}`;let $=b.get(x);if(!$){$=[];for(let C=0;C<360;C+=Q)$.push(q({l,c:g,h:C}));b.set(x,$)}return $},A=B-.002,H=(l,g,x,$)=>{const C=Math.hypot(l.a,l.b),O=Math.atan2(l.b,l.a)*180/Math.PI+180;let v=0;for(const E of x===$?[$]:[x,$]){if(E+C<B-1e-4)continue;let T=O,y=Z(q({l:g,c:E,h:O}),l);if(y>=B)return y;const _=S(g,E);for(let w=0;w<_.length;w+=1){const R=Z(_[w],l);if(R>=B)return R;R>y&&(y=R,T=w*Q)}let D=T;for(let w=T-Q;w<=T+Q;w+=.1){const R=Z(q({l:g,c:E,h:w}),l);if(R>=B)return R;R>y&&(y=R,D=w)}if(y>=A)for(let w=D-.1;w<=D+.1;w+=.001){const R=Z(q({l:g,c:E,h:w}),l);if(R>=B)return R;R>y&&(y=R)}y>v&&(v=y)}return v},F=(l,g,x)=>{const $=g===x?[x]:[g,x];let C=0;for(const O of $)for(const v of $){if(O+v<B-1e-4)continue;const E=S(l,O),T=S(l,v);let y=0,_=0,D=-1;for(let P=0;P<E.length;P+=1)for(let G=0;G<T.length;G+=1){const V=Z(E[P],T[G]);if(V>=B)return V;V>D&&(D=V,y=P*Q,_=G*Q)}const w=(P,G,V,Ie)=>{const Ne=[];for(let J=G-V;J<=G+V;J+=Ie)Ne.push({h:J,lab:q({l,c:v,h:J})});let ye=-1,Le=P,Pe=G;for(let J=P-V;J<=P+V;J+=Ie){const gt=q({l,c:O,h:J});for(const De of Ne){const He=Z(gt,De.lab);He>ye&&(ye=He,Le=J,Pe=De.h)}}return{distance:ye,hueA:Le,hueB:Pe}},R=w(y,_,Q,.1);if(R.distance>=B)return R.distance;let L=Math.max(D,R.distance);if(L>=A){const P=w(R.hueA,R.hueB,.1,.001);if(P.distance>L&&(L=P.distance),L>=B)return L}L>C&&(C=L)}return C},I=l=>ee.includes(l),s=(l,g,x,$,C)=>{const O=q(u(l.base,x,$,C)),v=q(u(g.base,x,$,C));if(Z(O,v)>=B)return{outcome:"direct"};const E=I(l.name)&&I(g.name),T=[l,g].filter(D=>I(D.name)),y=E?"one of them":`"${I(l.name)?l.name:g.name}"`;let _;for(const D of T){const w=H(D===l?v:O,x,$,C);if(w>=B)return{outcome:"retune",target:y};w>=B-pt&&(_=_??y)}if(E){const D=F(x,$,C);if(D>=B)return{outcome:"retune",target:"both"};D>=B-pt&&(_=_??"both")}return _!==void 0?{outcome:"near",target:_}:{outcome:"no"}},r=l=>l.outcome==="direct"?4:l.outcome==="retune"?l.target==="both"?2:3:l.outcome==="near"?1:0,c=l=>[...l].sort().join("|"),f=new Set(Fe(d.map(({name:l,base:g})=>[l,fe(u(g,a,0,X))]),B,["normal"]).map(l=>c(l.pair))),p=new Map(d.map(l=>[l.name,l])),h=new Map;for(const{pair:l,distance:g}of k){const x=p.get(l[0]),$=p.get(l[1]),C=I(x.name)&&I($.name),O=s(x,$,a,i.min,i.max);if(O.outcome==="direct"||O.outcome==="retune"){const L=O.target??(C?"one of them":`"${I(x.name)?x.name:$.name}"`);f.has(c(l))?m.push(`Status colors "${l[0]}" and "${l[1]}" are hard to distinguish under normal vision (distance ${lt(g)} < ${B}); status meanings must stay distinguishable \u2014 retune ${L} via intents.`):m.push(`Status colors "${l[0]}" and "${l[1]}" are hard to distinguish as rendered (distance ${lt(g)} < ${B}); the actionBackground chroma band ({ min: ${i.min}, max: ${i.max} }) pushes them together \u2014 widen the band, or retune ${L} via intents.`);continue}const v=s(x,$,a,0,X);let E={outcome:"no"};for(let L=1;L<=19&&E.outcome!=="direct";L+=1){const P=L*.05;if(Math.abs(P-a)<.001)continue;const G=s(x,$,P,i.min,i.max);r(G)>r(E)&&(E=G)}let T={outcome:"no"};const y=v.outcome==="direct"||v.outcome==="retune",_=E.outcome==="direct"||E.outcome==="retune";if(!y&&!_)for(let L=1;L<=19&&T.outcome!=="direct";L+=1){const P=s(x,$,L*.05,0,X);r(P)>r(T)&&(T=P)}const D=rn(v,E,T),w=`${O.outcome}|${D}`;let R=h.get(w);R||(R=[],h.set(w,R)),R.push(l)}for(const[l,g]of h){const x=l.indexOf("|"),$=l.slice(0,x),C=l.slice(x+1),O=g.map(([T,y])=>`"${T}"/"${y}"`),v=O.length>1?`${O.slice(0,-1).join(", ")} and ${O[O.length-1]}`:O[0],E=$==="near"?`Status colors ${v} may not separate by retuning as rendered: at the action stop's lightness (${a}) with the actionBackground chroma band ({ min: ${i.min}, max: ${i.max} }), the closest reachable retune found comes within the audit's search margin of the ${B} threshold`:`Status colors ${v} cannot be separated as rendered: at the action stop's lightness (${a}) with the actionBackground chroma band ({ min: ${i.min}, max: ${i.max} }), no intent retuning can pull ${g.length>1?"these pairs":"the pair"} ${B} apart`;m.push(E+C)}return m}function rn(e,n,t){if(e.outcome==="direct"&&n.outcome==="direct")return" \u2014 widen the chroma band or move the action lightness stop.";if(e.outcome==="direct")return n.outcome==="no"?"; no other action lightness stop can help while the band holds \u2014 widen the chroma band.":" \u2014 widen the chroma band.";if(n.outcome==="direct")return e.outcome==="no"?"; no wider chroma band can help at this lightness \u2014 move the action lightness stop.":" \u2014 move the action lightness stop.";if(e.outcome==="retune"&&n.outcome==="retune")return` \u2014 widen the chroma band or move the action lightness stop, then retune ${e.target} via intents.`;if(e.outcome==="retune")return n.outcome==="no"?`; no other action lightness stop can help while the band holds \u2014 widen the chroma band, then retune ${e.target} via intents.`:` \u2014 widen the chroma band, then retune ${e.target} via intents.`;if(n.outcome==="retune")return e.outcome==="no"?`; no wider chroma band can help at this lightness \u2014 move the action lightness stop, then retune ${n.target} via intents.`:` \u2014 move the action lightness stop, then retune ${n.target} via intents.`;const o=e.outcome==="no"&&n.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"?`${o} \u2014 change the band and the stop together.`:t.outcome==="retune"?`${o} \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 bn(e,n){const t=Be(e),o=Be(n),i=t.error!==void 0?{valid:!1,errors:[t.error],warnings:[]}:_e(t.value),a=o.error!==void 0?{valid:!1,errors:[o.error],warnings:[]}:_e(o.value,Qe),u=[...i.errors.map(m=>`light: ${m}`),...a.errors.map(m=>`dark: ${m}`)],d=[...i.warnings.map(m=>`light: ${m}`),...a.warnings.map(m=>`dark: ${m}`)];if(i.valid&&a.valid){const m=new Set(Object.keys(t.value?.contexts??{})),k=new Set(Object.keys(o.value?.contexts??{})),b=[...k].filter(A=>!m.has(A)).sort(),S=[...m].filter(A=>!k.has(A)).sort();(b.length>0||S.length>0)&&u.push(`contexts must declare the same names in both schemes. Missing from light: ${b.join(", ")||"(none)"}. Missing from dark: ${S.join(", ")||"(none)"}.`)}return{valid:u.length===0,errors:u,warnings:d}}const an=["anchors","angles","contexts","dataPalette","dataRamps","intents","roles","chroma","lightness","tones","semanticHues","semanticMappings","variantChroma"];function cn(e,n){const t={};for(const[a,u]of Object.entries(e))M(a)&&(t[a]=u);for(const[a,u]of Object.entries(n))u!==void 0&&M(a)&&(t[a]=u);for(const a of an){const u=e[a],d=n[a];if(u&&typeof u=="object"&&!Array.isArray(u)&&d&&typeof d=="object"&&!Array.isArray(d)){if(a==="anchors"){t[a]=nt(u,d);continue}if(a==="contexts"){t[a]=Xt(u,d);continue}if(a==="dataRamps"){t[a]=rt(u,d);continue}const m={};for(const[k,b]of Object.entries(u))M(k)&&(m[k]=b);for(const[k,b]of Object.entries(d))b!==void 0&&M(k)&&(m[k]=b);t[a]=m}}const o=he(e),i=he(n);if(o!==void 0||i!==void 0){const a=o??new Set(Object.keys(e.semanticMappings??{}).filter(u=>z.includes(u)));for(const u of Object.keys(n.semanticMappings??{}))i===void 0||i.has(u)?a.add(u):a.delete(u);t.explicitMappingTokens=et(a)}return t}function $n(...e){let n={};for(const t of e){if(!t)continue;const o=zt(t);o&&(n=cn(n,o))}return Ee(n)}function mt(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r")}const ht={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 xn(e){return Ee({...ht,pageBackgroundImage:`url("${mt(e)}")`,pageBackgroundImageOpacity:.5})}function kn(e){return Ee({...ht,pageBackgroundImage:`url("${mt(e)}")`,pageBackgroundImageOpacity:.55})}export{Cn as AA_LARGE_RATIO,vn as AA_NON_TEXT_RATIO,En as AA_TEXT_RATIO,K as ANCHOR_SLUG_PATTERN,Me as COLOR_SOURCES,Xe as DEFAULT_BODY_FONT_FAMILY,Wt as DEFAULT_DARK_LIGHTNESS,Qe as DEFAULT_DARK_THEME,Ft as DEFAULT_LIGHT_LIGHTNESS,Ce as DEFAULT_LIGHT_THEME,qe as DEFAULT_MONOSPACE_FONT_FAMILY,Je as DEFAULT_SEMANTIC_MAPPINGS,U as LIGHTNESS_KEYS,an as NESTED_THEME_KEYS,Et as ROLE_DERIVED_INK,ae as ROLE_NAMES,ze as ROLE_PAIRED_INK,de as ROLE_TOKEN_PLAN,z as SEMANTIC_COLOR_NAMES,ee as STATUS_COLOR_SOURCES,Tn as TOKEN_PAIRINGS,Ht as VARIANT_COLOR_SOURCES,kn as buildTaprootDarkTheme,xn as buildTaprootLightTheme,Ge as compileRoles,Ee as encodeTheme,tn as explicitMappingTokens,te as isLightnessKey,N as isObjectRecord,hn as isSemanticColorName,Mn as isTallHeaderPaint,$n as layerThemes,cn as mergePartials,ge as mergeTheme,Ae as parseAnchorSource,zt as parseTheme,Ke as resolveAnchorColor,ft as resolveContextTheme,Ct as resolveDataColorSource,Te as resolveLightnessReference,mn as roleInkProvenance,gn as semanticToCSS,Oe as toneReferenceName,yn as validateTheme,bn as validateThemePair,wn as wcagRatio};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SemanticColorName } from "./theme.js";
|
|
2
|
+
/**
|
|
3
|
+
* Which semantic tokens are ink, what surface each sits on, and the
|
|
4
|
+
* APCA contrast each must clear.
|
|
5
|
+
*
|
|
6
|
+
* This pairing lived as an identical hardcoded table inside both
|
|
7
|
+
* `compute-theme-properties.ts` and `esp-element-base.ts` — invisible to
|
|
8
|
+
* themes and duplicated in exactly the way this repository's adoption
|
|
9
|
+
* rules exist to prevent. It belongs to the model: every serious system
|
|
10
|
+
* makes the surface/ink pair the unit designers see (Material's
|
|
11
|
+
* `on-primary`, shadcn's `-foreground`), and the roles layer derives an
|
|
12
|
+
* action's ink from it rather than asking a designer to hand-pick a
|
|
13
|
+
* legible color.
|
|
14
|
+
*
|
|
15
|
+
* Lc targets follow the APCA guidelines (ADR-002):
|
|
16
|
+
* 90 → body text at any size
|
|
17
|
+
* 75 → 16 px+ text (UI labels, links, body)
|
|
18
|
+
* 60 → 24 px+ bold / 28 px+ normal (headings, carets, decorative)
|
|
19
|
+
*/
|
|
20
|
+
type TokenPairing = Readonly<{
|
|
21
|
+
bg: SemanticColorName;
|
|
22
|
+
targetLc: number;
|
|
23
|
+
}>;
|
|
24
|
+
export declare const TOKEN_PAIRINGS: Readonly<Record<"actionText" | "linkHover", TokenPairing> & Partial<Record<SemanticColorName, TokenPairing>>>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t={text:{bg:"background",targetLc:75},typeOverline:{bg:"background",targetLc:90},typeLabel:{bg:"background",targetLc:75},typeLead:{bg:"background",targetLc:75},typeCaption:{bg:"background",targetLc:90},dangerText:{bg:"background",targetLc:75},headings:{bg:"background",targetLc:60},headingsHover:{bg:"background",targetLc:60},link:{bg:"background",targetLc:75},linkHover:{bg:"linkHoverBg",targetLc:75},actionText:{bg:"actionBackground",targetLc:75},inputCaret:{bg:"layer2",targetLc:60},inputSelection:{bg:"inputSelectionBg",targetLc:60}};export{t as TOKEN_PAIRINGS};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Minimum WCAG AA contrast for text. */
|
|
2
|
+
export declare const AA_TEXT_RATIO = 4.5;
|
|
3
|
+
/** Minimum WCAG AA contrast for large text. */
|
|
4
|
+
export declare const AA_LARGE_RATIO = 3;
|
|
5
|
+
/** Minimum WCAG AA contrast for graphics and indicators. */
|
|
6
|
+
export declare const AA_NON_TEXT_RATIO = 3;
|
|
7
|
+
interface WcagColor {
|
|
8
|
+
r: number;
|
|
9
|
+
g: number;
|
|
10
|
+
b: number;
|
|
11
|
+
}
|
|
12
|
+
/** Return the unrounded contrast of two opaque gamma-encoded sRGB colors (channels 0–1). */
|
|
13
|
+
export declare function wcagRatio(foreground: WcagColor, background: WcagColor): number;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{gammaToLinear as r}from"./color-engine.js";const c=4.5,i=3,T=3;function e({r:n,g:o,b:t}){return .2126*r(n)+.7152*r(o)+.0722*r(t)}function m(n,o){const t=e(n),a=e(o);return(Math.max(t,a)+.05)/(Math.min(t,a)+.05)}export{i as AA_LARGE_RATIO,T as AA_NON_TEXT_RATIO,c as AA_TEXT_RATIO,m as wcagRatio};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { PAINT_CATALOG, enabledPaintEntries } from "../shared/paint-catalog.js";
|
|
2
|
+
export type { PaintColor } from "../shared/paint-color.js";
|
|
3
|
+
export type { PaintAttribution, PaintCandidate, PaintEntriesByRole, PaintEntry, PaintInteraction, PaintKind, PaintNavigationFact, PaintSchemeFeatures, PaintTarget, } from "../shared/paint-types.js";
|
|
4
|
+
export { auditPaintCoverage } from "./paint-coverage.js";
|
|
5
|
+
export type { PaintCoverageAudit } from "./paint-coverage.js";
|
|
6
|
+
export { observePaint } from "./observe-paint.js";
|
|
7
|
+
export type { ObservePaintOptions, PaintObservation } from "./observe-paint.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{PAINT_CATALOG as o,enabledPaintEntries as t}from"../shared/paint-catalog.js";import{auditPaintCoverage as i}from"./paint-coverage.js";import{observePaint as P}from"./observe-paint.js";export{o as PAINT_CATALOG,i as auditPaintCoverage,t as enabledPaintEntries,P as observePaint};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type PaintColor } from "../shared/paint-color.js";
|
|
2
|
+
import type { PaintCandidate, PaintTarget } from "../shared/paint-types.js";
|
|
3
|
+
export interface ObservePaintOptions {
|
|
4
|
+
role: string;
|
|
5
|
+
extraTargets?: readonly PaintTarget[];
|
|
6
|
+
}
|
|
7
|
+
export interface PaintObservation {
|
|
8
|
+
role: string;
|
|
9
|
+
element: string;
|
|
10
|
+
state: string;
|
|
11
|
+
kind: PaintCandidate["kind"];
|
|
12
|
+
source: PaintCandidate["source"];
|
|
13
|
+
indicator?: PaintCandidate["indicator"];
|
|
14
|
+
/** Local paint opacity independent of the color's alpha and any shadow blur. Defaults to 1. */
|
|
15
|
+
paintOpacity?: number;
|
|
16
|
+
foreground: string;
|
|
17
|
+
background: string;
|
|
18
|
+
foregroundColor: PaintColor;
|
|
19
|
+
backgroundColor: PaintColor;
|
|
20
|
+
ratio: number;
|
|
21
|
+
required: 3 | 4.5;
|
|
22
|
+
location: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Read visible paint beneath an attached surface. Call after the browser has
|
|
26
|
+
* reached the intended interaction and layout state. Missing or ambiguous
|
|
27
|
+
* attributions and color identities are reported with their DOM locations.
|
|
28
|
+
*/
|
|
29
|
+
export declare function observePaint(root: Element | ShadowRoot, options: ObservePaintOptions): Promise<PaintObservation[]>;
|