contour-ds 1.1.2 → 1.7.1
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 +30 -2
- package/dist/agent-rules.json +5 -1
- package/dist/build-manifest.json +94 -93
- package/dist/contour-wc.esm.js +4443 -534
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +4441 -528
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.components.json +4054 -171
- package/dist/contour.css +1325 -565
- package/dist/contour.d.ts +119 -62
- package/dist/contour.esm.js +23 -0
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.js +23 -0
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.tokens.json +47 -2
- package/dist/docs/actions.md +6 -2
- package/dist/docs/affordances.md +19 -3
- package/dist/docs/apireference.md +30 -0
- package/dist/docs/colour.md +2 -2
- package/dist/docs/componentindex.md +39 -0
- package/dist/docs/data.md +38 -3
- package/dist/docs/docs.md +6 -2
- package/dist/docs/feedback.md +13 -3
- package/dist/docs/field.md +7 -2
- package/dist/docs/forms.md +35 -3
- package/dist/docs/index.json +44 -75
- package/dist/docs/install.md +4 -2
- package/dist/docs/landing.md +3 -2
- package/dist/docs/mapengine.md +9 -3
- package/dist/docs/motion.md +5 -2
- package/dist/docs/navigation.md +10 -3
- package/dist/docs/overlays.md +26 -3
- package/dist/docs/overview.md +2 -2
- package/dist/docs/patterns.md +38 -3
- package/dist/docs/playground.md +5 -2
- package/dist/docs/principles.md +2 -2
- package/dist/docs/recipes.md +7 -3
- package/dist/docs/space.md +2 -2
- package/dist/docs/status.md +19 -3
- package/dist/docs/surfaces.md +7 -3
- package/dist/docs/theming.md +5 -2
- package/dist/docs/type.md +2 -2
- package/dist/docs/webcomponents.md +26 -7
- package/dist/map-chrome.mapbox.css +4 -4
- package/dist/map-chrome.maplibre.css +4 -4
- 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/wc/behaviours.mjs +69 -11
- package/dist/wc/content.mjs +163 -8
- package/dist/wc/core.mjs +177 -36
- package/dist/wc/dashboard.mjs +69 -4
- package/dist/wc/data.mjs +933 -128
- package/dist/wc/docs.mjs +118 -0
- package/dist/wc/feedback.mjs +75 -13
- package/dist/wc/forms.mjs +371 -34
- package/dist/wc/index.mjs +31 -3
- package/dist/wc/interaction.mjs +11 -6
- package/dist/wc/map.mjs +142 -38
- package/dist/wc/misc.mjs +29 -1
- package/dist/wc/navigation.mjs +424 -75
- package/dist/wc/registration.mjs +8 -4
- package/dist/wc/shadow.mjs +29 -12
- package/dist/wc/states.mjs +15 -0
- package/dist/wc/svg.mjs +10 -0
- package/dist/wc/ui.mjs +1767 -129
- 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) {
|
|
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,44 @@
|
|
|
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:
|
|
115
|
+
"contour:brush-start": { payload: ["end", "start", "value"], composed: true },
|
|
116
|
+
"contour:brush-end": { payload: ["end", "start", "value"], composed: true },
|
|
117
|
+
"contour:brush": { payload: ["end", "start", "value"], composed: true },
|
|
118
|
+
"contour:change": { payload: ["checked", "color", "direction", "end", "files", "high", "index", "low", "month", "name", "speed", "start", "unit", "value", "year"], composed: true },
|
|
119
|
+
"contour:collapse": { payload: ["collapsed"], composed: true },
|
|
120
|
+
"contour:cluster-toggle": { payload: ["count", "expanded"], composed: true },
|
|
89
121
|
"contour:clear": { payload: [], composed: true },
|
|
90
|
-
"contour:
|
|
122
|
+
"contour:clear-all": { payload: [], composed: true },
|
|
123
|
+
"contour:close": { payload: ["index", "label"], composed: true },
|
|
91
124
|
"contour:copy": { payload: ["text"], composed: true },
|
|
92
125
|
"contour:dash-action": { payload: ["label"], composed: true },
|
|
93
126
|
"contour:diff-activate": { payload: ["kind", "text"], composed: true },
|
|
94
|
-
"contour:
|
|
127
|
+
"contour:draw-start": { payload: ["mode"], composed: true },
|
|
128
|
+
"contour:drag": { payload: ["delta", "key", "value"], composed: true },
|
|
95
129
|
"contour:do-dont-activate": { payload: ["kind", "text"], composed: true },
|
|
96
130
|
"contour:docs-nav-select": { payload: ["label", "href"], composed: true },
|
|
97
131
|
"contour:dragend": { payload: ["value"], composed: true },
|
|
98
132
|
"contour:dragstart": { payload: ["value"], composed: true },
|
|
99
133
|
"contour:drop": { payload: ["value", "label"], composed: true },
|
|
100
134
|
"contour:empty-action": { payload: ["state"], composed: true },
|
|
101
|
-
"contour:
|
|
135
|
+
"contour:filter": { payload: ["query"], composed: true },
|
|
136
|
+
"contour:error": { payload: ["src", "message", "name", "status"], composed: true },
|
|
137
|
+
"contour:export": { payload: ["format"], composed: true },
|
|
138
|
+
"contour:refresh": { payload: [], composed: true },
|
|
102
139
|
"contour:hide": { payload: [], composed: true },
|
|
140
|
+
"contour:hover": { payload: ["row"], composed: true },
|
|
103
141
|
"contour:input": { payload: ["name", "value", "checked"], composed: true },
|
|
104
142
|
"contour:layer-opacity": { payload: ["name", "opacity"], composed: true },
|
|
105
143
|
"contour:layer-rename": { payload: ["name", "newName"], composed: true },
|
|
@@ -108,39 +146,44 @@
|
|
|
108
146
|
"contour:layer-projection": { payload: ["name", "projection"], composed: true },
|
|
109
147
|
"contour:layer-remove": { payload: ["name"], composed: true },
|
|
110
148
|
"contour:layer-reorder": { payload: ["layerIds"], composed: true },
|
|
111
|
-
"contour:layer-toggle": { payload: ["name"], composed: true },
|
|
149
|
+
"contour:layer-toggle": { payload: ["name", "visible"], composed: true },
|
|
112
150
|
"contour:layer-visibility": { payload: ["name", "visible"], composed: true },
|
|
113
|
-
"contour:legend-toggle": { payload: ["
|
|
151
|
+
"contour:legend-toggle": { payload: ["key", "label", "pressed"], composed: true },
|
|
152
|
+
"contour:leave": { payload: [], composed: true },
|
|
114
153
|
"contour:load": { payload: ["src", "count"], composed: true },
|
|
115
154
|
"contour:map-control": { payload: ["control"], composed: true },
|
|
116
155
|
"contour:map-attach": { payload: [], composed: true },
|
|
117
156
|
"contour:map-detach": { payload: [], composed: true },
|
|
118
157
|
"contour:mode-change": { payload: ["mode"], composed: true },
|
|
119
|
-
"contour:move": { payload: ["direction"], composed: true },
|
|
158
|
+
"contour:move": { payload: ["direction", "from", "to"], composed: true },
|
|
120
159
|
"contour:open": { payload: [], composed: true },
|
|
121
160
|
"contour:page": { payload: ["page"], composed: true },
|
|
122
161
|
"contour:ready": { payload: ["version", "count"], composed: true },
|
|
123
|
-
"contour:remove": { payload: ["
|
|
162
|
+
"contour:remove": { payload: ["key", "label", "value"], composed: true },
|
|
163
|
+
"contour:reorder": { payload: ["from", "to"], composed: true },
|
|
124
164
|
"contour:range-change": { payload: ["value"], composed: true },
|
|
165
|
+
"contour:resize": { payload: ["height", "width"], composed: true },
|
|
125
166
|
"contour:retry": { payload: ["src"], composed: true },
|
|
126
167
|
"contour:loop-change": { payload: ["loop"], composed: true },
|
|
127
168
|
"contour:pause": { payload: [], composed: true },
|
|
128
169
|
"contour:play": { payload: [], composed: true },
|
|
129
170
|
"contour:seek": { payload: ["progress", "value"], composed: true },
|
|
130
|
-
"contour:select": { payload: ["
|
|
171
|
+
"contour:select": { payload: ["area", "col", "index", "key", "label", "labels", "path", "row", "rows", "series", "value"], composed: true },
|
|
172
|
+
"contour:search": { payload: ["query"], composed: true },
|
|
131
173
|
"contour:speed-change": { payload: ["speed"], composed: true },
|
|
132
174
|
"contour:showcase-activate": { payload: ["title"], composed: true },
|
|
133
175
|
"contour:step-activate": { payload: ["index", "title"], composed: true },
|
|
134
|
-
"contour:step-change": { payload: ["index", "title"], composed: true },
|
|
176
|
+
"contour:step-change": { payload: ["direction", "index", "title"], composed: true },
|
|
135
177
|
"contour:show": { payload: [], composed: true },
|
|
136
178
|
"contour:sort": { payload: ["column", "direction"], composed: true },
|
|
179
|
+
"contour:submit": { payload: ["submitting"], composed: true },
|
|
137
180
|
"contour:stream-state": { payload: ["running"], composed: true },
|
|
138
181
|
"contour:tab-change": { payload: ["index", "label"], composed: true },
|
|
139
182
|
"contour:theme-change": { payload: ["theme"], composed: true },
|
|
140
183
|
"contour:tick": { payload: ["frame"], composed: true },
|
|
141
|
-
"contour:time-change": { payload: ["value"], composed: true },
|
|
184
|
+
"contour:time-change": { payload: ["progress", "value"], composed: true },
|
|
142
185
|
"contour:time-range-change": { payload: ["value"], composed: true },
|
|
143
|
-
"contour:toggle": { payload: ["
|
|
186
|
+
"contour:toggle": { payload: ["expanded", "label", "open", "path", "playing"], composed: true },
|
|
144
187
|
"contour:view-enter": { payload: [], composed: true },
|
|
145
188
|
"contour:view-leave": { payload: [], composed: true },
|
|
146
189
|
});
|
|
@@ -148,9 +191,15 @@
|
|
|
148
191
|
// Shared HTML sanitizer (B3-18): allowlist via DOMParser instead of a
|
|
149
192
|
// blacklist regex, so single-quoted, unquoted and javascript: payloads
|
|
150
193
|
// cannot slip through.
|
|
194
|
+
/** Sanitize consumer-provided HTML using a DOM allowlist. */
|
|
151
195
|
export function sanitizeHtml(input) {
|
|
152
196
|
const str = String(input == null ? "" : input);
|
|
153
|
-
|
|
197
|
+
// Fail closed when no parser is available (SSR, constrained runtimes):
|
|
198
|
+
// never treat "no parser" as "trusted markup". Return the input as inert
|
|
199
|
+
// text so no tag is interpreted by an innerHTML assignment.
|
|
200
|
+
if (typeof DOMParser === "undefined") {
|
|
201
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
202
|
+
}
|
|
154
203
|
const doc = new DOMParser().parseFromString(str, "text/html");
|
|
155
204
|
const drop = new Set(["script", "iframe", "object", "embed", "style", "link", "meta", "base", "form", "input", "button"]);
|
|
156
205
|
const walk = (node) => {
|
|
@@ -182,18 +231,20 @@
|
|
|
182
231
|
// Excluded because the render bodies below set them on the host:
|
|
183
232
|
// role, open, aria-label, aria-valuenow, aria-valuemin, aria-valuemax, tabindex
|
|
184
233
|
// Adding one of those back to this list makes that component recurse.
|
|
234
|
+
/** Shared attribute vocabulary used by components that opt into defaults. */
|
|
185
235
|
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", "
|
|
188
|
-
"empty", "
|
|
189
|
-
"label", "lazy", "lede", "legend", "line", "link", "links", "live", "loading", "locale", "loop", "max", "media", "message", "method", "
|
|
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", "
|
|
192
|
-
"state", "steps", "subtitle", "summary", "src", "table", "tabs", "tag", "text", "ticks", "title", "type", "unit",
|
|
236
|
+
"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",
|
|
237
|
+
"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",
|
|
238
|
+
"empty", "exclusive", "fallback", "filename", "format", "heading", "help", "hint", "href", "icon", "illustration", "instrument", "interval", "items", "key", "layers", "level", "range-end", "range-start",
|
|
239
|
+
"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",
|
|
240
|
+
"options", "orientation", "page-size", "pages", "pause", "paused", "pausable", "persist", "placeholder", "playing", "point", "points", "prev", "presets", "progress", "prompt", "question", "recent", "required",
|
|
241
|
+
"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",
|
|
242
|
+
"state", "steps", "style", "subtitle", "summary", "src", "table", "tabs", "tag", "text", "ticks", "title", "type", "unit", "cluster-items", "row-height",
|
|
193
243
|
"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",
|
|
244
|
+
"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
245
|
];
|
|
196
246
|
|
|
247
|
+
/** Resolve an authored heading level while keeping the fallback valid. */
|
|
197
248
|
export function headingTag(host, fallback = "h3") {
|
|
198
249
|
const v = host && host.getAttribute ? host.getAttribute("heading") : null;
|
|
199
250
|
return /^h[1-6]$/.test(v || "") ? v : fallback;
|
|
@@ -223,7 +274,12 @@
|
|
|
223
274
|
// consumer put on authored children survive a re-render. The cost is honest:
|
|
224
275
|
// nodes a component generated are rebuilt, so state inside them (a typed
|
|
225
276
|
// value, a focus ring) is lost when a host attribute changes.
|
|
226
|
-
|
|
277
|
+
// SSR-safe base (R12-25): in a non-DOM runtime (Node, type-only tooling)
|
|
278
|
+
// HTMLElement is undefined. Fall back to Object so the module can be imported
|
|
279
|
+
// for metadata/type inspection without a DOM shim; components cannot be
|
|
280
|
+
// instantiated there, which is the correct boundary.
|
|
281
|
+
const _ContourBaseParent = (typeof HTMLElement !== "undefined") ? HTMLElement : Object;
|
|
282
|
+
export class ContourBase extends _ContourBaseParent {
|
|
227
283
|
static formAssociated = false;
|
|
228
284
|
constructor() {
|
|
229
285
|
super();
|
|
@@ -248,7 +304,28 @@
|
|
|
248
304
|
return {};
|
|
249
305
|
}
|
|
250
306
|
|
|
251
|
-
//
|
|
307
|
+
// Update policy (R12-06): "scaffold" components may rebuild their generated
|
|
308
|
+
// DOM on attribute change (the default lifecycle). High-volume components
|
|
309
|
+
// (table, grid, tree, virtual-list, chart) should override to "keyed" and
|
|
310
|
+
// use ensure()/keyed patching, or expose an imperative update method.
|
|
311
|
+
// Documented here so consumers know which components guarantee identity
|
|
312
|
+
// stability across renders.
|
|
313
|
+
static get updateMode() {
|
|
314
|
+
return "scaffold";
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Brownout helpers (G-16): components read their degraded level from the
|
|
318
|
+
// `brownout` / `brownout-level` attribute and shed non-essential chrome
|
|
319
|
+
// above a threshold. Centralised here so a new component does not
|
|
320
|
+
// re-implement the attribute lookup.
|
|
321
|
+
brownoutLevel() {
|
|
322
|
+
const raw = this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0";
|
|
323
|
+
const n = parseInt(raw, 10);
|
|
324
|
+
return Number.isFinite(n) ? n : 0;
|
|
325
|
+
}
|
|
326
|
+
shed(kind, threshold) {
|
|
327
|
+
return this.brownoutLevel() >= (threshold || 1);
|
|
328
|
+
}
|
|
252
329
|
// Read-only and diagnostic: it exists so a page can show that `batch()` did
|
|
253
330
|
// what it claims instead of asking the reader to believe it, and so a test can
|
|
254
331
|
// assert a re-render happened without watching for a specific node. A consumer
|
|
@@ -275,8 +352,8 @@
|
|
|
275
352
|
Object.defineProperty(ctor.prototype, name, {
|
|
276
353
|
get() {
|
|
277
354
|
const raw = this.getAttribute(attr);
|
|
355
|
+
if (type === Boolean) return raw !== null;
|
|
278
356
|
if (raw === null) return spec && spec.default !== undefined ? spec.default : null;
|
|
279
|
-
if (type === Boolean) return true;
|
|
280
357
|
if (type === Number) { const n = Number(raw); return Number.isNaN(n) ? null : n; }
|
|
281
358
|
return raw;
|
|
282
359
|
},
|
|
@@ -718,6 +795,7 @@
|
|
|
718
795
|
// render. Usage: el.batch(() => { el.value = 42; el.delta = "+3"; });
|
|
719
796
|
// The render fires once when the callback returns, reading all final
|
|
720
797
|
// attribute values. Nested calls are supported.
|
|
798
|
+
/** Coalesce synchronous property changes into one render. */
|
|
721
799
|
batch(fn) {
|
|
722
800
|
if (typeof fn !== "function") return;
|
|
723
801
|
this._batchDepth = (this._batchDepth || 0) + 1;
|
|
@@ -841,7 +919,24 @@
|
|
|
841
919
|
}
|
|
842
920
|
}
|
|
843
921
|
|
|
922
|
+
// Brownout mixin (G-16): opt-in base for components that shed non-essential
|
|
923
|
+
// chrome under degraded conditions. Merges `brownout` / `brownout-level`
|
|
924
|
+
// into the subclass observed list and exposes the helpers already on
|
|
925
|
+
// ContourBase. Usage: `class Foo extends withBrownout(ContourBase) { ... }`.
|
|
926
|
+
export function withBrownout(Base) {
|
|
927
|
+
return class extends Base {
|
|
928
|
+
static get observed() {
|
|
929
|
+
const base = (super.observed && Array.isArray(super.observed)) ? super.observed : [];
|
|
930
|
+
const extra = ["brownout", "brownout-level"];
|
|
931
|
+
return Array.from(new Set(base.concat(extra)));
|
|
932
|
+
}
|
|
933
|
+
brownoutLevel() { return super.brownoutLevel ? super.brownoutLevel() : (parseInt(this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0", 10) || 0); }
|
|
934
|
+
shed(kind, threshold) { return this.brownoutLevel() >= (threshold || 1); }
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
|
|
844
938
|
// Simple component: just adds CSS classes.
|
|
939
|
+
/** Create a light-DOM component that only applies block and modifier classes. */
|
|
845
940
|
export const simple = (classes) => class extends ContourBase {
|
|
846
941
|
render() {
|
|
847
942
|
classes.forEach((c) => this.classList.add(c));
|
|
@@ -869,6 +964,7 @@
|
|
|
869
964
|
// here — they declare a class above, and their presence in this list would be
|
|
870
965
|
// a fallback that only runs when the real component is broken, so the
|
|
871
966
|
// registration loop skips a name an explicit component already claimed.
|
|
967
|
+
/** Blocks whose custom elements need no generated markup. */
|
|
872
968
|
export const CLASS_ONLY = [
|
|
873
969
|
"box", "cluster", "container", "row", "scrim", "stack"
|
|
874
970
|
];
|
|
@@ -876,6 +972,7 @@
|
|
|
876
972
|
// Feature detection for `hidden="until-found"` (BY-51). Browsers that do not
|
|
877
973
|
// support it treat the value as the boolean hidden attribute, which would
|
|
878
974
|
// hide the content permanently — so we only upgrade where supported.
|
|
975
|
+
/** Detect support for the non-destructive `hidden="until-found"` value. */
|
|
879
976
|
export function supportsUntilFound() {
|
|
880
977
|
try {
|
|
881
978
|
const t = document.createElement("div");
|
|
@@ -884,11 +981,13 @@
|
|
|
884
981
|
} catch (e) { return false; }
|
|
885
982
|
}
|
|
886
983
|
|
|
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
|
|
890
|
-
// defaults to the runtime locale.
|
|
891
|
-
|
|
984
|
+
// Value formatting (BY-31/BY-22): opt-in Intl formatting for kpi/stat/readout/coordinate.
|
|
985
|
+
// `format` is a preset ("number","currency","percent","compact","date","time",
|
|
986
|
+
// "unit","relative") or a JSON string of Intl.NumberFormat/DateTimeFormat/
|
|
987
|
+
// RelativeTimeFormat options. `locale` defaults to the runtime locale.
|
|
988
|
+
// Returns the raw value when formatting fails.
|
|
989
|
+
/** Format a value with the component's supported Intl presets. */
|
|
990
|
+
export function formatValue(value, format, locale, unit) {
|
|
892
991
|
if (!format) return value;
|
|
893
992
|
const loc = locale || (typeof navigator !== "undefined" && navigator.language) || "en";
|
|
894
993
|
if (format === "date" || format === "time") {
|
|
@@ -897,10 +996,27 @@
|
|
|
897
996
|
return new Intl.DateTimeFormat(loc, opts).format(new Date(value));
|
|
898
997
|
} catch (e) { return value; }
|
|
899
998
|
}
|
|
999
|
+
if (format === "relative") {
|
|
1000
|
+
try {
|
|
1001
|
+
const num = Number(value);
|
|
1002
|
+
// Interpret the value as seconds from now unless it is an ISO date.
|
|
1003
|
+
let seconds = num;
|
|
1004
|
+
if (Number.isNaN(num)) {
|
|
1005
|
+
const then = new Date(value).getTime();
|
|
1006
|
+
if (Number.isFinite(then)) seconds = (then - Date.now()) / 1000;
|
|
1007
|
+
}
|
|
1008
|
+
const rtf = new Intl.RelativeTimeFormat(loc, { numeric: "auto" });
|
|
1009
|
+
if (Math.abs(seconds) < 60) return rtf.format(Math.round(seconds), "second");
|
|
1010
|
+
if (Math.abs(seconds) < 3600) return rtf.format(Math.round(seconds / 60), "minute");
|
|
1011
|
+
if (Math.abs(seconds) < 86400) return rtf.format(Math.round(seconds / 3600), "hour");
|
|
1012
|
+
return rtf.format(Math.round(seconds / 86400), "day");
|
|
1013
|
+
} catch (e) { return value; }
|
|
1014
|
+
}
|
|
900
1015
|
let opts = {};
|
|
901
1016
|
if (format === "currency") opts = { style: "currency", currency: "USD" };
|
|
902
1017
|
else if (format === "percent") opts = { style: "percent" };
|
|
903
1018
|
else if (format === "compact") opts = { notation: "compact" };
|
|
1019
|
+
else if (format === "unit") opts = { style: "unit", unit: unit || "meter" };
|
|
904
1020
|
else if (format !== "number") {
|
|
905
1021
|
try { opts = JSON.parse(format); } catch (e) { return value; }
|
|
906
1022
|
}
|
|
@@ -908,4 +1024,29 @@
|
|
|
908
1024
|
catch (e) { return value; }
|
|
909
1025
|
}
|
|
910
1026
|
|
|
911
|
-
|
|
1027
|
+
// Spatial maths (BY-23): pure functions on the host's own attributes.
|
|
1028
|
+
// Haversine distance in meters between two lat/lon points.
|
|
1029
|
+
/** Return the great-circle distance between two latitude/longitude points. */
|
|
1030
|
+
export function haversine(lat1, lon1, lat2, lon2) {
|
|
1031
|
+
const R = 6371000;
|
|
1032
|
+
const toRad = (d) => d * Math.PI / 180;
|
|
1033
|
+
const dLat = toRad(lat2 - lat1);
|
|
1034
|
+
const dLon = toRad(lon2 - lon1);
|
|
1035
|
+
const a = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon / 2) ** 2;
|
|
1036
|
+
return 2 * R * Math.asin(Math.sqrt(a));
|
|
1037
|
+
}
|
|
1038
|
+
// Bearing in degrees (clockwise from north) from point 1 to point 2.
|
|
1039
|
+
/** Return the initial bearing from one latitude/longitude point to another. */
|
|
1040
|
+
export function bearing(lat1, lon1, lat2, lon2) {
|
|
1041
|
+
const toRad = (d) => d * Math.PI / 180;
|
|
1042
|
+
const toDeg = (r) => r * 180 / Math.PI;
|
|
1043
|
+
const dLon = toRad(lon2 - lon1);
|
|
1044
|
+
const y = Math.sin(dLon) * Math.cos(toRad(lat2));
|
|
1045
|
+
const x = Math.cos(toRad(lat1)) * Math.sin(toRad(lat2)) - Math.sin(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.cos(dLon);
|
|
1046
|
+
return (toDeg(Math.atan2(y, x)) + 360) % 360;
|
|
1047
|
+
}
|
|
1048
|
+
// Mercator resolution (meters per pixel) at a given latitude and zoom.
|
|
1049
|
+
/** Return meters per pixel for Web Mercator at a latitude and zoom level. */
|
|
1050
|
+
export function mercatorResolution(lat, zoom) {
|
|
1051
|
+
return 156543.03392 * Math.cos(lat * Math.PI / 180) / Math.pow(2, zoom);
|
|
1052
|
+
}
|
package/dist/wc/dashboard.mjs
CHANGED
|
@@ -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
|
-
|
|
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);
|