@taprootio/espalier 4.3.0 → 4.5.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 +17 -0
- package/css/fonts/font-fallback-profiles.json +1 -0
- package/custom-elements.json +2338 -1491
- package/dist/action-menu/esp-action-menu-item.js +7 -4
- package/dist/avatar/esp-avatar.js +14 -8
- package/dist/avatar/esp-profile-chip.js +4 -1
- package/dist/badge/esp-badge.js +7 -4
- package/dist/box/esp-box.d.ts +1 -1
- package/dist/checkbox/esp-checkbox.js +6 -3
- package/dist/color-picker/esp-color-picker.js +1 -1
- package/dist/data-cell/esp-data-cell.js +6 -3
- package/dist/date-picker/helpers/styles.js +10 -4
- package/dist/details/esp-details.d.ts +4 -4
- package/dist/details/esp-details.js +11 -5
- package/dist/empty-state/esp-empty-state.js +16 -7
- package/dist/flyout/esp-flyout.js +5 -2
- package/dist/font-picker/esp-font-picker.d.ts +1 -0
- package/dist/font-picker/esp-font-picker.js +4 -4
- package/dist/footer/esp-footer-link-group.js +12 -6
- package/dist/footer/esp-footer.js +21 -6
- package/dist/form-item/esp-form-item.js +4 -1
- package/dist/header/esp-header.d.ts +2 -1
- package/dist/header/esp-header.js +24 -6
- package/dist/help/esp-help-button.d.ts +1 -1
- package/dist/help/help-document.js +4 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/lightbox/esp-lightbox.d.ts +1 -1
- package/dist/page/esp-page.d.ts +1 -0
- package/dist/page/esp-page.js +40 -783
- package/dist/page/esp-page.styles.js +748 -0
- package/dist/page/workspace-geometry.js +1 -0
- package/dist/page/workspace-resize-session.js +1 -0
- package/dist/page/workspace-width.js +1 -1
- package/dist/pickers/esp-picker-menu.js +6 -6
- package/dist/progress/esp-progress.js +11 -5
- package/dist/radio-button/esp-radio-button.js +6 -3
- package/dist/root/esp-root.d.ts +8 -0
- package/dist/root/esp-root.js +13 -7
- package/dist/root/helpers/compute-theme-properties.js +1 -1
- package/dist/search/esp-search.js +10 -4
- package/dist/shared/esp-element-base.js +20 -4
- package/dist/shared/font-helpers.d.ts +26 -0
- package/dist/shared/font-helpers.js +1 -1
- package/dist/shared/font-plan.d.ts +90 -0
- package/dist/shared/font-plan.js +5 -0
- package/dist/shared/scale-engine.js +1 -1
- package/dist/shared/theme.d.ts +28 -4
- package/dist/shared/theme.js +1 -1
- package/dist/slider/esp-slider.js +8 -5
- package/dist/status-indicator/esp-status-indicator.d.ts +1 -1
- package/dist/switch/esp-switch.js +11 -5
- package/dist/tabs/esp-tab-group.js +6 -3
- package/dist/tabs/esp-tab.js +6 -3
- package/dist/tree/esp-tree.js +4 -1
- package/espalier.css-data.json +9 -5
- package/espalier.token-manifest.json +13 -5
- package/licenses/ASSET_PROVENANCE.md +2 -1
- package/licenses/THIRD_PARTY_NOTICES.md +35 -0
- package/licenses/asset-provenance.json +26 -2
- package/package.json +16 -2
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency-free compiler for first-paint, site-specific font plans.
|
|
3
|
+
*
|
|
4
|
+
* Hosts load the checked-in fallback profile catalog at build time, collect
|
|
5
|
+
* the exact requested faces, resolve only those WOFF2 sources, and embed the
|
|
6
|
+
* resulting CSS in the document head before `<esp-root>` can paint.
|
|
7
|
+
*/
|
|
8
|
+
import type { EspalierTheme } from "./theme.js";
|
|
9
|
+
export type FontPlanTheme = Pick<EspalierTheme, "fontBody" | "fontHeadings" | "fontBrand" | "fontMonospace" | "fontWeightBody" | "fontWeightHeadings" | "fontWeightBrand" | "fontWeightMonospace">;
|
|
10
|
+
export type FontPlanSlot = "body" | "headings" | "brand" | "monospace";
|
|
11
|
+
export type FontPlanScheme = "light" | "dark";
|
|
12
|
+
export type FontPlanStyle = "normal" | "italic";
|
|
13
|
+
export type FontFaceRequest = {
|
|
14
|
+
key: string;
|
|
15
|
+
family: string;
|
|
16
|
+
weight: number;
|
|
17
|
+
style: FontPlanStyle;
|
|
18
|
+
};
|
|
19
|
+
export type ResolvedFontSource = {
|
|
20
|
+
/** Absolute or root-relative URL for one WOFF2 face or subset. */
|
|
21
|
+
url: string;
|
|
22
|
+
/** Optional CSS unicode-range for this source's subset. */
|
|
23
|
+
unicodeRange?: string;
|
|
24
|
+
};
|
|
25
|
+
export type FontFallbackProfile = readonly [
|
|
26
|
+
fallbackIndex: number,
|
|
27
|
+
fallbackVariant: string,
|
|
28
|
+
sizeAdjust: number | null,
|
|
29
|
+
ascentOverride: number | null,
|
|
30
|
+
descentOverride: number | null,
|
|
31
|
+
lineGapOverride: number | null
|
|
32
|
+
];
|
|
33
|
+
export type FontFallbackCatalog = {
|
|
34
|
+
version: 1;
|
|
35
|
+
metadata: {
|
|
36
|
+
subset: string;
|
|
37
|
+
percentScale: number;
|
|
38
|
+
familyCount: number;
|
|
39
|
+
variantCount: number;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
};
|
|
42
|
+
bases: ReadonlyArray<readonly [family: string, variants: Readonly<Record<string, readonly string[]>>]>;
|
|
43
|
+
profiles: Readonly<Record<string, Readonly<Record<string, readonly FontFallbackProfile[]>>>>;
|
|
44
|
+
};
|
|
45
|
+
export type FontPlanProfileMiss = {
|
|
46
|
+
family: string;
|
|
47
|
+
weight: number | null;
|
|
48
|
+
style: FontPlanStyle;
|
|
49
|
+
schemes: FontPlanScheme[];
|
|
50
|
+
slots: FontPlanSlot[];
|
|
51
|
+
};
|
|
52
|
+
export type CompileFontPlanOptions = {
|
|
53
|
+
lightTheme: FontPlanTheme;
|
|
54
|
+
darkTheme: FontPlanTheme;
|
|
55
|
+
catalog: FontFallbackCatalog;
|
|
56
|
+
/** Sources keyed with {@link fontFaceRequestKey}. Unselected keys are ignored. */
|
|
57
|
+
sources?: Readonly<Record<string, ResolvedFontSource | readonly ResolvedFontSource[]>>;
|
|
58
|
+
/** Optional unique root id selector, for example `#site-shell`. Defaults to every `esp-root`. */
|
|
59
|
+
rootSelector?: string;
|
|
60
|
+
};
|
|
61
|
+
export type CompiledFontPlan = {
|
|
62
|
+
/** Minified CSS suitable for the existing inline page-head style block. */
|
|
63
|
+
css: string;
|
|
64
|
+
/** Exact, deduplicated faces that the host must resolve. */
|
|
65
|
+
requests: FontFaceRequest[];
|
|
66
|
+
/** Requested faces for which no source was supplied. */
|
|
67
|
+
missingSources: FontFaceRequest[];
|
|
68
|
+
/** Catalog families that lacked the requested weight/style profile. */
|
|
69
|
+
missingProfiles: FontPlanProfileMiss[];
|
|
70
|
+
/** Scheme/slot stacks represented by the emitted private effective tokens. */
|
|
71
|
+
effectiveStacks: Record<FontPlanScheme, Record<FontPlanSlot, string>>;
|
|
72
|
+
/** UTF-8 byte size of `css`, convenient for static-site budget checks. */
|
|
73
|
+
byteLength: number;
|
|
74
|
+
};
|
|
75
|
+
/** Return the stable source-map key for a requested target face. */
|
|
76
|
+
export declare function fontFaceRequestKey(family: string, weight: number, style?: FontPlanStyle): string;
|
|
77
|
+
/** Return the fallback base indexes used for one Google Fonts category. */
|
|
78
|
+
export declare function fontFallbackBaseIndexes(category: string): readonly number[];
|
|
79
|
+
/**
|
|
80
|
+
* Return the deterministic profile aliases a runtime font stack may reference
|
|
81
|
+
* without loading the build-time profile catalog in the browser.
|
|
82
|
+
*/
|
|
83
|
+
export declare function fontFallbackAliases(family: string, weight: string | number, category: string, style?: FontPlanStyle): string[];
|
|
84
|
+
/**
|
|
85
|
+
* Compile a complete, first-paint font plan from two resolved themes.
|
|
86
|
+
*
|
|
87
|
+
* Call once without `sources` to discover `requests`, resolve those assets in
|
|
88
|
+
* the host build, then call again with the keyed source map for final CSS.
|
|
89
|
+
*/
|
|
90
|
+
export declare function compileFontPlan(options: CompileFontPlanOptions): CompiledFontPlan;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{extractFamily as R,normalizeFontFaceWeight as A}from"./font-helpers.js";const N="U+0000-024F,U+1E00-1EFF,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD",F=["body","headings","brand","monospace"],z={"sans-serif":[0,1],display:[0,1],handwriting:[0,1],"not-display":[0,1],serif:[2],monospace:[3]};function b(t){let e="";for(const n of t){const s=n.codePointAt(0)??0;n==="\\"?e+="\\\\":n==='"'?e+='\\"':n==="<"?e+="\\3c ":s<=31||s===127?e+=`\\${s.toString(16)} `:e+=n}return`"${e}"`}function I(t){return`url(${b(t)}) format("woff2")`}function U(t){for(const o of t){const y=o.codePointAt(0)??0;if(o===";"||o==="{"||o==="}"||o==="<"||y<=31||y===127)throw new Error("Font stack contains characters that cannot be embedded in inline CSS")}if(t.includes("/*")||t.includes("*/"))throw new Error("Font stack contains characters that cannot be embedded in inline CSS");const e=[];let n="",s="",r=!1,a=0;for(const o of t){if(r){n+=o,r=!1;continue}if(o==="\\"){n+=o,r=!0;continue}if(s){n+=o,o===s&&(s="");continue}if(o==='"'||o==="'"){n+=o,s=o;continue}if(o==="("&&(a+=1),o===")"&&(a=Math.max(0,a-1)),o===","&&a===0){n.trim()&&e.push(n.trim()),n="";continue}n+=o}if(r||s||a!==0)throw new Error("Font stack contains an unterminated escape, quote, or function");return n.trim()&&e.push(n.trim()),e}function W(t){return A(t)}function _(t,e){return`${t}${e==="italic"?"i":""}`}function x(t,e,n="normal"){return`${encodeURIComponent(t)}~${e}~${n==="italic"?"i":"n"}`}function j(t,e){return t.family.localeCompare(e.family,"en")||t.weight-e.weight||t.style.localeCompare(e.style,"en")}function q(t,e){let n=2166136261;for(const s of`${t}:${e}`)n^=s.charCodeAt(0),n=Math.imul(n,16777619);return`ef${(n>>>0).toString(36)}`}function B(t){return z[t]??[]}function H(t,e,n,s="normal"){const r=A(e);if(!t.trim()||r===null)return[];const a=x(t.trim(),r,s);return B(n).map(o=>q(a,o))}function O(t,e){if(!Number.isInteger(t)||t<0||!Number.isInteger(e)||e<=0)throw new Error("Font fallback catalog contains an invalid encoded percentage");const n=Math.floor(t/e),s=String(t%e).padStart(String(e).length-1,"0").replace(/0+$/,"");return`${n}${s?`.${s}`:""}%`}function k(t,e,n,s){n!==null&&t.push(`${e}:${O(n,s)};`)}function P(t,e){const n=U(t);return n.length===0||e.length===0?t:[n[0],...e,...n.slice(1)].join(",")}function M(t){const e=t.fontBody,n=t.fontHeadings||e,s=t.fontBrand||n,r=t.fontMonospace;return{body:[e,t.fontWeightBody],headings:[n,t.fontWeightHeadings],brand:[s,t.fontWeightBrand],monospace:[r,t.fontWeightMonospace]}}function C(t,e,n,s,r){const a={},o={},y=M(e);for(const l of F){const[f,$]=y[l];a[l]=f,U(f);const u=R(f),i=n.profiles[u];if(!i)continue;const d=W($);if(d===null){const w=`${u}
|
|
2
|
+
${$}
|
|
3
|
+
normal`,p=r.get(w)??{family:u,weight:null,style:"normal",schemes:[],slots:[]};p.schemes.includes(t)||p.schemes.push(t),p.slots.includes(l)||p.slots.push(l),r.set(w,p);continue}const c="normal",m=i[_(d,c)];if(!m){const w=`${u}
|
|
4
|
+
${d}
|
|
5
|
+
${c}`,p=r.get(w)??{family:u,weight:d,style:c,schemes:[],slots:[]};p.schemes.includes(t)||p.schemes.push(t),p.slots.includes(l)||p.slots.push(l),r.set(w,p);continue}const h=x(u,d,c),g=s.get(h)??{request:{key:h,family:u,weight:d,style:c},profile:m,schemes:new Set,slots:new Set};g.schemes.add(t),g.slots.add(l),s.set(h,g),o[l]=g}return{stacks:a,uses:o}}function T(t){const e=t.trim();if(!/^U\+[0-9A-F?]{1,6}(?:-[0-9A-F]{1,6})?(?:\s*,\s*U\+[0-9A-F?]{1,6}(?:-[0-9A-F]{1,6})?)*$/i.test(e))throw new Error(`Invalid font source unicode-range "${t}"`);return e.replace(/\s+/g,"")}function L(t){return t?Array.isArray(t)?t:[t]:[]}function D(t,e){return e.map(n=>{if(!n.url.trim())throw new Error(`Empty WOFF2 source for ${t.key}`);const s=n.unicodeRange?`unicode-range:${T(n.unicodeRange)};`:"";return`@font-face{font-family:${b(t.family)};src:${I(n.url)};font-style:${t.style};font-weight:${t.weight};font-display:swap;${s}}`}).join("")}function G(t,e,n){const[s,r,a,o,y,l]=e,f=n.bases[s],$=f?.[1]?.[r];if(!f||!$||$.length===0)throw new Error(`Font fallback catalog is missing base ${s} ${r}`);const u=q(t.key,s),i=[`@font-face{font-family:${u};src:${$.map(d=>`local(${b(d)})`).join(",")};`,`font-style:${t.style};font-weight:${t.weight};`];return k(i,"size-adjust",a,n.metadata.percentScale),k(i,"ascent-override",o,n.metadata.percentScale),k(i,"descent-override",y,n.metadata.percentScale),k(i,"line-gap-override",l,n.metadata.percentScale),i.push(`unicode-range:${N};}`),{alias:u,css:i.join("")}}function E(t,e){const n=F.map(s=>`--_esp-font-${s}-effective:${e[s]};`).join("");return`${t}{${n}}`}function K(t){if(t===void 0||t.trim()==="")return"esp-root";const e=t.trim();if(!/^#[A-Za-z_][A-Za-z0-9_-]*$/.test(e))throw new Error('rootSelector must be a unique id selector such as "#site-shell"');return e}function J(t){const{catalog:e}=t;if(e.version!==1||e.metadata?.subset!=="latin"||!/^10+$/.test(String(e.metadata?.percentScale)))throw new Error(`Unsupported font fallback catalog metadata: version ${String(e.version)}, subset ${String(e.metadata?.subset)}, percentScale ${String(e.metadata?.percentScale)}`);const n=new Map,s=K(t.rootSelector),r=new Map,a={light:C("light",t.lightTheme,e,n,r),dark:C("dark",t.darkTheme,e,n,r)},o=[...n.values()].sort((c,m)=>j(c.request,m.request)),y=o.map(({request:c})=>c),l=[],f=[],$=new Map,u=new Map;for(const c of o){const m=L(t.sources?.[c.request.key]);m.length===0?l.push(c.request):f.push(D(c.request,m));const h=[];for(const S of c.profile){const g=G(c.request,S,e),w=u.get(g.alias);if(w&&w!==`${c.request.key}:${S[0]}`)throw new Error(`Generated fallback family collision for ${g.alias}`);u.set(g.alias,`${c.request.key}:${S[0]}`),h.push(g.alias),f.push(g.css)}$.set(c.request.key,h)}const i={light:{},dark:{}};for(const c of["light","dark"]){const m=a[c];for(const h of F){const S=m.uses[h];i[c][h]=S?P(m.stacks[h],$.get(S.request.key)??[]):m.stacks[h]}}f.push(E(s,i.light)),JSON.stringify(i.dark)!==JSON.stringify(i.light)&&(f.push(E(`${s}[scheme=dark],${s}[default-scheme=dark]:not([scheme])`,i.dark)),f.push(`@media(prefers-color-scheme:dark){${E(`${s}[default-scheme=system]:not([scheme])`,i.dark)}}`));const d=f.join("");return{css:d,requests:y,missingSources:l,missingProfiles:[...r.values()],effectiveStacks:i,byteLength:new TextEncoder().encode(d).byteLength}}export{J as compileFontPlan,x as fontFaceRequestKey,H as fontFallbackAliases,B as fontFallbackBaseIndexes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const l=["tiny","small","normal","medium","big","large","huge"],
|
|
1
|
+
const l=["tiny","small","normal","medium","big","large","huge"],b=2,O=1.125,g=1.3333333333333333,h=[["tiny","small"],["small","normal"],["normal","medium"],["medium","big"],["big","large"],["large","huge"]],u=.375,z={rootFontSize:16,typeRatio:1.25,spaceRatio:1.618,borderRadius:.2,viewportMin:320,viewportMax:1200};function c(s,e=4){const t=10**e;return Math.round(s*t)/t}function d(s,e,t,o,p){if(Math.abs(e-s)<1e-4)return`${c(s)}rem`;const y=(e-s)*t*100/(p-o),n=s-y*o/(100*t);return`clamp(${c(s)}rem, ${c(n)}rem + ${c(y)}vw, ${c(e)}rem)`}function E(s){const e={};for(let t=0;t<l.length;t++){const o=t-2,p=1.125*s.typeRatio**o;e[l[t]]={min:p,max:p*g}}return e}function x(s){const e={};for(let t=0;t<l.length;t++){const o=u*s.spaceRatio**t;e[l[t]]={min:o,max:o*g}}return e}const _={"--esp-shadow-1":"1px 1px 4px var(--esp-color-shadow)","--esp-shadow-2":"0 2px 8px var(--esp-color-shadow)","--esp-shadow-3":"0 6px 20px var(--esp-color-shadow)"},w={"--esp-type-overline-color":"var(--esp-color-type-overline, var(--esp-color-text))","--esp-type-label-color":"var(--esp-color-type-label, var(--esp-color-text))","--esp-type-lead-color":"var(--esp-color-type-lead, var(--esp-color-text))","--esp-type-caption-color":"var(--esp-color-type-caption, var(--esp-color-text))","--esp-type-display-color":"var(--esp-color-headings, var(--esp-color-text))"},S={"--esp-type-overline-font-size":"var(--esp-type-tiny)","--esp-type-overline-font-weight":"var(--esp-font-weight-headings)","--esp-type-overline-letter-spacing":"0.08em","--esp-type-overline-text-transform":"uppercase","--esp-type-label-font-size":"var(--esp-type-normal)","--esp-type-label-font-weight":"var(--esp-font-weight-headings)","--esp-type-label-letter-spacing":"0.01em","--esp-type-lead-font-size":"var(--esp-type-medium)","--esp-type-lead-font-weight":"var(--esp-font-weight-body)","--esp-type-lead-letter-spacing":"normal","--esp-type-caption-font-size":"var(--esp-type-small)","--esp-type-caption-font-weight":"var(--esp-font-weight-body)","--esp-type-caption-letter-spacing":"normal","--esp-type-display-font-family":"var(--_esp-font-headings-effective, var(--esp-font-headings, var(--_esp-font-body-effective, var(--esp-font-body, system-ui, sans-serif))))","--esp-type-display-font-weight":"var(--esp-font-weight-headings)","--esp-type-display-line-height":"1.1","--esp-type-display-letter-spacing":"normal",...w};function P(s){const e={},{rootFontSize:t,viewportMin:o,viewportMax:p,borderRadius:y}=s,n=16,r=t/n,m=E(s);for(const a of l){const{min:i,max:f}=m[a];e[`--esp-type-${a}`]=d(i*r,f*r,n,o,p)}e["--esp-type-display-font-size"]=d(m.large.min*r,m.huge.max*r,n,o,p),Object.assign(e,S);const v=x(s);for(const a of l){const{min:i,max:f}=v[a];e[`--esp-size-${a}`]=d(i*r,f*r,n,o,p)}for(const[a,i]of h)e[`--esp-size-${a}-to-${i}`]=d(v[a].min*r,v[i].max*r,n,o,p);return e["--esp-size-font"]="var(--esp-type-normal)",e["--esp-size-padding"]="var(--esp-size-tiny-to-small)",e["--esp-size-padding-page"]="var(--esp-size-small-to-normal)",e["--esp-size-border-radius"]=`${c(y*r)}rem`,e["--esp-measure"]="66ch",e["--esp-measure-wide"]="90ch",e["--esp-size-section"]="clamp(var(--esp-size-big), 7vw, var(--esp-size-huge))",Object.assign(e,_),e["--esp-card-min"]="16rem",e}export{z as DEFAULT_SCALE_CONFIG,_ as ELEVATION_PROPERTIES,l as STEP_NAMES,w as TYPE_ROLE_COLOR_PROPERTIES,S as TYPE_ROLE_PROPERTIES,P as generateScaleProperties};
|
package/dist/shared/theme.d.ts
CHANGED
|
@@ -315,13 +315,33 @@ export interface EspalierTheme {
|
|
|
315
315
|
* carries an `oklch()` string here.
|
|
316
316
|
*/
|
|
317
317
|
seedColor: string;
|
|
318
|
-
/**
|
|
318
|
+
/**
|
|
319
|
+
* CSS `font-family` for body / UI text. Empty and omitted overrides resolve
|
|
320
|
+
* to the built-in UI stack.
|
|
321
|
+
*
|
|
322
|
+
* @default "system-ui, sans-serif"
|
|
323
|
+
*/
|
|
319
324
|
fontBody: string;
|
|
320
|
-
/**
|
|
325
|
+
/**
|
|
326
|
+
* CSS `font-family` for headings. When empty, heading recipes fall back to
|
|
327
|
+
* {@link fontBody} without changing this authored value.
|
|
328
|
+
*
|
|
329
|
+
* @default ""
|
|
330
|
+
*/
|
|
321
331
|
fontHeadings: string;
|
|
322
|
-
/**
|
|
332
|
+
/**
|
|
333
|
+
* CSS `font-family` for brand marks and product names. When empty, brand
|
|
334
|
+
* recipes fall back through {@link fontHeadings} to {@link fontBody}.
|
|
335
|
+
*
|
|
336
|
+
* @default ""
|
|
337
|
+
*/
|
|
323
338
|
fontBrand: string;
|
|
324
|
-
/**
|
|
339
|
+
/**
|
|
340
|
+
* CSS `font-family` for code / monospace text. Empty and omitted overrides
|
|
341
|
+
* resolve to the built-in monospace family.
|
|
342
|
+
*
|
|
343
|
+
* @default "monospace"
|
|
344
|
+
*/
|
|
325
345
|
fontMonospace: string;
|
|
326
346
|
/**
|
|
327
347
|
* CSS `font-weight` for body / UI text.
|
|
@@ -629,6 +649,10 @@ export declare const DEFAULT_DARK_LIGHTNESS: Readonly<LightnessMap>;
|
|
|
629
649
|
* hue and which lightness key sets the perceived brightness.
|
|
630
650
|
*/
|
|
631
651
|
export declare const DEFAULT_SEMANTIC_MAPPINGS: Readonly<SemanticMappings>;
|
|
652
|
+
/** Built-in authored stack for body and UI text. */
|
|
653
|
+
export declare const DEFAULT_BODY_FONT_FAMILY = "system-ui, sans-serif";
|
|
654
|
+
/** Built-in authored family for code and monospace text. */
|
|
655
|
+
export declare const DEFAULT_MONOSPACE_FONT_FAMILY = "monospace";
|
|
632
656
|
/**
|
|
633
657
|
* The built-in **light** theme.
|
|
634
658
|
*
|
package/dist/shared/theme.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{UNSAFE_KEYS as lt,isSafeKey as M}from"./unsafe-keys.js";import{ACCEPTED_COLOR_FORMS as oe,apcaContrast as pt,clampChannel as ge,deltaEOK as dt,deriveSemantic as ae,gamutMapToSRGB as he,linearRgbToOklab as mt,oklchToSRGB as gt,parseCssColor as W,parseOklch as ht,serializeOklch as ce,srgbToLinearRGB as yt}from"./color-engine.js";import{computeVariants as ye,parseAnchorSource as bt,resolveAnchorColor as $t,resolveMappingSource as ue}from"./variant-engine.js";import{auditColorDistances as Fe,auditDataPalette as xt,describePaletteCollision as kt,DATA_SERIES_KEYS as fe,DEFAULT_DATA_PALETTE as be,DEFAULT_DATA_RAMP_STEPS as St,MAX_DATA_RAMP_STEPS as $e,MIN_DATA_RAMP_LIGHTNESS_STEP as We,MIN_DATA_RAMP_STEPS as xe}from"./data-colors.js";const j=/^[a-z][a-z0-9-]*$/;function ke(e){return bt(e)}function je(e,n){return $t(e,n)}function At(e,n){const t=ke(e);if(t){const o=je(n,t);return o&&W(o)?o:null}return W(e)?e:null}const se=["canvas","ink","accent","action","structure"],Se={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"]]}},Mt=new Set(["action.color"]),Ot={canvas:"background",ink:"text",accent:"link",action:"actionBackground",structure:"border"},Tt={"action.ink":{role:"canvas",slot:"color"}},Ct=.45,Rt=.045;function ze(e,n,t){const o=Ue.actionText,i=[...U].sort((y,T)=>e[y]-e[T]||U.indexOf(y)-U.indexOf(T)),a=n?i.filter(y=>n(y)>=o.targetLc):i,u=t?a.filter(y=>t(y)>=Rt):a,d=u.length>0?u:a,m=d.length>0?d:i;let A,k=1/0;for(const y of m){const T=Math.abs(e[y]-Ct);T<k&&(k=T,A=y)}return A??"muted"}function vt(e,n,t){const o=Oe(n,t,e)>.5;let i=U[0];for(const a of U)(o?n[a]<n[i]:n[a]>n[i])&&(i=a);return i}const wt={"accent.hover":"text"};function Et(e,n){const t=new Map;try{const o=de(n,e),i=(a,u,d,m)=>{const A=ke(u),k=A?je(m,A):null,y=k===null?null:W(k),T=t.get(a)??[];T.some(_=>_.source===u&&_.chroma===y?.c)||(T.push({source:u,where:d,chroma:y?.c}),t.set(a,T))};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=st(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 X(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 Ke(e,n,t,o={}){const i={},a={};for(const[u,d]of Object.entries(o.explicitMappings??{}))d!==void 0&&(a[u]=d.lightness);for(const u of se){const d=e[u];if(d!==void 0)for(const[m,A]of Object.entries(Se[u])){const k=Tt[`${u}.${m}`];let y=X(d,m),T=!1;if(y===void 0){k&&(y=X(e[k.role],k.slot),y??=t[Ot[k.role]]?.source,T=y!==void 0);const _=wt[`${u}.${m}`];_!==void 0&&(y??=X(d,_)),y??=X(d,"color")}if(y!==void 0)for(const[_,z]of A){let H=z;if(Mt.has(`${u}.${m}`))H=ze(n,o.actionSurfaceContrast?s=>o.actionSurfaceContrast(y,s):void 0,o.actionSurfaceSeparation?s=>o.actionSurfaceSeparation(y,s):void 0);else if(T&&k){const s=Ue[_],r=(s&&a[s.bg])??ze(n,o.actionSurfaceContrast?c=>o.actionSurfaceContrast(X(d,"color"),c):void 0,o.actionSurfaceSeparation?c=>o.actionSurfaceSeparation(X(d,"color"),c):void 0);H=vt(r,n,o.tones??{})}i[_]={source:y,lightness:H}}}}return i}const Ue={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}},K=["background","layer1","layer2","layer3","layer4","actionBackground","actionText","border","shadow","text","typeOverline","typeLabel","typeLead","typeCaption","dangerText","headings","headingsHover","link","linkHover","linkHoverBg","inputCaret","inputSelection","inputSelectionBg"];function rn(e){return typeof e=="string"&&K.includes(e)}const Bt=["typeOverline","typeLabel","typeLead","typeCaption"],Ae=["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"],_t=["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"],Ge="tone:";function Me(e){if(typeof e!="string"||!e.startsWith(Ge))return null;const n=e.slice(Ge.length);return M(n)&&j.test(n)?n:null}function te(e){return typeof e!="string"?!1:U.includes(e)}function Oe(e,n,t){if(te(t))return e[t];const o=Me(t);return o===null?e.surface:n?.[o]??e.surface}const Lt={surface:.99,raised1:.97,raised2:.9,raised3:.8,raised4:.72,accent:.5,muted:.45,text:.35,border:.3,ink:.25,shadow:.2},It={surface:.15,raised1:.2,raised2:.3,raised3:.4,raised4:.36,accent:.6,muted:.75,text:.85,border:.7,ink:.95,shadow:.6},Te={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:"raised3"},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"}},Y=.4;function Ce(){const e={};for(const n of K)e[n]={min:0,max:Y};return e}const Ve={seedColor:"oklch(0.7 0.125 216)",fontBody:"",fontHeadings:"",fontBrand:"",fontMonospace:"",fontWeightBody:"normal",fontWeightHeadings:"bold",fontWeightBrand:"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:{...Te},explicitMappingTokens:[],anchors:{},roles:{},contexts:{},dataPalette:{...be},dataRamps:{}},Re={...Ve,chroma:Ce(),semanticMappings:{...Te},anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...be},dataRamps:{},lightness:{...Lt}},Je={...Ve,chroma:Ce(),semanticMappings:{...Te},anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...be},dataRamps:{},lightness:{...It}},le=new WeakMap;le.set(Re,new Set),le.set(Je,new Set);function Nt(e,n){return lt.has(e)?void 0:n}function pe(e){const n=e.explicitMappingTokens;if(!Array.isArray(n)||n.some(o=>typeof o!="string"||!K.includes(o)))return;const t=new Set(n);if(t.size===n.length&&!(t.size>0&&(!L(e.semanticMappings)||[...t].some(o=>!Object.prototype.hasOwnProperty.call(e.semanticMappings,o)))))return t}function Ye(e){return K.filter(n=>e.has(n))}function an(e){return`--esp-color-${e.replace(/([A-Z])/g,"-$1").replace(/(\d)/g,"-$1").toLowerCase()}`}function Ht(e){try{const n=qe(e),t=JSON.parse(n,Nt);return typeof t!="object"||t===null||Array.isArray(t)?null:t}catch{return null}}const ve="\xEF\xBB\xBF";function Pt(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 qe(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 we(e){return Pt(JSON.stringify(e))}function Dt(e){const n={};for(const t of ee){const o=e[t];typeof o=="string"&&(n[t]=o.startsWith("anchor:")?o:re(o))}return n}function re(e){if(ht(e))return e;const n=W(e);return n?ce(n):e}function Xe(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 Ee(e){const n={};if(!L(e))return n;for(const[t,o]of Object.entries(e))M(t)&&j.test(t)&&!te(t)&&typeof o=="number"&&Number.isFinite(o)&&o>=0&&o<=1&&(n[t]=o);return n}function Ft(e,n){return{...Ee(e),...Ee(n)}}function Wt(e,n){const t={...e};if(!L(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 Ze(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const n=e,t={};for(const o of se){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=Ee(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)||!K.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)&&Me(d)===null||(o[i]={source:u,lightness:d}))}Object.keys(o).length>0&&(t.semanticMappings=o)}return t}function jt(e,n){const t={};for(const[o,i]of Object.entries(e)){if(!M(o)||!j.test(o))continue;const a=Ze(i);a&&(t[o]=a)}if(!n)return t;for(const[o,i]of Object.entries(n)){if(!M(o)||!j.test(o)||i===void 0)continue;const a=Ze(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 L(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function F(e){const n={};for(const[t,o]of Object.entries(e))o!==void 0&&M(t)&&(n[t]=o);return n}function Qe(e){if(!L(e))return e;const n=F(e);return L(e.lightness)&&(n.lightness=F(e.lightness)),L(e.tones)&&(n.tones=F(e.tones)),n}function zt(e,n){const t={};for(const[o,i]of Object.entries(e))M(o)&&(t[o]=Qe(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(!L(a)||!L(i)){t[o]=Qe(i);continue}const u={...F(a),...F(i)};L(a.lightness)&&L(i.lightness)?u.lightness={...F(a.lightness),...F(i.lightness)}:L(i.lightness)&&(u.lightness=F(i.lightness)),L(a.tones)&&L(i.tones)?u.tones={...F(a.tones),...F(i.tones)}:L(i.tones)&&(u.tones=F(i.tones)),L(a.semanticMappings)&&L(i.semanticMappings)?u.semanticMappings={...F(a.semanticMappings),...F(i.semanticMappings)}:L(i.semanticMappings)&&(u.semanticMappings=F(i.semanticMappings)),t[o]=u}return t}function Kt(e){const n={};for(const[t,o]of Object.entries(e)){if(!M(t))continue;if(typeof o=="string"){n[t]=re(o);continue}const i={};for(const[a,u]of Object.entries(o))M(a)&&(i[a]=typeof u=="string"?re(u):u);n[t]=i}return n}function ie(e){return typeof e!="string"?"":e.startsWith("anchor:")?e:re(e)}function Ut(e){const n={};for(const t of fe)n[t]=ie(e[t]);return n}function et(e,n){const t={};for(const[o,i]of Object.entries(e))M(o)&&j.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)||!j.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 Gt(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:ie(o.source)};continue}if(o.type==="diverging"&&typeof o.start=="string"&&typeof o.end=="string"){n[t]={...o,start:ie(o.start),end:ie(o.end),...typeof o.neutral=="string"?{neutral:ie(o.neutral)}:{}};continue}n[t]={...o}}return n}function tt(e){const n=W(e.seedColor);if(!n)return;const t=ye(n,e);return(o,i)=>{const a=ue(o,t,e.anchors)??t.primary,u=e.chroma.actionBackground,d=ae(a,e.lightness[i],u.min,u.max),m={l:d.l>.5?0:1,c:0,h:0};return Math.abs(pt(m,d))}}function Vt(e,n,t){if(n?.background)return n.background;const o=X(e.canvas,"color");if(o!==void 0){const i=Se.canvas.color?.find(([a])=>a==="background");if(i)return{source:o,lightness:i[1]}}return t.background}function nt(e,n){const t=W(e.seedColor);if(!t||!n)return;const o=ye(t,e),i=ue(n.source,o,e.anchors)??o.primary,a=e.chroma.background,u=ae(i,Oe(e.lightness,e.tones,n.lightness),a.min,a.max);return(d,m)=>{const A=ue(d,o,e.anchors)??o.primary,k=e.chroma.actionBackground,y=ae(A,e.lightness[m],k.min,k.max);return dt(y,u)}}function Jt(e){const n=le.get(e);if(n)return new Set(n);const t=pe(e);if(t)return t;const o=new Set,i=Ke(e.roles,e.lightness,e.semanticMappings,{tones:e.tones,actionSurfaceContrast:tt(e),actionSurfaceSeparation:nt(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 de(e,n){const t={...e.roles,...n.roles},o=jt(e.contexts,n.contexts),i=Wt(e.lightness,n.lightness),a=Ft(e.tones,n.tones),u=Kt(Xe(e.anchors,n.anchors)),d=typeof n.seedColor=="string"?re(n.seedColor):e.seedColor,m=n.semanticMappings,A={...e.angles,...n.angles},k={...e.semanticHues,...n.semanticHues},y={...e.variantChroma,...n.variantChroma},T=Dt({...e.intents,...n.intents}),_=n.chroma,z=ne(e.chroma,_),H=Ut(ne(e.dataPalette,n.dataPalette)),s=Gt(et(e.dataRamps,n.dataRamps)),r=Jt(e),c=new Set(r),l=pe(n),p={};for(const x of r)p[x]=e.semanticMappings[x];for(const[x,O]of Object.entries(m??{}))O!==void 0&&(l===void 0||l.has(x)?(c.add(x),p[x]=O):(c.delete(x),delete p[x]));const g=ne(e.semanticMappings,m),f={angles:A,anchors:u,chroma:z,intents:T,lightness:i,tones:a,seedColor:d,semanticHues:k,variantChroma:y},h=tt(f),$=nt(f,Vt(t,p,g)),b=Ke(t,i,g,{explicitMappings:p,tones:a,actionSurfaceContrast:h,actionSurfaceSeparation:$}),R={};for(const[x,O]of Object.entries(b))c.has(x)||(R[x]=O);const C={};for(const x of Bt)!c.has(x)&&R[x]===void 0&&(C[x]={source:g.text.source,lightness:g.text.lightness},_?.text!==void 0&&_[x]===void 0&&(z[x]={...z.text}));const E=ne(ne(ne(e.semanticMappings,C),R),m),S={...e,seedColor:d,fontBody:n.fontBody??e.fontBody,fontHeadings:n.fontHeadings??e.fontHeadings,fontBrand:n.fontBrand??e.fontBrand,fontMonospace:n.fontMonospace??e.fontMonospace,fontWeightBody:String(n.fontWeightBody??e.fontWeightBody),fontWeightHeadings:String(n.fontWeightHeadings??e.fontWeightHeadings),fontWeightBrand:String(n.fontWeightBrand??e.fontWeightBrand),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:A,semanticHues:k,variantChroma:y,intents:T,lightness:i,tones:a,chroma:z,semanticMappings:E,explicitMappingTokens:Ye(c),anchors:u,roles:t,contexts:o,dataPalette:H,dataRamps:s};return n.pageBackgroundImage!==void 0&&(S.pageBackgroundImage=n.pageBackgroundImage),n.pageBackgroundImageOpacity!==void 0&&(S.pageBackgroundImageOpacity=n.pageBackgroundImageOpacity),n.boxBackgroundImage!==void 0&&(S.boxBackgroundImage=n.boxBackgroundImage),n.boxBackgroundImageOpacity!==void 0&&(S.boxBackgroundImageOpacity=n.boxBackgroundImageOpacity),n.vellumOpacity!==void 0&&(S.vellumOpacity=n.vellumOpacity),n.vellumBackgroundImage!==void 0&&(S.vellumBackgroundImage=n.vellumBackgroundImage),n.vellumBackgroundImageOpacity!==void 0&&(S.vellumBackgroundImageOpacity=n.vellumBackgroundImageOpacity),le.set(S,new Set(c)),S}const ot=new WeakMap;function st(e,n){const t=e.contexts&&Object.prototype.hasOwnProperty.call(e.contexts,n)?e.contexts[n]:void 0;if(!t)return null;let o=ot.get(e);const i=o?.get(n);if(i)return i;const a={};for(const d of se){const m=t[d];m!==void 0&&(a[d]=m)}const u=de(e,{lightness:t.lightness,tones:t.tones,roles:a,semanticMappings:t.semanticMappings});return o||(o=new Map,ot.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=qe(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 cn(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","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","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 l=e[s];r!==void 0&&l<r&&t.push(`${s} must be \u2265 ${r} (got ${l}).`),c!==void 0&&l>c&&o.push(`${s} = ${l} 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 _t)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>Y&&o.push(`variantChroma["${r}"] = ${c} exceeds ${Y}.`)}}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 l of Object.keys(c))(!M(l)||!te(l))&&t.push(`${r}.${l} is not a built-in lightness stop; expected one of: ${U.join(", ")}.`);for(const l of U)if(l in c)if(typeof c[l]!="number"||!isFinite(c[l]))t.push(`${r}.${l} must be a finite number.`);else{const p=c[l];(p<0||p>1)&&t.push(`${r}.${l} must be 0\u20131 (got ${p}).`)}}"lightness"in e&&d(e.lightness,"lightness");function m(s,r){const c=new Set;if(!L(s))return t.push(`${r} must be an object.`),c;for(const[l,p]of Object.entries(s)){if(!M(l)||!j.test(l)){t.push(`${r}.${l} must be a lowercase slug matching ${j.source}.`);continue}if(te(l)){t.push(`${r}.${l} conflicts with the built-in "${l}" lightness stop; choose a distinct custom tone name.`);continue}c.add(l),typeof p!="number"||!Number.isFinite(p)?t.push(`${r}.${l} must be a finite number.`):(p<0||p>1)&&t.push(`${r}.${l} must be 0\u20131 (got ${p}).`)}return c}const A=new Set(Object.keys(n.tones??{}));if("tones"in e)for(const s of m(e.tones,"tones"))A.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=Et(e,n);for(const c of K)if(c in s){const l=s[c];if(typeof l!="object"||l===null){t.push(`chroma.${c} must be { min, max }.`);continue}const p=l;for(const f of r.get(c)??[])f.chroma!==void 0&&typeof p.min=="number"&&typeof p.max=="number"&&(f.chroma<p.min-1e-9||f.chroma>p.max+1e-9)&&o.push(`chroma.${c} clamps the anchor-sourced token ${c} ("${f.source}", effective in ${f.where}) and moves it off its declared swatch. Remove the band if that is unintended \u2014 anchors otherwise keep their own chroma.`);const g=l;(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>Y)&&t.push(`chroma.${c}.max must be 0\u2013${Y}.`),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)?j.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.`),Ae.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[l,p]of Object.entries(c))M(l)?l!=="color"&&!j.test(l)&&t.push(`anchors.${s}: "${l}" is not a valid slot name; use a lowercase slug.`):t.push(`anchors.${s}: "${l}" is a reserved JavaScript property name and cannot be a slot name; rename it.`),typeof p!="string"?t.push(`anchors.${s}.${l} must be a CSS color string.`):W(p)||t.push(`anchors.${s}.${l} 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 k=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))k.set(s,r);function y(s,r){const c=ke(s);if(!c){t.push(`${r} "${s}" is not valid anchor syntax; use anchor:<name> or anchor:<name>.<slot>.`);return}if(!k.has(c.name)){const l=[...k.keys()];t.push(`${r} references undeclared anchor "${c.name}". Declared anchors: ${l.length>0?l.join(", "):"(none)"}.`);return}if(c.slot!==void 0){const l=k.get(c.name);if(typeof(typeof l=="object"&&l!==null&&!Array.isArray(l)?l[c.slot]:void 0)!="string"){const g=typeof l=="object"&&l!==null?Object.keys(l).filter(f=>f!=="color"):[];t.push(`${r} references unknown slot "${c.slot}" on anchor "${c.name}". Declared slots: ${g.length>0?g.join(", "):"(none)"}.`)}}}function T(s,r){if(s.startsWith("anchor:")){y(s,r);return}Ae.includes(s)||t.push(`${r} must be one of: ${Ae.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:")){y(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 _(s,r){if(s.startsWith("anchor:")){y(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(!fe.includes(r)){t.push(`dataPalette.${r} is not a series slot; expected one of: ${fe.join(", ")}.`);continue}typeof c!="string"?t.push(`dataPalette.${r} must be a CSS color or anchor reference string.`):_(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)?j.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,l=c.steps??St;if((typeof l!="number"||!Number.isInteger(l)||l<xe||l>$e)&&t.push(`dataRamps.${s}.steps must be an integer from ${xe} through ${$e}.`),c.type==="sequential"){typeof c.source!="string"?t.push(`dataRamps.${s}.source must be a CSS color or anchor reference string.`):_(c.source,`dataRamps.${s}.source`);const p=c.lightnessStart??.95,g=c.lightnessEnd??.25;for(const[f,h]of[["lightnessStart",p],["lightnessEnd",g]])(typeof h!="number"||!Number.isFinite(h)||h<0||h>1)&&t.push(`dataRamps.${s}.${f} 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 l=="number"&&Number.isInteger(l)&&l>=xe&&l<=$e&&(p-g)/(l-1)<=We&&t.push(`dataRamps.${s} lightness bounds must leave more than ${We} lightness between serialized stops.`);continue}if(c.type==="diverging"){typeof l=="number"&&Number.isInteger(l)&&l%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.`):_(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.`):_(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=de(Re,e),r={};let c=!0;for(const l of fe){const p=At(s.dataPalette[l],s.anchors);if(!p){c=!1;break}r[l]=p}if(c)for(const l of xt(r))o.push(kt(l))}function z(s,r){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const c=s;for(const[l,p]of Object.entries(c)){const g=`${r}.${l}`;if(!se.includes(l)){t.push(`${g} is not a role; expected one of: ${se.join(", ")}. (The status family is reserved and is not a role.)`);continue}const f=l,h=Se[f];if(typeof p=="string"){T(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 $=p;typeof $.color!="string"&&t.push(`${g} must declare its base "color".`);for(const[b,R]of Object.entries($)){if(!Object.prototype.hasOwnProperty.call(h,b)||!M(b)){const C=Object.keys(h).filter(E=>E!=="color");t.push(`${g}.${b} is not a slot of the ${f} role. Declared slots: ${C.length>0?C.join(", "):"(none)"}.`);continue}typeof R!="string"?t.push(`${g}.${b} must be a color source string.`):T(R,`${g}.${b}`)}}}if("roles"in e&&z(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)||!j.test(s)){t.push(`contexts.${s} must be a lowercase slug matching ${j.source}.`);continue}if(typeof r!="object"||r===null||Array.isArray(r)){z(r,`contexts.${s}`);continue}const c=r,l=Object.fromEntries(Object.entries(c).filter(([g])=>g!=="lightness"&&g!=="tones"&&g!=="semanticMappings"));z(l,`contexts.${s}`),"lightness"in c&&d(c.lightness,`contexts.${s}.lightness`);const p=new Set(A);if("tones"in c)for(const g of m(c.tones,`contexts.${s}.tones`))p.add(g);"semanticMappings"in c&&H(c.semanticMappings,`contexts.${s}.semanticMappings`,p)}function H(s,r,c){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const l=s;for(const p of Object.keys(l))K.includes(p)||t.push(`${r}.${p} is not a semantic token; expected one of: ${K.join(", ")}.`);for(const p of K)if(p in l){const g=l[p];if(typeof g!="object"||g===null){t.push(`${r}.${p} must be { source, lightness }.`);continue}const f=g;if(typeof f.source!="string"?t.push(`${r}.${p}.source must be a string.`):T(f.source,`${r}.${p}.source`),typeof f.lightness!="string")t.push(`${r}.${p}.lightness must be one of: ${U.join(", ")}, or a declared tone:<name>.`);else if(!te(f.lightness)){const h=Me(f.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 $=[...c].sort();t.push(`${r}.${p}.lightness references undeclared tone "${h}". Declared tones: ${$.length>0?$.join(", "):"(none)"}.`)}}}}if("semanticMappings"in e&&H(e.semanticMappings,"semanticMappings",A),"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=L(e.semanticMappings)?e.semanticMappings:void 0;for(const c of e.explicitMappingTokens){if(typeof c!="string"||!K.includes(c)){t.push(`explicitMappingTokens entries must be one of: ${K.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(...Yt(e,n)),{valid:t.length===0,errors:t,warnings:o}}const B=.045;function Yt(e,n){try{return qt(e,n)}catch{return[]}}function qt(e,n){const t=de(n,e),o=at(t),i=[...o],a=new Set(o);for(const u of Object.keys(t.contexts)){const d=st(t,u);if(d)for(const m of at(d))a.has(m)||i.push(`contexts.${u}: ${m}`)}return i}function Xt(e){const n=gt(he(e)),t=yt(n);return mt({r:ge(t.r),g:ge(t.g),b:ge(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 Xt(W(ce(he(e))))}function rt(e){return(Math.floor(e*1e4)/1e4).toFixed(4)}const Q=2,it=1e-4;function at(e){const n=W(e.seedColor);if(!n)return[];const t=ye(n,e),o=e.semanticMappings.actionBackground,i=e.chroma.actionBackground,a=Oe(e.lightness,e.tones,o.lightness),u=(f,h,$,b)=>he(ae(f,h,$,b)),d=ee.map(f=>({name:f,base:t[f]})),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 f=ue(o.source,t,e.anchors);f&&d.push({name:"action",base:f})}const A=Fe(d.map(({name:f,base:h})=>[f,ce(u(h,a,i.min,i.max))]),B,["normal"]);if(A.length===0)return m;const k=new Map,y=(f,h)=>{const $=`${f}:${h}`;let b=k.get($);if(!b){b=[];for(let R=0;R<360;R+=Q)b.push(q({l:f,c:h,h:R}));k.set($,b)}return b},T=B-.002,_=(f,h,$,b)=>{const R=Math.hypot(f.a,f.b),C=Math.atan2(f.b,f.a)*180/Math.PI+180;let E=0;for(const S of $===b?[b]:[$,b]){if(S+R<B-1e-4)continue;let x=C,O=Z(q({l:h,c:S,h:C}),f);if(O>=B)return O;const D=y(h,S);for(let w=0;w<D.length;w+=1){const v=Z(D[w],f);if(v>=B)return v;v>O&&(O=v,x=w*Q)}let P=x;for(let w=x-Q;w<=x+Q;w+=.1){const v=Z(q({l:h,c:S,h:w}),f);if(v>=B)return v;v>O&&(O=v,P=w)}if(O>=T)for(let w=P-.1;w<=P+.1;w+=.001){const v=Z(q({l:h,c:S,h:w}),f);if(v>=B)return v;v>O&&(O=v)}O>E&&(E=O)}return E},z=(f,h,$)=>{const b=h===$?[$]:[h,$];let R=0;for(const C of b)for(const E of b){if(C+E<B-1e-4)continue;const S=y(f,C),x=y(f,E);let O=0,D=0,P=-1;for(let N=0;N<S.length;N+=1)for(let G=0;G<x.length;G+=1){const V=Z(S[N],x[G]);if(V>=B)return V;V>P&&(P=V,O=N*Q,D=G*Q)}const w=(N,G,V,Le)=>{const Ie=[];for(let J=G-V;J<=G+V;J+=Le)Ie.push({h:J,lab:q({l:f,c:E,h:J})});let me=-1,Ne=N,He=G;for(let J=N-V;J<=N+V;J+=Le){const ft=q({l:f,c:C,h:J});for(const Pe of Ie){const De=Z(ft,Pe.lab);De>me&&(me=De,Ne=J,He=Pe.h)}}return{distance:me,hueA:Ne,hueB:He}},v=w(O,D,Q,.1);if(v.distance>=B)return v.distance;let I=Math.max(P,v.distance);if(I>=T){const N=w(v.hueA,v.hueB,.1,.001);if(N.distance>I&&(I=N.distance),I>=B)return I}I>R&&(R=I)}return R},H=f=>ee.includes(f),s=(f,h,$,b,R)=>{const C=q(u(f.base,$,b,R)),E=q(u(h.base,$,b,R));if(Z(C,E)>=B)return{outcome:"direct"};const S=H(f.name)&&H(h.name),x=[f,h].filter(P=>H(P.name)),O=S?"one of them":`"${H(f.name)?f.name:h.name}"`;let D;for(const P of x){const w=_(P===f?E:C,$,b,R);if(w>=B)return{outcome:"retune",target:O};w>=B-it&&(D=D??O)}if(S){const P=z($,b,R);if(P>=B)return{outcome:"retune",target:"both"};P>=B-it&&(D=D??"both")}return D!==void 0?{outcome:"near",target:D}:{outcome:"no"}},r=f=>f.outcome==="direct"?4:f.outcome==="retune"?f.target==="both"?2:3:f.outcome==="near"?1:0,c=f=>[...f].sort().join("|"),l=new Set(Fe(d.map(({name:f,base:h})=>[f,ce(u(h,a,0,Y))]),B,["normal"]).map(f=>c(f.pair))),p=new Map(d.map(f=>[f.name,f])),g=new Map;for(const{pair:f,distance:h}of A){const $=p.get(f[0]),b=p.get(f[1]),R=H($.name)&&H(b.name),C=s($,b,a,i.min,i.max);if(C.outcome==="direct"||C.outcome==="retune"){const I=C.target??(R?"one of them":`"${H($.name)?$.name:b.name}"`);l.has(c(f))?m.push(`Status colors "${f[0]}" and "${f[1]}" are hard to distinguish under normal vision (distance ${rt(h)} < ${B}); status meanings must stay distinguishable \u2014 retune ${I} via intents.`):m.push(`Status colors "${f[0]}" and "${f[1]}" are hard to distinguish as rendered (distance ${rt(h)} < ${B}); the actionBackground chroma band ({ min: ${i.min}, max: ${i.max} }) pushes them together \u2014 widen the band, or retune ${I} via intents.`);continue}const E=s($,b,a,0,Y);let S={outcome:"no"};for(let I=1;I<=19&&S.outcome!=="direct";I+=1){const N=I*.05;if(Math.abs(N-a)<.001)continue;const G=s($,b,N,i.min,i.max);r(G)>r(S)&&(S=G)}let x={outcome:"no"};const O=E.outcome==="direct"||E.outcome==="retune",D=S.outcome==="direct"||S.outcome==="retune";if(!O&&!D)for(let I=1;I<=19&&x.outcome!=="direct";I+=1){const N=s($,b,I*.05,0,Y);r(N)>r(x)&&(x=N)}const P=Zt(E,S,x),w=`${C.outcome}|${P}`;let v=g.get(w);v||(v=[],g.set(w,v)),v.push(f)}for(const[f,h]of g){const $=f.indexOf("|"),b=f.slice(0,$),R=f.slice($+1),C=h.map(([x,O])=>`"${x}"/"${O}"`),E=C.length>1?`${C.slice(0,-1).join(", ")} and ${C[C.length-1]}`:C[0],S=b==="near"?`Status colors ${E} 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 ${E} 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(S+R)}return m}function Zt(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 un(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,Je),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??{})),A=new Set(Object.keys(o.value?.contexts??{})),k=[...A].filter(T=>!m.has(T)).sort(),y=[...m].filter(T=>!A.has(T)).sort();(k.length>0||y.length>0)&&u.push(`contexts must declare the same names in both schemes. Missing from light: ${k.join(", ")||"(none)"}. Missing from dark: ${y.join(", ")||"(none)"}.`)}return{valid:u.length===0,errors:u,warnings:d}}const Qt=["anchors","angles","contexts","dataPalette","dataRamps","intents","roles","chroma","lightness","tones","semanticHues","semanticMappings","variantChroma"];function en(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 Qt){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]=Xe(u,d);continue}if(a==="contexts"){t[a]=zt(u,d);continue}if(a==="dataRamps"){t[a]=et(u,d);continue}const m={};for(const[A,k]of Object.entries(u))M(A)&&(m[A]=k);for(const[A,k]of Object.entries(d))k!==void 0&&M(A)&&(m[A]=k);t[a]=m}}const o=pe(e),i=pe(n);if(o!==void 0||i!==void 0){const a=o??new Set(Object.keys(e.semanticMappings??{}).filter(u=>K.includes(u)));for(const u of Object.keys(n.semanticMappings??{}))i===void 0||i.has(u)?a.add(u):a.delete(u);t.explicitMappingTokens=Ye(a)}return t}function fn(...e){let n={};for(const t of e){if(!t)continue;const o=Ht(t);o&&(n=en(n,o))}return we(n)}function ct(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r")}const ut={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 ln(e){return we({...ut,pageBackgroundImage:`url("${ct(e)}")`,pageBackgroundImageOpacity:.5})}function pn(e){return we({...ut,pageBackgroundImage:`url("${ct(e)}")`,pageBackgroundImageOpacity:.55})}export{j as ANCHOR_SLUG_PATTERN,Ae as COLOR_SOURCES,It as DEFAULT_DARK_LIGHTNESS,Je as DEFAULT_DARK_THEME,Lt as DEFAULT_LIGHT_LIGHTNESS,Re as DEFAULT_LIGHT_THEME,Te as DEFAULT_SEMANTIC_MAPPINGS,U as LIGHTNESS_KEYS,Qt as NESTED_THEME_KEYS,se as ROLE_NAMES,Tt as ROLE_PAIRED_INK,Se as ROLE_TOKEN_PLAN,K as SEMANTIC_COLOR_NAMES,ee as STATUS_COLOR_SOURCES,Ue as TOKEN_PAIRINGS,_t as VARIANT_COLOR_SOURCES,pn as buildTaprootDarkTheme,ln as buildTaprootLightTheme,Ke as compileRoles,we as encodeTheme,Jt as explicitMappingTokens,te as isLightnessKey,L as isObjectRecord,rn as isSemanticColorName,fn as layerThemes,en as mergePartials,de as mergeTheme,ke as parseAnchorSource,Ht as parseTheme,je as resolveAnchorColor,st as resolveContextTheme,At as resolveDataColorSource,Oe as resolveLightnessReference,an as semanticToCSS,Me as toneReferenceName,cn as validateTheme,un as validateThemePair};
|
|
1
|
+
import{UNSAFE_KEYS as dt,isSafeKey as M}from"./unsafe-keys.js";import{ACCEPTED_COLOR_FORMS as oe,apcaContrast as mt,clampChannel as ge,deltaEOK as gt,deriveSemantic as ae,gamutMapToSRGB as he,linearRgbToOklab as ht,oklchToSRGB as yt,parseCssColor as W,parseOklch as bt,serializeOklch as ce,srgbToLinearRGB as $t}from"./color-engine.js";import{computeVariants as ye,parseAnchorSource as xt,resolveAnchorColor as kt,resolveMappingSource as ue}from"./variant-engine.js";import{auditColorDistances as Fe,auditDataPalette as St,describePaletteCollision as At,DATA_SERIES_KEYS as fe,DEFAULT_DATA_PALETTE as be,DEFAULT_DATA_RAMP_STEPS as Mt,MAX_DATA_RAMP_STEPS as $e,MIN_DATA_RAMP_LIGHTNESS_STEP as We,MIN_DATA_RAMP_STEPS as xe}from"./data-colors.js";const j=/^[a-z][a-z0-9-]*$/;function ke(e){return xt(e)}function je(e,n){return kt(e,n)}function Ot(e,n){const t=ke(e);if(t){const o=je(n,t);return o&&W(o)?o:null}return W(e)?e:null}const se=["canvas","ink","accent","action","structure"],Se={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"]]}},Tt=new Set(["action.color"]),Ct={canvas:"background",ink:"text",accent:"link",action:"actionBackground",structure:"border"},Rt={"action.ink":{role:"canvas",slot:"color"}},vt=.45,Et=.045;function ze(e,n,t){const o=Ue.actionText,i=[...U].sort((y,T)=>e[y]-e[T]||U.indexOf(y)-U.indexOf(T)),a=n?i.filter(y=>n(y)>=o.targetLc):i,u=t?a.filter(y=>t(y)>=Et):a,d=u.length>0?u:a,m=d.length>0?d:i;let A,k=1/0;for(const y of m){const T=Math.abs(e[y]-vt);T<k&&(k=T,A=y)}return A??"muted"}function wt(e,n,t){const o=Oe(n,t,e)>.5;let i=U[0];for(const a of U)(o?n[a]<n[i]:n[a]>n[i])&&(i=a);return i}const Bt={"accent.hover":"text"};function _t(e,n){const t=new Map;try{const o=de(n,e),i=(a,u,d,m)=>{const A=ke(u),k=A?je(m,A):null,y=k===null?null:W(k),T=t.get(a)??[];T.some(_=>_.source===u&&_.chroma===y?.c)||(T.push({source:u,where:d,chroma:y?.c}),t.set(a,T))};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=it(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 X(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 Ke(e,n,t,o={}){const i={},a={};for(const[u,d]of Object.entries(o.explicitMappings??{}))d!==void 0&&(a[u]=d.lightness);for(const u of se){const d=e[u];if(d!==void 0)for(const[m,A]of Object.entries(Se[u])){const k=Rt[`${u}.${m}`];let y=X(d,m),T=!1;if(y===void 0){k&&(y=X(e[k.role],k.slot),y??=t[Ct[k.role]]?.source,T=y!==void 0);const _=Bt[`${u}.${m}`];_!==void 0&&(y??=X(d,_)),y??=X(d,"color")}if(y!==void 0)for(const[_,z]of A){let H=z;if(Tt.has(`${u}.${m}`))H=ze(n,o.actionSurfaceContrast?s=>o.actionSurfaceContrast(y,s):void 0,o.actionSurfaceSeparation?s=>o.actionSurfaceSeparation(y,s):void 0);else if(T&&k){const s=Ue[_],r=(s&&a[s.bg])??ze(n,o.actionSurfaceContrast?c=>o.actionSurfaceContrast(X(d,"color"),c):void 0,o.actionSurfaceSeparation?c=>o.actionSurfaceSeparation(X(d,"color"),c):void 0);H=wt(r,n,o.tones??{})}i[_]={source:y,lightness:H}}}}return i}const Ue={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}},K=["background","layer1","layer2","layer3","layer4","actionBackground","actionText","border","shadow","text","typeOverline","typeLabel","typeLead","typeCaption","dangerText","headings","headingsHover","link","linkHover","linkHoverBg","inputCaret","inputSelection","inputSelectionBg"];function cn(e){return typeof e=="string"&&K.includes(e)}const Lt=["typeOverline","typeLabel","typeLead","typeCaption"],Ae=["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"],It=["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"],Ge="tone:";function Me(e){if(typeof e!="string"||!e.startsWith(Ge))return null;const n=e.slice(Ge.length);return M(n)&&j.test(n)?n:null}function te(e){return typeof e!="string"?!1:U.includes(e)}function Oe(e,n,t){if(te(t))return e[t];const o=Me(t);return o===null?e.surface:n?.[o]??e.surface}const Nt={surface:.99,raised1:.97,raised2:.9,raised3:.8,raised4:.72,accent:.5,muted:.45,text:.35,border:.3,ink:.25,shadow:.2},Ht={surface:.15,raised1:.2,raised2:.3,raised3:.4,raised4:.36,accent:.6,muted:.75,text:.85,border:.7,ink:.95,shadow:.6},Te={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:"raised3"},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"}},Y=.4;function Ce(){const e={};for(const n of K)e[n]={min:0,max:Y};return e}const Ve="system-ui, sans-serif",Je="monospace",Ye={seedColor:"oklch(0.7 0.125 216)",fontBody:Ve,fontHeadings:"",fontBrand:"",fontMonospace:Je,fontWeightBody:"normal",fontWeightHeadings:"bold",fontWeightBrand:"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:{...Te},explicitMappingTokens:[],anchors:{},roles:{},contexts:{},dataPalette:{...be},dataRamps:{}},Re={...Ye,chroma:Ce(),semanticMappings:{...Te},anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...be},dataRamps:{},lightness:{...Nt}},qe={...Ye,chroma:Ce(),semanticMappings:{...Te},anchors:{},roles:{},contexts:{},tones:{},dataPalette:{...be},dataRamps:{},lightness:{...Ht}},le=new WeakMap;le.set(Re,new Set),le.set(qe,new Set);function Pt(e,n){return dt.has(e)?void 0:n}function pe(e){const n=e.explicitMappingTokens;if(!Array.isArray(n)||n.some(o=>typeof o!="string"||!K.includes(o)))return;const t=new Set(n);if(t.size===n.length&&!(t.size>0&&(!L(e.semanticMappings)||[...t].some(o=>!Object.prototype.hasOwnProperty.call(e.semanticMappings,o)))))return t}function Xe(e){return K.filter(n=>e.has(n))}function un(e){return`--esp-color-${e.replace(/([A-Z])/g,"-$1").replace(/(\d)/g,"-$1").toLowerCase()}`}function Dt(e){try{const n=Ze(e),t=JSON.parse(n,Pt);return typeof t!="object"||t===null||Array.isArray(t)?null:t}catch{return null}}const ve="\xEF\xBB\xBF";function Ft(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 Ze(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 Ft(JSON.stringify(e))}function Wt(e){const n={};for(const t of ee){const o=e[t];typeof o=="string"&&(n[t]=o.startsWith("anchor:")?o:re(o))}return n}function re(e){if(bt(e))return e;const n=W(e);return n?ce(n):e}function Qe(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(!L(e))return n;for(const[t,o]of Object.entries(e))M(t)&&j.test(t)&&!te(t)&&typeof o=="number"&&Number.isFinite(o)&&o>=0&&o<=1&&(n[t]=o);return n}function jt(e,n){return{...we(e),...we(n)}}function zt(e,n){const t={...e};if(!L(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 et(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const n=e,t={};for(const o of se){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)||!K.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)&&Me(d)===null||(o[i]={source:u,lightness:d}))}Object.keys(o).length>0&&(t.semanticMappings=o)}return t}function Kt(e,n){const t={};for(const[o,i]of Object.entries(e)){if(!M(o)||!j.test(o))continue;const a=et(i);a&&(t[o]=a)}if(!n)return t;for(const[o,i]of Object.entries(n)){if(!M(o)||!j.test(o)||i===void 0)continue;const a=et(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 L(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function F(e){const n={};for(const[t,o]of Object.entries(e))o!==void 0&&M(t)&&(n[t]=o);return n}function tt(e){if(!L(e))return e;const n=F(e);return L(e.lightness)&&(n.lightness=F(e.lightness)),L(e.tones)&&(n.tones=F(e.tones)),n}function Ut(e,n){const t={};for(const[o,i]of Object.entries(e))M(o)&&(t[o]=tt(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(!L(a)||!L(i)){t[o]=tt(i);continue}const u={...F(a),...F(i)};L(a.lightness)&&L(i.lightness)?u.lightness={...F(a.lightness),...F(i.lightness)}:L(i.lightness)&&(u.lightness=F(i.lightness)),L(a.tones)&&L(i.tones)?u.tones={...F(a.tones),...F(i.tones)}:L(i.tones)&&(u.tones=F(i.tones)),L(a.semanticMappings)&&L(i.semanticMappings)?u.semanticMappings={...F(a.semanticMappings),...F(i.semanticMappings)}:L(i.semanticMappings)&&(u.semanticMappings=F(i.semanticMappings)),t[o]=u}return t}function Gt(e){const n={};for(const[t,o]of Object.entries(e)){if(!M(t))continue;if(typeof o=="string"){n[t]=re(o);continue}const i={};for(const[a,u]of Object.entries(o))M(a)&&(i[a]=typeof u=="string"?re(u):u);n[t]=i}return n}function ie(e){return typeof e!="string"?"":e.startsWith("anchor:")?e:re(e)}function Vt(e){const n={};for(const t of fe)n[t]=ie(e[t]);return n}function nt(e,n){const t={};for(const[o,i]of Object.entries(e))M(o)&&j.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)||!j.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 Jt(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:ie(o.source)};continue}if(o.type==="diverging"&&typeof o.start=="string"&&typeof o.end=="string"){n[t]={...o,start:ie(o.start),end:ie(o.end),...typeof o.neutral=="string"?{neutral:ie(o.neutral)}:{}};continue}n[t]={...o}}return n}function ot(e){const n=W(e.seedColor);if(!n)return;const t=ye(n,e);return(o,i)=>{const a=ue(o,t,e.anchors)??t.primary,u=e.chroma.actionBackground,d=ae(a,e.lightness[i],u.min,u.max),m={l:d.l>.5?0:1,c:0,h:0};return Math.abs(mt(m,d))}}function Yt(e,n,t){if(n?.background)return n.background;const o=X(e.canvas,"color");if(o!==void 0){const i=Se.canvas.color?.find(([a])=>a==="background");if(i)return{source:o,lightness:i[1]}}return t.background}function st(e,n){const t=W(e.seedColor);if(!t||!n)return;const o=ye(t,e),i=ue(n.source,o,e.anchors)??o.primary,a=e.chroma.background,u=ae(i,Oe(e.lightness,e.tones,n.lightness),a.min,a.max);return(d,m)=>{const A=ue(d,o,e.anchors)??o.primary,k=e.chroma.actionBackground,y=ae(A,e.lightness[m],k.min,k.max);return gt(y,u)}}function qt(e){const n=le.get(e);if(n)return new Set(n);const t=pe(e);if(t)return t;const o=new Set,i=Ke(e.roles,e.lightness,e.semanticMappings,{tones:e.tones,actionSurfaceContrast:ot(e),actionSurfaceSeparation:st(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 de(e,n){const t={...e.roles,...n.roles},o=Kt(e.contexts,n.contexts),i=zt(e.lightness,n.lightness),a=jt(e.tones,n.tones),u=Gt(Qe(e.anchors,n.anchors)),d=typeof n.seedColor=="string"?re(n.seedColor):e.seedColor,m=n.semanticMappings,A={...e.angles,...n.angles},k={...e.semanticHues,...n.semanticHues},y={...e.variantChroma,...n.variantChroma},T=Wt({...e.intents,...n.intents}),_=n.chroma,z=ne(e.chroma,_),H=Vt(ne(e.dataPalette,n.dataPalette)),s=Jt(nt(e.dataRamps,n.dataRamps)),r=qt(e),c=new Set(r),l=pe(n),p={};for(const x of r)p[x]=e.semanticMappings[x];for(const[x,O]of Object.entries(m??{}))O!==void 0&&(l===void 0||l.has(x)?(c.add(x),p[x]=O):(c.delete(x),delete p[x]));const g=ne(e.semanticMappings,m),f={angles:A,anchors:u,chroma:z,intents:T,lightness:i,tones:a,seedColor:d,semanticHues:k,variantChroma:y},h=ot(f),$=st(f,Yt(t,p,g)),b=Ke(t,i,g,{explicitMappings:p,tones:a,actionSurfaceContrast:h,actionSurfaceSeparation:$}),R={};for(const[x,O]of Object.entries(b))c.has(x)||(R[x]=O);const C={};for(const x of Lt)!c.has(x)&&R[x]===void 0&&(C[x]={source:g.text.source,lightness:g.text.lightness},_?.text!==void 0&&_[x]===void 0&&(z[x]={...z.text}));const w=ne(ne(ne(e.semanticMappings,C),R),m),S={...e,seedColor:d,fontBody:n.fontBody||e.fontBody||Ve,fontHeadings:n.fontHeadings??e.fontHeadings,fontBrand:n.fontBrand??e.fontBrand,fontMonospace:n.fontMonospace||e.fontMonospace||Je,fontWeightBody:String(n.fontWeightBody??e.fontWeightBody),fontWeightHeadings:String(n.fontWeightHeadings??e.fontWeightHeadings),fontWeightBrand:String(n.fontWeightBrand??e.fontWeightBrand),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:A,semanticHues:k,variantChroma:y,intents:T,lightness:i,tones:a,chroma:z,semanticMappings:w,explicitMappingTokens:Xe(c),anchors:u,roles:t,contexts:o,dataPalette:H,dataRamps:s};return n.pageBackgroundImage!==void 0&&(S.pageBackgroundImage=n.pageBackgroundImage),n.pageBackgroundImageOpacity!==void 0&&(S.pageBackgroundImageOpacity=n.pageBackgroundImageOpacity),n.boxBackgroundImage!==void 0&&(S.boxBackgroundImage=n.boxBackgroundImage),n.boxBackgroundImageOpacity!==void 0&&(S.boxBackgroundImageOpacity=n.boxBackgroundImageOpacity),n.vellumOpacity!==void 0&&(S.vellumOpacity=n.vellumOpacity),n.vellumBackgroundImage!==void 0&&(S.vellumBackgroundImage=n.vellumBackgroundImage),n.vellumBackgroundImageOpacity!==void 0&&(S.vellumBackgroundImageOpacity=n.vellumBackgroundImageOpacity),le.set(S,new Set(c)),S}const rt=new WeakMap;function it(e,n){const t=e.contexts&&Object.prototype.hasOwnProperty.call(e.contexts,n)?e.contexts[n]:void 0;if(!t)return null;let o=rt.get(e);const i=o?.get(n);if(i)return i;const a={};for(const d of se){const m=t[d];m!==void 0&&(a[d]=m)}const u=de(e,{lightness:t.lightness,tones:t.tones,roles:a,semanticMappings:t.semanticMappings});return o||(o=new Map,rt.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=Ze(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 fn(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","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","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 l=e[s];r!==void 0&&l<r&&t.push(`${s} must be \u2265 ${r} (got ${l}).`),c!==void 0&&l>c&&o.push(`${s} = ${l} 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 It)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>Y&&o.push(`variantChroma["${r}"] = ${c} exceeds ${Y}.`)}}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 l of Object.keys(c))(!M(l)||!te(l))&&t.push(`${r}.${l} is not a built-in lightness stop; expected one of: ${U.join(", ")}.`);for(const l of U)if(l in c)if(typeof c[l]!="number"||!isFinite(c[l]))t.push(`${r}.${l} must be a finite number.`);else{const p=c[l];(p<0||p>1)&&t.push(`${r}.${l} must be 0\u20131 (got ${p}).`)}}"lightness"in e&&d(e.lightness,"lightness");function m(s,r){const c=new Set;if(!L(s))return t.push(`${r} must be an object.`),c;for(const[l,p]of Object.entries(s)){if(!M(l)||!j.test(l)){t.push(`${r}.${l} must be a lowercase slug matching ${j.source}.`);continue}if(te(l)){t.push(`${r}.${l} conflicts with the built-in "${l}" lightness stop; choose a distinct custom tone name.`);continue}c.add(l),typeof p!="number"||!Number.isFinite(p)?t.push(`${r}.${l} must be a finite number.`):(p<0||p>1)&&t.push(`${r}.${l} must be 0\u20131 (got ${p}).`)}return c}const A=new Set(Object.keys(n.tones??{}));if("tones"in e)for(const s of m(e.tones,"tones"))A.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=_t(e,n);for(const c of K)if(c in s){const l=s[c];if(typeof l!="object"||l===null){t.push(`chroma.${c} must be { min, max }.`);continue}const p=l;for(const f of r.get(c)??[])f.chroma!==void 0&&typeof p.min=="number"&&typeof p.max=="number"&&(f.chroma<p.min-1e-9||f.chroma>p.max+1e-9)&&o.push(`chroma.${c} clamps the anchor-sourced token ${c} ("${f.source}", effective in ${f.where}) and moves it off its declared swatch. Remove the band if that is unintended \u2014 anchors otherwise keep their own chroma.`);const g=l;(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>Y)&&t.push(`chroma.${c}.max must be 0\u2013${Y}.`),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)?j.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.`),Ae.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[l,p]of Object.entries(c))M(l)?l!=="color"&&!j.test(l)&&t.push(`anchors.${s}: "${l}" is not a valid slot name; use a lowercase slug.`):t.push(`anchors.${s}: "${l}" is a reserved JavaScript property name and cannot be a slot name; rename it.`),typeof p!="string"?t.push(`anchors.${s}.${l} must be a CSS color string.`):W(p)||t.push(`anchors.${s}.${l} 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 k=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))k.set(s,r);function y(s,r){const c=ke(s);if(!c){t.push(`${r} "${s}" is not valid anchor syntax; use anchor:<name> or anchor:<name>.<slot>.`);return}if(!k.has(c.name)){const l=[...k.keys()];t.push(`${r} references undeclared anchor "${c.name}". Declared anchors: ${l.length>0?l.join(", "):"(none)"}.`);return}if(c.slot!==void 0){const l=k.get(c.name);if(typeof(typeof l=="object"&&l!==null&&!Array.isArray(l)?l[c.slot]:void 0)!="string"){const g=typeof l=="object"&&l!==null?Object.keys(l).filter(f=>f!=="color"):[];t.push(`${r} references unknown slot "${c.slot}" on anchor "${c.name}". Declared slots: ${g.length>0?g.join(", "):"(none)"}.`)}}}function T(s,r){if(s.startsWith("anchor:")){y(s,r);return}Ae.includes(s)||t.push(`${r} must be one of: ${Ae.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:")){y(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 _(s,r){if(s.startsWith("anchor:")){y(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(!fe.includes(r)){t.push(`dataPalette.${r} is not a series slot; expected one of: ${fe.join(", ")}.`);continue}typeof c!="string"?t.push(`dataPalette.${r} must be a CSS color or anchor reference string.`):_(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)?j.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,l=c.steps??Mt;if((typeof l!="number"||!Number.isInteger(l)||l<xe||l>$e)&&t.push(`dataRamps.${s}.steps must be an integer from ${xe} through ${$e}.`),c.type==="sequential"){typeof c.source!="string"?t.push(`dataRamps.${s}.source must be a CSS color or anchor reference string.`):_(c.source,`dataRamps.${s}.source`);const p=c.lightnessStart??.95,g=c.lightnessEnd??.25;for(const[f,h]of[["lightnessStart",p],["lightnessEnd",g]])(typeof h!="number"||!Number.isFinite(h)||h<0||h>1)&&t.push(`dataRamps.${s}.${f} 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 l=="number"&&Number.isInteger(l)&&l>=xe&&l<=$e&&(p-g)/(l-1)<=We&&t.push(`dataRamps.${s} lightness bounds must leave more than ${We} lightness between serialized stops.`);continue}if(c.type==="diverging"){typeof l=="number"&&Number.isInteger(l)&&l%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.`):_(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.`):_(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=de(Re,e),r={};let c=!0;for(const l of fe){const p=Ot(s.dataPalette[l],s.anchors);if(!p){c=!1;break}r[l]=p}if(c)for(const l of St(r))o.push(At(l))}function z(s,r){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const c=s;for(const[l,p]of Object.entries(c)){const g=`${r}.${l}`;if(!se.includes(l)){t.push(`${g} is not a role; expected one of: ${se.join(", ")}. (The status family is reserved and is not a role.)`);continue}const f=l,h=Se[f];if(typeof p=="string"){T(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 $=p;typeof $.color!="string"&&t.push(`${g} must declare its base "color".`);for(const[b,R]of Object.entries($)){if(!Object.prototype.hasOwnProperty.call(h,b)||!M(b)){const C=Object.keys(h).filter(w=>w!=="color");t.push(`${g}.${b} is not a slot of the ${f} role. Declared slots: ${C.length>0?C.join(", "):"(none)"}.`);continue}typeof R!="string"?t.push(`${g}.${b} must be a color source string.`):T(R,`${g}.${b}`)}}}if("roles"in e&&z(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)||!j.test(s)){t.push(`contexts.${s} must be a lowercase slug matching ${j.source}.`);continue}if(typeof r!="object"||r===null||Array.isArray(r)){z(r,`contexts.${s}`);continue}const c=r,l=Object.fromEntries(Object.entries(c).filter(([g])=>g!=="lightness"&&g!=="tones"&&g!=="semanticMappings"));z(l,`contexts.${s}`),"lightness"in c&&d(c.lightness,`contexts.${s}.lightness`);const p=new Set(A);if("tones"in c)for(const g of m(c.tones,`contexts.${s}.tones`))p.add(g);"semanticMappings"in c&&H(c.semanticMappings,`contexts.${s}.semanticMappings`,p)}function H(s,r,c){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const l=s;for(const p of Object.keys(l))K.includes(p)||t.push(`${r}.${p} is not a semantic token; expected one of: ${K.join(", ")}.`);for(const p of K)if(p in l){const g=l[p];if(typeof g!="object"||g===null){t.push(`${r}.${p} must be { source, lightness }.`);continue}const f=g;if(typeof f.source!="string"?t.push(`${r}.${p}.source must be a string.`):T(f.source,`${r}.${p}.source`),typeof f.lightness!="string")t.push(`${r}.${p}.lightness must be one of: ${U.join(", ")}, or a declared tone:<name>.`);else if(!te(f.lightness)){const h=Me(f.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 $=[...c].sort();t.push(`${r}.${p}.lightness references undeclared tone "${h}". Declared tones: ${$.length>0?$.join(", "):"(none)"}.`)}}}}if("semanticMappings"in e&&H(e.semanticMappings,"semanticMappings",A),"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=L(e.semanticMappings)?e.semanticMappings:void 0;for(const c of e.explicitMappingTokens){if(typeof c!="string"||!K.includes(c)){t.push(`explicitMappingTokens entries must be one of: ${K.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(...Xt(e,n)),{valid:t.length===0,errors:t,warnings:o}}const B=.045;function Xt(e,n){try{return Zt(e,n)}catch{return[]}}function Zt(e,n){const t=de(n,e),o=ut(t),i=[...o],a=new Set(o);for(const u of Object.keys(t.contexts)){const d=it(t,u);if(d)for(const m of ut(d))a.has(m)||i.push(`contexts.${u}: ${m}`)}return i}function Qt(e){const n=yt(he(e)),t=$t(n);return ht({r:ge(t.r),g:ge(t.g),b:ge(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 Qt(W(ce(he(e))))}function at(e){return(Math.floor(e*1e4)/1e4).toFixed(4)}const Q=2,ct=1e-4;function ut(e){const n=W(e.seedColor);if(!n)return[];const t=ye(n,e),o=e.semanticMappings.actionBackground,i=e.chroma.actionBackground,a=Oe(e.lightness,e.tones,o.lightness),u=(f,h,$,b)=>he(ae(f,h,$,b)),d=ee.map(f=>({name:f,base:t[f]})),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 f=ue(o.source,t,e.anchors);f&&d.push({name:"action",base:f})}const A=Fe(d.map(({name:f,base:h})=>[f,ce(u(h,a,i.min,i.max))]),B,["normal"]);if(A.length===0)return m;const k=new Map,y=(f,h)=>{const $=`${f}:${h}`;let b=k.get($);if(!b){b=[];for(let R=0;R<360;R+=Q)b.push(q({l:f,c:h,h:R}));k.set($,b)}return b},T=B-.002,_=(f,h,$,b)=>{const R=Math.hypot(f.a,f.b),C=Math.atan2(f.b,f.a)*180/Math.PI+180;let w=0;for(const S of $===b?[b]:[$,b]){if(S+R<B-1e-4)continue;let x=C,O=Z(q({l:h,c:S,h:C}),f);if(O>=B)return O;const D=y(h,S);for(let E=0;E<D.length;E+=1){const v=Z(D[E],f);if(v>=B)return v;v>O&&(O=v,x=E*Q)}let P=x;for(let E=x-Q;E<=x+Q;E+=.1){const v=Z(q({l:h,c:S,h:E}),f);if(v>=B)return v;v>O&&(O=v,P=E)}if(O>=T)for(let E=P-.1;E<=P+.1;E+=.001){const v=Z(q({l:h,c:S,h:E}),f);if(v>=B)return v;v>O&&(O=v)}O>w&&(w=O)}return w},z=(f,h,$)=>{const b=h===$?[$]:[h,$];let R=0;for(const C of b)for(const w of b){if(C+w<B-1e-4)continue;const S=y(f,C),x=y(f,w);let O=0,D=0,P=-1;for(let N=0;N<S.length;N+=1)for(let G=0;G<x.length;G+=1){const V=Z(S[N],x[G]);if(V>=B)return V;V>P&&(P=V,O=N*Q,D=G*Q)}const E=(N,G,V,Le)=>{const Ie=[];for(let J=G-V;J<=G+V;J+=Le)Ie.push({h:J,lab:q({l:f,c:w,h:J})});let me=-1,Ne=N,He=G;for(let J=N-V;J<=N+V;J+=Le){const pt=q({l:f,c:C,h:J});for(const Pe of Ie){const De=Z(pt,Pe.lab);De>me&&(me=De,Ne=J,He=Pe.h)}}return{distance:me,hueA:Ne,hueB:He}},v=E(O,D,Q,.1);if(v.distance>=B)return v.distance;let I=Math.max(P,v.distance);if(I>=T){const N=E(v.hueA,v.hueB,.1,.001);if(N.distance>I&&(I=N.distance),I>=B)return I}I>R&&(R=I)}return R},H=f=>ee.includes(f),s=(f,h,$,b,R)=>{const C=q(u(f.base,$,b,R)),w=q(u(h.base,$,b,R));if(Z(C,w)>=B)return{outcome:"direct"};const S=H(f.name)&&H(h.name),x=[f,h].filter(P=>H(P.name)),O=S?"one of them":`"${H(f.name)?f.name:h.name}"`;let D;for(const P of x){const E=_(P===f?w:C,$,b,R);if(E>=B)return{outcome:"retune",target:O};E>=B-ct&&(D=D??O)}if(S){const P=z($,b,R);if(P>=B)return{outcome:"retune",target:"both"};P>=B-ct&&(D=D??"both")}return D!==void 0?{outcome:"near",target:D}:{outcome:"no"}},r=f=>f.outcome==="direct"?4:f.outcome==="retune"?f.target==="both"?2:3:f.outcome==="near"?1:0,c=f=>[...f].sort().join("|"),l=new Set(Fe(d.map(({name:f,base:h})=>[f,ce(u(h,a,0,Y))]),B,["normal"]).map(f=>c(f.pair))),p=new Map(d.map(f=>[f.name,f])),g=new Map;for(const{pair:f,distance:h}of A){const $=p.get(f[0]),b=p.get(f[1]),R=H($.name)&&H(b.name),C=s($,b,a,i.min,i.max);if(C.outcome==="direct"||C.outcome==="retune"){const I=C.target??(R?"one of them":`"${H($.name)?$.name:b.name}"`);l.has(c(f))?m.push(`Status colors "${f[0]}" and "${f[1]}" are hard to distinguish under normal vision (distance ${at(h)} < ${B}); status meanings must stay distinguishable \u2014 retune ${I} via intents.`):m.push(`Status colors "${f[0]}" and "${f[1]}" are hard to distinguish as rendered (distance ${at(h)} < ${B}); the actionBackground chroma band ({ min: ${i.min}, max: ${i.max} }) pushes them together \u2014 widen the band, or retune ${I} via intents.`);continue}const w=s($,b,a,0,Y);let S={outcome:"no"};for(let I=1;I<=19&&S.outcome!=="direct";I+=1){const N=I*.05;if(Math.abs(N-a)<.001)continue;const G=s($,b,N,i.min,i.max);r(G)>r(S)&&(S=G)}let x={outcome:"no"};const O=w.outcome==="direct"||w.outcome==="retune",D=S.outcome==="direct"||S.outcome==="retune";if(!O&&!D)for(let I=1;I<=19&&x.outcome!=="direct";I+=1){const N=s($,b,I*.05,0,Y);r(N)>r(x)&&(x=N)}const P=en(w,S,x),E=`${C.outcome}|${P}`;let v=g.get(E);v||(v=[],g.set(E,v)),v.push(f)}for(const[f,h]of g){const $=f.indexOf("|"),b=f.slice(0,$),R=f.slice($+1),C=h.map(([x,O])=>`"${x}"/"${O}"`),w=C.length>1?`${C.slice(0,-1).join(", ")} and ${C[C.length-1]}`:C[0],S=b==="near"?`Status colors ${w} 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 ${w} 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(S+R)}return m}function en(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 ln(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??{})),A=new Set(Object.keys(o.value?.contexts??{})),k=[...A].filter(T=>!m.has(T)).sort(),y=[...m].filter(T=>!A.has(T)).sort();(k.length>0||y.length>0)&&u.push(`contexts must declare the same names in both schemes. Missing from light: ${k.join(", ")||"(none)"}. Missing from dark: ${y.join(", ")||"(none)"}.`)}return{valid:u.length===0,errors:u,warnings:d}}const tn=["anchors","angles","contexts","dataPalette","dataRamps","intents","roles","chroma","lightness","tones","semanticHues","semanticMappings","variantChroma"];function nn(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 tn){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]=Qe(u,d);continue}if(a==="contexts"){t[a]=Ut(u,d);continue}if(a==="dataRamps"){t[a]=nt(u,d);continue}const m={};for(const[A,k]of Object.entries(u))M(A)&&(m[A]=k);for(const[A,k]of Object.entries(d))k!==void 0&&M(A)&&(m[A]=k);t[a]=m}}const o=pe(e),i=pe(n);if(o!==void 0||i!==void 0){const a=o??new Set(Object.keys(e.semanticMappings??{}).filter(u=>K.includes(u)));for(const u of Object.keys(n.semanticMappings??{}))i===void 0||i.has(u)?a.add(u):a.delete(u);t.explicitMappingTokens=Xe(a)}return t}function pn(...e){let n={};for(const t of e){if(!t)continue;const o=Dt(t);o&&(n=nn(n,o))}return Ee(n)}function ft(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r")}const lt={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 dn(e){return Ee({...lt,pageBackgroundImage:`url("${ft(e)}")`,pageBackgroundImageOpacity:.5})}function mn(e){return Ee({...lt,pageBackgroundImage:`url("${ft(e)}")`,pageBackgroundImageOpacity:.55})}export{j as ANCHOR_SLUG_PATTERN,Ae as COLOR_SOURCES,Ve as DEFAULT_BODY_FONT_FAMILY,Ht as DEFAULT_DARK_LIGHTNESS,qe as DEFAULT_DARK_THEME,Nt as DEFAULT_LIGHT_LIGHTNESS,Re as DEFAULT_LIGHT_THEME,Je as DEFAULT_MONOSPACE_FONT_FAMILY,Te as DEFAULT_SEMANTIC_MAPPINGS,U as LIGHTNESS_KEYS,tn as NESTED_THEME_KEYS,se as ROLE_NAMES,Rt as ROLE_PAIRED_INK,Se as ROLE_TOKEN_PLAN,K as SEMANTIC_COLOR_NAMES,ee as STATUS_COLOR_SOURCES,Ue as TOKEN_PAIRINGS,It as VARIANT_COLOR_SOURCES,mn as buildTaprootDarkTheme,dn as buildTaprootLightTheme,Ke as compileRoles,Ee as encodeTheme,qt as explicitMappingTokens,te as isLightnessKey,L as isObjectRecord,cn as isSemanticColorName,pn as layerThemes,nn as mergePartials,de as mergeTheme,ke as parseAnchorSource,Dt as parseTheme,je as resolveAnchorColor,it as resolveContextTheme,Ot as resolveDataColorSource,Oe as resolveLightnessReference,un as semanticToCSS,Me as toneReferenceName,fn as validateTheme,ln as validateThemePair};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var o=function(d,t,e,i){var a=arguments.length,r=a<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,e):i,l;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(d,t,e,i);else for(var h=d.length-1;h>=0;h--)(l=d[h])&&(r=(a<3?l(r):a>3?l(t,e,r):l(t,e))||r);return a>3&&r&&Object.defineProperty(t,e,r),r},p;import{css as v,html as c}from"lit";import{customElement as y,property as n,state as f}from"lit/decorators.js";import{createRef as m,ref as u}from"lit/directives/ref.js";import{classMap as w}from"lit/directives/class-map.js";import{styleMap as _}from"lit/directives/style-map.js";import{ifDefined as
|
|
1
|
+
var o=function(d,t,e,i){var a=arguments.length,r=a<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,e):i,l;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(d,t,e,i);else for(var h=d.length-1;h>=0;h--)(l=d[h])&&(r=(a<3?l(r):a>3?l(t,e,r):l(t,e))||r);return a>3&&r&&Object.defineProperty(t,e,r),r},p;import{css as v,html as c}from"lit";import{customElement as y,property as n,state as f}from"lit/decorators.js";import{createRef as m,ref as u}from"lit/directives/ref.js";import{classMap as w}from"lit/directives/class-map.js";import{styleMap as _}from"lit/directives/style-map.js";import{ifDefined as b}from"lit/directives/if-defined.js";import{EspalierElementBase as g}from"../shared/esp-element-base.js";import{FormFieldController as S}from"../shared/form-field-controller.js";import{FormFieldDescriptionController as k}from"../shared/form-field-description-controller.js";import{disabledControl as x,focusRing as C}from"../shared/style-fragments.js";import{slotHasContent as $}from"../shared/slot-content.js";let s=p=class extends g{constructor(){super(...arguments),this.internals=this.attachInternals(),this.formCtrl=new S({host:this,internals:this.internals,getFormValue:()=>this.value||null,getValidity:()=>null,onReset:()=>{this.value=String(this._low)},onRestore:t=>{this.value=t},onDisabled:t=>{this.disabled=t}}),this.formItemDescription=new k({host:this,getTarget:()=>this._thumbRef.value}),this.min=0,this.max=100,this.step=1,this.value="0",this.name="",this.disabled=!1,this.label="",this._dragging=!1,this._hasSlotContent=!1,this._trackRef=m(),this._thumbRef=m(),this._slotRef=m(),this._labelId=`esp-slider-label-${p._nextId++}`}get _safeStep(){return Number.isFinite(this.step)&&this.step>0?this.step:1}get _safeMin(){return Number.isFinite(this.min)?this.min:0}get _safeMax(){return Number.isFinite(this.max)?this.max:100}get _stepPrecision(){const t=String(this._safeStep),e=/^(\d+\.?(\d*))e-(\d+)$/.exec(t);if(e){const a=e[2].length,r=Number(e[3]);return a+r}const i=t.indexOf(".");return i===-1?0:t.length-i-1}get _low(){return Math.min(this._safeMin,this._safeMax)}get _high(){return Math.max(this._safeMin,this._safeMax)}_snapToStep(t){const e=this._safeStep,i=this._low,a=this._high,r=Math.round((t-i)/e)*e+i,l=Math.max(i,Math.min(a,r)),h=10**this._stepPrecision;return Math.round(l*h)/h}get numericValue(){const t=Number(this.value);return Number.isNaN(t)?this._snapToStep(this._low):this._snapToStep(t)}get percentage(){const t=this._high-this._low;return t<=0?0:(this.numericValue-this._low)/t*100}_normalizeValue(){const t=String(this.numericValue);t!==this.value&&(this.value=t),this.formCtrl.syncValueSilently()}willUpdate(t){super.willUpdate(t),(t.has("value")||t.has("min")||t.has("max")||t.has("step"))&&this._normalizeValue()}firstUpdated(t){super.firstUpdated(t),this._syncSlotContent()}focus(t){this.focusResolvedElementAfterUpdate(()=>this._thumbRef.value,t)}setFormItemDescription(t){this.formItemDescription.setDescription(t)}validate(){this.formCtrl.validate()}checkValidity(){return this.formCtrl.checkValidity()}_setValueAndNotify(t){const e=String(this._snapToStep(t));e!==this.value&&(this.value=e,this.formCtrl.syncValue(),this.emitValueChanged(e))}_handleKeyDown(t){if(this.disabled)return;const e=this._safeStep;let i=0;switch(t.key){case"ArrowRight":case"ArrowUp":i=e;break;case"ArrowLeft":case"ArrowDown":i=-e;break;case"Home":this._setValueAndNotify(this._low),t.preventDefault();return;case"End":this._setValueAndNotify(this._high),t.preventDefault();return;case"PageUp":i=e*10;break;case"PageDown":i=-e*10;break;default:return}t.preventDefault(),this._setValueAndNotify(this.numericValue+i)}_handlePointerDown(t){if(this.disabled)return;const e=this._thumbRef.value,i=this._trackRef.value;if(!e||!i)return;const a=t.composedPath().includes(e);t.pointerType==="touch"&&!a||(t.preventDefault(),this._dragging=!0,e.setPointerCapture(t.pointerId),e.focus({preventScroll:!0}),this._updateValueFromPointer(t))}_handlePointerMove(t){this._dragging&&this._updateValueFromPointer(t)}_handlePointerUp(){this._endDrag()}_handleLostPointerCapture(){this._endDrag()}_endDrag(){this._dragging&&(this._dragging=!1)}_updateValueFromPointer(t){const e=this._trackRef.value;if(!e)return;const i=e.getBoundingClientRect();if(i.width<=0)return;const a=Math.max(0,Math.min(1,(t.clientX-i.left)/i.width)),r=this._low+a*(this._high-this._low);this._setValueAndNotify(r)}_handleSlotChange(){this._syncSlotContent()}_syncSlotContent(){const t=this._slotRef.value;t&&(this._hasSlotContent=$(t))}formResetCallback(){this.formCtrl.handleFormReset()}formStateRestoreCallback(t){this.formCtrl.handleFormStateRestore(t)}formDisabledCallback(t){this.formCtrl.handleFormDisabled(t)}render(){const t=this.percentage,e=this._hasSlotContent?this._labelId:void 0,i=this._hasSlotContent?void 0:this.label||void 0;return c`
|
|
2
2
|
<div
|
|
3
3
|
class=${w({"slider-container":!0,dragging:this._dragging})}
|
|
4
4
|
@pointerdown=${this._handlePointerDown}
|
|
@@ -19,8 +19,8 @@ var o=function(d,t,e,i){var a=arguments.length,r=a<3?t:i===null?i=Object.getOwnP
|
|
|
19
19
|
aria-valuenow=${this.numericValue}
|
|
20
20
|
aria-valuetext=${String(this.numericValue)}
|
|
21
21
|
aria-orientation="horizontal"
|
|
22
|
-
aria-labelledby=${
|
|
23
|
-
aria-label=${
|
|
22
|
+
aria-labelledby=${b(e)}
|
|
23
|
+
aria-label=${b(i)}
|
|
24
24
|
aria-disabled=${String(this.disabled)}
|
|
25
25
|
@keydown=${this._handleKeyDown}
|
|
26
26
|
style=${_({left:`${t}%`})}
|
|
@@ -29,7 +29,7 @@ var o=function(d,t,e,i){var a=arguments.length,r=a<3?t:i===null?i=Object.getOwnP
|
|
|
29
29
|
${this._hasSlotContent?c`<span class="label" id=${this._labelId}>
|
|
30
30
|
<slot ${u(this._slotRef)} @slotchange=${this._handleSlotChange}></slot>
|
|
31
31
|
</span>`:c`<slot ${u(this._slotRef)} @slotchange=${this._handleSlotChange} hidden></slot>`}
|
|
32
|
-
`}};s.formAssociated=!0,s._nextId=0,s.styles=[...
|
|
32
|
+
`}};s.formAssociated=!0,s._nextId=0,s.styles=[...g.styles,C(".thumb:focus-visible","--esp-slider-focus-shadow","0 0 0 3px","var(--esp-slider-thumb-shadow, 0 1px 3px oklch(0 0 0 / 0.2)),"),x(".slider-container"),v`
|
|
33
33
|
:host {
|
|
34
34
|
display: block;
|
|
35
35
|
}
|
|
@@ -91,7 +91,10 @@ var o=function(d,t,e,i){var a=arguments.length,r=a<3?t:i===null?i=Object.getOwnP
|
|
|
91
91
|
|
|
92
92
|
.label {
|
|
93
93
|
display: block;
|
|
94
|
-
font-family: var(
|
|
94
|
+
font-family: var(
|
|
95
|
+
--_esp-font-body-effective,
|
|
96
|
+
var(--esp-font-body, var(--_esp-font-body-fallback))
|
|
97
|
+
);
|
|
95
98
|
font-size: var(--esp-size-font);
|
|
96
99
|
color: var(--esp-color-text);
|
|
97
100
|
line-height: 1.3;
|
|
@@ -70,7 +70,7 @@ export type EspalierStatusIndicatorChrome = "pill" | "outline" | "none";
|
|
|
70
70
|
*
|
|
71
71
|
* .file-type-indicator svg text {
|
|
72
72
|
* fill: var(--esp-color-background);
|
|
73
|
-
* font-family: var(--esp-font-body);
|
|
73
|
+
* font-family: var(--esp-font-body, system-ui, sans-serif);
|
|
74
74
|
* font-size: 14px;
|
|
75
75
|
* font-weight: 600;
|
|
76
76
|
* text-anchor: middle;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var s=function(a,e,i,l){var c=arguments.length,o=c<3?e:l===null?l=Object.getOwnPropertyDescriptor(e,i):l,n;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(a,e,i,l);else for(var h=a.length-1;h>=0;h--)(n=a[h])&&(o=(c<3?n(o):c>3?n(e,i,o):n(e,i))||o);return c>3&&o&&Object.defineProperty(e,i,o),o};import{css as m,html as d}from"lit";import{customElement as v,property as r}from"lit/decorators.js";import{classMap as p}from"lit/directives/class-map.js";import{EspalierElementBase as u}from"../shared/esp-element-base.js";import{FormFieldController as b}from"../shared/form-field-controller.js";import{FormFieldDescriptionController as g}from"../shared/form-field-description-controller.js";import{disabledControl as w,focusRing as f,srOnly as y}from"../shared/style-fragments.js";let t=class extends u{constructor(){super(...arguments),this.internals=this.attachInternals(),this.formCtrl=new b({host:this,internals:this.internals,getFormValue:()=>this.checked?this.value||"on":null,getValidity:()=>this.required&&!this.checked?{flags:{valueMissing:!0},message:this.requiredMessage||"Please toggle this switch to continue."}:null,onReset:()=>{this.checked=!1},onRestore:e=>{this.checked=e==="on"||e===this.value},onDisabled:e=>{this.disabled=e}}),this.formItemDescription=new g({host:this,getTarget:()=>this.shadowRoot?.querySelector(".switch-control")}),this.mode="switch",this.offLabel="",this.onLabel="",this.checked=!1,this.value="",this.name="",this.required=!1,this.requiredMessage="",this.disabled=!1}focus(e){this.focusShadowElementAfterUpdate(".switch-control",e)}setFormItemDescription(e){this.formItemDescription.setDescription(e)}validate(){this.formCtrl.validate()}checkValidity(){return this.formCtrl.checkValidity()}toggle(){this.disabled||(this.checked=!this.checked,this.formCtrl.syncValue(),this.emitValueChanged({checked:this.checked,value:this.value}))}handleKeyDown(e){(e.key===" "||e.key==="Enter")&&(e.preventDefault(),this.toggle())}handleLabelSlotChange(){this.requestUpdate()}getCurrentTextModeLabel(){return(this.checked?this.onLabel:this.offLabel).trim()}getTextModeAriaLabel(){const e=this.textContent?.replace(/\s+/g," ").trim()??"",i=this.getCurrentTextModeLabel();return e&&i?`${e}: ${i}`:e||i}formResetCallback(){this.formCtrl.handleFormReset()}formStateRestoreCallback(e){this.formCtrl.handleFormStateRestore(e)}formDisabledCallback(e){this.formCtrl.handleFormDisabled(e)}render(){return this.mode==="text"?d`
|
|
2
2
|
<div
|
|
3
3
|
class="switch-control text-control"
|
|
4
4
|
role="switch"
|
|
@@ -34,7 +34,7 @@ var i=function(a,e,s,l){var c=arguments.length,o=c<3?e:l===null?l=Object.getOwnP
|
|
|
34
34
|
</div>
|
|
35
35
|
<span class="label"><slot></slot></span>
|
|
36
36
|
</div>
|
|
37
|
-
`}};t.formAssociated=!0,t.styles=[...u.styles,
|
|
37
|
+
`}};t.formAssociated=!0,t.styles=[...u.styles,y,f(".switch-control:focus-visible","--esp-switch-focus-shadow"),f(".text-control:focus-visible","--esp-switch-focus-shadow"),w(".switch-control"),m`
|
|
38
38
|
:host {
|
|
39
39
|
display: block;
|
|
40
40
|
}
|
|
@@ -45,7 +45,10 @@ var i=function(a,e,s,l){var c=arguments.length,o=c<3?e:l===null?l=Object.getOwnP
|
|
|
45
45
|
align-items: center;
|
|
46
46
|
gap: var(--esp-size-tiny);
|
|
47
47
|
cursor: pointer;
|
|
48
|
-
font-family: var(
|
|
48
|
+
font-family: var(
|
|
49
|
+
--_esp-font-body-effective,
|
|
50
|
+
var(--esp-font-body, var(--_esp-font-body-fallback))
|
|
51
|
+
);
|
|
49
52
|
font-size: var(--esp-size-font);
|
|
50
53
|
color: var(--esp-color-text);
|
|
51
54
|
outline: none;
|
|
@@ -110,7 +113,10 @@ var i=function(a,e,s,l){var c=arguments.length,o=c<3?e:l===null?l=Object.getOwnP
|
|
|
110
113
|
border-radius: calc(var(--esp-size-border-radius) + 2px);
|
|
111
114
|
padding: 2px;
|
|
112
115
|
gap: 0;
|
|
113
|
-
font-family: var(
|
|
116
|
+
font-family: var(
|
|
117
|
+
--_esp-font-body-effective,
|
|
118
|
+
var(--esp-font-body, var(--_esp-font-body-fallback))
|
|
119
|
+
);
|
|
114
120
|
font-size: var(--esp-switch-text-font-size, var(--esp-size-font));
|
|
115
121
|
user-select: none;
|
|
116
122
|
cursor: pointer;
|
|
@@ -147,4 +153,4 @@ var i=function(a,e,s,l){var c=arguments.length,o=c<3?e:l===null?l=Object.getOwnP
|
|
|
147
153
|
.text-option.active {
|
|
148
154
|
color: var(--esp-switch-text-active-color, var(--esp-color-action-text));
|
|
149
155
|
}
|
|
150
|
-
`],
|
|
156
|
+
`],s([r({type:String,reflect:!0})],t.prototype,"mode",void 0),s([r({attribute:"off-label"})],t.prototype,"offLabel",void 0),s([r({attribute:"on-label"})],t.prototype,"onLabel",void 0),s([r({type:Boolean,reflect:!0})],t.prototype,"checked",void 0),s([r({type:String})],t.prototype,"value",void 0),s([r({type:String,reflect:!0})],t.prototype,"name",void 0),s([r({type:Boolean,reflect:!0})],t.prototype,"required",void 0),s([r({attribute:"required-message"})],t.prototype,"requiredMessage",void 0),s([r({type:Boolean,reflect:!0})],t.prototype,"disabled",void 0),t=s([v("esp-switch")],t);export{t as EspalierSwitch};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var b=function(i,t,a,e){var s=arguments.length,o=s<3?t:e===null?e=Object.getOwnPropertyDescriptor(t,a):e,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(i,t,a,e);else for(var l=i.length-1;l>=0;l--)(r=i[l])&&(o=(s<3?r(o):s>3?r(t,a,o):r(t,a))||o);return s>3&&o&&Object.defineProperty(t,a,o),o};import{css as u,html as d,nothing as f}from"lit";import{customElement as v,property as m,state as g}from"lit/decorators.js";import{createRef as y,ref as w}from"lit/directives/ref.js";import{EspalierElementBase as c}from"../shared/esp-element-base.js";import{ESP_EVENTS as
|
|
1
|
+
var b=function(i,t,a,e){var s=arguments.length,o=s<3?t:e===null?e=Object.getOwnPropertyDescriptor(t,a):e,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(i,t,a,e);else for(var l=i.length-1;l>=0;l--)(r=i[l])&&(o=(s<3?r(o):s>3?r(t,a,o):r(t,a))||o);return s>3&&o&&Object.defineProperty(t,a,o),o};import{css as u,html as d,nothing as f}from"lit";import{customElement as v,property as m,state as g}from"lit/decorators.js";import{createRef as y,ref as w}from"lit/directives/ref.js";import{EspalierElementBase as c}from"../shared/esp-element-base.js";import{ESP_EVENTS as k}from"../shared/events.js";import{EspalierTab as p}from"./esp-tab.js";import{disabledControl as T}from"../shared/style-fragments.js";let n=class extends c{constructor(){super(...arguments),this.panelsSlot=y(),this.disabled=!1,this.tabData=[]}getTabs(){const t=this.panelsSlot.value?Array.from(this.panelsSlot.value.assignedElements()).filter(a=>a instanceof p):[];return t.length>0?t:Array.from(this.children).filter(a=>a instanceof p)}syncTabData(){const t=this.getTabs();if(t.length===0){this.tabData=[];return}const a=t.find(e=>e.active&&!e.disabled);if(a)for(const e of t)e!==a&&(e.active=!1);else{const e=t.find(s=>!s.disabled);e?e.active=!0:t[0].active=!0}this.tabData=t.map((e,s)=>{const o=`esp-tab-btn-${this.correlationId}-${s}`,r=`esp-tab-panel-${this.correlationId}-${s}`;return e.panelId=r,e.ariaLabelledBy=o,{label:e.label,active:e.active,disabled:this.disabled||e.disabled,buttonId:o,panelId:r}})}activateTab(t){const a=this.getTabs(),e=a[t];if(!(!e||e.disabled||this.disabled)){for(const s of a)s.active=s===e;this.syncTabData(),this.dispatchEvent(new CustomEvent(k.TAB_GROUP_CHANGED,{detail:{index:t,label:e.label},bubbles:!0,composed:!0}))}}handleTabClick(t){this.activateTab(t),this.updateComplete.then(()=>{this.shadowRoot?.getElementById(this.tabData[t]?.buttonId)?.focus()})}handleKeyDown(t){if(!["ArrowLeft","ArrowRight","Home","End"].includes(t.key))return;t.preventDefault();const e=this.tabData.map((l,h)=>({td:l,i:h})).filter(({td:l})=>!l.disabled).map(({i:l})=>l);if(e.length===0)return;const s=this.tabData.findIndex(l=>l.active),o=e.indexOf(s);let r;switch(t.key){case"ArrowRight":o===-1?r=e[0]:r=e[(o+1)%e.length];break;case"ArrowLeft":o===-1?r=e[e.length-1]:r=e[(o-1+e.length)%e.length];break;case"Home":r=e[0];break;case"End":r=e[e.length-1];break;default:return}this.activateTab(r),this.updateComplete.then(()=>{this.shadowRoot?.getElementById(this.tabData[r]?.buttonId)?.focus()})}handleChildUpdated(){this.syncTabData()}handleSlotChange(){this.syncTabData()}connectedCallback(){super.connectedCallback(),this.syncTabData()}willUpdate(t){super.willUpdate(t),t.has("disabled")&&this.syncTabData()}render(){return d`
|
|
2
2
|
<div class="tab-container">
|
|
3
3
|
<div class="tab-list" role="tablist" part="tab-list" @keydown=${this.handleKeyDown}>
|
|
4
4
|
${this.tabData.map((t,a)=>d`
|
|
@@ -26,7 +26,7 @@ var b=function(i,t,a,e){var s=arguments.length,o=s<3?t:e===null?e=Object.getOwnP
|
|
|
26
26
|
></slot>
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
29
|
-
`}};n.styles=[...c.styles,
|
|
29
|
+
`}};n.styles=[...c.styles,T(".tab-button[disabled]"),u`
|
|
30
30
|
:host {
|
|
31
31
|
display: block;
|
|
32
32
|
--_esp-tab-resolved-button-hover: var(
|
|
@@ -58,7 +58,10 @@ var b=function(i,t,a,e){var s=arguments.length,o=s<3?t:e===null?e=Object.getOwnP
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
.tab-button {
|
|
61
|
-
font-family: var(
|
|
61
|
+
font-family: var(
|
|
62
|
+
--_esp-font-body-effective,
|
|
63
|
+
var(--esp-font-body, var(--_esp-font-body-fallback))
|
|
64
|
+
);
|
|
62
65
|
font-size: var(--esp-size-font);
|
|
63
66
|
font-weight: 600;
|
|
64
67
|
color: var(--esp-tab-color-text, var(--esp-color-headings));
|