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
package/dist/wc/feedback.mjs
CHANGED
|
@@ -1,9 +1,44 @@
|
|
|
1
|
-
import { ContourBase, define, onDispose, sanitizeHtml, headingTag } from './core.mjs';
|
|
1
|
+
import { setHTML, ContourBase, define, onDispose, sanitizeHtml, headingTag , warnBadJson, contourId, flagOn, labelText, statusIcon } from './core.mjs';
|
|
2
2
|
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
|
|
3
3
|
import { wireRemovable, modalContain } from './behaviours.mjs';
|
|
4
|
+
// R31-12: an authored `open` at load displays the modal (CSS [open]) but never
|
|
5
|
+
// ran show(), so it was not actually modal — no aria-modal, no inert siblings,
|
|
6
|
+
// no focus inside. Engage the modal for an initial open without re-entering
|
|
7
|
+
// show() (which returns early while `open` is already set). Idempotent per host.
|
|
8
|
+
function engageInitialModal(host) {
|
|
9
|
+
if (!host.hasAttribute("open") || host._modalEngaged) return;
|
|
10
|
+
host._modalEngaged = true;
|
|
11
|
+
host.setAttribute("aria-modal", "true");
|
|
12
|
+
modalContain(host, true);
|
|
13
|
+
const focusable = host.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
14
|
+
if (focusable) { try { focusable.focus(); } catch (e) {} }
|
|
15
|
+
}
|
|
16
|
+
/** R31-34: a later `open` attribute write is the same contract as the property. */
|
|
17
|
+
function syncDeclarativeOpen(host, name, newValue, wired) {
|
|
18
|
+
if (name !== "open" || !wired || host._declarativeOpen) return;
|
|
19
|
+
host._declarativeOpen = true;
|
|
20
|
+
try {
|
|
21
|
+
if (newValue !== null && !host.hasAttribute("aria-modal")) {
|
|
22
|
+
host.removeAttribute("open");
|
|
23
|
+
host.show();
|
|
24
|
+
} else if (newValue === null && host.hasAttribute("aria-modal")) {
|
|
25
|
+
host.close();
|
|
26
|
+
}
|
|
27
|
+
} finally {
|
|
28
|
+
host._declarativeOpen = false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
4
31
|
class ContourDialog extends ContourBase {
|
|
5
|
-
static get observed() { return ["title", "size", "heading"]; }
|
|
32
|
+
static get observed() { return ["title", "size", "heading", "open"]; }
|
|
6
33
|
static get properties() { return { title: { attribute: "title" }, size: { attribute: "size" } }; }
|
|
34
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
35
|
+
if (name === "open") { syncDeclarativeOpen(this, name, newValue, this._wiredDialog); return; }
|
|
36
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
37
|
+
}
|
|
38
|
+
// Native-dialog parity (R20 T-32): showModal() aliases show(); open routes through show()/close(); returnValue persists.
|
|
39
|
+
showModal() { this.show(); }
|
|
40
|
+
get open() { return this.hasAttribute("open"); }
|
|
41
|
+
set open(v) { if (v) this.show(); else this.close(); }
|
|
7
42
|
render() {
|
|
8
43
|
this.classList.add("c-dialog");
|
|
9
44
|
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-dialog--")) this.classList.remove(c); });
|
|
@@ -22,12 +57,12 @@ class ContourDialog extends ContourBase {
|
|
|
22
57
|
const closeBtn = document.createElement("button");
|
|
23
58
|
closeBtn.className = "c-btn c-btn--icon c-btn--ghost c-dialog__close";
|
|
24
59
|
closeBtn.setAttribute("type", "button");
|
|
25
|
-
closeBtn.setAttribute("aria-label", "Close");
|
|
26
|
-
closeBtn
|
|
60
|
+
closeBtn.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
61
|
+
setHTML(closeBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-x" /></svg>');
|
|
27
62
|
head.appendChild(closeBtn);
|
|
28
63
|
}
|
|
29
64
|
const h = head.querySelector(".c-dialog__title");
|
|
30
|
-
if (h) { h.textContent = title; if (!h.id) h.id = "contour-dialog-title
|
|
65
|
+
if (h) { h.textContent = title; if (!h.id) h.id = contourId("contour-dialog-title"); this.setAttribute("aria-labelledby", h.id); }
|
|
31
66
|
}
|
|
32
67
|
if (head && head.parentNode !== this) this.prepend(head);
|
|
33
68
|
// Wrap authored content in a body so it picks up the dialog's padding.
|
|
@@ -47,15 +82,17 @@ class ContourDialog extends ContourBase {
|
|
|
47
82
|
enhance() {
|
|
48
83
|
if (this._wiredDialog) return;
|
|
49
84
|
this._wiredDialog = true;
|
|
85
|
+
this.returnValue = "";
|
|
50
86
|
onDispose(this, () => { if (this.hasAttribute("open")) modalContain(this, false); });
|
|
51
|
-
|
|
52
|
-
// and a caller can read host.open; it is written here and never observed,
|
|
53
|
-
// so changing it cannot re-enter the render (the shared list excludes it
|
|
54
|
-
// for exactly this reason).
|
|
87
|
+
// open attribute is written, never observed — no render re-entry.
|
|
55
88
|
this.show = () => {
|
|
56
89
|
if (this.hasAttribute("open")) return;
|
|
57
90
|
this._dialogLastFocus = document.activeElement;
|
|
58
|
-
|
|
91
|
+
// Guard our own `open` write: syncDeclarativeOpen would otherwise see the
|
|
92
|
+
// attribute change (aria-modal is not set yet) and re-enter show(), firing
|
|
93
|
+
// contour:open twice and leaking a second modalContain depth.
|
|
94
|
+
this._declarativeOpen = true;
|
|
95
|
+
try { this.setAttribute("open", ""); } finally { this._declarativeOpen = false; }
|
|
59
96
|
this.setAttribute("aria-modal", "true");
|
|
60
97
|
const dlg = this.querySelector("dialog") || (this.tagName === "DIALOG" ? this : null);
|
|
61
98
|
if (dlg && typeof dlg.showModal === "function") { try { dlg.showModal(); } catch (e) {} }
|
|
@@ -66,10 +103,17 @@ class ContourDialog extends ContourBase {
|
|
|
66
103
|
this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true }));
|
|
67
104
|
};
|
|
68
105
|
this.close = () => {
|
|
69
|
-
|
|
106
|
+
// `open` may already be gone when close() is reached through
|
|
107
|
+
// syncDeclarativeOpen (the host removed the attribute first); an engaged
|
|
108
|
+
// modal (aria-modal still set) must still release its inert siblings, or
|
|
109
|
+
// a lower stacked dialog stays inert.
|
|
110
|
+
const wasOpen = this.hasAttribute("open") || this.hasAttribute("aria-modal");
|
|
70
111
|
const dlg = this.querySelector("dialog") || (this.tagName === "DIALOG" ? this : null);
|
|
71
112
|
if (dlg && typeof dlg.close === "function") dlg.close();
|
|
72
|
-
|
|
113
|
+
// Guard our own `open` removal so syncDeclarativeOpen does not re-enter
|
|
114
|
+
// close() (which would double the close event and the modalContain release).
|
|
115
|
+
this._declarativeOpen = true;
|
|
116
|
+
try { if (this.hasAttribute("open")) this.removeAttribute("open"); } finally { this._declarativeOpen = false; }
|
|
73
117
|
this.removeAttribute("aria-modal");
|
|
74
118
|
if (wasOpen) {
|
|
75
119
|
modalContain(this, false);
|
|
@@ -91,38 +135,46 @@ class ContourDialog extends ContourBase {
|
|
|
91
135
|
// Backdrop click: clicking the host surface (not its content) closes.
|
|
92
136
|
if (e.target === this) this.close();
|
|
93
137
|
});
|
|
94
|
-
|
|
95
|
-
// close to report, and an unconditional event is a claim the component
|
|
96
|
-
// cannot back (F-18).
|
|
138
|
+
// Escape closes only while open; unconditional event is a claim it can't back.
|
|
97
139
|
this.addEventListener("keydown", (e) => {
|
|
98
140
|
if (e.key === "Escape" && this.hasAttribute("open")) this.close();
|
|
99
141
|
});
|
|
142
|
+
engageInitialModal(this);
|
|
100
143
|
}
|
|
101
144
|
}
|
|
102
145
|
define("contour-dialog", ContourDialog);
|
|
103
146
|
class ContourAlert extends ContourBase {
|
|
104
|
-
static get observed() { return ["title", "body", "variant", "icon", "closable", "action", "actions", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
147
|
+
static get observed() { return ["title", "body", "variant", "icon", "closable", "action", "actions", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
105
148
|
static get properties() {
|
|
106
149
|
return { title: { attribute: "title" }, body: { attribute: "body" }, variant: { attribute: "variant" }, icon: { attribute: "icon" }, closable: { attribute: "closable", type: Boolean }, action: { attribute: "action" }, actions: { attribute: "actions" } };
|
|
107
150
|
}
|
|
108
151
|
render() {
|
|
109
152
|
this.classList.add("c-alert");
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
153
|
+
// Urgent variants (warning/danger) = alert/assertive; others = status/polite (don't talk over reader).
|
|
154
|
+
const urgent = /^(warning|danger)$/.test(this.getAttribute("variant") || "");
|
|
155
|
+
const role = urgent ? "alert" : "status";
|
|
156
|
+
const live = urgent ? "assertive" : "polite";
|
|
157
|
+
// Host-written role/aria-live so loader state announces inside region; authored wins.
|
|
158
|
+
if (!this.hasAttribute("role") || this.getAttribute("role") === this._autoRole) {
|
|
159
|
+
this.setAttribute("role", role);
|
|
160
|
+
this._autoRole = role;
|
|
161
|
+
}
|
|
162
|
+
if (!this.hasAttribute("aria-live") || this.getAttribute("aria-live") === this._autoLive) {
|
|
163
|
+
this.setAttribute("aria-live", live);
|
|
164
|
+
this._autoLive = live;
|
|
165
|
+
}
|
|
115
166
|
wireStates(this);
|
|
116
167
|
loadRemote(this, "title");
|
|
117
168
|
if (renderStates(this, "alert")) return;
|
|
118
169
|
const variant = this.getAttribute("variant");
|
|
119
170
|
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-alert--")) this.classList.remove(c); });
|
|
120
171
|
if (variant) this.classList.add("c-alert--" + variant);
|
|
121
|
-
const
|
|
172
|
+
const iconAttr = this.getAttribute("icon");
|
|
173
|
+
const icon = iconAttr === "none" ? "" : (iconAttr || statusIcon(variant));
|
|
122
174
|
if (icon) {
|
|
123
175
|
const ic = this.ensure(".c-alert__icon", () => { const el = document.createElement("span"); el.className = "c-alert__icon"; return el; });
|
|
124
176
|
if (ic.parentNode === this && this.firstChild !== ic) this.prepend(ic);
|
|
125
|
-
ic
|
|
177
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
126
178
|
} else {
|
|
127
179
|
const ic = this.querySelector(".c-alert__icon");
|
|
128
180
|
if (ic) ic.remove();
|
|
@@ -136,16 +188,25 @@ class ContourAlert extends ContourBase {
|
|
|
136
188
|
const t = this.querySelector(".c-alert__title");
|
|
137
189
|
if (t) t.remove();
|
|
138
190
|
}
|
|
191
|
+
// Authored children move into .c-alert__body (default slot); `body` attribute fills when no children.
|
|
139
192
|
const body = this.getAttribute("body");
|
|
140
|
-
|
|
193
|
+
const authored = Array.from(this.childNodes).filter((n) => {
|
|
194
|
+
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;
|
|
195
|
+
if (n.nodeType === 3 && !n.textContent.trim()) return false;
|
|
196
|
+
return true;
|
|
197
|
+
});
|
|
198
|
+
if (authored.length) {
|
|
199
|
+
const b = this.ensure(".c-alert__body", () => { const el = document.createElement("div"); el.className = "c-alert__body"; return el; });
|
|
200
|
+
b.textContent = "";
|
|
201
|
+
for (const n of authored) b.appendChild(n);
|
|
202
|
+
} else if (body) {
|
|
141
203
|
const b = this.ensure(".c-alert__body", () => { const el = document.createElement("div"); el.className = "c-alert__body"; return el; });
|
|
142
204
|
b.textContent = body;
|
|
143
205
|
} else {
|
|
144
206
|
const b = this.querySelector(".c-alert__body");
|
|
145
207
|
if (b) b.remove();
|
|
146
208
|
}
|
|
147
|
-
|
|
148
|
-
// different `action`/`actions` value does not leave stale buttons behind.
|
|
209
|
+
// Remove stale action buttons on re-render.
|
|
149
210
|
Array.from(this.querySelectorAll(".c-alert__action")).forEach((n) => n.remove());
|
|
150
211
|
const actionsAttr = this.getAttribute("actions");
|
|
151
212
|
let actionList = [];
|
|
@@ -163,12 +224,12 @@ class ContourAlert extends ContourBase {
|
|
|
163
224
|
a.textContent = label;
|
|
164
225
|
this.appendChild(a);
|
|
165
226
|
});
|
|
166
|
-
if (this
|
|
227
|
+
if (flagOn(this, "closable")) {
|
|
167
228
|
this.ensure(".c-alert__close", () => {
|
|
168
229
|
const btn = document.createElement("button");
|
|
169
230
|
btn.className = "c-alert__close";
|
|
170
231
|
btn.type = "button";
|
|
171
|
-
btn.setAttribute("aria-label", "Close");
|
|
232
|
+
btn.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
172
233
|
btn.textContent = "×";
|
|
173
234
|
return btn;
|
|
174
235
|
});
|
|
@@ -176,7 +237,7 @@ class ContourAlert extends ContourBase {
|
|
|
176
237
|
const btn = this.querySelector(".c-alert__close");
|
|
177
238
|
if (btn) btn.remove();
|
|
178
239
|
}
|
|
179
|
-
if (!title && !body && !icon) {
|
|
240
|
+
if (!title && !body && !icon && !authored.length) {
|
|
180
241
|
renderEmpty(this, "alert");
|
|
181
242
|
}
|
|
182
243
|
}
|
|
@@ -188,7 +249,7 @@ class ContourAlert extends ContourBase {
|
|
|
188
249
|
const actionBtn = e.target && e.target.closest ? e.target.closest(".c-alert__action") : null;
|
|
189
250
|
if (actionBtn && this.contains(actionBtn)) {
|
|
190
251
|
e.preventDefault();
|
|
191
|
-
this.dispatchEvent(new CustomEvent("contour:
|
|
252
|
+
this.dispatchEvent(new CustomEvent("contour:action", { bubbles: true, composed: true, detail: { label: actionBtn.textContent.trim() } }));
|
|
192
253
|
return;
|
|
193
254
|
}
|
|
194
255
|
const btn = e.target && e.target.closest ? e.target.closest(".c-alert__close") : null;
|
|
@@ -210,8 +271,7 @@ class ContourDisclosure extends ContourBase {
|
|
|
210
271
|
super.connectedCallback();
|
|
211
272
|
}
|
|
212
273
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
213
|
-
|
|
214
|
-
// container that holds it.
|
|
274
|
+
// Preserve authored content before base reset removes generated container.
|
|
215
275
|
const details = this.querySelector("details");
|
|
216
276
|
if (details) {
|
|
217
277
|
const body = details.querySelector(".c-disclosure__body");
|
|
@@ -235,37 +295,35 @@ class ContourDisclosure extends ContourBase {
|
|
|
235
295
|
if (icon) {
|
|
236
296
|
const ic = document.createElement("span");
|
|
237
297
|
ic.className = "c-disclosure__icon";
|
|
238
|
-
ic
|
|
298
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
239
299
|
summ.appendChild(ic);
|
|
240
300
|
}
|
|
241
301
|
summ.appendChild(document.createTextNode(summary));
|
|
242
302
|
d.appendChild(summ);
|
|
243
303
|
const content = document.createElement("div");
|
|
244
304
|
content.className = "c-disclosure__body";
|
|
245
|
-
content
|
|
305
|
+
setHTML(content, captured);
|
|
246
306
|
d.appendChild(content);
|
|
247
307
|
return d;
|
|
248
308
|
});
|
|
249
|
-
// update summary if already existed
|
|
250
309
|
const summ = details.querySelector("summary");
|
|
251
310
|
if (summ) {
|
|
252
311
|
const ic = summ.querySelector(".c-disclosure__icon");
|
|
253
312
|
if (icon && !ic) {
|
|
254
313
|
const newIc = document.createElement("span");
|
|
255
314
|
newIc.className = "c-disclosure__icon";
|
|
256
|
-
newIc
|
|
315
|
+
setHTML(newIc, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
257
316
|
summ.insertBefore(newIc, summ.firstChild);
|
|
258
317
|
} else if (!icon && ic) {
|
|
259
318
|
ic.remove();
|
|
260
319
|
}
|
|
261
|
-
// Update text content (remove icon text, set summary)
|
|
262
320
|
const textNodes = Array.from(summ.childNodes).filter(n => n.nodeType === 3);
|
|
263
321
|
textNodes.forEach(n => n.remove());
|
|
264
322
|
summ.appendChild(document.createTextNode(summary));
|
|
265
323
|
}
|
|
266
324
|
const body = details.querySelector(".c-disclosure__body");
|
|
267
|
-
if (body) body
|
|
268
|
-
if (details.parentNode !== this) { this
|
|
325
|
+
if (body) setHTML(body, captured);
|
|
326
|
+
if (details.parentNode !== this) { setHTML(this, ""); this.appendChild(details); }
|
|
269
327
|
} else {
|
|
270
328
|
const details = this.querySelector("details");
|
|
271
329
|
if (details) details.remove();
|
|
@@ -288,14 +346,17 @@ class ContourCallout extends ContourBase {
|
|
|
288
346
|
static get properties() { return { variant: { attribute: "variant" }, title: { attribute: "title" }, icon: { attribute: "icon" }, closable: { attribute: "closable", type: Boolean } }; }
|
|
289
347
|
render() {
|
|
290
348
|
this.classList.add("c-callout");
|
|
349
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "note");
|
|
350
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Callout");
|
|
291
351
|
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-callout--")) this.classList.remove(c); });
|
|
292
352
|
const variant = this.getAttribute("variant");
|
|
293
353
|
if (variant) this.classList.add("c-callout--" + variant);
|
|
294
|
-
const
|
|
354
|
+
const iconAttr = this.getAttribute("icon");
|
|
355
|
+
const icon = iconAttr === "none" ? "" : (iconAttr || statusIcon(variant));
|
|
295
356
|
if (icon) {
|
|
296
357
|
const ic = this.ensure(".c-callout__icon", () => { const el = document.createElement("span"); el.className = "c-callout__icon"; return el; });
|
|
297
358
|
if (ic.parentNode === this && this.firstChild !== ic) this.prepend(ic);
|
|
298
|
-
ic
|
|
359
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
299
360
|
} else {
|
|
300
361
|
const ic = this.querySelector(".c-callout__icon");
|
|
301
362
|
if (ic) ic.remove();
|
|
@@ -309,12 +370,12 @@ class ContourCallout extends ContourBase {
|
|
|
309
370
|
const t = this.querySelector(".c-callout__title");
|
|
310
371
|
if (t) t.remove();
|
|
311
372
|
}
|
|
312
|
-
if (this
|
|
373
|
+
if (flagOn(this, "closable")) {
|
|
313
374
|
this.ensure(".c-callout__close", () => {
|
|
314
375
|
const btn = document.createElement("button");
|
|
315
376
|
btn.className = "c-callout__close";
|
|
316
377
|
btn.type = "button";
|
|
317
|
-
btn.setAttribute("aria-label", "Close");
|
|
378
|
+
btn.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
318
379
|
btn.textContent = "×";
|
|
319
380
|
return btn;
|
|
320
381
|
});
|
|
@@ -349,7 +410,7 @@ class ContourEmpty extends ContourBase {
|
|
|
349
410
|
const icon = this.getAttribute("icon");
|
|
350
411
|
if (icon) {
|
|
351
412
|
const ic = this.ensure(".c-empty__icon", () => { const el = document.createElement("span"); el.className = "c-empty__icon"; return el; });
|
|
352
|
-
ic
|
|
413
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
353
414
|
} else {
|
|
354
415
|
const ic = this.querySelector(".c-empty__icon");
|
|
355
416
|
if (ic) ic.remove();
|
|
@@ -357,7 +418,7 @@ class ContourEmpty extends ContourBase {
|
|
|
357
418
|
const illustration = this.getAttribute("illustration");
|
|
358
419
|
if (illustration) {
|
|
359
420
|
const il = this.ensure(".c-empty__illustration", () => { const el = document.createElement("div"); el.className = "c-empty__illustration"; return el; });
|
|
360
|
-
il
|
|
421
|
+
setHTML(il, sanitizeHtml(illustration));
|
|
361
422
|
} else {
|
|
362
423
|
const il = this.querySelector(".c-empty__illustration");
|
|
363
424
|
if (il) il.remove();
|
|
@@ -377,10 +438,7 @@ class ContourEmpty extends ContourBase {
|
|
|
377
438
|
if (b) b.remove();
|
|
378
439
|
}
|
|
379
440
|
if (action) {
|
|
380
|
-
|
|
381
|
-
// element: the action is a real `.c-btn`. The invented action class
|
|
382
|
-
// matched no rule, so it styled nothing yet was the click hook in both
|
|
383
|
-
// layers — `data-empty-action` is the same hook without the invented name.
|
|
441
|
+
// empty state: real .c-btn action, hooked via data-empty-action.
|
|
384
442
|
const a = this.ensure("button.c-btn[data-empty-action]", () => {
|
|
385
443
|
const el = document.createElement("button");
|
|
386
444
|
el.className = "c-btn c-btn--primary";
|
|
@@ -395,15 +453,13 @@ class ContourEmpty extends ContourBase {
|
|
|
395
453
|
}
|
|
396
454
|
}
|
|
397
455
|
enhance() {
|
|
398
|
-
|
|
399
|
-
// One implementation, so the two layers cannot drift apart again: the shadow
|
|
400
|
-
// copy queried its root for slotted nodes, found none, and wired nothing.
|
|
456
|
+
// Interaction in behaviours.mjs; one impl so layers can't drift.
|
|
401
457
|
wireRemovable(this);
|
|
402
458
|
}
|
|
403
459
|
}
|
|
404
460
|
define("contour-empty", ContourEmpty);
|
|
405
461
|
class ContourFaq extends ContourBase {
|
|
406
|
-
static get observed() { return ["question", "answer", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
462
|
+
static get observed() { return ["question", "answer", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
407
463
|
static get properties() { return { question: { attribute: "question" }, answer: { attribute: "answer" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
408
464
|
render() {
|
|
409
465
|
this.classList.add("c-faq");
|
|
@@ -419,9 +475,7 @@ class ContourFaq extends ContourBase {
|
|
|
419
475
|
const parsed = JSON.parse(items);
|
|
420
476
|
Array.from(this.querySelectorAll(".c-faq__item")).forEach((n) => n.remove());
|
|
421
477
|
parsed.forEach((it, i) => {
|
|
422
|
-
|
|
423
|
-
// summary, so the [open] styling and the marker hiding apply. The
|
|
424
|
-
// first item opens like the guide's own FAQ section does.
|
|
478
|
+
// Native details+summary; [open] styling and marker hiding apply. First item opens.
|
|
425
479
|
const item = document.createElement("details");
|
|
426
480
|
item.className = "c-faq__item";
|
|
427
481
|
if (i === 0) item.setAttribute("open", "");
|
|
@@ -431,7 +485,7 @@ class ContourFaq extends ContourBase {
|
|
|
431
485
|
const sign = document.createElement("span");
|
|
432
486
|
sign.className = "c-faq__sign";
|
|
433
487
|
sign.setAttribute("aria-hidden", "true");
|
|
434
|
-
sign
|
|
488
|
+
setHTML(sign, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-plus" /></svg>');
|
|
435
489
|
q.appendChild(sign);
|
|
436
490
|
item.appendChild(q);
|
|
437
491
|
const a = document.createElement("div");
|
|
@@ -440,7 +494,7 @@ class ContourFaq extends ContourBase {
|
|
|
440
494
|
item.appendChild(a);
|
|
441
495
|
this.appendChild(item);
|
|
442
496
|
});
|
|
443
|
-
} catch (e) {
|
|
497
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
444
498
|
} else if (!items) {
|
|
445
499
|
if (!question && !answer) {
|
|
446
500
|
renderEmpty(this, "faq");
|
|
@@ -451,7 +505,7 @@ class ContourFaq extends ContourBase {
|
|
|
451
505
|
q.textContent = question || "";
|
|
452
506
|
const sign = this.ensure(".c-faq__sign", () => { const el = document.createElement("span"); el.className = "c-faq__sign"; return el; }, q);
|
|
453
507
|
sign.setAttribute("aria-hidden", "true");
|
|
454
|
-
sign
|
|
508
|
+
setHTML(sign, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-plus" /></svg>');
|
|
455
509
|
const a = this.ensure(".c-faq__answer", () => { const el = document.createElement("div"); el.className = "c-faq__answer"; return el; }, item);
|
|
456
510
|
a.textContent = answer || "";
|
|
457
511
|
}
|
|
@@ -460,12 +514,12 @@ class ContourFaq extends ContourBase {
|
|
|
460
514
|
}
|
|
461
515
|
define("contour-faq", ContourFaq);
|
|
462
516
|
class ContourAccordion extends ContourBase {
|
|
463
|
-
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "exclusive"]; }
|
|
517
|
+
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "exclusive", "cache-key", "no-cache"]; }
|
|
464
518
|
static get properties() { return { items: { attribute: "items" }, exclusive: { attribute: "exclusive", type: Boolean }, src: { attribute: "src" } }; }
|
|
465
519
|
render() {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
520
|
+
// Host is plain container; children carry .c-disclosure styling (no .c-accordion rule).
|
|
521
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
522
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "accordion", "Accordion"));
|
|
469
523
|
const authored = Array.from(this.children).filter((n) => n.tagName === "DETAILS");
|
|
470
524
|
wireStates(this);
|
|
471
525
|
loadRemote(this, "items");
|
|
@@ -488,7 +542,7 @@ class ContourAccordion extends ContourBase {
|
|
|
488
542
|
details.appendChild(body);
|
|
489
543
|
this.appendChild(details);
|
|
490
544
|
});
|
|
491
|
-
} catch (e) {
|
|
545
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
492
546
|
} else if (!items && !authored.length) {
|
|
493
547
|
renderEmpty(this, "accordion");
|
|
494
548
|
}
|
|
@@ -547,8 +601,16 @@ class ContourAccordion extends ContourBase {
|
|
|
547
601
|
}
|
|
548
602
|
define("contour-accordion", ContourAccordion);
|
|
549
603
|
class ContourDrawer extends ContourBase {
|
|
550
|
-
static get observed() { return ["title", "body", "size"]; }
|
|
604
|
+
static get observed() { return ["title", "body", "size", "open"]; }
|
|
551
605
|
static get properties() { return { title: { attribute: "title" }, body: { attribute: "body" }, size: { attribute: "size" } }; }
|
|
606
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
607
|
+
if (name === "open") { syncDeclarativeOpen(this, name, newValue, this._wiredDrawer); return; }
|
|
608
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
609
|
+
}
|
|
610
|
+
// Native-dialog parity (R20 T-32), same contract as contour-dialog.
|
|
611
|
+
showModal() { this.show(); }
|
|
612
|
+
get open() { return this.hasAttribute("open"); }
|
|
613
|
+
set open(v) { if (v) this.show(); else this.close(); }
|
|
552
614
|
render() {
|
|
553
615
|
this.classList.add("c-drawer");
|
|
554
616
|
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-drawer--")) this.classList.remove(c); });
|
|
@@ -567,40 +629,53 @@ class ContourDrawer extends ContourBase {
|
|
|
567
629
|
const closeBtn = document.createElement("button");
|
|
568
630
|
closeBtn.className = "c-btn c-btn--icon c-btn--ghost c-drawer__close";
|
|
569
631
|
closeBtn.setAttribute("type", "button");
|
|
570
|
-
closeBtn.setAttribute("aria-label", "Close");
|
|
571
|
-
closeBtn
|
|
632
|
+
closeBtn.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
633
|
+
setHTML(closeBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-x" /></svg>');
|
|
572
634
|
head.appendChild(closeBtn);
|
|
573
635
|
}
|
|
574
636
|
const t = head.querySelector(".c-drawer__title");
|
|
575
|
-
if (t) { t.textContent = title; if (!t.id) t.id = "contour-drawer-title
|
|
637
|
+
if (t) { t.textContent = title; if (!t.id) t.id = contourId("contour-drawer-title"); this.setAttribute("aria-labelledby", t.id); }
|
|
576
638
|
if (head.parentNode !== this) this.prepend(head);
|
|
577
639
|
} else if (head) {
|
|
640
|
+
// The generated head is going away, so a label that points at its
|
|
641
|
+
// title would dangle. Drop it only when it names the title we remove.
|
|
642
|
+
const t = head.querySelector(".c-drawer__title");
|
|
643
|
+
if (t && t.id && this.getAttribute("aria-labelledby") === t.id) this.removeAttribute("aria-labelledby");
|
|
578
644
|
head.remove();
|
|
579
645
|
}
|
|
580
|
-
|
|
581
|
-
// cannot re-enter the render — see the dialog); the `.is-open` class the
|
|
582
|
-
// CSS keys off is re-derived here because the base restores the authored
|
|
583
|
-
// class on every render and would otherwise drop it mid-lock.
|
|
646
|
+
// open state re-derived each render; base restores authored class.
|
|
584
647
|
if (this.hasAttribute("open")) this.classList.add("is-open"); else this.classList.remove("is-open");
|
|
648
|
+
// authored children move into .c-drawer__body; body attr fills if none.
|
|
585
649
|
const body = this.getAttribute("body");
|
|
586
|
-
const
|
|
587
|
-
|
|
588
|
-
|
|
650
|
+
const authored = Array.from(this.childNodes).filter((n) => {
|
|
651
|
+
if (n.nodeType === 1 && n.classList && (n.classList.contains("c-drawer__head") || n.classList.contains("c-drawer__body"))) return false;
|
|
652
|
+
if (n.nodeType === 3 && !n.textContent.trim()) return false;
|
|
653
|
+
return true;
|
|
654
|
+
});
|
|
655
|
+
if (authored.length) {
|
|
656
|
+
const el = this.ensure(".c-drawer__body", () => { const e = document.createElement("div"); e.className = "c-drawer__body"; return e; });
|
|
657
|
+
for (const n of authored) el.appendChild(n);
|
|
658
|
+
} else if (body) {
|
|
589
659
|
const el = this.ensure(".c-drawer__body", () => { const e = document.createElement("div"); e.className = "c-drawer__body"; return e; });
|
|
590
|
-
el
|
|
591
|
-
} else
|
|
592
|
-
b.
|
|
660
|
+
setHTML(el, sanitizeHtml(body));
|
|
661
|
+
} else {
|
|
662
|
+
const b = this.querySelector(".c-drawer__body");
|
|
663
|
+
if (b) b.remove();
|
|
593
664
|
}
|
|
594
665
|
}
|
|
595
666
|
enhance() {
|
|
596
667
|
if (this._wiredDrawer) return;
|
|
597
668
|
this._wiredDrawer = true;
|
|
669
|
+
this.returnValue = "";
|
|
598
670
|
onDispose(this, () => { if (this.hasAttribute("open")) modalContain(this, false); });
|
|
599
671
|
this._drawerLastFocus = null;
|
|
600
672
|
this.show = () => {
|
|
601
673
|
if (this.hasAttribute("open")) return;
|
|
602
674
|
this._drawerLastFocus = document.activeElement;
|
|
603
|
-
|
|
675
|
+
// Guard our own `open` write (see ContourDialog.show): re-entry doubles
|
|
676
|
+
// contour:open and leaks a modalContain depth.
|
|
677
|
+
this._declarativeOpen = true;
|
|
678
|
+
try { this.setAttribute("open", ""); } finally { this._declarativeOpen = false; }
|
|
604
679
|
this.setAttribute("aria-modal", "true");
|
|
605
680
|
this.classList.add("is-open");
|
|
606
681
|
modalContain(this, true);
|
|
@@ -609,8 +684,13 @@ class ContourDrawer extends ContourBase {
|
|
|
609
684
|
this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true }));
|
|
610
685
|
};
|
|
611
686
|
this.close = () => {
|
|
612
|
-
|
|
613
|
-
|
|
687
|
+
// `open` may already be gone via syncDeclarativeOpen; an engaged modal
|
|
688
|
+
// (aria-modal set) must still release its inert siblings.
|
|
689
|
+
if (!this.hasAttribute("open") && !this.hasAttribute("aria-modal")) return;
|
|
690
|
+
// Guard our own `open` removal (see ContourDialog.close): re-entry
|
|
691
|
+
// doubles the close event and the modalContain release.
|
|
692
|
+
this._declarativeOpen = true;
|
|
693
|
+
try { this.removeAttribute("open"); } finally { this._declarativeOpen = false; }
|
|
614
694
|
this.removeAttribute("aria-modal");
|
|
615
695
|
this.classList.remove("is-open");
|
|
616
696
|
modalContain(this, false);
|
|
@@ -641,12 +721,21 @@ class ContourDrawer extends ContourBase {
|
|
|
641
721
|
const dy = t.clientY - touchStartY;
|
|
642
722
|
if (Math.abs(dx) > 60 && Math.abs(dx) > Math.abs(dy) * 1.5) this.close();
|
|
643
723
|
}, { passive: true });
|
|
724
|
+
engageInitialModal(this);
|
|
644
725
|
}
|
|
645
726
|
}
|
|
646
727
|
define("contour-drawer", ContourDrawer);
|
|
647
728
|
class ContourSheet extends ContourBase {
|
|
648
|
-
static get observed() { return ["title", "body", "size"]; }
|
|
729
|
+
static get observed() { return ["title", "body", "size", "open"]; }
|
|
649
730
|
static get properties() { return { title: { attribute: "title" }, body: { attribute: "body" }, size: { attribute: "size" } }; }
|
|
731
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
732
|
+
if (name === "open") { syncDeclarativeOpen(this, name, newValue, this._wiredSheet); return; }
|
|
733
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
734
|
+
}
|
|
735
|
+
// Native-dialog parity (R20 T-32), same contract as contour-dialog.
|
|
736
|
+
showModal() { this.show(); }
|
|
737
|
+
get open() { return this.hasAttribute("open"); }
|
|
738
|
+
set open(v) { if (v) this.show(); else this.close(); }
|
|
650
739
|
render() {
|
|
651
740
|
this.classList.add("c-sheet");
|
|
652
741
|
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-sheet--")) this.classList.remove(c); });
|
|
@@ -665,39 +754,53 @@ class ContourSheet extends ContourBase {
|
|
|
665
754
|
const closeBtn = document.createElement("button");
|
|
666
755
|
closeBtn.className = "c-btn c-btn--icon c-btn--ghost c-sheet__close";
|
|
667
756
|
closeBtn.setAttribute("type", "button");
|
|
668
|
-
closeBtn.setAttribute("aria-label", "Close");
|
|
669
|
-
closeBtn
|
|
757
|
+
closeBtn.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
758
|
+
setHTML(closeBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-x" /></svg>');
|
|
670
759
|
head.appendChild(closeBtn);
|
|
671
760
|
}
|
|
672
761
|
const t = head.querySelector(".c-sheet__title");
|
|
673
|
-
if (t) { t.textContent = title; if (!t.id) t.id = "contour-sheet-title
|
|
762
|
+
if (t) { t.textContent = title; if (!t.id) t.id = contourId("contour-sheet-title"); this.setAttribute("aria-labelledby", t.id); }
|
|
674
763
|
if (head.parentNode !== this) this.prepend(head);
|
|
675
764
|
} else if (head) {
|
|
765
|
+
// The generated head is going away, so a label that points at its
|
|
766
|
+
// title would dangle. Drop it only when it names the title we remove.
|
|
767
|
+
const t = head.querySelector(".c-sheet__title");
|
|
768
|
+
if (t && t.id && this.getAttribute("aria-labelledby") === t.id) this.removeAttribute("aria-labelledby");
|
|
676
769
|
head.remove();
|
|
677
770
|
}
|
|
678
|
-
|
|
679
|
-
// cannot re-enter the render); the `.is-open` class is re-derived because
|
|
680
|
-
// the base restores the authored class on every render (see the drawer).
|
|
771
|
+
// open state re-derived each render (see drawer).
|
|
681
772
|
if (this.hasAttribute("open")) this.classList.add("is-open"); else this.classList.remove("is-open");
|
|
773
|
+
// authored children move into .c-sheet__body; body attr fills if none.
|
|
682
774
|
const body = this.getAttribute("body");
|
|
683
|
-
const
|
|
684
|
-
|
|
685
|
-
|
|
775
|
+
const authored = Array.from(this.childNodes).filter((n) => {
|
|
776
|
+
if (n.nodeType === 1 && n.classList && (n.classList.contains("c-sheet__head") || n.classList.contains("c-sheet__body"))) return false;
|
|
777
|
+
if (n.nodeType === 3 && !n.textContent.trim()) return false;
|
|
778
|
+
return true;
|
|
779
|
+
});
|
|
780
|
+
if (authored.length) {
|
|
781
|
+
const el = this.ensure(".c-sheet__body", () => { const e = document.createElement("div"); e.className = "c-sheet__body"; return e; });
|
|
782
|
+
for (const n of authored) el.appendChild(n);
|
|
783
|
+
} else if (body) {
|
|
686
784
|
const el = this.ensure(".c-sheet__body", () => { const e = document.createElement("div"); e.className = "c-sheet__body"; return e; });
|
|
687
|
-
el
|
|
688
|
-
} else
|
|
689
|
-
b.
|
|
785
|
+
setHTML(el, sanitizeHtml(body));
|
|
786
|
+
} else {
|
|
787
|
+
const b = this.querySelector(".c-sheet__body");
|
|
788
|
+
if (b) b.remove();
|
|
690
789
|
}
|
|
691
790
|
}
|
|
692
791
|
enhance() {
|
|
693
792
|
if (this._wiredSheet) return;
|
|
694
793
|
this._wiredSheet = true;
|
|
794
|
+
this.returnValue = "";
|
|
695
795
|
onDispose(this, () => { if (this.hasAttribute("open")) modalContain(this, false); });
|
|
696
796
|
this._sheetLastFocus = null;
|
|
697
797
|
this.show = () => {
|
|
698
798
|
if (this.hasAttribute("open")) return;
|
|
699
799
|
this._sheetLastFocus = document.activeElement;
|
|
700
|
-
|
|
800
|
+
// Guard our own `open` write (see ContourDialog.show): re-entry doubles
|
|
801
|
+
// contour:open and leaks a modalContain depth.
|
|
802
|
+
this._declarativeOpen = true;
|
|
803
|
+
try { this.setAttribute("open", ""); } finally { this._declarativeOpen = false; }
|
|
701
804
|
this.setAttribute("aria-modal", "true");
|
|
702
805
|
this.classList.add("is-open");
|
|
703
806
|
modalContain(this, true);
|
|
@@ -706,8 +809,13 @@ class ContourSheet extends ContourBase {
|
|
|
706
809
|
this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true }));
|
|
707
810
|
};
|
|
708
811
|
this.close = () => {
|
|
709
|
-
|
|
710
|
-
|
|
812
|
+
// `open` may already be gone via syncDeclarativeOpen; an engaged modal
|
|
813
|
+
// (aria-modal set) must still release its inert siblings.
|
|
814
|
+
if (!this.hasAttribute("open") && !this.hasAttribute("aria-modal")) return;
|
|
815
|
+
// Guard our own `open` removal (see ContourDialog.close): re-entry
|
|
816
|
+
// doubles the close event and the modalContain release.
|
|
817
|
+
this._declarativeOpen = true;
|
|
818
|
+
try { this.removeAttribute("open"); } finally { this._declarativeOpen = false; }
|
|
711
819
|
this.removeAttribute("aria-modal");
|
|
712
820
|
this.classList.remove("is-open");
|
|
713
821
|
modalContain(this, false);
|
|
@@ -738,12 +846,13 @@ class ContourSheet extends ContourBase {
|
|
|
738
846
|
const dx = t.clientX - touchStartX;
|
|
739
847
|
if (dy > 60 && Math.abs(dy) > Math.abs(dx) * 1.5) this.close();
|
|
740
848
|
}, { passive: true });
|
|
849
|
+
engageInitialModal(this);
|
|
741
850
|
}
|
|
742
851
|
}
|
|
743
852
|
define("contour-sheet", ContourSheet);
|
|
744
853
|
class ContourToast extends ContourBase {
|
|
745
|
-
static get observed() { return ["message", "variant", "duration"]; }
|
|
746
|
-
static get properties() { return { message: { attribute: "message" }, variant: { attribute: "variant" }, duration: { attribute: "duration", type: Number } }; }
|
|
854
|
+
static get observed() { return ["message", "variant", "duration", "action", "icon"]; }
|
|
855
|
+
static get properties() { return { message: { attribute: "message" }, variant: { attribute: "variant" }, duration: { attribute: "duration", type: Number }, action: { attribute: "action" } }; }
|
|
747
856
|
render() {
|
|
748
857
|
this.classList.add("c-toast");
|
|
749
858
|
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
@@ -756,17 +865,88 @@ class ContourToast extends ContourBase {
|
|
|
756
865
|
const variant = this.getAttribute("variant");
|
|
757
866
|
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-toast--")) this.classList.remove(c); });
|
|
758
867
|
if (variant) this.classList.add("c-toast--" + variant);
|
|
868
|
+
const iconAttr = this.getAttribute("icon");
|
|
869
|
+
const icon = iconAttr === "none" ? "" : (iconAttr || statusIcon(variant));
|
|
870
|
+
let ic = this.querySelector(".c-toast__icon");
|
|
871
|
+
if (icon) {
|
|
872
|
+
if (!ic) { ic = document.createElement("span"); ic.className = "c-toast__icon"; }
|
|
873
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
874
|
+
if (this.firstChild !== ic) this.prepend(ic);
|
|
875
|
+
} else if (ic) {
|
|
876
|
+
ic.remove();
|
|
877
|
+
}
|
|
878
|
+
// Action button (e.g. "Undo"): scaffold from `action` attribute.
|
|
879
|
+
const action = this.getAttribute("action");
|
|
880
|
+
let btn = this.querySelector(".c-toast__action");
|
|
881
|
+
if (action) {
|
|
882
|
+
if (!btn) { btn = document.createElement("button"); btn.className = "c-toast__action"; btn.type = "button"; this.appendChild(btn); }
|
|
883
|
+
btn.textContent = action;
|
|
884
|
+
} else if (btn) {
|
|
885
|
+
btn.remove();
|
|
886
|
+
}
|
|
887
|
+
// R31-65: a toast the reader cannot dismiss is a notification, not a
|
|
888
|
+
// message. The close action is part of the component at every duration.
|
|
889
|
+
let close = this.querySelector(".c-toast__close");
|
|
890
|
+
if (!close) {
|
|
891
|
+
close = document.createElement("button");
|
|
892
|
+
close.className = "c-toast__close";
|
|
893
|
+
close.type = "button";
|
|
894
|
+
close.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
895
|
+
close.textContent = "×";
|
|
896
|
+
this.appendChild(close);
|
|
897
|
+
}
|
|
759
898
|
}
|
|
760
899
|
enhance() {
|
|
761
900
|
if (this._wiredToast) return;
|
|
762
901
|
this._wiredToast = true;
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
if (
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
902
|
+
this.addEventListener("click", (e) => {
|
|
903
|
+
const close = e.target && e.target.closest ? e.target.closest(".c-toast__close") : null;
|
|
904
|
+
if (close) { e.preventDefault(); this._dismiss(); }
|
|
905
|
+
});
|
|
906
|
+
const pause = () => { clearTimeout(this._toastTimer); this._toastTimer = null; };
|
|
907
|
+
this.addEventListener("mouseenter", pause);
|
|
908
|
+
this.addEventListener("focusin", pause);
|
|
909
|
+
this.addEventListener("mouseleave", () => this._arm());
|
|
910
|
+
this.addEventListener("focusout", () => this._arm());
|
|
911
|
+
this._arm();
|
|
912
|
+
onDispose(this, () => clearTimeout(this._toastTimer));
|
|
913
|
+
}
|
|
914
|
+
_durationMs() {
|
|
915
|
+
const raw = (this._toastDuration != null) ? Number(this._toastDuration) : Number(this.duration);
|
|
916
|
+
if (raw === 0) return 0;
|
|
917
|
+
return raw > 0 ? raw : 4000;
|
|
918
|
+
}
|
|
919
|
+
_arm() {
|
|
920
|
+
clearTimeout(this._toastTimer);
|
|
921
|
+
this._toastTimer = null;
|
|
922
|
+
const ms = this._durationMs();
|
|
923
|
+
if (ms > 0) this._toastTimer = setTimeout(() => this._dismiss(), ms);
|
|
924
|
+
}
|
|
925
|
+
_dismiss() {
|
|
926
|
+
clearTimeout(this._toastTimer);
|
|
927
|
+
this._toastTimer = null;
|
|
928
|
+
this.setAttribute("hidden", "");
|
|
929
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
930
|
+
}
|
|
931
|
+
// Re-show a toast (e.g. from a trigger button): paint content directly
|
|
932
|
+
// (no observed-attribute writes, which would re-enter render), un-hide and
|
|
933
|
+
// restart the auto-dismiss timer. A bare toast hides rather than removing
|
|
934
|
+
// itself so a specimen — or a host that re-uses the node — can show it again.
|
|
935
|
+
show(message, opts) {
|
|
936
|
+
const msg = message != null ? String(message) : this.getAttribute("message");
|
|
937
|
+
const variant = (opts && opts.variant) || this.getAttribute("variant");
|
|
938
|
+
const action = (opts && opts.action) || this.getAttribute("action");
|
|
939
|
+
if (msg && !this.hasChildNodes()) this.textContent = msg;
|
|
940
|
+
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-toast--")) this.classList.remove(c); });
|
|
941
|
+
if (variant) this.classList.add("c-toast--" + variant);
|
|
942
|
+
let btn = this.querySelector(".c-toast__action");
|
|
943
|
+
if (action) {
|
|
944
|
+
if (!btn) { btn = document.createElement("button"); btn.className = "c-toast__action"; btn.type = "button"; this.appendChild(btn); }
|
|
945
|
+
btn.textContent = action;
|
|
946
|
+
} else if (btn) btn.remove();
|
|
947
|
+
if (opts && opts.duration != null) this._toastDuration = Number(opts.duration);
|
|
948
|
+
this.removeAttribute("hidden");
|
|
949
|
+
this._arm();
|
|
770
950
|
}
|
|
771
951
|
}
|
|
772
952
|
define("contour-toast", ContourToast);
|
|
@@ -792,6 +972,8 @@ class ContourExpandable extends ContourBase {
|
|
|
792
972
|
}
|
|
793
973
|
render() {
|
|
794
974
|
this.classList.add("c-expandable");
|
|
975
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
976
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("summary") || "Expandable");
|
|
795
977
|
const summary = this.getAttribute("summary");
|
|
796
978
|
if (summary) {
|
|
797
979
|
let captured = this.innerHTML.trim() ? this.innerHTML : (this._expandableContent || "");
|
|
@@ -804,15 +986,15 @@ class ContourExpandable extends ContourBase {
|
|
|
804
986
|
d.appendChild(summ);
|
|
805
987
|
const content = document.createElement("div");
|
|
806
988
|
content.className = "c-expandable__body";
|
|
807
|
-
content
|
|
989
|
+
setHTML(content, captured);
|
|
808
990
|
d.appendChild(content);
|
|
809
991
|
return d;
|
|
810
992
|
});
|
|
811
993
|
const summ = details.querySelector("summary");
|
|
812
994
|
if (summ) summ.textContent = summary;
|
|
813
995
|
const body = details.querySelector(".c-expandable__body");
|
|
814
|
-
if (body) body
|
|
815
|
-
if (details.parentNode !== this) { this
|
|
996
|
+
if (body) setHTML(body, captured);
|
|
997
|
+
if (details.parentNode !== this) { setHTML(this, ""); this.appendChild(details); }
|
|
816
998
|
} else {
|
|
817
999
|
const details = this.querySelector("details");
|
|
818
1000
|
if (details) details.remove();
|
|
@@ -835,6 +1017,7 @@ class ContourToastHost extends ContourBase {
|
|
|
835
1017
|
render() {
|
|
836
1018
|
this.classList.add("c-toast-host");
|
|
837
1019
|
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
1020
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "toast-host", "Toast host"));
|
|
838
1021
|
if (!this.hasAttribute("aria-live")) this.setAttribute("aria-live", "polite");
|
|
839
1022
|
if (!this.hasAttribute("aria-atomic")) this.setAttribute("aria-atomic", "true");
|
|
840
1023
|
}
|
|
@@ -851,6 +1034,13 @@ class ContourToastHost extends ContourBase {
|
|
|
851
1034
|
toast.setAttribute("aria-live", "polite");
|
|
852
1035
|
toast.setAttribute("aria-atomic", "true");
|
|
853
1036
|
if (opts.variant) toast.classList.add("c-toast--" + opts.variant);
|
|
1037
|
+
const icon = statusIcon(opts.variant);
|
|
1038
|
+
if (icon) {
|
|
1039
|
+
const ic = document.createElement("span");
|
|
1040
|
+
ic.className = "c-toast__icon";
|
|
1041
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + icon + '" /></svg>');
|
|
1042
|
+
toast.appendChild(ic);
|
|
1043
|
+
}
|
|
854
1044
|
toast.dataset.message = message == null ? "" : String(message);
|
|
855
1045
|
const text = document.createElement("span");
|
|
856
1046
|
text.className = "c-toast__text";
|
|
@@ -871,6 +1061,23 @@ class ContourToastHost extends ContourBase {
|
|
|
871
1061
|
});
|
|
872
1062
|
toast.appendChild(btn);
|
|
873
1063
|
}
|
|
1064
|
+
const close = document.createElement("button");
|
|
1065
|
+
close.type = "button";
|
|
1066
|
+
close.className = "c-toast__close";
|
|
1067
|
+
close.setAttribute("aria-label", labelText(this, "close", "Close"));
|
|
1068
|
+
close.textContent = "×";
|
|
1069
|
+
toast.appendChild(close);
|
|
1070
|
+
close.addEventListener("click", (e) => { e.stopPropagation(); dismiss(toast); });
|
|
1071
|
+
toast._arm = () => {
|
|
1072
|
+
clearTimeout(toast._timer);
|
|
1073
|
+
const d = opts.duration;
|
|
1074
|
+
const ms = d === 0 ? 0 : (d > 0 ? d : 4000);
|
|
1075
|
+
if (ms > 0) toast._timer = setTimeout(() => dismiss(toast), ms);
|
|
1076
|
+
};
|
|
1077
|
+
toast.addEventListener("mouseenter", () => clearTimeout(toast._timer));
|
|
1078
|
+
toast.addEventListener("focusin", () => clearTimeout(toast._timer));
|
|
1079
|
+
toast.addEventListener("mouseleave", toast._arm);
|
|
1080
|
+
toast.addEventListener("focusout", toast._arm);
|
|
874
1081
|
return toast;
|
|
875
1082
|
};
|
|
876
1083
|
const dismiss = (toast) => {
|
|
@@ -882,19 +1089,16 @@ class ContourToastHost extends ContourBase {
|
|
|
882
1089
|
pump();
|
|
883
1090
|
};
|
|
884
1091
|
const pump = () => {
|
|
885
|
-
|
|
886
|
-
//
|
|
1092
|
+
// R31-65: stack independent messages; each toast owns its timer and
|
|
1093
|
+
// close button. A host-level queue still dedups identical messages.
|
|
887
1094
|
while (this._toastQueue.length) {
|
|
888
1095
|
const next = this._toastQueue.shift();
|
|
889
1096
|
if (next._deduped) continue;
|
|
890
1097
|
const toast = buildToast(next.message, next.opts);
|
|
891
1098
|
this._toastActive = toast;
|
|
892
1099
|
this.appendChild(toast);
|
|
893
|
-
|
|
894
|
-
toast._timer = setTimeout(() => dismiss(toast), ms);
|
|
895
|
-
return;
|
|
1100
|
+
toast._arm();
|
|
896
1101
|
}
|
|
897
|
-
this._toastActive = null;
|
|
898
1102
|
};
|
|
899
1103
|
this.show = (message, opts) => {
|
|
900
1104
|
opts = opts || {};
|
|
@@ -903,7 +1107,7 @@ class ContourToastHost extends ContourBase {
|
|
|
903
1107
|
const active = this._toastActive;
|
|
904
1108
|
if (active && active.dataset && active.dataset.message === key && key !== "") {
|
|
905
1109
|
if (active._timer) { clearTimeout(active._timer); }
|
|
906
|
-
const ms = (opts.duration && opts.duration > 0) ? opts.duration :
|
|
1110
|
+
const ms = (opts.duration && opts.duration > 0) ? opts.duration : 4000;
|
|
907
1111
|
active._timer = setTimeout(() => dismiss(active), ms);
|
|
908
1112
|
return active;
|
|
909
1113
|
}
|