contour-ds 1.1.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +7 -1
  2. package/dist/agent-rules.json +5 -1
  3. package/dist/build-manifest.json +93 -92
  4. package/dist/contour-wc.esm.js +4113 -480
  5. package/dist/contour-wc.esm.min.js +1 -1
  6. package/dist/contour-wc.js +4115 -478
  7. package/dist/contour-wc.min.js +1 -1
  8. package/dist/contour.components.json +2597 -135
  9. package/dist/contour.css +625 -27
  10. package/dist/contour.d.ts +109 -61
  11. package/dist/contour.esm.js +16 -0
  12. package/dist/contour.js +16 -0
  13. package/dist/contour.min.css +1 -1
  14. package/dist/contour.tokens.json +37 -0
  15. package/dist/docs/actions.md +6 -2
  16. package/dist/docs/affordances.md +19 -3
  17. package/dist/docs/colour.md +2 -2
  18. package/dist/docs/componentindex.md +39 -0
  19. package/dist/docs/data.md +38 -3
  20. package/dist/docs/docs.md +6 -2
  21. package/dist/docs/feedback.md +13 -3
  22. package/dist/docs/field.md +7 -2
  23. package/dist/docs/forms.md +35 -3
  24. package/dist/docs/index.json +32 -76
  25. package/dist/docs/install.md +4 -2
  26. package/dist/docs/landing.md +3 -2
  27. package/dist/docs/mapengine.md +9 -3
  28. package/dist/docs/motion.md +5 -2
  29. package/dist/docs/navigation.md +10 -3
  30. package/dist/docs/overlays.md +26 -3
  31. package/dist/docs/overview.md +2 -2
  32. package/dist/docs/patterns.md +38 -3
  33. package/dist/docs/playground.md +5 -2
  34. package/dist/docs/principles.md +2 -2
  35. package/dist/docs/recipes.md +7 -3
  36. package/dist/docs/space.md +2 -2
  37. package/dist/docs/status.md +19 -3
  38. package/dist/docs/surfaces.md +7 -3
  39. package/dist/docs/theming.md +5 -2
  40. package/dist/docs/type.md +2 -2
  41. package/dist/docs/webcomponents.md +26 -3
  42. package/dist/map-chrome.mapbox.css +4 -4
  43. package/dist/map-chrome.maplibre.css +4 -4
  44. package/dist/registry/items/contour-core.json +2 -2
  45. package/dist/registry/items/contour-data.json +2 -2
  46. package/dist/registry/items/contour-docs.json +2 -2
  47. package/dist/registry/items/contour-landing.json +2 -2
  48. package/dist/registry/registry.json +8 -8
  49. package/dist/surfaces/contour-core.min.css +1 -1
  50. package/dist/surfaces/contour-data.min.css +1 -1
  51. package/dist/surfaces/contour-docs.min.css +1 -1
  52. package/dist/surfaces/contour-landing.min.css +1 -1
  53. package/dist/wc/behaviours.mjs +69 -11
  54. package/dist/wc/content.mjs +163 -8
  55. package/dist/wc/core.mjs +145 -34
  56. package/dist/wc/dashboard.mjs +69 -4
  57. package/dist/wc/data.mjs +866 -115
  58. package/dist/wc/docs.mjs +1 -0
  59. package/dist/wc/feedback.mjs +75 -13
  60. package/dist/wc/forms.mjs +371 -34
  61. package/dist/wc/index.mjs +7 -3
  62. package/dist/wc/interaction.mjs +11 -6
  63. package/dist/wc/map.mjs +121 -38
  64. package/dist/wc/misc.mjs +29 -1
  65. package/dist/wc/navigation.mjs +424 -75
  66. package/dist/wc/registration.mjs +8 -4
  67. package/dist/wc/shadow.mjs +29 -12
  68. package/dist/wc/states.mjs +15 -0
  69. package/dist/wc/svg.mjs +10 -0
  70. package/dist/wc/ui.mjs +1710 -126
  71. package/package.json +39 -6
package/dist/wc/ui.mjs CHANGED
@@ -1,5 +1,10 @@
1
1
  import { ContourBase, define, contourId, onDispose } from './core.mjs';
2
2
  import { wireRemovable } from './behaviours.mjs';
3
+ /**
4
+ * Avatar: a circular avatar with initials (from `name`) or an image (`src`),
5
+ * optional size/variant modifiers and a status dot. Attributes: `name`, `size`,
6
+ * `variant`, `src`, `status`.
7
+ */
3
8
  class ContourAvatar extends ContourBase {
4
9
  static get observed() { return ["name", "size", "variant", "src", "status"]; }
5
10
  static get properties() { return { name: { attribute: "name" }, size: { attribute: "size" }, variant: { attribute: "variant" }, src: { attribute: "src" }, status: { attribute: "status" } }; }
@@ -42,6 +47,10 @@ class ContourAvatar extends ContourBase {
42
47
  }
43
48
  }
44
49
  define("contour-avatar", ContourAvatar);
50
+ /**
51
+ * Badge: a small status label with variant/size modifiers and an optional
52
+ * removable (×) button. Attributes: `variant`, `label`, `size`, `removable`.
53
+ */
45
54
  class ContourBadgeFull extends ContourBase {
46
55
  static get observed() { return ["variant", "label", "size", "removable"]; }
47
56
  static get properties() { return { variant: { attribute: "variant" }, label: { attribute: "label" }, size: { attribute: "size" }, removable: { attribute: "removable", type: Boolean } }; }
@@ -79,6 +88,10 @@ class ContourBadgeFull extends ContourBase {
79
88
  }
80
89
  }
81
90
  define("contour-badge", ContourBadgeFull);
91
+ /**
92
+ * Chip: a compact status pill with `key`/`value` text and a variant modifier.
93
+ * Attributes: `variant`, `key`, `value`.
94
+ */
82
95
  class ContourChipFull extends ContourBase {
83
96
  static get observed() { return ["variant", "key", "value"]; }
84
97
  static get properties() { return { variant: { attribute: "variant" }, key: { attribute: "key" }, value: { attribute: "value" } }; }
@@ -107,6 +120,10 @@ class ContourChipFull extends ContourBase {
107
120
  }
108
121
  }
109
122
  define("contour-chip", ContourChipFull);
123
+ /**
124
+ * Tag: a removable status label with a variant modifier. Attributes: `label`,
125
+ * `removable`, `variant`.
126
+ */
110
127
  class ContourTag extends ContourBase {
111
128
  static get observed() { return ["label", "removable", "variant"]; }
112
129
  static get properties() { return { label: { attribute: "label" }, removable: { attribute: "removable", type: Boolean }, variant: { attribute: "variant" } }; }
@@ -148,6 +165,10 @@ class ContourTag extends ContourBase {
148
165
  }
149
166
  }
150
167
  define("contour-tag", ContourTag);
168
+ /**
169
+ * Dot: a small status indicator with variant and live states. Attributes:
170
+ * `variant`, `live`.
171
+ */
151
172
  class ContourDot extends ContourBase {
152
173
  static get observed() { return ["variant", "live"]; }
153
174
  static get properties() { return { variant: { attribute: "variant" }, live: { attribute: "live", type: Boolean } }; }
@@ -158,10 +179,14 @@ class ContourDot extends ContourBase {
158
179
  Array.from(this.classList).forEach((c) => { if (c.startsWith("c-dot--")) this.classList.remove(c); });
159
180
  const variant = this.getAttribute("variant");
160
181
  if (variant) this.classList.add("c-dot--" + variant);
161
- if (this.hasAttribute("live")) this.classList.add("c-dot--live");
182
+ if (this.hasAttribute("live")) this.classList.add("c-dot--live"); else this.classList.remove("c-dot--live");
162
183
  }
163
184
  }
164
185
  define("contour-dot", ContourDot);
186
+ /**
187
+ * Pill: a rounded status label with live state and variant modifier.
188
+ * Attributes: `label`, `live`, `variant`.
189
+ */
165
190
  class ContourPill extends ContourBase {
166
191
  static get observed() { return ["label", "live", "variant"]; }
167
192
  static get properties() { return { label: { attribute: "label" }, live: { attribute: "live", type: Boolean }, variant: { attribute: "variant" } }; }
@@ -175,10 +200,13 @@ class ContourPill extends ContourBase {
175
200
  if (label) {
176
201
  this.textContent = label;
177
202
  }
178
- if (this.hasAttribute("live")) this.classList.add("c-pill--live");
203
+ if (this.hasAttribute("live")) this.classList.add("c-pill--live"); else this.classList.remove("c-pill--live");
179
204
  }
180
205
  }
181
206
  define("contour-pill", ContourPill);
207
+ /**
208
+ * Kbd: a keyboard key display. Attribute: `key`.
209
+ */
182
210
  class ContourKbd extends ContourBase {
183
211
  static get observed() { return ["key"]; }
184
212
  static get properties() { return { key: { attribute: "key" } }; }
@@ -191,6 +219,9 @@ class ContourKbd extends ContourBase {
191
219
  }
192
220
  }
193
221
  define("contour-kbd", ContourKbd);
222
+ /**
223
+ * Spinner: a loading indicator with size modifier. Attribute: `size`.
224
+ */
194
225
  class ContourSpinner extends ContourBase {
195
226
  static get observed() { return ["size"]; }
196
227
  static get properties() { return { size: { attribute: "size" } }; }
@@ -204,17 +235,32 @@ class ContourSpinner extends ContourBase {
204
235
  }
205
236
  }
206
237
  define("contour-spinner", ContourSpinner);
238
+ /**
239
+ * Skeleton: a loading placeholder with size and shimmer options. Attributes:
240
+ * `size`, `shimmer`.
241
+ */
207
242
  class ContourSkeleton extends ContourBase {
208
- static get observed() { return ["size"]; }
209
- static get properties() { return { size: { attribute: "size" } }; }
243
+ static get observed() { return ["size", "shimmer"]; }
244
+ static get properties() { return { size: { attribute: "size" }, shimmer: { attribute: "shimmer", type: Boolean } }; }
210
245
  render() {
211
246
  this.classList.add("c-skeleton");
212
247
  Array.from(this.classList).forEach((c) => { if (c.startsWith("c-skeleton--")) this.classList.remove(c); });
213
248
  const size = this.getAttribute("size");
214
249
  if (size) this.classList.add("c-skeleton--" + size);
250
+ if (!this.hasAttribute("role")) this.setAttribute("role", "status");
251
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Loading");
252
+ if (!this.hasAttribute("aria-busy")) this.setAttribute("aria-busy", "true");
253
+ if (!this.hasAttribute("aria-hidden")) this.setAttribute("aria-hidden", "true");
254
+ const shimmer = this.getAttribute("shimmer");
255
+ if (shimmer === "false" || shimmer === "off") this.classList.add("c-skeleton--static");
256
+ else this.classList.remove("c-skeleton--static");
215
257
  }
216
258
  }
217
259
  define("contour-skeleton", ContourSkeleton);
260
+ /**
261
+ * Tooltip: a popover-triggered tooltip with anchor association, delay, and
262
+ * viewport flip. Attributes: `text`, `anchor`, `delay`, `trigger`.
263
+ */
218
264
  class ContourTooltip extends ContourBase {
219
265
  static get observed() { return ["text", "anchor", "delay", "trigger"]; }
220
266
  static get properties() { return { text: { attribute: "text" }, anchor: { attribute: "anchor" }, delay: { attribute: "delay", type: Number }, trigger: { attribute: "trigger" } }; }
@@ -247,14 +293,24 @@ class ContourTooltip extends ContourBase {
247
293
  }
248
294
  const delayMs = (this.delay && this.delay > 0) ? this.delay : 0;
249
295
  let showTimer = null;
296
+ const hasPopover = typeof this.showPopover === "function";
250
297
  const show = () => {
251
298
  if (showTimer) clearTimeout(showTimer);
252
- if (delayMs > 0) showTimer = setTimeout(() => { try { this.showPopover(); } catch (e) {} }, delayMs);
253
- else { try { this.showPopover(); } catch (e) {} }
299
+ if (delayMs > 0) showTimer = setTimeout(() => {
300
+ if (hasPopover) { try { this.showPopover(); } catch (e) {} }
301
+ else this.classList.add("is-open");
302
+ try { requestAnimationFrame(flipIfNeeded); } catch (e) { flipIfNeeded(); }
303
+ }, delayMs);
304
+ else {
305
+ if (hasPopover) { try { this.showPopover(); } catch (e) {} }
306
+ else this.classList.add("is-open");
307
+ try { requestAnimationFrame(flipIfNeeded); } catch (e) { flipIfNeeded(); }
308
+ }
254
309
  };
255
310
  const hide = () => {
256
311
  if (showTimer) { clearTimeout(showTimer); showTimer = null; }
257
- try { this.hidePopover(); } catch (e) {}
312
+ if (hasPopover) { try { this.hidePopover(); } catch (e) {} }
313
+ else this.classList.remove("is-open");
258
314
  };
259
315
  const triggerMode = this.getAttribute("trigger") || "hover";
260
316
  const trigger = anchorSel ? (anchorSel.startsWith("#") ? document.getElementById(anchorSel.slice(1)) : document.querySelector(anchorSel)) : null;
@@ -268,17 +324,35 @@ class ContourTooltip extends ContourBase {
268
324
  if (this.matches(":popover-open")) hide(); else show();
269
325
  }
270
326
  };
327
+ const onTouchStart = () => { if (triggerMode !== "click") show(); };
328
+ const onTouchEnd = () => { if (triggerMode !== "click") { setTimeout(hide, 1500); } };
271
329
  target.addEventListener("mouseenter", onEnter);
272
330
  target.addEventListener("mouseleave", onLeave);
273
331
  target.addEventListener("focus", onFocus);
274
332
  target.addEventListener("blur", onBlur);
275
333
  target.addEventListener("click", onClick);
334
+ target.addEventListener("touchstart", onTouchStart, { passive: true });
335
+ target.addEventListener("touchend", onTouchEnd, { passive: true });
336
+ // Placement flip: if the tooltip would overflow the viewport, flip it.
337
+ const flipIfNeeded = () => {
338
+ try {
339
+ const r = this.getBoundingClientRect();
340
+ if (r.right > window.innerWidth) this.classList.add("c-tooltip--flip-x");
341
+ else this.classList.remove("c-tooltip--flip-x");
342
+ if (r.bottom > window.innerHeight) this.classList.add("c-tooltip--flip-y");
343
+ else this.classList.remove("c-tooltip--flip-y");
344
+ } catch (e) {}
345
+ };
346
+ const origShow = show;
347
+ // wrap show to flip after display
276
348
  onDispose(this, () => {
277
349
  target.removeEventListener("mouseenter", onEnter);
278
350
  target.removeEventListener("mouseleave", onLeave);
279
351
  target.removeEventListener("focus", onFocus);
280
352
  target.removeEventListener("blur", onBlur);
281
353
  target.removeEventListener("click", onClick);
354
+ target.removeEventListener("touchstart", onTouchStart);
355
+ target.removeEventListener("touchend", onTouchEnd);
282
356
  if (showTimer) clearTimeout(showTimer);
283
357
  });
284
358
  this.addEventListener("toggle", (e) => {
@@ -293,6 +367,11 @@ class ContourTooltip extends ContourBase {
293
367
  }
294
368
  }
295
369
  define("contour-tooltip", ContourTooltip);
370
+ /**
371
+ * Progress: a determinate or indeterminate progress bar with value, min/max,
372
+ * paused and pausable states. Attributes: `value`, `label`, `min`, `max`,
373
+ * `paused`, `pausable`.
374
+ */
296
375
  class ContourProgress extends ContourBase {
297
376
  static get observed() { return ["value", "label", "min", "max", "paused", "pausable"]; }
298
377
  static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, min: { attribute: "min" }, max: { attribute: "max" }, paused: { attribute: "paused", type: Boolean }, pausable: { attribute: "pausable", type: Boolean } }; }
@@ -353,19 +432,31 @@ class ContourProgress extends ContourBase {
353
432
  }
354
433
  }
355
434
  define("contour-progress", ContourProgress);
435
+ /**
436
+ * Mark: a highlighted text marker. No attributes.
437
+ */
356
438
  class ContourMark extends ContourBase {
357
439
  render() {
358
440
  this.classList.add("c-mark");
359
441
  }
360
442
  }
361
443
  define("contour-mark", ContourMark);
444
+ /**
445
+ * Loading: a spinner wrapped in a container. No attributes.
446
+ */
362
447
  class ContourLoading extends ContourBase {
363
448
  render() {
364
449
  this.classList.add("c-loading");
365
- this.ensure(".c-spinner", () => { const el = document.createElement("span"); el.className = "c-spinner"; return el; });
450
+ if (!this.hasAttribute("role")) this.setAttribute("role", "status");
451
+ if (!this.hasAttribute("aria-live")) this.setAttribute("aria-live", "polite");
452
+ this.ensure(".c-spinner", () => { const el = document.createElement("span"); el.className = "c-spinner"; el.setAttribute("aria-hidden", "true"); return el; });
366
453
  }
367
454
  }
368
455
  define("contour-loading", ContourLoading);
