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,133 @@
|
|
|
1
|
+
import { ContourBase, define, onDispose, formatValue, contourId, navKey, isRtl, cssLength , safeColor, warnBadJson, labelText } from './core.mjs';
|
|
2
|
+
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates, remoteInvalidate, watchViewport, parseArrayAttr, stateLabel } from './states.mjs';
|
|
3
|
+
import { donutSlices, barRects, smoothPath, polylinePoints, contourPaths } from './svg.mjs';
|
|
4
|
+
import { paintDonutGlyph, paintSparklineGlyph, paintPurityRing } from './glyph.mjs';
|
|
5
|
+
|
|
6
|
+
// R31-58: canvas fillStyle cannot resolve var(), so resolve the token to a
|
|
7
|
+
// concrete colour here. An explicit `color` attribute wins; otherwise read the
|
|
8
|
+
// design token off the host; otherwise the neutral fallback.
|
|
9
|
+
function tokenColor(host, attr, token, fallback) {
|
|
10
|
+
const explicit = safeColor(host.getAttribute(attr));
|
|
11
|
+
if (explicit) return explicit;
|
|
12
|
+
try {
|
|
13
|
+
const v = getComputedStyle(host).getPropertyValue(token).trim();
|
|
14
|
+
if (v) return v;
|
|
15
|
+
} catch (e) { /* not connected / no computed style */ }
|
|
16
|
+
return fallback;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Donut Glyph: canvas-based glyph-scale donut for MapLibre symbol layers.
|
|
21
|
+
* Fixed 24–32 px sprite, no DOM overhead, no labels, solid fill only.
|
|
22
|
+
* Attributes: `size`, `value`, `color`, `stroke-width`, `bg-color`.
|
|
23
|
+
*/
|
|
24
|
+
class ContourDonutGlyph extends ContourBase {
|
|
25
|
+
static get observed() { return ["size", "value", "color", "stroke-width", "bg-color", "empty", "loading", "error", "cache-key", "no-cache", "retry", "skeleton", "src"]; }
|
|
26
|
+
static get properties() { return { size: { attribute: "size" }, value: { attribute: "value" }, color: { attribute: "color" }, strokeWidth: { attribute: "stroke-width" }, bgColor: { attribute: "bg-color" } }; }
|
|
27
|
+
render() {
|
|
28
|
+
this.classList.add("c-donut-glyph");
|
|
29
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
30
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "donut-glyph", "Donut glyph"));
|
|
31
|
+
wireStates(this);
|
|
32
|
+
if (renderStates(this, "donut-glyph")) return;
|
|
33
|
+
const old = this.querySelector("canvas");
|
|
34
|
+
if (old) old.remove();
|
|
35
|
+
const size = Number(this.getAttribute("size")) || 24;
|
|
36
|
+
const canvas = document.createElement("canvas");
|
|
37
|
+
canvas.width = size;
|
|
38
|
+
canvas.height = size;
|
|
39
|
+
canvas.style.inlineSize = size + "px";
|
|
40
|
+
canvas.style.blockSize = size + "px";
|
|
41
|
+
const ctx = canvas.getContext("2d");
|
|
42
|
+
if (!ctx) return;
|
|
43
|
+
paintDonutGlyph(ctx, {
|
|
44
|
+
size,
|
|
45
|
+
value: Number(this.getAttribute("value")) || 0,
|
|
46
|
+
color: tokenColor(this, "color", "--color-data", "#1f77b4"),
|
|
47
|
+
strokeWidth: this.getAttribute("stroke-width") ? Number(this.getAttribute("stroke-width")) : undefined,
|
|
48
|
+
bgColor: this.getAttribute("bg-color") || "transparent",
|
|
49
|
+
});
|
|
50
|
+
this.appendChild(canvas);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
define("contour-donut-glyph", ContourDonutGlyph);
|
|
54
|
+
/**
|
|
55
|
+
* Sparkline Glyph: canvas-based glyph-scale sparkline for MapLibre symbol layers.
|
|
56
|
+
* Fixed 24–32 px sprite, no axes, no labels.
|
|
57
|
+
* Attributes: `size`, `points`, `color`, `stroke-width`, `bg-color`.
|
|
58
|
+
*/
|
|
59
|
+
class ContourSparklineGlyph extends ContourBase {
|
|
60
|
+
static get observed() { return ["size", "points", "color", "stroke-width", "bg-color", "empty", "loading", "error", "cache-key", "no-cache", "retry", "skeleton", "src"]; }
|
|
61
|
+
static get properties() { return { size: { attribute: "size" }, points: { attribute: "points" }, color: { attribute: "color" }, strokeWidth: { attribute: "stroke-width" }, bgColor: { attribute: "bg-color" } }; }
|
|
62
|
+
render() {
|
|
63
|
+
this.classList.add("c-sparkline-glyph");
|
|
64
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
65
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "sparkline-glyph", "Sparkline glyph"));
|
|
66
|
+
wireStates(this);
|
|
67
|
+
if (renderStates(this, "sparkline-glyph")) return;
|
|
68
|
+
const old = this.querySelector("canvas");
|
|
69
|
+
if (old) old.remove();
|
|
70
|
+
const size = Number(this.getAttribute("size")) || 24;
|
|
71
|
+
const canvas = document.createElement("canvas");
|
|
72
|
+
canvas.width = size;
|
|
73
|
+
canvas.height = size;
|
|
74
|
+
canvas.style.inlineSize = size + "px";
|
|
75
|
+
canvas.style.blockSize = size + "px";
|
|
76
|
+
const ctx = canvas.getContext("2d");
|
|
77
|
+
if (!ctx) return;
|
|
78
|
+
let values = [];
|
|
79
|
+
const pAttr = this.getAttribute("points");
|
|
80
|
+
if (pAttr) {
|
|
81
|
+
try {
|
|
82
|
+
const parsed = JSON.parse(pAttr);
|
|
83
|
+
values = Array.isArray(parsed) ? parsed.filter(Number.isFinite) : [];
|
|
84
|
+
} catch (e) { warnBadJson(this, "points", e); }
|
|
85
|
+
}
|
|
86
|
+
paintSparklineGlyph(ctx, {
|
|
87
|
+
size,
|
|
88
|
+
values,
|
|
89
|
+
color: tokenColor(this, "color", "--color-data", "#1f77b4"),
|
|
90
|
+
strokeWidth: this.getAttribute("stroke-width") ? Number(this.getAttribute("stroke-width")) : undefined,
|
|
91
|
+
bgColor: this.getAttribute("bg-color") || "transparent",
|
|
92
|
+
});
|
|
93
|
+
this.appendChild(canvas);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
define("contour-sparkline-glyph", ContourSparklineGlyph);
|
|
97
|
+
/**
|
|
98
|
+
* Purity Ring: concentration/dominance encoding — filled arc = dominance
|
|
99
|
+
* (max / total, quantised to 8 buckets), hue = dominant category.
|
|
100
|
+
* Attributes: `size`, `hue`, `concentration`, `color`, `uncertainty`, `time-step`, `time-steps`.
|
|
101
|
+
*/
|
|
102
|
+
class ContourPurityRing extends ContourBase {
|
|
103
|
+
static get observed() { return ["size", "hue", "concentration", "color", "uncertainty", "time-step", "time-steps", "empty", "loading", "error", "cache-key", "no-cache", "retry", "skeleton", "src"]; }
|
|
104
|
+
static get properties() { return { size: { attribute: "size" }, hue: { attribute: "hue" }, concentration: { attribute: "concentration" }, color: { attribute: "color" }, uncertainty: { attribute: "uncertainty" }, timeStep: { attribute: "time-step" }, timeSteps: { attribute: "time-steps" } }; }
|
|
105
|
+
render() {
|
|
106
|
+
this.classList.add("c-purity-ring");
|
|
107
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
108
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "purity-ring", "Purity ring"));
|
|
109
|
+
wireStates(this);
|
|
110
|
+
if (renderStates(this, "purity-ring")) return;
|
|
111
|
+
const old = this.querySelector("canvas");
|
|
112
|
+
if (old) old.remove();
|
|
113
|
+
const size = Number(this.getAttribute("size")) || 32;
|
|
114
|
+
const canvas = document.createElement("canvas");
|
|
115
|
+
canvas.width = size;
|
|
116
|
+
canvas.height = size;
|
|
117
|
+
canvas.style.inlineSize = size + "px";
|
|
118
|
+
canvas.style.blockSize = size + "px";
|
|
119
|
+
const ctx = canvas.getContext("2d");
|
|
120
|
+
if (!ctx) return;
|
|
121
|
+
paintPurityRing(ctx, {
|
|
122
|
+
size,
|
|
123
|
+
hue: Number(this.getAttribute("hue")) || 0,
|
|
124
|
+
concentration: Number(this.getAttribute("concentration")) || 0,
|
|
125
|
+
color: tokenColor(this, "color", "--color-data", undefined),
|
|
126
|
+
uncertainty: Number(this.getAttribute("uncertainty")) || 0,
|
|
127
|
+
timeStep: this.getAttribute("time-step") ? Number(this.getAttribute("time-step")) : undefined,
|
|
128
|
+
timeSteps: this.getAttribute("time-steps") ? Number(this.getAttribute("time-steps")) : 4,
|
|
129
|
+
});
|
|
130
|
+
this.appendChild(canvas);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
define("contour-purity-ring", ContourPurityRing);
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { ContourBase, define, onDispose, formatValue, contourId, navKey, isRtl, cssLength , safeColor, warnBadJson, labelText } from './core.mjs';
|
|
2
|
+
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates, remoteInvalidate, watchViewport, parseArrayAttr, stateLabel } from './states.mjs';
|
|
3
|
+
import { donutSlices, barRects, smoothPath, polylinePoints, contourPaths } from './svg.mjs';
|
|
4
|
+
import { paintDonutGlyph, paintSparklineGlyph, paintPurityRing } from './glyph.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Legend: web component wrapper.
|
|
8
|
+
* Attributes: `title`, `ramp`, `scale`, `items`, `method`, `norm`, `selectable`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `glyphs`, `thresholds`, `breaks`, `no-data-color`, `size`, `table`, `classification`, `audit`, `continuous`, `ends`, `caption`.
|
|
9
|
+
*/
|
|
10
|
+
class ContourLegend extends ContourBase {
|
|
11
|
+
static get observed() { return ["title", "ramp", "scale", "items", "method", "norm", "selectable", "brownout", "brownout-level", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "glyphs", "thresholds", "breaks", "no-data-color", "no-data-label", "size", "table", "classification", "audit", "continuous", "ends", "caption", "graduated", "cache-key", "no-cache"]; }
|
|
12
|
+
static get properties() { return { title: { attribute: "title" }, ramp: { attribute: "ramp" }, scale: { attribute: "scale" }, items: { attribute: "items" }, method: { attribute: "method" }, norm: { attribute: "norm" }, selectable: { attribute: "selectable", type: Boolean }, src: { attribute: "src" }, graduated: { attribute: "graduated", type: Boolean } }; }
|
|
13
|
+
render() {
|
|
14
|
+
this.classList.add("c-legend");
|
|
15
|
+
const graduated = this.hasAttribute("graduated");
|
|
16
|
+
if (graduated) this.classList.add("c-legend--graduated");
|
|
17
|
+
const continuous = this.hasAttribute("continuous");
|
|
18
|
+
if (continuous || this.hasAttribute("selectable")) {
|
|
19
|
+
this.setAttribute("role", "group");
|
|
20
|
+
} else {
|
|
21
|
+
this.setAttribute("role", "list");
|
|
22
|
+
}
|
|
23
|
+
wireStates(this);
|
|
24
|
+
loadRemote(this, "items");
|
|
25
|
+
if (renderStates(this, "legend")) return;
|
|
26
|
+
// Selectable legends (BY-41): items become toggle buttons with aria-pressed; .c-legend--interactive rules apply.
|
|
27
|
+
const selectable = this.hasAttribute("selectable");
|
|
28
|
+
// R24-32: the sheet's `.c-legend--interactive` rules (hover, dim when
|
|
29
|
+
// pressed=false) never applied because the host never carried the class.
|
|
30
|
+
if (selectable) this.classList.add("c-legend--interactive");
|
|
31
|
+
else this.classList.remove("c-legend--interactive");
|
|
32
|
+
// Slotted content support: authored .c-legend__item children take
|
|
33
|
+
// precedence over the JSON `items` attribute.
|
|
34
|
+
const authoredLegendItems = Array.from(this.querySelectorAll(":scope > .c-legend__item"));
|
|
35
|
+
let items = remoteData(this, "items");
|
|
36
|
+
if (authoredLegendItems.length) {
|
|
37
|
+
items = JSON.stringify(authoredLegendItems.map((el) => {
|
|
38
|
+
const sw = el.querySelector(".c-legend__swatch");
|
|
39
|
+
const lbl = el.querySelector(".c-legend__label") || el;
|
|
40
|
+
return { label: lbl ? lbl.textContent.trim() : el.textContent.trim(), color: sw ? (sw.dataset && sw.dataset.color) || sw.style.background || undefined : undefined };
|
|
41
|
+
}));
|
|
42
|
+
authoredLegendItems.forEach((el) => el.remove());
|
|
43
|
+
}
|
|
44
|
+
const title = this.getAttribute("title");
|
|
45
|
+
if (title) {
|
|
46
|
+
const t = this.ensure(".c-legend__title", () => { const el = document.createElement("div"); el.className = "c-legend__title"; return el; });
|
|
47
|
+
t.textContent = title;
|
|
48
|
+
} else {
|
|
49
|
+
const t = this.querySelector(".c-legend__title");
|
|
50
|
+
if (t) t.remove();
|
|
51
|
+
}
|
|
52
|
+
if (items) {
|
|
53
|
+
try {
|
|
54
|
+
const parsed = JSON.parse(items);
|
|
55
|
+
const list = this.ensure(".c-legend__items", () => { const el = document.createElement("div"); el.className = "c-legend__items"; return el; });
|
|
56
|
+
if (this.hasAttribute("selectable")) {
|
|
57
|
+
list.setAttribute("role", "group");
|
|
58
|
+
} else {
|
|
59
|
+
// Host already has role="list"; inner container should be generic
|
|
60
|
+
list.removeAttribute("role");
|
|
61
|
+
}
|
|
62
|
+
if (title) list.setAttribute("aria-label", title);
|
|
63
|
+
list.innerHTML = "";
|
|
64
|
+
parsed.forEach((it) => {
|
|
65
|
+
const label = typeof it === "string" ? it : (it.label || String(it));
|
|
66
|
+
const key = typeof it === "string" ? it : (it.key || it.label || String(it));
|
|
67
|
+
const item = document.createElement("div");
|
|
68
|
+
item.className = "c-legend__item";
|
|
69
|
+
item.setAttribute("tabindex", "-1");
|
|
70
|
+
if (selectable) {
|
|
71
|
+
item.setAttribute("role", "button");
|
|
72
|
+
// Restore pressed state from host's set so re-render doesn't reset items to pressed=true; set tracks UNPRESSED keys.
|
|
73
|
+
const unpressed = this._legendUnpressed && this._legendUnpressed.has(key);
|
|
74
|
+
item.setAttribute("aria-pressed", unpressed ? "false" : "true");
|
|
75
|
+
item.dataset.key = key;
|
|
76
|
+
} else {
|
|
77
|
+
item.setAttribute("role", "listitem");
|
|
78
|
+
// aria-selected is not valid on role="listitem"; omit for non-selectable legends
|
|
79
|
+
}
|
|
80
|
+
const sw = document.createElement("span");
|
|
81
|
+
if (graduated) {
|
|
82
|
+
sw.className = "c-legend__swatch c-legend__swatch--graduated";
|
|
83
|
+
const gSize = it && it.size != null ? it.size : (it && it.value != null ? it.value : 1);
|
|
84
|
+
const sizePx = Math.max(6, Math.min(24, parseFloat(gSize) * 4));
|
|
85
|
+
sw.style.inlineSize = sizePx + "px";
|
|
86
|
+
sw.style.blockSize = sizePx + "px";
|
|
87
|
+
} else {
|
|
88
|
+
sw.className = "c-legend__swatch";
|
|
89
|
+
}
|
|
90
|
+
if (it && it.color) { const safe = safeColor(it.color); if (safe) { sw.style.background = safe; sw.dataset.color = safe; } }
|
|
91
|
+
item.appendChild(sw);
|
|
92
|
+
// graduated break label
|
|
93
|
+
if (graduated && (it && it.break != null)) {
|
|
94
|
+
const bl = document.createElement("span");
|
|
95
|
+
bl.className = "c-legend__break-label";
|
|
96
|
+
bl.textContent = String(it.break);
|
|
97
|
+
item.appendChild(bl);
|
|
98
|
+
}
|
|
99
|
+
// geometry glyph
|
|
100
|
+
const glyphShape = (it && (it.shape || it.marker || it.glyph)) || this.getAttribute("glyphs");
|
|
101
|
+
if (glyphShape) {
|
|
102
|
+
const g = document.createElement("span");
|
|
103
|
+
g.className = "c-legend__glyph";
|
|
104
|
+
g.setAttribute("part", "glyph");
|
|
105
|
+
g.textContent = glyphShape === "circle" ? "●" : glyphShape === "square" ? "■" : glyphShape === "triangle" ? "▲" : glyphShape === "diamond" ? "◆" : glyphShape === "star" ? "★" : String(glyphShape);
|
|
106
|
+
if (it && it.size != null) g.style.fontSize = (typeof it.size === "number" ? it.size + "px" : String(it.size));
|
|
107
|
+
item.appendChild(g);
|
|
108
|
+
}
|
|
109
|
+
// threshold break marker
|
|
110
|
+
if (it && it.break != null) {
|
|
111
|
+
const b = document.createElement("span");
|
|
112
|
+
b.className = "c-legend__break";
|
|
113
|
+
b.textContent = String(it.break);
|
|
114
|
+
item.appendChild(b);
|
|
115
|
+
}
|
|
116
|
+
const lbl = document.createElement("span");
|
|
117
|
+
// Bare item label addressable two ways: class for parser, data-label for toggle handler (glyph/break/caption never pollute identity).
|
|
118
|
+
lbl.className = "c-legend__label";
|
|
119
|
+
lbl.textContent = label;
|
|
120
|
+
item.dataset.label = label;
|
|
121
|
+
item.appendChild(lbl);
|
|
122
|
+
// caption (source-and-method line)
|
|
123
|
+
const caption = (typeof it === "object" && it) ? (it.caption || it.note || "") : "";
|
|
124
|
+
if (caption) {
|
|
125
|
+
const cap = document.createElement("span");
|
|
126
|
+
cap.className = "c-legend__caption";
|
|
127
|
+
cap.textContent = caption;
|
|
128
|
+
item.appendChild(cap);
|
|
129
|
+
}
|
|
130
|
+
// threshold mark: outline on swatches that begin at a threshold
|
|
131
|
+
if (it && (it.threshold || it.break != null)) {
|
|
132
|
+
sw.style.outline = "2px solid var(--color-border-strong)";
|
|
133
|
+
}
|
|
134
|
+
list.appendChild(item);
|
|
135
|
+
});
|
|
136
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
137
|
+
} else {
|
|
138
|
+
const list = this.querySelector(".c-legend__items");
|
|
139
|
+
if (list) list.remove();
|
|
140
|
+
const hasOther = this.getAttribute("title") || this.getAttribute("ramp") || this.getAttribute("scale") || this.getAttribute("method") || this.getAttribute("norm");
|
|
141
|
+
if (!hasOther) {
|
|
142
|
+
renderEmpty(this, "legend");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// caption as option description (aria-describedby), not part of name
|
|
146
|
+
const caption = this.getAttribute("caption");
|
|
147
|
+
let captionEl = this.querySelector(".c-legend__caption");
|
|
148
|
+
if (caption) {
|
|
149
|
+
if (!captionEl) { captionEl = document.createElement("span"); captionEl.className = "c-legend__caption"; this.appendChild(captionEl); }
|
|
150
|
+
captionEl.id = captionEl.id || contourId("legend-caption");
|
|
151
|
+
captionEl.textContent = caption;
|
|
152
|
+
captionEl.style.position = "absolute"; captionEl.style.width = "1px"; captionEl.style.height = "1px"; captionEl.style.overflow = "hidden"; captionEl.style.clip = "rect(0,0,0,0)";
|
|
153
|
+
} else if (captionEl) {
|
|
154
|
+
// The caption is going away, so an option that described itself with
|
|
155
|
+
// it would point at nothing. Drop the id from every option first.
|
|
156
|
+
const gone = captionEl.id;
|
|
157
|
+
captionEl.remove();
|
|
158
|
+
if (gone) this.querySelectorAll(".c-legend__item").forEach((o) => {
|
|
159
|
+
const db = (o.getAttribute("aria-describedby") || "").split(" ").filter((x) => x && x !== gone);
|
|
160
|
+
if (db.length) o.setAttribute("aria-describedby", db.join(" "));
|
|
161
|
+
else o.removeAttribute("aria-describedby");
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
// single tab stop: first option (selectable legends only). Non-selectable
|
|
165
|
+
// legend items are not tab stops (R24-87).
|
|
166
|
+
const _items = this.querySelector(".c-legend__items");
|
|
167
|
+
if (_items) {
|
|
168
|
+
const opts = Array.from(_items.querySelectorAll(".c-legend__item"));
|
|
169
|
+
if (selectable) opts.forEach((o, i) => o.setAttribute("tabindex", i === 0 ? "0" : "-1"));
|
|
170
|
+
else opts.forEach((o) => o.setAttribute("tabindex", "-1"));
|
|
171
|
+
if (captionEl) opts.forEach((o) => o.setAttribute("aria-describedby", captionEl.id));
|
|
172
|
+
}
|
|
173
|
+
// no-data entry from palette / no-data-color
|
|
174
|
+
const ndColor = this.getAttribute("no-data-color");
|
|
175
|
+
const ndLabel = this.getAttribute("no-data-label") || "No data";
|
|
176
|
+
if (ndColor) {
|
|
177
|
+
let nd = this.querySelector(".c-legend__no-data");
|
|
178
|
+
if (!nd) { nd = document.createElement("div"); nd.className = "c-legend__no-data"; this.appendChild(nd); }
|
|
179
|
+
nd.setAttribute("part", "no-data");
|
|
180
|
+
nd.setAttribute("aria-label", ndLabel);
|
|
181
|
+
nd.textContent = ndLabel;
|
|
182
|
+
const glyph = document.createElement("span");
|
|
183
|
+
glyph.className = "glyph";
|
|
184
|
+
glyph.style.background = safeColor(ndColor);
|
|
185
|
+
glyph.dataset.color = ndColor;
|
|
186
|
+
nd.prepend(glyph);
|
|
187
|
+
} else {
|
|
188
|
+
const nd = this.querySelector(".c-legend__no-data");
|
|
189
|
+
if (nd) nd.remove();
|
|
190
|
+
}
|
|
191
|
+
// audit notice
|
|
192
|
+
const audit = this.getAttribute("audit");
|
|
193
|
+
if (audit) {
|
|
194
|
+
const a = this.ensure(".c-legend__audit", () => { const el = document.createElement("div"); el.className = "c-legend__audit"; return el; });
|
|
195
|
+
a.textContent = audit;
|
|
196
|
+
} else {
|
|
197
|
+
const a = this.querySelector(".c-legend__audit");
|
|
198
|
+
if (a) a.remove();
|
|
199
|
+
}
|
|
200
|
+
// continuous variant: ramp with two ends labelled
|
|
201
|
+
if (this.hasAttribute("continuous")) {
|
|
202
|
+
const ends = this.getAttribute("ends");
|
|
203
|
+
let parsedEnds = null;
|
|
204
|
+
if (ends) { try { parsedEnds = JSON.parse(ends); } catch (e) { parsedEnds = ends.split(","); } }
|
|
205
|
+
if (Array.isArray(parsedEnds) && parsedEnds.length >= 2) {
|
|
206
|
+
const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
|
|
207
|
+
// labels
|
|
208
|
+
let left = this.querySelector(".c-legend__ramp-label--start");
|
|
209
|
+
if (!left) { left = document.createElement("span"); left.className = "c-legend__ramp-label c-legend__ramp-label--start"; r.appendChild(left); }
|
|
210
|
+
left.textContent = parsedEnds[0];
|
|
211
|
+
let right = this.querySelector(".c-legend__ramp-label--end");
|
|
212
|
+
if (!right) { right = document.createElement("span"); right.className = "c-legend__ramp-label c-legend__ramp-label--end"; r.appendChild(right); }
|
|
213
|
+
right.textContent = parsedEnds[parsedEnds.length - 1];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// size variant: differently-sized glyphs
|
|
217
|
+
const sizeAttr = this.getAttribute("size");
|
|
218
|
+
if (sizeAttr) {
|
|
219
|
+
const sc = this.ensure(".c-legend__size", () => { const el = document.createElement("div"); el.className = "c-legend__size"; return el; });
|
|
220
|
+
sc.textContent = sizeAttr;
|
|
221
|
+
} else {
|
|
222
|
+
const sc = this.querySelector(".c-legend__size");
|
|
223
|
+
if (sc) sc.remove();
|
|
224
|
+
}
|
|
225
|
+
// classification line
|
|
226
|
+
const classification = this.getAttribute("classification");
|
|
227
|
+
if (classification) {
|
|
228
|
+
const c = this.ensure(".c-legend__classification", () => { const el = document.createElement("div"); el.className = "c-legend__classification"; return el; });
|
|
229
|
+
c.textContent = classification;
|
|
230
|
+
} else {
|
|
231
|
+
const c = this.querySelector(".c-legend__classification");
|
|
232
|
+
if (c) c.remove();
|
|
233
|
+
}
|
|
234
|
+
// data table (collapsible)
|
|
235
|
+
const tableAttr = this.getAttribute("table");
|
|
236
|
+
if (tableAttr) {
|
|
237
|
+
let parsed = null;
|
|
238
|
+
try { parsed = JSON.parse(tableAttr); } catch (e) { parsed = null; }
|
|
239
|
+
if (Array.isArray(parsed)) {
|
|
240
|
+
let det = this.querySelector(".c-legend__table-wrap");
|
|
241
|
+
if (!det) { det = document.createElement("details"); det.className = "c-legend__table-wrap"; this.appendChild(det); }
|
|
242
|
+
det.innerHTML = "";
|
|
243
|
+
const sum = document.createElement("summary"); sum.textContent = labelText(this, "data-table", "Data table"); det.appendChild(sum);
|
|
244
|
+
const tbl = document.createElement("table"); tbl.className = "c-legend__table";
|
|
245
|
+
const tbody = document.createElement("tbody");
|
|
246
|
+
parsed.forEach((row) => {
|
|
247
|
+
const tr = document.createElement("tr");
|
|
248
|
+
const cells = Array.isArray(row) ? row : [row.label ?? row.key ?? "", row.value ?? ""];
|
|
249
|
+
cells.forEach((cell) => { const td = document.createElement("td"); td.textContent = cell; tr.appendChild(td); });
|
|
250
|
+
tbody.appendChild(tr);
|
|
251
|
+
});
|
|
252
|
+
tbl.appendChild(tbody);
|
|
253
|
+
det.appendChild(tbl);
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
const det = this.querySelector(".c-legend__table-wrap");
|
|
257
|
+
if (det) det.remove();
|
|
258
|
+
}
|
|
259
|
+
// size variant on glyphs
|
|
260
|
+
if (items) {
|
|
261
|
+
// apply size to glyphs already rendered? handled below via re-render not needed
|
|
262
|
+
}
|
|
263
|
+
const method = this.getAttribute("method");
|
|
264
|
+
if (method) {
|
|
265
|
+
const m = this.ensure(".c-legend__method", () => { const el = document.createElement("div"); el.className = "c-legend__method"; return el; });
|
|
266
|
+
m.textContent = method;
|
|
267
|
+
} else {
|
|
268
|
+
const m = this.querySelector(".c-legend__method");
|
|
269
|
+
if (m) m.remove();
|
|
270
|
+
}
|
|
271
|
+
const norm = this.getAttribute("norm");
|
|
272
|
+
if (norm) {
|
|
273
|
+
const n = this.ensure(".c-legend__norm", () => { const el = document.createElement("span"); el.className = "c-legend__norm"; return el; });
|
|
274
|
+
n.textContent = norm;
|
|
275
|
+
} else {
|
|
276
|
+
const n = this.querySelector(".c-legend__norm");
|
|
277
|
+
if (n) n.remove();
|
|
278
|
+
}
|
|
279
|
+
const ramp = this.getAttribute("ramp");
|
|
280
|
+
if (ramp) {
|
|
281
|
+
const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
|
|
282
|
+
r.style.background = safeColor(ramp);
|
|
283
|
+
// ramp routing: equal-width segments with break labels
|
|
284
|
+
const breaksAttr = this.getAttribute("breaks");
|
|
285
|
+
if (breaksAttr) {
|
|
286
|
+
let breaks = null;
|
|
287
|
+
try { breaks = JSON.parse(breaksAttr); } catch (e) { breaks = breaksAttr.split(",").map((s) => s.trim()); }
|
|
288
|
+
if (Array.isArray(breaks)) {
|
|
289
|
+
// remove old segments
|
|
290
|
+
Array.from(r.querySelectorAll(".c-legend__ramp-segment")).forEach((n) => n.remove());
|
|
291
|
+
breaks.forEach((b, i) => {
|
|
292
|
+
const seg = document.createElement("span");
|
|
293
|
+
seg.className = "c-legend__ramp-segment";
|
|
294
|
+
seg.style.flex = "1";
|
|
295
|
+
const lbl = document.createElement("span");
|
|
296
|
+
lbl.className = "c-legend__ramp-break";
|
|
297
|
+
lbl.textContent = String(b);
|
|
298
|
+
seg.appendChild(lbl);
|
|
299
|
+
r.appendChild(seg);
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
const r = this.querySelector(".c-legend__ramp");
|
|
305
|
+
if (r) r.remove();
|
|
306
|
+
}
|
|
307
|
+
const scale = this.getAttribute("scale");
|
|
308
|
+
if (scale) {
|
|
309
|
+
const sc = this.ensure(".c-legend__scale", () => { const el = document.createElement("div"); el.className = "c-legend__scale"; return el; });
|
|
310
|
+
sc.textContent = scale;
|
|
311
|
+
} else {
|
|
312
|
+
const sc = this.querySelector(".c-legend__scale");
|
|
313
|
+
if (sc) sc.remove();
|
|
314
|
+
}
|
|
315
|
+
// Legend shed: chrome (ramp/scale/caption) at ≥2; items at ≥3 (hidden not removed — toggle state survives for crossfilter).
|
|
316
|
+
const shedChrome = this.shed("chrome", 2);
|
|
317
|
+
const shedItems = this.shed("items", 3);
|
|
318
|
+
[".c-legend__ramp", ".c-legend__scale"].forEach((sel) => {
|
|
319
|
+
const n = this.querySelector(sel);
|
|
320
|
+
if (n) n.style.display = shedChrome ? "none" : "";
|
|
321
|
+
});
|
|
322
|
+
this.querySelectorAll(".c-legend__caption").forEach((n) => { n.style.display = shedChrome ? "none" : ""; });
|
|
323
|
+
const legendList = this.querySelector(".c-legend__items");
|
|
324
|
+
if (legendList) legendList.style.display = shedItems ? "none" : "";
|
|
325
|
+
}
|
|
326
|
+
enhance() {
|
|
327
|
+
if (this._wiredLegend) return;
|
|
328
|
+
this._wiredLegend = true;
|
|
329
|
+
this.addEventListener("click", (e) => {
|
|
330
|
+
// Read selectable PER-CLICK (not captured in enhance): handler uses current value if attribute added/removed later (LS-5 behavioral break).
|
|
331
|
+
if (!this.hasAttribute("selectable")) return;
|
|
332
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-legend__item") : null;
|
|
333
|
+
if (!btn || !this.contains(btn)) return;
|
|
334
|
+
const pressed = btn.getAttribute("aria-pressed") !== "true";
|
|
335
|
+
btn.setAttribute("aria-pressed", String(pressed));
|
|
336
|
+
// Persist pressed state on host so re-render restores it; set tracks UNPRESSED keys (empty = all pressed).
|
|
337
|
+
this._legendUnpressed = this._legendUnpressed || new Set();
|
|
338
|
+
const toggleKey = btn.dataset.key || btn.textContent.trim();
|
|
339
|
+
if (toggleKey) { if (pressed) this._legendUnpressed.delete(toggleKey); else this._legendUnpressed.add(toggleKey); }
|
|
340
|
+
const items = Array.from(this.querySelectorAll(".c-legend__item"));
|
|
341
|
+
const index = items.indexOf(btn);
|
|
342
|
+
// Event label is BARE item label (not whole textContent with glyph/break/caption); read from data-label or label span.
|
|
343
|
+
const labelSpan = btn.querySelector(".c-legend__label");
|
|
344
|
+
const bare = btn.dataset.label
|
|
345
|
+
|| (labelSpan ? labelSpan.textContent.trim() : btn.textContent.trim());
|
|
346
|
+
this.dispatchEvent(new CustomEvent("contour:legend-toggle", {
|
|
347
|
+
detail: { label: bare, key: btn.dataset.key || bare, pressed, index },
|
|
348
|
+
bubbles: true,
|
|
349
|
+
composed: true,
|
|
350
|
+
}));
|
|
351
|
+
this.dispatchEvent(new CustomEvent("contour:select", {
|
|
352
|
+
detail: { label: bare, key: btn.dataset.key || bare, value: btn.dataset.key || bare },
|
|
353
|
+
bubbles: true,
|
|
354
|
+
composed: true,
|
|
355
|
+
}));
|
|
356
|
+
});
|
|
357
|
+
// emit style-resolved once on enhance
|
|
358
|
+
try {
|
|
359
|
+
let parsed = null;
|
|
360
|
+
try { parsed = JSON.parse(this.getAttribute("items") || "null"); } catch (e) { parsed = this.getAttribute("items"); }
|
|
361
|
+
this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: this.getAttribute("items"), items: parsed }, bubbles: true, composed: true }));
|
|
362
|
+
} catch (e) {}
|
|
363
|
+
// break-change delegated
|
|
364
|
+
this.addEventListener("change", (e) => {
|
|
365
|
+
const t = e.target;
|
|
366
|
+
if (t && t.classList && t.classList.contains("c-legend__break-input")) {
|
|
367
|
+
this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value }, bubbles: true, composed: true }));
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
// Keyboard nav (selectable only): read selectable PER-EVENT like click handler, so attribute changes after enhance() still govern nav.
|
|
371
|
+
this.addEventListener("keydown", (e) => {
|
|
372
|
+
if (!this.hasAttribute("selectable")) return;
|
|
373
|
+
const items = Array.from(this.querySelectorAll(".c-legend__item"));
|
|
374
|
+
if (!items.length) return;
|
|
375
|
+
const active = document.activeElement;
|
|
376
|
+
const idx = items.indexOf(active);
|
|
377
|
+
if (e.key === "Escape") {
|
|
378
|
+
// clear selection
|
|
379
|
+
items.forEach((o) => o.setAttribute("aria-pressed", "false"));
|
|
380
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
384
|
+
// type-ahead
|
|
385
|
+
if (items.length > 7) {
|
|
386
|
+
const start = idx >= 0 ? idx + 1 : 0;
|
|
387
|
+
for (let i = 0; i < items.length; i++) {
|
|
388
|
+
const ii = (start + i) % items.length;
|
|
389
|
+
const txt = (items[ii].textContent || "").trim().toLowerCase();
|
|
390
|
+
if (txt.startsWith(e.key.toLowerCase())) {
|
|
391
|
+
e.preventDefault();
|
|
392
|
+
items[ii].focus();
|
|
393
|
+
items.forEach((o,j)=>o.setAttribute("tabindex", j===ii?"0":"-1"));
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
401
|
+
e.preventDefault();
|
|
402
|
+
if (active && active.classList.contains("c-legend__item")) {
|
|
403
|
+
active.click();
|
|
404
|
+
}
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
navKey(e, items, {
|
|
408
|
+
wrap: true,
|
|
409
|
+
homeEnd: true,
|
|
410
|
+
rtl: isRtl(this),
|
|
411
|
+
onNavigate: (i) => items.forEach((o, j) => o.setAttribute("tabindex", j === i ? "0" : "-1")),
|
|
412
|
+
onKey: () => {}
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
// Cross-filter contract (R16-16): clear-all resets legend selection.
|
|
416
|
+
this.addEventListener("contour:clear-all", () => {
|
|
417
|
+
const items = Array.from(this.querySelectorAll(".c-legend__item"));
|
|
418
|
+
let changed = false;
|
|
419
|
+
items.forEach((o) => {
|
|
420
|
+
if (o.getAttribute("role") === "button" && o.getAttribute("aria-pressed") === "true") {
|
|
421
|
+
o.setAttribute("aria-pressed", "false");
|
|
422
|
+
changed = true;
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
if (changed) {
|
|
426
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "legend", filter: { selection: null } } }));
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
define("contour-legend", ContourLegend);
|