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.
Files changed (150) hide show
  1. package/README.md +244 -326
  2. package/dist/agent-cookbook.json +960 -0
  3. package/dist/agent-examples.json +65 -0
  4. package/dist/agent-map-wiring.json +152 -0
  5. package/dist/agent-rules.json +16 -0
  6. package/dist/build-manifest.json +344 -126
  7. package/dist/contour-wc-content.esm.js +1939 -0
  8. package/dist/contour-wc-content.esm.min.js +1 -0
  9. package/dist/contour-wc-core.esm.js +3724 -0
  10. package/dist/contour-wc-core.esm.min.js +1 -0
  11. package/dist/contour-wc-dashboard.esm.js +6986 -0
  12. package/dist/contour-wc-dashboard.esm.min.js +1 -0
  13. package/dist/contour-wc-data.esm.js +6572 -0
  14. package/dist/contour-wc-data.esm.min.js +1 -0
  15. package/dist/contour-wc-docs.esm.js +976 -0
  16. package/dist/contour-wc-docs.esm.min.js +1 -0
  17. package/dist/contour-wc-feedback.esm.js +1742 -0
  18. package/dist/contour-wc-feedback.esm.min.js +1 -0
  19. package/dist/contour-wc-forms.esm.js +2437 -0
  20. package/dist/contour-wc-forms.esm.min.js +1 -0
  21. package/dist/contour-wc-interaction.esm.js +1343 -0
  22. package/dist/contour-wc-interaction.esm.min.js +1 -0
  23. package/dist/contour-wc-layout.esm.js +845 -0
  24. package/dist/contour-wc-layout.esm.min.js +1 -0
  25. package/dist/contour-wc-map.esm.js +2411 -0
  26. package/dist/contour-wc-map.esm.min.js +1 -0
  27. package/dist/contour-wc-misc.esm.js +945 -0
  28. package/dist/contour-wc-misc.esm.min.js +1 -0
  29. package/dist/contour-wc-navigation.esm.js +2842 -0
  30. package/dist/contour-wc-navigation.esm.min.js +1 -0
  31. package/dist/contour-wc-ui.esm.js +6519 -0
  32. package/dist/contour-wc-ui.esm.min.js +1 -0
  33. package/dist/contour-wc.esm.js +14435 -5723
  34. package/dist/contour-wc.esm.min.js +1 -1
  35. package/dist/contour-wc.js +14436 -5725
  36. package/dist/contour-wc.min.js +1 -1
  37. package/dist/contour.a11y.json +402 -0
  38. package/dist/contour.code-snippets +4534 -0
  39. package/dist/contour.components.json +4870 -1222
  40. package/dist/contour.css +6672 -4711
  41. package/dist/contour.d.ts +753 -1085
  42. package/dist/contour.esm.js +440 -18
  43. package/dist/contour.esm.min.js +1 -1
  44. package/dist/contour.html-data.json +11343 -0
  45. package/dist/contour.js +440 -18
  46. package/dist/contour.min.css +1 -1
  47. package/dist/contour.min.js +1 -1
  48. package/dist/contour.react.d.ts +422 -0
  49. package/dist/contour.single.html +17 -0
  50. package/dist/contour.single.min.css +1 -0
  51. package/dist/contour.themes.json +56 -12
  52. package/dist/contour.tokens.json +1318 -1053
  53. package/dist/contour.vue.d.ts +420 -0
  54. package/dist/contour.web-types.json +11703 -0
  55. package/dist/custom-elements.json +36120 -0
  56. package/dist/docs/actions.md +16 -6
  57. package/dist/docs/affordances.md +21 -85
  58. package/dist/docs/apireference.md +9 -5
  59. package/dist/docs/colour.md +10 -4
  60. package/dist/docs/componentindex.md +9 -22
  61. package/dist/docs/data.md +39 -58
  62. package/dist/docs/docs.md +12 -7
  63. package/dist/docs/feedback.md +30 -12
  64. package/dist/docs/field.md +28 -13
  65. package/dist/docs/forms.md +35 -19
  66. package/dist/docs/index.json +70 -61
  67. package/dist/docs/install.md +12 -7
  68. package/dist/docs/landing.md +7 -4
  69. package/dist/docs/mapengine.md +30 -8
  70. package/dist/docs/motion.md +12 -6
  71. package/dist/docs/navigation.md +31 -7
  72. package/dist/docs/overlays.md +32 -25
  73. package/dist/docs/overview.md +3 -2
  74. package/dist/docs/patterns.md +20 -10
  75. package/dist/docs/playground.md +11 -4
  76. package/dist/docs/principles.md +8 -6
  77. package/dist/docs/recipes.md +117 -13
  78. package/dist/docs/space.md +10 -6
  79. package/dist/docs/status.md +13 -14
  80. package/dist/docs/surfaces.md +17 -22
  81. package/dist/docs/theming.md +18 -32
  82. package/dist/docs/type.md +12 -5
  83. package/dist/docs/webcomponents.md +75 -33
  84. package/dist/hljs.css +1 -20
  85. package/dist/map-chrome.mapbox.css +68 -92
  86. package/dist/map-chrome.maplibre.css +68 -92
  87. package/dist/registry/items/contour-core.json +2 -2
  88. package/dist/registry/items/contour-data.json +2 -2
  89. package/dist/registry/items/contour-docs.json +2 -2
  90. package/dist/registry/items/contour-landing.json +2 -2
  91. package/dist/registry/registry.json +8 -8
  92. package/dist/surfaces/contour-core.min.css +1 -1
  93. package/dist/surfaces/contour-data.min.css +1 -1
  94. package/dist/surfaces/contour-docs.min.css +1 -1
  95. package/dist/surfaces/contour-landing.min.css +1 -1
  96. package/dist/svg/icons.svg +367 -0
  97. package/dist/wc/behaviours.mjs +222 -192
  98. package/dist/wc/content.mjs +486 -142
  99. package/dist/wc/core.mjs +917 -395
  100. package/dist/wc/dashboard.mjs +252 -25
  101. package/dist/wc/data-chart.mjs +1333 -0
  102. package/dist/wc/data-export.mjs +391 -0
  103. package/dist/wc/data-gauge.mjs +779 -0
  104. package/dist/wc/data-geo.mjs +696 -0
  105. package/dist/wc/data-glyphs.mjs +133 -0
  106. package/dist/wc/data-legend.mjs +431 -0
  107. package/dist/wc/data-readout.mjs +227 -0
  108. package/dist/wc/data-series.mjs +1004 -0
  109. package/dist/wc/data-table.mjs +751 -0
  110. package/dist/wc/data.mjs +15 -3707
  111. package/dist/wc/docs.mjs +113 -19
  112. package/dist/wc/feedback.mjs +320 -116
  113. package/dist/wc/forms-controls.mjs +635 -0
  114. package/dist/wc/forms-field.mjs +547 -0
  115. package/dist/wc/forms-groups.mjs +347 -0
  116. package/dist/wc/forms-input.mjs +292 -0
  117. package/dist/wc/forms.mjs +10 -1122
  118. package/dist/wc/glyph.mjs +204 -0
  119. package/dist/wc/index.mjs +16 -7
  120. package/dist/wc/interaction.mjs +322 -75
  121. package/dist/wc/layout.mjs +100 -29
  122. package/dist/wc/map.mjs +888 -285
  123. package/dist/wc/misc.mjs +137 -26
  124. package/dist/wc/navigation-menu.mjs +735 -0
  125. package/dist/wc/navigation-shell.mjs +495 -0
  126. package/dist/wc/navigation-tree.mjs +995 -0
  127. package/dist/wc/navigation.mjs +9 -1636
  128. package/dist/wc/registration.mjs +1 -8
  129. package/dist/wc/shadow.mjs +285 -113
  130. package/dist/wc/states.mjs +75 -78
  131. package/dist/wc/svg.mjs +209 -34
  132. package/dist/wc/ui-atoms.mjs +608 -0
  133. package/dist/wc/ui-data.mjs +1404 -0
  134. package/dist/wc/ui-feedback.mjs +419 -0
  135. package/dist/wc/ui-inputs.mjs +1570 -0
  136. package/dist/wc/ui-menus.mjs +307 -0
  137. package/dist/wc/ui-overlays.mjs +1605 -0
  138. package/integrations/README.md +25 -5
  139. package/integrations/ai/CLAUDE.md +6 -3
  140. package/integrations/ai/COPILOT.md +14 -0
  141. package/integrations/ai/GEMINI.md +14 -0
  142. package/integrations/ai/WINDSURF.md +14 -0
  143. package/integrations/ai/v0-prompt.md +13 -1
  144. package/integrations/frameworks/README.md +235 -0
  145. package/integrations/native/README.md +0 -3
  146. package/integrations/native/style-dictionary.config.json +1 -1
  147. package/integrations/tailwind/contour-theme.css +71 -13
  148. package/integrations/validate-markup.mjs +172 -0
  149. package/package.json +103 -39
  150. package/dist/wc/ui.mjs +0 -3560
