contour-ds 1.8.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +227 -378
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/build-manifest.json +320 -179
- package/dist/contour-wc-content.esm.js +479 -3665
- package/dist/contour-wc-content.esm.min.js +1 -1
- package/dist/contour-wc-core.esm.js +3724 -0
- package/dist/contour-wc-core.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +2713 -4381
- package/dist/contour-wc-dashboard.esm.min.js +1 -1
- package/dist/contour-wc-data.esm.js +2658 -4346
- package/dist/contour-wc-data.esm.min.js +1 -1
- package/dist/contour-wc-docs.esm.js +218 -3547
- package/dist/contour-wc-docs.esm.min.js +1 -1
- package/dist/contour-wc-feedback.esm.js +483 -3658
- package/dist/contour-wc-feedback.esm.min.js +1 -1
- package/dist/contour-wc-forms.esm.js +503 -3754
- package/dist/contour-wc-forms.esm.min.js +1 -1
- package/dist/contour-wc-interaction.esm.js +379 -3616
- package/dist/contour-wc-interaction.esm.min.js +1 -1
- package/dist/contour-wc-layout.esm.js +234 -3563
- package/dist/contour-wc-layout.esm.min.js +1 -1
- package/dist/contour-wc-map.esm.js +949 -3743
- package/dist/contour-wc-map.esm.min.js +1 -1
- package/dist/contour-wc-misc.esm.js +237 -3556
- package/dist/contour-wc-misc.esm.min.js +1 -1
- package/dist/contour-wc-navigation.esm.js +2235 -5237
- package/dist/contour-wc-navigation.esm.min.js +1 -1
- package/dist/contour-wc-ui.esm.js +4638 -7128
- package/dist/contour-wc-ui.esm.min.js +1 -1
- package/dist/contour-wc.esm.js +11971 -7727
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +11971 -7727
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +96 -74
- package/dist/contour.components.json +2591 -741
- package/dist/contour.css +2624 -1888
- package/dist/contour.d.ts +421 -228
- package/dist/contour.esm.js +433 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +1231 -199
- package/dist/contour.js +433 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +100 -98
- package/dist/contour.single.html +2 -2
- package/dist/contour.single.min.css +1 -1
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +482 -255
- package/dist/contour.vue.d.ts +100 -98
- package/dist/contour.web-types.json +1226 -226
- package/dist/custom-elements.json +7649 -2237
- package/dist/docs/actions.md +15 -6
- package/dist/docs/affordances.md +18 -96
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -26
- package/dist/docs/data.md +36 -60
- package/dist/docs/docs.md +10 -12
- package/dist/docs/feedback.md +30 -12
- package/dist/docs/field.md +28 -13
- package/dist/docs/forms.md +35 -19
- package/dist/docs/index.json +63 -56
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +18 -13
- package/dist/docs/motion.md +12 -6
- package/dist/docs/navigation.md +31 -7
- package/dist/docs/overlays.md +32 -25
- package/dist/docs/overview.md +3 -2
- package/dist/docs/patterns.md +19 -9
- package/dist/docs/playground.md +9 -22
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +113 -14
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +12 -25
- package/dist/docs/surfaces.md +17 -22
- package/dist/docs/theming.md +18 -32
- package/dist/docs/type.md +12 -5
- package/dist/docs/webcomponents.md +66 -38
- package/dist/hljs.css +1 -20
- package/dist/map-chrome.mapbox.css +68 -92
- package/dist/map-chrome.maplibre.css +68 -92
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/svg/icons.svg +367 -0
- package/dist/wc/behaviours.mjs +190 -148
- package/dist/wc/content.mjs +273 -129
- package/dist/wc/core.mjs +598 -395
- package/dist/wc/dashboard.mjs +64 -44
- package/dist/wc/data-chart.mjs +1333 -0
- package/dist/wc/data-export.mjs +391 -0
- package/dist/wc/data-gauge.mjs +779 -0
- package/dist/wc/data-geo.mjs +696 -0
- package/dist/wc/data-glyphs.mjs +133 -0
- package/dist/wc/data-legend.mjs +431 -0
- package/dist/wc/data-readout.mjs +227 -0
- package/dist/wc/data-series.mjs +1004 -0
- package/dist/wc/data-table.mjs +751 -0
- package/dist/wc/data.mjs +15 -4322
- package/dist/wc/docs.mjs +12 -11
- package/dist/wc/feedback.mjs +277 -122
- package/dist/wc/forms-controls.mjs +635 -0
- package/dist/wc/forms-field.mjs +547 -0
- package/dist/wc/forms-groups.mjs +347 -0
- package/dist/wc/forms-input.mjs +292 -0
- package/dist/wc/forms.mjs +10 -1751
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +11 -9
- package/dist/wc/interaction.mjs +173 -80
- package/dist/wc/layout.mjs +28 -27
- package/dist/wc/map.mjs +743 -207
- package/dist/wc/misc.mjs +31 -20
- package/dist/wc/navigation-menu.mjs +735 -0
- package/dist/wc/navigation-shell.mjs +495 -0
- package/dist/wc/navigation-tree.mjs +995 -0
- package/dist/wc/navigation.mjs +9 -1905
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +206 -110
- package/dist/wc/states.mjs +54 -75
- package/dist/wc/svg.mjs +118 -47
- package/dist/wc/ui-atoms.mjs +608 -0
- package/dist/wc/ui-data.mjs +1404 -0
- package/dist/wc/ui-feedback.mjs +419 -0
- package/dist/wc/ui-inputs.mjs +1570 -0
- package/dist/wc/ui-menus.mjs +307 -0
- package/dist/wc/ui-overlays.mjs +1605 -0
- package/integrations/README.md +23 -5
- package/integrations/ai/CLAUDE.md +3 -0
- package/integrations/ai/COPILOT.md +14 -0
- package/integrations/ai/GEMINI.md +14 -0
- package/integrations/ai/WINDSURF.md +14 -0
- package/integrations/ai/v0-prompt.md +13 -1
- package/integrations/native/README.md +0 -3
- package/integrations/tailwind/contour-theme.css +66 -7
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +77 -42
- package/dist/wc/ui.mjs +0 -5072
package/dist/wc/core.mjs
CHANGED
|
@@ -1,44 +1,25 @@
|
|
|
1
|
-
/*
|
|
2
|
-
CONTOUR — Web Components (progressive enhancement)
|
|
3
|
-
----------------------------------------------------------------------------
|
|
4
|
-
Two layers over the same blocks. The light-DOM wrappers add the CSS classes
|
|
5
|
-
the block already has and, where a block needs scaffolding, generate it from
|
|
6
|
-
attributes; styles come straight from ds.css. The contour-shadow-* wrappers
|
|
7
|
-
are an opt-in alternative for consumers who want an isolated root with named
|
|
8
|
-
parts to style through ::part(); they hold a template and slots and share the
|
|
9
|
-
document's sheets. Neither layer replaces a native element, and nothing here
|
|
10
|
-
is required for a page to work.
|
|
11
|
-
|
|
12
|
-
What this file registers is published as the frozen array
|
|
13
|
-
`window.ContourElements`, because `customElements` cannot be enumerated and a
|
|
14
|
-
reader should not have to infer the registry by scraping quoted strings out of
|
|
15
|
-
the source. A scrape counts whatever shape the prose happens to be in: it is
|
|
16
|
-
how a gate came to certify a fraction of this file's elements as the whole of
|
|
17
|
-
them, and call the difference a pass. No number is written down here for that
|
|
18
|
-
reason — the array is the count, and the contract gate reads it.
|
|
19
|
-
========================================================================= */
|
|
1
|
+
/* CONTOUR Web Components — two light-DOM layers over ds.css blocks; publishes the frozen `window.ContourElements` registry. */
|
|
20
2
|
"use strict";
|
|
21
3
|
|
|
22
|
-
// Every name this file actually registers, in registration order. define() is
|
|
23
|
-
// the only door to the registry, so the list cannot drift from what the
|
|
24
|
-
// browser was handed.
|
|
25
4
|
/** Names registered by this module, in registration order. */
|
|
26
5
|
export const REGISTERED = [];
|
|
27
6
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
7
|
+
/**
|
|
8
|
+
* R31-38: a real scroller is an element whose computed overflow is
|
|
9
|
+
* auto/scroll AND that actually overflows. The re-render layout pass used to
|
|
10
|
+
* read scrollHeight/clientHeight on EVERY element (4,018 layout reads per
|
|
11
|
+
* 500-row density change); the overflow pre-check is a style query (no
|
|
12
|
+
* layout) and short-circuits, so the layout reads happen only on scrollers.
|
|
13
|
+
*/
|
|
14
|
+
const isScroller = (el) => {
|
|
15
|
+
if (typeof getComputedStyle !== "function") return false;
|
|
16
|
+
const s = getComputedStyle(el);
|
|
17
|
+
if (s.overflowY !== "auto" && s.overflowY !== "scroll" && s.overflowX !== "auto" && s.overflowX !== "scroll") return false;
|
|
18
|
+
return el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Anything a host starts against the document (fetch, timer, observer) registers
|
|
22
|
+
// cleanup here; `disconnectedCallback` runs the list, one disposal per mount.
|
|
42
23
|
const DISPOSERS = new WeakMap();
|
|
43
24
|
/** Register teardown work for the host's current connection. */
|
|
44
25
|
export const onDispose = (host, fn) => {
|
|
@@ -78,28 +59,36 @@
|
|
|
78
59
|
|
|
79
60
|
/** Define a custom element once, while remaining safe in SSR runtimes. */
|
|
80
61
|
export const define = (name, cls) => {
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
// element remains an unknown (upgradable) tag until a browser defines it.
|
|
62
|
+
// No-op when the Custom Elements registry is unavailable (SSR-safe); the tag
|
|
63
|
+
// stays unknown until a browser defines it.
|
|
84
64
|
if (typeof customElements === "undefined" || !customElements || typeof customElements.define !== "function") return;
|
|
85
65
|
if (customElements.get(name)) return;
|
|
66
|
+
// Opt-in lazy hydration (data-hydrate="lazy"): definitions defer until near viewport; REGISTERED names only handed elements.
|
|
67
|
+
if (typeof window !== "undefined" && typeof window.__contourDefineDefer === "function" && window.__contourDefineDefer(name, cls)) return;
|
|
86
68
|
customElements.define(name, cls);
|
|
87
69
|
REGISTERED.push(name);
|
|
70
|
+
// Publish on every registration: raw-fragment imports never load shadow.mjs, so each slice is frozen and current.
|
|
71
|
+
if (typeof window !== "undefined") {
|
|
72
|
+
window.ContourElements = Object.freeze(REGISTERED.slice());
|
|
73
|
+
}
|
|
88
74
|
};
|
|
89
75
|
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
// how the light and shadow halves drifted apart over "color".
|
|
76
|
+
// One list for both layers — a separate modifier list is how light and shadow
|
|
77
|
+
// drifted apart over "color".
|
|
93
78
|
/** Attribute names that map to component modifier classes. */
|
|
94
79
|
export const MODS = ["variant", "size", "color"];
|
|
95
80
|
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
81
|
+
// The count — the gate compares emitted names against this object, so no
|
|
82
|
+
// number is written anywhere else; payload keys are the union across sites.
|
|
83
|
+
/**
|
|
84
|
+
* Sentinel type for JSON-typed reflected properties (R24-90). A property
|
|
85
|
+
* declared `type: JSON_TYPE` serialises objects/arrays with JSON.stringify and
|
|
86
|
+
* parses JSON-looking attribute values back on read, so a framework that
|
|
87
|
+
* assigns `el.items = [{label:"Alpha"}]` writes a JSON string instead of
|
|
88
|
+
* "[object Object]".
|
|
89
|
+
*/
|
|
90
|
+
const JSON_TYPE = Symbol("JSON");
|
|
91
|
+
|
|
103
92
|
/** Frozen event vocabulary with the public detail keys for each event. */
|
|
104
93
|
export const CONTOUR_EVENTS = Object.freeze({
|
|
105
94
|
"contour:activate": { payload: ["files", "label", "row", "value"], composed: true },
|
|
@@ -107,6 +96,9 @@
|
|
|
107
96
|
"contour:activity-clear": { payload: [], composed: true },
|
|
108
97
|
"contour:activity-filter": { payload: ["unread"], composed: true },
|
|
109
98
|
"contour:activity-select": { payload: ["index", "text"], composed: true },
|
|
99
|
+
"contour:rendered": { payload: ["renderCount"], composed: true },
|
|
100
|
+
"contour:cap": { payload: ["series", "total", "shown"], composed: true },
|
|
101
|
+
"contour:action": { payload: ["label"], composed: true },
|
|
110
102
|
"contour:break-change": { payload: ["layer", "value"], composed: true },
|
|
111
103
|
"contour:style-resolved": { payload: ["applied", "classification", "colors", "items", "layer", "n", "palette", "property", "value"], composed: true },
|
|
112
104
|
"contour:advanced-toggle": { payload: ["title"], composed: true },
|
|
@@ -141,31 +133,34 @@
|
|
|
141
133
|
"contour:error": { payload: ["src", "message", "name", "status"], composed: true },
|
|
142
134
|
"contour:export": { payload: ["format"], composed: true },
|
|
143
135
|
"contour:refresh": { payload: [], composed: true },
|
|
144
|
-
"contour:hide": { payload: [], composed: true },
|
|
136
|
+
"contour:hide": { payload: [], composed: true, deprecated: "use contour:close instead" },
|
|
145
137
|
"contour:hover": { payload: ["row"], composed: true },
|
|
146
138
|
"contour:input": { payload: ["name", "value", "checked"], composed: true },
|
|
147
139
|
"contour:invalid": { payload: ["field", "input", "message"], composed: true, cancelable: true },
|
|
148
|
-
"contour:inspect-action": { payload: ["label"], composed: true },
|
|
149
|
-
"contour:layer-opacity": { payload: ["name", "opacity"], composed: true },
|
|
150
|
-
"contour:layer-rename": { payload: ["name", "newName"], composed: true },
|
|
151
|
-
"contour:layer-duplicate": { payload: ["name"], composed: true },
|
|
152
|
-
"contour:layer-zoom": { payload: ["name"], composed: true },
|
|
140
|
+
"contour:inspect-action": { payload: ["label", "value"], composed: true },
|
|
141
|
+
"contour:layer-opacity": { payload: ["layerId", "name", "opacity"], composed: true },
|
|
142
|
+
"contour:layer-rename": { payload: ["layerId", "name", "newName"], composed: true },
|
|
143
|
+
"contour:layer-duplicate": { payload: ["layerId", "name"], composed: true },
|
|
144
|
+
"contour:layer-zoom": { payload: ["layerId", "name"], composed: true },
|
|
153
145
|
"contour:zoom": { payload: ["data", "index", "row"], composed: true },
|
|
154
|
-
"contour:layer-projection": { payload: ["name", "projection"], composed: true },
|
|
155
|
-
"contour:layer-remove": { payload: ["name"], composed: true },
|
|
146
|
+
"contour:layer-projection": { payload: ["layerId", "name", "projection"], composed: true },
|
|
147
|
+
"contour:layer-remove": { payload: ["layerId", "name"], composed: true },
|
|
156
148
|
"contour:layer-reorder": { payload: ["layerIds"], composed: true },
|
|
157
|
-
"contour:layer-toggle": { payload: ["name", "visible"], composed: true },
|
|
158
|
-
"contour:layer-visibility": { payload: ["name", "visible"], composed: true },
|
|
149
|
+
"contour:layer-toggle": { payload: ["layerId", "name", "visible"], composed: true },
|
|
150
|
+
"contour:layer-visibility": { payload: ["layerId", "name", "visible"], composed: true },
|
|
159
151
|
"contour:legend-toggle": { payload: ["index", "key", "label", "pressed"], composed: true },
|
|
160
152
|
"contour:leave": { payload: [], composed: true },
|
|
161
153
|
"contour:load": { payload: ["src", "count"], composed: true },
|
|
162
154
|
"contour:map-control": { payload: ["control"], composed: true },
|
|
155
|
+
"contour:map-style": { payload: ["style", "name"], composed: true },
|
|
163
156
|
"contour:map-attach": { payload: [], composed: true },
|
|
157
|
+
"contour:map-ready": { payload: [], composed: true },
|
|
164
158
|
"contour:map-detach": { payload: [], composed: true },
|
|
165
159
|
"contour:map-popup-reposition": { payload: ["anchor", "flippedX", "flippedY", "left", "top"], composed: true },
|
|
160
|
+
"contour:map-viewport": { payload: ["crossesAntimeridian", "west", "south", "east", "north", "zoom", "center"], composed: true },
|
|
166
161
|
"contour:mode-change": { payload: ["mode"], composed: true },
|
|
167
162
|
"contour:scope-change": { payload: ["scope"], composed: true },
|
|
168
|
-
"contour:move": { payload: ["direction", "from", "to"], composed: true },
|
|
163
|
+
"contour:move": { payload: ["direction", "from", "to", "dx", "dy"], composed: true },
|
|
169
164
|
"contour:open": { payload: [], composed: true },
|
|
170
165
|
"contour:page": { payload: ["page"], composed: true },
|
|
171
166
|
"contour:ready": { payload: ["version", "count"], composed: true },
|
|
@@ -173,13 +168,13 @@
|
|
|
173
168
|
"contour:remove": { payload: ["key", "label", "name", "value"], composed: true },
|
|
174
169
|
"contour:reorder": { payload: ["from", "to"], composed: true },
|
|
175
170
|
"contour:range-change": { payload: ["value"], composed: true },
|
|
176
|
-
"contour:resize": { payload: ["delta", "height", "value", "width"], composed: true },
|
|
171
|
+
"contour:resize": { payload: ["column", "delta", "height", "value", "width"], composed: true },
|
|
177
172
|
"contour:retry": { payload: ["src"], composed: true },
|
|
178
173
|
"contour:loop-change": { payload: ["loop"], composed: true },
|
|
179
174
|
"contour:pause": { payload: [], composed: true },
|
|
180
175
|
"contour:play": { payload: [], composed: true },
|
|
181
176
|
"contour:seek": { payload: ["progress", "value"], composed: true },
|
|
182
|
-
"contour:select": { payload: ["area", "col", "expanded", "href", "index", "key", "label", "labels", "path", "range", "result", "row", "rows", "series", "value"], composed: true },
|
|
177
|
+
"contour:select": { payload: ["area", "col", "expanded", "href", "index", "key", "label", "labels", "level", "path", "range", "result", "row", "rows", "series", "value"], composed: true },
|
|
183
178
|
"contour:search": { payload: ["query"], composed: true },
|
|
184
179
|
"contour:spatial-filter": { payload: ["action", "mode", "operator"], composed: true },
|
|
185
180
|
"contour:split-change": { payload: ["value", "width", "height"], composed: true },
|
|
@@ -187,8 +182,9 @@
|
|
|
187
182
|
"contour:showcase-activate": { payload: ["title"], composed: true },
|
|
188
183
|
"contour:step-activate": { payload: ["index", "title"], composed: true },
|
|
189
184
|
"contour:step-change": { payload: ["direction", "index", "title"], composed: true },
|
|
190
|
-
"contour:show": { payload: [], composed: true },
|
|
185
|
+
"contour:show": { payload: [], composed: true, deprecated: "use contour:open instead" },
|
|
191
186
|
"contour:sort": { payload: ["column", "direction"], composed: true },
|
|
187
|
+
"contour:column-toggle": { payload: ["column", "visible"], composed: true },
|
|
192
188
|
"contour:submit": { payload: ["submitting"], composed: true },
|
|
193
189
|
"contour:stream-state": { payload: ["running"], composed: true },
|
|
194
190
|
"contour:tab-change": { payload: ["index", "label"], composed: true },
|
|
@@ -201,37 +197,75 @@
|
|
|
201
197
|
"contour:view-leave": { payload: [], composed: true },
|
|
202
198
|
});
|
|
203
199
|
|
|
204
|
-
//
|
|
205
|
-
|
|
206
|
-
|
|
200
|
+
// DOMParser allowlist (blocklist regexes let `javascript:` variants through); `style` dropped (UI-redress), colour via safeColor.
|
|
201
|
+
const SANITIZE_DROP = new Set(["script", "iframe", "object", "embed", "style", "link", "meta", "base", "form", "input", "button"]);
|
|
202
|
+
const SANITIZE_ANIMATE = new Set(["animate", "animatemotion", "animatetransform", "set", "discard"]);
|
|
203
|
+
const SANITIZE_URL_ATTRS = new Set(["href", "src", "xlink:href", "from", "to", "values", "by", "attributename"]);
|
|
204
|
+
/**
|
|
205
|
+
* Normalise a candidate URL the way the URL parser does before testing its
|
|
206
|
+
* scheme: strip ASCII tab/newline/CR anywhere, strip leading and trailing C0
|
|
207
|
+
* controls and spaces, then percent-decode. `javascript:…` and
|
|
208
|
+
* `java\tscript:…` both collapse to `javascript:` here.
|
|
209
|
+
*
|
|
210
|
+
* @param {string} value raw attribute value
|
|
211
|
+
* @returns {string} the normalised candidate, lowercased
|
|
212
|
+
*/
|
|
213
|
+
function normalizeUrlCandidate(value) {
|
|
214
|
+
let v = String(value == null ? "" : value);
|
|
215
|
+
v = v.replace(/[\t\n\r]/g, "");
|
|
216
|
+
// Leading C0 controls and spaces are what `trim()` misses and the URL
|
|
217
|
+
// parser drops; trailing ones are harmless but stripped for symmetry.
|
|
218
|
+
v = v.replace(/^[\u0000-\u0020]+/, "").replace(/[\u0000-\u0020]+$/, "");
|
|
219
|
+
try { v = decodeURIComponent(v); } catch (e) { /* malformed escape: test as-is */ }
|
|
220
|
+
return v.toLowerCase();
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Whether a URL attribute value names a scheme the sanitizer refuses.
|
|
224
|
+
*
|
|
225
|
+
* @param {string} value raw attribute value
|
|
226
|
+
* @returns {boolean} true when the value must be removed
|
|
227
|
+
*/
|
|
228
|
+
function isUnsafeUrl(value) {
|
|
229
|
+
const v = normalizeUrlCandidate(value);
|
|
230
|
+
// Strip any remaining embedded controls so `java\tscript:` cannot re-form
|
|
231
|
+
// after decoding, then test the scheme prefix.
|
|
232
|
+
const flat = v.replace(/[\u0000-\u001f\u007f]/g, "");
|
|
233
|
+
return flat.startsWith("javascript:") || flat.startsWith("vbscript:") || flat.startsWith("data:text/html") || flat.startsWith("data:image/svg+xml");
|
|
234
|
+
}
|
|
207
235
|
/** Sanitize consumer-provided HTML using a DOM allowlist. */
|
|
208
236
|
export function sanitizeHtml(input) {
|
|
209
237
|
const str = String(input == null ? "" : input);
|
|
210
|
-
// Fail closed when no parser is available (SSR,
|
|
211
|
-
// never treat "no parser" as "trusted markup". Return the input as inert
|
|
212
|
-
// text so no tag is interpreted by an innerHTML assignment.
|
|
238
|
+
// Fail closed when no parser is available (SSR): return input as inert text, never treat "no parser" as trusted markup.
|
|
213
239
|
if (typeof DOMParser === "undefined") {
|
|
214
240
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
215
241
|
}
|
|
216
242
|
const doc = new DOMParser().parseFromString(str, "text/html");
|
|
217
|
-
const drop = new Set(["script", "iframe", "object", "embed", "style", "link", "meta", "base", "form", "input", "button"]);
|
|
218
243
|
const walk = (node) => {
|
|
244
|
+
// Snapshot: the loop mutates the child list (removals, template walks).
|
|
219
245
|
const children = Array.from(node.childNodes);
|
|
220
246
|
for (const c of children) {
|
|
221
|
-
if (c.nodeType
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
247
|
+
if (c.nodeType !== 1) continue;
|
|
248
|
+
const tag = c.tagName.toLowerCase();
|
|
249
|
+
if (SANITIZE_DROP.has(tag)) { c.remove(); continue; }
|
|
250
|
+
// SMIL animation can rewrite a URL-bearing attribute after the walk,
|
|
251
|
+
// so the element goes before its target attribute is ever read.
|
|
252
|
+
if (SANITIZE_ANIMATE.has(tag)) {
|
|
253
|
+
const attrNames = Array.from(c.attributes).map((a) => a.name.toLowerCase());
|
|
254
|
+
const target = String(c.getAttribute("attributename") || "").toLowerCase();
|
|
255
|
+
const carriesUrl = attrNames.some((n) => SANITIZE_URL_ATTRS.has(n));
|
|
256
|
+
if (carriesUrl || SANITIZE_URL_ATTRS.has(target)) { c.remove(); continue; }
|
|
257
|
+
}
|
|
258
|
+
for (const attr of Array.from(c.attributes)) {
|
|
259
|
+
const name = attr.name.toLowerCase();
|
|
260
|
+
if (name.startsWith("on")) { c.removeAttribute(attr.name); continue; }
|
|
261
|
+
if (name === "style") { c.removeAttribute(attr.name); continue; }
|
|
262
|
+
if (name === "srcdoc") { c.removeAttribute(attr.name); continue; }
|
|
263
|
+
if (SANITIZE_URL_ATTRS.has(name) && isUnsafeUrl(attr.value)) { c.removeAttribute(attr.name); }
|
|
234
264
|
}
|
|
265
|
+
// `<template>` keeps its markup in a separate document fragment, so
|
|
266
|
+
// the walk has to descend into `.content` explicitly.
|
|
267
|
+
if (tag === "template") { walk(c.content || c); continue; }
|
|
268
|
+
walk(c);
|
|
235
269
|
}
|
|
236
270
|
};
|
|
237
271
|
walk(doc.body);
|
|
@@ -255,6 +289,16 @@
|
|
|
255
289
|
if (/url\s*\(/i.test(raw) || /expression\s*\(/i.test(raw)) return "";
|
|
256
290
|
if (/^#[0-9a-f]{3,8}$/i.test(raw)) return raw;
|
|
257
291
|
if (/^(rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color)\(/i.test(raw)) return raw;
|
|
292
|
+
// Token-driven colours are the system's own vocabulary: `var(--color-…)`, `light-dark(…)` and `color-mix(…)` are all le...
|
|
293
|
+
if (/^(var|light-dark|color-mix)\(/i.test(raw)) {
|
|
294
|
+
let depth = 0;
|
|
295
|
+
for (let i = 0; i < raw.length; i++) {
|
|
296
|
+
const ch = raw[i];
|
|
297
|
+
if (ch === "(") depth++;
|
|
298
|
+
else if (ch === ")") { depth--; if (depth < 0) return ""; }
|
|
299
|
+
}
|
|
300
|
+
return depth === 0 ? raw : "";
|
|
301
|
+
}
|
|
258
302
|
if (/^[a-z]+$/i.test(raw)) return raw;
|
|
259
303
|
return "";
|
|
260
304
|
}
|
|
@@ -315,39 +359,23 @@
|
|
|
315
359
|
const msg = (error && error.message) || String(error);
|
|
316
360
|
console.warn(`[contour] ${name}: malformed ${label || "attribute"} — ${msg}`);
|
|
317
361
|
}
|
|
318
|
-
// contract: an attribute that is not here cannot ask an element to re-render,
|
|
319
|
-
// and an attribute a component WRITES to itself must never be here, because
|
|
320
|
-
// that write would fire the callback that performs the render.
|
|
321
|
-
//
|
|
322
|
-
// Excluded because the render bodies below set them on the host:
|
|
323
|
-
// role, open, aria-label, aria-valuenow, aria-valuemin, aria-valuemax, tabindex
|
|
324
|
-
// speed — the time-slider writes its committed speed back (R20 T-30);
|
|
325
|
-
// both readers (time-slider, animation-controls) observe it per-class.
|
|
326
|
-
// x, y — the annotation writes its dragged position back (R20 T-11);
|
|
327
|
-
// its only reader observes them per-class.
|
|
328
|
-
// progress — animation-controls writes its playhead back (R20 T-10);
|
|
329
|
-
// both readers (animation-controls, file-upload) observe it per-class.
|
|
330
|
-
// colors — palette-editor writes the edited palette back (R20 T-15);
|
|
331
|
-
// all readers (palette-editor, style-panel, bivariate, bivariate-legend)
|
|
332
|
-
// observe it per-class.
|
|
333
|
-
// Adding one of those back to this list makes that component recurse.
|
|
362
|
+
// contract: an attribute that is not here cannot ask an element to re-render, and an attribute a component WRITES to it...
|
|
334
363
|
/** Shared attribute vocabulary used by components that opt into defaults. */
|
|
335
364
|
export const OBSERVED = [
|
|
336
365
|
"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", "bounds", "breakpoint", "breaks", "brush", "brush-end", "brush-max", "brush-min", "brush-start", "cache-key", "canvas", "center", "clearable", "cols", "columns", "color", "command",
|
|
337
366
|
"cells", "checked", "chrome", "confidence", "coverage", "debounce", "closable", "collapsed", "collapsible", "classification", "continuous", "content", "controls", "copyable", "count", "data", "data-table", "date", "delta", "description", "glyphs", "graduated", "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",
|
|
338
|
-
"empty", "exclusive", "fallback", "filename", "format", "heading", "help", "hint", "href", "icon", "illustration", "instrument", "interval", "items", "key", "layers", "level", "markers",
|
|
339
|
-
"label", "labels", "lazy", "lede", "legend", "left-label", "right-label", "line", "limit", "link", "links", "live", "loading", "locale", "loop", "max", "media", "message", "method", "methodology", "menu", "min", "multiple", "name", "needle", "next", "no", "no-cache", "no-data-message", "nodes", "note", "norm",
|
|
367
|
+
"empty", "exclusive", "fallback", "filename", "format", "heading", "help", "hint", "href", "icon", "illustration", "instrument", "interval", "items", "key", "layers", "level", "markers",
|
|
368
|
+
"label", "labels", "latitude", "lazy", "lede", "legend", "left-label", "right-label", "line", "limit", "link", "links", "live", "loading", "locale", "loop", "max", "media", "message", "method", "methodology", "menu", "min", "multiple", "name", "needle", "next", "no", "no-cache", "no-data-message", "nodes", "note", "norm",
|
|
340
369
|
"options", "orientation", "page-size", "pages", "pause", "paused", "pausable", "persist", "placeholder", "playing", "point", "points", "prev", "presets", "prompt", "question", "recent", "required",
|
|
341
370
|
"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", "status", "step", "submit", "submitting", "timeout", "trigger", "virtual", "sticky", "cluster-count", "cluster-expanded", "time", "resizable",
|
|
342
|
-
"state", "steps", "style", "subtitle", "summary", "src", "source", "table", "tabs", "tag", "text", "ticks", "title", "type", "unread-only", "unit", "updated", "
|
|
343
|
-
"variant", "values", "viewport", "warning", "yes", "zoomable",
|
|
371
|
+
"state", "steps", "style", "subtitle", "summary", "src", "source", "table", "tabs", "tag", "text", "ticks", "title", "type", "unread-only", "unit", "updated", "row-height",
|
|
372
|
+
"variant", "values", "viewport", "warning", "yes", "zoom", "zoomable",
|
|
344
373
|
"caption", "current-time", "is-playing", "loop-label", "no-data-color", "no-data-label", "property", "show-loop", "show-thumb", "show-thumb-caption", "speeds", "item-height", "pause-label", "play-label", "speed-label", "time-label", "shimmer",
|
|
345
374
|
"search",
|
|
346
375
|
"numbered",
|
|
347
376
|
"bucket-count", "limit-values",
|
|
348
377
|
"autocomplete", "levels", "submit-label",
|
|
349
378
|
"fields", "gap",
|
|
350
|
-
"controls",
|
|
351
379
|
"flush", "head", "preview", "tags", "url",
|
|
352
380
|
"custom-error",
|
|
353
381
|
];
|
|
@@ -358,6 +386,92 @@
|
|
|
358
386
|
return /^h[1-6]$/.test(v || "") ? v : fallback;
|
|
359
387
|
}
|
|
360
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Read a boolean attribute the way an author means it.
|
|
391
|
+
*
|
|
392
|
+
* `hasAttribute()` answers "is it there", not "is it on": a consumer who
|
|
393
|
+
* writes `closable="false"` or `sparkline="0"` from a template still has the
|
|
394
|
+
* attribute, so a presence test renders the close button / the sparkline they
|
|
395
|
+
* explicitly switched off (F-RO19, F-RO20, F-FC11). The HTML boolean
|
|
396
|
+
* convention is presence-only, but these attributes are commonly rendered by
|
|
397
|
+
* frameworks that stringify `false`, so the explicit negative values win.
|
|
398
|
+
*
|
|
399
|
+
* A bare attribute (`closable`) is present with an empty value and is ON —
|
|
400
|
+
* that is the HTML boolean convention, and treating `""` as off broke every
|
|
401
|
+
* plain `closable` in the guide.
|
|
402
|
+
*/
|
|
403
|
+
export function flagOn(host, name) {
|
|
404
|
+
if (!host || !host.getAttribute) return false;
|
|
405
|
+
const raw = host.getAttribute(name);
|
|
406
|
+
if (raw === null) return false;
|
|
407
|
+
const v = raw.trim().toLowerCase();
|
|
408
|
+
return v !== "0" && v !== "false" && v !== "no" && v !== "off" && v !== "null" && v !== "undefined";
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* R24-91: Resolve a boolean value the way an author means it, for the
|
|
413
|
+
* property-setter path. `el.disabled = "false"` must turn the feature OFF
|
|
414
|
+
* (string negatives route through the same vocabulary as flagOn), while
|
|
415
|
+
* `el.disabled = true` turns it ON. The attribute path keeps HTML presence
|
|
416
|
+
* semantics (`disabled="false"` stays ON) — that's a deliberate judgment call
|
|
417
|
+
* (R24-83), not a bug.
|
|
418
|
+
*/
|
|
419
|
+
export function flagOnValue(v) {
|
|
420
|
+
if (v === null || v === undefined || v === false) return false;
|
|
421
|
+
if (typeof v === "string") {
|
|
422
|
+
const s = v.trim().toLowerCase();
|
|
423
|
+
return s !== "0" && s !== "false" && s !== "no" && s !== "off" && s !== "null" && s !== "undefined";
|
|
424
|
+
}
|
|
425
|
+
return Boolean(v);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** R31-148: the default shape for a status variant, so a state never rides
|
|
429
|
+
* on hue alone. `icon="none"` is the explicit opt-out at each call site. */
|
|
430
|
+
export function statusIcon(variant) {
|
|
431
|
+
switch (String(variant || "").toLowerCase()) {
|
|
432
|
+
case "success": return "i-check-circle";
|
|
433
|
+
case "warning": return "i-alert";
|
|
434
|
+
case "danger":
|
|
435
|
+
case "error": return "i-x";
|
|
436
|
+
case "info":
|
|
437
|
+
case "note":
|
|
438
|
+
case "tip":
|
|
439
|
+
case "accent": return "i-info";
|
|
440
|
+
default: return "";
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* R24-93: Emit an overlay visibility event. `contour:open`/`contour:close`
|
|
446
|
+
* are the canonical pair; `contour:show`/`contour:hide` are deprecated
|
|
447
|
+
* aliases emitted alongside for one minor release with a console warning
|
|
448
|
+
* (per the repo's deprecation policy). `contour:toggle` is kept for
|
|
449
|
+
* non-visibility transitions (tree expansion, accordion, sidebar collapse)
|
|
450
|
+
* and is not aliased here.
|
|
451
|
+
*
|
|
452
|
+
* Consumers listening to `show`/`hide` will still receive their event during
|
|
453
|
+
* the deprecation window, but each emission logs a warning directing them to
|
|
454
|
+
* migrate to `open`/`close`. The aliases are removed in v2.0.
|
|
455
|
+
*/
|
|
456
|
+
export function wcEmitOverlay(host, type, detail) {
|
|
457
|
+
if (!host || !host.dispatchEvent) return;
|
|
458
|
+
const isOpen = type === "contour:open";
|
|
459
|
+
const isClose = type === "contour:close";
|
|
460
|
+
if (!isOpen && !isClose) {
|
|
461
|
+
host.dispatchEvent(new CustomEvent(type, { detail, bubbles: true, composed: true }));
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
// Canonical event first.
|
|
465
|
+
host.dispatchEvent(new CustomEvent(type, { detail, bubbles: true, composed: true }));
|
|
466
|
+
// Deprecated alias with a one-minor deprecation warning.
|
|
467
|
+
const alias = isOpen ? "contour:show" : "contour:hide";
|
|
468
|
+
console.warn(
|
|
469
|
+
`[Contour] ${alias} is deprecated, use ${type} instead. ` +
|
|
470
|
+
`Will be removed in v2.0. (host: ${host.tagName || host.constructor.name})`
|
|
471
|
+
);
|
|
472
|
+
host.dispatchEvent(new CustomEvent(alias, { detail, bubbles: true, composed: true }));
|
|
473
|
+
}
|
|
474
|
+
|
|
361
475
|
/**
|
|
362
476
|
* Resolve a localised label for a host (R18-63). A consumer supplies a
|
|
363
477
|
* `labels` JSON attribute (e.g. `labels='{"clear":"Effacer"}'`); it is merged
|
|
@@ -376,6 +490,50 @@
|
|
|
376
490
|
return def;
|
|
377
491
|
}
|
|
378
492
|
|
|
493
|
+
/**
|
|
494
|
+
* R31-147: the one way to write a sprite icon. Every icon-only control used
|
|
495
|
+
* to inline the same `<svg><use href="#i-…">` string; a helper keeps the
|
|
496
|
+
* shape (and the aria-hidden) in one place, so a new glyph cannot forget it.
|
|
497
|
+
*
|
|
498
|
+
* @param {string} id symbol id, e.g. "i-check"
|
|
499
|
+
* @returns {string} svg markup
|
|
500
|
+
*/
|
|
501
|
+
export function iconMarkup(id) {
|
|
502
|
+
return '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + id + '" /></svg>';
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* R31-160: write markup through a Trusted Types policy, when the page has one.
|
|
507
|
+
*
|
|
508
|
+
* The system has ~86 `innerHTML` sinks. Under
|
|
509
|
+
* `Content-Security-Policy: require-trusted-types-for 'script'` a raw
|
|
510
|
+
* `el.innerHTML = "..."` throws even for a constant string, because the sink
|
|
511
|
+
* demands a TrustedHTML. This helper is the one place that crosses that
|
|
512
|
+
* boundary: it routes the string through a named policy (`contour-html`) whose
|
|
513
|
+
* `createHTML` is the identity for the strings this system already controls
|
|
514
|
+
* (constants, `sanitizeHtml()` output, `iconMarkup()`), so a page that sets
|
|
515
|
+
* the policy is satisfied and a page that does not is unaffected.
|
|
516
|
+
*
|
|
517
|
+
* The policy is created lazily and only when `window.trustedTypes` exists, so
|
|
518
|
+
* a browser without Trusted Types (or a page without the CSP) takes the plain
|
|
519
|
+
* path. It never installs a global default policy — a consumer that wants to
|
|
520
|
+
* audit every sink names its own policy and this helper uses it if present.
|
|
521
|
+
*/
|
|
522
|
+
let _contourHtmlPolicy = null;
|
|
523
|
+
export function setHTML(el, html) {
|
|
524
|
+
if (!el) return;
|
|
525
|
+
const empty = html == null || html === "";
|
|
526
|
+
if (!empty && typeof window !== "undefined" && window.trustedTypes && typeof window.trustedTypes.createPolicy === "function") {
|
|
527
|
+
if (!_contourHtmlPolicy) {
|
|
528
|
+
try { _contourHtmlPolicy = window.trustedTypes.createPolicy("contour-html", { createHTML: (s) => s }); }
|
|
529
|
+
catch (e) { _contourHtmlPolicy = null; /* a consumer already named it */ }
|
|
530
|
+
}
|
|
531
|
+
el.innerHTML = _contourHtmlPolicy ? _contourHtmlPolicy.createHTML(html) : html;
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
el.innerHTML = empty ? "" : html;
|
|
535
|
+
}
|
|
536
|
+
|
|
379
537
|
/**
|
|
380
538
|
* Write localised copy onto a node without stealing an author's words (R18-63).
|
|
381
539
|
*
|
|
@@ -409,26 +567,10 @@
|
|
|
409
567
|
*
|
|
410
568
|
* All components use light DOM so that `ds.css` styles apply directly.
|
|
411
569
|
*/
|
|
412
|
-
// Base class: the lifecycle belongs here, the markup belongs to the subclass.
|
|
413
|
-
//
|
|
414
|
-
// A render body is written to run more than once, and it is idempotent because
|
|
415
|
-
// of this snapshot rather than because of its own guards. The first
|
|
416
|
-
// connectedCallback records the nodes and the class attribute the AUTHOR
|
|
417
|
-
// wrote; every later render drops everything, re-appends exactly those nodes,
|
|
418
|
-
// and runs again. So a body may keep the natural
|
|
419
|
-
// `if (!this.querySelector(".c-card__title"))` shape: after the reset the
|
|
420
|
-
// generated node is gone, the guard passes, and the changed attribute reaches
|
|
421
|
-
// the page. Without the reset the guard is permanent and reactivity is a lie.
|
|
422
|
-
//
|
|
423
|
-
// The snapshot holds node references, not a re-parsed string, so listeners a
|
|
424
|
-
// consumer put on authored children survive a re-render. The cost is honest:
|
|
425
|
-
// nodes a component generated are rebuilt, so state inside them (a typed
|
|
426
|
-
// value, a focus ring) is lost when a host attribute changes.
|
|
427
|
-
// SSR-safe base (R12-25): in a non-DOM runtime (Node, type-only tooling)
|
|
428
|
-
// HTMLElement is undefined. Fall back to Object so the module can be imported
|
|
429
|
-
// for metadata/type inspection without a DOM shim; components cannot be
|
|
430
|
-
// instantiated there, which is the correct boundary.
|
|
570
|
+
// Base class: the lifecycle belongs here, the markup belongs to the subclass. A render body is written to run more than...
|
|
431
571
|
const _ContourBaseParent = (typeof HTMLElement !== "undefined") ? HTMLElement : Object;
|
|
572
|
+
// R31-39: constructors whose property accessors are already installed.
|
|
573
|
+
const INSTALLED_PROPS = new WeakSet();
|
|
432
574
|
export class ContourBase extends _ContourBaseParent {
|
|
433
575
|
static formAssociated = false;
|
|
434
576
|
constructor() {
|
|
@@ -437,9 +579,7 @@
|
|
|
437
579
|
this._internals = this.attachInternals();
|
|
438
580
|
}
|
|
439
581
|
}
|
|
440
|
-
// Per-component observed attributes. Subclasses override `static get observed()`
|
|
441
|
-
// with only the attributes they read; the default is the full shared list so
|
|
442
|
-
// a component that does not opt in keeps working.
|
|
582
|
+
// Per-component observed attributes. Subclasses override `static get observed()` with only the attributes they read; th...
|
|
443
583
|
static get observed() {
|
|
444
584
|
return OBSERVED;
|
|
445
585
|
}
|
|
@@ -458,27 +598,17 @@
|
|
|
458
598
|
return list.includes("labels") ? list : [...list, "labels"];
|
|
459
599
|
}
|
|
460
600
|
|
|
461
|
-
// Subclasses override to declare reflected properties:
|
|
462
|
-
// static get properties() { return { value: { attribute: "value", type: String } }; }
|
|
463
|
-
// A property with no entry is not reflected. Types: String (default), Number, Boolean.
|
|
601
|
+
// Subclasses override to declare reflected properties: static get properties() { return { value: { attribute: "value", ...
|
|
464
602
|
static get properties() {
|
|
465
603
|
return {};
|
|
466
604
|
}
|
|
467
605
|
|
|
468
|
-
// Update policy
|
|
469
|
-
// DOM on attribute change (the default lifecycle). High-volume components
|
|
470
|
-
// (table, grid, tree, virtual-list, chart) should override to "keyed" and
|
|
471
|
-
// use ensure()/keyed patching, or expose an imperative update method.
|
|
472
|
-
// Documented here so consumers know which components guarantee identity
|
|
473
|
-
// stability across renders.
|
|
606
|
+
// Update policy : "scaffold" components may rebuild their generated DOM on attribute change (the default lifecycle). Hi...
|
|
474
607
|
static get updateMode() {
|
|
475
608
|
return "scaffold";
|
|
476
609
|
}
|
|
477
610
|
|
|
478
|
-
// Brownout helpers
|
|
479
|
-
// `brownout` / `brownout-level` attribute and shed non-essential chrome
|
|
480
|
-
// above a threshold. Centralised here so a new component does not
|
|
481
|
-
// re-implement the attribute lookup.
|
|
611
|
+
// Brownout helpers : components read their degraded level from the `brownout` / `brownout-level` attribute and shed non...
|
|
482
612
|
brownoutLevel() {
|
|
483
613
|
const raw = this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0";
|
|
484
614
|
const n = parseInt(raw, 10);
|
|
@@ -487,27 +617,72 @@
|
|
|
487
617
|
shed(kind, threshold) {
|
|
488
618
|
return this.brownoutLevel() >= (threshold || 1);
|
|
489
619
|
}
|
|
490
|
-
// Read-only and diagnostic: it exists so a page can show that `batch()` did
|
|
491
|
-
// what it claims instead of asking the reader to believe it, and so a test can
|
|
492
|
-
// assert a re-render happened without watching for a specific node. A consumer
|
|
493
|
-
// that never calls `batch()` never needs it, and nothing here reads it.
|
|
620
|
+
// Read-only and diagnostic: it exists so a page can show that `batch()` did what it claims instead of asking the reader...
|
|
494
621
|
get renderCount() {
|
|
495
622
|
return this._contourRenderCount || 0;
|
|
496
623
|
}
|
|
497
624
|
|
|
625
|
+
/**
|
|
626
|
+
* Resolves one microtask after the last render has settled (render →
|
|
627
|
+
* enhance → restore for a re-render, render → enhance for a first paint).
|
|
628
|
+
* Read it when a caller needs the measured result of an attribute change —
|
|
629
|
+
* a box that has been laid out, a control that exists — instead of waiting
|
|
630
|
+
* on a timer. Also announced as `contour:rendered`; a caller may listen for
|
|
631
|
+
* the event when it holds the element before it is connected.
|
|
632
|
+
*/
|
|
633
|
+
get updateComplete() {
|
|
634
|
+
return this._renderTicket || Promise.resolve(this);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// R31-93: a re-render is synchronous, but its *effects* are not observable
|
|
638
|
+
// from outside, so consumers reached for `setTimeout(50)`. One microtask
|
|
639
|
+
// after the render settles, the promise resolves and the event fires with
|
|
640
|
+
// the render count that produced it.
|
|
641
|
+
_announceRendered() {
|
|
642
|
+
// The count is read now: two renders in one task each announce, and the
|
|
643
|
+
// later one would otherwise relabel the earlier event with its own count.
|
|
644
|
+
const renderCount = this.renderCount;
|
|
645
|
+
this._renderTicket = new Promise((resolve) => {
|
|
646
|
+
queueMicrotask(() => {
|
|
647
|
+
this._renderTicket = null;
|
|
648
|
+
resolve(this);
|
|
649
|
+
if (!this.isConnected) return;
|
|
650
|
+
this.dispatchEvent(new CustomEvent("contour:rendered", {
|
|
651
|
+
bubbles: true,
|
|
652
|
+
composed: true,
|
|
653
|
+
detail: { renderCount },
|
|
654
|
+
}));
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
|
|
498
659
|
_countRender() {
|
|
499
660
|
this._contourRenderCount = (this._contourRenderCount || 0) + 1;
|
|
500
661
|
}
|
|
501
662
|
|
|
502
663
|
// Install accessors once per class, so `el.value = 42` writes the attribute
|
|
503
664
|
// and triggers the normal re-render path instead of being a silent no-op.
|
|
504
|
-
|
|
665
|
+
// R31-39: track installed constructors in a module-level WeakSet, not a
|
|
666
|
+
// static flag read through the prototype chain. A subclass that installs
|
|
667
|
+
// after its parent saw the inherited `true` and skipped its own property
|
|
668
|
+
// declarations, so a child-only property was missing on pages that
|
|
669
|
+
// instantiated the parent first.
|
|
505
670
|
_installProperties() {
|
|
506
671
|
const ctor = this.constructor;
|
|
507
|
-
if (ctor
|
|
508
|
-
ctor
|
|
672
|
+
if (INSTALLED_PROPS.has(ctor)) return;
|
|
673
|
+
INSTALLED_PROPS.add(ctor);
|
|
509
674
|
const props = ctor.properties || {};
|
|
510
675
|
const declared = new Set();
|
|
676
|
+
// R24-90: JSON-typed property support. When a framework sets `el.items = [{label:"Alpha"}]`, the setter must write a JS...
|
|
677
|
+
const serialize = (v) => (typeof v === "object" && v !== null) ? JSON.stringify(v) : String(v);
|
|
678
|
+
const deserialize = (raw) => {
|
|
679
|
+
if (raw === null) return null;
|
|
680
|
+
const t = raw.trim();
|
|
681
|
+
if (t.startsWith("[") || t.startsWith("{")) {
|
|
682
|
+
try { return JSON.parse(t); } catch { /* not JSON, return raw */ }
|
|
683
|
+
}
|
|
684
|
+
return raw;
|
|
685
|
+
};
|
|
511
686
|
for (const [name, spec] of Object.entries(props)) {
|
|
512
687
|
const attr = (spec && spec.attribute) || name;
|
|
513
688
|
declared.add(attr);
|
|
@@ -515,28 +690,30 @@
|
|
|
515
690
|
Object.defineProperty(ctor.prototype, name, {
|
|
516
691
|
get() {
|
|
517
692
|
const raw = this.getAttribute(attr);
|
|
518
|
-
|
|
693
|
+
// R31-37: a boolean property must agree with what render() draws.
|
|
694
|
+
// The render path reads flags through flagOn()/flagOnValue(), which
|
|
695
|
+
// treat "false"/"0"/"off" as OFF; returning `raw !== null` here made
|
|
696
|
+
// `el.closable` true for `closable="false"` while the close button
|
|
697
|
+
// was absent. Presence with a false-y string is off.
|
|
698
|
+
if (type === Boolean) return flagOnValue(raw);
|
|
519
699
|
if (raw === null) return spec && spec.default !== undefined ? spec.default : null;
|
|
520
700
|
if (type === Number) { const n = Number(raw); return Number.isNaN(n) ? null : n; }
|
|
701
|
+
if (type === JSON_TYPE) return deserialize(raw);
|
|
521
702
|
return raw;
|
|
522
703
|
},
|
|
523
704
|
set(v) {
|
|
524
705
|
if (v === null || v === undefined || v === false) this.removeAttribute(attr);
|
|
525
|
-
else if (type === Boolean) {
|
|
526
|
-
|
|
706
|
+
else if (type === Boolean) {
|
|
707
|
+
// R24-91: route string negatives ("false", "0", "no", "off", …) through the flagOn vocabulary so el.disabled = "false" ...
|
|
708
|
+
if (!flagOnValue(v)) this.removeAttribute(attr);
|
|
709
|
+
else this.setAttribute(attr, "");
|
|
710
|
+
}
|
|
711
|
+
else this.setAttribute(attr, serialize(v));
|
|
527
712
|
},
|
|
528
713
|
configurable: true,
|
|
529
714
|
});
|
|
530
715
|
}
|
|
531
|
-
// Default reflection
|
|
532
|
-
// but does not declare in properties() still gets an accessor, so
|
|
533
|
-
// `el.allowDuplicate = true` writes `allow-duplicate=""` instead of being
|
|
534
|
-
// a silent no-op. The property name is the camelCase form of the
|
|
535
|
-
// attribute (kebab -> camel); a kebab attribute with no valid identifier
|
|
536
|
-
// form is skipped rather than guessed. Declared properties win.
|
|
537
|
-
//
|
|
538
|
-
// The list is `observedAttributes`, not `observed`, so the reflection
|
|
539
|
-
// surface and the platform's stay the same set — `labels` included.
|
|
716
|
+
// Default reflection : every observed attribute a component reads but does not declare in properties() still gets an ac...
|
|
540
717
|
const observed = ctor.observedAttributes;
|
|
541
718
|
for (const attr of observed) {
|
|
542
719
|
if (declared.has(attr)) continue;
|
|
@@ -547,13 +724,19 @@
|
|
|
547
724
|
Object.defineProperty(ctor.prototype, prop, {
|
|
548
725
|
get() {
|
|
549
726
|
const raw = this.getAttribute(attr);
|
|
550
|
-
|
|
551
|
-
|
|
727
|
+
// R31-37: same as the declared-property getter — a reflected boolean
|
|
728
|
+
// agrees with the rendered state, not with raw presence.
|
|
729
|
+
if (isBool) return flagOnValue(raw);
|
|
730
|
+
return deserialize(raw);
|
|
552
731
|
},
|
|
553
732
|
set(v) {
|
|
554
733
|
if (v === null || v === undefined || v === false) this.removeAttribute(attr);
|
|
555
|
-
else if (isBool) {
|
|
556
|
-
|
|
734
|
+
else if (isBool) {
|
|
735
|
+
// R24-91: route string negatives through the flagOn vocabulary.
|
|
736
|
+
if (!flagOnValue(v)) this.removeAttribute(attr);
|
|
737
|
+
else this.setAttribute(attr, "");
|
|
738
|
+
}
|
|
739
|
+
else this.setAttribute(attr, serialize(v));
|
|
557
740
|
},
|
|
558
741
|
configurable: true,
|
|
559
742
|
});
|
|
@@ -561,26 +744,56 @@
|
|
|
561
744
|
}
|
|
562
745
|
|
|
563
746
|
connectedCallback() {
|
|
564
|
-
if (this._contourAuthored) {
|
|
747
|
+
if (this._contourAuthored) {
|
|
748
|
+
// R24-01 / R28-09: reconnected, not re-specified. Reset _wired* flags and re-run enhance() so disposables (document/win...
|
|
749
|
+
this._wireFormData();
|
|
750
|
+
for (const key of Object.keys(this)) {
|
|
751
|
+
// CI-11: _wiredFormData and _wiredValueTracking are NOT reset here.
|
|
752
|
+
// Their listeners live on the host and survive a disconnect (they are
|
|
753
|
+
// added outside _runEnhance, so _contourHostListeners does not track
|
|
754
|
+
// them and disconnectedCallback does not remove them). Resetting the
|
|
755
|
+
// flag would re-add a duplicate pair on every reconnect. _wireFormData
|
|
756
|
+
// re-wires against a new form owner via its own disposer; value
|
|
757
|
+
// tracking is host-bound and needs no re-wire.
|
|
758
|
+
if (key.startsWith("_wired") && key !== "_wiredFormData" && key !== "_wiredValueTracking") {
|
|
759
|
+
this[key] = false;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
// R24-01 residue (INF-5/6): re-render on reconnect, not just re-enhance. disconnectedCallback cleared _remoteStatus/_re...
|
|
763
|
+
this.attributeChangedCallback("__contour_reconnect__", null, "");
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
565
766
|
this._installProperties();
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
767
|
+
this._contourAuthored = {
|
|
768
|
+
nodes: Array.from(this.childNodes),
|
|
769
|
+
};
|
|
770
|
+
// R31-02: the base owns only the classes IT generates, never the whole
|
|
771
|
+
// `class` attribute. A framework's state class, `hidden`, a Tailwind
|
|
772
|
+
// utility or any app-owned modifier added after mount must survive a
|
|
773
|
+
// re-render; the old code restored a frozen snapshot and deleted them.
|
|
774
|
+
this._contourOwnedClasses = new Set();
|
|
775
|
+
// R24-02: mark authored nodes so the refresh can find them inside generated wrappers. A component that moves authored c...
|
|
776
|
+
for (const n of this._contourAuthored.nodes) {
|
|
777
|
+
if (n.nodeType === 1) n.setAttribute("data-contour-authored", "");
|
|
778
|
+
}
|
|
570
779
|
const before = Array.from(this.childNodes);
|
|
571
780
|
this._contourRenderGen = (this._contourRenderGen || 0) + 1;
|
|
572
781
|
this._ensureCache = new Map();
|
|
573
782
|
this._ensureCacheGen = this._contourRenderGen;
|
|
574
783
|
this._countRender();
|
|
784
|
+
const _preRenderClasses = new Set(Array.from(this.classList));
|
|
575
785
|
try { this.render(); }
|
|
576
786
|
catch (e) { console.error("Contour render error:", e); this.textContent = labelText(this, "render-error", "Component failed to render."); }
|
|
577
787
|
this._contourGenerated = Array.from(this.childNodes).filter((n) => !before.includes(n));
|
|
578
|
-
|
|
788
|
+
// R31-02: the classes render() just added are the ones this component
|
|
789
|
+
// owns; remember them so the next render removes only those.
|
|
790
|
+
this._contourOwnedClasses = new Set(Array.from(this.classList).filter((c) => !_preRenderClasses.has(c)));
|
|
579
791
|
this._applyDensity();
|
|
580
|
-
this.
|
|
792
|
+
this._runEnhance();
|
|
581
793
|
this._detachInnerFormControls();
|
|
582
794
|
this._wireFormData();
|
|
583
795
|
this._wireValueTracking();
|
|
796
|
+
this._announceRendered();
|
|
584
797
|
}
|
|
585
798
|
|
|
586
799
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
@@ -588,17 +801,12 @@
|
|
|
588
801
|
// Fires before connectedCallback during an upgrade: nothing to reset to
|
|
589
802
|
// yet, and connectedCallback will render with the final attributes.
|
|
590
803
|
if (!this.isConnected || !this._contourAuthored) return;
|
|
591
|
-
// Opt-in batching: when inside batch(), attribute changes are coalesced
|
|
592
|
-
// into a single render that fires when the batch ends. This lets a
|
|
593
|
-
// dashboard update value + delta + direction without three rebuilds,
|
|
594
|
-
// without changing the default synchronous contract the gate enforces.
|
|
804
|
+
// Opt-in batching: when inside batch(), attribute changes are coalesced into a single render that fires when the batch ...
|
|
595
805
|
if (this._batchDepth > 0) {
|
|
596
806
|
this._batchDirty = true;
|
|
597
807
|
return;
|
|
598
808
|
}
|
|
599
|
-
// Re-entrant change (an attribute set while a render is in flight): do
|
|
600
|
-
// not drop it, defer a single re-render to the next microtask so the
|
|
601
|
-
// in-flight render can finish first. Coalesces several such changes.
|
|
809
|
+
// Re-entrant change (an attribute set while a render is in flight): do not drop it, defer a single re-render to the nex...
|
|
602
810
|
if (this._contourRendering) {
|
|
603
811
|
if (!this._pendingRerender) {
|
|
604
812
|
this._pendingRerender = true;
|
|
@@ -615,9 +823,7 @@
|
|
|
615
823
|
if (name === "checked") this._checkedAttrChanged = true;
|
|
616
824
|
this._contourRendering = true;
|
|
617
825
|
try {
|
|
618
|
-
// Preserve form control values across a re-render: generated inputs are
|
|
619
|
-
// dropped and rebuilt, so without this a host attribute change wipes
|
|
620
|
-
// whatever the user typed.
|
|
826
|
+
// Preserve form control values across a re-render: generated inputs are dropped and rebuilt, so without this a host att...
|
|
621
827
|
const savedControls = Array.from(this.querySelectorAll("input, textarea, select"));
|
|
622
828
|
const savedValues = savedControls.map((el) => ({
|
|
623
829
|
key: el.name || el.id || null,
|
|
@@ -625,56 +831,70 @@
|
|
|
625
831
|
value: el.value,
|
|
626
832
|
checked: el.checked,
|
|
627
833
|
type: el.type,
|
|
628
|
-
// User-dirty tracking (R20 T-02): a control the user edited keeps
|
|
629
|
-
// its value until the host's `value` attribute changes. A
|
|
630
|
-
// multi-select saves its whole selection, not just select.value
|
|
631
|
-
// (which is only the first selected option).
|
|
834
|
+
// User-dirty tracking (R20 T-02): a control the user edited keeps its value until the host's `value` attribute changes....
|
|
632
835
|
dirty: !!el._contourUserDirty,
|
|
633
836
|
attrAtDirty: el._contourAttrAtDirty,
|
|
634
837
|
selected: el.tagName === "SELECT" && el.multiple ? Array.from(el.selectedOptions).map((o) => o.value) : null,
|
|
635
838
|
}));
|
|
636
|
-
// Preserve focus, scroll position and <details> open state across the
|
|
637
|
-
// rebuild, so a host attribute change does not yank focus to <body>
|
|
638
|
-
// or collapse an open disclosure.
|
|
839
|
+
// Preserve focus, scroll position and <details> open state across the rebuild, so a host attribute change does not yank...
|
|
639
840
|
const hadFocus = this.contains(document.activeElement) ? document.activeElement : null;
|
|
640
|
-
// Capture a recovery key for unkeyed active elements: an id is the
|
|
641
|
-
// strongest key, then a `data-contour-preserve-key`, then a `name`,
|
|
642
|
-
// then the relative index among all focusable controls inside the host.
|
|
643
|
-
// Without these, an attribute update that rebuilds an unkeyed input
|
|
644
|
-
// drops focus to <body>.
|
|
841
|
+
// Capture a recovery key for unkeyed active elements: an id is the strongest key, then a `data-contour-preserve-key`, t...
|
|
645
842
|
const _focusableSelector = "button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])";
|
|
646
843
|
const _focusablesBefore = Array.from(this.querySelectorAll(_focusableSelector));
|
|
647
844
|
const hadFocusIndex = hadFocus ? _focusablesBefore.indexOf(hadFocus) : -1;
|
|
648
845
|
const hadFocusKey = hadFocus ? (hadFocus.id || null) : null;
|
|
649
846
|
const hadFocusPreserveKey = hadFocus ? (hadFocus.getAttribute("data-contour-preserve-key") || null) : null;
|
|
650
847
|
const hadFocusName = hadFocus ? (hadFocus.getAttribute("name") || null) : null;
|
|
651
|
-
const savedScrolls = Array.from(this.querySelectorAll("*")).filter(
|
|
848
|
+
const savedScrolls = Array.from(this.querySelectorAll("*")).filter(isScroller).map((el) => ({ el, id: el.id || null, preserveKey: el.getAttribute("data-contour-preserve-key") || null, top: el.scrollTop, left: el.scrollLeft }));
|
|
652
849
|
const savedDetails = Array.from(this.querySelectorAll("details")).map((d) => ({ id: d.id || null, preserveKey: d.getAttribute("data-contour-preserve-key") || null, open: d.open }));
|
|
653
|
-
// Unwrap authored content from generated wrappers before dropping them,
|
|
654
|
-
// so an attribute re-render cannot destroy authored light-DOM children
|
|
655
|
-
// that render() moved into a body/pre wrapper (B3-05).
|
|
850
|
+
// Unwrap authored content from generated wrappers before dropping them, so an attribute re-render cannot destroy author...
|
|
656
851
|
for (const g of (this._contourGenerated || [])) {
|
|
657
852
|
if (!g || g.parentNode !== this) continue;
|
|
658
853
|
let wrapper = null;
|
|
659
|
-
|
|
854
|
+
if (g.classList && (g.classList.contains("c-panel__body") || g.classList.contains("c-dialog__body") || g.classList.contains("c-popover__body") || g.classList.contains("c-map-popup__body") || g.classList.contains("c-hover-card__body") || g.classList.contains("c-drawer__body") || g.classList.contains("c-sheet__body") || g.classList.contains("c-alert__body"))) wrapper = g;
|
|
660
855
|
else if (g.tagName === "PRE") wrapper = g.querySelector("code") || g;
|
|
661
856
|
if (wrapper) {
|
|
662
857
|
while (wrapper.firstChild) this.insertBefore(wrapper.firstChild, g);
|
|
663
858
|
}
|
|
664
859
|
}
|
|
665
|
-
// Drop generated nodes from the previous render.
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
860
|
+
// Drop generated nodes from the previous render. Drop generated nodes from the previous render — except the ones the co...
|
|
861
|
+
const persistent = this._contourPersistent;
|
|
862
|
+
const isPersistent = (n) => !!(persistent && persistent.size && persistent.has(n));
|
|
863
|
+
// R24-02: before dropping a generated wrapper, extract any authored children it holds back to the host. A component tha...
|
|
864
|
+
const authoredSet = new Set(this._contourAuthored.nodes || []);
|
|
865
|
+
for (const g of (this._contourGenerated || [])) {
|
|
866
|
+
if (isPersistent(g)) continue;
|
|
867
|
+
// Extract authored children before dropping the wrapper.
|
|
868
|
+
for (const child of Array.from(g.childNodes)) {
|
|
869
|
+
if (authoredSet.has(child)) {
|
|
870
|
+
g.parentNode.insertBefore(child, g);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
if (g.parentNode === this) this.removeChild(g);
|
|
874
|
+
}
|
|
875
|
+
// Refresh the authored snapshot so content added after connect survives. Persistent nodes are generated, not authored: ...
|
|
670
876
|
const generated = new Set(this._contourGenerated || []);
|
|
671
|
-
const authoredNow = Array.from(this.childNodes).filter((n) => !generated.has(n));
|
|
877
|
+
const authoredNow = Array.from(this.childNodes).filter((n) => !generated.has(n) && !isPersistent(n));
|
|
878
|
+
// Find authored nodes inside generated wrappers.
|
|
879
|
+
for (const g of (this._contourGenerated || [])) {
|
|
880
|
+
if (isPersistent(g)) continue;
|
|
881
|
+
const marked = g.querySelectorAll ? g.querySelectorAll("[data-contour-authored]") : [];
|
|
882
|
+
for (const m of marked) {
|
|
883
|
+
if (!authoredNow.includes(m)) authoredNow.push(m);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
672
886
|
this._contourAuthored.nodes = authoredNow;
|
|
673
|
-
// Clear and restore authored nodes.
|
|
674
|
-
|
|
675
|
-
for (const node of
|
|
676
|
-
|
|
677
|
-
|
|
887
|
+
// Clear and restore authored nodes. Persistent nodes stay connected: they are lifted to the end of the child list and t...
|
|
888
|
+
const kept = Array.from(this.childNodes).filter(isPersistent);
|
|
889
|
+
for (const node of kept) this.appendChild(node); // move to end, no detach
|
|
890
|
+
while (this.firstChild && !isPersistent(this.firstChild)) this.removeChild(this.firstChild);
|
|
891
|
+
for (const node of this._contourAuthored.nodes) this.insertBefore(node, this.firstChild && isPersistent(this.firstChild) ? this.firstChild : null);
|
|
892
|
+
for (const node of kept) this.appendChild(node); // re-assert order after authored inserts
|
|
893
|
+
// R31-02: remove only the classes the previous render generated, then
|
|
894
|
+
// let render() re-add them. Authored and app-added classes are left
|
|
895
|
+
// untouched, so a consumer's own classList edits survive every render.
|
|
896
|
+
for (const c of this._contourOwnedClasses) this.classList.remove(c);
|
|
897
|
+
const _preRenderClasses = new Set(Array.from(this.classList));
|
|
678
898
|
const before = Array.from(this.childNodes);
|
|
679
899
|
this._contourRenderGen = (this._contourRenderGen || 0) + 1;
|
|
680
900
|
this._ensureCache = new Map();
|
|
@@ -683,15 +903,11 @@
|
|
|
683
903
|
try { this.render(); }
|
|
684
904
|
catch (e) { console.error("Contour render error:", e); this.textContent = labelText(this, "render-error", "Component failed to render."); }
|
|
685
905
|
this._contourGenerated = Array.from(this.childNodes).filter((n) => !before.includes(n));
|
|
686
|
-
this
|
|
906
|
+
// R31-02: remember the classes this render added, so the next pass
|
|
907
|
+
// removes only those and never a consumer's own class.
|
|
908
|
+
this._contourOwnedClasses = new Set(Array.from(this.classList).filter((c) => !_preRenderClasses.has(c)));
|
|
687
909
|
this._applyDensity();
|
|
688
|
-
// Restore preserved form control values. A re-render that adds or
|
|
689
|
-
// removes a control must not wipe the rest: keyed controls (those with
|
|
690
|
-
// a `name` or `id`) are matched by key first, so a new field inserted
|
|
691
|
-
// between two existing ones leaves both neighbours' values intact.
|
|
692
|
-
// Unkeyed controls fall back to index matching up to the shorter of
|
|
693
|
-
// the two lists, so a field removed at the end does not shift values
|
|
694
|
-
// onto the wrong input.
|
|
910
|
+
// Restore preserved form control values. A re-render that adds or removes a control must not wipe the rest: keyed contr...
|
|
695
911
|
const newControls = Array.from(this.querySelectorAll("input, textarea, select"));
|
|
696
912
|
const keyed = savedValues.filter((sv) => sv.key || sv.preserveKey);
|
|
697
913
|
const unkeyed = savedValues.filter((sv) => !sv.key && !sv.preserveKey);
|
|
@@ -707,11 +923,7 @@
|
|
|
707
923
|
el.checked = match.checked;
|
|
708
924
|
}
|
|
709
925
|
}
|
|
710
|
-
// Restore unkeyed controls by type-aware index matching: group saved
|
|
711
|
-
// unkeyed controls by type, then match new unkeyed controls by type and
|
|
712
|
-
// index within that type group. This prevents misalignment when elements
|
|
713
|
-
// are inserted or removed between renders (F-R4). A textarea removed
|
|
714
|
-
// from the middle no longer shifts its value onto a following input.
|
|
926
|
+
// Restore unkeyed controls by type-aware index matching: group saved unkeyed controls by type, then match new unkeyed c...
|
|
715
927
|
const savedByType = new Map();
|
|
716
928
|
for (const sv of unkeyed) {
|
|
717
929
|
const group = savedByType.get(sv.type) || [];
|
|
@@ -732,12 +944,7 @@
|
|
|
732
944
|
el.checked = saved.checked;
|
|
733
945
|
}
|
|
734
946
|
}
|
|
735
|
-
// Restore <details> open state. A disclosure carries an `id` when it is
|
|
736
|
-
// stable across renders (a faq item, a doc section); match those by id
|
|
737
|
-
// so inserting a new disclosure above them does not collapse the ones
|
|
738
|
-
// below. Disclosures without an id fall back to index matching up to
|
|
739
|
-
// the shorter list, which is the behaviour the length guard existed
|
|
740
|
-
// to protect and still protects for the tail of either list.
|
|
947
|
+
// Restore <details> open state. A disclosure carries an `id` when it is stable across renders (a faq item, a doc sectio...
|
|
741
948
|
const newDetails = Array.from(this.querySelectorAll("details"));
|
|
742
949
|
const keyedDetails = savedDetails.filter((sd) => sd.id || sd.preserveKey);
|
|
743
950
|
const usedIds = new Set();
|
|
@@ -759,11 +966,8 @@
|
|
|
759
966
|
if (!sd) break;
|
|
760
967
|
d.open = sd.open;
|
|
761
968
|
}
|
|
762
|
-
// Restore scroll positions. A scroller that carries an `id` is matched by
|
|
763
|
-
|
|
764
|
-
// the wrong container; the rest fall back to index matching up to the
|
|
765
|
-
// shorter list, which is what the old length guard protected.
|
|
766
|
-
const newScrolls = Array.from(this.querySelectorAll("*")).filter((el) => el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth);
|
|
969
|
+
// Restore scroll positions. A scroller that carries an `id` is matched by id so inserting another scroller above it doe...
|
|
970
|
+
const newScrolls = Array.from(this.querySelectorAll("*")).filter(isScroller);
|
|
767
971
|
const keyedScrolls = savedScrolls.filter((s) => s.id || s.preserveKey);
|
|
768
972
|
const usedScrolls = new Set();
|
|
769
973
|
for (const el of newScrolls) {
|
|
@@ -786,10 +990,16 @@
|
|
|
786
990
|
el.scrollTop = s.top;
|
|
787
991
|
el.scrollLeft = s.left;
|
|
788
992
|
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
993
|
+
// A persistent node kept its identity but not necessarily its offset: the rebuild clears its subtree, and the browser c...
|
|
994
|
+
for (const s of savedScrolls) {
|
|
995
|
+
if (!s.el || !s.el.isConnected) continue;
|
|
996
|
+
// _contourPersistent only exists once keepNode() has been called; a host with scrollable descendants but no persistent ...
|
|
997
|
+
if (!persistent || !persistent.has(s.el)) continue;
|
|
998
|
+
if (s.el.scrollTop === s.top && s.el.scrollLeft === s.left) continue;
|
|
999
|
+
s.el.scrollTop = s.top;
|
|
1000
|
+
s.el.scrollLeft = s.left;
|
|
1001
|
+
}
|
|
1002
|
+
// Restore focus if it was inside the host. Keyed elements (id) are matched first; unkeyed ones fall back to a `name` at...
|
|
793
1003
|
if (hadFocus) {
|
|
794
1004
|
let target = null;
|
|
795
1005
|
if (hadFocusKey) {
|
|
@@ -817,13 +1027,14 @@
|
|
|
817
1027
|
else try { this.focus(); } catch (e) {}
|
|
818
1028
|
}
|
|
819
1029
|
}
|
|
820
|
-
this.
|
|
1030
|
+
this._runEnhance();
|
|
821
1031
|
this._detachInnerFormControls();
|
|
822
1032
|
this._checkedAttrChanged = false;
|
|
823
1033
|
this._contourResetting = false;
|
|
824
1034
|
} finally {
|
|
825
1035
|
this._contourRendering = false;
|
|
826
1036
|
}
|
|
1037
|
+
this._announceRendered();
|
|
827
1038
|
}
|
|
828
1039
|
|
|
829
1040
|
disconnectedCallback() {
|
|
@@ -834,29 +1045,47 @@
|
|
|
834
1045
|
// Form listeners were removed by runDisposers below; clear the guard so
|
|
835
1046
|
// a reconnected host re-attaches them (connectedCallback re-wires).
|
|
836
1047
|
this._wiredFormData = false;
|
|
1048
|
+
// R24-98: clear remote-load state so a reconnect re-fetches. A host detached mid-fetch has _remoteStatus="loading" and ...
|
|
1049
|
+
this._remoteStatus = null;
|
|
1050
|
+
this._remoteSrc = null;
|
|
837
1051
|
runDisposers(this);
|
|
1052
|
+
// R28-09 : drop the host listeners enhance() added this mount. They live on the host element and would otherwise surviv...
|
|
1053
|
+
const hostListeners = this._contourHostListeners;
|
|
1054
|
+
if (hostListeners) {
|
|
1055
|
+
for (const { type, listener, options } of hostListeners) {
|
|
1056
|
+
try { this.removeEventListener(type, listener, options); } catch (e) { /* already gone */ }
|
|
1057
|
+
}
|
|
1058
|
+
this._contourHostListeners = null;
|
|
1059
|
+
}
|
|
838
1060
|
// Override in subclasses that attach event listeners or timers.
|
|
839
1061
|
}
|
|
840
1062
|
|
|
841
1063
|
adoptedCallback() {
|
|
842
1064
|
// Re-apply parts and the density mirror when the node is moved to a new
|
|
843
1065
|
// document.
|
|
844
|
-
if (this._contourAuthored) { this.
|
|
1066
|
+
if (this._contourAuthored) { this._applyDensity(); }
|
|
845
1067
|
}
|
|
846
1068
|
|
|
847
1069
|
// Default no-op: subclasses with behaviour override this.
|
|
848
1070
|
enhance() {}
|
|
849
1071
|
|
|
850
|
-
//
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
1072
|
+
// R28-09 : a host listener added by enhance() lives on the host element, which a disconnect does not destroy, so it sur...
|
|
1073
|
+
addEventListener(type, listener, options) {
|
|
1074
|
+
// Behaviour listeners (behaviours.mjs wcTrack) carry _contourBehaviour: their claim persists across a light reconnect, ...
|
|
1075
|
+
if (this._contourHostWiring && listener && !listener._contourBehaviour) {
|
|
1076
|
+
let list = this._contourHostListeners;
|
|
1077
|
+
if (!list) { list = []; this._contourHostListeners = list; }
|
|
1078
|
+
list.push({ type, listener, options });
|
|
1079
|
+
}
|
|
1080
|
+
return super.addEventListener(type, listener, options);
|
|
1081
|
+
}
|
|
1082
|
+
_runEnhance() {
|
|
1083
|
+
this._contourHostWiring = true;
|
|
1084
|
+
try { this.enhance(); }
|
|
1085
|
+
finally { this._contourHostWiring = false; }
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// Form lifecycle (form-associated components only). The platform calls these on <form>.reset(), on disable by a fieldse...
|
|
860
1089
|
_syncFormValue() {
|
|
861
1090
|
if (!this._internals) return;
|
|
862
1091
|
// A boolean group (a contour-radio-list) submits the *checked* item's
|
|
@@ -869,29 +1098,33 @@
|
|
|
869
1098
|
this._syncValidity(this.hasAttribute("required") && !value);
|
|
870
1099
|
}
|
|
871
1100
|
|
|
872
|
-
// The single validity writer
|
|
873
|
-
//
|
|
874
|
-
//
|
|
875
|
-
//
|
|
876
|
-
//
|
|
1101
|
+
// The single validity writer . Every form class used to repeat the required-check + setValidity pair; the copies in for...
|
|
1102
|
+
// R31-61: mirror the inner control's NATIVE validity onto the host, not only
|
|
1103
|
+
// `required`. A `contour-input type="email" value="not-an-email"` must make
|
|
1104
|
+
// the host and its form invalid (typeMismatch), and number/pattern/min/max
|
|
1105
|
+
// must do the same. `valueMissing` is the authored-required fallback for
|
|
1106
|
+
// groups that have no single inner control to read.
|
|
877
1107
|
_syncValidity(valueMissing) {
|
|
878
1108
|
if (!this._internals) return;
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
this.
|
|
1109
|
+
const flags = valueMissing ? { valueMissing: true } : {};
|
|
1110
|
+
let msg = valueMissing ? "This field is required." : "";
|
|
1111
|
+
const ctl = this.querySelector("input, textarea, select");
|
|
1112
|
+
const v = ctl && ctl.validity;
|
|
1113
|
+
if (v) {
|
|
1114
|
+
if (v.valueMissing) { flags.valueMissing = true; msg = msg || "This field is required."; }
|
|
1115
|
+
if (v.typeMismatch) { flags.typeMismatch = true; msg = msg || "Please enter a valid value."; }
|
|
1116
|
+
if (v.patternMismatch) { flags.patternMismatch = true; msg = msg || "Please match the requested format."; }
|
|
1117
|
+
if (v.rangeUnderflow) { flags.rangeUnderflow = true; msg = msg || "Value is too low."; }
|
|
1118
|
+
if (v.rangeOverflow) { flags.rangeOverflow = true; msg = msg || "Value is too high."; }
|
|
1119
|
+
if (v.tooLong) { flags.tooLong = true; msg = msg || "Value is too long."; }
|
|
1120
|
+
if (v.tooShort) { flags.tooShort = true; msg = msg || "Value is too short."; }
|
|
1121
|
+
if (v.badInput) { flags.badInput = true; msg = msg || "Invalid input."; }
|
|
1122
|
+
}
|
|
1123
|
+
this._internals.setValidity(flags, msg);
|
|
1124
|
+
this._setCustomState("data-invalid", Object.keys(flags).length > 0);
|
|
882
1125
|
}
|
|
883
1126
|
|
|
884
|
-
// Custom-state mirror
|
|
885
|
-
// own boolean to CSS as `:state(name)` — a consumer writes
|
|
886
|
-
// `contour-switch:state(data-checked)` without the layer inventing a data-*
|
|
887
|
-
// attribute. Loader hosts are NOT formAssociated, so the states-only
|
|
888
|
-
// internals are attached lazily into `_stateInternals` — never `_internals`,
|
|
889
|
-
// which every form path uses as its "form-associated" guard (`_wireFormData`
|
|
890
|
-
// reads .form on it, which throws on a non-form host; probing lazy attach
|
|
891
|
-
// into `_internals` broke every src-mounting arm with exactly that error).
|
|
892
|
-
// Where CustomStateSet is absent the mirror is a silent no-op and the
|
|
893
|
-
// ARIA/attribute path remains the announcement. Not a write to OBSERVED,
|
|
894
|
-
// so it can never re-enter render.
|
|
1127
|
+
// Custom-state mirror . `ElementInternals.states` exposes a host's own boolean to CSS as `:state(name)` — a consumer wr...
|
|
895
1128
|
_setCustomState(name, on) {
|
|
896
1129
|
let internals = this._internals;
|
|
897
1130
|
if (!internals) {
|
|
@@ -906,12 +1139,7 @@
|
|
|
906
1139
|
else if (states.has(name)) states.delete(name);
|
|
907
1140
|
}
|
|
908
1141
|
|
|
909
|
-
// The form value events
|
|
910
|
-
// bubbling contour:* events; the form family had 16 user-interaction
|
|
911
|
-
// listeners and emitted none, so a consumer could not observe a change
|
|
912
|
-
// without polling. This is the ONE value-shape both `contour:input` and
|
|
913
|
-
// `contour:change` carry, derived from the same control state _syncFormValue
|
|
914
|
-
// submits, so the event can never disagree with the entry list.
|
|
1142
|
+
// The form value events . §23 promises interactive components emit bubbling contour:* events; the form family had 16 us...
|
|
915
1143
|
_emitForm(type) {
|
|
916
1144
|
if (!this._internals) return;
|
|
917
1145
|
const ctl = this.querySelector("input:checked, textarea, select") || this.querySelector("input, textarea, select");
|
|
@@ -928,12 +1156,7 @@
|
|
|
928
1156
|
}));
|
|
929
1157
|
}
|
|
930
1158
|
formResetCallback() {
|
|
931
|
-
// Reset synchronously: re-rendering would restore the base class's
|
|
932
|
-
// *preserved* typed value, not the authored default. The authored
|
|
933
|
-
// default is the host's own value/checked attributes, so restore the
|
|
934
|
-
// inner control from them, then re-sync internals. The user-dirty marks
|
|
935
|
-
// go with the reset: a later re-render must not resurrect the typed
|
|
936
|
-
// value the form just discarded.
|
|
1159
|
+
// Reset synchronously: re-rendering would restore the base class's *preserved* typed value, not the authored default. T...
|
|
937
1160
|
for (const ctl of this.querySelectorAll("input, textarea, select")) {
|
|
938
1161
|
ctl._contourUserDirty = false;
|
|
939
1162
|
if (ctl.type === "checkbox" || ctl.type === "radio") {
|
|
@@ -979,14 +1202,7 @@
|
|
|
979
1202
|
return this._internals ? this._internals.reportValidity() : true;
|
|
980
1203
|
}
|
|
981
1204
|
|
|
982
|
-
// Keep internals in step with the group. Checking radio B fires `change` on
|
|
983
|
-
// B only — the deselected host A hears nothing, so its internals keep the
|
|
984
|
-
// stale "a" and the entry list collects both ("g=a","g=b"; measured by the
|
|
985
|
-
// form-lifecycle probe, 2026-10-28). Re-syncing in the `formdata` handler
|
|
986
|
-
// is too late: the entry list has already copied each host's internals
|
|
987
|
-
// before that event fires. `change` bubbles through the shared form, so a
|
|
988
|
-
// same-name host re-derives its value the moment B is checked — before any
|
|
989
|
-
// collection can read it.
|
|
1205
|
+
// Keep internals in step with the group. Checking radio B fires `change` on B only — the deselected host A hears nothin...
|
|
990
1206
|
_wireFormData() {
|
|
991
1207
|
if (!this._internals || this._wiredFormData) return;
|
|
992
1208
|
const form = this._internals.form;
|
|
@@ -1006,17 +1222,7 @@
|
|
|
1006
1222
|
});
|
|
1007
1223
|
}
|
|
1008
1224
|
|
|
1009
|
-
// User-dirty value tracking (R20 T-02). The restore path only fills
|
|
1010
|
-
// controls a render left empty, so a host with an authored `value`
|
|
1011
|
-
// attribute overwrote whatever the user typed on every unrelated
|
|
1012
|
-
// attribute change. A control the user actually edited — an `input` or
|
|
1013
|
-
// `change` event, which programmatic `.value` writes do not fire — is
|
|
1014
|
-
// marked dirty together with the host's `value` attribute at that moment;
|
|
1015
|
-
// `_restoreControlValue` keeps the typed value until the author changes
|
|
1016
|
-
// that attribute. Scoped to form-associated hosts: their controls carry
|
|
1017
|
-
// the submission contract, and a non-form widget that clears its own
|
|
1018
|
-
// field on re-render keeps that behaviour. Delegated on the host (rule
|
|
1019
|
-
// 12): the controls are rebuilt on every render.
|
|
1225
|
+
// User-dirty value tracking (R20 T-02). The restore path only fills controls a render left empty, so a host with an aut...
|
|
1020
1226
|
_wireValueTracking() {
|
|
1021
1227
|
if (!this._internals || this._wiredValueTracking) return;
|
|
1022
1228
|
this._wiredValueTracking = true;
|
|
@@ -1031,14 +1237,10 @@
|
|
|
1031
1237
|
this.addEventListener("change", mark);
|
|
1032
1238
|
}
|
|
1033
1239
|
|
|
1034
|
-
// Restore one control's value from its snapshot (R20 T-02/T-06). A
|
|
1035
|
-
// user-dirty control keeps its typed value — a multi-select its whole
|
|
1036
|
-
// selection, not just the first selected option — until the host's
|
|
1037
|
-
// `value` attribute changes. Otherwise the original rule stands: only a
|
|
1038
|
-
// control the render left empty, with no value attribute of its own,
|
|
1039
|
-
// takes the saved value. The dirty mark is re-applied to the rebuilt
|
|
1040
|
-
// control so the NEXT re-render preserves it too.
|
|
1240
|
+
// Restore one control's value from its snapshot (R20 T-02/T-06). A user-dirty control keeps its typed value — a multi-s...
|
|
1041
1241
|
_restoreControlValue(el, saved) {
|
|
1242
|
+
// R24-116: a file input's `.value` is read-only — assigning it throws an InvalidStateError (the value is a synthetic "C...
|
|
1243
|
+
if (el.type === "file") return;
|
|
1042
1244
|
if (saved.dirty && saved.attrAtDirty === this.getAttribute("value")) {
|
|
1043
1245
|
if (saved.selected && el.tagName === "SELECT" && el.multiple) {
|
|
1044
1246
|
const wanted = new Set(saved.selected);
|
|
@@ -1053,13 +1255,7 @@
|
|
|
1053
1255
|
if (el.value === "" && el.getAttribute("value") === null) el.value = saved.value;
|
|
1054
1256
|
}
|
|
1055
1257
|
|
|
1056
|
-
// The inner native control(s) are scaffolding; the host reports through
|
|
1057
|
-
// ElementInternals. A same-name native control inside a <form> would submit
|
|
1058
|
-
// a second entry with the same name — double submission, measured as
|
|
1059
|
-
// ["g=a","g=a"] in a two-entry FormData (2026-10-27, form-lifecycle probe).
|
|
1060
|
-
// form="" (no matching form element) detaches it from the form owner while
|
|
1061
|
-
// keeping native radio-group semantics: same name, same tree, both
|
|
1062
|
-
// form-ownerless → they still share one checked state.
|
|
1258
|
+
// The inner native control(s) are scaffolding; the host reports through ElementInternals. A same-name native control in...
|
|
1063
1259
|
_detachInnerFormControls() {
|
|
1064
1260
|
if (!this._internals) return;
|
|
1065
1261
|
for (const ctl of this.querySelectorAll("input, textarea, select")) {
|
|
@@ -1067,10 +1263,7 @@
|
|
|
1067
1263
|
}
|
|
1068
1264
|
}
|
|
1069
1265
|
|
|
1070
|
-
// Opt-in batching: coalesce multiple attribute changes into a single
|
|
1071
|
-
// render. Usage: el.batch(() => { el.value = 42; el.delta = "+3"; });
|
|
1072
|
-
// The render fires once when the callback returns, reading all final
|
|
1073
|
-
// attribute values. Nested calls are supported.
|
|
1266
|
+
// Opt-in batching: coalesce multiple attribute changes into a single render. Usage: el.batch(() => { el.value = 42; el....
|
|
1074
1267
|
/** Coalesce synchronous property changes into one render. */
|
|
1075
1268
|
batch(fn) {
|
|
1076
1269
|
if (typeof fn !== "function") return;
|
|
@@ -1090,19 +1283,7 @@
|
|
|
1090
1283
|
}
|
|
1091
1284
|
}
|
|
1092
1285
|
|
|
1093
|
-
//
|
|
1094
|
-
// host started itself — a `src` fetch that resolved, a timer, an observer. A
|
|
1095
|
-
// render body must never reach for `attributeChangedCallback` directly: on the
|
|
1096
|
-
// connect path `_contourRendering` is still false, so that call performs a
|
|
1097
|
-
// synchronous nested re-render and the outer body then carries on painting the
|
|
1098
|
-
// node the nested pass already painted. Measured in Chromium (tmp/wc9/probe.mjs,
|
|
1099
|
-
// 2026-10-27): a host with `src` rendered "Loading…Loading…" — two nodes — while
|
|
1100
|
-
// the identical host with an authored `loading` attribute rendered one.
|
|
1101
|
-
//
|
|
1102
|
-
// Deferring to a microtask lets the in-flight render finish before the next one
|
|
1103
|
-
// starts, and the flag coalesces N asks in one pass into one render. It runs
|
|
1104
|
-
// through the same reset/restore path as an attribute change, so a consumer's
|
|
1105
|
-
// authored nodes and focus survive it exactly as they survive a real change.
|
|
1286
|
+
// Request a re-render without naming the changed attribute (for host-driven work: a resolved fetch, a timer, an observer). A render body must never call attributeChangedCallback directly — on the connect path that nests a synchronous render. Deferring to a microtask coalesces N asks into one render through the same reset/restore path.
|
|
1106
1287
|
requestRender() {
|
|
1107
1288
|
if (this._contourRerenderQueued) return;
|
|
1108
1289
|
this._contourRerenderQueued = true;
|
|
@@ -1113,38 +1294,21 @@
|
|
|
1113
1294
|
});
|
|
1114
1295
|
}
|
|
1115
1296
|
|
|
1116
|
-
//
|
|
1117
|
-
// `
|
|
1118
|
-
//
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
for (const node of nodes) {
|
|
1123
|
-
if (node.hasAttribute("part")) continue;
|
|
1124
|
-
if (typeof node.className !== "string") continue;
|
|
1125
|
-
for (const c of node.className.split(/\s+/)) {
|
|
1126
|
-
const m = c.match(/^c-[a-z0-9-]+__([a-z0-9-]+)$/);
|
|
1127
|
-
if (m) { node.setAttribute("part", m[1]); break; }
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1297
|
+
// R31-15: the light layer no longer writes `part=` on generated nodes.
|
|
1298
|
+
// `::part()` matches only shadow parts, so the attribute was inert on every
|
|
1299
|
+
// light component while `_applyParts` scanned every `[class]` on every
|
|
1300
|
+
// render (~12% of steady-state re-render on a 500-row table). The light
|
|
1301
|
+
// theming seam is `contour-<block> .c-<block>__<element>`; the shadow layer
|
|
1302
|
+
// keeps its real `::part()` hooks (shadow.mjs).
|
|
1131
1303
|
|
|
1132
|
-
// Density modifier
|
|
1133
|
-
// attribute the token layer ships with (`--density`, `--density-compact`
|
|
1134
|
-
// in tokens.css) — so the wc layer exposes a `density` attribute and
|
|
1135
|
-
// mirrors it to `data-density` on the host. `data-density` is not in
|
|
1136
|
-
// OBSERVED, so the write cannot re-enter the render this runs from.
|
|
1304
|
+
// Density modifier: mirror `density` attribute to `data-density` on the host (the sheet hooks on it); not in OBSERVED so the write can't re-enter render.
|
|
1137
1305
|
_applyDensity() {
|
|
1138
1306
|
const density = this.getAttribute("density");
|
|
1139
1307
|
if (density !== null) this.setAttribute("data-density", density);
|
|
1140
1308
|
else if (this.hasAttribute("data-density")) this.removeAttribute("data-density");
|
|
1141
1309
|
}
|
|
1142
1310
|
|
|
1143
|
-
//
|
|
1144
|
-
// path never crosses another host. `ensure()` may only reuse a node its own
|
|
1145
|
-
// host owns: querySelector reaches straight through a nested host's
|
|
1146
|
-
// boundary, so two blocks that both carry a `__title` would share one
|
|
1147
|
-
// element and the outer render would write the inner one's text.
|
|
1311
|
+
// Closest host above `node` up to `root`, or null. ensure() may only reuse a node its own host owns: querySelector reaches through a nested host's boundary, so two blocks with a `__title` would share one element.
|
|
1148
1312
|
_ownerBetween(node, root) {
|
|
1149
1313
|
for (let p = node.parentElement; p && p !== root; p = p.parentElement) {
|
|
1150
1314
|
if (p instanceof ContourBase) return p;
|
|
@@ -1153,15 +1317,26 @@
|
|
|
1153
1317
|
}
|
|
1154
1318
|
|
|
1155
1319
|
// Helper for update-or-create reactivity: returns the first node matching
|
|
1156
|
-
// `selector`, creating it via `factory()` and appending
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1320
|
+
// `selector`, creating it via `factory()` and appending if absent, so an attribute change updates the existing node. A per-render cache (keyed by scope and selector) avoids re-querying the subtree for every ensure() call.
|
|
1321
|
+
/**
|
|
1322
|
+
* Register a generated node as persistent across re-renders.
|
|
1323
|
+
*
|
|
1324
|
+
* The base class drops every generated node on each render and rebuilds it
|
|
1325
|
+
* from `render()`. That is right for markup and wrong for a node whose
|
|
1326
|
+
* identity carries state the markup does not: a scroller's `scrollTop`, a
|
|
1327
|
+
* canvas' drawn pixels, a media element's `currentTime`. Registering the
|
|
1328
|
+
* node here keeps it alive across the rebuild; `render()` re-attaches it.
|
|
1329
|
+
*
|
|
1330
|
+
* @param {Node} node generated node to keep
|
|
1331
|
+
* @returns {Node} the same node, for chaining
|
|
1332
|
+
*/
|
|
1333
|
+
keepNode(node) {
|
|
1334
|
+
if (!node) return node;
|
|
1335
|
+
if (!this._contourPersistent) this._contourPersistent = new Set();
|
|
1336
|
+
this._contourPersistent.add(node);
|
|
1337
|
+
return node;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1165
1340
|
ensure(selector, factory, parent) {
|
|
1166
1341
|
const root = parent || this;
|
|
1167
1342
|
if (!root._ensureCache || root._ensureCacheGen !== this._contourRenderGen) {
|
|
@@ -1181,13 +1356,8 @@
|
|
|
1181
1356
|
}
|
|
1182
1357
|
if (!node) {
|
|
1183
1358
|
node = factory();
|
|
1184
|
-
//
|
|
1185
|
-
//
|
|
1186
|
-
// name after the block's `__` separator (e.g. .c-card__title -> "title").
|
|
1187
|
-
if (node && node.setAttribute && !node.hasAttribute("part")) {
|
|
1188
|
-
const m = String(selector).match(/\.c-[a-z0-9-]+__([a-z0-9-]+)/);
|
|
1189
|
-
if (m) node.setAttribute("part", m[1]);
|
|
1190
|
-
}
|
|
1359
|
+
// R31-15: no `part=` write here — it is inert on light DOM (see the
|
|
1360
|
+
// removed _applyParts). Shadow wrappers set their own real parts.
|
|
1191
1361
|
root.appendChild(node);
|
|
1192
1362
|
cache.set(key, node);
|
|
1193
1363
|
}
|
|
@@ -1195,10 +1365,7 @@
|
|
|
1195
1365
|
}
|
|
1196
1366
|
}
|
|
1197
1367
|
|
|
1198
|
-
// Brownout mixin
|
|
1199
|
-
// chrome under degraded conditions. Merges `brownout` / `brownout-level`
|
|
1200
|
-
// into the subclass observed list and exposes the helpers already on
|
|
1201
|
-
// ContourBase. Usage: `class Foo extends withBrownout(ContourBase) { ... }`.
|
|
1368
|
+
// Brownout mixin : opt-in base for components that shed non-essential chrome under degraded conditions. Merges `brownou...
|
|
1202
1369
|
export function withBrownout(Base) {
|
|
1203
1370
|
return class extends Base {
|
|
1204
1371
|
static get observed() {
|
|
@@ -1210,6 +1377,11 @@
|
|
|
1210
1377
|
shed(kind, threshold) { return this.brownoutLevel() >= (threshold || 1); }
|
|
1211
1378
|
};
|
|
1212
1379
|
}
|
|
1380
|
+
/** Pure helper: compute brownout level from an attribute bag (framework-neutral). */
|
|
1381
|
+
export function levelFromAttributes(attrs = {}) {
|
|
1382
|
+
const raw = (attrs && (attrs["brownout-level"] || attrs["brownout"])) || "0";
|
|
1383
|
+
return parseInt(raw, 10) || 0;
|
|
1384
|
+
}
|
|
1213
1385
|
|
|
1214
1386
|
// Simple component: just adds CSS classes.
|
|
1215
1387
|
/** Create a light-DOM component that only applies block and modifier classes. */
|
|
@@ -1233,21 +1405,13 @@
|
|
|
1233
1405
|
};
|
|
1234
1406
|
|
|
1235
1407
|
// ---- Class-only blocks ----
|
|
1236
|
-
//
|
|
1237
|
-
// A block in this list needs nothing but its own class: the element name is
|
|
1238
|
-
// \`contour-<block>\` and the class is \`c-<block>\`, which is why the table holds
|
|
1239
|
-
// the block and not two spellings of it. Blocks that need scaffolding are not
|
|
1240
|
-
// here — they declare a class above, and their presence in this list would be
|
|
1241
|
-
// a fallback that only runs when the real component is broken, so the
|
|
1242
|
-
// registration loop skips a name an explicit component already claimed.
|
|
1408
|
+
// A block here needs only its own class: element `contour-<block>`, class `c-<block>`. Blocks needing scaffolding declare a class above; the registration loop skips a name an explicit component already claimed.
|
|
1243
1409
|
/** Blocks whose custom elements need no generated markup. */
|
|
1244
1410
|
export const CLASS_ONLY = [
|
|
1245
1411
|
"box", "cluster", "container", "row", "scrim", "stack"
|
|
1246
1412
|
];
|
|
1247
1413
|
|
|
1248
|
-
// Feature detection for `hidden="until-found"
|
|
1249
|
-
// support it treat the value as the boolean hidden attribute, which would
|
|
1250
|
-
// hide the content permanently — so we only upgrade where supported.
|
|
1414
|
+
// Feature detection for `hidden="until-found"`: unsupported browsers treat the value as boolean hidden (permanent hide), so only upgrade where supported.
|
|
1251
1415
|
/** Detect support for the non-destructive `hidden="until-found"` value. */
|
|
1252
1416
|
export function supportsUntilFound() {
|
|
1253
1417
|
try {
|
|
@@ -1257,11 +1421,7 @@
|
|
|
1257
1421
|
} catch (e) { return false; }
|
|
1258
1422
|
}
|
|
1259
1423
|
|
|
1260
|
-
// Value formatting
|
|
1261
|
-
// `format` is a preset ("number","currency","percent","compact","date","time",
|
|
1262
|
-
// "unit","relative") or a JSON string of Intl.NumberFormat/DateTimeFormat/
|
|
1263
|
-
// RelativeTimeFormat options. `locale` defaults to the runtime locale.
|
|
1264
|
-
// Returns the raw value when formatting fails.
|
|
1424
|
+
// Value formatting: opt-in Intl formatting for kpi/stat/readout/coordinate. `format` is a preset or JSON of Intl options; `locale` defaults to runtime locale; returns raw value on failure.
|
|
1265
1425
|
/** Format a value with the component's supported Intl presets. */
|
|
1266
1426
|
export function formatValue(value, format, locale, unit) {
|
|
1267
1427
|
if (!format) return value;
|
|
@@ -1300,12 +1460,7 @@
|
|
|
1300
1460
|
catch (e) { return value; }
|
|
1301
1461
|
}
|
|
1302
1462
|
|
|
1303
|
-
// Shared keyboard navigation for roving-tabindex patterns.
|
|
1304
|
-
// `items`: array of focusable elements, `e`: KeyboardEvent.
|
|
1305
|
-
// Options: `{ wrap (default true), enter (default true), homeEnd (false),
|
|
1306
|
-
// onKey(key, idx, item) }` — return truthy to preventDefault.
|
|
1307
|
-
// `onNavigate(newIdx)` — called after focus moves with new index.
|
|
1308
|
-
// `rtl` — if true, ArrowRight/Left swap direction; defaults to dir attribute.
|
|
1463
|
+
// Shared keyboard navigation for roving-tabindex patterns. Options: { wrap=true, enter=true, homeEnd=false, onKey(key,idx,item)→truthy prevents default, onNavigate(newIdx), rtl (defaults to dir attr) }.
|
|
1309
1464
|
/** Navigate a roving-tabindex group with arrow keys, Home/End, Enter/Space. */
|
|
1310
1465
|
export function navKey(e, items, { wrap = true, enter = true, homeEnd = false, onKey, onNavigate, rtl } = {}) {
|
|
1311
1466
|
const idx = items.indexOf(document.activeElement);
|
|
@@ -1365,7 +1520,55 @@
|
|
|
1365
1520
|
return (toDeg(Math.atan2(y, x)) + 360) % 360;
|
|
1366
1521
|
}
|
|
1367
1522
|
// Mercator resolution (meters per pixel) at a given latitude and zoom.
|
|
1523
|
+
/** The latitude Web Mercator can represent; beyond it the projection diverges. */
|
|
1524
|
+
export const MERCATOR_MAX_LAT = 85.05112878;
|
|
1525
|
+
|
|
1526
|
+
/** Clamp a latitude into the Mercator domain; NaN when the input is not a number. */
|
|
1527
|
+
export function clampLat(lat) {
|
|
1528
|
+
const v = Number(lat);
|
|
1529
|
+
if (!Number.isFinite(v)) return NaN;
|
|
1530
|
+
return Math.max(-MERCATOR_MAX_LAT, Math.min(MERCATOR_MAX_LAT, v));
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
/** Wrap a longitude into [-180, 180). NaN when the input is not a number. */
|
|
1534
|
+
export function normaliseLng(lng) {
|
|
1535
|
+
const v = Number(lng);
|
|
1536
|
+
if (!Number.isFinite(v)) return NaN;
|
|
1537
|
+
return ((((v + 180) % 360) + 360) % 360) - 180;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
/**
|
|
1541
|
+
* Normalise a west/south/east/north box. A box that crosses the antimeridian
|
|
1542
|
+
* arrives as `west > east` (MapLibre reports 170 → -170 that way), which makes
|
|
1543
|
+
* `east - west` negative and hides the crossing. The returned box is unwrapped
|
|
1544
|
+
* — `east` continues past 180 — and says so, so a span is always positive and
|
|
1545
|
+
* a consumer that needs the engine's own numbers can subtract 360 from `east`
|
|
1546
|
+
* when `crossesAntimeridian` is true.
|
|
1547
|
+
*/
|
|
1548
|
+
export function unwrapBounds(bounds) {
|
|
1549
|
+
const b = bounds || {};
|
|
1550
|
+
const west = normaliseLng(b.west);
|
|
1551
|
+
const eastRaw = normaliseLng(b.east);
|
|
1552
|
+
const crossesAntimeridian = Number.isFinite(west) && Number.isFinite(eastRaw) && west > eastRaw;
|
|
1553
|
+
return {
|
|
1554
|
+
west,
|
|
1555
|
+
south: clampLat(b.south),
|
|
1556
|
+
east: crossesAntimeridian ? eastRaw + 360 : eastRaw,
|
|
1557
|
+
north: clampLat(b.north),
|
|
1558
|
+
crossesAntimeridian,
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1368
1562
|
/** Return meters per pixel for Web Mercator at a latitude and zoom level. */
|
|
1369
1563
|
export function mercatorResolution(lat, zoom) {
|
|
1370
|
-
|
|
1564
|
+
// Beyond ±85.05112878° the projection is undefined and cos() collapses
|
|
1565
|
+
// toward zero (resolution 6e-17 at the pole instead of a finite number).
|
|
1566
|
+
const phi = clampLat(lat);
|
|
1567
|
+
if (!Number.isFinite(phi)) return NaN;
|
|
1568
|
+
return 156543.03392 * Math.cos(phi * Math.PI / 180) / Math.pow(2, zoom);
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
// Event vocabulary is static, so publish once here (frozen) rather than per-registration; any import path reaching core.mjs exposes it.
|
|
1572
|
+
if (typeof window !== "undefined") {
|
|
1573
|
+
window.ContourEvents = Object.freeze(CONTOUR_EVENTS);
|
|
1371
1574
|
}
|