contour-ds 1.1.2 → 1.5.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 (71) hide show
  1. package/README.md +7 -1
  2. package/dist/agent-rules.json +5 -1
  3. package/dist/build-manifest.json +93 -92
  4. package/dist/contour-wc.esm.js +4113 -480
  5. package/dist/contour-wc.esm.min.js +1 -1
  6. package/dist/contour-wc.js +4115 -478
  7. package/dist/contour-wc.min.js +1 -1
  8. package/dist/contour.components.json +2597 -135
  9. package/dist/contour.css +625 -27
  10. package/dist/contour.d.ts +109 -61
  11. package/dist/contour.esm.js +16 -0
  12. package/dist/contour.js +16 -0
  13. package/dist/contour.min.css +1 -1
  14. package/dist/contour.tokens.json +37 -0
  15. package/dist/docs/actions.md +6 -2
  16. package/dist/docs/affordances.md +19 -3
  17. package/dist/docs/colour.md +2 -2
  18. package/dist/docs/componentindex.md +39 -0
  19. package/dist/docs/data.md +38 -3
  20. package/dist/docs/docs.md +6 -2
  21. package/dist/docs/feedback.md +13 -3
  22. package/dist/docs/field.md +7 -2
  23. package/dist/docs/forms.md +35 -3
  24. package/dist/docs/index.json +32 -76
  25. package/dist/docs/install.md +4 -2
  26. package/dist/docs/landing.md +3 -2
  27. package/dist/docs/mapengine.md +9 -3
  28. package/dist/docs/motion.md +5 -2
  29. package/dist/docs/navigation.md +10 -3
  30. package/dist/docs/overlays.md +26 -3
  31. package/dist/docs/overview.md +2 -2
  32. package/dist/docs/patterns.md +38 -3
  33. package/dist/docs/playground.md +5 -2
  34. package/dist/docs/principles.md +2 -2
  35. package/dist/docs/recipes.md +7 -3
  36. package/dist/docs/space.md +2 -2
  37. package/dist/docs/status.md +19 -3
  38. package/dist/docs/surfaces.md +7 -3
  39. package/dist/docs/theming.md +5 -2
  40. package/dist/docs/type.md +2 -2
  41. package/dist/docs/webcomponents.md +26 -3
  42. package/dist/map-chrome.mapbox.css +4 -4
  43. package/dist/map-chrome.maplibre.css +4 -4
  44. package/dist/registry/items/contour-core.json +2 -2
  45. package/dist/registry/items/contour-data.json +2 -2
  46. package/dist/registry/items/contour-docs.json +2 -2
  47. package/dist/registry/items/contour-landing.json +2 -2
  48. package/dist/registry/registry.json +8 -8
  49. package/dist/surfaces/contour-core.min.css +1 -1
  50. package/dist/surfaces/contour-data.min.css +1 -1
  51. package/dist/surfaces/contour-docs.min.css +1 -1
  52. package/dist/surfaces/contour-landing.min.css +1 -1
  53. package/dist/wc/behaviours.mjs +69 -11
  54. package/dist/wc/content.mjs +163 -8
  55. package/dist/wc/core.mjs +145 -34
  56. package/dist/wc/dashboard.mjs +69 -4
  57. package/dist/wc/data.mjs +866 -115
  58. package/dist/wc/docs.mjs +1 -0
  59. package/dist/wc/feedback.mjs +75 -13
  60. package/dist/wc/forms.mjs +371 -34
  61. package/dist/wc/index.mjs +7 -3
  62. package/dist/wc/interaction.mjs +11 -6
  63. package/dist/wc/map.mjs +121 -38
  64. package/dist/wc/misc.mjs +29 -1
  65. package/dist/wc/navigation.mjs +424 -75
  66. package/dist/wc/registration.mjs +8 -4
  67. package/dist/wc/shadow.mjs +29 -12
  68. package/dist/wc/states.mjs +15 -0
  69. package/dist/wc/svg.mjs +10 -0
  70. package/dist/wc/ui.mjs +1710 -126
  71. package/package.json +39 -6
package/dist/wc/core.mjs CHANGED
@@ -22,6 +22,7 @@
22
22
  // Every name this file actually registers, in registration order. define() is
23
23
  // the only door to the registry, so the list cannot drift from what the
24
24
  // browser was handed.
25
+ /** Names registered by this module, in registration order. */
25
26
  export const REGISTERED = [];
26
27
 
27
28
  // Per-host teardown, run when a host leaves the page.
