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,976 @@
|
|
|
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
|
+
/* Route matching (CDS-075). The URL is the state for a documentation surface, so
|
|
611
|
+
the sidebar says where the reader is by marking the matching link
|
|
612
|
+
`aria-current="page"` — the shipped CSS already styles that attribute, and a
|
|
613
|
+
reader who cannot see the highlight still hears "current page".
|
|
614
|
+
|
|
615
|
+
Two ways to say where the reader is, in order:
|
|
616
|
+
1. a `current` attribute on the host, which is what a client-side router
|
|
617
|
+
sets after it navigates (a path, or a bare `#hash`);
|
|
618
|
+
2. the document's own location, which is what a static docs site has.
|
|
619
|
+
|
|
620
|
+
A bare hash also matches the last path segment, because that is the shape a
|
|
621
|
+
docs URL takes: `/docs/install` is the page `#install` points at. */
|
|
622
|
+
const routeKey = (value) => {
|
|
623
|
+
const raw = String(value == null ? "" : value).trim();
|
|
624
|
+
if (!raw) return "";
|
|
625
|
+
if (raw.startsWith("#")) return "hash:" + raw;
|
|
626
|
+
try {
|
|
627
|
+
const base = typeof location !== "undefined" ? location.href : "http://localhost/";
|
|
628
|
+
const url = new URL(raw, base);
|
|
629
|
+
return "path:" + url.pathname.replace(/\/+$/, "") + url.search;
|
|
630
|
+
} catch (e) {
|
|
631
|
+
return "raw:" + raw;
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
const hereKey = (explicit) => {
|
|
636
|
+
const raw = String(explicit == null ? "" : explicit).trim();
|
|
637
|
+
if (raw) return routeKey(raw);
|
|
638
|
+
if (typeof location === "undefined") return "";
|
|
639
|
+
return "path:" + String(location.pathname || "").replace(/\/+$/, "") + (location.search || "");
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
const hashMatchesHere = (hash) => {
|
|
643
|
+
if (typeof location === "undefined") return false;
|
|
644
|
+
if (location.hash && location.hash === hash) return true;
|
|
645
|
+
const segment = String(location.pathname || "").split("/").filter(Boolean).pop() || "";
|
|
646
|
+
return Boolean(segment) && hash === "#" + segment;
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
class ContourDocsNav extends ContourBase {
|
|
650
|
+
static get observed() { return ["items", "title", "current", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "empty", "no-cache"]; }
|
|
651
|
+
static get properties() { return { items: { attribute: "items" }, title: { attribute: "title" }, src: { attribute: "src" } }; }
|
|
652
|
+
render() {
|
|
653
|
+
this.classList.add("c-docs-nav");
|
|
654
|
+
this.setAttribute("role", "navigation");
|
|
655
|
+
const title = this.getAttribute("title");
|
|
656
|
+
if (title) this.setAttribute("aria-label", title);
|
|
657
|
+
else this.setAttribute("aria-label", labelText(this, "documentation-navigation", "Documentation navigation"));
|
|
658
|
+
wireStates(this);
|
|
659
|
+
loadRemote(this, "items");
|
|
660
|
+
if (renderStates(this, "docs-nav")) return;
|
|
661
|
+
const _remote = remoteData(this, "items");
|
|
662
|
+
const items = this.hasAttribute("src") ? _remote : (_remote || (this.hasAttribute("items") ? this.getAttribute("items") : null));
|
|
663
|
+
const list = this.querySelector(".c-docs-nav__list");
|
|
664
|
+
const authored = list ? Array.from(list.children).filter((n) => n.classList && n.classList.contains("c-docs-nav__group")) : [];
|
|
665
|
+
if (items && !authored.length) {
|
|
666
|
+
try {
|
|
667
|
+
const parsed = JSON.parse(items);
|
|
668
|
+
const list = this.ensure(".c-docs-nav__list", () => { const el = document.createElement("div"); el.className = "c-docs-nav__list"; return el; });
|
|
669
|
+
list.innerHTML = "";
|
|
670
|
+
parsed.forEach((g) => {
|
|
671
|
+
const group = document.createElement("div");
|
|
672
|
+
group.className = "c-docs-nav__group";
|
|
673
|
+
if (g.title) {
|
|
674
|
+
const gt = document.createElement("div");
|
|
675
|
+
gt.className = "c-docs-nav__group-title";
|
|
676
|
+
gt.textContent = g.title;
|
|
677
|
+
group.appendChild(gt);
|
|
678
|
+
}
|
|
679
|
+
const ul = document.createElement("div");
|
|
680
|
+
ul.className = "c-docs-nav__list";
|
|
681
|
+
(g.links || g.items || []).forEach((l) => {
|
|
682
|
+
const a = document.createElement("a");
|
|
683
|
+
a.className = "c-docs-nav__link";
|
|
684
|
+
a.href = safeHref(typeof l === "string" ? "#" : (l.href || "#"));
|
|
685
|
+
const label = typeof l === "string" ? l : (l.label || l);
|
|
686
|
+
if (typeof l === "object" && l !== null && l.badge) {
|
|
687
|
+
const b = document.createElement("span");
|
|
688
|
+
b.className = "c-docs-nav__badge";
|
|
689
|
+
b.textContent = l.badge;
|
|
690
|
+
a.appendChild(b);
|
|
691
|
+
}
|
|
692
|
+
a.appendChild(document.createTextNode(label));
|
|
693
|
+
if (typeof l === "object" && l !== null && l.chevron) {
|
|
694
|
+
const ch = document.createElement("span");
|
|
695
|
+
ch.className = "c-docs-nav__chevron";
|
|
696
|
+
// R31-152: the submenu caret is the sprite chevron, not a text glyph.
|
|
697
|
+
setHTML(ch, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>');
|
|
698
|
+
a.appendChild(ch);
|
|
699
|
+
}
|
|
700
|
+
if (typeof l === "object" && l !== null && Array.isArray(l.items)) {
|
|
701
|
+
a.classList.add("c-docs-nav__link--nested");
|
|
702
|
+
const nested = document.createElement("div");
|
|
703
|
+
nested.className = "c-docs-nav__list c-docs-nav__list--nested";
|
|
704
|
+
l.items.forEach((nl) => {
|
|
705
|
+
const na = document.createElement("a");
|
|
706
|
+
na.className = "c-docs-nav__link";
|
|
707
|
+
na.href = safeHref(typeof nl === "string" ? "#" : (nl.href || "#"));
|
|
708
|
+
na.textContent = typeof nl === "string" ? nl : (nl.label || nl);
|
|
709
|
+
nested.appendChild(na);
|
|
710
|
+
});
|
|
711
|
+
ul.appendChild(a);
|
|
712
|
+
ul.appendChild(nested);
|
|
713
|
+
} else {
|
|
714
|
+
ul.appendChild(a);
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
group.appendChild(ul);
|
|
718
|
+
list.appendChild(group);
|
|
719
|
+
});
|
|
720
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
721
|
+
} else if (!items && list) {
|
|
722
|
+
list.remove();
|
|
723
|
+
renderEmpty(this, "docs-nav");
|
|
724
|
+
} else if (!items && !list) {
|
|
725
|
+
renderEmpty(this, "docs-nav");
|
|
726
|
+
}
|
|
727
|
+
this.applyCurrent();
|
|
728
|
+
}
|
|
729
|
+
/* Mark the link the reader is on. Idempotent: it clears every other link
|
|
730
|
+
first, so a re-render or a route change cannot leave two "current" items. */
|
|
731
|
+
applyCurrent() {
|
|
732
|
+
const links = Array.from(this.querySelectorAll(".c-docs-nav__link"));
|
|
733
|
+
if (!links.length) return;
|
|
734
|
+
const explicit = this.getAttribute("current");
|
|
735
|
+
const here = hereKey(explicit);
|
|
736
|
+
links.forEach((a) => {
|
|
737
|
+
const href = a.getAttribute("href") || "";
|
|
738
|
+
const key = routeKey(href);
|
|
739
|
+
const hit = Boolean(here) && (
|
|
740
|
+
(key && key === here) ||
|
|
741
|
+
(href.startsWith("#") && !explicit && hashMatchesHere(href))
|
|
742
|
+
);
|
|
743
|
+
if (hit) a.setAttribute("aria-current", "page");
|
|
744
|
+
else a.removeAttribute("aria-current");
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
enhance() {
|
|
748
|
+
if (this._wiredDocsNav) return;
|
|
749
|
+
this._wiredDocsNav = true;
|
|
750
|
+
this.addEventListener("click", (e) => {
|
|
751
|
+
const link = e.target && e.target.closest ? e.target.closest(".c-docs-nav__link") : null;
|
|
752
|
+
if (link && this.contains(link)) {
|
|
753
|
+
const label = link.textContent || "";
|
|
754
|
+
this.dispatchEvent(new CustomEvent("contour:docs-nav-select", { bubbles: true, composed: true, detail: { label, href: link.getAttribute("href") } }));
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
// Keyboard: roving tabindex over docs-nav links, Enter follows the link.
|
|
758
|
+
this.addEventListener("keydown", (e) => {
|
|
759
|
+
const links = Array.from(this.querySelectorAll(".c-docs-nav__link"));
|
|
760
|
+
if (!links.length) return;
|
|
761
|
+
if (!links.some((l) => l.tabIndex === 0)) links.forEach((l, i) => l.tabIndex = i === 0 ? 0 : -1);
|
|
762
|
+
navKey(e, links, { wrap: true, homeEnd: true, onNavigate: (i) => { links.forEach((l, j) => l.tabIndex = j === i ? 0 : -1); }, onKey: (k) => { if (k === "Enter") { const a = document.activeElement; if (a) { e.preventDefault(); a.click(); } } } });
|
|
763
|
+
});
|
|
764
|
+
// Static docs navigate by URL, so highlight follows the URL not the click; a host passing `current` owns state and this is a no-op.
|
|
765
|
+
if (typeof window !== "undefined" && window.addEventListener) {
|
|
766
|
+
const sync = () => this.applyCurrent();
|
|
767
|
+
window.addEventListener("hashchange", sync);
|
|
768
|
+
window.addEventListener("popstate", sync);
|
|
769
|
+
onDispose(this, () => {
|
|
770
|
+
window.removeEventListener("hashchange", sync);
|
|
771
|
+
window.removeEventListener("popstate", sync);
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
define("contour-docs-nav", ContourDocsNav);
|
|
777
|
+
class ContourDocsShell extends ContourBase {
|
|
778
|
+
static get observed() { return ["title", "lede", "article", "heading"]; }
|
|
779
|
+
static get properties() { return { title: { attribute: "title" }, lede: { attribute: "lede" }, article: { attribute: "article" } }; }
|
|
780
|
+
render() {
|
|
781
|
+
this.classList.add("c-docs-shell");
|
|
782
|
+
this.setAttribute("role", "region");
|
|
783
|
+
const title = this.getAttribute("title");
|
|
784
|
+
if (title) {
|
|
785
|
+
const h = this.ensure(".c-docs-shell__title", () => { const el = document.createElement(headingTag(this, "h2")); el.className = "c-docs-shell__title"; return el; });
|
|
786
|
+
h.textContent = title;
|
|
787
|
+
this.setAttribute("aria-label", title);
|
|
788
|
+
} else {
|
|
789
|
+
const h = this.querySelector(".c-docs-shell__title");
|
|
790
|
+
if (h) h.remove();
|
|
791
|
+
}
|
|
792
|
+
const lede = this.getAttribute("lede");
|
|
793
|
+
if (lede) {
|
|
794
|
+
const p = this.ensure(".c-docs-shell__lede", () => { const el = document.createElement("p"); el.className = "c-docs-shell__lede"; return el; });
|
|
795
|
+
p.textContent = lede;
|
|
796
|
+
} else {
|
|
797
|
+
const p = this.querySelector(".c-docs-shell__lede");
|
|
798
|
+
if (p) p.remove();
|
|
799
|
+
}
|
|
800
|
+
const article = this.getAttribute("article");
|
|
801
|
+
if (article) {
|
|
802
|
+
const a = this.ensure(".c-docs-shell__article", () => { const el = document.createElement("article"); el.className = "c-docs-shell__article"; return el; });
|
|
803
|
+
setHTML(a, sanitizeHtml(article));
|
|
804
|
+
} else {
|
|
805
|
+
const a = this.querySelector(".c-docs-shell__article");
|
|
806
|
+
if (a) a.remove();
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
define("contour-docs-shell", ContourDocsShell);
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
class ContourFileTree extends ContourBase {
|
|
814
|
+
static get updateMode() { return "keyed"; }
|
|
815
|
+
static get observed() { return ["items"]; }
|
|
816
|
+
static get properties() { return { items: { attribute: "items" } }; }
|
|
817
|
+
render() {
|
|
818
|
+
this.classList.add("c-file-tree");
|
|
819
|
+
const items = this.getAttribute("items");
|
|
820
|
+
if (items) {
|
|
821
|
+
try {
|
|
822
|
+
const parsed = JSON.parse(items);
|
|
823
|
+
const renderNode = (node, depth) => {
|
|
824
|
+
const row = document.createElement("div");
|
|
825
|
+
row.className = "c-file-tree__row" + (node.dir ? " c-file-tree__row--dir" : "") + (node.active ? " c-file-tree__row--active" : "");
|
|
826
|
+
row.style.setProperty("--depth", String(depth));
|
|
827
|
+
const label = document.createElement("span");
|
|
828
|
+
// R31-156: a folder/file glyph makes the tree scannable.
|
|
829
|
+
setHTML(label, node.dir ? '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-folder" /></svg>' : '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-file" /></svg>');
|
|
830
|
+
label.appendChild(document.createTextNode(" " + (node.label || node.name || "")));
|
|
831
|
+
row.appendChild(label);
|
|
832
|
+
this.appendChild(row);
|
|
833
|
+
if (Array.isArray(node.children)) {
|
|
834
|
+
node.children.forEach((c) => renderNode(c, depth + 1));
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
// clear generated
|
|
838
|
+
Array.from(this.querySelectorAll(".c-file-tree__row")).forEach((n) => n.remove());
|
|
839
|
+
parsed.forEach((n) => renderNode(n, 0));
|
|
840
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
define("contour-file-tree", ContourFileTree);
|
|
845
|
+
|
|
846
|
+
class ContourChangelog extends ContourBase {
|
|
847
|
+
static get observed() { return ["src", "max", "loading", "error"]; }
|
|
848
|
+
static get properties() { return { src: { attribute: "src" }, max: { attribute: "max", type: Number } }; }
|
|
849
|
+
render() {
|
|
850
|
+
this.classList.add("c-changelog");
|
|
851
|
+
const src = this.getAttribute("src");
|
|
852
|
+
if (src) {
|
|
853
|
+
if (this.dataset.loaded === src) return;
|
|
854
|
+
this.dataset.loaded = "";
|
|
855
|
+
const loading = this.ensure(".c-changelog__loading", () => { const el = document.createElement("div"); el.className = "c-changelog__loading"; return el; });
|
|
856
|
+
loading.textContent = labelText(this, "loading", "Loading…");
|
|
857
|
+
// clear
|
|
858
|
+
Array.from(this.querySelectorAll(".c-changelog__entry, .c-changelog__error")).forEach((n) => n.remove());
|
|
859
|
+
if (!this.querySelector(".c-changelog__loading")) this.appendChild(loading);
|
|
860
|
+
// Abort the in-flight fetch when the host leaves the page, so a slow
|
|
861
|
+
// changelog cannot write into a detached element.
|
|
862
|
+
try { if (this._changelogAbort) this._changelogAbort.abort(); } catch (e) {}
|
|
863
|
+
this._changelogAbort = typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
864
|
+
fetch(src, this._changelogAbort ? { signal: this._changelogAbort.signal } : undefined).then((r) => {
|
|
865
|
+
if (!r.ok) throw new Error("HTTP " + r.status);
|
|
866
|
+
return r.text();
|
|
867
|
+
}).then((text) => {
|
|
868
|
+
if (!this.isConnected) return;
|
|
869
|
+
const ld = this.querySelector(".c-changelog__loading");
|
|
870
|
+
if (ld) ld.remove();
|
|
871
|
+
this.dataset.loaded = src;
|
|
872
|
+
const entries = parseChangelog(text);
|
|
873
|
+
const max = parseInt(this.getAttribute("max") || "0", 10);
|
|
874
|
+
const list = (max > 0) ? entries.slice(0, max) : entries;
|
|
875
|
+
if (!list.length) {
|
|
876
|
+
const empty = document.createElement("div");
|
|
877
|
+
empty.className = "c-changelog__empty";
|
|
878
|
+
empty.textContent = labelText(this, "empty", "No releases found.");
|
|
879
|
+
this.appendChild(empty);
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
list.forEach((e) => {
|
|
883
|
+
const det = document.createElement("details");
|
|
884
|
+
det.className = "c-changelog__entry";
|
|
885
|
+
const sum = document.createElement("summary");
|
|
886
|
+
sum.className = "c-changelog__summary";
|
|
887
|
+
const ver = document.createElement("span");
|
|
888
|
+
ver.className = "c-changelog__version";
|
|
889
|
+
ver.textContent = e.version;
|
|
890
|
+
sum.appendChild(ver);
|
|
891
|
+
if (e.date) {
|
|
892
|
+
const d = document.createElement("span");
|
|
893
|
+
d.className = "c-changelog__date";
|
|
894
|
+
d.textContent = e.date;
|
|
895
|
+
sum.appendChild(d);
|
|
896
|
+
}
|
|
897
|
+
det.appendChild(sum);
|
|
898
|
+
const body = document.createElement("div");
|
|
899
|
+
body.className = "c-changelog__body";
|
|
900
|
+
setHTML(body, renderChangelogBody(e.body));
|
|
901
|
+
det.appendChild(body);
|
|
902
|
+
this.appendChild(det);
|
|
903
|
+
});
|
|
904
|
+
}).catch((err) => {
|
|
905
|
+
if (!this.isConnected) return;
|
|
906
|
+
const ld = this.querySelector(".c-changelog__loading");
|
|
907
|
+
if (ld) ld.remove();
|
|
908
|
+
const er = document.createElement("div");
|
|
909
|
+
er.className = "c-changelog__error";
|
|
910
|
+
er.textContent = labelText(this, "load-error", "Failed to load changelog") + ": " + (err && err.message ? err.message : err);
|
|
911
|
+
this.appendChild(er);
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
disconnectedCallback() {
|
|
916
|
+
super.disconnectedCallback();
|
|
917
|
+
try { if (this._changelogAbort) this._changelogAbort.abort(); } catch (e) {}
|
|
918
|
+
this._changelogAbort = null;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
define("contour-changelog", ContourChangelog);
|
|
922
|
+
|
|
923
|
+
function parseChangelog(text) {
|
|
924
|
+
const lines = String(text).split(/\r?\n/);
|
|
925
|
+
const entries = [];
|
|
926
|
+
let cur = null;
|
|
927
|
+
for (const line of lines) {
|
|
928
|
+
const m = line.match(/^##\s+\[?([^\]\n]+)\]?\s*[-–—]?\s*(.*)$/);
|
|
929
|
+
if (m && (line.startsWith("## ") )) {
|
|
930
|
+
// only treat as version header if it looks like a version or "Unreleased"
|
|
931
|
+
const ver = m[1].trim();
|
|
932
|
+
const rest = m[2].trim();
|
|
933
|
+
if (/^\d|unreleased/i.test(ver)) {
|
|
934
|
+
if (cur) entries.push(cur);
|
|
935
|
+
cur = { version: ver, date: rest.replace(/^[-–—]\s*/, "").trim(), body: "" };
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
if (cur) cur.body += line + "\n";
|
|
940
|
+
}
|
|
941
|
+
if (cur) entries.push(cur);
|
|
942
|
+
return entries;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
function escapeHtml(s) {
|
|
946
|
+
return String(s).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
function renderChangelogBody(body) {
|
|
950
|
+
const lines = String(body).trim().split(/\r?\n/);
|
|
951
|
+
const out = [];
|
|
952
|
+
let inList = false;
|
|
953
|
+
for (const raw of lines) {
|
|
954
|
+
const line = raw.trimEnd();
|
|
955
|
+
if (/^###\s+/.test(line)) {
|
|
956
|
+
if (inList) { out.push("</ul>"); inList = false; }
|
|
957
|
+
out.push("<h3>" + escapeHtml(line.replace(/^###\s+/, "")) + "</h3>");
|
|
958
|
+
} else if (/^##\s+/.test(line)) {
|
|
959
|
+
if (inList) { out.push("</ul>"); inList = false; }
|
|
960
|
+
out.push("<h2>" + escapeHtml(line.replace(/^##\s+/, "")) + "</h2>");
|
|
961
|
+
} else if (/^#\s+/.test(line)) {
|
|
962
|
+
if (inList) { out.push("</ul>"); inList = false; }
|
|
963
|
+
out.push("<h2>" + escapeHtml(line.replace(/^#\s+/, "")) + "</h2>");
|
|
964
|
+
} else if (/^[-*]\s+/.test(line)) {
|
|
965
|
+
if (!inList) { out.push("<ul>"); inList = true; }
|
|
966
|
+
out.push("<li>" + escapeHtml(line.replace(/^[-*]\s+/, "")) + "</li>");
|
|
967
|
+
} else if (line.trim() === "") {
|
|
968
|
+
if (inList) { out.push("</ul>"); inList = false; }
|
|
969
|
+
} else {
|
|
970
|
+
if (inList) { out.push("</ul>"); inList = false; }
|
|
971
|
+
out.push("<p>" + escapeHtml(line) + "</p>");
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
if (inList) out.push("</ul>");
|
|
975
|
+
return out.join("");
|
|
976
|
+
}
|