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,1343 @@
|
|
|
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
|
+
class ContourPressableFull extends ContourBase {
|
|
611
|
+
static get observed() { return ["disabled", "label"]; }
|
|
612
|
+
static get properties() { return { disabled: { attribute: "disabled", type: Boolean } }; }
|
|
613
|
+
render() {
|
|
614
|
+
this.classList.add("c-pressable");
|
|
615
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "button");
|
|
616
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Pressable");
|
|
617
|
+
if (this.hasAttribute("disabled")) {
|
|
618
|
+
this.setAttribute("aria-disabled", "true");
|
|
619
|
+
this.setAttribute("tabindex", "-1");
|
|
620
|
+
} else {
|
|
621
|
+
this.removeAttribute("aria-disabled");
|
|
622
|
+
if (!this.hasAttribute("tabindex") || this.getAttribute("tabindex") === "-1") this.setAttribute("tabindex", "0");
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
enhance() {
|
|
626
|
+
if (this._wiredPressable) return;
|
|
627
|
+
this._wiredPressable = true;
|
|
628
|
+
// disabled pressable must not activate (capture phase fires first).
|
|
629
|
+
const isDisabled = () => this.hasAttribute("disabled") || this.getAttribute("aria-disabled") === "true";
|
|
630
|
+
this.addEventListener("click", (e) => {
|
|
631
|
+
if (isDisabled()) { e.preventDefault(); e.stopImmediatePropagation(); }
|
|
632
|
+
}, true);
|
|
633
|
+
this.addEventListener("keydown", (e) => {
|
|
634
|
+
if (isDisabled()) { e.preventDefault(); e.stopImmediatePropagation(); return; }
|
|
635
|
+
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); this.click(); this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true })); }
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
define("contour-pressable", ContourPressableFull);
|
|
640
|
+
class ContourResizeHandleFull extends ContourBase {
|
|
641
|
+
render() {
|
|
642
|
+
this.classList.add("c-resize-handle");
|
|
643
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "separator");
|
|
644
|
+
if (!this.hasAttribute("aria-valuenow")) this.setAttribute("aria-valuenow", "0");
|
|
645
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "resize-handle", "Resize handle"));
|
|
646
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
647
|
+
if (!this.hasAttribute("aria-orientation")) this.setAttribute("aria-orientation", "horizontal");
|
|
648
|
+
}
|
|
649
|
+
enhance() {
|
|
650
|
+
if (this._wiredResizeHandle) return;
|
|
651
|
+
this._wiredResizeHandle = true;
|
|
652
|
+
// Keyboard resize: arrows nudge 5%, Home/End to min/max; dispatches contour:resize.
|
|
653
|
+
this.addEventListener("keydown", (e) => {
|
|
654
|
+
// Home/End send finite delta (±Infinity serialises to null).
|
|
655
|
+
const cur = Number(this.getAttribute("aria-valuenow")) || 0;
|
|
656
|
+
let delta = 0;
|
|
657
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowDown") delta = -5;
|
|
658
|
+
else if (e.key === "ArrowRight" || e.key === "ArrowUp") delta = 5;
|
|
659
|
+
else if (e.key === "Home") delta = -cur; // jump to min (0)
|
|
660
|
+
else if (e.key === "End") delta = 100 - cur; // jump to max (100)
|
|
661
|
+
else return;
|
|
662
|
+
e.preventDefault();
|
|
663
|
+
const next = Math.min(100, Math.max(0, cur + delta));
|
|
664
|
+
this.setAttribute("aria-valuenow", String(next));
|
|
665
|
+
this.dispatchEvent(new CustomEvent("contour:resize", { bubbles: true, composed: true, detail: { value: next, delta } }));
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
define("contour-resize-handle", ContourResizeHandleFull);
|
|
670
|
+
class ContourSearchTriggerFull extends ContourBase {
|
|
671
|
+
static get observed() { return ["label", "shortcut"]; }
|
|
672
|
+
static get properties() { return { label: { attribute: "label" }, shortcut: { attribute: "shortcut" } }; }
|
|
673
|
+
render() {
|
|
674
|
+
this.classList.add("c-search-trigger");
|
|
675
|
+
const label = this.getAttribute("label") || "Search";
|
|
676
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", label);
|
|
677
|
+
const span = this.ensure(".c-search-trigger__text", () => { const el = document.createElement("span"); el.className = "c-search-trigger__text"; return el; });
|
|
678
|
+
span.className = "c-search-trigger__text";
|
|
679
|
+
if (!span.textContent.trim() || span.textContent.trim() !== label) span.textContent = label;
|
|
680
|
+
const kbd = this.ensure("kbd.c-search-trigger__kbd", () => { const el = document.createElement("kbd"); el.className = "c-search-trigger__kbd"; return el; });
|
|
681
|
+
kbd.className = "c-search-trigger__kbd";
|
|
682
|
+
kbd.textContent = this.getAttribute("shortcut") || "⌘K";
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
define("contour-search-trigger", ContourSearchTriggerFull);
|
|
686
|
+
class ContourShortcutListFull extends ContourBase {
|
|
687
|
+
static get observed() { return ["title"]; }
|
|
688
|
+
static get properties() { return { title: { attribute: "title" } }; }
|
|
689
|
+
render() {
|
|
690
|
+
this.classList.add("c-shortcut-list");
|
|
691
|
+
this.setAttribute("role", "list");
|
|
692
|
+
const title = this.getAttribute("title");
|
|
693
|
+
if (title) {
|
|
694
|
+
const t = this.ensure(".c-shortcut-list__title", () => { const el = document.createElement("div"); el.className = "c-shortcut-list__title"; return el; });
|
|
695
|
+
t.textContent = title;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
define("contour-shortcut-list", ContourShortcutListFull);
|
|
700
|
+
class ContourShortcutRowFull extends ContourBase {
|
|
701
|
+
static get observed() { return ["desc", "key"]; }
|
|
702
|
+
static get properties() { return { desc: { attribute: "desc" }, key: { attribute: "key" } }; }
|
|
703
|
+
render() {
|
|
704
|
+
this.classList.add("c-shortcut-row");
|
|
705
|
+
// rows get role=listitem so list > listitem is valid.
|
|
706
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "listitem");
|
|
707
|
+
const key = this.getAttribute("key");
|
|
708
|
+
const desc = this.getAttribute("desc");
|
|
709
|
+
if (key) {
|
|
710
|
+
const k = this.ensure(".c-shortcut-row__keys", () => { const el = document.createElement("kbd"); el.className = "c-shortcut-row__keys"; return el; });
|
|
711
|
+
k.className = "c-shortcut-row__keys";
|
|
712
|
+
k.textContent = key;
|
|
713
|
+
} else {
|
|
714
|
+
const k = this.querySelector(".c-shortcut-row__keys");
|
|
715
|
+
if (k) k.remove();
|
|
716
|
+
}
|
|
717
|
+
if (desc) {
|
|
718
|
+
const s = this.ensure(".c-shortcut-row__label", () => { const el = document.createElement("span"); el.className = "c-shortcut-row__label"; return el; });
|
|
719
|
+
s.className = "c-shortcut-row__label";
|
|
720
|
+
s.textContent = desc;
|
|
721
|
+
} else {
|
|
722
|
+
const s = this.querySelector(".c-shortcut-row__label");
|
|
723
|
+
if (s) s.remove();
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
define("contour-shortcut-row", ContourShortcutRowFull);
|
|
728
|
+
class ContourShortcutPanelFull extends ContourBase {
|
|
729
|
+
static get observed() { return ["title"]; }
|
|
730
|
+
static get properties() { return { title: { attribute: "title" } }; }
|
|
731
|
+
render() {
|
|
732
|
+
this.classList.add("c-shortcut-panel");
|
|
733
|
+
const title = this.getAttribute("title");
|
|
734
|
+
if (title) {
|
|
735
|
+
const t = this.ensure(".c-shortcut-panel__title", () => { const el = document.createElement("div"); el.className = "c-shortcut-panel__title"; return el; });
|
|
736
|
+
t.textContent = title;
|
|
737
|
+
} else {
|
|
738
|
+
const t = this.querySelector(".c-shortcut-panel__title");
|
|
739
|
+
if (t) t.remove();
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
define("contour-shortcut-panel", ContourShortcutPanelFull);
|
|
744
|
+
class ContourShortcutOverlayFull extends ContourBase {
|
|
745
|
+
static get observed() { return ["title", "open", "keybind"]; }
|
|
746
|
+
static get properties() { return { title: { attribute: "title" }, open: { attribute: "open", type: Boolean }, keybind: { attribute: "keybind" } }; }
|
|
747
|
+
render() {
|
|
748
|
+
this.classList.add("c-shortcut-overlay");
|
|
749
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
|
|
750
|
+
if (!this.hasAttribute("aria-modal")) this.setAttribute("aria-modal", "true");
|
|
751
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Keyboard shortcuts");
|
|
752
|
+
const title = this.getAttribute("title");
|
|
753
|
+
if (title) {
|
|
754
|
+
const t = this.ensure(".c-shortcut-overlay__title", () => { const el = document.createElement("div"); el.className = "c-shortcut-overlay__title"; return el; });
|
|
755
|
+
t.textContent = title;
|
|
756
|
+
}
|
|
757
|
+
if (this.hasAttribute("open")) this.removeAttribute("hidden");
|
|
758
|
+
else if (!this.hasAttribute("hidden")) this.setAttribute("hidden", "");
|
|
759
|
+
}
|
|
760
|
+
show() {
|
|
761
|
+
// R31-73: re-entry (a keydown plus a click) must not stack the modal lock.
|
|
762
|
+
if (this.hasAttribute("open")) return;
|
|
763
|
+
// capture opener, focus first focusable element.
|
|
764
|
+
this._opener = document.activeElement;
|
|
765
|
+
this.setAttribute("open", "");
|
|
766
|
+
this.removeAttribute("hidden");
|
|
767
|
+
modalContain(this, true);
|
|
768
|
+
this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true }));
|
|
769
|
+
const first = this.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
770
|
+
if (first) first.focus();
|
|
771
|
+
}
|
|
772
|
+
hide() {
|
|
773
|
+
if (!this.hasAttribute("open")) return;
|
|
774
|
+
this.removeAttribute("open");
|
|
775
|
+
this.setAttribute("hidden", "");
|
|
776
|
+
modalContain(this, false);
|
|
777
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
778
|
+
// restore focus to the element that opened the overlay.
|
|
779
|
+
if (this._opener && typeof this._opener.focus === "function") this._opener.focus();
|
|
780
|
+
this._opener = null;
|
|
781
|
+
}
|
|
782
|
+
toggle() { if (this.hasAttribute("open")) this.hide(); else this.show(); }
|
|
783
|
+
enhance() {
|
|
784
|
+
if (this._wiredShortcutOverlay) return;
|
|
785
|
+
this._wiredShortcutOverlay = true;
|
|
786
|
+
// `keybind` opts into global "?" toggle: absent=off, bare=on, "false"=off. Escape closes while open regardless.
|
|
787
|
+
const keyHandler = (e) => {
|
|
788
|
+
if (e.key === "?" && flagOn(this, "keybind") && !e.metaKey && !e.ctrlKey && !e.altKey) {
|
|
789
|
+
const tag = (e.target && e.target.tagName) || "";
|
|
790
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || (e.target && e.target.isContentEditable)) return;
|
|
791
|
+
e.preventDefault();
|
|
792
|
+
this.toggle();
|
|
793
|
+
} else if (e.key === "Escape" && this.hasAttribute("open")) {
|
|
794
|
+
this.hide();
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
document.addEventListener("keydown", keyHandler);
|
|
798
|
+
onDispose(this, () => document.removeEventListener("keydown", keyHandler));
|
|
799
|
+
this.addEventListener("click", (e) => {
|
|
800
|
+
if (e.target === this) this.hide();
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
define("contour-shortcut-overlay", ContourShortcutOverlayFull);
|
|
805
|
+
class ContourRowActionFull extends ContourBase {
|
|
806
|
+
static get observed() { return ["label", "disabled"]; }
|
|
807
|
+
static get properties() { return { label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean } }; }
|
|
808
|
+
render() {
|
|
809
|
+
this.classList.add("c-row-action");
|
|
810
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "button");
|
|
811
|
+
if (this.hasAttribute("disabled")) {
|
|
812
|
+
this.setAttribute("aria-disabled", "true");
|
|
813
|
+
this.setAttribute("tabindex", "-1");
|
|
814
|
+
} else {
|
|
815
|
+
this.removeAttribute("aria-disabled");
|
|
816
|
+
if (!this.hasAttribute("tabindex") || this.getAttribute("tabindex") === "-1") this.setAttribute("tabindex", "0");
|
|
817
|
+
}
|
|
818
|
+
const label = this.getAttribute("label");
|
|
819
|
+
if (label && !this.hasChildNodes()) this.textContent = label;
|
|
820
|
+
if (label && !this.hasAttribute("aria-label")) this.setAttribute("aria-label", label);
|
|
821
|
+
}
|
|
822
|
+
enhance() {
|
|
823
|
+
if (this._wiredRowAction) return;
|
|
824
|
+
this._wiredRowAction = true;
|
|
825
|
+
// disabled activation guard (same pattern as c-btn).
|
|
826
|
+
const isDisabled = () => this.hasAttribute("disabled") || this.getAttribute("aria-disabled") === "true";
|
|
827
|
+
this.addEventListener("click", (e) => {
|
|
828
|
+
if (isDisabled()) { e.preventDefault(); e.stopImmediatePropagation(); }
|
|
829
|
+
}, true);
|
|
830
|
+
this.addEventListener("keydown", (e) => {
|
|
831
|
+
if (isDisabled()) { e.preventDefault(); e.stopImmediatePropagation(); return; }
|
|
832
|
+
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); this.click(); this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true })); }
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
define("contour-row-action", ContourRowActionFull);
|
|
837
|
+
class ContourSegmented extends ContourBase {
|
|
838
|
+
static get observed() { return ["options", "items", "selected", "label", "value"]; }
|
|
839
|
+
static get properties() { return { options: { attribute: "options" }, items: { attribute: "items" }, selected: { attribute: "selected" }, label: { attribute: "label" }, value: { attribute: "value" } }; }
|
|
840
|
+
render() {
|
|
841
|
+
this.classList.add("c-segmented");
|
|
842
|
+
const options = this.getAttribute("options") || this.getAttribute("items");
|
|
843
|
+
if (options) {
|
|
844
|
+
let parsed = null;
|
|
845
|
+
try { parsed = JSON.parse(options); } catch (e) { parsed = null; }
|
|
846
|
+
if (Array.isArray(parsed)) {
|
|
847
|
+
Array.from(this.querySelectorAll("button.c-segmented__option")).forEach((n) => n.remove());
|
|
848
|
+
const selected = this.getAttribute("selected") || this.getAttribute("value");
|
|
849
|
+
parsed.forEach((opt, i) => {
|
|
850
|
+
const label = typeof opt === "string" ? opt : (opt.label || opt.value || "");
|
|
851
|
+
const val = typeof opt === "string" ? opt : (opt.value || opt.label || "");
|
|
852
|
+
const btn = document.createElement("button");
|
|
853
|
+
btn.className = "c-segmented__option";
|
|
854
|
+
btn.type = "button";
|
|
855
|
+
btn.textContent = label;
|
|
856
|
+
btn.dataset.value = val;
|
|
857
|
+
if (selected !== null && String(val) === String(selected)) btn.setAttribute("aria-pressed", "true");
|
|
858
|
+
else if (selected === null && i === 0) btn.setAttribute("aria-pressed", "true");
|
|
859
|
+
else btn.setAttribute("aria-pressed", "false");
|
|
860
|
+
this.appendChild(btn);
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
enhance() {
|
|
866
|
+
wireSegmented(this);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
define("contour-segmented", ContourSegmented);
|
|
870
|
+
class ContourDraggable extends ContourBase {
|
|
871
|
+
render() {
|
|
872
|
+
this.classList.add("c-draggable");
|
|
873
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "button");
|
|
874
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
875
|
+
if (!this.hasAttribute("draggable")) this.setAttribute("draggable", "true");
|
|
876
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Draggable item");
|
|
877
|
+
}
|
|
878
|
+
// _dragValue: value || label || textContent. Same detail for dragstart and drop.
|
|
879
|
+
_dragValue() {
|
|
880
|
+
return this.getAttribute("value") || this.getAttribute("label") || (this.textContent || "").trim() || "draggable";
|
|
881
|
+
}
|
|
882
|
+
enhance() {
|
|
883
|
+
if (this._wiredDraggable) return;
|
|
884
|
+
this._wiredDraggable = true;
|
|
885
|
+
// Native DnD (BY-26): dragstart writes text/plain payload, adds dragging state, dispatches contour:dragstart.
|
|
886
|
+
this.addEventListener("dragstart", (e) => {
|
|
887
|
+
if (!e.dataTransfer) return;
|
|
888
|
+
const value = this._dragValue();
|
|
889
|
+
try { e.dataTransfer.effectAllowed = "move"; } catch (err) { /* synthetic drag: read-only */ }
|
|
890
|
+
e.dataTransfer.setData("text/plain", value);
|
|
891
|
+
this.classList.add("c-draggable--dragging");
|
|
892
|
+
this.dispatchEvent(new CustomEvent("contour:dragstart", { bubbles: true, composed: true, detail: { value } }));
|
|
893
|
+
});
|
|
894
|
+
this.addEventListener("dragend", () => {
|
|
895
|
+
this.classList.remove("c-draggable--dragging");
|
|
896
|
+
this.dispatchEvent(new CustomEvent("contour:dragend", { bubbles: true, composed: true, detail: { value: this._dragValue() } }));
|
|
897
|
+
});
|
|
898
|
+
// Keyboard move: ArrowUp/Down dispatches contour:move (DnD has no keyboard story).
|
|
899
|
+
this.addEventListener("keydown", (e) => {
|
|
900
|
+
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true })); return; }
|
|
901
|
+
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
|
902
|
+
e.preventDefault();
|
|
903
|
+
this.dispatchEvent(new CustomEvent("contour:move", { bubbles: true, composed: true, detail: { direction: e.key === "ArrowUp" ? "up" : "down" } }));
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
define("contour-draggable", ContourDraggable);
|
|
909
|
+
class ContourDragHandle extends ContourBase {
|
|
910
|
+
render() {
|
|
911
|
+
this.classList.add("c-drag-handle");
|
|
912
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "separator");
|
|
913
|
+
// Focusable separator = range widget; needs value range for AT.
|
|
914
|
+
const min = this.getAttribute("min") || "0";
|
|
915
|
+
const max = this.getAttribute("max") || "100";
|
|
916
|
+
if (!this.hasAttribute("aria-valuenow")) this.setAttribute("aria-valuenow", min);
|
|
917
|
+
if (!this.hasAttribute("aria-valuemin")) this.setAttribute("aria-valuemin", min);
|
|
918
|
+
if (!this.hasAttribute("aria-valuemax")) this.setAttribute("aria-valuemax", max);
|
|
919
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
920
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Drag handle");
|
|
921
|
+
if (!this.hasAttribute("aria-orientation")) this.setAttribute("aria-orientation", "horizontal");
|
|
922
|
+
// Name the pane the handle resizes, when the author says which.
|
|
923
|
+
const controls = this.getAttribute("controls");
|
|
924
|
+
if (controls && !this.hasAttribute("aria-controls")) this.setAttribute("aria-controls", controls);
|
|
925
|
+
// grip glyph is the signifier; base rule gives size/cursor/ring.
|
|
926
|
+
const grip = this.ensure(".c-drag-handle__grip", () => {
|
|
927
|
+
const s = document.createElement("span");
|
|
928
|
+
s.className = "c-drag-handle__grip";
|
|
929
|
+
s.setAttribute("aria-hidden", "true");
|
|
930
|
+
setHTML(s, '<svg viewBox="0 0 24 24"><use href="#i-drag" /></svg>');
|
|
931
|
+
return s;
|
|
932
|
+
});
|
|
933
|
+
if (grip.parentNode !== this) this.appendChild(grip);
|
|
934
|
+
}
|
|
935
|
+
enhance() {
|
|
936
|
+
if (this._wiredDragHandle) return;
|
|
937
|
+
this._wiredDragHandle = true;
|
|
938
|
+
this.addEventListener("keydown", (e) => {
|
|
939
|
+
const now = Number(this.getAttribute("aria-valuenow") || 0);
|
|
940
|
+
const min = Number(this.getAttribute("aria-valuemin") || 0);
|
|
941
|
+
const max = Number(this.getAttribute("aria-valuemax") || 100);
|
|
942
|
+
let delta = 0;
|
|
943
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowDown") delta = -1;
|
|
944
|
+
else if (e.key === "ArrowRight" || e.key === "ArrowUp") delta = 1;
|
|
945
|
+
// Home/End: finite delta to min/max (±Infinity serialises to null).
|
|
946
|
+
else if (e.key === "Home") delta = min - now;
|
|
947
|
+
else if (e.key === "End") delta = max - now;
|
|
948
|
+
else return;
|
|
949
|
+
e.preventDefault();
|
|
950
|
+
this.dispatchEvent(new CustomEvent("contour:drag", { bubbles: true, composed: true, detail: { key: e.key, delta, value: now } }));
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
define("contour-drag-handle", ContourDragHandle);
|
|
955
|
+
class ContourDropIndicator extends ContourBase {
|
|
956
|
+
static get observed() { return ["label", "open"]; }
|
|
957
|
+
static get properties() { return { label: { attribute: "label" }, open: { attribute: "open", type: Boolean } }; }
|
|
958
|
+
render() {
|
|
959
|
+
this.classList.add("c-drop-indicator");
|
|
960
|
+
// Visible only while `open` is set (old code stamped --visible always on).
|
|
961
|
+
this.classList.toggle("c-drop-indicator--visible", this.hasAttribute("open"));
|
|
962
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "presentation");
|
|
963
|
+
// presentation role strips accessible name (axe prohibits on role=presentation).
|
|
964
|
+
if (this.getAttribute("role") === "presentation") {
|
|
965
|
+
this.removeAttribute("aria-label");
|
|
966
|
+
this.removeAttribute("aria-labelledby");
|
|
967
|
+
}
|
|
968
|
+
Array.from(this.childNodes).forEach((n) => { if (n.nodeType === Node.TEXT_NODE) n.remove(); else if (n.nodeType === Node.ELEMENT_NODE && n.tagName === "SPAN") n.remove(); });
|
|
969
|
+
const label = this.getAttribute("label");
|
|
970
|
+
if (label) {
|
|
971
|
+
const t = this.ensure(".c-drop-indicator__label", () => { const el = document.createElement("span"); el.className = "c-drop-indicator__label"; return el; });
|
|
972
|
+
t.textContent = label;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
define("contour-drop-indicator", ContourDropIndicator);
|
|
977
|
+
class ContourDropZone extends ContourBase {
|
|
978
|
+
static get observed() { return ["label"]; }
|
|
979
|
+
static get properties() { return { label: { attribute: "label" } }; }
|
|
980
|
+
render() {
|
|
981
|
+
this.classList.add("c-drop-zone");
|
|
982
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
983
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Drop zone");
|
|
984
|
+
Array.from(this.childNodes).forEach((n) => { if (n.nodeType === Node.TEXT_NODE) n.remove(); else if (n.nodeType === Node.ELEMENT_NODE && n.tagName === "SPAN") n.remove(); });
|
|
985
|
+
const label = this.getAttribute("label");
|
|
986
|
+
if (label) {
|
|
987
|
+
const t = this.ensure(".c-drop-zone__label", () => { const el = document.createElement("p"); el.className = "c-drop-zone__label"; return el; });
|
|
988
|
+
// R31-150: an upload glyph makes the drop zone scannable.
|
|
989
|
+
setHTML(t, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-upload" /></svg>');
|
|
990
|
+
t.appendChild(document.createTextNode(" " + label));
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
enhance() {
|
|
994
|
+
if (this._wiredDropZone) return;
|
|
995
|
+
this._wiredDropZone = true;
|
|
996
|
+
// Native drop target (BY-26, host-delegated): dragover allows text/plain (--active), refuses others (--reject).
|
|
997
|
+
const accepts = (e) => e.dataTransfer && Array.from(e.dataTransfer.types).includes("text/plain");
|
|
998
|
+
const clear = () => { this.classList.remove("c-drop-zone--active", "c-drop-zone--reject"); };
|
|
999
|
+
this.addEventListener("dragenter", (e) => {
|
|
1000
|
+
if (!e.dataTransfer) return;
|
|
1001
|
+
this.classList.toggle("c-drop-zone--reject", !accepts(e));
|
|
1002
|
+
if (accepts(e)) { e.preventDefault(); this.classList.add("c-drop-zone--active"); }
|
|
1003
|
+
});
|
|
1004
|
+
this.addEventListener("dragover", (e) => {
|
|
1005
|
+
if (!e.dataTransfer) return;
|
|
1006
|
+
this.classList.toggle("c-drop-zone--reject", !accepts(e));
|
|
1007
|
+
if (accepts(e)) { e.preventDefault(); this.classList.add("c-drop-zone--active"); }
|
|
1008
|
+
});
|
|
1009
|
+
this.addEventListener("dragleave", clear);
|
|
1010
|
+
this.addEventListener("drop", (e) => {
|
|
1011
|
+
if (!accepts(e)) return;
|
|
1012
|
+
e.preventDefault();
|
|
1013
|
+
clear();
|
|
1014
|
+
const value = e.dataTransfer.getData("text/plain") || "";
|
|
1015
|
+
this.dispatchEvent(new CustomEvent("contour:drop", { bubbles: true, composed: true, detail: { value, label: this.getAttribute("label") } }));
|
|
1016
|
+
});
|
|
1017
|
+
// Keyboard path on the draggable (contour:move); target only needs pointer role.
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
define("contour-drop-zone", ContourDropZone);
|
|
1021
|
+
class ContourResizable extends ContourBase {
|
|
1022
|
+
static get observed() { return ["direction", "value"]; }
|
|
1023
|
+
static get properties() { return { direction: { attribute: "direction" }, value: { attribute: "value" } }; }
|
|
1024
|
+
render() {
|
|
1025
|
+
this.classList.add("c-resizable");
|
|
1026
|
+
this.classList.remove("c-resizable--vertical", "c-resizable--horizontal");
|
|
1027
|
+
const vertical = this.getAttribute("direction") === "vertical";
|
|
1028
|
+
this.classList.add(vertical ? "c-resizable--vertical" : "c-resizable--horizontal");
|
|
1029
|
+
if (!this.querySelector(".c-resizable__pane")) {
|
|
1030
|
+
// Structural panes only; author fills them (no invented Pane A/B).
|
|
1031
|
+
const p1 = document.createElement("div");
|
|
1032
|
+
p1.className = "c-resizable__pane";
|
|
1033
|
+
const handle = document.createElement("div");
|
|
1034
|
+
handle.className = "c-resize-handle";
|
|
1035
|
+
handle.setAttribute("tabindex", "0");
|
|
1036
|
+
handle.setAttribute("role", "separator");
|
|
1037
|
+
handle.setAttribute("aria-valuenow", "0");
|
|
1038
|
+
const p2 = document.createElement("div");
|
|
1039
|
+
p2.className = "c-resizable__pane";
|
|
1040
|
+
this.appendChild(p1);
|
|
1041
|
+
this.appendChild(handle);
|
|
1042
|
+
this.appendChild(p2);
|
|
1043
|
+
}
|
|
1044
|
+
const v = this._splitValue || this.getAttribute("value");
|
|
1045
|
+
const handle = this.querySelector(".c-resize-handle");
|
|
1046
|
+
if (handle) {
|
|
1047
|
+
// R31-66: the first paint must already be a named separator, not an
|
|
1048
|
+
// unnamed 0-valued handle that only becomes valid after a drag.
|
|
1049
|
+
handle.setAttribute("role", "separator");
|
|
1050
|
+
handle.setAttribute("tabindex", "0");
|
|
1051
|
+
handle.setAttribute("aria-valuenow", String(Math.round(parseFloat(v) || 50)));
|
|
1052
|
+
handle.setAttribute("aria-valuemin", "10");
|
|
1053
|
+
handle.setAttribute("aria-valuemax", "90");
|
|
1054
|
+
handle.setAttribute("aria-orientation", vertical ? "horizontal" : "vertical");
|
|
1055
|
+
handle.setAttribute("aria-label", labelText(this, "resize-panels", "Resize panels"));
|
|
1056
|
+
}
|
|
1057
|
+
if (v) {
|
|
1058
|
+
const p1 = this.querySelector(".c-resizable__pane");
|
|
1059
|
+
if (p1) p1.style.flex = `0 0 ${v}%`;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
enhance() {
|
|
1063
|
+
if (this._wiredResizable) return;
|
|
1064
|
+
this._wiredResizable = true;
|
|
1065
|
+
// Pointer resize (BY-27): host-delegated listeners; first pane flex-basis = drag value. One split writer for pointer+keyboard.
|
|
1066
|
+
const applySplit = (pct) => {
|
|
1067
|
+
const p1 = this.querySelector(".c-resizable__pane");
|
|
1068
|
+
if (p1) p1.style.flex = `0 0 ${pct}%`;
|
|
1069
|
+
this._splitValue = String(pct);
|
|
1070
|
+
// sync ARIA on handle so readers announce split position.
|
|
1071
|
+
const handle = this.querySelector(".c-resize-handle");
|
|
1072
|
+
if (handle) {
|
|
1073
|
+
const vertical = this.classList.contains("c-resizable--vertical");
|
|
1074
|
+
handle.setAttribute("role", "separator");
|
|
1075
|
+
handle.setAttribute("aria-valuenow", String(pct));
|
|
1076
|
+
handle.setAttribute("aria-valuemin", "10");
|
|
1077
|
+
handle.setAttribute("aria-valuemax", "90");
|
|
1078
|
+
handle.setAttribute("aria-orientation", vertical ? "horizontal" : "vertical");
|
|
1079
|
+
handle.setAttribute("aria-label", labelText(this, "resize-panels", "Resize panels"));
|
|
1080
|
+
handle.setAttribute("tabindex", "0");
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
const setSplit = (clientX, clientY) => {
|
|
1084
|
+
const rect = this.getBoundingClientRect();
|
|
1085
|
+
const vertical = this.classList.contains("c-resizable--vertical");
|
|
1086
|
+
const span = vertical ? rect.height : rect.width;
|
|
1087
|
+
const pos = vertical ? clientY - rect.top : clientX - rect.left;
|
|
1088
|
+
const frac = span > 0 ? Math.min(0.9, Math.max(0.1, pos / span)) : 0.5;
|
|
1089
|
+
applySplit(Math.round(frac * 100));
|
|
1090
|
+
};
|
|
1091
|
+
this.addEventListener("pointerdown", (e) => {
|
|
1092
|
+
const handle = this.querySelector(".c-resize-handle");
|
|
1093
|
+
if (!handle || e.target !== handle) return;
|
|
1094
|
+
this._resizing = true;
|
|
1095
|
+
handle.classList.add("c-resize-handle--dragging");
|
|
1096
|
+
if (handle.setPointerCapture) { try { handle.setPointerCapture(e.pointerId); } catch (err) { /* synthetic pointer: ignore */ } }
|
|
1097
|
+
e.preventDefault();
|
|
1098
|
+
});
|
|
1099
|
+
this.addEventListener("pointermove", (e) => {
|
|
1100
|
+
if (!this._resizing) return;
|
|
1101
|
+
setSplit(e.clientX, e.clientY);
|
|
1102
|
+
});
|
|
1103
|
+
const stopResize = (e) => {
|
|
1104
|
+
if (!this._resizing) return;
|
|
1105
|
+
this._resizing = false;
|
|
1106
|
+
if (this._splitValue) { this.setAttribute("value", this._splitValue); this._splitValue = null; }
|
|
1107
|
+
const rect = this.getBoundingClientRect();
|
|
1108
|
+
this.dispatchEvent(new CustomEvent("contour:resize", { bubbles: true, composed: true, detail: { width: Math.round(rect.width), height: Math.round(rect.height) } }));
|
|
1109
|
+
const handle = this.querySelector(".c-resize-handle");
|
|
1110
|
+
if (handle) {
|
|
1111
|
+
handle.classList.remove("c-resize-handle--dragging");
|
|
1112
|
+
if (handle.hasPointerCapture && handle.hasPointerCapture(e.pointerId)) {
|
|
1113
|
+
try { handle.releasePointerCapture(e.pointerId); } catch (err) { /* ignore */ }
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
this.addEventListener("pointerup", stopResize);
|
|
1118
|
+
this.addEventListener("pointercancel", stopResize);
|
|
1119
|
+
this.addEventListener("keydown", (e) => {
|
|
1120
|
+
const handle = this.querySelector(".c-resize-handle");
|
|
1121
|
+
if (!handle || document.activeElement !== handle) return;
|
|
1122
|
+
const vertical = this.classList.contains("c-resizable--vertical");
|
|
1123
|
+
const cur = parseFloat(this.getAttribute("value")) || 50;
|
|
1124
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowDown") { e.preventDefault(); applySplit(Math.max(10, cur - 5)); this._splitValue = null; this.setAttribute("value", String(Math.max(10, cur - 5))); }
|
|
1125
|
+
else if (e.key === "ArrowRight" || e.key === "ArrowUp") { e.preventDefault(); applySplit(Math.min(90, cur + 5)); this._splitValue = null; this.setAttribute("value", String(Math.min(90, cur + 5))); }
|
|
1126
|
+
const r = this.getBoundingClientRect();
|
|
1127
|
+
this.dispatchEvent(new CustomEvent("contour:resize", { bubbles: true, composed: true, detail: { width: Math.round(r.width), height: Math.round(r.height) } }));
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
define("contour-resizable", ContourResizable);
|
|
1132
|
+
// R31-96: the ONE split primitive. `contour-split-view` is a generic two-pane
|
|
1133
|
+
// resizer; `contour-split-map` (map before/after) and `contour-comparison`
|
|
1134
|
+
// (chart A/B) are specialized compositions of it, not separate primitives. A
|
|
1135
|
+
// new split need must extend this, not add a fourth.
|
|
1136
|
+
class ContourSplitView extends ContourBase {
|
|
1137
|
+
static get observed() { return ["direction", "value", "left-label", "right-label"]; }
|
|
1138
|
+
static get properties() { return { direction: { attribute: "direction" }, value: { attribute: "value" }, "left-label": { attribute: "left-label" }, "right-label": { attribute: "right-label" } }; }
|
|
1139
|
+
render() {
|
|
1140
|
+
this.classList.add("c-split-view");
|
|
1141
|
+
this.setAttribute("role", "region");
|
|
1142
|
+
const vertical = this.getAttribute("direction") === "vertical";
|
|
1143
|
+
if (vertical) {
|
|
1144
|
+
this.classList.add("c-split-view--vertical");
|
|
1145
|
+
this.classList.remove("c-split-view--horizontal");
|
|
1146
|
+
} else {
|
|
1147
|
+
this.classList.add("c-split-view--horizontal");
|
|
1148
|
+
this.classList.remove("c-split-view--vertical");
|
|
1149
|
+
}
|
|
1150
|
+
if (this.getAttribute("left-label")) this.setAttribute("aria-label", this.getAttribute("left-label"));
|
|
1151
|
+
if (!this.querySelector(".c-split-view__pane")) {
|
|
1152
|
+
const p1 = document.createElement("div");
|
|
1153
|
+
p1.className = "c-split-view__pane c-split-view__pane--left";
|
|
1154
|
+
p1.setAttribute("role", "region");
|
|
1155
|
+
if (this.getAttribute("left-label")) p1.setAttribute("aria-label", this.getAttribute("left-label"));
|
|
1156
|
+
const divider = document.createElement("div");
|
|
1157
|
+
divider.className = "c-split-view__divider";
|
|
1158
|
+
divider.setAttribute("tabindex", "0");
|
|
1159
|
+
divider.setAttribute("role", "separator");
|
|
1160
|
+
divider.setAttribute("aria-valuenow", this.getAttribute("value") || "50");
|
|
1161
|
+
divider.setAttribute("aria-valuemin", "10");
|
|
1162
|
+
divider.setAttribute("aria-valuemax", "90");
|
|
1163
|
+
divider.setAttribute("aria-orientation", vertical ? "horizontal" : "vertical");
|
|
1164
|
+
divider.setAttribute("aria-label", labelText(this, "split-divider", "Split divider"));
|
|
1165
|
+
const p2 = document.createElement("div");
|
|
1166
|
+
p2.className = "c-split-view__pane c-split-view__pane--right";
|
|
1167
|
+
p2.setAttribute("role", "region");
|
|
1168
|
+
if (this.getAttribute("right-label")) p2.setAttribute("aria-label", this.getAttribute("right-label"));
|
|
1169
|
+
this.appendChild(p1);
|
|
1170
|
+
this.appendChild(divider);
|
|
1171
|
+
this.appendChild(p2);
|
|
1172
|
+
}
|
|
1173
|
+
// Divider created independently of pane guard; author panes still need it.
|
|
1174
|
+
if (!this.querySelector(".c-split-view__divider")) {
|
|
1175
|
+
const divider = document.createElement("div");
|
|
1176
|
+
divider.className = "c-split-view__divider";
|
|
1177
|
+
divider.setAttribute("tabindex", "0");
|
|
1178
|
+
divider.setAttribute("role", "separator");
|
|
1179
|
+
divider.setAttribute("aria-valuenow", this.getAttribute("value") || "50");
|
|
1180
|
+
divider.setAttribute("aria-valuemin", "10");
|
|
1181
|
+
divider.setAttribute("aria-valuemax", "90");
|
|
1182
|
+
divider.setAttribute("aria-orientation", vertical ? "horizontal" : "vertical");
|
|
1183
|
+
divider.setAttribute("aria-label", labelText(this, "split-divider", "Split divider"));
|
|
1184
|
+
this.appendChild(divider);
|
|
1185
|
+
}
|
|
1186
|
+
const v = this.getAttribute("value") || "50";
|
|
1187
|
+
const p1 = this.querySelector(".c-split-view__pane--left");
|
|
1188
|
+
if (p1) p1.style.flex = `0 0 ${v}%`;
|
|
1189
|
+
const divider = this.querySelector(".c-split-view__divider");
|
|
1190
|
+
if (divider) {
|
|
1191
|
+
divider.setAttribute("aria-valuenow", v);
|
|
1192
|
+
divider.setAttribute("aria-valuemin", "10");
|
|
1193
|
+
divider.setAttribute("aria-valuemax", "90");
|
|
1194
|
+
divider.setAttribute("aria-orientation", vertical ? "horizontal" : "vertical");
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
enhance() {
|
|
1198
|
+
if (this._wiredSplitView) return;
|
|
1199
|
+
this._wiredSplitView = true;
|
|
1200
|
+
// R31-114: the stylesheet stacks a horizontal split below 40rem. A media query
|
|
1201
|
+
// cannot restyle its own container, so the class still says what the author
|
|
1202
|
+
// asked for while the rendered axis says what the reader got — the drag maths
|
|
1203
|
+
// and the separator's announced orientation follow the second.
|
|
1204
|
+
const isColumn = () => getComputedStyle(this).flexDirection === "column";
|
|
1205
|
+
const syncAxis = () => {
|
|
1206
|
+
const d = this.querySelector(".c-split-view__divider");
|
|
1207
|
+
if (d) d.setAttribute("aria-orientation", isColumn() ? "horizontal" : "vertical");
|
|
1208
|
+
};
|
|
1209
|
+
syncAxis();
|
|
1210
|
+
if (typeof ResizeObserver === "function") {
|
|
1211
|
+
const ro = new ResizeObserver(syncAxis);
|
|
1212
|
+
ro.observe(this);
|
|
1213
|
+
onDispose(this, () => ro.disconnect());
|
|
1214
|
+
}
|
|
1215
|
+
const setSplit = (clientX, clientY) => {
|
|
1216
|
+
const rect = this.getBoundingClientRect();
|
|
1217
|
+
const vertical = isColumn();
|
|
1218
|
+
const span = vertical ? rect.height : rect.width;
|
|
1219
|
+
const pos = vertical ? clientY - rect.top : clientX - rect.left;
|
|
1220
|
+
const frac = span > 0 ? Math.min(0.9, Math.max(0.1, pos / span)) : 0.5;
|
|
1221
|
+
const pct = Math.round(frac * 100);
|
|
1222
|
+
const p1 = this.querySelector(".c-split-view__pane--left");
|
|
1223
|
+
if (p1) p1.style.flex = `0 0 ${pct}%`;
|
|
1224
|
+
const divider = this.querySelector(".c-split-view__divider");
|
|
1225
|
+
if (divider) divider.setAttribute("aria-valuenow", String(pct));
|
|
1226
|
+
this.setAttribute("value", String(pct));
|
|
1227
|
+
};
|
|
1228
|
+
this.addEventListener("pointerdown", (e) => {
|
|
1229
|
+
const divider = this.querySelector(".c-split-view__divider");
|
|
1230
|
+
if (!divider || e.target !== divider) return;
|
|
1231
|
+
this._resizing = true;
|
|
1232
|
+
divider.classList.add("c-split-view__divider--dragging");
|
|
1233
|
+
if (divider.setPointerCapture) { try { divider.setPointerCapture(e.pointerId); } catch (err) { /* ignore */ } }
|
|
1234
|
+
e.preventDefault();
|
|
1235
|
+
});
|
|
1236
|
+
this.addEventListener("pointermove", (e) => {
|
|
1237
|
+
if (!this._resizing) return;
|
|
1238
|
+
setSplit(e.clientX, e.clientY);
|
|
1239
|
+
});
|
|
1240
|
+
const stopResize = (e) => {
|
|
1241
|
+
if (!this._resizing) return;
|
|
1242
|
+
this._resizing = false;
|
|
1243
|
+
const divider = this.querySelector(".c-split-view__divider");
|
|
1244
|
+
if (divider) {
|
|
1245
|
+
divider.classList.remove("c-split-view__divider--dragging");
|
|
1246
|
+
if (divider.hasPointerCapture && divider.hasPointerCapture(e.pointerId)) {
|
|
1247
|
+
try { divider.releasePointerCapture(e.pointerId); } catch (err) { /* ignore */ }
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
const r = this.getBoundingClientRect();
|
|
1251
|
+
this.dispatchEvent(new CustomEvent("contour:split-change", { bubbles: true, composed: true, detail: { value: this.getAttribute("value"), width: Math.round(r.width), height: Math.round(r.height) } }));
|
|
1252
|
+
};
|
|
1253
|
+
this.addEventListener("pointerup", stopResize);
|
|
1254
|
+
this.addEventListener("pointercancel", stopResize);
|
|
1255
|
+
this.addEventListener("keydown", (e) => {
|
|
1256
|
+
const divider = this.querySelector(".c-split-view__divider");
|
|
1257
|
+
if (!divider || document.activeElement !== divider) return;
|
|
1258
|
+
const cur = parseFloat(this.getAttribute("value")) || 50;
|
|
1259
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowDown") { e.preventDefault(); const nv = Math.max(10, cur - 5); const p1 = this.querySelector(".c-split-view__pane--left"); if (p1) p1.style.flex = `0 0 ${nv}%`; this.setAttribute("value", String(nv)); const d = this.querySelector(".c-split-view__divider"); if (d) d.setAttribute("aria-valuenow", String(nv)); }
|
|
1260
|
+
else if (e.key === "ArrowRight" || e.key === "ArrowUp") { e.preventDefault(); const nv = Math.min(90, cur + 5); const p1 = this.querySelector(".c-split-view__pane--left"); if (p1) p1.style.flex = `0 0 ${nv}%`; this.setAttribute("value", String(nv)); const d = this.querySelector(".c-split-view__divider"); if (d) d.setAttribute("aria-valuenow", String(nv)); }
|
|
1261
|
+
const r = this.getBoundingClientRect();
|
|
1262
|
+
this.dispatchEvent(new CustomEvent("contour:split-change", { bubbles: true, composed: true, detail: { value: this.getAttribute("value"), width: Math.round(r.width), height: Math.round(r.height) } }));
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
define("contour-split-view", ContourSplitView);
|
|
1267
|
+
class ContourTableWrap extends ContourBase {
|
|
1268
|
+
static get observed() { return []; }
|
|
1269
|
+
static get properties() { return {}; }
|
|
1270
|
+
render() {
|
|
1271
|
+
this.classList.add("c-table-wrap");
|
|
1272
|
+
Array.from(this.childNodes).forEach((n) => { if (n.nodeType === Node.TEXT_NODE) n.remove(); else if (n.nodeType === Node.ELEMENT_NODE && n.tagName === "SPAN") n.remove(); });
|
|
1273
|
+
// Author supplies the <table>; component doesn't invent one (old code rendered A/B/1/2).
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
define("contour-table-wrap", ContourTableWrap);
|
|
1277
|
+
class ContourScrollArea extends ContourBase {
|
|
1278
|
+
static get observed() { return ["title"]; }
|
|
1279
|
+
static get properties() { return { title: { attribute: "title" } }; }
|
|
1280
|
+
render() {
|
|
1281
|
+
this.classList.add("c-scroll-area");
|
|
1282
|
+
const title = this.getAttribute("title");
|
|
1283
|
+
if (title) {
|
|
1284
|
+
const t = this.ensure(".c-scroll-area__title", () => { const el = document.createElement("div"); el.className = "c-scroll-area__title"; return el; });
|
|
1285
|
+
t.textContent = title;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
define("contour-scroll-area", ContourScrollArea);
|
|
1290
|
+
class ContourBtn extends ContourBase {
|
|
1291
|
+
static get observed() { return ["variant", "size", "color", "label", "disabled", "href", "loading", "title"]; }
|
|
1292
|
+
static get properties() { return { variant: { attribute: "variant" }, size: { attribute: "size" }, color: { attribute: "color" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean } }; }
|
|
1293
|
+
render() {
|
|
1294
|
+
this.classList.add("c-btn");
|
|
1295
|
+
// keep authored variant classes; add attribute-driven ones on top.
|
|
1296
|
+
for (const attr of ["variant", "size", "color"]) {
|
|
1297
|
+
const val = this.getAttribute(attr);
|
|
1298
|
+
if (val) this.classList.add("c-btn--" + val);
|
|
1299
|
+
}
|
|
1300
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "button");
|
|
1301
|
+
if (this.hasAttribute("disabled")) {
|
|
1302
|
+
this.setAttribute("aria-disabled", "true");
|
|
1303
|
+
this.setAttribute("tabindex", "-1");
|
|
1304
|
+
} else {
|
|
1305
|
+
this.removeAttribute("aria-disabled");
|
|
1306
|
+
if (!this.hasAttribute("tabindex") || this.getAttribute("tabindex") === "-1") this.setAttribute("tabindex", "0");
|
|
1307
|
+
}
|
|
1308
|
+
// Name icon-only buttons from label/title when there is no text content.
|
|
1309
|
+
const label = this.getAttribute("label") || this.getAttribute("title");
|
|
1310
|
+
if (label && !this.hasChildNodes()) this.textContent = label;
|
|
1311
|
+
if (label && !this.hasAttribute("aria-label")) this.setAttribute("aria-label", label);
|
|
1312
|
+
// Loading state: expose data-loading + aria-busy so the spinner CSS and
|
|
1313
|
+
// assistive technology both reflect the busy state.
|
|
1314
|
+
if (this.hasAttribute("loading")) {
|
|
1315
|
+
this.setAttribute("data-loading", "true");
|
|
1316
|
+
this.setAttribute("aria-busy", "true");
|
|
1317
|
+
} else {
|
|
1318
|
+
this.removeAttribute("data-loading");
|
|
1319
|
+
this.removeAttribute("aria-busy");
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
enhance() {
|
|
1323
|
+
if (this._wiredBtn) return;
|
|
1324
|
+
this._wiredBtn = true;
|
|
1325
|
+
// disabled guard: no activation on click/keydown; capture-phase.
|
|
1326
|
+
const isDisabled = () => this.hasAttribute("disabled") || this.getAttribute("aria-disabled") === "true";
|
|
1327
|
+
this.addEventListener("click", (e) => {
|
|
1328
|
+
if (isDisabled()) { e.preventDefault(); e.stopImmediatePropagation(); }
|
|
1329
|
+
}, true);
|
|
1330
|
+
// optional href mode — sanitize via safeHref and navigate on
|
|
1331
|
+
// click/Enter (guard above keeps disabled buttons from navigating).
|
|
1332
|
+
this.addEventListener("click", (e) => {
|
|
1333
|
+
if (isDisabled()) return;
|
|
1334
|
+
const href = safeHref(this.getAttribute("href"));
|
|
1335
|
+
if (href && href !== "#") location.href = href;
|
|
1336
|
+
});
|
|
1337
|
+
this.addEventListener("keydown", (e) => {
|
|
1338
|
+
if (isDisabled()) { e.preventDefault(); e.stopImmediatePropagation(); return; }
|
|
1339
|
+
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); this.click(); this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true })); }
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
define("contour-btn", ContourBtn);
|