contour-ds 1.7.2 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +244 -326
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/agent-rules.json +16 -0
- package/dist/build-manifest.json +344 -126
- package/dist/contour-wc-content.esm.js +1939 -0
- package/dist/contour-wc-content.esm.min.js +1 -0
- package/dist/contour-wc-core.esm.js +3724 -0
- package/dist/contour-wc-core.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +6986 -0
- package/dist/contour-wc-dashboard.esm.min.js +1 -0
- package/dist/contour-wc-data.esm.js +6572 -0
- package/dist/contour-wc-data.esm.min.js +1 -0
- package/dist/contour-wc-docs.esm.js +976 -0
- package/dist/contour-wc-docs.esm.min.js +1 -0
- package/dist/contour-wc-feedback.esm.js +1742 -0
- package/dist/contour-wc-feedback.esm.min.js +1 -0
- package/dist/contour-wc-forms.esm.js +2437 -0
- package/dist/contour-wc-forms.esm.min.js +1 -0
- package/dist/contour-wc-interaction.esm.js +1343 -0
- package/dist/contour-wc-interaction.esm.min.js +1 -0
- package/dist/contour-wc-layout.esm.js +845 -0
- package/dist/contour-wc-layout.esm.min.js +1 -0
- package/dist/contour-wc-map.esm.js +2411 -0
- package/dist/contour-wc-map.esm.min.js +1 -0
- package/dist/contour-wc-misc.esm.js +945 -0
- package/dist/contour-wc-misc.esm.min.js +1 -0
- package/dist/contour-wc-navigation.esm.js +2842 -0
- package/dist/contour-wc-navigation.esm.min.js +1 -0
- package/dist/contour-wc-ui.esm.js +6519 -0
- package/dist/contour-wc-ui.esm.min.js +1 -0
- package/dist/contour-wc.esm.js +14435 -5723
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +14436 -5725
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +4534 -0
- package/dist/contour.components.json +4870 -1222
- package/dist/contour.css +6672 -4711
- package/dist/contour.d.ts +753 -1085
- package/dist/contour.esm.js +440 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +11343 -0
- package/dist/contour.js +440 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +422 -0
- package/dist/contour.single.html +17 -0
- package/dist/contour.single.min.css +1 -0
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +1318 -1053
- package/dist/contour.vue.d.ts +420 -0
- package/dist/contour.web-types.json +11703 -0
- package/dist/custom-elements.json +36120 -0
- package/dist/docs/actions.md +16 -6
- package/dist/docs/affordances.md +21 -85
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -22
- package/dist/docs/data.md +39 -58
- package/dist/docs/docs.md +12 -7
- package/dist/docs/feedback.md +30 -12
- package/dist/docs/field.md +28 -13
- package/dist/docs/forms.md +35 -19
- package/dist/docs/index.json +70 -61
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +30 -8
- package/dist/docs/motion.md +12 -6
- package/dist/docs/navigation.md +31 -7
- package/dist/docs/overlays.md +32 -25
- package/dist/docs/overview.md +3 -2
- package/dist/docs/patterns.md +20 -10
- package/dist/docs/playground.md +11 -4
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +117 -13
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +13 -14
- package/dist/docs/surfaces.md +17 -22
- package/dist/docs/theming.md +18 -32
- package/dist/docs/type.md +12 -5
- package/dist/docs/webcomponents.md +75 -33
- package/dist/hljs.css +1 -20
- package/dist/map-chrome.mapbox.css +68 -92
- package/dist/map-chrome.maplibre.css +68 -92
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/svg/icons.svg +367 -0
- package/dist/wc/behaviours.mjs +222 -192
- package/dist/wc/content.mjs +486 -142
- package/dist/wc/core.mjs +917 -395
- package/dist/wc/dashboard.mjs +252 -25
- package/dist/wc/data-chart.mjs +1333 -0
- package/dist/wc/data-export.mjs +391 -0
- package/dist/wc/data-gauge.mjs +779 -0
- package/dist/wc/data-geo.mjs +696 -0
- package/dist/wc/data-glyphs.mjs +133 -0
- package/dist/wc/data-legend.mjs +431 -0
- package/dist/wc/data-readout.mjs +227 -0
- package/dist/wc/data-series.mjs +1004 -0
- package/dist/wc/data-table.mjs +751 -0
- package/dist/wc/data.mjs +15 -3707
- package/dist/wc/docs.mjs +113 -19
- package/dist/wc/feedback.mjs +320 -116
- package/dist/wc/forms-controls.mjs +635 -0
- package/dist/wc/forms-field.mjs +547 -0
- package/dist/wc/forms-groups.mjs +347 -0
- package/dist/wc/forms-input.mjs +292 -0
- package/dist/wc/forms.mjs +10 -1122
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +16 -7
- package/dist/wc/interaction.mjs +322 -75
- package/dist/wc/layout.mjs +100 -29
- package/dist/wc/map.mjs +888 -285
- package/dist/wc/misc.mjs +137 -26
- package/dist/wc/navigation-menu.mjs +735 -0
- package/dist/wc/navigation-shell.mjs +495 -0
- package/dist/wc/navigation-tree.mjs +995 -0
- package/dist/wc/navigation.mjs +9 -1636
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +285 -113
- package/dist/wc/states.mjs +75 -78
- package/dist/wc/svg.mjs +209 -34
- package/dist/wc/ui-atoms.mjs +608 -0
- package/dist/wc/ui-data.mjs +1404 -0
- package/dist/wc/ui-feedback.mjs +419 -0
- package/dist/wc/ui-inputs.mjs +1570 -0
- package/dist/wc/ui-menus.mjs +307 -0
- package/dist/wc/ui-overlays.mjs +1605 -0
- package/integrations/README.md +25 -5
- package/integrations/ai/CLAUDE.md +6 -3
- package/integrations/ai/COPILOT.md +14 -0
- package/integrations/ai/GEMINI.md +14 -0
- package/integrations/ai/WINDSURF.md +14 -0
- package/integrations/ai/v0-prompt.md +13 -1
- package/integrations/frameworks/README.md +235 -0
- package/integrations/native/README.md +0 -3
- package/integrations/native/style-dictionary.config.json +1 -1
- package/integrations/tailwind/contour-theme.css +71 -13
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +103 -39
- package/dist/wc/ui.mjs +0 -3560
package/dist/wc/content.mjs
CHANGED
|
@@ -1,6 +1,80 @@
|
|
|
1
|
-
import { ContourBase, define, sanitizeHtml, headingTag, formatValue } from './core.mjs';
|
|
1
|
+
import { setHTML, ContourBase, define, sanitizeHtml, headingTag, formatValue, navKey, isRtl, safeHref , warnBadJson, labelText, contourId } from './core.mjs';
|
|
2
2
|
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
|
|
3
3
|
import { wireCopy } from './behaviours.mjs';
|
|
4
|
+
|
|
5
|
+
/* Line numbers are real elements, not a CSS counter: a counter cannot be left
|
|
6
|
+
out of a selection or the copied text. wireCopy drops them before copying.
|
|
7
|
+
A highlight token can span several lines (a multi-line string or comment is
|
|
8
|
+
one <span> whose text holds "\n"). Such a span cannot live inside one grid
|
|
9
|
+
row, so the splitter walks the subtree, breaks at every newline and rebuilds
|
|
10
|
+
each line with its own shallow clone of the spans it touches — the markup is
|
|
11
|
+
preserved per line and no span crosses a row boundary (R24-149). */
|
|
12
|
+
const splitCodeLines = (code) => {
|
|
13
|
+
// Flatten to per-line runs: { chain: [ancestor elements], text } split at "\n".
|
|
14
|
+
const lines = [[]];
|
|
15
|
+
let cur = lines[0];
|
|
16
|
+
const walk = (node, chain) => {
|
|
17
|
+
if (node.nodeType === 3) {
|
|
18
|
+
String(node.textContent || "").split("\n").forEach((p, i) => {
|
|
19
|
+
if (i) { cur = []; lines.push(cur); }
|
|
20
|
+
if (p) cur.push({ chain, text: p });
|
|
21
|
+
});
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (node.nodeType !== 1) return;
|
|
25
|
+
const next = chain.concat(node);
|
|
26
|
+
Array.from(node.childNodes).forEach((c) => walk(c, next));
|
|
27
|
+
};
|
|
28
|
+
Array.from(code.childNodes).forEach((n) => walk(n, []));
|
|
29
|
+
const lastLine = lines[lines.length - 1];
|
|
30
|
+
if (!lastLine.length && lines.length > 1) lines.pop();
|
|
31
|
+
if (!lines.length) return;
|
|
32
|
+
|
|
33
|
+
const frag = document.createDocumentFragment();
|
|
34
|
+
lines.forEach((runs, i) => {
|
|
35
|
+
const lineEl = document.createElement("span");
|
|
36
|
+
lineEl.className = "c-code__line";
|
|
37
|
+
lineEl.setAttribute("data-contour-generated", "line");
|
|
38
|
+
// Reuse a clone while consecutive runs share the same ancestor at a depth.
|
|
39
|
+
const clones = [];
|
|
40
|
+
for (const run of runs) {
|
|
41
|
+
for (let d = 0; d < run.chain.length; d++) {
|
|
42
|
+
if (!clones[d] || clones[d]._contourSrc !== run.chain[d]) {
|
|
43
|
+
const clone = run.chain[d].cloneNode(false); // shallow: attrs/class only
|
|
44
|
+
clone._contourSrc = run.chain[d];
|
|
45
|
+
if (d === 0) lineEl.appendChild(clone);
|
|
46
|
+
else clones[d - 1].appendChild(clone);
|
|
47
|
+
clones[d] = clone;
|
|
48
|
+
clones.length = d + 1; // drop deeper clones from a different parent
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const parent = run.chain.length ? clones[run.chain.length - 1] : lineEl;
|
|
52
|
+
parent.appendChild(document.createTextNode(run.text));
|
|
53
|
+
}
|
|
54
|
+
const num = document.createElement("span");
|
|
55
|
+
num.className = "c-code__line-number";
|
|
56
|
+
num.setAttribute("aria-hidden", "true");
|
|
57
|
+
num.textContent = String(i + 1);
|
|
58
|
+
lineEl.prepend(num);
|
|
59
|
+
frag.appendChild(lineEl);
|
|
60
|
+
});
|
|
61
|
+
code.textContent = "";
|
|
62
|
+
code.appendChild(frag);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const joinCodeLines = (code) => {
|
|
66
|
+
const frag = document.createDocumentFragment();
|
|
67
|
+
Array.from(code.querySelectorAll(".c-code__line")).forEach((l) => {
|
|
68
|
+
Array.from(l.childNodes).forEach((n) => {
|
|
69
|
+
if (n.classList && n.classList.contains("c-code__line-number")) return;
|
|
70
|
+
frag.appendChild(n);
|
|
71
|
+
});
|
|
72
|
+
frag.appendChild(document.createTextNode("\n"));
|
|
73
|
+
});
|
|
74
|
+
code.textContent = "";
|
|
75
|
+
code.appendChild(frag);
|
|
76
|
+
};
|
|
77
|
+
|
|
4
78
|
class ContourCard extends ContourBase {
|
|
5
79
|
static get observed() { return ["title", "variant", "heading"]; }
|
|
6
80
|
static get properties() { return { title: { attribute: "title" }, variant: { attribute: "variant" } }; }
|
|
@@ -26,8 +100,7 @@ class ContourFeature extends ContourBase {
|
|
|
26
100
|
static get properties() { return { index: { attribute: "index" }, title: { attribute: "title" }, body: { attribute: "body" } }; }
|
|
27
101
|
render() {
|
|
28
102
|
this.classList.add("c-feature");
|
|
29
|
-
// `.c-feature`
|
|
30
|
-
// no icon slot, so the index line is the label this block actually carries.
|
|
103
|
+
// `.c-feature` has no icon slot; the index line is its label.
|
|
31
104
|
const index = this.getAttribute("index");
|
|
32
105
|
const title = this.getAttribute("title");
|
|
33
106
|
const body = this.getAttribute("body");
|
|
@@ -56,25 +129,33 @@ class ContourFeature extends ContourBase {
|
|
|
56
129
|
}
|
|
57
130
|
define("contour-feature", ContourFeature);
|
|
58
131
|
class ContourSteps extends ContourBase {
|
|
59
|
-
static get observed() { return ["steps", "current", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "heading"]; }
|
|
132
|
+
static get observed() { return ["steps", "current", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "heading", "cache-key", "no-cache"]; }
|
|
60
133
|
static get properties() { return { steps: { attribute: "steps" }, current: { attribute: "current", type: Number }, src: { attribute: "src" } }; }
|
|
61
134
|
render() {
|
|
62
135
|
this.classList.add("c-steps");
|
|
63
|
-
|
|
136
|
+
// Native list semantics: an <ol> numbers itself and <li> are list items.
|
|
137
|
+
let list = this.querySelector(".c-steps__list");
|
|
138
|
+
if (!list) {
|
|
139
|
+
list = document.createElement("ol");
|
|
140
|
+
list.className = "c-steps__list";
|
|
141
|
+
list.setAttribute("aria-label", this.getAttribute("aria-label") || "Steps");
|
|
142
|
+
this.appendChild(list);
|
|
143
|
+
}
|
|
64
144
|
wireStates(this);
|
|
65
145
|
loadRemote(this, "steps");
|
|
66
146
|
if (renderStates(this, "steps")) return;
|
|
67
147
|
const steps = remoteData(this, "steps");
|
|
68
148
|
const authored = Array.from(this.children).filter((n) => n.classList && n.classList.contains("c-steps__item"));
|
|
149
|
+
// Adopt authored items into the ol so they share its semantics.
|
|
150
|
+
authored.forEach((it) => { if (it.parentNode !== list) list.appendChild(it); });
|
|
69
151
|
if (steps && !authored.length) {
|
|
70
152
|
// Drop previously generated items so a re-render cannot stack a second set.
|
|
71
|
-
Array.from(
|
|
153
|
+
Array.from(list.querySelectorAll(".c-steps__item")).forEach((n) => n.remove());
|
|
72
154
|
try {
|
|
73
155
|
const parsed = JSON.parse(steps);
|
|
74
156
|
parsed.forEach((st, i) => {
|
|
75
|
-
const item = document.createElement("
|
|
157
|
+
const item = document.createElement("li");
|
|
76
158
|
item.className = "c-steps__item";
|
|
77
|
-
item.setAttribute("role", "listitem");
|
|
78
159
|
item.tabIndex = -1;
|
|
79
160
|
const title = typeof st === "string" ? st : st.title;
|
|
80
161
|
const body = typeof st === "string" ? "" : st.body;
|
|
@@ -90,14 +171,13 @@ class ContourSteps extends ContourBase {
|
|
|
90
171
|
p.textContent = body;
|
|
91
172
|
item.appendChild(p);
|
|
92
173
|
}
|
|
93
|
-
|
|
174
|
+
list.appendChild(item);
|
|
94
175
|
});
|
|
95
|
-
} catch (e) {
|
|
176
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
96
177
|
} else if (!steps && !authored.length) {
|
|
97
178
|
renderEmpty(this, "steps");
|
|
98
179
|
}
|
|
99
|
-
// Reflect the current step onto the items
|
|
100
|
-
// a re-render's generated nodes.
|
|
180
|
+
// Reflect the current step onto the items without clobbering generated nodes.
|
|
101
181
|
const attrCurrent = this.getAttribute("current");
|
|
102
182
|
const current = (this._current != null) ? this._current : (attrCurrent != null ? parseInt(attrCurrent, 10) : NaN);
|
|
103
183
|
const items = Array.from(this.querySelectorAll(".c-steps__item"));
|
|
@@ -116,34 +196,7 @@ class ContourSteps extends ContourBase {
|
|
|
116
196
|
this.addEventListener("keydown", (e) => {
|
|
117
197
|
const items = Array.from(this.querySelectorAll(".c-steps__item"));
|
|
118
198
|
if (!items.length) return;
|
|
119
|
-
const
|
|
120
|
-
const idx = items.indexOf(active);
|
|
121
|
-
let next = -1;
|
|
122
|
-
const rtl = (this.getAttribute("dir") || document.documentElement.getAttribute("dir") || "").toLowerCase() === "rtl";
|
|
123
|
-
if (e.key === "ArrowDown") next = idx < 0 ? 0 : Math.min(items.length - 1, idx + 1);
|
|
124
|
-
else if (e.key === "ArrowUp") next = idx < 0 ? 0 : Math.max(0, idx - 1);
|
|
125
|
-
else if (e.key === "ArrowRight") next = rtl ? (idx < 0 ? 0 : Math.max(0, idx - 1)) : (idx < 0 ? 0 : Math.min(items.length - 1, idx + 1));
|
|
126
|
-
else if (e.key === "ArrowLeft") next = rtl ? (idx < 0 ? 0 : Math.min(items.length - 1, idx + 1)) : (idx < 0 ? 0 : Math.max(0, idx - 1));
|
|
127
|
-
else if (e.key === "Home") next = 0;
|
|
128
|
-
else if (e.key === "End") next = items.length - 1;
|
|
129
|
-
if (next >= 0 && next !== idx) {
|
|
130
|
-
e.preventDefault();
|
|
131
|
-
items[next].focus();
|
|
132
|
-
this._current = next;
|
|
133
|
-
items.forEach((it, i) => {
|
|
134
|
-
if (i === next) it.setAttribute("aria-current", "step");
|
|
135
|
-
else it.removeAttribute("aria-current");
|
|
136
|
-
it.tabIndex = i === next ? 0 : -1;
|
|
137
|
-
});
|
|
138
|
-
if (idx >= 0) items[idx].tabIndex = -1;
|
|
139
|
-
const title = items[next].querySelector(".c-steps__title")?.textContent || "";
|
|
140
|
-
this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { index: next, title } }));
|
|
141
|
-
}
|
|
142
|
-
if ((e.key === "Enter" || e.key === " ") && idx >= 0) {
|
|
143
|
-
e.preventDefault();
|
|
144
|
-
const title = items[idx].querySelector(".c-steps__title")?.textContent || "";
|
|
145
|
-
this.dispatchEvent(new CustomEvent("contour:step-activate", { bubbles: true, composed: true, detail: { index: idx, title } }));
|
|
146
|
-
}
|
|
199
|
+
navKey(e, items, { wrap: false, homeEnd: true, rtl: isRtl(this), onNavigate: (i) => { this._current = i; items.forEach((it, j) => { if (j === i) it.setAttribute("aria-current", "step"); else it.removeAttribute("aria-current"); it.tabIndex = j === i ? 0 : -1; }); const title = items[i].querySelector(".c-steps__title")?.textContent || ""; this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { index: i, title } })); }, onKey: () => { if (e.key === "Enter" || e.key === " ") { const idx = items.indexOf(document.activeElement); const title = document.activeElement.querySelector(".c-steps__title")?.textContent || ""; this.dispatchEvent(new CustomEvent("contour:step-activate", { bubbles: true, composed: true, detail: { index: idx, title } })); } } });
|
|
147
200
|
});
|
|
148
201
|
this.addEventListener("click", (e) => {
|
|
149
202
|
const item = e.target && e.target.closest ? e.target.closest(".c-steps__item") : null;
|
|
@@ -171,12 +224,12 @@ class ContourLink extends ContourBase {
|
|
|
171
224
|
this.classList.add("c-link");
|
|
172
225
|
const href = this.getAttribute("href");
|
|
173
226
|
const label = this.getAttribute("label");
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
if (prevLink) prevLink.remove();
|
|
227
|
+
// Remove only generated anchors; an authored-only link renders nothing.
|
|
228
|
+
Array.from(this.querySelectorAll("a[data-contour-generated]")).forEach((n) => n.remove());
|
|
177
229
|
if (href && label) {
|
|
178
230
|
const a = document.createElement("a");
|
|
179
|
-
a.
|
|
231
|
+
a.dataset.contourGenerated = "";
|
|
232
|
+
a.href = safeHref(href);
|
|
180
233
|
a.textContent = label;
|
|
181
234
|
const ariaLabel = this.getAttribute("aria-label");
|
|
182
235
|
if (ariaLabel) a.setAttribute("aria-label", ariaLabel);
|
|
@@ -220,7 +273,12 @@ class ContourSectionHead extends ContourBase {
|
|
|
220
273
|
if (!this.querySelector(".c-icon-badge")) {
|
|
221
274
|
const badge = document.createElement("div");
|
|
222
275
|
badge.className = "c-icon-badge";
|
|
223
|
-
|
|
276
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
277
|
+
svg.setAttribute("aria-hidden", "true");
|
|
278
|
+
const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
|
|
279
|
+
use.setAttribute("href", "#i-crosshair");
|
|
280
|
+
svg.appendChild(use);
|
|
281
|
+
badge.replaceChildren(svg);
|
|
224
282
|
this.prepend(badge);
|
|
225
283
|
}
|
|
226
284
|
// content wrapper
|
|
@@ -254,29 +312,42 @@ class ContourDiff extends ContourBase {
|
|
|
254
312
|
render() {
|
|
255
313
|
this.classList.add("c-diff");
|
|
256
314
|
this.setAttribute("role", "group");
|
|
257
|
-
this.setAttribute("aria-label", "Diff");
|
|
258
|
-
// The block is a list of lines, not two panes: `.c-diff__line` carries
|
|
259
|
-
//
|
|
260
|
-
// two states it defines. A removed line and an added line are what a
|
|
261
|
-
// before/after pair actually becomes in a diff.
|
|
315
|
+
this.setAttribute("aria-label", labelText(this, "diff", "Diff"));
|
|
316
|
+
// The block is a list of lines, not two panes: each `.c-diff__line` carries
|
|
317
|
+
// a sign, number and text, with `--add`/`--del` as its only states.
|
|
262
318
|
Array.from(this.querySelectorAll(".c-diff__line")).forEach((n) => n.remove());
|
|
263
|
-
const line = (kind, sign, text) => {
|
|
319
|
+
const line = (kind, sign, text, num) => {
|
|
264
320
|
const el = document.createElement("div");
|
|
265
321
|
el.className = kind ? `c-diff__line c-diff__line--${kind}` : "c-diff__line";
|
|
266
322
|
el.setAttribute("role", "listitem");
|
|
267
323
|
el.setAttribute("tabindex", "0");
|
|
324
|
+
// Emit sign+number+text (3 children matching the grid).
|
|
268
325
|
const s = document.createElement("span");
|
|
269
326
|
s.className = "c-diff__sign";
|
|
270
327
|
s.textContent = sign;
|
|
328
|
+
const n = document.createElement("span");
|
|
329
|
+
n.className = "c-diff__num";
|
|
330
|
+
n.setAttribute("aria-hidden", "true");
|
|
331
|
+
n.textContent = String(num || "");
|
|
271
332
|
const code = document.createElement("span");
|
|
272
333
|
code.textContent = text;
|
|
273
|
-
el.append(s, code);
|
|
334
|
+
el.append(s, n, code);
|
|
274
335
|
return el;
|
|
275
336
|
};
|
|
276
337
|
const before = this.getAttribute("before");
|
|
277
338
|
const after = this.getAttribute("after");
|
|
278
|
-
|
|
279
|
-
|
|
339
|
+
// Split before/after on newlines so multi-line values render as separate lines.
|
|
340
|
+
let lineNum = 1;
|
|
341
|
+
if (before) {
|
|
342
|
+
String(before).split("\n").forEach((l) => {
|
|
343
|
+
this.appendChild(line("del", "−", l, lineNum++));
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
if (after) {
|
|
347
|
+
String(after).split("\n").forEach((l) => {
|
|
348
|
+
this.appendChild(line("add", "+", l, lineNum++));
|
|
349
|
+
});
|
|
350
|
+
}
|
|
280
351
|
}
|
|
281
352
|
enhance() {
|
|
282
353
|
if (this._wiredDiff) return;
|
|
@@ -306,15 +377,17 @@ class ContourDoDont extends ContourBase {
|
|
|
306
377
|
render() {
|
|
307
378
|
this.classList.add("c-do-dont");
|
|
308
379
|
this.setAttribute("role", "group");
|
|
309
|
-
this.setAttribute("aria-label", "Do and don't");
|
|
310
|
-
// An item is one element with
|
|
311
|
-
//
|
|
312
|
-
// `__do` or `__dont` element in the system.
|
|
380
|
+
this.setAttribute("aria-label", labelText(this, "do-and-dont", "Do and don't"));
|
|
381
|
+
// An item is one element with a state modifier (`__item--do`/`--dont`) and
|
|
382
|
+
// a `__label`; there is no `__do`/`__dont` element.
|
|
313
383
|
Array.from(this.querySelectorAll(".c-do-dont__item")).forEach((n) => n.remove());
|
|
384
|
+
// role + tabindex are set in render so they survive re-render (enhance() runs
|
|
385
|
+
// once); items are keyboard-activated, so they are buttons, not listitems.
|
|
314
386
|
const item = (kind, word, text) => {
|
|
315
387
|
const el = document.createElement("div");
|
|
316
388
|
el.className = `c-do-dont__item c-do-dont__item--${kind}`;
|
|
317
|
-
el.setAttribute("role", "
|
|
389
|
+
el.setAttribute("role", "button");
|
|
390
|
+
el.setAttribute("tabindex", "0");
|
|
318
391
|
const label = document.createElement("p");
|
|
319
392
|
label.className = "c-do-dont__label";
|
|
320
393
|
label.textContent = word;
|
|
@@ -366,7 +439,10 @@ class ContourFlag extends ContourBase {
|
|
|
366
439
|
if (variant) this.classList.add("c-flag--" + variant);
|
|
367
440
|
const label = this.getAttribute("label");
|
|
368
441
|
if (label) {
|
|
369
|
-
|
|
442
|
+
// Update the text node, not textContent, so authored children survive.
|
|
443
|
+
let text = Array.from(this.childNodes).find((n) => n.nodeType === 3);
|
|
444
|
+
if (!text) { text = document.createTextNode(""); this.appendChild(text); }
|
|
445
|
+
text.nodeValue = label;
|
|
370
446
|
}
|
|
371
447
|
}
|
|
372
448
|
}
|
|
@@ -388,8 +464,8 @@ class ContourInstallFull extends ContourBase {
|
|
|
388
464
|
const btn = document.createElement("button");
|
|
389
465
|
btn.className = "c-btn c-btn--ghost c-btn--sm c-install__copy";
|
|
390
466
|
btn.type = "button";
|
|
391
|
-
btn.setAttribute("aria-label", "Copy command");
|
|
392
|
-
btn.textContent = "Copy";
|
|
467
|
+
btn.setAttribute("aria-label", labelText(this, "copy-command", "Copy command"));
|
|
468
|
+
btn.textContent = labelText(this, "copy", "Copy");
|
|
393
469
|
return btn;
|
|
394
470
|
});
|
|
395
471
|
} else {
|
|
@@ -399,9 +475,7 @@ class ContourInstallFull extends ContourBase {
|
|
|
399
475
|
}
|
|
400
476
|
}
|
|
401
477
|
enhance() {
|
|
402
|
-
// Interaction lives in behaviours.mjs
|
|
403
|
-
// One implementation, so the two layers cannot drift apart again: the shadow
|
|
404
|
-
// copy queried its root for slotted nodes, found none, and wired nothing.
|
|
478
|
+
// Interaction lives in behaviours.mjs so the shadow wrappers share it.
|
|
405
479
|
wireCopy(this);
|
|
406
480
|
}
|
|
407
481
|
}
|
|
@@ -422,8 +496,8 @@ class ContourTestimonialFull extends ContourBase {
|
|
|
422
496
|
const name = this.getAttribute("name");
|
|
423
497
|
const role = this.getAttribute("role");
|
|
424
498
|
if (name) {
|
|
425
|
-
const by = this.ensure(".c-testimonial__byline", () => { const el = document.createElement("
|
|
426
|
-
const n = by.querySelector(".c-testimonial__name") || (() => { const el = document.createElement("
|
|
499
|
+
const by = this.ensure(".c-testimonial__byline", () => { const el = document.createElement("figcaption"); el.className = "c-testimonial__byline"; return el; });
|
|
500
|
+
const n = by.querySelector(".c-testimonial__name") || (() => { const el = document.createElement("cite"); el.className = "c-testimonial__name"; by.appendChild(el); return el; })();
|
|
427
501
|
n.className = "c-testimonial__name";
|
|
428
502
|
n.textContent = name;
|
|
429
503
|
if (role) {
|
|
@@ -442,7 +516,7 @@ class ContourTestimonialFull extends ContourBase {
|
|
|
442
516
|
}
|
|
443
517
|
define("contour-testimonial", ContourTestimonialFull);
|
|
444
518
|
class ContourShowcaseFull extends ContourBase {
|
|
445
|
-
static get observed() { return ["title", "text", "media", "reverse", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "heading"]; }
|
|
519
|
+
static get observed() { return ["title", "text", "media", "reverse", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "heading", "cache-key", "no-cache"]; }
|
|
446
520
|
static get properties() { return { title: { attribute: "title" }, text: { attribute: "text" }, media: { attribute: "media" }, reverse: { attribute: "reverse" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
447
521
|
render() {
|
|
448
522
|
this.classList.add("c-showcase");
|
|
@@ -459,9 +533,21 @@ class ContourShowcaseFull extends ContourBase {
|
|
|
459
533
|
const text = this.getAttribute("text");
|
|
460
534
|
const media = this.getAttribute("media");
|
|
461
535
|
if (media) {
|
|
462
|
-
|
|
463
|
-
m.
|
|
464
|
-
if (
|
|
536
|
+
// A figure with a figcaption is the native shape for an image + caption.
|
|
537
|
+
const m = this.ensure(".c-showcase__media", () => { const el = document.createElement("figure"); el.className = "c-showcase__media"; return el; });
|
|
538
|
+
if (/^https?:\/\/|^\/|^\.\/|\.(png|jpg|jpeg|svg|webp|gif|avif)$/i.test(media.trim())) {
|
|
539
|
+
let img = m.querySelector("img");
|
|
540
|
+
if (!img) { img = document.createElement("img"); m.appendChild(img); }
|
|
541
|
+
img.src = media.trim();
|
|
542
|
+
img.alt = title || "";
|
|
543
|
+
} else {
|
|
544
|
+
setHTML(m, sanitizeHtml(media));
|
|
545
|
+
}
|
|
546
|
+
if (title) {
|
|
547
|
+
let cap = m.querySelector(".c-showcase__caption");
|
|
548
|
+
if (!cap) { cap = document.createElement("figcaption"); cap.className = "c-showcase__caption"; m.appendChild(cap); }
|
|
549
|
+
cap.textContent = title;
|
|
550
|
+
}
|
|
465
551
|
} else {
|
|
466
552
|
const m = this.querySelector(".c-showcase__media");
|
|
467
553
|
if (m) m.remove();
|
|
@@ -486,13 +572,13 @@ class ContourShowcaseFull extends ContourBase {
|
|
|
486
572
|
try {
|
|
487
573
|
const parsed = JSON.parse(items);
|
|
488
574
|
const l = this.ensure(".c-showcase__list", () => { const el = document.createElement("ul"); el.className = "c-showcase__list"; return el; });
|
|
489
|
-
l.
|
|
575
|
+
l.replaceChildren();
|
|
490
576
|
parsed.forEach((it) => {
|
|
491
577
|
const li = document.createElement("li");
|
|
492
|
-
li.textContent = typeof it === "string" ? it : it.label;
|
|
578
|
+
li.textContent = typeof it === "string" ? it : (it.label || it.title || "");
|
|
493
579
|
l.appendChild(li);
|
|
494
580
|
});
|
|
495
|
-
} catch (e) {
|
|
581
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
496
582
|
} else if (!items && !authored.length && !title && !text && !media) {
|
|
497
583
|
renderEmpty(this, "showcase");
|
|
498
584
|
} else if (!items && ul) {
|
|
@@ -509,24 +595,65 @@ class ContourShowcaseFull extends ContourBase {
|
|
|
509
595
|
this.dispatchEvent(new CustomEvent("contour:showcase-activate", { bubbles: true, composed: true, detail: { title } }));
|
|
510
596
|
}
|
|
511
597
|
});
|
|
598
|
+
this.addEventListener("keydown", (e) => {
|
|
599
|
+
// Authored interactive children own Enter/Space; only act on other targets.
|
|
600
|
+
const target = e.target && e.target.closest ? e.target.closest("button, a, input, select, textarea, [role='button'], [role='link'], [role='checkbox'], [role='menuitem'], [role='option'], [role='tab']") : null;
|
|
601
|
+
if (target && this.contains(target)) return;
|
|
602
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
603
|
+
const media = this.querySelector(".c-showcase__media");
|
|
604
|
+
if (media) {
|
|
605
|
+
e.preventDefault();
|
|
606
|
+
const title = this.getAttribute("title") || "";
|
|
607
|
+
this.dispatchEvent(new CustomEvent("contour:showcase-activate", { bubbles: true, composed: true, detail: { title } }));
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
});
|
|
512
611
|
}
|
|
513
612
|
}
|
|
514
613
|
define("contour-showcase", ContourShowcaseFull);
|
|
515
614
|
class ContourPricingFull extends ContourBase {
|
|
516
615
|
static get observed() { return []; }
|
|
517
616
|
render() {
|
|
518
|
-
// `.c-pricing` is the grid;
|
|
519
|
-
// A pricing element that scaffolded its own label invented a name no rule
|
|
520
|
-
// defines, so the grid holds its children and stays a container.
|
|
617
|
+
// `.c-pricing` is the grid; its parts live on `.c-price`. It stays a container.
|
|
521
618
|
this.classList.add("c-pricing");
|
|
522
619
|
}
|
|
523
620
|
}
|
|
524
621
|
define("contour-pricing", ContourPricingFull);
|
|
525
622
|
class ContourRecipeFull extends ContourBase {
|
|
526
|
-
static get observed() { return ["title", "body", "canvas", "heading"]; }
|
|
527
|
-
static get properties() { return { title: { attribute: "title" }, body: { attribute: "body" }, canvas: { attribute: "canvas" } }; }
|
|
623
|
+
static get observed() { return ["title", "body", "canvas", "heading", "url", "tags", "head", "index"]; }
|
|
624
|
+
static get properties() { return { title: { attribute: "title" }, body: { attribute: "body" }, canvas: { attribute: "canvas" }, url: { attribute: "url" }, tags: { attribute: "tags" }, head: { attribute: "head" }, index: { attribute: "index" } }; }
|
|
528
625
|
render() {
|
|
529
626
|
this.classList.add("c-recipe");
|
|
627
|
+
// Frame chrome (browser mockup): opt-in via `url` attribute.
|
|
628
|
+
const url = this.getAttribute("url");
|
|
629
|
+
let frame = this.querySelector(".c-recipe__frame");
|
|
630
|
+
if (url) {
|
|
631
|
+
if (!frame) {
|
|
632
|
+
frame = document.createElement("div");
|
|
633
|
+
frame.className = "c-recipe__frame";
|
|
634
|
+
const bar = document.createElement("div");
|
|
635
|
+
bar.className = "c-recipe__frame-bar";
|
|
636
|
+
for (let i = 0; i < 3; i++) { const dot = document.createElement("span"); dot.className = "c-recipe__frame-dot"; bar.appendChild(dot); }
|
|
637
|
+
const urlEl = document.createElement("span");
|
|
638
|
+
urlEl.className = "c-recipe__frame-url";
|
|
639
|
+
bar.appendChild(urlEl);
|
|
640
|
+
frame.appendChild(bar);
|
|
641
|
+
this.prepend(frame);
|
|
642
|
+
}
|
|
643
|
+
const urlEl = frame.querySelector(".c-recipe__frame-url");
|
|
644
|
+
if (urlEl) urlEl.textContent = url;
|
|
645
|
+
} else if (frame) {
|
|
646
|
+
frame.remove();
|
|
647
|
+
}
|
|
648
|
+
// Head (category/eyebrow above title).
|
|
649
|
+
const head = this.getAttribute("head");
|
|
650
|
+
if (head) {
|
|
651
|
+
const h = this.ensure(".c-recipe__head", () => { const el = document.createElement("div"); el.className = "c-recipe__head"; return el; });
|
|
652
|
+
h.textContent = head;
|
|
653
|
+
} else {
|
|
654
|
+
const h = this.querySelector(".c-recipe__head");
|
|
655
|
+
if (h) h.remove();
|
|
656
|
+
}
|
|
530
657
|
const title = this.getAttribute("title");
|
|
531
658
|
if (title) {
|
|
532
659
|
const t = this.ensure(".c-recipe__title", () => { const el = document.createElement(headingTag(this, "h3")); el.className = "c-recipe__title"; return el; });
|
|
@@ -535,6 +662,15 @@ class ContourRecipeFull extends ContourBase {
|
|
|
535
662
|
const t = this.querySelector(".c-recipe__title");
|
|
536
663
|
if (t) t.remove();
|
|
537
664
|
}
|
|
665
|
+
// Index (recipe number, e.g. "01").
|
|
666
|
+
const index = this.getAttribute("index");
|
|
667
|
+
if (index) {
|
|
668
|
+
const idx = this.ensure(".c-recipe__index", () => { const el = document.createElement("span"); el.className = "c-recipe__index"; return el; });
|
|
669
|
+
idx.textContent = index;
|
|
670
|
+
} else {
|
|
671
|
+
const idx = this.querySelector(".c-recipe__index");
|
|
672
|
+
if (idx) idx.remove();
|
|
673
|
+
}
|
|
538
674
|
const body = this.getAttribute("body");
|
|
539
675
|
if (body) {
|
|
540
676
|
const b = this.ensure(".c-recipe__desc", () => { const el = document.createElement("p"); el.className = "c-recipe__desc"; return el; });
|
|
@@ -543,10 +679,31 @@ class ContourRecipeFull extends ContourBase {
|
|
|
543
679
|
const b = this.querySelector(".c-recipe__desc");
|
|
544
680
|
if (b) b.remove();
|
|
545
681
|
}
|
|
682
|
+
// Tags (comma-separated list).
|
|
683
|
+
const tags = this.getAttribute("tags");
|
|
684
|
+
if (tags) {
|
|
685
|
+
const t = this.ensure(".c-recipe__tags", () => { const el = document.createElement("div"); el.className = "c-recipe__tags"; return el; });
|
|
686
|
+
t.innerHTML = "";
|
|
687
|
+
tags.split(",").map((s) => s.trim()).filter(Boolean).forEach((tag) => {
|
|
688
|
+
const span = document.createElement("span");
|
|
689
|
+
span.textContent = tag;
|
|
690
|
+
t.appendChild(span);
|
|
691
|
+
});
|
|
692
|
+
} else {
|
|
693
|
+
const t = this.querySelector(".c-recipe__tags");
|
|
694
|
+
if (t) t.remove();
|
|
695
|
+
}
|
|
546
696
|
const canvas = this.getAttribute("canvas");
|
|
547
697
|
if (canvas) {
|
|
548
698
|
const c = this.ensure(".c-recipe__canvas", () => { const el = document.createElement("div"); el.className = "c-recipe__canvas"; return el; });
|
|
549
|
-
|
|
699
|
+
if (/^https?:\/\/|^\/|^\.\/|\.(png|jpg|jpeg|svg|webp|gif|avif)$/i.test(canvas.trim())) {
|
|
700
|
+
let img = c.querySelector("img");
|
|
701
|
+
if (!img) { img = document.createElement("img"); c.appendChild(img); }
|
|
702
|
+
img.src = canvas.trim();
|
|
703
|
+
img.alt = "";
|
|
704
|
+
} else {
|
|
705
|
+
setHTML(c, sanitizeHtml(canvas));
|
|
706
|
+
}
|
|
550
707
|
} else {
|
|
551
708
|
const c = this.querySelector(".c-recipe__canvas");
|
|
552
709
|
if (c) c.remove();
|
|
@@ -556,21 +713,14 @@ class ContourRecipeFull extends ContourBase {
|
|
|
556
713
|
define("contour-recipe", ContourRecipeFull);
|
|
557
714
|
class ContourLogosFull extends ContourBase {
|
|
558
715
|
static get observed() { return []; }
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
const span = document.createElement("span");
|
|
564
|
-
span.className = "c-logos__item";
|
|
565
|
-
span.textContent = name;
|
|
566
|
-
this.appendChild(span);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
716
|
+
render() {
|
|
717
|
+
this.classList.add("c-logos");
|
|
718
|
+
// No invented brands — an empty logo wall renders nothing.
|
|
719
|
+
}
|
|
570
720
|
}
|
|
571
721
|
define("contour-logos", ContourLogosFull);
|
|
572
722
|
class ContourLandingFeaturesFull extends ContourBase {
|
|
573
|
-
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
723
|
+
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
574
724
|
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
575
725
|
render() {
|
|
576
726
|
this.classList.add("c-landing-features");
|
|
@@ -589,7 +739,12 @@ class ContourLandingFeaturesFull extends ContourBase {
|
|
|
589
739
|
if (it.icon) {
|
|
590
740
|
const ic = document.createElement("span");
|
|
591
741
|
ic.className = "c-landing-features__icon";
|
|
592
|
-
|
|
742
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
743
|
+
svg.setAttribute("aria-hidden", "true");
|
|
744
|
+
const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
|
|
745
|
+
use.setAttribute("href", "#" + String(it.icon).replace(/[^a-zA-Z0-9_-]/g, ""));
|
|
746
|
+
svg.appendChild(use);
|
|
747
|
+
ic.appendChild(svg);
|
|
593
748
|
item.appendChild(ic);
|
|
594
749
|
}
|
|
595
750
|
if (it.title) {
|
|
@@ -606,7 +761,7 @@ class ContourLandingFeaturesFull extends ContourBase {
|
|
|
606
761
|
}
|
|
607
762
|
this.appendChild(item);
|
|
608
763
|
});
|
|
609
|
-
} catch (e) {
|
|
764
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
610
765
|
} else if (!items && !authored.length) {
|
|
611
766
|
this.querySelectorAll(".c-landing-features__item").forEach((el) => el.remove());
|
|
612
767
|
renderEmpty(this, "landing-features");
|
|
@@ -615,13 +770,44 @@ class ContourLandingFeaturesFull extends ContourBase {
|
|
|
615
770
|
}
|
|
616
771
|
define("contour-landing-features", ContourLandingFeaturesFull);
|
|
617
772
|
class ContourLandingHeroFull extends ContourBase {
|
|
618
|
-
static get observed() { return ["actions", "title", "text", "heading"]; }
|
|
619
|
-
static get properties() { return { actions: { attribute: "actions" }, title: { attribute: "title" }, text: { attribute: "text" } }; }
|
|
773
|
+
static get observed() { return ["actions", "title", "text", "heading", "preview"]; }
|
|
774
|
+
static get properties() { return { actions: { attribute: "actions" }, title: { attribute: "title" }, text: { attribute: "text" }, preview: { attribute: "preview" } }; }
|
|
620
775
|
render() {
|
|
621
776
|
this.classList.add("c-landing-hero");
|
|
777
|
+
// Preview mockup (product screenshot): opt-in via `preview` attribute.
|
|
778
|
+
const preview = this.getAttribute("preview");
|
|
779
|
+
let pv = this.querySelector(".c-landing-hero__preview");
|
|
780
|
+
if (preview) {
|
|
781
|
+
if (!pv) {
|
|
782
|
+
pv = document.createElement("div");
|
|
783
|
+
pv.className = "c-landing-hero__preview";
|
|
784
|
+
const bar = document.createElement("div");
|
|
785
|
+
bar.className = "c-landing-hero__preview-bar";
|
|
786
|
+
for (let i = 0; i < 3; i++) { const dot = document.createElement("span"); dot.className = "c-landing-hero__preview-dot"; bar.appendChild(dot); }
|
|
787
|
+
const body = document.createElement("div");
|
|
788
|
+
body.className = "c-landing-hero__preview-body";
|
|
789
|
+
pv.appendChild(bar);
|
|
790
|
+
pv.appendChild(body);
|
|
791
|
+
this.appendChild(pv);
|
|
792
|
+
}
|
|
793
|
+
const body = pv.querySelector(".c-landing-hero__preview-body");
|
|
794
|
+
if (body) {
|
|
795
|
+
if (/^https?:\/\/|^\/|^\.\/|\.(png|jpg|jpeg|svg|webp|gif|avif)$/i.test(preview.trim())) {
|
|
796
|
+
body.innerHTML = "";
|
|
797
|
+
const img = document.createElement("img");
|
|
798
|
+
img.src = preview.trim();
|
|
799
|
+
img.alt = "";
|
|
800
|
+
body.appendChild(img);
|
|
801
|
+
} else {
|
|
802
|
+
setHTML(body, sanitizeHtml(preview));
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
} else if (pv) {
|
|
806
|
+
pv.remove();
|
|
807
|
+
}
|
|
622
808
|
const title = this.getAttribute("title");
|
|
623
809
|
if (title) {
|
|
624
|
-
const t = this.ensure(".c-landing-hero__title", () => { const el = document.createElement(headingTag(this, "
|
|
810
|
+
const t = this.ensure(".c-landing-hero__title", () => { const el = document.createElement(headingTag(this, "h2")); el.className = "c-landing-hero__title"; return el; });
|
|
625
811
|
t.textContent = title;
|
|
626
812
|
}
|
|
627
813
|
const text = this.getAttribute("text");
|
|
@@ -634,7 +820,24 @@ class ContourLandingHeroFull extends ContourBase {
|
|
|
634
820
|
const authored = a ? Array.from(a.children) : [];
|
|
635
821
|
if (actions && !authored.length) {
|
|
636
822
|
const el = this.ensure(".c-landing-hero__actions", () => { const e = document.createElement("div"); e.className = "c-landing-hero__actions"; return e; });
|
|
637
|
-
|
|
823
|
+
try {
|
|
824
|
+
const parsed = JSON.parse(actions);
|
|
825
|
+
if (Array.isArray(parsed)) {
|
|
826
|
+
el.replaceChildren();
|
|
827
|
+
parsed.forEach((act) => {
|
|
828
|
+
const btn = document.createElement(act.href ? "a" : "button");
|
|
829
|
+
btn.className = "c-btn" + (act.primary ? " c-btn--primary" : "");
|
|
830
|
+
if (act.href) btn.href = safeHref(act.href);
|
|
831
|
+
else btn.type = "button";
|
|
832
|
+
btn.textContent = act.label || act.text || "";
|
|
833
|
+
el.appendChild(btn);
|
|
834
|
+
});
|
|
835
|
+
} else {
|
|
836
|
+
setHTML(el, sanitizeHtml(actions));
|
|
837
|
+
}
|
|
838
|
+
} catch (_) {
|
|
839
|
+
setHTML(el, sanitizeHtml(actions));
|
|
840
|
+
}
|
|
638
841
|
} else if (!actions && a && !authored.length) {
|
|
639
842
|
a.remove();
|
|
640
843
|
}
|
|
@@ -652,7 +855,18 @@ class ContourPriceFull extends ContourBase {
|
|
|
652
855
|
render() {
|
|
653
856
|
this.classList.add("c-price");
|
|
654
857
|
const value = this.getAttribute("value");
|
|
655
|
-
|
|
858
|
+
// Format into a generated .c-price__amount span, preserving authored parts.
|
|
859
|
+
let amount = this.querySelector(".c-price__amount");
|
|
860
|
+
if (value) {
|
|
861
|
+
if (!amount) {
|
|
862
|
+
amount = document.createElement("span");
|
|
863
|
+
amount.className = "c-price__amount";
|
|
864
|
+
this.appendChild(amount);
|
|
865
|
+
}
|
|
866
|
+
amount.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
|
|
867
|
+
} else if (amount) {
|
|
868
|
+
amount.remove();
|
|
869
|
+
}
|
|
656
870
|
}
|
|
657
871
|
}
|
|
658
872
|
define("contour-price", ContourPriceFull);
|
|
@@ -662,10 +876,12 @@ class ContourProseFull extends ContourBase {
|
|
|
662
876
|
}
|
|
663
877
|
define("contour-prose", ContourProseFull);
|
|
664
878
|
class ContourPanel extends ContourBase {
|
|
665
|
-
static get observed() { return ["title", "subtitle", "status", "heading", "collapsible", "collapsed"]; }
|
|
666
|
-
static get properties() { return { title: { attribute: "title" }, subtitle: { attribute: "subtitle" }, status: { attribute: "status" }, collapsible: { attribute: "collapsible", type: Boolean }, collapsed: { attribute: "collapsed", type: Boolean } }; }
|
|
879
|
+
static get observed() { return ["title", "subtitle", "status", "heading", "collapsible", "collapsed", "flush"]; }
|
|
880
|
+
static get properties() { return { title: { attribute: "title" }, subtitle: { attribute: "subtitle" }, status: { attribute: "status" }, collapsible: { attribute: "collapsible", type: Boolean }, collapsed: { attribute: "collapsed", type: Boolean }, flush: { attribute: "flush", type: Boolean } }; }
|
|
667
881
|
render() {
|
|
668
882
|
this.classList.add("c-panel");
|
|
883
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
884
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Panel");
|
|
669
885
|
const title = this.getAttribute("title");
|
|
670
886
|
const subtitle = this.getAttribute("subtitle");
|
|
671
887
|
const status = this.getAttribute("status");
|
|
@@ -686,6 +902,8 @@ class ContourPanel extends ContourBase {
|
|
|
686
902
|
}
|
|
687
903
|
if (status) {
|
|
688
904
|
const st = this.ensure(".c-panel__status", () => { const el = document.createElement("span"); el.className = "c-panel__status"; return el; });
|
|
905
|
+
Array.from(st.classList).forEach((c) => { if (c.startsWith("c-panel__status--")) st.classList.remove(c); });
|
|
906
|
+
if (status === "error" || status === "live") st.classList.add("c-panel__status--" + status);
|
|
689
907
|
st.textContent = status;
|
|
690
908
|
} else {
|
|
691
909
|
const st = this.querySelector(".c-panel__status");
|
|
@@ -698,18 +916,19 @@ class ContourPanel extends ContourBase {
|
|
|
698
916
|
btn = document.createElement("button");
|
|
699
917
|
btn.type = "button";
|
|
700
918
|
btn.className = "c-panel__collapse c-btn c-btn--ghost c-btn--sm";
|
|
701
|
-
btn.setAttribute("aria-label", "Toggle panel");
|
|
702
|
-
|
|
919
|
+
btn.setAttribute("aria-label", labelText(this, "collapse", "Toggle panel"));
|
|
920
|
+
// R24-134: SVG glyph instead of text arrows.
|
|
921
|
+
setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16"><use href="#i-chevron-down" /></svg>');
|
|
703
922
|
this.appendChild(btn);
|
|
704
923
|
}
|
|
705
924
|
if (this.hasAttribute("collapsed")) {
|
|
706
925
|
this.classList.add("c-panel--collapsed");
|
|
707
926
|
btn.setAttribute("aria-expanded", "false");
|
|
708
|
-
btn
|
|
927
|
+
setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16"><use href="#i-chevron-right" /></svg>');
|
|
709
928
|
} else {
|
|
710
929
|
this.classList.remove("c-panel--collapsed");
|
|
711
930
|
btn.setAttribute("aria-expanded", "true");
|
|
712
|
-
btn
|
|
931
|
+
setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16"><use href="#i-chevron-down" /></svg>');
|
|
713
932
|
}
|
|
714
933
|
} else {
|
|
715
934
|
const btn = this.querySelector(".c-panel__collapse");
|
|
@@ -718,10 +937,14 @@ class ContourPanel extends ContourBase {
|
|
|
718
937
|
}
|
|
719
938
|
// Wrap authored content in a body so it picks up the panel's padding.
|
|
720
939
|
const body = this.ensure(".c-panel__body", () => { const el = document.createElement("div"); el.className = "c-panel__body"; return el; });
|
|
940
|
+
body.classList.toggle("c-panel__body--flush", this.hasAttribute("flush"));
|
|
721
941
|
const head = this.querySelector(".c-panel__head");
|
|
942
|
+
// Exclude the collapse toggle from the body wrap so it stays visible when collapsed.
|
|
943
|
+
const collapseBtn = this.querySelector(".c-panel__collapse");
|
|
722
944
|
Array.from(this.childNodes).forEach((n) => {
|
|
723
945
|
if (n === body || n === head) return;
|
|
724
946
|
if (n.nodeType === 1 && (n.classList.contains("c-panel__title") || n.classList.contains("c-panel__subtitle") || n.classList.contains("c-panel__status"))) return;
|
|
947
|
+
if (n === collapseBtn) return;
|
|
725
948
|
body.appendChild(n);
|
|
726
949
|
});
|
|
727
950
|
if (!body.parentNode) this.appendChild(body);
|
|
@@ -765,7 +988,7 @@ class ContourCta extends ContourBase {
|
|
|
765
988
|
if (p) p.remove();
|
|
766
989
|
}
|
|
767
990
|
const actions = this.getAttribute("actions");
|
|
768
|
-
//
|
|
991
|
+
// Remove only the generated actions wrap, not authored actions.
|
|
769
992
|
const prevWrap = this.querySelector(".c-cta__actions");
|
|
770
993
|
if (prevWrap) prevWrap.remove();
|
|
771
994
|
if (actions) {
|
|
@@ -773,22 +996,31 @@ class ContourCta extends ContourBase {
|
|
|
773
996
|
const parsed = JSON.parse(actions);
|
|
774
997
|
const wrap = document.createElement("div");
|
|
775
998
|
wrap.className = "c-cta__actions";
|
|
999
|
+
// Support {label, href, primary} like landing-hero.
|
|
1000
|
+
let hasPrimary = false;
|
|
776
1001
|
parsed.forEach((a) => {
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
1002
|
+
const label = typeof a === "string" ? a : (a.label || a);
|
|
1003
|
+
const href = typeof a === "object" && a ? a.href : null;
|
|
1004
|
+
const primary = typeof a === "object" && a ? a.primary : false;
|
|
1005
|
+
// Single-primary signal: first primary wins, rest are secondary.
|
|
1006
|
+
const isPrimary = primary && !hasPrimary;
|
|
1007
|
+
if (isPrimary) hasPrimary = true;
|
|
1008
|
+
const btn = document.createElement(href ? "a" : "button");
|
|
1009
|
+
btn.className = isPrimary ? "c-btn c-btn--primary" : "c-btn c-btn--ghost";
|
|
1010
|
+
if (href) { btn.href = safeHref(href); btn.setAttribute("role", "button"); }
|
|
1011
|
+
else btn.type = "button";
|
|
1012
|
+
btn.textContent = label;
|
|
781
1013
|
wrap.appendChild(btn);
|
|
782
1014
|
});
|
|
783
1015
|
this.appendChild(wrap);
|
|
784
|
-
} catch (e) {
|
|
1016
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
785
1017
|
}
|
|
786
1018
|
}
|
|
787
1019
|
}
|
|
788
1020
|
define("contour-cta", ContourCta);
|
|
789
1021
|
class ContourCode extends ContourBase {
|
|
790
|
-
static get observed() { return ["title", "copyable"]; }
|
|
791
|
-
static get properties() { return { title: { attribute: "title" }, copyable: { attribute: "copyable", type: Boolean } }; }
|
|
1022
|
+
static get observed() { return ["title", "copyable", "numbered"]; }
|
|
1023
|
+
static get properties() { return { title: { attribute: "title" }, copyable: { attribute: "copyable", type: Boolean }, numbered: { attribute: "numbered", type: Boolean } }; }
|
|
792
1024
|
render() {
|
|
793
1025
|
this.classList.add("c-code");
|
|
794
1026
|
const title = this.getAttribute("title");
|
|
@@ -804,11 +1036,15 @@ class ContourCode extends ContourBase {
|
|
|
804
1036
|
if (t) t.remove();
|
|
805
1037
|
}
|
|
806
1038
|
if (this.hasAttribute("copyable")) {
|
|
1039
|
+
const head = this.ensure(".c-code__head", () => { const el = document.createElement("div"); el.className = "c-code__head"; return el; });
|
|
1040
|
+
// Copy button into head with c-btn classes + icon + labelText.
|
|
807
1041
|
this.ensure(".c-code__copy", () => {
|
|
808
1042
|
const btn = document.createElement("button");
|
|
809
|
-
btn.className = "c-code__copy";
|
|
1043
|
+
btn.className = "c-btn c-btn--ghost c-btn--sm c-code__copy";
|
|
810
1044
|
btn.type = "button";
|
|
811
|
-
btn
|
|
1045
|
+
setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24" width="14" height="14"><use href="#i-copy" /></svg>');
|
|
1046
|
+
btn.setAttribute("aria-label", labelText(this, "copy", "Copy"));
|
|
1047
|
+
head.appendChild(btn);
|
|
812
1048
|
return btn;
|
|
813
1049
|
});
|
|
814
1050
|
} else {
|
|
@@ -832,11 +1068,24 @@ class ContourCode extends ContourBase {
|
|
|
832
1068
|
if (head && head.parentNode === this && pre.parentNode === this && head.compareDocumentPosition(pre) & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
833
1069
|
this.insertBefore(pre, head.nextSibling);
|
|
834
1070
|
}
|
|
1071
|
+
// Line numbers are applied after wrapping and are idempotent: a flag on the
|
|
1072
|
+
// <code> prevents numbering the same source twice.
|
|
1073
|
+
const numbered = this.hasAttribute("numbered");
|
|
1074
|
+
this.classList.toggle("c-code--numbered", numbered);
|
|
1075
|
+
const codeEl = pre.querySelector("code");
|
|
1076
|
+
if (codeEl) {
|
|
1077
|
+
const split = codeEl.dataset.contourLines === "1";
|
|
1078
|
+
if (numbered && !split) {
|
|
1079
|
+
splitCodeLines(codeEl);
|
|
1080
|
+
codeEl.dataset.contourLines = "1";
|
|
1081
|
+
} else if (!numbered && split) {
|
|
1082
|
+
joinCodeLines(codeEl);
|
|
1083
|
+
delete codeEl.dataset.contourLines;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
835
1086
|
}
|
|
836
1087
|
enhance() {
|
|
837
|
-
// Interaction lives in behaviours.mjs
|
|
838
|
-
// One implementation, so the two layers cannot drift apart again: the shadow
|
|
839
|
-
// copy queried its root for slotted nodes, found none, and wired nothing.
|
|
1088
|
+
// Interaction lives in behaviours.mjs so the shadow wrappers share it.
|
|
840
1089
|
wireCopy(this);
|
|
841
1090
|
}
|
|
842
1091
|
}
|
|
@@ -852,9 +1101,7 @@ class ContourPullquote extends ContourBase {
|
|
|
852
1101
|
render() {
|
|
853
1102
|
this.classList.add("c-pullquote");
|
|
854
1103
|
const quote = this.getAttribute("quote");
|
|
855
|
-
// `.c-pullquote`
|
|
856
|
-
// the paragraph itself, and the one element the sheet styles inside it is
|
|
857
|
-
// `cite`, which is what an attribution is.
|
|
1104
|
+
// `.c-pullquote` styles the paragraph and `cite`; there is no `__quote`/`__byline`.
|
|
858
1105
|
if (quote) {
|
|
859
1106
|
// Preserve a generated <cite> (attribution) while updating the quote text.
|
|
860
1107
|
Array.from(this.childNodes).forEach((n) => { if (n.nodeType === 3) n.remove(); });
|
|
@@ -879,12 +1126,12 @@ class ContourAnchor extends ContourBase {
|
|
|
879
1126
|
this.classList.add("c-anchor");
|
|
880
1127
|
const href = this.getAttribute("href");
|
|
881
1128
|
const label = this.getAttribute("label");
|
|
882
|
-
//
|
|
883
|
-
|
|
884
|
-
if (prevAnchor) prevAnchor.remove();
|
|
1129
|
+
// Remove only generated anchors; an authored-only link renders nothing.
|
|
1130
|
+
Array.from(this.querySelectorAll("a[data-contour-generated]")).forEach((n) => n.remove());
|
|
885
1131
|
if (href && label) {
|
|
886
1132
|
const a = document.createElement("a");
|
|
887
|
-
a.
|
|
1133
|
+
a.dataset.contourGenerated = "";
|
|
1134
|
+
a.href = safeHref(href);
|
|
888
1135
|
a.textContent = label;
|
|
889
1136
|
const ariaLabel = this.getAttribute("aria-label");
|
|
890
1137
|
if (ariaLabel) a.setAttribute("aria-label", ariaLabel);
|
|
@@ -903,19 +1150,24 @@ class ContourAnchor extends ContourBase {
|
|
|
903
1150
|
* `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
904
1151
|
*/
|
|
905
1152
|
class ContourGeocoder extends ContourBase {
|
|
906
|
-
static get observed() { return ["placeholder", "value", "results", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1153
|
+
static get observed() { return ["placeholder", "value", "results", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
907
1154
|
static get properties() { return { placeholder: { attribute: "placeholder" }, value: { attribute: "value" }, results: { attribute: "results" }, src: { attribute: "src" } }; }
|
|
908
1155
|
render() {
|
|
909
1156
|
this.classList.add("c-geocoder");
|
|
910
1157
|
wireStates(this);
|
|
911
1158
|
loadRemote(this, ["results"]);
|
|
912
1159
|
if (renderStates(this, "geocoder")) return;
|
|
913
|
-
//
|
|
1160
|
+
// The input carries `c-input` so it inherits the system control contract.
|
|
914
1161
|
let inp = this.querySelector(".c-geocoder__input");
|
|
915
1162
|
if (!inp) {
|
|
916
1163
|
inp = document.createElement("input");
|
|
917
1164
|
inp.type = "search";
|
|
918
|
-
inp.className = "c-geocoder__input";
|
|
1165
|
+
inp.className = "c-input c-geocoder__input";
|
|
1166
|
+
if (!inp.hasAttribute("aria-label")) inp.setAttribute("aria-label", this.getAttribute("placeholder") || "Search location");
|
|
1167
|
+
// Combobox contract: the input owns the list and announces the active option.
|
|
1168
|
+
inp.setAttribute("role", "combobox");
|
|
1169
|
+
inp.setAttribute("aria-autocomplete", "list");
|
|
1170
|
+
inp.setAttribute("aria-expanded", "false");
|
|
919
1171
|
this.appendChild(inp);
|
|
920
1172
|
}
|
|
921
1173
|
const ph = this.getAttribute("placeholder");
|
|
@@ -924,20 +1176,33 @@ class ContourGeocoder extends ContourBase {
|
|
|
924
1176
|
if (val !== null && inp.value !== val) inp.value = val;
|
|
925
1177
|
// Results
|
|
926
1178
|
Array.from(this.querySelectorAll(".c-geocoder__result")).forEach((n) => n.remove());
|
|
1179
|
+
Array.from(this.querySelectorAll(".c-geocoder__list")).forEach((n) => n.remove());
|
|
927
1180
|
let results = [];
|
|
928
1181
|
const rAttr = this.getAttribute("results");
|
|
929
1182
|
if (rAttr) { try { results = JSON.parse(rAttr); } catch (e) { results = []; } }
|
|
930
1183
|
const remote = remoteData(this, "results");
|
|
931
|
-
|
|
1184
|
+
// remoteData returns a string; parse it so fetched results render.
|
|
1185
|
+
if (typeof remote === "string") {
|
|
1186
|
+
try { const parsed = JSON.parse(remote); if (Array.isArray(parsed)) results = parsed; } catch (e) {}
|
|
1187
|
+
} else if (Array.isArray(remote)) {
|
|
1188
|
+
results = remote;
|
|
1189
|
+
}
|
|
932
1190
|
if (Array.isArray(results) && results.length) {
|
|
1191
|
+
// A rebuilt list has no active option, whatever was active before.
|
|
1192
|
+
this._geocoderIndex = -1;
|
|
1193
|
+
// One list id per host, so aria-controls survives a re-render.
|
|
1194
|
+
if (!this._geocoderListId) this._geocoderListId = contourId("geocoder-list");
|
|
933
1195
|
const list = document.createElement("ul");
|
|
934
1196
|
list.className = "c-geocoder__list";
|
|
1197
|
+
list.id = this._geocoderListId;
|
|
935
1198
|
list.setAttribute("role", "listbox");
|
|
936
1199
|
results.forEach((r, idx) => {
|
|
937
1200
|
const li = document.createElement("li");
|
|
938
1201
|
li.className = "c-geocoder__result";
|
|
1202
|
+
li.id = this._geocoderListId + "-" + idx;
|
|
939
1203
|
li.setAttribute("role", "option");
|
|
940
|
-
li.setAttribute("
|
|
1204
|
+
li.setAttribute("aria-selected", "false");
|
|
1205
|
+
li.setAttribute("tabindex", "-1");
|
|
941
1206
|
li.textContent = (typeof r === "object") ? (r.label || r.name || "") : String(r);
|
|
942
1207
|
if (typeof r === "object") {
|
|
943
1208
|
if (r.lat != null) li.dataset.lat = String(r.lat);
|
|
@@ -946,44 +1211,123 @@ class ContourGeocoder extends ContourBase {
|
|
|
946
1211
|
list.appendChild(li);
|
|
947
1212
|
});
|
|
948
1213
|
this.appendChild(list);
|
|
949
|
-
|
|
950
|
-
|
|
1214
|
+
inp.setAttribute("aria-controls", this._geocoderListId);
|
|
1215
|
+
inp.setAttribute("aria-expanded", "true");
|
|
1216
|
+
} else {
|
|
1217
|
+
inp.removeAttribute("aria-controls");
|
|
1218
|
+
inp.setAttribute("aria-expanded", "false");
|
|
1219
|
+
inp.removeAttribute("aria-activedescendant");
|
|
1220
|
+
this._geocoderIndex = -1;
|
|
1221
|
+
if (!this.hasAttribute("loading") && !this.hasAttribute("error")) {
|
|
1222
|
+
// Suppress the empty state before the user has typed anything.
|
|
1223
|
+
const inp = this.querySelector(".c-geocoder__input");
|
|
1224
|
+
if (inp && inp.value) renderEmpty(this, "geocoder");
|
|
1225
|
+
}
|
|
951
1226
|
}
|
|
952
1227
|
}
|
|
953
1228
|
enhance() {
|
|
954
1229
|
if (this._wiredGeocoder) return;
|
|
955
1230
|
this._wiredGeocoder = true;
|
|
956
1231
|
const inp = this.querySelector(".c-geocoder__input");
|
|
1232
|
+
// Active option index, re-derived from the DOM per event (rule 12). Must be
|
|
1233
|
+
// a number starting at -1: `undefined + 1` is NaN and selects nothing.
|
|
1234
|
+
if (typeof this._geocoderIndex !== "number") this._geocoderIndex = -1;
|
|
1235
|
+
const options = () => Array.from(this.querySelectorAll(".c-geocoder__result"));
|
|
1236
|
+
const active = () => {
|
|
1237
|
+
const opts = options();
|
|
1238
|
+
const i = this._geocoderIndex;
|
|
1239
|
+
return i >= 0 && i < opts.length ? opts[i] : null;
|
|
1240
|
+
};
|
|
1241
|
+
const setActive = (i) => {
|
|
1242
|
+
const opts = options();
|
|
1243
|
+
if (!opts.length) return;
|
|
1244
|
+
const next = Math.max(0, Math.min(opts.length - 1, Number.isFinite(i) ? i : 0));
|
|
1245
|
+
opts.forEach((o, n) => o.setAttribute("aria-selected", n === next ? "true" : "false"));
|
|
1246
|
+
this._geocoderIndex = next;
|
|
1247
|
+
if (inp) {
|
|
1248
|
+
if (next >= 0) inp.setAttribute("aria-activedescendant", opts[next].id);
|
|
1249
|
+
else inp.removeAttribute("aria-activedescendant");
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
const clearActive = () => {
|
|
1253
|
+
this._geocoderIndex = -1;
|
|
1254
|
+
options().forEach((o) => o.setAttribute("aria-selected", "false"));
|
|
1255
|
+
if (inp) inp.removeAttribute("aria-activedescendant");
|
|
1256
|
+
};
|
|
1257
|
+
const select = (li) => {
|
|
1258
|
+
if (!li) return;
|
|
1259
|
+
// R24-132: emit numeric lat/lon, not strings.
|
|
1260
|
+
const result = { label: li.textContent.trim(), lat: li.dataset.lat ? Number(li.dataset.lat) : undefined, lon: li.dataset.lon ? Number(li.dataset.lon) : undefined };
|
|
1261
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { result } }));
|
|
1262
|
+
};
|
|
957
1263
|
if (inp) {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
if (
|
|
961
|
-
|
|
1264
|
+
// Delegate input/keydown on host (rule 12): input is rebuilt every render, so listeners on it are lost.
|
|
1265
|
+
this.addEventListener("input", (e) => {
|
|
1266
|
+
if (e.target !== inp) return;
|
|
1267
|
+
clearActive();
|
|
1268
|
+
if (this._geocoderTimer) clearTimeout(this._geocoderTimer);
|
|
1269
|
+
this._geocoderTimer = setTimeout(() => {
|
|
1270
|
+
this._geocoderTimer = null;
|
|
1271
|
+
if (!this.isConnected) return;
|
|
962
1272
|
this.dispatchEvent(new CustomEvent("contour:search", { bubbles: true, composed: true, detail: { query: inp.value } }));
|
|
963
1273
|
}, 200);
|
|
964
1274
|
});
|
|
965
|
-
|
|
1275
|
+
this.addEventListener("keydown", (e) => {
|
|
1276
|
+
if (e.target !== inp) return;
|
|
1277
|
+
const opts = options();
|
|
1278
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
1279
|
+
if (!opts.length) return;
|
|
1280
|
+
e.preventDefault();
|
|
1281
|
+
const cur = this._geocoderIndex < 0 ? (e.key === "ArrowDown" ? -1 : opts.length) : this._geocoderIndex;
|
|
1282
|
+
setActive(cur + (e.key === "ArrowDown" ? 1 : -1));
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
966
1285
|
if (e.key === "Enter") {
|
|
967
1286
|
e.preventDefault();
|
|
968
|
-
|
|
1287
|
+
// R24-132: Enter commits the label + closes the list.
|
|
1288
|
+
const li = active();
|
|
1289
|
+
if (li) {
|
|
1290
|
+
select(li);
|
|
1291
|
+
inp.setAttribute("aria-expanded", "false");
|
|
1292
|
+
inp.removeAttribute("aria-controls");
|
|
1293
|
+
clearActive();
|
|
1294
|
+
} else {
|
|
1295
|
+
this.dispatchEvent(new CustomEvent("contour:search", { bubbles: true, composed: true, detail: { query: inp.value } }));
|
|
1296
|
+
}
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
if (e.key === "Escape") {
|
|
1300
|
+
// R24-132: Escape hides the list (not ARIA-only).
|
|
1301
|
+
if (opts.length && inp.getAttribute("aria-expanded") === "true") {
|
|
1302
|
+
e.preventDefault();
|
|
1303
|
+
clearActive();
|
|
1304
|
+
inp.setAttribute("aria-expanded", "false");
|
|
1305
|
+
inp.removeAttribute("aria-controls");
|
|
1306
|
+
// Actually hide the list from the DOM.
|
|
1307
|
+
const list = this.querySelector(".c-geocoder__list");
|
|
1308
|
+
if (list) list.remove();
|
|
1309
|
+
}
|
|
969
1310
|
}
|
|
970
1311
|
});
|
|
971
1312
|
}
|
|
972
1313
|
this.addEventListener("click", (e) => {
|
|
973
1314
|
const li = e.target && e.target.closest ? e.target.closest(".c-geocoder__result") : null;
|
|
974
1315
|
if (!li || !this.contains(li)) return;
|
|
975
|
-
|
|
976
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { result } }));
|
|
1316
|
+
select(li);
|
|
977
1317
|
});
|
|
978
1318
|
this.addEventListener("keydown", (e) => {
|
|
979
1319
|
const li = e.target && e.target.closest ? e.target.closest(".c-geocoder__result") : null;
|
|
980
1320
|
if (!li || !this.contains(li)) return;
|
|
981
1321
|
if (e.key === "Enter" || e.key === " ") {
|
|
982
1322
|
e.preventDefault();
|
|
983
|
-
|
|
984
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { result } }));
|
|
1323
|
+
select(li);
|
|
985
1324
|
}
|
|
986
1325
|
});
|
|
987
1326
|
}
|
|
1327
|
+
disconnectedCallback() {
|
|
1328
|
+
// A pending debounce must not outlive its host (F-RO10).
|
|
1329
|
+
if (this._geocoderTimer) { clearTimeout(this._geocoderTimer); this._geocoderTimer = null; }
|
|
1330
|
+
super.disconnectedCallback();
|
|
1331
|
+
}
|
|
988
1332
|
}
|
|
989
1333
|
define("contour-geocoder", ContourGeocoder);
|