@@ -0,0 +1,779 @@
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
+ * Meter: web component wrapper.
8
+ * Attributes: `value`, `label`, `variant`, `min`, `max`, `low`, `high`, `optimum`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
9
+ */
10
+ class ContourMeter extends ContourBase {
11
+ static get observed() { return ["value", "label", "variant", "min", "max", "low", "high", "optimum", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
12
+ static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, variant: { attribute: "variant" }, min: { attribute: "min" }, max: { attribute: "max" }, low: { attribute: "low" }, high: { attribute: "high" }, optimum: { attribute: "optimum" }, src: { attribute: "src" } }; }
13
+ render() {
14
+ this.classList.add("c-meter");
15
+ wireStates(this);
16
+ loadRemote(this, ["value", "label"]);
17
+ if (renderStates(this, "meter")) return;
18
+ const rValue = remoteData(this, "value") || (this._remoteData && this._remoteData.value);
19
+ const label = remoteData(this, "label") || (this._remoteData && this._remoteData.label) || "";
20
+ const variant = this.getAttribute("variant");
21
+ Array.from(this.classList).forEach((c) => { if (c.startsWith("c-meter--")) this.classList.remove(c); });
22
+ if (variant) this.classList.add("c-meter--" + variant);
23
+ if (!rValue && !label) {
24
+ renderEmpty(this, "meter");
25
+ return;
26
+ }
27
+ if (rValue === null) {
28
+ this.style.removeProperty("--meter-value");
29
+ } else {
30
+ const num = parseFloat(rValue);
31
+ const min = parseFloat(this.getAttribute("min")) || 0;
32
+ const max = parseFloat(this.getAttribute("max")) || 100;
33
+ // R24-27: normalize to (num-min)/(max-min) and write the parsed
34
+ // number, not the raw string. Clamp to [0, 1].
35
+ if (Number.isFinite(num)) {
36
+ const norm = max > min ? Math.min(1, Math.max(0, (num - min) / (max - min))) : 0;
37
+ this.style.setProperty("--meter-value", String(norm));
38
+ } else this.style.removeProperty("--meter-value");
39
+ }
40
+ const core = this.ensure(".c-meter__core", () => { const el = document.createElement("span"); el.className = "c-meter__core"; return el; });
41
+ let val = core.querySelector(".c-meter__value");
42
+ if (!val) { val = document.createElement("span"); val.className = "c-meter__value"; core.appendChild(val); }
43
+ // R24-27: show the normalized percentage, not num*100.
44
+ const num2 = parseFloat(rValue);
45
+ const min2 = parseFloat(this.getAttribute("min")) || 0;
46
+ const max2 = parseFloat(this.getAttribute("max")) || 100;
47
+ const norm2 = Number.isFinite(num2) && max2 > min2 ? Math.min(1, Math.max(0, (num2 - min2) / (max2 - min2))) : 0;
48
+ val.textContent = Math.round(norm2 * 100) + "%";
49
+ if (label) {
50
+ const lbl = core.querySelector(".c-meter__label") || (() => { const el = document.createElement("span"); el.className = "c-meter__label"; core.appendChild(el); return el; })();
51
+ lbl.textContent = label;
52
+ }
53
+ if (!this.hasAttribute("role")) this.setAttribute("role", "meter");
54
+ if (label && !this.hasAttribute("aria-label")) this.setAttribute("aria-label", label);
55
+ // ARIA requires `aria-valuenow` to be a number. The raw attribute string would put `aria-valuenow="abc"` on the host while the text showed 0% (F-RO14), so mirror the same finite-number guard the label uses.
56
+ const ariaValue = Number.isFinite(num2) ? String(num2) : "0";
57
+ const prevVal = this._meterAriaValue;
58
+ if (!this.hasAttribute("aria-valuenow") || this.getAttribute("aria-valuenow") === prevVal) {
59
+ this.setAttribute("aria-valuenow", ariaValue);
60
+ this._meterAriaValue = ariaValue;
61
+ }
62
+ const min = this.getAttribute("min");
63
+ const max = this.getAttribute("max");
64
+ // R31-57: aria-valuemax/min must match the value the bar is normalised
65
+ // against. The old default was "1", so a value of 35 announced
66
+ // "aria-valuemax=1" while the bar showed 35 %. Use the resolved bounds.
67
+ if (min !== null) this.setAttribute("aria-valuemin", min);
68
+ else this.setAttribute("aria-valuemin", String(min2));
69
+ if (max !== null) this.setAttribute("aria-valuemax", max);
70
+ else this.setAttribute("aria-valuemax", String(max2));
71
+ for (const a of ["low", "high", "optimum"]) {
72
+ const v = this.getAttribute(a);
73
+ if (v !== null) this.setAttribute("data-" + a, v);
74
+ else this.removeAttribute("data-" + a);
75
+ }
76
+ }
77
+ }
78
+ define("contour-meter", ContourMeter);
79
+ /**
80
+ * Delta: web component wrapper.
81
+ * Attributes: `value`, `direction`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
82
+ */
83
+ class ContourDelta extends ContourBase {
84
+ static get observed() { return ["value", "direction", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
85
+ static get properties() { return { value: { attribute: "value" }, direction: { attribute: "direction" }, src: { attribute: "src" } }; }
86
+ render() {
87
+ this.classList.add("c-delta");
88
+ wireStates(this);
89
+ loadRemote(this, "value");
90
+ if (renderStates(this, "delta")) return;
91
+ const value = remoteData(this, "value") || "";
92
+ Array.from(this.classList).forEach((c) => { if (c.startsWith("c-delta--")) this.classList.remove(c); });
93
+ const direction = this.getAttribute("direction") || (this._remoteData && this._remoteData.direction) || "up";
94
+ if (!value) {
95
+ renderEmpty(this, "delta");
96
+ return;
97
+ }
98
+ this.classList.add("c-delta--" + direction);
99
+ const icon = { up: "#i-arrow-up", down: "#i-arrow-down", flat: "#i-minus" }[direction] || "#i-arrow-up";
100
+ this.querySelectorAll("svg").forEach((s) => s.remove());
101
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
102
+ svg.setAttribute("aria-hidden", "true");
103
+ const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
104
+ use.setAttribute("href", icon);
105
+ svg.appendChild(use);
106
+ this.appendChild(svg);
107
+ this.appendChild(document.createTextNode(" " + value));
108
+ }
109
+ }
110
+ define("contour-delta", ContourDelta);
111
+ /**
112
+ * Stat: web component wrapper.
113
+ * Attributes: `value`, `label`, `delta`, `unit`, `format`, `locale`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
114
+ */
115
+ class ContourStat extends ContourBase {
116
+ static get observed() { return ["value", "label", "delta", "unit", "format", "locale", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
117
+ static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, delta: { attribute: "delta" }, unit: { attribute: "unit" }, format: { attribute: "format" }, locale: { attribute: "locale" }, src: { attribute: "src" } }; }
118
+ render() {
119
+ this.classList.add("c-stat");
120
+ wireStates(this);
121
+ loadRemote(this, ["value", "label"]);
122
+ if (renderStates(this, "stat")) return;
123
+ const value = remoteData(this, "value");
124
+ const label = remoteData(this, "label");
125
+ const delta = this.getAttribute("delta");
126
+ if (value) {
127
+ const v = this.ensure(".c-stat__value", () => { const el = document.createElement("div"); el.className = "c-stat__value"; el.setAttribute("aria-live", "polite"); return el; });
128
+ v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit"));
129
+ } else {
130
+ const v = this.querySelector(".c-stat__value");
131
+ if (v) v.remove();
132
+ }
133
+ if (label) {
134
+ const l = this.ensure(".c-stat__label", () => { const el = document.createElement("div"); el.className = "c-stat__label"; return el; });
135
+ l.textContent = label;
136
+ } else {
137
+ const l = this.querySelector(".c-stat__label");
138
+ if (l) l.remove();
139
+ }
140
+ if (delta) {
141
+ const d = this.ensure(".c-stat__delta", () => { const el = document.createElement("div"); el.className = "c-stat__delta"; return el; });
142
+ d.textContent = delta;
143
+ } else {
144
+ const d = this.querySelector(".c-stat__delta");
145
+ if (d) d.remove();
146
+ }
147
+ const unit = this.getAttribute("unit");
148
+ const v = this.querySelector(".c-stat__value");
149
+ if (v) {
150
+ if (unit) {
151
+ let u = v.querySelector(".c-stat__unit");
152
+ if (!u) { u = document.createElement("span"); u.className = "c-stat__unit"; v.appendChild(u); }
153
+ u.textContent = unit;
154
+ } else {
155
+ const u = v.querySelector(".c-stat__unit");
156
+ if (u) u.remove();
157
+ }
158
+ }
159
+ if (!value && !label) {
160
+ renderEmpty(this, "stat");
161
+ }
162
+ }
163
+ }
164
+ define("contour-stat", ContourStat);
165
+ /**
166
+ * Gauge: web component wrapper.
167
+ * Attributes: `value`, `min`, `max`, `heading`, `thresholds`, `format`, `locale`, `unit`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `brownout`, `brownout-level`, `no-data-message`, `show-header`, `description`.
168
+ */
169
+ class ContourGauge extends ContourBase {
170
+ static get observed() { return ["value", "min", "max", "heading", "thresholds", "format", "locale", "unit", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level", "no-data-message", "show-header", "description", "cache-key", "no-cache"]; }
171
+ static get properties() { return { value: { attribute: "value" }, min: { attribute: "min" }, max: { attribute: "max" }, heading: { attribute: "heading" }, thresholds: { attribute: "thresholds" }, format: { attribute: "format" }, locale: { attribute: "locale" }, unit: { attribute: "unit" }, src: { attribute: "src" }, brownout: { attribute: "brownout" } }; }
172
+ render() {
173
+ this.classList.add("c-gauge");
174
+ wireStates(this);
175
+ loadRemote(this, ["value"]);
176
+ if (renderStates(this, "gauge")) return;
177
+ const rawValue = this.getAttribute("value");
178
+ const num = parseFloat(rawValue);
179
+ const hasValue = rawValue !== null && rawValue !== "" && Number.isFinite(num);
180
+ // R24-28: finite-guard min/max so a NaN doesn't propagate to the needle.
181
+ const min = Number.isFinite(parseFloat(this.getAttribute("min"))) ? parseFloat(this.getAttribute("min")) : 0;
182
+ const max = Number.isFinite(parseFloat(this.getAttribute("max"))) ? parseFloat(this.getAttribute("max")) : 100;
183
+ const heading = this.getAttribute("heading");
184
+ const showHeader = this.getAttribute("show-header") !== "false";
185
+ const description = this.getAttribute("description");
186
+ const noDataMessage = this.getAttribute("no-data-message") || "No readings in view";
187
+ const brownoutLevel = this.brownoutLevel();
188
+ // empty state
189
+ if (!hasValue) {
190
+ if (heading && showHeader) {
191
+ const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; return el; });
192
+ t.textContent = heading;
193
+ }
194
+ const empty = this.ensure(".c-gauge__empty", () => { const el = document.createElement("div"); el.className = "c-gauge__empty"; el.setAttribute("part", "empty"); return el; });
195
+ empty.textContent = noDataMessage;
196
+ // remove dial/value/band if present
197
+ [".c-gauge__dial", ".c-gauge__value", ".c-gauge__band"].forEach((sel) => { const n = this.querySelector(sel); if (n) n.remove(); });
198
+ return;
199
+ }
200
+ // heading
201
+ if (heading && showHeader) {
202
+ const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; el.setAttribute("part", "title"); return el; });
203
+ t.textContent = heading;
204
+ } else {
205
+ const t = this.querySelector(".c-gauge__title"); if (t) t.remove();
206
+ }
207
+ // thresholds
208
+ let thresholds = [];
209
+ const tAttr = this.getAttribute("thresholds");
210
+ // R24-28: Array.isArray guard so a malformed thresholds attr doesn't crash.
211
+ if (tAttr) { try { const p = JSON.parse(tAttr); if (Array.isArray(p)) thresholds = p; else warnBadJson(this, "thresholds", new Error("not an array")); } catch (e) { thresholds = []; } }
212
+ // band determination
213
+ let band = null;
214
+ if (thresholds && thresholds.length) {
215
+ // thresholds sorted ascending by value
216
+ const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
217
+ for (let i = sorted.length - 1; i >= 0; i--) {
218
+ if (num >= (sorted[i].value || 0)) { band = sorted[i]; break; }
219
+ }
220
+ }
221
+ // dial (unless brownout >= 3)
222
+ const shedDial = this.shed("dial", 3);
223
+ let dial = this.querySelector(".c-gauge__dial");
224
+ if (shedDial) {
225
+ if (dial) dial.remove();
226
+ } else {
227
+ if (!dial) {
228
+ dial = document.createElementNS("http://www.w3.org/2000/svg", "svg");
229
+ dial.setAttribute("class", "c-gauge__dial");
230
+ dial.setAttribute("part", "dial");
231
+ dial.setAttribute("aria-hidden", "true");
232
+ dial.setAttribute("viewBox", "0 0 100 100");
233
+ this.appendChild(dial);
234
+ }
235
+ // rebuild dial content
236
+ dial.innerHTML = "";
237
+ // track arc (semicircle)
238
+ const track = document.createElementNS("http://www.w3.org/2000/svg", "path");
239
+ track.setAttribute("class", "c-gauge__track");
240
+ track.setAttribute("d", "M 10 90 A 40 40 0 0 1 90 90");
241
+ dial.appendChild(track);
242
+ // zones: each threshold defines a band from its value to the next threshold's value (or max), drawn as an arc along the track so the bands no longer stack on top of one another.
243
+ if (thresholds && thresholds.length) {
244
+ const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
245
+ const toPoint = (v) => {
246
+ const pos = (1 - (v - min) / (max - min || 1)) * Math.PI;
247
+ return { x: 50 + 40 * Math.cos(pos), y: 90 - 40 * Math.sin(pos) };
248
+ };
249
+ for (let i = 0; i < sorted.length; i++) {
250
+ const v1 = sorted[i].value || 0;
251
+ const v2 = (i + 1 < sorted.length) ? (sorted[i + 1].value || max) : max;
252
+ const p1 = toPoint(v1);
253
+ const p2 = toPoint(v2);
254
+ const z = document.createElementNS("http://www.w3.org/2000/svg", "path");
255
+ z.setAttribute("class", "c-gauge__zone");
256
+ z.setAttribute("stroke", sorted[i].color || "var(--color-primary)");
257
+ z.setAttribute("d", "M " + p1.x.toFixed(2) + " " + p1.y.toFixed(2) + " A 40 40 0 0 1 " + p2.x.toFixed(2) + " " + p2.y.toFixed(2));
258
+ dial.appendChild(z);
259
+ }
260
+ }
261
+ // Needle pivot at dial centre (50,90); 0→left, 100→right. R24-28: clamp ratio to [0,1] so value outside min/max doesn't exceed dial.
262
+ const ratio = Math.max(0, Math.min(1, (num - min) / (max - min || 1)));
263
+ const angle = Math.PI * (1 - ratio);
264
+ const needle = document.createElementNS("http://www.w3.org/2000/svg", "line");
265
+ needle.setAttribute("class", "c-gauge__needle needle");
266
+ needle.setAttribute("x1", "50"); needle.setAttribute("y1", "90");
267
+ needle.setAttribute("x2", String(50 + 35 * Math.cos(angle)));
268
+ needle.setAttribute("y2", String(90 - 35 * Math.sin(angle)));
269
+ dial.appendChild(needle);
270
+ const hub = document.createElementNS("http://www.w3.org/2000/svg", "circle");
271
+ hub.setAttribute("class", "c-gauge__hub hub");
272
+ hub.setAttribute("cx", "50"); hub.setAttribute("cy", "90"); hub.setAttribute("r", "4");
273
+ dial.appendChild(hub);
274
+ }
275
+ // value element (meter)
276
+ const valueEl = this.ensure(".c-gauge__value", () => { const el = document.createElement("div"); el.className = "c-gauge__value"; el.setAttribute("part", "value"); return el; });
277
+ valueEl.textContent = formatValue(String(num), this.getAttribute("format"), this.getAttribute("locale")) + (this.getAttribute("unit") ? " " + this.getAttribute("unit") : "");
278
+ valueEl.setAttribute("role", "meter");
279
+ // Clamp aria-valuenow to [min,max] so value>max doesn't announce above valuemax — needle already clamped, ARIA wasn't.
280
+ const ariaNow = Math.max(min, Math.min(max, num));
281
+ valueEl.setAttribute("aria-valuenow", String(ariaNow));
282
+ valueEl.setAttribute("aria-valuemin", String(min));
283
+ valueEl.setAttribute("aria-valuemax", String(max));
284
+ if (heading) {
285
+ // labelledby
286
+ if (!valueEl.id) valueEl.id = contourId("gauge-value");
287
+ }
288
+ if (band) {
289
+ valueEl.setAttribute("aria-valuetext", num + ", " + (band.label || (">= " + band.value)));
290
+ } else {
291
+ valueEl.setAttribute("aria-valuetext", String(num));
292
+ }
293
+ // aria-labelledby / aria-label
294
+ const titleEl = this.querySelector(".c-gauge__title");
295
+ if (titleEl) {
296
+ if (!titleEl.id) titleEl.id = contourId("gauge-title");
297
+ valueEl.setAttribute("aria-labelledby", titleEl.id);
298
+ valueEl.removeAttribute("aria-label");
299
+ } else {
300
+ valueEl.removeAttribute("aria-labelledby");
301
+ if (heading) valueEl.setAttribute("aria-label", heading);
302
+ else valueEl.setAttribute("aria-label", valueEl.textContent || "Gauge");
303
+ }
304
+ // band word
305
+ const bandEl = this.querySelector(".c-gauge__band");
306
+ if (band) {
307
+ const b = this.ensure(".c-gauge__band", () => { const el = document.createElement("div"); el.className = "c-gauge__band"; el.setAttribute("part", "band"); return el; });
308
+ b.textContent = band.label || (">= " + band.value);
309
+ } else {
310
+ if (bandEl) bandEl.remove();
311
+ }
312
+ // description
313
+ if (description) {
314
+ let d = this.querySelector(".c-gauge__desc");
315
+ if (!d) { d = document.createElement("div"); d.className = "c-gauge__desc"; this.appendChild(d); }
316
+ d.textContent = description;
317
+ }
318
+ }
319
+ enhance() {}
320
+ }
321
+ define("contour-gauge", ContourGauge);
322
+ /**
323
+ * Axis: web component wrapper.
324
+ * Attributes: `orientation`, `values`, `ticks`, `format`, `locale`, `padding`, `min`, `max`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
325
+ */
326
+ class ContourAxis extends ContourBase {
327
+ static get observed() { return ["orientation", "values", "ticks", "format", "locale", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
328
+ static get properties() { return { orientation: { attribute: "orientation" }, values: { attribute: "values" }, ticks: { attribute: "ticks" }, format: { attribute: "format" }, locale: { attribute: "locale" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
329
+ render() {
330
+ this.classList.add("c-axis");
331
+ if (!this.hasAttribute("role")) this.setAttribute("role", "img");
332
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "axis", "Axis"));
333
+ const orientation = this.getAttribute("orientation") || "horizontal";
334
+ this.classList.toggle("c-axis--horizontal", orientation === "horizontal");
335
+ this.classList.toggle("c-axis--vertical", orientation === "vertical");
336
+ if (orientation === "horizontal") this.setAttribute("part", "axis-x");
337
+ else this.setAttribute("part", "axis-y");
338
+ wireStates(this);
339
+ loadRemote(this, ["values"]);
340
+ if (renderStates(this, "axis")) return;
341
+ // parse values
342
+ let values = [];
343
+ const vAttr = this.getAttribute("values");
344
+ if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map((x) => x.trim()); } }
345
+ const ticks = parseInt(this.getAttribute("ticks") || "0", 10) || values.length;
346
+ // Slotted content support: authored .c-axis__tick children take
347
+ // precedence over the JSON `values` attribute.
348
+ const authoredTicks = Array.from(this.querySelectorAll(":scope > .c-axis__tick"));
349
+ // R24-34: the generated-ticks branch pins each tick to its value's position. Toggle the host class so the sheet can switch the tick layout from flex (authored children) to absolute (value-positioned).
350
+ this.classList.toggle("c-axis--value-ticks", !authoredTicks.length);
351
+ if (authoredTicks.length) {
352
+ // keep authored ticks, just ensure labels are formatted
353
+ authoredTicks.forEach((tick) => {
354
+ const label = tick.querySelector(".c-axis__label");
355
+ if (label && !label.textContent) label.textContent = tick.textContent;
356
+ });
357
+ } else {
358
+ // clear
359
+ Array.from(this.querySelectorAll(".c-axis__tick")).forEach((n) => n.remove());
360
+ const list = values.length ? values : Array.from({ length: ticks }, (_, i) => i);
361
+ // Position ticks by VALUE, not flex spacing: old justify-content:space-between lied about tick positions; compute range from min/max and pin each tick to its value's position.
362
+ const nums = list.map((v) => Number(v)).filter(Number.isFinite);
363
+ let lo = nums.length ? Math.min(...nums) : 0;
364
+ let hi = nums.length ? Math.max(...nums) : 0;
365
+ const minAttr = parseFloat(this.getAttribute("min"));
366
+ const maxAttr = parseFloat(this.getAttribute("max"));
367
+ if (Number.isFinite(minAttr)) lo = minAttr;
368
+ if (Number.isFinite(maxAttr)) hi = maxAttr;
369
+ const range = (hi - lo) || 1;
370
+ list.forEach((v) => {
371
+ const tick = document.createElement("span");
372
+ tick.className = "c-axis__tick";
373
+ const label = document.createElement("span");
374
+ label.className = "c-axis__label";
375
+ label.textContent = formatValue(String(v), this.getAttribute("format"), this.getAttribute("locale"));
376
+ tick.appendChild(label);
377
+ // R24-34: `--tick-pos` is the value's share of the range, in percent.
378
+ // The sheet's `.c-axis__tick` rule reads it to place the tick.
379
+ const n = Number(v);
380
+ tick.style.setProperty("--tick-pos", Number.isFinite(n) ? (((n - lo) / range) * 100) + "%" : "0%");
381
+ this.appendChild(tick);
382
+ });
383
+ }
384
+ }
385
+ enhance() {}
386
+ }
387
+ define("contour-axis", ContourAxis);
388
+ /**
389
+ * Brush: web component wrapper.
390
+ * Attributes: `start`, `end`, `min`, `max`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
391
+ */
392
+ class ContourBrush extends ContourBase {
393
+ static get observed() { return ["start", "end", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
394
+ static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
395
+ // The selection as a numeric pair in the track's own units. `start`/`end` stay the attribute strings; `range` is the shape a cross-filter consumer wants, and libreship's histogram binder reads it.
396
+ _rangeValue() {
397
+ const start = parseFloat(this.getAttribute("start"));
398
+ const end = parseFloat(this.getAttribute("end"));
399
+ return Number.isFinite(start) && Number.isFinite(end) ? [start, end] : null;
400
+ }
401
+ // R24-153: one numeric detail shape for every brush event. `start`/`end`/`value` are numbers (the track's own units), never the raw attribute strings, so a consumer reading `detail.start` gets a number on the pointer path and the keyboard path alike.
402
+ _brushDetail() {
403
+ const r = this._rangeValue();
404
+ return { start: r ? r[0] : null, end: r ? r[1] : null, value: r ? r[1] : null, range: r };
405
+ }
406
+ render() {
407
+ this.classList.add("c-brush");
408
+ this.setAttribute("role", "group");
409
+ this.setAttribute("aria-label", labelText(this, "brush-selection", "Brush selection"));
410
+ wireStates(this);
411
+ loadRemote(this, []);
412
+ if (renderStates(this, "brush")) return;
413
+ let sel = this.querySelector(".c-brush__selection");
414
+ if (!sel) { sel = document.createElement("div"); sel.className = "c-brush__selection"; this.appendChild(sel); }
415
+ const start = parseFloat(this.getAttribute("start") || "0");
416
+ const end = parseFloat(this.getAttribute("end") || "100");
417
+ const min = parseFloat(this.getAttribute("min") || "0");
418
+ const max = parseFloat(this.getAttribute("max") || "100");
419
+ const range = max - min || 1;
420
+ const left = ((start - min) / range) * 100;
421
+ const width = ((end - start) / range) * 100;
422
+ sel.style.insetInlineStart = left + "%";
423
+ sel.style.inlineSize = width + "%";
424
+ // handles
425
+ ["start","end"].forEach((h) => {
426
+ let handle = this.querySelector(".c-brush__handle--" + h);
427
+ if (!handle) { handle = document.createElement("div"); handle.className = "c-brush__handle c-brush__handle--" + h; this.appendChild(handle); }
428
+ const val = h === "start" ? start : end;
429
+ handle.style.insetInlineStart = (((val - min) / range) * 100) + "%";
430
+ // Brush handles are focusable sliders (APG dual-slider); keyboard users adjust range in track units, aria-valuenow synced on render.
431
+ handle.setAttribute("role", "slider");
432
+ handle.setAttribute("tabindex", "0");
433
+ handle.setAttribute("aria-valuemin", String(min));
434
+ handle.setAttribute("aria-valuemax", String(max));
435
+ handle.setAttribute("aria-valuenow", String(val));
436
+ handle.setAttribute("aria-label", h === "start" ? "Start" : "End");
437
+ });
438
+ }
439
+ enhance() {
440
+ if (this._wiredBrush) return;
441
+ this._wiredBrush = true;
442
+ let dragging = null;
443
+ const min = () => parseFloat(this.getAttribute("min") || "0");
444
+ const max = () => parseFloat(this.getAttribute("max") || "100");
445
+ const toValue = (clientX) => {
446
+ const r = this.getBoundingClientRect();
447
+ const ratio = Math.max(0, Math.min(1, (clientX - r.left) / (r.width || 1)));
448
+ return min() + ratio * (max() - min());
449
+ };
450
+ this.addEventListener("pointerdown", (e) => {
451
+ const handle = e.target && e.target.classList && e.target.classList.contains("c-brush__handle") ? e.target : null;
452
+ dragging = handle ? (handle.classList.contains("c-brush__handle--start") ? "start" : "end") : "move";
453
+ try { this.setPointerCapture(e.pointerId); } catch (err) {}
454
+ this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: this._brushDetail() }));
455
+ });
456
+ this.addEventListener("pointermove", (e) => {
457
+ if (!dragging) return;
458
+ const v = toValue(e.clientX);
459
+ const mn = min(), mx = max(), range = mx - mn || 1;
460
+ const sel = this.querySelector(".c-brush__selection");
461
+ let ns = parseFloat(this.getAttribute("start") || "0");
462
+ let ne = parseFloat(this.getAttribute("end") || "100");
463
+ if (dragging === "start") {
464
+ ns = Math.min(v, ne);
465
+ } else if (dragging === "end") {
466
+ ne = Math.max(v, ns);
467
+ } else {
468
+ const width = ne - ns;
469
+ ns = v - width / 2;
470
+ ne = v + width / 2;
471
+ if (ns < mn) { ne += mn - ns; ns = mn; }
472
+ if (ne > mx) { ns -= ne - mx; ne = mx; }
473
+ }
474
+ ns = Math.max(mn, Math.min(mx, ns));
475
+ ne = Math.max(mn, Math.min(mx, ne));
476
+ // update DOM directly to avoid re-render during drag
477
+ if (sel) {
478
+ sel.style.insetInlineStart = (((ns - mn) / range) * 100) + "%";
479
+ sel.style.inlineSize = (((ne - ns) / range) * 100) + "%";
480
+ }
481
+ const sh = this.querySelector(".c-brush__handle--start");
482
+ const eh = this.querySelector(".c-brush__handle--end");
483
+ if (sh) sh.style.insetInlineStart = (((ns - mn) / range) * 100) + "%";
484
+ if (eh) eh.style.insetInlineStart = (((ne - mn) / range) * 100) + "%";
485
+ // stash pending values
486
+ this._brushPending = { start: ns, end: ne };
487
+ this.dispatchEvent(new CustomEvent("contour:brush", { bubbles: true, composed: true, detail: { start: ns, end: ne, value: ns, range: [ns, ne] } }));
488
+ });
489
+ this.addEventListener("pointerup", (e) => {
490
+ if (!dragging) return;
491
+ dragging = null;
492
+ const p = this._brushPending;
493
+ if (p) {
494
+ this.setAttribute("start", String(p.start));
495
+ this.setAttribute("end", String(p.end));
496
+ this._brushPending = null;
497
+ }
498
+ this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: this._brushDetail() }));
499
+ this.dispatchEvent(new CustomEvent("contour:brush", { bubbles: true, composed: true, detail: this._brushDetail() }));
500
+ });
501
+ // Cancelled pointer never fires pointerup; without re-render, handles stay mid-drag (F-RO13). Re-render snaps handles to committed range.
502
+ this.addEventListener("pointercancel", () => {
503
+ if (!dragging) return;
504
+ dragging = null;
505
+ this._brushPending = null;
506
+ this.requestRender();
507
+ });
508
+ // Keyboard: focused handle is a slider; arrows/UpDown step, Home/End jump bounds, Enter/Space commits — each adjustment is a full transaction (start→brush→end) with numeric detail matching pointer path.
509
+ this.addEventListener("keydown", (e) => {
510
+ const handle = e.target && e.target.classList && e.target.classList.contains("c-brush__handle") ? e.target : null;
511
+ const which = handle ? (handle.classList.contains("c-brush__handle--start") ? "start" : "end") : null;
512
+ const mn = min(), mx = max();
513
+ const step = (mx - mn) / 100 || 1;
514
+ let ns = parseFloat(this.getAttribute("start") || "0");
515
+ let ne = parseFloat(this.getAttribute("end") || "100");
516
+ if (e.key === "Enter" || e.key === " ") {
517
+ e.preventDefault();
518
+ this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: this._brushDetail() }));
519
+ this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: this._brushDetail() }));
520
+ return;
521
+ }
522
+ let handled = true;
523
+ if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
524
+ if (which === "start") ns -= step;
525
+ else if (which === "end") ne -= step;
526
+ else { const w = ne - ns; ns -= step; ne = ns + w; }
527
+ } else if (e.key === "ArrowRight" || e.key === "ArrowUp") {
528
+ if (which === "start") ns += step;
529
+ else if (which === "end") ne += step;
530
+ else { const w = ne - ns; ne += step; ns = ne - w; }
531
+ } else if (e.key === "Home") {
532
+ if (which === "end") ne = ns; else ns = mn;
533
+ } else if (e.key === "End") {
534
+ if (which === "start") ns = ne; else ne = mx;
535
+ } else handled = false;
536
+ if (!handled) return;
537
+ e.preventDefault();
538
+ ns = Math.max(mn, Math.min(mx, ns));
539
+ ne = Math.max(mn, Math.min(mx, ne));
540
+ if (ns > ne) { const t = ns; ns = ne; ne = t; }
541
+ this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: this._brushDetail() }));
542
+ this.setAttribute("start", String(ns));
543
+ this.setAttribute("end", String(ne));
544
+ this.dispatchEvent(new CustomEvent("contour:brush", { bubbles: true, composed: true, detail: this._brushDetail() }));
545
+ this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: this._brushDetail() }));
546
+ });
547
+ // Cross-filter contract (R16-16): clear-all resets brush range.
548
+ this.addEventListener("contour:clear-all", () => {
549
+ if (this.hasAttribute("start") || this.hasAttribute("end")) {
550
+ this.removeAttribute("start");
551
+ this.removeAttribute("end");
552
+ this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "brush", filter: { start: null, end: null } } }));
553
+ this.requestRender();
554
+ }
555
+ });
556
+ }
557
+ }
558
+ define("contour-brush", ContourBrush);
559
+ /**
560
+ * Stacked Bar: web component wrapper.
561
+ * Attributes: `segments`, `values`, `colors`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `normalize`.
562
+ */
563
+ class ContourStackedBar extends ContourBase {
564
+ static get observed() { return ["segments", "values", "colors", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "max", "no-cache"]; }
565
+ static get properties() { return { segments: { attribute: "segments" }, values: { attribute: "values" }, colors: { attribute: "colors" }, src: { attribute: "src" }, max: { attribute: "max" } }; }
566
+ render() {
567
+ this.classList.add("c-stacked-bar");
568
+ // The bar carries a listbox of selectable segments; role=img would make
569
+ // every one of them presentational. A named group exposes them.
570
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
571
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "stacked-bar", "Stacked bar"));
572
+ wireStates(this);
573
+ loadRemote(this, ["segments", "values"]);
574
+ if (renderStates(this, "stacked-bar")) return;
575
+ Array.from(this.querySelectorAll(".c-stacked-bar__segment")).forEach((n) => n.remove());
576
+ // Slotted content support: authored .c-stacked-bar__segment children take
577
+ // precedence over the JSON `segments` attribute.
578
+ const authoredSegments = Array.from(this.querySelectorAll(":scope > .c-stacked-bar__segment"));
579
+ let segments = [];
580
+ if (authoredSegments.length) {
581
+ segments = authoredSegments.map((el) => ({
582
+ label: el.getAttribute("data-title") || el.getAttribute("title") || el.textContent || "",
583
+ value: parseFloat(el.style.inlineSize) || 0,
584
+ color: (el.dataset && el.dataset.color) || el.style.background || undefined,
585
+ }));
586
+ authoredSegments.forEach((el) => el.remove());
587
+ } else {
588
+ const sAttr = this.getAttribute("segments");
589
+ if (sAttr) { segments = parseArrayAttr(this, "segments", warnBadJson); }
590
+ }
591
+ const values = segments.map((seg) => (typeof seg === "object" ? (seg.value || 0) : Number(seg) || 0));
592
+ const hasNegative = values.some((v) => v < 0);
593
+ const posSum = values.filter((v) => v > 0).reduce((a, b) => a + b, 0);
594
+ const negSum = Math.abs(values.filter((v) => v < 0).reduce((a, b) => a + b, 0));
595
+ const totalAbs = posSum + negSum;
596
+ const sideMax = Math.max(posSum, negSum, 1);
597
+ const scale = Math.max(1, parseFloat(this.getAttribute("max")) || (hasNegative ? sideMax : totalAbs));
598
+ this.querySelectorAll(".c-stacked-bar__track").forEach((n) => n.remove());
599
+ const makeSegment = (seg, i, widthPct) => {
600
+ const v = values[i];
601
+ const el = document.createElement("div");
602
+ el.className = "c-stacked-bar__segment" + (v === 0 ? " c-stacked-bar__segment--zero" : "");
603
+ el.style.inlineSize = widthPct + "%";
604
+ el.style.background = safeColor((typeof seg === "object" && seg.color) ? seg.color : "var(--chart-" + ((i % 8) + 1) + ")");
605
+ el.dataset.color = (typeof seg === "object" && seg.color) ? seg.color : el.style.background;
606
+ const label = typeof seg === "object" ? (seg.label || "") : "";
607
+ el.setAttribute("data-title", label + " " + v);
608
+ el.setAttribute("role", "img");
609
+ el.setAttribute("aria-label", (label ? label + ": " : "") + v);
610
+ return el;
611
+ };
612
+ if (hasNegative) {
613
+ this.classList.add("c-stacked-bar--diverging");
614
+ const negTrack = document.createElement("div");
615
+ negTrack.className = "c-stacked-bar__track c-stacked-bar__track--neg";
616
+ const posTrack = document.createElement("div");
617
+ posTrack.className = "c-stacked-bar__track";
618
+ segments.forEach((seg, i) => {
619
+ const v = values[i];
620
+ if (v === 0) return;
621
+ const width = (Math.abs(v) / scale) * 100;
622
+ (v < 0 ? negTrack : posTrack).appendChild(makeSegment(seg, i, width));
623
+ });
624
+ this.appendChild(negTrack);
625
+ this.appendChild(posTrack);
626
+ } else {
627
+ this.classList.remove("c-stacked-bar--diverging");
628
+ const track = document.createElement("div");
629
+ track.className = "c-stacked-bar__track";
630
+ segments.forEach((seg, i) => track.appendChild(makeSegment(seg, i, (values[i] / scale) * 100)));
631
+ this.appendChild(track);
632
+ }
633
+ if (!segments.length) renderEmpty(this, "stacked-bar");
634
+ }
635
+ enhance() {}
636
+ }
637
+ define("contour-stacked-bar", ContourStackedBar);
638
+ /**
639
+ * Category: web component wrapper.
640
+ * Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
641
+ * R24-35: `search` is a clear-all signal (read in the clear-all handler, not
642
+ * render()), so it stays in `observed` to satisfy the reads-but-observes arm;
643
+ * it is not a reflected property.
644
+ */
645
+ class ContourCategory extends ContourBase {
646
+ static get observed() { return ["items", "search", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "note", "limit", "sort", "format", "locale", "unit", "cache-key", "no-cache"]; }
647
+ static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, note: { attribute: "note" }, limit: { attribute: "limit" }, sort: { attribute: "sort" }, format: { attribute: "format" }, locale: { attribute: "locale" }, unit: { attribute: "unit" } }; }
648
+ render() {
649
+ this.classList.add("c-category");
650
+ this.setAttribute("role", "listbox");
651
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "category", "Category"));
652
+ wireStates(this);
653
+ loadRemote(this, ["items"]);
654
+ if (renderStates(this, "category")) return;
655
+ Array.from(this.querySelectorAll(".c-category__item")).forEach((n) => n.remove());
656
+ // Slotted content support: authored .c-category__item children take
657
+ // precedence over the JSON `items` attribute.
658
+ const authoredItems = Array.from(this.querySelectorAll(":scope > .c-category__item"));
659
+ let items = [];
660
+ if (authoredItems.length) {
661
+ authoredItems.forEach((el) => {
662
+ const lbl = el.querySelector(".c-category__label");
663
+ items.push({ label: lbl ? lbl.textContent : el.textContent, value: 0 });
664
+ });
665
+ authoredItems.forEach((el) => el.remove());
666
+ } else {
667
+ const iAttr = this.getAttribute("items");
668
+ if (iAttr) { items = parseArrayAttr(this, "items", warnBadJson); }
669
+ }
670
+ // Top-N + sort (CARTO-inspired): optional limit and sort attributes (value-desc/asc, alpha-asc/desc).
671
+ const sort = this.getAttribute("sort") || "value-desc";
672
+ items.sort((a, b) => {
673
+ const va = (typeof a === "object") ? (a.value || 0) : (Number(a) || 0);
674
+ const vb = (typeof b === "object") ? (b.value || 0) : (Number(b) || 0);
675
+ const la = (typeof a === "object") ? (a.label || a.name || "") : String(a);
676
+ const lb = (typeof b === "object") ? (b.label || b.name || "") : String(b);
677
+ if (sort === "value-asc") return va - vb;
678
+ if (sort === "alpha-asc") return String(la).localeCompare(String(lb));
679
+ if (sort === "alpha-desc") return String(lb).localeCompare(String(la));
680
+ return vb - va; // value-desc (default)
681
+ });
682
+ const limit = parseInt(this.getAttribute("limit") || "0", 10);
683
+ if (limit > 0) items = items.slice(0, limit);
684
+ // R31-60: scale bars against the largest MAGNITUDE, so a negative value
685
+ // produces a positive-width bar (a negative inline-size is invalid CSS
686
+ // and rendered nothing) and the sign is carried by the formatted value.
687
+ const max = items.reduce((m, it) => Math.max(m, Math.abs(typeof it === "object" ? (it.value || 0) : Number(it) || 0)), 0) || 1;
688
+ items.forEach((it, idx) => {
689
+ const value = (typeof it === "object") ? (it.value || 0) : (Number(it) || 0);
690
+ const label = (typeof it === "object") ? (it.label || it.name || "") : String(it);
691
+ const item = document.createElement("div");
692
+ item.className = "c-category__item";
693
+ item.setAttribute("role", "option");
694
+ item.setAttribute("aria-selected", "false");
695
+ item.setAttribute("tabindex", idx === 0 ? "0" : "-1");
696
+ const lbl = document.createElement("span");
697
+ lbl.className = "c-category__label";
698
+ lbl.textContent = label;
699
+ const barWrap = document.createElement("div");
700
+ barWrap.style.flex = "1";
701
+ const bar = document.createElement("div");
702
+ bar.className = "c-category__bar";
703
+ bar.style.inlineSize = ((Math.abs(value) / max) * 100) + "%";
704
+ barWrap.appendChild(bar);
705
+ const val = document.createElement("span");
706
+ val.className = "c-category__value";
707
+ val.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit"));
708
+ item.appendChild(lbl);
709
+ item.appendChild(barWrap);
710
+ item.appendChild(val);
711
+ this.appendChild(item);
712
+ });
713
+ if (!items.length) renderEmpty(this, "category");
714
+ const note = this.getAttribute("note");
715
+ let noteEl = this.querySelector(".c-category__note");
716
+ if (note) {
717
+ if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-category__note"; this.appendChild(noteEl); }
718
+ noteEl.textContent = note;
719
+ } else if (noteEl) {
720
+ noteEl.remove();
721
+ }
722
+ }
723
+ enhance() {
724
+ if (this._wiredCategory) return;
725
+ this._wiredCategory = true;
726
+ const items = () => Array.from(this.querySelectorAll(".c-category__item"));
727
+ const showTip = (e) => {};
728
+ this.addEventListener("click", (e) => {
729
+ const item = e.target && e.target.closest ? e.target.closest(".c-category__item") : null;
730
+ if (!item || !this.contains(item)) return;
731
+ const all = items();
732
+ const idx = all.indexOf(item);
733
+ all.forEach((o, i) => o.setAttribute("aria-selected", i === idx ? "true" : "false"));
734
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, label: item.querySelector(".c-category__label") ? item.querySelector(".c-category__label").textContent : item.textContent.trim() } }));
735
+ });
736
+ this.addEventListener("keydown", (e) => {
737
+ const item = e.target && e.target.closest ? e.target.closest(".c-category__item") : null;
738
+ if (!item || !this.contains(item)) return;
739
+ const all = items();
740
+ const idx = all.indexOf(item);
741
+ if (e.key === "Enter" || e.key === " ") {
742
+ e.preventDefault();
743
+ all.forEach((o, i) => o.setAttribute("aria-selected", i === idx ? "true" : "false"));
744
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, label: item.querySelector(".c-category__label") ? item.querySelector(".c-category__label").textContent : item.textContent.trim() } }));
745
+ return;
746
+ }
747
+ navKey(e, all, {
748
+ wrap: false,
749
+ homeEnd: true,
750
+ rtl: isRtl(this),
751
+ onNavigate: (i) => all.forEach((it, j) => it.setAttribute("tabindex", j === i ? "0" : "-1")),
752
+ onKey: () => {
753
+ if (e.key === "Enter" || e.key === " ") {
754
+ const idx2 = all.indexOf(document.activeElement);
755
+ all.forEach((o, j) => o.setAttribute("aria-selected", j === idx2 ? "true" : "false"));
756
+ this.dispatchEvent(new CustomEvent("contour:select", {
757
+ bubbles: true,
758
+ composed: true,
759
+ detail: {
760
+ index: idx2,
761
+ label: document.activeElement.querySelector(".c-category__label")
762
+ ? document.activeElement.querySelector(".c-category__label").textContent
763
+ : document.activeElement.textContent.trim()
764
+ }
765
+ }));
766
+ }
767
+ }
768
+ });
769
+ });
770
+ // Cross-filter contract (R16-16): clear-all resets search filter.
771
+ this.addEventListener("contour:clear-all", () => {
772
+ if (this.hasAttribute("search")) {
773
+ this.removeAttribute("search");
774
+ this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "category", filter: { search: null } } }));
775
+ }
776
+ });
777
+ }
778
+ }
779
+ define("contour-category", ContourCategory);