contour-ds 1.7.2 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +244 -326
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/agent-rules.json +16 -0
- package/dist/build-manifest.json +344 -126
- package/dist/contour-wc-content.esm.js +1939 -0
- package/dist/contour-wc-content.esm.min.js +1 -0
- package/dist/contour-wc-core.esm.js +3724 -0
- package/dist/contour-wc-core.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +6986 -0
- package/dist/contour-wc-dashboard.esm.min.js +1 -0
- package/dist/contour-wc-data.esm.js +6572 -0
- package/dist/contour-wc-data.esm.min.js +1 -0
- package/dist/contour-wc-docs.esm.js +976 -0
- package/dist/contour-wc-docs.esm.min.js +1 -0
- package/dist/contour-wc-feedback.esm.js +1742 -0
- package/dist/contour-wc-feedback.esm.min.js +1 -0
- package/dist/contour-wc-forms.esm.js +2437 -0
- package/dist/contour-wc-forms.esm.min.js +1 -0
- package/dist/contour-wc-interaction.esm.js +1343 -0
- package/dist/contour-wc-interaction.esm.min.js +1 -0
- package/dist/contour-wc-layout.esm.js +845 -0
- package/dist/contour-wc-layout.esm.min.js +1 -0
- package/dist/contour-wc-map.esm.js +2411 -0
- package/dist/contour-wc-map.esm.min.js +1 -0
- package/dist/contour-wc-misc.esm.js +945 -0
- package/dist/contour-wc-misc.esm.min.js +1 -0
- package/dist/contour-wc-navigation.esm.js +2842 -0
- package/dist/contour-wc-navigation.esm.min.js +1 -0
- package/dist/contour-wc-ui.esm.js +6519 -0
- package/dist/contour-wc-ui.esm.min.js +1 -0
- package/dist/contour-wc.esm.js +14435 -5723
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +14436 -5725
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +4534 -0
- package/dist/contour.components.json +4870 -1222
- package/dist/contour.css +6672 -4711
- package/dist/contour.d.ts +753 -1085
- package/dist/contour.esm.js +440 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +11343 -0
- package/dist/contour.js +440 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +422 -0
- package/dist/contour.single.html +17 -0
- package/dist/contour.single.min.css +1 -0
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +1318 -1053
- package/dist/contour.vue.d.ts +420 -0
- package/dist/contour.web-types.json +11703 -0
- package/dist/custom-elements.json +36120 -0
- package/dist/docs/actions.md +16 -6
- package/dist/docs/affordances.md +21 -85
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -22
- package/dist/docs/data.md +39 -58
- package/dist/docs/docs.md +12 -7
- package/dist/docs/feedback.md +30 -12
- package/dist/docs/field.md +28 -13
- package/dist/docs/forms.md +35 -19
- package/dist/docs/index.json +70 -61
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +30 -8
- package/dist/docs/motion.md +12 -6
- package/dist/docs/navigation.md +31 -7
- package/dist/docs/overlays.md +32 -25
- package/dist/docs/overview.md +3 -2
- package/dist/docs/patterns.md +20 -10
- package/dist/docs/playground.md +11 -4
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +117 -13
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +13 -14
- package/dist/docs/surfaces.md +17 -22
- package/dist/docs/theming.md +18 -32
- package/dist/docs/type.md +12 -5
- package/dist/docs/webcomponents.md +75 -33
- package/dist/hljs.css +1 -20
- package/dist/map-chrome.mapbox.css +68 -92
- package/dist/map-chrome.maplibre.css +68 -92
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/svg/icons.svg +367 -0
- package/dist/wc/behaviours.mjs +222 -192
- package/dist/wc/content.mjs +486 -142
- package/dist/wc/core.mjs +917 -395
- package/dist/wc/dashboard.mjs +252 -25
- package/dist/wc/data-chart.mjs +1333 -0
- package/dist/wc/data-export.mjs +391 -0
- package/dist/wc/data-gauge.mjs +779 -0
- package/dist/wc/data-geo.mjs +696 -0
- package/dist/wc/data-glyphs.mjs +133 -0
- package/dist/wc/data-legend.mjs +431 -0
- package/dist/wc/data-readout.mjs +227 -0
- package/dist/wc/data-series.mjs +1004 -0
- package/dist/wc/data-table.mjs +751 -0
- package/dist/wc/data.mjs +15 -3707
- package/dist/wc/docs.mjs +113 -19
- package/dist/wc/feedback.mjs +320 -116
- package/dist/wc/forms-controls.mjs +635 -0
- package/dist/wc/forms-field.mjs +547 -0
- package/dist/wc/forms-groups.mjs +347 -0
- package/dist/wc/forms-input.mjs +292 -0
- package/dist/wc/forms.mjs +10 -1122
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +16 -7
- package/dist/wc/interaction.mjs +322 -75
- package/dist/wc/layout.mjs +100 -29
- package/dist/wc/map.mjs +888 -285
- package/dist/wc/misc.mjs +137 -26
- package/dist/wc/navigation-menu.mjs +735 -0
- package/dist/wc/navigation-shell.mjs +495 -0
- package/dist/wc/navigation-tree.mjs +995 -0
- package/dist/wc/navigation.mjs +9 -1636
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +285 -113
- package/dist/wc/states.mjs +75 -78
- package/dist/wc/svg.mjs +209 -34
- package/dist/wc/ui-atoms.mjs +608 -0
- package/dist/wc/ui-data.mjs +1404 -0
- package/dist/wc/ui-feedback.mjs +419 -0
- package/dist/wc/ui-inputs.mjs +1570 -0
- package/dist/wc/ui-menus.mjs +307 -0
- package/dist/wc/ui-overlays.mjs +1605 -0
- package/integrations/README.md +25 -5
- package/integrations/ai/CLAUDE.md +6 -3
- package/integrations/ai/COPILOT.md +14 -0
- package/integrations/ai/GEMINI.md +14 -0
- package/integrations/ai/WINDSURF.md +14 -0
- package/integrations/ai/v0-prompt.md +13 -1
- package/integrations/frameworks/README.md +235 -0
- package/integrations/native/README.md +0 -3
- package/integrations/native/style-dictionary.config.json +1 -1
- package/integrations/tailwind/contour-theme.css +71 -13
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +103 -39
- package/dist/wc/ui.mjs +0 -3560
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { setHTML, ContourBase, define, contourId, onDispose, navKey, safeColor, safeHref, cssLength , warnBadJson, labelText, flagOn, formatValue, wcEmitOverlay, statusIcon } from './core.mjs';
|
|
2
|
+
import { wireRemovable, modalContain } from './behaviours.mjs';
|
|
3
|
+
import { parseArrayAttr, renderEmpty } from './states.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tooltip: a popover-triggered tooltip with anchor association, delay, and
|
|
7
|
+
* viewport flip. Attributes: `text`, `anchor`, `delay`, `trigger`.
|
|
8
|
+
*/
|
|
9
|
+
class ContourTooltip extends ContourBase {
|
|
10
|
+
static get observed() { return ["text", "anchor", "delay", "trigger"]; }
|
|
11
|
+
static get properties() { return { text: { attribute: "text" }, anchor: { attribute: "anchor" }, delay: { attribute: "delay", type: Number }, trigger: { attribute: "trigger" } }; }
|
|
12
|
+
render() {
|
|
13
|
+
this.classList.add("c-tooltip");
|
|
14
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "tooltip", "Tooltip"));
|
|
15
|
+
if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
|
|
16
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "tooltip");
|
|
17
|
+
if (!this.id) this.id = contourId("tip");
|
|
18
|
+
const text = this.getAttribute("text");
|
|
19
|
+
if (text !== null && !this.hasChildNodes()) {
|
|
20
|
+
this.textContent = text;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
enhance() {
|
|
24
|
+
if (this._wiredTooltip) return;
|
|
25
|
+
this._wiredTooltip = true;
|
|
26
|
+
// Anchor association: link a trigger element to this tooltip.
|
|
27
|
+
const anchorSel = this.getAttribute("anchor");
|
|
28
|
+
if (anchorSel) {
|
|
29
|
+
let trigger = null;
|
|
30
|
+
if (anchorSel.startsWith("#")) {
|
|
31
|
+
trigger = document.getElementById(anchorSel.slice(1));
|
|
32
|
+
} else {
|
|
33
|
+
trigger = document.querySelector(anchorSel);
|
|
34
|
+
}
|
|
35
|
+
if (trigger) {
|
|
36
|
+
trigger.setAttribute("popovertarget", this.id || (this.id = contourId("tip")));
|
|
37
|
+
trigger.setAttribute("aria-describedby", this.id);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const delayMs = (this.delay && this.delay > 0) ? this.delay : 0;
|
|
41
|
+
// CSS anchor positioning so tooltip anchors to trigger, not (0,0).
|
|
42
|
+
const tipAnchorSel = this.getAttribute("anchor");
|
|
43
|
+
let anchorEl = null;
|
|
44
|
+
if (tipAnchorSel) {
|
|
45
|
+
anchorEl = tipAnchorSel.startsWith("#") ? document.getElementById(tipAnchorSel.slice(1)) : document.querySelector(tipAnchorSel);
|
|
46
|
+
}
|
|
47
|
+
const anchorName = "--tooltip-" + (this.id || (this.id = contourId("tip")));
|
|
48
|
+
const applyAnchor = () => {
|
|
49
|
+
if (anchorEl) {
|
|
50
|
+
anchorEl.style.setProperty("anchor-name", anchorName);
|
|
51
|
+
this.style.setProperty("position-anchor", anchorName);
|
|
52
|
+
this.style.setProperty("position-area", "top");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
applyAnchor();
|
|
56
|
+
// Hoverable grace period (WC 1.4.13): keep tooltip open while pointer moves to it.
|
|
57
|
+
const hasPopover = typeof this.showPopover === "function";
|
|
58
|
+
let showTimer = null;
|
|
59
|
+
let hoverTimer = null;
|
|
60
|
+
const showTooltip = () => {
|
|
61
|
+
if (hasPopover) { try { this.showPopover(); } catch (e) {} }
|
|
62
|
+
else {
|
|
63
|
+
this.classList.add("is-open");
|
|
64
|
+
// Non-popover fallback is position:fixed, so it needs the tooltip z-index rung; the top layer does not.
|
|
65
|
+
this.style.zIndex = "var(--z-tooltip)";
|
|
66
|
+
}
|
|
67
|
+
try { requestAnimationFrame(flipIfNeeded); } catch (e) { flipIfNeeded(); }
|
|
68
|
+
};
|
|
69
|
+
const hideTooltip = () => {
|
|
70
|
+
if (hoverTimer) { clearTimeout(hoverTimer); hoverTimer = null; }
|
|
71
|
+
if (hasPopover) { try { this.hidePopover(); } catch (e) {} }
|
|
72
|
+
else { this.classList.remove("is-open"); this.style.removeProperty("z-index"); }
|
|
73
|
+
};
|
|
74
|
+
const show = () => {
|
|
75
|
+
if (showTimer) clearTimeout(showTimer);
|
|
76
|
+
if (delayMs > 0) showTimer = setTimeout(showTooltip, delayMs);
|
|
77
|
+
else showTooltip();
|
|
78
|
+
};
|
|
79
|
+
const hide = () => {
|
|
80
|
+
if (showTimer) { clearTimeout(showTimer); showTimer = null; }
|
|
81
|
+
// Grace period: keep tooltip open briefly so pointer can reach it (WC 1.4.13).
|
|
82
|
+
if (hoverTimer) clearTimeout(hoverTimer);
|
|
83
|
+
hoverTimer = setTimeout(hideTooltip, 300);
|
|
84
|
+
};
|
|
85
|
+
// Hoverable: cancel hide when pointer enters tooltip.
|
|
86
|
+
this.addEventListener("pointerenter", () => { if (hoverTimer) { clearTimeout(hoverTimer); hoverTimer = null; } });
|
|
87
|
+
this.addEventListener("pointerleave", hide);
|
|
88
|
+
onDispose(this, () => { if (anchorEl) anchorEl.style.removeProperty("anchor-name"); });
|
|
89
|
+
const triggerMode = this.getAttribute("trigger") || "hover";
|
|
90
|
+
const trigger = tipAnchorSel ? (tipAnchorSel.startsWith("#") ? document.getElementById(tipAnchorSel.slice(1)) : document.querySelector(tipAnchorSel)) : null;
|
|
91
|
+
const target = trigger || this;
|
|
92
|
+
const onEnter = () => { if (triggerMode !== "click") show(); };
|
|
93
|
+
const onLeave = () => { if (triggerMode !== "click") hide(); };
|
|
94
|
+
const onFocus = () => { if (triggerMode !== "click") show(); };
|
|
95
|
+
const onBlur = () => { if (triggerMode !== "click") hide(); };
|
|
96
|
+
const onClick = (e) => {
|
|
97
|
+
// A trigger with `popovertarget` toggles natively; our toggle would race it.
|
|
98
|
+
if (trigger && trigger.hasAttribute("popovertarget")) {
|
|
99
|
+
// In hover/focus mode, native click toggle closes tooltip on Enter — suppress it.
|
|
100
|
+
if (triggerMode !== "click" && e && e.preventDefault) e.preventDefault();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (triggerMode === "click" || triggerMode === "hover") {
|
|
104
|
+
if (this.matches(":popover-open")) hide(); else show();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const onTouchStart = () => { if (triggerMode !== "click") show(); };
|
|
108
|
+
const onTouchEnd = () => { if (triggerMode !== "click") { setTimeout(hide, 1500); } };
|
|
109
|
+
target.addEventListener("mouseenter", onEnter);
|
|
110
|
+
target.addEventListener("mouseleave", onLeave);
|
|
111
|
+
target.addEventListener("focus", onFocus);
|
|
112
|
+
target.addEventListener("blur", onBlur);
|
|
113
|
+
target.addEventListener("click", onClick);
|
|
114
|
+
target.addEventListener("touchstart", onTouchStart, { passive: true });
|
|
115
|
+
target.addEventListener("touchend", onTouchEnd, { passive: true });
|
|
116
|
+
// Placement flip: if the tooltip would overflow the viewport, flip it.
|
|
117
|
+
const flipIfNeeded = () => {
|
|
118
|
+
try {
|
|
119
|
+
const r = this.getBoundingClientRect();
|
|
120
|
+
if (r.right > window.innerWidth) this.classList.add("c-tooltip--flip-x");
|
|
121
|
+
else this.classList.remove("c-tooltip--flip-x");
|
|
122
|
+
if (r.bottom > window.innerHeight) this.classList.add("c-tooltip--flip-y");
|
|
123
|
+
else this.classList.remove("c-tooltip--flip-y");
|
|
124
|
+
} catch (e) {}
|
|
125
|
+
};
|
|
126
|
+
const origShow = show;
|
|
127
|
+
// wrap show to flip after display
|
|
128
|
+
onDispose(this, () => {
|
|
129
|
+
target.removeEventListener("mouseenter", onEnter);
|
|
130
|
+
target.removeEventListener("mouseleave", onLeave);
|
|
131
|
+
target.removeEventListener("focus", onFocus);
|
|
132
|
+
target.removeEventListener("blur", onBlur);
|
|
133
|
+
target.removeEventListener("click", onClick);
|
|
134
|
+
target.removeEventListener("touchstart", onTouchStart);
|
|
135
|
+
target.removeEventListener("touchend", onTouchEnd);
|
|
136
|
+
if (showTimer) clearTimeout(showTimer);
|
|
137
|
+
});
|
|
138
|
+
this.addEventListener("toggle", (e) => {
|
|
139
|
+
const t = e.target;
|
|
140
|
+
if (t && t === this) {
|
|
141
|
+
const open = this.matches(":popover-open");
|
|
142
|
+
wcEmitOverlay(this, open ? "contour:open" : "contour:close", { open });
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
// Canonical contour:open/close emitted from post-flip toggle; beforetoggle would double-fire.
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
define("contour-tooltip", ContourTooltip);
|
|
149
|
+
/**
|
|
150
|
+
* Progress: a determinate or indeterminate progress bar with value, min/max,
|
|
151
|
+
* paused and pausable states. Attributes: `value`, `label`, `min`, `max`,
|
|
152
|
+
* `paused`, `pausable`.
|
|
153
|
+
*/
|
|
154
|
+
class ContourProgress extends ContourBase {
|
|
155
|
+
static get observed() { return ["value", "label", "min", "max", "paused", "pausable"]; }
|
|
156
|
+
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 } }; }
|
|
157
|
+
render() {
|
|
158
|
+
this.classList.add("c-progress");
|
|
159
|
+
const value = this.getAttribute("value");
|
|
160
|
+
// min/max normalise percentage: value=75 min=50 max=100 is 50%, not 75%.
|
|
161
|
+
const min = this.getAttribute("min");
|
|
162
|
+
const max = this.getAttribute("max");
|
|
163
|
+
const minV = min !== null ? Number(min) : 0;
|
|
164
|
+
const maxV = max !== null ? Number(max) : 100;
|
|
165
|
+
const rangeV = (maxV - minV) || 1;
|
|
166
|
+
// pct must be declared before branches: else-block ReferenceError left screen readers with no value.
|
|
167
|
+
if (value === null) {
|
|
168
|
+
// Indeterminate: no fill, no value announced.
|
|
169
|
+
this.style.removeProperty("--progress");
|
|
170
|
+
this.classList.add("c-progress--indeterminate");
|
|
171
|
+
if (this.getAttribute("aria-valuenow") === this._progressAriaValue) {
|
|
172
|
+
this.removeAttribute("aria-valuenow");
|
|
173
|
+
}
|
|
174
|
+
this._progressAriaValue = null;
|
|
175
|
+
} else {
|
|
176
|
+
this.classList.remove("c-progress--indeterminate");
|
|
177
|
+
const num = Number(value);
|
|
178
|
+
// Accept 0-1 (fraction) or 0-100 (percentage). <=1 with decimal = fraction; else normalise against min/max.
|
|
179
|
+
let pct;
|
|
180
|
+
if (!Number.isFinite(num)) pct = 0;
|
|
181
|
+
else if (num <= 1 && value.includes(".")) pct = num * 100;
|
|
182
|
+
else pct = ((num - minV) / rangeV) * 100;
|
|
183
|
+
pct = Math.max(0, Math.min(100, pct));
|
|
184
|
+
this.style.setProperty("--progress", pct + "%");
|
|
185
|
+
// A quiet acknowledgement at full: the bar gets a one-shot settle
|
|
186
|
+
// pulse (CSS), a "needle reaching the mark" rather than confetti.
|
|
187
|
+
this.classList.toggle("c-progress--complete", pct >= 100);
|
|
188
|
+
// aria-valuenow in control's units (min..max), not percentage.
|
|
189
|
+
const ariaNow = Number.isFinite(num) ? Math.max(minV, Math.min(maxV, num)) : minV;
|
|
190
|
+
const prevVal = this._progressAriaValue;
|
|
191
|
+
if (!this.hasAttribute("aria-valuenow") || this.getAttribute("aria-valuenow") === prevVal) {
|
|
192
|
+
this.setAttribute("aria-valuenow", String(ariaNow));
|
|
193
|
+
this._progressAriaValue = String(ariaNow);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
this.ensure(".c-progress__bar", () => { const el = document.createElement("span"); el.className = "c-progress__bar"; return el; });
|
|
197
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "progressbar");
|
|
198
|
+
const label = this.getAttribute("label");
|
|
199
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", label || "Progress");
|
|
200
|
+
if (min !== null) this.setAttribute("aria-valuemin", min);
|
|
201
|
+
else if (!this.hasAttribute("aria-valuemin")) this.setAttribute("aria-valuemin", "0");
|
|
202
|
+
if (max !== null) this.setAttribute("aria-valuemax", max);
|
|
203
|
+
else if (!this.hasAttribute("aria-valuemax")) this.setAttribute("aria-valuemax", "100");
|
|
204
|
+
// aria-valuenow must sit inside declared min/max, not always 0-100.
|
|
205
|
+
if (this.hasAttribute("aria-valuenow")) {
|
|
206
|
+
const now = Number(this.getAttribute("aria-valuenow"));
|
|
207
|
+
if (Number.isFinite(now)) this.setAttribute("aria-valuenow", String(Math.max(minV, Math.min(maxV, now))));
|
|
208
|
+
}
|
|
209
|
+
if (flagOn(this, "paused")) this.classList.add("c-progress--paused");
|
|
210
|
+
else Array.from(this.classList).forEach((c) => { if (c === "c-progress--paused") this.classList.remove(c); });
|
|
211
|
+
if (flagOn(this, "pausable")) {
|
|
212
|
+
const paused = flagOn(this, "paused");
|
|
213
|
+
const btn = this.ensure(".c-progress__pause", () => {
|
|
214
|
+
const el = document.createElement("button");
|
|
215
|
+
el.className = "c-progress__pause";
|
|
216
|
+
el.type = "button";
|
|
217
|
+
return el;
|
|
218
|
+
});
|
|
219
|
+
btn.setAttribute("aria-label", paused ? "Resume" : "Pause");
|
|
220
|
+
btn.textContent = paused ? "▶" : "⏸";
|
|
221
|
+
} else {
|
|
222
|
+
const btn = this.querySelector(".c-progress__pause");
|
|
223
|
+
if (btn) btn.remove();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
enhance() {
|
|
227
|
+
if (this._wiredProgress) return;
|
|
228
|
+
this._wiredProgress = true;
|
|
229
|
+
this.addEventListener("click", (e) => {
|
|
230
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-progress__pause") : null;
|
|
231
|
+
if (!btn || !this.contains(btn)) return;
|
|
232
|
+
e.preventDefault();
|
|
233
|
+
const paused = !flagOn(this, "paused");
|
|
234
|
+
this.toggleAttribute("paused", paused);
|
|
235
|
+
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { paused } }));
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
define("contour-progress", ContourProgress);
|
|
240
|
+
/**
|
|
241
|
+
* VersionBanner: a dismissible info banner with message, link and href.
|
|
242
|
+
* Attributes: `message`, `link`, `href`, `dismissible`.
|
|
243
|
+
*/
|
|
244
|
+
class ContourVersionBannerFull extends ContourBase {
|
|
245
|
+
static get observed() { return ["message", "link", "href", "dismissible"]; }
|
|
246
|
+
static get properties() { return { message: { attribute: "message" }, link: { attribute: "link" }, href: { attribute: "href" }, dismissible: { attribute: "dismissible", type: Boolean } }; }
|
|
247
|
+
render() {
|
|
248
|
+
this.classList.add("c-version-banner");
|
|
249
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "status");
|
|
250
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("message") || "Version banner");
|
|
251
|
+
Array.from(this.children).forEach((n) => n.remove());
|
|
252
|
+
const message = this.getAttribute("message");
|
|
253
|
+
if (message) {
|
|
254
|
+
// createElement("svg") makes HTMLUnknownElement; SVG namespace needed for <use> to render.
|
|
255
|
+
const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
256
|
+
icon.setAttribute("aria-hidden", "true");
|
|
257
|
+
setHTML(icon, '<use href="#i-info" />');
|
|
258
|
+
this.appendChild(icon);
|
|
259
|
+
const span = document.createElement("span");
|
|
260
|
+
span.textContent = message;
|
|
261
|
+
this.appendChild(span);
|
|
262
|
+
}
|
|
263
|
+
const link = this.getAttribute("link");
|
|
264
|
+
const href = this.getAttribute("href");
|
|
265
|
+
if (link && href) {
|
|
266
|
+
const a = document.createElement("a");
|
|
267
|
+
a.className = "c-version-banner__link";
|
|
268
|
+
a.href = safeHref(href);
|
|
269
|
+
a.textContent = link;
|
|
270
|
+
this.appendChild(a);
|
|
271
|
+
}
|
|
272
|
+
if (flagOn(this, "dismissible")) {
|
|
273
|
+
const btn = document.createElement("button");
|
|
274
|
+
btn.className = "c-version-banner__dismiss";
|
|
275
|
+
btn.type = "button";
|
|
276
|
+
btn.setAttribute("aria-label", labelText(this, "dismiss", "Dismiss"));
|
|
277
|
+
btn.textContent = "×";
|
|
278
|
+
this.appendChild(btn);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
enhance() {
|
|
282
|
+
if (this._wiredVersionBanner) return;
|
|
283
|
+
this._wiredVersionBanner = true;
|
|
284
|
+
this.addEventListener("click", (e) => {
|
|
285
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-version-banner__dismiss") : null;
|
|
286
|
+
if (btn && this.contains(btn)) {
|
|
287
|
+
e.preventDefault();
|
|
288
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
289
|
+
this.remove();
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
define("contour-version-banner", ContourVersionBannerFull);
|
|
295
|
+
/**
|
|
296
|
+
* Banner: a simple message banner with a variant modifier. Attributes:
|
|
297
|
+
* `message`, `variant`.
|
|
298
|
+
*/
|
|
299
|
+
class ContourBanner extends ContourBase {
|
|
300
|
+
static get observed() { return ["message", "variant"]; }
|
|
301
|
+
static get properties() { return { message: { attribute: "message" }, variant: { attribute: "variant" } }; }
|
|
302
|
+
render() {
|
|
303
|
+
this.classList.add("c-banner");
|
|
304
|
+
const variant = this.getAttribute("variant");
|
|
305
|
+
// Validate variant against supported set so typos silently produce no class (state not conveyed by hue alone).
|
|
306
|
+
const validVariants = ["info", "success", "warning", "danger", "error"];
|
|
307
|
+
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-banner--")) this.classList.remove(c); });
|
|
308
|
+
if (variant && validVariants.includes(variant)) this.classList.add("c-banner--" + variant);
|
|
309
|
+
const icon = statusIcon(variant);
|
|
310
|
+
let ic = this.querySelector(".c-banner__icon");
|
|
311
|
+
if (icon) {
|
|
312
|
+
if (!ic) { ic = document.createElement("span"); ic.className = "c-banner__icon"; }
|
|
313
|
+
setHTML(ic, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + String(icon).replace(/[^a-zA-Z0-9_-]/g, "") + '" /></svg>');
|
|
314
|
+
if (this.firstChild !== ic) this.prepend(ic);
|
|
315
|
+
} else if (ic) {
|
|
316
|
+
ic.remove();
|
|
317
|
+
}
|
|
318
|
+
const message = this.getAttribute("message");
|
|
319
|
+
if (message) {
|
|
320
|
+
const span = this.ensure(".c-banner__message", () => { const el = document.createElement("span"); el.className = "c-banner__message"; return el; });
|
|
321
|
+
span.textContent = message;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
define("contour-banner", ContourBanner);
|
|
326
|
+
class ContourPullToRefresh extends ContourBase {
|
|
327
|
+
static get observed() { return ["threshold"]; }
|
|
328
|
+
static get properties() { return { threshold: { attribute: "threshold" } }; }
|
|
329
|
+
render() {
|
|
330
|
+
this.classList.add("c-pull-to-refresh");
|
|
331
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
332
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "label", "Pull to refresh"));
|
|
333
|
+
const ind = this.ensure(".c-pull-to-refresh__indicator", () => {
|
|
334
|
+
const e = document.createElement("div");
|
|
335
|
+
e.className = "c-pull-to-refresh__indicator";
|
|
336
|
+
return e;
|
|
337
|
+
});
|
|
338
|
+
ind.innerHTML = "";
|
|
339
|
+
const label = document.createElement("span");
|
|
340
|
+
label.className = "c-pull-to-refresh__label";
|
|
341
|
+
label.setAttribute("aria-live", "polite");
|
|
342
|
+
label.textContent = this._ptrError
|
|
343
|
+
? this._ptrError
|
|
344
|
+
: (this._ptrRefreshing ? labelText(this, "refreshing", "Refreshing…") : labelText(this, "label", "Pull to refresh"));
|
|
345
|
+
ind.appendChild(label);
|
|
346
|
+
// A keyboard-reachable refresh alternative: the gesture is pointer-only,
|
|
347
|
+
// and a control the reader can press must exist anyway (R20 T-25).
|
|
348
|
+
const btn = document.createElement("button");
|
|
349
|
+
btn.type = "button";
|
|
350
|
+
btn.className = "c-pull-to-refresh__btn";
|
|
351
|
+
btn.textContent = labelText(this, "refresh", "Refresh");
|
|
352
|
+
ind.appendChild(btn);
|
|
353
|
+
if (ind.parentNode !== this) this.prepend(ind);
|
|
354
|
+
this.classList.toggle("is-refreshing", !!this._ptrRefreshing);
|
|
355
|
+
this.classList.toggle("has-error", !!this._ptrError);
|
|
356
|
+
this.setAttribute("aria-busy", String(!!this._ptrRefreshing));
|
|
357
|
+
}
|
|
358
|
+
// Completion is consumer-driven: the consumer calls complete() when its fetch settles, or fail(message); both clear the pull offset.
|
|
359
|
+
complete() {
|
|
360
|
+
this._ptrRefreshing = false;
|
|
361
|
+
this._ptrError = null;
|
|
362
|
+
this.style.removeProperty("--ptr-offset");
|
|
363
|
+
this.requestRender();
|
|
364
|
+
}
|
|
365
|
+
fail(message) {
|
|
366
|
+
this._ptrRefreshing = false;
|
|
367
|
+
this._ptrError = String(message || labelText(this, "error", "Refresh failed"));
|
|
368
|
+
this.style.removeProperty("--ptr-offset");
|
|
369
|
+
this.requestRender();
|
|
370
|
+
this.dispatchEvent(new CustomEvent("contour:error", { bubbles: true, composed: true, detail: { message: this._ptrError } }));
|
|
371
|
+
}
|
|
372
|
+
_refresh() {
|
|
373
|
+
if (this._ptrRefreshing) return;
|
|
374
|
+
this._ptrRefreshing = true;
|
|
375
|
+
this._ptrError = null;
|
|
376
|
+
this.style.removeProperty("--ptr-offset");
|
|
377
|
+
this.requestRender();
|
|
378
|
+
this.dispatchEvent(new CustomEvent("contour:refresh", { bubbles: true, composed: true }));
|
|
379
|
+
}
|
|
380
|
+
enhance() {
|
|
381
|
+
if (this._wiredPullToRefresh) return;
|
|
382
|
+
this._wiredPullToRefresh = true;
|
|
383
|
+
this.addEventListener("click", (e) => {
|
|
384
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-pull-to-refresh__btn") : null;
|
|
385
|
+
if (btn && this.contains(btn)) this._refresh();
|
|
386
|
+
});
|
|
387
|
+
// Pointer events cover touch AND mouse; the gesture had been touch-only.
|
|
388
|
+
let startY = 0;
|
|
389
|
+
let pulling = false;
|
|
390
|
+
let offset = 0;
|
|
391
|
+
this.addEventListener("pointerdown", (e) => {
|
|
392
|
+
if (this._ptrRefreshing || this.scrollTop > 0) return;
|
|
393
|
+
if (e.target && e.target.closest && e.target.closest(".c-pull-to-refresh__btn")) return;
|
|
394
|
+
startY = e.clientY;
|
|
395
|
+
pulling = true;
|
|
396
|
+
offset = 0;
|
|
397
|
+
try { this.setPointerCapture(e.pointerId); } catch (err) {}
|
|
398
|
+
});
|
|
399
|
+
this.addEventListener("pointermove", (e) => {
|
|
400
|
+
if (!pulling) return;
|
|
401
|
+
const dy = e.clientY - startY;
|
|
402
|
+
if (dy > 0) {
|
|
403
|
+
offset = Math.min(120, dy * 0.6);
|
|
404
|
+
this.style.setProperty("--ptr-offset", offset + "px");
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
const end = () => {
|
|
408
|
+
if (!pulling) return;
|
|
409
|
+
pulling = false;
|
|
410
|
+
const thr = Number(this.getAttribute("threshold")) || 60;
|
|
411
|
+
if (offset >= thr) this._refresh();
|
|
412
|
+
else this.style.removeProperty("--ptr-offset");
|
|
413
|
+
offset = 0;
|
|
414
|
+
};
|
|
415
|
+
this.addEventListener("pointerup", end);
|
|
416
|
+
this.addEventListener("pointercancel", end);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
define("contour-pull-to-refresh", ContourPullToRefresh);
|