contour-ds 1.8.1 → 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 +227 -378
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/build-manifest.json +320 -179
- package/dist/contour-wc-content.esm.js +479 -3665
- package/dist/contour-wc-content.esm.min.js +1 -1
- 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 +2713 -4381
- package/dist/contour-wc-dashboard.esm.min.js +1 -1
- package/dist/contour-wc-data.esm.js +2658 -4346
- package/dist/contour-wc-data.esm.min.js +1 -1
- package/dist/contour-wc-docs.esm.js +218 -3547
- package/dist/contour-wc-docs.esm.min.js +1 -1
- package/dist/contour-wc-feedback.esm.js +483 -3658
- package/dist/contour-wc-feedback.esm.min.js +1 -1
- package/dist/contour-wc-forms.esm.js +503 -3754
- package/dist/contour-wc-forms.esm.min.js +1 -1
- package/dist/contour-wc-interaction.esm.js +379 -3616
- package/dist/contour-wc-interaction.esm.min.js +1 -1
- package/dist/contour-wc-layout.esm.js +234 -3563
- package/dist/contour-wc-layout.esm.min.js +1 -1
- package/dist/contour-wc-map.esm.js +949 -3743
- package/dist/contour-wc-map.esm.min.js +1 -1
- package/dist/contour-wc-misc.esm.js +237 -3556
- package/dist/contour-wc-misc.esm.min.js +1 -1
- package/dist/contour-wc-navigation.esm.js +2235 -5237
- package/dist/contour-wc-navigation.esm.min.js +1 -1
- package/dist/contour-wc-ui.esm.js +4638 -7128
- package/dist/contour-wc-ui.esm.min.js +1 -1
- package/dist/contour-wc.esm.js +11971 -7727
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +11971 -7727
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +96 -74
- package/dist/contour.components.json +2591 -741
- package/dist/contour.css +2624 -1888
- package/dist/contour.d.ts +421 -228
- package/dist/contour.esm.js +433 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +1231 -199
- package/dist/contour.js +433 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +100 -98
- package/dist/contour.single.html +2 -2
- package/dist/contour.single.min.css +1 -1
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +482 -255
- package/dist/contour.vue.d.ts +100 -98
- package/dist/contour.web-types.json +1226 -226
- package/dist/custom-elements.json +7649 -2237
- package/dist/docs/actions.md +15 -6
- package/dist/docs/affordances.md +18 -96
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -26
- package/dist/docs/data.md +36 -60
- package/dist/docs/docs.md +10 -12
- 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 +63 -56
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +18 -13
- 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 +19 -9
- package/dist/docs/playground.md +9 -22
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +113 -14
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +12 -25
- 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 +66 -38
- 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 +190 -148
- package/dist/wc/content.mjs +273 -129
- package/dist/wc/core.mjs +598 -395
- package/dist/wc/dashboard.mjs +64 -44
- 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 -4322
- package/dist/wc/docs.mjs +12 -11
- package/dist/wc/feedback.mjs +277 -122
- 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 -1751
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +11 -9
- package/dist/wc/interaction.mjs +173 -80
- package/dist/wc/layout.mjs +28 -27
- package/dist/wc/map.mjs +743 -207
- package/dist/wc/misc.mjs +31 -20
- 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 -1905
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +206 -110
- package/dist/wc/states.mjs +54 -75
- package/dist/wc/svg.mjs +118 -47
- 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 +23 -5
- package/integrations/ai/CLAUDE.md +3 -0
- 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/native/README.md +0 -3
- package/integrations/tailwind/contour-theme.css +66 -7
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +77 -42
- package/dist/wc/ui.mjs +0 -5072
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
import { setHTML, ContourBase, define, onDispose, supportsUntilFound, contourId, headingTag, navKey, safeHref, cssLength , warnBadJson, labelText, applyLabel, wcEmitOverlay } from './core.mjs';
|
|
2
|
+
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
|
|
3
|
+
import { wireMenu, wirePagination, wireTabs, wireTree, wireRemovable } from './behaviours.mjs';
|
|
4
|
+
|
|
5
|
+
class ContourHeader extends ContourBase {
|
|
6
|
+
static get observed() { return ["brand", "brand-href", "links"]; }
|
|
7
|
+
static get properties() { return { brand: { attribute: "brand" }, "brand-href": { attribute: "brand-href" }, links: { attribute: "links" } }; }
|
|
8
|
+
render() {
|
|
9
|
+
this.classList.add("c-header");
|
|
10
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "banner");
|
|
11
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("brand") || "Header");
|
|
12
|
+
const brand = this.getAttribute("brand");
|
|
13
|
+
const links = this.getAttribute("links");
|
|
14
|
+
const inner = this.ensure(".c-header__inner", () => { const el = document.createElement("div"); el.className = "container c-header__inner"; return el; });
|
|
15
|
+
inner.className = "container c-header__inner";
|
|
16
|
+
// Brand
|
|
17
|
+
let brandEl = inner.querySelector(".c-brand");
|
|
18
|
+
if (brand) {
|
|
19
|
+
if (!brandEl) {
|
|
20
|
+
brandEl = document.createElement("a");
|
|
21
|
+
brandEl.className = "c-brand";
|
|
22
|
+
brandEl.setAttribute("data-contour-generated", "");
|
|
23
|
+
brandEl.href = safeHref(this.getAttribute("brand-href") || "#");
|
|
24
|
+
setHTML(brandEl, `<span class="c-mark"><svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-mark" /></svg></span>`);
|
|
25
|
+
const brandName = document.createElement("span");
|
|
26
|
+
brandName.className = "c-brand__name";
|
|
27
|
+
brandEl.appendChild(brandName);
|
|
28
|
+
inner.insertBefore(brandEl, inner.firstChild);
|
|
29
|
+
}
|
|
30
|
+
const brandName = brandEl.querySelector(".c-brand__name");
|
|
31
|
+
if (brandName) brandName.textContent = brand;
|
|
32
|
+
} else if (brandEl && brandEl.hasAttribute("data-contour-generated")) {
|
|
33
|
+
brandEl.remove();
|
|
34
|
+
}
|
|
35
|
+
// Nav
|
|
36
|
+
let nav = inner.querySelector(".c-header__nav");
|
|
37
|
+
const authoredNav = nav ? Array.from(nav.children).filter((n) => n.tagName === "A") : [];
|
|
38
|
+
if (links && !authoredNav.length) {
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(links);
|
|
41
|
+
if (!nav) {
|
|
42
|
+
nav = document.createElement("nav");
|
|
43
|
+
nav.className = "c-header__nav";
|
|
44
|
+
nav.setAttribute("aria-label", labelText(this, "main", "Main"));
|
|
45
|
+
nav.setAttribute("data-contour-generated", "");
|
|
46
|
+
inner.appendChild(nav);
|
|
47
|
+
}
|
|
48
|
+
nav.innerHTML = "";
|
|
49
|
+
parsed.forEach((l) => {
|
|
50
|
+
const a = document.createElement("a");
|
|
51
|
+
a.href = safeHref(l.href || "#");
|
|
52
|
+
a.textContent = l.label || l;
|
|
53
|
+
nav.appendChild(a);
|
|
54
|
+
});
|
|
55
|
+
} catch (e) { /* skip */ }
|
|
56
|
+
} else if (links && authoredNav.length) {
|
|
57
|
+
// authored nav wins; keep it
|
|
58
|
+
} else if (nav && !links && !authoredNav.length && nav.hasAttribute("data-contour-generated")) {
|
|
59
|
+
nav.remove();
|
|
60
|
+
}
|
|
61
|
+
// Actions container
|
|
62
|
+
if (!inner.querySelector(".c-header__actions")) {
|
|
63
|
+
const actions = document.createElement("div");
|
|
64
|
+
actions.className = "c-header__actions";
|
|
65
|
+
inner.appendChild(actions);
|
|
66
|
+
}
|
|
67
|
+
// Mobile toggle: below 60rem the sheet hides .c-header__nav; toggle is the way. Created only when nav exists, controls it by id, starts closed to match CSS. R31-150: i-menu (hamburger) now that the glyph is in the sprite.
|
|
68
|
+
const navEl = inner.querySelector(".c-header__nav");
|
|
69
|
+
if (navEl) {
|
|
70
|
+
// A page may carry two headers; fixed id makes both toggles point at first nav in document order. Each generated nav gets its own id.
|
|
71
|
+
if (!navEl.id) navEl.id = contourId("header-nav");
|
|
72
|
+
const actions = inner.querySelector(".c-header__actions");
|
|
73
|
+
if (actions && !actions.querySelector(".c-header__toggle")) {
|
|
74
|
+
const toggle = document.createElement("button");
|
|
75
|
+
toggle.type = "button";
|
|
76
|
+
toggle.className = "c-header__toggle";
|
|
77
|
+
toggle.setAttribute("aria-label", labelText(this, "toggle-navigation", "Toggle navigation"));
|
|
78
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
79
|
+
toggle.setAttribute("aria-controls", navEl.id);
|
|
80
|
+
setHTML(toggle, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-menu" /></svg>');
|
|
81
|
+
actions.appendChild(toggle);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (inner.parentNode !== this) this.appendChild(inner);
|
|
85
|
+
}
|
|
86
|
+
enhance() {
|
|
87
|
+
if (this._wiredHeader) return;
|
|
88
|
+
this._wiredHeader = true;
|
|
89
|
+
// Scroll state: past threshold header gains c-header--scrolled so sheet can raise it.
|
|
90
|
+
const update = () => {
|
|
91
|
+
const y = window.scrollY || document.documentElement.scrollTop || 0;
|
|
92
|
+
this.classList.toggle("c-header--scrolled", y > 8);
|
|
93
|
+
};
|
|
94
|
+
update();
|
|
95
|
+
window.addEventListener("scroll", update, { passive: true });
|
|
96
|
+
onDispose(this, () => window.removeEventListener("scroll", update));
|
|
97
|
+
// Toggle: button shows/hides nav under 60rem and keeps aria-expanded in step. Close on Escape while open.
|
|
98
|
+
this.addEventListener("click", (e) => {
|
|
99
|
+
const toggle = e.target && e.target.closest ? e.target.closest(".c-header__toggle") : null;
|
|
100
|
+
if (!toggle || !this.contains(toggle)) return;
|
|
101
|
+
const nav = this.querySelector("#" + CSS.escape(toggle.getAttribute("aria-controls") || ""));
|
|
102
|
+
if (!nav) return;
|
|
103
|
+
const open = nav.classList.toggle("is-open");
|
|
104
|
+
toggle.setAttribute("aria-expanded", String(open));
|
|
105
|
+
this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { open } }));
|
|
106
|
+
});
|
|
107
|
+
this.addEventListener("keydown", (e) => {
|
|
108
|
+
if (e.key !== "Escape") return;
|
|
109
|
+
const toggle = this.querySelector(".c-header__toggle");
|
|
110
|
+
const nav = toggle && this.querySelector("#" + CSS.escape(toggle.getAttribute("aria-controls") || ""));
|
|
111
|
+
if (!toggle || !nav || !nav.classList.contains("is-open")) return;
|
|
112
|
+
nav.classList.remove("is-open");
|
|
113
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
define("contour-header", ContourHeader);
|
|
118
|
+
class ContourFooter extends ContourBase {
|
|
119
|
+
static get observed() { return ["brand", "note", "links", "cols", "heading"]; }
|
|
120
|
+
static get properties() { return { brand: { attribute: "brand" }, note: { attribute: "note" }, links: { attribute: "links" }, cols: { attribute: "cols" } }; }
|
|
121
|
+
render() {
|
|
122
|
+
this.classList.add("c-footer");
|
|
123
|
+
// A footer is a contentinfo landmark: the APG names it, and a reader who
|
|
124
|
+
// jumps to the landmark list expects the page's footer there.
|
|
125
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "contentinfo");
|
|
126
|
+
const brand = this.getAttribute("brand");
|
|
127
|
+
if (brand) {
|
|
128
|
+
const b = this.ensure(".c-footer__brand", () => { const el = document.createElement("div"); el.className = "c-footer__brand"; return el; });
|
|
129
|
+
b.textContent = brand;
|
|
130
|
+
} else {
|
|
131
|
+
const b = this.querySelector(".c-footer__brand");
|
|
132
|
+
if (b) b.remove();
|
|
133
|
+
}
|
|
134
|
+
const note = this.getAttribute("note");
|
|
135
|
+
if (note) {
|
|
136
|
+
const n = this.ensure(".c-footer__note", () => { const el = document.createElement("p"); el.className = "c-footer__note"; return el; });
|
|
137
|
+
n.textContent = note;
|
|
138
|
+
} else {
|
|
139
|
+
const n = this.querySelector(".c-footer__note");
|
|
140
|
+
if (n) n.remove();
|
|
141
|
+
}
|
|
142
|
+
const links = this.getAttribute("links");
|
|
143
|
+
if (links) {
|
|
144
|
+
try {
|
|
145
|
+
const parsed = JSON.parse(links);
|
|
146
|
+
const wrap = this.ensure(".c-footer__links", () => { const el = document.createElement("div"); el.className = "c-footer__links"; return el; });
|
|
147
|
+
wrap.innerHTML = "";
|
|
148
|
+
parsed.forEach((l) => {
|
|
149
|
+
const a = document.createElement("a");
|
|
150
|
+
a.href = safeHref(typeof l === "string" ? "#" : (l.href || "#"));
|
|
151
|
+
a.textContent = typeof l === "string" ? l : (l.label || l);
|
|
152
|
+
wrap.appendChild(a);
|
|
153
|
+
});
|
|
154
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
155
|
+
} else {
|
|
156
|
+
const w = this.querySelector(".c-footer__links");
|
|
157
|
+
if (w) w.remove();
|
|
158
|
+
}
|
|
159
|
+
const cols = this.getAttribute("cols");
|
|
160
|
+
if (cols) {
|
|
161
|
+
try {
|
|
162
|
+
const parsed = JSON.parse(cols);
|
|
163
|
+
// Remove previous cols
|
|
164
|
+
this.querySelectorAll(".c-footer__col").forEach((c) => c.remove());
|
|
165
|
+
parsed.forEach((col) => {
|
|
166
|
+
const c = document.createElement("div");
|
|
167
|
+
c.className = "c-footer__col";
|
|
168
|
+
if (col.title) {
|
|
169
|
+
const h = document.createElement(headingTag(this, "h3"));
|
|
170
|
+
h.textContent = col.title;
|
|
171
|
+
c.appendChild(h);
|
|
172
|
+
}
|
|
173
|
+
(col.links || []).forEach((l) => {
|
|
174
|
+
const a = document.createElement("a");
|
|
175
|
+
a.href = safeHref(typeof l === "string" ? "#" : (l.href || "#"));
|
|
176
|
+
a.textContent = typeof l === "string" ? l : (l.label || l);
|
|
177
|
+
c.appendChild(a);
|
|
178
|
+
});
|
|
179
|
+
this.appendChild(c);
|
|
180
|
+
});
|
|
181
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
182
|
+
} else {
|
|
183
|
+
this.querySelectorAll(".c-footer__col").forEach((c) => c.remove());
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
define("contour-footer", ContourFooter);
|
|
188
|
+
class ContourSchemeToggle extends ContourBase {
|
|
189
|
+
static get observed() { return []; }
|
|
190
|
+
// One persistence contract with ds.js; meta element is source of truth.
|
|
191
|
+
_stored() {
|
|
192
|
+
try { return localStorage.getItem("contour-scheme") ?? "light dark"; } catch (e) { return "light dark"; }
|
|
193
|
+
}
|
|
194
|
+
_resolved() {
|
|
195
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
196
|
+
}
|
|
197
|
+
_rendered() {
|
|
198
|
+
const stored = this._stored();
|
|
199
|
+
return stored === "light dark" ? this._resolved() : stored;
|
|
200
|
+
}
|
|
201
|
+
render() {
|
|
202
|
+
this.classList.add("c-scheme-toggle");
|
|
203
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "button");
|
|
204
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
205
|
+
// The text glyph is the standalone fallback; when the author slots the
|
|
206
|
+
// svg pair (__icons) the CSS shows the active svg and no glyph is added.
|
|
207
|
+
if (!this.querySelector(".c-scheme-toggle__icons") && !this.querySelector(".c-scheme-toggle__glyph")) {
|
|
208
|
+
const glyph = document.createElement("span");
|
|
209
|
+
glyph.className = "c-scheme-toggle__glyph";
|
|
210
|
+
glyph.setAttribute("aria-hidden", "true");
|
|
211
|
+
this.appendChild(glyph);
|
|
212
|
+
}
|
|
213
|
+
this._sync();
|
|
214
|
+
}
|
|
215
|
+
_sync() {
|
|
216
|
+
const rendered = this._rendered();
|
|
217
|
+
const target = rendered === "dark" ? "light" : "dark";
|
|
218
|
+
this.setAttribute("aria-pressed", String(rendered === "dark"));
|
|
219
|
+
this.setAttribute("aria-label", target === "dark" ? "Switch to dark theme" : "Switch to light theme");
|
|
220
|
+
const glyph = this.querySelector(".c-scheme-toggle__glyph");
|
|
221
|
+
// Target-action convention: the glyph is what a click switches TO, matching
|
|
222
|
+
// the svg pair (moon in light mode, sun in dark mode) and the aria-label.
|
|
223
|
+
if (glyph) glyph.textContent = rendered === "dark" ? "☀" : "☾";
|
|
224
|
+
}
|
|
225
|
+
_apply(value) {
|
|
226
|
+
const root = document.documentElement;
|
|
227
|
+
const rendered = value === "light dark" ? this._resolved() : value;
|
|
228
|
+
root.classList.add("is-theme-switching");
|
|
229
|
+
const meta = document.querySelector('meta[name="color-scheme"]');
|
|
230
|
+
if (meta) meta.setAttribute("content", value);
|
|
231
|
+
// data-theme stays published as a consumer hook, resolved to a concrete
|
|
232
|
+
// scheme; the cascade itself reads the meta element, not this attribute.
|
|
233
|
+
root.setAttribute("data-theme", rendered);
|
|
234
|
+
try {
|
|
235
|
+
if (value === "light dark") localStorage.removeItem("contour-scheme");
|
|
236
|
+
else localStorage.setItem("contour-scheme", value);
|
|
237
|
+
} catch (e) {}
|
|
238
|
+
requestAnimationFrame(() => requestAnimationFrame(() => root.classList.remove("is-theme-switching")));
|
|
239
|
+
this._sync();
|
|
240
|
+
this.dispatchEvent(new CustomEvent("contour:theme-change", { detail: { theme: rendered }, bubbles: true, composed: true }));
|
|
241
|
+
}
|
|
242
|
+
enhance() {
|
|
243
|
+
if (this._wiredScheme) return;
|
|
244
|
+
this._wiredScheme = true;
|
|
245
|
+
this.addEventListener("click", () => {
|
|
246
|
+
const target = this._rendered() === "dark" ? "light" : "dark";
|
|
247
|
+
this._apply(target === this._resolved() ? "light dark" : target);
|
|
248
|
+
});
|
|
249
|
+
this.addEventListener("keydown", (e) => {
|
|
250
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
this.click();
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
256
|
+
const onSystemChange = () => {
|
|
257
|
+
if (this._stored() === "light dark") {
|
|
258
|
+
document.documentElement.setAttribute("data-theme", this._resolved());
|
|
259
|
+
this._sync();
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
if (mq.addEventListener) mq.addEventListener("change", onSystemChange);
|
|
263
|
+
// Migrate the pre-R25 `contour-theme` key once, then restore the stored
|
|
264
|
+
// override so a standalone consumer page (no ds.js) lands on its theme.
|
|
265
|
+
try {
|
|
266
|
+
const legacy = localStorage.getItem("contour-theme");
|
|
267
|
+
if (legacy) {
|
|
268
|
+
if (!localStorage.getItem("contour-scheme") && (legacy === "dark" || legacy === "light")) localStorage.setItem("contour-scheme", legacy);
|
|
269
|
+
localStorage.removeItem("contour-theme");
|
|
270
|
+
}
|
|
271
|
+
} catch (e) {}
|
|
272
|
+
const stored = this._stored();
|
|
273
|
+
if (stored !== "light dark") this._apply(stored);
|
|
274
|
+
else this._sync();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
define("contour-scheme-toggle", ContourSchemeToggle);
|
|
278
|
+
class ContourSidebar extends ContourBase {
|
|
279
|
+
static get observed() { return ["title", "items", "collapsed"]; }
|
|
280
|
+
static get properties() { return { title: { attribute: "title" }, items: { attribute: "items" }, collapsed: { attribute: "collapsed", type: Boolean } }; }
|
|
281
|
+
render() {
|
|
282
|
+
this.classList.add("c-sidebar");
|
|
283
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "navigation");
|
|
284
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Sidebar");
|
|
285
|
+
// R24-74: collapsed state as a data-attribute, not a --modifier class, so
|
|
286
|
+
// the layout ratchet (check-layout) does not read it as a new primitive.
|
|
287
|
+
if (this.hasAttribute("collapsed")) this.setAttribute("data-collapsed", ""); else this.removeAttribute("data-collapsed");
|
|
288
|
+
const title = this.getAttribute("title");
|
|
289
|
+
if (title) {
|
|
290
|
+
const t = this.ensure(".c-sidebar__title", () => { const el = document.createElement("div"); el.className = "c-sidebar__title"; return el; });
|
|
291
|
+
t.textContent = title;
|
|
292
|
+
} else {
|
|
293
|
+
const t = this.querySelector(".c-sidebar__title");
|
|
294
|
+
if (t) t.remove();
|
|
295
|
+
}
|
|
296
|
+
// R24-74: collapse toggle — a real control that narrows the sidebar.
|
|
297
|
+
const collapsed = this.hasAttribute("collapsed");
|
|
298
|
+
const t = this.ensure(".c-sidebar__toggle", () => {
|
|
299
|
+
const el = document.createElement("button");
|
|
300
|
+
el.className = "c-sidebar__toggle";
|
|
301
|
+
el.type = "button";
|
|
302
|
+
return el;
|
|
303
|
+
});
|
|
304
|
+
t.setAttribute("aria-label", collapsed ? "Expand sidebar" : "Collapse sidebar");
|
|
305
|
+
t.setAttribute("aria-pressed", String(collapsed));
|
|
306
|
+
setHTML(t, collapsed
|
|
307
|
+
? '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>'
|
|
308
|
+
: '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-down" /></svg>');
|
|
309
|
+
const items = this.getAttribute("items");
|
|
310
|
+
if (items) {
|
|
311
|
+
try {
|
|
312
|
+
const parsed = JSON.parse(items);
|
|
313
|
+
const nav = this.ensure("nav.c-sidebar__nav", () => { const el = document.createElement("nav"); el.className = "c-sidebar__nav"; return el; });
|
|
314
|
+
nav.innerHTML = "";
|
|
315
|
+
parsed.forEach((it, i) => {
|
|
316
|
+
const a = document.createElement("a");
|
|
317
|
+
a.className = "c-sidebar__link";
|
|
318
|
+
a.href = safeHref((it && it.href) || "#");
|
|
319
|
+
a.textContent = (it && (it.label || it)) || "";
|
|
320
|
+
a.tabIndex = i === 0 ? 0 : -1;
|
|
321
|
+
nav.appendChild(a);
|
|
322
|
+
});
|
|
323
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
enhance() {
|
|
327
|
+
if (this._wiredSidebar) return;
|
|
328
|
+
this._wiredSidebar = true;
|
|
329
|
+
this.addEventListener("click", (e) => {
|
|
330
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-sidebar__toggle") : null;
|
|
331
|
+
if (!btn || !this.contains(btn)) return;
|
|
332
|
+
this.toggleAttribute("collapsed");
|
|
333
|
+
this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { collapsed: this.hasAttribute("collapsed") } }));
|
|
334
|
+
});
|
|
335
|
+
// Keyboard: roving tabindex over sidebar links, Enter follows the link.
|
|
336
|
+
this.addEventListener("keydown", (e) => {
|
|
337
|
+
const nav = this.querySelector("nav.c-sidebar__nav");
|
|
338
|
+
if (!nav) return;
|
|
339
|
+
const links = Array.from(nav.querySelectorAll(".c-sidebar__link"));
|
|
340
|
+
if (!links.length) return;
|
|
341
|
+
navKey(e, links, { wrap: true, homeEnd: true, onNavigate: (i) => { links.forEach((l, j) => l.tabIndex = j === i ? 0 : -1); }, onKey: (k) => { if (k === "Enter") { const a = document.activeElement; if (a) { e.preventDefault(); a.click(); } } } });
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
define("contour-sidebar", ContourSidebar);
|
|
346
|
+
class ContourToolbar extends ContourBase {
|
|
347
|
+
static get observed() { return ["title", "actions", "overflow"]; }
|
|
348
|
+
static get properties() { return { title: { attribute: "title" }, actions: { attribute: "actions" }, overflow: { attribute: "overflow", type: Number } }; }
|
|
349
|
+
render() {
|
|
350
|
+
this.classList.add("c-toolbar");
|
|
351
|
+
const title = this.getAttribute("title");
|
|
352
|
+
this.setAttribute("role", "toolbar");
|
|
353
|
+
if (title) this.setAttribute("aria-label", title);
|
|
354
|
+
const actions = this.getAttribute("actions");
|
|
355
|
+
if (actions) {
|
|
356
|
+
try {
|
|
357
|
+
const parsed = JSON.parse(actions);
|
|
358
|
+
const limit = this.overflow && this.overflow > 0 ? this.overflow : parsed.length;
|
|
359
|
+
const visible = parsed.slice(0, limit);
|
|
360
|
+
const excess = parsed.slice(limit);
|
|
361
|
+
visible.forEach((a, i) => {
|
|
362
|
+
const btn = document.createElement("button");
|
|
363
|
+
btn.className = "c-toolbar__btn";
|
|
364
|
+
btn.type = "button";
|
|
365
|
+
btn.tabIndex = i === 0 ? 0 : -1;
|
|
366
|
+
btn.textContent = typeof a === "string" ? a : (a.label || a);
|
|
367
|
+
// R24-41: text actions size to content; icon-only keep the fixed square.
|
|
368
|
+
if (typeof a === "string" || (a && a.label)) btn.classList.add("c-toolbar__btn--text");
|
|
369
|
+
this.appendChild(btn);
|
|
370
|
+
});
|
|
371
|
+
if (excess.length) {
|
|
372
|
+
const wrap = document.createElement("div");
|
|
373
|
+
wrap.className = "c-toolbar__overflow";
|
|
374
|
+
const btn = document.createElement("button");
|
|
375
|
+
btn.className = "c-toolbar__btn c-toolbar__overflow-btn";
|
|
376
|
+
btn.type = "button";
|
|
377
|
+
btn.tabIndex = -1;
|
|
378
|
+
btn.setAttribute("aria-haspopup", "menu");
|
|
379
|
+
btn.setAttribute("aria-expanded", "false");
|
|
380
|
+
btn.textContent = "…";
|
|
381
|
+
btn.setAttribute("aria-label", labelText(this, "more-options", "More options"));
|
|
382
|
+
wrap.appendChild(btn);
|
|
383
|
+
const menu = document.createElement("div");
|
|
384
|
+
menu.className = "c-toolbar__overflow-menu";
|
|
385
|
+
menu.setAttribute("role", "menu");
|
|
386
|
+
menu.setAttribute("hidden", "");
|
|
387
|
+
excess.forEach((a) => {
|
|
388
|
+
const mbtn = document.createElement("button");
|
|
389
|
+
mbtn.className = "c-toolbar__btn";
|
|
390
|
+
mbtn.type = "button";
|
|
391
|
+
mbtn.setAttribute("role", "menuitem");
|
|
392
|
+
mbtn.textContent = typeof a === "string" ? a : (a.label || a);
|
|
393
|
+
menu.appendChild(mbtn);
|
|
394
|
+
});
|
|
395
|
+
wrap.appendChild(menu);
|
|
396
|
+
this.appendChild(wrap);
|
|
397
|
+
}
|
|
398
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
enhance() {
|
|
402
|
+
if (this._wiredToolbar) return;
|
|
403
|
+
this._wiredToolbar = true;
|
|
404
|
+
this.addEventListener("click", (e) => {
|
|
405
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-toolbar__overflow-btn") : null;
|
|
406
|
+
if (btn && this.contains(btn)) {
|
|
407
|
+
const menu = btn.parentElement && btn.parentElement.querySelector(".c-toolbar__overflow-menu");
|
|
408
|
+
if (menu) {
|
|
409
|
+
const open = menu.hasAttribute("hidden");
|
|
410
|
+
if (open) menu.removeAttribute("hidden"); else menu.setAttribute("hidden", "");
|
|
411
|
+
btn.setAttribute("aria-expanded", String(open));
|
|
412
|
+
// R24-41: one tab stop in the overflow menu (first item), none on the
|
|
413
|
+
// overflow button while the menu is open.
|
|
414
|
+
btn.tabIndex = open ? -1 : 0;
|
|
415
|
+
const items = Array.from(menu.querySelectorAll("[role='menuitem']"));
|
|
416
|
+
items.forEach((it, j) => it.tabIndex = open ? (j === 0 ? 0 : -1) : -1);
|
|
417
|
+
if (open) { try { items[0]?.focus(); } catch (err) {} }
|
|
418
|
+
}
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const actionBtn = e.target && e.target.closest ? e.target.closest(".c-toolbar__btn") : null;
|
|
422
|
+
if (actionBtn && this.contains(actionBtn)) {
|
|
423
|
+
this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true, detail: { label: actionBtn.textContent.trim() } }));
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
// Roving tabindex over visible toolbar buttons; overflow menu is roving too.
|
|
427
|
+
this.addEventListener("keydown", (e) => {
|
|
428
|
+
// R24-41: Escape closes the overflow menu.
|
|
429
|
+
if (e.key === "Escape") {
|
|
430
|
+
const openMenu = this.querySelector(".c-toolbar__overflow-menu:not([hidden])");
|
|
431
|
+
if (openMenu) {
|
|
432
|
+
openMenu.setAttribute("hidden", "");
|
|
433
|
+
const btn = this.querySelector(".c-toolbar__overflow-btn");
|
|
434
|
+
if (btn) { btn.setAttribute("aria-expanded", "false"); btn.tabIndex = 0; btn.focus(); }
|
|
435
|
+
e.preventDefault();
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
const openMenu = this.querySelector(".c-toolbar__overflow-menu:not([hidden])");
|
|
440
|
+
if (openMenu) {
|
|
441
|
+
const items = Array.from(openMenu.querySelectorAll("[role='menuitem']"));
|
|
442
|
+
if (items.length) {
|
|
443
|
+
navKey(e, items, {
|
|
444
|
+
wrap: true,
|
|
445
|
+
homeEnd: true,
|
|
446
|
+
onNavigate: (i) => { items.forEach((it, j) => it.tabIndex = j === i ? 0 : -1); },
|
|
447
|
+
onKey: (k) => { if (k === "Enter" || k === " ") { const b = document.activeElement; if (b) { e.preventDefault(); b.click(); } } }
|
|
448
|
+
});
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
const btns = Array.from(this.querySelectorAll(":scope > .c-toolbar__btn"));
|
|
453
|
+
if (!btns.length) return;
|
|
454
|
+
navKey(e, btns, {
|
|
455
|
+
wrap: true,
|
|
456
|
+
homeEnd: true,
|
|
457
|
+
onNavigate: (i) => { btns.forEach((b, j) => b.tabIndex = j === i ? 0 : -1); },
|
|
458
|
+
onKey: (k) => {
|
|
459
|
+
if (k === "Enter" || k === " ") {
|
|
460
|
+
const b = document.activeElement;
|
|
461
|
+
if (b) {
|
|
462
|
+
e.preventDefault();
|
|
463
|
+
if (b.classList.contains("c-toolbar__overflow-btn")) {
|
|
464
|
+
const menu = b.parentElement && b.parentElement.querySelector(".c-toolbar__overflow-menu");
|
|
465
|
+
if (menu) {
|
|
466
|
+
const open = menu.hasAttribute("hidden");
|
|
467
|
+
if (open) menu.removeAttribute("hidden"); else menu.setAttribute("hidden", "");
|
|
468
|
+
b.setAttribute("aria-expanded", String(open));
|
|
469
|
+
b.tabIndex = open ? -1 : 0;
|
|
470
|
+
const items = Array.from(menu.querySelectorAll("[role='menuitem']"));
|
|
471
|
+
items.forEach((it, j) => it.tabIndex = open ? (j === 0 ? 0 : -1) : -1);
|
|
472
|
+
if (open) { try { items[0]?.focus(); } catch (err) {} }
|
|
473
|
+
}
|
|
474
|
+
} else {
|
|
475
|
+
b.click();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
// R24-41: outside-click closes the overflow menu.
|
|
483
|
+
this.addEventListener("focusout", (e) => {
|
|
484
|
+
if (!this.contains(e.relatedTarget)) {
|
|
485
|
+
const openMenu = this.querySelector(".c-toolbar__overflow-menu:not([hidden])");
|
|
486
|
+
if (openMenu) {
|
|
487
|
+
openMenu.setAttribute("hidden", "");
|
|
488
|
+
const btn = this.querySelector(".c-toolbar__overflow-btn");
|
|
489
|
+
if (btn) btn.setAttribute("aria-expanded", "false");
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
define("contour-toolbar", ContourToolbar);
|