456
+ /**
457
+ * Elevation: a single step of the elevation ramp (`.c-elevation` carries
458
+ * `--shadow-md`). Raises the surface it is given. No attributes.
459
+ */
369
460
  class ContourElevation extends ContourBase {
370
461
  render() {
371
462
  // The block is one step of the ramp, not the ramp: .c-elevation carries
@@ -377,6 +468,10 @@ class ContourElevation extends ContourBase {
377
468
  }
378
469
  }
379
470
  define("contour-elevation", ContourElevation);
471
+ /**
472
+ * VersionBanner: a dismissible info banner with message, link and href.
473
+ * Attributes: `message`, `link`, `href`, `dismissible`.
474
+ */
380
475
  class ContourVersionBannerFull extends ContourBase {
381
476
  static get observed() { return ["message", "link", "href", "dismissible"]; }
382
477
  static get properties() { return { message: { attribute: "message" }, link: { attribute: "link" }, href: { attribute: "href" }, dismissible: { attribute: "dismissible", type: Boolean } }; }
@@ -425,6 +520,10 @@ class ContourVersionBannerFull extends ContourBase {
425
520
  }
426
521
  }
427
522
  define("contour-version-banner", ContourVersionBannerFull);
523
+ /**
524
+ * Banner: a simple message banner with a variant modifier. Attributes:
525
+ * `message`, `variant`.
526
+ */
428
527
  class ContourBanner extends ContourBase {
429
528
  static get observed() { return ["message", "variant"]; }
430
529
  static get properties() { return { message: { attribute: "message" }, variant: { attribute: "variant" } }; }
@@ -440,6 +539,10 @@ class ContourBanner extends ContourBase {
440
539
  }
441
540
  }
442
541
  define("contour-banner", ContourBanner);
542
+ /**
543
+ * FilterPill: a key/value filter chip with an optional remove button.
544
+ * Attributes: `key`, `value`, `removable`.
545
+ */
443
546
  class ContourFilterPill extends ContourBase {
444
547
  static get observed() { return ["key", "value", "removable"]; }
445
548
  static get properties() { return { key: { attribute: "key" }, value: { attribute: "value" }, removable: { attribute: "removable", type: Boolean } }; }
@@ -483,6 +586,10 @@ class ContourFilterPill extends ContourBase {
483
586
  }
484
587
  }
485
588
  define("contour-filter-pill", ContourFilterPill);
589
+ /**
590
+ * Datamark: a data value display with optional unit and label. Attributes:
591
+ * `value`, `unit`, `label`.
592
+ */
486
593
  class ContourDatamark extends ContourBase {
487
594
  static get observed() { return ["value", "unit", "label"]; }
488
595
  static get properties() { return { value: { attribute: "value" }, unit: { attribute: "unit" }, label: { attribute: "label" } }; }
@@ -507,6 +614,9 @@ class ContourDatamark extends ContourBase {
507
614
  }
508
615
  }
509
616
  define("contour-datamark", ContourDatamark);
617
+ /**
618
+ * DestructiveHint: a text hint for destructive actions. Attribute: `text`.
619
+ */
510
620
  class ContourDestructiveHint extends ContourBase {
511
621
  static get observed() { return ["text"]; }
512
622
  static get properties() { return { text: { attribute: "text" } }; }
@@ -517,6 +627,10 @@ class ContourDestructiveHint extends ContourBase {
517
627
  }
518
628
  }
519
629
  define("contour-destructive-hint", ContourDestructiveHint);
630
+ /**
631
+ * IconBadge: an icon from the sprite (i-* convention) with a warning if the
632
+ * name doesn't match. Attribute: `icon`.
633
+ */
520
634
  class ContourIconBadge extends ContourBase {
521
635
  static get observed() { return ["icon"]; }
522
636
  static get properties() { return { icon: { attribute: "icon" } }; }
@@ -550,6 +664,10 @@ class ContourIconBadge extends ContourBase {
550
664
  }
551
665
  }
552
666
  define("contour-icon-badge", ContourIconBadge);
667
+ /**
668
+ * LiveBadge: a connection status badge with state/live modifiers and label.
669
+ * Attributes: `label`, `state`, `live`.
670
+ */
553
671
  class ContourLiveBadge extends ContourBase {
554
672
  static get observed() { return ["label", "state", "live"]; }
555
673
  static get properties() { return { label: { attribute: "label" }, state: { attribute: "state" }, live: { attribute: "live", type: Boolean } }; }
@@ -569,6 +687,9 @@ class ContourLiveBadge extends ContourBase {
569
687
  }
570
688
  define("contour-live-badge", ContourLiveBadge);
571
689
 
690
+ /**
691
+ * SkeletonGroup: a group of N skeleton placeholders. Attribute: `count`.
692
+ */
572
693
  class ContourSkeletonGroup extends ContourBase {
573
694
  static get observed() { return ["count"]; }
574
695
  static get properties() { return { count: { attribute: "count", type: Number } }; }
@@ -585,11 +706,17 @@ class ContourSkeletonGroup extends ContourBase {
585
706
  }
586
707
  define("contour-skeleton-group", ContourSkeletonGroup);
587
708
 
709
+ /**
710
+ * MapPopup: a map popup dialog with title, content, and optional cluster
711
+ * badge (cluster-count / cluster-expanded). Attributes: `title`, `content`,
712
+ * `cluster-count`, `cluster-expanded`.
713
+ */
588
714
  class ContourMapPopup extends ContourBase {
589
- static get observed() { return ["title", "content"]; }
590
- static get properties() { return { title: { attribute: "title" }, content: { attribute: "content" } }; }
715
+ static get observed() { return ["title", "content", "cluster-count", "cluster-expanded", "cluster-items"]; }
716
+ static get properties() { return { title: { attribute: "title" }, content: { attribute: "content" }, "cluster-count": { attribute: "cluster-count", type: Number }, "cluster-expanded": { attribute: "cluster-expanded", type: Boolean }, "cluster-items": { attribute: "cluster-items" } }; }
591
717
  render() {
592
718
  this.classList.add("c-map-popup");
719
+ this.setAttribute("role", "dialog");
593
720
  if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
594
721
  if (!this.id) this.id = contourId("map-popup");
595
722
  const title = this.getAttribute("title");
@@ -602,15 +729,71 @@ class ContourMapPopup extends ContourBase {
602
729
  const c = this.ensure(".c-map-popup__body", () => { const el = document.createElement("div"); el.className = "c-map-popup__body"; return el; });
603
730
  c.textContent = content;
604
731
  }
732
+ const clusterCount = Number(this.getAttribute("cluster-count"));
733
+ if (Number.isFinite(clusterCount) && clusterCount > 1) {
734
+ const badge = this.ensure(".c-map-popup__cluster", () => { const el = document.createElement("button"); el.className = "c-map-popup__cluster c-btn c-btn--sm"; el.type = "button"; return el; });
735
+ const expanded = this.hasAttribute("cluster-expanded");
736
+ badge.textContent = expanded ? "Hide locations" : `${clusterCount} locations`;
737
+ badge.setAttribute("aria-expanded", String(expanded));
738
+ badge.setAttribute("aria-label", expanded ? "Hide locations" : `Show ${clusterCount} locations`);
739
+ } else {
740
+ const badge = this.querySelector(".c-map-popup__cluster");
741
+ if (badge) badge.remove();
742
+ }
743
+ // Spatial clustering (R14-28): render clustered locations when expanded.
744
+ const expanded = this.hasAttribute("cluster-expanded");
745
+ let items = [];
746
+ try { items = this.getAttribute("cluster-items") ? JSON.parse(this.getAttribute("cluster-items")) : []; } catch (e) { items = []; }
747
+ const list = this.querySelector(".c-map-popup__cluster-list");
748
+ if (expanded && Array.isArray(items) && items.length) {
749
+ const ul = list || document.createElement("ul");
750
+ ul.className = "c-map-popup__cluster-list";
751
+ ul.innerHTML = "";
752
+ items.forEach((it) => {
753
+ const li = document.createElement("li");
754
+ li.className = "c-map-popup__cluster-item";
755
+ li.textContent = typeof it === "string" ? it : (it.label || it.name || JSON.stringify(it));
756
+ ul.appendChild(li);
757
+ });
758
+ if (ul.parentNode !== this) this.appendChild(ul);
759
+ } else if (list) {
760
+ list.remove();
761
+ }
762
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", title || "Map popup");
763
+ }
764
+ enhance() {
765
+ if (this._wiredMapPopup) return;
766
+ this._wiredMapPopup = true;
767
+ const close = () => { try { this.hidePopover(); } catch (e) {} this.classList.remove("is-open"); this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); };
768
+ const keyHandler = (e) => { if (e.key === "Escape" && (this.classList.contains("is-open") || this.matches(":popover-open"))) { e.preventDefault(); close(); } };
769
+ document.addEventListener("keydown", keyHandler);
770
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
771
+ this.addEventListener("click", (e) => {
772
+ const btn = e.target && e.target.closest ? e.target.closest(".c-map-popup__close") : null;
773
+ if (btn && this.contains(btn)) close();
774
+ const cluster = e.target && e.target.closest ? e.target.closest(".c-map-popup__cluster") : null;
775
+ if (cluster && this.contains(cluster)) {
776
+ const expanded = !this.hasAttribute("cluster-expanded");
777
+ this.toggleAttribute("cluster-expanded", expanded);
778
+ this.dispatchEvent(new CustomEvent("contour:cluster-toggle", { bubbles: true, composed: true, detail: { count: Number(this.getAttribute("cluster-count")), expanded } }));
779
+ }
780
+ });
605
781
  }
606
782
  }
607
783
  define("contour-map-popup", ContourMapPopup);
608
784
 
785
+ /**
786
+ * AnimationControls: a media control toolbar with play/pause, speed, scrubber
787
+ * and caption. Attributes: `playing`, `speed`, `progress`, `min`, `max`,
788
+ * `caption`, `show-thumb`, `show-thumb-caption`.
789
+ */
609
790
  class ContourAnimationControls extends ContourBase {
610
791
  static get observed() { return ["playing", "speed", "progress", "min", "max", "caption", "show-thumb", "show-thumb-caption"]; }
611
792
  static get properties() { return { playing: { attribute: "playing", type: Boolean }, speed: { attribute: "speed" }, progress: { attribute: "progress" }, min: { attribute: "min" }, max: { attribute: "max" } }; }
612
793
  render() {
613
794
  this.classList.add("c-animation-controls");
795
+ this.setAttribute("role", "toolbar");
796
+ this.setAttribute("aria-label", "Animation controls");
614
797
  const playBtn = this.ensure(".c-animation-controls__play", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-animation-controls__play"; el.type = "button"; return el; });
615
798
  playBtn.textContent = this.hasAttribute("playing") ? "Pause" : "Play";
616
799
  playBtn.setAttribute("aria-label", this.hasAttribute("playing") ? "Pause" : "Play");
@@ -618,7 +801,7 @@ class ContourAnimationControls extends ContourBase {
618
801
  const speedBtn = this.ensure(".c-animation-controls__speed", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-animation-controls__speed"; el.type = "button"; return el; });
619
802
  speedBtn.textContent = speed;
620
803
  // scrubber
621
- const scrubber = this.ensure(".c-animation-controls__scrubber", () => { const el = document.createElement("input"); el.className = "c-animation-controls__scrubber"; el.type = "range"; return el; });
804
+ const scrubber = this.ensure(".c-animation-controls__scrubber", () => { const el = document.createElement("input"); el.className = "c-range c-animation-controls__scrubber"; el.type = "range"; return el; });
622
805
  if (this.getAttribute("show-thumb") === "false") scrubber.classList.remove("c-animation-controls__scrubber--thumb");
623
806
  else scrubber.classList.add("c-animation-controls__scrubber--thumb");
624
807
  scrubber.min = this.getAttribute("min") || "0";
@@ -658,10 +841,52 @@ class ContourAnimationControls extends ContourBase {
658
841
  this.dispatchEvent(new CustomEvent("contour:seek", { bubbles: true, composed: true, detail: { progress: v, value: v } }));
659
842
  }
660
843
  });
844
+ this.addEventListener("keydown", (e) => {
845
+ if (e.key === " " || e.key === "Enter") {
846
+ const play = this.querySelector(".c-animation-controls__play");
847
+ if (play && (e.target === play || !e.target || e.target === this)) { e.preventDefault(); play.click(); }
848
+ } else if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
849
+ const scrubber = this.querySelector(".c-animation-controls__scrubber");
850
+ if (scrubber) {
851
+ e.preventDefault();
852
+ const step = e.key === "ArrowRight" ? 1 : -1;
853
+ scrubber.value = String(Number(scrubber.value) + step);
854
+ scrubber.dispatchEvent(new Event("input", { bubbles: true }));
855
+ }
856
+ }
857
+ });
858
+ // Playback ownership: when `playing` is set, advance the playhead on a
859
+ // timer and emit contour:time-change so a consumer can sync its data.
860
+ let timer = null;
861
+ const speedFactor = () => {
862
+ const s = this.getAttribute("speed") || "1x";
863
+ const n = parseFloat(s);
864
+ return Number.isFinite(n) && n > 0 ? n : 1;
865
+ };
866
+ const tick = () => {
867
+ const scrubber = this.querySelector(".c-animation-controls__scrubber");
868
+ if (!scrubber) return;
869
+ const min = Number(scrubber.min || 0);
870
+ const max = Number(scrubber.max || 100);
871
+ let v = Number(scrubber.value || 0) + speedFactor();
872
+ if (v > max) v = min;
873
+ scrubber.value = String(v);
874
+ this.dispatchEvent(new CustomEvent("contour:time-change", { bubbles: true, composed: true, detail: { progress: v, value: v } }));
875
+ };
876
+ const start = () => { if (timer) return; timer = setInterval(tick, 100); };
877
+ const stop = () => { if (timer) { clearInterval(timer); timer = null; } };
878
+ if (this.hasAttribute("playing")) start();
879
+ const obs = new MutationObserver(() => { if (this.hasAttribute("playing")) start(); else stop(); });
880
+ obs.observe(this, { attributes: true, attributeFilter: ["playing"] });
881
+ onDispose(this, () => { stop(); obs.disconnect(); });
661
882
  }
662
883
  }
663
884
  define("contour-animation-controls", ContourAnimationControls);
664
885
 
886
+ /**
887
+ * Dropdown: a trigger button with a menu of items from JSON `items` or slotted
888
+ * `.c-menu__item` children. Attributes: `label`, `items`.
889
+ */
665
890
  class ContourDropdown extends ContourBase {
666
891
  static get observed() { return ["label", "items"]; }
667
892
  static get properties() { return { label: { attribute: "label" }, items: { attribute: "items" } }; }
@@ -670,8 +895,14 @@ class ContourDropdown extends ContourBase {
670
895
  const btn = this.ensure(".c-dropdown__trigger", () => { const el = document.createElement("button"); el.className = "c-dropdown__trigger c-btn c-btn--sm"; el.type = "button"; return el; });
671
896
  btn.textContent = this.getAttribute("label") || "Menu";
672
897
  const menu = this.ensure(".c-dropdown__menu", () => { const el = document.createElement("div"); el.className = "c-dropdown__menu c-menu"; el.setAttribute("role", "menu"); el.hidden = true; return el; });
898
+ // Slotted content: authored .c-menu__item children take precedence over
899
+ // the JSON `items` attribute.
900
+ const authoredItems = Array.from(this.querySelectorAll(":scope > .c-menu__item"));
673
901
  const items = this.getAttribute("items");
674
- if (items) {
902
+ if (authoredItems.length) {
903
+ menu.innerHTML = "";
904
+ authoredItems.forEach((it) => { menu.appendChild(it); });
905
+ } else if (items) {
675
906
  try {
676
907
  const parsed = JSON.parse(items);
677
908
  menu.innerHTML = "";
@@ -694,26 +925,67 @@ class ContourDropdown extends ContourBase {
694
925
  const menu = () => this.querySelector(".c-dropdown__menu");
695
926
  this.addEventListener("click", (e) => {
696
927
  const b = btn();
928
+ const m = menu();
929
+ // Item selection.
930
+ const item = e.target && e.target.closest ? e.target.closest(".c-menu__item") : null;
931
+ if (item && m && m.contains(item) && !m.hidden) {
932
+ const idx = Array.from(m.querySelectorAll(".c-menu__item")).indexOf(item);
933
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, value: item.textContent } }));
934
+ m.hidden = true;
935
+ if (b) { b.setAttribute("aria-expanded", "false"); try { b.focus(); } catch (err) {} }
936
+ return;
937
+ }
697
938
  if (e.target === b || (b && b.contains(e.target))) {
698
- const m = menu();
699
- if (m) { m.hidden = !m.hidden; b.setAttribute("aria-expanded", String(!m.hidden)); }
939
+ if (m) {
940
+ m.hidden = !m.hidden;
941
+ b.setAttribute("aria-expanded", String(!m.hidden));
942
+ if (!m.hidden) {
943
+ if (!m.id) m.id = (this.id || contourId("dd")) + "-menu";
944
+ b.setAttribute("aria-controls", m.id);
945
+ const first = m.querySelector(".c-menu__item");
946
+ if (first) try { first.focus(); } catch (err) {}
947
+ }
948
+ }
700
949
  }
701
950
  });
702
- document.addEventListener("click", (e) => {
951
+ const docClick = (e) => {
703
952
  const m = menu();
704
953
  const b = btn();
705
954
  if (m && !m.hidden && !this.contains(e.target)) { m.hidden = true; if (b) b.setAttribute("aria-expanded", "false"); }
706
- });
955
+ };
956
+ document.addEventListener("click", docClick);
957
+ onDispose(this, () => document.removeEventListener("click", docClick));
958
+ const keyHandler = (e) => {
959
+ const m = menu(); const b = btn();
960
+ if (e.key === "Escape" && m && !m.hidden) { e.preventDefault(); m.hidden = true; if (b) { b.setAttribute("aria-expanded", "false"); try { b.focus(); } catch (err) {} } return; }
961
+ if (!m || m.hidden) return;
962
+ const items = Array.from(m.querySelectorAll(".c-menu__item"));
963
+ const active = document.activeElement;
964
+ const idx = items.indexOf(active);
965
+ if (e.key === "ArrowDown") { e.preventDefault(); const next = items[Math.min(items.length - 1, idx + 1)] || items[0]; if (next) try { next.focus(); } catch (err) {} }
966
+ else if (e.key === "ArrowUp") { e.preventDefault(); const prev = items[Math.max(0, idx - 1)] || items[items.length - 1]; if (prev) try { prev.focus(); } catch (err) {} }
967
+ else if (e.key === "Enter" || e.key === " ") {
968
+ if (active && items.includes(active)) { e.preventDefault(); active.click(); }
969
+ }
970
+ };
971
+ document.addEventListener("keydown", keyHandler);
972
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
707
973
  }
708
974
  }
709
975
  define("contour-dropdown", ContourDropdown);
710
976
 
977
+ /**
978
+ * Annotation: a positioned note with label and x/y coordinates. Attributes:
979
+ * `label`, `x`, `y`.
980
+ */
711
981
  class ContourAnnotation extends ContourBase {
712
982
  static get observed() { return ["label", "x", "y"]; }
713
983
  static get properties() { return { label: { attribute: "label" }, x: { attribute: "x" }, y: { attribute: "y" } }; }
714
984
  render() {
715
985
  this.classList.add("c-annotation");
986
+ this.setAttribute("role", "note");
716
987
  const label = this.getAttribute("label");
988
+ if (label) this.setAttribute("aria-label", label);
717
989
  if (label) {
718
990
  const l = this.ensure(".c-annotation__label", () => { const el = document.createElement("span"); el.className = "c-annotation__label"; return el; });
719
991
  l.textContent = label;
@@ -726,6 +998,10 @@ class ContourAnnotation extends ContourBase {
726
998
  }
727
999
  define("contour-annotation", ContourAnnotation);
728
1000
 
1001
+ /**
1002
+ * Style Switcher: web component wrapper.
1003
+ * Attributes: `items`, `value`.
1004
+ */
729
1005
  class ContourStyleSwitcher extends ContourBase {
730
1006
  static get observed() { return ["items", "value"]; }
731
1007
  static get properties() { return { items: { attribute: "items" }, value: { attribute: "value" } }; }
@@ -763,11 +1039,17 @@ class ContourStyleSwitcher extends ContourBase {
763
1039
  }
764
1040
  define("contour-style-switcher", ContourStyleSwitcher);
765
1041
 
1042
+ /**
1043
+ * Style Panel: web component wrapper.
1044
+ * Attributes: `title`, `layers`, `layer`, `single`, `classification`, `palette`, `breaks`, `opacity`, `n`, `colors`, `property`.
1045
+ */
766
1046
  class ContourStylePanel extends ContourBase {
767
1047
  static get observed() { return ["title", "layers", "layer", "single", "classification", "palette", "breaks", "opacity", "n", "colors", "property"]; }
768
1048
  static get properties() { return { title: { attribute: "title" }, layers: { attribute: "layers" }, classification: { attribute: "classification" }, palette: { attribute: "palette" }, breaks: { attribute: "breaks" }, opacity: { attribute: "opacity" } }; }
769
1049
  render() {
770
1050
  this.classList.add("c-style-panel");
1051
+ this.setAttribute("role", "group");
1052
+ this.setAttribute("aria-label", "Style panel");
771
1053
  const title = this.getAttribute("title");
772
1054
  if (title) {
773
1055
  const t = this.ensure(".c-style-panel__title", () => { const el = document.createElement("div"); el.className = "c-style-panel__title"; return el; });
@@ -799,7 +1081,7 @@ class ContourStylePanel extends ContourBase {
799
1081
  const nv = this.getAttribute("n"); if (nv) nIn.value = nv; else nIn.value = "5";
800
1082
  body.appendChild(nIn);
801
1083
  // opacity slider
802
- const op = document.createElement("input"); op.type = "range"; op.className = "c-style-panel__opacity"; op.min = "0"; op.max = "100";
1084
+ const op = document.createElement("input"); op.type = "range"; op.className = "c-style-panel__opacity"; op.setAttribute("aria-label", "Opacity"); op.min = "0"; op.max = "100";
803
1085
  const ov = this.getAttribute("opacity"); op.value = ov != null ? ov : "100";
804
1086
  body.appendChild(op);
805
1087
  // breaks as .break elements per class
@@ -807,7 +1089,7 @@ class ContourStylePanel extends ContourBase {
807
1089
  let breaksArr = null;
808
1090
  if (breaksAttr) { try { breaksArr = JSON.parse(breaksAttr); } catch (e) { breaksArr = breaksAttr.split(",").map((s) => s.trim()); } }
809
1091
  if (Array.isArray(breaksArr) && breaksArr.length) {
810
- const breaksWrap = document.createElement("div"); breaksWrap.className = "c-style-panel__breaks breaks";
1092
+ const breaksWrap = document.createElement("div"); breaksWrap.className = "c-style-panel__breaks";
811
1093
  breaksArr.forEach((b, i) => {
812
1094
  const br = document.createElement("div"); br.className = "break";
813
1095
  br.textContent = String(b);
@@ -820,7 +1102,7 @@ class ContourStylePanel extends ContourBase {
820
1102
  let colors = null;
821
1103
  if (colorsAttr) { try { colors = JSON.parse(colorsAttr); } catch (e) { colors = colorsAttr.split(",").map((s) => s.trim()); } }
822
1104
  if (Array.isArray(colors)) {
823
- const list = document.createElement("div"); list.className = "c-style-panel__colors colours";
1105
+ const list = document.createElement("div"); list.className = "c-style-panel__colors";
824
1106
  colors.forEach((c, i) => {
825
1107
  const sw = document.createElement("input"); sw.type = "color"; sw.className = "c-style-panel__color c-input"; sw.setAttribute("aria-label", "Colour for class " + (i + 1));
826
1108
  sw.value = c;
@@ -830,8 +1112,8 @@ class ContourStylePanel extends ContourBase {
830
1112
  body.appendChild(list);
831
1113
  }
832
1114
  // Apply/Revert buttons
833
- const actions = document.createElement("div"); actions.className = "c-style-panel__actions actions";
834
- const applyBtn = document.createElement("button"); applyBtn.type = "button"; applyBtn.className = "c-btn primary"; applyBtn.textContent = "Apply";
1115
+ const actions = document.createElement("div"); actions.className = "c-style-panel__actions";
1116
+ const applyBtn = document.createElement("button"); applyBtn.type = "button"; applyBtn.className = "c-btn c-btn--primary"; applyBtn.textContent = "Apply";
835
1117
  const revertBtn = document.createElement("button"); revertBtn.type = "button"; revertBtn.className = "c-btn"; revertBtn.textContent = "Revert";
836
1118
  actions.appendChild(applyBtn); actions.appendChild(revertBtn);
837
1119
  body.appendChild(actions);
@@ -870,11 +1152,13 @@ class ContourStylePanel extends ContourBase {
870
1152
  const input = document.createElement("input");
871
1153
  input.type = "color";
872
1154
  input.className = "c-style-panel__color";
1155
+ input.setAttribute("aria-label", "Colour for " + (typeof l === "string" ? l : (l.name || l.label || "layer")));
873
1156
  if (typeof l === "object" && l.color) input.value = l.color;
874
1157
  row.appendChild(input);
875
1158
  // classification method selector
876
1159
  const clsSel = document.createElement("select");
877
1160
  clsSel.className = "c-style-panel__classification";
1161
+ clsSel.setAttribute("aria-label", "Classification method");
878
1162
  ["equal","quantile","jenks","manual"].forEach((m) => { const o = document.createElement("option"); o.value = m; o.textContent = m; clsSel.appendChild(o); });
879
1163
  if (typeof l === "object" && l.classification) clsSel.value = l.classification;
880
1164
  row.appendChild(clsSel);
@@ -882,6 +1166,7 @@ class ContourStylePanel extends ContourBase {
882
1166
  const pal = document.createElement("input");
883
1167
  pal.type = "text";
884
1168
  pal.className = "c-style-panel__palette";
1169
+ pal.setAttribute("aria-label", "Palette");
885
1170
  pal.placeholder = "palette";
886
1171
  if (typeof l === "object" && l.palette) pal.value = l.palette;
887
1172
  row.appendChild(pal);
@@ -896,6 +1181,7 @@ class ContourStylePanel extends ContourBase {
896
1181
  const op = document.createElement("input");
897
1182
  op.type = "range";
898
1183
  op.className = "c-style-panel__opacity";
1184
+ op.setAttribute("aria-label", "Opacity");
899
1185
  op.min = "0"; op.max = "100";
900
1186
  op.value = (typeof l === "object" && l.opacity != null) ? l.opacity : "100";
901
1187
  row.appendChild(op);
@@ -917,6 +1203,10 @@ class ContourStylePanel extends ContourBase {
917
1203
  this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value, layer: name }, bubbles: true, composed: true }));
918
1204
  } else if (t.classList.contains("c-style-panel__opacity")) {
919
1205
  this.dispatchEvent(new CustomEvent("contour:layer-opacity", { detail: { name, opacity: Number(t.value) }, bubbles: true, composed: true }));
1206
+ } else if (t.classList.contains("c-style-panel__property")) {
1207
+ this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: t.value, layer: name, property: "property" }, bubbles: true, composed: true }));
1208
+ } else if (t.classList.contains("c-style-panel__n")) {
1209
+ this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: Number(t.value), layer: name, property: "n" }, bubbles: true, composed: true }));
920
1210
  }
921
1211
  });
922
1212
  this.addEventListener("input", (e) => {
@@ -941,6 +1231,10 @@ class ContourStylePanel extends ContourBase {
941
1231
  }
942
1232
  define("contour-style-panel", ContourStylePanel);
943
1233
 
1234
+ /**
1235
+ * Responsive Content: web component wrapper.
1236
+ * Attributes: `breakpoint`.
1237
+ */
944
1238
  class ContourResponsiveContent extends ContourBase {
945
1239
  static get observed() { return ["breakpoint"]; }
946
1240
  static get properties() { return { breakpoint: { attribute: "breakpoint" } }; }
@@ -952,6 +1246,10 @@ class ContourResponsiveContent extends ContourBase {
952
1246
  }
953
1247
  define("contour-responsive-content", ContourResponsiveContent);
954
1248
 
1249
+ /**
1250
+ * Avatar Group: web component wrapper.
1251
+ * Attributes: `items`, `max`.
1252
+ */
955
1253
  class ContourAvatarGroup extends ContourBase {
956
1254
  static get observed() { return ["items", "max"]; }
957
1255
  static get properties() { return { items: { attribute: "items" }, max: { attribute: "max", type: Number } }; }
@@ -984,6 +1282,10 @@ class ContourAvatarGroup extends ContourBase {
984
1282
  }
985
1283
  define("contour-avatar-group", ContourAvatarGroup);
986
1284
 
1285
+ /**
1286
+ * Divider: web component wrapper.
1287
+ * Attributes: `label`, `orientation`.
1288
+ */
987
1289
  class ContourDivider extends ContourBase {
988
1290
  static get observed() { return ["label", "orientation"]; }
989
1291
  static get properties() { return { label: { attribute: "label" }, orientation: { attribute: "orientation" } }; }
@@ -1000,6 +1302,10 @@ class ContourDivider extends ContourBase {
1000
1302
  }
1001
1303
  define("contour-divider", ContourDivider);
1002
1304
 
1305
+ /**
1306
+ * Status Light: web component wrapper.
1307
+ * Attributes: `status`, `label`.
1308
+ */
1003
1309
  class ContourStatusLight extends ContourBase {
1004
1310
  static get observed() { return ["status", "label"]; }
1005
1311
  static get properties() { return { status: { attribute: "status" }, label: { attribute: "label" } }; }
@@ -1016,6 +1322,10 @@ class ContourStatusLight extends ContourBase {
1016
1322
  }
1017
1323
  define("contour-status-light", ContourStatusLight);
1018
1324
 
1325
+ /**
1326
+ * Split Button: web component wrapper.
1327
+ * Attributes: `label`, `menu`.
1328
+ */
1019
1329
  class ContourSplitButton extends ContourBase {
1020
1330
  static get observed() { return ["label", "menu"]; }
1021
1331
  static get properties() { return { label: { attribute: "label" }, menu: { attribute: "menu" } }; }
@@ -1051,19 +1361,42 @@ class ContourSplitButton extends ContourBase {
1051
1361
  this.addEventListener("click", (e) => {
1052
1362
  const t = toggle();
1053
1363
  if (e.target === t || (t && t.contains(e.target))) {
1364
+ const m = menu();
1365
+ if (m) { m.hidden = !m.hidden; t.setAttribute("aria-expanded", String(!m.hidden)); this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { open: !m.hidden } })); }
1366
+ }
1367
+ const item = e.target && e.target.closest ? e.target.closest(".c-menu__item") : null;
1368
+ if (item && this.contains(item)) {
1369
+ const m = menu();
1370
+ if (m) { m.hidden = true; const t = toggle(); if (t) t.setAttribute("aria-expanded", "false"); }
1371
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { label: item.textContent } }));
1372
+ }
1373
+ });
1374
+ this.addEventListener("keydown", (e) => {
1375
+ const t = toggle();
1376
+ if ((e.target === t || (t && t.contains(e.target))) && (e.key === "Enter" || e.key === " ")) {
1377
+ e.preventDefault();
1054
1378
  const m = menu();
1055
1379
  if (m) { m.hidden = !m.hidden; t.setAttribute("aria-expanded", String(!m.hidden)); }
1380
+ } else if (e.key === "Escape") {
1381
+ const m = menu();
1382
+ if (m && !m.hidden) { m.hidden = true; if (t) t.setAttribute("aria-expanded", "false"); }
1056
1383
  }
1057
1384
  });
1058
- document.addEventListener("click", (e) => {
1385
+ const docClick = (e) => {
1059
1386
  const m = menu();
1060
1387
  const t = toggle();
1061
1388
  if (m && !m.hidden && !this.contains(e.target)) { m.hidden = true; if (t) t.setAttribute("aria-expanded", "false"); }
1062
- });
1389
+ };
1390
+ document.addEventListener("click", docClick);
1391
+ onDispose(this, () => document.removeEventListener("click", docClick));
1063
1392
  }
1064
1393
  }
1065
1394
  define("contour-split-button", ContourSplitButton);
1066
1395
 
1396
+ /**
1397
+ * Palette Editor: web component wrapper.
1398
+ * Attributes: `colors`.
1399
+ */
1067
1400
  class ContourPaletteEditor extends ContourBase {
1068
1401
  static get observed() { return ["colors"]; }
1069
1402
  static get properties() { return { colors: { attribute: "colors" } }; }
@@ -1094,24 +1427,47 @@ class ContourPaletteEditor extends ContourBase {
1094
1427
  this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { color: sw.style.background } }));
1095
1428
  }
1096
1429
  });
1430
+ this.addEventListener("keydown", (e) => {
1431
+ const swatches = Array.from(this.querySelectorAll(".c-palette-editor__swatch"));
1432
+ const active = document.activeElement;
1433
+ const idx = swatches.indexOf(active);
1434
+ if (e.key === "ArrowRight") { e.preventDefault(); const next = swatches[Math.min(swatches.length - 1, idx + 1)] || swatches[0]; if (next) try { next.focus(); } catch (err) {} }
1435
+ else if (e.key === "ArrowLeft") { e.preventDefault(); const prev = swatches[Math.max(0, idx - 1)] || swatches[swatches.length - 1]; if (prev) try { prev.focus(); } catch (err) {} }
1436
+ else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); if (active && active.classList.contains("c-palette-editor__swatch")) active.click(); }
1437
+ });
1097
1438
  }
