@taprootio/espalier 7.1.1 → 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 +9 -0
- package/custom-elements.json +8073 -5734
- 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 +10 -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/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
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[]>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
(()=>{var an=Object.defineProperty,sn=(t,e)=>{for(var n in e)an(t,n,{get:e[n],enumerable:!0})},Kt={};sn(Kt,{PAINT_CATALOG:()=>Te,auditPaintCoverage:()=>br,enabledPaintEntries:()=>hr,observePaint:()=>eo});function tt(t){return t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in t}function _(t){if(t.assignedSlot)return t.assignedSlot;if(t.parentElement)return t.parentElement;const e=t.parentNode;return e&&tt(e)?e.host:null}function S(t,e){for(let n=t;n;n=_(n))if(n.matches(e))return n;return null}function ft(t){const e=S(t,"nav.drawer");return e?e.classList.contains("full-screen")?"full-screen":"panel":S(t,".is-horizontal > .group-items")?"inline-panel":"inline"}function T(t,e){return t==="inline"?e:`${t}-${e}`}function dt(t){switch(t){case"inline":case"inline-panel":return["inlineNav"];case"panel":case"full-screen":return[`drawer:${t}`]}}var V=["rest","hover","focus","hover-focus"],K=t=>t==="hover"||t==="hover-focus",G=t=>t==="focus"||t==="hover-focus";function St(t,e){return t.ownerDocument.defaultView?.getComputedStyle(t).getPropertyValue(e).trim()||void 0}var Yt=Object.freeze({aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"}),Jt=Math.PI/180,q=1e-4,cn=50,pt="[+-]?(?:\\d+|\\d*\\.\\d+)(?:[eE][+-]?\\d+)?",D="[\\t\\n\\f\\r ]",ln=new RegExp(D+"*,"+D+"*"),un=new RegExp(D+"+");function ht(t){return t.replace(/\/\*[\s\S]*?(?:\*\/|$)/g," ").replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g,"")}var Zt={"":1,deg:1,grad:.9,rad:180/Math.PI,turn:360},fn=.4,dn=new RegExp("^oklch\\("+D+"*("+pt+")(%?)"+D+"+("+pt+")(%?)"+D+"+("+pt+")(deg|grad|rad|turn)?"+D+"*\\)$","i");function pn(t){const e=t.h*Jt;return{L:t.l,a:t.c*Math.cos(e),b:t.c*Math.sin(e)}}function hn(t){const e=t.L+.3963377774*t.a+.2158037573*t.b,n=t.L-.1055613458*t.a-.0638541728*t.b,r=t.L-.0894841775*t.a-1.291485548*t.b,o=e*e*e,a=n*n*n,i=r*r*r;return{r:4.0767416621*o-3.3077115913*a+.2309699292*i,g:-1.2684380046*o+2.6097574011*a-.3413193965*i,b:-.0041960863*o-.7034186147*a+1.707614701*i}}function Et(t){return t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055}function gn(t){return{r:Et(t.r),g:Et(t.g),b:Et(t.b)}}function mn(t){return t.r>=-q&&t.r<=1+q&&t.g>=-q&&t.g<=1+q&&t.b>=-q&&t.b<=1+q}function U(t){return Math.max(0,Math.min(1,t))}function bn(t){const e=ht(t).match(dn);if(!e)return null;let n=parseFloat(e[1]);e[2]==="%"&&(n/=100);let r=parseFloat(e[3]);e[4]==="%"&&(r=r/100*fn);const o=parseFloat(e[5])*Zt[(e[6]??"").toLowerCase()];return!isFinite(n)||!isFinite(r)||!isFinite(o)?null:{l:Math.max(0,Math.min(1,n)),c:Math.max(0,r),h:(o%360+360)%360}}function Ct(t){return gn(hn(pn(t)))}function Qt(t){return mn(Ct(t))}function te(t){if(t.c<=q||Qt(t))return{...t};let e=0,n=t.c,r={...t};for(let o=0;o<cn;o++){const a=(e+n)/2;if(r={l:t.l,c:a,h:t.h},Qt(r)?e=a:n=a,n-e<q)break}return{l:t.l,c:e,h:t.h}}function Y(t){return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function vn(t){return{r:Y(t.r),g:Y(t.g),b:Y(t.b)}}function yn({r:t,g:e,b:n}){const r=Math.cbrt(.4122214708*t+.5363325363*e+.0514459929*n),o=Math.cbrt(.2119034982*t+.6806995451*e+.1073969566*n),a=Math.cbrt(.0883024619*t+.2817188376*e+.6299787005*n);return{L:.2104542553*r+.793617785*o-.0040720468*a,a:1.9779984951*r-2.428592205*o+.4505937099*a,b:.0259040371*r+.7827717662*o-.808675766*a}}function wn(t){return yn(vn(t))}function ee(t){const e=Math.sqrt(t.a*t.a+t.b*t.b),n=e<1e-12?0:(Math.atan2(t.b,t.a)/Jt%360+360)%360;return{l:t.L,c:e,h:n}}function ne(t,e){const n=t.slice(1),r=n.length;if(!/^[0-9a-f]+$/i.test(n)||r!==3&&r!==6&&!(e&&(r===4||r===8)))return null;const o=r<=4?1:2,a=i=>{const s=n.slice(i*o,(i+1)*o);return parseInt(o===1?s.repeat(2):s,16)/255};return{space:"srgb",color:{r:a(0),g:a(1),b:a(2)},alpha:r===4||r===8?a(3):1}}function et(t,e,n){const r=t.match(new RegExp("^"+e+"\\("+D+"*([^)]*?)"+D+"*\\)$","i"));if(!r)return null;const o=r[1],a=o.includes(","),i=o.split("/");if(i.length>2||i.length===2&&(a||!n))return null;const l=ht(i[0]).split(a?ln:un),c=a&&l.length===4&&n?l.pop():i[1];if(l.length!==3||l.some(f=>f.length===0))return null;const u=c===void 0?1:re(ht(c));return u===null?null:{args:l,legacy:a,alpha:u}}var kn=new RegExp("^("+pt+")([a-z%]*)$","i");function gt(t){const e=t.match(kn);if(!e)return null;const n=parseFloat(e[1]);return isFinite(n)?{value:n,unit:e[2].toLowerCase()}:null}function re(t){if(t.toLowerCase()==="none")return 0;const e=gt(t);return!e||e.unit!==""&&e.unit!=="%"?null:U(e.unit==="%"?e.value/100:e.value)}function xn(t){if(t.unit!==""&&t.unit!=="%")return null;const e=t.unit==="%"?t.value/100:t.value/255;return Math.max(0,Math.min(1,e))}function Sn(t){const e=Zt[t.unit];return e===void 0?null:t.value*e}function oe(t){return t.unit!==""&&t.unit!=="%"?null:Math.max(0,Math.min(1,t.value/100))}function En(t,e,n){const r=(t%360+360)%360,o=a=>{const i=(a+r/30)%12,s=e*Math.min(n,1-n);return n-s*Math.max(-1,Math.min(i-3,9-i,1))};return{r:o(0),g:o(8),b:o(4)}}function ae(t,e){const n=ht(t);if(n.startsWith("#"))return ne(n,e);if(/^oklch\(/i.test(n)){const r=e?et(n,"oklch",!0):null;if(e&&(!r||r.legacy))return null;const o=bn(r?`oklch(${r.args.map(a=>a.toLowerCase()==="none"?"0":a).join(" ")})`:n);return o?{space:"oklch",color:o,alpha:r?.alpha??1}:null}if(/^rgba?\(/i.test(n)){const r=et(n,"rgba?",e);if(!r)return null;const o=r.args.map(gt);if(o.some(u=>u===null))return null;const a=o;if(r.legacy&&new Set(a.map(u=>u.unit)).size>1)return null;const i=a.map(xn);if(i.some(u=>u===null))return null;const[s,l,c]=i;return{space:"srgb",color:{r:s,g:l,b:c},alpha:r.alpha}}if(/^hsla?\(/i.test(n)){const r=et(n,"hsla?",e);if(!r)return null;const o=r.args.map(gt);if(o.some(f=>f===null))return null;const[a,i,s]=o;if(r.legacy&&(i.unit!=="%"||s.unit!=="%"))return null;const l=Sn(a),c=oe(i),u=oe(s);return l===null||c===null||u===null?null:{space:"srgb",color:En(l,c,u),alpha:r.alpha}}if(e){if(/^oklab\(/i.test(n)){const a=et(n,"oklab",!0);if(!a||a.legacy)return null;const i=a.args.map(u=>gt(u.toLowerCase()==="none"?"0":u));if(i.some(u=>!u||u.unit!==""&&u.unit!=="%"))return null;const[s,l,c]=i.map((u,f)=>{const d=u;return d.unit!=="%"?d.value:d.value/100*(f===0?1:.4)});return{space:"oklch",color:ee({L:U(s),a:l,b:c}),alpha:a.alpha}}const r=n.toLowerCase();if(Object.prototype.hasOwnProperty.call(Yt,r))return ne(Yt[r],e);if(r==="transparent")return{space:"srgb",color:{r:0,g:0,b:0},alpha:0};const o=n.match(new RegExp("^color\\("+D+"*srgb"+D+"+","i"));if(o){const a=et(`color(${n.slice(o[0].length)}`,"color",!0);if(!a||a.legacy)return null;const i=a.args.map(re);if(i.some(u=>u===null))return null;const[s,l,c]=i;return{space:"srgb",color:{r:s,g:l,b:c},alpha:a.alpha}}}return null}var Cn=4.5,Rn=3;function ie({r:t,g:e,b:n}){return .2126*Y(t)+.7152*Y(e)+.0722*Y(n)}function Mn(t,e){const n=ie(t),r=ie(e);return(Math.max(n,r)+.05)/(Math.min(n,r)+.05)}function nt(t){const e=ae(t,!0);if(!e)return null;const n=e.space==="oklch"?Ct(te(e.color)):e.color;return{r:U(n.r),g:U(n.g),b:U(n.b),alpha:e.alpha}}function se(t,e){const n=t&&ae(t,!0);if(!n)return null;const r=n.space==="oklch"?n.color:ee(wn(n.color)),o=Ct(te({...r,l:U(e(r.l))}));return{r:U(o.r),g:U(o.g),b:U(o.b),alpha:n.alpha}}function ce(t,e){if(t.alpha===0)return e;if(t.alpha===1||e.alpha===0)return t;const n=e.alpha*(1-t.alpha),r=t.alpha+n;return{r:(t.r*t.alpha+e.r*n)/r,g:(t.g*t.alpha+e.g*n)/r,b:(t.b*t.alpha+e.b*n)/r,alpha:r}}var le=3,Tn=4,ue=.1,mt=4;function fe(t){return t>=le&&t<=Tn}var de=1/Math.sqrt(2*Math.PI),Pn=de*Math.exp(-(mt**2)/2)/mt,An=.5-ue/(le/2)*de-3*Pn-.05;function pe(t){if(t.blur===0)return t.alpha;if(!fe(t.blur))throw new RangeError(`Unsupported shadow indicator blur ${t.blur}px. Expected 3\u20134px.`);return t.alpha*An}function On(t){return t==="text"?Cn:Rn}var Rt={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}},Nn=.88,bt="action-interaction-fill",Mt="button-focus-shadow",he=Rt.actionText.bg,ge=({element:t,source:e})=>{const n=e==="fill"||e==="stroke";if(e!=="text"&&e!=="shadow"&&!n)return;const r=S(t,"[part=wrapper].esp-field:not(.incognito)"),o=r&&S(r,"esp-button"),a=r?.querySelector(":scope > [part=control]");if(!r||!o||!a||e==="shadow"&&t!==r||e==="text"&&!S(t,"[part=label]"))return;const i=S(o,"esp-menu-item"),s=!i&&S(o,"esp-footer");if(!(i&&S(o,"esp-header"))&&!s)return;const l=i?ft(o):"inline",c=a.matches("[aria-current=page]"),u=a.matches("button:disabled"),f=!u&&r.matches(":hover"),d=!u&&r.matches(":focus-within"),p=f||d,v=c?f?"current-hover":"current":d?f?"hover-focus":"focus":f?"hover":"rest",g=s?"footer-action-button":"nav-button";return{element:n?`${g}-icon`:g,owner:a,state:()=>T(l,v),...e==="shadow"?{foregroundDerivations:[Mt],foregroundAliases:["shadow"]}:p?{backgroundDerivations:[bt]}:{}}};function me(t,e=!1){const n=e?["footerActionButton"]:dt(t),r=e?void 0:{kind:"button",...t==="inline"?{depth:"top-level"}:t==="inline-panel"?{depth:"nested"}:{}},o=e?"footer-action-button":"nav-button",a=e?[...n,"footerActionIcon"]:n,i=t==="inline"?"layer2":"layer1",s=V.flatMap(l=>{const c=T(t,l),u={element:o,foreground:"actionText",background:l==="rest"?he:bt,state:c,kind:"text",flags:n,...r?{navigation:r}:{}},f={...u,element:`${o}-icon`,kind:"graphic",flags:a,...r?{navigation:{...r,icon:!0}}:{}};return G(l)?[u,f,{...u,foreground:Mt,background:i,kind:"ring",indicator:"blurred-shadow"}]:[u,f]});if(r)for(const l of["current","current-hover"]){const c={element:o,foreground:"actionText",background:l==="current"?he:bt,state:T(t,l),kind:"text",flags:n,navigation:{...r,canBeCurrent:!0}};s.push(c,{...c,element:`${o}-icon`,kind:"graphic",navigation:{...r,canBeCurrent:!0,icon:!0}})}return s}var In={entriesByRole:{header:["inline","inline-panel","panel","full-screen"].flatMap(t=>me(t)),footer:me("inline",!0)},targets:{header:[ge],footer:[ge]},derivations:{[bt]:t=>se(t.readColor("actionBackground"),e=>e*Nn),[Mt]:t=>{const e=t.readProperty("--esp-field-focus-shadow");if(e)return nt(e);if(t.scheme==="light")return nt(t.readColor("shadow")??"");const n=t.readProperty("--_esp-context-shadow");if(n)return nt(n);const r=t.readProperty("--esp-l-ink")?.trim(),o=r?.endsWith("%")?Number(r.slice(0,-1))/100:Number(r);return r&&Number.isFinite(o)?se(t.readColor("primary"),()=>o):null}}},Ln=({element:t,source:e})=>{const n=S(t,".brand .configured-brand");if(!(!n||!S(n,"esp-footer"))){if(e==="outline"&&t===n&&n.matches("a[href]"))return{element:"brand-link",owner:n};if(e==="text"&&S(t,".brand-text"))return{element:"brand-text",owner:n,...n.matches("a[href]")?{}:{state:()=>"rest"},...n.matches("a[href]:hover")?{}:{brandColor:St(n,"--_esp-footer-brand-color")}}}};function _n(t){const e=t.ownerDocument,n=e.createTreeWalker(t,NodeFilter.SHOW_TEXT),r=e.createRange();for(let o=n.nextNode();o;o=n.nextNode()){const a=o.parentElement;if(!(!a||!o.textContent?.trim()||a.closest("svg, [hidden], .sr-only"))&&e.defaultView?.getComputedStyle(a).visibility==="visible"&&(r.selectNodeContents(o),Array.from(r.getClientRects()).some(({width:i,height:s})=>i>0&&s>0)))return!0}return!1}var $n=({element:t,source:e})=>{if(!S(t,"esp-footer")||S(t,"esp-button"))return;const n=S(t,"a[href]");if(n&&!n.classList.contains("configured-brand")&&(e==="text"||e==="outline"&&t===n&&_n(n)))return{element:"footer-link",owner:n};if(e!=="text")return;const r=S(t,"h1, h2, h3, h4, h5, h6");if(r)return{element:"footer-heading",owner:r,state:()=>"rest"};if(S(t,".aside, .bottom, esp-footer-link-group"))return{element:"footer-body",owner:t,state:()=>"rest"}},Dn=Rt.linkHover.bg,Bn={entriesByRole:{footer:[{element:"footer-heading",foreground:"headings",background:"layer2",state:"rest",kind:"text",flags:["footerHeadings"]},{element:"footer-body",foreground:"text",background:"layer2",state:"rest",kind:"text",flags:["footerBody"]},...V.flatMap(t=>{const e=K(t),n=G(t),r={foreground:e?"linkHover":"link",background:e?Dn:"layer2",state:t,kind:"text"},o=[{...r,element:"footer-link",flags:["footerLinks"]},{...r,element:"brand-text",foreground:e?"linkHover":"brand-color",flags:t==="rest"?["brandText"]:["brandText","brandLink"]}];if(n)for(const[a,i]of[["footer-link","footerLinks"],["brand-link","brandLink"]])o.push({element:a,foreground:"link",background:"layer2",state:t,kind:"ring",flags:[i]});return o})]},targets:{footer:[Ln,$n]}},Gn=({element:t,source:e})=>{const n=S(t,"section.brand .configured-brand");if(!(!n||!S(n,"esp-header"))){if(e==="outline"&&t===n&&n.matches("a[href]"))return{element:"brand-link",owner:n};if(e==="text"&&S(t,".brand-text"))return{element:"brand-text",owner:n,...n.matches(":hover")?{}:{brandColor:St(n,"--_esp-header-brand-color")}}}},Un=({element:t,source:e})=>{if(e!=="fill"&&e!=="stroke"&&e!=="outline")return;const n=S(t,"esp-header-button");if(!n||!S(n,"esp-header"))return;const r=n.shadowRoot?.querySelector("button");if(!r||e==="outline"&&t!==r)return;if(n.classList.contains("theme-toggle"))return{element:"theme-toggle",owner:r};if(n.classList.contains("menu-toggle")){const a=n.matches(":popover-open")?"full-screen":r.getAttribute("aria-expanded")==="true"?"panel":"inline";return{element:"burger",owner:r,state:i=>T(a,i)}}const o=n.shadowRoot?.querySelector("use[href$='#search']")??n.querySelector("use[href$='#search']");if(n.getAttribute("icon")==="search"||o)return{element:"search-button",owner:r}};function rt(t,e,n,r="inline"){return V.flatMap(o=>{const a={element:t,foreground:"text",background:n==="tall"?"layer2":K(o)?"layer4":"layer3",state:T(r,o),flags:e},i={...a,kind:"graphic"};return G(o)?[i,{...a,kind:"ring"}]:[i]})}var Hn={entriesByRole:{header:[...V.flatMap(t=>{const e={element:"brand-text",foreground:K(t)?"headingsHover":"brand-color",background:"layer2",state:t,kind:"text",flags:G(t)?["brandText","brandLink"]:["brandText"]};return G(t)?[e,{element:"brand-link",foreground:"link",background:"layer2",state:t,kind:"ring",flags:["brandLink"]}]:[e]}),...["standard","tall"].flatMap(t=>{const e=`headerPaint:${t}`;return[...rt("search-button",["searchButton",e],t),...rt("theme-toggle",["themeToggle",e],t),...rt("burger",["burger",e],t),...rt("burger",["burger","drawer:panel",e],t,"panel")]}),...rt("burger",["burger","drawer:full-screen"],"standard","full-screen")]},targets:{header:[Gn,Un]}},be=Rt.linkHover.bg,ve="headingsHover",Fn=["inline","inline-panel","panel","full-screen"];function vt(t,e){switch(t){case"inline":return{...e,depth:"top-level"};case"inline-panel":return{...e,depth:"nested"};default:return e}}var Vn=({element:t,source:e})=>{const n=S(t,".item:not(.button-appearance)"),r=n&&S(n,"esp-menu-item");if(!n||!r||!S(r,"esp-header"))return;const o=n.querySelector(":scope > :is(a, button, [aria-current=page])");if(!o)return;const a=o.matches("[aria-current=page]"),i=ft(n),s=i!=="inline"&&n.matches(":hover,:focus-within"),l=c=>a?T(i,s?"current-hover":"current"):T(i,s&&c==="rest"?"row-active":c);if(e==="shadow")return a&&t===n?{element:"nav-current-indicator",owner:o,state:l}:!a&&t===o?{element:"nav-hover-indicator",owner:o,state:l}:void 0;if((e==="fill"||e==="stroke")&&S(t,".icon-area"))return{element:"nav-item-icon",owner:o,state:l};if(e==="outline"&&t===o||e==="text"&&S(t,'[part="menu-text"]'))return{element:o.matches("button")?"nav-item":"nav-link",owner:o,state:l}},qn=({element:t,source:e})=>{const n=S(t,".group-header"),r=n&&S(n,"esp-menu-group");if(!n||!r||!S(r,"esp-header"))return;const o=ft(n),a=(e==="fill"||e==="stroke")&&S(t,".group-icon");if(a){const u=n.querySelector(".group-toggle");return u?{element:"nav-group-icon",owner:u,state:f=>T(o,a.matches(":hover")?G(f)?"hover-focus":"hover":f)}:void 0}const i=S(t,".group-link, .group-toggle, [aria-current=page]");if(!i)return;const s=i.matches("[aria-current=page]"),l=(o==="panel"||o==="inline-panel")&&n.matches(":hover,:focus-within"),c=u=>s?T(o,l?"current-row-active":"current"):T(o,l&&u==="rest"?"row-active":u);if(e==="shape"&&t.matches(".indicator"))return{element:"nav-group-disclosure",owner:i,state:c};if(e==="text"&&S(t,".group-label-text"))return{element:"nav-group-label",owner:i,state:c};if(e==="outline"&&t===i)return{element:"nav-group-control",owner:i,state:c}},jn=({element:t,source:e})=>{const n=S(t,".drawer-brand .configured-brand");if(!n||!S(n,"esp-header"))return;const r=ft(n),o=n.matches("a[href]"),a=i=>T(r,o?i:"rest");if(e==="outline"&&t===n&&o)return{element:"drawer-brand-link",owner:n,state:a};if(e==="text"&&S(t,".brand-text"))return{element:"drawer-brand-text",owner:n,state:a,brandColor:St(n,"--_esp-menu-drawer-brand-color")}};function Wn(t){const e=dt(t),n=t==="inline",r=t==="full-screen",o=n?"layer2":"layer1",a=vt(t,{kind:"plain",anchor:!0}),i=vt(t,{kind:"plain",anchor:!1}),s=[!0,!1].flatMap(u=>{const f=u?"nav-link":"nav-item",d=u?a:i;return(n?V:[...V,"row-active"]).flatMap(v=>{const g=v==="row-active",x=!g&&K(v),k=!g&&G(v),A=x||k||g,y=u&&x?"linkHover":!n&&A?"headingsHover":"text",w=u&&x&&!n&&!r?be:!r&&A?"layer2":o,m=T(t,v),h={element:f,foreground:y,background:w,state:m,kind:"text",flags:e,navigation:d},E={...h,element:"nav-item-icon",kind:"graphic",background:"layer2",navigation:{...d,icon:!0}};if(!k)return[h,E];const C={...h,foreground:"link",kind:"ring"};return n&&x?[h,E,C,{...C,background:ve}]:[h,E,C]})}),l={element:"nav-link",foreground:"link",background:r?"layer1":"layer2",state:T(t,"current"),kind:"text",flags:e,navigation:vt(t,{kind:"plain",canBeCurrent:!0})},c={...l,element:"nav-item-icon",kind:"graphic",background:"layer2",navigation:{...l.navigation,icon:!0}};return s.push(l,c),n?s.push({element:"nav-hover-indicator",foreground:ve,background:"layer2",state:"hover",kind:"graphic",flags:e,navigation:{kind:"plain",depth:"top-level"}},{...l,element:"nav-current-indicator",kind:"graphic",flags:[...e,"headerPaint:standard"]}):s.push({...l,foreground:"headingsHover",state:T(t,"current-hover")},{...c,foreground:"headingsHover",state:T(t,"current-hover")}),s}function zn(t){const e=dt(t),n=vt(t,{kind:"group"}),r=i=>t==="full-screen"?"layer1":t==="inline"||i?"layer2":"layer1",o={element:"nav-group-label",foreground:"link",background:r(!1),state:T(t,"current"),kind:"text",flags:e,navigation:{...n,canBeCurrent:!0}},a=V.flatMap(i=>{const s=G(i),l=r(s||K(i)),c=T(t,i),u={foreground:"text",background:l,state:c,flags:e,navigation:n},f=[{...u,element:"nav-group-label",kind:"text"},{...u,element:"nav-group-disclosure",kind:"graphic"},{...u,element:"nav-group-icon",kind:"graphic",background:"layer2",navigation:{...n,icon:!0}}];return s&&f.push({...u,element:"nav-group-control",foreground:"link",kind:"ring"}),f});if(a.push(o),t==="inline-panel"||t==="panel"){const i=r(!0),s={foreground:"text",background:i,state:T(t,"row-active"),flags:e,navigation:n};a.push({...s,element:"nav-group-label",kind:"text"},{...s,element:"nav-group-disclosure",kind:"graphic"},{...o,background:i,state:T(t,"current-row-active")})}return a}var Xn={entriesByRole:{header:[...Fn.flatMap(t=>[...Wn(t),...zn(t)]),...V.flatMap(t=>{const e=T("full-screen",t),n=dt("full-screen"),r=G(t),o=K(t),a={element:"drawer-brand-text",foreground:"brand-color",background:o?be:"layer1",state:e,kind:"text",flags:[...n,"brandText",...o||r?["brandLink"]:[]]};return r?[a,{element:"drawer-brand-link",foreground:"link",background:"layer1",state:e,kind:"ring",flags:[...n,"brandLink"]}]:[a]})]},targets:{header:[Vn,qn,jn]}};function Kn(t,e){return t?.trim()||e?.trim()||""}var Tt={series1:"#000000",series2:"#E69F00",series3:"#56B4E9",series4:"#009E73",series5:"#F0E442",series6:"#0072B2",series7:"#D55E00",series8:"#CC79A7"},ye=["background","layer1","layer2","layer3","layer4","actionBackground","actionText","border","shadow","text","typeOverline","typeLabel","typeLead","typeCaption","dangerText","headings","headingsHover","link","linkHover","linkHoverBg","inputCaret","inputSelection","inputSelectionBg"],Yn=["primary","analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning","info"],Jn={surface:.99,raised1:.97,raised2:.9,raised3:.8,raised4:.72,accent:.5,muted:.45,text:.35,border:.3,ink:.25,shadow:.2},Zn={surface:.15,raised1:.2,raised2:.3,raised3:.4,raised4:.36,accent:.6,muted:.75,text:.85,border:.7,ink:.95,shadow:.6},we={background:{source:"primary",lightness:"surface"},layer1:{source:"primary",lightness:"raised1"},layer2:{source:"primary",lightness:"raised2"},layer3:{source:"primary",lightness:"raised3"},layer4:{source:"primary",lightness:"raised4"},actionBackground:{source:"primary",lightness:"muted"},actionText:{source:"primary",lightness:"ink"},border:{source:"primary",lightness:"border"},shadow:{source:"primary",lightness:"shadow"},text:{source:"primary",lightness:"text"},typeOverline:{source:"primary",lightness:"text"},typeLabel:{source:"primary",lightness:"text"},typeLead:{source:"primary",lightness:"text"},typeCaption:{source:"primary",lightness:"text"},dangerText:{source:"danger",lightness:"text"},headings:{source:"primary",lightness:"muted"},headingsHover:{source:"primary",lightness:"text"},link:{source:"complementary",lightness:"accent"},linkHover:{source:"complementary",lightness:"text"},linkHoverBg:{source:"triadic-left",lightness:"raised2"},inputCaret:{source:"triadic-right",lightness:"ink"},inputSelection:{source:"complementary",lightness:"text"},inputSelectionBg:{source:"triadic-left",lightness:"raised2"}},Qn={light:"muted",dark:"raised3"};function ke(t){return{...we,actionBackground:{source:"primary",lightness:Qn[t]}}}var tr=.4;function Pt(){const t={};for(const e of ye)t[e]={min:0,max:tr};return t}var er="system-ui, sans-serif",nr="monospace",xe={seedColor:"oklch(0.7 0.125 216)",fontBody:er,fontHeadings:"",fontBrand:"",fontMenu:"",fontMonospace:nr,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:Pt(),semanticMappings:{...we},explicitMappingTokens:[],anchors:{},roles:{},contexts:{},dataPalette:{...Tt},dataRamps:{}},rr={...xe,chroma:Pt(),semanticMappings:ke("light"),anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...Tt},dataRamps:{},lightness:{...Jn}},or={...xe,chroma:Pt(),semanticMappings:ke("dark"),anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...Tt},dataRamps:{},lightness:{...Zn}},Se=new WeakMap;Se.set(rr,new Set),Se.set(or,new Set);function ar(t){return`--esp-color-${t.replace(/([A-Z])/g,"-$1").replace(/(\d)/g,"-$1").toLowerCase()}`}function At(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}var yt=new Map([...ye.map(t=>[t,ar(t)]),...Yn.map(t=>[t,`--esp-color-${t}`])]),Ee=Object.freeze([...yt.keys()]),W="brand-color";function ot(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function Ce(t){return yt.get(t)}function j(t){return typeof t=="string"&&t.trim()!==""}function Re(t){return j(t)&&t===t.trim()}function ir(t){return t==="text"||t==="graphic"||t==="ring"}function sr(t){return Array.isArray(t)&&Array.from(t).every(j)}var Me={depth:t=>t==="top-level"||t==="nested",kind:t=>t==="button"||t==="plain"||t==="group",anchor:t=>typeof t=="boolean",canBeCurrent:t=>typeof t=="boolean",icon:t=>t===void 0||typeof t=="boolean"},cr={element:!0,foreground:!0,background:!0,state:!0,kind:!0,flags:!0,navigation:!0,indicator:!0,paintOpacity:!0};function lr(t){return At(t)&&Object.entries(t).every(([e,n])=>ot(Me,e)&&Me[e](n))}function ur(t,e,n){if(!At(t)||!Object.keys(t).every(r=>ot(cr,r))||!j(t.element)||!j(t.state)||!ir(t.kind)||!sr(t.flags))throw new TypeError(`${e} is not a paint entry.`);for(const r of["foreground","background"]){const o=t[r];if(!j(o)||!(yt.has(o)||ot(n,o)||r==="foreground"&&o===W))throw new TypeError(`${e} has an unknown ${r} paint identifier "${String(o)}".`)}if(t.paintOpacity!==void 0&&(typeof t.paintOpacity!="number"||!Number.isFinite(t.paintOpacity)||t.paintOpacity<0||t.paintOpacity>1))throw new TypeError(`${e} has an invalid paint opacity.`);if(t.navigation!==void 0&&!lr(t.navigation))throw new TypeError(`${e} has an invalid navigation predicate.`);if(t.indicator!==void 0&&(t.indicator!=="blurred-shadow"||t.kind==="text"))throw new TypeError(`${e} has an invalid indicator.`)}function fr(t,e=Pe){if(!At(t))throw new TypeError("Paint entries must be grouped by role.");for(const[n,r]of Object.entries(t)){if(!Re(n)||!Array.isArray(r))throw new TypeError(`Paint entries for role "${n}" must be an array on a nonempty role without outer whitespace.`);for(let o=0;o<r.length;o+=1)ur(r[o],`Paint entry for "${n}" at index ${o}`,e)}}function dr(t){const e=Object.create(null),n=Object.create(null),r=Object.create(null);for(const o of t)for(const[a,i]of Object.entries(o.derivations??{})){if(!j(a)||a===W||yt.has(a)||a in r)throw new TypeError(`Paint derivation "${a}" must have a unique identifier.`);r[a]=i}for(const o of t){fr(o.entriesByRole,r);for(const[a,i]of Object.entries(o.entriesByRole))(e[a]??=[]).push(...i);for(const[a,i]of Object.entries(o.targets))(n[a]??=[]).push(...i)}for(const o of Object.values(e))Object.freeze(o);for(const o of Object.values(n))Object.freeze(o);return{entriesByRole:Object.freeze(e),targets:Object.freeze(n),derivations:Object.freeze(r)}}var Ot=dr([Hn,Bn,Xn,In]),Te=Ot.entriesByRole,pr=Ot.targets,Pe=Ot.derivations;function hr(t,e,n=Te,{brandColor:r}={}){const o=ot(n,t)?n[t]:[],a=new Set(e.flags),i=o.filter(s=>{if(!s.flags.every(c=>a.has(c)))return!1;if(s.navigation===void 0)return!0;const l=Object.entries(s.navigation);return e.navigation.some(c=>l.every(([u,f])=>c[u]===f))});return Kn(r)?i:i.map(s=>s.foreground===W?{...s,foreground:"headings"}:s)}function gr(t,e,n=Pe){if(ot(n,t))return n[t](e);const r=e.readColor(t);return r?nt(r):null}function mr(t){return JSON.stringify([t.role,t.element,t.state,t.kind,t.foreground,t.background,t.indicator,t.paintOpacity??1])}function Ae(t){const e=new Map;for(const n of t){const r=mr(n);e.has(r)||e.set(r,n)}return e}function br(t,e){const n=Object.entries(e).flatMap(([a,i])=>i.map(s=>({role:a,...s}))),r=Ae(n),o=Ae(t);return{unlisted:[...o].filter(([a])=>!r.has(a)).map(([,a])=>a),unobserved:[...r].filter(([a])=>!o.has(a)).map(([,a])=>a)}}var O="http://www.w3.org/2000/svg",Oe={r:0,g:0,b:0,alpha:0},Nt={r:1,g:1,b:1,alpha:1};function vr(t){const e=[],n=[];function r(o){if(o.nodeType===Node.TEXT_NODE){o.textContent?.trim()&&n.push(o);return}if(o.nodeType===Node.ELEMENT_NODE){const a=o;if(a.matches("style, script, template, defs, symbol"))return;if(e.push(a),a.shadowRoot){r(a.shadowRoot);return}if(a.localName==="slot"&&a.namespaceURI!==O){const i=a.assignedNodes();if(i.length){i.forEach(r);return}}}o.childNodes.forEach(r)}return r(t),{elements:e,text:n}}function $(t,e){const n=[];for(let o=t;o;o=_(o)){const a=o.localName;if(n.unshift(o.id?`${a}#${o.id}`:a+[...o.classList].slice(0,2).map(i=>`.${i}`).join("")),o.id)break}const r=e?.data.trim().slice(0,70);return n.join(" > ")+(r?` "${r}"`:"")}function yr(t){const e=[t];for(const n of e)for(const r of n.querySelectorAll("*"))r.shadowRoot&&e.push(r.shadowRoot);return e}function wr(t,e){const n=new CSSStyleSheet;n.replaceSync("* { pointer-events: auto !important; }");const r=new CSSStyleSheet;r.replaceSync(":host, *, ::slotted(*) { pointer-events: auto !important; }");const o=[];try{for(const a of t){const i=[...a.adoptedStyleSheets];a.adoptedStyleSheets=[...i,tt(a)?r:n],o.push([a,i])}return e()}finally{for(const[a,i]of o)a.adoptedStyleSheets=i}}function z(t){return t.width<=0||t.height<=0?[]:[.5,.25,.75].flatMap(e=>[.5,.25,.75].map(n=>({x:t.left+e*t.width,y:t.top+n*t.height})))}function kr(t){const e=t.ownerDocument.createRange();return e.selectNodeContents(t),[...e.getClientRects()].flatMap(z)}function xr(t,e){for(let n=t;n&&n!==e.host;n=_(n))if(n.getRootNode()===e)return!0;return!1}function Ne(t,{x:e,y:n}){const r=[],o=new Set,a=i=>{if(o.has(i))return;o.add(i);const s=i.shadowRoot;s&&s.elementsFromPoint(e,n).filter(l=>xr(l,s)).forEach(a),r.push(i)};return t.elementsFromPoint(e,n).forEach(a),r}function wt(t,e){return Math.abs(t.alpha-e.alpha)<=.001&&Math.abs(t.r-e.r)<=.001&&Math.abs(t.g-e.g)<=.001&&Math.abs(t.b-e.b)<=.001}function Ie(t,e){return{...t,alpha:t.alpha*e}}function H(t){return t.trim().toLowerCase()==="transparent"?Oe:nt(t)}function J(t,e){if(H(e))return e;const n=t.ownerDocument,r=t.namespaceURI===O?n.createElementNS(O,"g"):n.createElement("span");if(r.style.cssText="display:none!important;visibility:hidden!important",r.style.setProperty("color",e,"important"),!r.style.color)return e;(t.shadowRoot??t).append(r);try{const o=P(r).color;return H(o)?o:(r.style.setProperty("color",`oklch(from ${o} l c h / alpha)`,"important"),P(r).color)}finally{r.remove()}}function P(t){return t.ownerDocument.defaultView.getComputedStyle(t)}function It(t){const e=P(t);return e.display!=="none"&&e.visibility==="visible"&&Sr(t)>0}function Sr(t){return Le(t).reduce((e,n)=>e*n.opacity,1)}function Lt(t,e){for(let n=e;n;n=_(n))if(n===t)return!0;return!1}function Er(t){let e=t;for(let n=_(e);n&&P(e).display==="contents";n=_(e))e=n;return e}function Cr(t,e){for(let n=t,r=_(n);r&&!n.matches(":popover-open, dialog:modal");n=r,r=_(n)){const{overflowX:o,overflowY:a}=P(r);if(o==="visible"&&a==="visible")continue;const i=r.getBoundingClientRect();if(o!=="visible"&&(e.x<i.left||e.x>=i.right)||a!=="visible"&&(e.y<i.top||e.y>=i.bottom))return!0}return!1}function Rr(t,e){function n(g,x){t.style.setProperty("left",`${g}px`,"important"),t.style.setProperty("top",`${x}px`,"important");const k=t.getBoundingClientRect();return{x:(k.left+k.right)/2,y:(k.top+k.bottom)/2}}const r=e.x-.5,o=e.y-.5,a=n(r,o);if(Math.abs(a.x-e.x)<.05&&Math.abs(a.y-e.y)<.05)return;const i=n(r+1,o),s=n(r,o+1),l=i.x-a.x,c=i.y-a.y,u=s.x-a.x,f=s.y-a.y,d=l*f-c*u;if(Math.abs(d)<1e-6)return;const p=e.x-a.x,v=e.y-a.y;n(r+(f*p-u*v)/d,o+(l*v-c*p)/d)}function Mr(t,e){const n=t.ownerDocument,r=n.createElement("span");r.style.cssText=["all:initial!important","display:block!important","width:1px!important","height:1px!important","position:fixed!important","z-index:auto!important","opacity:0!important","pointer-events:auto!important","visibility:visible!important"].join(";"),r.setAttribute("aria-hidden","true"),(t.shadowRoot??t).append(r);try{Rr(r,e);const o=Ne(n,e),a=o.indexOf(r);return a<0?void 0:{above:o.slice(0,a),below:o.slice(a+1).filter(i=>i!==t)}}finally{r.remove()}}function Le(t){const e=[];for(let n=t;n;n=_(n)){const r=Number(P(n).opacity);r<1&&e.unshift({element:n,opacity:r})}return e}function _e(t,e,n){const r=H(J(t,e));if(!r)throw new Error(`Cannot resolve ${n} "${e}" on ${$(t)}`);return r}function Tr(t,e){const n=P(t);if(n.visibility!=="visible"||e.some(o=>o.opacity===0))return null;const r=_e(t,n.backgroundColor,"background paint");return r.alpha===0?null:{element:t,color:r,sourceColor:r,groups:e}}function Pr(t,e,n){if("uncertainty"in e)throw new Error(e.uncertainty);const r=_e(t,e.rawColor,"overlapping paint");return{element:t,color:Ie(r,e.opacity),sourceColor:r,groups:[...n,...e.groups??[]]}}function Ar(t,e){return t.length===e.length&&t.every((n,r)=>n.element===e[r].element)}function _t(t,e,n=0){let r=e;for(let o=t.length-1;o>=0;o--){const a=t[o],i=a.groups[n];if(!i){r=ce(a.color,r);continue}let s=o;for(;t[s-1]?.groups[n]?.element===i.element;)s--;const l=_t(t.slice(s,o+1),Oe,n+1);r=ce(Ie(l,i.opacity),r),o=s}return r}function Or(t,e){const n=new Map,r=new WeakMap,o=new WeakMap;function a(l){const c=`${l.x},${l.y}`;let u=n.get(c);return u||(u=Ne(t,l),n.set(c,u)),u}function i(l){let c=o.get(l);return c||(c=Le(l),o.set(l,c)),c}function s(l){return r.has(l)||r.set(l,Tr(l,i(l))),r.get(l)??null}return function(c,u,f){const d=a(u);if(d.length===0)return;let p;function v(b){return b===u.svgRoot||b.namespaceURI!==O||b.localName!=="svg"?[]:(p??=new Set(d),e(b,u,p))}const g=Er(c),x=d.includes(g)?g:u.retarget&&d.includes(u.retarget)?u.retarget:void 0;if(u.svgRoot&&!x)return;const k=u.svgRoot??x??g,A=d.indexOf(k);let y,w;if(u.inside){if(Cr(c,u))return;const b=a(u.inside),R=b.indexOf(k);if(R<0)return;const kt=Mr(k,u);if(kt)({above:y,below:w}=kt);else{const Wt=new Set(b),xt=d.find(I=>!Wt.has(I)&&(s(I)||v(I).length));if(xt)throw new Error(`Cannot order outward paint against ${$(xt)}`);const Q=new Set(b.slice(0,R));y=d.filter(I=>Q.has(I)),w=d.filter(I=>I!==k&&!Q.has(I))}}else{if(A<0)return;y=d.slice(0,A),w=d.slice(A+(f?0:1))}const m=i(c),h=u.local,E=[...m,...h?.groups??[]],C=new Set(E.map(b=>b.element)),L=[];function N(b){return!b||b.color.alpha===0?!0:b.color.alpha===1&&b.groups.every(R=>C.has(R.element))?!1:(L.push(b),!0)}function M(b){const R=b.element??c;return b.requiresHit&&!d.includes(R)&&(!b.retarget||!d.includes(b.retarget))?null:Pr(R,b,i(R))}for(const b of y)if(!(Lt(b,k)||Lt(k,b)&&(u.svgRoot||f&&u.inside))){for(const R of v(b))if(!N(M(R)))return;if(!N(s(b)))return}for(const b of h?.above??[])if(!N(M(b)))return;const F=[];function X(b){return!b||b.color.alpha===0?!0:(F.push(b),b.color.alpha<1||b.groups.length>0)}let ct=!0,lt=!!h?.opaqueInk;for(const b of h?.below??[]){const R=M(b);if(!(!R||R.color.alpha===0)&&!(lt&&h?.opaqueInk&&R.color.alpha===1&&wt(h.opaqueInk,R.color)&&Ar(E,R.groups))&&(lt=!1,ct=X(R),!ct))break}if(ct){for(const b of w)if(!(u.svgRoot&&b!==k&&Lt(k,b))&&(v(b).some(R=>!X(M(R)))||!X(s(b))))break}const B=F[0];return{color:_t([...L,...F],Nt),sourceColor:B?.sourceColor??Nt,sourceElement:B?.element,paintForeground:b=>{const R={element:c,color:b,sourceColor:b,groups:E};return _t([...L,R,...F],Nt)}}}}function $e(t,e){let n=0,r=0;const o=[];for(let a=0;a<t.length;a++){const i=t[a];i==="("&&n++,i===")"&&n--,n===0&&e.test(i)&&(a>r&&o.push(t.slice(r,a).trim()),r=a+1)}return r<t.length&&o.push(t.slice(r).trim()),o}function $t(t){const e=parseFloat(t.outlineWidth),n=t.outlineStyle==="none"||t.outlineStyle==="hidden"||!(e>0)?void 0:{color:t.outlineColor,style:t.outlineStyle,width:e,offset:parseFloat(t.outlineOffset)},r=$e(t.boxShadow,/,/).flatMap(o=>{const a=$e(o,/\s/),i=a.filter(d=>/^[-+.\d]+px$/.test(d)),[s,l,c=0,u=0]=i.map(parseFloat),f=a.find(d=>d!=="inset"&&!i.includes(d));return f&&s!==void 0&&l!==void 0?[{color:f,x:s,y:l,blur:c,spread:u,value:o,inset:a.includes("inset")}]:[]});return{outline:n,shadow:r}}var Nr=/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\\.|:(?:focus-visible|focus-within|focus|hover)(?![\w-])/g;function Dt(t,e){return t.replace(Nr,n=>!n.startsWith(":")||e&&n===":hover"?n:`:not(:where(*)):is(${n})`)}function Ir(t){const e=[],n=new Set;function r(a){for(const i of a){if("selectorText"in i&&typeof i.selectorText=="string"){const s=i.selectorText;Dt(s,!1)!==s&&e.push([i,s])}if("cssRules"in i&&r(i.cssRules),"styleSheet"in i){const s=i.styleSheet;s&&o(s)}}}function o(a){if(n.has(a))return;n.add(a);let i;try{i=a.cssRules}catch{return}r(i)}for(const a of t)for(const i of[...a.styleSheets,...a.adoptedStyleSheets])o(i);return e}function Bt(t,e){return e?.color===t.color&&e.style===t.style&&e.width===t.width&&e.offset===t.offset}var De=new WeakMap,Lr=Ee.map(Ce).filter(t=>t!==void 0);function Be(t,e,n){let r=null,o=null;for(let a=t;a&&!(r&&o);a=_(a))r??=a.getAttribute("scheme")||null,o??=a.getAttribute("context")||null;return JSON.stringify([n,e.colorScheme,r,o,...Lr.map(a=>e.getPropertyValue(a))])}function _r(t,e){const n=t[0]?.ownerDocument.defaultView,r=[n?.matchMedia("(prefers-color-scheme: dark)").matches,n?.matchMedia("(forced-colors: active)").matches].join(":"),o=t.flatMap(c=>{const u=P(c),f=$t(u),d=c.matches(":focus-within, :focus-visible"),p=c.matches(":hover"),v=p?"hover":"rest";let g=De.get(c);if(d||(g||(g={},De.set(c,g)),g[v]={bands:f,environment:Be(c,u,r)}),!f.outline&&f.shadow.length===0)return[];const x=d?g?.[v]:void 0,k=x&&x.environment===Be(c,u,r)?x.bands:void 0;return[{element:c,bands:f,focus:d,hover:p,realNoFocus:k}]}),a=new Map,i=new Map,s=o.some(({focus:c})=>c),l=o.some(({hover:c})=>c);if(s||l){const c=Ir(e),u=[],f=new CSSStyleSheet;f.replaceSync("* { transition: none !important; }");try{for(const d of e){const p=[...d.adoptedStyleSheets];d.adoptedStyleSheets=[...p,f],u.push([d,p])}if(s){for(const[d,p]of c){const v=Dt(p,!0);v!==p&&(d.selectorText=v)}for(const{element:d,focus:p}of o)p&&i.set(d,$t(P(d)))}if(l){for(const[d,p]of c)d.selectorText=Dt(p,!1);for(const{element:d,hover:p}of o)p&&a.set(d,$t(P(d)))}}finally{for(const[d,p]of c)d.selectorText!==p&&(d.selectorText=p);for(const{element:d}of o)P(d).boxShadow;for(const[d,p]of u)d.adoptedStyleSheets=p}}return new Map(o.map(({element:c,bands:u,hover:f,focus:d,realNoFocus:p})=>{const v=a.get(c)??i.get(c),g=i.get(c),x=[...c.getClientRects()],k=u.outline,A=u.shadow.map(m=>({source:"shadow",shadow:m}));k&&A.unshift({source:"outline",outline:k});const y=[],w=k&&d&&(!Bt(k,g?.outline)||(p?!Bt(k,p.outline):k.style==="auto"&&c.matches(":focus-visible")));k&&(w||f&&!Bt(k,v?.outline))&&y.push({source:"outline",kind:w?"ring":"graphic",color:k.color,blur:0,points:x.flatMap(m=>Xe(c,m,A,0))});for(const[m,h]of u.shadow.entries()){const E=d&&(!g?.shadow.some(({value:M})=>M===h.value)||p&&!p.shadow.some(({value:M})=>M===h.value)),C=f&&!v?.shadow.some(({value:M})=>M===h.value);if(!E&&!C&&!(h.inset&&h.blur===0))continue;const L=k?m+1:m,N=x.flatMap(M=>Xe(c,M,A,L));y.push({source:"shadow",kind:E?"ring":"graphic",color:h.color,blur:h.blur,points:N})}return[c,y]}))}var Ge=["top","bottom","left","right"];function Ue(t,e,n,r){const o=t.left+r*t.width,a=t.top+r*t.height;switch(e){case"top":return{x:o,y:t.top-n};case"bottom":return{x:o,y:t.bottom+n};case"left":return{x:t.left-n,y:a};case"right":return{x:t.right+n,y:a}}}function Gt(t,e,n){return(e-t[n])*(n==="right"||n==="bottom"?1:-1)}function $r(t,e){const n=P(t),r=i=>parseFloat(n.getPropertyValue(`border-${i}-width`)),o=r("left"),a=r("top");return new DOMRect(e.left+o,e.top+a,e.width-o-r("right"),e.height-a-r("bottom"))}function Ut(t,e){const n=e.inset?-e.spread:e.spread;return new DOMRect(t.left+e.x-n,t.top+e.y-n,Math.max(0,t.width+2*n),Math.max(0,t.height+2*n))}function He(t,e,n,r){if(t.source==="outline"){const{offset:f,width:d}=t.outline;return[f,f+d]}const{shadow:o}=t;if(o.blur>0)return;const a=o.inset?n:e,i=Ut(a,o),s=Gt(e,i[r],r);if(!o.inset)return s>0?[0,s]:void 0;const l=Gt(e,a[r],r),c=r==="top"||r==="bottom"?a.height:a.width,u=i.width&&i.height?Math.max(s,l-c):l-c;return u<l?[u,l]:void 0}function Dr(t,e,n,r,o){const a=He(t[e],n,r,o);if(!a)return[];const[i,s]=a,l=[0,...t.flatMap(u=>He(u,n,r,o)??[])].filter(u=>u>i&&u<s),c=[...new Set([i,...l,s])].sort((u,f)=>u-f);return c.slice(1).map((u,f)=>(c[f]+u)/2)}function at(t,e,n=0){return e.x>t.left-n&&e.x<t.right+n&&e.y>t.top-n&&e.y<t.bottom+n}function Fe(t,e,n,r){const o=P(t),a=(d,p)=>/^[-+.\d]+(?:px|%)?$/.test(d)?parseFloat(d)*(d.endsWith("%")?p/100:1):NaN,[i,s,l,c]=[o.borderTopLeftRadius,o.borderTopRightRadius,o.borderBottomRightRadius,o.borderBottomLeftRadius].map(d=>{const[p,v=p]=d.split(/\s+/);return[a(p,e.width),a(v,e.height)]}),u=Math.min(1,e.width/(i[0]+s[0]),e.width/(c[0]+l[0]),e.height/(i[1]+c[1]),e.height/(s[1]+l[1])),f=[i,s,l,c];return{clip:n,spread:Ut(n,r),cornerX:u*Math.max(...f.map(([d])=>d)),cornerY:u*Math.max(...f.map(([,d])=>d))}}function Ve(t,e,n,r){return Gt(t,n.spread[r],r)+ue*(e.inset?-1:1)}function qe(t,e,n,r){if(at(e.clip,r)!==t.inset)return!1;const o=t.blur/2*mt,{spread:a,cornerX:i,cornerY:s}=e,l=n==="top"||n==="bottom",c=l?r.x:r.y,u=l?a.left:a.top,f=l?a.right:a.bottom,d=l?i:s;return(l?a.height:a.width)>=o&&c-u>=o+d&&f-c>=o+d}function je(t){return t.spread===0&&fe(t.blur)}function We(t){for(let e=t;e;e=_(e)){const{transform:n,rotate:r,scale:o}=P(e);if(r&&r!=="none"||o&&o!=="none")return!1;if(n==="none")continue;const a=new DOMMatrixReadOnly(n);if(a.m11!==1||a.m22!==1||a.m33!==1||a.m44!==1||a.m12||a.m13||a.m14||a.m21||a.m23||a.m24||a.m31||a.m32||a.m34||a.m43)return!1}return!0}function Br(t,e,n,r,o,a,i){if(e.source==="outline"){const{color:x,offset:k,width:A,style:y}=e.outline;return i<=k||i>=k+A||H(x)?.alpha===0?void 0:y!=="solid"?{ambiguous:"non-solid outline"}:{paint:{rawColor:x,opacity:1},opaque:H(x)?.alpha===1}}const{shadow:s}=e,{color:l,blur:c,inset:u}=s,f=u?r:n;if(at(f,o)!==u)return;const d=H(l)?.alpha;if(d===0)return;if(c===0)return at(Ut(f,s),o)===u?void 0:{paint:{rawColor:l,opacity:1},opaque:d===1};const p=Fe(t,n,f,s),v=Ve(n,s,p,a);if(je(s)&&Math.abs(i-v)<1e-6&&qe(s,p,a,o)&&We(t))return{paint:{rawColor:l,opacity:pe({alpha:1,blur:c})},opaque:!1};const g=c/2*mt*(u?-1:1);if(at(p.spread,o,g)!==u)return{ambiguous:"blurred shadow away from its spread boundary"}}function ze(t,e,n,r,o,a,i,s){return[.5,.3,.7].flatMap(l=>{const c={...Ue(e,a,i,l),inside:i>=0?Ue(e,a,-.5,l):void 0};if(s&&!s(c))return[];if(r.length===1)return[c];const u=g=>Br(t,g,e,n,c,a,i),f=r.slice(0,o).map(u);if(f.some(g=>g&&"opaque"in g&&g.opaque))return[];const d=[],p=[];function v(g,x){if(!x)return!0;if("ambiguous"in x)throw new Error(`Cannot resolve overlapping indicator paint at ${$(t)}: ${x.ambiguous}`);return g.push(x.paint),!x.opaque}for(const g of f)v(d,g);for(const g of r.slice(o+1))if(!v(p,u(g)))break;return[{...c,local:{above:d,below:p}}]})}function Xe(t,e,n,r){if(e.width<=0||e.height<=0)return[];const o=n[r],a=n.some(f=>f.source==="shadow"&&f.shadow.inset)?$r(t,e):e;if(o.source!=="shadow"||o.shadow.blur===0){const f=o.source==="shadow"&&o.shadow.inset?d=>at(a,d):void 0;return Ge.flatMap(d=>Dr(n,r,e,a,d).flatMap(p=>ze(t,e,a,n,r,d,p,f)))}const{shadow:i}=o,s=$(t);if(!je(i))throw new Error(`Unsupported shadow indicator geometry at ${s}: ${i.blur}px blur, ${i.spread}px spread. Expected 3\u20134px blur with zero spread.`);if(!We(t))throw new Error(`Unsupported shadow indicator geometry at ${s}: transformed spread edge.`);const l=Fe(t,e,i.inset?a:e,i);let c=!1;const u=Ge.flatMap(f=>ze(t,e,a,n,r,f,Ve(e,i,l,f),d=>{const p=qe(i,l,f,d);return c||=p,p}));if(!c)throw new Error(`Unsupported shadow indicator geometry at ${s}: no straight spread edge with enough clearance.`);return u}var Ht=new Set(["path","circle","ellipse","rect","line","polygon","polyline"]),Gr=new Set([...Ht,"symbol","g","svg","defs","use"]),Ke=["color","fill","fill-opacity","stroke","stroke-opacity","stroke-width","visibility"],Ye=new Set([...Ke,"display","opacity","d","x","y","x1","x2","y1","y2","points","width","height","cx","cy","r","rx","ry","viewBox","preserveAspectRatio","transform","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","fill-rule","paint-order","vector-effect","overflow"]),Je=new WeakMap;function Ft(t){return t.href.baseVal||null}function Ze(t){const e=Ft(t)?.trim();if(!e||e.startsWith("#"))return;const n=new URL(e,t.baseURI);if(!n.hash)return;const r=decodeURIComponent(n.hash.slice(1));return n.hash="",{url:n,id:r}}function it(t){return t.namespaceURI===O&&t.localName==="use"}async function Ur(t){const e=new Map;for(const r of t){if(!it(r))continue;let o;try{o=Ze(r)}catch{continue}if(!o||e.has(o.url.href)||o.url.origin!==r.ownerDocument.location?.origin)continue;const{url:a}=o;if(Vt(a,r.ownerDocument))continue;let i=Je.get(r.ownerDocument);i||(i=new Map,Je.set(r.ownerDocument,i));let s=i.get(a.href);if(!s){const l=i;s=Hr(a).then(c=>(c instanceof Error&&l.delete(a.href),c)),l.set(a.href,s)}e.set(a.href,s)}const n=await Promise.all([...e].map(async([r,o])=>[r,await o]));return new Map(n)}function Vt(t,e){const n=new URL(e.URL);return n.hash="",t.href===n.href}async function Hr(t){try{const e=await fetch(t,{mode:"same-origin"});if(!e.ok)throw new Error(`SVG sprite returned HTTP ${e.status}`);const n=new DOMParser().parseFromString(await e.text(),"image/svg+xml");if(n.documentElement.namespaceURI!==O)throw new Error("Response is not an SVG sprite");return n}catch(e){return e instanceof Error?e:new Error(String(e))}}function Fr(t,e){const n=t.getBoundingClientRect();if(n.width===0&&n.height===0)return[];const r=new DOMRect(n.x-(n.width?0:e/2),n.y-(n.height?0:e/2),n.width||e,n.height||e),o=z(r);if("getTotalLength"in t&&"getScreenCTM"in t){const a=t,i=a.getScreenCTM();if(i){const s=a.getTotalLength();for(let l=0;l<=16;l++){const c=a.getPointAtLength(s*l/16),u=new DOMPoint(c.x,c.y).matrixTransform(i);o.push({x:u.x,y:u.y})}}}return o}function Vr(t,e,n){const r=[];if(t.visibility!=="visible"||t.display==="none")return r;t.fill!=="none"&&n!=="line"&&r.push({source:"fill",color:t.fill,opacity:Number(t.fillOpacity),points:e}),t.stroke!=="none"&&parseFloat(t.strokeWidth)>0&&r.push({source:"stroke",color:t.stroke,opacity:Number(t.strokeOpacity),points:e});const a=[...t.getPropertyValue("paint-order").split(/\s+/),"fill","stroke"];return r.sort((i,s)=>a.indexOf(i.source)-a.indexOf(s.source))}function qr(t,e){const n=t.getScreenCTM()?.inverse();return n?({x:r,y:o})=>{const a=new DOMPoint(r,o).matrixTransform(n);return e==="fill"?t.isPointInFill(a):t.isPointInStroke(a)}:()=>!1}function jr(t,e){const n=Ft(t)?.trim();if(!n)throw new Error("SVG use has no href");let r,o;const a=Ze(t);if(n.startsWith("#")||a&&Vt(a.url,t.ownerDocument)){const s=t.getRootNode();r=tt(s)?s:t.ownerDocument,o=a?.id??decodeURIComponent(n.slice(1))}else{if(!a)throw new Error("SVG use does not identify a sprite fragment");const s=e.get(a.url.href);if(s instanceof Error)throw s;if(!s)throw new Error("SVG use requires a readable same-origin sprite");if(s.querySelector("style"))throw new Error("External SVG sprite styles cannot be inspected in its rendered instance");r=s,o=a.id}const i=r.getElementById(o);if(!i||i.namespaceURI!==O)throw new Error(`SVG paint target #${o} was not found`);return{target:i,scope:r}}function Z(t,e){return(t.ownerDocument.defaultView&&P(t).getPropertyValue(e)||t.style.getPropertyValue(e)||t.getAttribute(e)||"").trim()}function st(t,e){const n=Z(t,e);return n==="none"?"":n}function Qe(t){if(st(t,"mask-image")||st(t,"mask"))throw new Error(`Unsupported SVG sprite mask at ${$(t)}`)}function tn(t,e){const n=st(t,"clip-path");if(!n)return;const r=n.match(/^url\((?:"([^"]+)"|'([^']+)'|([^)]*))\)$/),o=(r?.[1]??r?.[2]??r?.[3])?.trim();let a;if(o?.startsWith("#"))a=o.slice(1);else if(o){const d=new URL(o,t.baseURI),p=d.hash.slice(1);d.hash="",Vt(d,t.ownerDocument)&&(a=p)}const i=a&&e.getElementById(decodeURIComponent(a)),s=i&&i.firstElementChild,l=i&&i.getAttribute("clipPathUnits"),c=()=>new Error(`Unsupported SVG sprite clip-path "${n}" at ${$(t)}`);if(!i||i.namespaceURI!==O||i.localName!=="clipPath"||l!==null&&l!=="userSpaceOnUse"||i.children.length!==1||!s||s.namespaceURI!==O||s.localName!=="rect")throw c();const u=s;for(const d of[i,u])if(["transform","translate","rotate","scale","clip-path","mask-image","mask"].some(p=>st(d,p))||Z(d,"display")==="none"||Z(d,"visibility")==="hidden")throw c();function f(d){const p=Z(u,d);if(!p||p==="auto")return 0;if(!/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:px)?$/.test(p))throw c();return parseFloat(p)}if(f("rx")!==0||f("ry")!==0)throw c();return{x:f("x"),y:f("y"),width:f("width"),height:f("height")}}function en(t,e){if(!t)return{bounds:new DOMRect,contains:()=>!1};const n=t.inverse(),r=[[e.x,e.y],[e.x+e.width,e.y],[e.x,e.y+e.height],[e.x+e.width,e.y+e.height]].map(([l,c])=>new DOMPoint(l,c).matrixTransform(t)),o=Math.min(...r.map(({x:l})=>l)),a=Math.min(...r.map(({y:l})=>l)),i=Math.max(...r.map(({x:l})=>l)),s=Math.max(...r.map(({y:l})=>l));return{bounds:new DOMRect(o,a,i-o,s-a),contains(l){const{x:c,y:u}=new DOMPoint(l.x,l.y).matrixTransform(n);return c>=e.x&&c<e.x+e.width&&u>=e.y&&u<e.y+e.height}}}function nn(t,e,n=0,r=0){const o=Math.max(t.left-n,...e.map(({bounds:l})=>l.left)),a=Math.max(t.top-r,...e.map(({bounds:l})=>l.top)),i=Math.min(t.right+n,...e.map(({bounds:l})=>l.right)),s=Math.min(t.bottom+r,...e.map(({bounds:l})=>l.bottom));return i<=o||s<=a?[]:z(new DOMRect(o,a,i-o,s-a))}function Wr(t,e,n,r){if(!e.length)return[];const o=n&&!r?t.getScreenCTM():null,a=n/2,i=a*(o?Math.hypot(o.a,o.c):1),s=a*(o?Math.hypot(o.b,o.d):1);return nn(t.getBoundingClientRect(),e,i,s)}function zr(t){const e=t.getRootNode(),n=tn(t,tt(e)?e:t.ownerDocument);if(!n)return;function r(o){const a=Z(t,o);if(!a||a==="auto")return 0;if(!/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:px)?$/.test(a))throw new Error(`Unsupported SVG use clip with ${o}="${a}" at ${$(t)}`);return parseFloat(a)}return en(t.getScreenCTM()?.translate(r("x"),r("y"))??null,n)}function qt(t,e,n,r,o){if(t.namespaceURI!==O||!Gr.has(t.localName))return;if(r.has(t))throw new Error("Circular SVG use reference");const a=t.localName==="symbol"?"svg":t.localName==="use"?"g":t.localName,i=n.createElementNS(O,a);if(t.localName!=="defs"){Qe(t);const l=tn(t,e);l&&o.set(i,l)}for(const l of["id","class",...Ye]){const c=t.getAttribute(l);c!==null&&i.setAttribute(l,c)}const s=t.style;for(const l of Ye){const c=s.getPropertyValue(l);c&&i.style.setProperty(l,c,s.getPropertyPriority(l))}if(t.localName==="use"){const l=Ft(t),c=l?.startsWith("#")?e.getElementById(decodeURIComponent(l.slice(1))):null;if(!c)throw new Error("Nested SVG use requires a local sprite fragment");const u=qt(c,e,n,new Set([...r,t]),o);return u&&(rn(i,u,f=>s.getPropertyValue(f)||t.getAttribute(f)),u.parentElement||i.append(u)),i}for(const l of t.children){const c=qt(l,e,n,r,o);c&&i.append(c)}return i}function rn(t,e,n){const r=(i,s)=>{const l=n(i)?.trim();return!l||l==="auto"?s:Number.isFinite(Number(l))?`${l}px`:l},o=r("x","0px"),a=r("y","0px");if(e.localName==="svg"){e.style.setProperty("x",o),e.style.setProperty("y",a);for(const i of["width","height"]){const s=e.getAttribute(i)||"100%";e.style.setProperty(i,r(i,s))}}else{const i=t.ownerDocument.createElementNS(O,"g");i.style.translate=`${o} ${a}`,t.append(i),i.append(e)}}function Xr(t,e){const n=t.ownerSVGElement;if(!n||!t.parentElement||!z(n.getBoundingClientRect()).length)return;const{target:r,scope:o}=jr(t,e),a=new WeakMap,i=qt(r,o,t.ownerDocument,new Set,a);if(!i)return;const s=P(t),l=t.ownerDocument.createElementNS(O,"g");l.style.cssText="opacity:0!important;pointer-events:none!important";for(const f of[...Ke,"transform","transform-origin","transform-box"])l.style.setProperty(f,s.getPropertyValue(f));rn(l,i,f=>s.getPropertyValue(f)),i.parentElement||l.append(i);const c=t.getBoundingClientRect(),u={root:i,wrapper:l,retarget:c.width||c.height?n:void 0,clips:a};u.expandingEffect=!!st(t,"filter");try{if(u.liveClip=zr(t),Qe(t),u.expandingEffect||!["","normal"].includes(Z(t,"mix-blend-mode")))throw new Error(`Unsupported SVG use filter or blend at ${$(t)}`)}catch(f){u.uncertainty=f instanceof Error?f.message:String(f)}return u}function Kr(t,e){const n=new Map,r=new Map,o=new Map,a=new Map,i=new Set;for(const c of t.querySelectorAll("use"))if(!(!it(c)||c.closest("defs, symbol, foreignObject")||!It(c)))try{const u=Xr(c,e);if(!u)continue;a.set(c,u),i.add(u.wrapper)}catch(u){o.set(c,u instanceof Error?u.message:String(u))}const s=[];function l(c,u,f,d,p=[]){if(i.has(c)||c.namespaceURI!==O||c.matches("defs, symbol, foreignObject"))return;const v=P(c),g=Number(v.opacity);if(v.display==="none"||g===0)return;if(it(c)&&!f){const w=c,m=a.get(w),h=o.get(w)??(m?.expandingEffect?m.uncertainty:void 0);if(h){const E=m?.expandingEffect&&w.ownerSVGElement?w.ownerSVGElement.getBoundingClientRect():w.getBoundingClientRect(),C=w.ownerSVGElement??void 0,L=m?.liveClip;s.push({points:L?nn(E,[L]):z(E),layer:{element:w,uncertainty:`${$(w)}: ${h}`,requiresHit:!0,retarget:C},retarget:C,hit:N=>N.x>=E.left&&N.x<E.right&&N.y>=E.top&&N.y<E.bottom&&(!L||L.contains(N))})}else m&&l(m.root,[],w,m.retarget,m.liveClip?[m.liveClip]:[]);return}const x=f&&a.get(f),k=x&&x.clips.get(c),A=k?[...p,en(c.getScreenCTM(),k)]:p,y=f&&g<1?[...u,{element:c,opacity:g}]:u;if(Ht.has(c.localName)){const w=c,m=parseFloat(v.strokeWidth)||0,h=[...Fr(w,m),...Wr(w,A,v.stroke==="none"?0:m,v.getPropertyValue("vector-effect")==="non-scaling-stroke")];for(const E of Vr(v,h,c.localName)){const C=H(J(c,E.color));if(E.opacity===0||C?.alpha===0)continue;const L=qr(w,E.source),N=x&&x.uncertainty;s.push({paint:N?void 0:E,points:h,layer:{element:f??c,...N?{uncertainty:N}:{rawColor:E.color,opacity:E.opacity},groups:y,requiresHit:!0,retarget:d},opaqueInk:!N&&E.opacity===1&&C?.alpha===1?C:void 0,retarget:d,projectedOwner:f,hit:M=>A.every(F=>F.contains(M))&&L(M)})}}for(const w of c.children)l(w,y,f,d,A)}try{for(const[c,{wrapper:u}]of a)c.after(u);l(t,[]);for(const[c,{paint:u,layer:f,hit:d,points:p,retarget:v,opaqueInk:g}]of s.entries()){const x=f.element,k=p.filter(d).map(m=>{const h=[],E=[];for(let C=s.length-1;C>=0;C--)C===c||!s[C].hit(m)||(C>c?h.push(s[C].layer):u&&E.push(s[C].layer));return{...m,retarget:v,svgRoot:t,local:{above:h,below:E,groups:f.groups,opaqueInk:g}}});if("uncertainty"in f){const m=r.get(x)??[];m.push({message:f.uncertainty,points:k}),r.set(x,m);continue}if(!u)continue;const A=(f.groups??[]).reduce((m,h)=>m*h.opacity,u.opacity),y=n.get(x),w={...u,opacity:A,primitiveOpacity:u.opacity,points:k};Array.isArray(y)?y.push(w):n.set(x,[w])}return{samples:n,refusals:r,layersAt(c,u){const f=s.filter(({layer:p})=>u.has(p.element)||!!(p.retarget&&u.has(p.retarget))),d=new Set(f.flatMap(({projectedOwner:p})=>p?[p]:[]));try{for(const p of d)p.after(a.get(p).wrapper);return f.reverse().flatMap(({hit:p,layer:v})=>p(c)?[v]:[])}finally{for(const p of d)a.get(p).wrapper.remove()}}}}finally{for(const{wrapper:c}of a.values())c.remove()}}function jt(t){let e;for(let n=t.parentElement;n?.namespaceURI===O&&n.localName!=="foreignObject";n=n.parentElement)n.localName==="svg"&&(e=n);return e}function Yr(t){const e=new WeakMap;function n(r){let o=e.get(r);return o||(o=Kr(r,t),e.set(r,o)),o}return{paints(r){if(r.namespaceURI!==O||!it(r)&&!Ht.has(r.localName))return[];const o=jt(r);return o?n(o).samples.get(r)??[]:[]},refusals(r){if(!it(r))return[];const o=jt(r);return o?n(o).refusals.get(r)??[]:[]},layersAt(r,o,a){return r.namespaceURI!==O||r.localName!=="svg"||jt(r)?[]:n(r).layersAt(o,a)}}}function Jr(t){const e=t.matches(":hover"),n=t.matches(":focus-visible");return e?n?"hover-focus":"hover":n?"focus":"rest"}function Zr(t,e){const n=e.flatMap(i=>{const s=i(t);return s?[s]:[]});if(n.length===0)throw new Error(`Missing ${t.kind} target for ${t.source}`);if(n.length>1)throw new Error(`Ambiguous ${t.kind} target: ${n.map(({element:i})=>i).join(", ")}`);const[r]=n;if(!j(r.element)||!r.owner?.isConnected)throw new Error("Paint target requires an element identifier and an attached interaction owner");const o=Jr(r.owner),a=r.state?.(o)??o;if(!j(a))throw new Error("Paint target returned an empty state");return{attribution:r,state:a}}function Qr(t,e){const n=P(t);let r,o=null;for(let i=t;i;i=_(i)){o??=i.getAttribute("context")?.trim()||null;const s=i.getAttribute("scheme");if((s==="light"||s==="dark")&&(r??=s),o&&r)break}const a=i=>{const s=n.getPropertyValue(i).trim();if(s)return CSS.supports("color",s)?J(t,s):s};return{scheme:r??(n.colorScheme==="dark"?"dark":"light"),context:o,readProperty:a,readColor(i){if(i===W)return e&&J(t,e);const s=Ce(i);return s?a(s):void 0}}}function on(t,e,n,r,o){const a=n==="foreground",i=a?r.foregroundAliases:r.backgroundAliases,s=a?r.foregroundDerivations:r.backgroundDerivations,l=a?r.brandColor:void 0;let c=o.get(e);c||(c=new Map,o.set(e,c));const u=Qr(e,l),f=g=>{const x=g===W?`${g}:${l}`:g;c.has(x)||c.set(x,gr(g,u));const k=c.get(x);return k!=null&&wt(k,t)};if(l&&f(W))return W;const p=[...new Set([...Ee,...s??[]])].filter(g=>!i?.includes(g)&&f(g));if(p.length===1)return p[0];const v=JSON.stringify(t);throw new Error(p.length===0?`Unmatched ${n} ${v}`:`Ambiguous ${n} ${v}: ${p.join(", ")}`)}function to(t,e){return t.namespaceURI===O||t.textContent?.trim()||e.clipPath==="none"&&e.maskImage==="none"?!1:H(J(t,e.backgroundColor))?.alpha!==0}async function eo(t,e){if(!Re(e?.role))throw new TypeError("observePaint requires a nonempty role without surrounding whitespace.");if(!t.isConnected||!t.ownerDocument.defaultView)throw new TypeError("observePaint requires an attached browser surface.");const{role:n}=e,r=[...pr[n]??[],...e.extraTargets??[]],{elements:o,text:a}=vr(t),i=yr(t.ownerDocument),s=(tt(t)?t.host:t).getBoundingClientRect(),l=new Set(o),c=i.flatMap(y=>[...y.querySelectorAll('svg use[href]:not([href^="#"])')].filter(w=>{if(l.has(w))return!1;const m=w.getBoundingClientRect();return m.right>s.left&&m.left<s.right&&m.bottom>s.top&&m.top<s.bottom})),u=Yr(await Ur([...o,...c])),f=o.filter(It),d=_r(f,i),p=new Set,v=[],g=[];for(const y of a){const w=_(y);if(!w||!It(w))continue;const m=kr(y);if(!m.length)continue;const h=P(w),E=h.getPropertyValue("-webkit-text-fill-color")||h.color;v.push({candidate:{element:w,text:y,kind:"text",source:"text"},rawColor:E,coverage:1,points:m})}for(const y of f){const w=P(y),m=to(y,w);m&&w.maskImage!=="none"?p.add(`Unsupported CSS shape mask at ${$(y)}`):m&&v.push({candidate:{element:y,kind:"graphic",source:"shape"},rawColor:w.backgroundColor,coverage:1,points:[...y.getClientRects()].flatMap(z)});for(const h of d.get(y)??[])v.push({candidate:{element:y,kind:h.kind,source:h.source,indicator:h.blur>0?"blurred-shadow":void 0},rawColor:h.color,coverage:1,blur:h.blur,points:h.points});try{for(const h of u.refusals(y))g.push({element:y,...h});for(const h of u.paints(y))v.push({candidate:{element:y,kind:"graphic",source:h.source},rawColor:h.color,coverage:h.opacity,primitiveOpacity:h.primitiveOpacity,points:h.points})}catch(h){g.push({element:y,message:h instanceof Error?h.message:String(h),points:[...y.getClientRects()].flatMap(z)})}}const x=v.map(y=>{try{return{sample:y,match:Zr(y.candidate,r)}}catch(w){return{sample:y,error:w}}}),k=new WeakMap,A=wr(i,()=>{const y=[],w=Or(t.ownerDocument,u.layersAt);for(const{element:m,message:h,points:E}of g)try{E.some(C=>w(m,C,!0))&&p.add(`${$(m)}: ${h}`)}catch(C){p.add(`${$(m)}: ${C instanceof Error?C.message:String(C)}`)}for(const{sample:m,match:h,error:E}of x){const{candidate:C,rawColor:L,points:N}=m,{element:M,kind:F,source:X,indicator:ct}=C,lt=$(M,C.text);try{const B=[];for(const I of N){const ut=w(M,I,X!=="shape");ut&&B.push(ut)}if(!B.length)continue;const b=H(J(M,L));if(!b)throw new Error(`Cannot resolve ${X} paint "${L}"`);if(!h)throw E;const{attribution:R,state:kt}=h,Wt=on(b,M,"foreground",R,k),xt=pe({alpha:b.alpha*(m.primitiveOpacity??m.coverage),blur:m.blur??0}),Q=[];for(const I of B){const ut=on(I.sourceColor,I.sourceElement??M,"background",R,k),zt=I.paintForeground({...b,alpha:xt});Q.some(Xt=>Xt.background===ut&&wt(Xt.backgroundColor,I.color)&&wt(Xt.foregroundColor,zt))||Q.push({role:n,element:R.element,state:kt,kind:F,source:X,indicator:ct,paintOpacity:m.coverage===1?void 0:m.coverage,foreground:Wt,background:ut,foregroundColor:zt,backgroundColor:I.color,ratio:Mn(zt,I.color),required:On(F),location:lt})}y.push(...Q)}catch(B){p.add(`${lt}: ${B instanceof Error?B.message:String(B)}`)}}return y});if(p.size)throw new Error(`Paint observation failed for "${n}":
|
|
2
|
+
${[...p].join(`
|
|
3
|
+
`)}`);return A}globalThis.EspalierPaintTesting=Kt})();
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{composedParent as F,isShadowRoot as tt}from"../shared/composed-dom.js";import{BRAND_PAINT_ID as x,PAINT_TARGETS as ot,PAINT_TOKEN_IDS as et,isPaintName as G,isPaintRole as rt,paintTokenProperty as nt,resolvePaintColor as st}from"../shared/paint-catalog.js";import{paintRequiredRatio as it,shadowIndicatorAlpha as at}from"../shared/paint-color.js";import{wcagRatio as ct}from"../shared/wcag-contrast.js";import{readIndicators as ut}from"./paint-bands.js";import{SVG_NAMESPACE as lt,browserColor as R,allShadowScopes as ft,createPaintSampler as dt,composedNodes as pt,cssPaintColor as z,equalColor as q,hasVisibleBox as H,locationOf as I,sampleRect as J,styleOf as _,textPoints as gt,withPaintHitTesting as ht}from"./paint-dom.js";import{createSvgPaintSampler as mt,loadSprites as wt}from"./svg-paint.js";function bt(t){const i=t.matches(":hover"),a=t.matches(":focus-visible");return i?a?"hover-focus":"hover":a?"focus":"rest"}function vt(t,i){const a=i.flatMap(s=>{const r=s(t);return r?[r]:[]});if(a.length===0)throw new Error(`Missing ${t.kind} target for ${t.source}`);if(a.length>1)throw new Error(`Ambiguous ${t.kind} target: ${a.map(({element:s})=>s).join(", ")}`);const[c]=a;if(!G(c.element)||!c.owner?.isConnected)throw new Error("Paint target requires an element identifier and an attached interaction owner");const l=bt(c.owner),f=c.state?.(l)??l;if(!G(f))throw new Error("Paint target returned an empty state");return{attribution:c,state:f}}function Ct(t,i){const a=_(t);let c,l=null;for(let s=t;s;s=F(s)){l??=s.getAttribute("context")?.trim()||null;const r=s.getAttribute("scheme");if((r==="light"||r==="dark")&&(c??=r),l&&c)break}const f=s=>{const r=a.getPropertyValue(s).trim();if(r)return CSS.supports("color",r)?R(t,r):r};return{scheme:c??(a.colorScheme==="dark"?"dark":"light"),context:l,readProperty:f,readColor(s){if(s===x)return i&&R(t,i);const r=nt(s);return r?f(r):void 0}}}function K(t,i,a,c,l){const f=a==="foreground",s=f?c.foregroundAliases:c.backgroundAliases,r=f?c.foregroundDerivations:c.backgroundDerivations,v=f?c.brandColor:void 0;let g=l.get(i);g||(g=new Map,l.set(i,g));const C=Ct(i,v),k=p=>{const S=p===x?`${p}:${v}`:p;g.has(S)||g.set(S,st(p,C));const y=g.get(S);return y!=null&&q(y,t)};if(v&&k(x))return x;const d=[...new Set([...et,...r??[]])].filter(p=>!s?.includes(p)&&k(p));if(d.length===1)return d[0];const h=JSON.stringify(t);throw new Error(d.length===0?`Unmatched ${a} ${h}`:`Ambiguous ${a} ${h}: ${d.join(", ")}`)}function kt(t,i){return t.namespaceURI===lt||t.textContent?.trim()||i.clipPath==="none"&&i.maskImage==="none"?!1:z(R(t,i.backgroundColor))?.alpha!==0}async function Rt(t,i){if(!rt(i?.role))throw new TypeError("observePaint requires a nonempty role without surrounding whitespace.");if(!t.isConnected||!t.ownerDocument.defaultView)throw new TypeError("observePaint requires an attached browser surface.");const{role:a}=i,c=[...ot[a]??[],...i.extraTargets??[]],{elements:l,text:f}=pt(t),s=ft(t.ownerDocument),r=(tt(t)?t.host:t).getBoundingClientRect(),v=new Set(l),g=s.flatMap(o=>[...o.querySelectorAll('svg use[href]:not([href^="#"])')].filter(u=>{if(v.has(u))return!1;const n=u.getBoundingClientRect();return n.right>r.left&&n.left<r.right&&n.bottom>r.top&&n.top<r.bottom})),C=mt(await wt([...l,...g])),k=l.filter(H),B=ut(k,s),d=new Set,h=[],p=[];for(const o of f){const u=F(o);if(!u||!H(u))continue;const n=gt(o);if(!n.length)continue;const e=_(u),P=e.getPropertyValue("-webkit-text-fill-color")||e.color;h.push({candidate:{element:u,text:o,kind:"text",source:"text"},rawColor:P,coverage:1,points:n})}for(const o of k){const u=_(o),n=kt(o,u);n&&u.maskImage!=="none"?d.add(`Unsupported CSS shape mask at ${I(o)}`):n&&h.push({candidate:{element:o,kind:"graphic",source:"shape"},rawColor:u.backgroundColor,coverage:1,points:[...o.getClientRects()].flatMap(J)});for(const e of B.get(o)??[])h.push({candidate:{element:o,kind:e.kind,source:e.source,indicator:e.blur>0?"blurred-shadow":void 0},rawColor:e.color,coverage:1,blur:e.blur,points:e.points});try{for(const e of C.refusals(o))p.push({element:o,...e});for(const e of C.paints(o))h.push({candidate:{element:o,kind:"graphic",source:e.source},rawColor:e.color,coverage:e.opacity,primitiveOpacity:e.primitiveOpacity,points:e.points})}catch(e){p.push({element:o,message:e instanceof Error?e.message:String(e),points:[...o.getClientRects()].flatMap(J)})}}const S=h.map(o=>{try{return{sample:o,match:vt(o.candidate,c)}}catch(u){return{sample:o,error:u}}}),y=new WeakMap,W=ht(s,()=>{const o=[],u=dt(t.ownerDocument,C.layersAt);for(const{element:n,message:e,points:P}of p)try{P.some(m=>u(n,m,!0))&&d.add(`${I(n)}: ${e}`)}catch(m){d.add(`${I(n)}: ${m instanceof Error?m.message:String(m)}`)}for(const{sample:n,match:e,error:P}of S){const{candidate:m,rawColor:V,points:L}=n,{element:$,kind:U,source:T,indicator:Q}=m,j=I($,m.text);try{const b=[];for(const w of L){const A=u($,w,T!=="shape");A&&b.push(A)}if(!b.length)continue;const E=z(R($,V));if(!E)throw new Error(`Cannot resolve ${T} paint "${V}"`);if(!e)throw P;const{attribution:N,state:X}=e,Y=K(E,$,"foreground",N,y),Z=at({alpha:E.alpha*(n.primitiveOpacity??n.coverage),blur:n.blur??0}),O=[];for(const w of b){const A=K(w.sourceColor,w.sourceElement??$,"background",N,y),D=w.paintForeground({...E,alpha:Z});O.some(M=>M.background===A&&q(M.backgroundColor,w.color)&&q(M.foregroundColor,D))||O.push({role:a,element:N.element,state:X,kind:U,source:T,indicator:Q,paintOpacity:n.coverage===1?void 0:n.coverage,foreground:Y,background:A,foregroundColor:D,backgroundColor:w.color,ratio:ct(D,w.color),required:it(U),location:j})}o.push(...O)}catch(b){d.add(`${j}: ${b instanceof Error?b.message:String(b)}`)}}return o});if(d.size)throw new Error(`Paint observation failed for "${a}":
|
|
2
|
+
${[...d].join(`
|
|
3
|
+
`)}`);return W}export{Rt as observePaint};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{composedParent as P}from"../shared/composed-dom.js";import{PAINT_TOKEN_IDS as Q,paintTokenProperty as Z}from"../shared/paint-catalog.js";import{SHADOW_INDICATOR_MARGIN_SIGMAS as $,SHADOW_INDICATOR_SAMPLE_OFFSET as tt,shadowIndicatorAlpha as ot,supportsShadowIndicatorBlur as nt}from"../shared/paint-color.js";import{cssPaintColor as O,locationOf as k,styleOf as x}from"./paint-dom.js";function _(t,o){let e=0,i=0;const s=[];for(let n=0;n<t.length;n++){const a=t[n];a==="("&&e++,a===")"&&e--,e===0&&o.test(a)&&(n>i&&s.push(t.slice(i,n).trim()),i=n+1)}return i<t.length&&s.push(t.slice(i).trim()),s}function v(t){const o=parseFloat(t.outlineWidth),e=t.outlineStyle==="none"||t.outlineStyle==="hidden"||!(o>0)?void 0:{color:t.outlineColor,style:t.outlineStyle,width:o,offset:parseFloat(t.outlineOffset)},i=_(t.boxShadow,/,/).flatMap(s=>{const n=_(s,/\s/),a=n.filter(r=>/^[-+.\d]+px$/.test(r)),[h,d,c=0,l=0]=a.map(parseFloat),f=n.find(r=>r!=="inset"&&!a.includes(r));return f&&h!==void 0&&d!==void 0?[{color:f,x:h,y:d,blur:c,spread:l,value:s,inset:n.includes("inset")}]:[]});return{outline:e,shadow:i}}const et=/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\\.|:(?:focus-visible|focus-within|focus|hover)(?![\w-])/g;function I(t,o){return t.replace(et,e=>!e.startsWith(":")||o&&e===":hover"?e:`:not(:where(*)):is(${e})`)}function st(t){const o=[],e=new Set;function i(n){for(const a of n){if("selectorText"in a&&typeof a.selectorText=="string"){const h=a.selectorText;I(h,!1)!==h&&o.push([a,h])}if("cssRules"in a&&i(a.cssRules),"styleSheet"in a){const h=a.styleSheet;h&&s(h)}}}function s(n){if(e.has(n))return;e.add(n);let a;try{a=n.cssRules}catch{return}i(a)}for(const n of t)for(const a of[...n.styleSheets,...n.adoptedStyleSheets])s(a);return o}function D(t,o){return o?.color===t.color&&o.style===t.style&&o.width===t.width&&o.offset===t.offset}const F=new WeakMap,rt=Q.map(Z).filter(t=>t!==void 0);function L(t,o,e){let i=null,s=null;for(let n=t;n&&!(i&&s);n=P(n))i??=n.getAttribute("scheme")||null,s??=n.getAttribute("context")||null;return JSON.stringify([e,o.colorScheme,i,s,...rt.map(n=>o.getPropertyValue(n))])}function dt(t,o){const e=t[0]?.ownerDocument.defaultView,i=[e?.matchMedia("(prefers-color-scheme: dark)").matches,e?.matchMedia("(forced-colors: active)").matches].join(":"),s=t.flatMap(c=>{const l=x(c),f=v(l),r=c.matches(":focus-within, :focus-visible"),u=c.matches(":hover"),w=u?"hover":"rest";let p=F.get(c);if(r||(p||(p={},F.set(c,p)),p[w]={bands:f,environment:L(c,l,i)}),!f.outline&&f.shadow.length===0)return[];const m=r?p?.[w]:void 0,b=m&&m.environment===L(c,l,i)?m.bands:void 0;return[{element:c,bands:f,focus:r,hover:u,realNoFocus:b}]}),n=new Map,a=new Map,h=s.some(({focus:c})=>c),d=s.some(({hover:c})=>c);if(h||d){const c=st(o),l=[],f=new CSSStyleSheet;f.replaceSync("* { transition: none !important; }");try{for(const r of o){const u=[...r.adoptedStyleSheets];r.adoptedStyleSheets=[...u,f],l.push([r,u])}if(h){for(const[r,u]of c){const w=I(u,!0);w!==u&&(r.selectorText=w)}for(const{element:r,focus:u}of s)u&&a.set(r,v(x(r)))}if(d){for(const[r,u]of c)r.selectorText=I(u,!1);for(const{element:r,hover:u}of s)u&&n.set(r,v(x(r)))}}finally{for(const[r,u]of c)r.selectorText!==u&&(r.selectorText=u);for(const{element:r}of s)x(r).boxShadow;for(const[r,u]of l)r.adoptedStyleSheets=u}}return new Map(s.map(({element:c,bands:l,hover:f,focus:r,realNoFocus:u})=>{const w=n.get(c)??a.get(c),p=a.get(c),m=[...c.getClientRects()],b=l.outline,M=l.shadow.map(y=>({source:"shadow",shadow:y}));b&&M.unshift({source:"outline",outline:b});const R=[],A=b&&r&&(!D(b,p?.outline)||(u?!D(b,u.outline):b.style==="auto"&&c.matches(":focus-visible")));b&&(A||f&&!D(b,w?.outline))&&R.push({source:"outline",kind:A?"ring":"graphic",color:b.color,blur:0,points:m.flatMap(y=>Y(c,y,M,0))});for(const[y,g]of l.shadow.entries()){const B=r&&(!p?.shadow.some(({value:S})=>S===g.value)||u&&!u.shadow.some(({value:S})=>S===g.value)),j=f&&!w?.shadow.some(({value:S})=>S===g.value);if(!B&&!j&&!(g.inset&&g.blur===0))continue;const J=b?y+1:y,K=m.flatMap(S=>Y(c,S,M,J));R.push({source:"shadow",kind:B?"ring":"graphic",color:g.color,blur:g.blur,points:K})}return[c,R]}))}const N=["top","bottom","left","right"];function W(t,o,e,i){const s=t.left+i*t.width,n=t.top+i*t.height;switch(o){case"top":return{x:s,y:t.top-e};case"bottom":return{x:s,y:t.bottom+e};case"left":return{x:t.left-e,y:n};case"right":return{x:t.right+e,y:n}}}function E(t,o,e){return(o-t[e])*(e==="right"||e==="bottom"?1:-1)}function it(t,o){const e=x(t),i=a=>parseFloat(e.getPropertyValue(`border-${a}-width`)),s=i("left"),n=i("top");return new DOMRect(o.left+s,o.top+n,o.width-s-i("right"),o.height-n-i("bottom"))}function C(t,o){const e=o.inset?-o.spread:o.spread;return new DOMRect(t.left+o.x-e,t.top+o.y-e,Math.max(0,t.width+2*e),Math.max(0,t.height+2*e))}function q(t,o,e,i){if(t.source==="outline"){const{offset:f,width:r}=t.outline;return[f,f+r]}const{shadow:s}=t;if(s.blur>0)return;const n=s.inset?e:o,a=C(n,s),h=E(o,a[i],i);if(!s.inset)return h>0?[0,h]:void 0;const d=E(o,n[i],i),c=i==="top"||i==="bottom"?n.height:n.width,l=a.width&&a.height?Math.max(h,d-c):d-c;return l<d?[l,d]:void 0}function at(t,o,e,i,s){const n=q(t[o],e,i,s);if(!n)return[];const[a,h]=n,d=[0,...t.flatMap(l=>q(l,e,i,s)??[])].filter(l=>l>a&&l<h),c=[...new Set([a,...d,h])].sort((l,f)=>l-f);return c.slice(1).map((l,f)=>(c[f]+l)/2)}function T(t,o,e=0){return o.x>t.left-e&&o.x<t.right+e&&o.y>t.top-e&&o.y<t.bottom+e}function H(t,o,e,i){const s=x(t),n=(r,u)=>/^[-+.\d]+(?:px|%)?$/.test(r)?parseFloat(r)*(r.endsWith("%")?u/100:1):NaN,[a,h,d,c]=[s.borderTopLeftRadius,s.borderTopRightRadius,s.borderBottomRightRadius,s.borderBottomLeftRadius].map(r=>{const[u,w=u]=r.split(/\s+/);return[n(u,o.width),n(w,o.height)]}),l=Math.min(1,o.width/(a[0]+h[0]),o.width/(c[0]+d[0]),o.height/(a[1]+c[1]),o.height/(h[1]+d[1])),f=[a,h,d,c];return{clip:e,spread:C(e,i),cornerX:l*Math.max(...f.map(([r])=>r)),cornerY:l*Math.max(...f.map(([,r])=>r))}}function U(t,o,e,i){return E(t,e.spread[i],i)+tt*(o.inset?-1:1)}function G(t,o,e,i){if(T(o.clip,i)!==t.inset)return!1;const s=t.blur/2*$,{spread:n,cornerX:a,cornerY:h}=o,d=e==="top"||e==="bottom",c=d?i.x:i.y,l=d?n.left:n.top,f=d?n.right:n.bottom,r=d?a:h;return(d?n.height:n.width)>=s&&c-l>=s+r&&f-c>=s+r}function V(t){return t.spread===0&&nt(t.blur)}function z(t){for(let o=t;o;o=P(o)){const{transform:e,rotate:i,scale:s}=x(o);if(i&&i!=="none"||s&&s!=="none")return!1;if(e==="none")continue;const n=new DOMMatrixReadOnly(e);if(n.m11!==1||n.m22!==1||n.m33!==1||n.m44!==1||n.m12||n.m13||n.m14||n.m21||n.m23||n.m24||n.m31||n.m32||n.m34||n.m43)return!1}return!0}function ct(t,o,e,i,s,n,a){if(o.source==="outline"){const{color:m,offset:b,width:M,style:R}=o.outline;return a<=b||a>=b+M||O(m)?.alpha===0?void 0:R!=="solid"?{ambiguous:"non-solid outline"}:{paint:{rawColor:m,opacity:1},opaque:O(m)?.alpha===1}}const{shadow:h}=o,{color:d,blur:c,inset:l}=h,f=l?i:e;if(T(f,s)!==l)return;const r=O(d)?.alpha;if(r===0)return;if(c===0)return T(C(f,h),s)===l?void 0:{paint:{rawColor:d,opacity:1},opaque:r===1};const u=H(t,e,f,h),w=U(e,h,u,n);if(V(h)&&Math.abs(a-w)<1e-6&&G(h,u,n,s)&&z(t))return{paint:{rawColor:d,opacity:ot({alpha:1,blur:c})},opaque:!1};const p=c/2*$*(l?-1:1);if(T(u.spread,s,p)!==l)return{ambiguous:"blurred shadow away from its spread boundary"}}function X(t,o,e,i,s,n,a,h){return[.5,.3,.7].flatMap(d=>{const c={...W(o,n,a,d),inside:a>=0?W(o,n,-.5,d):void 0};if(h&&!h(c))return[];if(i.length===1)return[c];const l=p=>ct(t,p,o,e,c,n,a),f=i.slice(0,s).map(l);if(f.some(p=>p&&"opaque"in p&&p.opaque))return[];const r=[],u=[];function w(p,m){if(!m)return!0;if("ambiguous"in m)throw new Error(`Cannot resolve overlapping indicator paint at ${k(t)}: ${m.ambiguous}`);return p.push(m.paint),!m.opaque}for(const p of f)w(r,p);for(const p of i.slice(s+1))if(!w(u,l(p)))break;return[{...c,local:{above:r,below:u}}]})}function Y(t,o,e,i){if(o.width<=0||o.height<=0)return[];const s=e[i],n=e.some(f=>f.source==="shadow"&&f.shadow.inset)?it(t,o):o;if(s.source!=="shadow"||s.shadow.blur===0){const f=s.source==="shadow"&&s.shadow.inset?r=>T(n,r):void 0;return N.flatMap(r=>at(e,i,o,n,r).flatMap(u=>X(t,o,n,e,i,r,u,f)))}const{shadow:a}=s,h=k(t);if(!V(a))throw new Error(`Unsupported shadow indicator geometry at ${h}: ${a.blur}px blur, ${a.spread}px spread. Expected 3\u20134px blur with zero spread.`);if(!z(t))throw new Error(`Unsupported shadow indicator geometry at ${h}: transformed spread edge.`);const d=H(t,o,a.inset?n:o,a);let c=!1;const l=N.flatMap(f=>X(t,o,n,e,i,f,U(o,a,d,f),r=>{const u=G(a,d,f,r);return c||=u,u}));if(!c)throw new Error(`Unsupported shadow indicator geometry at ${h}: no straight spread edge with enough clearance.`);return l}export{dt as readIndicators};
|