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/ui.mjs
DELETED
|
@@ -1,3560 +0,0 @@
|
|
|
1
|
-
import { ContourBase, define, contourId, onDispose } from './core.mjs';
|
|
2
|
-
import { wireRemovable } from './behaviours.mjs';
|
|
3
|
-
/**
|
|
4
|
-
* Avatar: a circular avatar with initials (from `name`) or an image (`src`),
|
|
5
|
-
* optional size/variant modifiers and a status dot. Attributes: `name`, `size`,
|
|
6
|
-
* `variant`, `src`, `status`.
|
|
7
|
-
*/
|
|
8
|
-
class ContourAvatar extends ContourBase {
|
|
9
|
-
static get observed() { return ["name", "size", "variant", "src", "status"]; }
|
|
10
|
-
static get properties() { return { name: { attribute: "name" }, size: { attribute: "size" }, variant: { attribute: "variant" }, src: { attribute: "src" }, status: { attribute: "status" } }; }
|
|
11
|
-
render() {
|
|
12
|
-
this.classList.add("c-avatar");
|
|
13
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-avatar--")) this.classList.remove(c); });
|
|
14
|
-
const name = this.getAttribute("name");
|
|
15
|
-
const size = this.getAttribute("size");
|
|
16
|
-
if (size) this.classList.add("c-avatar--" + size);
|
|
17
|
-
const variant = this.getAttribute("variant");
|
|
18
|
-
if (variant) this.classList.add("c-avatar--" + variant);
|
|
19
|
-
// Drop previously generated img/status so re-render doesn't stack.
|
|
20
|
-
const oldImg = this.querySelector("img.c-avatar__img");
|
|
21
|
-
if (oldImg) oldImg.remove();
|
|
22
|
-
const oldDot = this.querySelector(".c-avatar__status");
|
|
23
|
-
if (oldDot) oldDot.remove();
|
|
24
|
-
const src = this.getAttribute("src");
|
|
25
|
-
if (src) {
|
|
26
|
-
this.textContent = "";
|
|
27
|
-
const img = document.createElement("img");
|
|
28
|
-
img.className = "c-avatar__img";
|
|
29
|
-
img.src = src;
|
|
30
|
-
img.alt = name || "";
|
|
31
|
-
img.loading = "lazy";
|
|
32
|
-
img.decoding = "async";
|
|
33
|
-
this.appendChild(img);
|
|
34
|
-
} else if (name) {
|
|
35
|
-
const initials = name.split(" ").map((w) => w[0]).join("").toUpperCase().slice(0, 2);
|
|
36
|
-
// Keep initials as text only when no img.
|
|
37
|
-
if (!this.querySelector("img.c-avatar__img")) {
|
|
38
|
-
// Remove any stray text nodes? Keep simple: set textContent if no img.
|
|
39
|
-
}
|
|
40
|
-
this.textContent = initials;
|
|
41
|
-
}
|
|
42
|
-
const status = this.getAttribute("status");
|
|
43
|
-
if (status) {
|
|
44
|
-
const dot = document.createElement("span");
|
|
45
|
-
dot.className = "c-avatar__status c-avatar__status--" + status;
|
|
46
|
-
dot.setAttribute("aria-hidden", "true");
|
|
47
|
-
this.appendChild(dot);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
define("contour-avatar", ContourAvatar);
|
|
52
|
-
/**
|
|
53
|
-
* Badge: a small status label with variant/size modifiers and an optional
|
|
54
|
-
* removable (×) button. Attributes: `variant`, `label`, `size`, `removable`.
|
|
55
|
-
*/
|
|
56
|
-
class ContourBadgeFull extends ContourBase {
|
|
57
|
-
static get observed() { return ["variant", "label", "size", "removable"]; }
|
|
58
|
-
static get properties() { return { variant: { attribute: "variant" }, label: { attribute: "label" }, size: { attribute: "size" }, removable: { attribute: "removable", type: Boolean } }; }
|
|
59
|
-
render() {
|
|
60
|
-
this.classList.add("c-badge");
|
|
61
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-badge--")) this.classList.remove(c); });
|
|
62
|
-
const variant = this.getAttribute("variant");
|
|
63
|
-
if (variant) this.classList.add("c-badge--" + variant);
|
|
64
|
-
const size = this.getAttribute("size");
|
|
65
|
-
if (size) this.classList.add("c-badge--" + size);
|
|
66
|
-
const label = this.getAttribute("label");
|
|
67
|
-
if (label) {
|
|
68
|
-
// Preserve remove button if present.
|
|
69
|
-
let textNode = null;
|
|
70
|
-
for (const n of this.childNodes) { if (n.nodeType === 3) { textNode = n; break; } }
|
|
71
|
-
if (textNode) textNode.nodeValue = label;
|
|
72
|
-
else this.insertBefore(document.createTextNode(label), this.firstChild);
|
|
73
|
-
}
|
|
74
|
-
if (this.hasAttribute("removable")) {
|
|
75
|
-
this.ensure(".c-badge__remove", () => {
|
|
76
|
-
const btn = document.createElement("button");
|
|
77
|
-
btn.className = "c-badge__remove";
|
|
78
|
-
btn.type = "button";
|
|
79
|
-
btn.setAttribute("aria-label", "Remove");
|
|
80
|
-
btn.textContent = "×";
|
|
81
|
-
return btn;
|
|
82
|
-
});
|
|
83
|
-
} else {
|
|
84
|
-
const btn = this.querySelector(".c-badge__remove");
|
|
85
|
-
if (btn) btn.remove();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
enhance() {
|
|
89
|
-
wireRemovable(this);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
define("contour-badge", ContourBadgeFull);
|
|
93
|
-
/**
|
|
94
|
-
* Chip: a compact status pill with `key`/`value` text and a variant modifier.
|
|
95
|
-
* Attributes: `variant`, `key`, `value`.
|
|
96
|
-
*/
|
|
97
|
-
class ContourChipFull extends ContourBase {
|
|
98
|
-
static get observed() { return ["variant", "key", "value"]; }
|
|
99
|
-
static get properties() { return { variant: { attribute: "variant" }, key: { attribute: "key" }, value: { attribute: "value" } }; }
|
|
100
|
-
render() {
|
|
101
|
-
this.classList.add("c-chip");
|
|
102
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
103
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-chip--")) this.classList.remove(c); });
|
|
104
|
-
const variant = this.getAttribute("variant");
|
|
105
|
-
if (variant) this.classList.add("c-chip--" + variant);
|
|
106
|
-
const key = this.getAttribute("key");
|
|
107
|
-
const value = this.getAttribute("value");
|
|
108
|
-
if (key) {
|
|
109
|
-
const k = this.ensure(".c-chip__key", () => { const el = document.createElement("span"); el.className = "c-chip__key"; return el; });
|
|
110
|
-
k.textContent = key;
|
|
111
|
-
} else {
|
|
112
|
-
const k = this.querySelector(".c-chip__key");
|
|
113
|
-
if (k) k.remove();
|
|
114
|
-
}
|
|
115
|
-
if (value) {
|
|
116
|
-
const v = this.ensure(".c-chip__value", () => { const el = document.createElement("span"); el.className = "c-chip__value"; return el; });
|
|
117
|
-
v.textContent = value;
|
|
118
|
-
} else {
|
|
119
|
-
const v = this.querySelector(".c-chip__value");
|
|
120
|
-
if (v) v.remove();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
define("contour-chip", ContourChipFull);
|
|
125
|
-
/**
|
|
126
|
-
* Tag: a removable status label with a variant modifier. Attributes: `label`,
|
|
127
|
-
* `removable`, `variant`.
|
|
128
|
-
*/
|
|
129
|
-
class ContourTag extends ContourBase {
|
|
130
|
-
static get observed() { return ["label", "removable", "variant"]; }
|
|
131
|
-
static get properties() { return { label: { attribute: "label" }, removable: { attribute: "removable", type: Boolean }, variant: { attribute: "variant" } }; }
|
|
132
|
-
render() {
|
|
133
|
-
this.classList.add("c-tag");
|
|
134
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
135
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-tag--")) this.classList.remove(c); });
|
|
136
|
-
const variant = this.getAttribute("variant");
|
|
137
|
-
if (variant) this.classList.add("c-tag--" + variant);
|
|
138
|
-
const label = this.getAttribute("label");
|
|
139
|
-
if (label) {
|
|
140
|
-
// Update the text node without clobbering the remove button.
|
|
141
|
-
let textNode = null;
|
|
142
|
-
for (const n of this.childNodes) {
|
|
143
|
-
if (n.nodeType === 3) { textNode = n; break; }
|
|
144
|
-
}
|
|
145
|
-
if (textNode) textNode.nodeValue = label + " ";
|
|
146
|
-
else this.insertBefore(document.createTextNode(label + " "), this.firstChild);
|
|
147
|
-
}
|
|
148
|
-
if (this.hasAttribute("removable")) {
|
|
149
|
-
this.ensure(".c-tag__remove", () => {
|
|
150
|
-
const btn = document.createElement("button");
|
|
151
|
-
btn.className = "c-tag__remove";
|
|
152
|
-
btn.type = "button";
|
|
153
|
-
btn.setAttribute("aria-label", "Remove");
|
|
154
|
-
btn.textContent = "×";
|
|
155
|
-
return btn;
|
|
156
|
-
});
|
|
157
|
-
} else {
|
|
158
|
-
const btn = this.querySelector(".c-tag__remove");
|
|
159
|
-
if (btn) btn.remove();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
enhance() {
|
|
163
|
-
// Interaction lives in behaviours.mjs, which the shadow wrappers call too.
|
|
164
|
-
// One implementation, so the two layers cannot drift apart again: the shadow
|
|
165
|
-
// copy queried its root for slotted nodes, found none, and wired nothing.
|
|
166
|
-
wireRemovable(this);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
define("contour-tag", ContourTag);
|
|
170
|
-
/**
|
|
171
|
-
* Dot: a small status indicator with variant and live states. Attributes:
|
|
172
|
-
* `variant`, `live`.
|
|
173
|
-
*/
|
|
174
|
-
class ContourDot extends ContourBase {
|
|
175
|
-
static get observed() { return ["variant", "live"]; }
|
|
176
|
-
static get properties() { return { variant: { attribute: "variant" }, live: { attribute: "live", type: Boolean } }; }
|
|
177
|
-
render() {
|
|
178
|
-
this.classList.add("c-dot");
|
|
179
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
180
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "status indicator");
|
|
181
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-dot--")) this.classList.remove(c); });
|
|
182
|
-
const variant = this.getAttribute("variant");
|
|
183
|
-
if (variant) this.classList.add("c-dot--" + variant);
|
|
184
|
-
if (this.hasAttribute("live")) this.classList.add("c-dot--live"); else this.classList.remove("c-dot--live");
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
define("contour-dot", ContourDot);
|
|
188
|
-
/**
|
|
189
|
-
* Pill: a rounded status label with live state and variant modifier.
|
|
190
|
-
* Attributes: `label`, `live`, `variant`.
|
|
191
|
-
*/
|
|
192
|
-
class ContourPill extends ContourBase {
|
|
193
|
-
static get observed() { return ["label", "live", "variant"]; }
|
|
194
|
-
static get properties() { return { label: { attribute: "label" }, live: { attribute: "live", type: Boolean }, variant: { attribute: "variant" } }; }
|
|
195
|
-
render() {
|
|
196
|
-
this.classList.add("c-pill");
|
|
197
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
198
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-pill--")) this.classList.remove(c); });
|
|
199
|
-
const variant = this.getAttribute("variant");
|
|
200
|
-
if (variant) this.classList.add("c-pill--" + variant);
|
|
201
|
-
const label = this.getAttribute("label");
|
|
202
|
-
if (label) {
|
|
203
|
-
this.textContent = label;
|
|
204
|
-
}
|
|
205
|
-
if (this.hasAttribute("live")) this.classList.add("c-pill--live"); else this.classList.remove("c-pill--live");
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
define("contour-pill", ContourPill);
|
|
209
|
-
/**
|
|
210
|
-
* Kbd: a keyboard key display. Attribute: `key`.
|
|
211
|
-
*/
|
|
212
|
-
class ContourKbd extends ContourBase {
|
|
213
|
-
static get observed() { return ["key"]; }
|
|
214
|
-
static get properties() { return { key: { attribute: "key" } }; }
|
|
215
|
-
render() {
|
|
216
|
-
this.classList.add("c-kbd");
|
|
217
|
-
const key = this.getAttribute("key");
|
|
218
|
-
if (key) {
|
|
219
|
-
this.textContent = key;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
define("contour-kbd", ContourKbd);
|
|
224
|
-
/**
|
|
225
|
-
* Spinner: a loading indicator with size modifier. Attribute: `size`.
|
|
226
|
-
*/
|
|
227
|
-
class ContourSpinner extends ContourBase {
|
|
228
|
-
static get observed() { return ["size"]; }
|
|
229
|
-
static get properties() { return { size: { attribute: "size" } }; }
|
|
230
|
-
render() {
|
|
231
|
-
this.classList.add("c-spinner");
|
|
232
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-spinner--")) this.classList.remove(c); });
|
|
233
|
-
const size = this.getAttribute("size");
|
|
234
|
-
if (size) this.classList.add("c-spinner--" + size);
|
|
235
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
236
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Loading");
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
define("contour-spinner", ContourSpinner);
|
|
240
|
-
/**
|
|
241
|
-
* Skeleton: a loading placeholder with size and shimmer options. Attributes:
|
|
242
|
-
* `size`, `shimmer`.
|
|
243
|
-
*/
|
|
244
|
-
class ContourSkeleton extends ContourBase {
|
|
245
|
-
static get observed() { return ["size", "shimmer"]; }
|
|
246
|
-
static get properties() { return { size: { attribute: "size" }, shimmer: { attribute: "shimmer", type: Boolean } }; }
|
|
247
|
-
render() {
|
|
248
|
-
this.classList.add("c-skeleton");
|
|
249
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-skeleton--")) this.classList.remove(c); });
|
|
250
|
-
const size = this.getAttribute("size");
|
|
251
|
-
if (size) this.classList.add("c-skeleton--" + size);
|
|
252
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
253
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Loading");
|
|
254
|
-
if (!this.hasAttribute("aria-busy")) this.setAttribute("aria-busy", "true");
|
|
255
|
-
if (!this.hasAttribute("aria-hidden")) this.setAttribute("aria-hidden", "true");
|
|
256
|
-
const shimmer = this.getAttribute("shimmer");
|
|
257
|
-
if (shimmer === "false" || shimmer === "off") this.classList.add("c-skeleton--static");
|
|
258
|
-
else this.classList.remove("c-skeleton--static");
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
define("contour-skeleton", ContourSkeleton);
|
|
262
|
-
/**
|
|
263
|
-
* Tooltip: a popover-triggered tooltip with anchor association, delay, and
|
|
264
|
-
* viewport flip. Attributes: `text`, `anchor`, `delay`, `trigger`.
|
|
265
|
-
*/
|
|
266
|
-
class ContourTooltip extends ContourBase {
|
|
267
|
-
static get observed() { return ["text", "anchor", "delay", "trigger"]; }
|
|
268
|
-
static get properties() { return { text: { attribute: "text" }, anchor: { attribute: "anchor" }, delay: { attribute: "delay", type: Number }, trigger: { attribute: "trigger" } }; }
|
|
269
|
-
render() {
|
|
270
|
-
this.classList.add("c-tooltip");
|
|
271
|
-
if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
|
|
272
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "tooltip");
|
|
273
|
-
if (!this.id) this.id = contourId("tip");
|
|
274
|
-
const text = this.getAttribute("text");
|
|
275
|
-
if (text !== null && !this.hasChildNodes()) {
|
|
276
|
-
this.textContent = text;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
enhance() {
|
|
280
|
-
if (this._wiredTooltip) return;
|
|
281
|
-
this._wiredTooltip = true;
|
|
282
|
-
// Anchor association: link a trigger element to this tooltip.
|
|
283
|
-
const anchorSel = this.getAttribute("anchor");
|
|
284
|
-
if (anchorSel) {
|
|
285
|
-
let trigger = null;
|
|
286
|
-
if (anchorSel.startsWith("#")) {
|
|
287
|
-
trigger = document.getElementById(anchorSel.slice(1));
|
|
288
|
-
} else {
|
|
289
|
-
trigger = document.querySelector(anchorSel);
|
|
290
|
-
}
|
|
291
|
-
if (trigger) {
|
|
292
|
-
trigger.setAttribute("popovertarget", this.id || (this.id = contourId("tip")));
|
|
293
|
-
trigger.setAttribute("aria-describedby", this.id);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
const delayMs = (this.delay && this.delay > 0) ? this.delay : 0;
|
|
297
|
-
let showTimer = null;
|
|
298
|
-
const hasPopover = typeof this.showPopover === "function";
|
|
299
|
-
const show = () => {
|
|
300
|
-
if (showTimer) clearTimeout(showTimer);
|
|
301
|
-
if (delayMs > 0) showTimer = setTimeout(() => {
|
|
302
|
-
if (hasPopover) { try { this.showPopover(); } catch (e) {} }
|
|
303
|
-
else this.classList.add("is-open");
|
|
304
|
-
try { requestAnimationFrame(flipIfNeeded); } catch (e) { flipIfNeeded(); }
|
|
305
|
-
}, delayMs);
|
|
306
|
-
else {
|
|
307
|
-
if (hasPopover) { try { this.showPopover(); } catch (e) {} }
|
|
308
|
-
else this.classList.add("is-open");
|
|
309
|
-
try { requestAnimationFrame(flipIfNeeded); } catch (e) { flipIfNeeded(); }
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
const hide = () => {
|
|
313
|
-
if (showTimer) { clearTimeout(showTimer); showTimer = null; }
|
|
314
|
-
if (hasPopover) { try { this.hidePopover(); } catch (e) {} }
|
|
315
|
-
else this.classList.remove("is-open");
|
|
316
|
-
};
|
|
317
|
-
const triggerMode = this.getAttribute("trigger") || "hover";
|
|
318
|
-
const trigger = anchorSel ? (anchorSel.startsWith("#") ? document.getElementById(anchorSel.slice(1)) : document.querySelector(anchorSel)) : null;
|
|
319
|
-
const target = trigger || this;
|
|
320
|
-
const onEnter = () => { if (triggerMode !== "click") show(); };
|
|
321
|
-
const onLeave = () => { if (triggerMode !== "click") hide(); };
|
|
322
|
-
const onFocus = () => { if (triggerMode !== "click") show(); };
|
|
323
|
-
const onBlur = () => { if (triggerMode !== "click") hide(); };
|
|
324
|
-
const onClick = () => {
|
|
325
|
-
if (triggerMode === "click" || triggerMode === "hover") {
|
|
326
|
-
if (this.matches(":popover-open")) hide(); else show();
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
const onTouchStart = () => { if (triggerMode !== "click") show(); };
|
|
330
|
-
const onTouchEnd = () => { if (triggerMode !== "click") { setTimeout(hide, 1500); } };
|
|
331
|
-
target.addEventListener("mouseenter", onEnter);
|
|
332
|
-
target.addEventListener("mouseleave", onLeave);
|
|
333
|
-
target.addEventListener("focus", onFocus);
|
|
334
|
-
target.addEventListener("blur", onBlur);
|
|
335
|
-
target.addEventListener("click", onClick);
|
|
336
|
-
target.addEventListener("touchstart", onTouchStart, { passive: true });
|
|
337
|
-
target.addEventListener("touchend", onTouchEnd, { passive: true });
|
|
338
|
-
// Placement flip: if the tooltip would overflow the viewport, flip it.
|
|
339
|
-
const flipIfNeeded = () => {
|
|
340
|
-
try {
|
|
341
|
-
const r = this.getBoundingClientRect();
|
|
342
|
-
if (r.right > window.innerWidth) this.classList.add("c-tooltip--flip-x");
|
|
343
|
-
else this.classList.remove("c-tooltip--flip-x");
|
|
344
|
-
if (r.bottom > window.innerHeight) this.classList.add("c-tooltip--flip-y");
|
|
345
|
-
else this.classList.remove("c-tooltip--flip-y");
|
|
346
|
-
} catch (e) {}
|
|
347
|
-
};
|
|
348
|
-
const origShow = show;
|
|
349
|
-
// wrap show to flip after display
|
|
350
|
-
onDispose(this, () => {
|
|
351
|
-
target.removeEventListener("mouseenter", onEnter);
|
|
352
|
-
target.removeEventListener("mouseleave", onLeave);
|
|
353
|
-
target.removeEventListener("focus", onFocus);
|
|
354
|
-
target.removeEventListener("blur", onBlur);
|
|
355
|
-
target.removeEventListener("click", onClick);
|
|
356
|
-
target.removeEventListener("touchstart", onTouchStart);
|
|
357
|
-
target.removeEventListener("touchend", onTouchEnd);
|
|
358
|
-
if (showTimer) clearTimeout(showTimer);
|
|
359
|
-
});
|
|
360
|
-
this.addEventListener("toggle", (e) => {
|
|
361
|
-
const t = e.target;
|
|
362
|
-
if (t && t === this) {
|
|
363
|
-
this.dispatchEvent(new CustomEvent("contour:toggle", { detail: { open: this.matches(":popover-open") }, bubbles: true, composed: true }));
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
this.addEventListener("beforetoggle", (e) => {
|
|
367
|
-
this.dispatchEvent(new CustomEvent(e.newState === "open" ? "contour:show" : "contour:hide", { bubbles: true, composed: true }));
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
define("contour-tooltip", ContourTooltip);
|
|
372
|
-
/**
|
|
373
|
-
* Progress: a determinate or indeterminate progress bar with value, min/max,
|
|
374
|
-
* paused and pausable states. Attributes: `value`, `label`, `min`, `max`,
|
|
375
|
-
* `paused`, `pausable`.
|
|
376
|
-
*/
|
|
377
|
-
class ContourProgress extends ContourBase {
|
|
378
|
-
static get observed() { return ["value", "label", "min", "max", "paused", "pausable"]; }
|
|
379
|
-
static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, min: { attribute: "min" }, max: { attribute: "max" }, paused: { attribute: "paused", type: Boolean }, pausable: { attribute: "pausable", type: Boolean } }; }
|
|
380
|
-
render() {
|
|
381
|
-
this.classList.add("c-progress");
|
|
382
|
-
const value = this.getAttribute("value");
|
|
383
|
-
// The normalised percentage is read by the ARIA block below, which runs
|
|
384
|
-
// after this branch. Declaring it inside the `else` made `String(pct)` a
|
|
385
|
-
// ReferenceError: the bar built its node, set its role, and then died
|
|
386
|
-
// before announcing anything, so a determinate progressbar reached a
|
|
387
|
-
// screen reader with no value at all.
|
|
388
|
-
if (value === null) {
|
|
389
|
-
// Indeterminate bar: no fill, no value announced.
|
|
390
|
-
this.style.removeProperty("--progress");
|
|
391
|
-
if (this.getAttribute("aria-valuenow") === this._progressAriaValue) {
|
|
392
|
-
this.removeAttribute("aria-valuenow");
|
|
393
|
-
}
|
|
394
|
-
this._progressAriaValue = null;
|
|
395
|
-
} else {
|
|
396
|
-
const num = Number(value);
|
|
397
|
-
// Accept both 0-1 (fraction) and 0-100 (percentage). A value <= 1
|
|
398
|
-
// without a decimal point is treated as a percentage (e.g. "50" → 50%).
|
|
399
|
-
// A value <= 1 with a decimal point is treated as a fraction (e.g. "0.5" → 50%).
|
|
400
|
-
const pct = Number.isFinite(num) ? (num <= 1 && value.includes(".") ? num * 100 : num) : 0;
|
|
401
|
-
const pctStr = Math.max(0, Math.min(100, pct)) + "%";
|
|
402
|
-
this.style.setProperty("--progress", pctStr);
|
|
403
|
-
const prevVal = this._progressAriaValue;
|
|
404
|
-
if (!this.hasAttribute("aria-valuenow") || this.getAttribute("aria-valuenow") === prevVal) {
|
|
405
|
-
this.setAttribute("aria-valuenow", String(pct));
|
|
406
|
-
this._progressAriaValue = String(pct);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
this.ensure(".c-progress__bar", () => { const el = document.createElement("span"); el.className = "c-progress__bar"; return el; });
|
|
410
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "progressbar");
|
|
411
|
-
const label = this.getAttribute("label");
|
|
412
|
-
if (label && !this.hasAttribute("aria-label")) this.setAttribute("aria-label", label);
|
|
413
|
-
const min = this.getAttribute("min");
|
|
414
|
-
const max = this.getAttribute("max");
|
|
415
|
-
if (min !== null) this.setAttribute("aria-valuemin", min);
|
|
416
|
-
else if (!this.hasAttribute("aria-valuemin")) this.setAttribute("aria-valuemin", "0");
|
|
417
|
-
if (max !== null) this.setAttribute("aria-valuemax", max);
|
|
418
|
-
else if (!this.hasAttribute("aria-valuemax")) this.setAttribute("aria-valuemax", "100");
|
|
419
|
-
if (this.hasAttribute("paused")) this.classList.add("c-progress--paused");
|
|
420
|
-
else Array.from(this.classList).forEach((c) => { if (c === "c-progress--paused") this.classList.remove(c); });
|
|
421
|
-
if (this.hasAttribute("pausable")) {
|
|
422
|
-
this.ensure(".c-progress__pause", () => {
|
|
423
|
-
const btn = document.createElement("button");
|
|
424
|
-
btn.className = "c-progress__pause";
|
|
425
|
-
btn.type = "button";
|
|
426
|
-
btn.setAttribute("aria-label", "Pause");
|
|
427
|
-
btn.textContent = "⏸";
|
|
428
|
-
return btn;
|
|
429
|
-
});
|
|
430
|
-
} else {
|
|
431
|
-
const btn = this.querySelector(".c-progress__pause");
|
|
432
|
-
if (btn) btn.remove();
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
define("contour-progress", ContourProgress);
|
|
437
|
-
/**
|
|
438
|
-
* Mark: a highlighted text marker. No attributes.
|
|
439
|
-
*/
|
|
440
|
-
class ContourMark extends ContourBase {
|
|
441
|
-
render() {
|
|
442
|
-
this.classList.add("c-mark");
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
define("contour-mark", ContourMark);
|
|
446
|
-
/**
|
|
447
|
-
* Loading: a spinner wrapped in a container. No attributes.
|
|
448
|
-
*/
|
|
449
|
-
class ContourLoading extends ContourBase {
|
|
450
|
-
render() {
|
|
451
|
-
this.classList.add("c-loading");
|
|
452
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
453
|
-
if (!this.hasAttribute("aria-live")) this.setAttribute("aria-live", "polite");
|
|
454
|
-
this.ensure(".c-spinner", () => { const el = document.createElement("span"); el.className = "c-spinner"; el.setAttribute("aria-hidden", "true"); return el; });
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
define("contour-loading", ContourLoading);
|
|
458
|
-
/**
|
|
459
|
-
* Elevation: a single step of the elevation ramp (`.c-elevation` carries
|
|
460
|
-
* `--shadow-md`). Raises the surface it is given. No attributes.
|
|
461
|
-
*/
|
|
462
|
-
class ContourElevation extends ContourBase {
|
|
463
|
-
render() {
|
|
464
|
-
// The block is one step of the ramp, not the ramp: .c-elevation carries
|
|
465
|
-
// --shadow-md and nothing else, so this element raises the surface it is
|
|
466
|
-
// given and stops there. The rule has existed since 00e0494 — an earlier
|
|
467
|
-
// note here claimed it did not and dropped the class rather than invent
|
|
468
|
-
// one, which left a shipped rule with no emitter in either layer.
|
|
469
|
-
this.classList.add("c-elevation");
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
define("contour-elevation", ContourElevation);
|
|
473
|
-
/**
|
|
474
|
-
* VersionBanner: a dismissible info banner with message, link and href.
|
|
475
|
-
* Attributes: `message`, `link`, `href`, `dismissible`.
|
|
476
|
-
*/
|
|
477
|
-
class ContourVersionBannerFull extends ContourBase {
|
|
478
|
-
static get observed() { return ["message", "link", "href", "dismissible"]; }
|
|
479
|
-
static get properties() { return { message: { attribute: "message" }, link: { attribute: "link" }, href: { attribute: "href" }, dismissible: { attribute: "dismissible", type: Boolean } }; }
|
|
480
|
-
render() {
|
|
481
|
-
this.classList.add("c-version-banner");
|
|
482
|
-
Array.from(this.children).forEach((n) => n.remove());
|
|
483
|
-
const message = this.getAttribute("message");
|
|
484
|
-
if (message) {
|
|
485
|
-
const icon = document.createElement("svg");
|
|
486
|
-
icon.setAttribute("aria-hidden", "true");
|
|
487
|
-
icon.innerHTML = '<use href="#i-info" />';
|
|
488
|
-
this.appendChild(icon);
|
|
489
|
-
const span = document.createElement("span");
|
|
490
|
-
span.textContent = message;
|
|
491
|
-
this.appendChild(span);
|
|
492
|
-
}
|
|
493
|
-
const link = this.getAttribute("link");
|
|
494
|
-
const href = this.getAttribute("href");
|
|
495
|
-
if (link && href) {
|
|
496
|
-
const a = document.createElement("a");
|
|
497
|
-
a.className = "c-version-banner__link";
|
|
498
|
-
a.href = href;
|
|
499
|
-
a.textContent = link;
|
|
500
|
-
this.appendChild(a);
|
|
501
|
-
}
|
|
502
|
-
if (this.hasAttribute("dismissible")) {
|
|
503
|
-
const btn = document.createElement("button");
|
|
504
|
-
btn.className = "c-version-banner__dismiss";
|
|
505
|
-
btn.type = "button";
|
|
506
|
-
btn.setAttribute("aria-label", "Dismiss");
|
|
507
|
-
btn.textContent = "×";
|
|
508
|
-
this.appendChild(btn);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
enhance() {
|
|
512
|
-
if (this._wiredVersionBanner) return;
|
|
513
|
-
this._wiredVersionBanner = true;
|
|
514
|
-
this.addEventListener("click", (e) => {
|
|
515
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-version-banner__dismiss") : null;
|
|
516
|
-
if (btn && this.contains(btn)) {
|
|
517
|
-
e.preventDefault();
|
|
518
|
-
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
519
|
-
this.remove();
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
define("contour-version-banner", ContourVersionBannerFull);
|
|
525
|
-
/**
|
|
526
|
-
* Banner: a simple message banner with a variant modifier. Attributes:
|
|
527
|
-
* `message`, `variant`.
|
|
528
|
-
*/
|
|
529
|
-
class ContourBanner extends ContourBase {
|
|
530
|
-
static get observed() { return ["message", "variant"]; }
|
|
531
|
-
static get properties() { return { message: { attribute: "message" }, variant: { attribute: "variant" } }; }
|
|
532
|
-
render() {
|
|
533
|
-
this.classList.add("c-banner");
|
|
534
|
-
const variant = this.getAttribute("variant");
|
|
535
|
-
if (variant) this.classList.add("c-banner--" + variant);
|
|
536
|
-
const message = this.getAttribute("message");
|
|
537
|
-
if (message) {
|
|
538
|
-
const span = this.ensure(".c-banner__message", () => { const el = document.createElement("span"); el.className = "c-banner__message"; return el; });
|
|
539
|
-
span.textContent = message;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
define("contour-banner", ContourBanner);
|
|
544
|
-
/**
|
|
545
|
-
* FilterPill: a key/value filter chip with an optional remove button.
|
|
546
|
-
* Attributes: `key`, `value`, `removable`.
|
|
547
|
-
*/
|
|
548
|
-
class ContourFilterPill extends ContourBase {
|
|
549
|
-
static get observed() { return ["key", "value", "removable"]; }
|
|
550
|
-
static get properties() { return { key: { attribute: "key" }, value: { attribute: "value" }, removable: { attribute: "removable", type: Boolean } }; }
|
|
551
|
-
render() {
|
|
552
|
-
this.classList.add("c-filter-pill");
|
|
553
|
-
const key = this.getAttribute("key");
|
|
554
|
-
const value = this.getAttribute("value");
|
|
555
|
-
if (key) {
|
|
556
|
-
const k = this.ensure(".c-filter-pill__key", () => { const el = document.createElement("span"); el.className = "c-filter-pill__key"; return el; });
|
|
557
|
-
k.textContent = key;
|
|
558
|
-
} else {
|
|
559
|
-
const k = this.querySelector(".c-filter-pill__key");
|
|
560
|
-
if (k) k.remove();
|
|
561
|
-
}
|
|
562
|
-
if (value) {
|
|
563
|
-
const v = this.ensure(".c-filter-pill__value", () => { const el = document.createElement("span"); el.className = "c-filter-pill__value"; return el; });
|
|
564
|
-
v.textContent = value;
|
|
565
|
-
} else {
|
|
566
|
-
const v = this.querySelector(".c-filter-pill__value");
|
|
567
|
-
if (v) v.remove();
|
|
568
|
-
}
|
|
569
|
-
if (this.hasAttribute("removable")) {
|
|
570
|
-
this.ensure(".c-filter-pill__remove", () => {
|
|
571
|
-
const btn = document.createElement("button");
|
|
572
|
-
btn.className = "c-filter-pill__remove";
|
|
573
|
-
btn.type = "button";
|
|
574
|
-
btn.setAttribute("aria-label", "Remove filter");
|
|
575
|
-
btn.textContent = "×";
|
|
576
|
-
return btn;
|
|
577
|
-
});
|
|
578
|
-
} else {
|
|
579
|
-
const btn = this.querySelector(".c-filter-pill__remove");
|
|
580
|
-
if (btn) btn.remove();
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
enhance() {
|
|
584
|
-
// Interaction lives in behaviours.mjs, which the shadow wrappers call too.
|
|
585
|
-
// One implementation, so the two layers cannot drift apart again: the shadow
|
|
586
|
-
// copy queried its root for slotted nodes, found none, and wired nothing.
|
|
587
|
-
wireRemovable(this);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
define("contour-filter-pill", ContourFilterPill);
|
|
591
|
-
/**
|
|
592
|
-
* Datamark: a data value display with optional unit and label. Attributes:
|
|
593
|
-
* `value`, `unit`, `label`.
|
|
594
|
-
*/
|
|
595
|
-
class ContourDatamark extends ContourBase {
|
|
596
|
-
static get observed() { return ["value", "unit", "label"]; }
|
|
597
|
-
static get properties() { return { value: { attribute: "value" }, unit: { attribute: "unit" }, label: { attribute: "label" } }; }
|
|
598
|
-
render() {
|
|
599
|
-
this.classList.add("c-datamark");
|
|
600
|
-
// The guide sets `value` on this element (`<contour-datamark value="42">`),
|
|
601
|
-
// and the block's own specimen is the number with an optional unit — reading
|
|
602
|
-
// only `label` meant the published specimen rendered an empty box.
|
|
603
|
-
const value = this.getAttribute("value");
|
|
604
|
-
const unit = this.getAttribute("unit");
|
|
605
|
-
const label = this.getAttribute("label");
|
|
606
|
-
const text = value || label;
|
|
607
|
-
if (text) {
|
|
608
|
-
this.textContent = text;
|
|
609
|
-
if (unit) {
|
|
610
|
-
const u = document.createElement("span");
|
|
611
|
-
u.className = "u-subtle";
|
|
612
|
-
u.textContent = " " + unit;
|
|
613
|
-
this.appendChild(u);
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
define("contour-datamark", ContourDatamark);
|
|
619
|
-
/**
|
|
620
|
-
* DestructiveHint: a text hint for destructive actions. Attribute: `text`.
|
|
621
|
-
*/
|
|
622
|
-
class ContourDestructiveHint extends ContourBase {
|
|
623
|
-
static get observed() { return ["text"]; }
|
|
624
|
-
static get properties() { return { text: { attribute: "text" } }; }
|
|
625
|
-
render() {
|
|
626
|
-
this.classList.add("c-destructive-hint");
|
|
627
|
-
const text = this.getAttribute("text");
|
|
628
|
-
if (text) this.textContent = text;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
define("contour-destructive-hint", ContourDestructiveHint);
|
|
632
|
-
/**
|
|
633
|
-
* IconBadge: an icon from the sprite (i-* convention) with a warning if the
|
|
634
|
-
* name doesn't match. Attribute: `icon`.
|
|
635
|
-
*/
|
|
636
|
-
class ContourIconBadge extends ContourBase {
|
|
637
|
-
static get observed() { return ["icon"]; }
|
|
638
|
-
static get properties() { return { icon: { attribute: "icon" } }; }
|
|
639
|
-
render() {
|
|
640
|
-
this.classList.add("c-icon-badge");
|
|
641
|
-
const icon = this.getAttribute("icon");
|
|
642
|
-
if (icon) {
|
|
643
|
-
const sanitized = String(icon).replace(/[^a-zA-Z0-9_-]/g, "");
|
|
644
|
-
if (sanitized && !sanitized.startsWith("i-")) {
|
|
645
|
-
// Warn if icon name doesn't follow the i-* convention.
|
|
646
|
-
if (typeof console !== "undefined" && console.warn) {
|
|
647
|
-
console.warn("ContourIconBadge: icon '" + icon + "' may not exist in the sprite (expected i-* name).");
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
const existing = this.querySelector("svg");
|
|
651
|
-
const svg = existing || document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
652
|
-
if (!existing) {
|
|
653
|
-
svg.setAttribute("aria-hidden", "true");
|
|
654
|
-
const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
|
|
655
|
-
use.setAttribute("href", "#" + sanitized);
|
|
656
|
-
svg.appendChild(use);
|
|
657
|
-
this.appendChild(svg);
|
|
658
|
-
} else {
|
|
659
|
-
const use = svg.querySelector("use");
|
|
660
|
-
if (use) use.setAttribute("href", "#" + sanitized);
|
|
661
|
-
}
|
|
662
|
-
} else {
|
|
663
|
-
const svg = this.querySelector("svg");
|
|
664
|
-
if (svg) svg.remove();
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
define("contour-icon-badge", ContourIconBadge);
|
|
669
|
-
/**
|
|
670
|
-
* LiveBadge: a connection status badge with state/live modifiers and label.
|
|
671
|
-
* Attributes: `label`, `state`, `live`.
|
|
672
|
-
*/
|
|
673
|
-
class ContourLiveBadge extends ContourBase {
|
|
674
|
-
static get observed() { return ["label", "state", "live"]; }
|
|
675
|
-
static get properties() { return { label: { attribute: "label" }, state: { attribute: "state" }, live: { attribute: "live", type: Boolean } }; }
|
|
676
|
-
render() {
|
|
677
|
-
this.classList.add("c-live-badge");
|
|
678
|
-
// Remove previous state modifiers.
|
|
679
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-live-badge--")) this.classList.remove(c); });
|
|
680
|
-
const state = this.getAttribute("state");
|
|
681
|
-
if (state) {
|
|
682
|
-
this.classList.add("c-live-badge--" + state);
|
|
683
|
-
} else if (this.hasAttribute("live")) {
|
|
684
|
-
this.classList.add("c-live-badge--connected");
|
|
685
|
-
}
|
|
686
|
-
const label = this.getAttribute("label");
|
|
687
|
-
if (label && !this.hasChildNodes()) this.textContent = label;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
define("contour-live-badge", ContourLiveBadge);
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* SkeletonGroup: a group of N skeleton placeholders. Attribute: `count`.
|
|
694
|
-
*/
|
|
695
|
-
class ContourSkeletonGroup extends ContourBase {
|
|
696
|
-
static get observed() { return ["count"]; }
|
|
697
|
-
static get properties() { return { count: { attribute: "count", type: Number } }; }
|
|
698
|
-
render() {
|
|
699
|
-
this.classList.add("c-skeleton-group");
|
|
700
|
-
const count = Math.max(1, parseInt(this.getAttribute("count") || "3", 10) || 3);
|
|
701
|
-
Array.from(this.querySelectorAll(".c-skeleton")).forEach((n) => n.remove());
|
|
702
|
-
for (let i = 0; i < count; i++) {
|
|
703
|
-
const sk = document.createElement("div");
|
|
704
|
-
sk.className = "c-skeleton";
|
|
705
|
-
this.appendChild(sk);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
define("contour-skeleton-group", ContourSkeletonGroup);
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* MapPopup: a map popup dialog with title, content, and optional cluster
|
|
713
|
-
* badge (cluster-count / cluster-expanded). Attributes: `title`, `content`,
|
|
714
|
-
* `cluster-count`, `cluster-expanded`.
|
|
715
|
-
*/
|
|
716
|
-
class ContourMapPopup extends ContourBase {
|
|
717
|
-
static get observed() { return ["title", "content", "cluster-count", "cluster-expanded", "cluster-items"]; }
|
|
718
|
-
static get properties() { return { title: { attribute: "title" }, content: { attribute: "content" }, "cluster-count": { attribute: "cluster-count", type: Number }, "cluster-expanded": { attribute: "cluster-expanded", type: Boolean }, "cluster-items": { attribute: "cluster-items" } }; }
|
|
719
|
-
render() {
|
|
720
|
-
this.classList.add("c-map-popup");
|
|
721
|
-
this.setAttribute("role", "dialog");
|
|
722
|
-
if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
|
|
723
|
-
if (!this.id) this.id = contourId("map-popup");
|
|
724
|
-
const title = this.getAttribute("title");
|
|
725
|
-
if (title) {
|
|
726
|
-
const t = this.ensure(".c-map-popup__title", () => { const el = document.createElement("div"); el.className = "c-map-popup__title"; return el; });
|
|
727
|
-
t.textContent = title;
|
|
728
|
-
}
|
|
729
|
-
const content = this.getAttribute("content");
|
|
730
|
-
if (content) {
|
|
731
|
-
const c = this.ensure(".c-map-popup__body", () => { const el = document.createElement("div"); el.className = "c-map-popup__body"; return el; });
|
|
732
|
-
c.textContent = content;
|
|
733
|
-
}
|
|
734
|
-
const clusterCount = Number(this.getAttribute("cluster-count"));
|
|
735
|
-
if (Number.isFinite(clusterCount) && clusterCount > 1) {
|
|
736
|
-
const badge = this.ensure(".c-map-popup__cluster", () => { const el = document.createElement("button"); el.className = "c-map-popup__cluster c-btn c-btn--sm"; el.type = "button"; return el; });
|
|
737
|
-
const expanded = this.hasAttribute("cluster-expanded");
|
|
738
|
-
badge.textContent = expanded ? "Hide locations" : `${clusterCount} locations`;
|
|
739
|
-
badge.setAttribute("aria-expanded", String(expanded));
|
|
740
|
-
badge.setAttribute("aria-label", expanded ? "Hide locations" : `Show ${clusterCount} locations`);
|
|
741
|
-
} else {
|
|
742
|
-
const badge = this.querySelector(".c-map-popup__cluster");
|
|
743
|
-
if (badge) badge.remove();
|
|
744
|
-
}
|
|
745
|
-
// Spatial clustering (R14-28): render clustered locations when expanded.
|
|
746
|
-
const expanded = this.hasAttribute("cluster-expanded");
|
|
747
|
-
let items = [];
|
|
748
|
-
try { items = this.getAttribute("cluster-items") ? JSON.parse(this.getAttribute("cluster-items")) : []; } catch (e) { items = []; }
|
|
749
|
-
const list = this.querySelector(".c-map-popup__cluster-list");
|
|
750
|
-
if (expanded && Array.isArray(items) && items.length) {
|
|
751
|
-
const ul = list || document.createElement("ul");
|
|
752
|
-
ul.className = "c-map-popup__cluster-list";
|
|
753
|
-
ul.innerHTML = "";
|
|
754
|
-
items.forEach((it) => {
|
|
755
|
-
const li = document.createElement("li");
|
|
756
|
-
li.className = "c-map-popup__cluster-item";
|
|
757
|
-
li.textContent = typeof it === "string" ? it : (it.label || it.name || JSON.stringify(it));
|
|
758
|
-
ul.appendChild(li);
|
|
759
|
-
});
|
|
760
|
-
if (ul.parentNode !== this) this.appendChild(ul);
|
|
761
|
-
} else if (list) {
|
|
762
|
-
list.remove();
|
|
763
|
-
}
|
|
764
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", title || "Map popup");
|
|
765
|
-
}
|
|
766
|
-
enhance() {
|
|
767
|
-
if (this._wiredMapPopup) return;
|
|
768
|
-
this._wiredMapPopup = true;
|
|
769
|
-
const close = () => { try { this.hidePopover(); } catch (e) {} this.classList.remove("is-open"); this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); };
|
|
770
|
-
const keyHandler = (e) => { if (e.key === "Escape" && (this.classList.contains("is-open") || this.matches(":popover-open"))) { e.preventDefault(); close(); } };
|
|
771
|
-
document.addEventListener("keydown", keyHandler);
|
|
772
|
-
onDispose(this, () => document.removeEventListener("keydown", keyHandler));
|
|
773
|
-
this.addEventListener("click", (e) => {
|
|
774
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-map-popup__close") : null;
|
|
775
|
-
if (btn && this.contains(btn)) close();
|
|
776
|
-
const cluster = e.target && e.target.closest ? e.target.closest(".c-map-popup__cluster") : null;
|
|
777
|
-
if (cluster && this.contains(cluster)) {
|
|
778
|
-
const expanded = !this.hasAttribute("cluster-expanded");
|
|
779
|
-
this.toggleAttribute("cluster-expanded", expanded);
|
|
780
|
-
this.dispatchEvent(new CustomEvent("contour:cluster-toggle", { bubbles: true, composed: true, detail: { count: Number(this.getAttribute("cluster-count")), expanded } }));
|
|
781
|
-
}
|
|
782
|
-
});
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
define("contour-map-popup", ContourMapPopup);
|
|
786
|
-
|
|
787
|
-
/**
|
|
788
|
-
* AnimationControls: a media control toolbar with play/pause, speed, scrubber
|
|
789
|
-
* and caption. Attributes: `playing`, `speed`, `progress`, `min`, `max`,
|
|
790
|
-
* `caption`, `show-thumb`, `show-thumb-caption`.
|
|
791
|
-
*/
|
|
792
|
-
class ContourAnimationControls extends ContourBase {
|
|
793
|
-
static get observed() { return ["playing", "speed", "progress", "min", "max", "caption", "show-thumb", "show-thumb-caption"]; }
|
|
794
|
-
static get properties() { return { playing: { attribute: "playing", type: Boolean }, speed: { attribute: "speed" }, progress: { attribute: "progress" }, min: { attribute: "min" }, max: { attribute: "max" } }; }
|
|
795
|
-
render() {
|
|
796
|
-
this.classList.add("c-animation-controls");
|
|
797
|
-
this.setAttribute("role", "toolbar");
|
|
798
|
-
this.setAttribute("aria-label", "Animation controls");
|
|
799
|
-
const playBtn = this.ensure(".c-animation-controls__play", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-animation-controls__play"; el.type = "button"; return el; });
|
|
800
|
-
playBtn.textContent = this.hasAttribute("playing") ? "Pause" : "Play";
|
|
801
|
-
playBtn.setAttribute("aria-label", this.hasAttribute("playing") ? "Pause" : "Play");
|
|
802
|
-
const speed = this.getAttribute("speed") || "1x";
|
|
803
|
-
const speedBtn = this.ensure(".c-animation-controls__speed", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-animation-controls__speed"; el.type = "button"; return el; });
|
|
804
|
-
speedBtn.textContent = speed;
|
|
805
|
-
// scrubber
|
|
806
|
-
const scrubber = this.ensure(".c-animation-controls__scrubber", () => { const el = document.createElement("input"); el.className = "c-range c-animation-controls__scrubber"; el.type = "range"; return el; });
|
|
807
|
-
if (this.getAttribute("show-thumb") === "false") scrubber.classList.remove("c-animation-controls__scrubber--thumb");
|
|
808
|
-
else scrubber.classList.add("c-animation-controls__scrubber--thumb");
|
|
809
|
-
scrubber.min = this.getAttribute("min") || "0";
|
|
810
|
-
scrubber.max = this.getAttribute("max") || "100";
|
|
811
|
-
scrubber.value = this.getAttribute("progress") || "0";
|
|
812
|
-
const caption = this.getAttribute("caption");
|
|
813
|
-
if (caption) scrubber.setAttribute("aria-label", caption);
|
|
814
|
-
else if (!scrubber.getAttribute("aria-label")) scrubber.setAttribute("aria-label", "Playhead");
|
|
815
|
-
// caption display
|
|
816
|
-
const showCaption = this.hasAttribute("show-thumb-caption") || this.hasAttribute("show-thumb");
|
|
817
|
-
if (caption && showCaption) {
|
|
818
|
-
const cap = this.ensure(".c-animation-controls__caption", () => { const el = document.createElement("span"); el.className = "c-animation-controls__caption"; return el; });
|
|
819
|
-
cap.textContent = caption;
|
|
820
|
-
} else {
|
|
821
|
-
const cap = this.querySelector(".c-animation-controls__caption");
|
|
822
|
-
if (cap) cap.remove();
|
|
823
|
-
}
|
|
824
|
-
// showThumb: hide thumb via attribute? keep default
|
|
825
|
-
}
|
|
826
|
-
enhance() {
|
|
827
|
-
if (this._wiredAnimControls) return;
|
|
828
|
-
this._wiredAnimControls = true;
|
|
829
|
-
this.addEventListener("click", (e) => {
|
|
830
|
-
const play = e.target && e.target.closest ? e.target.closest(".c-animation-controls__play") : null;
|
|
831
|
-
const speed = e.target && e.target.closest ? e.target.closest(".c-animation-controls__speed") : null;
|
|
832
|
-
if (play && this.contains(play)) {
|
|
833
|
-
this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { playing: !this.hasAttribute("playing") } }));
|
|
834
|
-
}
|
|
835
|
-
if (speed && this.contains(speed)) {
|
|
836
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { speed: speed.textContent } }));
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
this.addEventListener("input", (e) => {
|
|
840
|
-
const scrubber = e.target && e.target.closest ? e.target.closest(".c-animation-controls__scrubber") : null;
|
|
841
|
-
if (scrubber && this.contains(scrubber)) {
|
|
842
|
-
const v = Number(scrubber.value);
|
|
843
|
-
this.dispatchEvent(new CustomEvent("contour:seek", { bubbles: true, composed: true, detail: { progress: v, value: v } }));
|
|
844
|
-
}
|
|
845
|
-
});
|
|
846
|
-
this.addEventListener("keydown", (e) => {
|
|
847
|
-
if (e.key === " " || e.key === "Enter") {
|
|
848
|
-
const play = this.querySelector(".c-animation-controls__play");
|
|
849
|
-
if (play && (e.target === play || !e.target || e.target === this)) { e.preventDefault(); play.click(); }
|
|
850
|
-
} else if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
|
|
851
|
-
const scrubber = this.querySelector(".c-animation-controls__scrubber");
|
|
852
|
-
if (scrubber) {
|
|
853
|
-
e.preventDefault();
|
|
854
|
-
const step = e.key === "ArrowRight" ? 1 : -1;
|
|
855
|
-
scrubber.value = String(Number(scrubber.value) + step);
|
|
856
|
-
scrubber.dispatchEvent(new Event("input", { bubbles: true }));
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
});
|
|
860
|
-
// Playback ownership: when `playing` is set, advance the playhead on a
|
|
861
|
-
// timer and emit contour:time-change so a consumer can sync its data.
|
|
862
|
-
let timer = null;
|
|
863
|
-
const speedFactor = () => {
|
|
864
|
-
const s = this.getAttribute("speed") || "1x";
|
|
865
|
-
const n = parseFloat(s);
|
|
866
|
-
return Number.isFinite(n) && n > 0 ? n : 1;
|
|
867
|
-
};
|
|
868
|
-
const tick = () => {
|
|
869
|
-
const scrubber = this.querySelector(".c-animation-controls__scrubber");
|
|
870
|
-
if (!scrubber) return;
|
|
871
|
-
const min = Number(scrubber.min || 0);
|
|
872
|
-
const max = Number(scrubber.max || 100);
|
|
873
|
-
let v = Number(scrubber.value || 0) + speedFactor();
|
|
874
|
-
if (v > max) v = min;
|
|
875
|
-
scrubber.value = String(v);
|
|
876
|
-
this.dispatchEvent(new CustomEvent("contour:time-change", { bubbles: true, composed: true, detail: { progress: v, value: v } }));
|
|
877
|
-
};
|
|
878
|
-
const start = () => { if (timer) return; timer = setInterval(tick, 100); };
|
|
879
|
-
const stop = () => { if (timer) { clearInterval(timer); timer = null; } };
|
|
880
|
-
if (this.hasAttribute("playing")) start();
|
|
881
|
-
const obs = new MutationObserver(() => { if (this.hasAttribute("playing")) start(); else stop(); });
|
|
882
|
-
obs.observe(this, { attributes: true, attributeFilter: ["playing"] });
|
|
883
|
-
onDispose(this, () => { stop(); obs.disconnect(); });
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
define("contour-animation-controls", ContourAnimationControls);
|
|
887
|
-
|
|
888
|
-
/**
|
|
889
|
-
* Dropdown: a trigger button with a menu of items from JSON `items` or slotted
|
|
890
|
-
* `.c-menu__item` children. Attributes: `label`, `items`.
|
|
891
|
-
*/
|
|
892
|
-
class ContourDropdown extends ContourBase {
|
|
893
|
-
static get observed() { return ["label", "items"]; }
|
|
894
|
-
static get properties() { return { label: { attribute: "label" }, items: { attribute: "items" } }; }
|
|
895
|
-
render() {
|
|
896
|
-
this.classList.add("c-dropdown");
|
|
897
|
-
const btn = this.ensure(".c-dropdown__trigger", () => { const el = document.createElement("button"); el.className = "c-dropdown__trigger c-btn c-btn--sm"; el.type = "button"; return el; });
|
|
898
|
-
btn.textContent = this.getAttribute("label") || "Menu";
|
|
899
|
-
const menu = this.ensure(".c-dropdown__menu", () => { const el = document.createElement("div"); el.className = "c-dropdown__menu c-menu"; el.setAttribute("role", "menu"); el.hidden = true; return el; });
|
|
900
|
-
// Slotted content: authored .c-menu__item children take precedence over
|
|
901
|
-
// the JSON `items` attribute.
|
|
902
|
-
const authoredItems = Array.from(this.querySelectorAll(":scope > .c-menu__item"));
|
|
903
|
-
const items = this.getAttribute("items");
|
|
904
|
-
if (authoredItems.length) {
|
|
905
|
-
menu.innerHTML = "";
|
|
906
|
-
authoredItems.forEach((it) => { menu.appendChild(it); });
|
|
907
|
-
} else if (items) {
|
|
908
|
-
try {
|
|
909
|
-
const parsed = JSON.parse(items);
|
|
910
|
-
menu.innerHTML = "";
|
|
911
|
-
parsed.forEach((it) => {
|
|
912
|
-
const li = document.createElement("button");
|
|
913
|
-
li.className = "c-menu__item";
|
|
914
|
-
li.setAttribute("role", "menuitem");
|
|
915
|
-
li.textContent = typeof it === "string" ? it : (it.label || it.title || "");
|
|
916
|
-
menu.appendChild(li);
|
|
917
|
-
});
|
|
918
|
-
} catch (e) { /* keep existing */ }
|
|
919
|
-
}
|
|
920
|
-
if (menu.parentNode !== this) this.appendChild(menu);
|
|
921
|
-
if (btn.parentNode !== this) this.insertBefore(btn, menu);
|
|
922
|
-
}
|
|
923
|
-
enhance() {
|
|
924
|
-
if (this._wiredDropdown) return;
|
|
925
|
-
this._wiredDropdown = true;
|
|
926
|
-
const btn = () => this.querySelector(".c-dropdown__trigger");
|
|
927
|
-
const menu = () => this.querySelector(".c-dropdown__menu");
|
|
928
|
-
this.addEventListener("click", (e) => {
|
|
929
|
-
const b = btn();
|
|
930
|
-
const m = menu();
|
|
931
|
-
// Item selection.
|
|
932
|
-
const item = e.target && e.target.closest ? e.target.closest(".c-menu__item") : null;
|
|
933
|
-
if (item && m && m.contains(item) && !m.hidden) {
|
|
934
|
-
const idx = Array.from(m.querySelectorAll(".c-menu__item")).indexOf(item);
|
|
935
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, value: item.textContent } }));
|
|
936
|
-
m.hidden = true;
|
|
937
|
-
if (b) { b.setAttribute("aria-expanded", "false"); try { b.focus(); } catch (err) {} }
|
|
938
|
-
return;
|
|
939
|
-
}
|
|
940
|
-
if (e.target === b || (b && b.contains(e.target))) {
|
|
941
|
-
if (m) {
|
|
942
|
-
m.hidden = !m.hidden;
|
|
943
|
-
b.setAttribute("aria-expanded", String(!m.hidden));
|
|
944
|
-
if (!m.hidden) {
|
|
945
|
-
if (!m.id) m.id = (this.id || contourId("dd")) + "-menu";
|
|
946
|
-
b.setAttribute("aria-controls", m.id);
|
|
947
|
-
const first = m.querySelector(".c-menu__item");
|
|
948
|
-
if (first) try { first.focus(); } catch (err) {}
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
});
|
|
953
|
-
const docClick = (e) => {
|
|
954
|
-
const m = menu();
|
|
955
|
-
const b = btn();
|
|
956
|
-
if (m && !m.hidden && !this.contains(e.target)) { m.hidden = true; if (b) b.setAttribute("aria-expanded", "false"); }
|
|
957
|
-
};
|
|
958
|
-
document.addEventListener("click", docClick);
|
|
959
|
-
onDispose(this, () => document.removeEventListener("click", docClick));
|
|
960
|
-
const keyHandler = (e) => {
|
|
961
|
-
const m = menu(); const b = btn();
|
|
962
|
-
if (e.key === "Escape" && m && !m.hidden) { e.preventDefault(); m.hidden = true; if (b) { b.setAttribute("aria-expanded", "false"); try { b.focus(); } catch (err) {} } return; }
|
|
963
|
-
if (!m || m.hidden) return;
|
|
964
|
-
const items = Array.from(m.querySelectorAll(".c-menu__item"));
|
|
965
|
-
const active = document.activeElement;
|
|
966
|
-
const idx = items.indexOf(active);
|
|
967
|
-
if (e.key === "ArrowDown") { e.preventDefault(); const next = items[Math.min(items.length - 1, idx + 1)] || items[0]; if (next) try { next.focus(); } catch (err) {} }
|
|
968
|
-
else if (e.key === "ArrowUp") { e.preventDefault(); const prev = items[Math.max(0, idx - 1)] || items[items.length - 1]; if (prev) try { prev.focus(); } catch (err) {} }
|
|
969
|
-
else if (e.key === "Enter" || e.key === " ") {
|
|
970
|
-
if (active && items.includes(active)) { e.preventDefault(); active.click(); }
|
|
971
|
-
}
|
|
972
|
-
};
|
|
973
|
-
document.addEventListener("keydown", keyHandler);
|
|
974
|
-
onDispose(this, () => document.removeEventListener("keydown", keyHandler));
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
define("contour-dropdown", ContourDropdown);
|
|
978
|
-
|
|
979
|
-
/**
|
|
980
|
-
* Annotation: a positioned note with label and x/y coordinates. Attributes:
|
|
981
|
-
* `label`, `x`, `y`.
|
|
982
|
-
*/
|
|
983
|
-
class ContourAnnotation extends ContourBase {
|
|
984
|
-
static get observed() { return ["label", "x", "y"]; }
|
|
985
|
-
static get properties() { return { label: { attribute: "label" }, x: { attribute: "x" }, y: { attribute: "y" } }; }
|
|
986
|
-
render() {
|
|
987
|
-
this.classList.add("c-annotation");
|
|
988
|
-
this.setAttribute("role", "note");
|
|
989
|
-
const label = this.getAttribute("label");
|
|
990
|
-
if (label) this.setAttribute("aria-label", label);
|
|
991
|
-
if (label) {
|
|
992
|
-
const l = this.ensure(".c-annotation__label", () => { const el = document.createElement("span"); el.className = "c-annotation__label"; return el; });
|
|
993
|
-
l.textContent = label;
|
|
994
|
-
}
|
|
995
|
-
const x = this.getAttribute("x");
|
|
996
|
-
const y = this.getAttribute("y");
|
|
997
|
-
if (x !== null) this.style.setProperty("--annotation-x", x);
|
|
998
|
-
if (y !== null) this.style.setProperty("--annotation-y", y);
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
define("contour-annotation", ContourAnnotation);
|
|
1002
|
-
|
|
1003
|
-
/**
|
|
1004
|
-
* Style Switcher: web component wrapper.
|
|
1005
|
-
* Attributes: `items`, `value`.
|
|
1006
|
-
*/
|
|
1007
|
-
class ContourStyleSwitcher extends ContourBase {
|
|
1008
|
-
static get observed() { return ["items", "value"]; }
|
|
1009
|
-
static get properties() { return { items: { attribute: "items" }, value: { attribute: "value" } }; }
|
|
1010
|
-
render() {
|
|
1011
|
-
this.classList.add("c-style-switcher");
|
|
1012
|
-
const items = this.getAttribute("items");
|
|
1013
|
-
const value = this.getAttribute("value");
|
|
1014
|
-
Array.from(this.querySelectorAll(".c-style-switcher__option")).forEach((n) => n.remove());
|
|
1015
|
-
if (items) {
|
|
1016
|
-
try {
|
|
1017
|
-
const parsed = JSON.parse(items);
|
|
1018
|
-
parsed.forEach((it) => {
|
|
1019
|
-
const name = typeof it === "string" ? it : (it.name || it.label || "");
|
|
1020
|
-
const btn = document.createElement("button");
|
|
1021
|
-
btn.className = "c-style-switcher__option c-btn c-btn--sm";
|
|
1022
|
-
btn.type = "button";
|
|
1023
|
-
btn.textContent = name;
|
|
1024
|
-
if (name === value) btn.classList.add("c-style-switcher__option--active");
|
|
1025
|
-
btn.dataset.value = name;
|
|
1026
|
-
this.appendChild(btn);
|
|
1027
|
-
});
|
|
1028
|
-
} catch (e) { /* keep existing */ }
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
enhance() {
|
|
1032
|
-
if (this._wiredStyleSwitcher) return;
|
|
1033
|
-
this._wiredStyleSwitcher = true;
|
|
1034
|
-
this.addEventListener("click", (e) => {
|
|
1035
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-style-switcher__option") : null;
|
|
1036
|
-
if (btn && this.contains(btn)) {
|
|
1037
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: btn.dataset.value } }));
|
|
1038
|
-
}
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
define("contour-style-switcher", ContourStyleSwitcher);
|
|
1043
|
-
|
|
1044
|
-
/**
|
|
1045
|
-
* Style Panel: web component wrapper.
|
|
1046
|
-
* Attributes: `title`, `layers`, `layer`, `single`, `classification`, `palette`, `breaks`, `opacity`, `n`, `colors`, `property`.
|
|
1047
|
-
*/
|
|
1048
|
-
class ContourStylePanel extends ContourBase {
|
|
1049
|
-
static get observed() { return ["title", "layers", "layer", "single", "classification", "palette", "breaks", "opacity", "n", "colors", "property"]; }
|
|
1050
|
-
static get properties() { return { title: { attribute: "title" }, layers: { attribute: "layers" }, classification: { attribute: "classification" }, palette: { attribute: "palette" }, breaks: { attribute: "breaks" }, opacity: { attribute: "opacity" } }; }
|
|
1051
|
-
render() {
|
|
1052
|
-
this.classList.add("c-style-panel");
|
|
1053
|
-
this.setAttribute("role", "group");
|
|
1054
|
-
this.setAttribute("aria-label", "Style panel");
|
|
1055
|
-
const title = this.getAttribute("title");
|
|
1056
|
-
if (title) {
|
|
1057
|
-
const t = this.ensure(".c-style-panel__title", () => { const el = document.createElement("div"); el.className = "c-style-panel__title"; return el; });
|
|
1058
|
-
t.textContent = title;
|
|
1059
|
-
}
|
|
1060
|
-
const singleMode = this.hasAttribute("single") || !!this.getAttribute("layer");
|
|
1061
|
-
if (singleMode) {
|
|
1062
|
-
const body = this.ensure(".c-style-panel__body", () => { const el = document.createElement("div"); el.className = "c-style-panel__body"; return el; });
|
|
1063
|
-
body.innerHTML = "";
|
|
1064
|
-
// property field
|
|
1065
|
-
const propLabel = document.createElement("label"); propLabel.textContent = "Colour field"; propLabel.setAttribute("for", "property"); body.appendChild(propLabel);
|
|
1066
|
-
const propIn = document.createElement("input"); propIn.type = "text"; propIn.id = "property"; propIn.className = "c-style-panel__property c-input"; propIn.setAttribute("aria-label", "Colour field");
|
|
1067
|
-
const pv = this.getAttribute("property"); if (pv) propIn.value = pv;
|
|
1068
|
-
body.appendChild(propIn);
|
|
1069
|
-
// classification method selector (policy)
|
|
1070
|
-
const clsLabel = document.createElement("label"); clsLabel.textContent = "Classification"; clsLabel.setAttribute("for", "policy"); body.appendChild(clsLabel);
|
|
1071
|
-
const clsSel = document.createElement("select"); clsSel.id = "policy"; clsSel.className = "c-style-panel__classification c-input"; clsSel.setAttribute("aria-label", "Classification method");
|
|
1072
|
-
["equal","quantile","jenks","manual"].forEach((m) => { const o = document.createElement("option"); o.value = m; o.textContent = m; clsSel.appendChild(o); });
|
|
1073
|
-
const cls = this.getAttribute("classification"); if (cls) clsSel.value = cls;
|
|
1074
|
-
body.appendChild(clsSel);
|
|
1075
|
-
// palette picker
|
|
1076
|
-
const palLabel = document.createElement("label"); palLabel.textContent = "Palette"; palLabel.setAttribute("for", "palette"); body.appendChild(palLabel);
|
|
1077
|
-
const pal = document.createElement("input"); pal.type = "text"; pal.id = "palette"; pal.className = "c-style-panel__palette c-input"; pal.placeholder = "palette"; pal.setAttribute("aria-label", "Palette");
|
|
1078
|
-
const palv = this.getAttribute("palette"); if (palv) pal.value = palv;
|
|
1079
|
-
body.appendChild(pal);
|
|
1080
|
-
// n (class count)
|
|
1081
|
-
const nLabel = document.createElement("label"); nLabel.textContent = "Classes"; nLabel.setAttribute("for", "n"); body.appendChild(nLabel);
|
|
1082
|
-
const nIn = document.createElement("input"); nIn.type = "number"; nIn.id = "n"; nIn.className = "c-style-panel__n c-input"; nIn.min = "2"; nIn.max = "12"; nIn.setAttribute("aria-label", "Class count");
|
|
1083
|
-
const nv = this.getAttribute("n"); if (nv) nIn.value = nv; else nIn.value = "5";
|
|
1084
|
-
body.appendChild(nIn);
|
|
1085
|
-
// opacity slider
|
|
1086
|
-
const op = document.createElement("input"); op.type = "range"; op.className = "c-style-panel__opacity"; op.setAttribute("aria-label", "Opacity"); op.min = "0"; op.max = "100";
|
|
1087
|
-
const ov = this.getAttribute("opacity"); op.value = ov != null ? ov : "100";
|
|
1088
|
-
body.appendChild(op);
|
|
1089
|
-
// breaks as .break elements per class
|
|
1090
|
-
const breaksAttr = this.getAttribute("breaks");
|
|
1091
|
-
let breaksArr = null;
|
|
1092
|
-
if (breaksAttr) { try { breaksArr = JSON.parse(breaksAttr); } catch (e) { breaksArr = breaksAttr.split(",").map((s) => s.trim()); } }
|
|
1093
|
-
if (Array.isArray(breaksArr) && breaksArr.length) {
|
|
1094
|
-
const breaksWrap = document.createElement("div"); breaksWrap.className = "c-style-panel__breaks";
|
|
1095
|
-
breaksArr.forEach((b, i) => {
|
|
1096
|
-
const br = document.createElement("div"); br.className = "break";
|
|
1097
|
-
const span = document.createElement("span"); span.textContent = String(b); br.appendChild(span);
|
|
1098
|
-
const inp = document.createElement("input"); inp.type = "number"; inp.className = "c-style-panel__breaks c-input"; inp.setAttribute("aria-label", "Class lower bound"); inp.value = String(b);
|
|
1099
|
-
br.appendChild(inp);
|
|
1100
|
-
breaksWrap.appendChild(br);
|
|
1101
|
-
});
|
|
1102
|
-
body.appendChild(breaksWrap);
|
|
1103
|
-
}
|
|
1104
|
-
// color swatches
|
|
1105
|
-
const colorsAttr = this.getAttribute("colors");
|
|
1106
|
-
let colors = null;
|
|
1107
|
-
if (colorsAttr) { try { colors = JSON.parse(colorsAttr); } catch (e) { colors = colorsAttr.split(",").map((s) => s.trim()); } }
|
|
1108
|
-
if (Array.isArray(colors)) {
|
|
1109
|
-
const list = document.createElement("div"); list.className = "c-style-panel__colors";
|
|
1110
|
-
colors.forEach((c, i) => {
|
|
1111
|
-
const sw = document.createElement("input"); sw.type = "color"; sw.className = "c-style-panel__color c-input"; sw.setAttribute("aria-label", "Colour for class " + (i + 1));
|
|
1112
|
-
sw.value = c;
|
|
1113
|
-
sw.addEventListener("input", () => { sw.setAttribute("data-edited", "true"); });
|
|
1114
|
-
list.appendChild(sw);
|
|
1115
|
-
});
|
|
1116
|
-
body.appendChild(list);
|
|
1117
|
-
}
|
|
1118
|
-
// Apply/Revert buttons
|
|
1119
|
-
const actions = document.createElement("div"); actions.className = "c-style-panel__actions c-btn-group";
|
|
1120
|
-
const applyBtn = document.createElement("button"); applyBtn.type = "button"; applyBtn.className = "c-btn c-btn--primary"; applyBtn.textContent = "Apply";
|
|
1121
|
-
const revertBtn = document.createElement("button"); revertBtn.type = "button"; revertBtn.className = "c-btn"; revertBtn.textContent = "Revert";
|
|
1122
|
-
actions.appendChild(applyBtn); actions.appendChild(revertBtn);
|
|
1123
|
-
body.appendChild(actions);
|
|
1124
|
-
return;
|
|
1125
|
-
}
|
|
1126
|
-
const layers = this.getAttribute("layers");
|
|
1127
|
-
const body = this.ensure(".c-style-panel__body", () => { const el = document.createElement("div"); el.className = "c-style-panel__body"; return el; });
|
|
1128
|
-
// Slotted content support: authored .c-style-panel__row children take
|
|
1129
|
-
// precedence over the JSON `layers` attribute.
|
|
1130
|
-
const authoredRows = Array.from(this.querySelectorAll(":scope > .c-style-panel__row"));
|
|
1131
|
-
let parsed = null;
|
|
1132
|
-
if (authoredRows.length) {
|
|
1133
|
-
parsed = authoredRows.map((row) => ({
|
|
1134
|
-
name: row.querySelector(".c-style-panel__name")?.textContent || "",
|
|
1135
|
-
color: row.querySelector(".c-style-panel__color")?.value,
|
|
1136
|
-
classification: row.querySelector(".c-style-panel__classification")?.value,
|
|
1137
|
-
palette: row.querySelector(".c-style-panel__palette")?.value,
|
|
1138
|
-
breaks: row.querySelector(".c-style-panel__breaks")?.value,
|
|
1139
|
-
opacity: row.querySelector(".c-style-panel__opacity")?.value,
|
|
1140
|
-
}));
|
|
1141
|
-
authoredRows.forEach((row) => row.remove());
|
|
1142
|
-
} else if (layers) {
|
|
1143
|
-
try {
|
|
1144
|
-
parsed = JSON.parse(layers);
|
|
1145
|
-
} catch (e) { parsed = null; }
|
|
1146
|
-
}
|
|
1147
|
-
if (parsed) {
|
|
1148
|
-
body.innerHTML = "";
|
|
1149
|
-
parsed.forEach((l) => {
|
|
1150
|
-
const row = document.createElement("div");
|
|
1151
|
-
row.className = "c-style-panel__row";
|
|
1152
|
-
const name = document.createElement("span");
|
|
1153
|
-
name.className = "c-style-panel__name";
|
|
1154
|
-
name.textContent = typeof l === "string" ? l : (l.name || l.label || "");
|
|
1155
|
-
row.appendChild(name);
|
|
1156
|
-
const input = document.createElement("input");
|
|
1157
|
-
input.type = "color";
|
|
1158
|
-
input.className = "c-style-panel__color";
|
|
1159
|
-
input.setAttribute("aria-label", "Colour for " + (typeof l === "string" ? l : (l.name || l.label || "layer")));
|
|
1160
|
-
if (typeof l === "object" && l.color) input.value = l.color;
|
|
1161
|
-
row.appendChild(input);
|
|
1162
|
-
// classification method selector
|
|
1163
|
-
const clsSel = document.createElement("select");
|
|
1164
|
-
clsSel.className = "c-style-panel__classification";
|
|
1165
|
-
clsSel.setAttribute("aria-label", "Classification method");
|
|
1166
|
-
["equal","quantile","jenks","manual"].forEach((m) => { const o = document.createElement("option"); o.value = m; o.textContent = m; clsSel.appendChild(o); });
|
|
1167
|
-
if (typeof l === "object" && l.classification) clsSel.value = l.classification;
|
|
1168
|
-
row.appendChild(clsSel);
|
|
1169
|
-
// palette picker
|
|
1170
|
-
const pal = document.createElement("input");
|
|
1171
|
-
pal.type = "text";
|
|
1172
|
-
pal.className = "c-style-panel__palette";
|
|
1173
|
-
pal.setAttribute("aria-label", "Palette");
|
|
1174
|
-
pal.placeholder = "palette";
|
|
1175
|
-
if (typeof l === "object" && l.palette) pal.value = l.palette;
|
|
1176
|
-
row.appendChild(pal);
|
|
1177
|
-
// breaks editor
|
|
1178
|
-
const breaks = document.createElement("input");
|
|
1179
|
-
breaks.type = "text";
|
|
1180
|
-
breaks.className = "c-style-panel__breaks";
|
|
1181
|
-
breaks.placeholder = "breaks";
|
|
1182
|
-
if (typeof l === "object" && l.breaks) breaks.value = (Array.isArray(l.breaks) ? l.breaks.join(",") : l.breaks);
|
|
1183
|
-
row.appendChild(breaks);
|
|
1184
|
-
// opacity control
|
|
1185
|
-
const op = document.createElement("input");
|
|
1186
|
-
op.type = "range";
|
|
1187
|
-
op.className = "c-style-panel__opacity";
|
|
1188
|
-
op.setAttribute("aria-label", "Opacity");
|
|
1189
|
-
op.min = "0"; op.max = "100";
|
|
1190
|
-
op.value = (typeof l === "object" && l.opacity != null) ? l.opacity : "100";
|
|
1191
|
-
row.appendChild(op);
|
|
1192
|
-
body.appendChild(row);
|
|
1193
|
-
});
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
enhance() {
|
|
1197
|
-
if (this._wiredStylePanel) return;
|
|
1198
|
-
this._wiredStylePanel = true;
|
|
1199
|
-
this.addEventListener("change", (e) => {
|
|
1200
|
-
const t = e.target;
|
|
1201
|
-
if (!t || !this.contains(t)) return;
|
|
1202
|
-
const row = t.closest(".c-style-panel__row");
|
|
1203
|
-
const name = row ? (row.querySelector(".c-style-panel__name")?.textContent || "") : "";
|
|
1204
|
-
if (t.classList.contains("c-style-panel__color")) {
|
|
1205
|
-
this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: t.value, layer: name, property: "color" }, bubbles: true, composed: true }));
|
|
1206
|
-
} else if (t.classList.contains("c-style-panel__classification")) {
|
|
1207
|
-
this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value, layer: name }, bubbles: true, composed: true }));
|
|
1208
|
-
} else if (t.classList.contains("c-style-panel__opacity")) {
|
|
1209
|
-
this.dispatchEvent(new CustomEvent("contour:layer-opacity", { detail: { name, opacity: Number(t.value) }, bubbles: true, composed: true }));
|
|
1210
|
-
} else if (t.classList.contains("c-style-panel__property")) {
|
|
1211
|
-
this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: t.value, layer: name, property: "property" }, bubbles: true, composed: true }));
|
|
1212
|
-
} else if (t.classList.contains("c-style-panel__n")) {
|
|
1213
|
-
this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: Number(t.value), layer: name, property: "n" }, bubbles: true, composed: true }));
|
|
1214
|
-
}
|
|
1215
|
-
});
|
|
1216
|
-
this.addEventListener("input", (e) => {
|
|
1217
|
-
const t = e.target;
|
|
1218
|
-
if (!t || !this.contains(t)) return;
|
|
1219
|
-
if (t.classList.contains("c-style-panel__palette") || t.classList.contains("c-style-panel__breaks")) {
|
|
1220
|
-
const row = t.closest(".c-style-panel__row");
|
|
1221
|
-
const name = row ? (row.querySelector(".c-style-panel__name")?.textContent || "") : "";
|
|
1222
|
-
this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: t.value, layer: name, property: t.classList.contains("c-style-panel__palette") ? "palette" : "breaks" }, bubbles: true, composed: true }));
|
|
1223
|
-
}
|
|
1224
|
-
});
|
|
1225
|
-
this.addEventListener("click", (e) => {
|
|
1226
|
-
const t = e.target && e.target.closest ? e.target.closest("button") : null;
|
|
1227
|
-
if (!t || !this.contains(t)) return;
|
|
1228
|
-
if (t.textContent.trim() === "Apply") {
|
|
1229
|
-
this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { applied: true }, bubbles: true, composed: true }));
|
|
1230
|
-
} else if (t.textContent.trim() === "Revert") {
|
|
1231
|
-
this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { applied: false }, bubbles: true, composed: true }));
|
|
1232
|
-
}
|
|
1233
|
-
});
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
define("contour-style-panel", ContourStylePanel);
|
|
1237
|
-
|
|
1238
|
-
/**
|
|
1239
|
-
* Responsive Content: web component wrapper.
|
|
1240
|
-
* Attributes: `breakpoint`.
|
|
1241
|
-
*/
|
|
1242
|
-
class ContourResponsiveContent extends ContourBase {
|
|
1243
|
-
static get observed() { return ["breakpoint"]; }
|
|
1244
|
-
static get properties() { return { breakpoint: { attribute: "breakpoint" } }; }
|
|
1245
|
-
render() {
|
|
1246
|
-
this.classList.add("c-responsive-content");
|
|
1247
|
-
const bp = this.getAttribute("breakpoint") || "md";
|
|
1248
|
-
this.dataset.breakpoint = bp;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
define("contour-responsive-content", ContourResponsiveContent);
|
|
1252
|
-
|
|
1253
|
-
/**
|
|
1254
|
-
* Avatar Group: web component wrapper.
|
|
1255
|
-
* Attributes: `items`, `max`.
|
|
1256
|
-
*/
|
|
1257
|
-
class ContourAvatarGroup extends ContourBase {
|
|
1258
|
-
static get observed() { return ["items", "max"]; }
|
|
1259
|
-
static get properties() { return { items: { attribute: "items" }, max: { attribute: "max", type: Number } }; }
|
|
1260
|
-
render() {
|
|
1261
|
-
this.classList.add("c-avatar-group");
|
|
1262
|
-
const items = this.getAttribute("items");
|
|
1263
|
-
const max = parseInt(this.getAttribute("max") || "4", 10) || 4;
|
|
1264
|
-
Array.from(this.querySelectorAll(".c-avatar, .c-avatar-group__overflow")).forEach((n) => n.remove());
|
|
1265
|
-
if (items) {
|
|
1266
|
-
try {
|
|
1267
|
-
const parsed = JSON.parse(items);
|
|
1268
|
-
const shown = parsed.slice(0, max);
|
|
1269
|
-
shown.forEach((it) => {
|
|
1270
|
-
const av = document.createElement("span");
|
|
1271
|
-
av.className = "c-avatar";
|
|
1272
|
-
const name = typeof it === "string" ? it : (it.name || it.label || "");
|
|
1273
|
-
av.textContent = name.slice(0, 2).toUpperCase();
|
|
1274
|
-
if (typeof it === "object" && it.color) { av.style.background = it.color; av.dataset.color = it.color; }
|
|
1275
|
-
this.appendChild(av);
|
|
1276
|
-
});
|
|
1277
|
-
if (parsed.length > max) {
|
|
1278
|
-
const overflow = document.createElement("span");
|
|
1279
|
-
overflow.className = "c-avatar c-avatar-group__overflow";
|
|
1280
|
-
overflow.textContent = "+" + (parsed.length - max);
|
|
1281
|
-
this.appendChild(overflow);
|
|
1282
|
-
}
|
|
1283
|
-
} catch (e) { /* keep existing */ }
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
define("contour-avatar-group", ContourAvatarGroup);
|
|
1288
|
-
|
|
1289
|
-
/**
|
|
1290
|
-
* Divider: web component wrapper.
|
|
1291
|
-
* Attributes: `label`, `orientation`.
|
|
1292
|
-
*/
|
|
1293
|
-
class ContourDivider extends ContourBase {
|
|
1294
|
-
static get observed() { return ["label", "orientation"]; }
|
|
1295
|
-
static get properties() { return { label: { attribute: "label" }, orientation: { attribute: "orientation" } }; }
|
|
1296
|
-
render() {
|
|
1297
|
-
this.classList.add("c-divider");
|
|
1298
|
-
const orientation = this.getAttribute("orientation") || "horizontal";
|
|
1299
|
-
this.classList.add("c-divider--" + orientation);
|
|
1300
|
-
const label = this.getAttribute("label");
|
|
1301
|
-
if (label) {
|
|
1302
|
-
const l = this.ensure(".c-divider__label", () => { const el = document.createElement("span"); el.className = "c-divider__label"; return el; });
|
|
1303
|
-
l.textContent = label;
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
define("contour-divider", ContourDivider);
|
|
1308
|
-
|
|
1309
|
-
/**
|
|
1310
|
-
* Status Light: web component wrapper.
|
|
1311
|
-
* Attributes: `status`, `label`.
|
|
1312
|
-
*/
|
|
1313
|
-
class ContourStatusLight extends ContourBase {
|
|
1314
|
-
static get observed() { return ["status", "label"]; }
|
|
1315
|
-
static get properties() { return { status: { attribute: "status" }, label: { attribute: "label" } }; }
|
|
1316
|
-
render() {
|
|
1317
|
-
this.classList.add("c-status-light");
|
|
1318
|
-
const status = this.getAttribute("status") || "neutral";
|
|
1319
|
-
this.classList.add("c-status-light--" + status);
|
|
1320
|
-
const label = this.getAttribute("label");
|
|
1321
|
-
if (label) {
|
|
1322
|
-
const l = this.ensure(".c-status-light__label", () => { const el = document.createElement("span"); el.className = "c-status-light__label"; return el; });
|
|
1323
|
-
l.textContent = label;
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
define("contour-status-light", ContourStatusLight);
|
|
1328
|
-
|
|
1329
|
-
/**
|
|
1330
|
-
* Split Button: web component wrapper.
|
|
1331
|
-
* Attributes: `label`, `menu`.
|
|
1332
|
-
*/
|
|
1333
|
-
class ContourSplitButton extends ContourBase {
|
|
1334
|
-
static get observed() { return ["label", "menu"]; }
|
|
1335
|
-
static get properties() { return { label: { attribute: "label" }, menu: { attribute: "menu" } }; }
|
|
1336
|
-
render() {
|
|
1337
|
-
this.classList.add("c-split-button");
|
|
1338
|
-
const main = this.ensure(".c-split-button__main", () => { const el = document.createElement("button"); el.className = "c-btn c-split-button__main"; el.type = "button"; return el; });
|
|
1339
|
-
main.textContent = this.getAttribute("label") || "Action";
|
|
1340
|
-
const toggle = this.ensure(".c-split-button__toggle", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--icon c-split-button__toggle"; el.type = "button"; el.setAttribute("aria-label", "More options"); el.textContent = "▾"; return el; });
|
|
1341
|
-
const menu = this.ensure(".c-split-button__menu", () => { const el = document.createElement("div"); el.className = "c-menu c-split-button__menu"; el.setAttribute("role", "menu"); el.hidden = true; return el; });
|
|
1342
|
-
const items = this.getAttribute("menu");
|
|
1343
|
-
if (items) {
|
|
1344
|
-
try {
|
|
1345
|
-
const parsed = JSON.parse(items);
|
|
1346
|
-
menu.innerHTML = "";
|
|
1347
|
-
parsed.forEach((it) => {
|
|
1348
|
-
const li = document.createElement("button");
|
|
1349
|
-
li.className = "c-menu__item";
|
|
1350
|
-
li.setAttribute("role", "menuitem");
|
|
1351
|
-
li.textContent = typeof it === "string" ? it : (it.label || it.title || "");
|
|
1352
|
-
menu.appendChild(li);
|
|
1353
|
-
});
|
|
1354
|
-
} catch (e) { /* keep existing */ }
|
|
1355
|
-
}
|
|
1356
|
-
if (main.parentNode !== this) this.appendChild(main);
|
|
1357
|
-
if (toggle.parentNode !== this) this.appendChild(toggle);
|
|
1358
|
-
if (menu.parentNode !== this) this.appendChild(menu);
|
|
1359
|
-
}
|
|
1360
|
-
enhance() {
|
|
1361
|
-
if (this._wiredSplitButton) return;
|
|
1362
|
-
this._wiredSplitButton = true;
|
|
1363
|
-
const toggle = () => this.querySelector(".c-split-button__toggle");
|
|
1364
|
-
const menu = () => this.querySelector(".c-split-button__menu");
|
|
1365
|
-
this.addEventListener("click", (e) => {
|
|
1366
|
-
const t = toggle();
|
|
1367
|
-
if (e.target === t || (t && t.contains(e.target))) {
|
|
1368
|
-
const m = menu();
|
|
1369
|
-
if (m) { m.hidden = !m.hidden; t.setAttribute("aria-expanded", String(!m.hidden)); this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { open: !m.hidden } })); }
|
|
1370
|
-
}
|
|
1371
|
-
const item = e.target && e.target.closest ? e.target.closest(".c-menu__item") : null;
|
|
1372
|
-
if (item && this.contains(item)) {
|
|
1373
|
-
const m = menu();
|
|
1374
|
-
if (m) { m.hidden = true; const t = toggle(); if (t) t.setAttribute("aria-expanded", "false"); }
|
|
1375
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { label: item.textContent } }));
|
|
1376
|
-
}
|
|
1377
|
-
});
|
|
1378
|
-
this.addEventListener("keydown", (e) => {
|
|
1379
|
-
const t = toggle();
|
|
1380
|
-
if ((e.target === t || (t && t.contains(e.target))) && (e.key === "Enter" || e.key === " ")) {
|
|
1381
|
-
e.preventDefault();
|
|
1382
|
-
const m = menu();
|
|
1383
|
-
if (m) { m.hidden = !m.hidden; t.setAttribute("aria-expanded", String(!m.hidden)); }
|
|
1384
|
-
} else if (e.key === "Escape") {
|
|
1385
|
-
const m = menu();
|
|
1386
|
-
if (m && !m.hidden) { m.hidden = true; if (t) t.setAttribute("aria-expanded", "false"); }
|
|
1387
|
-
}
|
|
1388
|
-
});
|
|
1389
|
-
const docClick = (e) => {
|
|
1390
|
-
const m = menu();
|
|
1391
|
-
const t = toggle();
|
|
1392
|
-
if (m && !m.hidden && !this.contains(e.target)) { m.hidden = true; if (t) t.setAttribute("aria-expanded", "false"); }
|
|
1393
|
-
};
|
|
1394
|
-
document.addEventListener("click", docClick);
|
|
1395
|
-
onDispose(this, () => document.removeEventListener("click", docClick));
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
define("contour-split-button", ContourSplitButton);
|
|
1399
|
-
|
|
1400
|
-
/**
|
|
1401
|
-
* Palette Editor: web component wrapper.
|
|
1402
|
-
* Attributes: `colors`.
|
|
1403
|
-
*/
|
|
1404
|
-
class ContourPaletteEditor extends ContourBase {
|
|
1405
|
-
static get observed() { return ["colors"]; }
|
|
1406
|
-
static get properties() { return { colors: { attribute: "colors" } }; }
|
|
1407
|
-
render() {
|
|
1408
|
-
this.classList.add("c-palette-editor");
|
|
1409
|
-
const colors = this.getAttribute("colors");
|
|
1410
|
-
Array.from(this.querySelectorAll(".c-palette-editor__swatch")).forEach((n) => n.remove());
|
|
1411
|
-
if (colors) {
|
|
1412
|
-
try {
|
|
1413
|
-
const parsed = JSON.parse(colors);
|
|
1414
|
-
parsed.forEach((c) => {
|
|
1415
|
-
const sw = document.createElement("button");
|
|
1416
|
-
sw.className = "c-palette-editor__swatch c-swatch";
|
|
1417
|
-
sw.type = "button";
|
|
1418
|
-
sw.style.background = typeof c === "string" ? c : (c.color || c.value || "");
|
|
1419
|
-
sw.dataset.color = typeof c === "string" ? c : (c.color || c.value || "");
|
|
1420
|
-
sw.setAttribute("aria-label", typeof c === "string" ? c : (c.name || c.label || "color"));
|
|
1421
|
-
this.appendChild(sw);
|
|
1422
|
-
});
|
|
1423
|
-
} catch (e) { /* keep existing */ }
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
enhance() {
|
|
1427
|
-
if (this._wiredPaletteEditor) return;
|
|
1428
|
-
this._wiredPaletteEditor = true;
|
|
1429
|
-
this.addEventListener("click", (e) => {
|
|
1430
|
-
const sw = e.target && e.target.closest ? e.target.closest(".c-palette-editor__swatch") : null;
|
|
1431
|
-
if (sw && this.contains(sw)) {
|
|
1432
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { color: (sw.dataset && sw.dataset.color) || sw.style.background } }));
|
|
1433
|
-
}
|
|
1434
|
-
});
|
|
1435
|
-
this.addEventListener("keydown", (e) => {
|
|
1436
|
-
const swatches = Array.from(this.querySelectorAll(".c-palette-editor__swatch"));
|
|
1437
|
-
const active = document.activeElement;
|
|
1438
|
-
const idx = swatches.indexOf(active);
|
|
1439
|
-
if (e.key === "ArrowRight") { e.preventDefault(); const next = swatches[Math.min(swatches.length - 1, idx + 1)] || swatches[0]; if (next) try { next.focus(); } catch (err) {} }
|
|
1440
|
-
else if (e.key === "ArrowLeft") { e.preventDefault(); const prev = swatches[Math.max(0, idx - 1)] || swatches[swatches.length - 1]; if (prev) try { prev.focus(); } catch (err) {} }
|
|
1441
|
-
else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); if (active && active.classList.contains("c-palette-editor__swatch")) active.click(); }
|
|
1442
|
-
});
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
define("contour-palette-editor", ContourPaletteEditor);
|
|
1446
|
-
|
|
1447
|
-
/**
|
|
1448
|
-
* Date Range: web component wrapper.
|
|
1449
|
-
* Attributes: `start`, `end`, `label`, `time`, `min`, `max`, `locale`.
|
|
1450
|
-
*/
|
|
1451
|
-
class ContourDateRange extends ContourBase {
|
|
1452
|
-
static get observed() { return ["start", "end", "label", "time", "min", "max", "locale"]; }
|
|
1453
|
-
static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, label: { attribute: "label" }, time: { attribute: "time", type: Boolean }, min: { attribute: "min" }, max: { attribute: "max" }, locale: { attribute: "locale" } }; }
|
|
1454
|
-
render() {
|
|
1455
|
-
this.classList.add("c-date-range");
|
|
1456
|
-
this.setAttribute("role", "group");
|
|
1457
|
-
this.setAttribute("aria-label", "Date range");
|
|
1458
|
-
const label = this.getAttribute("label");
|
|
1459
|
-
if (label) {
|
|
1460
|
-
const l = this.ensure(".c-date-range__label", () => { const el = document.createElement("span"); el.className = "c-date-range__label"; return el; });
|
|
1461
|
-
l.textContent = label;
|
|
1462
|
-
}
|
|
1463
|
-
const start = this.ensure(".c-date-range__start", () => { const el = document.createElement("input"); el.className = "c-input c-date-range__start"; return el; });
|
|
1464
|
-
start.type = this.hasAttribute("time") ? "datetime-local" : "date";
|
|
1465
|
-
start.value = this.getAttribute("start") || "";
|
|
1466
|
-
const end = this.ensure(".c-date-range__end", () => { const el = document.createElement("input"); el.className = "c-input c-date-range__end"; return el; });
|
|
1467
|
-
end.type = start.type;
|
|
1468
|
-
end.value = this.getAttribute("end") || "";
|
|
1469
|
-
const min = this.getAttribute("min");
|
|
1470
|
-
const max = this.getAttribute("max");
|
|
1471
|
-
[start, end].forEach((input) => {
|
|
1472
|
-
if (min) input.min = min; else input.removeAttribute("min");
|
|
1473
|
-
if (max) input.max = max; else input.removeAttribute("max");
|
|
1474
|
-
if (this.getAttribute("locale")) input.lang = this.getAttribute("locale");
|
|
1475
|
-
});
|
|
1476
|
-
}
|
|
1477
|
-
enhance() {
|
|
1478
|
-
if (this._wiredDateRange) return;
|
|
1479
|
-
this._wiredDateRange = true;
|
|
1480
|
-
this.addEventListener("change", (e) => {
|
|
1481
|
-
const t = e.target;
|
|
1482
|
-
if (t && (t.classList.contains("c-date-range__start") || t.classList.contains("c-date-range__end"))) {
|
|
1483
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { start: this.querySelector(".c-date-range__start")?.value, end: this.querySelector(".c-date-range__end")?.value } }));
|
|
1484
|
-
}
|
|
1485
|
-
});
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
define("contour-date-range", ContourDateRange);
|
|
1489
|
-
|
|
1490
|
-
/**
|
|
1491
|
-
* Shortcut: web component wrapper.
|
|
1492
|
-
* Attributes: `key`, `label`.
|
|
1493
|
-
*/
|
|
1494
|
-
class ContourShortcut extends ContourBase {
|
|
1495
|
-
static get observed() { return ["key", "label"]; }
|
|
1496
|
-
static get properties() { return { key: { attribute: "key" }, label: { attribute: "label" } }; }
|
|
1497
|
-
render() {
|
|
1498
|
-
this.classList.add("c-shortcut");
|
|
1499
|
-
const key = this.getAttribute("key") || "";
|
|
1500
|
-
const label = this.getAttribute("label") || "";
|
|
1501
|
-
if (key) {
|
|
1502
|
-
const k = this.ensure(".c-shortcut__key", () => { const el = document.createElement("kbd"); el.className = "c-shortcut__key"; return el; });
|
|
1503
|
-
k.textContent = key;
|
|
1504
|
-
}
|
|
1505
|
-
if (label) {
|
|
1506
|
-
const l = this.ensure(".c-shortcut__label", () => { const el = document.createElement("span"); el.className = "c-shortcut__label"; return el; });
|
|
1507
|
-
l.textContent = label;
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
enhance() {
|
|
1511
|
-
if (this._wiredShortcut) return;
|
|
1512
|
-
this._wiredShortcut = true;
|
|
1513
|
-
const key = this.getAttribute("key");
|
|
1514
|
-
if (key) {
|
|
1515
|
-
const handler = (e) => {
|
|
1516
|
-
if (e.key === key && (e.metaKey || e.ctrlKey)) {
|
|
1517
|
-
e.preventDefault();
|
|
1518
|
-
this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true }));
|
|
1519
|
-
}
|
|
1520
|
-
};
|
|
1521
|
-
document.addEventListener("keydown", handler);
|
|
1522
|
-
onDispose(this, () => document.removeEventListener("keydown", handler));
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
define("contour-shortcut", ContourShortcut);
|
|
1527
|
-
|
|
1528
|
-
/**
|
|
1529
|
-
* Popover: web component wrapper.
|
|
1530
|
-
* Attributes: `title`, `content`.
|
|
1531
|
-
*/
|
|
1532
|
-
class ContourPopover extends ContourBase {
|
|
1533
|
-
static get observed() { return ["title", "content"]; }
|
|
1534
|
-
static get properties() { return { title: { attribute: "title" }, content: { attribute: "content" } }; }
|
|
1535
|
-
render() {
|
|
1536
|
-
this.classList.add("c-popover");
|
|
1537
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
|
|
1538
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Popover");
|
|
1539
|
-
if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
|
|
1540
|
-
if (!this.id) this.id = contourId("popover");
|
|
1541
|
-
const title = this.getAttribute("title");
|
|
1542
|
-
if (title) {
|
|
1543
|
-
const t = this.ensure(".c-popover__title", () => { const el = document.createElement("div"); el.className = "c-popover__title"; return el; });
|
|
1544
|
-
t.textContent = title;
|
|
1545
|
-
}
|
|
1546
|
-
const content = this.getAttribute("content");
|
|
1547
|
-
if (content) {
|
|
1548
|
-
const c = this.ensure(".c-popover__body", () => { const el = document.createElement("div"); el.className = "c-popover__body"; return el; });
|
|
1549
|
-
c.textContent = content;
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
enhance() {
|
|
1553
|
-
if (this._wiredPopover) return;
|
|
1554
|
-
this._wiredPopover = true;
|
|
1555
|
-
const close = () => { try { this.hidePopover(); } catch (e) {} this.classList.remove("is-open"); this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); };
|
|
1556
|
-
const keyHandler = (e) => {
|
|
1557
|
-
const open = this.classList.contains("is-open") || this.matches(":popover-open");
|
|
1558
|
-
if (!open) return;
|
|
1559
|
-
if (e.key === "Escape") { e.preventDefault(); close(); return; }
|
|
1560
|
-
// Focus trap: keep Tab within the popover.
|
|
1561
|
-
if (e.key === "Tab") {
|
|
1562
|
-
const focusable = Array.from(this.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));
|
|
1563
|
-
if (!focusable.length) { e.preventDefault(); return; }
|
|
1564
|
-
const first = focusable[0];
|
|
1565
|
-
const last = focusable[focusable.length - 1];
|
|
1566
|
-
if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
|
|
1567
|
-
else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
|
|
1568
|
-
}
|
|
1569
|
-
};
|
|
1570
|
-
document.addEventListener("keydown", keyHandler);
|
|
1571
|
-
onDispose(this, () => document.removeEventListener("keydown", keyHandler));
|
|
1572
|
-
// Nested popover support: when a nested popover opens, mark this one as parent.
|
|
1573
|
-
this.addEventListener("contour:show", (e) => {
|
|
1574
|
-
if (e.target && e.target !== this && this.contains(e.target)) {
|
|
1575
|
-
this.classList.add("is-parent");
|
|
1576
|
-
}
|
|
1577
|
-
});
|
|
1578
|
-
this.addEventListener("contour:close", (e) => {
|
|
1579
|
-
if (e.target && e.target !== this) {
|
|
1580
|
-
this.classList.remove("is-parent");
|
|
1581
|
-
}
|
|
1582
|
-
});
|
|
1583
|
-
this.addEventListener("click", (e) => {
|
|
1584
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-popover__close") : null;
|
|
1585
|
-
if (btn && this.contains(btn)) close();
|
|
1586
|
-
});
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
define("contour-popover", ContourPopover);
|
|
1590
|
-
|
|
1591
|
-
/**
|
|
1592
|
-
* Date Picker: web component wrapper.
|
|
1593
|
-
* Attributes: `value`, `range`, `range-start`, `range-end`, `label`, `disabled`, `error`, `help`, `time`, `min`, `max`, `locale`.
|
|
1594
|
-
*/
|
|
1595
|
-
class ContourDatePicker extends ContourBase {
|
|
1596
|
-
static get observed() { return ["value", "range", "range-start", "range-end", "label", "disabled", "error", "help", "time", "min", "max", "locale"]; }
|
|
1597
|
-
static get properties() { return { value: { attribute: "value" }, range: { attribute: "range", type: Boolean }, rangeStart: { attribute: "range-start" }, rangeEnd: { attribute: "range-end" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, time: { attribute: "time", type: Boolean }, min: { attribute: "min" }, max: { attribute: "max" }, locale: { attribute: "locale" } }; }
|
|
1598
|
-
render() {
|
|
1599
|
-
this.classList.add("c-date-picker");
|
|
1600
|
-
this.setAttribute("role", "group");
|
|
1601
|
-
this.setAttribute("aria-label", "Date picker");
|
|
1602
|
-
const label = this.getAttribute("label");
|
|
1603
|
-
if (label) {
|
|
1604
|
-
const l = this.ensure(".c-date-picker__label", () => { const el = document.createElement("label"); el.className = "c-date-picker__label"; return el; });
|
|
1605
|
-
l.textContent = label;
|
|
1606
|
-
}
|
|
1607
|
-
const input = this.ensure(".c-date-picker__input", () => { const el = document.createElement("input"); el.className = "c-input c-date-picker__input"; return el; });
|
|
1608
|
-
const range = this.hasAttribute("range");
|
|
1609
|
-
const type = this.hasAttribute("time") ? "datetime-local" : "date";
|
|
1610
|
-
const configure = (control, value, name) => {
|
|
1611
|
-
control.type = type;
|
|
1612
|
-
control.value = value || "";
|
|
1613
|
-
control.setAttribute("aria-label", name);
|
|
1614
|
-
if (this.hasAttribute("min")) control.min = this.getAttribute("min"); else control.removeAttribute("min");
|
|
1615
|
-
if (this.hasAttribute("max")) control.max = this.getAttribute("max"); else control.removeAttribute("max");
|
|
1616
|
-
if (this.hasAttribute("locale")) control.lang = this.getAttribute("locale"); else control.removeAttribute("lang");
|
|
1617
|
-
if (this.hasAttribute("disabled")) control.setAttribute("disabled", ""); else control.removeAttribute("disabled");
|
|
1618
|
-
};
|
|
1619
|
-
configure(input, range ? this.getAttribute("range-start") : this.getAttribute("value"), range ? "Start date" : (label || "Date"));
|
|
1620
|
-
let end = this.querySelector(".c-date-picker__end");
|
|
1621
|
-
if (range) {
|
|
1622
|
-
end = end || document.createElement("input");
|
|
1623
|
-
end.className = "c-input c-date-picker__input c-date-picker__end";
|
|
1624
|
-
configure(end, this.getAttribute("range-end"), "End date");
|
|
1625
|
-
if (end.parentNode !== this) this.appendChild(end);
|
|
1626
|
-
} else if (end) end.remove();
|
|
1627
|
-
if (this.hasAttribute("disabled")) this.classList.add("is-disabled"); else this.classList.remove("is-disabled");
|
|
1628
|
-
const err = this.getAttribute("error");
|
|
1629
|
-
const help = this.getAttribute("help");
|
|
1630
|
-
let msg = this.querySelector(".c-date-picker__message");
|
|
1631
|
-
if (err || help) {
|
|
1632
|
-
if (!msg) { msg = document.createElement("div"); msg.className = "c-date-picker__message"; this.appendChild(msg); }
|
|
1633
|
-
msg.textContent = err || help || "";
|
|
1634
|
-
msg.classList.toggle("c-date-picker__message--error", !!err);
|
|
1635
|
-
} else if (msg) { msg.remove(); }
|
|
1636
|
-
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
1637
|
-
// Calendar affordance (R14-22): a toggle + month grid alongside the native input.
|
|
1638
|
-
const toggle = this.ensure(".c-date-picker__calendar-toggle", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-date-picker__calendar-toggle"; el.type = "button"; el.textContent = "📅"; el.setAttribute("aria-label", "Open calendar"); el.setAttribute("aria-expanded", "false"); return el; });
|
|
1639
|
-
let cal = this.querySelector(".c-date-picker__calendar");
|
|
1640
|
-
if (!cal) { cal = document.createElement("div"); cal.className = "c-date-picker__calendar"; cal.setAttribute("hidden", ""); cal.setAttribute("role", "dialog"); cal.setAttribute("aria-label", "Calendar"); this.appendChild(cal); }
|
|
1641
|
-
}
|
|
1642
|
-
_renderCalendar() {
|
|
1643
|
-
const cal = this.querySelector(".c-date-picker__calendar");
|
|
1644
|
-
if (!cal) return;
|
|
1645
|
-
const input = this.querySelector(".c-date-picker__input");
|
|
1646
|
-
const base = (input && input.value) ? new Date(input.value) : new Date();
|
|
1647
|
-
const month = this._calMonth || new Date(base.getFullYear(), base.getMonth(), 1);
|
|
1648
|
-
this._calMonth = month;
|
|
1649
|
-
const y = month.getFullYear();
|
|
1650
|
-
const m = month.getMonth();
|
|
1651
|
-
const first = new Date(y, m, 1);
|
|
1652
|
-
const startDay = first.getDay();
|
|
1653
|
-
const daysInMonth = new Date(y, m + 1, 0).getDate();
|
|
1654
|
-
cal.innerHTML = "";
|
|
1655
|
-
const header = document.createElement("div");
|
|
1656
|
-
header.className = "c-date-picker__calendar-header";
|
|
1657
|
-
const prev = document.createElement("button"); prev.type = "button"; prev.className = "c-btn c-btn--sm"; prev.textContent = "‹"; prev.setAttribute("aria-label", "Previous month");
|
|
1658
|
-
const title = document.createElement("span"); title.className = "c-date-picker__calendar-title"; title.textContent = month.toLocaleString(this.getAttribute("locale") || undefined, { month: "long", year: "numeric" });
|
|
1659
|
-
const next = document.createElement("button"); next.type = "button"; next.className = "c-btn c-btn--sm"; next.textContent = "›"; next.setAttribute("aria-label", "Next month");
|
|
1660
|
-
header.appendChild(prev); header.appendChild(title); header.appendChild(next);
|
|
1661
|
-
cal.appendChild(header);
|
|
1662
|
-
const grid = document.createElement("div");
|
|
1663
|
-
grid.className = "c-date-picker__calendar-grid";
|
|
1664
|
-
grid.setAttribute("role", "grid");
|
|
1665
|
-
const weekdays = ["Su","Mo","Tu","We","Th","Fr","Sa"];
|
|
1666
|
-
weekdays.forEach((w) => { const h = document.createElement("div"); h.className = "c-date-picker__calendar-weekday"; h.textContent = w; grid.appendChild(h); });
|
|
1667
|
-
for (let i = 0; i < startDay; i++) { const empty = document.createElement("div"); empty.className = "c-date-picker__calendar-day c-date-picker__calendar-day--empty"; grid.appendChild(empty); }
|
|
1668
|
-
const selected = input ? input.value : "";
|
|
1669
|
-
for (let d = 1; d <= daysInMonth; d++) {
|
|
1670
|
-
const btn = document.createElement("button");
|
|
1671
|
-
btn.type = "button";
|
|
1672
|
-
btn.className = "c-date-picker__calendar-day";
|
|
1673
|
-
btn.textContent = String(d);
|
|
1674
|
-
const iso = `${y}-${String(m + 1).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
|
|
1675
|
-
if (selected && selected.startsWith(iso)) btn.classList.add("is-selected");
|
|
1676
|
-
btn.addEventListener("click", () => {
|
|
1677
|
-
if (input) { input.value = iso; input.dispatchEvent(new Event("change", { bubbles: true })); }
|
|
1678
|
-
cal.setAttribute("hidden", "");
|
|
1679
|
-
const tgl = this.querySelector(".c-date-picker__calendar-toggle");
|
|
1680
|
-
if (tgl) tgl.setAttribute("aria-expanded", "false");
|
|
1681
|
-
});
|
|
1682
|
-
grid.appendChild(btn);
|
|
1683
|
-
}
|
|
1684
|
-
cal.appendChild(grid);
|
|
1685
|
-
prev.addEventListener("click", () => { this._calMonth = new Date(y, m - 1, 1); this._renderCalendar(); });
|
|
1686
|
-
next.addEventListener("click", () => { this._calMonth = new Date(y, m + 1, 1); this._renderCalendar(); });
|
|
1687
|
-
}
|
|
1688
|
-
enhance() {
|
|
1689
|
-
if (this._wiredDatePicker) return;
|
|
1690
|
-
this._wiredDatePicker = true;
|
|
1691
|
-
this.addEventListener("change", (e) => {
|
|
1692
|
-
const t = e.target;
|
|
1693
|
-
if (t && t.classList.contains("c-date-picker__input")) {
|
|
1694
|
-
const end = this.querySelector(".c-date-picker__end");
|
|
1695
|
-
const detail = end ? { start: this.querySelector(".c-date-picker__input").value, end: end.value } : { value: t.value };
|
|
1696
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail }));
|
|
1697
|
-
}
|
|
1698
|
-
});
|
|
1699
|
-
const toggle = () => {
|
|
1700
|
-
const cal = this.querySelector(".c-date-picker__calendar");
|
|
1701
|
-
const btn = this.querySelector(".c-date-picker__calendar-toggle");
|
|
1702
|
-
if (!cal) return;
|
|
1703
|
-
const hidden = cal.hasAttribute("hidden");
|
|
1704
|
-
if (hidden) { cal.removeAttribute("hidden"); if (btn) btn.setAttribute("aria-expanded", "true"); this._renderCalendar(); }
|
|
1705
|
-
else { cal.setAttribute("hidden", ""); if (btn) btn.setAttribute("aria-expanded", "false"); }
|
|
1706
|
-
};
|
|
1707
|
-
this.addEventListener("click", (e) => {
|
|
1708
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-date-picker__calendar-toggle") : null;
|
|
1709
|
-
if (btn && this.contains(btn)) { e.preventDefault(); toggle(); }
|
|
1710
|
-
});
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
define("contour-date-picker", ContourDatePicker);
|
|
1714
|
-
|
|
1715
|
-
/**
|
|
1716
|
-
* Rating: web component wrapper.
|
|
1717
|
-
* Attributes: `value`, `max`, `color`.
|
|
1718
|
-
*/
|
|
1719
|
-
class ContourRating extends ContourBase {
|
|
1720
|
-
static get observed() { return ["value", "max", "color"]; }
|
|
1721
|
-
static get properties() { return { value: { attribute: "value", type: Number }, max: { attribute: "max", type: Number }, color: { attribute: "color" } }; }
|
|
1722
|
-
render() {
|
|
1723
|
-
this.classList.add("c-rating");
|
|
1724
|
-
this.setAttribute("role", "radiogroup");
|
|
1725
|
-
this.setAttribute("aria-label", "Rating");
|
|
1726
|
-
const max = parseInt(this.getAttribute("max") || "5", 10) || 5;
|
|
1727
|
-
const value = parseInt(this.getAttribute("value") || "0", 10) || 0;
|
|
1728
|
-
const color = this.getAttribute("color");
|
|
1729
|
-
Array.from(this.querySelectorAll(".c-rating__star")).forEach((n) => n.remove());
|
|
1730
|
-
for (let i = 1; i <= max; i++) {
|
|
1731
|
-
const star = document.createElement("button");
|
|
1732
|
-
star.className = "c-rating__star" + (i <= value ? " c-rating__star--filled" : "");
|
|
1733
|
-
star.type = "button";
|
|
1734
|
-
star.setAttribute("role", "radio");
|
|
1735
|
-
star.setAttribute("aria-checked", String(i === value));
|
|
1736
|
-
star.innerHTML = '<span class="c-rating__swatch' + (i <= value ? ' c-rating__swatch--filled' : '') + '" aria-hidden="true"' + (color && i <= value ? ' style="background:' + color + ';border-color:' + color + '"' : '') + '></span>';
|
|
1737
|
-
star.dataset.value = String(i);
|
|
1738
|
-
star.setAttribute("aria-label", i + " star" + (i > 1 ? "s" : ""));
|
|
1739
|
-
this.appendChild(star);
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
enhance() {
|
|
1743
|
-
if (this._wiredRating) return;
|
|
1744
|
-
this._wiredRating = true;
|
|
1745
|
-
this.addEventListener("click", (e) => {
|
|
1746
|
-
const star = e.target && e.target.closest ? e.target.closest(".c-rating__star") : null;
|
|
1747
|
-
if (star && this.contains(star)) {
|
|
1748
|
-
const v = parseInt(star.dataset.value, 10);
|
|
1749
|
-
Array.from(this.querySelectorAll(".c-rating__star")).forEach((st) => st.setAttribute("aria-checked", String(parseInt(st.dataset.value, 10) === v)));
|
|
1750
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: v } }));
|
|
1751
|
-
}
|
|
1752
|
-
});
|
|
1753
|
-
this.addEventListener("keydown", (e) => {
|
|
1754
|
-
const stars = Array.from(this.querySelectorAll(".c-rating__star"));
|
|
1755
|
-
const active = document.activeElement;
|
|
1756
|
-
const idx = stars.indexOf(active);
|
|
1757
|
-
if (e.key === "ArrowRight" || e.key === "ArrowUp") {
|
|
1758
|
-
e.preventDefault();
|
|
1759
|
-
const next = stars[Math.min(stars.length - 1, idx + 1)] || stars[0];
|
|
1760
|
-
if (next) { try { next.focus(); } catch (err) {} }
|
|
1761
|
-
} else if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
|
|
1762
|
-
e.preventDefault();
|
|
1763
|
-
const prev = stars[Math.max(0, idx - 1)] || stars[stars.length - 1];
|
|
1764
|
-
if (prev) { try { prev.focus(); } catch (err) {} }
|
|
1765
|
-
} else if (e.key === "Enter" || e.key === " ") {
|
|
1766
|
-
e.preventDefault();
|
|
1767
|
-
if (active && active.classList.contains("c-rating__star")) {
|
|
1768
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: parseInt(active.dataset.value, 10) } }));
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
1771
|
-
});
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
define("contour-rating", ContourRating);
|
|
1775
|
-
|
|
1776
|
-
/**
|
|
1777
|
-
* Time Picker: web component wrapper.
|
|
1778
|
-
* Attributes: `value`, `label`, `disabled`, `error`, `help`.
|
|
1779
|
-
*/
|
|
1780
|
-
class ContourTimePicker extends ContourBase {
|
|
1781
|
-
static get observed() { return ["value", "label", "disabled", "error", "help"]; }
|
|
1782
|
-
static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
1783
|
-
render() {
|
|
1784
|
-
this.classList.add("c-time-picker");
|
|
1785
|
-
this.setAttribute("role", "group");
|
|
1786
|
-
this.setAttribute("aria-label", "Time picker");
|
|
1787
|
-
const label = this.getAttribute("label");
|
|
1788
|
-
if (label) {
|
|
1789
|
-
const l = this.ensure(".c-time-picker__label", () => { const el = document.createElement("label"); el.className = "c-time-picker__label"; return el; });
|
|
1790
|
-
l.textContent = label;
|
|
1791
|
-
}
|
|
1792
|
-
const input = this.ensure(".c-time-picker__input", () => { const el = document.createElement("input"); el.className = "c-input c-time-picker__input"; el.type = "time"; return el; });
|
|
1793
|
-
input.value = this.getAttribute("value") || "";
|
|
1794
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
1795
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
1796
|
-
const err = this.getAttribute("error");
|
|
1797
|
-
const help = this.getAttribute("help");
|
|
1798
|
-
let msg = this.querySelector(".c-time-picker__message");
|
|
1799
|
-
if (err || help) {
|
|
1800
|
-
if (!msg) { msg = document.createElement("div"); msg.className = "c-time-picker__message"; this.appendChild(msg); }
|
|
1801
|
-
msg.textContent = err || help || "";
|
|
1802
|
-
msg.classList.toggle("c-time-picker__message--error", !!err);
|
|
1803
|
-
} else if (msg) { msg.remove(); }
|
|
1804
|
-
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
1805
|
-
// Calendar affordance (R14-22): a toggle + month grid alongside the native input.
|
|
1806
|
-
const toggle = this.ensure(".c-date-picker__calendar-toggle", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-date-picker__calendar-toggle"; el.type = "button"; el.textContent = "📅"; el.setAttribute("aria-label", "Open calendar"); el.setAttribute("aria-expanded", "false"); return el; });
|
|
1807
|
-
let cal = this.querySelector(".c-date-picker__calendar");
|
|
1808
|
-
if (!cal) { cal = document.createElement("div"); cal.className = "c-date-picker__calendar"; cal.setAttribute("hidden", ""); cal.setAttribute("role", "dialog"); cal.setAttribute("aria-label", "Calendar"); this.appendChild(cal); }
|
|
1809
|
-
}
|
|
1810
|
-
enhance() {
|
|
1811
|
-
if (this._wiredTimePicker) return;
|
|
1812
|
-
this._wiredTimePicker = true;
|
|
1813
|
-
this.addEventListener("change", (e) => {
|
|
1814
|
-
const t = e.target;
|
|
1815
|
-
if (t && t.classList.contains("c-time-picker__input")) {
|
|
1816
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: t.value } }));
|
|
1817
|
-
}
|
|
1818
|
-
});
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
define("contour-time-picker", ContourTimePicker);
|
|
1822
|
-
|
|
1823
|
-
/**
|
|
1824
|
-
* Color Picker: web component wrapper.
|
|
1825
|
-
* Attributes: `value`, `label`, `disabled`, `error`, `help`, `alpha`, `presets`.
|
|
1826
|
-
*/
|
|
1827
|
-
class ContourColorPicker extends ContourBase {
|
|
1828
|
-
static get observed() { return ["value", "label", "disabled", "error", "help", "alpha", "presets"]; }
|
|
1829
|
-
static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, alpha: { attribute: "alpha", type: Boolean }, presets: { attribute: "presets" } }; }
|
|
1830
|
-
render() {
|
|
1831
|
-
this.classList.add("c-color-picker");
|
|
1832
|
-
this.setAttribute("role", "group");
|
|
1833
|
-
this.setAttribute("aria-label", "Color picker");
|
|
1834
|
-
const label = this.getAttribute("label");
|
|
1835
|
-
if (label) {
|
|
1836
|
-
const l = this.ensure(".c-color-picker__label", () => { const el = document.createElement("label"); el.className = "c-color-picker__label"; return el; });
|
|
1837
|
-
l.textContent = label;
|
|
1838
|
-
}
|
|
1839
|
-
const input = this.ensure(".c-color-picker__input", () => { const el = document.createElement("input"); el.className = "c-color-picker__input"; el.type = "color"; return el; });
|
|
1840
|
-
input.value = (this.getAttribute("value") || "#000000").slice(0, 7);
|
|
1841
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
1842
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
1843
|
-
// Alpha channel (optional).
|
|
1844
|
-
if (this.hasAttribute("alpha")) {
|
|
1845
|
-
const alpha = this.ensure(".c-color-picker__alpha", () => { const el = document.createElement("input"); el.className = "c-color-picker__alpha"; el.type = "range"; el.min = "0"; el.max = "1"; el.step = "0.01"; return el; });
|
|
1846
|
-
const v = this.getAttribute("value") || "#000000";
|
|
1847
|
-
const a = v.length === 9 ? parseInt(v.slice(7, 9), 16) / 255 : 1;
|
|
1848
|
-
alpha.value = String(a);
|
|
1849
|
-
alpha.setAttribute("aria-label", "Alpha");
|
|
1850
|
-
} else {
|
|
1851
|
-
const a = this.querySelector(".c-color-picker__alpha");
|
|
1852
|
-
if (a) a.remove();
|
|
1853
|
-
}
|
|
1854
|
-
// Presets.
|
|
1855
|
-
const presetsAttr = this.getAttribute("presets");
|
|
1856
|
-
let presets = [];
|
|
1857
|
-
if (presetsAttr) { try { presets = JSON.parse(presetsAttr); } catch (e) { presets = []; } }
|
|
1858
|
-
const oldPresets = this.querySelector(".c-color-picker__presets");
|
|
1859
|
-
if (oldPresets) oldPresets.remove();
|
|
1860
|
-
if (Array.isArray(presets) && presets.length) {
|
|
1861
|
-
const wrap = document.createElement("div");
|
|
1862
|
-
wrap.className = "c-color-picker__presets";
|
|
1863
|
-
presets.forEach((c) => {
|
|
1864
|
-
const btn = document.createElement("button");
|
|
1865
|
-
btn.type = "button";
|
|
1866
|
-
btn.className = "c-color-picker__preset";
|
|
1867
|
-
btn.style.background = c;
|
|
1868
|
-
btn.dataset.color = c;
|
|
1869
|
-
btn.setAttribute("aria-label", "Preset " + c);
|
|
1870
|
-
wrap.appendChild(btn);
|
|
1871
|
-
});
|
|
1872
|
-
this.appendChild(wrap);
|
|
1873
|
-
}
|
|
1874
|
-
// Eyedropper (if supported).
|
|
1875
|
-
if (typeof window !== "undefined" && "EyeDropper" in window) {
|
|
1876
|
-
const ed = this.ensure(".c-color-picker__eyedropper", () => { const el = document.createElement("button"); el.className = "c-color-picker__eyedropper"; el.type = "button"; el.textContent = "Pick"; el.setAttribute("aria-label", "Pick color from screen"); return el; });
|
|
1877
|
-
if (this.hasAttribute("disabled")) ed.setAttribute("disabled", "");
|
|
1878
|
-
else ed.removeAttribute("disabled");
|
|
1879
|
-
} else {
|
|
1880
|
-
const ed = this.querySelector(".c-color-picker__eyedropper");
|
|
1881
|
-
if (ed) ed.remove();
|
|
1882
|
-
}
|
|
1883
|
-
const err = this.getAttribute("error");
|
|
1884
|
-
const help = this.getAttribute("help");
|
|
1885
|
-
let msg = this.querySelector(".c-color-picker__message");
|
|
1886
|
-
if (err || help) {
|
|
1887
|
-
if (!msg) { msg = document.createElement("div"); msg.className = "c-color-picker__message"; this.appendChild(msg); }
|
|
1888
|
-
msg.textContent = err || help || "";
|
|
1889
|
-
msg.classList.toggle("c-color-picker__message--error", !!err);
|
|
1890
|
-
} else if (msg) { msg.remove(); }
|
|
1891
|
-
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
1892
|
-
// Calendar affordance (R14-22): a toggle + month grid alongside the native input.
|
|
1893
|
-
const toggle = this.ensure(".c-date-picker__calendar-toggle", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-date-picker__calendar-toggle"; el.type = "button"; el.textContent = "📅"; el.setAttribute("aria-label", "Open calendar"); el.setAttribute("aria-expanded", "false"); return el; });
|
|
1894
|
-
let cal = this.querySelector(".c-date-picker__calendar");
|
|
1895
|
-
if (!cal) { cal = document.createElement("div"); cal.className = "c-date-picker__calendar"; cal.setAttribute("hidden", ""); cal.setAttribute("role", "dialog"); cal.setAttribute("aria-label", "Calendar"); this.appendChild(cal); }
|
|
1896
|
-
}
|
|
1897
|
-
enhance() {
|
|
1898
|
-
if (this._wiredColorPicker) return;
|
|
1899
|
-
this._wiredColorPicker = true;
|
|
1900
|
-
this.addEventListener("change", (e) => {
|
|
1901
|
-
const t = e.target;
|
|
1902
|
-
if (t && t.classList.contains("c-color-picker__input")) {
|
|
1903
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: t.value } }));
|
|
1904
|
-
}
|
|
1905
|
-
if (t && t.classList.contains("c-color-picker__alpha")) {
|
|
1906
|
-
const base = (this.getAttribute("value") || "#000000").slice(0, 7);
|
|
1907
|
-
const a = Math.round(parseFloat(t.value) * 255).toString(16).padStart(2, "0");
|
|
1908
|
-
const val = base + a;
|
|
1909
|
-
this.setAttribute("value", val);
|
|
1910
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: val } }));
|
|
1911
|
-
}
|
|
1912
|
-
});
|
|
1913
|
-
this.addEventListener("click", (e) => {
|
|
1914
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-color-picker__preset") : null;
|
|
1915
|
-
if (btn && this.contains(btn)) {
|
|
1916
|
-
const c = btn.dataset.color;
|
|
1917
|
-
if (c) {
|
|
1918
|
-
this.setAttribute("value", c);
|
|
1919
|
-
const input = this.querySelector(".c-color-picker__input");
|
|
1920
|
-
if (input) input.value = c.slice(0, 7);
|
|
1921
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: c } }));
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
const ed = e.target && e.target.closest ? e.target.closest(".c-color-picker__eyedropper") : null;
|
|
1925
|
-
if (ed && this.contains(ed) && typeof window !== "undefined" && "EyeDropper" in window) {
|
|
1926
|
-
e.preventDefault();
|
|
1927
|
-
const dropper = new window.EyeDropper();
|
|
1928
|
-
dropper.open().then((r) => {
|
|
1929
|
-
if (r && r.sRGBHex) {
|
|
1930
|
-
this.setAttribute("value", r.sRGBHex);
|
|
1931
|
-
const input = this.querySelector(".c-color-picker__input");
|
|
1932
|
-
if (input) input.value = r.sRGBHex;
|
|
1933
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: r.sRGBHex } }));
|
|
1934
|
-
}
|
|
1935
|
-
}).catch(() => {});
|
|
1936
|
-
}
|
|
1937
|
-
});
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
define("contour-color-picker", ContourColorPicker);
|
|
1941
|
-
|
|
1942
|
-
/**
|
|
1943
|
-
* Number Field: web component wrapper.
|
|
1944
|
-
* Attributes: `value`, `min`, `max`, `step`, `label`, `disabled`, `error`, `help`.
|
|
1945
|
-
*/
|
|
1946
|
-
class ContourNumberField extends ContourBase {
|
|
1947
|
-
static get observed() { return ["value", "min", "max", "step", "label", "disabled", "error", "help"]; }
|
|
1948
|
-
static get properties() { return { value: { attribute: "value" }, min: { attribute: "min" }, max: { attribute: "max" }, step: { attribute: "step" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
1949
|
-
render() {
|
|
1950
|
-
this.classList.add("c-number-field");
|
|
1951
|
-
const label = this.getAttribute("label");
|
|
1952
|
-
if (label) {
|
|
1953
|
-
const l = this.ensure(".c-number-field__label", () => { const el = document.createElement("label"); el.className = "c-number-field__label"; return el; });
|
|
1954
|
-
l.textContent = label;
|
|
1955
|
-
}
|
|
1956
|
-
const input = this.ensure(".c-number-field__input", () => { const el = document.createElement("input"); el.className = "c-input c-number-field__input"; el.type = "number"; el.setAttribute("role", "spinbutton"); return el; });
|
|
1957
|
-
if (this.getAttribute("value") !== null) input.value = this.getAttribute("value");
|
|
1958
|
-
if (this.getAttribute("min") !== null) input.min = this.getAttribute("min");
|
|
1959
|
-
if (this.getAttribute("max") !== null) input.max = this.getAttribute("max");
|
|
1960
|
-
if (this.getAttribute("step") !== null) input.step = this.getAttribute("step");
|
|
1961
|
-
const v = input.value;
|
|
1962
|
-
input.setAttribute("aria-valuenow", v === "" ? "" : v);
|
|
1963
|
-
if (input.min !== "") input.setAttribute("aria-valuemin", input.min);
|
|
1964
|
-
if (input.max !== "") input.setAttribute("aria-valuemax", input.max);
|
|
1965
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
1966
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
1967
|
-
const err = this.getAttribute("error");
|
|
1968
|
-
const help = this.getAttribute("help");
|
|
1969
|
-
let msg = this.querySelector(".c-number-field__message");
|
|
1970
|
-
if (err || help) {
|
|
1971
|
-
if (!msg) { msg = document.createElement("div"); msg.className = "c-number-field__message"; this.appendChild(msg); }
|
|
1972
|
-
msg.textContent = err || help || "";
|
|
1973
|
-
msg.classList.toggle("c-number-field__message--error", !!err);
|
|
1974
|
-
} else if (msg) { msg.remove(); }
|
|
1975
|
-
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
1976
|
-
// Calendar affordance (R14-22): a toggle + month grid alongside the native input.
|
|
1977
|
-
const toggle = this.ensure(".c-date-picker__calendar-toggle", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-date-picker__calendar-toggle"; el.type = "button"; el.textContent = "📅"; el.setAttribute("aria-label", "Open calendar"); el.setAttribute("aria-expanded", "false"); return el; });
|
|
1978
|
-
let cal = this.querySelector(".c-date-picker__calendar");
|
|
1979
|
-
if (!cal) { cal = document.createElement("div"); cal.className = "c-date-picker__calendar"; cal.setAttribute("hidden", ""); cal.setAttribute("role", "dialog"); cal.setAttribute("aria-label", "Calendar"); this.appendChild(cal); }
|
|
1980
|
-
}
|
|
1981
|
-
enhance() {
|
|
1982
|
-
if (this._wiredNumberField) return;
|
|
1983
|
-
this._wiredNumberField = true;
|
|
1984
|
-
this.addEventListener("change", (e) => {
|
|
1985
|
-
const t = e.target;
|
|
1986
|
-
if (t && t.classList.contains("c-number-field__input")) {
|
|
1987
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: t.value } }));
|
|
1988
|
-
}
|
|
1989
|
-
});
|
|
1990
|
-
this.addEventListener("keydown", (e) => {
|
|
1991
|
-
const input = this.querySelector(".c-number-field__input");
|
|
1992
|
-
if (!input || document.activeElement !== input) return;
|
|
1993
|
-
const step = Number(input.step) || 1;
|
|
1994
|
-
const min = input.min === "" ? -Infinity : Number(input.min);
|
|
1995
|
-
const max = input.max === "" ? Infinity : Number(input.max);
|
|
1996
|
-
let next = null;
|
|
1997
|
-
if (e.key === "ArrowUp") next = (Number(input.value) || 0) + step;
|
|
1998
|
-
else if (e.key === "ArrowDown") next = (Number(input.value) || 0) - step;
|
|
1999
|
-
else if (e.key === "Home") next = min === -Infinity ? 0 : min;
|
|
2000
|
-
else if (e.key === "End") next = max === Infinity ? (Number(input.value) || 0) : max;
|
|
2001
|
-
if (next !== null) {
|
|
2002
|
-
e.preventDefault();
|
|
2003
|
-
next = Math.min(max, Math.max(min, next));
|
|
2004
|
-
input.value = String(next);
|
|
2005
|
-
input.setAttribute("aria-valuenow", String(next));
|
|
2006
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: input.value } }));
|
|
2007
|
-
}
|
|
2008
|
-
});
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
define("contour-number-field", ContourNumberField);
|
|
2012
|
-
|
|
2013
|
-
/**
|
|
2014
|
-
* Hover Card: web component wrapper.
|
|
2015
|
-
* Attributes: `title`, `content`, `anchor`.
|
|
2016
|
-
*/
|
|
2017
|
-
class ContourHoverCard extends ContourBase {
|
|
2018
|
-
static get observed() { return ["title", "content", "anchor"]; }
|
|
2019
|
-
static get properties() { return { title: { attribute: "title" }, content: { attribute: "content" }, anchor: { attribute: "anchor" } }; }
|
|
2020
|
-
render() {
|
|
2021
|
-
this.classList.add("c-hover-card");
|
|
2022
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "tooltip");
|
|
2023
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Hover card");
|
|
2024
|
-
if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
|
|
2025
|
-
if (!this.id) this.id = contourId("hover-card");
|
|
2026
|
-
const title = this.getAttribute("title");
|
|
2027
|
-
if (title) {
|
|
2028
|
-
const t = this.ensure(".c-hover-card__title", () => { const el = document.createElement("div"); el.className = "c-hover-card__title"; return el; });
|
|
2029
|
-
t.textContent = title;
|
|
2030
|
-
}
|
|
2031
|
-
const content = this.getAttribute("content");
|
|
2032
|
-
if (content) {
|
|
2033
|
-
const c = this.ensure(".c-hover-card__body", () => { const el = document.createElement("div"); el.className = "c-hover-card__body"; return el; });
|
|
2034
|
-
c.textContent = content;
|
|
2035
|
-
}
|
|
2036
|
-
}
|
|
2037
|
-
enhance() {
|
|
2038
|
-
if (this._wiredHoverCard) return;
|
|
2039
|
-
this._wiredHoverCard = true;
|
|
2040
|
-
const anchorSel = this.getAttribute("anchor");
|
|
2041
|
-
if (anchorSel) {
|
|
2042
|
-
const trigger = anchorSel.startsWith("#") ? document.getElementById(anchorSel.slice(1)) : document.querySelector(anchorSel);
|
|
2043
|
-
if (trigger) {
|
|
2044
|
-
trigger.setAttribute("popovertarget", this.id);
|
|
2045
|
-
let showTimer = null;
|
|
2046
|
-
const hasPopover = typeof this.showPopover === "function";
|
|
2047
|
-
const show = () => { if (hasPopover) { try { this.showPopover(); } catch (e) {} } else this.classList.add("is-open"); this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true })); };
|
|
2048
|
-
const hide = () => { if (showTimer) clearTimeout(showTimer); if (hasPopover) { try { this.hidePopover(); } catch (e) {} } else this.classList.remove("is-open"); this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); };
|
|
2049
|
-
trigger.addEventListener("mouseenter", () => { showTimer = setTimeout(show, 300); });
|
|
2050
|
-
trigger.addEventListener("mouseleave", () => { hide(); });
|
|
2051
|
-
trigger.addEventListener("focus", show);
|
|
2052
|
-
trigger.addEventListener("blur", () => { setTimeout(hide, 100); });
|
|
2053
|
-
onDispose(this, () => { if (showTimer) { clearTimeout(showTimer); showTimer = null; } });
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
const keyHandler = (e) => { if (e.key === "Escape" && (this.classList.contains("is-open") || this.matches(":popover-open"))) { e.preventDefault(); if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (err) {} } this.classList.remove("is-open"); this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); } };
|
|
2057
|
-
document.addEventListener("keydown", keyHandler);
|
|
2058
|
-
onDispose(this, () => document.removeEventListener("keydown", keyHandler));
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
define("contour-hover-card", ContourHoverCard);
|
|
2062
|
-
|
|
2063
|
-
/**
|
|
2064
|
-
* Context Menu: web component wrapper.
|
|
2065
|
-
* Attributes: `items`.
|
|
2066
|
-
*/
|
|
2067
|
-
class ContourContextMenu extends ContourBase {
|
|
2068
|
-
static get observed() { return ["items"]; }
|
|
2069
|
-
static get properties() { return { items: { attribute: "items" } }; }
|
|
2070
|
-
render() {
|
|
2071
|
-
this.classList.add("c-context-menu");
|
|
2072
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "menu");
|
|
2073
|
-
if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
|
|
2074
|
-
if (!this.id) this.id = contourId("context-menu");
|
|
2075
|
-
const items = this.getAttribute("items");
|
|
2076
|
-
if (items) {
|
|
2077
|
-
try {
|
|
2078
|
-
const parsed = JSON.parse(items);
|
|
2079
|
-
this.innerHTML = "";
|
|
2080
|
-
parsed.forEach((it) => {
|
|
2081
|
-
const btn = document.createElement("button");
|
|
2082
|
-
btn.className = "c-menu__item";
|
|
2083
|
-
btn.setAttribute("role", "menuitem");
|
|
2084
|
-
btn.textContent = typeof it === "string" ? it : (it.label || it.title || "");
|
|
2085
|
-
this.appendChild(btn);
|
|
2086
|
-
});
|
|
2087
|
-
} catch (e) { /* keep existing */ }
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
enhance() {
|
|
2091
|
-
if (this._wiredContextMenu) return;
|
|
2092
|
-
this._wiredContextMenu = true;
|
|
2093
|
-
this.addEventListener("contextmenu", (e) => {
|
|
2094
|
-
e.preventDefault();
|
|
2095
|
-
if (typeof this.showPopover === "function") { try { this.showPopover(); } catch (err) {} }
|
|
2096
|
-
else this.classList.toggle("is-open");
|
|
2097
|
-
});
|
|
2098
|
-
this.addEventListener("click", (e) => {
|
|
2099
|
-
const item = e.target && e.target.closest ? e.target.closest(".c-menu__item") : null;
|
|
2100
|
-
if (item && this.contains(item)) {
|
|
2101
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { label: item.textContent.trim() } }));
|
|
2102
|
-
if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (err) {} }
|
|
2103
|
-
this.classList.remove("is-open");
|
|
2104
|
-
}
|
|
2105
|
-
});
|
|
2106
|
-
this.addEventListener("keydown", (e) => {
|
|
2107
|
-
const items = Array.from(this.querySelectorAll(".c-menu__item"));
|
|
2108
|
-
const active = document.activeElement;
|
|
2109
|
-
const idx = items.indexOf(active);
|
|
2110
|
-
if (e.key === "ArrowDown") { e.preventDefault(); const next = items[Math.min(items.length - 1, idx + 1)] || items[0]; if (next) try { next.focus(); } catch (err) {} }
|
|
2111
|
-
else if (e.key === "ArrowUp") { e.preventDefault(); const prev = items[Math.max(0, idx - 1)] || items[items.length - 1]; if (prev) try { prev.focus(); } catch (err) {} }
|
|
2112
|
-
else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); if (active && active.classList.contains("c-menu__item")) active.click(); }
|
|
2113
|
-
else if (e.key === "Escape") { e.preventDefault(); if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (err) {} } this.classList.remove("is-open"); }
|
|
2114
|
-
});
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
define("contour-context-menu", ContourContextMenu);
|
|
2118
|
-
|
|
2119
|
-
/**
|
|
2120
|
-
* Fab: web component wrapper.
|
|
2121
|
-
* Attributes: `label`, `icon`.
|
|
2122
|
-
*/
|
|
2123
|
-
class ContourFab extends ContourBase {
|
|
2124
|
-
static get observed() { return ["label", "icon"]; }
|
|
2125
|
-
static get properties() { return { label: { attribute: "label" }, icon: { attribute: "icon" } }; }
|
|
2126
|
-
render() {
|
|
2127
|
-
this.classList.add("c-fab");
|
|
2128
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "button");
|
|
2129
|
-
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
2130
|
-
const label = this.getAttribute("label");
|
|
2131
|
-
if (label) this.setAttribute("aria-label", label);
|
|
2132
|
-
const icon = this.getAttribute("icon");
|
|
2133
|
-
if (icon && !this.hasChildNodes()) this.textContent = icon;
|
|
2134
|
-
}
|
|
2135
|
-
enhance() {
|
|
2136
|
-
if (this._wiredFab) return;
|
|
2137
|
-
this._wiredFab = true;
|
|
2138
|
-
this.addEventListener("click", () => {
|
|
2139
|
-
this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true }));
|
|
2140
|
-
});
|
|
2141
|
-
this.addEventListener("keydown", (e) => {
|
|
2142
|
-
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true })); }
|
|
2143
|
-
});
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
define("contour-fab", ContourFab);
|
|
2147
|
-
|
|
2148
|
-
/**
|
|
2149
|
-
* File Upload: web component wrapper.
|
|
2150
|
-
* Attributes: `label`, `accept`, `multiple`, `progress`.
|
|
2151
|
-
*/
|
|
2152
|
-
class ContourFileUpload extends ContourBase {
|
|
2153
|
-
static get observed() { return ["label", "accept", "multiple", "progress"]; }
|
|
2154
|
-
static get properties() { return { label: { attribute: "label" }, accept: { attribute: "accept" }, multiple: { attribute: "multiple", type: Boolean }, progress: { attribute: "progress" } }; }
|
|
2155
|
-
render() {
|
|
2156
|
-
this.classList.add("c-file-upload");
|
|
2157
|
-
const label = this.getAttribute("label") || "Drop files here or click to browse";
|
|
2158
|
-
const dz = this.ensure(".c-file-upload__dropzone", () => { const el = document.createElement("div"); el.className = "c-file-upload__dropzone"; el.setAttribute("role", "button"); el.tabIndex = 0; return el; });
|
|
2159
|
-
dz.textContent = label;
|
|
2160
|
-
const input = this.ensure(".c-file-upload__input", () => { const el = document.createElement("input"); el.className = "c-file-upload__input"; el.type = "file"; el.hidden = true; return el; });
|
|
2161
|
-
input.accept = this.getAttribute("accept") || "";
|
|
2162
|
-
input.multiple = this.hasAttribute("multiple");
|
|
2163
|
-
const p = this.getAttribute("progress");
|
|
2164
|
-
if (p !== null) {
|
|
2165
|
-
const bar = this.ensure(".c-file-upload__progress", () => { const el = document.createElement("progress"); el.className = "c-file-upload__progress"; return el; });
|
|
2166
|
-
bar.value = Number(p) || 0;
|
|
2167
|
-
bar.max = 100;
|
|
2168
|
-
} else {
|
|
2169
|
-
const bar = this.querySelector(".c-file-upload__progress");
|
|
2170
|
-
if (bar) bar.remove();
|
|
2171
|
-
}
|
|
2172
|
-
const preview = this.ensure(".c-file-upload__preview", () => { const el = document.createElement("div"); el.className = "c-file-upload__preview"; return el; });
|
|
2173
|
-
if (!preview) {}
|
|
2174
|
-
}
|
|
2175
|
-
enhance() {
|
|
2176
|
-
if (this._wiredFileUpload) return;
|
|
2177
|
-
this._wiredFileUpload = true;
|
|
2178
|
-
const dz = () => this.querySelector(".c-file-upload__dropzone");
|
|
2179
|
-
const input = () => this.querySelector(".c-file-upload__input");
|
|
2180
|
-
const activate = () => { const i = input(); if (i) i.click(); };
|
|
2181
|
-
this.addEventListener("click", (e) => { const d = dz(); if (e.target === d || (d && d.contains(e.target))) { activate(); } });
|
|
2182
|
-
this.addEventListener("keydown", (e) => { const d = dz(); if ((e.target === d || (d && d.contains(e.target))) && (e.key === "Enter" || e.key === " ")) { e.preventDefault(); activate(); } });
|
|
2183
|
-
const renderPreview = (files) => {
|
|
2184
|
-
const preview = this.querySelector(".c-file-upload__preview");
|
|
2185
|
-
if (!preview) return;
|
|
2186
|
-
preview.innerHTML = "";
|
|
2187
|
-
Array.from(files || []).forEach((f) => {
|
|
2188
|
-
const item = document.createElement("div");
|
|
2189
|
-
item.className = "c-file-upload__preview-item";
|
|
2190
|
-
if (f.type && f.type.startsWith("image/")) {
|
|
2191
|
-
const img = document.createElement("img");
|
|
2192
|
-
img.className = "c-file-upload__preview-thumb";
|
|
2193
|
-
img.alt = f.name;
|
|
2194
|
-
img.loading = "lazy";
|
|
2195
|
-
img.decoding = "async";
|
|
2196
|
-
try { img.src = URL.createObjectURL(f); } catch (e) {}
|
|
2197
|
-
item.appendChild(img);
|
|
2198
|
-
} else {
|
|
2199
|
-
const name = document.createElement("span");
|
|
2200
|
-
name.className = "c-file-upload__preview-name";
|
|
2201
|
-
name.textContent = f.name;
|
|
2202
|
-
item.appendChild(name);
|
|
2203
|
-
}
|
|
2204
|
-
preview.appendChild(item);
|
|
2205
|
-
});
|
|
2206
|
-
};
|
|
2207
|
-
this.addEventListener("change", (e) => { const t = e.target; if (t && t.classList.contains("c-file-upload__input")) { renderPreview(t.files); this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { files: t.files } })); } });
|
|
2208
|
-
// drag-drop already dispatches contour:change; also render preview there
|
|
2209
|
-
this.addEventListener("dragover", (e) => { e.preventDefault(); this.classList.add("is-dragover"); });
|
|
2210
|
-
this.addEventListener("dragleave", () => this.classList.remove("is-dragover"));
|
|
2211
|
-
this.addEventListener("drop", (e) => { e.preventDefault(); this.classList.remove("is-dragover"); const i = input(); if (i && e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files.length) { try { i.files = e.dataTransfer.files; } catch (err) { /* some browsers disallow */ } const preview = this.querySelector(".c-file-upload__preview"); if (preview) { preview.innerHTML = ""; Array.from(e.dataTransfer.files).forEach((f) => { const item = document.createElement("div"); item.className = "c-file-upload__preview-item"; if (f.type && f.type.startsWith("image/")) { const img = document.createElement("img"); img.className = "c-file-upload__preview-thumb"; img.alt = f.name; try { img.src = URL.createObjectURL(f); } catch (err2) {} item.appendChild(img); } else { const name = document.createElement("span"); name.className = "c-file-upload__preview-name"; name.textContent = f.name; item.appendChild(name); } preview.appendChild(item); }); } this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { files: e.dataTransfer.files } })); } });
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
define("contour-file-upload", ContourFileUpload);
|
|
2215
|
-
|
|
2216
|
-
/**
|
|
2217
|
-
* Notification Center: web component wrapper.
|
|
2218
|
-
* Attributes: `count`, `items`, `color`.
|
|
2219
|
-
*/
|
|
2220
|
-
class ContourNotificationCenter extends ContourBase {
|
|
2221
|
-
static get observed() { return ["count", "items", "color"]; }
|
|
2222
|
-
static get properties() { return { count: { attribute: "count" }, items: { attribute: "items" }, color: { attribute: "color" } }; }
|
|
2223
|
-
render() {
|
|
2224
|
-
this.classList.add("c-notification-center");
|
|
2225
|
-
this.setAttribute("role", "list");
|
|
2226
|
-
const btn = this.ensure(".c-notification-center__trigger", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-notification-center__trigger"; el.type = "button"; el.innerHTML = '<span class="c-notification-center__bullet" aria-hidden="true"></span>'; el.setAttribute("aria-haspopup", "dialog"); el.setAttribute("aria-expanded", "false"); return el; });
|
|
2227
|
-
const color = this.getAttribute("color");
|
|
2228
|
-
const bullet = btn.querySelector(".c-notification-center__bullet");
|
|
2229
|
-
if (bullet && color) { bullet.style.background = color; bullet.dataset.color = color; }
|
|
2230
|
-
const count = this.getAttribute("count");
|
|
2231
|
-
let badge = btn.querySelector(".c-notification-center__badge");
|
|
2232
|
-
if (count && Number(count) > 0) {
|
|
2233
|
-
if (!badge) { badge = document.createElement("span"); badge.className = "c-notification-center__badge c-badge c-badge--dot"; btn.appendChild(badge); }
|
|
2234
|
-
badge.textContent = count;
|
|
2235
|
-
} else if (badge) { badge.remove(); }
|
|
2236
|
-
const panel = this.ensure(".c-notification-center__panel", () => { const el = document.createElement("div"); el.className = "c-notification-center__panel"; el.hidden = true; el.setAttribute("role", "dialog"); el.setAttribute("aria-label", "Notifications"); return el; });
|
|
2237
|
-
// Slotted content: authored .c-notification-center__item children take
|
|
2238
|
-
// precedence over the JSON `items` attribute.
|
|
2239
|
-
const authoredItems = Array.from(this.querySelectorAll(":scope > .c-notification-center__item"));
|
|
2240
|
-
const items = this.getAttribute("items");
|
|
2241
|
-
if (authoredItems.length) {
|
|
2242
|
-
panel.innerHTML = "";
|
|
2243
|
-
authoredItems.forEach((it) => { panel.appendChild(it); });
|
|
2244
|
-
} else if (items) {
|
|
2245
|
-
try {
|
|
2246
|
-
const parsed = JSON.parse(items);
|
|
2247
|
-
panel.innerHTML = "";
|
|
2248
|
-
parsed.forEach((it) => {
|
|
2249
|
-
const row = document.createElement("div");
|
|
2250
|
-
row.className = "c-notification-center__item";
|
|
2251
|
-
row.setAttribute("tabindex", "0");
|
|
2252
|
-
row.setAttribute("role", "option");
|
|
2253
|
-
row.textContent = typeof it === "string" ? it : (it.text || it.title || "");
|
|
2254
|
-
panel.appendChild(row);
|
|
2255
|
-
});
|
|
2256
|
-
} catch (e) { /* keep */ }
|
|
2257
|
-
}
|
|
2258
|
-
}
|
|
2259
|
-
enhance() {
|
|
2260
|
-
if (this._wiredNotifCenter) return;
|
|
2261
|
-
this._wiredNotifCenter = true;
|
|
2262
|
-
this.addEventListener("click", (e) => {
|
|
2263
|
-
const btn = this.querySelector(".c-notification-center__trigger");
|
|
2264
|
-
const panel = this.querySelector(".c-notification-center__panel");
|
|
2265
|
-
if (btn && (e.target === btn || btn.contains(e.target))) {
|
|
2266
|
-
if (panel) { panel.hidden = !panel.hidden; btn.setAttribute("aria-expanded", String(!panel.hidden)); this.dispatchEvent(new CustomEvent(panel.hidden ? "contour:close" : "contour:open", { bubbles: true, composed: true })); }
|
|
2267
|
-
}
|
|
2268
|
-
});
|
|
2269
|
-
this.addEventListener("click", (e) => {
|
|
2270
|
-
const item = e.target && e.target.closest ? e.target.closest(".c-notification-center__item") : null;
|
|
2271
|
-
if (item && this.contains(item)) {
|
|
2272
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { label: item.textContent } }));
|
|
2273
|
-
}
|
|
2274
|
-
});
|
|
2275
|
-
const docClick = (e) => {
|
|
2276
|
-
const panel = this.querySelector(".c-notification-center__panel");
|
|
2277
|
-
const btn = this.querySelector(".c-notification-center__trigger");
|
|
2278
|
-
if (panel && !panel.hidden && !this.contains(e.target)) { panel.hidden = true; if (btn) btn.setAttribute("aria-expanded", "false"); }
|
|
2279
|
-
};
|
|
2280
|
-
document.addEventListener("click", docClick);
|
|
2281
|
-
onDispose(this, () => document.removeEventListener("click", docClick));
|
|
2282
|
-
const keyHandler = (e) => {
|
|
2283
|
-
const panel = this.querySelector(".c-notification-center__panel");
|
|
2284
|
-
const btn = this.querySelector(".c-notification-center__trigger");
|
|
2285
|
-
if (e.key === "Escape" && panel && !panel.hidden) { panel.hidden = true; if (btn) { btn.setAttribute("aria-expanded", "false"); try { btn.focus(); } catch (err) {} } return; }
|
|
2286
|
-
if (!panel || panel.hidden) return;
|
|
2287
|
-
const items = Array.from(panel.querySelectorAll(".c-notification-center__item"));
|
|
2288
|
-
if (!items.length) return;
|
|
2289
|
-
const active = document.activeElement;
|
|
2290
|
-
const idx = items.indexOf(active);
|
|
2291
|
-
if (e.key === "ArrowDown") { e.preventDefault(); const next = items[Math.min(items.length - 1, idx + 1)] || items[0]; if (next) try { next.focus(); } catch (err) {} }
|
|
2292
|
-
else if (e.key === "ArrowUp") { e.preventDefault(); const prev = items[Math.max(0, idx - 1)] || items[items.length - 1]; if (prev) try { prev.focus(); } catch (err) {} }
|
|
2293
|
-
};
|
|
2294
|
-
document.addEventListener("keydown", keyHandler);
|
|
2295
|
-
onDispose(this, () => document.removeEventListener("keydown", keyHandler));
|
|
2296
|
-
}
|
|
2297
|
-
}
|
|
2298
|
-
define("contour-notification-center", ContourNotificationCenter);
|
|
2299
|
-
|
|
2300
|
-
/**
|
|
2301
|
-
* Stepper: web component wrapper.
|
|
2302
|
-
* Attributes: `steps`, `current`.
|
|
2303
|
-
*/
|
|
2304
|
-
class ContourStepper extends ContourBase {
|
|
2305
|
-
static get observed() { return ["steps", "current"]; }
|
|
2306
|
-
static get properties() { return { steps: { attribute: "steps" }, current: { attribute: "current" } }; }
|
|
2307
|
-
render() {
|
|
2308
|
-
this.classList.add("c-stepper");
|
|
2309
|
-
const steps = this.getAttribute("steps");
|
|
2310
|
-
const current = Number(this.getAttribute("current") || 0);
|
|
2311
|
-
const list = this.ensure(".c-stepper__list", () => { const el = document.createElement("ol"); el.className = "c-stepper__list"; return el; });
|
|
2312
|
-
list.innerHTML = "";
|
|
2313
|
-
// Slotted content: authored .c-stepper__step children take precedence.
|
|
2314
|
-
const authoredSteps = Array.from(this.querySelectorAll(":scope > .c-stepper__step"));
|
|
2315
|
-
let parsed = [];
|
|
2316
|
-
if (authoredSteps.length) {
|
|
2317
|
-
parsed = authoredSteps.map((el) => el.textContent.trim());
|
|
2318
|
-
authoredSteps.forEach((el) => el.remove());
|
|
2319
|
-
} else {
|
|
2320
|
-
try { parsed = steps ? JSON.parse(steps) : []; } catch (e) { parsed = []; }
|
|
2321
|
-
}
|
|
2322
|
-
parsed.forEach((s, i) => {
|
|
2323
|
-
const li = document.createElement("li");
|
|
2324
|
-
li.className = "c-stepper__step" + (i === current ? " is-current" : "") + (i < current ? " is-done" : "");
|
|
2325
|
-
if (i === current) li.setAttribute("aria-current", "step");
|
|
2326
|
-
li.textContent = typeof s === "string" ? s : (s.title || s.label || "");
|
|
2327
|
-
list.appendChild(li);
|
|
2328
|
-
});
|
|
2329
|
-
const nav = this.ensure(".c-stepper__nav", () => { const el = document.createElement("div"); el.className = "c-stepper__nav c-btn-group"; return el; });
|
|
2330
|
-
const prev = this.ensure(".c-stepper__prev", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-stepper__prev"; el.type = "button"; el.textContent = "Back"; return el; });
|
|
2331
|
-
const next = this.ensure(".c-stepper__next", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-stepper__next"; el.type = "button"; el.textContent = "Next"; return el; });
|
|
2332
|
-
if (!nav.contains(prev)) nav.appendChild(prev);
|
|
2333
|
-
if (!nav.contains(next)) nav.appendChild(next);
|
|
2334
|
-
if (nav.parentNode !== this) this.appendChild(nav);
|
|
2335
|
-
}
|
|
2336
|
-
enhance() {
|
|
2337
|
-
if (this._wiredStepper) return;
|
|
2338
|
-
this._wiredStepper = true;
|
|
2339
|
-
const go = (dir) => {
|
|
2340
|
-
const list = this.querySelector(".c-stepper__list");
|
|
2341
|
-
const total = list ? list.querySelectorAll(".c-stepper__step").length : 0;
|
|
2342
|
-
if (!total) return;
|
|
2343
|
-
let cur = Number(this.getAttribute("current") || 0);
|
|
2344
|
-
if (dir === "prev") cur = Math.max(0, cur - 1);
|
|
2345
|
-
else cur = Math.min(total - 1, cur + 1);
|
|
2346
|
-
this.setAttribute("current", String(cur));
|
|
2347
|
-
this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { direction: dir, index: cur } }));
|
|
2348
|
-
};
|
|
2349
|
-
this.addEventListener("click", (e) => {
|
|
2350
|
-
const prev = e.target && e.target.closest ? e.target.closest(".c-stepper__prev") : null;
|
|
2351
|
-
const next = e.target && e.target.closest ? e.target.closest(".c-stepper__next") : null;
|
|
2352
|
-
if (prev && this.contains(prev)) go("prev");
|
|
2353
|
-
if (next && this.contains(next)) go("next");
|
|
2354
|
-
});
|
|
2355
|
-
this.addEventListener("keydown", (e) => {
|
|
2356
|
-
if (e.key === "ArrowLeft") { e.preventDefault(); go("prev"); }
|
|
2357
|
-
else if (e.key === "ArrowRight") { e.preventDefault(); go("next"); }
|
|
2358
|
-
});
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
define("contour-stepper", ContourStepper);
|
|
2362
|
-
|
|
2363
|
-
/**
|
|
2364
|
-
* Virtual List: web component wrapper.
|
|
2365
|
-
* Attributes: `items`, `item-height`, `orientation`, `sticky`.
|
|
2366
|
-
*/
|
|
2367
|
-
class ContourVirtualList extends ContourBase {
|
|
2368
|
-
static get updateMode() { return "keyed"; }
|
|
2369
|
-
static get observed() { return ["items", "item-height", "orientation", "sticky"]; }
|
|
2370
|
-
static get properties() { return { items: { attribute: "items" }, "item-height": { attribute: "item-height" }, orientation: { attribute: "orientation" }, sticky: { attribute: "sticky", type: Boolean } }; }
|
|
2371
|
-
_items() {
|
|
2372
|
-
const items = this.getAttribute("items");
|
|
2373
|
-
let parsed = [];
|
|
2374
|
-
try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
|
|
2375
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
2376
|
-
}
|
|
2377
|
-
_itemHeight() {
|
|
2378
|
-
const h = Number(this.getAttribute("item-height"));
|
|
2379
|
-
return Number.isFinite(h) && h > 0 ? h : 28;
|
|
2380
|
-
}
|
|
2381
|
-
_autoHeight() {
|
|
2382
|
-
return this.getAttribute("item-height") === "auto";
|
|
2383
|
-
}
|
|
2384
|
-
render() {
|
|
2385
|
-
this.classList.add("c-virtual-list");
|
|
2386
|
-
this.setAttribute("role", "list");
|
|
2387
|
-
const scroller = this.ensure(".c-virtual-list__scroller", () => { const el = document.createElement("div"); el.className = "c-virtual-list__scroller"; return el; });
|
|
2388
|
-
scroller.setAttribute("role", "presentation");
|
|
2389
|
-
const horizontal = this.getAttribute("orientation") === "horizontal";
|
|
2390
|
-
scroller.style.overflowX = horizontal ? "auto" : "hidden";
|
|
2391
|
-
scroller.style.overflowY = horizontal ? "hidden" : "auto";
|
|
2392
|
-
const inner = this.ensure(".c-virtual-list__inner", () => { const el = document.createElement("div"); el.className = "c-virtual-list__inner"; el.style.position = "relative"; return el; });
|
|
2393
|
-
if (inner.parentNode !== scroller) scroller.appendChild(inner);
|
|
2394
|
-
this._renderWindow(scroller, inner, horizontal ? (scroller.scrollLeft || 0) : (scroller.scrollTop || 0));
|
|
2395
|
-
}
|
|
2396
|
-
_measureHeights(inner, horizontal) {
|
|
2397
|
-
const rows = Array.from(inner.querySelectorAll(".c-virtual-list__item"));
|
|
2398
|
-
return rows.map((r) => horizontal ? (r.getBoundingClientRect().width || 28) : (r.getBoundingClientRect().height || 28));
|
|
2399
|
-
}
|
|
2400
|
-
_renderWindow(scroller, inner, scrollTop) {
|
|
2401
|
-
const items = this._items();
|
|
2402
|
-
const ih = this._itemHeight();
|
|
2403
|
-
const horizontal = this.getAttribute("orientation") === "horizontal";
|
|
2404
|
-
const autoHeight = this._autoHeight();
|
|
2405
|
-
const viewportSize = horizontal ? (scroller.clientWidth || 320) : (scroller.clientHeight || 320);
|
|
2406
|
-
const total = items.length;
|
|
2407
|
-
// Reset measured heights when item count changes.
|
|
2408
|
-
if (this._vlItemCount !== total) { this._vlHeights = null; this._vlItemCount = total; }
|
|
2409
|
-
let heights = autoHeight ? this._vlHeights : null;
|
|
2410
|
-
let cumulative = null;
|
|
2411
|
-
if (autoHeight && heights && heights.length === total) {
|
|
2412
|
-
cumulative = [0];
|
|
2413
|
-
for (let i = 0; i < total; i++) cumulative.push(cumulative[i] + (heights[i] || 28));
|
|
2414
|
-
}
|
|
2415
|
-
const visibleCount = autoHeight && !cumulative ? total : (autoHeight ? Math.ceil(viewportSize / 28) + 6 : Math.ceil(viewportSize / ih) + 4);
|
|
2416
|
-
let start = 0;
|
|
2417
|
-
if (autoHeight && cumulative) {
|
|
2418
|
-
// binary search for start
|
|
2419
|
-
let lo = 0, hi = total;
|
|
2420
|
-
while (lo < hi) {
|
|
2421
|
-
const mid = (lo + hi) >> 1;
|
|
2422
|
-
if (cumulative[mid] < (scrollTop || 0)) lo = mid + 1; else hi = mid;
|
|
2423
|
-
}
|
|
2424
|
-
start = Math.max(0, lo - 3);
|
|
2425
|
-
} else if (!autoHeight) {
|
|
2426
|
-
start = Math.floor((scrollTop || 0) / ih);
|
|
2427
|
-
}
|
|
2428
|
-
if (start < 0) start = 0;
|
|
2429
|
-
const end = autoHeight && cumulative
|
|
2430
|
-
? Math.min(total, start + visibleCount)
|
|
2431
|
-
: Math.min(total, start + visibleCount);
|
|
2432
|
-
if (start > Math.max(0, total - visibleCount) && !autoHeight) start = Math.max(0, total - visibleCount);
|
|
2433
|
-
const topSpacerSize = autoHeight && cumulative ? cumulative[start] : (autoHeight ? 0 : start * ih);
|
|
2434
|
-
const bottomSpacerSize = autoHeight && cumulative ? Math.max(0, cumulative[total] - cumulative[end]) : (autoHeight ? 0 : Math.max(0, (total - end) * ih));
|
|
2435
|
-
inner.style.display = horizontal ? "flex" : "block";
|
|
2436
|
-
inner.style.width = horizontal && autoHeight ? "max-content" : "";
|
|
2437
|
-
inner.style.height = horizontal || autoHeight ? "" : (total * ih) + "px";
|
|
2438
|
-
inner.innerHTML = "";
|
|
2439
|
-
const top = document.createElement("div");
|
|
2440
|
-
top.className = "c-virtual-list__spacer c-virtual-list__spacer--top";
|
|
2441
|
-
top.style[horizontal ? "width" : "height"] = topSpacerSize + "px";
|
|
2442
|
-
inner.appendChild(top);
|
|
2443
|
-
for (let i = start; i < end; i++) {
|
|
2444
|
-
const row = document.createElement("div");
|
|
2445
|
-
row.className = "c-virtual-list__item";
|
|
2446
|
-
row.setAttribute("role", "listitem");
|
|
2447
|
-
// aria-rowindex omitted: not allowed on role="listitem" (axe aria-allowed-attr)
|
|
2448
|
-
row.setAttribute("tabindex", i === 0 ? "0" : "-1");
|
|
2449
|
-
row.textContent = typeof items[i] === "string" ? items[i] : (items[i].label || items[i].text || JSON.stringify(items[i]));
|
|
2450
|
-
if (this.hasAttribute("sticky") && items[i] && items[i].sticky) {
|
|
2451
|
-
row.style.position = "sticky";
|
|
2452
|
-
row.style.insetBlockStart = "0";
|
|
2453
|
-
row.style.zIndex = "1";
|
|
2454
|
-
}
|
|
2455
|
-
if (horizontal && !autoHeight) row.style.flex = "0 0 " + ih + "px";
|
|
2456
|
-
row.dataset.index = String(i);
|
|
2457
|
-
inner.appendChild(row);
|
|
2458
|
-
}
|
|
2459
|
-
const bottom = document.createElement("div");
|
|
2460
|
-
bottom.className = "c-virtual-list__spacer c-virtual-list__spacer--bottom";
|
|
2461
|
-
bottom.style[horizontal ? "width" : "height"] = bottomSpacerSize + "px";
|
|
2462
|
-
inner.appendChild(bottom);
|
|
2463
|
-
if (horizontal && !autoHeight) inner.style.width = (total * ih) + "px";
|
|
2464
|
-
// Measure heights in auto mode for future windowing.
|
|
2465
|
-
if (autoHeight && !this._vlHeights) {
|
|
2466
|
-
// defer measurement to next frame so layout is done
|
|
2467
|
-
requestAnimationFrame(() => {
|
|
2468
|
-
this._vlHeights = this._measureHeights(inner, horizontal);
|
|
2469
|
-
// re-render windowed now that heights known
|
|
2470
|
-
const s = scroller;
|
|
2471
|
-
const i = inner;
|
|
2472
|
-
if (s && i) this._renderWindow(s, i, s.scrollTop || 0);
|
|
2473
|
-
});
|
|
2474
|
-
}
|
|
2475
|
-
}
|
|
2476
|
-
enhance() {
|
|
2477
|
-
if (this._wiredVirtualList) return;
|
|
2478
|
-
this._wiredVirtualList = true;
|
|
2479
|
-
const scroller = () => this.querySelector(".c-virtual-list__scroller");
|
|
2480
|
-
const inner = () => this.querySelector(".c-virtual-list__inner");
|
|
2481
|
-
let raf = 0;
|
|
2482
|
-
const onScroll = () => {
|
|
2483
|
-
if (raf) return;
|
|
2484
|
-
raf = requestAnimationFrame(() => {
|
|
2485
|
-
raf = 0;
|
|
2486
|
-
const s = scroller(); const i = inner();
|
|
2487
|
-
if (s && i) this._renderWindow(s, i, this.getAttribute("orientation") === "horizontal" ? s.scrollLeft : s.scrollTop);
|
|
2488
|
-
});
|
|
2489
|
-
};
|
|
2490
|
-
const s = scroller();
|
|
2491
|
-
if (s) {
|
|
2492
|
-
s.addEventListener("scroll", onScroll, { passive: true });
|
|
2493
|
-
onDispose(this, () => { s.removeEventListener("scroll", onScroll); if (raf) cancelAnimationFrame(raf); });
|
|
2494
|
-
}
|
|
2495
|
-
// keyboard + selection
|
|
2496
|
-
this.addEventListener("keydown", (e) => {
|
|
2497
|
-
const rows = Array.from(this.querySelectorAll(".c-virtual-list__item"));
|
|
2498
|
-
if (!rows.length) return;
|
|
2499
|
-
const active = this.querySelector(".c-virtual-list__item:focus") || rows[0];
|
|
2500
|
-
const idx = rows.indexOf(active);
|
|
2501
|
-
let next = -1;
|
|
2502
|
-
if (e.key === "ArrowDown") next = Math.min(idx + 1, rows.length - 1);
|
|
2503
|
-
else if (e.key === "ArrowUp") next = Math.max(idx - 1, 0);
|
|
2504
|
-
else if (e.key === "Home") next = 0;
|
|
2505
|
-
else if (e.key === "End") next = rows.length - 1;
|
|
2506
|
-
else if (e.key === "Enter" || e.key === " ") {
|
|
2507
|
-
e.preventDefault();
|
|
2508
|
-
const i = Number(active.dataset.index);
|
|
2509
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: i, value: active.textContent } }));
|
|
2510
|
-
return;
|
|
2511
|
-
}
|
|
2512
|
-
if (next < 0 || next === idx) return;
|
|
2513
|
-
e.preventDefault();
|
|
2514
|
-
rows.forEach((r, i) => r.setAttribute("tabindex", i === next ? "0" : "-1"));
|
|
2515
|
-
try { rows[next].focus(); } catch (err) {}
|
|
2516
|
-
});
|
|
2517
|
-
this.addEventListener("click", (e) => {
|
|
2518
|
-
const row = e.target && e.target.closest ? e.target.closest(".c-virtual-list__item") : null;
|
|
2519
|
-
if (!row || !this.contains(row)) return;
|
|
2520
|
-
const i = Number(row.dataset.index);
|
|
2521
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: i, value: row.textContent } }));
|
|
2522
|
-
});
|
|
2523
|
-
}
|
|
2524
|
-
}
|
|
2525
|
-
define("contour-virtual-list", ContourVirtualList);
|
|
2526
|
-
|
|
2527
|
-
/**
|
|
2528
|
-
* Command Palette: web component wrapper.
|
|
2529
|
-
* Attributes: `open`, `items`.
|
|
2530
|
-
*/
|
|
2531
|
-
class ContourCommandPalette extends ContourBase {
|
|
2532
|
-
static get observed() { return ["open", "items"]; }
|
|
2533
|
-
static get properties() { return { open: { attribute: "open", type: Boolean }, items: { attribute: "items" } }; }
|
|
2534
|
-
render() {
|
|
2535
|
-
this.classList.add("c-command-palette");
|
|
2536
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
|
|
2537
|
-
if (!this.hasAttribute("aria-modal")) this.setAttribute("aria-modal", "true");
|
|
2538
|
-
if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
|
|
2539
|
-
const search = this.ensure(".c-command-palette__search", () => { const el = document.createElement("input"); el.className = "c-input c-command-palette__search"; el.type = "search"; el.placeholder = "Search…"; el.setAttribute("aria-label", "Search commands"); return el; });
|
|
2540
|
-
const list = this.ensure(".c-command-palette__list", () => { const el = document.createElement("div"); el.className = "c-command-palette__list"; el.setAttribute("role", "listbox"); return el; });
|
|
2541
|
-
const items = this.getAttribute("items");
|
|
2542
|
-
if (items) {
|
|
2543
|
-
try {
|
|
2544
|
-
const parsed = JSON.parse(items);
|
|
2545
|
-
list.innerHTML = "";
|
|
2546
|
-
parsed.forEach((it, i) => {
|
|
2547
|
-
const row = document.createElement("div");
|
|
2548
|
-
row.className = "c-command-palette__item";
|
|
2549
|
-
row.setAttribute("role", "option");
|
|
2550
|
-
row.id = this.id + "-opt-" + i;
|
|
2551
|
-
row.textContent = typeof it === "string" ? it : (it.label || it.title || "");
|
|
2552
|
-
row.dataset.index = String(i);
|
|
2553
|
-
row.dataset.label = row.textContent;
|
|
2554
|
-
list.appendChild(row);
|
|
2555
|
-
});
|
|
2556
|
-
} catch (e) { /* keep */ }
|
|
2557
|
-
}
|
|
2558
|
-
}
|
|
2559
|
-
show() { if (typeof this.showPopover === "function") { try { this.showPopover(); } catch (e) {} } this.classList.add("is-open"); }
|
|
2560
|
-
hide() { if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (e) {} } this.classList.remove("is-open"); }
|
|
2561
|
-
toggle() { if (this.classList.contains("is-open") || this.matches(":popover-open")) this.hide(); else this.show(); }
|
|
2562
|
-
enhance() {
|
|
2563
|
-
this._wiredCmdPalette = true;
|
|
2564
|
-
const search = () => this.querySelector(".c-command-palette__search");
|
|
2565
|
-
const list = () => this.querySelector(".c-command-palette__list");
|
|
2566
|
-
const items = () => Array.from(this.querySelectorAll(".c-command-palette__item"));
|
|
2567
|
-
const visibleItems = () => items().filter((it) => !it.hidden);
|
|
2568
|
-
const setActive = (idx) => {
|
|
2569
|
-
const vis = visibleItems();
|
|
2570
|
-
vis.forEach((it, i) => it.classList.toggle("is-active", i === idx));
|
|
2571
|
-
const active = vis[idx];
|
|
2572
|
-
const s = search();
|
|
2573
|
-
if (s && active) s.setAttribute("aria-activedescendant", active.id);
|
|
2574
|
-
else if (s) s.removeAttribute("aria-activedescendant");
|
|
2575
|
-
};
|
|
2576
|
-
const filter = (q) => {
|
|
2577
|
-
const needle = (q || "").toLowerCase().trim();
|
|
2578
|
-
items().forEach((it) => {
|
|
2579
|
-
const label = (it.dataset.label || it.textContent || "").toLowerCase();
|
|
2580
|
-
it.hidden = needle !== "" && !label.includes(needle);
|
|
2581
|
-
});
|
|
2582
|
-
setActive(0);
|
|
2583
|
-
};
|
|
2584
|
-
const select = (it) => {
|
|
2585
|
-
if (!it) return;
|
|
2586
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: Number(it.dataset.index), label: it.dataset.label || it.textContent } }));
|
|
2587
|
-
try { this.hidePopover(); } catch (e) {}
|
|
2588
|
-
this.classList.remove("is-open");
|
|
2589
|
-
};
|
|
2590
|
-
const s = search();
|
|
2591
|
-
if (s) {
|
|
2592
|
-
s.setAttribute("role", "combobox");
|
|
2593
|
-
s.setAttribute("aria-autocomplete", "list");
|
|
2594
|
-
s.setAttribute("aria-controls", list() ? list().id || "" : "");
|
|
2595
|
-
if (!list().id) list().id = this.id + "-list";
|
|
2596
|
-
s.setAttribute("aria-controls", list().id);
|
|
2597
|
-
s.addEventListener("input", (e) => filter(e.target.value));
|
|
2598
|
-
s.addEventListener("keydown", (e) => {
|
|
2599
|
-
const vis = visibleItems();
|
|
2600
|
-
const active = this.querySelector(".c-command-palette__item.is-active");
|
|
2601
|
-
let idx = active ? vis.indexOf(active) : -1;
|
|
2602
|
-
if (e.key === "ArrowDown") { e.preventDefault(); idx = Math.min(vis.length - 1, idx + 1); if (idx < 0) idx = 0; setActive(idx); }
|
|
2603
|
-
else if (e.key === "ArrowUp") { e.preventDefault(); idx = Math.max(0, idx - 1); if (vis.length && idx < 0) idx = 0; setActive(idx); }
|
|
2604
|
-
else if (e.key === "Home") { e.preventDefault(); setActive(0); }
|
|
2605
|
-
else if (e.key === "End") { e.preventDefault(); setActive(vis.length - 1); }
|
|
2606
|
-
else if (e.key === "Enter") { e.preventDefault(); if (active) select(active); }
|
|
2607
|
-
else if (e.key === "Escape") { e.preventDefault(); try { this.hidePopover(); } catch (e) {} this.classList.remove("is-open"); }
|
|
2608
|
-
});
|
|
2609
|
-
}
|
|
2610
|
-
// click selection
|
|
2611
|
-
this.addEventListener("click", (e) => {
|
|
2612
|
-
const it = e.target && e.target.closest ? e.target.closest(".c-command-palette__item") : null;
|
|
2613
|
-
if (it && this.contains(it) && !it.hidden) select(it);
|
|
2614
|
-
});
|
|
2615
|
-
// focus return on close
|
|
2616
|
-
let lastFocus = null;
|
|
2617
|
-
this.addEventListener("beforetoggle", (e) => {
|
|
2618
|
-
if (e.newState === "open") lastFocus = document.activeElement;
|
|
2619
|
-
else if (lastFocus && typeof lastFocus.focus === "function") { try { lastFocus.focus(); } catch (err) {} }
|
|
2620
|
-
});
|
|
2621
|
-
// Escape via popover light dismiss is handled by keydown above; also close on outside handled by popover.
|
|
2622
|
-
setActive(0);
|
|
2623
|
-
}
|
|
2624
|
-
}
|
|
2625
|
-
define("contour-command-palette", ContourCommandPalette);
|
|
2626
|
-
|
|
2627
|
-
/**
|
|
2628
|
-
* Badge Overflow: web component wrapper.
|
|
2629
|
-
* Attributes: `count`, `max`.
|
|
2630
|
-
*/
|
|
2631
|
-
class ContourBadgeOverflow extends ContourBase {
|
|
2632
|
-
static get observed() { return ["count", "max"]; }
|
|
2633
|
-
static get properties() { return { count: { attribute: "count" }, max: { attribute: "max" } }; }
|
|
2634
|
-
render() {
|
|
2635
|
-
this.classList.add("c-badge-overflow");
|
|
2636
|
-
const count = Number(this.getAttribute("count") || 0);
|
|
2637
|
-
const max = Number(this.getAttribute("max") || 3);
|
|
2638
|
-
const extra = Math.max(0, count - max);
|
|
2639
|
-
this.textContent = "";
|
|
2640
|
-
if (extra > 0) {
|
|
2641
|
-
const b = document.createElement("span");
|
|
2642
|
-
b.className = "c-badge c-badge-overflow__more";
|
|
2643
|
-
b.textContent = "+" + extra;
|
|
2644
|
-
this.appendChild(b);
|
|
2645
|
-
}
|
|
2646
|
-
}
|
|
2647
|
-
}
|
|
2648
|
-
define("contour-badge-overflow", ContourBadgeOverflow);
|
|
2649
|
-
|
|
2650
|
-
/**
|
|
2651
|
-
* Side Sheet: web component wrapper.
|
|
2652
|
-
* Attributes: `open`, `side`, `title`.
|
|
2653
|
-
*/
|
|
2654
|
-
class ContourSideSheet extends ContourBase {
|
|
2655
|
-
static get observed() { return ["open", "side", "title"]; }
|
|
2656
|
-
static get properties() { return { open: { attribute: "open", type: Boolean }, side: { attribute: "side" }, title: { attribute: "title" } }; }
|
|
2657
|
-
render() {
|
|
2658
|
-
this.classList.add("c-side-sheet");
|
|
2659
|
-
this.setAttribute("role", "dialog");
|
|
2660
|
-
this.setAttribute("aria-modal", "true");
|
|
2661
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Side sheet");
|
|
2662
|
-
const side = this.getAttribute("side") || "end";
|
|
2663
|
-
this.classList.add("c-side-sheet--" + side);
|
|
2664
|
-
if (this.hasAttribute("open")) this.classList.add("is-open"); else this.classList.remove("is-open");
|
|
2665
|
-
const title = this.getAttribute("title");
|
|
2666
|
-
if (title) {
|
|
2667
|
-
const t = this.ensure(".c-side-sheet__title", () => { const el = document.createElement("div"); el.className = "c-side-sheet__title"; return el; });
|
|
2668
|
-
t.textContent = title;
|
|
2669
|
-
}
|
|
2670
|
-
}
|
|
2671
|
-
enhance() {
|
|
2672
|
-
if (this._wiredSideSheet) return;
|
|
2673
|
-
this._wiredSideSheet = true;
|
|
2674
|
-
let lastFocus = null;
|
|
2675
|
-
const close = () => this.removeAttribute("open");
|
|
2676
|
-
const keyHandler = (e) => {
|
|
2677
|
-
if (e.key === "Escape" && this.hasAttribute("open")) { e.preventDefault(); close(); return; }
|
|
2678
|
-
if (e.key === "Tab" && this.hasAttribute("open")) {
|
|
2679
|
-
const focusables = Array.from(this.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")).filter((el) => !el.hasAttribute("disabled"));
|
|
2680
|
-
if (!focusables.length) { e.preventDefault(); return; }
|
|
2681
|
-
const first = focusables[0], last = focusables[focusables.length - 1];
|
|
2682
|
-
if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
|
|
2683
|
-
else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
|
|
2684
|
-
}
|
|
2685
|
-
};
|
|
2686
|
-
document.addEventListener("keydown", keyHandler);
|
|
2687
|
-
onDispose(this, () => document.removeEventListener("keydown", keyHandler));
|
|
2688
|
-
this.addEventListener("click", (e) => {
|
|
2689
|
-
if (e.target === this) close();
|
|
2690
|
-
});
|
|
2691
|
-
// Focus management: capture focus on open, restore on close.
|
|
2692
|
-
const obs = new MutationObserver(() => {
|
|
2693
|
-
if (this.hasAttribute("open")) {
|
|
2694
|
-
lastFocus = document.activeElement;
|
|
2695
|
-
const first = this.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
2696
|
-
if (first) try { first.focus(); } catch (err) {}
|
|
2697
|
-
} else if (lastFocus) {
|
|
2698
|
-
try { lastFocus.focus(); } catch (err) {}
|
|
2699
|
-
lastFocus = null;
|
|
2700
|
-
}
|
|
2701
|
-
});
|
|
2702
|
-
obs.observe(this, { attributes: true, attributeFilter: ["open"] });
|
|
2703
|
-
onDispose(this, () => obs.disconnect());
|
|
2704
|
-
}
|
|
2705
|
-
}
|
|
2706
|
-
define("contour-side-sheet", ContourSideSheet);
|
|
2707
|
-
|
|
2708
|
-
/**
|
|
2709
|
-
* Tour: web component wrapper.
|
|
2710
|
-
* Attributes: `steps`, `current`.
|
|
2711
|
-
*/
|
|
2712
|
-
class ContourTour extends ContourBase {
|
|
2713
|
-
static get observed() { return ["steps", "current"]; }
|
|
2714
|
-
static get properties() { return { steps: { attribute: "steps" }, current: { attribute: "current" } }; }
|
|
2715
|
-
render() {
|
|
2716
|
-
this.classList.add("c-tour");
|
|
2717
|
-
this.setAttribute("role", "dialog");
|
|
2718
|
-
this.setAttribute("aria-modal", "true");
|
|
2719
|
-
this.setAttribute("aria-label", "Tour");
|
|
2720
|
-
const steps = this.getAttribute("steps");
|
|
2721
|
-
const current = Number(this.getAttribute("current") || 0);
|
|
2722
|
-
let parsed = [];
|
|
2723
|
-
try { parsed = steps ? JSON.parse(steps) : []; } catch (e) { parsed = []; }
|
|
2724
|
-
const step = parsed[current] || {};
|
|
2725
|
-
const tip = this.ensure(".c-tour__tip", () => { const el = document.createElement("div"); el.className = "c-tour__tip"; return el; });
|
|
2726
|
-
tip.textContent = typeof step === "string" ? step : (step.text || step.title || "");
|
|
2727
|
-
const nav = this.ensure(".c-tour__nav", () => { const el = document.createElement("div"); el.className = "c-tour__nav c-btn-group"; return el; });
|
|
2728
|
-
const next = this.ensure(".c-tour__next", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-tour__next"; el.type = "button"; el.textContent = "Next"; return el; });
|
|
2729
|
-
if (!nav.contains(next)) nav.appendChild(next);
|
|
2730
|
-
}
|
|
2731
|
-
enhance() {
|
|
2732
|
-
if (this._wiredTour) return;
|
|
2733
|
-
this._wiredTour = true;
|
|
2734
|
-
const nextBtn = this.querySelector(".c-tour__next");
|
|
2735
|
-
if (nextBtn) try { nextBtn.focus(); } catch (err) {}
|
|
2736
|
-
this.addEventListener("click", (e) => {
|
|
2737
|
-
const next = e.target && e.target.closest ? e.target.closest(".c-tour__next") : null;
|
|
2738
|
-
if (next && this.contains(next)) this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { direction: "next" } }));
|
|
2739
|
-
});
|
|
2740
|
-
const keyHandler = (e) => { if (e.key === "Escape") this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); };
|
|
2741
|
-
document.addEventListener("keydown", keyHandler);
|
|
2742
|
-
onDispose(this, () => document.removeEventListener("keydown", keyHandler));
|
|
2743
|
-
}
|
|
2744
|
-
}
|
|
2745
|
-
define("contour-tour", ContourTour);
|
|
2746
|
-
|
|
2747
|
-
/**
|
|
2748
|
-
* Tags Input: web component wrapper.
|
|
2749
|
-
* Attributes: `value`, `placeholder`, `disabled`, `error`, `help`.
|
|
2750
|
-
*/
|
|
2751
|
-
class ContourTagsInput extends ContourBase {
|
|
2752
|
-
static get observed() { return ["value", "placeholder", "disabled", "error", "help"]; }
|
|
2753
|
-
static get properties() { return { value: { attribute: "value" }, placeholder: { attribute: "placeholder" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
2754
|
-
render() {
|
|
2755
|
-
this.classList.add("c-tags-input");
|
|
2756
|
-
const input = this.ensure(".c-tags-input__input", () => { const el = document.createElement("input"); el.className = "c-input c-tags-input__input"; el.type = "text"; el.setAttribute("aria-label", "Add tag"); return el; });
|
|
2757
|
-
input.placeholder = this.getAttribute("placeholder") || "Add tag…";
|
|
2758
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
2759
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
2760
|
-
const err = this.getAttribute("error");
|
|
2761
|
-
const help = this.getAttribute("help");
|
|
2762
|
-
let msg = this.querySelector(".c-tags-input__message");
|
|
2763
|
-
if (err || help) {
|
|
2764
|
-
if (!msg) { msg = document.createElement("div"); msg.className = "c-tags-input__message"; this.appendChild(msg); }
|
|
2765
|
-
msg.textContent = err || help || "";
|
|
2766
|
-
msg.classList.toggle("c-tags-input__message--error", !!err);
|
|
2767
|
-
} else if (msg) { msg.remove(); }
|
|
2768
|
-
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
2769
|
-
const tags = this.getAttribute("value");
|
|
2770
|
-
let parsed = [];
|
|
2771
|
-
try { parsed = tags ? JSON.parse(tags) : []; } catch (e) { parsed = tags ? tags.split(",").map((s) => s.trim()).filter(Boolean) : []; }
|
|
2772
|
-
Array.from(this.querySelectorAll(".c-tags-input__tag")).forEach((n) => n.remove());
|
|
2773
|
-
parsed.forEach((t) => {
|
|
2774
|
-
const chip = document.createElement("span");
|
|
2775
|
-
chip.className = "c-tag c-tags-input__tag";
|
|
2776
|
-
chip.textContent = t;
|
|
2777
|
-
const rm = document.createElement("button");
|
|
2778
|
-
rm.className = "c-tags-input__remove";
|
|
2779
|
-
rm.type = "button";
|
|
2780
|
-
rm.textContent = "×";
|
|
2781
|
-
rm.dataset.value = t;
|
|
2782
|
-
chip.appendChild(rm);
|
|
2783
|
-
this.insertBefore(chip, input);
|
|
2784
|
-
});
|
|
2785
|
-
}
|
|
2786
|
-
enhance() {
|
|
2787
|
-
if (this._wiredTagsInput) return;
|
|
2788
|
-
this._wiredTagsInput = true;
|
|
2789
|
-
let live = this.querySelector(".c-tags-input__live");
|
|
2790
|
-
if (!live) { live = document.createElement("span"); live.className = "c-tags-input__live visually-hidden"; live.setAttribute("aria-live", "polite"); live.setAttribute("aria-atomic", "true"); this.appendChild(live); }
|
|
2791
|
-
const announce = (msg) => { if (live) live.textContent = msg; };
|
|
2792
|
-
this.addEventListener("keydown", (e) => {
|
|
2793
|
-
const input = this.querySelector(".c-tags-input__input");
|
|
2794
|
-
if (!input) return;
|
|
2795
|
-
if (e.key === "Enter" && e.target === input) {
|
|
2796
|
-
e.preventDefault();
|
|
2797
|
-
const v = input.value.trim();
|
|
2798
|
-
if (v) {
|
|
2799
|
-
let tags = [];
|
|
2800
|
-
try { tags = JSON.parse(this.getAttribute("value") || "[]"); } catch (err) { tags = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean); }
|
|
2801
|
-
if (!Array.isArray(tags)) tags = [];
|
|
2802
|
-
if (!tags.includes(v)) tags.push(v);
|
|
2803
|
-
this.setAttribute("value", JSON.stringify(tags));
|
|
2804
|
-
input.value = "";
|
|
2805
|
-
announce("Added " + v);
|
|
2806
|
-
this.dispatchEvent(new CustomEvent("contour:add", { bubbles: true, composed: true, detail: { value: v } }));
|
|
2807
|
-
}
|
|
2808
|
-
} else if (e.key === "Backspace" && e.target === input && input.value === "") {
|
|
2809
|
-
let tags = [];
|
|
2810
|
-
try { tags = JSON.parse(this.getAttribute("value") || "[]"); } catch (err) { tags = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean); }
|
|
2811
|
-
if (!Array.isArray(tags)) tags = [];
|
|
2812
|
-
if (tags.length) {
|
|
2813
|
-
const removed = tags.pop();
|
|
2814
|
-
this.setAttribute("value", JSON.stringify(tags));
|
|
2815
|
-
announce("Removed " + removed);
|
|
2816
|
-
this.dispatchEvent(new CustomEvent("contour:remove", { bubbles: true, composed: true, detail: { value: removed } }));
|
|
2817
|
-
}
|
|
2818
|
-
}
|
|
2819
|
-
});
|
|
2820
|
-
this.addEventListener("click", (e) => {
|
|
2821
|
-
const rm = e.target && e.target.closest ? e.target.closest(".c-tags-input__remove") : null;
|
|
2822
|
-
if (rm && this.contains(rm)) {
|
|
2823
|
-
const val = rm.dataset.value;
|
|
2824
|
-
let tags = [];
|
|
2825
|
-
try { tags = JSON.parse(this.getAttribute("value") || "[]"); } catch (err) { tags = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean); }
|
|
2826
|
-
if (!Array.isArray(tags)) tags = [];
|
|
2827
|
-
const next = tags.filter((t) => t !== val);
|
|
2828
|
-
this.setAttribute("value", JSON.stringify(next));
|
|
2829
|
-
announce("Removed " + val);
|
|
2830
|
-
this.dispatchEvent(new CustomEvent("contour:remove", { bubbles: true, composed: true, detail: { value: val } }));
|
|
2831
|
-
}
|
|
2832
|
-
});
|
|
2833
|
-
}
|
|
2834
|
-
}
|
|
2835
|
-
define("contour-tags-input", ContourTagsInput);
|
|
2836
|
-
|
|
2837
|
-
/**
|
|
2838
|
-
* Sortable List: web component wrapper.
|
|
2839
|
-
* Attributes: `items`.
|
|
2840
|
-
*/
|
|
2841
|
-
class ContourSortableList extends ContourBase {
|
|
2842
|
-
static get updateMode() { return "keyed"; }
|
|
2843
|
-
static get observed() { return ["items"]; }
|
|
2844
|
-
static get properties() { return { items: { attribute: "items" } }; }
|
|
2845
|
-
render() {
|
|
2846
|
-
this.classList.add("c-sortable-list");
|
|
2847
|
-
const list = this.ensure(".c-sortable-list__list", () => { const el = document.createElement("ul"); el.className = "c-sortable-list__list"; return el; });
|
|
2848
|
-
const items = this.getAttribute("items");
|
|
2849
|
-
let parsed = [];
|
|
2850
|
-
try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
|
|
2851
|
-
list.innerHTML = "";
|
|
2852
|
-
parsed.forEach((it, i) => {
|
|
2853
|
-
const li = document.createElement("li");
|
|
2854
|
-
li.className = "c-sortable-list__item";
|
|
2855
|
-
li.setAttribute("draggable", "true");
|
|
2856
|
-
li.dataset.index = String(i);
|
|
2857
|
-
const handle = document.createElement("span");
|
|
2858
|
-
handle.className = "c-sortable-list__handle";
|
|
2859
|
-
handle.textContent = "⋮⋮";
|
|
2860
|
-
handle.setAttribute("role", "button");
|
|
2861
|
-
handle.tabIndex = 0;
|
|
2862
|
-
li.appendChild(handle);
|
|
2863
|
-
const label = document.createElement("span");
|
|
2864
|
-
label.className = "c-sortable-list__label";
|
|
2865
|
-
label.textContent = typeof it === "string" ? it : (it.label || it.text || "");
|
|
2866
|
-
li.appendChild(label);
|
|
2867
|
-
list.appendChild(li);
|
|
2868
|
-
});
|
|
2869
|
-
}
|
|
2870
|
-
enhance() {
|
|
2871
|
-
if (this._wiredSortableList) return;
|
|
2872
|
-
this._wiredSortableList = true;
|
|
2873
|
-
const list = () => this.querySelector(".c-sortable-list__list");
|
|
2874
|
-
// Live region for position announcements.
|
|
2875
|
-
let live = this.querySelector(".c-sortable-list__live");
|
|
2876
|
-
if (!live) { live = document.createElement("span"); live.className = "c-sortable-list__live visually-hidden"; live.setAttribute("aria-live", "polite"); live.setAttribute("aria-atomic", "true"); this.appendChild(live); }
|
|
2877
|
-
const announce = (msg) => { if (live) live.textContent = msg; };
|
|
2878
|
-
const index = (li) => Array.from(list().children).indexOf(li);
|
|
2879
|
-
// Pointer drag reorder.
|
|
2880
|
-
let dragFrom = null;
|
|
2881
|
-
this.addEventListener("dragstart", (e) => {
|
|
2882
|
-
const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
|
|
2883
|
-
if (!li || !this.contains(li)) return;
|
|
2884
|
-
dragFrom = index(li);
|
|
2885
|
-
if (e.dataTransfer) { e.dataTransfer.effectAllowed = "move"; try { e.dataTransfer.setData("text/plain", String(dragFrom)); } catch (err) {} }
|
|
2886
|
-
li.classList.add("is-dragging");
|
|
2887
|
-
});
|
|
2888
|
-
this.addEventListener("dragover", (e) => {
|
|
2889
|
-
const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
|
|
2890
|
-
if (!li || !this.contains(li) || dragFrom === null) return;
|
|
2891
|
-
e.preventDefault();
|
|
2892
|
-
if (e.dataTransfer) e.dataTransfer.dropEffect = "move";
|
|
2893
|
-
});
|
|
2894
|
-
this.addEventListener("drop", (e) => {
|
|
2895
|
-
const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
|
|
2896
|
-
if (!li || !this.contains(li) || dragFrom === null) return;
|
|
2897
|
-
e.preventDefault();
|
|
2898
|
-
const to = index(li);
|
|
2899
|
-
const l = list();
|
|
2900
|
-
const fromLi = l.children[dragFrom];
|
|
2901
|
-
if (fromLi && dragFrom !== to) {
|
|
2902
|
-
if (dragFrom < to) l.insertBefore(fromLi, l.children[to + 1] || null);
|
|
2903
|
-
else l.insertBefore(fromLi, l.children[to]);
|
|
2904
|
-
const item = fromLi.querySelector(".c-sortable-list__label");
|
|
2905
|
-
announce((item ? item.textContent : "Item") + " moved to position " + (to + 1));
|
|
2906
|
-
this.dispatchEvent(new CustomEvent("contour:reorder", { bubbles: true, composed: true, detail: { from: dragFrom, to } }));
|
|
2907
|
-
}
|
|
2908
|
-
dragFrom = null;
|
|
2909
|
-
Array.from(l.children).forEach((n) => n.classList.remove("is-dragging"));
|
|
2910
|
-
});
|
|
2911
|
-
this.addEventListener("dragend", () => {
|
|
2912
|
-
dragFrom = null;
|
|
2913
|
-
const l = list();
|
|
2914
|
-
if (l) Array.from(l.children).forEach((n) => n.classList.remove("is-dragging"));
|
|
2915
|
-
});
|
|
2916
|
-
// Keyboard reorder.
|
|
2917
|
-
this.addEventListener("keydown", (e) => {
|
|
2918
|
-
const handle = e.target && e.target.closest ? e.target.closest(".c-sortable-list__handle") : null;
|
|
2919
|
-
if (!handle) return;
|
|
2920
|
-
const li = handle.closest(".c-sortable-list__item");
|
|
2921
|
-
if (!li) return;
|
|
2922
|
-
const l = list();
|
|
2923
|
-
const from = index(li);
|
|
2924
|
-
if (e.key === "ArrowUp" && li.previousElementSibling) {
|
|
2925
|
-
e.preventDefault();
|
|
2926
|
-
l.insertBefore(li, li.previousElementSibling);
|
|
2927
|
-
const to = index(li);
|
|
2928
|
-
const label = li.querySelector(".c-sortable-list__label");
|
|
2929
|
-
announce((label ? label.textContent : "Item") + " moved to position " + (to + 1));
|
|
2930
|
-
this.dispatchEvent(new CustomEvent("contour:move", { bubbles: true, composed: true, detail: { direction: "up", from, to } }));
|
|
2931
|
-
this.dispatchEvent(new CustomEvent("contour:reorder", { bubbles: true, composed: true, detail: { from, to } }));
|
|
2932
|
-
}
|
|
2933
|
-
if (e.key === "ArrowDown" && li.nextElementSibling) {
|
|
2934
|
-
e.preventDefault();
|
|
2935
|
-
l.insertBefore(li.nextElementSibling, li);
|
|
2936
|
-
const to = index(li);
|
|
2937
|
-
const label = li.querySelector(".c-sortable-list__label");
|
|
2938
|
-
announce((label ? label.textContent : "Item") + " moved to position " + (to + 1));
|
|
2939
|
-
this.dispatchEvent(new CustomEvent("contour:move", { bubbles: true, composed: true, detail: { direction: "down", from, to } }));
|
|
2940
|
-
this.dispatchEvent(new CustomEvent("contour:reorder", { bubbles: true, composed: true, detail: { from, to } }));
|
|
2941
|
-
}
|
|
2942
|
-
});
|
|
2943
|
-
}
|
|
2944
|
-
}
|
|
2945
|
-
define("contour-sortable-list", ContourSortableList);
|
|
2946
|
-
|
|
2947
|
-
/**
|
|
2948
|
-
* Swatch: web component wrapper.
|
|
2949
|
-
* Attributes: `color`, `selected`, `label`.
|
|
2950
|
-
*/
|
|
2951
|
-
class ContourSwatch extends ContourBase {
|
|
2952
|
-
static get observed() { return ["color", "selected", "label"]; }
|
|
2953
|
-
static get properties() { return { color: { attribute: "color" }, selected: { attribute: "selected", type: Boolean }, label: { attribute: "label" } }; }
|
|
2954
|
-
render() {
|
|
2955
|
-
this.classList.add("c-swatch");
|
|
2956
|
-
const color = this.getAttribute("color") || "#000";
|
|
2957
|
-
this.style.setProperty("--swatch-color", color);
|
|
2958
|
-
if (this.hasAttribute("selected")) this.classList.add("is-selected");
|
|
2959
|
-
else this.classList.remove("is-selected");
|
|
2960
|
-
if (!this.hasAttribute("aria-label")) {
|
|
2961
|
-
const label = this.getAttribute("label") || color;
|
|
2962
|
-
this.setAttribute("aria-label", label);
|
|
2963
|
-
}
|
|
2964
|
-
if (!this.querySelector("button") && !this.querySelector("span")) {
|
|
2965
|
-
const btn = document.createElement("button");
|
|
2966
|
-
btn.className = "c-swatch__btn";
|
|
2967
|
-
btn.type = "button";
|
|
2968
|
-
this.appendChild(btn);
|
|
2969
|
-
}
|
|
2970
|
-
}
|
|
2971
|
-
enhance() {
|
|
2972
|
-
if (this._wiredSwatch) return;
|
|
2973
|
-
this._wiredSwatch = true;
|
|
2974
|
-
this.addEventListener("click", () => {
|
|
2975
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { value: this.getAttribute("color") } }));
|
|
2976
|
-
});
|
|
2977
|
-
}
|
|
2978
|
-
}
|
|
2979
|
-
define("contour-swatch", ContourSwatch);
|
|
2980
|
-
|
|
2981
|
-
/**
|
|
2982
|
-
* Calendar: web component wrapper.
|
|
2983
|
-
* Attributes: `value`.
|
|
2984
|
-
*/
|
|
2985
|
-
class ContourCalendar extends ContourBase {
|
|
2986
|
-
static get observed() { return ["value"]; }
|
|
2987
|
-
static get properties() { return { value: { attribute: "value" }, month: { attribute: "month" }, year: { attribute: "year" } }; }
|
|
2988
|
-
render() {
|
|
2989
|
-
this.classList.add("c-calendar");
|
|
2990
|
-
const now = new Date();
|
|
2991
|
-
const year = Number(this.getAttribute("year")) || now.getFullYear();
|
|
2992
|
-
const month = Number(this.getAttribute("month")) || now.getMonth();
|
|
2993
|
-
const header = this.ensure(".c-calendar__header", () => { const el = document.createElement("div"); el.className = "c-calendar__header"; return el; });
|
|
2994
|
-
header.innerHTML = "";
|
|
2995
|
-
const prev = document.createElement("button");
|
|
2996
|
-
prev.type = "button"; prev.className = "c-btn c-btn--sm c-calendar__prev"; prev.textContent = "‹"; prev.setAttribute("aria-label", "Previous month");
|
|
2997
|
-
const title = document.createElement("span");
|
|
2998
|
-
title.className = "c-calendar__title";
|
|
2999
|
-
title.textContent = new Date(year, month, 1).toLocaleString(undefined, { month: "long", year: "numeric" });
|
|
3000
|
-
const next = document.createElement("button");
|
|
3001
|
-
next.type = "button"; next.className = "c-btn c-btn--sm c-calendar__next"; next.textContent = "›"; next.setAttribute("aria-label", "Next month");
|
|
3002
|
-
header.appendChild(prev); header.appendChild(title); header.appendChild(next);
|
|
3003
|
-
const grid = this.ensure(".c-calendar__grid", () => { const el = document.createElement("div"); el.className = "c-calendar__grid"; el.setAttribute("role", "grid"); return el; });
|
|
3004
|
-
grid.setAttribute("aria-label", title.textContent);
|
|
3005
|
-
grid.innerHTML = "";
|
|
3006
|
-
const first = new Date(year, month, 1);
|
|
3007
|
-
const startDay = first.getDay();
|
|
3008
|
-
const daysInMonth = new Date(year, month + 1, 0).getDate();
|
|
3009
|
-
const selected = this.getAttribute("value");
|
|
3010
|
-
for (let i = 0; i < startDay; i++) {
|
|
3011
|
-
const empty = document.createElement("div");
|
|
3012
|
-
empty.className = "c-calendar__day c-calendar__day--empty";
|
|
3013
|
-
grid.appendChild(empty);
|
|
3014
|
-
}
|
|
3015
|
-
for (let d = 1; d <= daysInMonth; d++) {
|
|
3016
|
-
const cell = document.createElement("button");
|
|
3017
|
-
cell.className = "c-calendar__day";
|
|
3018
|
-
cell.type = "button";
|
|
3019
|
-
cell.setAttribute("role", "gridcell");
|
|
3020
|
-
cell.setAttribute("tabindex", "0");
|
|
3021
|
-
cell.textContent = String(d);
|
|
3022
|
-
const iso = year + "-" + String(month + 1).padStart(2, "0") + "-" + String(d).padStart(2, "0");
|
|
3023
|
-
if (iso === selected) { cell.classList.add("is-selected"); cell.setAttribute("aria-selected", "true"); }
|
|
3024
|
-
else cell.setAttribute("aria-selected", "false");
|
|
3025
|
-
const todayIso = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0") + "-" + String(now.getDate()).padStart(2, "0");
|
|
3026
|
-
if (iso === todayIso) cell.setAttribute("aria-current", "date");
|
|
3027
|
-
cell.dataset.value = iso;
|
|
3028
|
-
grid.appendChild(cell);
|
|
3029
|
-
}
|
|
3030
|
-
if (header.parentNode !== this) this.insertBefore(header, grid);
|
|
3031
|
-
}
|
|
3032
|
-
enhance() {
|
|
3033
|
-
if (this._wiredCalendar) return;
|
|
3034
|
-
this._wiredCalendar = true;
|
|
3035
|
-
this.addEventListener("click", (e) => {
|
|
3036
|
-
const prev = e.target && e.target.closest ? e.target.closest(".c-calendar__prev") : null;
|
|
3037
|
-
const next = e.target && e.target.closest ? e.target.closest(".c-calendar__next") : null;
|
|
3038
|
-
if (prev && this.contains(prev)) {
|
|
3039
|
-
let m = Number(this.getAttribute("month")) || new Date().getMonth();
|
|
3040
|
-
let y = Number(this.getAttribute("year")) || new Date().getFullYear();
|
|
3041
|
-
m -= 1;
|
|
3042
|
-
if (m < 0) { m = 11; y -= 1; }
|
|
3043
|
-
this.setAttribute("month", String(m));
|
|
3044
|
-
this.setAttribute("year", String(y));
|
|
3045
|
-
this.render();
|
|
3046
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { month: m, year: y } }));
|
|
3047
|
-
return;
|
|
3048
|
-
}
|
|
3049
|
-
if (next && this.contains(next)) {
|
|
3050
|
-
let m = Number(this.getAttribute("month")) || new Date().getMonth();
|
|
3051
|
-
let y = Number(this.getAttribute("year")) || new Date().getFullYear();
|
|
3052
|
-
m += 1;
|
|
3053
|
-
if (m > 11) { m = 0; y += 1; }
|
|
3054
|
-
this.setAttribute("month", String(m));
|
|
3055
|
-
this.setAttribute("year", String(y));
|
|
3056
|
-
this.render();
|
|
3057
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { month: m, year: y } }));
|
|
3058
|
-
return;
|
|
3059
|
-
}
|
|
3060
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-calendar__day") : null;
|
|
3061
|
-
if (cell && this.contains(cell) && cell.dataset.value) {
|
|
3062
|
-
this.setAttribute("value", cell.dataset.value);
|
|
3063
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { value: cell.dataset.value } }));
|
|
3064
|
-
}
|
|
3065
|
-
});
|
|
3066
|
-
this.addEventListener("keydown", (e) => {
|
|
3067
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-calendar__day") : null;
|
|
3068
|
-
if (!cell || !this.contains(cell)) return;
|
|
3069
|
-
const cells = Array.from(this.querySelectorAll(".c-calendar__day:not(.c-calendar__day--empty)"));
|
|
3070
|
-
const idx = cells.indexOf(cell);
|
|
3071
|
-
let next = null;
|
|
3072
|
-
if (e.key === "ArrowRight") next = cells[idx + 1];
|
|
3073
|
-
else if (e.key === "ArrowLeft") next = cells[idx - 1];
|
|
3074
|
-
else if (e.key === "ArrowDown") next = cells[idx + 7];
|
|
3075
|
-
else if (e.key === "ArrowUp") next = cells[idx - 7];
|
|
3076
|
-
else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); cell.click(); return; }
|
|
3077
|
-
if (next) { e.preventDefault(); try { next.focus(); } catch (err) {} }
|
|
3078
|
-
});
|
|
3079
|
-
}
|
|
3080
|
-
}
|
|
3081
|
-
define("contour-calendar", ContourCalendar);
|
|
3082
|
-
|
|
3083
|
-
/**
|
|
3084
|
-
* Carousel: web component wrapper.
|
|
3085
|
-
* Attributes: `items`, `index`.
|
|
3086
|
-
*/
|
|
3087
|
-
class ContourCarousel extends ContourBase {
|
|
3088
|
-
static get observed() { return ["items", "index"]; }
|
|
3089
|
-
static get properties() { return { items: { attribute: "items" }, index: { attribute: "index" } }; }
|
|
3090
|
-
_items() {
|
|
3091
|
-
const items = this.getAttribute("items");
|
|
3092
|
-
let parsed = [];
|
|
3093
|
-
try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
|
|
3094
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
3095
|
-
}
|
|
3096
|
-
_index() {
|
|
3097
|
-
const i = Number(this.getAttribute("index"));
|
|
3098
|
-
const items = this._items();
|
|
3099
|
-
if (Number.isFinite(i) && i >= 0 && i < items.length) return i;
|
|
3100
|
-
return 0;
|
|
3101
|
-
}
|
|
3102
|
-
render() {
|
|
3103
|
-
this.classList.add("c-carousel");
|
|
3104
|
-
this.setAttribute("role", "region");
|
|
3105
|
-
this.setAttribute("aria-roledescription", "carousel");
|
|
3106
|
-
const track = this.ensure(".c-carousel__track", () => { const el = document.createElement("div"); el.className = "c-carousel__track"; el.setAttribute("role", "group"); el.setAttribute("aria-roledescription", "slide container"); return el; });
|
|
3107
|
-
const items = this._items();
|
|
3108
|
-
track.innerHTML = "";
|
|
3109
|
-
const idx = this._index();
|
|
3110
|
-
items.forEach((it, i) => {
|
|
3111
|
-
const slide = document.createElement("div");
|
|
3112
|
-
slide.className = "c-carousel__slide" + (i === idx ? " is-active" : "");
|
|
3113
|
-
slide.setAttribute("role", "group");
|
|
3114
|
-
slide.setAttribute("aria-roledescription", "slide");
|
|
3115
|
-
slide.setAttribute("aria-label", (i + 1) + " of " + items.length);
|
|
3116
|
-
slide.setAttribute("aria-hidden", i === idx ? "false" : "true");
|
|
3117
|
-
slide.textContent = typeof it === "string" ? it : (it.label || it.text || "");
|
|
3118
|
-
slide.dataset.index = String(i);
|
|
3119
|
-
track.appendChild(slide);
|
|
3120
|
-
});
|
|
3121
|
-
const prev = this.ensure(".c-carousel__prev", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-carousel__prev"; el.type = "button"; el.textContent = "‹"; el.setAttribute("aria-label", "Previous slide"); return el; });
|
|
3122
|
-
const next = this.ensure(".c-carousel__next", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-carousel__next"; el.type = "button"; el.textContent = "›"; el.setAttribute("aria-label", "Next slide"); return el; });
|
|
3123
|
-
const status = this.ensure(".c-carousel__status", () => { const el = document.createElement("span"); el.className = "c-carousel__status"; el.setAttribute("aria-live", "polite"); return el; });
|
|
3124
|
-
status.textContent = (idx + 1) + " of " + items.length;
|
|
3125
|
-
}
|
|
3126
|
-
enhance() {
|
|
3127
|
-
if (this._wiredCarousel) return;
|
|
3128
|
-
this._wiredCarousel = true;
|
|
3129
|
-
const go = (dir) => {
|
|
3130
|
-
const items = this._items();
|
|
3131
|
-
if (!items.length) return;
|
|
3132
|
-
let idx = this._index();
|
|
3133
|
-
if (dir === "prev") idx = (idx - 1 + items.length) % items.length;
|
|
3134
|
-
else idx = (idx + 1) % items.length;
|
|
3135
|
-
this.setAttribute("index", String(idx));
|
|
3136
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: idx, direction: dir } }));
|
|
3137
|
-
};
|
|
3138
|
-
this.addEventListener("click", (e) => {
|
|
3139
|
-
const prev = e.target && e.target.closest ? e.target.closest(".c-carousel__prev") : null;
|
|
3140
|
-
const next = e.target && e.target.closest ? e.target.closest(".c-carousel__next") : null;
|
|
3141
|
-
if (prev && this.contains(prev)) go("prev");
|
|
3142
|
-
if (next && this.contains(next)) go("next");
|
|
3143
|
-
});
|
|
3144
|
-
this.addEventListener("keydown", (e) => {
|
|
3145
|
-
if (e.key === "ArrowLeft") { e.preventDefault(); go("prev"); }
|
|
3146
|
-
else if (e.key === "ArrowRight") { e.preventDefault(); go("next"); }
|
|
3147
|
-
else if (e.key === "Home") { e.preventDefault(); this.setAttribute("index", "0"); this.render(); this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: 0, direction: "home" } })); }
|
|
3148
|
-
else if (e.key === "End") { e.preventDefault(); const last = this._items().length - 1; if (last >= 0) { this.setAttribute("index", String(last)); this.render(); this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: last, direction: "end" } })); } }
|
|
3149
|
-
});
|
|
3150
|
-
}
|
|
3151
|
-
}
|
|
3152
|
-
define("contour-carousel", ContourCarousel);
|
|
3153
|
-
|
|
3154
|
-
/**
|
|
3155
|
-
* Data Grid: web component wrapper.
|
|
3156
|
-
* Attributes: `columns`, `rows`, `page`, `filter`, `page-size`, `resizable`.
|
|
3157
|
-
*/
|
|
3158
|
-
class ContourDataGrid extends ContourBase {
|
|
3159
|
-
static get updateMode() { return "keyed"; }
|
|
3160
|
-
static get observed() { return ["columns", "rows", "page", "filter", "page-size", "resizable", "virtual", "row-height"]; }
|
|
3161
|
-
static get properties() { return { columns: { attribute: "columns" }, rows: { attribute: "rows" }, page: { attribute: "page" }, filter: { attribute: "filter" }, "page-size": { attribute: "page-size" }, resizable: { attribute: "resizable", type: Boolean }, virtual: { attribute: "virtual", type: Boolean }, "row-height": { attribute: "row-height" } }; }
|
|
3162
|
-
render() {
|
|
3163
|
-
this.classList.add("c-data-grid");
|
|
3164
|
-
if (this.hasAttribute("loading") || this.hasAttribute("error") || this.hasAttribute("empty")) {
|
|
3165
|
-
const table = this.ensure(".c-data-grid__table", () => { const el = document.createElement("table"); el.className = "c-table c-data-grid__table"; el.setAttribute("role", "grid"); return el; });
|
|
3166
|
-
const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
|
|
3167
|
-
if (tbody.parentNode !== table) table.appendChild(tbody);
|
|
3168
|
-
tbody.innerHTML = "";
|
|
3169
|
-
const tr = document.createElement("tr");
|
|
3170
|
-
const td = document.createElement("td");
|
|
3171
|
-
td.colSpan = 1;
|
|
3172
|
-
td.style.textAlign = "center";
|
|
3173
|
-
td.style.color = "var(--color-text-muted)";
|
|
3174
|
-
if (this.hasAttribute("loading")) td.textContent = this.getAttribute("loading") || "Loading…";
|
|
3175
|
-
else if (this.hasAttribute("error")) td.textContent = this.getAttribute("error") || "Error";
|
|
3176
|
-
else td.textContent = this.getAttribute("empty") || "No data";
|
|
3177
|
-
tr.appendChild(td);
|
|
3178
|
-
tbody.appendChild(tr);
|
|
3179
|
-
// Wrap in a scroll container for virtualization of large datasets.
|
|
3180
|
-
let wrap = this.querySelector(".c-data-grid__wrap");
|
|
3181
|
-
if (!wrap) { wrap = document.createElement("div"); wrap.className = "c-data-grid__wrap"; wrap.style.maxHeight = "400px"; wrap.style.overflow = "auto"; }
|
|
3182
|
-
if (table.parentNode !== wrap) wrap.appendChild(table);
|
|
3183
|
-
if (wrap.parentNode !== this) this.appendChild(wrap);
|
|
3184
|
-
return;
|
|
3185
|
-
}
|
|
3186
|
-
const table = this.ensure(".c-data-grid__table", () => { const el = document.createElement("table"); el.className = "c-table c-data-grid__table"; el.setAttribute("role", "grid"); return el; });
|
|
3187
|
-
const thead = this.ensure("thead", () => { const el = document.createElement("thead"); return el; });
|
|
3188
|
-
const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
|
|
3189
|
-
if (thead.parentNode !== table) table.appendChild(thead);
|
|
3190
|
-
if (tbody.parentNode !== table) table.appendChild(tbody);
|
|
3191
|
-
const cols = this.getAttribute("columns");
|
|
3192
|
-
let parsedCols = [];
|
|
3193
|
-
try { parsedCols = cols ? JSON.parse(cols) : []; } catch (e) { parsedCols = []; }
|
|
3194
|
-
if (parsedCols.length && !thead.querySelector("tr")) {
|
|
3195
|
-
const tr = document.createElement("tr");
|
|
3196
|
-
parsedCols.forEach((c) => {
|
|
3197
|
-
const th = document.createElement("th");
|
|
3198
|
-
th.setAttribute("role", "columnheader");
|
|
3199
|
-
th.setAttribute("aria-sort", "none");
|
|
3200
|
-
th.setAttribute("tabindex", "0");
|
|
3201
|
-
th.textContent = typeof c === "string" ? c : (c.label || c.key || "");
|
|
3202
|
-
tr.appendChild(th);
|
|
3203
|
-
});
|
|
3204
|
-
thead.appendChild(tr);
|
|
3205
|
-
}
|
|
3206
|
-
if (this.hasAttribute("resizable")) {
|
|
3207
|
-
Array.from(thead.querySelectorAll("th")).forEach((th) => {
|
|
3208
|
-
th.style.position = "relative";
|
|
3209
|
-
th.setAttribute("data-resizable", "true");
|
|
3210
|
-
});
|
|
3211
|
-
}
|
|
3212
|
-
const rows = this.getAttribute("rows");
|
|
3213
|
-
let parsedRows = [];
|
|
3214
|
-
try { parsedRows = rows ? JSON.parse(rows) : []; } catch (e) { parsedRows = []; }
|
|
3215
|
-
table.setAttribute("aria-rowcount", String(parsedRows.length));
|
|
3216
|
-
table.setAttribute("aria-colcount", String(parsedCols.length));
|
|
3217
|
-
const filter = this.getAttribute("filter");
|
|
3218
|
-
if (filter) {
|
|
3219
|
-
const q = filter.toLowerCase();
|
|
3220
|
-
parsedRows = parsedRows.filter((r) => JSON.stringify(r).toLowerCase().includes(q));
|
|
3221
|
-
}
|
|
3222
|
-
const page = Number(this.getAttribute("page") || 1);
|
|
3223
|
-
const pageSize = Number(this.getAttribute("page-size") || 0);
|
|
3224
|
-
if (pageSize > 0) {
|
|
3225
|
-
const start = (page - 1) * pageSize;
|
|
3226
|
-
parsedRows = parsedRows.slice(start, start + pageSize);
|
|
3227
|
-
}
|
|
3228
|
-
this._dgCols = parsedCols;
|
|
3229
|
-
this._dgRows = parsedRows;
|
|
3230
|
-
this._dgFilteredRows = parsedRows;
|
|
3231
|
-
const virtual = this.hasAttribute("virtual") && !(Number(this.getAttribute("page-size")) > 0);
|
|
3232
|
-
if (virtual) {
|
|
3233
|
-
this._renderDataGridWindow(0);
|
|
3234
|
-
} else {
|
|
3235
|
-
tbody.innerHTML = "";
|
|
3236
|
-
parsedRows.forEach((r) => {
|
|
3237
|
-
const tr = document.createElement("tr");
|
|
3238
|
-
parsedCols.forEach((c) => {
|
|
3239
|
-
const key = typeof c === "string" ? c : (c.key || c.label || "");
|
|
3240
|
-
const td = document.createElement("td");
|
|
3241
|
-
td.setAttribute("role", "gridcell");
|
|
3242
|
-
td.setAttribute("tabindex", "0");
|
|
3243
|
-
td.textContent = r && r[key] != null ? r[key] : "";
|
|
3244
|
-
if (!String(td.textContent).trim()) td.setAttribute("aria-label", "Empty");
|
|
3245
|
-
tr.appendChild(td);
|
|
3246
|
-
});
|
|
3247
|
-
tbody.appendChild(tr);
|
|
3248
|
-
});
|
|
3249
|
-
}
|
|
3250
|
-
// Wrap in a scroll container for virtualization of large datasets.
|
|
3251
|
-
let wrap = this.querySelector(".c-data-grid__wrap");
|
|
3252
|
-
if (!wrap) { wrap = document.createElement("div"); wrap.className = "c-data-grid__wrap"; wrap.style.maxHeight = "400px"; wrap.style.overflow = "auto"; }
|
|
3253
|
-
if (table.parentNode !== wrap) wrap.appendChild(table);
|
|
3254
|
-
if (wrap.parentNode !== this) this.appendChild(wrap);
|
|
3255
|
-
}
|
|
3256
|
-
_rowHeight() {
|
|
3257
|
-
const h = Number(this.getAttribute("row-height"));
|
|
3258
|
-
return Number.isFinite(h) && h > 0 ? h : 32;
|
|
3259
|
-
}
|
|
3260
|
-
_renderDataGridWindow(scrollTop) {
|
|
3261
|
-
const table = this.querySelector(".c-data-grid__table");
|
|
3262
|
-
const tbody = table && table.querySelector("tbody");
|
|
3263
|
-
if (!tbody) return;
|
|
3264
|
-
const cols = this._dgCols || [];
|
|
3265
|
-
const rows = this._dgRows || [];
|
|
3266
|
-
const rh = this._rowHeight();
|
|
3267
|
-
const viewport = 400;
|
|
3268
|
-
const visibleCount = Math.ceil(viewport / rh) + 6;
|
|
3269
|
-
let start = Math.floor((scrollTop || 0) / rh);
|
|
3270
|
-
if (start < 0) start = 0;
|
|
3271
|
-
if (start > Math.max(0, rows.length - visibleCount)) start = Math.max(0, rows.length - visibleCount);
|
|
3272
|
-
const end = Math.min(rows.length, start + visibleCount);
|
|
3273
|
-
tbody.innerHTML = "";
|
|
3274
|
-
// top spacer
|
|
3275
|
-
if (start > 0) {
|
|
3276
|
-
const sp = document.createElement("tr");
|
|
3277
|
-
const td = document.createElement("td");
|
|
3278
|
-
td.colSpan = Math.max(1, cols.length);
|
|
3279
|
-
td.style.blockSize = (start * rh) + "px";
|
|
3280
|
-
td.style.padding = "0";
|
|
3281
|
-
sp.appendChild(td);
|
|
3282
|
-
tbody.appendChild(sp);
|
|
3283
|
-
}
|
|
3284
|
-
for (let i = start; i < end; i++) {
|
|
3285
|
-
const r = rows[i];
|
|
3286
|
-
const tr = document.createElement("tr");
|
|
3287
|
-
tr.dataset.index = String(i);
|
|
3288
|
-
cols.forEach((c) => {
|
|
3289
|
-
const key = typeof c === "string" ? c : (c.key || c.label || "");
|
|
3290
|
-
const td = document.createElement("td");
|
|
3291
|
-
td.setAttribute("role", "gridcell");
|
|
3292
|
-
td.setAttribute("tabindex", "0");
|
|
3293
|
-
td.textContent = r && r[key] != null ? r[key] : "";
|
|
3294
|
-
if (!String(td.textContent).trim()) td.setAttribute("aria-label", "Empty");
|
|
3295
|
-
tr.appendChild(td);
|
|
3296
|
-
});
|
|
3297
|
-
tbody.appendChild(tr);
|
|
3298
|
-
}
|
|
3299
|
-
if (end < rows.length) {
|
|
3300
|
-
const sp = document.createElement("tr");
|
|
3301
|
-
const td = document.createElement("td");
|
|
3302
|
-
td.colSpan = Math.max(1, cols.length);
|
|
3303
|
-
td.style.blockSize = ((rows.length - end) * rh) + "px";
|
|
3304
|
-
td.style.padding = "0";
|
|
3305
|
-
sp.appendChild(td);
|
|
3306
|
-
tbody.appendChild(sp);
|
|
3307
|
-
}
|
|
3308
|
-
}
|
|
3309
|
-
enhance() {
|
|
3310
|
-
if (this._wiredDataGrid) return;
|
|
3311
|
-
this._wiredDataGrid = true;
|
|
3312
|
-
const wrap = () => this.querySelector(".c-data-grid__wrap");
|
|
3313
|
-
const onScroll = () => {
|
|
3314
|
-
const w = wrap();
|
|
3315
|
-
if (w && this.hasAttribute("virtual")) this._renderDataGridWindow(w.scrollTop);
|
|
3316
|
-
};
|
|
3317
|
-
// attach after render creates wrap; use delegated listener on host
|
|
3318
|
-
this.addEventListener("scroll", (e) => {
|
|
3319
|
-
const w = e.target && e.target.classList && e.target.classList.contains("c-data-grid__wrap") ? e.target : null;
|
|
3320
|
-
if (w && this.hasAttribute("virtual")) this._renderDataGridWindow(w.scrollTop);
|
|
3321
|
-
}, true);
|
|
3322
|
-
let sortCol = -1, sortDir = "asc";
|
|
3323
|
-
this.addEventListener("keydown", (e) => {
|
|
3324
|
-
const cell = e.target && e.target.closest ? e.target.closest("[role='gridcell'], [role='columnheader']") : null;
|
|
3325
|
-
if (!cell || !this.contains(cell)) return;
|
|
3326
|
-
const row = cell.parentElement;
|
|
3327
|
-
const table = this.querySelector(".c-data-grid__table");
|
|
3328
|
-
if (!table) return;
|
|
3329
|
-
const rows = Array.from(table.querySelectorAll("tr"));
|
|
3330
|
-
const ri = rows.indexOf(row);
|
|
3331
|
-
const ci = Array.from(row.children).indexOf(cell);
|
|
3332
|
-
let target = null;
|
|
3333
|
-
if (e.key === "ArrowRight") target = row.children[ci + 1];
|
|
3334
|
-
else if (e.key === "ArrowLeft") target = row.children[ci - 1];
|
|
3335
|
-
else if (e.key === "ArrowDown") target = rows[ri + 1] && rows[ri + 1].children[ci];
|
|
3336
|
-
else if (e.key === "ArrowUp") target = rows[ri - 1] && rows[ri - 1].children[ci];
|
|
3337
|
-
if (target) { e.preventDefault(); try { target.focus(); } catch (err) {} }
|
|
3338
|
-
});
|
|
3339
|
-
this.addEventListener("click", (e) => {
|
|
3340
|
-
const tr = e.target && e.target.closest ? e.target.closest("tr") : null;
|
|
3341
|
-
const th = e.target && e.target.closest ? e.target.closest("th") : null;
|
|
3342
|
-
if (tr && this.contains(tr) && !th) {
|
|
3343
|
-
const idx = Array.from(tr.parentElement.children).indexOf(tr);
|
|
3344
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { row: idx } }));
|
|
3345
|
-
}
|
|
3346
|
-
if (th && this.contains(th)) {
|
|
3347
|
-
const idx = Array.from(th.parentElement.children).indexOf(th);
|
|
3348
|
-
if (sortCol === idx) sortDir = sortDir === "asc" ? "desc" : "asc";
|
|
3349
|
-
else { sortCol = idx; sortDir = "asc"; }
|
|
3350
|
-
// Re-render sorted rows.
|
|
3351
|
-
const table = this.querySelector(".c-data-grid__table");
|
|
3352
|
-
const tbody = table && table.querySelector("tbody");
|
|
3353
|
-
const thead = table && table.querySelector("thead");
|
|
3354
|
-
if (tbody && thead) {
|
|
3355
|
-
const cols = Array.from(thead.querySelectorAll("th")).map((h) => h.textContent);
|
|
3356
|
-
const rows = Array.from(tbody.querySelectorAll("tr")).map((tr) => Array.from(tr.querySelectorAll("td")).map((td) => td.textContent));
|
|
3357
|
-
rows.sort((a, b) => {
|
|
3358
|
-
const va = a[idx] || "", vb = b[idx] || "";
|
|
3359
|
-
const na = Number(va), nb = Number(vb);
|
|
3360
|
-
const cmp = (!isNaN(na) && !isNaN(nb)) ? na - nb : String(va).localeCompare(String(vb));
|
|
3361
|
-
return sortDir === "asc" ? cmp : -cmp;
|
|
3362
|
-
});
|
|
3363
|
-
tbody.innerHTML = "";
|
|
3364
|
-
rows.forEach((r) => {
|
|
3365
|
-
const tr = document.createElement("tr");
|
|
3366
|
-
r.forEach((v) => { const td = document.createElement("td"); td.textContent = v; tr.appendChild(td); });
|
|
3367
|
-
tbody.appendChild(tr);
|
|
3368
|
-
});
|
|
3369
|
-
}
|
|
3370
|
-
// Update aria-sort on headers.
|
|
3371
|
-
Array.from(thead.querySelectorAll("th")).forEach((h, i) => {
|
|
3372
|
-
h.setAttribute("aria-sort", i === idx ? (sortDir === "asc" ? "ascending" : "descending") : "none");
|
|
3373
|
-
});
|
|
3374
|
-
this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: idx, direction: sortDir } }));
|
|
3375
|
-
}
|
|
3376
|
-
});
|
|
3377
|
-
this.addEventListener("pointerdown", (e) => {
|
|
3378
|
-
if (!this.hasAttribute("resizable")) return;
|
|
3379
|
-
const th = e.target && e.target.closest ? e.target.closest("th[data-resizable]") : null;
|
|
3380
|
-
if (!th || !this.contains(th) || th.getBoundingClientRect().right - e.clientX > 10) return;
|
|
3381
|
-
e.preventDefault();
|
|
3382
|
-
const startX = e.clientX;
|
|
3383
|
-
const startWidth = th.getBoundingClientRect().width;
|
|
3384
|
-
const index = Array.from(th.parentElement.children).indexOf(th);
|
|
3385
|
-
const move = (event) => {
|
|
3386
|
-
const width = Math.max(48, startWidth + event.clientX - startX);
|
|
3387
|
-
const table = this.querySelector(".c-data-grid__table");
|
|
3388
|
-
if (table) Array.from(table.rows).forEach((row) => { if (row.children[index]) row.children[index].style.inlineSize = width + "px"; });
|
|
3389
|
-
};
|
|
3390
|
-
const stop = () => window.removeEventListener("pointermove", move);
|
|
3391
|
-
window.addEventListener("pointermove", move);
|
|
3392
|
-
window.addEventListener("pointerup", stop, { once: true });
|
|
3393
|
-
onDispose(this, stop);
|
|
3394
|
-
});
|
|
3395
|
-
}
|
|
3396
|
-
}
|
|
3397
|
-
define("contour-data-grid", ContourDataGrid);
|
|
3398
|
-
|
|
3399
|
-
/**
|
|
3400
|
-
* Tree Grid: web component wrapper.
|
|
3401
|
-
* Attributes: `items`, `expanded`.
|
|
3402
|
-
*/
|
|
3403
|
-
class ContourTreeGrid extends ContourBase {
|
|
3404
|
-
static get updateMode() { return "keyed"; }
|
|
3405
|
-
static get observed() { return ["items", "expanded"]; }
|
|
3406
|
-
static get properties() { return { items: { attribute: "items" }, expanded: { attribute: "expanded" } }; }
|
|
3407
|
-
_expandedSet() {
|
|
3408
|
-
const raw = this.getAttribute("expanded");
|
|
3409
|
-
if (!raw) return new Set();
|
|
3410
|
-
try { return new Set(JSON.parse(raw)); } catch (e) { return new Set([raw]); }
|
|
3411
|
-
}
|
|
3412
|
-
render() {
|
|
3413
|
-
this.classList.add("c-tree-grid");
|
|
3414
|
-
const table = this.ensure(".c-tree-grid__table", () => { const el = document.createElement("table"); el.className = "c-table c-tree-grid__table"; el.setAttribute("role", "treegrid"); return el; });
|
|
3415
|
-
table.setAttribute("aria-label", "Tree grid");
|
|
3416
|
-
const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
|
|
3417
|
-
if (tbody.parentNode !== table) table.appendChild(tbody);
|
|
3418
|
-
const items = this.getAttribute("items");
|
|
3419
|
-
let parsed = [];
|
|
3420
|
-
try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
|
|
3421
|
-
const expanded = this._expandedSet();
|
|
3422
|
-
tbody.innerHTML = "";
|
|
3423
|
-
const rows = [];
|
|
3424
|
-
const renderNode = (node, depth, path) => {
|
|
3425
|
-
const tr = document.createElement("tr");
|
|
3426
|
-
tr.setAttribute("role", "row");
|
|
3427
|
-
tr.setAttribute("tabindex", "0");
|
|
3428
|
-
tr.setAttribute("aria-level", String(depth + 1));
|
|
3429
|
-
tr.dataset.path = path;
|
|
3430
|
-
const hasChildren = !!(node && Array.isArray(node.children) && node.children.length);
|
|
3431
|
-
if (hasChildren) {
|
|
3432
|
-
tr.setAttribute("aria-expanded", expanded.has(path) ? "true" : "false");
|
|
3433
|
-
}
|
|
3434
|
-
const td = document.createElement("td");
|
|
3435
|
-
td.setAttribute("role", "gridcell");
|
|
3436
|
-
td.style.paddingInlineStart = (depth * 1.25) + "rem";
|
|
3437
|
-
const label = (node && (node.label || node.text || node.name)) || "";
|
|
3438
|
-
if (hasChildren) {
|
|
3439
|
-
const toggle = document.createElement("button");
|
|
3440
|
-
toggle.type = "button";
|
|
3441
|
-
toggle.className = "c-tree-grid__toggle";
|
|
3442
|
-
toggle.textContent = expanded.has(path) ? "▾" : "▸";
|
|
3443
|
-
toggle.setAttribute("aria-label", (expanded.has(path) ? "Collapse" : "Expand") + " " + label);
|
|
3444
|
-
td.appendChild(toggle);
|
|
3445
|
-
}
|
|
3446
|
-
const span = document.createElement("span");
|
|
3447
|
-
span.className = "c-tree-grid__label";
|
|
3448
|
-
span.textContent = label;
|
|
3449
|
-
td.appendChild(span);
|
|
3450
|
-
tr.appendChild(td);
|
|
3451
|
-
tbody.appendChild(tr);
|
|
3452
|
-
rows.push(tr);
|
|
3453
|
-
if (hasChildren && expanded.has(path)) {
|
|
3454
|
-
node.children.forEach((c, i) => renderNode(c, depth + 1, path + "." + i));
|
|
3455
|
-
}
|
|
3456
|
-
};
|
|
3457
|
-
parsed.forEach((n, i) => renderNode(n, 0, String(i)));
|
|
3458
|
-
if (table.parentNode !== this) this.appendChild(table);
|
|
3459
|
-
}
|
|
3460
|
-
enhance() {
|
|
3461
|
-
if (this._wiredTreeGrid) return;
|
|
3462
|
-
this._wiredTreeGrid = true;
|
|
3463
|
-
const rows = () => Array.from(this.querySelectorAll("tr[role='row']"));
|
|
3464
|
-
this.addEventListener("click", (e) => {
|
|
3465
|
-
const toggle = e.target && e.target.closest ? e.target.closest(".c-tree-grid__toggle") : null;
|
|
3466
|
-
const tr = e.target && e.target.closest ? e.target.closest("tr[role='row']") : null;
|
|
3467
|
-
if (!tr || !this.contains(tr)) return;
|
|
3468
|
-
const path = tr.dataset.path;
|
|
3469
|
-
if (toggle) {
|
|
3470
|
-
e.preventDefault();
|
|
3471
|
-
const expanded = this._expandedSet();
|
|
3472
|
-
if (expanded.has(path)) expanded.delete(path); else expanded.add(path);
|
|
3473
|
-
this.setAttribute("expanded", JSON.stringify([...expanded]));
|
|
3474
|
-
this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: expanded.has(path) } }));
|
|
3475
|
-
} else {
|
|
3476
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { path } }));
|
|
3477
|
-
}
|
|
3478
|
-
});
|
|
3479
|
-
this.addEventListener("keydown", (e) => {
|
|
3480
|
-
const tr = e.target && e.target.closest ? e.target.closest("tr[role='row']") : null;
|
|
3481
|
-
if (!tr || !this.contains(tr)) return;
|
|
3482
|
-
const all = rows();
|
|
3483
|
-
const idx = all.indexOf(tr);
|
|
3484
|
-
const path = tr.dataset.path;
|
|
3485
|
-
const hasChildren = tr.getAttribute("aria-expanded") !== null;
|
|
3486
|
-
const expanded = this._expandedSet();
|
|
3487
|
-
if (e.key === "ArrowRight" && hasChildren && !expanded.has(path)) {
|
|
3488
|
-
e.preventDefault();
|
|
3489
|
-
expanded.add(path);
|
|
3490
|
-
this.setAttribute("expanded", JSON.stringify([...expanded]));
|
|
3491
|
-
this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: true } }));
|
|
3492
|
-
} else if (e.key === "ArrowLeft" && hasChildren && expanded.has(path)) {
|
|
3493
|
-
e.preventDefault();
|
|
3494
|
-
expanded.delete(path);
|
|
3495
|
-
this.setAttribute("expanded", JSON.stringify([...expanded]));
|
|
3496
|
-
this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: false } }));
|
|
3497
|
-
} else if (e.key === "ArrowDown") {
|
|
3498
|
-
e.preventDefault();
|
|
3499
|
-
if (all[idx + 1]) try { all[idx + 1].focus(); } catch (err) {}
|
|
3500
|
-
} else if (e.key === "ArrowUp") {
|
|
3501
|
-
e.preventDefault();
|
|
3502
|
-
if (all[idx - 1]) try { all[idx - 1].focus(); } catch (err) {}
|
|
3503
|
-
} else if (e.key === "Enter" || e.key === " ") {
|
|
3504
|
-
e.preventDefault();
|
|
3505
|
-
const toggle = tr.querySelector(".c-tree-grid__toggle");
|
|
3506
|
-
if (toggle) toggle.click();
|
|
3507
|
-
}
|
|
3508
|
-
});
|
|
3509
|
-
}
|
|
3510
|
-
}
|
|
3511
|
-
define("contour-tree-grid", ContourTreeGrid);
|
|
3512
|
-
|
|
3513
|
-
class ContourPullToRefresh extends ContourBase {
|
|
3514
|
-
static get observed() { return ["threshold"]; }
|
|
3515
|
-
static get properties() { return { threshold: { attribute: "threshold" } }; }
|
|
3516
|
-
render() {
|
|
3517
|
-
this.classList.add("c-pull-to-refresh");
|
|
3518
|
-
const ind = this.ensure(".c-pull-to-refresh__indicator", () => {
|
|
3519
|
-
const e = document.createElement("div");
|
|
3520
|
-
e.className = "c-pull-to-refresh__indicator";
|
|
3521
|
-
e.textContent = "Pull to refresh";
|
|
3522
|
-
return e;
|
|
3523
|
-
});
|
|
3524
|
-
if (ind.parentNode !== this) this.prepend(ind);
|
|
3525
|
-
}
|
|
3526
|
-
enhance() {
|
|
3527
|
-
if (this._wiredPullToRefresh) return;
|
|
3528
|
-
this._wiredPullToRefresh = true;
|
|
3529
|
-
let startY = 0;
|
|
3530
|
-
let pulling = false;
|
|
3531
|
-
this.addEventListener("touchstart", (e) => {
|
|
3532
|
-
if (this.scrollTop > 0) return;
|
|
3533
|
-
const t = e.touches && e.touches[0];
|
|
3534
|
-
if (t) { startY = t.clientY; pulling = true; }
|
|
3535
|
-
}, { passive: true });
|
|
3536
|
-
this.addEventListener("touchmove", (e) => {
|
|
3537
|
-
if (!pulling) return;
|
|
3538
|
-
const t = e.touches && e.touches[0];
|
|
3539
|
-
if (!t) return;
|
|
3540
|
-
const dy = t.clientY - startY;
|
|
3541
|
-
if (dy > 0 && dy < 120) {
|
|
3542
|
-
this.style.setProperty("--ptr-offset", dy + "px");
|
|
3543
|
-
}
|
|
3544
|
-
}, { passive: true });
|
|
3545
|
-
this.addEventListener("touchend", (e) => {
|
|
3546
|
-
if (!pulling) return;
|
|
3547
|
-
pulling = false;
|
|
3548
|
-
const t = e.changedTouches && e.changedTouches[0];
|
|
3549
|
-
const dy = t ? t.clientY - startY : 0;
|
|
3550
|
-
const thr = Number(this.getAttribute("threshold")) || 60;
|
|
3551
|
-
if (dy >= thr) {
|
|
3552
|
-
this.classList.add("is-refreshing");
|
|
3553
|
-
this.dispatchEvent(new CustomEvent("contour:refresh", { bubbles: true, composed: true }));
|
|
3554
|
-
setTimeout(() => this.classList.remove("is-refreshing"), 800);
|
|
3555
|
-
}
|
|
3556
|
-
this.style.removeProperty("--ptr-offset");
|
|
3557
|
-
}, { passive: true });
|
|
3558
|
-
}
|
|
3559
|
-
}
|
|
3560
|
-
define("contour-pull-to-refresh", ContourPullToRefresh);
|