1098
1439
  }
1099
1440
  define("contour-palette-editor", ContourPaletteEditor);
1100
1441
 
1442
+ /**
1443
+ * Date Range: web component wrapper.
1444
+ * Attributes: `start`, `end`, `label`, `time`, `min`, `max`, `locale`.
1445
+ */
1101
1446
  class ContourDateRange extends ContourBase {
1102
- static get observed() { return ["start", "end", "label"]; }
1103
- static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, label: { attribute: "label" } }; }
1447
+ static get observed() { return ["start", "end", "label", "time", "min", "max", "locale"]; }
1448
+ static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, label: { attribute: "label" }, time: { attribute: "time", type: Boolean }, min: { attribute: "min" }, max: { attribute: "max" }, locale: { attribute: "locale" } }; }
1104
1449
  render() {
1105
1450
  this.classList.add("c-date-range");
1451
+ this.setAttribute("role", "group");
1452
+ this.setAttribute("aria-label", "Date range");
1106
1453
  const label = this.getAttribute("label");
1107
1454
  if (label) {
1108
1455
  const l = this.ensure(".c-date-range__label", () => { const el = document.createElement("span"); el.className = "c-date-range__label"; return el; });
1109
1456
  l.textContent = label;
1110
1457
  }
1111
- const start = this.ensure(".c-date-range__start", () => { const el = document.createElement("input"); el.className = "c-input c-date-range__start"; el.type = "date"; return el; });
1458
+ const start = this.ensure(".c-date-range__start", () => { const el = document.createElement("input"); el.className = "c-input c-date-range__start"; return el; });
1459
+ start.type = this.hasAttribute("time") ? "datetime-local" : "date";
1112
1460
  start.value = this.getAttribute("start") || "";
1113
- const end = this.ensure(".c-date-range__end", () => { const el = document.createElement("input"); el.className = "c-input c-date-range__end"; el.type = "date"; return el; });
1461
+ const end = this.ensure(".c-date-range__end", () => { const el = document.createElement("input"); el.className = "c-input c-date-range__end"; return el; });
1462
+ end.type = start.type;
1114
1463
  end.value = this.getAttribute("end") || "";
1464
+ const min = this.getAttribute("min");
1465
+ const max = this.getAttribute("max");
1466
+ [start, end].forEach((input) => {
1467
+ if (min) input.min = min; else input.removeAttribute("min");
1468
+ if (max) input.max = max; else input.removeAttribute("max");
1469
+ if (this.getAttribute("locale")) input.lang = this.getAttribute("locale");
1470
+ });
1115
1471
  }
1116
1472
  enhance() {
1117
1473
  if (this._wiredDateRange) return;
@@ -1126,6 +1482,10 @@ class ContourDateRange extends ContourBase {
1126
1482
  }
1127
1483
  define("contour-date-range", ContourDateRange);
1128
1484
 
1485
+ /**
1486
+ * Shortcut: web component wrapper.
1487
+ * Attributes: `key`, `label`.
1488
+ */
1129
1489
  class ContourShortcut extends ContourBase {
1130
1490
  static get observed() { return ["key", "label"]; }
1131
1491
  static get properties() { return { key: { attribute: "key" }, label: { attribute: "label" } }; }
@@ -1147,22 +1507,30 @@ class ContourShortcut extends ContourBase {
1147
1507
  this._wiredShortcut = true;
1148
1508
  const key = this.getAttribute("key");
1149
1509
  if (key) {
1150
- document.addEventListener("keydown", (e) => {
1510
+ const handler = (e) => {
1151
1511
  if (e.key === key && (e.metaKey || e.ctrlKey)) {
1152
1512
  e.preventDefault();
1153
1513
  this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true }));
1154
1514
  }
1155
- });
1515
+ };
1516
+ document.addEventListener("keydown", handler);
1517
+ onDispose(this, () => document.removeEventListener("keydown", handler));
1156
1518
  }
1157
1519
  }
1158
1520
  }
1159
1521
  define("contour-shortcut", ContourShortcut);
1160
1522
 
1523
+ /**
1524
+ * Popover: web component wrapper.
1525
+ * Attributes: `title`, `content`.
1526
+ */
1161
1527
  class ContourPopover extends ContourBase {
1162
1528
  static get observed() { return ["title", "content"]; }
1163
1529
  static get properties() { return { title: { attribute: "title" }, content: { attribute: "content" } }; }
1164
1530
  render() {
1165
1531
  this.classList.add("c-popover");
1532
+ if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
1533
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Popover");
1166
1534
  if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
1167
1535
  if (!this.id) this.id = contourId("popover");
1168
1536
  const title = this.getAttribute("title");
@@ -1176,21 +1544,141 @@ class ContourPopover extends ContourBase {
1176
1544
  c.textContent = content;
1177
1545
  }
1178
1546
  }
1547
+ enhance() {
1548
+ if (this._wiredPopover) return;
1549
+ this._wiredPopover = true;
1550
+ const close = () => { try { this.hidePopover(); } catch (e) {} this.classList.remove("is-open"); this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); };
1551
+ const keyHandler = (e) => {
1552
+ const open = this.classList.contains("is-open") || this.matches(":popover-open");
1553
+ if (!open) return;
1554
+ if (e.key === "Escape") { e.preventDefault(); close(); return; }
1555
+ // Focus trap: keep Tab within the popover.
1556
+ if (e.key === "Tab") {
1557
+ const focusable = Array.from(this.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));
1558
+ if (!focusable.length) { e.preventDefault(); return; }
1559
+ const first = focusable[0];
1560
+ const last = focusable[focusable.length - 1];
1561
+ if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
1562
+ else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
1563
+ }
1564
+ };
1565
+ document.addEventListener("keydown", keyHandler);
1566
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
1567
+ // Nested popover support: when a nested popover opens, mark this one as parent.
1568
+ this.addEventListener("contour:show", (e) => {
1569
+ if (e.target && e.target !== this && this.contains(e.target)) {
1570
+ this.classList.add("is-parent");
1571
+ }
1572
+ });
1573
+ this.addEventListener("contour:close", (e) => {
1574
+ if (e.target && e.target !== this) {
1575
+ this.classList.remove("is-parent");
1576
+ }
1577
+ });
1578
+ this.addEventListener("click", (e) => {
1579
+ const btn = e.target && e.target.closest ? e.target.closest(".c-popover__close") : null;
1580
+ if (btn && this.contains(btn)) close();
1581
+ });
1582
+ }
1179
1583
  }
1180
1584
  define("contour-popover", ContourPopover);
1181
1585
 
