contour-ds 1.7.2 → 1.9.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/README.md +244 -326
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/agent-rules.json +16 -0
- package/dist/build-manifest.json +344 -126
- package/dist/contour-wc-content.esm.js +1939 -0
- package/dist/contour-wc-content.esm.min.js +1 -0
- package/dist/contour-wc-core.esm.js +3724 -0
- package/dist/contour-wc-core.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +6986 -0
- package/dist/contour-wc-dashboard.esm.min.js +1 -0
- package/dist/contour-wc-data.esm.js +6572 -0
- package/dist/contour-wc-data.esm.min.js +1 -0
- package/dist/contour-wc-docs.esm.js +976 -0
- package/dist/contour-wc-docs.esm.min.js +1 -0
- package/dist/contour-wc-feedback.esm.js +1742 -0
- package/dist/contour-wc-feedback.esm.min.js +1 -0
- package/dist/contour-wc-forms.esm.js +2437 -0
- package/dist/contour-wc-forms.esm.min.js +1 -0
- package/dist/contour-wc-interaction.esm.js +1343 -0
- package/dist/contour-wc-interaction.esm.min.js +1 -0
- package/dist/contour-wc-layout.esm.js +845 -0
- package/dist/contour-wc-layout.esm.min.js +1 -0
- package/dist/contour-wc-map.esm.js +2411 -0
- package/dist/contour-wc-map.esm.min.js +1 -0
- package/dist/contour-wc-misc.esm.js +945 -0
- package/dist/contour-wc-misc.esm.min.js +1 -0
- package/dist/contour-wc-navigation.esm.js +2842 -0
- package/dist/contour-wc-navigation.esm.min.js +1 -0
- package/dist/contour-wc-ui.esm.js +6519 -0
- package/dist/contour-wc-ui.esm.min.js +1 -0
- package/dist/contour-wc.esm.js +14435 -5723
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +14436 -5725
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +4534 -0
- package/dist/contour.components.json +4870 -1222
- package/dist/contour.css +6672 -4711
- package/dist/contour.d.ts +753 -1085
- package/dist/contour.esm.js +440 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +11343 -0
- package/dist/contour.js +440 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +422 -0
- package/dist/contour.single.html +17 -0
- package/dist/contour.single.min.css +1 -0
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +1318 -1053
- package/dist/contour.vue.d.ts +420 -0
- package/dist/contour.web-types.json +11703 -0
- package/dist/custom-elements.json +36120 -0
- package/dist/docs/actions.md +16 -6
- package/dist/docs/affordances.md +21 -85
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -22
- package/dist/docs/data.md +39 -58
- package/dist/docs/docs.md +12 -7
- package/dist/docs/feedback.md +30 -12
- package/dist/docs/field.md +28 -13
- package/dist/docs/forms.md +35 -19
- package/dist/docs/index.json +70 -61
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +30 -8
- package/dist/docs/motion.md +12 -6
- package/dist/docs/navigation.md +31 -7
- package/dist/docs/overlays.md +32 -25
- package/dist/docs/overview.md +3 -2
- package/dist/docs/patterns.md +20 -10
- package/dist/docs/playground.md +11 -4
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +117 -13
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +13 -14
- package/dist/docs/surfaces.md +17 -22
- package/dist/docs/theming.md +18 -32
- package/dist/docs/type.md +12 -5
- package/dist/docs/webcomponents.md +75 -33
- package/dist/hljs.css +1 -20
- package/dist/map-chrome.mapbox.css +68 -92
- package/dist/map-chrome.maplibre.css +68 -92
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/svg/icons.svg +367 -0
- package/dist/wc/behaviours.mjs +222 -192
- package/dist/wc/content.mjs +486 -142
- package/dist/wc/core.mjs +917 -395
- package/dist/wc/dashboard.mjs +252 -25
- package/dist/wc/data-chart.mjs +1333 -0
- package/dist/wc/data-export.mjs +391 -0
- package/dist/wc/data-gauge.mjs +779 -0
- package/dist/wc/data-geo.mjs +696 -0
- package/dist/wc/data-glyphs.mjs +133 -0
- package/dist/wc/data-legend.mjs +431 -0
- package/dist/wc/data-readout.mjs +227 -0
- package/dist/wc/data-series.mjs +1004 -0
- package/dist/wc/data-table.mjs +751 -0
- package/dist/wc/data.mjs +15 -3707
- package/dist/wc/docs.mjs +113 -19
- package/dist/wc/feedback.mjs +320 -116
- package/dist/wc/forms-controls.mjs +635 -0
- package/dist/wc/forms-field.mjs +547 -0
- package/dist/wc/forms-groups.mjs +347 -0
- package/dist/wc/forms-input.mjs +292 -0
- package/dist/wc/forms.mjs +10 -1122
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +16 -7
- package/dist/wc/interaction.mjs +322 -75
- package/dist/wc/layout.mjs +100 -29
- package/dist/wc/map.mjs +888 -285
- package/dist/wc/misc.mjs +137 -26
- package/dist/wc/navigation-menu.mjs +735 -0
- package/dist/wc/navigation-shell.mjs +495 -0
- package/dist/wc/navigation-tree.mjs +995 -0
- package/dist/wc/navigation.mjs +9 -1636
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +285 -113
- package/dist/wc/states.mjs +75 -78
- package/dist/wc/svg.mjs +209 -34
- package/dist/wc/ui-atoms.mjs +608 -0
- package/dist/wc/ui-data.mjs +1404 -0
- package/dist/wc/ui-feedback.mjs +419 -0
- package/dist/wc/ui-inputs.mjs +1570 -0
- package/dist/wc/ui-menus.mjs +307 -0
- package/dist/wc/ui-overlays.mjs +1605 -0
- package/integrations/README.md +25 -5
- package/integrations/ai/CLAUDE.md +6 -3
- package/integrations/ai/COPILOT.md +14 -0
- package/integrations/ai/GEMINI.md +14 -0
- package/integrations/ai/WINDSURF.md +14 -0
- package/integrations/ai/v0-prompt.md +13 -1
- package/integrations/frameworks/README.md +235 -0
- package/integrations/native/README.md +0 -3
- package/integrations/native/style-dictionary.config.json +1 -1
- package/integrations/tailwind/contour-theme.css +71 -13
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +103 -39
- package/dist/wc/ui.mjs +0 -3560
|
@@ -0,0 +1,1742 @@
|
|
|
1
|
+
import { CLASS_ONLY, CONTOUR_EVENTS, ContourBase, MERCATOR_MAX_LAT, MODS, OBSERVED, REGISTERED, applyLabel, bearing, clampLat, contourId, cssLength, define, flagOn, flagOnValue, formatValue, haversine, headingTag, iconMarkup, isRtl, labelText, levelFromAttributes, mercatorResolution, navKey, normaliseLng, onDispose, safeColor, safeHref, sanitizeHtml, setHTML, simple, statusIcon, supportsUntilFound, unwrapBounds, warnBadJson, wcEmitOverlay, withBrownout, MARKER_SHAPES, arcPath, assignMarkers, barRects, compassNeedle, contourPaths, donutSlices, isMissing, marchingSquares, markerStyles, niceTicks, polylinePoints, scaleBarTicks, smoothPath, modalContain, wcReset, wireCombobox, wireCopy, wireMenu, wirePagination, wireRemovable, wireSegmented, wireTabs, wireTree, STATE_FALLBACK, loadRemote, parseArrayAttr, remoteData, remoteInvalidate, remoteRefresh, remoteVisible, renderEmpty, renderStates, stateLabel, watchViewport, wireStates } from "./contour-wc-core.esm.js";
|
|
2
|
+
|
|
3
|
+
// ---- Registration: class-only wrappers run last (define() skips claimed names) ----
|
|
4
|
+
define("contour-box", simple(["c-box"]));
|
|
5
|
+
define("contour-cluster", simple(["c-cluster"]));
|
|
6
|
+
define("contour-container", simple(["c-container"]));
|
|
7
|
+
define("contour-row", simple(["c-row"]));
|
|
8
|
+
define("contour-scrim", simple(["c-scrim"]));
|
|
9
|
+
define("contour-stack", simple(["c-stack"]));
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// R31-19: the text a shadow <label> shows through its <slot>, read from the
|
|
15
|
+
// light-tree assigned nodes (the shadow label's own textContent is empty).
|
|
16
|
+
const assignedText = (label) => {
|
|
17
|
+
const slot = label.querySelector("slot");
|
|
18
|
+
const nodes = slot ? slot.assignedElements({ flatten: true }) : [];
|
|
19
|
+
const text = nodes.map((n) => (n.textContent || "").trim()).join(" ").trim();
|
|
20
|
+
return text || (label.textContent || "").trim();
|
|
21
|
+
};
|
|
22
|
+
// ---- Shadow DOM wrappers (opt-in) ------------------------------------
|
|
23
|
+
let ADOPTED = null;
|
|
24
|
+
let ADOPTED_KEY = "";
|
|
25
|
+
const _hashCss = (str) => {
|
|
26
|
+
let h = 2166136261;
|
|
27
|
+
for (let i = 0; i < str.length; i++) {
|
|
28
|
+
h ^= str.charCodeAt(i);
|
|
29
|
+
h = Math.imul(h, 16777619);
|
|
30
|
+
}
|
|
31
|
+
return (h >>> 0).toString(36);
|
|
32
|
+
};
|
|
33
|
+
export const adoptedSheets = () => {
|
|
34
|
+
let key = document.styleSheets.length + ":";
|
|
35
|
+
for (const sheet of document.styleSheets) {
|
|
36
|
+
let sig = "-1";
|
|
37
|
+
try {
|
|
38
|
+
const rules = sheet.cssRules;
|
|
39
|
+
let text = "";
|
|
40
|
+
for (let i = 0; i < rules.length; i++) text += rules[i].cssText + "\n";
|
|
41
|
+
sig = rules.length + ":" + _hashCss(text);
|
|
42
|
+
} catch (e) { /* cross-origin: unreadable */ }
|
|
43
|
+
key += (sheet.href || "inline") + "~" + sig + "|";
|
|
44
|
+
}
|
|
45
|
+
if (ADOPTED && key === ADOPTED_KEY) return ADOPTED;
|
|
46
|
+
ADOPTED_KEY = key;
|
|
47
|
+
ADOPTED = [];
|
|
48
|
+
// Collect every rule a sheet carries, descending into @imported sheets,
|
|
49
|
+
const collect = (sheet, out) => {
|
|
50
|
+
let rules;
|
|
51
|
+
try { rules = sheet.cssRules; } catch (e) { return; }
|
|
52
|
+
if (!rules) return;
|
|
53
|
+
for (const r of rules) {
|
|
54
|
+
if (r instanceof CSSImportRule) {
|
|
55
|
+
if (r.styleSheet) collect(r.styleSheet, out);
|
|
56
|
+
} else {
|
|
57
|
+
try { out.push(r.cssText); } catch (e) { /* unreadable */ }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
for (const sheet of document.styleSheets) {
|
|
62
|
+
try {
|
|
63
|
+
// Include same-origin linked sheets AND same-origin inline <style> sheets (!sheet.href).
|
|
64
|
+
if (!sheet.href || new URL(sheet.href).origin === location.origin) {
|
|
65
|
+
const collected = [];
|
|
66
|
+
collect(sheet, collected);
|
|
67
|
+
const built = new CSSStyleSheet();
|
|
68
|
+
if (collected.length) built.replaceSync(collected.join("\n"));
|
|
69
|
+
ADOPTED.push(built);
|
|
70
|
+
}
|
|
71
|
+
} catch (e) { /* cross-origin or unreadable */ }
|
|
72
|
+
}
|
|
73
|
+
return ADOPTED;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// One base for every wrapper: adopt the sheets, clone the subclass template,
|
|
77
|
+
const _ShadowParent = (typeof HTMLElement !== "undefined") ? HTMLElement : Object;
|
|
78
|
+
class ContourShadow extends _ShadowParent {
|
|
79
|
+
// R30-33: observe `labels` alongside the modifier attributes so a labels
|
|
80
|
+
// change re-runs _applyLabels(). applyMods() ignores it (it only maps MODS),
|
|
81
|
+
// so adding it here does not create a bogus modifier class.
|
|
82
|
+
static get observedAttributes() { return MODS.concat("labels"); }
|
|
83
|
+
constructor() {
|
|
84
|
+
super();
|
|
85
|
+
// Reuse a Declarative Shadow Root when the platform already attached one
|
|
86
|
+
// (SSR/DSD hydration); otherwise create and populate the shadow root.
|
|
87
|
+
let root = this.shadowRoot;
|
|
88
|
+
if (!root) {
|
|
89
|
+
root = this.attachShadow({ mode: "open" });
|
|
90
|
+
if (this.constructor.contourTemplate) {
|
|
91
|
+
root.appendChild(this.constructor.contourTemplate.content.cloneNode(true));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const sheets = adoptedSheets();
|
|
95
|
+
if (sheets.length) {
|
|
96
|
+
try { root.adoptedStyleSheets = sheets; } catch (e) { /* unsupported or read-only */ }
|
|
97
|
+
}
|
|
98
|
+
this._shadowBase = root.firstElementChild ? root.firstElementChild.className : "";
|
|
99
|
+
}
|
|
100
|
+
// Subclasses with behaviour beyond the template override this.
|
|
101
|
+
enhance(root) {
|
|
102
|
+
if (!root) root = this.shadowRoot;
|
|
103
|
+
if (!root) return;
|
|
104
|
+
// ARIA setup is idempotent (guards on hasAttribute), so it re-runs on
|
|
105
|
+
root.querySelectorAll("details").forEach((d) => {
|
|
106
|
+
const summary = d.querySelector("summary");
|
|
107
|
+
if (summary && !summary.hasAttribute("aria-expanded")) {
|
|
108
|
+
summary.setAttribute("aria-expanded", String(d.open));
|
|
109
|
+
d.addEventListener("toggle", () => {
|
|
110
|
+
summary.setAttribute("aria-expanded", String(d.open));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
// ARIA: ensure live regions have proper roles
|
|
115
|
+
root.querySelectorAll("[data-live]").forEach((el) => {
|
|
116
|
+
if (!el.hasAttribute("role")) el.setAttribute("role", "status");
|
|
117
|
+
if (!el.hasAttribute("aria-live")) el.setAttribute("aria-live", "polite");
|
|
118
|
+
});
|
|
119
|
+
// ARIA: spinners and toasts get live region roles (opt-in: an author-set role wins)
|
|
120
|
+
root.querySelectorAll(".c-spinner").forEach((el) => {
|
|
121
|
+
if (!el.hasAttribute("role")) el.setAttribute("role", "status");
|
|
122
|
+
if (!el.hasAttribute("aria-live")) el.setAttribute("aria-live", "polite");
|
|
123
|
+
});
|
|
124
|
+
// ARIA: toast elements get live region roles
|
|
125
|
+
root.querySelectorAll(".c-toast, .c-toast-host").forEach((el) => {
|
|
126
|
+
if (!el.hasAttribute("role")) el.setAttribute("role", "status");
|
|
127
|
+
if (!el.hasAttribute("aria-live")) el.setAttribute("aria-live", "polite");
|
|
128
|
+
if (!el.hasAttribute("aria-atomic")) el.setAttribute("aria-atomic", "true");
|
|
129
|
+
});
|
|
130
|
+
// ARIA: link tabs to panels via aria-controls
|
|
131
|
+
root.querySelectorAll("[role='tab']").forEach((tab) => {
|
|
132
|
+
const ctrl = tab.getAttribute("aria-controls");
|
|
133
|
+
if (ctrl) {
|
|
134
|
+
const panel = root.querySelector("#" + CSS.escape(ctrl)) || document.getElementById(ctrl);
|
|
135
|
+
if (panel && !panel.hasAttribute("aria-labelledby")) {
|
|
136
|
+
if (!tab.id) tab.id = contourId("tab");
|
|
137
|
+
panel.setAttribute("aria-labelledby", tab.id);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
// ARIA: link inputs to their labels/hints via aria-describedby
|
|
142
|
+
root.querySelectorAll("input, textarea, select").forEach((input) => {
|
|
143
|
+
if (input.hasAttribute("aria-describedby")) return;
|
|
144
|
+
const field = input.closest(".c-field");
|
|
145
|
+
if (field) {
|
|
146
|
+
const hint = field.querySelector(".c-field__hint");
|
|
147
|
+
if (hint) {
|
|
148
|
+
if (!hint.id) hint.id = contourId("hint");
|
|
149
|
+
input.setAttribute("aria-describedby", hint.id);
|
|
150
|
+
}
|
|
151
|
+
const err = field.querySelector(".c-field__error");
|
|
152
|
+
if (err) {
|
|
153
|
+
if (!err.id) err.id = contourId("err");
|
|
154
|
+
const existing = input.getAttribute("aria-describedby") || "";
|
|
155
|
+
input.setAttribute("aria-describedby", (existing + " " + err.id).trim());
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
// ARIA: alert elements are live regions, and the variant sets the volume.
|
|
160
|
+
root.querySelectorAll(".c-alert").forEach((el) => {
|
|
161
|
+
const urgent = el.classList.contains("c-alert--warning") || el.classList.contains("c-alert--danger");
|
|
162
|
+
const role = urgent ? "alert" : "status";
|
|
163
|
+
const live = urgent ? "assertive" : "polite";
|
|
164
|
+
if (!el.hasAttribute("role") || el.dataset.contourAutoRole) {
|
|
165
|
+
el.setAttribute("role", role);
|
|
166
|
+
el.dataset.contourAutoRole = role;
|
|
167
|
+
}
|
|
168
|
+
if (!el.hasAttribute("aria-live") || el.dataset.contourAutoLive) {
|
|
169
|
+
el.setAttribute("aria-live", live);
|
|
170
|
+
el.dataset.contourAutoLive = live;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
// ARIA: required form fields
|
|
174
|
+
root.querySelectorAll("input[required], textarea[required], select[required]").forEach((el) => {
|
|
175
|
+
if (!el.hasAttribute("aria-required")) el.setAttribute("aria-required", "true");
|
|
176
|
+
});
|
|
177
|
+
// Interaction is delegated to the implementation the light-DOM wrappers
|
|
178
|
+
this._wireLabels(root);
|
|
179
|
+
this._wireClose(root);
|
|
180
|
+
}
|
|
181
|
+
// R31-22: the shadow callout/alert/tag/filter-pill close/remove buttons were
|
|
182
|
+
// inert — a control the reader could focus and never use. Wire them to
|
|
183
|
+
// dismiss the host (hide + emit contour:close/dismiss), once per host.
|
|
184
|
+
_wireClose(root) {
|
|
185
|
+
if (!root || this._wiredShadowClose) return;
|
|
186
|
+
const btns = root.querySelectorAll(".c-callout__close, .c-alert__close, .c-tag__remove, .c-filter-pill__remove");
|
|
187
|
+
if (!btns.length) return;
|
|
188
|
+
this._wiredShadowClose = true;
|
|
189
|
+
for (const b of btns) {
|
|
190
|
+
b.addEventListener("click", () => {
|
|
191
|
+
this.hidden = true;
|
|
192
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// R31-03: a shadow <label> wrapping a <slot> does not label a slotted input.
|
|
197
|
+
// The input is in the light tree, the label in the shadow tree, and HTML's
|
|
198
|
+
// label/for association does not cross the boundary. Give the slotted
|
|
199
|
+
// control an id and point the shadow label's `for` at it, and mirror the
|
|
200
|
+
// field hint/error into aria-describedby. Idempotent.
|
|
201
|
+
_wireLabels(root) {
|
|
202
|
+
if (!root) return;
|
|
203
|
+
root.querySelectorAll("label").forEach((label) => {
|
|
204
|
+
const slot = label.querySelector("slot");
|
|
205
|
+
const field = label.closest(".c-field") || label.parentElement;
|
|
206
|
+
const host = this;
|
|
207
|
+
const controls = [];
|
|
208
|
+
if (slot) {
|
|
209
|
+
for (const n of slot.assignedElements({ flatten: true })) {
|
|
210
|
+
if (n.matches("input, textarea, select")) controls.push(n);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// A field's input lives in a named "input" slot, not inside the label.
|
|
214
|
+
if (!controls.length && field) {
|
|
215
|
+
const inputSlot = field.querySelector('slot[name="input"]');
|
|
216
|
+
if (inputSlot) {
|
|
217
|
+
for (const n of inputSlot.assignedElements({ flatten: true })) {
|
|
218
|
+
if (n.matches("input, textarea, select")) controls.push(n);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (const input of controls) {
|
|
223
|
+
if (!input.id) input.id = contourId("shadow-input");
|
|
224
|
+
if (!label.hasAttribute("for")) label.setAttribute("for", input.id);
|
|
225
|
+
// R31-19: `for` does not cross the shadow boundary — the label is in
|
|
226
|
+
// the shadow tree, the input in the light tree, so `label.control`
|
|
227
|
+
// is null and `input.labels` is empty. Give the input an explicit
|
|
228
|
+
// accessible name from the label's slotted text, and forward a label
|
|
229
|
+
// click to the control, so the visible label actually toggles it.
|
|
230
|
+
if (!input.hasAttribute("aria-label") && !input.hasAttribute("aria-labelledby")) {
|
|
231
|
+
const text = assignedText(label);
|
|
232
|
+
if (text) input.setAttribute("aria-label", text);
|
|
233
|
+
}
|
|
234
|
+
if (!input._contourLabelWired) {
|
|
235
|
+
input._contourLabelWired = true;
|
|
236
|
+
label.addEventListener("click", (e) => {
|
|
237
|
+
if (e.target.closest("a, button, input, textarea, select")) return;
|
|
238
|
+
try { input.click(); } catch (err) { /* control without click */ }
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
// Mirror the field hint/error into aria-describedby (once).
|
|
242
|
+
if (field && !input.hasAttribute("aria-describedby")) {
|
|
243
|
+
const hint = field.querySelector(".c-field__hint");
|
|
244
|
+
const err = field.querySelector(".c-field__error");
|
|
245
|
+
const ids = [];
|
|
246
|
+
if (hint) { if (!hint.id) hint.id = contourId("hint"); ids.push(hint.id); }
|
|
247
|
+
if (err) { if (!err.id) err.id = contourId("err"); ids.push(err.id); }
|
|
248
|
+
if (ids.length) input.setAttribute("aria-describedby", ids.join(" "));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
connectedCallback() {
|
|
254
|
+
this.applyMods();
|
|
255
|
+
try { this.enhance(this.shadowRoot); } catch (e) { /* ignore */ }
|
|
256
|
+
this._applyLabels();
|
|
257
|
+
// Wire behaviours now that slotted content is present.
|
|
258
|
+
try {
|
|
259
|
+
wcReset(this);
|
|
260
|
+
wireTabs(this); wireSegmented(this); wireCombobox(this); wireTree(this);
|
|
261
|
+
wireMenu(this); wirePagination(this); wireCopy(this); wireRemovable(this);
|
|
262
|
+
} catch (e) { /* ignore */ }
|
|
263
|
+
// Re-wire behaviour when slotted content changes. Reset the wired set so
|
|
264
|
+
if (this.shadowRoot && !this._wiredSlotchange) {
|
|
265
|
+
this._wiredSlotchange = true;
|
|
266
|
+
this.shadowRoot.addEventListener("slotchange", () => {
|
|
267
|
+
try { this.enhance(this.shadowRoot);
|
|
268
|
+
this._applyLabels();
|
|
269
|
+
wireTabs(this); wireSegmented(this); wireCombobox(this); wireTree(this);
|
|
270
|
+
wireMenu(this); wirePagination(this); wireCopy(this); wireRemovable(this);
|
|
271
|
+
} catch (e) { /* ignore */ }
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
attributeChangedCallback() { this.applyMods(); this._applyLabels(); }
|
|
276
|
+
// R30-33: localise the static aria-labels/copy baked into shadow templates.
|
|
277
|
+
// The light-DOM sweep (R30-13) routes literals through labelText(); the
|
|
278
|
+
// shadow layer has no such path because its markup is a static template
|
|
279
|
+
// string. This post-processes the rendered shadowRoot, replacing the
|
|
280
|
+
// English defaults with the host's `labels` overrides where present. It is
|
|
281
|
+
// idempotent and only touches nodes that still carry the default text, so
|
|
282
|
+
// an author's own shadow content (slotted) is never overwritten.
|
|
283
|
+
_applyLabels() {
|
|
284
|
+
const root = this.shadowRoot;
|
|
285
|
+
if (!root) return;
|
|
286
|
+
const set = (selector, key, fallback) => {
|
|
287
|
+
const node = root.querySelector(selector);
|
|
288
|
+
if (node) node.setAttribute("aria-label", labelText(this, key, fallback));
|
|
289
|
+
};
|
|
290
|
+
set(".c-callout__close", "close", "Close");
|
|
291
|
+
set(".c-alert__close", "close", "Close");
|
|
292
|
+
set(".c-tag__remove", "remove", "Remove");
|
|
293
|
+
set(".c-filter-pill__remove", "remove-filter", "Remove filter");
|
|
294
|
+
set(".c-breadcrumb", "breadcrumb", "Breadcrumb");
|
|
295
|
+
set(".c-spinner", "loading", "Loading");
|
|
296
|
+
set(".c-install__copy", "copy-command", "Copy command");
|
|
297
|
+
// The install/code copy buttons carry visible "Copy" text as well as an
|
|
298
|
+
// aria-label; localise both, but only while they still read "Copy" so a
|
|
299
|
+
// consumer who set their own label keeps it.
|
|
300
|
+
const copyBtn = root.querySelector(".c-install__copy, .c-code__copy");
|
|
301
|
+
if (copyBtn && copyBtn.textContent.trim() === "Copy") {
|
|
302
|
+
copyBtn.textContent = labelText(this, "copy", "Copy");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
applyMods() {
|
|
306
|
+
const el = this.shadowRoot.firstElementChild;
|
|
307
|
+
if (!el || !this._shadowBase) return;
|
|
308
|
+
const mods = [];
|
|
309
|
+
for (const attr of MODS) {
|
|
310
|
+
const val = this.getAttribute(attr);
|
|
311
|
+
if (!val) continue;
|
|
312
|
+
for (const cls of this._shadowBase.split(/\s+/)) {
|
|
313
|
+
if (cls) mods.push("c-" + cls.replace(/^c-/, "") + "--" + val);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
el.className = (this._shadowBase + " " + mods.join(" ")).trim();
|
|
317
|
+
// An alert's live region follows its variant, and rewriting the class above
|
|
318
|
+
if (el.classList.contains("c-alert")) {
|
|
319
|
+
const urgent = el.classList.contains("c-alert--warning") || el.classList.contains("c-alert--danger");
|
|
320
|
+
const role = urgent ? "alert" : "status";
|
|
321
|
+
const live = urgent ? "assertive" : "polite";
|
|
322
|
+
if (!el.hasAttribute("role") || el.dataset.contourAutoRole) {
|
|
323
|
+
el.setAttribute("role", role);
|
|
324
|
+
el.dataset.contourAutoRole = role;
|
|
325
|
+
}
|
|
326
|
+
if (!el.hasAttribute("aria-live") || el.dataset.contourAutoLive) {
|
|
327
|
+
el.setAttribute("aria-live", live);
|
|
328
|
+
el.dataset.contourAutoLive = live;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Registers a wrapper. The template markup is always recorded so Node/SSR
|
|
335
|
+
const SHADOW_PARTS_PUBLIC = {};
|
|
336
|
+
const SHADOW_MARKUP = {};
|
|
337
|
+
const recordParts = (name, markup) => {
|
|
338
|
+
SHADOW_PARTS_PUBLIC[name] = [...markup.matchAll(/part="([^"]+)"/g)]
|
|
339
|
+
.flatMap((m) => m[1].split(/\s+/))
|
|
340
|
+
.filter(Boolean);
|
|
341
|
+
};
|
|
342
|
+
const shadow = (name, markup) => {
|
|
343
|
+
SHADOW_MARKUP[name] = markup;
|
|
344
|
+
recordParts(name, markup);
|
|
345
|
+
if (typeof document === "undefined") return;
|
|
346
|
+
const tpl = document.createElement("template");
|
|
347
|
+
setHTML(tpl, markup);
|
|
348
|
+
const cls = class extends ContourShadow {};
|
|
349
|
+
cls.contourTemplate = tpl;
|
|
350
|
+
define(name, cls);
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// A wrapper that is one default slot needs no markup of its own: the element,
|
|
354
|
+
const slotWrapper = (tag, block, part) =>
|
|
355
|
+
"<" + tag + ' class="c-' + block + '" part="' + (part || block) + '"' + (tag === "button" ? ' type="button"' : "") + "><slot></slot></" + tag + ">";
|
|
356
|
+
const SHADOW_SLOTS = {
|
|
357
|
+
div: [
|
|
358
|
+
"accordion", "activity", "advanced", "affordance", "affordances", "anchor", "app", "app-body", "box", "btn-group", "chart-grid",
|
|
359
|
+
"catchment", "cluster", "command", "compare", "comparison", "compass",
|
|
360
|
+
"contour-plot", "cta", "dash-freshness", "dash-kpi-row", "dash-shell", "dash-toolbar", "datamark", "delta", "draggable", "drag-handle", "drop-indicator", "drop-zone",
|
|
361
|
+
"destructive-hint", "docs-shell", "drawer", "elevation",
|
|
362
|
+
"filter-bar", "flow-map", "heatmap", "hexbin", "icon-badge", "input-group", "instrument", "range-scale", "resizable", "table-wrap", "time-range", "toast-host", "scroll-area",
|
|
363
|
+
"isochrone", "landing-features", "landing-hero", "layer-panel", "layer-switch", "legend", "logos", "map-area",
|
|
364
|
+
"map-footer", "map-panel", "map-slot", "measure", "metrics", "minimap", "pager", "pagination",
|
|
365
|
+
"panel", "plate", "price", "pricing", "progress", "prose", "pullquote", "radio-list",
|
|
366
|
+
"range", "readout", "recipe", "reserved", "resize-handle", "row",
|
|
367
|
+
"row-action", "scale-bar", "scrim", "segmented", "sheet", "shortcut-list", "shortcut-overlay", "shortcut-panel",
|
|
368
|
+
"shortcut-row", "showcase", "sidebar", "skeleton", "sparkline", "stack", "steps", "streaming-chart",
|
|
369
|
+
"survey", "theme-scope", "time-slider", "timeline", "toast",
|
|
370
|
+
"toolbar", "tooltip", "tree", "version", "version-banner"
|
|
371
|
+
],
|
|
372
|
+
button: [
|
|
373
|
+
"btn", "pressable"
|
|
374
|
+
],
|
|
375
|
+
span: [
|
|
376
|
+
"avatar", "badge", "chip", "dot", "flag", "live-badge", "mark", "pill"
|
|
377
|
+
],
|
|
378
|
+
a: [
|
|
379
|
+
"link", "linkish"
|
|
380
|
+
],
|
|
381
|
+
kbd: [
|
|
382
|
+
"kbd"
|
|
383
|
+
],
|
|
384
|
+
label: [
|
|
385
|
+
"check", "radio", "switch"
|
|
386
|
+
],
|
|
387
|
+
nav: [
|
|
388
|
+
"docs-nav"
|
|
389
|
+
],
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// Two wrappers name their part after the region it holds rather than after
|
|
393
|
+
const SHADOW_PARTS = {
|
|
394
|
+
"version-banner": "banner",
|
|
395
|
+
"contour-plot": "plot",
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
// The slot wrappers are recorded wherever this module runs. `shadow()` already
|
|
399
|
+
for (const [tag, blocks] of Object.entries(SHADOW_SLOTS)) {
|
|
400
|
+
for (const block of blocks) {
|
|
401
|
+
const part = SHADOW_PARTS[block] || block;
|
|
402
|
+
shadow("contour-shadow-" + block, slotWrapper(tag, block, part));
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Structured templates: more than one slot, or a class that is not the block's
|
|
407
|
+
// own, so the markup is the definition and is written out.
|
|
408
|
+
shadow("contour-shadow-callout", `<div class="c-callout" part="callout"><div class="c-callout__title" part="title"><slot name="title"></slot></div><div class="c-callout__body" part="body"><slot></slot></div><button class="c-callout__close" part="close" type="button" aria-label="Close">×</button></div>`);
|
|
409
|
+
shadow("contour-shadow-empty", `<div class="c-empty" part="empty"><div class="c-empty__illustration" part="illustration"><slot name="illustration"></slot></div><div class="c-empty__title" part="title"><slot name="title"></slot></div><div class="c-empty__text" part="body"><slot></slot></div><div><slot name="action"></slot></div></div>`);
|
|
410
|
+
shadow("contour-shadow-feature", `<div class="c-feature" part="feature"><span class="c-feature__index" part="index"><slot name="index"></slot></span><div class="c-feature__title" part="title"><slot name="title"></slot></div><div class="c-feature__body" part="body"><slot></slot></div></div>`);
|
|
411
|
+
shadow("contour-shadow-kpi", `<div class="c-kpi" part="kpi"><div class="c-kpi__value" part="value"><slot name="value"></slot></div><div class="c-kpi__label" part="label"><slot name="label"></slot></div><div class="c-kpi__foot" part="foot"><slot name="delta"></slot><slot name="note"></slot></div></div>`);
|
|
412
|
+
shadow("contour-shadow-stat", `<div class="c-stat" part="stat"><div class="c-stat__value" part="value"><slot name="value"></slot></div><div class="c-stat__label" part="label"><slot name="label"></slot></div><div class="c-stat__delta" part="delta"><slot name="delta"></slot></div></div>`);
|
|
413
|
+
shadow("contour-shadow-meter", `<div class="c-meter" part="meter"><span class="c-meter__core" part="core"><span class="c-meter__value" part="value"><slot name="value"></slot></span><span class="c-meter__label" part="label"><slot name="label"></slot></span></span></div>`);
|
|
414
|
+
shadow("contour-shadow-brownout", `<div class="c-brownout" part="brownout" data-level="0"><slot></slot></div>`);
|
|
415
|
+
shadow("contour-shadow-widget-state", `<div class="c-widget-state" part="widget-state"><slot></slot></div>`);
|
|
416
|
+
shadow("contour-shadow-donut", `<div class="c-donut" part="donut"><svg class="c-donut__ring" part="ring" viewBox="0 0 32 32"></svg><div class="c-donut__center" part="center"><slot name="value"></slot></div><div class="c-donut__list" part="list"><slot></slot></div></div>`);
|
|
417
|
+
shadow("contour-shadow-axis", `<div class="c-axis" part="axis"><slot></slot></div>`);
|
|
418
|
+
shadow("contour-shadow-brush", `<div class="c-brush" part="brush"><div class="c-brush__selection" part="selection"></div></div>`);
|
|
419
|
+
shadow("contour-shadow-stacked-bar", `<div class="c-stacked-bar" part="bar"><slot></slot></div>`);
|
|
420
|
+
shadow("contour-shadow-category", `<div class="c-category" part="category" role="listbox"><slot></slot></div>`);
|
|
421
|
+
shadow("contour-shadow-gauge", `<div class="c-gauge" part="gauge"><svg class="c-gauge__dial" part="dial" aria-hidden="true" viewBox="0 0 100 100"><path class="c-gauge__track" part="track" d="M 10 90 A 40 40 0 0 1 90 90"></path><g class="c-gauge__zones"></g><line class="c-gauge__needle" part="needle" x1="50" y1="50" x2="50" y2="15"></line><circle class="c-gauge__hub" part="hub" cx="50" cy="50" r="4"></circle></svg><div class="c-gauge__value" part="value"><slot name="value"></slot></div><div class="c-gauge__band" part="band"><slot name="band"></slot></div></div>`);
|
|
422
|
+
shadow("contour-shadow-diff", `<div class="c-diff" part="diff"><div class="c-diff__line c-diff__line--del" part="before"><span class="c-diff__sign">−</span><span><slot name="before"></slot></span></div><div class="c-diff__line c-diff__line--add" part="after"><span class="c-diff__sign">+</span><span><slot name="after"></slot></span></div></div>`);
|
|
423
|
+
shadow("contour-shadow-do-dont", `<div class="c-do-dont" part="do-dont"><div class="c-do-dont__item c-do-dont__item--do" part="do"><slot name="do"></slot></div><div class="c-do-dont__item c-do-dont__item--dont" part="dont"><slot name="dont"></slot></div></div>`);
|
|
424
|
+
shadow("contour-shadow-threshold", `<div class="c-threshold" part="threshold"><span class="c-threshold__fill" part="value"></span><span class="c-threshold__target" part="target"></span></div>`);
|
|
425
|
+
shadow("contour-shadow-coordinate", `<div class="c-coordinate" part="coordinate"><span class="c-coordinate__value" part="value"><slot name="value"></slot></span></div>`);
|
|
426
|
+
shadow("contour-shadow-install", `<div class="c-install" part="install"><span class="c-install__prompt" part="prompt"><slot name="prompt"></slot></span><span class="c-install__command" part="command"><slot name="command"></slot></span><button class="c-btn c-btn--ghost c-btn--sm c-install__copy" part="copy" type="button" aria-label="Copy command">Copy</button></div>`);
|
|
427
|
+
shadow("contour-shadow-toc", `<div class="c-toc" part="toc"><div class="c-toc__title" part="title"><slot name="title"></slot></div><nav class="c-toc__list" part="list"><slot></slot></nav></div>`);
|
|
428
|
+
shadow("contour-shadow-testimonial", `<div class="c-testimonial" part="testimonial"><blockquote class="c-testimonial__quote" part="quote"><slot name="quote"></slot></blockquote><div class="c-testimonial__byline" part="byline"><span class="c-testimonial__name" part="name"><slot name="name"></slot></span><span class="c-testimonial__role" part="role"><slot name="role"></slot></span></div></div>`);
|
|
429
|
+
shadow("contour-shadow-search-trigger", `<button class="c-search-trigger" part="trigger"><span><slot name="label"></slot></span><kbd class="c-search-trigger__kbd"><slot name="shortcut"></slot></kbd></button>`);
|
|
430
|
+
shadow("contour-shadow-brand", `<a class="c-brand" part="brand"><span class="c-mark" part="mark"><slot name="mark"></slot></span><span class="c-brand__name" part="name"><slot name="name"></slot></span></a>`);
|
|
431
|
+
shadow("contour-shadow-section-head", `<div class="c-section-head" part="head"><h2 class="c-section-head__title" part="title"><slot name="title"></slot></h2><p class="c-section-head__desc" part="desc"><slot name="desc"></slot></p></div>`);
|
|
432
|
+
shadow("contour-shadow-loading", `<div class="c-loading" part="loading"><span class="c-spinner" part="spinner"></span><slot></slot></div>`);
|
|
433
|
+
// Shadow tabs are a styling shell: panels are authored by the consumer
|
|
434
|
+
shadow("contour-shadow-tabs", `<div class="c-tabs" part="tabs"><div class="c-tabs__list" part="list" role="tablist"><slot name="tabs"></slot></div><div class="c-tabs__panels" role="presentation"><slot></slot></div></div>`);
|
|
435
|
+
shadow("contour-shadow-breadcrumb", `<nav class="c-breadcrumb" part="breadcrumb" aria-label="Breadcrumb"><ol><slot></slot></ol></nav>`);
|
|
436
|
+
shadow("contour-shadow-menu", `<div class="c-menu" part="menu" role="menu"><slot></slot></div>`);
|
|
437
|
+
shadow("contour-shadow-combobox", `<div class="c-combobox" part="combobox"><input class="c-combobox__input" part="input" type="text" /><ul class="c-combobox__list" part="list" hidden><slot></slot></ul></div>`);
|
|
438
|
+
shadow("contour-shadow-chart", `<div class="c-chart" part="chart"><div class="c-chart__plot" part="plot"><slot></slot></div></div>`);
|
|
439
|
+
shadow("contour-shadow-bivariate", `<div class="c-bivariate" part="bivariate"><div class="c-bivariate__matrix" part="matrix"><slot></slot></div></div>`);
|
|
440
|
+
shadow("contour-shadow-bivariate-legend", `<div class="c-bivariate-legend" part="legend"><div class="c-bivariate-legend__matrix" part="matrix"><slot></slot></div></div>`);
|
|
441
|
+
shadow("contour-shadow-expandable", `<details class="c-expandable" part="expandable"><summary class="c-expandable__summary"><slot name="summary"></slot></summary><div class="c-expandable__body" part="body"><slot></slot></div></details>`);
|
|
442
|
+
shadow("contour-shadow-disclosure", `<details class="c-disclosure" part="disclosure"><summary><slot name="summary"></slot></summary><div class="c-disclosure__body" part="body"><slot></slot></div></details>`);
|
|
443
|
+
shadow("contour-shadow-faq", `<div class="c-faq" part="faq"><div class="c-faq__question" part="question"><slot name="question"></slot></div><div class="c-faq__answer" part="answer"><slot name="answer"></slot></div></div>`);
|
|
444
|
+
shadow("contour-shadow-code-tabs", `<div class="c-code-tabs" part="code-tabs"><div class="c-code-tabs__list" part="list" role="tablist"><slot name="tabs"></slot></div><div class="c-code-tabs__panels"><slot></slot></div></div>`);
|
|
445
|
+
shadow("contour-shadow-header", `<header class="c-header" part="header"><div class="container c-header__inner" part="inner"><a class="c-brand" part="brand"><slot name="brand"></slot></a><nav class="c-header__nav" part="nav"><slot name="nav"></slot></nav><div class="c-header__actions" part="actions"><slot name="actions"></slot></div></div></header>`);
|
|
446
|
+
shadow("contour-shadow-footer", `<footer class="c-footer" part="footer"><div class="container c-footer__grid" part="grid"><div class="c-footer__brand" part="brand"><slot name="brand"></slot></div><div class="c-footer__links" part="links"><slot name="links"></slot></div></div></footer>`);
|
|
447
|
+
shadow("contour-shadow-container", `<div class="container" part="container"><slot></slot></div>`);
|
|
448
|
+
// R31-03: contour-shadow-input / -textarea / -select / -table / -scheme-toggle
|
|
449
|
+
// were removed. Each was a control shell that could not hold the state its
|
|
450
|
+
// light twin holds (no value, no options, no rows, no toggle), so it was a
|
|
451
|
+
// trap rather than a styling seam. Use the light <contour-input>,
|
|
452
|
+
// <contour-select>, <contour-table> and <contour-scheme-toggle>, or style a
|
|
453
|
+
// native control with the `.c-input` / `.c-table` classes directly.
|
|
454
|
+
shadow("contour-shadow-spinner", `<span class="c-spinner" part="spinner" aria-label="Loading"></span>`);
|
|
455
|
+
shadow("contour-shadow-code", `<pre class="c-code" part="code"><code><slot></slot></code><button class="c-code__copy" part="copy" type="button">Copy</button></pre>`);
|
|
456
|
+
// (folded in from the hand-written component that used to carry its own copy of the sheet logic)
|
|
457
|
+
shadow("contour-shadow-card", `<div class="c-card" part="card"> <div class="c-card__title" part="head"><slot name="title">Untitled</slot></div> <div class="c-card__body" part="body"><slot></slot></div> <div class="c-card__foot" part="foot"><slot name="foot"></slot></div> </div>`);
|
|
458
|
+
// (folded in from the hand-written component that used to carry its own copy of the sheet logic)
|
|
459
|
+
// (folded in from the hand-written component that used to carry its own copy of the sheet logic)
|
|
460
|
+
shadow("contour-shadow-field", `<div class="c-field" part="field"> <label class="c-field__label" part="label"><slot name="label">Label</slot></label> <slot name="input"></slot> <span class="c-field__hint" part="hint"><slot name="hint"></slot></span> </div>`);
|
|
461
|
+
// (folded in from the hand-written component that used to carry its own copy of the sheet logic)
|
|
462
|
+
shadow("contour-shadow-alert", `<div class="c-alert" part="alert"> <div class="c-alert__title" part="title"><slot name="title"></slot></div> <div class="c-alert__body" part="body"><slot></slot></div> <div class="c-alert__actions" part="actions"><slot name="action"></slot></div> <button class="c-alert__close" part="close" type="button" aria-label="Close">×</button> </div>`);
|
|
463
|
+
shadow("contour-shadow-tag", `<span class="c-tag" part="tag"><slot></slot><button class="c-tag__remove" part="remove" type="button" aria-label="Remove">×</button></span>`);
|
|
464
|
+
shadow("contour-shadow-filter-pill", `<span class="c-filter-pill" part="filter-pill"><slot></slot><button class="c-filter-pill__remove" part="remove" type="button" aria-label="Remove filter">×</button></span>`);
|
|
465
|
+
|
|
466
|
+
// The dialog is the one wrapper with behaviour, because a close button that
|
|
467
|
+
// does not close is a control the reader cannot use.
|
|
468
|
+
const DIALOG_MARKUP = "<dialog class=\"c-dialog\" part=\"dialog\"> <div class=\"c-dialog__head\" part=\"head\"> <slot name=\"title\"></slot> <button class=\"c-btn c-btn--icon c-btn--ghost\" part=\"close\" type=\"button\" aria-label=\"Close\"> <svg aria-hidden=\"true\" viewBox=\"0 0 24 24\"><path d=\"m18 6-12 12M6 6l12 12\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.7\" stroke-linecap=\"round\"/></svg> </button> </div> <div class=\"c-dialog__body\" part=\"body\"><slot></slot></div> <div class=\"c-dialog__foot\" part=\"foot\"><slot name=\"foot\"></slot></div> </dialog>";
|
|
469
|
+
SHADOW_MARKUP["contour-shadow-dialog"] = DIALOG_MARKUP;
|
|
470
|
+
recordParts("contour-shadow-dialog", DIALOG_MARKUP);
|
|
471
|
+
class ContourShadowDialog extends ContourShadow {
|
|
472
|
+
static contourTemplate = (typeof document !== "undefined") ? (() => {
|
|
473
|
+
const tpl = document.createElement("template");
|
|
474
|
+
setHTML(tpl, DIALOG_MARKUP);
|
|
475
|
+
return tpl;
|
|
476
|
+
})() : null;
|
|
477
|
+
enhance(root) {
|
|
478
|
+
super.enhance(root);
|
|
479
|
+
// The base constructor AND connectedCallback both call enhance; the base's
|
|
480
|
+
if (this._wiredShadowDialog) return;
|
|
481
|
+
this._wiredShadowDialog = true;
|
|
482
|
+
const dlg = root.querySelector("dialog");
|
|
483
|
+
const close = root.querySelector('[part="close"]');
|
|
484
|
+
if (close) close.addEventListener("click", () => dlg?.close());
|
|
485
|
+
if (dlg) {
|
|
486
|
+
let lastFocus = null;
|
|
487
|
+
// `<dialog>` fires no `show` or `close` events in this engine (measured
|
|
488
|
+
dlg.addEventListener("beforetoggle", (e) => {
|
|
489
|
+
if (e.newState === "open") {
|
|
490
|
+
lastFocus = document.activeElement;
|
|
491
|
+
// beforetoggle fires BEFORE dialog.open flips, so the attribute
|
|
492
|
+
// write must not re-enter attributeChangedCallback's show() path.
|
|
493
|
+
this._syncingOpenAttr = true;
|
|
494
|
+
if (!this.hasAttribute("open")) this.setAttribute("open", "");
|
|
495
|
+
this._syncingOpenAttr = false;
|
|
496
|
+
this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true }));
|
|
497
|
+
// Focus the close button or first focusable element
|
|
498
|
+
const focusable = dlg.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
499
|
+
if (focusable) try { focusable.focus(); } catch (e) {}
|
|
500
|
+
} else if (e.newState === "closed") {
|
|
501
|
+
this._syncingOpenAttr = true;
|
|
502
|
+
if (this.hasAttribute("open")) this.removeAttribute("open");
|
|
503
|
+
this._syncingOpenAttr = false;
|
|
504
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
505
|
+
// Restore focus
|
|
506
|
+
if (lastFocus && typeof lastFocus.focus === "function") {
|
|
507
|
+
try { lastFocus.focus(); } catch (e) {}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
// Focus trap: keep Tab within the dialog. R31-04: the focusables are not
|
|
512
|
+
// only in the shadow tree — slotted light-DOM controls (the dialog body
|
|
513
|
+
// is a <slot>) are real tab stops too, and `document.activeElement` is
|
|
514
|
+
// the shadow host, not the control. Collect both, and read the
|
|
515
|
+
// shadow-aware active element.
|
|
516
|
+
const collectFocusable = () => {
|
|
517
|
+
const sel = "button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])";
|
|
518
|
+
const out = Array.from(dlg.querySelectorAll(sel));
|
|
519
|
+
for (const slot of dlg.querySelectorAll("slot")) {
|
|
520
|
+
for (const n of slot.assignedElements({ flatten: true })) {
|
|
521
|
+
if (n.matches(sel)) out.push(n);
|
|
522
|
+
for (const sub of n.querySelectorAll(sel)) out.push(sub);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return out;
|
|
526
|
+
};
|
|
527
|
+
const activeEl = () => (this.shadowRoot && this.shadowRoot.activeElement) || document.activeElement;
|
|
528
|
+
dlg.addEventListener("keydown", (e) => {
|
|
529
|
+
if (e.key !== "Tab") return;
|
|
530
|
+
const focusables = collectFocusable();
|
|
531
|
+
if (!focusables.length) return;
|
|
532
|
+
const first = focusables[0];
|
|
533
|
+
const last = focusables[focusables.length - 1];
|
|
534
|
+
if (e.shiftKey && activeEl() === first) {
|
|
535
|
+
e.preventDefault();
|
|
536
|
+
last.focus();
|
|
537
|
+
} else if (!e.shiftKey && activeEl() === last) {
|
|
538
|
+
e.preventDefault();
|
|
539
|
+
first.focus();
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
static get observedAttributes() { return [...super.observedAttributes, "open"]; }
|
|
545
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
546
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
547
|
+
// The host's `open` attribute drives the inner native dialog, matching
|
|
548
|
+
// the light family; without this the attribute was inert (R25-12).
|
|
549
|
+
if (name === "open" && this.shadowRoot && !this._syncingOpenAttr) {
|
|
550
|
+
const dlg = this.shadowRoot.querySelector("dialog");
|
|
551
|
+
if (dlg) {
|
|
552
|
+
if (newValue !== null && !dlg.open) this.show();
|
|
553
|
+
else if (newValue === null && dlg.open) this.close();
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
connectedCallback() {
|
|
558
|
+
super.connectedCallback();
|
|
559
|
+
// R31-33: an `open` attribute set before the element was connected (or a
|
|
560
|
+
// show() called while disconnected) must engage the dialog once it lands
|
|
561
|
+
// in the document; showModal() on a disconnected dialog throws.
|
|
562
|
+
if (this.hasAttribute("open")) this.show();
|
|
563
|
+
}
|
|
564
|
+
show() {
|
|
565
|
+
// R31-33: showModal() throws on a disconnected element. If not yet
|
|
566
|
+
// connected, leave the `open` attribute set; connectedCallback applies it.
|
|
567
|
+
if (!this.isConnected) { if (!this.hasAttribute("open")) this.setAttribute("open", ""); return; }
|
|
568
|
+
const d = this.shadowRoot?.querySelector("dialog");
|
|
569
|
+
if (d && !d.open) d.showModal();
|
|
570
|
+
}
|
|
571
|
+
close() { const d = this.shadowRoot?.querySelector("dialog"); if (d && d.open) d.close(); }
|
|
572
|
+
// Native-dialog parity with the light family (R20 T-32): showModal() is
|
|
573
|
+
showModal() { this.show(); }
|
|
574
|
+
get open() { return !!this.shadowRoot?.querySelector("dialog")?.open; }
|
|
575
|
+
set open(v) { if (v) this.show(); else this.close(); }
|
|
576
|
+
get returnValue() { return this.shadowRoot?.querySelector("dialog")?.returnValue ?? ""; }
|
|
577
|
+
set returnValue(v) { const d = this.shadowRoot?.querySelector("dialog"); if (d) d.returnValue = String(v); }
|
|
578
|
+
}
|
|
579
|
+
define("contour-shadow-dialog", ContourShadowDialog);
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Render a Declarative Shadow DOM string for a registered contour-shadow-* element.
|
|
583
|
+
* Intended for SSR/string emission; returns null for unknown tags.
|
|
584
|
+
*/
|
|
585
|
+
const renderShadowDSD = (tag, attrs = "", light = "") => {
|
|
586
|
+
const markup = SHADOW_MARKUP[tag];
|
|
587
|
+
if (typeof markup !== "string") return null;
|
|
588
|
+
const attrStr = attrs ? (attrs.startsWith(" ") ? attrs : " " + attrs) : "";
|
|
589
|
+
return `<${tag}${attrStr}><template shadowrootmode="open">${markup}</template>${light}</${tag}>`;
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// Published once, at the end, so the array holds what the browser was actually
|
|
593
|
+
const FROZEN_SHADOW_MARKUP = Object.freeze({ ...SHADOW_MARKUP });
|
|
594
|
+
if (typeof globalThis !== "undefined") {
|
|
595
|
+
globalThis.ContourShadowTemplates = FROZEN_SHADOW_MARKUP;
|
|
596
|
+
}
|
|
597
|
+
// Only the SHADOW vocabulary publishes here (R25-06). ContourElements and
|
|
598
|
+
if (typeof window !== "undefined") {
|
|
599
|
+
window.ContourShadowParts = Object.freeze(Object.fromEntries(
|
|
600
|
+
Object.entries(SHADOW_PARTS_PUBLIC).map(([name, parts]) => [name, Object.freeze([...new Set(parts)])]),
|
|
601
|
+
));
|
|
602
|
+
if (!window.Contour) window.Contour = {};
|
|
603
|
+
try { window.Contour.shadowTemplates = FROZEN_SHADOW_MARKUP; } catch {}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export { SHADOW_MARKUP, renderShadowDSD };
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
// R31-12: an authored `open` at load displays the modal (CSS [open]) but never
|
|
612
|
+
// ran show(), so it was not actually modal — no aria-modal, no inert siblings,
|
|
613
|
+
// no focus inside. Engage the modal for an initial open without re-entering
|
|
614
|
+
// show() (which returns early while `open` is already set). Idempotent per host.
|
|
615
|
+
function engageInitialModal(host) {
|
|
616
|
+
if (!host.hasAttribute("open") || host._modalEngaged) return;
|
|
617
|
+
host._modalEngaged = true;
|
|
618
|
+
host.setAttribute("aria-modal", "true");
|
|
619
|
+
modalContain(host, true);
|
|
620
|
+
const focusable = host.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
621
|
+
if (focusable) { try { focusable.focus(); } catch (e) {} }
|
|
622
|
+
}
|
|
623
|
+
/** R31-34: a later `open` attribute write is the same contract as the property. */
|
|
624
|
+
function syncDeclarativeOpen(host, name, newValue, wired) {
|
|
625
|
+
if (name !== "open" || !wired || host._declarativeOpen) return;
|
|
626
|
+
host._declarativeOpen = true;
|
|
627
|
+
try {
|
|
628
|
+
if (newValue !== null && !host.hasAttribute("aria-modal")) {
|
|
629
|
+
host.removeAttribute("open");
|
|
630
|
+
host.show();
|
|
631
|
+
} else if (newValue === null && host.hasAttribute("aria-modal")) {
|
|
632
|
+
host.close();
|
|
633
|
+
}
|
|
634
|
+
} finally {
|
|
635
|
+
host._declarativeOpen = false;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
class ContourDialog extends ContourBase {
|
|
639
|
+
static get observed() { return ["title", "size", "heading", "open"]; }
|
|
640
|
+
static get properties() { return { title: { attribute: "title" }, size: { attribute: "size" } }; }
|
|
641
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
642
|
+
if (name === "open") { syncDeclarativeOpen(this, name, newValue, this._wiredDialog); return; }
|
|
643
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
644
|
+
}
|
|
645
|
+
// Native-dialog parity (R20 T-32): showModal() aliases show(); open routes through show()/close(); returnValue persists.
|
|
646
|
+
showModal() { this.show(); }
|
|
647
|
+
get open() { return this.hasAttribute("open"); }
|
|
648
|
+
set open(v) { if (v) this.show(); else this.close(); }
|
|
649
|
+
render() {
|
|
650
|
+
this.classList.add("c-dialog");
|
|
651
|
+
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-dialog--")) this.classList.remove(c); });
|
|
652
|
+
const size = this.getAttribute("size");
|
|
653
|
+
if (size) this.classList.add("c-dialog--" + size);
|
|
654
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
|
|
655
|
+
const title = this.getAttribute("title");
|
|
656
|
+
let head = this.querySelector(".c-dialog__head");
|
|
657
|
+
if (title) {
|
|
658
|
+
if (!head) {
|
|
659
|
+
head = document.createElement("div");
|
|
660
|
+
head.className = "c-dialog__head";
|
|
661
|
+
const h = document.createElement(headingTag(this, "h2"));
|
|
662
|
+
h.className = "c-dialog__title";
|
|
663
|
+
head.appendChild(h);
|
|
664
|
+
const closeBtn = document.createElement("button");
|
|
665
|
+
closeBtn.className = "c-btn c-btn--icon c-btn--ghost c-dialog__close";
|
|
666
|
+
closeBtn.setAttribute("type", "button");
|
|
667
|
+
closeBtn.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
668
|
+
setHTML(closeBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-x" /></svg>');
|
|
669
|
+
head.appendChild(closeBtn);
|
|
670
|
+
}
|
|
671
|
+
const h = head.querySelector(".c-dialog__title");
|
|
672
|
+
if (h) { h.textContent = title; if (!h.id) h.id = contourId("contour-dialog-title"); this.setAttribute("aria-labelledby", h.id); }
|
|
673
|
+
}
|
|
674
|
+
if (head && head.parentNode !== this) this.prepend(head);
|
|
675
|
+
// Wrap authored content in a body so it picks up the dialog's padding.
|
|
676
|
+
const body = this.ensure(".c-dialog__body", () => { const el = document.createElement("div"); el.className = "c-dialog__body"; return el; });
|
|
677
|
+
Array.from(this.childNodes).forEach((n) => {
|
|
678
|
+
if (n === body || n === head) return;
|
|
679
|
+
if (n.nodeType === 1 && n.classList && n.classList.contains("c-dialog__head")) return;
|
|
680
|
+
body.appendChild(n);
|
|
681
|
+
});
|
|
682
|
+
if (head && head.parentNode === this) {
|
|
683
|
+
if (body.parentNode !== this) this.insertBefore(body, head.nextSibling);
|
|
684
|
+
else if (head.compareDocumentPosition(body) & Node.DOCUMENT_POSITION_PRECEDING) this.insertBefore(body, head.nextSibling);
|
|
685
|
+
} else {
|
|
686
|
+
if (body.parentNode !== this) this.appendChild(body);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
enhance() {
|
|
690
|
+
if (this._wiredDialog) return;
|
|
691
|
+
this._wiredDialog = true;
|
|
692
|
+
this.returnValue = "";
|
|
693
|
+
onDispose(this, () => { if (this.hasAttribute("open")) modalContain(this, false); });
|
|
694
|
+
// open attribute is written, never observed — no render re-entry.
|
|
695
|
+
this.show = () => {
|
|
696
|
+
if (this.hasAttribute("open")) return;
|
|
697
|
+
this._dialogLastFocus = document.activeElement;
|
|
698
|
+
// Guard our own `open` write: syncDeclarativeOpen would otherwise see the
|
|
699
|
+
// attribute change (aria-modal is not set yet) and re-enter show(), firing
|
|
700
|
+
// contour:open twice and leaking a second modalContain depth.
|
|
701
|
+
this._declarativeOpen = true;
|
|
702
|
+
try { this.setAttribute("open", ""); } finally { this._declarativeOpen = false; }
|
|
703
|
+
this.setAttribute("aria-modal", "true");
|
|
704
|
+
const dlg = this.querySelector("dialog") || (this.tagName === "DIALOG" ? this : null);
|
|
705
|
+
if (dlg && typeof dlg.showModal === "function") { try { dlg.showModal(); } catch (e) {} }
|
|
706
|
+
modalContain(this, true);
|
|
707
|
+
// Focus the close button or the first focusable, like the shadow twin.
|
|
708
|
+
const focusable = this.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
709
|
+
if (focusable) { try { focusable.focus(); } catch (e) {} }
|
|
710
|
+
this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true }));
|
|
711
|
+
};
|
|
712
|
+
this.close = () => {
|
|
713
|
+
// `open` may already be gone when close() is reached through
|
|
714
|
+
// syncDeclarativeOpen (the host removed the attribute first); an engaged
|
|
715
|
+
// modal (aria-modal still set) must still release its inert siblings, or
|
|
716
|
+
// a lower stacked dialog stays inert.
|
|
717
|
+
const wasOpen = this.hasAttribute("open") || this.hasAttribute("aria-modal");
|
|
718
|
+
const dlg = this.querySelector("dialog") || (this.tagName === "DIALOG" ? this : null);
|
|
719
|
+
if (dlg && typeof dlg.close === "function") dlg.close();
|
|
720
|
+
// Guard our own `open` removal so syncDeclarativeOpen does not re-enter
|
|
721
|
+
// close() (which would double the close event and the modalContain release).
|
|
722
|
+
this._declarativeOpen = true;
|
|
723
|
+
try { if (this.hasAttribute("open")) this.removeAttribute("open"); } finally { this._declarativeOpen = false; }
|
|
724
|
+
this.removeAttribute("aria-modal");
|
|
725
|
+
if (wasOpen) {
|
|
726
|
+
modalContain(this, false);
|
|
727
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
728
|
+
const last = this._dialogLastFocus;
|
|
729
|
+
if (last && typeof last.focus === "function") {
|
|
730
|
+
try { last.focus(); } catch (e) {}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
this.focus = () => {
|
|
735
|
+
const focusable = this.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
736
|
+
if (focusable) { try { focusable.focus(); } catch (e) {} }
|
|
737
|
+
else { try { HTMLElement.prototype.focus.call(this); } catch (e) {} }
|
|
738
|
+
};
|
|
739
|
+
this.addEventListener("click", (e) => {
|
|
740
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-dialog__close") : null;
|
|
741
|
+
if (btn && this.contains(btn)) { this.close(); return; }
|
|
742
|
+
// Backdrop click: clicking the host surface (not its content) closes.
|
|
743
|
+
if (e.target === this) this.close();
|
|
744
|
+
});
|
|
745
|
+
// Escape closes only while open; unconditional event is a claim it can't back.
|
|
746
|
+
this.addEventListener("keydown", (e) => {
|
|
747
|
+
if (e.key === "Escape" && this.hasAttribute("open")) this.close();
|
|
748
|
+
});
|
|
749
|
+
engageInitialModal(this);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
define("contour-dialog", ContourDialog);
|
|
753
|
+
class ContourAlert extends ContourBase {
|
|
754
|
+
static get observed() { return ["title", "body", "variant", "icon", "closable", "action", "actions", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
755
|
+
static get properties() {
|
|
756
|
+
return { title: { attribute: "title" }, body: { attribute: "body" }, variant: { attribute: "variant" }, icon: { attribute: "icon" }, closable: { attribute: "closable", type: Boolean }, action: { attribute: "action" }, actions: { attribute: "actions" } };
|
|
757
|
+
}
|
|
758
|
+
render() {
|
|
759
|
+
this.classList.add("c-alert");
|
|
760
|
+
// Urgent variants (warning/danger) = alert/assertive; others = status/polite (don't talk over reader).
|
|
761
|
+
const urgent = /^(warning|danger)$/.test(this.getAttribute("variant") || "");
|
|
762
|
+
const role = urgent ? "alert" : "status";
|
|
763
|
+
const live = urgent ? "assertive" : "polite";
|
|
764
|
+
// Host-written role/aria-live so loader state announces inside region; authored wins.
|
|
765
|
+
if (!this.hasAttribute("role") || this.getAttribute("role") === this._autoRole) {
|
|
766
|
+
this.setAttribute("role", role);
|
|
767
|
+
this._autoRole = role;
|
|
768
|
+
}
|
|
769
|
+
if (!this.hasAttribute("aria-live") || this.getAttribute("aria-live") === this._autoLive) {
|
|
770
|
+
this.setAttribute("aria-live", live);
|
|
771
|
+
this._autoLive = live;
|
|
772
|
+
}
|
|
773
|
+
wireStates(this);
|
|
774
|
+
loadRemote(this, "title");
|
|
775
|
+
if (renderStates(this, "alert")) return;
|
|
776
|
+
const variant = this.getAttribute("variant");
|
|
777
|
+
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-alert--")) this.classList.remove(c); });
|
|
778
|
+
if (variant) this.classList.add("c-alert--" + variant);
|
|
779
|
+
const iconAttr = this.getAttribute("icon");
|
|
780
|
+
const icon = iconAttr === "none" ? "" : (iconAttr || statusIcon(variant));
|
|
781
|
+
if (icon) {
|
|
782
|
+
const ic = this.ensure(".c-alert__icon", () => { const el = document.createElement("span"); el.className = "c-alert__icon"; return el; });
|
|
783
|
+
if (ic.parentNode === this && this.firstChild !== ic) this.prepend(ic);
|
|
784
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
785
|
+
} else {
|
|
786
|
+
const ic = this.querySelector(".c-alert__icon");
|
|
787
|
+
if (ic) ic.remove();
|
|
788
|
+
}
|
|
789
|
+
const title = this.getAttribute("title") || (this._remoteData && this._remoteData.title);
|
|
790
|
+
if (title) {
|
|
791
|
+
const t = this.ensure(".c-alert__title", () => { const el = document.createElement("div"); el.className = "c-alert__title"; return el; });
|
|
792
|
+
if (t.parentNode === this && this.firstChild !== t) this.prepend(t);
|
|
793
|
+
t.textContent = title;
|
|
794
|
+
} else {
|
|
795
|
+
const t = this.querySelector(".c-alert__title");
|
|
796
|
+
if (t) t.remove();
|
|
797
|
+
}
|
|
798
|
+
// Authored children move into .c-alert__body (default slot); `body` attribute fills when no children.
|
|
799
|
+
const body = this.getAttribute("body");
|
|
800
|
+
const authored = Array.from(this.childNodes).filter((n) => {
|
|
801
|
+
if (n.nodeType === 1 && n.classList && (n.classList.contains("c-alert__icon") || n.classList.contains("c-alert__title") || n.classList.contains("c-alert__body"))) return false;
|
|
802
|
+
if (n.nodeType === 3 && !n.textContent.trim()) return false;
|
|
803
|
+
return true;
|
|
804
|
+
});
|
|
805
|
+
if (authored.length) {
|
|
806
|
+
const b = this.ensure(".c-alert__body", () => { const el = document.createElement("div"); el.className = "c-alert__body"; return el; });
|
|
807
|
+
b.textContent = "";
|
|
808
|
+
for (const n of authored) b.appendChild(n);
|
|
809
|
+
} else if (body) {
|
|
810
|
+
const b = this.ensure(".c-alert__body", () => { const el = document.createElement("div"); el.className = "c-alert__body"; return el; });
|
|
811
|
+
b.textContent = body;
|
|
812
|
+
} else {
|
|
813
|
+
const b = this.querySelector(".c-alert__body");
|
|
814
|
+
if (b) b.remove();
|
|
815
|
+
}
|
|
816
|
+
// Remove stale action buttons on re-render.
|
|
817
|
+
Array.from(this.querySelectorAll(".c-alert__action")).forEach((n) => n.remove());
|
|
818
|
+
const actionsAttr = this.getAttribute("actions");
|
|
819
|
+
let actionList = [];
|
|
820
|
+
if (actionsAttr) {
|
|
821
|
+
try { const parsed = JSON.parse(actionsAttr); if (Array.isArray(parsed)) actionList = parsed.map((x) => String(x)); } catch (e) { actionList = [actionsAttr]; }
|
|
822
|
+
} else {
|
|
823
|
+
const single = this.getAttribute("action");
|
|
824
|
+
if (single) actionList = [single];
|
|
825
|
+
}
|
|
826
|
+
actionList.forEach((label) => {
|
|
827
|
+
const a = document.createElement("button");
|
|
828
|
+
a.className = "c-btn c-btn--sm c-alert__action";
|
|
829
|
+
a.type = "button";
|
|
830
|
+
a.setAttribute("data-alert-action", "");
|
|
831
|
+
a.textContent = label;
|
|
832
|
+
this.appendChild(a);
|
|
833
|
+
});
|
|
834
|
+
if (flagOn(this, "closable")) {
|
|
835
|
+
this.ensure(".c-alert__close", () => {
|
|
836
|
+
const btn = document.createElement("button");
|
|
837
|
+
btn.className = "c-alert__close";
|
|
838
|
+
btn.type = "button";
|
|
839
|
+
btn.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
840
|
+
btn.textContent = "×";
|
|
841
|
+
return btn;
|
|
842
|
+
});
|
|
843
|
+
} else {
|
|
844
|
+
const btn = this.querySelector(".c-alert__close");
|
|
845
|
+
if (btn) btn.remove();
|
|
846
|
+
}
|
|
847
|
+
if (!title && !body && !icon && !authored.length) {
|
|
848
|
+
renderEmpty(this, "alert");
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
ContourAlert.prototype.enhance = function() {
|
|
853
|
+
if (this._wiredAlert) return;
|
|
854
|
+
this._wiredAlert = true;
|
|
855
|
+
this.addEventListener("click", (e) => {
|
|
856
|
+
const actionBtn = e.target && e.target.closest ? e.target.closest(".c-alert__action") : null;
|
|
857
|
+
if (actionBtn && this.contains(actionBtn)) {
|
|
858
|
+
e.preventDefault();
|
|
859
|
+
this.dispatchEvent(new CustomEvent("contour:action", { bubbles: true, composed: true, detail: { label: actionBtn.textContent.trim() } }));
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-alert__close") : null;
|
|
863
|
+
if (!btn || !this.contains(btn)) return;
|
|
864
|
+
e.preventDefault();
|
|
865
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
866
|
+
this.remove();
|
|
867
|
+
});
|
|
868
|
+
};
|
|
869
|
+
define("contour-alert", ContourAlert);
|
|
870
|
+
class ContourDisclosure extends ContourBase {
|
|
871
|
+
static get observed() { return ["summary", "icon"]; }
|
|
872
|
+
static get properties() { return { summary: { attribute: "summary" }, icon: { attribute: "icon" } }; }
|
|
873
|
+
disconnectedCallback() { this._disclosureContent = null; super.disconnectedCallback(); }
|
|
874
|
+
connectedCallback() {
|
|
875
|
+
if (this.innerHTML.trim() && !this._disclosureContent) {
|
|
876
|
+
this._disclosureContent = this.innerHTML;
|
|
877
|
+
}
|
|
878
|
+
super.connectedCallback();
|
|
879
|
+
}
|
|
880
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
881
|
+
// Preserve authored content before base reset removes generated container.
|
|
882
|
+
const details = this.querySelector("details");
|
|
883
|
+
if (details) {
|
|
884
|
+
const body = details.querySelector(".c-disclosure__body");
|
|
885
|
+
if (body) this._disclosureContent = body.innerHTML;
|
|
886
|
+
} else if (this.innerHTML.trim()) {
|
|
887
|
+
this._disclosureContent = this.innerHTML;
|
|
888
|
+
}
|
|
889
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
890
|
+
}
|
|
891
|
+
render() {
|
|
892
|
+
this.classList.add("c-disclosure");
|
|
893
|
+
const summary = this.getAttribute("summary");
|
|
894
|
+
const icon = this.getAttribute("icon");
|
|
895
|
+
if (summary) {
|
|
896
|
+
let captured = this.innerHTML.trim() ? this.innerHTML : (this._disclosureContent || "");
|
|
897
|
+
if (captured.trim()) this._disclosureContent = captured;
|
|
898
|
+
const details = this.ensure("details", () => {
|
|
899
|
+
const d = document.createElement("details");
|
|
900
|
+
const summ = document.createElement("summary");
|
|
901
|
+
summ.className = "c-disclosure__summary";
|
|
902
|
+
if (icon) {
|
|
903
|
+
const ic = document.createElement("span");
|
|
904
|
+
ic.className = "c-disclosure__icon";
|
|
905
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
906
|
+
summ.appendChild(ic);
|
|
907
|
+
}
|
|
908
|
+
summ.appendChild(document.createTextNode(summary));
|
|
909
|
+
d.appendChild(summ);
|
|
910
|
+
const content = document.createElement("div");
|
|
911
|
+
content.className = "c-disclosure__body";
|
|
912
|
+
setHTML(content, captured);
|
|
913
|
+
d.appendChild(content);
|
|
914
|
+
return d;
|
|
915
|
+
});
|
|
916
|
+
const summ = details.querySelector("summary");
|
|
917
|
+
if (summ) {
|
|
918
|
+
const ic = summ.querySelector(".c-disclosure__icon");
|
|
919
|
+
if (icon && !ic) {
|
|
920
|
+
const newIc = document.createElement("span");
|
|
921
|
+
newIc.className = "c-disclosure__icon";
|
|
922
|
+
setHTML(newIc, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
923
|
+
summ.insertBefore(newIc, summ.firstChild);
|
|
924
|
+
} else if (!icon && ic) {
|
|
925
|
+
ic.remove();
|
|
926
|
+
}
|
|
927
|
+
const textNodes = Array.from(summ.childNodes).filter(n => n.nodeType === 3);
|
|
928
|
+
textNodes.forEach(n => n.remove());
|
|
929
|
+
summ.appendChild(document.createTextNode(summary));
|
|
930
|
+
}
|
|
931
|
+
const body = details.querySelector(".c-disclosure__body");
|
|
932
|
+
if (body) setHTML(body, captured);
|
|
933
|
+
if (details.parentNode !== this) { setHTML(this, ""); this.appendChild(details); }
|
|
934
|
+
} else {
|
|
935
|
+
const details = this.querySelector("details");
|
|
936
|
+
if (details) details.remove();
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
enhance() {
|
|
940
|
+
if (this._wiredDisclosure) return;
|
|
941
|
+
this._wiredDisclosure = true;
|
|
942
|
+
this.addEventListener("toggle", (e) => {
|
|
943
|
+
const t = e.target;
|
|
944
|
+
if (t && t.tagName === "DETAILS") {
|
|
945
|
+
this.dispatchEvent(new CustomEvent("contour:toggle", { detail: { open: t.open }, bubbles: true, composed: true }));
|
|
946
|
+
}
|
|
947
|
+
}, true);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
define("contour-disclosure", ContourDisclosure);
|
|
951
|
+
class ContourCallout extends ContourBase {
|
|
952
|
+
static get observed() { return ["variant", "title", "icon", "closable"]; }
|
|
953
|
+
static get properties() { return { variant: { attribute: "variant" }, title: { attribute: "title" }, icon: { attribute: "icon" }, closable: { attribute: "closable", type: Boolean } }; }
|
|
954
|
+
render() {
|
|
955
|
+
this.classList.add("c-callout");
|
|
956
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "note");
|
|
957
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Callout");
|
|
958
|
+
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-callout--")) this.classList.remove(c); });
|
|
959
|
+
const variant = this.getAttribute("variant");
|
|
960
|
+
if (variant) this.classList.add("c-callout--" + variant);
|
|
961
|
+
const iconAttr = this.getAttribute("icon");
|
|
962
|
+
const icon = iconAttr === "none" ? "" : (iconAttr || statusIcon(variant));
|
|
963
|
+
if (icon) {
|
|
964
|
+
const ic = this.ensure(".c-callout__icon", () => { const el = document.createElement("span"); el.className = "c-callout__icon"; return el; });
|
|
965
|
+
if (ic.parentNode === this && this.firstChild !== ic) this.prepend(ic);
|
|
966
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
967
|
+
} else {
|
|
968
|
+
const ic = this.querySelector(".c-callout__icon");
|
|
969
|
+
if (ic) ic.remove();
|
|
970
|
+
}
|
|
971
|
+
const title = this.getAttribute("title");
|
|
972
|
+
if (title) {
|
|
973
|
+
const t = this.ensure(".c-callout__title", () => { const el = document.createElement("div"); el.className = "c-callout__title"; return el; });
|
|
974
|
+
if (t.parentNode === this && this.firstChild !== t) this.prepend(t);
|
|
975
|
+
t.textContent = title;
|
|
976
|
+
} else {
|
|
977
|
+
const t = this.querySelector(".c-callout__title");
|
|
978
|
+
if (t) t.remove();
|
|
979
|
+
}
|
|
980
|
+
if (flagOn(this, "closable")) {
|
|
981
|
+
this.ensure(".c-callout__close", () => {
|
|
982
|
+
const btn = document.createElement("button");
|
|
983
|
+
btn.className = "c-callout__close";
|
|
984
|
+
btn.type = "button";
|
|
985
|
+
btn.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
986
|
+
btn.textContent = "×";
|
|
987
|
+
return btn;
|
|
988
|
+
});
|
|
989
|
+
} else {
|
|
990
|
+
const btn = this.querySelector(".c-callout__close");
|
|
991
|
+
if (btn) btn.remove();
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
ContourCallout.prototype.enhance = function() {
|
|
996
|
+
if (this._wiredCallout) return;
|
|
997
|
+
this._wiredCallout = true;
|
|
998
|
+
this.addEventListener("click", (e) => {
|
|
999
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-callout__close") : null;
|
|
1000
|
+
if (!btn || !this.contains(btn)) return;
|
|
1001
|
+
e.preventDefault();
|
|
1002
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
1003
|
+
this.remove();
|
|
1004
|
+
});
|
|
1005
|
+
};
|
|
1006
|
+
define("contour-callout", ContourCallout);
|
|
1007
|
+
class ContourEmpty extends ContourBase {
|
|
1008
|
+
static get observed() { return ["state", "title", "body", "action", "icon", "illustration", "heading"]; }
|
|
1009
|
+
static get properties() { return { state: { attribute: "state" }, title: { attribute: "title" }, body: { attribute: "body" }, action: { attribute: "action" }, icon: { attribute: "icon" }, illustration: { attribute: "illustration" } }; }
|
|
1010
|
+
render() {
|
|
1011
|
+
this.classList.add("c-empty");
|
|
1012
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
1013
|
+
const state = this.getAttribute("state") || "empty";
|
|
1014
|
+
const title = this.getAttribute("title") || (state === "filtered" ? "Nothing matches" : state === "error" ? "Could not load" : "No data yet");
|
|
1015
|
+
const body = this.getAttribute("body") || (state === "filtered" ? "Try clearing some filters." : state === "error" ? "Check your connection and try again." : "There is nothing to show here yet.");
|
|
1016
|
+
const action = this.getAttribute("action") || (state === "filtered" ? "Clear filters" : state === "error" ? "Retry" : "");
|
|
1017
|
+
const icon = this.getAttribute("icon");
|
|
1018
|
+
if (icon) {
|
|
1019
|
+
const ic = this.ensure(".c-empty__icon", () => { const el = document.createElement("span"); el.className = "c-empty__icon"; return el; });
|
|
1020
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
1021
|
+
} else {
|
|
1022
|
+
const ic = this.querySelector(".c-empty__icon");
|
|
1023
|
+
if (ic) ic.remove();
|
|
1024
|
+
}
|
|
1025
|
+
const illustration = this.getAttribute("illustration");
|
|
1026
|
+
if (illustration) {
|
|
1027
|
+
const il = this.ensure(".c-empty__illustration", () => { const el = document.createElement("div"); el.className = "c-empty__illustration"; return el; });
|
|
1028
|
+
setHTML(il, sanitizeHtml(illustration));
|
|
1029
|
+
} else {
|
|
1030
|
+
const il = this.querySelector(".c-empty__illustration");
|
|
1031
|
+
if (il) il.remove();
|
|
1032
|
+
}
|
|
1033
|
+
if (title) {
|
|
1034
|
+
const t = this.ensure(".c-empty__title", () => { const el = document.createElement(headingTag(this, "h3")); el.className = "c-empty__title"; return el; });
|
|
1035
|
+
t.textContent = title;
|
|
1036
|
+
} else {
|
|
1037
|
+
const t = this.querySelector(".c-empty__title");
|
|
1038
|
+
if (t) t.remove();
|
|
1039
|
+
}
|
|
1040
|
+
if (body) {
|
|
1041
|
+
const b = this.ensure(".c-empty__text", () => { const el = document.createElement("p"); el.className = "c-empty__text"; return el; });
|
|
1042
|
+
b.textContent = body;
|
|
1043
|
+
} else {
|
|
1044
|
+
const b = this.querySelector(".c-empty__text");
|
|
1045
|
+
if (b) b.remove();
|
|
1046
|
+
}
|
|
1047
|
+
if (action) {
|
|
1048
|
+
// empty state: real .c-btn action, hooked via data-empty-action.
|
|
1049
|
+
const a = this.ensure("button.c-btn[data-empty-action]", () => {
|
|
1050
|
+
const el = document.createElement("button");
|
|
1051
|
+
el.className = "c-btn c-btn--primary";
|
|
1052
|
+
el.type = "button";
|
|
1053
|
+
el.setAttribute("data-empty-action", "");
|
|
1054
|
+
return el;
|
|
1055
|
+
});
|
|
1056
|
+
a.textContent = action;
|
|
1057
|
+
} else {
|
|
1058
|
+
const a = this.querySelector("[data-empty-action]");
|
|
1059
|
+
if (a) a.remove();
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
enhance() {
|
|
1063
|
+
// Interaction in behaviours.mjs; one impl so layers can't drift.
|
|
1064
|
+
wireRemovable(this);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
define("contour-empty", ContourEmpty);
|
|
1068
|
+
class ContourFaq extends ContourBase {
|
|
1069
|
+
static get observed() { return ["question", "answer", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
1070
|
+
static get properties() { return { question: { attribute: "question" }, answer: { attribute: "answer" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
1071
|
+
render() {
|
|
1072
|
+
this.classList.add("c-faq");
|
|
1073
|
+
wireStates(this);
|
|
1074
|
+
loadRemote(this, "items");
|
|
1075
|
+
if (renderStates(this, "faq")) return;
|
|
1076
|
+
const items = remoteData(this, "items");
|
|
1077
|
+
const question = this.getAttribute("question");
|
|
1078
|
+
const answer = this.getAttribute("answer");
|
|
1079
|
+
const authored = Array.from(this.children).filter((n) => n.classList && n.classList.contains("c-faq__item"));
|
|
1080
|
+
if (items && !authored.length) {
|
|
1081
|
+
try {
|
|
1082
|
+
const parsed = JSON.parse(items);
|
|
1083
|
+
Array.from(this.querySelectorAll(".c-faq__item")).forEach((n) => n.remove());
|
|
1084
|
+
parsed.forEach((it, i) => {
|
|
1085
|
+
// Native details+summary; [open] styling and marker hiding apply. First item opens.
|
|
1086
|
+
const item = document.createElement("details");
|
|
1087
|
+
item.className = "c-faq__item";
|
|
1088
|
+
if (i === 0) item.setAttribute("open", "");
|
|
1089
|
+
const q = document.createElement("summary");
|
|
1090
|
+
q.className = "c-faq__question";
|
|
1091
|
+
q.textContent = typeof it === "string" ? it : (it.question || it.q || "");
|
|
1092
|
+
const sign = document.createElement("span");
|
|
1093
|
+
sign.className = "c-faq__sign";
|
|
1094
|
+
sign.setAttribute("aria-hidden", "true");
|
|
1095
|
+
setHTML(sign, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-plus" /></svg>');
|
|
1096
|
+
q.appendChild(sign);
|
|
1097
|
+
item.appendChild(q);
|
|
1098
|
+
const a = document.createElement("div");
|
|
1099
|
+
a.className = "c-faq__answer";
|
|
1100
|
+
a.textContent = typeof it === "string" ? "" : (it.answer || it.a || "");
|
|
1101
|
+
item.appendChild(a);
|
|
1102
|
+
this.appendChild(item);
|
|
1103
|
+
});
|
|
1104
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1105
|
+
} else if (!items) {
|
|
1106
|
+
if (!question && !answer) {
|
|
1107
|
+
renderEmpty(this, "faq");
|
|
1108
|
+
} else {
|
|
1109
|
+
const item = this.ensure("details.c-faq__item", () => { const el = document.createElement("details"); el.className = "c-faq__item"; return el; });
|
|
1110
|
+
if (!item.hasAttribute("open")) item.setAttribute("open", "");
|
|
1111
|
+
const q = this.ensure("summary.c-faq__question", () => { const el = document.createElement("summary"); el.className = "c-faq__question"; return el; }, item);
|
|
1112
|
+
q.textContent = question || "";
|
|
1113
|
+
const sign = this.ensure(".c-faq__sign", () => { const el = document.createElement("span"); el.className = "c-faq__sign"; return el; }, q);
|
|
1114
|
+
sign.setAttribute("aria-hidden", "true");
|
|
1115
|
+
setHTML(sign, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-plus" /></svg>');
|
|
1116
|
+
const a = this.ensure(".c-faq__answer", () => { const el = document.createElement("div"); el.className = "c-faq__answer"; return el; }, item);
|
|
1117
|
+
a.textContent = answer || "";
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
define("contour-faq", ContourFaq);
|
|
1123
|
+
class ContourAccordion extends ContourBase {
|
|
1124
|
+
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "exclusive", "cache-key", "no-cache"]; }
|
|
1125
|
+
static get properties() { return { items: { attribute: "items" }, exclusive: { attribute: "exclusive", type: Boolean }, src: { attribute: "src" } }; }
|
|
1126
|
+
render() {
|
|
1127
|
+
// Host is plain container; children carry .c-disclosure styling (no .c-accordion rule).
|
|
1128
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
1129
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "accordion", "Accordion"));
|
|
1130
|
+
const authored = Array.from(this.children).filter((n) => n.tagName === "DETAILS");
|
|
1131
|
+
wireStates(this);
|
|
1132
|
+
loadRemote(this, "items");
|
|
1133
|
+
if (renderStates(this, "accordion")) return;
|
|
1134
|
+
const items = remoteData(this, "items");
|
|
1135
|
+
if (items && !authored.length) {
|
|
1136
|
+
Array.from(this.querySelectorAll("details.c-disclosure")).forEach((d) => d.remove());
|
|
1137
|
+
try {
|
|
1138
|
+
const parsed = JSON.parse(items);
|
|
1139
|
+
parsed.forEach((item) => {
|
|
1140
|
+
const details = document.createElement("details");
|
|
1141
|
+
details.className = "c-disclosure";
|
|
1142
|
+
const summary = document.createElement("summary");
|
|
1143
|
+
summary.className = "c-disclosure__summary";
|
|
1144
|
+
summary.textContent = item.title || item.question || item.q || item.label || "";
|
|
1145
|
+
details.appendChild(summary);
|
|
1146
|
+
const body = document.createElement("div");
|
|
1147
|
+
body.className = "c-disclosure__body";
|
|
1148
|
+
body.textContent = item.body || item.answer || item.a || item.content || "";
|
|
1149
|
+
details.appendChild(body);
|
|
1150
|
+
this.appendChild(details);
|
|
1151
|
+
});
|
|
1152
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1153
|
+
} else if (!items && !authored.length) {
|
|
1154
|
+
renderEmpty(this, "accordion");
|
|
1155
|
+
}
|
|
1156
|
+
// Restore persisted open state (BY-49).
|
|
1157
|
+
const persist = this.getAttribute("persist");
|
|
1158
|
+
if (persist) {
|
|
1159
|
+
let saved = null;
|
|
1160
|
+
if (persist === "storage" && this.id) { try { saved = localStorage.getItem("contour-accordion:" + this.id); } catch (e) {} }
|
|
1161
|
+
else if (persist === "url") { try { saved = new URLSearchParams(window.location.search).get("c-accordion"); } catch (e) {} }
|
|
1162
|
+
if (saved !== null) {
|
|
1163
|
+
try {
|
|
1164
|
+
const labels = JSON.parse(saved);
|
|
1165
|
+
if (Array.isArray(labels)) {
|
|
1166
|
+
const want = new Set(labels.map((l) => String(l)));
|
|
1167
|
+
Array.from(this.querySelectorAll("details.c-disclosure")).forEach((d) => {
|
|
1168
|
+
const summary = d.querySelector("summary");
|
|
1169
|
+
const label = (summary ? summary.textContent : "").trim().slice(0, 120);
|
|
1170
|
+
if (want.has(label)) d.open = true;
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
} catch (e) {}
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
enhance() {
|
|
1178
|
+
if (this._wiredAccordion) return;
|
|
1179
|
+
this._wiredAccordion = true;
|
|
1180
|
+
this.addEventListener("toggle", (e) => {
|
|
1181
|
+
const t = e.target;
|
|
1182
|
+
if (t && t.tagName === "DETAILS") {
|
|
1183
|
+
if (t.open && this.hasAttribute("exclusive")) {
|
|
1184
|
+
Array.from(this.querySelectorAll("details.c-disclosure")).forEach((d) => {
|
|
1185
|
+
if (d !== t) d.open = false;
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
this.dispatchEvent(new CustomEvent("contour:toggle", { detail: { open: t.open }, bubbles: true, composed: true }));
|
|
1189
|
+
const persist = this.getAttribute("persist");
|
|
1190
|
+
if (persist === "storage" && this.id) {
|
|
1191
|
+
try {
|
|
1192
|
+
const open = [];
|
|
1193
|
+
Array.from(this.querySelectorAll("details.c-disclosure")).forEach((d) => { if (d.open) { const s = d.querySelector("summary"); open.push((s ? s.textContent : "").trim().slice(0, 120)); } });
|
|
1194
|
+
localStorage.setItem("contour-accordion:" + this.id, JSON.stringify(open));
|
|
1195
|
+
} catch (e) {}
|
|
1196
|
+
} else if (persist === "url") {
|
|
1197
|
+
try {
|
|
1198
|
+
const open = [];
|
|
1199
|
+
Array.from(this.querySelectorAll("details.c-disclosure")).forEach((d) => { if (d.open) { const s = d.querySelector("summary"); open.push((s ? s.textContent : "").trim().slice(0, 120)); } });
|
|
1200
|
+
const url = new URL(window.location.href);
|
|
1201
|
+
url.searchParams.set("c-accordion", JSON.stringify(open));
|
|
1202
|
+
window.history.replaceState(null, "", url.toString());
|
|
1203
|
+
} catch (e) {}
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
}, true);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
define("contour-accordion", ContourAccordion);
|
|
1210
|
+
class ContourDrawer extends ContourBase {
|
|
1211
|
+
static get observed() { return ["title", "body", "size", "open"]; }
|
|
1212
|
+
static get properties() { return { title: { attribute: "title" }, body: { attribute: "body" }, size: { attribute: "size" } }; }
|
|
1213
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1214
|
+
if (name === "open") { syncDeclarativeOpen(this, name, newValue, this._wiredDrawer); return; }
|
|
1215
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
1216
|
+
}
|
|
1217
|
+
// Native-dialog parity (R20 T-32), same contract as contour-dialog.
|
|
1218
|
+
showModal() { this.show(); }
|
|
1219
|
+
get open() { return this.hasAttribute("open"); }
|
|
1220
|
+
set open(v) { if (v) this.show(); else this.close(); }
|
|
1221
|
+
render() {
|
|
1222
|
+
this.classList.add("c-drawer");
|
|
1223
|
+
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-drawer--")) this.classList.remove(c); });
|
|
1224
|
+
const size = this.getAttribute("size");
|
|
1225
|
+
if (size) this.classList.add("c-drawer--" + size);
|
|
1226
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
|
|
1227
|
+
const title = this.getAttribute("title");
|
|
1228
|
+
let head = this.querySelector(".c-drawer__head");
|
|
1229
|
+
if (title) {
|
|
1230
|
+
if (!head) {
|
|
1231
|
+
head = document.createElement("div");
|
|
1232
|
+
head.className = "c-drawer__head";
|
|
1233
|
+
const t = document.createElement("div");
|
|
1234
|
+
t.className = "c-drawer__title";
|
|
1235
|
+
head.appendChild(t);
|
|
1236
|
+
const closeBtn = document.createElement("button");
|
|
1237
|
+
closeBtn.className = "c-btn c-btn--icon c-btn--ghost c-drawer__close";
|
|
1238
|
+
closeBtn.setAttribute("type", "button");
|
|
1239
|
+
closeBtn.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
1240
|
+
setHTML(closeBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-x" /></svg>');
|
|
1241
|
+
head.appendChild(closeBtn);
|
|
1242
|
+
}
|
|
1243
|
+
const t = head.querySelector(".c-drawer__title");
|
|
1244
|
+
if (t) { t.textContent = title; if (!t.id) t.id = contourId("contour-drawer-title"); this.setAttribute("aria-labelledby", t.id); }
|
|
1245
|
+
if (head.parentNode !== this) this.prepend(head);
|
|
1246
|
+
} else if (head) {
|
|
1247
|
+
// The generated head is going away, so a label that points at its
|
|
1248
|
+
// title would dangle. Drop it only when it names the title we remove.
|
|
1249
|
+
const t = head.querySelector(".c-drawer__title");
|
|
1250
|
+
if (t && t.id && this.getAttribute("aria-labelledby") === t.id) this.removeAttribute("aria-labelledby");
|
|
1251
|
+
head.remove();
|
|
1252
|
+
}
|
|
1253
|
+
// open state re-derived each render; base restores authored class.
|
|
1254
|
+
if (this.hasAttribute("open")) this.classList.add("is-open"); else this.classList.remove("is-open");
|
|
1255
|
+
// authored children move into .c-drawer__body; body attr fills if none.
|
|
1256
|
+
const body = this.getAttribute("body");
|
|
1257
|
+
const authored = Array.from(this.childNodes).filter((n) => {
|
|
1258
|
+
if (n.nodeType === 1 && n.classList && (n.classList.contains("c-drawer__head") || n.classList.contains("c-drawer__body"))) return false;
|
|
1259
|
+
if (n.nodeType === 3 && !n.textContent.trim()) return false;
|
|
1260
|
+
return true;
|
|
1261
|
+
});
|
|
1262
|
+
if (authored.length) {
|
|
1263
|
+
const el = this.ensure(".c-drawer__body", () => { const e = document.createElement("div"); e.className = "c-drawer__body"; return e; });
|
|
1264
|
+
for (const n of authored) el.appendChild(n);
|
|
1265
|
+
} else if (body) {
|
|
1266
|
+
const el = this.ensure(".c-drawer__body", () => { const e = document.createElement("div"); e.className = "c-drawer__body"; return e; });
|
|
1267
|
+
setHTML(el, sanitizeHtml(body));
|
|
1268
|
+
} else {
|
|
1269
|
+
const b = this.querySelector(".c-drawer__body");
|
|
1270
|
+
if (b) b.remove();
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
enhance() {
|
|
1274
|
+
if (this._wiredDrawer) return;
|
|
1275
|
+
this._wiredDrawer = true;
|
|
1276
|
+
this.returnValue = "";
|
|
1277
|
+
onDispose(this, () => { if (this.hasAttribute("open")) modalContain(this, false); });
|
|
1278
|
+
this._drawerLastFocus = null;
|
|
1279
|
+
this.show = () => {
|
|
1280
|
+
if (this.hasAttribute("open")) return;
|
|
1281
|
+
this._drawerLastFocus = document.activeElement;
|
|
1282
|
+
// Guard our own `open` write (see ContourDialog.show): re-entry doubles
|
|
1283
|
+
// contour:open and leaks a modalContain depth.
|
|
1284
|
+
this._declarativeOpen = true;
|
|
1285
|
+
try { this.setAttribute("open", ""); } finally { this._declarativeOpen = false; }
|
|
1286
|
+
this.setAttribute("aria-modal", "true");
|
|
1287
|
+
this.classList.add("is-open");
|
|
1288
|
+
modalContain(this, true);
|
|
1289
|
+
const focusable = this.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
1290
|
+
if (focusable) { try { focusable.focus(); } catch (e) {} }
|
|
1291
|
+
this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true }));
|
|
1292
|
+
};
|
|
1293
|
+
this.close = () => {
|
|
1294
|
+
// `open` may already be gone via syncDeclarativeOpen; an engaged modal
|
|
1295
|
+
// (aria-modal set) must still release its inert siblings.
|
|
1296
|
+
if (!this.hasAttribute("open") && !this.hasAttribute("aria-modal")) return;
|
|
1297
|
+
// Guard our own `open` removal (see ContourDialog.close): re-entry
|
|
1298
|
+
// doubles the close event and the modalContain release.
|
|
1299
|
+
this._declarativeOpen = true;
|
|
1300
|
+
try { this.removeAttribute("open"); } finally { this._declarativeOpen = false; }
|
|
1301
|
+
this.removeAttribute("aria-modal");
|
|
1302
|
+
this.classList.remove("is-open");
|
|
1303
|
+
modalContain(this, false);
|
|
1304
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
1305
|
+
const last = this._drawerLastFocus;
|
|
1306
|
+
if (last && typeof last.focus === "function") { try { last.focus(); } catch (e) {} }
|
|
1307
|
+
};
|
|
1308
|
+
this.addEventListener("click", (e) => {
|
|
1309
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-drawer__close") : null;
|
|
1310
|
+
if (btn && this.contains(btn)) { this.close(); return; }
|
|
1311
|
+
if (e.target === this) this.close();
|
|
1312
|
+
});
|
|
1313
|
+
this.addEventListener("keydown", (e) => {
|
|
1314
|
+
if (e.key === "Escape" && this.hasAttribute("open")) this.close();
|
|
1315
|
+
});
|
|
1316
|
+
// Swipe-to-close (deferred P3): horizontal swipe past threshold closes.
|
|
1317
|
+
let touchStartX = 0, touchStartY = 0;
|
|
1318
|
+
this.addEventListener("touchstart", (e) => {
|
|
1319
|
+
if (!this.hasAttribute("open")) return;
|
|
1320
|
+
const t = e.touches && e.touches[0];
|
|
1321
|
+
if (t) { touchStartX = t.clientX; touchStartY = t.clientY; }
|
|
1322
|
+
}, { passive: true });
|
|
1323
|
+
this.addEventListener("touchend", (e) => {
|
|
1324
|
+
if (!this.hasAttribute("open")) return;
|
|
1325
|
+
const t = e.changedTouches && e.changedTouches[0];
|
|
1326
|
+
if (!t) return;
|
|
1327
|
+
const dx = t.clientX - touchStartX;
|
|
1328
|
+
const dy = t.clientY - touchStartY;
|
|
1329
|
+
if (Math.abs(dx) > 60 && Math.abs(dx) > Math.abs(dy) * 1.5) this.close();
|
|
1330
|
+
}, { passive: true });
|
|
1331
|
+
engageInitialModal(this);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
define("contour-drawer", ContourDrawer);
|
|
1335
|
+
class ContourSheet extends ContourBase {
|
|
1336
|
+
static get observed() { return ["title", "body", "size", "open"]; }
|
|
1337
|
+
static get properties() { return { title: { attribute: "title" }, body: { attribute: "body" }, size: { attribute: "size" } }; }
|
|
1338
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1339
|
+
if (name === "open") { syncDeclarativeOpen(this, name, newValue, this._wiredSheet); return; }
|
|
1340
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
1341
|
+
}
|
|
1342
|
+
// Native-dialog parity (R20 T-32), same contract as contour-dialog.
|
|
1343
|
+
showModal() { this.show(); }
|
|
1344
|
+
get open() { return this.hasAttribute("open"); }
|
|
1345
|
+
set open(v) { if (v) this.show(); else this.close(); }
|
|
1346
|
+
render() {
|
|
1347
|
+
this.classList.add("c-sheet");
|
|
1348
|
+
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-sheet--")) this.classList.remove(c); });
|
|
1349
|
+
const size = this.getAttribute("size");
|
|
1350
|
+
if (size) this.classList.add("c-sheet--" + size);
|
|
1351
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
|
|
1352
|
+
const title = this.getAttribute("title");
|
|
1353
|
+
let head = this.querySelector(".c-sheet__head");
|
|
1354
|
+
if (title) {
|
|
1355
|
+
if (!head) {
|
|
1356
|
+
head = document.createElement("div");
|
|
1357
|
+
head.className = "c-sheet__head";
|
|
1358
|
+
const t = document.createElement("div");
|
|
1359
|
+
t.className = "c-sheet__title";
|
|
1360
|
+
head.appendChild(t);
|
|
1361
|
+
const closeBtn = document.createElement("button");
|
|
1362
|
+
closeBtn.className = "c-btn c-btn--icon c-btn--ghost c-sheet__close";
|
|
1363
|
+
closeBtn.setAttribute("type", "button");
|
|
1364
|
+
closeBtn.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
1365
|
+
setHTML(closeBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-x" /></svg>');
|
|
1366
|
+
head.appendChild(closeBtn);
|
|
1367
|
+
}
|
|
1368
|
+
const t = head.querySelector(".c-sheet__title");
|
|
1369
|
+
if (t) { t.textContent = title; if (!t.id) t.id = contourId("contour-sheet-title"); this.setAttribute("aria-labelledby", t.id); }
|
|
1370
|
+
if (head.parentNode !== this) this.prepend(head);
|
|
1371
|
+
} else if (head) {
|
|
1372
|
+
// The generated head is going away, so a label that points at its
|
|
1373
|
+
// title would dangle. Drop it only when it names the title we remove.
|
|
1374
|
+
const t = head.querySelector(".c-sheet__title");
|
|
1375
|
+
if (t && t.id && this.getAttribute("aria-labelledby") === t.id) this.removeAttribute("aria-labelledby");
|
|
1376
|
+
head.remove();
|
|
1377
|
+
}
|
|
1378
|
+
// open state re-derived each render (see drawer).
|
|
1379
|
+
if (this.hasAttribute("open")) this.classList.add("is-open"); else this.classList.remove("is-open");
|
|
1380
|
+
// authored children move into .c-sheet__body; body attr fills if none.
|
|
1381
|
+
const body = this.getAttribute("body");
|
|
1382
|
+
const authored = Array.from(this.childNodes).filter((n) => {
|
|
1383
|
+
if (n.nodeType === 1 && n.classList && (n.classList.contains("c-sheet__head") || n.classList.contains("c-sheet__body"))) return false;
|
|
1384
|
+
if (n.nodeType === 3 && !n.textContent.trim()) return false;
|
|
1385
|
+
return true;
|
|
1386
|
+
});
|
|
1387
|
+
if (authored.length) {
|
|
1388
|
+
const el = this.ensure(".c-sheet__body", () => { const e = document.createElement("div"); e.className = "c-sheet__body"; return e; });
|
|
1389
|
+
for (const n of authored) el.appendChild(n);
|
|
1390
|
+
} else if (body) {
|
|
1391
|
+
const el = this.ensure(".c-sheet__body", () => { const e = document.createElement("div"); e.className = "c-sheet__body"; return e; });
|
|
1392
|
+
setHTML(el, sanitizeHtml(body));
|
|
1393
|
+
} else {
|
|
1394
|
+
const b = this.querySelector(".c-sheet__body");
|
|
1395
|
+
if (b) b.remove();
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
enhance() {
|
|
1399
|
+
if (this._wiredSheet) return;
|
|
1400
|
+
this._wiredSheet = true;
|
|
1401
|
+
this.returnValue = "";
|
|
1402
|
+
onDispose(this, () => { if (this.hasAttribute("open")) modalContain(this, false); });
|
|
1403
|
+
this._sheetLastFocus = null;
|
|
1404
|
+
this.show = () => {
|
|
1405
|
+
if (this.hasAttribute("open")) return;
|
|
1406
|
+
this._sheetLastFocus = document.activeElement;
|
|
1407
|
+
// Guard our own `open` write (see ContourDialog.show): re-entry doubles
|
|
1408
|
+
// contour:open and leaks a modalContain depth.
|
|
1409
|
+
this._declarativeOpen = true;
|
|
1410
|
+
try { this.setAttribute("open", ""); } finally { this._declarativeOpen = false; }
|
|
1411
|
+
this.setAttribute("aria-modal", "true");
|
|
1412
|
+
this.classList.add("is-open");
|
|
1413
|
+
modalContain(this, true);
|
|
1414
|
+
const focusable = this.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
1415
|
+
if (focusable) { try { focusable.focus(); } catch (e) {} }
|
|
1416
|
+
this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true }));
|
|
1417
|
+
};
|
|
1418
|
+
this.close = () => {
|
|
1419
|
+
// `open` may already be gone via syncDeclarativeOpen; an engaged modal
|
|
1420
|
+
// (aria-modal set) must still release its inert siblings.
|
|
1421
|
+
if (!this.hasAttribute("open") && !this.hasAttribute("aria-modal")) return;
|
|
1422
|
+
// Guard our own `open` removal (see ContourDialog.close): re-entry
|
|
1423
|
+
// doubles the close event and the modalContain release.
|
|
1424
|
+
this._declarativeOpen = true;
|
|
1425
|
+
try { this.removeAttribute("open"); } finally { this._declarativeOpen = false; }
|
|
1426
|
+
this.removeAttribute("aria-modal");
|
|
1427
|
+
this.classList.remove("is-open");
|
|
1428
|
+
modalContain(this, false);
|
|
1429
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
1430
|
+
const last = this._sheetLastFocus;
|
|
1431
|
+
if (last && typeof last.focus === "function") { try { last.focus(); } catch (e) {} }
|
|
1432
|
+
};
|
|
1433
|
+
this.addEventListener("click", (e) => {
|
|
1434
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-sheet__close") : null;
|
|
1435
|
+
if (btn && this.contains(btn)) { this.close(); return; }
|
|
1436
|
+
if (e.target === this) this.close();
|
|
1437
|
+
});
|
|
1438
|
+
this.addEventListener("keydown", (e) => {
|
|
1439
|
+
if (e.key === "Escape" && this.hasAttribute("open")) this.close();
|
|
1440
|
+
});
|
|
1441
|
+
// Swipe-to-close (deferred P3): vertical swipe down past threshold closes.
|
|
1442
|
+
let touchStartY = 0, touchStartX = 0;
|
|
1443
|
+
this.addEventListener("touchstart", (e) => {
|
|
1444
|
+
if (!this.hasAttribute("open")) return;
|
|
1445
|
+
const t = e.touches && e.touches[0];
|
|
1446
|
+
if (t) { touchStartX = t.clientX; touchStartY = t.clientY; }
|
|
1447
|
+
}, { passive: true });
|
|
1448
|
+
this.addEventListener("touchend", (e) => {
|
|
1449
|
+
if (!this.hasAttribute("open")) return;
|
|
1450
|
+
const t = e.changedTouches && e.changedTouches[0];
|
|
1451
|
+
if (!t) return;
|
|
1452
|
+
const dy = t.clientY - touchStartY;
|
|
1453
|
+
const dx = t.clientX - touchStartX;
|
|
1454
|
+
if (dy > 60 && Math.abs(dy) > Math.abs(dx) * 1.5) this.close();
|
|
1455
|
+
}, { passive: true });
|
|
1456
|
+
engageInitialModal(this);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
define("contour-sheet", ContourSheet);
|
|
1460
|
+
class ContourToast extends ContourBase {
|
|
1461
|
+
static get observed() { return ["message", "variant", "duration", "action", "icon"]; }
|
|
1462
|
+
static get properties() { return { message: { attribute: "message" }, variant: { attribute: "variant" }, duration: { attribute: "duration", type: Number }, action: { attribute: "action" } }; }
|
|
1463
|
+
render() {
|
|
1464
|
+
this.classList.add("c-toast");
|
|
1465
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
1466
|
+
if (!this.hasAttribute("aria-live")) this.setAttribute("aria-live", "polite");
|
|
1467
|
+
if (!this.hasAttribute("aria-atomic")) this.setAttribute("aria-atomic", "true");
|
|
1468
|
+
const message = this.getAttribute("message");
|
|
1469
|
+
if (message && !this.hasChildNodes()) {
|
|
1470
|
+
this.textContent = message;
|
|
1471
|
+
}
|
|
1472
|
+
const variant = this.getAttribute("variant");
|
|
1473
|
+
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-toast--")) this.classList.remove(c); });
|
|
1474
|
+
if (variant) this.classList.add("c-toast--" + variant);
|
|
1475
|
+
const iconAttr = this.getAttribute("icon");
|
|
1476
|
+
const icon = iconAttr === "none" ? "" : (iconAttr || statusIcon(variant));
|
|
1477
|
+
let ic = this.querySelector(".c-toast__icon");
|
|
1478
|
+
if (icon) {
|
|
1479
|
+
if (!ic) { ic = document.createElement("span"); ic.className = "c-toast__icon"; }
|
|
1480
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
1481
|
+
if (this.firstChild !== ic) this.prepend(ic);
|
|
1482
|
+
} else if (ic) {
|
|
1483
|
+
ic.remove();
|
|
1484
|
+
}
|
|
1485
|
+
// Action button (e.g. "Undo"): scaffold from `action` attribute.
|
|
1486
|
+
const action = this.getAttribute("action");
|
|
1487
|
+
let btn = this.querySelector(".c-toast__action");
|
|
1488
|
+
if (action) {
|
|
1489
|
+
if (!btn) { btn = document.createElement("button"); btn.className = "c-toast__action"; btn.type = "button"; this.appendChild(btn); }
|
|
1490
|
+
btn.textContent = action;
|
|
1491
|
+
} else if (btn) {
|
|
1492
|
+
btn.remove();
|
|
1493
|
+
}
|
|
1494
|
+
// R31-65: a toast the reader cannot dismiss is a notification, not a
|
|
1495
|
+
// message. The close action is part of the component at every duration.
|
|
1496
|
+
let close = this.querySelector(".c-toast__close");
|
|
1497
|
+
if (!close) {
|
|
1498
|
+
close = document.createElement("button");
|
|
1499
|
+
close.className = "c-toast__close";
|
|
1500
|
+
close.type = "button";
|
|
1501
|
+
close.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
1502
|
+
close.textContent = "×";
|
|
1503
|
+
this.appendChild(close);
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
enhance() {
|
|
1507
|
+
if (this._wiredToast) return;
|
|
1508
|
+
this._wiredToast = true;
|
|
1509
|
+
this.addEventListener("click", (e) => {
|
|
1510
|
+
const close = e.target && e.target.closest ? e.target.closest(".c-toast__close") : null;
|
|
1511
|
+
if (close) { e.preventDefault(); this._dismiss(); }
|
|
1512
|
+
});
|
|
1513
|
+
const pause = () => { clearTimeout(this._toastTimer); this._toastTimer = null; };
|
|
1514
|
+
this.addEventListener("mouseenter", pause);
|
|
1515
|
+
this.addEventListener("focusin", pause);
|
|
1516
|
+
this.addEventListener("mouseleave", () => this._arm());
|
|
1517
|
+
this.addEventListener("focusout", () => this._arm());
|
|
1518
|
+
this._arm();
|
|
1519
|
+
onDispose(this, () => clearTimeout(this._toastTimer));
|
|
1520
|
+
}
|
|
1521
|
+
_durationMs() {
|
|
1522
|
+
const raw = (this._toastDuration != null) ? Number(this._toastDuration) : Number(this.duration);
|
|
1523
|
+
if (raw === 0) return 0;
|
|
1524
|
+
return raw > 0 ? raw : 4000;
|
|
1525
|
+
}
|
|
1526
|
+
_arm() {
|
|
1527
|
+
clearTimeout(this._toastTimer);
|
|
1528
|
+
this._toastTimer = null;
|
|
1529
|
+
const ms = this._durationMs();
|
|
1530
|
+
if (ms > 0) this._toastTimer = setTimeout(() => this._dismiss(), ms);
|
|
1531
|
+
}
|
|
1532
|
+
_dismiss() {
|
|
1533
|
+
clearTimeout(this._toastTimer);
|
|
1534
|
+
this._toastTimer = null;
|
|
1535
|
+
this.setAttribute("hidden", "");
|
|
1536
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
1537
|
+
}
|
|
1538
|
+
// Re-show a toast (e.g. from a trigger button): paint content directly
|
|
1539
|
+
// (no observed-attribute writes, which would re-enter render), un-hide and
|
|
1540
|
+
// restart the auto-dismiss timer. A bare toast hides rather than removing
|
|
1541
|
+
// itself so a specimen — or a host that re-uses the node — can show it again.
|
|
1542
|
+
show(message, opts) {
|
|
1543
|
+
const msg = message != null ? String(message) : this.getAttribute("message");
|
|
1544
|
+
const variant = (opts && opts.variant) || this.getAttribute("variant");
|
|
1545
|
+
const action = (opts && opts.action) || this.getAttribute("action");
|
|
1546
|
+
if (msg && !this.hasChildNodes()) this.textContent = msg;
|
|
1547
|
+
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-toast--")) this.classList.remove(c); });
|
|
1548
|
+
if (variant) this.classList.add("c-toast--" + variant);
|
|
1549
|
+
let btn = this.querySelector(".c-toast__action");
|
|
1550
|
+
if (action) {
|
|
1551
|
+
if (!btn) { btn = document.createElement("button"); btn.className = "c-toast__action"; btn.type = "button"; this.appendChild(btn); }
|
|
1552
|
+
btn.textContent = action;
|
|
1553
|
+
} else if (btn) btn.remove();
|
|
1554
|
+
if (opts && opts.duration != null) this._toastDuration = Number(opts.duration);
|
|
1555
|
+
this.removeAttribute("hidden");
|
|
1556
|
+
this._arm();
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
define("contour-toast", ContourToast);
|
|
1560
|
+
class ContourExpandable extends ContourBase {
|
|
1561
|
+
static get observed() { return ["summary"]; }
|
|
1562
|
+
static get properties() { return { summary: { attribute: "summary" } }; }
|
|
1563
|
+
disconnectedCallback() { this._expandableContent = null; super.disconnectedCallback(); }
|
|
1564
|
+
connectedCallback() {
|
|
1565
|
+
if (this.innerHTML.trim() && !this._expandableContent) {
|
|
1566
|
+
this._expandableContent = this.innerHTML;
|
|
1567
|
+
}
|
|
1568
|
+
super.connectedCallback();
|
|
1569
|
+
}
|
|
1570
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1571
|
+
const details = this.querySelector("details");
|
|
1572
|
+
if (details) {
|
|
1573
|
+
const body = details.querySelector(".c-expandable__body");
|
|
1574
|
+
if (body) this._expandableContent = body.innerHTML;
|
|
1575
|
+
} else if (this.innerHTML.trim()) {
|
|
1576
|
+
this._expandableContent = this.innerHTML;
|
|
1577
|
+
}
|
|
1578
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
1579
|
+
}
|
|
1580
|
+
render() {
|
|
1581
|
+
this.classList.add("c-expandable");
|
|
1582
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
1583
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("summary") || "Expandable");
|
|
1584
|
+
const summary = this.getAttribute("summary");
|
|
1585
|
+
if (summary) {
|
|
1586
|
+
let captured = this.innerHTML.trim() ? this.innerHTML : (this._expandableContent || "");
|
|
1587
|
+
if (captured.trim()) this._expandableContent = captured;
|
|
1588
|
+
const details = this.ensure("details", () => {
|
|
1589
|
+
const d = document.createElement("details");
|
|
1590
|
+
const summ = document.createElement("summary");
|
|
1591
|
+
summ.className = "c-expandable__summary";
|
|
1592
|
+
summ.textContent = summary;
|
|
1593
|
+
d.appendChild(summ);
|
|
1594
|
+
const content = document.createElement("div");
|
|
1595
|
+
content.className = "c-expandable__body";
|
|
1596
|
+
setHTML(content, captured);
|
|
1597
|
+
d.appendChild(content);
|
|
1598
|
+
return d;
|
|
1599
|
+
});
|
|
1600
|
+
const summ = details.querySelector("summary");
|
|
1601
|
+
if (summ) summ.textContent = summary;
|
|
1602
|
+
const body = details.querySelector(".c-expandable__body");
|
|
1603
|
+
if (body) setHTML(body, captured);
|
|
1604
|
+
if (details.parentNode !== this) { setHTML(this, ""); this.appendChild(details); }
|
|
1605
|
+
} else {
|
|
1606
|
+
const details = this.querySelector("details");
|
|
1607
|
+
if (details) details.remove();
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
enhance() {
|
|
1611
|
+
if (this._wiredExpandable) return;
|
|
1612
|
+
this._wiredExpandable = true;
|
|
1613
|
+
this.addEventListener("toggle", (e) => {
|
|
1614
|
+
const t = e.target;
|
|
1615
|
+
if (t && t.tagName === "DETAILS") {
|
|
1616
|
+
this.dispatchEvent(new CustomEvent("contour:toggle", { detail: { open: t.open }, bubbles: true, composed: true }));
|
|
1617
|
+
}
|
|
1618
|
+
}, true);
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
define("contour-expandable", ContourExpandable);
|
|
1622
|
+
class ContourToastHost extends ContourBase {
|
|
1623
|
+
static get observed() { return []; }
|
|
1624
|
+
render() {
|
|
1625
|
+
this.classList.add("c-toast-host");
|
|
1626
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
1627
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "toast-host", "Toast host"));
|
|
1628
|
+
if (!this.hasAttribute("aria-live")) this.setAttribute("aria-live", "polite");
|
|
1629
|
+
if (!this.hasAttribute("aria-atomic")) this.setAttribute("aria-atomic", "true");
|
|
1630
|
+
}
|
|
1631
|
+
enhance() {
|
|
1632
|
+
if (this._wiredToastHost) return;
|
|
1633
|
+
this._wiredToastHost = true;
|
|
1634
|
+
this._toastQueue = [];
|
|
1635
|
+
this._toastActive = null;
|
|
1636
|
+
const buildToast = (message, opts) => {
|
|
1637
|
+
opts = opts || {};
|
|
1638
|
+
const toast = document.createElement("div");
|
|
1639
|
+
toast.className = "c-toast";
|
|
1640
|
+
toast.setAttribute("role", "status");
|
|
1641
|
+
toast.setAttribute("aria-live", "polite");
|
|
1642
|
+
toast.setAttribute("aria-atomic", "true");
|
|
1643
|
+
if (opts.variant) toast.classList.add("c-toast--" + opts.variant);
|
|
1644
|
+
const icon = statusIcon(opts.variant);
|
|
1645
|
+
if (icon) {
|
|
1646
|
+
const ic = document.createElement("span");
|
|
1647
|
+
ic.className = "c-toast__icon";
|
|
1648
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + icon + '" /></svg>');
|
|
1649
|
+
toast.appendChild(ic);
|
|
1650
|
+
}
|
|
1651
|
+
toast.dataset.message = message == null ? "" : String(message);
|
|
1652
|
+
const text = document.createElement("span");
|
|
1653
|
+
text.className = "c-toast__text";
|
|
1654
|
+
text.textContent = message == null ? "" : String(message);
|
|
1655
|
+
toast.appendChild(text);
|
|
1656
|
+
if (opts.action && (typeof opts.action === "string" || (opts.action.label))) {
|
|
1657
|
+
const label = (typeof opts.action === "string") ? opts.action : opts.action.label;
|
|
1658
|
+
const btn = document.createElement("button");
|
|
1659
|
+
btn.type = "button";
|
|
1660
|
+
btn.className = "c-btn c-btn--ghost c-toast__action";
|
|
1661
|
+
btn.textContent = label;
|
|
1662
|
+
btn.addEventListener("click", (e) => {
|
|
1663
|
+
e.stopPropagation();
|
|
1664
|
+
if (typeof opts.action === "object" && typeof opts.action.onClick === "function") {
|
|
1665
|
+
try { opts.action.onClick(); } catch (err) {}
|
|
1666
|
+
}
|
|
1667
|
+
dismiss(toast);
|
|
1668
|
+
});
|
|
1669
|
+
toast.appendChild(btn);
|
|
1670
|
+
}
|
|
1671
|
+
const close = document.createElement("button");
|
|
1672
|
+
close.type = "button";
|
|
1673
|
+
close.className = "c-toast__close";
|
|
1674
|
+
close.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
1675
|
+
close.textContent = "×";
|
|
1676
|
+
toast.appendChild(close);
|
|
1677
|
+
close.addEventListener("click", (e) => { e.stopPropagation(); dismiss(toast); });
|
|
1678
|
+
toast._arm = () => {
|
|
1679
|
+
clearTimeout(toast._timer);
|
|
1680
|
+
const d = opts.duration;
|
|
1681
|
+
const ms = d === 0 ? 0 : (d > 0 ? d : 4000);
|
|
1682
|
+
if (ms > 0) toast._timer = setTimeout(() => dismiss(toast), ms);
|
|
1683
|
+
};
|
|
1684
|
+
toast.addEventListener("mouseenter", () => clearTimeout(toast._timer));
|
|
1685
|
+
toast.addEventListener("focusin", () => clearTimeout(toast._timer));
|
|
1686
|
+
toast.addEventListener("mouseleave", toast._arm);
|
|
1687
|
+
toast.addEventListener("focusout", toast._arm);
|
|
1688
|
+
return toast;
|
|
1689
|
+
};
|
|
1690
|
+
const dismiss = (toast) => {
|
|
1691
|
+
if (!toast || !toast.parentNode) return;
|
|
1692
|
+
if (toast._timer) { clearTimeout(toast._timer); toast._timer = null; }
|
|
1693
|
+
toast.parentNode.removeChild(toast);
|
|
1694
|
+
if (this._toastActive === toast) this._toastActive = null;
|
|
1695
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true, detail: { message: toast.textContent } }));
|
|
1696
|
+
pump();
|
|
1697
|
+
};
|
|
1698
|
+
const pump = () => {
|
|
1699
|
+
// R31-65: stack independent messages; each toast owns its timer and
|
|
1700
|
+
// close button. A host-level queue still dedups identical messages.
|
|
1701
|
+
while (this._toastQueue.length) {
|
|
1702
|
+
const next = this._toastQueue.shift();
|
|
1703
|
+
if (next._deduped) continue;
|
|
1704
|
+
const toast = buildToast(next.message, next.opts);
|
|
1705
|
+
this._toastActive = toast;
|
|
1706
|
+
this.appendChild(toast);
|
|
1707
|
+
toast._arm();
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
this.show = (message, opts) => {
|
|
1711
|
+
opts = opts || {};
|
|
1712
|
+
const key = String(message == null ? "" : message);
|
|
1713
|
+
// dedup: if an identical message is already queued or active, reset its timer instead of stacking
|
|
1714
|
+
const active = this._toastActive;
|
|
1715
|
+
if (active && active.dataset && active.dataset.message === key && key !== "") {
|
|
1716
|
+
if (active._timer) { clearTimeout(active._timer); }
|
|
1717
|
+
const ms = (opts.duration && opts.duration > 0) ? opts.duration : 4000;
|
|
1718
|
+
active._timer = setTimeout(() => dismiss(active), ms);
|
|
1719
|
+
return active;
|
|
1720
|
+
}
|
|
1721
|
+
const queuedDup = this._toastQueue.find((q) => String(q.message) === key && key !== "");
|
|
1722
|
+
if (queuedDup) {
|
|
1723
|
+
queuedDup.opts = Object.assign({}, queuedDup.opts, opts);
|
|
1724
|
+
return null;
|
|
1725
|
+
}
|
|
1726
|
+
const entry = { message, opts, _deduped: false };
|
|
1727
|
+
this._toastQueue.push(entry);
|
|
1728
|
+
pump();
|
|
1729
|
+
return this._toastActive;
|
|
1730
|
+
};
|
|
1731
|
+
this.hide = () => {
|
|
1732
|
+
if (this._toastActive) dismiss(this._toastActive);
|
|
1733
|
+
this._toastQueue.length = 0;
|
|
1734
|
+
Array.from(this.querySelectorAll(".c-toast")).forEach((t) => {
|
|
1735
|
+
if (t._timer) clearTimeout(t._timer);
|
|
1736
|
+
if (t.parentNode) t.parentNode.removeChild(t);
|
|
1737
|
+
});
|
|
1738
|
+
this._toastActive = null;
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
define("contour-toast-host", ContourToastHost);
|