@@ -39,23 +40,48 @@
39
40
  // `disconnectedCallback` runs the list. A reconnect re-renders and re-registers,
40
41
  // which is why the list is dropped rather than kept: one disposal per mount.
41
42
  const DISPOSERS = new WeakMap();
43
+ /** Register teardown work for the host's current connection. */
42
44
  export const onDispose = (host, fn) => {
43
45
  let list = DISPOSERS.get(host);
44
46
  if (!list) { list = []; DISPOSERS.set(host, list); }
45
47
  list.push(fn);
46
48
  };
49
+ function contourDebugEnabled() {
50
+ try {
51
+ if (typeof window !== "undefined" && (window.ContourDebug || window.__CONTOUR_DEBUG__)) return true;
52
+ } catch (e) {}
53
+ try {
54
+ if (typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production" && process.env.CONTOUR_DEBUG) return true;
55
+ } catch (e) {}
56
+ return false;
57
+ }
47
58
  const runDisposers = (host) => {
48
59
  const list = DISPOSERS.get(host);
49
60
  if (!list) return;
50
61
  DISPOSERS.delete(host);
51
- for (const fn of list) { try { fn(); } catch (e) { /* one bad cleanup cannot strand the rest */ } }
62
+ for (const fn of list) {
63
+ try { fn(); }
64
+ catch (e) {
65
+ // One bad cleanup cannot strand the rest. Surface the failure in
66
+ // development/debug mode so a leaking disposer is not invisible.
67
+ if (contourDebugEnabled()) {
68
+ try { console.warn("Contour disposer failed for", host && host.tagName, e); } catch (err) {}
69
+ }
70
+ }
71
+ }
52
72
  };
53
73
 
54
74
  // Monotonic counter for unique IDs (avoids Math.random() collision risk).
55
75
  let _contourIdCounter = 0;
76
+ /** Return a unique, document-safe id with the supplied prefix. */
56
77
  export const contourId = (prefix) => prefix + "-" + (++_contourIdCounter).toString(36);
57
78
 
79
+ /** Define a custom element once, while remaining safe in SSR runtimes. */
58
80
  export const define = (name, cls) => {
81
+ // SSR-safe / constrained-runtime boundary: if the Custom Elements registry
82
+ // is unavailable, do not throw on import; registration is a no-op and the
83
+ // element remains an unknown (upgradable) tag until a browser defines it.
84
+ if (typeof customElements === "undefined" || !customElements || typeof customElements.define !== "function") return;
59
85
  if (customElements.get(name)) return;
60
86
  customElements.define(name, cls);
61
87
  REGISTERED.push(name);
@@ -64,6 +90,7 @@
64
90
  // The attributes a consumer may set to ask for a modifier class. Both layers
65
91
  // read this one list: a wrapper that added a modifier from a different list is
66
92
  // how the light and shadow halves drifted apart over "color".
93
+ /** Attribute names that map to component modifier classes. */
67
94
  export const MODS = ["variant", "size", "color"];
68
95
 
69
96
  // Every event this layer emits, with the payload keys each one carries and
@@ -73,33 +100,41 @@
73
100
  // Payload keys are the union of keys every emission site passes, read from
74
101
  // the source rather than invented: contour:select carries {series, index},
75
102
  // {index, label} and {value} across its sites, so all three are listed.
103
+ /** Frozen event vocabulary with the public detail keys for each event. */
76
104
  export const CONTOUR_EVENTS = Object.freeze({
77
- "contour:activate": { payload: [], composed: true },
105
+ "contour:activate": { payload: ["row"], composed: true },
78
106
  "contour:add": { payload: ["value"], composed: true },
79
107
  "contour:activity-select": { payload: ["index", "text"], composed: true },
80
- "contour:break-change": { payload: ["value"], composed: true },
81
- "contour:style-resolved": { payload: ["value"], composed: true },
108
+ "contour:break-change": { payload: ["layer", "value"], composed: true },
109
+ "contour:style-resolved": { payload: ["applied", "items", "layer", "property", "value"], composed: true },
82
110
  "contour:advanced-toggle": { payload: ["title"], composed: true },
83
111
  "contour:affordance-activate": { payload: ["name"], composed: true },
112
+ "contour:aggregate": { payload: ["aggregate"], composed: true },
84
113
  "contour:bearing": { payload: ["direction", "degrees"], composed: true },
85
114
  "contour:btn-group-change": { payload: ["index", "label"], composed: true },
86
- "contour:brush-start": { payload: ["value"], composed: true },
87
- "contour:brush-end": { payload: ["value"], composed: true },
88
- "contour:change": { payload: ["name", "value", "checked"], composed: true },
115
+ "contour:brush-start": { payload: ["end", "start", "value"], composed: true },
116
+ "contour:brush-end": { payload: ["end", "start", "value"], composed: true },
117
+ "contour:change": { payload: ["checked", "color", "direction", "end", "files", "high", "index", "low", "month", "name", "speed", "start", "unit", "value", "year"], composed: true },
118
+ "contour:collapse": { payload: ["collapsed"], composed: true },
119
+ "contour:cluster-toggle": { payload: ["count", "expanded"], composed: true },
89
120
  "contour:clear": { payload: [], composed: true },
90
- "contour:close": { payload: [], composed: true },
121
+ "contour:clear-all": { payload: [], composed: true },
122
+ "contour:close": { payload: ["index", "label"], composed: true },
91
123
  "contour:copy": { payload: ["text"], composed: true },
92
124
  "contour:dash-action": { payload: ["label"], composed: true },
93
125
  "contour:diff-activate": { payload: ["kind", "text"], composed: true },
94
- "contour:drag": { payload: ["value"], composed: true },
126
+ "contour:draw-start": { payload: ["mode"], composed: true },
127
+ "contour:drag": { payload: ["delta", "key", "value"], composed: true },
95
128
  "contour:do-dont-activate": { payload: ["kind", "text"], composed: true },
96
129
  "contour:docs-nav-select": { payload: ["label", "href"], composed: true },
97
130
  "contour:dragend": { payload: ["value"], composed: true },
98
131
  "contour:dragstart": { payload: ["value"], composed: true },
99
132
  "contour:drop": { payload: ["value", "label"], composed: true },
100
133
  "contour:empty-action": { payload: ["state"], composed: true },
134
+ "contour:filter": { payload: ["query"], composed: true },
101
135
  "contour:error": { payload: ["src", "message", "name", "status"], composed: true },
102
136
  "contour:hide": { payload: [], composed: true },
137
+ "contour:hover": { payload: ["row"], composed: true },
103
138
  "contour:input": { payload: ["name", "value", "checked"], composed: true },
104
139
  "contour:layer-opacity": { payload: ["name", "opacity"], composed: true },
105
140
  "contour:layer-rename": { payload: ["name", "newName"], composed: true },
@@ -108,39 +143,44 @@
108
143
  "contour:layer-projection": { payload: ["name", "projection"], composed: true },
109
144
  "contour:layer-remove": { payload: ["name"], composed: true },
110
145
  "contour:layer-reorder": { payload: ["layerIds"], composed: true },
111
- "contour:layer-toggle": { payload: ["name"], composed: true },
146
+ "contour:layer-toggle": { payload: ["name", "visible"], composed: true },
112
147
  "contour:layer-visibility": { payload: ["name", "visible"], composed: true },
113
- "contour:legend-toggle": { payload: ["label", "key", "layers", "pressed"], composed: true },
148
+ "contour:legend-toggle": { payload: ["key", "label", "pressed"], composed: true },
149
+ "contour:leave": { payload: [], composed: true },
114
150
  "contour:load": { payload: ["src", "count"], composed: true },
115
151
  "contour:map-control": { payload: ["control"], composed: true },
116
152
  "contour:map-attach": { payload: [], composed: true },
117
153
  "contour:map-detach": { payload: [], composed: true },
118
154
  "contour:mode-change": { payload: ["mode"], composed: true },
119
- "contour:move": { payload: ["direction"], composed: true },
155
+ "contour:move": { payload: ["direction", "from", "to"], composed: true },
120
156
  "contour:open": { payload: [], composed: true },
121
157
  "contour:page": { payload: ["page"], composed: true },
122
158
  "contour:ready": { payload: ["version", "count"], composed: true },
123
- "contour:remove": { payload: ["label", "key", "layers", "value"], composed: true },
159
+ "contour:remove": { payload: ["key", "label", "value"], composed: true },
160
+ "contour:reorder": { payload: ["from", "to"], composed: true },
124
161
  "contour:range-change": { payload: ["value"], composed: true },
162
+ "contour:resize": { payload: ["height", "width"], composed: true },
125
163
  "contour:retry": { payload: ["src"], composed: true },
126
164
  "contour:loop-change": { payload: ["loop"], composed: true },
127
165
  "contour:pause": { payload: [], composed: true },
128
166
  "contour:play": { payload: [], composed: true },
129
167
  "contour:seek": { payload: ["progress", "value"], composed: true },
130
- "contour:select": { payload: ["series", "index", "label", "value"], composed: true },
168
+ "contour:select": { payload: ["area", "col", "index", "key", "label", "labels", "path", "row", "rows", "series", "value"], composed: true },
169
+ "contour:search": { payload: ["query"], composed: true },
131
170
  "contour:speed-change": { payload: ["speed"], composed: true },
132
171
  "contour:showcase-activate": { payload: ["title"], composed: true },
133
172
  "contour:step-activate": { payload: ["index", "title"], composed: true },
134
- "contour:step-change": { payload: ["index", "title"], composed: true },
173
+ "contour:step-change": { payload: ["direction", "index", "title"], composed: true },
135
174
  "contour:show": { payload: [], composed: true },
136
175
  "contour:sort": { payload: ["column", "direction"], composed: true },
176
+ "contour:submit": { payload: ["submitting"], composed: true },
137
177
  "contour:stream-state": { payload: ["running"], composed: true },
138
178
  "contour:tab-change": { payload: ["index", "label"], composed: true },
139
179
  "contour:theme-change": { payload: ["theme"], composed: true },
140
180
  "contour:tick": { payload: ["frame"], composed: true },
141
- "contour:time-change": { payload: ["value"], composed: true },
181
+ "contour:time-change": { payload: ["progress", "value"], composed: true },
142
182
  "contour:time-range-change": { payload: ["value"], composed: true },
143
- "contour:toggle": { payload: ["open", "label"], composed: true },
183
+ "contour:toggle": { payload: ["expanded", "label", "open", "path", "playing"], composed: true },
144
184
  "contour:view-enter": { payload: [], composed: true },
145
185
  "contour:view-leave": { payload: [], composed: true },
146
186
  });
@@ -148,9 +188,15 @@
148
188
  // Shared HTML sanitizer (B3-18): allowlist via DOMParser instead of a
149
189
  // blacklist regex, so single-quoted, unquoted and javascript: payloads
150
190
  // cannot slip through.
191
+ /** Sanitize consumer-provided HTML using a DOM allowlist. */
151
192
  export function sanitizeHtml(input) {
152
193
  const str = String(input == null ? "" : input);
153
- if (typeof DOMParser === "undefined") return str;
194
+ // Fail closed when no parser is available (SSR, constrained runtimes):
195
+ // never treat "no parser" as "trusted markup". Return the input as inert
196
+ // text so no tag is interpreted by an innerHTML assignment.
197
+ if (typeof DOMParser === "undefined") {
198
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
199
+ }
154
200
  const doc = new DOMParser().parseFromString(str, "text/html");
155
201
  const drop = new Set(["script", "iframe", "object", "embed", "style", "link", "meta", "base", "form", "input", "button"]);
156
202
  const walk = (node) => {
@@ -182,18 +228,20 @@
182
228
  // Excluded because the render bodies below set them on the host:
183
229
  // role, open, aria-label, aria-valuenow, aria-valuemin, aria-valuemax, tabindex
184
230
  // Adding one of those back to this list makes that component recurse.
231
+ /** Shared attribute vocabulary used by components that opt into defaults. */
185
232
  export const OBSERVED = [
186
- "accept", "action", "actions", "after", "allow-duplicate", "allow-remove", "allow-rename", "allow-zoom", "anchor", "answer", "area", "article", "attribution", "attribution-mark", "audit", "autoplay", "axis", "axis-x", "axis-y", "brownout", "brownout-level", "before", "body", "brand", "breakpoint", "breaks", "cache-key", "canvas", "center", "clearable", "cols", "columns", "color", "command",
187
- "cells", "checked", "chrome", "closable", "classification", "colors", "continuous", "content", "controls", "copyable", "count", "current", "data", "date", "delta", "description", "glyphs", "demo", "density", "desc", "dir", "direction", "disabled", "dismissible", "divider", "do", "dont", "dot", "ends", "high", "input", "layer", "low", "mode", "modes", "n", "opacity", "palette", "polarity", "range", "single",
188
- "empty", "error", "exclusive", "format", "heading", "hint", "href", "icon", "illustration", "index", "instrument", "interval", "items", "key", "layers", "level",
189
- "label", "lazy", "lede", "legend", "line", "link", "links", "live", "loading", "locale", "loop", "max", "media", "message", "method", "month", "menu", "min", "multiple", "name", "needle", "next", "no", "no-cache", "no-data-message", "nodes", "note", "norm", "normalize",
190
- "options", "orientation", "page-size", "pages", "pause", "paused", "pausable", "persist", "placeholder", "playing", "point", "points", "prev", "progress", "prompt", "question", "recent", "required",
191
- "quote", "ramp", "refresh", "removable", "reverse", "rings", "retry", "rows", "scale", "selectable", "segments", "show-header", "sparkline", "start", "end", "threshold", "thresholds", "selected", "separator", "series", "shortcut", "side", "size", "skeleton", "sort", "sort-dir", "speed", "status", "step", "submit", "timeout", "trigger", "virtual",
192
- "state", "steps", "subtitle", "summary", "src", "table", "tabs", "tag", "text", "ticks", "title", "type", "unit",
233
+ "accept", "action", "actions", "active", "after", "allow-duplicate", "allow-remove", "allow-rename", "allow-zoom", "alpha", "anchor", "answer", "area", "article", "attribution", "attribution-mark", "audit", "autoplay", "axis", "axis-x", "axis-y", "brownout", "brownout-level", "before", "body", "brand", "breakpoint", "breaks", "brush", "brush-end", "brush-max", "brush-min", "brush-start", "cache-key", "canvas", "center", "clearable", "cols", "columns", "color", "command",
234
+ "cells", "checked", "chrome", "debounce", "closable", "collapsed", "collapsible", "classification", "colors", "continuous", "content", "controls", "copyable", "count", "data", "data-table", "date", "delta", "description", "glyphs", "demo", "density", "desc", "dir", "direction", "disabled", "distance", "dismissible", "divider", "do", "dont", "dot", "ends", "high", "input", "layer", "low", "mode", "modes", "n", "opacity", "palette", "polarity", "precision", "range", "single",
235
+ "empty", "exclusive", "fallback", "format", "heading", "help", "hint", "href", "icon", "illustration", "instrument", "interval", "items", "key", "layers", "level", "range-end", "range-start",
236
+ "label", "lazy", "lede", "legend", "line", "limit", "link", "links", "live", "loading", "locale", "loop", "max", "media", "message", "method", "menu", "min", "multiple", "name", "needle", "next", "no", "no-cache", "no-data-message", "nodes", "note", "norm", "normalize",
237
+ "options", "orientation", "page-size", "pages", "pause", "paused", "pausable", "persist", "placeholder", "playing", "point", "points", "prev", "presets", "progress", "prompt", "question", "recent", "required",
238
+ "quote", "ramp", "refresh", "removable", "resolution", "reverse", "rings", "retry", "results", "rows", "scale", "selectable", "segments", "show-header", "sparkline", "threshold", "thresholds", "selected", "separator", "series", "shortcut", "side", "size", "skeleton", "sort", "sort-dir", "speed", "status", "step", "submit", "submitting", "timeout", "trigger", "virtual", "sticky", "cluster-count", "cluster-expanded", "time", "resizable",
239
+ "state", "steps", "style", "subtitle", "summary", "src", "table", "tabs", "tag", "text", "ticks", "title", "type", "unit", "cluster-items", "row-height",
193
240
  "variant", "values", "viewport", "yes", "zoomable", "x", "y",
194
- "caption", "current-time", "is-playing", "loop-label", "no-data-color", "property", "show-loop", "show-thumb", "show-thumb-caption", "speeds",
241
+ "caption", "current-time", "is-playing", "loop-label", "no-data-color", "property", "show-loop", "show-thumb", "show-thumb-caption", "speeds", "item-height", "pause-label", "play-label", "speed-label", "time-label", "shimmer",
195
242
  ];
196
243
 
244
+ /** Resolve an authored heading level while keeping the fallback valid. */
197
245
  export function headingTag(host, fallback = "h3") {
198
246
  const v = host && host.getAttribute ? host.getAttribute("heading") : null;
199
247
  return /^h[1-6]$/.test(v || "") ? v : fallback;
@@ -223,7 +271,12 @@
223
271
  // consumer put on authored children survive a re-render. The cost is honest:
224
272
  // nodes a component generated are rebuilt, so state inside them (a typed
225
273
  // value, a focus ring) is lost when a host attribute changes.
226
- export class ContourBase extends HTMLElement {
274
+ // SSR-safe base (R12-25): in a non-DOM runtime (Node, type-only tooling)
275
+ // HTMLElement is undefined. Fall back to Object so the module can be imported
276
+ // for metadata/type inspection without a DOM shim; components cannot be
277
+ // instantiated there, which is the correct boundary.
278
+ const _ContourBaseParent = (typeof HTMLElement !== "undefined") ? HTMLElement : Object;
279
+ export class ContourBase extends _ContourBaseParent {
227
280
  static formAssociated = false;
228
281
  constructor() {
229
282
  super();
@@ -248,6 +301,16 @@
248
301
  return {};
249
302
  }
250
303
 
304
+ // Update policy (R12-06): "scaffold" components may rebuild their generated
305
+ // DOM on attribute change (the default lifecycle). High-volume components
306
+ // (table, grid, tree, virtual-list, chart) should override to "keyed" and
307
+ // use ensure()/keyed patching, or expose an imperative update method.
308
+ // Documented here so consumers know which components guarantee identity
309
+ // stability across renders.
310
+ static get updateMode() {
311
+ return "scaffold";
312
+ }
313
+
251
314
  // How many times this host has run `render()`, counting the first connect.
252
315
  // Read-only and diagnostic: it exists so a page can show that `batch()` did
253
316
  // what it claims instead of asking the reader to believe it, and so a test can
@@ -275,8 +338,8 @@
275
338
  Object.defineProperty(ctor.prototype, name, {
276
339
  get() {
277
340
  const raw = this.getAttribute(attr);
341
+ if (type === Boolean) return raw !== null;
278
342
  if (raw === null) return spec && spec.default !== undefined ? spec.default : null;
279
- if (type === Boolean) return true;
280
343
  if (type === Number) { const n = Number(raw); return Number.isNaN(n) ? null : n; }
281
344
  return raw;
282
345
  },
@@ -718,6 +781,7 @@
718
781
  // render. Usage: el.batch(() => { el.value = 42; el.delta = "+3"; });
719
782
  // The render fires once when the callback returns, reading all final
720
783
  // attribute values. Nested calls are supported.
784
+ /** Coalesce synchronous property changes into one render. */
721
785
  batch(fn) {
722
786
  if (typeof fn !== "function") return;
723
787
  this._batchDepth = (this._batchDepth || 0) + 1;
@@ -842,6 +906,7 @@
842
906
  }
843
907
 
844
908
  // Simple component: just adds CSS classes.
909
+ /** Create a light-DOM component that only applies block and modifier classes. */
845
910
  export const simple = (classes) => class extends ContourBase {
846
911
  render() {
847
912
  classes.forEach((c) => this.classList.add(c));
@@ -869,6 +934,7 @@
869
934
  // here — they declare a class above, and their presence in this list would be
870
935
  // a fallback that only runs when the real component is broken, so the
871
936
  // registration loop skips a name an explicit component already claimed.
937
+ /** Blocks whose custom elements need no generated markup. */
872
938
  export const CLASS_ONLY = [
873
939
  "box", "cluster", "container", "row", "scrim", "stack"
874
940
  ];
@@ -876,6 +942,7 @@
876
942
  // Feature detection for `hidden="until-found"` (BY-51). Browsers that do not
877
943
  // support it treat the value as the boolean hidden attribute, which would
878
944
  // hide the content permanently — so we only upgrade where supported.
945
+ /** Detect support for the non-destructive `hidden="until-found"` value. */
879
946
  export function supportsUntilFound() {
880
947
  try {
881
948
  const t = document.createElement("div");
@@ -884,11 +951,13 @@
884
951
  } catch (e) { return false; }
885
952
  }
886
953
 
887
- // Value formatting (BY-31): opt-in Intl formatting for kpi/stat/readout/coordinate.
888
- // `format` is a preset ("number","currency","percent","compact","date","time")
889
- // or a JSON string of Intl.NumberFormat/DateTimeFormat options. `locale`
890
- // defaults to the runtime locale. Returns the raw value when formatting fails.
891
- export function formatValue(value, format, locale) {
954
+ // Value formatting (BY-31/BY-22): opt-in Intl formatting for kpi/stat/readout/coordinate.
955
+ // `format` is a preset ("number","currency","percent","compact","date","time",
956
+ // "unit","relative") or a JSON string of Intl.NumberFormat/DateTimeFormat/
957
+ // RelativeTimeFormat options. `locale` defaults to the runtime locale.
958
+ // Returns the raw value when formatting fails.
959
+ /** Format a value with the component's supported Intl presets. */
960
+ export function formatValue(value, format, locale, unit) {
892
961
  if (!format) return value;
893
962
  const loc = locale || (typeof navigator !== "undefined" && navigator.language) || "en";
894
963
  if (format === "date" || format === "time") {
@@ -897,10 +966,27 @@
897
966
  return new Intl.DateTimeFormat(loc, opts).format(new Date(value));
898
967
  } catch (e) { return value; }
899
968
  }
969
+ if (format === "relative") {
970
+ try {
971
+ const num = Number(value);
972
+ // Interpret the value as seconds from now unless it is an ISO date.
973
+ let seconds = num;
974
+ if (Number.isNaN(num)) {
975
+ const then = new Date(value).getTime();
976
+ if (Number.isFinite(then)) seconds = (then - Date.now()) / 1000;
977
+ }
978
+ const rtf = new Intl.RelativeTimeFormat(loc, { numeric: "auto" });
979
+ if (Math.abs(seconds) < 60) return rtf.format(Math.round(seconds), "second");
980
+ if (Math.abs(seconds) < 3600) return rtf.format(Math.round(seconds / 60), "minute");
981
+ if (Math.abs(seconds) < 86400) return rtf.format(Math.round(seconds / 3600), "hour");
982
+ return rtf.format(Math.round(seconds / 86400), "day");
983
+ } catch (e) { return value; }
984
+ }
900
985
  let opts = {};
901
986
  if (format === "currency") opts = { style: "currency", currency: "USD" };
902
987
  else if (format === "percent") opts = { style: "percent" };
903
988
  else if (format === "compact") opts = { notation: "compact" };
989
+ else if (format === "unit") opts = { style: "unit", unit: unit || "meter" };
904
990
  else if (format !== "number") {
905
991
  try { opts = JSON.parse(format); } catch (e) { return value; }
906
992
  }
@@ -908,4 +994,29 @@
908
994
  catch (e) { return value; }
909
995
  }
910
996
 
911
-
997
+ // Spatial maths (BY-23): pure functions on the host's own attributes.
998
+ // Haversine distance in meters between two lat/lon points.
999
+ /** Return the great-circle distance between two latitude/longitude points. */
1000
+ export function haversine(lat1, lon1, lat2, lon2) {
1001
+ const R = 6371000;
1002
+ const toRad = (d) => d * Math.PI / 180;
1003
+ const dLat = toRad(lat2 - lat1);
1004
+ const dLon = toRad(lon2 - lon1);
1005
+ const a = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon / 2) ** 2;
1006
+ return 2 * R * Math.asin(Math.sqrt(a));
1007
+ }
1008
+ // Bearing in degrees (clockwise from north) from point 1 to point 2.
1009
+ /** Return the initial bearing from one latitude/longitude point to another. */
1010
+ export function bearing(lat1, lon1, lat2, lon2) {
1011
+ const toRad = (d) => d * Math.PI / 180;
1012
+ const toDeg = (r) => r * 180 / Math.PI;
1013
+ const dLon = toRad(lon2 - lon1);
1014
+ const y = Math.sin(dLon) * Math.cos(toRad(lat2));
1015
+ const x = Math.cos(toRad(lat1)) * Math.sin(toRad(lat2)) - Math.sin(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.cos(dLon);
1016
+ return (toDeg(Math.atan2(y, x)) + 360) % 360;
1017
+ }
1018
+ // Mercator resolution (meters per pixel) at a given latitude and zoom.
1019
+ /** Return meters per pixel for Web Mercator at a latitude and zoom level. */
1020
+ export function mercatorResolution(lat, zoom) {
1021
+ return 156543.03392 * Math.cos(lat * Math.PI / 180) / Math.pow(2, zoom);
1022
+ }
@@ -1,4 +1,45 @@
1
- import { ContourBase, define } from './core.mjs';
1
+ import { ContourBase, define, formatValue } from './core.mjs';
2
+
3
+ /**
4
+ * Dashboard state machine (R13-06).
5
+ *
6
+ * A dashboard widget moves through a small, well-defined set of states:
7
+ * loading -> data is being fetched/rendered (show skeleton/spinner)
8
+ * empty -> fetch resolved but no rows/points (show empty state)
9
+ * error -> fetch failed (show error + retry affordance)
10
+ * stale -> data present but older than the freshness threshold
11
+ * ready -> data present and current (default)
12
+ *
13
+ * Components that participate:
14
+ * - contour-widget-state : renders the state chrome (loading/empty/error)
15
+ * via its `state` attribute; emits `contour:retry` on retry click.
16
+ * - contour-brownout : sheds non-essential chrome at levels 1-3
17
+ * (level 3 drops the dial/ring entirely).
18
+ * - contour-dash-freshness : live region announcing the last-updated value;
19
+ * consumers set `value` to an ISO timestamp and `format`/`locale`.
20
+ * - contour-dash-kpi-row : renders one contour-kpi per item; emits
21
+ * `contour:select` with { index } on click.
22
+ *
23
+ * Retry/offline handling lives in the consumer (libreship): contour-ds only
24
+ * provides the affordances (retry button in widget-state, brownout levels,
25
+ * freshness live region). No data fetching or state management is shipped.
26
+ *
27
+ * Slot contracts (R13-17):
28
+ * - contour-dash-shell : light-DOM children become the grid cells; the
29
+ * optional `title` attribute generates a contour-dash-toolbar with a
30
+ * `.c-dash-toolbar__title`. No shadow slots.
31
+ * - contour-dash-toolbar : light-DOM children are appended after the
32
+ * generated title/actions; `.c-dash-toolbar__actions` is generated from
33
+ * the `actions` JSON attribute.
34
+ * - contour-dash-kpi-row : light-DOM children are replaced by generated
35
+ * contour-kpi elements from the `items` attribute; authored children are
36
+ * only kept when no items are provided.
37
+ * - contour-dash-freshness : no slots; renders a `.c-dot` + text node.
38
+ * - contour-widget-state : light-DOM children are the fallback content
39
+ * shown in the ready state.
40
+ * - contour-brownout : light-DOM children are the content that may be
41
+ * shed at higher brownout levels.
42
+ */
2
43
  class ContourDashShell extends ContourBase {
3
44
  static get observed() { return ["title"]; }
4
45
  static get properties() { return { title: { attribute: "title" } }; }
@@ -62,6 +103,17 @@ class ContourDashToolbar extends ContourBase {
62
103
  this.dispatchEvent(new CustomEvent("contour:dash-action", { bubbles: true, composed: true, detail: { label } }));
63
104
  }
64
105
  });
106
+ this.addEventListener("keydown", (e) => {
107
+ const btn = e.target && e.target.closest ? e.target.closest(".c-btn") : null;
108
+ if (!btn || !this.contains(btn)) return;
109
+ const btns = Array.from(this.querySelectorAll(".c-btn"));
110
+ const idx = btns.indexOf(btn);
111
+ let next = -1;
112
+ if (e.key === "ArrowRight") next = Math.min(btns.length - 1, idx + 1);
113
+ else if (e.key === "ArrowLeft") next = Math.max(0, idx - 1);
114
+ if (next >= 0) { e.preventDefault(); try { btns[next].focus(); } catch (err) {} }
115
+ else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); btn.click(); }
116
+ });
65
117
  }
66
118
  }
67
119
  define("contour-dash-toolbar", ContourDashToolbar);
@@ -95,11 +147,23 @@ class ContourDashKpiRow extends ContourBase {
95
147
  this.appendChild(k);
96
148
  }
97
149
  }
150
+ enhance() {
151
+ if (this._wiredDashKpiRow) return;
152
+ this._wiredDashKpiRow = true;
153
+ this.addEventListener("click", (e) => {
154
+ const kpi = e.target && e.target.closest ? e.target.closest("contour-kpi") : null;
155
+ if (kpi && this.contains(kpi)) {
156
+ const kpis = Array.from(this.querySelectorAll("contour-kpi"));
157
+ const idx = kpis.indexOf(kpi);
158
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx } }));
159
+ }
160
+ });
161
+ }
98
162
  }
99
163
  define("contour-dash-kpi-row", ContourDashKpiRow);
100
164
  class ContourDashFreshness extends ContourBase {
101
- static get observed() { return ["label", "value"]; }
102
- static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" } }; }
165
+ static get observed() { return ["label", "value", "format", "locale"]; }
166
+ static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, format: { attribute: "format" }, locale: { attribute: "locale" } }; }
103
167
  render() {
104
168
  this.classList.add("c-dash-freshness");
105
169
  this.setAttribute("role", "status");
@@ -116,7 +180,8 @@ class ContourDashFreshness extends ContourBase {
116
180
  this._freshnessText = document.createTextNode("");
117
181
  this.appendChild(this._freshnessText);
118
182
  }
119
- this._freshnessText.nodeValue = [label, value].filter(Boolean).join(" ");
183
+ const formattedValue = value ? formatValue(value, this.getAttribute("format"), this.getAttribute("locale")) : value;
184
+ this._freshnessText.nodeValue = [label, formattedValue].filter(Boolean).join(" ");
120
185
  }
121
186
  }
122
187
  define("contour-dash-freshness", ContourDashFreshness);