1586
+ /**
1587
+ * Date Picker: web component wrapper.
1588
+ * Attributes: `value`, `range`, `range-start`, `range-end`, `label`, `disabled`, `error`, `help`, `time`, `min`, `max`, `locale`.
1589
+ */
1182
1590
  class ContourDatePicker extends ContourBase {
1183
- static get observed() { return ["value", "label"]; }
1184
- static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" } }; }
1591
+ static get observed() { return ["value", "range", "range-start", "range-end", "label", "disabled", "error", "help", "time", "min", "max", "locale"]; }
1592
+ static get properties() { return { value: { attribute: "value" }, range: { attribute: "range", type: Boolean }, rangeStart: { attribute: "range-start" }, rangeEnd: { attribute: "range-end" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, time: { attribute: "time", type: Boolean }, min: { attribute: "min" }, max: { attribute: "max" }, locale: { attribute: "locale" } }; }
1185
1593
  render() {
1186
1594
  this.classList.add("c-date-picker");
1595
+ this.setAttribute("role", "group");
1596
+ this.setAttribute("aria-label", "Date picker");
1187
1597
  const label = this.getAttribute("label");
1188
1598
  if (label) {
1189
1599
  const l = this.ensure(".c-date-picker__label", () => { const el = document.createElement("label"); el.className = "c-date-picker__label"; return el; });
1190
1600
  l.textContent = label;
1191
1601
  }
1192
- const input = this.ensure(".c-date-picker__input", () => { const el = document.createElement("input"); el.className = "c-input c-date-picker__input"; el.type = "date"; return el; });
1193
- input.value = this.getAttribute("value") || "";
1602
+ const input = this.ensure(".c-date-picker__input", () => { const el = document.createElement("input"); el.className = "c-input c-date-picker__input"; return el; });
1603
+ const range = this.hasAttribute("range");
1604
+ const type = this.hasAttribute("time") ? "datetime-local" : "date";
1605
+ const configure = (control, value, name) => {
1606
+ control.type = type;
1607
+ control.value = value || "";
1608
+ control.setAttribute("aria-label", name);
1609
+ if (this.hasAttribute("min")) control.min = this.getAttribute("min"); else control.removeAttribute("min");
1610
+ if (this.hasAttribute("max")) control.max = this.getAttribute("max"); else control.removeAttribute("max");
1611
+ if (this.hasAttribute("locale")) control.lang = this.getAttribute("locale"); else control.removeAttribute("lang");
1612
+ if (this.hasAttribute("disabled")) control.setAttribute("disabled", ""); else control.removeAttribute("disabled");
1613
+ };
1614
+ configure(input, range ? this.getAttribute("range-start") : this.getAttribute("value"), range ? "Start date" : (label || "Date"));
1615
+ let end = this.querySelector(".c-date-picker__end");
1616
+ if (range) {
1617
+ end = end || document.createElement("input");
1618
+ end.className = "c-input c-date-picker__input c-date-picker__end";
1619
+ configure(end, this.getAttribute("range-end"), "End date");
1620
+ if (end.parentNode !== this) this.appendChild(end);
1621
+ } else if (end) end.remove();
1622
+ if (this.hasAttribute("disabled")) this.classList.add("is-disabled"); else this.classList.remove("is-disabled");
1623
+ const err = this.getAttribute("error");
1624
+ const help = this.getAttribute("help");
1625
+ let msg = this.querySelector(".c-date-picker__message");
1626
+ if (err || help) {
1627
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-date-picker__message"; this.appendChild(msg); }
1628
+ msg.textContent = err || help || "";
1629
+ msg.classList.toggle("c-date-picker__message--error", !!err);
1630
+ } else if (msg) { msg.remove(); }
1631
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
1632
+ // Calendar affordance (R14-22): a toggle + month grid alongside the native input.
1633
+ const toggle = this.ensure(".c-date-picker__calendar-toggle", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-date-picker__calendar-toggle"; el.type = "button"; el.textContent = "📅"; el.setAttribute("aria-label", "Open calendar"); el.setAttribute("aria-expanded", "false"); return el; });
1634
+ let cal = this.querySelector(".c-date-picker__calendar");
1635
+ if (!cal) { cal = document.createElement("div"); cal.className = "c-date-picker__calendar"; cal.setAttribute("hidden", ""); cal.setAttribute("role", "dialog"); cal.setAttribute("aria-label", "Calendar"); this.appendChild(cal); }
1636
+ }
1637
+ _renderCalendar() {
1638
+ const cal = this.querySelector(".c-date-picker__calendar");
1639
+ if (!cal) return;
1640
+ const input = this.querySelector(".c-date-picker__input");
1641
+ const base = (input && input.value) ? new Date(input.value) : new Date();
1642
+ const month = this._calMonth || new Date(base.getFullYear(), base.getMonth(), 1);
1643
+ this._calMonth = month;
1644
+ const y = month.getFullYear();
1645
+ const m = month.getMonth();
1646
+ const first = new Date(y, m, 1);
1647
+ const startDay = first.getDay();
1648
+ const daysInMonth = new Date(y, m + 1, 0).getDate();
1649
+ cal.innerHTML = "";
1650
+ const header = document.createElement("div");
1651
+ header.className = "c-date-picker__calendar-header";
1652
+ const prev = document.createElement("button"); prev.type = "button"; prev.className = "c-btn c-btn--sm"; prev.textContent = "‹"; prev.setAttribute("aria-label", "Previous month");
1653
+ const title = document.createElement("span"); title.className = "c-date-picker__calendar-title"; title.textContent = month.toLocaleString(this.getAttribute("locale") || undefined, { month: "long", year: "numeric" });
1654
+ const next = document.createElement("button"); next.type = "button"; next.className = "c-btn c-btn--sm"; next.textContent = "›"; next.setAttribute("aria-label", "Next month");
1655
+ header.appendChild(prev); header.appendChild(title); header.appendChild(next);
1656
+ cal.appendChild(header);
1657
+ const grid = document.createElement("div");
1658
+ grid.className = "c-date-picker__calendar-grid";
1659
+ grid.setAttribute("role", "grid");
1660
+ const weekdays = ["Su","Mo","Tu","We","Th","Fr","Sa"];
1661
+ weekdays.forEach((w) => { const h = document.createElement("div"); h.className = "c-date-picker__calendar-weekday"; h.textContent = w; grid.appendChild(h); });
1662
+ for (let i = 0; i < startDay; i++) { const empty = document.createElement("div"); empty.className = "c-date-picker__calendar-day c-date-picker__calendar-day--empty"; grid.appendChild(empty); }
1663
+ const selected = input ? input.value : "";
1664
+ for (let d = 1; d <= daysInMonth; d++) {
1665
+ const btn = document.createElement("button");
1666
+ btn.type = "button";
1667
+ btn.className = "c-date-picker__calendar-day";
1668
+ btn.textContent = String(d);
1669
+ const iso = `${y}-${String(m + 1).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
1670
+ if (selected && selected.startsWith(iso)) btn.classList.add("is-selected");
1671
+ btn.addEventListener("click", () => {
1672
+ if (input) { input.value = iso; input.dispatchEvent(new Event("change", { bubbles: true })); }
1673
+ cal.setAttribute("hidden", "");
1674
+ const tgl = this.querySelector(".c-date-picker__calendar-toggle");
1675
+ if (tgl) tgl.setAttribute("aria-expanded", "false");
1676
+ });
1677
+ grid.appendChild(btn);
1678
+ }
1679
+ cal.appendChild(grid);
1680
+ prev.addEventListener("click", () => { this._calMonth = new Date(y, m - 1, 1); this._renderCalendar(); });
1681
+ next.addEventListener("click", () => { this._calMonth = new Date(y, m + 1, 1); this._renderCalendar(); });
1194
1682
  }
1195
1683
  enhance() {
1196
1684
  if (this._wiredDatePicker) return;
@@ -1198,26 +1686,49 @@ class ContourDatePicker extends ContourBase {
1198
1686
  this.addEventListener("change", (e) => {
1199
1687
  const t = e.target;
1200
1688
  if (t && t.classList.contains("c-date-picker__input")) {
1201
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: t.value } }));
1689
+ const end = this.querySelector(".c-date-picker__end");
1690
+ const detail = end ? { start: this.querySelector(".c-date-picker__input").value, end: end.value } : { value: t.value };
1691
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail }));
1202
1692
  }
1203
1693
  });
1694
+ const toggle = () => {
1695
+ const cal = this.querySelector(".c-date-picker__calendar");
1696
+ const btn = this.querySelector(".c-date-picker__calendar-toggle");
1697
+ if (!cal) return;
1698
+ const hidden = cal.hasAttribute("hidden");
1699
+ if (hidden) { cal.removeAttribute("hidden"); if (btn) btn.setAttribute("aria-expanded", "true"); this._renderCalendar(); }
1700
+ else { cal.setAttribute("hidden", ""); if (btn) btn.setAttribute("aria-expanded", "false"); }
1701
+ };
1702
+ this.addEventListener("click", (e) => {
1703
+ const btn = e.target && e.target.closest ? e.target.closest(".c-date-picker__calendar-toggle") : null;
1704
+ if (btn && this.contains(btn)) { e.preventDefault(); toggle(); }
1705
+ });
1204
1706
  }
1205
1707
  }
1206
1708
  define("contour-date-picker", ContourDatePicker);
1207
1709
 
1710
+ /**
1711
+ * Rating: web component wrapper.
1712
+ * Attributes: `value`, `max`, `color`.
1713
+ */
1208
1714
  class ContourRating extends ContourBase {
1209
- static get observed() { return ["value", "max"]; }
1210
- static get properties() { return { value: { attribute: "value", type: Number }, max: { attribute: "max", type: Number } }; }
1715
+ static get observed() { return ["value", "max", "color"]; }
1716
+ static get properties() { return { value: { attribute: "value", type: Number }, max: { attribute: "max", type: Number }, color: { attribute: "color" } }; }
1211
1717
  render() {
1212
1718
  this.classList.add("c-rating");
1719
+ this.setAttribute("role", "radiogroup");
1720
+ this.setAttribute("aria-label", "Rating");
1213
1721
  const max = parseInt(this.getAttribute("max") || "5", 10) || 5;
1214
1722
  const value = parseInt(this.getAttribute("value") || "0", 10) || 0;
1723
+ const color = this.getAttribute("color");
1215
1724
  Array.from(this.querySelectorAll(".c-rating__star")).forEach((n) => n.remove());
1216
1725
  for (let i = 1; i <= max; i++) {
1217
1726
  const star = document.createElement("button");
1218
1727
  star.className = "c-rating__star" + (i <= value ? " c-rating__star--filled" : "");
1219
1728
  star.type = "button";
1220
- star.textContent = "★";
1729
+ star.setAttribute("role", "radio");
1730
+ star.setAttribute("aria-checked", String(i === value));
1731
+ star.innerHTML = '<span class="c-rating__swatch' + (i <= value ? ' c-rating__swatch--filled' : '') + '" aria-hidden="true"' + (color && i <= value ? ' style="background:' + color + ';border-color:' + color + '"' : '') + '></span>';
1221
1732
  star.dataset.value = String(i);
1222
1733
  star.setAttribute("aria-label", i + " star" + (i > 1 ? "s" : ""));
1223
1734
  this.appendChild(star);
@@ -1229,18 +1740,45 @@ class ContourRating extends ContourBase {
1229
1740
  this.addEventListener("click", (e) => {
1230
1741
  const star = e.target && e.target.closest ? e.target.closest(".c-rating__star") : null;
1231
1742
  if (star && this.contains(star)) {
1232
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: parseInt(star.dataset.value, 10) } }));
1743
+ const v = parseInt(star.dataset.value, 10);
1744
+ Array.from(this.querySelectorAll(".c-rating__star")).forEach((st) => st.setAttribute("aria-checked", String(parseInt(st.dataset.value, 10) === v)));
1745
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: v } }));
1746
+ }
1747
+ });
1748
+ this.addEventListener("keydown", (e) => {
1749
+ const stars = Array.from(this.querySelectorAll(".c-rating__star"));
1750
+ const active = document.activeElement;
1751
+ const idx = stars.indexOf(active);
1752
+ if (e.key === "ArrowRight" || e.key === "ArrowUp") {
1753
+ e.preventDefault();
1754
+ const next = stars[Math.min(stars.length - 1, idx + 1)] || stars[0];
1755
+ if (next) { try { next.focus(); } catch (err) {} }
1756
+ } else if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
1757
+ e.preventDefault();
1758
+ const prev = stars[Math.max(0, idx - 1)] || stars[stars.length - 1];
1759
+ if (prev) { try { prev.focus(); } catch (err) {} }
1760
+ } else if (e.key === "Enter" || e.key === " ") {
1761
+ e.preventDefault();
1762
+ if (active && active.classList.contains("c-rating__star")) {
1763
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: parseInt(active.dataset.value, 10) } }));
1764
+ }
1233
1765
  }
1234
1766
  });
1235
1767
  }
1236
1768
  }
1237
1769
  define("contour-rating", ContourRating);
1238
1770
 
1771
+ /**
1772
+ * Time Picker: web component wrapper.
1773
+ * Attributes: `value`, `label`, `disabled`, `error`, `help`.
1774
+ */
1239
1775
  class ContourTimePicker extends ContourBase {
1240
- static get observed() { return ["value", "label"]; }
1241
- static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" } }; }
1776
+ static get observed() { return ["value", "label", "disabled", "error", "help"]; }
1777
+ static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
1242
1778
  render() {
1243
1779
  this.classList.add("c-time-picker");
1780
+ this.setAttribute("role", "group");
1781
+ this.setAttribute("aria-label", "Time picker");
1244
1782
  const label = this.getAttribute("label");
1245
1783
  if (label) {
1246
1784
  const l = this.ensure(".c-time-picker__label", () => { const el = document.createElement("label"); el.className = "c-time-picker__label"; return el; });
@@ -1248,6 +1786,21 @@ class ContourTimePicker extends ContourBase {
1248
1786
  }
1249
1787
  const input = this.ensure(".c-time-picker__input", () => { const el = document.createElement("input"); el.className = "c-input c-time-picker__input"; el.type = "time"; return el; });
1250
1788
  input.value = this.getAttribute("value") || "";
1789
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
1790
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
1791
+ const err = this.getAttribute("error");
1792
+ const help = this.getAttribute("help");
1793
+ let msg = this.querySelector(".c-time-picker__message");
1794
+ if (err || help) {
1795
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-time-picker__message"; this.appendChild(msg); }
1796
+ msg.textContent = err || help || "";
1797
+ msg.classList.toggle("c-time-picker__message--error", !!err);
1798
+ } else if (msg) { msg.remove(); }
1799
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
1800
+ // Calendar affordance (R14-22): a toggle + month grid alongside the native input.
1801
+ const toggle = this.ensure(".c-date-picker__calendar-toggle", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-date-picker__calendar-toggle"; el.type = "button"; el.textContent = "📅"; el.setAttribute("aria-label", "Open calendar"); el.setAttribute("aria-expanded", "false"); return el; });
1802
+ let cal = this.querySelector(".c-date-picker__calendar");
1803
+ if (!cal) { cal = document.createElement("div"); cal.className = "c-date-picker__calendar"; cal.setAttribute("hidden", ""); cal.setAttribute("role", "dialog"); cal.setAttribute("aria-label", "Calendar"); this.appendChild(cal); }
1251
1804
  }
1252
1805
  enhance() {
1253
1806
  if (this._wiredTimePicker) return;
@@ -1262,18 +1815,79 @@ class ContourTimePicker extends ContourBase {
1262
1815
  }
1263
1816
  define("contour-time-picker", ContourTimePicker);
1264
1817
 
1818
+ /**
1819
+ * Color Picker: web component wrapper.
1820
+ * Attributes: `value`, `label`, `disabled`, `error`, `help`, `alpha`, `presets`.
1821
+ */
1265
1822
  class ContourColorPicker extends ContourBase {
1266
- static get observed() { return ["value", "label"]; }
1267
- static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" } }; }
1823
+ static get observed() { return ["value", "label", "disabled", "error", "help", "alpha", "presets"]; }
1824
+ static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, alpha: { attribute: "alpha", type: Boolean }, presets: { attribute: "presets" } }; }
1268
1825
  render() {
1269
1826
  this.classList.add("c-color-picker");
1827
+ this.setAttribute("role", "group");
1828
+ this.setAttribute("aria-label", "Color picker");
1270
1829
  const label = this.getAttribute("label");
1271
1830
  if (label) {
1272
1831
  const l = this.ensure(".c-color-picker__label", () => { const el = document.createElement("label"); el.className = "c-color-picker__label"; return el; });
1273
1832
  l.textContent = label;
1274
1833
  }
1275
1834
  const input = this.ensure(".c-color-picker__input", () => { const el = document.createElement("input"); el.className = "c-color-picker__input"; el.type = "color"; return el; });
1276
- input.value = this.getAttribute("value") || "#000000";
1835
+ input.value = (this.getAttribute("value") || "#000000").slice(0, 7);
1836
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
1837
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
1838
+ // Alpha channel (optional).
1839
+ if (this.hasAttribute("alpha")) {
1840
+ const alpha = this.ensure(".c-color-picker__alpha", () => { const el = document.createElement("input"); el.className = "c-color-picker__alpha"; el.type = "range"; el.min = "0"; el.max = "1"; el.step = "0.01"; return el; });
1841
+ const v = this.getAttribute("value") || "#000000";
1842
+ const a = v.length === 9 ? parseInt(v.slice(7, 9), 16) / 255 : 1;
1843
+ alpha.value = String(a);
1844
+ alpha.setAttribute("aria-label", "Alpha");
1845
+ } else {
1846
+ const a = this.querySelector(".c-color-picker__alpha");
1847
+ if (a) a.remove();
1848
+ }
1849
+ // Presets.
1850
+ const presetsAttr = this.getAttribute("presets");
1851
+ let presets = [];
1852
+ if (presetsAttr) { try { presets = JSON.parse(presetsAttr); } catch (e) { presets = []; } }
1853
+ const oldPresets = this.querySelector(".c-color-picker__presets");
1854
+ if (oldPresets) oldPresets.remove();
1855
+ if (Array.isArray(presets) && presets.length) {
1856
+ const wrap = document.createElement("div");
1857
+ wrap.className = "c-color-picker__presets";
1858
+ presets.forEach((c) => {
1859
+ const btn = document.createElement("button");
1860
+ btn.type = "button";
1861
+ btn.className = "c-color-picker__preset";
1862
+ btn.style.background = c;
1863
+ btn.setAttribute("aria-label", "Preset " + c);
1864
+ btn.dataset.color = c;
1865
+ wrap.appendChild(btn);
1866
+ });
1867
+ this.appendChild(wrap);
1868
+ }
1869
+ // Eyedropper (if supported).
1870
+ if (typeof window !== "undefined" && "EyeDropper" in window) {
1871
+ const ed = this.ensure(".c-color-picker__eyedropper", () => { const el = document.createElement("button"); el.className = "c-color-picker__eyedropper"; el.type = "button"; el.textContent = "Pick"; el.setAttribute("aria-label", "Pick color from screen"); return el; });
1872
+ if (this.hasAttribute("disabled")) ed.setAttribute("disabled", "");
1873
+ else ed.removeAttribute("disabled");
1874
+ } else {
1875
+ const ed = this.querySelector(".c-color-picker__eyedropper");
1876
+ if (ed) ed.remove();
1877
+ }
1878
+ const err = this.getAttribute("error");
1879
+ const help = this.getAttribute("help");
1880
+ let msg = this.querySelector(".c-color-picker__message");
1881
+ if (err || help) {
1882
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-color-picker__message"; this.appendChild(msg); }
1883
+ msg.textContent = err || help || "";
1884
+ msg.classList.toggle("c-color-picker__message--error", !!err);
1885
+ } else if (msg) { msg.remove(); }
1886
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
1887
+ // Calendar affordance (R14-22): a toggle + month grid alongside the native input.
1888
+ const toggle = this.ensure(".c-date-picker__calendar-toggle", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-date-picker__calendar-toggle"; el.type = "button"; el.textContent = "📅"; el.setAttribute("aria-label", "Open calendar"); el.setAttribute("aria-expanded", "false"); return el; });
1889
+ let cal = this.querySelector(".c-date-picker__calendar");
1890
+ if (!cal) { cal = document.createElement("div"); cal.className = "c-date-picker__calendar"; cal.setAttribute("hidden", ""); cal.setAttribute("role", "dialog"); cal.setAttribute("aria-label", "Calendar"); this.appendChild(cal); }
1277
1891
  }
1278
1892
  enhance() {
1279
1893
  if (this._wiredColorPicker) return;
@@ -1283,14 +1897,50 @@ class ContourColorPicker extends ContourBase {
1283
1897
  if (t && t.classList.contains("c-color-picker__input")) {
1284
1898
  this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: t.value } }));
1285
1899
  }
1900
+ if (t && t.classList.contains("c-color-picker__alpha")) {
1901
+ const base = (this.getAttribute("value") || "#000000").slice(0, 7);
1902
+ const a = Math.round(parseFloat(t.value) * 255).toString(16).padStart(2, "0");
1903
+ const val = base + a;
1904
+ this.setAttribute("value", val);
1905
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: val } }));
1906
+ }
1907
+ });
1908
+ this.addEventListener("click", (e) => {
1909
+ const btn = e.target && e.target.closest ? e.target.closest(".c-color-picker__preset") : null;
1910
+ if (btn && this.contains(btn)) {
1911
+ const c = btn.dataset.color;
1912
+ if (c) {
1913
+ this.setAttribute("value", c);
1914
+ const input = this.querySelector(".c-color-picker__input");
1915
+ if (input) input.value = c.slice(0, 7);
1916
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: c } }));
1917
+ }
1918
+ }
1919
+ const ed = e.target && e.target.closest ? e.target.closest(".c-color-picker__eyedropper") : null;
1920
+ if (ed && this.contains(ed) && typeof window !== "undefined" && "EyeDropper" in window) {
1921
+ e.preventDefault();
1922
+ const dropper = new window.EyeDropper();
1923
+ dropper.open().then((r) => {
1924
+ if (r && r.sRGBHex) {
1925
+ this.setAttribute("value", r.sRGBHex);
1926
+ const input = this.querySelector(".c-color-picker__input");
1927
+ if (input) input.value = r.sRGBHex;
1928
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: r.sRGBHex } }));
1929
+ }
1930
+ }).catch(() => {});
1931
+ }
1286
1932
  });
1287
1933
  }
1288
1934
  }
1289
1935
  define("contour-color-picker", ContourColorPicker);
1290
1936
 
1937
+ /**
1938
+ * Number Field: web component wrapper.
1939
+ * Attributes: `value`, `min`, `max`, `step`, `label`, `disabled`, `error`, `help`.
1940
+ */
1291
1941
  class ContourNumberField extends ContourBase {
1292
- static get observed() { return ["value", "min", "max", "step", "label"]; }
1293
- static get properties() { return { value: { attribute: "value" }, min: { attribute: "min" }, max: { attribute: "max" }, step: { attribute: "step" }, label: { attribute: "label" } }; }
1942
+ static get observed() { return ["value", "min", "max", "step", "label", "disabled", "error", "help"]; }
1943
+ static get properties() { return { value: { attribute: "value" }, min: { attribute: "min" }, max: { attribute: "max" }, step: { attribute: "step" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
1294
1944
  render() {
1295
1945
  this.classList.add("c-number-field");
1296
1946
  const label = this.getAttribute("label");
@@ -1298,11 +1948,30 @@ class ContourNumberField extends ContourBase {
1298
1948
  const l = this.ensure(".c-number-field__label", () => { const el = document.createElement("label"); el.className = "c-number-field__label"; return el; });
1299
1949
  l.textContent = label;
1300
1950
  }
1301
- const input = this.ensure(".c-number-field__input", () => { const el = document.createElement("input"); el.className = "c-input c-number-field__input"; el.type = "number"; return el; });
1951
+ const input = this.ensure(".c-number-field__input", () => { const el = document.createElement("input"); el.className = "c-input c-number-field__input"; el.type = "number"; el.setAttribute("role", "spinbutton"); return el; });
1302
1952
  if (this.getAttribute("value") !== null) input.value = this.getAttribute("value");
1303
1953
  if (this.getAttribute("min") !== null) input.min = this.getAttribute("min");
1304
1954
  if (this.getAttribute("max") !== null) input.max = this.getAttribute("max");
1305
1955
  if (this.getAttribute("step") !== null) input.step = this.getAttribute("step");
1956
+ const v = input.value;
1957
+ input.setAttribute("aria-valuenow", v === "" ? "" : v);
1958
+ if (input.min !== "") input.setAttribute("aria-valuemin", input.min);
1959
+ if (input.max !== "") input.setAttribute("aria-valuemax", input.max);
1960
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
1961
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
1962
+ const err = this.getAttribute("error");
1963
+ const help = this.getAttribute("help");
1964
+ let msg = this.querySelector(".c-number-field__message");
1965
+ if (err || help) {
1966
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-number-field__message"; this.appendChild(msg); }
1967
+ msg.textContent = err || help || "";
1968
+ msg.classList.toggle("c-number-field__message--error", !!err);
1969
+ } else if (msg) { msg.remove(); }
1970
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
1971
+ // Calendar affordance (R14-22): a toggle + month grid alongside the native input.
1972
+ const toggle = this.ensure(".c-date-picker__calendar-toggle", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-date-picker__calendar-toggle"; el.type = "button"; el.textContent = "📅"; el.setAttribute("aria-label", "Open calendar"); el.setAttribute("aria-expanded", "false"); return el; });
1973
+ let cal = this.querySelector(".c-date-picker__calendar");
1974
+ if (!cal) { cal = document.createElement("div"); cal.className = "c-date-picker__calendar"; cal.setAttribute("hidden", ""); cal.setAttribute("role", "dialog"); cal.setAttribute("aria-label", "Calendar"); this.appendChild(cal); }
1306
1975
  }
1307
1976
  enhance() {
1308
1977
  if (this._wiredNumberField) return;
@@ -1313,15 +1982,40 @@ class ContourNumberField extends ContourBase {
1313
1982
  this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: t.value } }));
1314
1983
  }
1315
1984
  });
1985
+ this.addEventListener("keydown", (e) => {
1986
+ const input = this.querySelector(".c-number-field__input");
1987
+ if (!input || document.activeElement !== input) return;
1988
+ const step = Number(input.step) || 1;
1989
+ const min = input.min === "" ? -Infinity : Number(input.min);
1990
+ const max = input.max === "" ? Infinity : Number(input.max);
1991
+ let next = null;
1992
+ if (e.key === "ArrowUp") next = (Number(input.value) || 0) + step;
1993
+ else if (e.key === "ArrowDown") next = (Number(input.value) || 0) - step;
1994
+ else if (e.key === "Home") next = min === -Infinity ? 0 : min;
1995
+ else if (e.key === "End") next = max === Infinity ? (Number(input.value) || 0) : max;
1996
+ if (next !== null) {
1997
+ e.preventDefault();
1998
+ next = Math.min(max, Math.max(min, next));
1999
+ input.value = String(next);
2000
+ input.setAttribute("aria-valuenow", String(next));
2001
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: input.value } }));
2002
+ }
2003
+ });
1316
2004
  }
1317
2005
  }
1318
2006
  define("contour-number-field", ContourNumberField);
1319
2007
 
2008
+ /**
2009
+ * Hover Card: web component wrapper.
2010
+ * Attributes: `title`, `content`, `anchor`.
2011
+ */
1320
2012
  class ContourHoverCard extends ContourBase {
1321
2013
  static get observed() { return ["title", "content", "anchor"]; }
1322
2014
  static get properties() { return { title: { attribute: "title" }, content: { attribute: "content" }, anchor: { attribute: "anchor" } }; }
1323
2015
  render() {
1324
2016
  this.classList.add("c-hover-card");
2017
+ if (!this.hasAttribute("role")) this.setAttribute("role", "tooltip");
2018
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Hover card");
1325
2019
  if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
1326
2020
  if (!this.id) this.id = contourId("hover-card");
1327
2021
  const title = this.getAttribute("title");
@@ -1344,19 +2038,33 @@ class ContourHoverCard extends ContourBase {
1344
2038
  if (trigger) {
1345
2039
  trigger.setAttribute("popovertarget", this.id);
1346
2040
  let showTimer = null;
1347
- trigger.addEventListener("mouseenter", () => { showTimer = setTimeout(() => { try { this.showPopover(); } catch (e) {} }, 300); });
1348
- trigger.addEventListener("mouseleave", () => { if (showTimer) clearTimeout(showTimer); try { this.hidePopover(); } catch (e) {} });
2041
+ const hasPopover = typeof this.showPopover === "function";
2042
+ const show = () => { if (hasPopover) { try { this.showPopover(); } catch (e) {} } else this.classList.add("is-open"); this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true })); };
2043
+ const hide = () => { if (showTimer) clearTimeout(showTimer); if (hasPopover) { try { this.hidePopover(); } catch (e) {} } else this.classList.remove("is-open"); this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); };
2044
+ trigger.addEventListener("mouseenter", () => { showTimer = setTimeout(show, 300); });
2045
+ trigger.addEventListener("mouseleave", () => { hide(); });
2046
+ trigger.addEventListener("focus", show);
2047
+ trigger.addEventListener("blur", () => { setTimeout(hide, 100); });
2048
+ onDispose(this, () => { if (showTimer) { clearTimeout(showTimer); showTimer = null; } });
1349
2049
  }
1350
2050
  }
2051
+ const keyHandler = (e) => { if (e.key === "Escape" && (this.classList.contains("is-open") || this.matches(":popover-open"))) { e.preventDefault(); if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (err) {} } this.classList.remove("is-open"); this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); } };
2052
+ document.addEventListener("keydown", keyHandler);
2053
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
1351
2054
  }
1352
2055
  }
1353
2056
  define("contour-hover-card", ContourHoverCard);
1354
2057
 
2058
+ /**
2059
+ * Context Menu: web component wrapper.
2060
+ * Attributes: `items`.
2061
+ */
1355
2062
  class ContourContextMenu extends ContourBase {
1356
2063
  static get observed() { return ["items"]; }
1357
2064
  static get properties() { return { items: { attribute: "items" } }; }
1358
2065
  render() {
1359
2066
  this.classList.add("c-context-menu");
2067
+ if (!this.hasAttribute("role")) this.setAttribute("role", "menu");
1360
2068
  if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
1361
2069
  if (!this.id) this.id = contourId("context-menu");
1362
2070
  const items = this.getAttribute("items");
@@ -1379,24 +2087,41 @@ class ContourContextMenu extends ContourBase {
1379
2087
  this._wiredContextMenu = true;
1380
2088
  this.addEventListener("contextmenu", (e) => {
1381
2089
  e.preventDefault();
1382
- try { this.showPopover(); } catch (err) {}
2090
+ if (typeof this.showPopover === "function") { try { this.showPopover(); } catch (err) {} }
2091
+ else this.classList.toggle("is-open");
1383
2092
  });
1384
2093
  this.addEventListener("click", (e) => {
1385
2094
  const item = e.target && e.target.closest ? e.target.closest(".c-menu__item") : null;
1386
2095
  if (item && this.contains(item)) {
1387
2096
  this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { label: item.textContent.trim() } }));
1388
- try { this.hidePopover(); } catch (err) {}
2097
+ if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (err) {} }
2098
+ this.classList.remove("is-open");
1389
2099
  }
1390
2100
  });
2101
+ this.addEventListener("keydown", (e) => {
2102
+ const items = Array.from(this.querySelectorAll(".c-menu__item"));
2103
+ const active = document.activeElement;
2104
+ const idx = items.indexOf(active);
2105
+ if (e.key === "ArrowDown") { e.preventDefault(); const next = items[Math.min(items.length - 1, idx + 1)] || items[0]; if (next) try { next.focus(); } catch (err) {} }
2106
+ else if (e.key === "ArrowUp") { e.preventDefault(); const prev = items[Math.max(0, idx - 1)] || items[items.length - 1]; if (prev) try { prev.focus(); } catch (err) {} }
2107
+ else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); if (active && active.classList.contains("c-menu__item")) active.click(); }
2108
+ else if (e.key === "Escape") { e.preventDefault(); if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (err) {} } this.classList.remove("is-open"); }
2109
+ });
1391
2110
  }
1392
2111
  }
1393
2112
  define("contour-context-menu", ContourContextMenu);
1394
2113
 
2114
+ /**
2115
+ * Fab: web component wrapper.
2116
+ * Attributes: `label`, `icon`.
2117
+ */
1395
2118
  class ContourFab extends ContourBase {
1396
2119
  static get observed() { return ["label", "icon"]; }
1397
2120
  static get properties() { return { label: { attribute: "label" }, icon: { attribute: "icon" } }; }
1398
2121
  render() {
1399
2122
  this.classList.add("c-fab");
2123
+ if (!this.hasAttribute("role")) this.setAttribute("role", "button");
2124
+ if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
1400
2125
  const label = this.getAttribute("label");
1401
2126
  if (label) this.setAttribute("aria-label", label);
1402
2127
  const icon = this.getAttribute("icon");
@@ -1408,10 +2133,17 @@ class ContourFab extends ContourBase {
1408
2133
  this.addEventListener("click", () => {
1409
2134
  this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true }));
1410
2135
  });
2136
+ this.addEventListener("keydown", (e) => {
2137
+ if (e.key === "Enter" || e.key === " ") { e.preventDefault(); this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true })); }
2138
+ });
1411
2139
  }
1412
2140
  }
1413
2141
  define("contour-fab", ContourFab);
1414
2142
 
2143
+ /**
2144
+ * File Upload: web component wrapper.
2145
+ * Attributes: `label`, `accept`, `multiple`, `progress`.
2146
+ */
1415
2147
  class ContourFileUpload extends ContourBase {
1416
2148
  static get observed() { return ["label", "accept", "multiple", "progress"]; }
1417
2149
  static get properties() { return { label: { attribute: "label" }, accept: { attribute: "accept" }, multiple: { attribute: "multiple", type: Boolean }, progress: { attribute: "progress" } }; }
@@ -1428,43 +2160,88 @@ class ContourFileUpload extends ContourBase {
1428
2160
  const bar = this.ensure(".c-file-upload__progress", () => { const el = document.createElement("progress"); el.className = "c-file-upload__progress"; return el; });
1429
2161
  bar.value = Number(p) || 0;
1430
2162
  bar.max = 100;
2163
+ } else {
2164
+ const bar = this.querySelector(".c-file-upload__progress");
2165
+ if (bar) bar.remove();
1431
2166
  }
2167
+ const preview = this.ensure(".c-file-upload__preview", () => { const el = document.createElement("div"); el.className = "c-file-upload__preview"; return el; });
2168
+ if (!preview) {}
1432
2169
  }
1433
2170
  enhance() {
1434
2171
  if (this._wiredFileUpload) return;
1435
2172
  this._wiredFileUpload = true;
1436
2173
  const dz = () => this.querySelector(".c-file-upload__dropzone");
1437
2174
  const input = () => this.querySelector(".c-file-upload__input");
1438
- this.addEventListener("click", (e) => { const d = dz(); if (e.target === d || (d && d.contains(e.target))) { const i = input(); if (i) i.click(); } });
1439
- this.addEventListener("change", (e) => { const t = e.target; if (t && t.classList.contains("c-file-upload__input")) { this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { files: t.files } })); } });
2175
+ const activate = () => { const i = input(); if (i) i.click(); };
2176
+ this.addEventListener("click", (e) => { const d = dz(); if (e.target === d || (d && d.contains(e.target))) { activate(); } });
2177
+ this.addEventListener("keydown", (e) => { const d = dz(); if ((e.target === d || (d && d.contains(e.target))) && (e.key === "Enter" || e.key === " ")) { e.preventDefault(); activate(); } });
2178
+ const renderPreview = (files) => {
2179
+ const preview = this.querySelector(".c-file-upload__preview");
2180
+ if (!preview) return;
2181
+ preview.innerHTML = "";
2182
+ Array.from(files || []).forEach((f) => {
2183
+ const item = document.createElement("div");
2184
+ item.className = "c-file-upload__preview-item";
2185
+ if (f.type && f.type.startsWith("image/")) {
2186
+ const img = document.createElement("img");
2187
+ img.className = "c-file-upload__preview-thumb";
2188
+ img.alt = f.name;
2189
+ try { img.src = URL.createObjectURL(f); } catch (e) {}
2190
+ item.appendChild(img);
2191
+ } else {
2192
+ const name = document.createElement("span");
2193
+ name.className = "c-file-upload__preview-name";
2194
+ name.textContent = f.name;
2195
+ item.appendChild(name);
2196
+ }
2197
+ preview.appendChild(item);
2198
+ });
2199
+ };
2200
+ this.addEventListener("change", (e) => { const t = e.target; if (t && t.classList.contains("c-file-upload__input")) { renderPreview(t.files); this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { files: t.files } })); } });
2201
+ // drag-drop already dispatches contour:change; also render preview there
1440
2202
  this.addEventListener("dragover", (e) => { e.preventDefault(); this.classList.add("is-dragover"); });
1441
2203
  this.addEventListener("dragleave", () => this.classList.remove("is-dragover"));
1442
- this.addEventListener("drop", (e) => { e.preventDefault(); this.classList.remove("is-dragover"); const i = input(); if (i && e.dataTransfer && e.dataTransfer.files) { i.files = e.dataTransfer.files; this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { files: e.dataTransfer.files } })); } });
2204
+ this.addEventListener("drop", (e) => { e.preventDefault(); this.classList.remove("is-dragover"); const i = input(); if (i && e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files.length) { try { i.files = e.dataTransfer.files; } catch (err) { /* some browsers disallow */ } const preview = this.querySelector(".c-file-upload__preview"); if (preview) { preview.innerHTML = ""; Array.from(e.dataTransfer.files).forEach((f) => { const item = document.createElement("div"); item.className = "c-file-upload__preview-item"; if (f.type && f.type.startsWith("image/")) { const img = document.createElement("img"); img.className = "c-file-upload__preview-thumb"; img.alt = f.name; try { img.src = URL.createObjectURL(f); } catch (err2) {} item.appendChild(img); } else { const name = document.createElement("span"); name.className = "c-file-upload__preview-name"; name.textContent = f.name; item.appendChild(name); } preview.appendChild(item); }); } this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { files: e.dataTransfer.files } })); } });
1443
2205
  }
1444
2206
  }
1445
2207
  define("contour-file-upload", ContourFileUpload);
1446
2208
 
2209
+ /**
2210
+ * Notification Center: web component wrapper.
2211
+ * Attributes: `count`, `items`, `color`.
2212
+ */
1447
2213
  class ContourNotificationCenter extends ContourBase {
1448
- static get observed() { return ["count", "items"]; }
1449
- static get properties() { return { count: { attribute: "count" }, items: { attribute: "items" } }; }
2214
+ static get observed() { return ["count", "items", "color"]; }
2215
+ static get properties() { return { count: { attribute: "count" }, items: { attribute: "items" }, color: { attribute: "color" } }; }
1450
2216
  render() {
1451
2217
  this.classList.add("c-notification-center");
1452
- const btn = this.ensure(".c-notification-center__trigger", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-notification-center__trigger"; el.type = "button"; el.textContent = "🔔"; return el; });
2218
+ const btn = this.ensure(".c-notification-center__trigger", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-notification-center__trigger"; el.type = "button"; el.innerHTML = '<span class="c-notification-center__bullet" aria-hidden="true"></span>'; el.setAttribute("aria-haspopup", "dialog"); el.setAttribute("aria-expanded", "false"); return el; });
2219
+ const color = this.getAttribute("color");
2220
+ const bullet = btn.querySelector(".c-notification-center__bullet");
2221
+ if (bullet && color) bullet.style.background = color;
1453
2222
  const count = this.getAttribute("count");
1454
- let badge = this.querySelector(".c-notification-center__badge");
2223
+ let badge = btn.querySelector(".c-notification-center__badge");
1455
2224
  if (count && Number(count) > 0) {
1456
- if (!badge) { badge = document.createElement("span"); badge.className = "c-notification-center__badge c-badge c-badge--dot"; this.appendChild(badge); }
2225
+ if (!badge) { badge = document.createElement("span"); badge.className = "c-notification-center__badge c-badge c-badge--dot"; btn.appendChild(badge); }
1457
2226
  badge.textContent = count;
1458
2227
  } else if (badge) { badge.remove(); }
1459
- const panel = this.ensure(".c-notification-center__panel", () => { const el = document.createElement("div"); el.className = "c-notification-center__panel"; el.hidden = true; return el; });
2228
+ const panel = this.ensure(".c-notification-center__panel", () => { const el = document.createElement("div"); el.className = "c-notification-center__panel"; el.hidden = true; el.setAttribute("role", "dialog"); el.setAttribute("aria-label", "Notifications"); return el; });
2229
+ // Slotted content: authored .c-notification-center__item children take
2230
+ // precedence over the JSON `items` attribute.
2231
+ const authoredItems = Array.from(this.querySelectorAll(":scope > .c-notification-center__item"));
1460
2232
  const items = this.getAttribute("items");
1461
- if (items) {
2233
+ if (authoredItems.length) {
2234
+ panel.innerHTML = "";
2235
+ authoredItems.forEach((it) => { panel.appendChild(it); });
2236
+ } else if (items) {
1462
2237
  try {
1463
2238
  const parsed = JSON.parse(items);
1464
2239
  panel.innerHTML = "";
1465
2240
  parsed.forEach((it) => {
1466
2241
  const row = document.createElement("div");
1467
2242
  row.className = "c-notification-center__item";
2243
+ row.setAttribute("tabindex", "0");
2244
+ row.setAttribute("role", "option");
1468
2245
  row.textContent = typeof it === "string" ? it : (it.text || it.title || "");
1469
2246
  panel.appendChild(row);
1470
2247
  });
@@ -1478,18 +2255,44 @@ class ContourNotificationCenter extends ContourBase {
1478
2255
  const btn = this.querySelector(".c-notification-center__trigger");
1479
2256
  const panel = this.querySelector(".c-notification-center__panel");
1480
2257
  if (btn && (e.target === btn || btn.contains(e.target))) {
1481
- if (panel) { panel.hidden = !panel.hidden; btn.setAttribute("aria-expanded", String(!panel.hidden)); }
2258
+ if (panel) { panel.hidden = !panel.hidden; btn.setAttribute("aria-expanded", String(!panel.hidden)); this.dispatchEvent(new CustomEvent(panel.hidden ? "contour:close" : "contour:open", { bubbles: true, composed: true })); }
2259
+ }
2260
+ });
2261
+ this.addEventListener("click", (e) => {
2262
+ const item = e.target && e.target.closest ? e.target.closest(".c-notification-center__item") : null;
2263
+ if (item && this.contains(item)) {
2264
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { label: item.textContent } }));
1482
2265
  }
1483
2266
  });
1484
- document.addEventListener("click", (e) => {
2267
+ const docClick = (e) => {
1485
2268
  const panel = this.querySelector(".c-notification-center__panel");
1486
2269
  const btn = this.querySelector(".c-notification-center__trigger");
1487
2270
  if (panel && !panel.hidden && !this.contains(e.target)) { panel.hidden = true; if (btn) btn.setAttribute("aria-expanded", "false"); }
1488
- });
2271
+ };
2272
+ document.addEventListener("click", docClick);
2273
+ onDispose(this, () => document.removeEventListener("click", docClick));
2274
+ const keyHandler = (e) => {
2275
+ const panel = this.querySelector(".c-notification-center__panel");
2276
+ const btn = this.querySelector(".c-notification-center__trigger");
2277
+ if (e.key === "Escape" && panel && !panel.hidden) { panel.hidden = true; if (btn) { btn.setAttribute("aria-expanded", "false"); try { btn.focus(); } catch (err) {} } return; }
2278
+ if (!panel || panel.hidden) return;
2279
+ const items = Array.from(panel.querySelectorAll(".c-notification-center__item"));
2280
+ if (!items.length) return;
2281
+ const active = document.activeElement;
2282
+ const idx = items.indexOf(active);
2283
+ if (e.key === "ArrowDown") { e.preventDefault(); const next = items[Math.min(items.length - 1, idx + 1)] || items[0]; if (next) try { next.focus(); } catch (err) {} }
2284
+ else if (e.key === "ArrowUp") { e.preventDefault(); const prev = items[Math.max(0, idx - 1)] || items[items.length - 1]; if (prev) try { prev.focus(); } catch (err) {} }
2285
+ };
2286
+ document.addEventListener("keydown", keyHandler);
2287
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
1489
2288
  }
1490
2289
  }
1491
2290
  define("contour-notification-center", ContourNotificationCenter);
1492
2291
 
2292
+ /**
2293
+ * Stepper: web component wrapper.
2294
+ * Attributes: `steps`, `current`.
2295
+ */
1493
2296
  class ContourStepper extends ContourBase {
1494
2297
  static get observed() { return ["steps", "current"]; }
1495
2298
  static get properties() { return { steps: { attribute: "steps" }, current: { attribute: "current" } }; }
@@ -1499,11 +2302,19 @@ class ContourStepper extends ContourBase {
1499
2302
  const current = Number(this.getAttribute("current") || 0);
1500
2303
  const list = this.ensure(".c-stepper__list", () => { const el = document.createElement("ol"); el.className = "c-stepper__list"; return el; });
1501
2304
  list.innerHTML = "";
2305
+ // Slotted content: authored .c-stepper__step children take precedence.
2306
+ const authoredSteps = Array.from(this.querySelectorAll(":scope > .c-stepper__step"));
1502
2307
  let parsed = [];
1503
- try { parsed = steps ? JSON.parse(steps) : []; } catch (e) { parsed = []; }
2308
+ if (authoredSteps.length) {
2309
+ parsed = authoredSteps.map((el) => el.textContent.trim());
2310
+ authoredSteps.forEach((el) => el.remove());
2311
+ } else {
2312
+ try { parsed = steps ? JSON.parse(steps) : []; } catch (e) { parsed = []; }
2313
+ }
1504
2314
  parsed.forEach((s, i) => {
1505
2315
  const li = document.createElement("li");
1506
2316
  li.className = "c-stepper__step" + (i === current ? " is-current" : "") + (i < current ? " is-done" : "");
2317
+ if (i === current) li.setAttribute("aria-current", "step");
1507
2318
  li.textContent = typeof s === "string" ? s : (s.title || s.label || "");
1508
2319
  list.appendChild(li);
1509
2320
  });
@@ -1517,44 +2328,207 @@ class ContourStepper extends ContourBase {
1517
2328
  enhance() {
1518
2329
  if (this._wiredStepper) return;
1519
2330
  this._wiredStepper = true;
2331
+ const go = (dir) => {
2332
+ const list = this.querySelector(".c-stepper__list");
2333
+ const total = list ? list.querySelectorAll(".c-stepper__step").length : 0;
2334
+ if (!total) return;
2335
+ let cur = Number(this.getAttribute("current") || 0);
2336
+ if (dir === "prev") cur = Math.max(0, cur - 1);
2337
+ else cur = Math.min(total - 1, cur + 1);
2338
+ this.setAttribute("current", String(cur));
2339
+ this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { direction: dir, index: cur } }));
2340
+ };
1520
2341
  this.addEventListener("click", (e) => {
1521
2342
  const prev = e.target && e.target.closest ? e.target.closest(".c-stepper__prev") : null;
1522
2343
  const next = e.target && e.target.closest ? e.target.closest(".c-stepper__next") : null;
1523
- if (prev && this.contains(prev)) this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { direction: "prev" } }));
1524
- if (next && this.contains(next)) this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { direction: "next" } }));
2344
+ if (prev && this.contains(prev)) go("prev");
2345
+ if (next && this.contains(next)) go("next");
2346
+ });
2347
+ this.addEventListener("keydown", (e) => {
2348
+ if (e.key === "ArrowLeft") { e.preventDefault(); go("prev"); }
2349
+ else if (e.key === "ArrowRight") { e.preventDefault(); go("next"); }
1525
2350
  });
1526
2351
  }
1527
2352
  }
1528
2353
  define("contour-stepper", ContourStepper);
1529
2354
 
2355
+ /**
2356
+ * Virtual List: web component wrapper.
2357
+ * Attributes: `items`, `item-height`, `orientation`, `sticky`.
2358
+ */
1530
2359
  class ContourVirtualList extends ContourBase {
1531
- static get observed() { return ["items", "item-height"]; }
1532
- static get properties() { return { items: { attribute: "items" }, "item-height": { attribute: "item-height" } }; }
1533
- render() {
1534
- this.classList.add("c-virtual-list");
1535
- const scroller = this.ensure(".c-virtual-list__scroller", () => { const el = document.createElement("div"); el.className = "c-virtual-list__scroller"; return el; });
2360
+ static get updateMode() { return "keyed"; }
2361
+ static get observed() { return ["items", "item-height", "orientation", "sticky"]; }
2362
+ static get properties() { return { items: { attribute: "items" }, "item-height": { attribute: "item-height" }, orientation: { attribute: "orientation" }, sticky: { attribute: "sticky", type: Boolean } }; }
2363
+ _items() {
1536
2364
  const items = this.getAttribute("items");
1537
2365
  let parsed = [];
1538
2366
  try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
1539
- scroller.innerHTML = "";
1540
- parsed.forEach((it, i) => {
2367
+ return Array.isArray(parsed) ? parsed : [];
2368
+ }
2369
+ _itemHeight() {
2370
+ const h = Number(this.getAttribute("item-height"));
2371
+ return Number.isFinite(h) && h > 0 ? h : 28;
2372
+ }
2373
+ _autoHeight() {
2374
+ return this.getAttribute("item-height") === "auto";
2375
+ }
2376
+ render() {
2377
+ this.classList.add("c-virtual-list");
2378
+ this.setAttribute("role", "list");
2379
+ const scroller = this.ensure(".c-virtual-list__scroller", () => { const el = document.createElement("div"); el.className = "c-virtual-list__scroller"; return el; });
2380
+ scroller.setAttribute("role", "presentation");
2381
+ const horizontal = this.getAttribute("orientation") === "horizontal";
2382
+ scroller.style.overflowX = horizontal ? "auto" : "hidden";
2383
+ scroller.style.overflowY = horizontal ? "hidden" : "auto";
2384
+ const inner = this.ensure(".c-virtual-list__inner", () => { const el = document.createElement("div"); el.className = "c-virtual-list__inner"; el.style.position = "relative"; return el; });
2385
+ if (inner.parentNode !== scroller) scroller.appendChild(inner);
2386
+ this._renderWindow(scroller, inner, horizontal ? (scroller.scrollLeft || 0) : (scroller.scrollTop || 0));
2387
+ }
2388
+ _measureHeights(inner, horizontal) {
2389
+ const rows = Array.from(inner.querySelectorAll(".c-virtual-list__item"));
2390
+ return rows.map((r) => horizontal ? (r.getBoundingClientRect().width || 28) : (r.getBoundingClientRect().height || 28));
2391
+ }
2392
+ _renderWindow(scroller, inner, scrollTop) {
2393
+ const items = this._items();
2394
+ const ih = this._itemHeight();
2395
+ const horizontal = this.getAttribute("orientation") === "horizontal";
2396
+ const autoHeight = this._autoHeight();
2397
+ const viewportSize = horizontal ? (scroller.clientWidth || 320) : (scroller.clientHeight || 320);
2398
+ const total = items.length;
2399
+ // Reset measured heights when item count changes.
2400
+ if (this._vlItemCount !== total) { this._vlHeights = null; this._vlItemCount = total; }
2401
+ let heights = autoHeight ? this._vlHeights : null;
2402
+ let cumulative = null;
2403
+ if (autoHeight && heights && heights.length === total) {
2404
+ cumulative = [0];
2405
+ for (let i = 0; i < total; i++) cumulative.push(cumulative[i] + (heights[i] || 28));
2406
+ }
2407
+ const visibleCount = autoHeight && !cumulative ? total : (autoHeight ? Math.ceil(viewportSize / 28) + 6 : Math.ceil(viewportSize / ih) + 4);
2408
+ let start = 0;
2409
+ if (autoHeight && cumulative) {
2410
+ // binary search for start
2411
+ let lo = 0, hi = total;
2412
+ while (lo < hi) {
2413
+ const mid = (lo + hi) >> 1;
2414
+ if (cumulative[mid] < (scrollTop || 0)) lo = mid + 1; else hi = mid;
2415
+ }
2416
+ start = Math.max(0, lo - 3);
2417
+ } else if (!autoHeight) {
2418
+ start = Math.floor((scrollTop || 0) / ih);
2419
+ }
2420
+ if (start < 0) start = 0;
2421
+ const end = autoHeight && cumulative
2422
+ ? Math.min(total, start + visibleCount)
2423
+ : Math.min(total, start + visibleCount);
2424
+ if (start > Math.max(0, total - visibleCount) && !autoHeight) start = Math.max(0, total - visibleCount);
2425
+ const topSpacerSize = autoHeight && cumulative ? cumulative[start] : (autoHeight ? 0 : start * ih);
2426
+ const bottomSpacerSize = autoHeight && cumulative ? Math.max(0, cumulative[total] - cumulative[end]) : (autoHeight ? 0 : Math.max(0, (total - end) * ih));
2427
+ inner.style.display = horizontal ? "flex" : "block";
2428
+ inner.style.width = horizontal && autoHeight ? "max-content" : "";
2429
+ inner.style.height = horizontal || autoHeight ? "" : (total * ih) + "px";
2430
+ inner.innerHTML = "";
2431
+ const top = document.createElement("div");
2432
+ top.className = "c-virtual-list__spacer c-virtual-list__spacer--top";
2433
+ top.style[horizontal ? "width" : "height"] = topSpacerSize + "px";
2434
+ inner.appendChild(top);
2435
+ for (let i = start; i < end; i++) {
1541
2436
  const row = document.createElement("div");
1542
2437
  row.className = "c-virtual-list__item";
1543
- row.textContent = typeof it === "string" ? it : (it.label || it.text || JSON.stringify(it));
2438
+ row.setAttribute("role", "listitem");
2439
+ // aria-rowindex omitted: not allowed on role="listitem" (axe aria-allowed-attr)
2440
+ row.setAttribute("tabindex", i === 0 ? "0" : "-1");
2441
+ row.textContent = typeof items[i] === "string" ? items[i] : (items[i].label || items[i].text || JSON.stringify(items[i]));
2442
+ if (this.hasAttribute("sticky") && items[i] && items[i].sticky) {
2443
+ row.style.position = "sticky";
2444
+ row.style.insetBlockStart = "0";
2445
+ row.style.zIndex = "1";
2446
+ }
2447
+ if (horizontal && !autoHeight) row.style.flex = "0 0 " + ih + "px";
1544
2448
  row.dataset.index = String(i);
1545
- scroller.appendChild(row);
2449
+ inner.appendChild(row);
2450
+ }
2451
+ const bottom = document.createElement("div");
2452
+ bottom.className = "c-virtual-list__spacer c-virtual-list__spacer--bottom";
2453
+ bottom.style[horizontal ? "width" : "height"] = bottomSpacerSize + "px";
2454
+ inner.appendChild(bottom);
2455
+ if (horizontal && !autoHeight) inner.style.width = (total * ih) + "px";
2456
+ // Measure heights in auto mode for future windowing.
2457
+ if (autoHeight && !this._vlHeights) {
2458
+ // defer measurement to next frame so layout is done
2459
+ requestAnimationFrame(() => {
2460
+ this._vlHeights = this._measureHeights(inner, horizontal);
2461
+ // re-render windowed now that heights known
2462
+ const s = scroller;
2463
+ const i = inner;
2464
+ if (s && i) this._renderWindow(s, i, s.scrollTop || 0);
2465
+ });
2466
+ }
2467
+ }
2468
+ enhance() {
2469
+ if (this._wiredVirtualList) return;
2470
+ this._wiredVirtualList = true;
2471
+ const scroller = () => this.querySelector(".c-virtual-list__scroller");
2472
+ const inner = () => this.querySelector(".c-virtual-list__inner");
2473
+ let raf = 0;
2474
+ const onScroll = () => {
2475
+ if (raf) return;
2476
+ raf = requestAnimationFrame(() => {
2477
+ raf = 0;
2478
+ const s = scroller(); const i = inner();
2479
+ if (s && i) this._renderWindow(s, i, this.getAttribute("orientation") === "horizontal" ? s.scrollLeft : s.scrollTop);
2480
+ });
2481
+ };
2482
+ const s = scroller();
2483
+ if (s) {
2484
+ s.addEventListener("scroll", onScroll, { passive: true });
2485
+ onDispose(this, () => { s.removeEventListener("scroll", onScroll); if (raf) cancelAnimationFrame(raf); });
2486
+ }
2487
+ // keyboard + selection
2488
+ this.addEventListener("keydown", (e) => {
2489
+ const rows = Array.from(this.querySelectorAll(".c-virtual-list__item"));
2490
+ if (!rows.length) return;
2491
+ const active = this.querySelector(".c-virtual-list__item:focus") || rows[0];
2492
+ const idx = rows.indexOf(active);
2493
+ let next = -1;
2494
+ if (e.key === "ArrowDown") next = Math.min(idx + 1, rows.length - 1);
2495
+ else if (e.key === "ArrowUp") next = Math.max(idx - 1, 0);
2496
+ else if (e.key === "Home") next = 0;
2497
+ else if (e.key === "End") next = rows.length - 1;
2498
+ else if (e.key === "Enter" || e.key === " ") {
2499
+ e.preventDefault();
2500
+ const i = Number(active.dataset.index);
2501
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: i, value: active.textContent } }));
2502
+ return;
2503
+ }
2504
+ if (next < 0 || next === idx) return;
2505
+ e.preventDefault();
2506
+ rows.forEach((r, i) => r.setAttribute("tabindex", i === next ? "0" : "-1"));
2507
+ try { rows[next].focus(); } catch (err) {}
2508
+ });
2509
+ this.addEventListener("click", (e) => {
2510
+ const row = e.target && e.target.closest ? e.target.closest(".c-virtual-list__item") : null;
2511
+ if (!row || !this.contains(row)) return;
2512
+ const i = Number(row.dataset.index);
2513
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: i, value: row.textContent } }));
1546
2514
  });
1547
2515
  }
1548
2516
  }
1549
2517
  define("contour-virtual-list", ContourVirtualList);
1550
2518
 
2519
+ /**
2520
+ * Command Palette: web component wrapper.
2521
+ * Attributes: `open`, `items`.
2522
+ */
1551
2523
  class ContourCommandPalette extends ContourBase {
1552
2524
  static get observed() { return ["open", "items"]; }
1553
2525
  static get properties() { return { open: { attribute: "open", type: Boolean }, items: { attribute: "items" } }; }
1554
2526
  render() {
1555
2527
  this.classList.add("c-command-palette");
2528
+ if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
2529
+ if (!this.hasAttribute("aria-modal")) this.setAttribute("aria-modal", "true");
1556
2530
  if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
1557
- const search = this.ensure(".c-command-palette__search", () => { const el = document.createElement("input"); el.className = "c-input c-command-palette__search"; el.type = "search"; el.placeholder = "Search…"; return el; });
2531
+ const search = this.ensure(".c-command-palette__search", () => { const el = document.createElement("input"); el.className = "c-input c-command-palette__search"; el.type = "search"; el.placeholder = "Search…"; el.setAttribute("aria-label", "Search commands"); return el; });
1558
2532
  const list = this.ensure(".c-command-palette__list", () => { const el = document.createElement("div"); el.className = "c-command-palette__list"; el.setAttribute("role", "listbox"); return el; });
1559
2533
  const items = this.getAttribute("items");
1560
2534
  if (items) {
@@ -1565,32 +2539,87 @@ class ContourCommandPalette extends ContourBase {
1565
2539
  const row = document.createElement("div");
1566
2540
  row.className = "c-command-palette__item";
1567
2541
  row.setAttribute("role", "option");
2542
+ row.id = this.id + "-opt-" + i;
1568
2543
  row.textContent = typeof it === "string" ? it : (it.label || it.title || "");
1569
2544
  row.dataset.index = String(i);
2545
+ row.dataset.label = row.textContent;
1570
2546
  list.appendChild(row);
1571
2547
  });
1572
2548
  } catch (e) { /* keep */ }
1573
2549
  }
1574
2550
  }
2551
+ show() { if (typeof this.showPopover === "function") { try { this.showPopover(); } catch (e) {} } this.classList.add("is-open"); }
2552
+ hide() { if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (e) {} } this.classList.remove("is-open"); }
2553
+ toggle() { if (this.classList.contains("is-open") || this.matches(":popover-open")) this.hide(); else this.show(); }
1575
2554
  enhance() {
1576
- if (this._wiredCmdPalette) return;
1577
2555
  this._wiredCmdPalette = true;
1578
- this.addEventListener("keydown", (e) => {
1579
- const items = Array.from(this.querySelectorAll(".c-command-palette__item"));
1580
- const active = this.querySelector(".c-command-palette__item.is-active");
1581
- let idx = active ? items.indexOf(active) : -1;
1582
- if (e.key === "ArrowDown") { e.preventDefault(); idx = Math.min(items.length - 1, idx + 1); }
1583
- else if (e.key === "ArrowUp") { e.preventDefault(); idx = Math.max(0, idx - 1); }
1584
- else if (e.key === "Home") { e.preventDefault(); idx = 0; }
1585
- else if (e.key === "End") { e.preventDefault(); idx = items.length - 1; }
1586
- else if (e.key === "Enter") { e.preventDefault(); if (active) this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: items.indexOf(active) } })); return; }
1587
- else return;
1588
- items.forEach((it, i) => it.classList.toggle("is-active", i === idx));
2556
+ const search = () => this.querySelector(".c-command-palette__search");
2557
+ const list = () => this.querySelector(".c-command-palette__list");
2558
+ const items = () => Array.from(this.querySelectorAll(".c-command-palette__item"));
2559
+ const visibleItems = () => items().filter((it) => !it.hidden);
2560
+ const setActive = (idx) => {
2561
+ const vis = visibleItems();
2562
+ vis.forEach((it, i) => it.classList.toggle("is-active", i === idx));
2563
+ const active = vis[idx];
2564
+ const s = search();
2565
+ if (s && active) s.setAttribute("aria-activedescendant", active.id);
2566
+ else if (s) s.removeAttribute("aria-activedescendant");
2567
+ };
2568
+ const filter = (q) => {
2569
+ const needle = (q || "").toLowerCase().trim();
2570
+ items().forEach((it) => {
2571
+ const label = (it.dataset.label || it.textContent || "").toLowerCase();
2572
+ it.hidden = needle !== "" && !label.includes(needle);
2573
+ });
2574
+ setActive(0);
2575
+ };
2576
+ const select = (it) => {
2577
+ if (!it) return;
2578
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: Number(it.dataset.index), label: it.dataset.label || it.textContent } }));
2579
+ try { this.hidePopover(); } catch (e) {}
2580
+ this.classList.remove("is-open");
2581
+ };
2582
+ const s = search();
2583
+ if (s) {
2584
+ s.setAttribute("role", "combobox");
2585
+ s.setAttribute("aria-autocomplete", "list");
2586
+ s.setAttribute("aria-controls", list() ? list().id || "" : "");
2587
+ if (!list().id) list().id = this.id + "-list";
2588
+ s.setAttribute("aria-controls", list().id);
2589
+ s.addEventListener("input", (e) => filter(e.target.value));
2590
+ s.addEventListener("keydown", (e) => {
2591
+ const vis = visibleItems();
2592
+ const active = this.querySelector(".c-command-palette__item.is-active");
2593
+ let idx = active ? vis.indexOf(active) : -1;
2594
+ if (e.key === "ArrowDown") { e.preventDefault(); idx = Math.min(vis.length - 1, idx + 1); if (idx < 0) idx = 0; setActive(idx); }
2595
+ else if (e.key === "ArrowUp") { e.preventDefault(); idx = Math.max(0, idx - 1); if (vis.length && idx < 0) idx = 0; setActive(idx); }
2596
+ else if (e.key === "Home") { e.preventDefault(); setActive(0); }
2597
+ else if (e.key === "End") { e.preventDefault(); setActive(vis.length - 1); }
2598
+ else if (e.key === "Enter") { e.preventDefault(); if (active) select(active); }
2599
+ else if (e.key === "Escape") { e.preventDefault(); try { this.hidePopover(); } catch (e) {} this.classList.remove("is-open"); }
2600
+ });
2601
+ }
2602
+ // click selection
2603
+ this.addEventListener("click", (e) => {
2604
+ const it = e.target && e.target.closest ? e.target.closest(".c-command-palette__item") : null;
2605
+ if (it && this.contains(it) && !it.hidden) select(it);
2606
+ });
2607
+ // focus return on close
2608
+ let lastFocus = null;
2609
+ this.addEventListener("beforetoggle", (e) => {
2610
+ if (e.newState === "open") lastFocus = document.activeElement;
2611
+ else if (lastFocus && typeof lastFocus.focus === "function") { try { lastFocus.focus(); } catch (err) {} }
1589
2612
  });
2613
+ // Escape via popover light dismiss is handled by keydown above; also close on outside handled by popover.
2614
+ setActive(0);
1590
2615
  }
1591
2616
  }
1592
2617
  define("contour-command-palette", ContourCommandPalette);
1593
2618
 
2619
+ /**
2620
+ * Badge Overflow: web component wrapper.
2621
+ * Attributes: `count`, `max`.
2622
+ */
1594
2623
  class ContourBadgeOverflow extends ContourBase {
1595
2624
  static get observed() { return ["count", "max"]; }
1596
2625
  static get properties() { return { count: { attribute: "count" }, max: { attribute: "max" } }; }
@@ -1610,29 +2639,76 @@ class ContourBadgeOverflow extends ContourBase {
1610
2639
  }
1611
2640
  define("contour-badge-overflow", ContourBadgeOverflow);
1612
2641
 
2642
+ /**
2643
+ * Side Sheet: web component wrapper.
2644
+ * Attributes: `open`, `side`, `title`.
2645
+ */
1613
2646
  class ContourSideSheet extends ContourBase {
1614
2647
  static get observed() { return ["open", "side", "title"]; }
1615
2648
  static get properties() { return { open: { attribute: "open", type: Boolean }, side: { attribute: "side" }, title: { attribute: "title" } }; }
1616
2649
  render() {
1617
2650
  this.classList.add("c-side-sheet");
2651
+ this.setAttribute("role", "dialog");
2652
+ this.setAttribute("aria-modal", "true");
2653
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Side sheet");
1618
2654
  const side = this.getAttribute("side") || "end";
1619
2655
  this.classList.add("c-side-sheet--" + side);
1620
- if (this.hasAttribute("open")) this.classList.add("is-open");
1621
- else this.classList.remove("is-open");
2656
+ if (this.hasAttribute("open")) this.classList.add("is-open"); else this.classList.remove("is-open");
1622
2657
  const title = this.getAttribute("title");
1623
2658
  if (title) {
1624
2659
  const t = this.ensure(".c-side-sheet__title", () => { const el = document.createElement("div"); el.className = "c-side-sheet__title"; return el; });
1625
2660
  t.textContent = title;
1626
2661
  }
1627
2662
  }
2663
+ enhance() {
2664
+ if (this._wiredSideSheet) return;
2665
+ this._wiredSideSheet = true;
2666
+ let lastFocus = null;
2667
+ const close = () => this.removeAttribute("open");
2668
+ const keyHandler = (e) => {
2669
+ if (e.key === "Escape" && this.hasAttribute("open")) { e.preventDefault(); close(); return; }
2670
+ if (e.key === "Tab" && this.hasAttribute("open")) {
2671
+ const focusables = Array.from(this.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")).filter((el) => !el.hasAttribute("disabled"));
2672
+ if (!focusables.length) { e.preventDefault(); return; }
2673
+ const first = focusables[0], last = focusables[focusables.length - 1];
2674
+ if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
2675
+ else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
2676
+ }
2677
+ };
2678
+ document.addEventListener("keydown", keyHandler);
2679
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
2680
+ this.addEventListener("click", (e) => {
2681
+ if (e.target === this) close();
2682
+ });
2683
+ // Focus management: capture focus on open, restore on close.
2684
+ const obs = new MutationObserver(() => {
2685
+ if (this.hasAttribute("open")) {
2686
+ lastFocus = document.activeElement;
2687
+ const first = this.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
2688
+ if (first) try { first.focus(); } catch (err) {}
2689
+ } else if (lastFocus) {
2690
+ try { lastFocus.focus(); } catch (err) {}
2691
+ lastFocus = null;
2692
+ }
2693
+ });
2694
+ obs.observe(this, { attributes: true, attributeFilter: ["open"] });
2695
+ onDispose(this, () => obs.disconnect());
2696
+ }
1628
2697
  }
1629
2698
  define("contour-side-sheet", ContourSideSheet);
1630
2699
 
2700
+ /**
2701
+ * Tour: web component wrapper.
2702
+ * Attributes: `steps`, `current`.
2703
+ */
1631
2704
  class ContourTour extends ContourBase {
1632
2705
  static get observed() { return ["steps", "current"]; }
1633
2706
  static get properties() { return { steps: { attribute: "steps" }, current: { attribute: "current" } }; }
1634
2707
  render() {
1635
2708
  this.classList.add("c-tour");
2709
+ this.setAttribute("role", "dialog");
2710
+ this.setAttribute("aria-modal", "true");
2711
+ this.setAttribute("aria-label", "Tour");
1636
2712
  const steps = this.getAttribute("steps");
1637
2713
  const current = Number(this.getAttribute("current") || 0);
1638
2714
  let parsed = [];
@@ -1647,21 +2723,41 @@ class ContourTour extends ContourBase {
1647
2723
  enhance() {
1648
2724
  if (this._wiredTour) return;
1649
2725
  this._wiredTour = true;
2726
+ const nextBtn = this.querySelector(".c-tour__next");
2727
+ if (nextBtn) try { nextBtn.focus(); } catch (err) {}
1650
2728
  this.addEventListener("click", (e) => {
1651
2729
  const next = e.target && e.target.closest ? e.target.closest(".c-tour__next") : null;
1652
2730
  if (next && this.contains(next)) this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { direction: "next" } }));
1653
2731
  });
2732
+ const keyHandler = (e) => { if (e.key === "Escape") this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); };
2733
+ document.addEventListener("keydown", keyHandler);
2734
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
1654
2735
  }
1655
2736
  }
1656
2737
  define("contour-tour", ContourTour);
1657
2738
 
2739
+ /**
2740
+ * Tags Input: web component wrapper.
2741
+ * Attributes: `value`, `placeholder`, `disabled`, `error`, `help`.
2742
+ */
1658
2743
  class ContourTagsInput extends ContourBase {
1659
- static get observed() { return ["value", "placeholder"]; }
1660
- static get properties() { return { value: { attribute: "value" }, placeholder: { attribute: "placeholder" } }; }
2744
+ static get observed() { return ["value", "placeholder", "disabled", "error", "help"]; }
2745
+ static get properties() { return { value: { attribute: "value" }, placeholder: { attribute: "placeholder" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
1661
2746
  render() {
1662
2747
  this.classList.add("c-tags-input");
1663
- const input = this.ensure(".c-tags-input__input", () => { const el = document.createElement("input"); el.className = "c-input c-tags-input__input"; el.type = "text"; return el; });
2748
+ const input = this.ensure(".c-tags-input__input", () => { const el = document.createElement("input"); el.className = "c-input c-tags-input__input"; el.type = "text"; el.setAttribute("aria-label", "Add tag"); return el; });
1664
2749
  input.placeholder = this.getAttribute("placeholder") || "Add tag…";
2750
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
2751
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
2752
+ const err = this.getAttribute("error");
2753
+ const help = this.getAttribute("help");
2754
+ let msg = this.querySelector(".c-tags-input__message");
2755
+ if (err || help) {
2756
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-tags-input__message"; this.appendChild(msg); }
2757
+ msg.textContent = err || help || "";
2758
+ msg.classList.toggle("c-tags-input__message--error", !!err);
2759
+ } else if (msg) { msg.remove(); }
2760
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
1665
2761
  const tags = this.getAttribute("value");
1666
2762
  let parsed = [];
1667
2763
  try { parsed = tags ? JSON.parse(tags) : []; } catch (e) { parsed = tags ? tags.split(",").map((s) => s.trim()).filter(Boolean) : []; }
@@ -1682,23 +2778,60 @@ class ContourTagsInput extends ContourBase {
1682
2778
  enhance() {
1683
2779
  if (this._wiredTagsInput) return;
1684
2780
  this._wiredTagsInput = true;
2781
+ let live = this.querySelector(".c-tags-input__live");
2782
+ if (!live) { live = document.createElement("span"); live.className = "c-tags-input__live visually-hidden"; live.setAttribute("aria-live", "polite"); live.setAttribute("aria-atomic", "true"); this.appendChild(live); }
2783
+ const announce = (msg) => { if (live) live.textContent = msg; };
1685
2784
  this.addEventListener("keydown", (e) => {
1686
2785
  const input = this.querySelector(".c-tags-input__input");
2786
+ if (!input) return;
1687
2787
  if (e.key === "Enter" && e.target === input) {
1688
2788
  e.preventDefault();
1689
2789
  const v = input.value.trim();
1690
- if (v) { this.dispatchEvent(new CustomEvent("contour:add", { bubbles: true, composed: true, detail: { value: v } })); input.value = ""; }
2790
+ if (v) {
2791
+ let tags = [];
2792
+ try { tags = JSON.parse(this.getAttribute("value") || "[]"); } catch (err) { tags = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean); }
2793
+ if (!Array.isArray(tags)) tags = [];
2794
+ if (!tags.includes(v)) tags.push(v);
2795
+ this.setAttribute("value", JSON.stringify(tags));
2796
+ input.value = "";
2797
+ announce("Added " + v);
2798
+ this.dispatchEvent(new CustomEvent("contour:add", { bubbles: true, composed: true, detail: { value: v } }));
2799
+ }
2800
+ } else if (e.key === "Backspace" && e.target === input && input.value === "") {
2801
+ let tags = [];
2802
+ try { tags = JSON.parse(this.getAttribute("value") || "[]"); } catch (err) { tags = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean); }
2803
+ if (!Array.isArray(tags)) tags = [];
2804
+ if (tags.length) {
2805
+ const removed = tags.pop();
2806
+ this.setAttribute("value", JSON.stringify(tags));
2807
+ announce("Removed " + removed);
2808
+ this.dispatchEvent(new CustomEvent("contour:remove", { bubbles: true, composed: true, detail: { value: removed } }));
2809
+ }
1691
2810
  }
1692
2811
  });
1693
2812
  this.addEventListener("click", (e) => {
1694
2813
  const rm = e.target && e.target.closest ? e.target.closest(".c-tags-input__remove") : null;
1695
- if (rm && this.contains(rm)) this.dispatchEvent(new CustomEvent("contour:remove", { bubbles: true, composed: true, detail: { value: rm.dataset.value } }));
2814
+ if (rm && this.contains(rm)) {
2815
+ const val = rm.dataset.value;
2816
+ let tags = [];
2817
+ try { tags = JSON.parse(this.getAttribute("value") || "[]"); } catch (err) { tags = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean); }
2818
+ if (!Array.isArray(tags)) tags = [];
2819
+ const next = tags.filter((t) => t !== val);
2820
+ this.setAttribute("value", JSON.stringify(next));
2821
+ announce("Removed " + val);
2822
+ this.dispatchEvent(new CustomEvent("contour:remove", { bubbles: true, composed: true, detail: { value: val } }));
2823
+ }
1696
2824
  });
1697
2825
  }
1698
2826
  }
1699
2827
  define("contour-tags-input", ContourTagsInput);
1700
2828
 
2829
+ /**
2830
+ * Sortable List: web component wrapper.
2831
+ * Attributes: `items`.
2832
+ */
1701
2833
  class ContourSortableList extends ContourBase {
2834
+ static get updateMode() { return "keyed"; }
1702
2835
  static get observed() { return ["items"]; }
1703
2836
  static get properties() { return { items: { attribute: "items" } }; }
1704
2837
  render() {
@@ -1729,19 +2862,84 @@ class ContourSortableList extends ContourBase {
1729
2862
  enhance() {
1730
2863
  if (this._wiredSortableList) return;
1731
2864
  this._wiredSortableList = true;
2865
+ const list = () => this.querySelector(".c-sortable-list__list");
2866
+ // Live region for position announcements.
2867
+ let live = this.querySelector(".c-sortable-list__live");
2868
+ if (!live) { live = document.createElement("span"); live.className = "c-sortable-list__live visually-hidden"; live.setAttribute("aria-live", "polite"); live.setAttribute("aria-atomic", "true"); this.appendChild(live); }
2869
+ const announce = (msg) => { if (live) live.textContent = msg; };
2870
+ const index = (li) => Array.from(list().children).indexOf(li);
2871
+ // Pointer drag reorder.
2872
+ let dragFrom = null;
2873
+ this.addEventListener("dragstart", (e) => {
2874
+ const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
2875
+ if (!li || !this.contains(li)) return;
2876
+ dragFrom = index(li);
2877
+ if (e.dataTransfer) { e.dataTransfer.effectAllowed = "move"; try { e.dataTransfer.setData("text/plain", String(dragFrom)); } catch (err) {} }
2878
+ li.classList.add("is-dragging");
2879
+ });
2880
+ this.addEventListener("dragover", (e) => {
2881
+ const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
2882
+ if (!li || !this.contains(li) || dragFrom === null) return;
2883
+ e.preventDefault();
2884
+ if (e.dataTransfer) e.dataTransfer.dropEffect = "move";
2885
+ });
2886
+ this.addEventListener("drop", (e) => {
2887
+ const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
2888
+ if (!li || !this.contains(li) || dragFrom === null) return;
2889
+ e.preventDefault();
2890
+ const to = index(li);
2891
+ const l = list();
2892
+ const fromLi = l.children[dragFrom];
2893
+ if (fromLi && dragFrom !== to) {
2894
+ if (dragFrom < to) l.insertBefore(fromLi, l.children[to + 1] || null);
2895
+ else l.insertBefore(fromLi, l.children[to]);
2896
+ const item = fromLi.querySelector(".c-sortable-list__label");
2897
+ announce((item ? item.textContent : "Item") + " moved to position " + (to + 1));
2898
+ this.dispatchEvent(new CustomEvent("contour:reorder", { bubbles: true, composed: true, detail: { from: dragFrom, to } }));
2899
+ }
2900
+ dragFrom = null;
2901
+ Array.from(l.children).forEach((n) => n.classList.remove("is-dragging"));
2902
+ });
2903
+ this.addEventListener("dragend", () => {
2904
+ dragFrom = null;
2905
+ const l = list();
2906
+ if (l) Array.from(l.children).forEach((n) => n.classList.remove("is-dragging"));
2907
+ });
2908
+ // Keyboard reorder.
1732
2909
  this.addEventListener("keydown", (e) => {
1733
2910
  const handle = e.target && e.target.closest ? e.target.closest(".c-sortable-list__handle") : null;
1734
2911
  if (!handle) return;
1735
2912
  const li = handle.closest(".c-sortable-list__item");
1736
2913
  if (!li) return;
1737
- const list = this.querySelector(".c-sortable-list__list");
1738
- if (e.key === "ArrowUp" && li.previousElementSibling) { e.preventDefault(); list.insertBefore(li, li.previousElementSibling); this.dispatchEvent(new CustomEvent("contour:move", { bubbles: true, composed: true, detail: { direction: "up" } })); }
1739
- if (e.key === "ArrowDown" && li.nextElementSibling) { e.preventDefault(); list.insertBefore(li.nextElementSibling, li); this.dispatchEvent(new CustomEvent("contour:move", { bubbles: true, composed: true, detail: { direction: "down" } })); }
2914
+ const l = list();
2915
+ const from = index(li);
2916
+ if (e.key === "ArrowUp" && li.previousElementSibling) {
2917
+ e.preventDefault();
2918
+ l.insertBefore(li, li.previousElementSibling);
2919
+ const to = index(li);
2920
+ const label = li.querySelector(".c-sortable-list__label");
2921
+ announce((label ? label.textContent : "Item") + " moved to position " + (to + 1));
2922
+ this.dispatchEvent(new CustomEvent("contour:move", { bubbles: true, composed: true, detail: { direction: "up", from, to } }));
2923
+ this.dispatchEvent(new CustomEvent("contour:reorder", { bubbles: true, composed: true, detail: { from, to } }));
2924
+ }
2925
+ if (e.key === "ArrowDown" && li.nextElementSibling) {
2926
+ e.preventDefault();
2927
+ l.insertBefore(li.nextElementSibling, li);
2928
+ const to = index(li);
2929
+ const label = li.querySelector(".c-sortable-list__label");
2930
+ announce((label ? label.textContent : "Item") + " moved to position " + (to + 1));
2931
+ this.dispatchEvent(new CustomEvent("contour:move", { bubbles: true, composed: true, detail: { direction: "down", from, to } }));
2932
+ this.dispatchEvent(new CustomEvent("contour:reorder", { bubbles: true, composed: true, detail: { from, to } }));
2933
+ }
1740
2934
  });
1741
2935
  }
1742
2936
  }
1743
2937
  define("contour-sortable-list", ContourSortableList);
1744
2938
 
2939
+ /**
2940
+ * Swatch: web component wrapper.
2941
+ * Attributes: `color`, `selected`, `label`.
2942
+ */
1745
2943
  class ContourSwatch extends ContourBase {
1746
2944
  static get observed() { return ["color", "selected", "label"]; }
1747
2945
  static get properties() { return { color: { attribute: "color" }, selected: { attribute: "selected", type: Boolean }, label: { attribute: "label" } }; }
@@ -1772,16 +2970,31 @@ class ContourSwatch extends ContourBase {
1772
2970
  }
1773
2971
  define("contour-swatch", ContourSwatch);
1774
2972
 
2973
+ /**
2974
+ * Calendar: web component wrapper.
2975
+ * Attributes: `value`.
2976
+ */
1775
2977
  class ContourCalendar extends ContourBase {
1776
- static get observed() { return ["value", "month"]; }
1777
- static get properties() { return { value: { attribute: "value" }, month: { attribute: "month" } }; }
2978
+ static get observed() { return ["value"]; }
2979
+ static get properties() { return { value: { attribute: "value" }, month: { attribute: "month" }, year: { attribute: "year" } }; }
1778
2980
  render() {
1779
2981
  this.classList.add("c-calendar");
1780
- const grid = this.ensure(".c-calendar__grid", () => { const el = document.createElement("div"); el.className = "c-calendar__grid"; el.setAttribute("role", "grid"); return el; });
1781
- grid.innerHTML = "";
1782
2982
  const now = new Date();
1783
- const year = now.getFullYear();
2983
+ const year = Number(this.getAttribute("year")) || now.getFullYear();
1784
2984
  const month = Number(this.getAttribute("month")) || now.getMonth();
2985
+ const header = this.ensure(".c-calendar__header", () => { const el = document.createElement("div"); el.className = "c-calendar__header"; return el; });
2986
+ header.innerHTML = "";
2987
+ const prev = document.createElement("button");
2988
+ prev.type = "button"; prev.className = "c-btn c-btn--sm c-calendar__prev"; prev.textContent = "‹"; prev.setAttribute("aria-label", "Previous month");
2989
+ const title = document.createElement("span");
2990
+ title.className = "c-calendar__title";
2991
+ title.textContent = new Date(year, month, 1).toLocaleString(undefined, { month: "long", year: "numeric" });
2992
+ const next = document.createElement("button");
2993
+ next.type = "button"; next.className = "c-btn c-btn--sm c-calendar__next"; next.textContent = "›"; next.setAttribute("aria-label", "Next month");
2994
+ header.appendChild(prev); header.appendChild(title); header.appendChild(next);
2995
+ const grid = this.ensure(".c-calendar__grid", () => { const el = document.createElement("div"); el.className = "c-calendar__grid"; el.setAttribute("role", "grid"); return el; });
2996
+ grid.setAttribute("aria-label", title.textContent);
2997
+ grid.innerHTML = "";
1785
2998
  const first = new Date(year, month, 1);
1786
2999
  const startDay = first.getDay();
1787
3000
  const daysInMonth = new Date(year, month + 1, 0).getDate();
@@ -1795,65 +3008,174 @@ class ContourCalendar extends ContourBase {
1795
3008
  const cell = document.createElement("button");
1796
3009
  cell.className = "c-calendar__day";
1797
3010
  cell.type = "button";
3011
+ cell.setAttribute("role", "gridcell");
3012
+ cell.setAttribute("tabindex", "0");
1798
3013
  cell.textContent = String(d);
1799
3014
  const iso = year + "-" + String(month + 1).padStart(2, "0") + "-" + String(d).padStart(2, "0");
1800
- if (iso === selected) cell.classList.add("is-selected");
3015
+ if (iso === selected) { cell.classList.add("is-selected"); cell.setAttribute("aria-selected", "true"); }
3016
+ else cell.setAttribute("aria-selected", "false");
3017
+ const todayIso = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0") + "-" + String(now.getDate()).padStart(2, "0");
3018
+ if (iso === todayIso) cell.setAttribute("aria-current", "date");
1801
3019
  cell.dataset.value = iso;
1802
3020
  grid.appendChild(cell);
1803
3021
  }
3022
+ if (header.parentNode !== this) this.insertBefore(header, grid);
1804
3023
  }
1805
3024
  enhance() {
1806
3025
  if (this._wiredCalendar) return;
1807
3026
  this._wiredCalendar = true;
1808
3027
  this.addEventListener("click", (e) => {
3028
+ const prev = e.target && e.target.closest ? e.target.closest(".c-calendar__prev") : null;
3029
+ const next = e.target && e.target.closest ? e.target.closest(".c-calendar__next") : null;
3030
+ if (prev && this.contains(prev)) {
3031
+ let m = Number(this.getAttribute("month")) || new Date().getMonth();
3032
+ let y = Number(this.getAttribute("year")) || new Date().getFullYear();
3033
+ m -= 1;
3034
+ if (m < 0) { m = 11; y -= 1; }
3035
+ this.setAttribute("month", String(m));
3036
+ this.setAttribute("year", String(y));
3037
+ this.render();
3038
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { month: m, year: y } }));
3039
+ return;
3040
+ }
3041
+ if (next && this.contains(next)) {
3042
+ let m = Number(this.getAttribute("month")) || new Date().getMonth();
3043
+ let y = Number(this.getAttribute("year")) || new Date().getFullYear();
3044
+ m += 1;
3045
+ if (m > 11) { m = 0; y += 1; }
3046
+ this.setAttribute("month", String(m));
3047
+ this.setAttribute("year", String(y));
3048
+ this.render();
3049
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { month: m, year: y } }));
3050
+ return;
3051
+ }
1809
3052
  const cell = e.target && e.target.closest ? e.target.closest(".c-calendar__day") : null;
1810
3053
  if (cell && this.contains(cell) && cell.dataset.value) {
3054
+ this.setAttribute("value", cell.dataset.value);
1811
3055
  this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { value: cell.dataset.value } }));
1812
3056
  }
1813
3057
  });
3058
+ this.addEventListener("keydown", (e) => {
3059
+ const cell = e.target && e.target.closest ? e.target.closest(".c-calendar__day") : null;
3060
+ if (!cell || !this.contains(cell)) return;
3061
+ const cells = Array.from(this.querySelectorAll(".c-calendar__day:not(.c-calendar__day--empty)"));
3062
+ const idx = cells.indexOf(cell);
3063
+ let next = null;
3064
+ if (e.key === "ArrowRight") next = cells[idx + 1];
3065
+ else if (e.key === "ArrowLeft") next = cells[idx - 1];
3066
+ else if (e.key === "ArrowDown") next = cells[idx + 7];
3067
+ else if (e.key === "ArrowUp") next = cells[idx - 7];
3068
+ else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); cell.click(); return; }
3069
+ if (next) { e.preventDefault(); try { next.focus(); } catch (err) {} }
3070
+ });
1814
3071
  }
1815
3072
  }
1816
3073
  define("contour-calendar", ContourCalendar);
1817
3074
 
3075
+ /**
3076
+ * Carousel: web component wrapper.
3077
+ * Attributes: `items`, `index`.
3078
+ */
1818
3079
  class ContourCarousel extends ContourBase {
1819
3080
  static get observed() { return ["items", "index"]; }
1820
3081
  static get properties() { return { items: { attribute: "items" }, index: { attribute: "index" } }; }
1821
- render() {
1822
- this.classList.add("c-carousel");
1823
- const track = this.ensure(".c-carousel__track", () => { const el = document.createElement("div"); el.className = "c-carousel__track"; return el; });
3082
+ _items() {
1824
3083
  const items = this.getAttribute("items");
1825
3084
  let parsed = [];
1826
3085
  try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
3086
+ return Array.isArray(parsed) ? parsed : [];
3087
+ }
3088
+ _index() {
3089
+ const i = Number(this.getAttribute("index"));
3090
+ const items = this._items();
3091
+ if (Number.isFinite(i) && i >= 0 && i < items.length) return i;
3092
+ return 0;
3093
+ }
3094
+ render() {
3095
+ this.classList.add("c-carousel");
3096
+ this.setAttribute("role", "region");
3097
+ this.setAttribute("aria-roledescription", "carousel");
3098
+ const track = this.ensure(".c-carousel__track", () => { const el = document.createElement("div"); el.className = "c-carousel__track"; el.setAttribute("role", "group"); el.setAttribute("aria-roledescription", "slide container"); return el; });
3099
+ const items = this._items();
1827
3100
  track.innerHTML = "";
1828
- parsed.forEach((it, i) => {
3101
+ const idx = this._index();
3102
+ items.forEach((it, i) => {
1829
3103
  const slide = document.createElement("div");
1830
- slide.className = "c-carousel__slide";
3104
+ slide.className = "c-carousel__slide" + (i === idx ? " is-active" : "");
3105
+ slide.setAttribute("role", "group");
3106
+ slide.setAttribute("aria-roledescription", "slide");
3107
+ slide.setAttribute("aria-label", (i + 1) + " of " + items.length);
3108
+ slide.setAttribute("aria-hidden", i === idx ? "false" : "true");
1831
3109
  slide.textContent = typeof it === "string" ? it : (it.label || it.text || "");
1832
3110
  slide.dataset.index = String(i);
1833
3111
  track.appendChild(slide);
1834
3112
  });
1835
- const prev = this.ensure(".c-carousel__prev", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-carousel__prev"; el.type = "button"; el.textContent = "‹"; return el; });
1836
- const next = this.ensure(".c-carousel__next", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-carousel__next"; el.type = "button"; el.textContent = "›"; return el; });
3113
+ const prev = this.ensure(".c-carousel__prev", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-carousel__prev"; el.type = "button"; el.textContent = "‹"; el.setAttribute("aria-label", "Previous slide"); return el; });
3114
+ const next = this.ensure(".c-carousel__next", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-carousel__next"; el.type = "button"; el.textContent = "›"; el.setAttribute("aria-label", "Next slide"); return el; });
3115
+ const status = this.ensure(".c-carousel__status", () => { const el = document.createElement("span"); el.className = "c-carousel__status"; el.setAttribute("aria-live", "polite"); return el; });
3116
+ status.textContent = (idx + 1) + " of " + items.length;
1837
3117
  }
1838
3118
  enhance() {
1839
3119
  if (this._wiredCarousel) return;
1840
3120
  this._wiredCarousel = true;
3121
+ const go = (dir) => {
3122
+ const items = this._items();
3123
+ if (!items.length) return;
3124
+ let idx = this._index();
3125
+ if (dir === "prev") idx = (idx - 1 + items.length) % items.length;
3126
+ else idx = (idx + 1) % items.length;
3127
+ this.setAttribute("index", String(idx));
3128
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: idx, direction: dir } }));
3129
+ };
1841
3130
  this.addEventListener("click", (e) => {
1842
3131
  const prev = e.target && e.target.closest ? e.target.closest(".c-carousel__prev") : null;
1843
3132
  const next = e.target && e.target.closest ? e.target.closest(".c-carousel__next") : null;
1844
- if (prev && this.contains(prev)) this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { direction: "prev" } }));
1845
- if (next && this.contains(next)) this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { direction: "next" } }));
3133
+ if (prev && this.contains(prev)) go("prev");
3134
+ if (next && this.contains(next)) go("next");
3135
+ });
3136
+ this.addEventListener("keydown", (e) => {
3137
+ if (e.key === "ArrowLeft") { e.preventDefault(); go("prev"); }
3138
+ else if (e.key === "ArrowRight") { e.preventDefault(); go("next"); }
3139
+ else if (e.key === "Home") { e.preventDefault(); this.setAttribute("index", "0"); this.render(); this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: 0, direction: "home" } })); }
3140
+ else if (e.key === "End") { e.preventDefault(); const last = this._items().length - 1; if (last >= 0) { this.setAttribute("index", String(last)); this.render(); this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: last, direction: "end" } })); } }
1846
3141
  });
1847
3142
  }
1848
3143
  }
1849
3144
  define("contour-carousel", ContourCarousel);
1850
3145
 
3146
+ /**
3147
+ * Data Grid: web component wrapper.
3148
+ * Attributes: `columns`, `rows`, `page`, `filter`, `page-size`, `resizable`.
3149
+ */
1851
3150
  class ContourDataGrid extends ContourBase {
1852
- static get observed() { return ["columns", "rows", "page"]; }
1853
- static get properties() { return { columns: { attribute: "columns" }, rows: { attribute: "rows" }, page: { attribute: "page" } }; }
3151
+ static get updateMode() { return "keyed"; }
3152
+ static get observed() { return ["columns", "rows", "page", "filter", "page-size", "resizable", "virtual", "row-height"]; }
3153
+ static get properties() { return { columns: { attribute: "columns" }, rows: { attribute: "rows" }, page: { attribute: "page" }, filter: { attribute: "filter" }, "page-size": { attribute: "page-size" }, resizable: { attribute: "resizable", type: Boolean }, virtual: { attribute: "virtual", type: Boolean }, "row-height": { attribute: "row-height" } }; }
1854
3154
  render() {
1855
3155
  this.classList.add("c-data-grid");
1856
- const table = this.ensure(".c-data-grid__table", () => { const el = document.createElement("table"); el.className = "c-table c-data-grid__table"; return el; });
3156
+ if (this.hasAttribute("loading") || this.hasAttribute("error") || this.hasAttribute("empty")) {
3157
+ const table = this.ensure(".c-data-grid__table", () => { const el = document.createElement("table"); el.className = "c-table c-data-grid__table"; el.setAttribute("role", "grid"); return el; });
3158
+ const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
3159
+ if (tbody.parentNode !== table) table.appendChild(tbody);
3160
+ tbody.innerHTML = "";
3161
+ const tr = document.createElement("tr");
3162
+ const td = document.createElement("td");
3163
+ td.colSpan = 1;
3164
+ td.style.textAlign = "center";
3165
+ td.style.color = "var(--color-text-muted)";
3166
+ if (this.hasAttribute("loading")) td.textContent = this.getAttribute("loading") || "Loading…";
3167
+ else if (this.hasAttribute("error")) td.textContent = this.getAttribute("error") || "Error";
3168
+ else td.textContent = this.getAttribute("empty") || "No data";
3169
+ tr.appendChild(td);
3170
+ tbody.appendChild(tr);
3171
+ // Wrap in a scroll container for virtualization of large datasets.
3172
+ let wrap = this.querySelector(".c-data-grid__wrap");
3173
+ if (!wrap) { wrap = document.createElement("div"); wrap.className = "c-data-grid__wrap"; wrap.style.maxHeight = "400px"; wrap.style.overflow = "auto"; }
3174
+ if (table.parentNode !== wrap) wrap.appendChild(table);
3175
+ if (wrap.parentNode !== this) this.appendChild(wrap);
3176
+ return;
3177
+ }
3178
+ const table = this.ensure(".c-data-grid__table", () => { const el = document.createElement("table"); el.className = "c-table c-data-grid__table"; el.setAttribute("role", "grid"); return el; });
1857
3179
  const thead = this.ensure("thead", () => { const el = document.createElement("thead"); return el; });
1858
3180
  const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
1859
3181
  if (thead.parentNode !== table) table.appendChild(thead);
@@ -1865,53 +3187,315 @@ class ContourDataGrid extends ContourBase {
1865
3187
  const tr = document.createElement("tr");
1866
3188
  parsedCols.forEach((c) => {
1867
3189
  const th = document.createElement("th");
3190
+ th.setAttribute("role", "columnheader");
3191
+ th.setAttribute("aria-sort", "none");
3192
+ th.setAttribute("tabindex", "0");
1868
3193
  th.textContent = typeof c === "string" ? c : (c.label || c.key || "");
1869
3194
  tr.appendChild(th);
1870
3195
  });
1871
3196
  thead.appendChild(tr);
1872
3197
  }
3198
+ if (this.hasAttribute("resizable")) {
3199
+ Array.from(thead.querySelectorAll("th")).forEach((th) => {
3200
+ th.style.position = "relative";
3201
+ th.setAttribute("data-resizable", "true");
3202
+ });
3203
+ }
1873
3204
  const rows = this.getAttribute("rows");
1874
3205
  let parsedRows = [];
1875
3206
  try { parsedRows = rows ? JSON.parse(rows) : []; } catch (e) { parsedRows = []; }
3207
+ table.setAttribute("aria-rowcount", String(parsedRows.length));
3208
+ table.setAttribute("aria-colcount", String(parsedCols.length));
3209
+ const filter = this.getAttribute("filter");
3210
+ if (filter) {
3211
+ const q = filter.toLowerCase();
3212
+ parsedRows = parsedRows.filter((r) => JSON.stringify(r).toLowerCase().includes(q));
3213
+ }
3214
+ const page = Number(this.getAttribute("page") || 1);
3215
+ const pageSize = Number(this.getAttribute("page-size") || 0);
3216
+ if (pageSize > 0) {
3217
+ const start = (page - 1) * pageSize;
3218
+ parsedRows = parsedRows.slice(start, start + pageSize);
3219
+ }
3220
+ this._dgCols = parsedCols;
3221
+ this._dgRows = parsedRows;
3222
+ this._dgFilteredRows = parsedRows;
3223
+ const virtual = this.hasAttribute("virtual") && !(Number(this.getAttribute("page-size")) > 0);
3224
+ if (virtual) {
3225
+ this._renderDataGridWindow(0);
3226
+ } else {
3227
+ tbody.innerHTML = "";
3228
+ parsedRows.forEach((r) => {
3229
+ const tr = document.createElement("tr");
3230
+ parsedCols.forEach((c) => {
3231
+ const key = typeof c === "string" ? c : (c.key || c.label || "");
3232
+ const td = document.createElement("td");
3233
+ td.setAttribute("role", "gridcell");
3234
+ td.setAttribute("tabindex", "0");
3235
+ td.textContent = r && r[key] != null ? r[key] : "";
3236
+ tr.appendChild(td);
3237
+ });
3238
+ tbody.appendChild(tr);
3239
+ });
3240
+ }
3241
+ // Wrap in a scroll container for virtualization of large datasets.
3242
+ let wrap = this.querySelector(".c-data-grid__wrap");
3243
+ if (!wrap) { wrap = document.createElement("div"); wrap.className = "c-data-grid__wrap"; wrap.style.maxHeight = "400px"; wrap.style.overflow = "auto"; }
3244
+ if (table.parentNode !== wrap) wrap.appendChild(table);
3245
+ if (wrap.parentNode !== this) this.appendChild(wrap);
3246
+ }
3247
+ _rowHeight() {
3248
+ const h = Number(this.getAttribute("row-height"));
3249
+ return Number.isFinite(h) && h > 0 ? h : 32;
3250
+ }
3251
+ _renderDataGridWindow(scrollTop) {
3252
+ const table = this.querySelector(".c-data-grid__table");
3253
+ const tbody = table && table.querySelector("tbody");
3254
+ if (!tbody) return;
3255
+ const cols = this._dgCols || [];
3256
+ const rows = this._dgRows || [];
3257
+ const rh = this._rowHeight();
3258
+ const viewport = 400;
3259
+ const visibleCount = Math.ceil(viewport / rh) + 6;
3260
+ let start = Math.floor((scrollTop || 0) / rh);
3261
+ if (start < 0) start = 0;
3262
+ if (start > Math.max(0, rows.length - visibleCount)) start = Math.max(0, rows.length - visibleCount);
3263
+ const end = Math.min(rows.length, start + visibleCount);
1876
3264
  tbody.innerHTML = "";
1877
- parsedRows.forEach((r) => {
3265
+ // top spacer
3266
+ if (start > 0) {
3267
+ const sp = document.createElement("tr");
3268
+ const td = document.createElement("td");
3269
+ td.colSpan = Math.max(1, cols.length);
3270
+ td.style.blockSize = (start * rh) + "px";
3271
+ td.style.padding = "0";
3272
+ sp.appendChild(td);
3273
+ tbody.appendChild(sp);
3274
+ }
3275
+ for (let i = start; i < end; i++) {
3276
+ const r = rows[i];
1878
3277
  const tr = document.createElement("tr");
1879
- parsedCols.forEach((c) => {
3278
+ tr.dataset.index = String(i);
3279
+ cols.forEach((c) => {
1880
3280
  const key = typeof c === "string" ? c : (c.key || c.label || "");
1881
3281
  const td = document.createElement("td");
3282
+ td.setAttribute("role", "gridcell");
3283
+ td.setAttribute("tabindex", "0");
1882
3284
  td.textContent = r && r[key] != null ? r[key] : "";
1883
3285
  tr.appendChild(td);
1884
3286
  });
1885
3287
  tbody.appendChild(tr);
3288
+ }
3289
+ if (end < rows.length) {
3290
+ const sp = document.createElement("tr");
3291
+ const td = document.createElement("td");
3292
+ td.colSpan = Math.max(1, cols.length);
3293
+ td.style.blockSize = ((rows.length - end) * rh) + "px";
3294
+ td.style.padding = "0";
3295
+ sp.appendChild(td);
3296
+ tbody.appendChild(sp);
3297
+ }
3298
+ }
3299
+ enhance() {
3300
+ if (this._wiredDataGrid) return;
3301
+ this._wiredDataGrid = true;
3302
+ const wrap = () => this.querySelector(".c-data-grid__wrap");
3303
+ const onScroll = () => {
3304
+ const w = wrap();
3305
+ if (w && this.hasAttribute("virtual")) this._renderDataGridWindow(w.scrollTop);
3306
+ };
3307
+ // attach after render creates wrap; use delegated listener on host
3308
+ this.addEventListener("scroll", (e) => {
3309
+ const w = e.target && e.target.classList && e.target.classList.contains("c-data-grid__wrap") ? e.target : null;
3310
+ if (w && this.hasAttribute("virtual")) this._renderDataGridWindow(w.scrollTop);
3311
+ }, true);
3312
+ let sortCol = -1, sortDir = "asc";
3313
+ this.addEventListener("keydown", (e) => {
3314
+ const cell = e.target && e.target.closest ? e.target.closest("[role='gridcell'], [role='columnheader']") : null;
3315
+ if (!cell || !this.contains(cell)) return;
3316
+ const row = cell.parentElement;
3317
+ const table = this.querySelector(".c-data-grid__table");
3318
+ if (!table) return;
3319
+ const rows = Array.from(table.querySelectorAll("tr"));
3320
+ const ri = rows.indexOf(row);
3321
+ const ci = Array.from(row.children).indexOf(cell);
3322
+ let target = null;
3323
+ if (e.key === "ArrowRight") target = row.children[ci + 1];
3324
+ else if (e.key === "ArrowLeft") target = row.children[ci - 1];
3325
+ else if (e.key === "ArrowDown") target = rows[ri + 1] && rows[ri + 1].children[ci];
3326
+ else if (e.key === "ArrowUp") target = rows[ri - 1] && rows[ri - 1].children[ci];
3327
+ if (target) { e.preventDefault(); try { target.focus(); } catch (err) {} }
3328
+ });
3329
+ this.addEventListener("click", (e) => {
3330
+ const tr = e.target && e.target.closest ? e.target.closest("tr") : null;
3331
+ const th = e.target && e.target.closest ? e.target.closest("th") : null;
3332
+ if (tr && this.contains(tr) && !th) {
3333
+ const idx = Array.from(tr.parentElement.children).indexOf(tr);
3334
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { row: idx } }));
3335
+ }
3336
+ if (th && this.contains(th)) {
3337
+ const idx = Array.from(th.parentElement.children).indexOf(th);
3338
+ if (sortCol === idx) sortDir = sortDir === "asc" ? "desc" : "asc";
3339
+ else { sortCol = idx; sortDir = "asc"; }
3340
+ // Re-render sorted rows.
3341
+ const table = this.querySelector(".c-data-grid__table");
3342
+ const tbody = table && table.querySelector("tbody");
3343
+ const thead = table && table.querySelector("thead");
3344
+ if (tbody && thead) {
3345
+ const cols = Array.from(thead.querySelectorAll("th")).map((h) => h.textContent);
3346
+ const rows = Array.from(tbody.querySelectorAll("tr")).map((tr) => Array.from(tr.querySelectorAll("td")).map((td) => td.textContent));
3347
+ rows.sort((a, b) => {
3348
+ const va = a[idx] || "", vb = b[idx] || "";
3349
+ const na = Number(va), nb = Number(vb);
3350
+ const cmp = (!isNaN(na) && !isNaN(nb)) ? na - nb : String(va).localeCompare(String(vb));
3351
+ return sortDir === "asc" ? cmp : -cmp;
3352
+ });
3353
+ tbody.innerHTML = "";
3354
+ rows.forEach((r) => {
3355
+ const tr = document.createElement("tr");
3356
+ r.forEach((v) => { const td = document.createElement("td"); td.textContent = v; tr.appendChild(td); });
3357
+ tbody.appendChild(tr);
3358
+ });
3359
+ }
3360
+ // Update aria-sort on headers.
3361
+ Array.from(thead.querySelectorAll("th")).forEach((h, i) => {
3362
+ h.setAttribute("aria-sort", i === idx ? (sortDir === "asc" ? "ascending" : "descending") : "none");
3363
+ });
3364
+ this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: idx, direction: sortDir } }));
3365
+ }
3366
+ });
3367
+ this.addEventListener("pointerdown", (e) => {
3368
+ if (!this.hasAttribute("resizable")) return;
3369
+ const th = e.target && e.target.closest ? e.target.closest("th[data-resizable]") : null;
3370
+ if (!th || !this.contains(th) || th.getBoundingClientRect().right - e.clientX > 10) return;
3371
+ e.preventDefault();
3372
+ const startX = e.clientX;
3373
+ const startWidth = th.getBoundingClientRect().width;
3374
+ const index = Array.from(th.parentElement.children).indexOf(th);
3375
+ const move = (event) => {
3376
+ const width = Math.max(48, startWidth + event.clientX - startX);
3377
+ const table = this.querySelector(".c-data-grid__table");
3378
+ if (table) Array.from(table.rows).forEach((row) => { if (row.children[index]) row.children[index].style.inlineSize = width + "px"; });
3379
+ };
3380
+ const stop = () => window.removeEventListener("pointermove", move);
3381
+ window.addEventListener("pointermove", move);
3382
+ window.addEventListener("pointerup", stop, { once: true });
3383
+ onDispose(this, stop);
1886
3384
  });
1887
- if (table.parentNode !== this) this.appendChild(table);
1888
3385
  }
1889
3386
  }
1890
3387
  define("contour-data-grid", ContourDataGrid);
1891
3388
 
3389
+ /**
3390
+ * Tree Grid: web component wrapper.
3391
+ * Attributes: `items`, `expanded`.
3392
+ */
1892
3393
  class ContourTreeGrid extends ContourBase {
1893
- static get observed() { return ["items"]; }
1894
- static get properties() { return { items: { attribute: "items" } }; }
3394
+ static get updateMode() { return "keyed"; }
3395
+ static get observed() { return ["items", "expanded"]; }
3396
+ static get properties() { return { items: { attribute: "items" }, expanded: { attribute: "expanded" } }; }
3397
+ _expandedSet() {
3398
+ const raw = this.getAttribute("expanded");
3399
+ if (!raw) return new Set();
3400
+ try { return new Set(JSON.parse(raw)); } catch (e) { return new Set([raw]); }
3401
+ }
1895
3402
  render() {
1896
3403
  this.classList.add("c-tree-grid");
1897
- const table = this.ensure(".c-tree-grid__table", () => { const el = document.createElement("table"); el.className = "c-table c-tree-grid__table"; return el; });
3404
+ const table = this.ensure(".c-tree-grid__table", () => { const el = document.createElement("table"); el.className = "c-table c-tree-grid__table"; el.setAttribute("role", "treegrid"); return el; });
3405
+ table.setAttribute("aria-label", "Tree grid");
1898
3406
  const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
1899
3407
  if (tbody.parentNode !== table) table.appendChild(tbody);
1900
3408
  const items = this.getAttribute("items");
1901
3409
  let parsed = [];
1902
3410
  try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
3411
+ const expanded = this._expandedSet();
1903
3412
  tbody.innerHTML = "";
1904
- const renderNode = (node, depth) => {
3413
+ const rows = [];
3414
+ const renderNode = (node, depth, path) => {
1905
3415
  const tr = document.createElement("tr");
3416
+ tr.setAttribute("role", "row");
3417
+ tr.setAttribute("tabindex", "0");
3418
+ tr.setAttribute("aria-level", String(depth + 1));
3419
+ tr.dataset.path = path;
3420
+ const hasChildren = !!(node && Array.isArray(node.children) && node.children.length);
3421
+ if (hasChildren) {
3422
+ tr.setAttribute("aria-expanded", expanded.has(path) ? "true" : "false");
3423
+ }
1906
3424
  const td = document.createElement("td");
3425
+ td.setAttribute("role", "gridcell");
1907
3426
  td.style.paddingInlineStart = (depth * 1.25) + "rem";
1908
- td.textContent = (node && (node.label || node.text || node.name)) || "";
3427
+ const label = (node && (node.label || node.text || node.name)) || "";
3428
+ if (hasChildren) {
3429
+ const toggle = document.createElement("button");
3430
+ toggle.type = "button";
3431
+ toggle.className = "c-tree-grid__toggle";
3432
+ toggle.textContent = expanded.has(path) ? "▾" : "▸";
3433
+ toggle.setAttribute("aria-label", (expanded.has(path) ? "Collapse" : "Expand") + " " + label);
3434
+ td.appendChild(toggle);
3435
+ }
3436
+ const span = document.createElement("span");
3437
+ span.className = "c-tree-grid__label";
3438
+ span.textContent = label;
3439
+ td.appendChild(span);
1909
3440
  tr.appendChild(td);
1910
3441
  tbody.appendChild(tr);
1911
- if (node && Array.isArray(node.children)) node.children.forEach((c) => renderNode(c, depth + 1));
3442
+ rows.push(tr);
3443
+ if (hasChildren && expanded.has(path)) {
3444
+ node.children.forEach((c, i) => renderNode(c, depth + 1, path + "." + i));
3445
+ }
1912
3446
  };
1913
- parsed.forEach((n) => renderNode(n, 0));
3447
+ parsed.forEach((n, i) => renderNode(n, 0, String(i)));
1914
3448
  if (table.parentNode !== this) this.appendChild(table);
1915
3449
  }
3450
+ enhance() {
3451
+ if (this._wiredTreeGrid) return;
3452
+ this._wiredTreeGrid = true;
3453
+ const rows = () => Array.from(this.querySelectorAll("tr[role='row']"));
3454
+ this.addEventListener("click", (e) => {
3455
+ const toggle = e.target && e.target.closest ? e.target.closest(".c-tree-grid__toggle") : null;
3456
+ const tr = e.target && e.target.closest ? e.target.closest("tr[role='row']") : null;
3457
+ if (!tr || !this.contains(tr)) return;
3458
+ const path = tr.dataset.path;
3459
+ if (toggle) {
3460
+ e.preventDefault();
3461
+ const expanded = this._expandedSet();
3462
+ if (expanded.has(path)) expanded.delete(path); else expanded.add(path);
3463
+ this.setAttribute("expanded", JSON.stringify([...expanded]));
3464
+ this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: expanded.has(path) } }));
3465
+ } else {
3466
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { path } }));
3467
+ }
3468
+ });
3469
+ this.addEventListener("keydown", (e) => {
3470
+ const tr = e.target && e.target.closest ? e.target.closest("tr[role='row']") : null;
3471
+ if (!tr || !this.contains(tr)) return;
3472
+ const all = rows();
3473
+ const idx = all.indexOf(tr);
3474
+ const path = tr.dataset.path;
3475
+ const hasChildren = tr.getAttribute("aria-expanded") !== null;
3476
+ const expanded = this._expandedSet();
3477
+ if (e.key === "ArrowRight" && hasChildren && !expanded.has(path)) {
3478
+ e.preventDefault();
3479
+ expanded.add(path);
3480
+ this.setAttribute("expanded", JSON.stringify([...expanded]));
3481
+ this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: true } }));
3482
+ } else if (e.key === "ArrowLeft" && hasChildren && expanded.has(path)) {
3483
+ e.preventDefault();
3484
+ expanded.delete(path);
3485
+ this.setAttribute("expanded", JSON.stringify([...expanded]));
3486
+ this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: false } }));
3487
+ } else if (e.key === "ArrowDown") {
3488
+ e.preventDefault();
3489
+ if (all[idx + 1]) try { all[idx + 1].focus(); } catch (err) {}
3490
+ } else if (e.key === "ArrowUp") {
3491
+ e.preventDefault();
3492
+ if (all[idx - 1]) try { all[idx - 1].focus(); } catch (err) {}
3493
+ } else if (e.key === "Enter" || e.key === " ") {
3494
+ e.preventDefault();
3495
+ const toggle = tr.querySelector(".c-tree-grid__toggle");
3496
+ if (toggle) toggle.click();
3497
+ }
3498
+ });
3499
+ }
1916
3500
  }
1917
3501
  define("contour-tree-grid", ContourTreeGrid);