@taprootio/espalier 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/custom-elements.json +13674 -10749
- package/dist/box/esp-box.d.ts +10 -0
- package/dist/box/esp-box.js +4 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/page/esp-page.d.ts +23 -7
- package/dist/page/esp-page.js +37 -10
- package/dist/root/esp-root.d.ts +24 -1
- package/dist/root/esp-root.js +3 -3
- package/dist/row/esp-row.d.ts +64 -0
- package/dist/row/esp-row.js +67 -0
- package/dist/section/esp-section.d.ts +55 -0
- package/dist/section/esp-section.js +22 -0
- package/dist/shared/esp-element-base.js +1 -1
- package/dist/shared/scale-engine.js +1 -1
- package/dist/shared/theme.d.ts +2 -1
- package/dist/shared/theme.js +1 -1
- package/dist/stack/esp-stack.d.ts +62 -0
- package/dist/stack/esp-stack.js +56 -0
- package/espalier.token-manifest.json +84 -1
- package/package.json +29 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { EspalierElementBase } from "../shared/esp-element-base.js";
|
|
2
|
+
import type { EspalierAlign, EspalierGap } from "../stack/esp-stack.js";
|
|
3
|
+
declare const ROW_JUSTIFIES: readonly ["start", "center", "end", "between"];
|
|
4
|
+
/** A main-axis distribution accepted by `esp-row`. */
|
|
5
|
+
export type EspalierJustify = (typeof ROW_JUSTIFIES)[number];
|
|
6
|
+
export { ROW_JUSTIFIES };
|
|
7
|
+
/**
|
|
8
|
+
* A horizontal flow: children sit in a wrapping row with a themed gap —
|
|
9
|
+
* "row, wrap, gap Y" without writing flexbox (ADR-010's micro half).
|
|
10
|
+
*
|
|
11
|
+
* ```html
|
|
12
|
+
* <esp-row gap="small" justify="between">
|
|
13
|
+
* <span>Yoga · 60 min</span>
|
|
14
|
+
* <esp-button label="Book"></esp-button>
|
|
15
|
+
* </esp-row>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Rows wrap by default, so a button row or badge cluster degrades to
|
|
19
|
+
* multiple lines at narrow widths instead of overflowing; set `nowrap`
|
|
20
|
+
* for toolbars that must stay on one line. Cross-axis alignment
|
|
21
|
+
* defaults to `center` — the icon-beside-label, text-beside-button
|
|
22
|
+
* case a row exists for.
|
|
23
|
+
*
|
|
24
|
+
* @customElement esp-row
|
|
25
|
+
* @slot - The row children.
|
|
26
|
+
* @csspart row - The flex row.
|
|
27
|
+
* @cssprop --esp-row-gap - Overrides the gap between children. Defaults to the `gap` attribute's step, `normal` when unset.
|
|
28
|
+
* @docPageTitle Row
|
|
29
|
+
* @docUrl /components/row
|
|
30
|
+
* @menuGroup Structure
|
|
31
|
+
* @menuIcon layout
|
|
32
|
+
*/
|
|
33
|
+
export declare class EspalierRow extends EspalierElementBase {
|
|
34
|
+
/**
|
|
35
|
+
* Gap between children as a space-scale step name
|
|
36
|
+
* (`none`, `tiny`, `small`, `normal`, `medium`, `big`, `large`,
|
|
37
|
+
* `huge`).
|
|
38
|
+
* @default "normal"
|
|
39
|
+
*/
|
|
40
|
+
gap: EspalierGap;
|
|
41
|
+
/**
|
|
42
|
+
* Cross-axis alignment of children: `start`, `center`, `end`, or
|
|
43
|
+
* `stretch`.
|
|
44
|
+
* @default "center"
|
|
45
|
+
*/
|
|
46
|
+
align: EspalierAlign;
|
|
47
|
+
/**
|
|
48
|
+
* Main-axis distribution: `start`, `center`, `end`, or `between`.
|
|
49
|
+
* @default "start"
|
|
50
|
+
*/
|
|
51
|
+
justify: EspalierJustify;
|
|
52
|
+
/**
|
|
53
|
+
* Keeps every child on one line instead of wrapping.
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
nowrap: boolean;
|
|
57
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
58
|
+
static styles: import("lit").CSSResult[];
|
|
59
|
+
}
|
|
60
|
+
declare global {
|
|
61
|
+
interface HTMLElementTagNameMap {
|
|
62
|
+
"esp-row": EspalierRow;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var o=function(p,r,s,a){var i=arguments.length,e=i<3?r:a===null?a=Object.getOwnPropertyDescriptor(r,s):a,l;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")e=Reflect.decorate(p,r,s,a);else for(var f=p.length-1;f>=0;f--)(l=p[f])&&(e=(i<3?l(e):i>3?l(r,s,e):l(r,s))||e);return i>3&&e&&Object.defineProperty(r,s,e),e};import{css as u,html as g}from"lit";import{customElement as c,property as n}from"lit/decorators.js";import{EspalierElementBase as w}from"../shared/esp-element-base.js";const h=["start","center","end","between"];let t=class extends w{constructor(){super(...arguments),this.gap="normal",this.align="center",this.justify="start",this.nowrap=!1}render(){return g`
|
|
2
|
+
<div class="esp-row" part="row">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</div>
|
|
5
|
+
`}};t.styles=[...w.styles,u`
|
|
6
|
+
:host {
|
|
7
|
+
display: block;
|
|
8
|
+
--_esp-row-gap: var(--esp-size-normal);
|
|
9
|
+
--_esp-row-align: center;
|
|
10
|
+
--_esp-row-justify: flex-start;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
:host([gap="none"]) {
|
|
14
|
+
--_esp-row-gap: 0px;
|
|
15
|
+
}
|
|
16
|
+
:host([gap="tiny"]) {
|
|
17
|
+
--_esp-row-gap: var(--esp-size-tiny);
|
|
18
|
+
}
|
|
19
|
+
:host([gap="small"]) {
|
|
20
|
+
--_esp-row-gap: var(--esp-size-small);
|
|
21
|
+
}
|
|
22
|
+
:host([gap="medium"]) {
|
|
23
|
+
--_esp-row-gap: var(--esp-size-medium);
|
|
24
|
+
}
|
|
25
|
+
:host([gap="big"]) {
|
|
26
|
+
--_esp-row-gap: var(--esp-size-big);
|
|
27
|
+
}
|
|
28
|
+
:host([gap="large"]) {
|
|
29
|
+
--_esp-row-gap: var(--esp-size-large);
|
|
30
|
+
}
|
|
31
|
+
:host([gap="huge"]) {
|
|
32
|
+
--_esp-row-gap: var(--esp-size-huge);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
:host([align="start"]) {
|
|
36
|
+
--_esp-row-align: flex-start;
|
|
37
|
+
}
|
|
38
|
+
:host([align="end"]) {
|
|
39
|
+
--_esp-row-align: flex-end;
|
|
40
|
+
}
|
|
41
|
+
:host([align="stretch"]) {
|
|
42
|
+
--_esp-row-align: stretch;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
:host([justify="center"]) {
|
|
46
|
+
--_esp-row-justify: center;
|
|
47
|
+
}
|
|
48
|
+
:host([justify="end"]) {
|
|
49
|
+
--_esp-row-justify: flex-end;
|
|
50
|
+
}
|
|
51
|
+
:host([justify="between"]) {
|
|
52
|
+
--_esp-row-justify: space-between;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.esp-row {
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-direction: row;
|
|
58
|
+
flex-wrap: wrap;
|
|
59
|
+
gap: var(--esp-row-gap, var(--_esp-row-gap));
|
|
60
|
+
align-items: var(--_esp-row-align);
|
|
61
|
+
justify-content: var(--_esp-row-justify);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
:host([nowrap]) .esp-row {
|
|
65
|
+
flex-wrap: nowrap;
|
|
66
|
+
}
|
|
67
|
+
`],o([n({reflect:!0,useDefault:!0})],t.prototype,"gap",void 0),o([n({reflect:!0,useDefault:!0})],t.prototype,"align",void 0),o([n({reflect:!0,useDefault:!0})],t.prototype,"justify",void 0),o([n({type:Boolean,reflect:!0})],t.prototype,"nowrap",void 0),t=o([c("esp-row")],t);export{t as EspalierRow,h as ROW_JUSTIFIES};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { EspalierElementBase } from "../shared/esp-element-base.js";
|
|
2
|
+
/**
|
|
3
|
+
* A full-bleed page band with a centered content well — the natural host
|
|
4
|
+
* for a theme zone.
|
|
5
|
+
*
|
|
6
|
+
* `esp-section` paints the local `--esp-color-background` edge to edge
|
|
7
|
+
* and centers its content in a capped well. It carries no card identity:
|
|
8
|
+
* no raised surface, no border radius, no shadow. Give it a `context`
|
|
9
|
+
* (see the theming guide, `/guides/color/theming` on the docs site) and
|
|
10
|
+
* the band renders the zone's complete token table with nothing to
|
|
11
|
+
* neutralize:
|
|
12
|
+
*
|
|
13
|
+
* ```html
|
|
14
|
+
* <esp-section context="inverted">
|
|
15
|
+
* <h2>The reversed band</h2>
|
|
16
|
+
* <p>Everything in here renders on the zone's tokens, and the band
|
|
17
|
+
* spans its container edge to edge.</p>
|
|
18
|
+
* </esp-section>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Inside `esp-page kind="site"` sections stack full-width and their
|
|
22
|
+
* wells share the page's `--esp-page-well-max-width`, so section
|
|
23
|
+
* content, the header, and the footer all align on one column. Outside
|
|
24
|
+
* a page the well defaults to the same width and the band fills
|
|
25
|
+
* whatever container it is given.
|
|
26
|
+
*
|
|
27
|
+
* The vertical rhythm defaults to the theme's fluid `--esp-size-section`
|
|
28
|
+
* step. For edge-to-edge content (a full-bleed hero image) clear both
|
|
29
|
+
* the well cap and the inline breathing room —
|
|
30
|
+
* `--esp-section-max-width: none; --esp-section-padding-inline: 0;` —
|
|
31
|
+
* and drop `--esp-section-padding-block` too when the media should
|
|
32
|
+
* meet the band's edges; the band's zone behavior is unaffected.
|
|
33
|
+
*
|
|
34
|
+
* @customElement esp-section
|
|
35
|
+
* @slot - The section's content, centered in the well.
|
|
36
|
+
* @csspart section - The full-bleed band.
|
|
37
|
+
* @csspart well - The centered content well.
|
|
38
|
+
* @cssprop --esp-section-background - The band's background. Defaults to the local `--esp-color-background`, which inside a `context` zone is the zone's canvas.
|
|
39
|
+
* @cssprop --esp-section-max-width - The content well's cap. Defaults to `var(--esp-page-well-max-width, 72rem)`; `none` lets content span the band.
|
|
40
|
+
* @cssprop --esp-section-padding-block - Vertical rhythm above and below the well. Defaults to `var(--esp-size-section)`.
|
|
41
|
+
* @cssprop --esp-section-padding-inline - Horizontal breathing room inside the band at narrow viewports. Defaults to `var(--esp-size-medium)`.
|
|
42
|
+
* @docPageTitle Section
|
|
43
|
+
* @docUrl /components/section
|
|
44
|
+
* @menuGroup Structure
|
|
45
|
+
* @menuIcon layout
|
|
46
|
+
*/
|
|
47
|
+
export declare class EspalierSection extends EspalierElementBase {
|
|
48
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
49
|
+
static styles: import("lit").CSSResult[];
|
|
50
|
+
}
|
|
51
|
+
declare global {
|
|
52
|
+
interface HTMLElementTagNameMap {
|
|
53
|
+
"esp-section": EspalierSection;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var a=function(t,i,s,n){var o=arguments.length,e=o<3?i:n===null?n=Object.getOwnPropertyDescriptor(i,s):n,l;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")e=Reflect.decorate(t,i,s,n);else for(var c=t.length-1;c>=0;c--)(l=t[c])&&(e=(o<3?l(e):o>3?l(i,s,e):l(i,s))||e);return o>3&&e&&Object.defineProperty(i,s,e),e};import{css as d,html as m}from"lit";import{customElement as v}from"lit/decorators.js";import{EspalierElementBase as p}from"../shared/esp-element-base.js";let r=class extends p{render(){return m`
|
|
2
|
+
<div class="esp-section" part="section">
|
|
3
|
+
<div class="esp-section-well" part="well">
|
|
4
|
+
<slot></slot>
|
|
5
|
+
</div>
|
|
6
|
+
</div>
|
|
7
|
+
`}};r.styles=[...p.styles,d`
|
|
8
|
+
:host {
|
|
9
|
+
display: block;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.esp-section {
|
|
13
|
+
background: var(--esp-section-background, var(--esp-color-background));
|
|
14
|
+
padding-block: var(--esp-section-padding-block, var(--esp-size-section));
|
|
15
|
+
padding-inline: var(--esp-section-padding-inline, var(--esp-size-medium));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.esp-section-well {
|
|
19
|
+
max-inline-size: var(--esp-section-max-width, var(--esp-page-well-max-width, 72rem));
|
|
20
|
+
margin-inline: auto;
|
|
21
|
+
}
|
|
22
|
+
`],r=a([v("esp-section")],r);export{r as EspalierSection};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var h=function(f,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(f,e,t,r);else for(var i=f.length-1;i>=0;i--)(a=f[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s};import{css as R,LitElement as C}from"lit";import{property as p,state as S}from"lit/decorators.js";import{subscribeToRootEvent as u}from"./root-event-subscription.js";import{traverseToClosest as b}from"./utilities.js";import{parseCssColor as w,serializeOklch as x,gamutMapToSRGB as P}from"./color-engine.js";import{computeVariants as v}from"../root/helpers/compute-variants.js";import{computeSemanticProperties as m}from"../root/helpers/compute-semantic-properties.js";import{lightnessRampProperties as E}from"../root/helpers/lightness-ramp-properties.js";import{ROLE_NAMES as
|
|
1
|
+
var h=function(f,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(f,e,t,r);else for(var i=f.length-1;i>=0;i--)(a=f[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s};import{css as R,LitElement as C}from"lit";import{property as p,state as S}from"lit/decorators.js";import{subscribeToRootEvent as u}from"./root-event-subscription.js";import{traverseToClosest as b}from"./utilities.js";import{parseCssColor as w,serializeOklch as x,gamutMapToSRGB as P}from"./color-engine.js";import{computeVariants as v}from"../root/helpers/compute-variants.js";import{computeSemanticProperties as m}from"../root/helpers/compute-semantic-properties.js";import{lightnessRampProperties as E}from"../root/helpers/lightness-ramp-properties.js";import{ELEVATION_PROPERTIES as V}from"./scale-engine.js";import{ROLE_NAMES as U,mergeTheme as I,semanticToCSS as A}from"./theme.js";import{alignAttributeTextInheritance as O,focusRing as D}from"./style-fragments.js";import{syncNormalizedAttribute as N}from"./attribute-helpers.js";import{INTENT_VARIANTS as y,normalizeIntentVariant as z}from"./intent-values.js";const k=new WeakMap;class n extends C{constructor(){super(...arguments),this.seedColorBacker="oklch(0.7 0.125 216)",this.espRoot=null,this.contextBacker="",this.scopedTokenOriginalValues=new Map,this.warnedUnknownContexts=new Set,this.pendingInitialThemeRoot=null,this.rootEventSubscriptionsActive=!1,this.subscribedRoot=null,this.rootEventUnsubscribers=[],this.intentBacker="neutral",this.intentEmitsTokens=!0,this.warnedUnknownIntents=new Set,this.correlationId=globalThis.crypto?.randomUUID?.()??Math.random().toString(36),this.scheme="light",this.handleSeedColorChanged=e=>{this.syncRootFromDom(!1)&&(this.seedColor=e.seedColor,this.applyScopedColorTokens())},this.handleSchemeChanged=e=>{!this.syncRootFromDom(!1)||this.scheme===e.scheme||(this.scheme=e.scheme,this.applyScopedColorTokens())},this.handleThemeChanged=()=>{this.syncRootFromDom(!1)&&this.applyScopedColorTokens()},this.handleIconSpriteUrlChanged=()=>{this.syncRootFromDom(!1)&&this.requestUpdate()}}get seedColor(){return this.seedColorBacker}set seedColor(e){this.seedColorBacker=e}focusResolvedElementAfterUpdate(e,t){const r=()=>{const o=e();return o?(o.focus(t),!0):!1};r()||this.updateComplete.then(()=>{r()})}focusShadowElementAfterUpdate(e,t){this.focusResolvedElementAfterUpdate(()=>this.shadowRoot?.querySelector(e),t)}emitValueChanged(e){this.dispatchEvent(new CustomEvent("value-changed",{detail:e,bubbles:!0,composed:!0}))}get intent(){return this.intentBacker}set intent(e){const t=typeof e=="string"?e.trim():"";t!==""&&!y.includes(t)&&!this.warnedUnknownIntents.has(t)&&(this.warnedUnknownIntents.add(t),console.warn(`Espalier intent: "${t}" is not an intent; expected one of ${y.join(", ")}. Treating it as "neutral".`));const r=this.intentBacker,o=z(e);N(this,"intent",o),o!==r&&(this.intentBacker=o,this.requestUpdate("intent",r),this.applyTokensWhenRootReady())}get context(){return this.contextBacker}set context(e){const t=e??"";t!==this.contextBacker&&(this.contextBacker=t,this.applyTokensWhenRootReady(),this.refreshDescendantIntentDerivations())}refreshDescendantIntentDerivations(){const e=new Set,t=o=>{for(const s of Array.from(o.children))r(s)},r=o=>{if(!e.has(o)){if(e.add(o),o instanceof n&&o.applyTokensWhenRootReady(),o.shadowRoot&&t(o.shadowRoot),o instanceof HTMLSlotElement)for(const s of o.assignedElements({flatten:!0}))r(s);t(o)}};t(this),this.shadowRoot&&t(this.shadowRoot)}static flattenedParent(e){return e instanceof Element&&e.assignedSlot?e.assignedSlot:e instanceof ShadowRoot?e.host:e.parentNode}resolveAncestorZoneTheme(e){let t=n.flattenedParent(this);for(;t;){if(t instanceof Element&&t.localName==="esp-root")return null;if(t instanceof n){const r=t.contextBacker.trim();if(r){const o=this.resolveNamedContextTheme(e,r);if(o)return o}}t=n.flattenedParent(t)}return null}connectedCallback(){super.connectedCallback();const e=this.syncRootFromDom(!1);e&&this.subscribeToRootEvents(e)}disconnectedCallback(){super.disconnectedCallback(),this.unsubscribeFromRootEvents(),this.clearScopedTokens(),this.espRoot=null}firstUpdated(e){this.syncRootFromDom(!0),this.applyTokensWhenRootReady()}syncRootFromDom(e){const t=b(this,"esp-root");if(!t){if(this.espRoot&&this.clearScopedTokens(),this.unsubscribeFromRootEvents(),this.espRoot=null,!e)return null;throw new Error("No esp-root ancestor found. Espalier components must be placed inside an <esp-root> element.")}const r=t!==this.espRoot,s=t.scheme==="dark"?"dark":"light",a=this.scheme!==s,i=this.seedColor!==t.seedColor;return this.espRoot=t,r&&this.isConnected&&this.subscribeToRootEvents(t),(r||a||i)&&(this.scheme=s,this.seedColor=t.seedColor,this.applyTokensWhenRootReady()),r&&this.requestUpdate(),t}applyTokensWhenRootReady(){const e=this.espRoot;if(e&&(!e.hasUpdated||e.isUpdatePending)){this.applyTokensAfterInitialRootUpdate(e);return}this.applyScopedColorTokens()}applyTokensAfterInitialRootUpdate(e){if(this.pendingInitialThemeRoot===e)return;this.pendingInitialThemeRoot=e;const t=e.updateComplete;if(!t){this.pendingInitialThemeRoot=null,this.applyScopedColorTokens();return}t.then(()=>{this.pendingInitialThemeRoot===e&&(this.pendingInitialThemeRoot=null),!(!this.isConnected||this.espRoot!==e)&&(this.scheme=e.scheme==="dark"?"dark":"light",this.seedColor=e.seedColor,this.applyScopedColorTokens())})}subscribeToRootEvents(e){this.rootEventSubscriptionsActive&&this.subscribedRoot===e||(this.unsubscribeFromRootEvents(),this.subscribedRoot=e,this.rootEventUnsubscribers=[u(e,"seed-color-changed",this.handleSeedColorChanged),u(e,"scheme-changed",this.handleSchemeChanged),u(e,"theme-changed",this.handleThemeChanged),u(e,"icon-sprite-url-changed",this.handleIconSpriteUrlChanged)],this.rootEventSubscriptionsActive=!0)}unsubscribeFromRootEvents(){if(this.rootEventSubscriptionsActive){for(const e of this.rootEventUnsubscribers)e();this.rootEventUnsubscribers=[],this.subscribedRoot=null,this.rootEventSubscriptionsActive=!1}}traverseToClosest(e){return b(this,e)}applyScopedColorTokens(){if(!this.espRoot)return;const e=this.intentEmitsTokens?n.intentColorSources[this.intentBacker]:"";if(!e&&!this.context.trim()){this.clearScopedTokens();return}const t=this.espRoot.activeTheme;if(!t){this.clearScopedTokens();return}const r=this.resolveContextTheme(t),o=r.theme,s=w(o.seedColor);if(!s)return;const a=v(s,o),i={};if(r.applied&&(Object.assign(i,m(o,a)),Object.assign(i,E(o)),Object.assign(i,V)),e){let c=o;r.applied||(c=this.resolveAncestorZoneTheme(t)??o);const l=c===o?a:v(s,c),T=m(c,l,{effectiveSource:(g,d)=>n.semanticActionTokens.has(g)?e:d});i["--esp-color-primary"]=x(P(l[e]));for(const g of n.semanticActionTokens){const d=A(g);i[d]=T[d]}}this.applyScopedTokenProperties(i)}resolveContextTheme(e){const t=this.context.trim();if(!t)return{applied:!1,theme:e};const r=this.resolveNamedContextTheme(e,t);return r?{applied:!0,theme:r}:(this.warnedUnknownContexts.has(t)||(this.warnedUnknownContexts.add(t),console.warn(`Espalier context: "${t}" is not defined by the active theme; inheriting root tokens.`)),{applied:!1,theme:e})}resolveNamedContextTheme(e,t){const r=e.contexts&&Object.prototype.hasOwnProperty.call(e.contexts,t)?e.contexts[t]:void 0;if(!r)return null;let o=k.get(e);const s=o?.get(t);if(s)return s;const a={};for(const c of U){const l=r[c];l!==void 0&&(a[c]=l)}const i=I(e,{lightness:r.lightness,roles:a});return o||(o=new Map,k.set(e,o)),o.set(t,i),i}applyScopedTokenProperties(e){for(const t of this.scopedTokenOriginalValues.keys())t in e||this.restoreScopedTokenProperty(t);for(const[t,r]of Object.entries(e))this.setScopedTokenProperty(t,r)}setScopedTokenProperty(e,t){const r=this.scopedTokenOriginalValues.get(e);if(r){const o=this.style.getPropertyValue(e),s=this.style.getPropertyPriority(e);(o!==r.generatedValue||s!==r.generatedPriority)&&(r.originalValue=o.length?o:null,r.originalPriority=s),r.generatedValue=t,r.generatedPriority=""}else{const o=this.style.getPropertyValue(e);this.scopedTokenOriginalValues.set(e,{generatedPriority:"",generatedValue:t,originalPriority:this.style.getPropertyPriority(e),originalValue:o.length?o:null})}this.style.setProperty(e,t)}restoreScopedTokenProperty(e){const t=this.scopedTokenOriginalValues.get(e);if(!t)return;const r=this.style.getPropertyValue(e),o=this.style.getPropertyPriority(e);(r!==t.generatedValue||o!==t.generatedPriority)&&(t.originalValue=r.length?r:null,t.originalPriority=o),t.originalValue===null?this.style.removeProperty(e):this.style.setProperty(e,t.originalValue,t.originalPriority),this.scopedTokenOriginalValues.delete(e)}clearScopedTokens(){for(const e of[...this.scopedTokenOriginalValues.keys()])this.restoreScopedTokenProperty(e)}}n.intentColorSources={danger:"danger",info:"info",neutral:"",success:"success",warning:"warning"},n.semanticActionTokens=new Set(["actionBackground","actionText"]),n.styles=[D(".esp-field:focus-within","--esp-field-focus-shadow"),O,R`
|
|
2
2
|
:host {
|
|
3
3
|
|
|
4
4
|
--_esp-field-resolved-hover-bg: var(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const i=["tiny","small","normal","medium","big","large","huge"],w=2,z=1.125,E=1.3333333333333333,g=[["tiny","small"],["small","normal"],["normal","medium"],["medium","big"],["big","large"],["large","huge"]],h=.375,T={rootFontSize:16,typeRatio:1.25,spaceRatio:1.618,borderRadius:.2,viewportMin:320,viewportMax:1200};function l(o,e=4){const s=10**e;return Math.round(o*s)/s}function S(o,e,s,t,r){if(Math.abs(e-o)<1e-4)return`${l(o)}rem`;const m=(e-o)*s*100/(r-t),p=o-m*t/(100*s);return`clamp(${l(o)}rem, ${l(p)}rem + ${l(m)}vw, ${l(e)}rem)`}function x(o){const e={};for(let s=0;s<i.length;s++){const t=s-2,r=1.125*o.typeRatio**t;e[i[s]]={min:r,max:r*E}}return e}function _(o){const e={};for(let s=0;s<i.length;s++){const t=h*o.spaceRatio**s;e[i[s]]={min:t,max:t*E}}return e}const v={"--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)"};function A(o){const e={},{rootFontSize:s,viewportMin:t,viewportMax:r,borderRadius:m}=o,p=16,a=s/p,f=x(o);for(const n of i){const{min:c,max:d}=f[n];e[`--esp-type-${n}`]=S(c*a,d*a,p,t,r)}const u=_(o);for(const n of i){const{min:c,max:d}=u[n];e[`--esp-size-${n}`]=S(c*a,d*a,p,t,r)}for(const[n,c]of g)e[`--esp-size-${n}-to-${c}`]=S(u[n].min*a,u[c].max*a,p,t,r);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"]=`${l(m*a)}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,v),e["--esp-card-min"]="16rem",e}export{T as DEFAULT_SCALE_CONFIG,v as ELEVATION_PROPERTIES,i as STEP_NAMES,A as generateScaleProperties};
|
package/dist/shared/theme.d.ts
CHANGED
|
@@ -628,7 +628,8 @@ export declare function parseTheme(base64: string): PartialTheme | null;
|
|
|
628
628
|
/**
|
|
629
629
|
* Encode a {@link PartialTheme} as a Base64 JSON string.
|
|
630
630
|
*
|
|
631
|
-
* The inverse of {@link parseTheme}.
|
|
631
|
+
* The inverse of {@link parseTheme}. Unicode-safe: theme strings (font
|
|
632
|
+
* names, anchor slugs' display metadata) may carry any code point.
|
|
632
633
|
*
|
|
633
634
|
* @param partial The partial theme to encode.
|
|
634
635
|
* @returns A Base64-encoded JSON string.
|
package/dist/shared/theme.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ACCEPTED_COLOR_FORMS as ee,apcaContrast as et,clampChannel as le,deriveSemantic as we,gamutMapToSRGB as fe,linearRgbToOklab as tt,oklchToSRGB as nt,parseCssColor as N,parseOklch as ot,serializeOklch as ae,srgbToLinearRGB as st}from"./color-engine.js";import{computeVariants as Te,parseAnchorSource as rt,resolveAnchorColor as at,resolveMappingSource as Ee}from"./variant-engine.js";import{auditColorDistances as _e,auditDataPalette as it,DATA_SERIES_KEYS as ie,DEFAULT_DATA_PALETTE as pe,DEFAULT_DATA_RAMP_STEPS as ct,MAX_DATA_RAMP_STEPS as me,MIN_DATA_RAMP_LIGHTNESS_STEP as Ie,MIN_DATA_RAMP_STEPS as he}from"./data-colors.js";const z=/^[a-z][a-z0-9-]*$/;function de(e){return rt(e)}function Le(e,n){return at(e,n)}function ut(e,n){const t=de(e);if(t){const s=Le(n,t);return s&&N(s)?s:null}return N(e)?e:null}const Z=["canvas","ink","accent","action","structure"],He={canvas:{color:[["background","surface"],["layer1","raised1"],["layer2","raised2"],["layer3","raised3"],["layer4","raised4"]]},ink:{color:[["text","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"]]}},lt=new Set(["action.color"]),ft={canvas:"background",ink:"text",accent:"link",action:"actionBackground",structure:"border"},pt={"action.ink":{role:"canvas",slot:"color"}},mt=.45;function Pe(e,n){const t=Ne.actionText,s=[...U].sort((p,S)=>e[p]-e[S]||U.indexOf(p)-U.indexOf(S)),a=n?s.filter(p=>n(p)>=t.targetLc):s,u=a.length>0?a:s;let f,h=1/0;for(const p of u){const S=Math.abs(e[p]-mt);S<h&&(h=S,f=p)}return f??"muted"}function ht(e,n){const t=n[e]>.5;let s=U[0];for(const a of U)(t?n[a]<n[s]:n[a]>n[s])&&(s=a);return s}const dt={"accent.hover":"text"};function gt(e,n){const t=new Map;try{const s=se(n,e),a=(u,f,h,p)=>{const S=de(f),$=S?Le(p,S):null,x=$===null?null:N($),C=t.get(u)??[];C.some(o=>o.source===f&&o.chroma===x?.c)||(C.push({source:f,where:h,chroma:x?.c}),t.set(u,C))};for(const[u,f]of Object.entries(s.semanticMappings))f.source.startsWith("anchor:")&&a(u,f.source,"the root table",s.anchors);for(const[u,f]of Object.entries(s.contexts)){const h={};for(const S of Z){const $=f[S];$!==void 0&&(h[S]=$)}const p=se(s,{lightness:f.lightness,roles:h});for(const[S,$]of Object.entries(p.semanticMappings))$.source.startsWith("anchor:")&&a(S,$.source,`contexts.${u}`,p.anchors)}}catch{return new Map}return t}function te(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 De(e,n,t,s={}){const a={},u={};for(const[f,h]of Object.entries(s.explicitMappings??{}))h!==void 0&&(u[f]=h.lightness);for(const f of Z){const h=e[f];if(h!==void 0)for(const[p,S]of Object.entries(He[f])){const $=pt[`${f}.${p}`];let x=te(h,p),C=!1;if(x===void 0){$&&(x=te(e[$.role],$.slot),x??=t[ft[$.role]]?.source,C=x!==void 0);const o=dt[`${f}.${p}`];o!==void 0&&(x??=te(h,o)),x??=te(h,"color")}if(x!==void 0)for(const[o,r]of S){let i=r;if(lt.has(`${f}.${p}`))i=Pe(n,s.actionSurfaceContrast?c=>s.actionSurfaceContrast(x,c):void 0);else if(C&&$){const c=Ne[o],m=(c&&u[c.bg])??Pe(n,s.actionSurfaceContrast?y=>s.actionSurfaceContrast(te(h,"color"),y):void 0);i=ht(m,n)}a[o]={source:x,lightness:i}}}}return a}const Ne={text:{bg:"background",targetLc:75},dangerText:{bg:"background",targetLc:75},headings:{bg:"background",targetLc:60},headingsHover:{bg:"background",targetLc:60},link:{bg:"background",targetLc:75},linkHover:{bg:"background",targetLc:75},actionText:{bg:"actionBackground",targetLc:75},inputCaret:{bg:"layer2",targetLc:60},inputSelection:{bg:"inputSelectionBg",targetLc:60}},ge=["background","layer1","layer2","layer3","layer4","actionBackground","actionText","border","shadow","text","dangerText","headings","headingsHover","link","linkHover","linkHoverBg","inputCaret","inputSelection","inputSelectionBg"],ye=["primary","analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning","info"],Q=["danger","success","warning","info"],yt=["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"],bt={surface:.99,raised1:.97,raised2:.9,raised3:.8,raised4:.72,accent:.5,muted:.45,text:.35,border:.3,ink:.25,shadow:.2},$t={surface:.15,raised1:.2,raised2:.3,raised3:.4,raised4:.36,accent:.6,muted:.75,text:.85,border:.7,ink:.95,shadow:.6},be={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"},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"}},G=.4;function $e(){const e={};for(const n of ge)e[n]={min:0,max:G};return e}const Fe={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:{},chroma:$e(),semanticMappings:{...be},anchors:{},roles:{},contexts:{},dataPalette:{...pe},dataRamps:{}},Se={...Fe,chroma:$e(),semanticMappings:{...be},anchors:{},roles:{},contexts:{},dataPalette:{...pe},dataRamps:{},lightness:{...bt}},We={...Fe,chroma:$e(),semanticMappings:{...be},anchors:{},roles:{},contexts:{},dataPalette:{...pe},dataRamps:{},lightness:{...$t}},ce=new WeakMap;ce.set(Se,new Set),ce.set(We,new Set);const je=new Set(["__proto__","constructor","prototype"]);function A(e){return!je.has(e)}function St(e,n){return je.has(e)?void 0:n}function Dt(e){return`--esp-color-${e.replace(/([A-Z])/g,"-$1").replace(/(\d)/g,"-$1").toLowerCase()}`}function xt(e){try{const n=atob(e),t=JSON.parse(n,St);return typeof t!="object"||t===null||Array.isArray(t)?null:t}catch{return null}}function xe(e){return btoa(JSON.stringify(e))}function kt(e){const n={};for(const t of Q){const s=e[t];typeof s=="string"&&(n[t]=s.startsWith("anchor:")?s:ne(s))}return n}function ne(e){if(ot(e))return e;const n=N(e);return n?ae(n):e}function Ke(e,n){const t={};for(const[s,a]of Object.entries(e))A(s)&&(t[s]=a);if(!n)return t;for(const[s,a]of Object.entries(n)){if(a===void 0||!A(s))continue;const u=t[s];if(u!==void 0&&typeof a=="object"&&a!==null){const f={};if(typeof u=="string")f.color=u;else for(const[h,p]of Object.entries(u))A(h)&&(f[h]=p);for(const[h,p]of Object.entries(a))p!==void 0&&A(h)&&(f[h]=p);t[s]=f;continue}t[s]=a}return t}function ze(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const n=e,t={};for(const s of Z){const a=n[s];a!==void 0&&(t[s]=a)}if(typeof n.lightness=="object"&&n.lightness!==null&&!Array.isArray(n.lightness)){const s={};for(const a of U){const u=n.lightness[a];u!==void 0&&(s[a]=u)}t.lightness=s}return t}function At(e,n){const t={};for(const[s,a]of Object.entries(e)){if(!A(s)||!z.test(s))continue;const u=ze(a);u&&(t[s]=u)}if(!n)return t;for(const[s,a]of Object.entries(n)){if(!A(s)||!z.test(s)||a===void 0)continue;const u=ze(a);if(!u)continue;const f=t[s];t[s]={...f??{},...u,...f?.lightness||u.lightness?{lightness:{...f?.lightness,...u.lightness}}:{}}}return t}function J(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Y(e){const n={};for(const[t,s]of Object.entries(e))s!==void 0&&A(t)&&(n[t]=s);return n}function Ue(e){if(!J(e))return e;const n=Y(e);return J(e.lightness)&&(n.lightness=Y(e.lightness)),n}function vt(e,n){const t={};for(const[s,a]of Object.entries(e))A(s)&&(t[s]=Ue(a));if(!n)return t;for(const[s,a]of Object.entries(n)){if(!A(s)||a===void 0)continue;const u=t[s];if(!J(u)||!J(a)){t[s]=Ue(a);continue}const f={...Y(u),...Y(a)};J(u.lightness)&&J(a.lightness)?f.lightness={...Y(u.lightness),...Y(a.lightness)}:J(a.lightness)&&(f.lightness=Y(a.lightness)),t[s]=f}return t}function Rt(e){const n={};for(const[t,s]of Object.entries(e)){if(!A(t))continue;if(typeof s=="string"){n[t]=ne(s);continue}const a={};for(const[u,f]of Object.entries(s))A(u)&&(a[u]=typeof f=="string"?ne(f):f);n[t]=a}return n}function oe(e){return typeof e!="string"?"":e.startsWith("anchor:")?e:ne(e)}function Ot(e){const n={};for(const t of ie)n[t]=oe(e[t]);return n}function Ge(e,n){const t={};for(const[s,a]of Object.entries(e))A(s)&&z.test(s)&&a&&typeof a=="object"&&!Array.isArray(a)&&(t[s]={...a});if(!n)return t;for(const[s,a]of Object.entries(n)){if(!A(s)||!z.test(s)||!a||typeof a!="object"||Array.isArray(a))continue;const u=t[s],f=u!==void 0&&a.type!==void 0&&a.type!==u.type;t[s]={...f?{}:u??{},...a}}return t}function Ct(e){const n={};for(const[t,s]of Object.entries(e))if(A(t)){if(s.type==="sequential"&&typeof s.source=="string"){n[t]={...s,source:oe(s.source)};continue}if(s.type==="diverging"&&typeof s.start=="string"&&typeof s.end=="string"){n[t]={...s,start:oe(s.start),end:oe(s.end),...typeof s.neutral=="string"?{neutral:oe(s.neutral)}:{}};continue}n[t]={...s}}return n}function Ve(e){const n=N(e.seedColor);if(!n)return;const t=Te(n,e);return(s,a)=>{const u=Ee(s,t,e.anchors)??t.primary,f=e.chroma.actionBackground,h=we(u,e.lightness[a],f.min,f.max),p={l:h.l>.5?0:1,c:0,h:0};return Math.abs(et(p,h))}}function Mt(e){const n=ce.get(e);if(n)return new Set(n);const t=new Set,s=De(e.roles,e.lightness,e.semanticMappings,{actionSurfaceContrast:Ve(e)});for(const[a,u]of Object.entries(s)){const f=e.semanticMappings[a];(f.source!==u.source||f.lightness!==u.lightness)&&t.add(a)}return t}function se(e,n){const t={...e.roles,...n.roles},s=At(e.contexts,n.contexts),a={...e.lightness,...n.lightness},u=Rt(Ke(e.anchors,n.anchors)),f=typeof n.seedColor=="string"?ne(n.seedColor):e.seedColor,h=n.semanticMappings,p={...e.angles,...n.angles},S={...e.semanticHues,...n.semanticHues},$={...e.variantChroma,...n.variantChroma},x=kt({...e.intents,...n.intents}),C=re(e.chroma,n.chroma),o=Ot(re(e.dataPalette,n.dataPalette)),r=Ct(Ge(e.dataRamps,n.dataRamps)),i=Mt(e),c=new Set(i),m={};for(const g of i)m[g]=e.semanticMappings[g];for(const[g,b]of Object.entries(h??{}))b!==void 0&&(c.add(g),m[g]=b);const y=re(e.semanticMappings,h),I=Ve({angles:p,anchors:u,chroma:C,intents:x,lightness:a,seedColor:f,semanticHues:S,variantChroma:$}),D=De(t,a,y,{explicitMappings:m,actionSurfaceContrast:I}),W={};for(const[g,b]of Object.entries(D))c.has(g)||(W[g]=b);const l=re(re(e.semanticMappings,W),h),d={...e,seedColor:f,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:p,semanticHues:S,variantChroma:$,intents:x,lightness:a,chroma:C,semanticMappings:l,anchors:u,roles:t,contexts:s,dataPalette:o,dataRamps:r};return n.pageBackgroundImage!==void 0&&(d.pageBackgroundImage=n.pageBackgroundImage),n.pageBackgroundImageOpacity!==void 0&&(d.pageBackgroundImageOpacity=n.pageBackgroundImageOpacity),n.boxBackgroundImage!==void 0&&(d.boxBackgroundImage=n.boxBackgroundImage),n.boxBackgroundImageOpacity!==void 0&&(d.boxBackgroundImageOpacity=n.boxBackgroundImageOpacity),n.vellumOpacity!==void 0&&(d.vellumOpacity=n.vellumOpacity),n.vellumBackgroundImage!==void 0&&(d.vellumBackgroundImage=n.vellumBackgroundImage),n.vellumBackgroundImageOpacity!==void 0&&(d.vellumBackgroundImageOpacity=n.vellumBackgroundImageOpacity),ce.set(d,new Set(c)),d}function re(e,n){if(!n)return{...e};const t={...e};for(const s of Object.keys(n)){const a=n[s];a!==void 0&&(t[s]=a)}return t}function ke(e){let n;try{n=atob(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 Nt(e){const n=ke(e);return n.error!==void 0?{valid:!1,errors:[n.error],warnings:[]}:Ae(n.value)}function Ae(e,n=Se){const t=[],s=[];"seedColor"in e&&(typeof e.seedColor!="string"?t.push("seedColor must be a string."):N(e.seedColor)||t.push(`seedColor is not a valid CSS color: "${e.seedColor}". Accepted forms: ${ee}.`));for(const o of["fontBody","fontHeadings","fontBrand","fontMonospace"])o in e&&typeof e[o]!="string"&&t.push(`${o} must be a string.`);const a=["normal","bold","lighter","bolder"],u=["inherit","initial","unset","revert","revert-layer"];for(const o of["fontWeightBody","fontWeightHeadings","fontWeightBrand","fontWeightMonospace"])if(o in e){const r=e[o];if(typeof r=="number")(r<1||r>1e3)&&t.push(`${o} numeric value must be 1\u20131000 (got ${r}).`);else if(typeof r=="string"){const i=a.includes(r)||u.includes(r);if(/^\d+$/.test(r)){const m=Number(r);(m<1||m>1e3)&&t.push(`${o} numeric value must be 1\u20131000 (got "${r}").`)}else i||s.push(`${o} = "${r}" is not a standard font-weight value.`)}else t.push(`${o} must be a string or number.`)}"stylesheets"in e&&(Array.isArray(e.stylesheets)?e.stylesheets.some(o=>typeof o!="string")&&t.push("Every entry in stylesheets must be a string."):t.push("stylesheets must be an array of strings."));const f=[["rootFontSize",1,100],["borderRadius",0,10],["viewportMin",100,1e4],["viewportMax",200,1e4]];for(const[o,r,i]of f)if(o in e)if(typeof e[o]!="number"||!isFinite(e[o]))t.push(`${o} must be a finite number.`);else{const c=e[o];r!==void 0&&c<r&&t.push(`${o} must be \u2265 ${r} (got ${c}).`),i!==void 0&&c>i&&s.push(`${o} = ${c} is unusually high (max ${i}).`)}for(const o of["typeRatio","spaceRatio"])if(o in e)if(typeof e[o]!="number"||!isFinite(e[o]))t.push(`${o} must be a finite number.`);else{const r=e[o];r<=1&&t.push(`${o} must be > 1 (got ${r}).`);const i=o==="typeRatio"?1.3:2;r>i&&s.push(`${o} = ${r} is very high (max ${i}); scales may be extreme.`)}if("viewportMin"in e&&"viewportMax"in e){const o=e.viewportMin,r=e.viewportMax;typeof o=="number"&&typeof r=="number"&&o>=r&&t.push(`viewportMin (${o}) 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 o=e.angles;for(const r of["analogous","complementary","splitComplementary","triadic"])if(r in o)if(typeof o[r]!="number"||!isFinite(o[r]))t.push(`angles.${r} must be a finite number.`);else{const i=o[r];(i<0||i>360)&&s.push(`angles.${r} = ${i} 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 o=e.semanticHues;for(const r of["danger","success","warning","info"])if(r in o)if(typeof o[r]!="number"||!isFinite(o[r]))t.push(`semanticHues.${r} must be a finite number.`);else{const i=o[r];(i<0||i>360)&&s.push(`semanticHues.${r} = ${i} 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 o=e.variantChroma;for(const r of yt)if(r in o)if(typeof o[r]!="number"||!isFinite(o[r]))t.push(`variantChroma["${r}"] must be a finite number.`);else{const i=o[r];i<0&&t.push(`variantChroma["${r}"] must be \u2265 0 (got ${i}).`),i>G&&s.push(`variantChroma["${r}"] = ${i} exceeds ${G}.`)}}function h(o,r){if(typeof o!="object"||o===null||Array.isArray(o)){t.push(`${r} must be an object.`);return}const i=o;for(const c of U)if(c in i)if(typeof i[c]!="number"||!isFinite(i[c]))t.push(`${r}.${c} must be a finite number.`);else{const m=i[c];(m<0||m>1)&&t.push(`${r}.${c} must be 0\u20131 (got ${m}).`)}}if("lightness"in e&&h(e.lightness,"lightness"),"chroma"in e)if(typeof e.chroma!="object"||e.chroma===null)t.push("chroma must be an object.");else{const o=e.chroma,r=gt(e,n);for(const i of ge)if(i in o){const c=o[i];if(typeof c!="object"||c===null){t.push(`chroma.${i} must be { min, max }.`);continue}const m=c;for(const I of r.get(i)??[])I.chroma!==void 0&&typeof m.min=="number"&&typeof m.max=="number"&&(I.chroma<m.min-1e-9||I.chroma>m.max+1e-9)&&s.push(`chroma.${i} clamps the anchor-sourced token ${i} ("${I.source}", effective in ${I.where}) and moves it off its declared swatch. Remove the band if that is unintended \u2014 anchors otherwise keep their own chroma.`);const y=c;(typeof y.min!="number"||y.min<0)&&t.push(`chroma.${i}.min must be \u2265 0.`),(typeof y.max!="number"||y.max<0||y.max>G)&&t.push(`chroma.${i}.max must be 0\u2013${G}.`),typeof y.min=="number"&&typeof y.max=="number"&&y.min>y.max&&t.push(`chroma.${i}.min (${y.min}) must be \u2264 max (${y.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[o,r]of Object.entries(e.anchors))if(A(o)?z.test(o)||t.push(`anchors: "${o}" is not a valid anchor name; use a lowercase slug (letters, digits, hyphens).`):t.push(`anchors: "${o}" is a reserved JavaScript property name and cannot be an anchor name; rename it.`),ye.includes(o)&&t.push(`anchors: "${o}" collides with a reserved color source name.`),typeof r=="string")N(r)||t.push(`anchors.${o} is not a valid CSS color: "${r}". Accepted forms: ${ee}.`);else if(typeof r=="object"&&r!==null&&!Array.isArray(r)){const i=r;typeof i.color!="string"&&t.push(`anchors.${o} must declare its base "color".`);for(const[c,m]of Object.entries(i))A(c)?c!=="color"&&!z.test(c)&&t.push(`anchors.${o}: "${c}" is not a valid slot name; use a lowercase slug.`):t.push(`anchors.${o}: "${c}" is a reserved JavaScript property name and cannot be a slot name; rename it.`),typeof m!="string"?t.push(`anchors.${o}.${c} must be a CSS color string.`):N(m)||t.push(`anchors.${o}.${c} is not a valid CSS color: "${m}". Accepted forms: ${ee}.`)}else t.push(`anchors.${o} must be a color string or a { color, \u2026slots } object.`);const p=new Map;if("anchors"in e&&typeof e.anchors=="object"&&e.anchors!==null&&!Array.isArray(e.anchors))for(const[o,r]of Object.entries(e.anchors))p.set(o,r);function S(o,r){const i=de(o);if(!i){t.push(`${r} "${o}" is not valid anchor syntax; use anchor:<name> or anchor:<name>.<slot>.`);return}if(!p.has(i.name)){const c=[...p.keys()];t.push(`${r} references undeclared anchor "${i.name}". Declared anchors: ${c.length>0?c.join(", "):"(none)"}.`);return}if(i.slot!==void 0){const c=p.get(i.name);if(typeof(typeof c=="object"&&c!==null&&!Array.isArray(c)?c[i.slot]:void 0)!="string"){const y=typeof c=="object"&&c!==null?Object.keys(c).filter(I=>I!=="color"):[];t.push(`${r} references unknown slot "${i.slot}" on anchor "${i.name}". Declared slots: ${y.length>0?y.join(", "):"(none)"}.`)}}}function $(o,r){if(o.startsWith("anchor:")){S(o,r);return}ye.includes(o)||t.push(`${r} must be one of: ${ye.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[o,r]of Object.entries(e.intents)){const i=`intents.${o}`;if(!Q.includes(o)){t.push(`${i} is not a status family; expected one of: ${Q.join(", ")}.`);continue}if(typeof r!="string"){t.push(`${i} must be a string (a CSS color or an anchor: reference).`);continue}if(r.startsWith("anchor:")){S(r,i);continue}N(r)||t.push(`${i} "${r}" is not a supported color form or anchor: reference. Accepted forms: ${ee}, 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 x(o,r){if(o.startsWith("anchor:")){S(o,r);return}N(o)||t.push(`${r} is not a valid CSS color: "${o}". Accepted forms: ${ee}, 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 o=e.dataPalette;for(const[r,i]of Object.entries(o)){if(!ie.includes(r)){t.push(`dataPalette.${r} is not a series slot; expected one of: ${ie.join(", ")}.`);continue}typeof i!="string"?t.push(`dataPalette.${r} must be a CSS color or anchor reference string.`):x(i,`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[o,r]of Object.entries(e.dataRamps)){if(A(o)?z.test(o)||t.push(`dataRamps: "${o}" is not a valid ramp name; use a lowercase slug (letters, digits, hyphens).`):t.push(`dataRamps: "${o}" 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.${o} must be a sequential or diverging ramp object.`);continue}const i=r,c=i.steps??ct;if((typeof c!="number"||!Number.isInteger(c)||c<he||c>me)&&t.push(`dataRamps.${o}.steps must be an integer from ${he} through ${me}.`),i.type==="sequential"){typeof i.source!="string"?t.push(`dataRamps.${o}.source must be a CSS color or anchor reference string.`):x(i.source,`dataRamps.${o}.source`);const m=i.lightnessStart??.95,y=i.lightnessEnd??.25;for(const[I,D]of[["lightnessStart",m],["lightnessEnd",y]])(typeof D!="number"||!Number.isFinite(D)||D<0||D>1)&&t.push(`dataRamps.${o}.${I} must be a finite number from 0 through 1.`);typeof m=="number"&&typeof y=="number"&&m<=y?t.push(`dataRamps.${o}.lightnessStart must be greater than lightnessEnd.`):typeof m=="number"&&Number.isFinite(m)&&typeof y=="number"&&Number.isFinite(y)&&typeof c=="number"&&Number.isInteger(c)&&c>=he&&c<=me&&(m-y)/(c-1)<=Ie&&t.push(`dataRamps.${o} lightness bounds must leave more than ${Ie} lightness between serialized stops.`);continue}if(i.type==="diverging"){typeof c=="number"&&Number.isInteger(c)&&c%2===0&&t.push(`dataRamps.${o}.steps must be odd so the neutral is the exact midpoint.`);for(const m of["start","end"])typeof i[m]!="string"?t.push(`dataRamps.${o}.${m} must be a CSS color or anchor reference string.`):x(i[m],`dataRamps.${o}.${m}`);"neutral"in i&&(typeof i.neutral!="string"?t.push(`dataRamps.${o}.neutral must be a CSS color or anchor reference string.`):x(i.neutral,`dataRamps.${o}.neutral`));continue}t.push(`dataRamps.${o}.type must be "sequential" or "diverging".`)}if("dataPalette"in e&&t.length===0){const o=se(Se,e),r={};let i=!0;for(const c of ie){const m=ut(o.dataPalette[c],o.anchors);if(!m){i=!1;break}r[c]=m}if(i)for(const c of it(r))s.push(`dataPalette.${c.series[0]} and dataPalette.${c.series[1]} are only ${c.distance.toFixed(4)} apart under ${c.simulation} simulation (minimum ${c.threshold.toFixed(4)}); also distinguish the series with labels, shapes, or patterns.`)}function C(o,r){if(typeof o!="object"||o===null||Array.isArray(o)){t.push(`${r} must be an object.`);return}const i=o;for(const[c,m]of Object.entries(i)){const y=`${r}.${c}`;if(!Z.includes(c)){t.push(`${y} is not a role; expected one of: ${Z.join(", ")}. (The status family is reserved and is not a role.)`);continue}const I=c,D=He[I];if(typeof m=="string"){$(m,y);continue}if(typeof m!="object"||m===null||Array.isArray(m)){t.push(`${y} must be a color source or a { color, \u2026slots } object.`);continue}const W=m;typeof W.color!="string"&&t.push(`${y} must declare its base "color".`);for(const[l,d]of Object.entries(W)){if(!Object.prototype.hasOwnProperty.call(D,l)||!A(l)){const g=Object.keys(D).filter(b=>b!=="color");t.push(`${y}.${l} is not a slot of the ${I} role. Declared slots: ${g.length>0?g.join(", "):"(none)"}.`);continue}typeof d!="string"?t.push(`${y}.${l} must be a color source string.`):$(d,`${y}.${l}`)}}}if("roles"in e&&C(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[o,r]of Object.entries(e.contexts)){if(!A(o)||!z.test(o)){t.push(`contexts.${o} must be a lowercase slug matching ${z.source}.`);continue}if(typeof r!="object"||r===null||Array.isArray(r)){C(r,`contexts.${o}`);continue}const i=r,c=Object.fromEntries(Object.entries(i).filter(([m])=>m!=="lightness"));C(c,`contexts.${o}`),"lightness"in i&&h(i.lightness,`contexts.${o}.lightness`)}if("semanticMappings"in e)if(typeof e.semanticMappings!="object"||e.semanticMappings===null)t.push("semanticMappings must be an object.");else{const o=e.semanticMappings;for(const r of ge)if(r in o){const i=o[r];if(typeof i!="object"||i===null){t.push(`semanticMappings.${r} must be { source, lightness }.`);continue}const c=i;typeof c.source!="string"?t.push(`semanticMappings.${r}.source must be a string.`):$(c.source,`semanticMappings.${r}.source`),(typeof c.lightness!="string"||!U.includes(c.lightness))&&t.push(`semanticMappings.${r}.lightness must be one of: ${U.join(", ")}.`)}}for(const o of["pageBackgroundImage","boxBackgroundImage","vellumBackgroundImage"])o in e&&typeof e[o]!="string"&&t.push(`${o} must be a string.`);for(const o of["pageBackgroundImageOpacity","boxBackgroundImageOpacity","vellumOpacity","vellumBackgroundImageOpacity"])if(o in e)if(typeof e[o]!="number"||!isFinite(e[o]))t.push(`${o} must be a finite number.`);else{const r=e[o];(r<0||r>1)&&t.push(`${o} must be 0\u20131 (got ${r}).`)}return s.push(...Bt(e,n)),{valid:t.length===0,errors:t,warnings:s}}const O=.045;function Bt(e,n){try{return wt(e,n)}catch{return[]}}function wt(e,n){const t=se(n,e),s=qe(t),a=[...s],u=new Set(s);for(const[f,h]of Object.entries(t.contexts)){const p={};for(const $ of Z){const x=h[$];x!==void 0&&(p[$]=x)}const S=se(t,{lightness:h.lightness,roles:p});for(const $ of qe(S))u.has($)||a.push(`contexts.${f}: ${$}`)}return a}function Tt(e){const n=nt(fe(e)),t=st(n);return tt({r:le(t.r),g:le(t.g),b:le(t.b)})}function q(e,n){return Math.hypot(e.L-n.L,e.a-n.a,e.b-n.b)}function V(e){return Tt(N(ae(fe(e))))}function Je(e){return(Math.floor(e*1e4)/1e4).toFixed(4)}const X=2,Ye=1e-4;function qe(e){const n=N(e.seedColor);if(!n)return[];const t=Te(n,e),s=e.semanticMappings.actionBackground,a=e.chroma.actionBackground,u=e.lightness[s.lightness],f=(l,d,g,b)=>fe(we(l,d,g,b)),h=Q.map(l=>({name:l,base:t[l]})),p=[];if(Q.includes(s.source))p.push(`actionBackground is sourced from the "${s.source}" status family: ordinary and ${s.source}-intent action surfaces render identically (their labels may still differ). Remap the action to a non-status source \u2014 retuning "${s.source}" via intents moves both colors together.`);else{const l=Ee(s.source,t,e.anchors);l&&h.push({name:"action",base:l})}const S=_e(h.map(({name:l,base:d})=>[l,ae(f(d,u,a.min,a.max))]),O,["normal"]);if(S.length===0)return p;const $=new Map,x=(l,d)=>{const g=`${l}:${d}`;let b=$.get(g);if(!b){b=[];for(let w=0;w<360;w+=X)b.push(V({l,c:d,h:w}));$.set(g,b)}return b},C=O-.002,o=(l,d,g,b)=>{const w=Math.hypot(l.a,l.b),M=Math.atan2(l.b,l.a)*180/Math.PI+180;let E=0;for(const B of g===b?[b]:[g,b]){if(B+w<O-1e-4)continue;let L=M,R=q(V({l:d,c:B,h:M}),l);if(R>=O)return R;const P=x(d,B);for(let v=0;v<P.length;v+=1){const k=q(P[v],l);if(k>=O)return k;k>R&&(R=k,L=v*X)}let H=L;for(let v=L-X;v<=L+X;v+=.1){const k=q(V({l:d,c:B,h:v}),l);if(k>=O)return k;k>R&&(R=k,H=v)}if(R>=C)for(let v=H-.1;v<=H+.1;v+=.001){const k=q(V({l:d,c:B,h:v}),l);if(k>=O)return k;k>R&&(R=k)}R>E&&(E=R)}return E},r=(l,d,g)=>{const b=d===g?[g]:[d,g];let w=0;for(const M of b)for(const E of b){if(M+E<O-1e-4)continue;const B=x(l,M),L=x(l,E);let R=0,P=0,H=-1;for(let _=0;_<B.length;_+=1)for(let F=0;F<L.length;F+=1){const j=q(B[_],L[F]);if(j>=O)return j;j>H&&(H=j,R=_*X,P=F*X)}const v=(_,F,j,ve)=>{const Re=[];for(let K=F-j;K<=F+j;K+=ve)Re.push({h:K,lab:V({l,c:E,h:K})});let ue=-1,Oe=_,Ce=F;for(let K=_-j;K<=_+j;K+=ve){const Qe=V({l,c:M,h:K});for(const Me of Re){const Be=q(Qe,Me.lab);Be>ue&&(ue=Be,Oe=K,Ce=Me.h)}}return{distance:ue,hueA:Oe,hueB:Ce}},k=v(R,P,X,.1);if(k.distance>=O)return k.distance;let T=Math.max(H,k.distance);if(T>=C){const _=v(k.hueA,k.hueB,.1,.001);if(_.distance>T&&(T=_.distance),T>=O)return T}T>w&&(w=T)}return w},i=l=>Q.includes(l),c=(l,d,g,b,w)=>{const M=V(f(l.base,g,b,w)),E=V(f(d.base,g,b,w));if(q(M,E)>=O)return{outcome:"direct"};const B=i(l.name)&&i(d.name),L=[l,d].filter(H=>i(H.name)),R=B?"one of them":`"${i(l.name)?l.name:d.name}"`;let P;for(const H of L){const v=o(H===l?E:M,g,b,w);if(v>=O)return{outcome:"retune",target:R};v>=O-Ye&&(P=P??R)}if(B){const H=r(g,b,w);if(H>=O)return{outcome:"retune",target:"both"};H>=O-Ye&&(P=P??"both")}return P!==void 0?{outcome:"near",target:P}:{outcome:"no"}},m=l=>l.outcome==="direct"?4:l.outcome==="retune"?l.target==="both"?2:3:l.outcome==="near"?1:0,y=l=>[...l].sort().join("|"),I=new Set(_e(h.map(({name:l,base:d})=>[l,ae(f(d,u,0,G))]),O,["normal"]).map(l=>y(l.pair))),D=new Map(h.map(l=>[l.name,l])),W=new Map;for(const{pair:l,distance:d}of S){const g=D.get(l[0]),b=D.get(l[1]),w=i(g.name)&&i(b.name),M=c(g,b,u,a.min,a.max);if(M.outcome==="direct"||M.outcome==="retune"){const T=M.target??(w?"one of them":`"${i(g.name)?g.name:b.name}"`);I.has(y(l))?p.push(`Status colors "${l[0]}" and "${l[1]}" are hard to distinguish under normal vision (distance ${Je(d)} < ${O}); status meanings must stay distinguishable \u2014 retune ${T} via intents.`):p.push(`Status colors "${l[0]}" and "${l[1]}" are hard to distinguish as rendered (distance ${Je(d)} < ${O}); the actionBackground chroma band ({ min: ${a.min}, max: ${a.max} }) pushes them together \u2014 widen the band, or retune ${T} via intents.`);continue}const E=c(g,b,u,0,G);let B={outcome:"no"};for(let T=1;T<=19&&B.outcome!=="direct";T+=1){const _=T*.05;if(Math.abs(_-u)<.001)continue;const F=c(g,b,_,a.min,a.max);m(F)>m(B)&&(B=F)}let L={outcome:"no"};const R=E.outcome==="direct"||E.outcome==="retune",P=B.outcome==="direct"||B.outcome==="retune";if(!R&&!P)for(let T=1;T<=19&&L.outcome!=="direct";T+=1){const _=c(g,b,T*.05,0,G);m(_)>m(L)&&(L=_)}const H=Et(E,B,L),v=`${M.outcome}|${H}`;let k=W.get(v);k||(k=[],W.set(v,k)),k.push(l)}for(const[l,d]of W){const g=l.indexOf("|"),b=l.slice(0,g),w=l.slice(g+1),M=d.map(([L,R])=>`"${L}"/"${R}"`),E=M.length>1?`${M.slice(0,-1).join(", ")} and ${M[M.length-1]}`:M[0],B=b==="near"?`Status colors ${E} may not separate by retuning as rendered: at the action stop's lightness (${u}) with the actionBackground chroma band ({ min: ${a.min}, max: ${a.max} }), the closest reachable retune found comes within the audit's search margin of the ${O} threshold`:`Status colors ${E} cannot be separated as rendered: at the action stop's lightness (${u}) with the actionBackground chroma band ({ min: ${a.min}, max: ${a.max} }), no intent retuning can pull ${d.length>1?"these pairs":"the pair"} ${O} apart`;p.push(B+w)}return p}function Et(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 s=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"?`${s} \u2014 change the band and the stop together.`:t.outcome==="retune"?`${s} \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 Ft(e,n){const t=ke(e),s=ke(n),a=t.error!==void 0?{valid:!1,errors:[t.error],warnings:[]}:Ae(t.value),u=s.error!==void 0?{valid:!1,errors:[s.error],warnings:[]}:Ae(s.value,We),f=[...a.errors.map(p=>`light: ${p}`),...u.errors.map(p=>`dark: ${p}`)],h=[...a.warnings.map(p=>`light: ${p}`),...u.warnings.map(p=>`dark: ${p}`)];if(a.valid&&u.valid){const p=new Set(Object.keys(t.value?.contexts??{})),S=new Set(Object.keys(s.value?.contexts??{})),$=[...S].filter(C=>!p.has(C)).sort(),x=[...p].filter(C=>!S.has(C)).sort();($.length>0||x.length>0)&&f.push(`contexts must declare the same names in both schemes. Missing from light: ${$.join(", ")||"(none)"}. Missing from dark: ${x.join(", ")||"(none)"}.`)}return{valid:f.length===0,errors:f,warnings:h}}const _t=["anchors","angles","contexts","dataPalette","dataRamps","intents","roles","chroma","lightness","semanticHues","semanticMappings","variantChroma"];function It(e,n){const t={};for(const[s,a]of Object.entries(e))A(s)&&(t[s]=a);for(const[s,a]of Object.entries(n))a!==void 0&&A(s)&&(t[s]=a);for(const s of _t){const a=e[s],u=n[s];if(a&&typeof a=="object"&&!Array.isArray(a)&&u&&typeof u=="object"&&!Array.isArray(u)){if(s==="anchors"){t[s]=Ke(a,u);continue}if(s==="contexts"){t[s]=vt(a,u);continue}if(s==="dataRamps"){t[s]=Ge(a,u);continue}const f={};for(const[h,p]of Object.entries(a))A(h)&&(f[h]=p);for(const[h,p]of Object.entries(u))p!==void 0&&A(h)&&(f[h]=p);t[s]=f}}return t}function Wt(...e){let n={};for(const t of e){if(!t)continue;const s=xt(t);s&&(n=It(n,s))}return xe(n)}function Xe(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r")}const Ze={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 jt(e){return xe({...Ze,pageBackgroundImage:`url("${Xe(e)}")`,pageBackgroundImageOpacity:.5})}function Kt(e){return xe({...Ze,pageBackgroundImage:`url("${Xe(e)}")`,pageBackgroundImageOpacity:.55})}export{z as ANCHOR_SLUG_PATTERN,ye as COLOR_SOURCES,$t as DEFAULT_DARK_LIGHTNESS,We as DEFAULT_DARK_THEME,bt as DEFAULT_LIGHT_LIGHTNESS,Se as DEFAULT_LIGHT_THEME,be as DEFAULT_SEMANTIC_MAPPINGS,U as LIGHTNESS_KEYS,_t as NESTED_THEME_KEYS,Z as ROLE_NAMES,pt as ROLE_PAIRED_INK,He as ROLE_TOKEN_PLAN,ge as SEMANTIC_COLOR_NAMES,Q as STATUS_COLOR_SOURCES,Ne as TOKEN_PAIRINGS,yt as VARIANT_COLOR_SOURCES,Kt as buildTaprootDarkTheme,jt as buildTaprootLightTheme,De as compileRoles,xe as encodeTheme,Wt as layerThemes,It as mergePartials,se as mergeTheme,de as parseAnchorSource,xt as parseTheme,Le as resolveAnchorColor,ut as resolveDataColorSource,Dt as semanticToCSS,Nt as validateTheme,Ft as validateThemePair};
|
|
1
|
+
import{ACCEPTED_COLOR_FORMS as ee,apcaContrast as nt,clampChannel as le,deriveSemantic as we,gamutMapToSRGB as fe,linearRgbToOklab as ot,oklchToSRGB as st,parseCssColor as N,parseOklch as rt,serializeOklch as ae,srgbToLinearRGB as at}from"./color-engine.js";import{computeVariants as Ee,parseAnchorSource as it,resolveAnchorColor as ct,resolveMappingSource as _e}from"./variant-engine.js";import{auditColorDistances as Ie,auditDataPalette as ut,DATA_SERIES_KEYS as ie,DEFAULT_DATA_PALETTE as pe,DEFAULT_DATA_RAMP_STEPS as lt,MAX_DATA_RAMP_STEPS as me,MIN_DATA_RAMP_LIGHTNESS_STEP as Le,MIN_DATA_RAMP_STEPS as he}from"./data-colors.js";const z=/^[a-z][a-z0-9-]*$/;function de(e){return it(e)}function He(e,n){return ct(e,n)}function ft(e,n){const t=de(e);if(t){const o=He(n,t);return o&&N(o)?o:null}return N(e)?e:null}const Z=["canvas","ink","accent","action","structure"],Pe={canvas:{color:[["background","surface"],["layer1","raised1"],["layer2","raised2"],["layer3","raised3"],["layer4","raised4"]]},ink:{color:[["text","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"]]}},pt=new Set(["action.color"]),mt={canvas:"background",ink:"text",accent:"link",action:"actionBackground",structure:"border"},ht={"action.ink":{role:"canvas",slot:"color"}},dt=.45;function De(e,n){const t=Fe.actionText,o=[...j].sort((p,S)=>e[p]-e[S]||j.indexOf(p)-j.indexOf(S)),a=n?o.filter(p=>n(p)>=t.targetLc):o,u=a.length>0?a:o;let f,h=1/0;for(const p of u){const S=Math.abs(e[p]-dt);S<h&&(h=S,f=p)}return f??"muted"}function gt(e,n){const t=n[e]>.5;let o=j[0];for(const a of j)(t?n[a]<n[o]:n[a]>n[o])&&(o=a);return o}const yt={"accent.hover":"text"};function bt(e,n){const t=new Map;try{const o=se(n,e),a=(u,f,h,p)=>{const S=de(f),$=S?He(p,S):null,x=$===null?null:N($),C=t.get(u)??[];C.some(s=>s.source===f&&s.chroma===x?.c)||(C.push({source:f,where:h,chroma:x?.c}),t.set(u,C))};for(const[u,f]of Object.entries(o.semanticMappings))f.source.startsWith("anchor:")&&a(u,f.source,"the root table",o.anchors);for(const[u,f]of Object.entries(o.contexts)){const h={};for(const S of Z){const $=f[S];$!==void 0&&(h[S]=$)}const p=se(o,{lightness:f.lightness,roles:h});for(const[S,$]of Object.entries(p.semanticMappings))$.source.startsWith("anchor:")&&a(S,$.source,`contexts.${u}`,p.anchors)}}catch{return new Map}return t}function te(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 Ne(e,n,t,o={}){const a={},u={};for(const[f,h]of Object.entries(o.explicitMappings??{}))h!==void 0&&(u[f]=h.lightness);for(const f of Z){const h=e[f];if(h!==void 0)for(const[p,S]of Object.entries(Pe[f])){const $=ht[`${f}.${p}`];let x=te(h,p),C=!1;if(x===void 0){$&&(x=te(e[$.role],$.slot),x??=t[mt[$.role]]?.source,C=x!==void 0);const s=yt[`${f}.${p}`];s!==void 0&&(x??=te(h,s)),x??=te(h,"color")}if(x!==void 0)for(const[s,r]of S){let i=r;if(pt.has(`${f}.${p}`))i=De(n,o.actionSurfaceContrast?c=>o.actionSurfaceContrast(x,c):void 0);else if(C&&$){const c=Fe[s],m=(c&&u[c.bg])??De(n,o.actionSurfaceContrast?y=>o.actionSurfaceContrast(te(h,"color"),y):void 0);i=gt(m,n)}a[s]={source:x,lightness:i}}}}return a}const Fe={text:{bg:"background",targetLc:75},dangerText:{bg:"background",targetLc:75},headings:{bg:"background",targetLc:60},headingsHover:{bg:"background",targetLc:60},link:{bg:"background",targetLc:75},linkHover:{bg:"background",targetLc:75},actionText:{bg:"actionBackground",targetLc:75},inputCaret:{bg:"layer2",targetLc:60},inputSelection:{bg:"inputSelectionBg",targetLc:60}},ge=["background","layer1","layer2","layer3","layer4","actionBackground","actionText","border","shadow","text","dangerText","headings","headingsHover","link","linkHover","linkHoverBg","inputCaret","inputSelection","inputSelectionBg"],ye=["primary","analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning","info"],Q=["danger","success","warning","info"],$t=["analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning","info"],j=["surface","raised1","raised2","raised3","raised4","accent","muted","text","border","ink","shadow"],St={surface:.99,raised1:.97,raised2:.9,raised3:.8,raised4:.72,accent:.5,muted:.45,text:.35,border:.3,ink:.25,shadow:.2},xt={surface:.15,raised1:.2,raised2:.3,raised3:.4,raised4:.36,accent:.6,muted:.75,text:.85,border:.7,ink:.95,shadow:.6},be={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"},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"}},G=.4;function $e(){const e={};for(const n of ge)e[n]={min:0,max:G};return e}const We={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:{},chroma:$e(),semanticMappings:{...be},anchors:{},roles:{},contexts:{},dataPalette:{...pe},dataRamps:{}},Se={...We,chroma:$e(),semanticMappings:{...be},anchors:{},roles:{},contexts:{},dataPalette:{...pe},dataRamps:{},lightness:{...St}},Ke={...We,chroma:$e(),semanticMappings:{...be},anchors:{},roles:{},contexts:{},dataPalette:{...pe},dataRamps:{},lightness:{...xt}},ce=new WeakMap;ce.set(Se,new Set),ce.set(Ke,new Set);const Ue=new Set(["__proto__","constructor","prototype"]);function A(e){return!Ue.has(e)}function kt(e,n){return Ue.has(e)?void 0:n}function Wt(e){return`--esp-color-${e.replace(/([A-Z])/g,"-$1").replace(/(\d)/g,"-$1").toLowerCase()}`}function At(e){try{const n=ze(e),t=JSON.parse(n,kt);return typeof t!="object"||t===null||Array.isArray(t)?null:t}catch{return null}}const xe="\xEF\xBB\xBF";function vt(e){if(/^[\u0000-\u007f]*$/.test(e))return btoa(e);const n=new TextEncoder().encode(e);let t=xe;for(const o of n)t+=String.fromCharCode(o);return btoa(t)}function ze(e){const n=atob(e);if(!n.startsWith(xe))return n;const t=Uint8Array.from(n.slice(xe.length),o=>o.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(t)}function ke(e){return vt(JSON.stringify(e))}function Rt(e){const n={};for(const t of Q){const o=e[t];typeof o=="string"&&(n[t]=o.startsWith("anchor:")?o:ne(o))}return n}function ne(e){if(rt(e))return e;const n=N(e);return n?ae(n):e}function je(e,n){const t={};for(const[o,a]of Object.entries(e))A(o)&&(t[o]=a);if(!n)return t;for(const[o,a]of Object.entries(n)){if(a===void 0||!A(o))continue;const u=t[o];if(u!==void 0&&typeof a=="object"&&a!==null){const f={};if(typeof u=="string")f.color=u;else for(const[h,p]of Object.entries(u))A(h)&&(f[h]=p);for(const[h,p]of Object.entries(a))p!==void 0&&A(h)&&(f[h]=p);t[o]=f;continue}t[o]=a}return t}function Ge(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const n=e,t={};for(const o of Z){const a=n[o];a!==void 0&&(t[o]=a)}if(typeof n.lightness=="object"&&n.lightness!==null&&!Array.isArray(n.lightness)){const o={};for(const a of j){const u=n.lightness[a];u!==void 0&&(o[a]=u)}t.lightness=o}return t}function Ot(e,n){const t={};for(const[o,a]of Object.entries(e)){if(!A(o)||!z.test(o))continue;const u=Ge(a);u&&(t[o]=u)}if(!n)return t;for(const[o,a]of Object.entries(n)){if(!A(o)||!z.test(o)||a===void 0)continue;const u=Ge(a);if(!u)continue;const f=t[o];t[o]={...f??{},...u,...f?.lightness||u.lightness?{lightness:{...f?.lightness,...u.lightness}}:{}}}return t}function V(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Y(e){const n={};for(const[t,o]of Object.entries(e))o!==void 0&&A(t)&&(n[t]=o);return n}function Je(e){if(!V(e))return e;const n=Y(e);return V(e.lightness)&&(n.lightness=Y(e.lightness)),n}function Ct(e,n){const t={};for(const[o,a]of Object.entries(e))A(o)&&(t[o]=Je(a));if(!n)return t;for(const[o,a]of Object.entries(n)){if(!A(o)||a===void 0)continue;const u=t[o];if(!V(u)||!V(a)){t[o]=Je(a);continue}const f={...Y(u),...Y(a)};V(u.lightness)&&V(a.lightness)?f.lightness={...Y(u.lightness),...Y(a.lightness)}:V(a.lightness)&&(f.lightness=Y(a.lightness)),t[o]=f}return t}function Mt(e){const n={};for(const[t,o]of Object.entries(e)){if(!A(t))continue;if(typeof o=="string"){n[t]=ne(o);continue}const a={};for(const[u,f]of Object.entries(o))A(u)&&(a[u]=typeof f=="string"?ne(f):f);n[t]=a}return n}function oe(e){return typeof e!="string"?"":e.startsWith("anchor:")?e:ne(e)}function Tt(e){const n={};for(const t of ie)n[t]=oe(e[t]);return n}function Ve(e,n){const t={};for(const[o,a]of Object.entries(e))A(o)&&z.test(o)&&a&&typeof a=="object"&&!Array.isArray(a)&&(t[o]={...a});if(!n)return t;for(const[o,a]of Object.entries(n)){if(!A(o)||!z.test(o)||!a||typeof a!="object"||Array.isArray(a))continue;const u=t[o],f=u!==void 0&&a.type!==void 0&&a.type!==u.type;t[o]={...f?{}:u??{},...a}}return t}function Bt(e){const n={};for(const[t,o]of Object.entries(e))if(A(t)){if(o.type==="sequential"&&typeof o.source=="string"){n[t]={...o,source:oe(o.source)};continue}if(o.type==="diverging"&&typeof o.start=="string"&&typeof o.end=="string"){n[t]={...o,start:oe(o.start),end:oe(o.end),...typeof o.neutral=="string"?{neutral:oe(o.neutral)}:{}};continue}n[t]={...o}}return n}function Ye(e){const n=N(e.seedColor);if(!n)return;const t=Ee(n,e);return(o,a)=>{const u=_e(o,t,e.anchors)??t.primary,f=e.chroma.actionBackground,h=we(u,e.lightness[a],f.min,f.max),p={l:h.l>.5?0:1,c:0,h:0};return Math.abs(nt(p,h))}}function wt(e){const n=ce.get(e);if(n)return new Set(n);const t=new Set,o=Ne(e.roles,e.lightness,e.semanticMappings,{actionSurfaceContrast:Ye(e)});for(const[a,u]of Object.entries(o)){const f=e.semanticMappings[a];(f.source!==u.source||f.lightness!==u.lightness)&&t.add(a)}return t}function se(e,n){const t={...e.roles,...n.roles},o=Ot(e.contexts,n.contexts),a={...e.lightness,...n.lightness},u=Mt(je(e.anchors,n.anchors)),f=typeof n.seedColor=="string"?ne(n.seedColor):e.seedColor,h=n.semanticMappings,p={...e.angles,...n.angles},S={...e.semanticHues,...n.semanticHues},$={...e.variantChroma,...n.variantChroma},x=Rt({...e.intents,...n.intents}),C=re(e.chroma,n.chroma),s=Tt(re(e.dataPalette,n.dataPalette)),r=Bt(Ve(e.dataRamps,n.dataRamps)),i=wt(e),c=new Set(i),m={};for(const g of i)m[g]=e.semanticMappings[g];for(const[g,b]of Object.entries(h??{}))b!==void 0&&(c.add(g),m[g]=b);const y=re(e.semanticMappings,h),I=Ye({angles:p,anchors:u,chroma:C,intents:x,lightness:a,seedColor:f,semanticHues:S,variantChroma:$}),D=Ne(t,a,y,{explicitMappings:m,actionSurfaceContrast:I}),W={};for(const[g,b]of Object.entries(D))c.has(g)||(W[g]=b);const l=re(re(e.semanticMappings,W),h),d={...e,seedColor:f,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:p,semanticHues:S,variantChroma:$,intents:x,lightness:a,chroma:C,semanticMappings:l,anchors:u,roles:t,contexts:o,dataPalette:s,dataRamps:r};return n.pageBackgroundImage!==void 0&&(d.pageBackgroundImage=n.pageBackgroundImage),n.pageBackgroundImageOpacity!==void 0&&(d.pageBackgroundImageOpacity=n.pageBackgroundImageOpacity),n.boxBackgroundImage!==void 0&&(d.boxBackgroundImage=n.boxBackgroundImage),n.boxBackgroundImageOpacity!==void 0&&(d.boxBackgroundImageOpacity=n.boxBackgroundImageOpacity),n.vellumOpacity!==void 0&&(d.vellumOpacity=n.vellumOpacity),n.vellumBackgroundImage!==void 0&&(d.vellumBackgroundImage=n.vellumBackgroundImage),n.vellumBackgroundImageOpacity!==void 0&&(d.vellumBackgroundImageOpacity=n.vellumBackgroundImageOpacity),ce.set(d,new Set(c)),d}function re(e,n){if(!n)return{...e};const t={...e};for(const o of Object.keys(n)){const a=n[o];a!==void 0&&(t[o]=a)}return t}function Ae(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 Kt(e){const n=Ae(e);return n.error!==void 0?{valid:!1,errors:[n.error],warnings:[]}:ve(n.value)}function ve(e,n=Se){const t=[],o=[];"seedColor"in e&&(typeof e.seedColor!="string"?t.push("seedColor must be a string."):N(e.seedColor)||t.push(`seedColor is not a valid CSS color: "${e.seedColor}". Accepted forms: ${ee}.`));for(const s of["fontBody","fontHeadings","fontBrand","fontMonospace"])s in e&&typeof e[s]!="string"&&t.push(`${s} must be a string.`);const a=["normal","bold","lighter","bolder"],u=["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 i=a.includes(r)||u.includes(r);if(/^\d+$/.test(r)){const m=Number(r);(m<1||m>1e3)&&t.push(`${s} numeric value must be 1\u20131000 (got "${r}").`)}else i||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 f=[["rootFontSize",1,100],["borderRadius",0,10],["viewportMin",100,1e4],["viewportMax",200,1e4]];for(const[s,r,i]of f)if(s in e)if(typeof e[s]!="number"||!isFinite(e[s]))t.push(`${s} must be a finite number.`);else{const c=e[s];r!==void 0&&c<r&&t.push(`${s} must be \u2265 ${r} (got ${c}).`),i!==void 0&&c>i&&o.push(`${s} = ${c} is unusually high (max ${i}).`)}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 i=s==="typeRatio"?1.3:2;r>i&&o.push(`${s} = ${r} is very high (max ${i}); 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 i=s[r];(i<0||i>360)&&o.push(`angles.${r} = ${i} 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 i=s[r];(i<0||i>360)&&o.push(`semanticHues.${r} = ${i} 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 i=s[r];i<0&&t.push(`variantChroma["${r}"] must be \u2265 0 (got ${i}).`),i>G&&o.push(`variantChroma["${r}"] = ${i} exceeds ${G}.`)}}function h(s,r){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const i=s;for(const c of j)if(c in i)if(typeof i[c]!="number"||!isFinite(i[c]))t.push(`${r}.${c} must be a finite number.`);else{const m=i[c];(m<0||m>1)&&t.push(`${r}.${c} must be 0\u20131 (got ${m}).`)}}if("lightness"in e&&h(e.lightness,"lightness"),"chroma"in e)if(typeof e.chroma!="object"||e.chroma===null)t.push("chroma must be an object.");else{const s=e.chroma,r=bt(e,n);for(const i of ge)if(i in s){const c=s[i];if(typeof c!="object"||c===null){t.push(`chroma.${i} must be { min, max }.`);continue}const m=c;for(const I of r.get(i)??[])I.chroma!==void 0&&typeof m.min=="number"&&typeof m.max=="number"&&(I.chroma<m.min-1e-9||I.chroma>m.max+1e-9)&&o.push(`chroma.${i} clamps the anchor-sourced token ${i} ("${I.source}", effective in ${I.where}) and moves it off its declared swatch. Remove the band if that is unintended \u2014 anchors otherwise keep their own chroma.`);const y=c;(typeof y.min!="number"||y.min<0)&&t.push(`chroma.${i}.min must be \u2265 0.`),(typeof y.max!="number"||y.max<0||y.max>G)&&t.push(`chroma.${i}.max must be 0\u2013${G}.`),typeof y.min=="number"&&typeof y.max=="number"&&y.min>y.max&&t.push(`chroma.${i}.min (${y.min}) must be \u2264 max (${y.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(A(s)?z.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.`),ye.includes(s)&&t.push(`anchors: "${s}" collides with a reserved color source name.`),typeof r=="string")N(r)||t.push(`anchors.${s} is not a valid CSS color: "${r}". Accepted forms: ${ee}.`);else if(typeof r=="object"&&r!==null&&!Array.isArray(r)){const i=r;typeof i.color!="string"&&t.push(`anchors.${s} must declare its base "color".`);for(const[c,m]of Object.entries(i))A(c)?c!=="color"&&!z.test(c)&&t.push(`anchors.${s}: "${c}" is not a valid slot name; use a lowercase slug.`):t.push(`anchors.${s}: "${c}" is a reserved JavaScript property name and cannot be a slot name; rename it.`),typeof m!="string"?t.push(`anchors.${s}.${c} must be a CSS color string.`):N(m)||t.push(`anchors.${s}.${c} is not a valid CSS color: "${m}". Accepted forms: ${ee}.`)}else t.push(`anchors.${s} must be a color string or a { color, \u2026slots } object.`);const p=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))p.set(s,r);function S(s,r){const i=de(s);if(!i){t.push(`${r} "${s}" is not valid anchor syntax; use anchor:<name> or anchor:<name>.<slot>.`);return}if(!p.has(i.name)){const c=[...p.keys()];t.push(`${r} references undeclared anchor "${i.name}". Declared anchors: ${c.length>0?c.join(", "):"(none)"}.`);return}if(i.slot!==void 0){const c=p.get(i.name);if(typeof(typeof c=="object"&&c!==null&&!Array.isArray(c)?c[i.slot]:void 0)!="string"){const y=typeof c=="object"&&c!==null?Object.keys(c).filter(I=>I!=="color"):[];t.push(`${r} references unknown slot "${i.slot}" on anchor "${i.name}". Declared slots: ${y.length>0?y.join(", "):"(none)"}.`)}}}function $(s,r){if(s.startsWith("anchor:")){S(s,r);return}ye.includes(s)||t.push(`${r} must be one of: ${ye.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 i=`intents.${s}`;if(!Q.includes(s)){t.push(`${i} is not a status family; expected one of: ${Q.join(", ")}.`);continue}if(typeof r!="string"){t.push(`${i} must be a string (a CSS color or an anchor: reference).`);continue}if(r.startsWith("anchor:")){S(r,i);continue}N(r)||t.push(`${i} "${r}" is not a supported color form or anchor: reference. Accepted forms: ${ee}, 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 x(s,r){if(s.startsWith("anchor:")){S(s,r);return}N(s)||t.push(`${r} is not a valid CSS color: "${s}". Accepted forms: ${ee}, 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,i]of Object.entries(s)){if(!ie.includes(r)){t.push(`dataPalette.${r} is not a series slot; expected one of: ${ie.join(", ")}.`);continue}typeof i!="string"?t.push(`dataPalette.${r} must be a CSS color or anchor reference string.`):x(i,`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(A(s)?z.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 i=r,c=i.steps??lt;if((typeof c!="number"||!Number.isInteger(c)||c<he||c>me)&&t.push(`dataRamps.${s}.steps must be an integer from ${he} through ${me}.`),i.type==="sequential"){typeof i.source!="string"?t.push(`dataRamps.${s}.source must be a CSS color or anchor reference string.`):x(i.source,`dataRamps.${s}.source`);const m=i.lightnessStart??.95,y=i.lightnessEnd??.25;for(const[I,D]of[["lightnessStart",m],["lightnessEnd",y]])(typeof D!="number"||!Number.isFinite(D)||D<0||D>1)&&t.push(`dataRamps.${s}.${I} must be a finite number from 0 through 1.`);typeof m=="number"&&typeof y=="number"&&m<=y?t.push(`dataRamps.${s}.lightnessStart must be greater than lightnessEnd.`):typeof m=="number"&&Number.isFinite(m)&&typeof y=="number"&&Number.isFinite(y)&&typeof c=="number"&&Number.isInteger(c)&&c>=he&&c<=me&&(m-y)/(c-1)<=Le&&t.push(`dataRamps.${s} lightness bounds must leave more than ${Le} lightness between serialized stops.`);continue}if(i.type==="diverging"){typeof c=="number"&&Number.isInteger(c)&&c%2===0&&t.push(`dataRamps.${s}.steps must be odd so the neutral is the exact midpoint.`);for(const m of["start","end"])typeof i[m]!="string"?t.push(`dataRamps.${s}.${m} must be a CSS color or anchor reference string.`):x(i[m],`dataRamps.${s}.${m}`);"neutral"in i&&(typeof i.neutral!="string"?t.push(`dataRamps.${s}.neutral must be a CSS color or anchor reference string.`):x(i.neutral,`dataRamps.${s}.neutral`));continue}t.push(`dataRamps.${s}.type must be "sequential" or "diverging".`)}if("dataPalette"in e&&t.length===0){const s=se(Se,e),r={};let i=!0;for(const c of ie){const m=ft(s.dataPalette[c],s.anchors);if(!m){i=!1;break}r[c]=m}if(i)for(const c of ut(r))o.push(`dataPalette.${c.series[0]} and dataPalette.${c.series[1]} are only ${c.distance.toFixed(4)} apart under ${c.simulation} simulation (minimum ${c.threshold.toFixed(4)}); also distinguish the series with labels, shapes, or patterns.`)}function C(s,r){if(typeof s!="object"||s===null||Array.isArray(s)){t.push(`${r} must be an object.`);return}const i=s;for(const[c,m]of Object.entries(i)){const y=`${r}.${c}`;if(!Z.includes(c)){t.push(`${y} is not a role; expected one of: ${Z.join(", ")}. (The status family is reserved and is not a role.)`);continue}const I=c,D=Pe[I];if(typeof m=="string"){$(m,y);continue}if(typeof m!="object"||m===null||Array.isArray(m)){t.push(`${y} must be a color source or a { color, \u2026slots } object.`);continue}const W=m;typeof W.color!="string"&&t.push(`${y} must declare its base "color".`);for(const[l,d]of Object.entries(W)){if(!Object.prototype.hasOwnProperty.call(D,l)||!A(l)){const g=Object.keys(D).filter(b=>b!=="color");t.push(`${y}.${l} is not a slot of the ${I} role. Declared slots: ${g.length>0?g.join(", "):"(none)"}.`);continue}typeof d!="string"?t.push(`${y}.${l} must be a color source string.`):$(d,`${y}.${l}`)}}}if("roles"in e&&C(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(!A(s)||!z.test(s)){t.push(`contexts.${s} must be a lowercase slug matching ${z.source}.`);continue}if(typeof r!="object"||r===null||Array.isArray(r)){C(r,`contexts.${s}`);continue}const i=r,c=Object.fromEntries(Object.entries(i).filter(([m])=>m!=="lightness"));C(c,`contexts.${s}`),"lightness"in i&&h(i.lightness,`contexts.${s}.lightness`)}if("semanticMappings"in e)if(typeof e.semanticMappings!="object"||e.semanticMappings===null)t.push("semanticMappings must be an object.");else{const s=e.semanticMappings;for(const r of ge)if(r in s){const i=s[r];if(typeof i!="object"||i===null){t.push(`semanticMappings.${r} must be { source, lightness }.`);continue}const c=i;typeof c.source!="string"?t.push(`semanticMappings.${r}.source must be a string.`):$(c.source,`semanticMappings.${r}.source`),(typeof c.lightness!="string"||!j.includes(c.lightness))&&t.push(`semanticMappings.${r}.lightness must be one of: ${j.join(", ")}.`)}}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(...Et(e,n)),{valid:t.length===0,errors:t,warnings:o}}const O=.045;function Et(e,n){try{return _t(e,n)}catch{return[]}}function _t(e,n){const t=se(n,e),o=Ze(t),a=[...o],u=new Set(o);for(const[f,h]of Object.entries(t.contexts)){const p={};for(const $ of Z){const x=h[$];x!==void 0&&(p[$]=x)}const S=se(t,{lightness:h.lightness,roles:p});for(const $ of Ze(S))u.has($)||a.push(`contexts.${f}: ${$}`)}return a}function It(e){const n=st(fe(e)),t=at(n);return ot({r:le(t.r),g:le(t.g),b:le(t.b)})}function q(e,n){return Math.hypot(e.L-n.L,e.a-n.a,e.b-n.b)}function J(e){return It(N(ae(fe(e))))}function qe(e){return(Math.floor(e*1e4)/1e4).toFixed(4)}const X=2,Xe=1e-4;function Ze(e){const n=N(e.seedColor);if(!n)return[];const t=Ee(n,e),o=e.semanticMappings.actionBackground,a=e.chroma.actionBackground,u=e.lightness[o.lightness],f=(l,d,g,b)=>fe(we(l,d,g,b)),h=Q.map(l=>({name:l,base:t[l]})),p=[];if(Q.includes(o.source))p.push(`actionBackground is sourced from the "${o.source}" status family: ordinary and ${o.source}-intent action surfaces render identically (their labels may still differ). Remap the action to a non-status source \u2014 retuning "${o.source}" via intents moves both colors together.`);else{const l=_e(o.source,t,e.anchors);l&&h.push({name:"action",base:l})}const S=Ie(h.map(({name:l,base:d})=>[l,ae(f(d,u,a.min,a.max))]),O,["normal"]);if(S.length===0)return p;const $=new Map,x=(l,d)=>{const g=`${l}:${d}`;let b=$.get(g);if(!b){b=[];for(let B=0;B<360;B+=X)b.push(J({l,c:d,h:B}));$.set(g,b)}return b},C=O-.002,s=(l,d,g,b)=>{const B=Math.hypot(l.a,l.b),M=Math.atan2(l.b,l.a)*180/Math.PI+180;let E=0;for(const T of g===b?[b]:[g,b]){if(T+B<O-1e-4)continue;let L=M,R=q(J({l:d,c:T,h:M}),l);if(R>=O)return R;const P=x(d,T);for(let v=0;v<P.length;v+=1){const k=q(P[v],l);if(k>=O)return k;k>R&&(R=k,L=v*X)}let H=L;for(let v=L-X;v<=L+X;v+=.1){const k=q(J({l:d,c:T,h:v}),l);if(k>=O)return k;k>R&&(R=k,H=v)}if(R>=C)for(let v=H-.1;v<=H+.1;v+=.001){const k=q(J({l:d,c:T,h:v}),l);if(k>=O)return k;k>R&&(R=k)}R>E&&(E=R)}return E},r=(l,d,g)=>{const b=d===g?[g]:[d,g];let B=0;for(const M of b)for(const E of b){if(M+E<O-1e-4)continue;const T=x(l,M),L=x(l,E);let R=0,P=0,H=-1;for(let _=0;_<T.length;_+=1)for(let F=0;F<L.length;F+=1){const K=q(T[_],L[F]);if(K>=O)return K;K>H&&(H=K,R=_*X,P=F*X)}const v=(_,F,K,Re)=>{const Oe=[];for(let U=F-K;U<=F+K;U+=Re)Oe.push({h:U,lab:J({l,c:E,h:U})});let ue=-1,Ce=_,Me=F;for(let U=_-K;U<=_+K;U+=Re){const tt=J({l,c:M,h:U});for(const Te of Oe){const Be=q(tt,Te.lab);Be>ue&&(ue=Be,Ce=U,Me=Te.h)}}return{distance:ue,hueA:Ce,hueB:Me}},k=v(R,P,X,.1);if(k.distance>=O)return k.distance;let w=Math.max(H,k.distance);if(w>=C){const _=v(k.hueA,k.hueB,.1,.001);if(_.distance>w&&(w=_.distance),w>=O)return w}w>B&&(B=w)}return B},i=l=>Q.includes(l),c=(l,d,g,b,B)=>{const M=J(f(l.base,g,b,B)),E=J(f(d.base,g,b,B));if(q(M,E)>=O)return{outcome:"direct"};const T=i(l.name)&&i(d.name),L=[l,d].filter(H=>i(H.name)),R=T?"one of them":`"${i(l.name)?l.name:d.name}"`;let P;for(const H of L){const v=s(H===l?E:M,g,b,B);if(v>=O)return{outcome:"retune",target:R};v>=O-Xe&&(P=P??R)}if(T){const H=r(g,b,B);if(H>=O)return{outcome:"retune",target:"both"};H>=O-Xe&&(P=P??"both")}return P!==void 0?{outcome:"near",target:P}:{outcome:"no"}},m=l=>l.outcome==="direct"?4:l.outcome==="retune"?l.target==="both"?2:3:l.outcome==="near"?1:0,y=l=>[...l].sort().join("|"),I=new Set(Ie(h.map(({name:l,base:d})=>[l,ae(f(d,u,0,G))]),O,["normal"]).map(l=>y(l.pair))),D=new Map(h.map(l=>[l.name,l])),W=new Map;for(const{pair:l,distance:d}of S){const g=D.get(l[0]),b=D.get(l[1]),B=i(g.name)&&i(b.name),M=c(g,b,u,a.min,a.max);if(M.outcome==="direct"||M.outcome==="retune"){const w=M.target??(B?"one of them":`"${i(g.name)?g.name:b.name}"`);I.has(y(l))?p.push(`Status colors "${l[0]}" and "${l[1]}" are hard to distinguish under normal vision (distance ${qe(d)} < ${O}); status meanings must stay distinguishable \u2014 retune ${w} via intents.`):p.push(`Status colors "${l[0]}" and "${l[1]}" are hard to distinguish as rendered (distance ${qe(d)} < ${O}); the actionBackground chroma band ({ min: ${a.min}, max: ${a.max} }) pushes them together \u2014 widen the band, or retune ${w} via intents.`);continue}const E=c(g,b,u,0,G);let T={outcome:"no"};for(let w=1;w<=19&&T.outcome!=="direct";w+=1){const _=w*.05;if(Math.abs(_-u)<.001)continue;const F=c(g,b,_,a.min,a.max);m(F)>m(T)&&(T=F)}let L={outcome:"no"};const R=E.outcome==="direct"||E.outcome==="retune",P=T.outcome==="direct"||T.outcome==="retune";if(!R&&!P)for(let w=1;w<=19&&L.outcome!=="direct";w+=1){const _=c(g,b,w*.05,0,G);m(_)>m(L)&&(L=_)}const H=Lt(E,T,L),v=`${M.outcome}|${H}`;let k=W.get(v);k||(k=[],W.set(v,k)),k.push(l)}for(const[l,d]of W){const g=l.indexOf("|"),b=l.slice(0,g),B=l.slice(g+1),M=d.map(([L,R])=>`"${L}"/"${R}"`),E=M.length>1?`${M.slice(0,-1).join(", ")} and ${M[M.length-1]}`:M[0],T=b==="near"?`Status colors ${E} may not separate by retuning as rendered: at the action stop's lightness (${u}) with the actionBackground chroma band ({ min: ${a.min}, max: ${a.max} }), the closest reachable retune found comes within the audit's search margin of the ${O} threshold`:`Status colors ${E} cannot be separated as rendered: at the action stop's lightness (${u}) with the actionBackground chroma band ({ min: ${a.min}, max: ${a.max} }), no intent retuning can pull ${d.length>1?"these pairs":"the pair"} ${O} apart`;p.push(T+B)}return p}function Lt(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 Ut(e,n){const t=Ae(e),o=Ae(n),a=t.error!==void 0?{valid:!1,errors:[t.error],warnings:[]}:ve(t.value),u=o.error!==void 0?{valid:!1,errors:[o.error],warnings:[]}:ve(o.value,Ke),f=[...a.errors.map(p=>`light: ${p}`),...u.errors.map(p=>`dark: ${p}`)],h=[...a.warnings.map(p=>`light: ${p}`),...u.warnings.map(p=>`dark: ${p}`)];if(a.valid&&u.valid){const p=new Set(Object.keys(t.value?.contexts??{})),S=new Set(Object.keys(o.value?.contexts??{})),$=[...S].filter(C=>!p.has(C)).sort(),x=[...p].filter(C=>!S.has(C)).sort();($.length>0||x.length>0)&&f.push(`contexts must declare the same names in both schemes. Missing from light: ${$.join(", ")||"(none)"}. Missing from dark: ${x.join(", ")||"(none)"}.`)}return{valid:f.length===0,errors:f,warnings:h}}const Ht=["anchors","angles","contexts","dataPalette","dataRamps","intents","roles","chroma","lightness","semanticHues","semanticMappings","variantChroma"];function Pt(e,n){const t={};for(const[o,a]of Object.entries(e))A(o)&&(t[o]=a);for(const[o,a]of Object.entries(n))a!==void 0&&A(o)&&(t[o]=a);for(const o of Ht){const a=e[o],u=n[o];if(a&&typeof a=="object"&&!Array.isArray(a)&&u&&typeof u=="object"&&!Array.isArray(u)){if(o==="anchors"){t[o]=je(a,u);continue}if(o==="contexts"){t[o]=Ct(a,u);continue}if(o==="dataRamps"){t[o]=Ve(a,u);continue}const f={};for(const[h,p]of Object.entries(a))A(h)&&(f[h]=p);for(const[h,p]of Object.entries(u))p!==void 0&&A(h)&&(f[h]=p);t[o]=f}}return t}function zt(...e){let n={};for(const t of e){if(!t)continue;const o=At(t);o&&(n=Pt(n,o))}return ke(n)}function Qe(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r")}const et={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 jt(e){return ke({...et,pageBackgroundImage:`url("${Qe(e)}")`,pageBackgroundImageOpacity:.5})}function Gt(e){return ke({...et,pageBackgroundImage:`url("${Qe(e)}")`,pageBackgroundImageOpacity:.55})}export{z as ANCHOR_SLUG_PATTERN,ye as COLOR_SOURCES,xt as DEFAULT_DARK_LIGHTNESS,Ke as DEFAULT_DARK_THEME,St as DEFAULT_LIGHT_LIGHTNESS,Se as DEFAULT_LIGHT_THEME,be as DEFAULT_SEMANTIC_MAPPINGS,j as LIGHTNESS_KEYS,Ht as NESTED_THEME_KEYS,Z as ROLE_NAMES,ht as ROLE_PAIRED_INK,Pe as ROLE_TOKEN_PLAN,ge as SEMANTIC_COLOR_NAMES,Q as STATUS_COLOR_SOURCES,Fe as TOKEN_PAIRINGS,$t as VARIANT_COLOR_SOURCES,Gt as buildTaprootDarkTheme,jt as buildTaprootLightTheme,Ne as compileRoles,ke as encodeTheme,zt as layerThemes,Pt as mergePartials,se as mergeTheme,de as parseAnchorSource,At as parseTheme,He as resolveAnchorColor,ft as resolveDataColorSource,Wt as semanticToCSS,Kt as validateTheme,Ut as validateThemePair};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { EspalierElementBase } from "../shared/esp-element-base.js";
|
|
2
|
+
declare const STACK_GAPS: readonly ["none", "tiny", "small", "normal", "medium", "big", "large", "huge"];
|
|
3
|
+
/** A named gap step accepted by `esp-stack` and `esp-row`. */
|
|
4
|
+
export type EspalierGap = (typeof STACK_GAPS)[number];
|
|
5
|
+
declare const STACK_ALIGNS: readonly ["start", "center", "end", "stretch"];
|
|
6
|
+
/** A cross-axis alignment accepted by `esp-stack` and `esp-row`. */
|
|
7
|
+
export type EspalierAlign = (typeof STACK_ALIGNS)[number];
|
|
8
|
+
export { STACK_GAPS, STACK_ALIGNS };
|
|
9
|
+
/**
|
|
10
|
+
* A vertical flow: children stack in a column with a themed gap —
|
|
11
|
+
* "column, gap X" without writing flexbox (ADR-010's micro half).
|
|
12
|
+
*
|
|
13
|
+
* ```html
|
|
14
|
+
* <esp-stack gap="medium">
|
|
15
|
+
* <h2>Title</h2>
|
|
16
|
+
* <p>Copy under it.</p>
|
|
17
|
+
* <esp-button label="Act"></esp-button>
|
|
18
|
+
* </esp-stack>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* The default cross-axis alignment is `stretch`, matching normal block
|
|
22
|
+
* flow: grids, form fields, and text fill the column — with one
|
|
23
|
+
* deliberate exception: slotted `esp-button` and `esp-button-group`
|
|
24
|
+
* keep their natural width, because a field should fill its column
|
|
25
|
+
* while the submit button under it should not. That is the pairing a
|
|
26
|
+
* plain flex column cannot express with any single `align-items`
|
|
27
|
+
* value. An explicit `align` — `align="stretch"` included, authored as
|
|
28
|
+
* an attribute or assigned to the property — governs every child
|
|
29
|
+
* uniformly; removing the attribute restores the default state, and
|
|
30
|
+
* `align-self` on any child overrides either way.
|
|
31
|
+
*
|
|
32
|
+
* @customElement esp-stack
|
|
33
|
+
* @slot - The stacked children.
|
|
34
|
+
* @csspart stack - The flex column.
|
|
35
|
+
* @cssprop --esp-stack-gap - Overrides the gap between children. Defaults to the `gap` attribute's step, `normal` when unset.
|
|
36
|
+
* @docPageTitle Stack
|
|
37
|
+
* @docUrl /components/stack
|
|
38
|
+
* @menuGroup Structure
|
|
39
|
+
* @menuIcon layout
|
|
40
|
+
*/
|
|
41
|
+
export declare class EspalierStack extends EspalierElementBase {
|
|
42
|
+
/**
|
|
43
|
+
* Gap between children as a space-scale step name
|
|
44
|
+
* (`none`, `tiny`, `small`, `normal`, `medium`, `big`, `large`,
|
|
45
|
+
* `huge`).
|
|
46
|
+
* @default "normal"
|
|
47
|
+
*/
|
|
48
|
+
gap: EspalierGap;
|
|
49
|
+
/**
|
|
50
|
+
* Cross-axis alignment of children: `start`, `center`, `end`, or
|
|
51
|
+
* `stretch`.
|
|
52
|
+
* @default "stretch"
|
|
53
|
+
*/
|
|
54
|
+
align: EspalierAlign;
|
|
55
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
56
|
+
static styles: import("lit").CSSResult[];
|
|
57
|
+
}
|
|
58
|
+
declare global {
|
|
59
|
+
interface HTMLElementTagNameMap {
|
|
60
|
+
"esp-stack": EspalierStack;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var o=function(l,t,a,r){var n=arguments.length,e=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,a):r,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")e=Reflect.decorate(l,t,a,r);else for(var p=l.length-1;p>=0;p--)(i=l[p])&&(e=(n<3?i(e):n>3?i(t,a,e):i(t,a))||e);return n>3&&e&&Object.defineProperty(t,a,e),e};import{css as u,html as h}from"lit";import{customElement as f,property as c}from"lit/decorators.js";import{EspalierElementBase as g}from"../shared/esp-element-base.js";const m=["none","tiny","small","normal","medium","big","large","huge"],d=["start","center","end","stretch"];let s=class extends g{constructor(){super(...arguments),this.gap="normal",this.align="stretch"}render(){return h`
|
|
2
|
+
<div class="esp-stack" part="stack">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</div>
|
|
5
|
+
`}};s.styles=[...g.styles,u`
|
|
6
|
+
:host {
|
|
7
|
+
display: block;
|
|
8
|
+
--_esp-stack-gap: var(--esp-size-normal);
|
|
9
|
+
--_esp-stack-align: stretch;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
:host([gap="none"]) {
|
|
13
|
+
--_esp-stack-gap: 0px;
|
|
14
|
+
}
|
|
15
|
+
:host([gap="tiny"]) {
|
|
16
|
+
--_esp-stack-gap: var(--esp-size-tiny);
|
|
17
|
+
}
|
|
18
|
+
:host([gap="small"]) {
|
|
19
|
+
--_esp-stack-gap: var(--esp-size-small);
|
|
20
|
+
}
|
|
21
|
+
:host([gap="medium"]) {
|
|
22
|
+
--_esp-stack-gap: var(--esp-size-medium);
|
|
23
|
+
}
|
|
24
|
+
:host([gap="big"]) {
|
|
25
|
+
--_esp-stack-gap: var(--esp-size-big);
|
|
26
|
+
}
|
|
27
|
+
:host([gap="large"]) {
|
|
28
|
+
--_esp-stack-gap: var(--esp-size-large);
|
|
29
|
+
}
|
|
30
|
+
:host([gap="huge"]) {
|
|
31
|
+
--_esp-stack-gap: var(--esp-size-huge);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
:host([align="start"]) {
|
|
35
|
+
--_esp-stack-align: flex-start;
|
|
36
|
+
}
|
|
37
|
+
:host([align="center"]) {
|
|
38
|
+
--_esp-stack-align: center;
|
|
39
|
+
}
|
|
40
|
+
:host([align="end"]) {
|
|
41
|
+
--_esp-stack-align: flex-end;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.esp-stack {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-direction: column;
|
|
47
|
+
gap: var(--esp-stack-gap, var(--_esp-stack-gap));
|
|
48
|
+
align-items: var(--_esp-stack-align);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
:host(:not([align])) ::slotted(esp-button),
|
|
53
|
+
:host(:not([align])) ::slotted(esp-button-group) {
|
|
54
|
+
align-self: flex-start;
|
|
55
|
+
}
|
|
56
|
+
`],o([c({reflect:!0,useDefault:!0})],s.prototype,"gap",void 0),o([c({reflect:!0,useDefault:!0})],s.prototype,"align",void 0),s=o([f("esp-stack")],s);export{s as EspalierStack,d as STACK_ALIGNS,m as STACK_GAPS};
|