contour-ds 1.1.2 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +30 -2
  2. package/dist/agent-rules.json +5 -1
  3. package/dist/build-manifest.json +94 -93
  4. package/dist/contour-wc.esm.js +4443 -534
  5. package/dist/contour-wc.esm.min.js +1 -1
  6. package/dist/contour-wc.js +4441 -528
  7. package/dist/contour-wc.min.js +1 -1
  8. package/dist/contour.components.json +4054 -171
  9. package/dist/contour.css +1325 -565
  10. package/dist/contour.d.ts +119 -62
  11. package/dist/contour.esm.js +23 -0
  12. package/dist/contour.esm.min.js +1 -1
  13. package/dist/contour.js +23 -0
  14. package/dist/contour.min.css +1 -1
  15. package/dist/contour.min.js +1 -1
  16. package/dist/contour.tokens.json +47 -2
  17. package/dist/docs/actions.md +6 -2
  18. package/dist/docs/affordances.md +19 -3
  19. package/dist/docs/apireference.md +30 -0
  20. package/dist/docs/colour.md +2 -2
  21. package/dist/docs/componentindex.md +39 -0
  22. package/dist/docs/data.md +38 -3
  23. package/dist/docs/docs.md +6 -2
  24. package/dist/docs/feedback.md +13 -3
  25. package/dist/docs/field.md +7 -2
  26. package/dist/docs/forms.md +35 -3
  27. package/dist/docs/index.json +44 -75
  28. package/dist/docs/install.md +4 -2
  29. package/dist/docs/landing.md +3 -2
  30. package/dist/docs/mapengine.md +9 -3
  31. package/dist/docs/motion.md +5 -2
  32. package/dist/docs/navigation.md +10 -3
  33. package/dist/docs/overlays.md +26 -3
  34. package/dist/docs/overview.md +2 -2
  35. package/dist/docs/patterns.md +38 -3
  36. package/dist/docs/playground.md +5 -2
  37. package/dist/docs/principles.md +2 -2
  38. package/dist/docs/recipes.md +7 -3
  39. package/dist/docs/space.md +2 -2
  40. package/dist/docs/status.md +19 -3
  41. package/dist/docs/surfaces.md +7 -3
  42. package/dist/docs/theming.md +5 -2
  43. package/dist/docs/type.md +2 -2
  44. package/dist/docs/webcomponents.md +26 -7
  45. package/dist/map-chrome.mapbox.css +4 -4
  46. package/dist/map-chrome.maplibre.css +4 -4
  47. package/dist/registry/items/contour-core.json +2 -2
  48. package/dist/registry/items/contour-data.json +2 -2
  49. package/dist/registry/items/contour-docs.json +2 -2
  50. package/dist/registry/items/contour-landing.json +2 -2
  51. package/dist/registry/registry.json +8 -8
  52. package/dist/surfaces/contour-core.min.css +1 -1
  53. package/dist/surfaces/contour-data.min.css +1 -1
  54. package/dist/surfaces/contour-docs.min.css +1 -1
  55. package/dist/surfaces/contour-landing.min.css +1 -1
  56. package/dist/wc/behaviours.mjs +69 -11
  57. package/dist/wc/content.mjs +163 -8
  58. package/dist/wc/core.mjs +177 -36
  59. package/dist/wc/dashboard.mjs +69 -4
  60. package/dist/wc/data.mjs +933 -128
  61. package/dist/wc/docs.mjs +118 -0
  62. package/dist/wc/feedback.mjs +75 -13
  63. package/dist/wc/forms.mjs +371 -34
  64. package/dist/wc/index.mjs +31 -3
  65. package/dist/wc/interaction.mjs +11 -6
  66. package/dist/wc/map.mjs +142 -38
  67. package/dist/wc/misc.mjs +29 -1
  68. package/dist/wc/navigation.mjs +424 -75
  69. package/dist/wc/registration.mjs +8 -4
  70. package/dist/wc/shadow.mjs +29 -12
  71. package/dist/wc/states.mjs +15 -0
  72. package/dist/wc/svg.mjs +10 -0
  73. package/dist/wc/ui.mjs +1767 -129
  74. 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,10 +1089,12 @@ 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
- br.textContent = String(b);
1095
+ const span = document.createElement("span"); span.textContent = String(b); br.appendChild(span);
1096
+ const inp = document.createElement("input"); inp.type = "number"; inp.className = "c-style-panel__breaks c-input"; inp.setAttribute("aria-label", "Class lower bound"); inp.value = String(b);
1097
+ br.appendChild(inp);
814
1098
  breaksWrap.appendChild(br);
815
1099
  });
816
1100
  body.appendChild(breaksWrap);
@@ -820,7 +1104,7 @@ class ContourStylePanel extends ContourBase {
820
1104
  let colors = null;
821
1105
  if (colorsAttr) { try { colors = JSON.parse(colorsAttr); } catch (e) { colors = colorsAttr.split(",").map((s) => s.trim()); } }
822
1106
  if (Array.isArray(colors)) {
823
- const list = document.createElement("div"); list.className = "c-style-panel__colors colours";
1107
+ const list = document.createElement("div"); list.className = "c-style-panel__colors";
824
1108
  colors.forEach((c, i) => {
825
1109
  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
1110
  sw.value = c;
@@ -830,8 +1114,8 @@ class ContourStylePanel extends ContourBase {
830
1114
  body.appendChild(list);
831
1115
  }
832
1116
  // 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";
1117
+ const actions = document.createElement("div"); actions.className = "c-style-panel__actions";
1118
+ const applyBtn = document.createElement("button"); applyBtn.type = "button"; applyBtn.className = "c-btn c-btn--primary"; applyBtn.textContent = "Apply";
835
1119
  const revertBtn = document.createElement("button"); revertBtn.type = "button"; revertBtn.className = "c-btn"; revertBtn.textContent = "Revert";
836
1120
  actions.appendChild(applyBtn); actions.appendChild(revertBtn);
837
1121
  body.appendChild(actions);
@@ -870,11 +1154,13 @@ class ContourStylePanel extends ContourBase {
870
1154
  const input = document.createElement("input");
871
1155
  input.type = "color";
872
1156
  input.className = "c-style-panel__color";
1157
+ input.setAttribute("aria-label", "Colour for " + (typeof l === "string" ? l : (l.name || l.label || "layer")));
873
1158
  if (typeof l === "object" && l.color) input.value = l.color;
874
1159
  row.appendChild(input);
875
1160
  // classification method selector
876
1161
  const clsSel = document.createElement("select");
877
1162
  clsSel.className = "c-style-panel__classification";
1163
+ clsSel.setAttribute("aria-label", "Classification method");
878
1164
  ["equal","quantile","jenks","manual"].forEach((m) => { const o = document.createElement("option"); o.value = m; o.textContent = m; clsSel.appendChild(o); });
879
1165
  if (typeof l === "object" && l.classification) clsSel.value = l.classification;
880
1166
  row.appendChild(clsSel);
@@ -882,6 +1168,7 @@ class ContourStylePanel extends ContourBase {
882
1168
  const pal = document.createElement("input");
883
1169
  pal.type = "text";
884
1170
  pal.className = "c-style-panel__palette";
1171
+ pal.setAttribute("aria-label", "Palette");
885
1172
  pal.placeholder = "palette";
886
1173
  if (typeof l === "object" && l.palette) pal.value = l.palette;
887
1174
  row.appendChild(pal);
@@ -896,6 +1183,7 @@ class ContourStylePanel extends ContourBase {
896
1183
  const op = document.createElement("input");
897
1184
  op.type = "range";
898
1185
  op.className = "c-style-panel__opacity";
1186
+ op.setAttribute("aria-label", "Opacity");
899
1187
  op.min = "0"; op.max = "100";
900
1188
  op.value = (typeof l === "object" && l.opacity != null) ? l.opacity : "100";
901
1189
  row.appendChild(op);
@@ -917,6 +1205,10 @@ class ContourStylePanel extends ContourBase {
917
1205
  this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value, layer: name }, bubbles: true, composed: true }));
918
1206
  } else if (t.classList.contains("c-style-panel__opacity")) {
919
1207
  this.dispatchEvent(new CustomEvent("contour:layer-opacity", { detail: { name, opacity: Number(t.value) }, bubbles: true, composed: true }));
1208
+ } else if (t.classList.contains("c-style-panel__property")) {
1209
+ this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: t.value, layer: name, property: "property" }, bubbles: true, composed: true }));
1210
+ } else if (t.classList.contains("c-style-panel__n")) {
1211
+ this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: Number(t.value), layer: name, property: "n" }, bubbles: true, composed: true }));
920
1212
  }
921
1213
  });
922
1214
  this.addEventListener("input", (e) => {
@@ -941,6 +1233,10 @@ class ContourStylePanel extends ContourBase {
941
1233
  }
942
1234
  define("contour-style-panel", ContourStylePanel);
943
1235
 
1236
+ /**
1237
+ * Responsive Content: web component wrapper.
1238
+ * Attributes: `breakpoint`.
1239
+ */
944
1240
  class ContourResponsiveContent extends ContourBase {
945
1241
  static get observed() { return ["breakpoint"]; }
946
1242
  static get properties() { return { breakpoint: { attribute: "breakpoint" } }; }
@@ -952,6 +1248,10 @@ class ContourResponsiveContent extends ContourBase {
952
1248
  }
953
1249
  define("contour-responsive-content", ContourResponsiveContent);
954
1250
 
1251
+ /**
1252
+ * Avatar Group: web component wrapper.
1253
+ * Attributes: `items`, `max`.
1254
+ */
955
1255
  class ContourAvatarGroup extends ContourBase {
956
1256
  static get observed() { return ["items", "max"]; }
957
1257
  static get properties() { return { items: { attribute: "items" }, max: { attribute: "max", type: Number } }; }
@@ -969,7 +1269,7 @@ class ContourAvatarGroup extends ContourBase {
969
1269
  av.className = "c-avatar";
970
1270
  const name = typeof it === "string" ? it : (it.name || it.label || "");
971
1271
  av.textContent = name.slice(0, 2).toUpperCase();
972
- if (typeof it === "object" && it.color) av.style.background = it.color;
1272
+ if (typeof it === "object" && it.color) { av.style.background = it.color; av.dataset.color = it.color; }
973
1273
  this.appendChild(av);
974
1274
  });
975
1275
  if (parsed.length > max) {
@@ -984,6 +1284,10 @@ class ContourAvatarGroup extends ContourBase {
984
1284
  }
985
1285
  define("contour-avatar-group", ContourAvatarGroup);
986
1286
 
1287
+ /**
1288
+ * Divider: web component wrapper.
1289
+ * Attributes: `label`, `orientation`.
1290
+ */
987
1291
  class ContourDivider extends ContourBase {
988
1292
  static get observed() { return ["label", "orientation"]; }
989
1293
  static get properties() { return { label: { attribute: "label" }, orientation: { attribute: "orientation" } }; }
@@ -1000,6 +1304,10 @@ class ContourDivider extends ContourBase {
1000
1304
  }
1001
1305
  define("contour-divider", ContourDivider);
1002
1306
 
1307
+ /**
1308
+ * Status Light: web component wrapper.
1309
+ * Attributes: `status`, `label`.
1310
+ */
1003
1311
  class ContourStatusLight extends ContourBase {
1004
1312
  static get observed() { return ["status", "label"]; }
1005
1313
  static get properties() { return { status: { attribute: "status" }, label: { attribute: "label" } }; }
@@ -1016,6 +1324,10 @@ class ContourStatusLight extends ContourBase {
1016
1324
  }
1017
1325
  define("contour-status-light", ContourStatusLight);
1018
1326
 
1327
+ /**
1328
+ * Split Button: web component wrapper.
1329
+ * Attributes: `label`, `menu`.
1330
+ */
1019
1331
  class ContourSplitButton extends ContourBase {
1020
1332
  static get observed() { return ["label", "menu"]; }
1021
1333
  static get properties() { return { label: { attribute: "label" }, menu: { attribute: "menu" } }; }
@@ -1051,19 +1363,42 @@ class ContourSplitButton extends ContourBase {
1051
1363
  this.addEventListener("click", (e) => {
1052
1364
  const t = toggle();
1053
1365
  if (e.target === t || (t && t.contains(e.target))) {
1366
+ const m = menu();
1367
+ 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 } })); }
1368
+ }
1369
+ const item = e.target && e.target.closest ? e.target.closest(".c-menu__item") : null;
1370
+ if (item && this.contains(item)) {
1371
+ const m = menu();
1372
+ if (m) { m.hidden = true; const t = toggle(); if (t) t.setAttribute("aria-expanded", "false"); }
1373
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { label: item.textContent } }));
1374
+ }
1375
+ });
1376
+ this.addEventListener("keydown", (e) => {
1377
+ const t = toggle();
1378
+ if ((e.target === t || (t && t.contains(e.target))) && (e.key === "Enter" || e.key === " ")) {
1379
+ e.preventDefault();
1054
1380
  const m = menu();
1055
1381
  if (m) { m.hidden = !m.hidden; t.setAttribute("aria-expanded", String(!m.hidden)); }
1382
+ } else if (e.key === "Escape") {
1383
+ const m = menu();
1384
+ if (m && !m.hidden) { m.hidden = true; if (t) t.setAttribute("aria-expanded", "false"); }
1056
1385
  }
1057
1386
  });
1058
- document.addEventListener("click", (e) => {
1387
+ const docClick = (e) => {
1059
1388
  const m = menu();
1060
1389
  const t = toggle();
1061
1390
  if (m && !m.hidden && !this.contains(e.target)) { m.hidden = true; if (t) t.setAttribute("aria-expanded", "false"); }
1062
- });
1391
+ };
1392
+ document.addEventListener("click", docClick);
1393
+ onDispose(this, () => document.removeEventListener("click", docClick));
1063
1394
  }
1064
1395
  }
1065
1396
  define("contour-split-button", ContourSplitButton);
1066
1397
 
1398
+ /**
1399
+ * Palette Editor: web component wrapper.
1400
+ * Attributes: `colors`.
1401
+ */
1067
1402
  class ContourPaletteEditor extends ContourBase {
1068
1403
  static get observed() { return ["colors"]; }
1069
1404
  static get properties() { return { colors: { attribute: "colors" } }; }
@@ -1079,6 +1414,7 @@ class ContourPaletteEditor extends ContourBase {
1079
1414
  sw.className = "c-palette-editor__swatch c-swatch";
1080
1415
  sw.type = "button";
1081
1416
  sw.style.background = typeof c === "string" ? c : (c.color || c.value || "");
1417
+ sw.dataset.color = typeof c === "string" ? c : (c.color || c.value || "");
1082
1418
  sw.setAttribute("aria-label", typeof c === "string" ? c : (c.name || c.label || "color"));
1083
1419
  this.appendChild(sw);
1084
1420
  });
@@ -1091,27 +1427,50 @@ class ContourPaletteEditor extends ContourBase {
1091
1427
  this.addEventListener("click", (e) => {
1092
1428
  const sw = e.target && e.target.closest ? e.target.closest(".c-palette-editor__swatch") : null;
1093
1429
  if (sw && this.contains(sw)) {
1094
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { color: sw.style.background } }));
1430
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { color: (sw.dataset && sw.dataset.color) || sw.style.background } }));
1095
1431
  }
1096
1432
  });
1433
+ this.addEventListener("keydown", (e) => {
1434
+ const swatches = Array.from(this.querySelectorAll(".c-palette-editor__swatch"));
1435
+ const active = document.activeElement;
1436
+ const idx = swatches.indexOf(active);
1437
+ 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) {} }
1438
+ 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) {} }
1439
+ else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); if (active && active.classList.contains("c-palette-editor__swatch")) active.click(); }
1440
+ });
1097
1441
  }
1098
1442
  }
1099
1443
  define("contour-palette-editor", ContourPaletteEditor);
1100
1444
 
1445
+ /**
1446
+ * Date Range: web component wrapper.
1447
+ * Attributes: `start`, `end`, `label`, `time`, `min`, `max`, `locale`.
1448
+ */
1101
1449
  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" } }; }
1450
+ static get observed() { return ["start", "end", "label", "time", "min", "max", "locale"]; }
1451
+ 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
1452
  render() {
1105
1453
  this.classList.add("c-date-range");
1454
+ this.setAttribute("role", "group");
1455
+ this.setAttribute("aria-label", "Date range");
1106
1456
  const label = this.getAttribute("label");
1107
1457
  if (label) {
1108
1458
  const l = this.ensure(".c-date-range__label", () => { const el = document.createElement("span"); el.className = "c-date-range__label"; return el; });
1109
1459
  l.textContent = label;
1110
1460
  }
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; });
1461
+ const start = this.ensure(".c-date-range__start", () => { const el = document.createElement("input"); el.className = "c-input c-date-range__start"; return el; });
1462
+ start.type = this.hasAttribute("time") ? "datetime-local" : "date";
1112
1463
  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; });
1464
+ const end = this.ensure(".c-date-range__end", () => { const el = document.createElement("input"); el.className = "c-input c-date-range__end"; return el; });
1465
+ end.type = start.type;
1114
1466
  end.value = this.getAttribute("end") || "";
1467
+ const min = this.getAttribute("min");
1468
+ const max = this.getAttribute("max");
1469
+ [start, end].forEach((input) => {
1470
+ if (min) input.min = min; else input.removeAttribute("min");
1471
+ if (max) input.max = max; else input.removeAttribute("max");
1472
+ if (this.getAttribute("locale")) input.lang = this.getAttribute("locale");
1473
+ });
1115
1474
  }
1116
1475
  enhance() {
1117
1476
  if (this._wiredDateRange) return;
@@ -1126,6 +1485,10 @@ class ContourDateRange extends ContourBase {
1126
1485
  }
1127
1486
  define("contour-date-range", ContourDateRange);
1128
1487
 
1488
+ /**
1489
+ * Shortcut: web component wrapper.
1490
+ * Attributes: `key`, `label`.
1491
+ */
1129
1492
  class ContourShortcut extends ContourBase {
1130
1493
  static get observed() { return ["key", "label"]; }
1131
1494
  static get properties() { return { key: { attribute: "key" }, label: { attribute: "label" } }; }
@@ -1147,22 +1510,30 @@ class ContourShortcut extends ContourBase {
1147
1510
  this._wiredShortcut = true;
1148
1511
  const key = this.getAttribute("key");
1149
1512
  if (key) {
1150
- document.addEventListener("keydown", (e) => {
1513
+ const handler = (e) => {
1151
1514
  if (e.key === key && (e.metaKey || e.ctrlKey)) {
1152
1515
  e.preventDefault();
1153
1516
  this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true }));
1154
1517
  }
1155
- });
1518
+ };
1519
+ document.addEventListener("keydown", handler);
1520
+ onDispose(this, () => document.removeEventListener("keydown", handler));
1156
1521
  }
1157
1522
  }
1158
1523
  }
1159
1524
  define("contour-shortcut", ContourShortcut);
1160
1525
 
1526
+ /**
1527
+ * Popover: web component wrapper.
1528
+ * Attributes: `title`, `content`.
1529
+ */
1161
1530
  class ContourPopover extends ContourBase {
1162
1531
  static get observed() { return ["title", "content"]; }
1163
1532
  static get properties() { return { title: { attribute: "title" }, content: { attribute: "content" } }; }
1164
1533
  render() {
1165
1534
  this.classList.add("c-popover");
1535
+ if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
1536
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Popover");
1166
1537
  if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
1167
1538
  if (!this.id) this.id = contourId("popover");
1168
1539
  const title = this.getAttribute("title");
@@ -1176,21 +1547,141 @@ class ContourPopover extends ContourBase {
1176
1547
  c.textContent = content;
1177
1548
  }
1178
1549
  }
1550
+ enhance() {
1551
+ if (this._wiredPopover) return;
1552
+ this._wiredPopover = true;
1553
+ const close = () => { try { this.hidePopover(); } catch (e) {} this.classList.remove("is-open"); this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); };
1554
+ const keyHandler = (e) => {
1555
+ const open = this.classList.contains("is-open") || this.matches(":popover-open");
1556
+ if (!open) return;
1557
+ if (e.key === "Escape") { e.preventDefault(); close(); return; }
1558
+ // Focus trap: keep Tab within the popover.
1559
+ if (e.key === "Tab") {
1560
+ const focusable = Array.from(this.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));
1561
+ if (!focusable.length) { e.preventDefault(); return; }
1562
+ const first = focusable[0];
1563
+ const last = focusable[focusable.length - 1];
1564
+ if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
1565
+ else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
1566
+ }
1567
+ };
1568
+ document.addEventListener("keydown", keyHandler);
1569
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
1570
+ // Nested popover support: when a nested popover opens, mark this one as parent.
1571
+ this.addEventListener("contour:show", (e) => {
1572
+ if (e.target && e.target !== this && this.contains(e.target)) {
1573
+ this.classList.add("is-parent");
1574
+ }
1575
+ });
1576
+ this.addEventListener("contour:close", (e) => {
1577
+ if (e.target && e.target !== this) {
1578
+ this.classList.remove("is-parent");
1579
+ }
1580
+ });
1581
+ this.addEventListener("click", (e) => {
1582
+ const btn = e.target && e.target.closest ? e.target.closest(".c-popover__close") : null;
1583
+ if (btn && this.contains(btn)) close();
1584
+ });
1585
+ }
1179
1586
  }
1180
1587
  define("contour-popover", ContourPopover);
1181
1588
 
1589
+ /**
1590
+ * Date Picker: web component wrapper.
1591
+ * Attributes: `value`, `range`, `range-start`, `range-end`, `label`, `disabled`, `error`, `help`, `time`, `min`, `max`, `locale`.
1592
+ */
1182
1593
  class ContourDatePicker extends ContourBase {
1183
- static get observed() { return ["value", "label"]; }
1184
- static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" } }; }
1594
+ static get observed() { return ["value", "range", "range-start", "range-end", "label", "disabled", "error", "help", "time", "min", "max", "locale"]; }
1595
+ 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
1596
  render() {
1186
1597
  this.classList.add("c-date-picker");
1598
+ this.setAttribute("role", "group");
1599
+ this.setAttribute("aria-label", "Date picker");
1187
1600
  const label = this.getAttribute("label");
1188
1601
  if (label) {
1189
1602
  const l = this.ensure(".c-date-picker__label", () => { const el = document.createElement("label"); el.className = "c-date-picker__label"; return el; });
1190
1603
  l.textContent = label;
1191
1604
  }
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") || "";
1605
+ const input = this.ensure(".c-date-picker__input", () => { const el = document.createElement("input"); el.className = "c-input c-date-picker__input"; return el; });
1606
+ const range = this.hasAttribute("range");
1607
+ const type = this.hasAttribute("time") ? "datetime-local" : "date";
1608
+ const configure = (control, value, name) => {
1609
+ control.type = type;
1610
+ control.value = value || "";
1611
+ control.setAttribute("aria-label", name);
1612
+ if (this.hasAttribute("min")) control.min = this.getAttribute("min"); else control.removeAttribute("min");
1613
+ if (this.hasAttribute("max")) control.max = this.getAttribute("max"); else control.removeAttribute("max");
1614
+ if (this.hasAttribute("locale")) control.lang = this.getAttribute("locale"); else control.removeAttribute("lang");
1615
+ if (this.hasAttribute("disabled")) control.setAttribute("disabled", ""); else control.removeAttribute("disabled");
1616
+ };
1617
+ configure(input, range ? this.getAttribute("range-start") : this.getAttribute("value"), range ? "Start date" : (label || "Date"));
1618
+ let end = this.querySelector(".c-date-picker__end");
1619
+ if (range) {
1620
+ end = end || document.createElement("input");
1621
+ end.className = "c-input c-date-picker__input c-date-picker__end";
1622
+ configure(end, this.getAttribute("range-end"), "End date");
1623
+ if (end.parentNode !== this) this.appendChild(end);
1624
+ } else if (end) end.remove();
1625
+ if (this.hasAttribute("disabled")) this.classList.add("is-disabled"); else this.classList.remove("is-disabled");
1626
+ const err = this.getAttribute("error");
1627
+ const help = this.getAttribute("help");
1628
+ let msg = this.querySelector(".c-date-picker__message");
1629
+ if (err || help) {
1630
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-date-picker__message"; this.appendChild(msg); }
1631
+ msg.textContent = err || help || "";
1632
+ msg.classList.toggle("c-date-picker__message--error", !!err);
1633
+ } else if (msg) { msg.remove(); }
1634
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
1635
+ // Calendar affordance (R14-22): a toggle + month grid alongside the native input.
1636
+ 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; });
1637
+ let cal = this.querySelector(".c-date-picker__calendar");
1638
+ 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); }
1639
+ }
1640
+ _renderCalendar() {
1641
+ const cal = this.querySelector(".c-date-picker__calendar");
1642
+ if (!cal) return;
1643
+ const input = this.querySelector(".c-date-picker__input");
1644
+ const base = (input && input.value) ? new Date(input.value) : new Date();
1645
+ const month = this._calMonth || new Date(base.getFullYear(), base.getMonth(), 1);
1646
+ this._calMonth = month;
1647
+ const y = month.getFullYear();
1648
+ const m = month.getMonth();
1649
+ const first = new Date(y, m, 1);
1650
+ const startDay = first.getDay();
1651
+ const daysInMonth = new Date(y, m + 1, 0).getDate();
1652
+ cal.innerHTML = "";
1653
+ const header = document.createElement("div");
1654
+ header.className = "c-date-picker__calendar-header";
1655
+ const prev = document.createElement("button"); prev.type = "button"; prev.className = "c-btn c-btn--sm"; prev.textContent = "‹"; prev.setAttribute("aria-label", "Previous month");
1656
+ const title = document.createElement("span"); title.className = "c-date-picker__calendar-title"; title.textContent = month.toLocaleString(this.getAttribute("locale") || undefined, { month: "long", year: "numeric" });
1657
+ const next = document.createElement("button"); next.type = "button"; next.className = "c-btn c-btn--sm"; next.textContent = "›"; next.setAttribute("aria-label", "Next month");
1658
+ header.appendChild(prev); header.appendChild(title); header.appendChild(next);
1659
+ cal.appendChild(header);
1660
+ const grid = document.createElement("div");
1661
+ grid.className = "c-date-picker__calendar-grid";
1662
+ grid.setAttribute("role", "grid");
1663
+ const weekdays = ["Su","Mo","Tu","We","Th","Fr","Sa"];
1664
+ weekdays.forEach((w) => { const h = document.createElement("div"); h.className = "c-date-picker__calendar-weekday"; h.textContent = w; grid.appendChild(h); });
1665
+ 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); }
1666
+ const selected = input ? input.value : "";
1667
+ for (let d = 1; d <= daysInMonth; d++) {
1668
+ const btn = document.createElement("button");
1669
+ btn.type = "button";
1670
+ btn.className = "c-date-picker__calendar-day";
1671
+ btn.textContent = String(d);
1672
+ const iso = `${y}-${String(m + 1).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
1673
+ if (selected && selected.startsWith(iso)) btn.classList.add("is-selected");
1674
+ btn.addEventListener("click", () => {
1675
+ if (input) { input.value = iso; input.dispatchEvent(new Event("change", { bubbles: true })); }
1676
+ cal.setAttribute("hidden", "");
1677
+ const tgl = this.querySelector(".c-date-picker__calendar-toggle");
1678
+ if (tgl) tgl.setAttribute("aria-expanded", "false");
1679
+ });
1680
+ grid.appendChild(btn);
1681
+ }
1682
+ cal.appendChild(grid);
1683
+ prev.addEventListener("click", () => { this._calMonth = new Date(y, m - 1, 1); this._renderCalendar(); });
1684
+ next.addEventListener("click", () => { this._calMonth = new Date(y, m + 1, 1); this._renderCalendar(); });
1194
1685
  }
1195
1686
  enhance() {
1196
1687
  if (this._wiredDatePicker) return;
@@ -1198,26 +1689,49 @@ class ContourDatePicker extends ContourBase {
1198
1689
  this.addEventListener("change", (e) => {
1199
1690
  const t = e.target;
1200
1691
  if (t && t.classList.contains("c-date-picker__input")) {
1201
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: t.value } }));
1692
+ const end = this.querySelector(".c-date-picker__end");
1693
+ const detail = end ? { start: this.querySelector(".c-date-picker__input").value, end: end.value } : { value: t.value };
1694
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail }));
1202
1695
  }
1203
1696
  });
1697
+ const toggle = () => {
1698
+ const cal = this.querySelector(".c-date-picker__calendar");
1699
+ const btn = this.querySelector(".c-date-picker__calendar-toggle");
1700
+ if (!cal) return;
1701
+ const hidden = cal.hasAttribute("hidden");
1702
+ if (hidden) { cal.removeAttribute("hidden"); if (btn) btn.setAttribute("aria-expanded", "true"); this._renderCalendar(); }
1703
+ else { cal.setAttribute("hidden", ""); if (btn) btn.setAttribute("aria-expanded", "false"); }
1704
+ };
1705
+ this.addEventListener("click", (e) => {
1706
+ const btn = e.target && e.target.closest ? e.target.closest(".c-date-picker__calendar-toggle") : null;
1707
+ if (btn && this.contains(btn)) { e.preventDefault(); toggle(); }
1708
+ });
1204
1709
  }
1205
1710
  }
1206
1711
  define("contour-date-picker", ContourDatePicker);
1207
1712
 
1713
+ /**
1714
+ * Rating: web component wrapper.
1715
+ * Attributes: `value`, `max`, `color`.
1716
+ */
1208
1717
  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 } }; }
1718
+ static get observed() { return ["value", "max", "color"]; }
1719
+ static get properties() { return { value: { attribute: "value", type: Number }, max: { attribute: "max", type: Number }, color: { attribute: "color" } }; }
1211
1720
  render() {
1212
1721
  this.classList.add("c-rating");
1722
+ this.setAttribute("role", "radiogroup");
1723
+ this.setAttribute("aria-label", "Rating");
1213
1724
  const max = parseInt(this.getAttribute("max") || "5", 10) || 5;
1214
1725
  const value = parseInt(this.getAttribute("value") || "0", 10) || 0;
1726
+ const color = this.getAttribute("color");
1215
1727
  Array.from(this.querySelectorAll(".c-rating__star")).forEach((n) => n.remove());
1216
1728
  for (let i = 1; i <= max; i++) {
1217
1729
  const star = document.createElement("button");
1218
1730
  star.className = "c-rating__star" + (i <= value ? " c-rating__star--filled" : "");
1219
1731
  star.type = "button";
1220
- star.textContent = "★";
1732
+ star.setAttribute("role", "radio");
1733
+ star.setAttribute("aria-checked", String(i === value));
1734
+ 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
1735
  star.dataset.value = String(i);
1222
1736
  star.setAttribute("aria-label", i + " star" + (i > 1 ? "s" : ""));
1223
1737
  this.appendChild(star);
@@ -1229,18 +1743,45 @@ class ContourRating extends ContourBase {
1229
1743
  this.addEventListener("click", (e) => {
1230
1744
  const star = e.target && e.target.closest ? e.target.closest(".c-rating__star") : null;
1231
1745
  if (star && this.contains(star)) {
1232
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: parseInt(star.dataset.value, 10) } }));
1746
+ const v = parseInt(star.dataset.value, 10);
1747
+ Array.from(this.querySelectorAll(".c-rating__star")).forEach((st) => st.setAttribute("aria-checked", String(parseInt(st.dataset.value, 10) === v)));
1748
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: v } }));
1749
+ }
1750
+ });
1751
+ this.addEventListener("keydown", (e) => {
1752
+ const stars = Array.from(this.querySelectorAll(".c-rating__star"));
1753
+ const active = document.activeElement;
1754
+ const idx = stars.indexOf(active);
1755
+ if (e.key === "ArrowRight" || e.key === "ArrowUp") {
1756
+ e.preventDefault();
1757
+ const next = stars[Math.min(stars.length - 1, idx + 1)] || stars[0];
1758
+ if (next) { try { next.focus(); } catch (err) {} }
1759
+ } else if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
1760
+ e.preventDefault();
1761
+ const prev = stars[Math.max(0, idx - 1)] || stars[stars.length - 1];
1762
+ if (prev) { try { prev.focus(); } catch (err) {} }
1763
+ } else if (e.key === "Enter" || e.key === " ") {
1764
+ e.preventDefault();
1765
+ if (active && active.classList.contains("c-rating__star")) {
1766
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: parseInt(active.dataset.value, 10) } }));
1767
+ }
1233
1768
  }
1234
1769
  });
1235
1770
  }
1236
1771
  }
1237
1772
  define("contour-rating", ContourRating);
1238
1773
 
1774
+ /**
1775
+ * Time Picker: web component wrapper.
1776
+ * Attributes: `value`, `label`, `disabled`, `error`, `help`.
1777
+ */
1239
1778
  class ContourTimePicker extends ContourBase {
1240
- static get observed() { return ["value", "label"]; }
1241
- static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" } }; }
1779
+ static get observed() { return ["value", "label", "disabled", "error", "help"]; }
1780
+ static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
1242
1781
  render() {
1243
1782
  this.classList.add("c-time-picker");
1783
+ this.setAttribute("role", "group");
1784
+ this.setAttribute("aria-label", "Time picker");
1244
1785
  const label = this.getAttribute("label");
1245
1786
  if (label) {
1246
1787
  const l = this.ensure(".c-time-picker__label", () => { const el = document.createElement("label"); el.className = "c-time-picker__label"; return el; });
@@ -1248,6 +1789,21 @@ class ContourTimePicker extends ContourBase {
1248
1789
  }
1249
1790
  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
1791
  input.value = this.getAttribute("value") || "";
1792
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
1793
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
1794
+ const err = this.getAttribute("error");
1795
+ const help = this.getAttribute("help");
1796
+ let msg = this.querySelector(".c-time-picker__message");
1797
+ if (err || help) {
1798
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-time-picker__message"; this.appendChild(msg); }
1799
+ msg.textContent = err || help || "";
1800
+ msg.classList.toggle("c-time-picker__message--error", !!err);
1801
+ } else if (msg) { msg.remove(); }
1802
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
1803
+ // Calendar affordance (R14-22): a toggle + month grid alongside the native input.
1804
+ 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; });
1805
+ let cal = this.querySelector(".c-date-picker__calendar");
1806
+ 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
1807
  }
1252
1808
  enhance() {
1253
1809
  if (this._wiredTimePicker) return;
@@ -1262,18 +1818,79 @@ class ContourTimePicker extends ContourBase {
1262
1818
  }
1263
1819
  define("contour-time-picker", ContourTimePicker);
1264
1820
 
1821
+ /**
1822
+ * Color Picker: web component wrapper.
1823
+ * Attributes: `value`, `label`, `disabled`, `error`, `help`, `alpha`, `presets`.
1824
+ */
1265
1825
  class ContourColorPicker extends ContourBase {
1266
- static get observed() { return ["value", "label"]; }
1267
- static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" } }; }
1826
+ static get observed() { return ["value", "label", "disabled", "error", "help", "alpha", "presets"]; }
1827
+ 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
1828
  render() {
1269
1829
  this.classList.add("c-color-picker");
1830
+ this.setAttribute("role", "group");
1831
+ this.setAttribute("aria-label", "Color picker");
1270
1832
  const label = this.getAttribute("label");
1271
1833
  if (label) {
1272
1834
  const l = this.ensure(".c-color-picker__label", () => { const el = document.createElement("label"); el.className = "c-color-picker__label"; return el; });
1273
1835
  l.textContent = label;
1274
1836
  }
1275
1837
  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";
1838
+ input.value = (this.getAttribute("value") || "#000000").slice(0, 7);
1839
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
1840
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
1841
+ // Alpha channel (optional).
1842
+ if (this.hasAttribute("alpha")) {
1843
+ 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; });
1844
+ const v = this.getAttribute("value") || "#000000";
1845
+ const a = v.length === 9 ? parseInt(v.slice(7, 9), 16) / 255 : 1;
1846
+ alpha.value = String(a);
1847
+ alpha.setAttribute("aria-label", "Alpha");
1848
+ } else {
1849
+ const a = this.querySelector(".c-color-picker__alpha");
1850
+ if (a) a.remove();
1851
+ }
1852
+ // Presets.
1853
+ const presetsAttr = this.getAttribute("presets");
1854
+ let presets = [];
1855
+ if (presetsAttr) { try { presets = JSON.parse(presetsAttr); } catch (e) { presets = []; } }
1856
+ const oldPresets = this.querySelector(".c-color-picker__presets");
1857
+ if (oldPresets) oldPresets.remove();
1858
+ if (Array.isArray(presets) && presets.length) {
1859
+ const wrap = document.createElement("div");
1860
+ wrap.className = "c-color-picker__presets";
1861
+ presets.forEach((c) => {
1862
+ const btn = document.createElement("button");
1863
+ btn.type = "button";
1864
+ btn.className = "c-color-picker__preset";
1865
+ btn.style.background = c;
1866
+ btn.dataset.color = c;
1867
+ btn.setAttribute("aria-label", "Preset " + c);
1868
+ wrap.appendChild(btn);
1869
+ });
1870
+ this.appendChild(wrap);
1871
+ }
1872
+ // Eyedropper (if supported).
1873
+ if (typeof window !== "undefined" && "EyeDropper" in window) {
1874
+ 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; });
1875
+ if (this.hasAttribute("disabled")) ed.setAttribute("disabled", "");
1876
+ else ed.removeAttribute("disabled");
1877
+ } else {
1878
+ const ed = this.querySelector(".c-color-picker__eyedropper");
1879
+ if (ed) ed.remove();
1880
+ }
1881
+ const err = this.getAttribute("error");
1882
+ const help = this.getAttribute("help");
1883
+ let msg = this.querySelector(".c-color-picker__message");
1884
+ if (err || help) {
1885
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-color-picker__message"; this.appendChild(msg); }
1886
+ msg.textContent = err || help || "";
1887
+ msg.classList.toggle("c-color-picker__message--error", !!err);
1888
+ } else if (msg) { msg.remove(); }
1889
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
1890
+ // Calendar affordance (R14-22): a toggle + month grid alongside the native input.
1891
+ 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; });
1892
+ let cal = this.querySelector(".c-date-picker__calendar");
1893
+ 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
1894
  }
1278
1895
  enhance() {
1279
1896
  if (this._wiredColorPicker) return;
@@ -1283,14 +1900,50 @@ class ContourColorPicker extends ContourBase {
1283
1900
  if (t && t.classList.contains("c-color-picker__input")) {
1284
1901
  this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: t.value } }));
1285
1902
  }
1903
+ if (t && t.classList.contains("c-color-picker__alpha")) {
1904
+ const base = (this.getAttribute("value") || "#000000").slice(0, 7);
1905
+ const a = Math.round(parseFloat(t.value) * 255).toString(16).padStart(2, "0");
1906
+ const val = base + a;
1907
+ this.setAttribute("value", val);
1908
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: val } }));
1909
+ }
1910
+ });
1911
+ this.addEventListener("click", (e) => {
1912
+ const btn = e.target && e.target.closest ? e.target.closest(".c-color-picker__preset") : null;
1913
+ if (btn && this.contains(btn)) {
1914
+ const c = btn.dataset.color;
1915
+ if (c) {
1916
+ this.setAttribute("value", c);
1917
+ const input = this.querySelector(".c-color-picker__input");
1918
+ if (input) input.value = c.slice(0, 7);
1919
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: c } }));
1920
+ }
1921
+ }
1922
+ const ed = e.target && e.target.closest ? e.target.closest(".c-color-picker__eyedropper") : null;
1923
+ if (ed && this.contains(ed) && typeof window !== "undefined" && "EyeDropper" in window) {
1924
+ e.preventDefault();
1925
+ const dropper = new window.EyeDropper();
1926
+ dropper.open().then((r) => {
1927
+ if (r && r.sRGBHex) {
1928
+ this.setAttribute("value", r.sRGBHex);
1929
+ const input = this.querySelector(".c-color-picker__input");
1930
+ if (input) input.value = r.sRGBHex;
1931
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: r.sRGBHex } }));
1932
+ }
1933
+ }).catch(() => {});
1934
+ }
1286
1935
  });
1287
1936
  }
1288
1937
  }
1289
1938
  define("contour-color-picker", ContourColorPicker);
1290
1939
 
1940
+ /**
1941
+ * Number Field: web component wrapper.
1942
+ * Attributes: `value`, `min`, `max`, `step`, `label`, `disabled`, `error`, `help`.
1943
+ */
1291
1944
  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" } }; }
1945
+ static get observed() { return ["value", "min", "max", "step", "label", "disabled", "error", "help"]; }
1946
+ 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
1947
  render() {
1295
1948
  this.classList.add("c-number-field");
1296
1949
  const label = this.getAttribute("label");
@@ -1298,11 +1951,30 @@ class ContourNumberField extends ContourBase {
1298
1951
  const l = this.ensure(".c-number-field__label", () => { const el = document.createElement("label"); el.className = "c-number-field__label"; return el; });
1299
1952
  l.textContent = label;
1300
1953
  }
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; });
1954
+ 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
1955
  if (this.getAttribute("value") !== null) input.value = this.getAttribute("value");
1303
1956
  if (this.getAttribute("min") !== null) input.min = this.getAttribute("min");
1304
1957
  if (this.getAttribute("max") !== null) input.max = this.getAttribute("max");
1305
1958
  if (this.getAttribute("step") !== null) input.step = this.getAttribute("step");
1959
+ const v = input.value;
1960
+ input.setAttribute("aria-valuenow", v === "" ? "" : v);
1961
+ if (input.min !== "") input.setAttribute("aria-valuemin", input.min);
1962
+ if (input.max !== "") input.setAttribute("aria-valuemax", input.max);
1963
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
1964
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
1965
+ const err = this.getAttribute("error");
1966
+ const help = this.getAttribute("help");
1967
+ let msg = this.querySelector(".c-number-field__message");
1968
+ if (err || help) {
1969
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-number-field__message"; this.appendChild(msg); }
1970
+ msg.textContent = err || help || "";
1971
+ msg.classList.toggle("c-number-field__message--error", !!err);
1972
+ } else if (msg) { msg.remove(); }
1973
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
1974
+ // Calendar affordance (R14-22): a toggle + month grid alongside the native input.
1975
+ 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; });
1976
+ let cal = this.querySelector(".c-date-picker__calendar");
1977
+ 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
1978
  }
1307
1979
  enhance() {
1308
1980
  if (this._wiredNumberField) return;
@@ -1313,15 +1985,40 @@ class ContourNumberField extends ContourBase {
1313
1985
  this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: t.value } }));
1314
1986
  }
1315
1987
  });
1988
+ this.addEventListener("keydown", (e) => {
1989
+ const input = this.querySelector(".c-number-field__input");
1990
+ if (!input || document.activeElement !== input) return;
1991
+ const step = Number(input.step) || 1;
1992
+ const min = input.min === "" ? -Infinity : Number(input.min);
1993
+ const max = input.max === "" ? Infinity : Number(input.max);
1994
+ let next = null;
1995
+ if (e.key === "ArrowUp") next = (Number(input.value) || 0) + step;
1996
+ else if (e.key === "ArrowDown") next = (Number(input.value) || 0) - step;
1997
+ else if (e.key === "Home") next = min === -Infinity ? 0 : min;
1998
+ else if (e.key === "End") next = max === Infinity ? (Number(input.value) || 0) : max;
1999
+ if (next !== null) {
2000
+ e.preventDefault();
2001
+ next = Math.min(max, Math.max(min, next));
2002
+ input.value = String(next);
2003
+ input.setAttribute("aria-valuenow", String(next));
2004
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: input.value } }));
2005
+ }
2006
+ });
1316
2007
  }
1317
2008
  }
1318
2009
  define("contour-number-field", ContourNumberField);
1319
2010
 
2011
+ /**
2012
+ * Hover Card: web component wrapper.
2013
+ * Attributes: `title`, `content`, `anchor`.
2014
+ */
1320
2015
  class ContourHoverCard extends ContourBase {
1321
2016
  static get observed() { return ["title", "content", "anchor"]; }
1322
2017
  static get properties() { return { title: { attribute: "title" }, content: { attribute: "content" }, anchor: { attribute: "anchor" } }; }
1323
2018
  render() {
1324
2019
  this.classList.add("c-hover-card");
2020
+ if (!this.hasAttribute("role")) this.setAttribute("role", "tooltip");
2021
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Hover card");
1325
2022
  if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
1326
2023
  if (!this.id) this.id = contourId("hover-card");
1327
2024
  const title = this.getAttribute("title");
@@ -1344,19 +2041,33 @@ class ContourHoverCard extends ContourBase {
1344
2041
  if (trigger) {
1345
2042
  trigger.setAttribute("popovertarget", this.id);
1346
2043
  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) {} });
2044
+ const hasPopover = typeof this.showPopover === "function";
2045
+ 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 })); };
2046
+ 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 })); };
2047
+ trigger.addEventListener("mouseenter", () => { showTimer = setTimeout(show, 300); });
2048
+ trigger.addEventListener("mouseleave", () => { hide(); });
2049
+ trigger.addEventListener("focus", show);
2050
+ trigger.addEventListener("blur", () => { setTimeout(hide, 100); });
2051
+ onDispose(this, () => { if (showTimer) { clearTimeout(showTimer); showTimer = null; } });
1349
2052
  }
1350
2053
  }
2054
+ 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 })); } };
2055
+ document.addEventListener("keydown", keyHandler);
2056
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
1351
2057
  }
1352
2058
  }
1353
2059
  define("contour-hover-card", ContourHoverCard);
1354
2060
 
2061
+ /**
2062
+ * Context Menu: web component wrapper.
2063
+ * Attributes: `items`.
2064
+ */
1355
2065
  class ContourContextMenu extends ContourBase {
1356
2066
  static get observed() { return ["items"]; }
1357
2067
  static get properties() { return { items: { attribute: "items" } }; }
1358
2068
  render() {
1359
2069
  this.classList.add("c-context-menu");
2070
+ if (!this.hasAttribute("role")) this.setAttribute("role", "menu");
1360
2071
  if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
1361
2072
  if (!this.id) this.id = contourId("context-menu");
1362
2073
  const items = this.getAttribute("items");
@@ -1379,24 +2090,41 @@ class ContourContextMenu extends ContourBase {
1379
2090
  this._wiredContextMenu = true;
1380
2091
  this.addEventListener("contextmenu", (e) => {
1381
2092
  e.preventDefault();
1382
- try { this.showPopover(); } catch (err) {}
2093
+ if (typeof this.showPopover === "function") { try { this.showPopover(); } catch (err) {} }
2094
+ else this.classList.toggle("is-open");
1383
2095
  });
1384
2096
  this.addEventListener("click", (e) => {
1385
2097
  const item = e.target && e.target.closest ? e.target.closest(".c-menu__item") : null;
1386
2098
  if (item && this.contains(item)) {
1387
2099
  this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { label: item.textContent.trim() } }));
1388
- try { this.hidePopover(); } catch (err) {}
2100
+ if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (err) {} }
2101
+ this.classList.remove("is-open");
1389
2102
  }
1390
2103
  });
2104
+ this.addEventListener("keydown", (e) => {
2105
+ const items = Array.from(this.querySelectorAll(".c-menu__item"));
2106
+ const active = document.activeElement;
2107
+ const idx = items.indexOf(active);
2108
+ 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) {} }
2109
+ 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) {} }
2110
+ else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); if (active && active.classList.contains("c-menu__item")) active.click(); }
2111
+ else if (e.key === "Escape") { e.preventDefault(); if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (err) {} } this.classList.remove("is-open"); }
2112
+ });
1391
2113
  }
1392
2114
  }
1393
2115
  define("contour-context-menu", ContourContextMenu);
1394
2116
 
2117
+ /**
2118
+ * Fab: web component wrapper.
2119
+ * Attributes: `label`, `icon`.
2120
+ */
1395
2121
  class ContourFab extends ContourBase {
1396
2122
  static get observed() { return ["label", "icon"]; }
1397
2123
  static get properties() { return { label: { attribute: "label" }, icon: { attribute: "icon" } }; }
1398
2124
  render() {
1399
2125
  this.classList.add("c-fab");
2126
+ if (!this.hasAttribute("role")) this.setAttribute("role", "button");
2127
+ if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
1400
2128
  const label = this.getAttribute("label");
1401
2129
  if (label) this.setAttribute("aria-label", label);
1402
2130
  const icon = this.getAttribute("icon");
@@ -1408,10 +2136,17 @@ class ContourFab extends ContourBase {
1408
2136
  this.addEventListener("click", () => {
1409
2137
  this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true }));
1410
2138
  });
2139
+ this.addEventListener("keydown", (e) => {
2140
+ if (e.key === "Enter" || e.key === " ") { e.preventDefault(); this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true })); }
2141
+ });
1411
2142
  }
1412
2143
  }
1413
2144
  define("contour-fab", ContourFab);
1414
2145
 
2146
+ /**
2147
+ * File Upload: web component wrapper.
2148
+ * Attributes: `label`, `accept`, `multiple`, `progress`.
2149
+ */
1415
2150
  class ContourFileUpload extends ContourBase {
1416
2151
  static get observed() { return ["label", "accept", "multiple", "progress"]; }
1417
2152
  static get properties() { return { label: { attribute: "label" }, accept: { attribute: "accept" }, multiple: { attribute: "multiple", type: Boolean }, progress: { attribute: "progress" } }; }
@@ -1428,43 +2163,88 @@ class ContourFileUpload extends ContourBase {
1428
2163
  const bar = this.ensure(".c-file-upload__progress", () => { const el = document.createElement("progress"); el.className = "c-file-upload__progress"; return el; });
1429
2164
  bar.value = Number(p) || 0;
1430
2165
  bar.max = 100;
2166
+ } else {
2167
+ const bar = this.querySelector(".c-file-upload__progress");
2168
+ if (bar) bar.remove();
1431
2169
  }
2170
+ const preview = this.ensure(".c-file-upload__preview", () => { const el = document.createElement("div"); el.className = "c-file-upload__preview"; return el; });
2171
+ if (!preview) {}
1432
2172
  }
1433
2173
  enhance() {
1434
2174
  if (this._wiredFileUpload) return;
1435
2175
  this._wiredFileUpload = true;
1436
2176
  const dz = () => this.querySelector(".c-file-upload__dropzone");
1437
2177
  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 } })); } });
2178
+ const activate = () => { const i = input(); if (i) i.click(); };
2179
+ this.addEventListener("click", (e) => { const d = dz(); if (e.target === d || (d && d.contains(e.target))) { activate(); } });
2180
+ this.addEventListener("keydown", (e) => { const d = dz(); if ((e.target === d || (d && d.contains(e.target))) && (e.key === "Enter" || e.key === " ")) { e.preventDefault(); activate(); } });
2181
+ const renderPreview = (files) => {
2182
+ const preview = this.querySelector(".c-file-upload__preview");
2183
+ if (!preview) return;
2184
+ preview.innerHTML = "";
2185
+ Array.from(files || []).forEach((f) => {
2186
+ const item = document.createElement("div");
2187
+ item.className = "c-file-upload__preview-item";
2188
+ if (f.type && f.type.startsWith("image/")) {
2189
+ const img = document.createElement("img");
2190
+ img.className = "c-file-upload__preview-thumb";
2191
+ img.alt = f.name;
2192
+ try { img.src = URL.createObjectURL(f); } catch (e) {}
2193
+ item.appendChild(img);
2194
+ } else {
2195
+ const name = document.createElement("span");
2196
+ name.className = "c-file-upload__preview-name";
2197
+ name.textContent = f.name;
2198
+ item.appendChild(name);
2199
+ }
2200
+ preview.appendChild(item);
2201
+ });
2202
+ };
2203
+ 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 } })); } });
2204
+ // drag-drop already dispatches contour:change; also render preview there
1440
2205
  this.addEventListener("dragover", (e) => { e.preventDefault(); this.classList.add("is-dragover"); });
1441
2206
  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 } })); } });
2207
+ 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
2208
  }
1444
2209
  }
1445
2210
  define("contour-file-upload", ContourFileUpload);
1446
2211
 
2212
+ /**
2213
+ * Notification Center: web component wrapper.
2214
+ * Attributes: `count`, `items`, `color`.
2215
+ */
1447
2216
  class ContourNotificationCenter extends ContourBase {
1448
- static get observed() { return ["count", "items"]; }
1449
- static get properties() { return { count: { attribute: "count" }, items: { attribute: "items" } }; }
2217
+ static get observed() { return ["count", "items", "color"]; }
2218
+ static get properties() { return { count: { attribute: "count" }, items: { attribute: "items" }, color: { attribute: "color" } }; }
1450
2219
  render() {
1451
2220
  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; });
2221
+ 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; });
2222
+ const color = this.getAttribute("color");
2223
+ const bullet = btn.querySelector(".c-notification-center__bullet");
2224
+ if (bullet && color) { bullet.style.background = color; bullet.dataset.color = color; }
1453
2225
  const count = this.getAttribute("count");
1454
- let badge = this.querySelector(".c-notification-center__badge");
2226
+ let badge = btn.querySelector(".c-notification-center__badge");
1455
2227
  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); }
2228
+ if (!badge) { badge = document.createElement("span"); badge.className = "c-notification-center__badge c-badge c-badge--dot"; btn.appendChild(badge); }
1457
2229
  badge.textContent = count;
1458
2230
  } 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; });
2231
+ 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; });
2232
+ // Slotted content: authored .c-notification-center__item children take
2233
+ // precedence over the JSON `items` attribute.
2234
+ const authoredItems = Array.from(this.querySelectorAll(":scope > .c-notification-center__item"));
1460
2235
  const items = this.getAttribute("items");
1461
- if (items) {
2236
+ if (authoredItems.length) {
2237
+ panel.innerHTML = "";
2238
+ authoredItems.forEach((it) => { panel.appendChild(it); });
2239
+ } else if (items) {
1462
2240
  try {
1463
2241
  const parsed = JSON.parse(items);
1464
2242
  panel.innerHTML = "";
1465
2243
  parsed.forEach((it) => {
1466
2244
  const row = document.createElement("div");
1467
2245
  row.className = "c-notification-center__item";
2246
+ row.setAttribute("tabindex", "0");
2247
+ row.setAttribute("role", "option");
1468
2248
  row.textContent = typeof it === "string" ? it : (it.text || it.title || "");
1469
2249
  panel.appendChild(row);
1470
2250
  });
@@ -1478,18 +2258,44 @@ class ContourNotificationCenter extends ContourBase {
1478
2258
  const btn = this.querySelector(".c-notification-center__trigger");
1479
2259
  const panel = this.querySelector(".c-notification-center__panel");
1480
2260
  if (btn && (e.target === btn || btn.contains(e.target))) {
1481
- if (panel) { panel.hidden = !panel.hidden; btn.setAttribute("aria-expanded", String(!panel.hidden)); }
2261
+ 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 })); }
1482
2262
  }
1483
2263
  });
1484
- document.addEventListener("click", (e) => {
2264
+ this.addEventListener("click", (e) => {
2265
+ const item = e.target && e.target.closest ? e.target.closest(".c-notification-center__item") : null;
2266
+ if (item && this.contains(item)) {
2267
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { label: item.textContent } }));
2268
+ }
2269
+ });
2270
+ const docClick = (e) => {
1485
2271
  const panel = this.querySelector(".c-notification-center__panel");
1486
2272
  const btn = this.querySelector(".c-notification-center__trigger");
1487
2273
  if (panel && !panel.hidden && !this.contains(e.target)) { panel.hidden = true; if (btn) btn.setAttribute("aria-expanded", "false"); }
1488
- });
2274
+ };
2275
+ document.addEventListener("click", docClick);
2276
+ onDispose(this, () => document.removeEventListener("click", docClick));
2277
+ const keyHandler = (e) => {
2278
+ const panel = this.querySelector(".c-notification-center__panel");
2279
+ const btn = this.querySelector(".c-notification-center__trigger");
2280
+ if (e.key === "Escape" && panel && !panel.hidden) { panel.hidden = true; if (btn) { btn.setAttribute("aria-expanded", "false"); try { btn.focus(); } catch (err) {} } return; }
2281
+ if (!panel || panel.hidden) return;
2282
+ const items = Array.from(panel.querySelectorAll(".c-notification-center__item"));
2283
+ if (!items.length) return;
2284
+ const active = document.activeElement;
2285
+ const idx = items.indexOf(active);
2286
+ 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) {} }
2287
+ 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) {} }
2288
+ };
2289
+ document.addEventListener("keydown", keyHandler);
2290
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
1489
2291
  }
1490
2292
  }
1491
2293
  define("contour-notification-center", ContourNotificationCenter);
1492
2294
 
2295
+ /**
2296
+ * Stepper: web component wrapper.
2297
+ * Attributes: `steps`, `current`.
2298
+ */
1493
2299
  class ContourStepper extends ContourBase {
1494
2300
  static get observed() { return ["steps", "current"]; }
1495
2301
  static get properties() { return { steps: { attribute: "steps" }, current: { attribute: "current" } }; }
@@ -1499,11 +2305,19 @@ class ContourStepper extends ContourBase {
1499
2305
  const current = Number(this.getAttribute("current") || 0);
1500
2306
  const list = this.ensure(".c-stepper__list", () => { const el = document.createElement("ol"); el.className = "c-stepper__list"; return el; });
1501
2307
  list.innerHTML = "";
2308
+ // Slotted content: authored .c-stepper__step children take precedence.
2309
+ const authoredSteps = Array.from(this.querySelectorAll(":scope > .c-stepper__step"));
1502
2310
  let parsed = [];
1503
- try { parsed = steps ? JSON.parse(steps) : []; } catch (e) { parsed = []; }
2311
+ if (authoredSteps.length) {
2312
+ parsed = authoredSteps.map((el) => el.textContent.trim());
2313
+ authoredSteps.forEach((el) => el.remove());
2314
+ } else {
2315
+ try { parsed = steps ? JSON.parse(steps) : []; } catch (e) { parsed = []; }
2316
+ }
1504
2317
  parsed.forEach((s, i) => {
1505
2318
  const li = document.createElement("li");
1506
2319
  li.className = "c-stepper__step" + (i === current ? " is-current" : "") + (i < current ? " is-done" : "");
2320
+ if (i === current) li.setAttribute("aria-current", "step");
1507
2321
  li.textContent = typeof s === "string" ? s : (s.title || s.label || "");
1508
2322
  list.appendChild(li);
1509
2323
  });
@@ -1517,44 +2331,207 @@ class ContourStepper extends ContourBase {
1517
2331
  enhance() {
1518
2332
  if (this._wiredStepper) return;
1519
2333
  this._wiredStepper = true;
2334
+ const go = (dir) => {
2335
+ const list = this.querySelector(".c-stepper__list");
2336
+ const total = list ? list.querySelectorAll(".c-stepper__step").length : 0;
2337
+ if (!total) return;
2338
+ let cur = Number(this.getAttribute("current") || 0);
2339
+ if (dir === "prev") cur = Math.max(0, cur - 1);
2340
+ else cur = Math.min(total - 1, cur + 1);
2341
+ this.setAttribute("current", String(cur));
2342
+ this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { direction: dir, index: cur } }));
2343
+ };
1520
2344
  this.addEventListener("click", (e) => {
1521
2345
  const prev = e.target && e.target.closest ? e.target.closest(".c-stepper__prev") : null;
1522
2346
  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" } }));
2347
+ if (prev && this.contains(prev)) go("prev");
2348
+ if (next && this.contains(next)) go("next");
2349
+ });
2350
+ this.addEventListener("keydown", (e) => {
2351
+ if (e.key === "ArrowLeft") { e.preventDefault(); go("prev"); }
2352
+ else if (e.key === "ArrowRight") { e.preventDefault(); go("next"); }
1525
2353
  });
1526
2354
  }
1527
2355
  }
1528
2356
  define("contour-stepper", ContourStepper);
1529
2357
 
2358
+ /**
2359
+ * Virtual List: web component wrapper.
2360
+ * Attributes: `items`, `item-height`, `orientation`, `sticky`.
2361
+ */
1530
2362
  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; });
2363
+ static get updateMode() { return "keyed"; }
2364
+ static get observed() { return ["items", "item-height", "orientation", "sticky"]; }
2365
+ static get properties() { return { items: { attribute: "items" }, "item-height": { attribute: "item-height" }, orientation: { attribute: "orientation" }, sticky: { attribute: "sticky", type: Boolean } }; }
2366
+ _items() {
1536
2367
  const items = this.getAttribute("items");
1537
2368
  let parsed = [];
1538
2369
  try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
1539
- scroller.innerHTML = "";
1540
- parsed.forEach((it, i) => {
2370
+ return Array.isArray(parsed) ? parsed : [];
2371
+ }
2372
+ _itemHeight() {
2373
+ const h = Number(this.getAttribute("item-height"));
2374
+ return Number.isFinite(h) && h > 0 ? h : 28;
2375
+ }
2376
+ _autoHeight() {
2377
+ return this.getAttribute("item-height") === "auto";
2378
+ }
2379
+ render() {
2380
+ this.classList.add("c-virtual-list");
2381
+ this.setAttribute("role", "list");
2382
+ const scroller = this.ensure(".c-virtual-list__scroller", () => { const el = document.createElement("div"); el.className = "c-virtual-list__scroller"; return el; });
2383
+ scroller.setAttribute("role", "presentation");
2384
+ const horizontal = this.getAttribute("orientation") === "horizontal";
2385
+ scroller.style.overflowX = horizontal ? "auto" : "hidden";
2386
+ scroller.style.overflowY = horizontal ? "hidden" : "auto";
2387
+ 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; });
2388
+ if (inner.parentNode !== scroller) scroller.appendChild(inner);
2389
+ this._renderWindow(scroller, inner, horizontal ? (scroller.scrollLeft || 0) : (scroller.scrollTop || 0));
2390
+ }
2391
+ _measureHeights(inner, horizontal) {
2392
+ const rows = Array.from(inner.querySelectorAll(".c-virtual-list__item"));
2393
+ return rows.map((r) => horizontal ? (r.getBoundingClientRect().width || 28) : (r.getBoundingClientRect().height || 28));
2394
+ }
2395
+ _renderWindow(scroller, inner, scrollTop) {
2396
+ const items = this._items();
2397
+ const ih = this._itemHeight();
2398
+ const horizontal = this.getAttribute("orientation") === "horizontal";
2399
+ const autoHeight = this._autoHeight();
2400
+ const viewportSize = horizontal ? (scroller.clientWidth || 320) : (scroller.clientHeight || 320);
2401
+ const total = items.length;
2402
+ // Reset measured heights when item count changes.
2403
+ if (this._vlItemCount !== total) { this._vlHeights = null; this._vlItemCount = total; }
2404
+ let heights = autoHeight ? this._vlHeights : null;
2405
+ let cumulative = null;
2406
+ if (autoHeight && heights && heights.length === total) {
2407
+ cumulative = [0];
2408
+ for (let i = 0; i < total; i++) cumulative.push(cumulative[i] + (heights[i] || 28));
2409
+ }
2410
+ const visibleCount = autoHeight && !cumulative ? total : (autoHeight ? Math.ceil(viewportSize / 28) + 6 : Math.ceil(viewportSize / ih) + 4);
2411
+ let start = 0;
2412
+ if (autoHeight && cumulative) {
2413
+ // binary search for start
2414
+ let lo = 0, hi = total;
2415
+ while (lo < hi) {
2416
+ const mid = (lo + hi) >> 1;
2417
+ if (cumulative[mid] < (scrollTop || 0)) lo = mid + 1; else hi = mid;
2418
+ }
2419
+ start = Math.max(0, lo - 3);
2420
+ } else if (!autoHeight) {
2421
+ start = Math.floor((scrollTop || 0) / ih);
2422
+ }
2423
+ if (start < 0) start = 0;
2424
+ const end = autoHeight && cumulative
2425
+ ? Math.min(total, start + visibleCount)
2426
+ : Math.min(total, start + visibleCount);
2427
+ if (start > Math.max(0, total - visibleCount) && !autoHeight) start = Math.max(0, total - visibleCount);
2428
+ const topSpacerSize = autoHeight && cumulative ? cumulative[start] : (autoHeight ? 0 : start * ih);
2429
+ const bottomSpacerSize = autoHeight && cumulative ? Math.max(0, cumulative[total] - cumulative[end]) : (autoHeight ? 0 : Math.max(0, (total - end) * ih));
2430
+ inner.style.display = horizontal ? "flex" : "block";
2431
+ inner.style.width = horizontal && autoHeight ? "max-content" : "";
2432
+ inner.style.height = horizontal || autoHeight ? "" : (total * ih) + "px";
2433
+ inner.innerHTML = "";
2434
+ const top = document.createElement("div");
2435
+ top.className = "c-virtual-list__spacer c-virtual-list__spacer--top";
2436
+ top.style[horizontal ? "width" : "height"] = topSpacerSize + "px";
2437
+ inner.appendChild(top);
2438
+ for (let i = start; i < end; i++) {
1541
2439
  const row = document.createElement("div");
1542
2440
  row.className = "c-virtual-list__item";
1543
- row.textContent = typeof it === "string" ? it : (it.label || it.text || JSON.stringify(it));
2441
+ row.setAttribute("role", "listitem");
2442
+ // aria-rowindex omitted: not allowed on role="listitem" (axe aria-allowed-attr)
2443
+ row.setAttribute("tabindex", i === 0 ? "0" : "-1");
2444
+ row.textContent = typeof items[i] === "string" ? items[i] : (items[i].label || items[i].text || JSON.stringify(items[i]));
2445
+ if (this.hasAttribute("sticky") && items[i] && items[i].sticky) {
2446
+ row.style.position = "sticky";
2447
+ row.style.insetBlockStart = "0";
2448
+ row.style.zIndex = "1";
2449
+ }
2450
+ if (horizontal && !autoHeight) row.style.flex = "0 0 " + ih + "px";
1544
2451
  row.dataset.index = String(i);
1545
- scroller.appendChild(row);
2452
+ inner.appendChild(row);
2453
+ }
2454
+ const bottom = document.createElement("div");
2455
+ bottom.className = "c-virtual-list__spacer c-virtual-list__spacer--bottom";
2456
+ bottom.style[horizontal ? "width" : "height"] = bottomSpacerSize + "px";
2457
+ inner.appendChild(bottom);
2458
+ if (horizontal && !autoHeight) inner.style.width = (total * ih) + "px";
2459
+ // Measure heights in auto mode for future windowing.
2460
+ if (autoHeight && !this._vlHeights) {
2461
+ // defer measurement to next frame so layout is done
2462
+ requestAnimationFrame(() => {
2463
+ this._vlHeights = this._measureHeights(inner, horizontal);
2464
+ // re-render windowed now that heights known
2465
+ const s = scroller;
2466
+ const i = inner;
2467
+ if (s && i) this._renderWindow(s, i, s.scrollTop || 0);
2468
+ });
2469
+ }
2470
+ }
2471
+ enhance() {
2472
+ if (this._wiredVirtualList) return;
2473
+ this._wiredVirtualList = true;
2474
+ const scroller = () => this.querySelector(".c-virtual-list__scroller");
2475
+ const inner = () => this.querySelector(".c-virtual-list__inner");
2476
+ let raf = 0;
2477
+ const onScroll = () => {
2478
+ if (raf) return;
2479
+ raf = requestAnimationFrame(() => {
2480
+ raf = 0;
2481
+ const s = scroller(); const i = inner();
2482
+ if (s && i) this._renderWindow(s, i, this.getAttribute("orientation") === "horizontal" ? s.scrollLeft : s.scrollTop);
2483
+ });
2484
+ };
2485
+ const s = scroller();
2486
+ if (s) {
2487
+ s.addEventListener("scroll", onScroll, { passive: true });
2488
+ onDispose(this, () => { s.removeEventListener("scroll", onScroll); if (raf) cancelAnimationFrame(raf); });
2489
+ }
2490
+ // keyboard + selection
2491
+ this.addEventListener("keydown", (e) => {
2492
+ const rows = Array.from(this.querySelectorAll(".c-virtual-list__item"));
2493
+ if (!rows.length) return;
2494
+ const active = this.querySelector(".c-virtual-list__item:focus") || rows[0];
2495
+ const idx = rows.indexOf(active);
2496
+ let next = -1;
2497
+ if (e.key === "ArrowDown") next = Math.min(idx + 1, rows.length - 1);
2498
+ else if (e.key === "ArrowUp") next = Math.max(idx - 1, 0);
2499
+ else if (e.key === "Home") next = 0;
2500
+ else if (e.key === "End") next = rows.length - 1;
2501
+ else if (e.key === "Enter" || e.key === " ") {
2502
+ e.preventDefault();
2503
+ const i = Number(active.dataset.index);
2504
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: i, value: active.textContent } }));
2505
+ return;
2506
+ }
2507
+ if (next < 0 || next === idx) return;
2508
+ e.preventDefault();
2509
+ rows.forEach((r, i) => r.setAttribute("tabindex", i === next ? "0" : "-1"));
2510
+ try { rows[next].focus(); } catch (err) {}
2511
+ });
2512
+ this.addEventListener("click", (e) => {
2513
+ const row = e.target && e.target.closest ? e.target.closest(".c-virtual-list__item") : null;
2514
+ if (!row || !this.contains(row)) return;
2515
+ const i = Number(row.dataset.index);
2516
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: i, value: row.textContent } }));
1546
2517
  });
1547
2518
  }
1548
2519
  }
1549
2520
  define("contour-virtual-list", ContourVirtualList);
1550
2521
 
2522
+ /**
2523
+ * Command Palette: web component wrapper.
2524
+ * Attributes: `open`, `items`.
2525
+ */
1551
2526
  class ContourCommandPalette extends ContourBase {
1552
2527
  static get observed() { return ["open", "items"]; }
1553
2528
  static get properties() { return { open: { attribute: "open", type: Boolean }, items: { attribute: "items" } }; }
1554
2529
  render() {
1555
2530
  this.classList.add("c-command-palette");
2531
+ if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
2532
+ if (!this.hasAttribute("aria-modal")) this.setAttribute("aria-modal", "true");
1556
2533
  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; });
2534
+ 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
2535
  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
2536
  const items = this.getAttribute("items");
1560
2537
  if (items) {
@@ -1565,32 +2542,87 @@ class ContourCommandPalette extends ContourBase {
1565
2542
  const row = document.createElement("div");
1566
2543
  row.className = "c-command-palette__item";
1567
2544
  row.setAttribute("role", "option");
2545
+ row.id = this.id + "-opt-" + i;
1568
2546
  row.textContent = typeof it === "string" ? it : (it.label || it.title || "");
1569
2547
  row.dataset.index = String(i);
2548
+ row.dataset.label = row.textContent;
1570
2549
  list.appendChild(row);
1571
2550
  });
1572
2551
  } catch (e) { /* keep */ }
1573
2552
  }
1574
2553
  }
2554
+ show() { if (typeof this.showPopover === "function") { try { this.showPopover(); } catch (e) {} } this.classList.add("is-open"); }
2555
+ hide() { if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (e) {} } this.classList.remove("is-open"); }
2556
+ toggle() { if (this.classList.contains("is-open") || this.matches(":popover-open")) this.hide(); else this.show(); }
1575
2557
  enhance() {
1576
- if (this._wiredCmdPalette) return;
1577
2558
  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));
2559
+ const search = () => this.querySelector(".c-command-palette__search");
2560
+ const list = () => this.querySelector(".c-command-palette__list");
2561
+ const items = () => Array.from(this.querySelectorAll(".c-command-palette__item"));
2562
+ const visibleItems = () => items().filter((it) => !it.hidden);
2563
+ const setActive = (idx) => {
2564
+ const vis = visibleItems();
2565
+ vis.forEach((it, i) => it.classList.toggle("is-active", i === idx));
2566
+ const active = vis[idx];
2567
+ const s = search();
2568
+ if (s && active) s.setAttribute("aria-activedescendant", active.id);
2569
+ else if (s) s.removeAttribute("aria-activedescendant");
2570
+ };
2571
+ const filter = (q) => {
2572
+ const needle = (q || "").toLowerCase().trim();
2573
+ items().forEach((it) => {
2574
+ const label = (it.dataset.label || it.textContent || "").toLowerCase();
2575
+ it.hidden = needle !== "" && !label.includes(needle);
2576
+ });
2577
+ setActive(0);
2578
+ };
2579
+ const select = (it) => {
2580
+ if (!it) return;
2581
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: Number(it.dataset.index), label: it.dataset.label || it.textContent } }));
2582
+ try { this.hidePopover(); } catch (e) {}
2583
+ this.classList.remove("is-open");
2584
+ };
2585
+ const s = search();
2586
+ if (s) {
2587
+ s.setAttribute("role", "combobox");
2588
+ s.setAttribute("aria-autocomplete", "list");
2589
+ s.setAttribute("aria-controls", list() ? list().id || "" : "");
2590
+ if (!list().id) list().id = this.id + "-list";
2591
+ s.setAttribute("aria-controls", list().id);
2592
+ s.addEventListener("input", (e) => filter(e.target.value));
2593
+ s.addEventListener("keydown", (e) => {
2594
+ const vis = visibleItems();
2595
+ const active = this.querySelector(".c-command-palette__item.is-active");
2596
+ let idx = active ? vis.indexOf(active) : -1;
2597
+ if (e.key === "ArrowDown") { e.preventDefault(); idx = Math.min(vis.length - 1, idx + 1); if (idx < 0) idx = 0; setActive(idx); }
2598
+ else if (e.key === "ArrowUp") { e.preventDefault(); idx = Math.max(0, idx - 1); if (vis.length && idx < 0) idx = 0; setActive(idx); }
2599
+ else if (e.key === "Home") { e.preventDefault(); setActive(0); }
2600
+ else if (e.key === "End") { e.preventDefault(); setActive(vis.length - 1); }
2601
+ else if (e.key === "Enter") { e.preventDefault(); if (active) select(active); }
2602
+ else if (e.key === "Escape") { e.preventDefault(); try { this.hidePopover(); } catch (e) {} this.classList.remove("is-open"); }
2603
+ });
2604
+ }
2605
+ // click selection
2606
+ this.addEventListener("click", (e) => {
2607
+ const it = e.target && e.target.closest ? e.target.closest(".c-command-palette__item") : null;
2608
+ if (it && this.contains(it) && !it.hidden) select(it);
2609
+ });
2610
+ // focus return on close
2611
+ let lastFocus = null;
2612
+ this.addEventListener("beforetoggle", (e) => {
2613
+ if (e.newState === "open") lastFocus = document.activeElement;
2614
+ else if (lastFocus && typeof lastFocus.focus === "function") { try { lastFocus.focus(); } catch (err) {} }
1589
2615
  });
2616
+ // Escape via popover light dismiss is handled by keydown above; also close on outside handled by popover.
2617
+ setActive(0);
1590
2618
  }
1591
2619
  }
1592
2620
  define("contour-command-palette", ContourCommandPalette);
1593
2621
 
2622
+ /**
2623
+ * Badge Overflow: web component wrapper.
2624
+ * Attributes: `count`, `max`.
2625
+ */
1594
2626
  class ContourBadgeOverflow extends ContourBase {
1595
2627
  static get observed() { return ["count", "max"]; }
1596
2628
  static get properties() { return { count: { attribute: "count" }, max: { attribute: "max" } }; }
@@ -1610,29 +2642,76 @@ class ContourBadgeOverflow extends ContourBase {
1610
2642
  }
1611
2643
  define("contour-badge-overflow", ContourBadgeOverflow);
1612
2644
 
2645
+ /**
2646
+ * Side Sheet: web component wrapper.
2647
+ * Attributes: `open`, `side`, `title`.
2648
+ */
1613
2649
  class ContourSideSheet extends ContourBase {
1614
2650
  static get observed() { return ["open", "side", "title"]; }
1615
2651
  static get properties() { return { open: { attribute: "open", type: Boolean }, side: { attribute: "side" }, title: { attribute: "title" } }; }
1616
2652
  render() {
1617
2653
  this.classList.add("c-side-sheet");
2654
+ this.setAttribute("role", "dialog");
2655
+ this.setAttribute("aria-modal", "true");
2656
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Side sheet");
1618
2657
  const side = this.getAttribute("side") || "end";
1619
2658
  this.classList.add("c-side-sheet--" + side);
1620
- if (this.hasAttribute("open")) this.classList.add("is-open");
1621
- else this.classList.remove("is-open");
2659
+ if (this.hasAttribute("open")) this.classList.add("is-open"); else this.classList.remove("is-open");
1622
2660
  const title = this.getAttribute("title");
1623
2661
  if (title) {
1624
2662
  const t = this.ensure(".c-side-sheet__title", () => { const el = document.createElement("div"); el.className = "c-side-sheet__title"; return el; });
1625
2663
  t.textContent = title;
1626
2664
  }
1627
2665
  }
2666
+ enhance() {
2667
+ if (this._wiredSideSheet) return;
2668
+ this._wiredSideSheet = true;
2669
+ let lastFocus = null;
2670
+ const close = () => this.removeAttribute("open");
2671
+ const keyHandler = (e) => {
2672
+ if (e.key === "Escape" && this.hasAttribute("open")) { e.preventDefault(); close(); return; }
2673
+ if (e.key === "Tab" && this.hasAttribute("open")) {
2674
+ const focusables = Array.from(this.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")).filter((el) => !el.hasAttribute("disabled"));
2675
+ if (!focusables.length) { e.preventDefault(); return; }
2676
+ const first = focusables[0], last = focusables[focusables.length - 1];
2677
+ if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
2678
+ else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
2679
+ }
2680
+ };
2681
+ document.addEventListener("keydown", keyHandler);
2682
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
2683
+ this.addEventListener("click", (e) => {
2684
+ if (e.target === this) close();
2685
+ });
2686
+ // Focus management: capture focus on open, restore on close.
2687
+ const obs = new MutationObserver(() => {
2688
+ if (this.hasAttribute("open")) {
2689
+ lastFocus = document.activeElement;
2690
+ const first = this.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
2691
+ if (first) try { first.focus(); } catch (err) {}
2692
+ } else if (lastFocus) {
2693
+ try { lastFocus.focus(); } catch (err) {}
2694
+ lastFocus = null;
2695
+ }
2696
+ });
2697
+ obs.observe(this, { attributes: true, attributeFilter: ["open"] });
2698
+ onDispose(this, () => obs.disconnect());
2699
+ }
1628
2700
  }
1629
2701
  define("contour-side-sheet", ContourSideSheet);
1630
2702
 
2703
+ /**
2704
+ * Tour: web component wrapper.
2705
+ * Attributes: `steps`, `current`.
2706
+ */
1631
2707
  class ContourTour extends ContourBase {
1632
2708
  static get observed() { return ["steps", "current"]; }
1633
2709
  static get properties() { return { steps: { attribute: "steps" }, current: { attribute: "current" } }; }
1634
2710
  render() {
1635
2711
  this.classList.add("c-tour");
2712
+ this.setAttribute("role", "dialog");
2713
+ this.setAttribute("aria-modal", "true");
2714
+ this.setAttribute("aria-label", "Tour");
1636
2715
  const steps = this.getAttribute("steps");
1637
2716
  const current = Number(this.getAttribute("current") || 0);
1638
2717
  let parsed = [];
@@ -1647,21 +2726,41 @@ class ContourTour extends ContourBase {
1647
2726
  enhance() {
1648
2727
  if (this._wiredTour) return;
1649
2728
  this._wiredTour = true;
2729
+ const nextBtn = this.querySelector(".c-tour__next");
2730
+ if (nextBtn) try { nextBtn.focus(); } catch (err) {}
1650
2731
  this.addEventListener("click", (e) => {
1651
2732
  const next = e.target && e.target.closest ? e.target.closest(".c-tour__next") : null;
1652
2733
  if (next && this.contains(next)) this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { direction: "next" } }));
1653
2734
  });
2735
+ const keyHandler = (e) => { if (e.key === "Escape") this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true })); };
2736
+ document.addEventListener("keydown", keyHandler);
2737
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
1654
2738
  }
1655
2739
  }
1656
2740
  define("contour-tour", ContourTour);
1657
2741
 
2742
+ /**
2743
+ * Tags Input: web component wrapper.
2744
+ * Attributes: `value`, `placeholder`, `disabled`, `error`, `help`.
2745
+ */
1658
2746
  class ContourTagsInput extends ContourBase {
1659
- static get observed() { return ["value", "placeholder"]; }
1660
- static get properties() { return { value: { attribute: "value" }, placeholder: { attribute: "placeholder" } }; }
2747
+ static get observed() { return ["value", "placeholder", "disabled", "error", "help"]; }
2748
+ static get properties() { return { value: { attribute: "value" }, placeholder: { attribute: "placeholder" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
1661
2749
  render() {
1662
2750
  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; });
2751
+ 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
2752
  input.placeholder = this.getAttribute("placeholder") || "Add tag…";
2753
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
2754
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
2755
+ const err = this.getAttribute("error");
2756
+ const help = this.getAttribute("help");
2757
+ let msg = this.querySelector(".c-tags-input__message");
2758
+ if (err || help) {
2759
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-tags-input__message"; this.appendChild(msg); }
2760
+ msg.textContent = err || help || "";
2761
+ msg.classList.toggle("c-tags-input__message--error", !!err);
2762
+ } else if (msg) { msg.remove(); }
2763
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
1665
2764
  const tags = this.getAttribute("value");
1666
2765
  let parsed = [];
1667
2766
  try { parsed = tags ? JSON.parse(tags) : []; } catch (e) { parsed = tags ? tags.split(",").map((s) => s.trim()).filter(Boolean) : []; }
@@ -1682,23 +2781,60 @@ class ContourTagsInput extends ContourBase {
1682
2781
  enhance() {
1683
2782
  if (this._wiredTagsInput) return;
1684
2783
  this._wiredTagsInput = true;
2784
+ let live = this.querySelector(".c-tags-input__live");
2785
+ 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); }
2786
+ const announce = (msg) => { if (live) live.textContent = msg; };
1685
2787
  this.addEventListener("keydown", (e) => {
1686
2788
  const input = this.querySelector(".c-tags-input__input");
2789
+ if (!input) return;
1687
2790
  if (e.key === "Enter" && e.target === input) {
1688
2791
  e.preventDefault();
1689
2792
  const v = input.value.trim();
1690
- if (v) { this.dispatchEvent(new CustomEvent("contour:add", { bubbles: true, composed: true, detail: { value: v } })); input.value = ""; }
2793
+ if (v) {
2794
+ let tags = [];
2795
+ try { tags = JSON.parse(this.getAttribute("value") || "[]"); } catch (err) { tags = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean); }
2796
+ if (!Array.isArray(tags)) tags = [];
2797
+ if (!tags.includes(v)) tags.push(v);
2798
+ this.setAttribute("value", JSON.stringify(tags));
2799
+ input.value = "";
2800
+ announce("Added " + v);
2801
+ this.dispatchEvent(new CustomEvent("contour:add", { bubbles: true, composed: true, detail: { value: v } }));
2802
+ }
2803
+ } else if (e.key === "Backspace" && e.target === input && input.value === "") {
2804
+ let tags = [];
2805
+ try { tags = JSON.parse(this.getAttribute("value") || "[]"); } catch (err) { tags = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean); }
2806
+ if (!Array.isArray(tags)) tags = [];
2807
+ if (tags.length) {
2808
+ const removed = tags.pop();
2809
+ this.setAttribute("value", JSON.stringify(tags));
2810
+ announce("Removed " + removed);
2811
+ this.dispatchEvent(new CustomEvent("contour:remove", { bubbles: true, composed: true, detail: { value: removed } }));
2812
+ }
1691
2813
  }
1692
2814
  });
1693
2815
  this.addEventListener("click", (e) => {
1694
2816
  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 } }));
2817
+ if (rm && this.contains(rm)) {
2818
+ const val = rm.dataset.value;
2819
+ let tags = [];
2820
+ try { tags = JSON.parse(this.getAttribute("value") || "[]"); } catch (err) { tags = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean); }
2821
+ if (!Array.isArray(tags)) tags = [];
2822
+ const next = tags.filter((t) => t !== val);
2823
+ this.setAttribute("value", JSON.stringify(next));
2824
+ announce("Removed " + val);
2825
+ this.dispatchEvent(new CustomEvent("contour:remove", { bubbles: true, composed: true, detail: { value: val } }));
2826
+ }
1696
2827
  });
1697
2828
  }
1698
2829
  }
1699
2830
  define("contour-tags-input", ContourTagsInput);
1700
2831
 
2832
+ /**
2833
+ * Sortable List: web component wrapper.
2834
+ * Attributes: `items`.
2835
+ */
1701
2836
  class ContourSortableList extends ContourBase {
2837
+ static get updateMode() { return "keyed"; }
1702
2838
  static get observed() { return ["items"]; }
1703
2839
  static get properties() { return { items: { attribute: "items" } }; }
1704
2840
  render() {
@@ -1729,19 +2865,84 @@ class ContourSortableList extends ContourBase {
1729
2865
  enhance() {
1730
2866
  if (this._wiredSortableList) return;
1731
2867
  this._wiredSortableList = true;
2868
+ const list = () => this.querySelector(".c-sortable-list__list");
2869
+ // Live region for position announcements.
2870
+ let live = this.querySelector(".c-sortable-list__live");
2871
+ 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); }
2872
+ const announce = (msg) => { if (live) live.textContent = msg; };
2873
+ const index = (li) => Array.from(list().children).indexOf(li);
2874
+ // Pointer drag reorder.
2875
+ let dragFrom = null;
2876
+ this.addEventListener("dragstart", (e) => {
2877
+ const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
2878
+ if (!li || !this.contains(li)) return;
2879
+ dragFrom = index(li);
2880
+ if (e.dataTransfer) { e.dataTransfer.effectAllowed = "move"; try { e.dataTransfer.setData("text/plain", String(dragFrom)); } catch (err) {} }
2881
+ li.classList.add("is-dragging");
2882
+ });
2883
+ this.addEventListener("dragover", (e) => {
2884
+ const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
2885
+ if (!li || !this.contains(li) || dragFrom === null) return;
2886
+ e.preventDefault();
2887
+ if (e.dataTransfer) e.dataTransfer.dropEffect = "move";
2888
+ });
2889
+ this.addEventListener("drop", (e) => {
2890
+ const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
2891
+ if (!li || !this.contains(li) || dragFrom === null) return;
2892
+ e.preventDefault();
2893
+ const to = index(li);
2894
+ const l = list();
2895
+ const fromLi = l.children[dragFrom];
2896
+ if (fromLi && dragFrom !== to) {
2897
+ if (dragFrom < to) l.insertBefore(fromLi, l.children[to + 1] || null);
2898
+ else l.insertBefore(fromLi, l.children[to]);
2899
+ const item = fromLi.querySelector(".c-sortable-list__label");
2900
+ announce((item ? item.textContent : "Item") + " moved to position " + (to + 1));
2901
+ this.dispatchEvent(new CustomEvent("contour:reorder", { bubbles: true, composed: true, detail: { from: dragFrom, to } }));
2902
+ }
2903
+ dragFrom = null;
2904
+ Array.from(l.children).forEach((n) => n.classList.remove("is-dragging"));
2905
+ });
2906
+ this.addEventListener("dragend", () => {
2907
+ dragFrom = null;
2908
+ const l = list();
2909
+ if (l) Array.from(l.children).forEach((n) => n.classList.remove("is-dragging"));
2910
+ });
2911
+ // Keyboard reorder.
1732
2912
  this.addEventListener("keydown", (e) => {
1733
2913
  const handle = e.target && e.target.closest ? e.target.closest(".c-sortable-list__handle") : null;
1734
2914
  if (!handle) return;
1735
2915
  const li = handle.closest(".c-sortable-list__item");
1736
2916
  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" } })); }
2917
+ const l = list();
2918
+ const from = index(li);
2919
+ if (e.key === "ArrowUp" && li.previousElementSibling) {
2920
+ e.preventDefault();
2921
+ l.insertBefore(li, li.previousElementSibling);
2922
+ const to = index(li);
2923
+ const label = li.querySelector(".c-sortable-list__label");
2924
+ announce((label ? label.textContent : "Item") + " moved to position " + (to + 1));
2925
+ this.dispatchEvent(new CustomEvent("contour:move", { bubbles: true, composed: true, detail: { direction: "up", from, to } }));
2926
+ this.dispatchEvent(new CustomEvent("contour:reorder", { bubbles: true, composed: true, detail: { from, to } }));
2927
+ }
2928
+ if (e.key === "ArrowDown" && li.nextElementSibling) {
2929
+ e.preventDefault();
2930
+ l.insertBefore(li.nextElementSibling, li);
2931
+ const to = index(li);
2932
+ const label = li.querySelector(".c-sortable-list__label");
2933
+ announce((label ? label.textContent : "Item") + " moved to position " + (to + 1));
2934
+ this.dispatchEvent(new CustomEvent("contour:move", { bubbles: true, composed: true, detail: { direction: "down", from, to } }));
2935
+ this.dispatchEvent(new CustomEvent("contour:reorder", { bubbles: true, composed: true, detail: { from, to } }));
2936
+ }
1740
2937
  });
1741
2938
  }
1742
2939
  }
1743
2940
  define("contour-sortable-list", ContourSortableList);
1744
2941
 
2942
+ /**
2943
+ * Swatch: web component wrapper.
2944
+ * Attributes: `color`, `selected`, `label`.
2945
+ */
1745
2946
  class ContourSwatch extends ContourBase {
1746
2947
  static get observed() { return ["color", "selected", "label"]; }
1747
2948
  static get properties() { return { color: { attribute: "color" }, selected: { attribute: "selected", type: Boolean }, label: { attribute: "label" } }; }
@@ -1772,16 +2973,31 @@ class ContourSwatch extends ContourBase {
1772
2973
  }
1773
2974
  define("contour-swatch", ContourSwatch);
1774
2975
 
2976
+ /**
2977
+ * Calendar: web component wrapper.
2978
+ * Attributes: `value`.
2979
+ */
1775
2980
  class ContourCalendar extends ContourBase {
1776
- static get observed() { return ["value", "month"]; }
1777
- static get properties() { return { value: { attribute: "value" }, month: { attribute: "month" } }; }
2981
+ static get observed() { return ["value"]; }
2982
+ static get properties() { return { value: { attribute: "value" }, month: { attribute: "month" }, year: { attribute: "year" } }; }
1778
2983
  render() {
1779
2984
  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
2985
  const now = new Date();
1783
- const year = now.getFullYear();
2986
+ const year = Number(this.getAttribute("year")) || now.getFullYear();
1784
2987
  const month = Number(this.getAttribute("month")) || now.getMonth();
2988
+ const header = this.ensure(".c-calendar__header", () => { const el = document.createElement("div"); el.className = "c-calendar__header"; return el; });
2989
+ header.innerHTML = "";
2990
+ const prev = document.createElement("button");
2991
+ prev.type = "button"; prev.className = "c-btn c-btn--sm c-calendar__prev"; prev.textContent = "‹"; prev.setAttribute("aria-label", "Previous month");
2992
+ const title = document.createElement("span");
2993
+ title.className = "c-calendar__title";
2994
+ title.textContent = new Date(year, month, 1).toLocaleString(undefined, { month: "long", year: "numeric" });
2995
+ const next = document.createElement("button");
2996
+ next.type = "button"; next.className = "c-btn c-btn--sm c-calendar__next"; next.textContent = "›"; next.setAttribute("aria-label", "Next month");
2997
+ header.appendChild(prev); header.appendChild(title); header.appendChild(next);
2998
+ const grid = this.ensure(".c-calendar__grid", () => { const el = document.createElement("div"); el.className = "c-calendar__grid"; el.setAttribute("role", "grid"); return el; });
2999
+ grid.setAttribute("aria-label", title.textContent);
3000
+ grid.innerHTML = "";
1785
3001
  const first = new Date(year, month, 1);
1786
3002
  const startDay = first.getDay();
1787
3003
  const daysInMonth = new Date(year, month + 1, 0).getDate();
@@ -1795,65 +3011,174 @@ class ContourCalendar extends ContourBase {
1795
3011
  const cell = document.createElement("button");
1796
3012
  cell.className = "c-calendar__day";
1797
3013
  cell.type = "button";
3014
+ cell.setAttribute("role", "gridcell");
3015
+ cell.setAttribute("tabindex", "0");
1798
3016
  cell.textContent = String(d);
1799
3017
  const iso = year + "-" + String(month + 1).padStart(2, "0") + "-" + String(d).padStart(2, "0");
1800
- if (iso === selected) cell.classList.add("is-selected");
3018
+ if (iso === selected) { cell.classList.add("is-selected"); cell.setAttribute("aria-selected", "true"); }
3019
+ else cell.setAttribute("aria-selected", "false");
3020
+ const todayIso = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0") + "-" + String(now.getDate()).padStart(2, "0");
3021
+ if (iso === todayIso) cell.setAttribute("aria-current", "date");
1801
3022
  cell.dataset.value = iso;
1802
3023
  grid.appendChild(cell);
1803
3024
  }
3025
+ if (header.parentNode !== this) this.insertBefore(header, grid);
1804
3026
  }
1805
3027
  enhance() {
1806
3028
  if (this._wiredCalendar) return;
1807
3029
  this._wiredCalendar = true;
1808
3030
  this.addEventListener("click", (e) => {
3031
+ const prev = e.target && e.target.closest ? e.target.closest(".c-calendar__prev") : null;
3032
+ const next = e.target && e.target.closest ? e.target.closest(".c-calendar__next") : null;
3033
+ if (prev && this.contains(prev)) {
3034
+ let m = Number(this.getAttribute("month")) || new Date().getMonth();
3035
+ let y = Number(this.getAttribute("year")) || new Date().getFullYear();
3036
+ m -= 1;
3037
+ if (m < 0) { m = 11; y -= 1; }
3038
+ this.setAttribute("month", String(m));
3039
+ this.setAttribute("year", String(y));
3040
+ this.render();
3041
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { month: m, year: y } }));
3042
+ return;
3043
+ }
3044
+ if (next && this.contains(next)) {
3045
+ let m = Number(this.getAttribute("month")) || new Date().getMonth();
3046
+ let y = Number(this.getAttribute("year")) || new Date().getFullYear();
3047
+ m += 1;
3048
+ if (m > 11) { m = 0; y += 1; }
3049
+ this.setAttribute("month", String(m));
3050
+ this.setAttribute("year", String(y));
3051
+ this.render();
3052
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { month: m, year: y } }));
3053
+ return;
3054
+ }
1809
3055
  const cell = e.target && e.target.closest ? e.target.closest(".c-calendar__day") : null;
1810
3056
  if (cell && this.contains(cell) && cell.dataset.value) {
3057
+ this.setAttribute("value", cell.dataset.value);
1811
3058
  this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { value: cell.dataset.value } }));
1812
3059
  }
1813
3060
  });
3061
+ this.addEventListener("keydown", (e) => {
3062
+ const cell = e.target && e.target.closest ? e.target.closest(".c-calendar__day") : null;
3063
+ if (!cell || !this.contains(cell)) return;
3064
+ const cells = Array.from(this.querySelectorAll(".c-calendar__day:not(.c-calendar__day--empty)"));
3065
+ const idx = cells.indexOf(cell);
3066
+ let next = null;
3067
+ if (e.key === "ArrowRight") next = cells[idx + 1];
3068
+ else if (e.key === "ArrowLeft") next = cells[idx - 1];
3069
+ else if (e.key === "ArrowDown") next = cells[idx + 7];
3070
+ else if (e.key === "ArrowUp") next = cells[idx - 7];
3071
+ else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); cell.click(); return; }
3072
+ if (next) { e.preventDefault(); try { next.focus(); } catch (err) {} }
3073
+ });
1814
3074
  }
1815
3075
  }
1816
3076
  define("contour-calendar", ContourCalendar);
1817
3077
 
3078
+ /**
3079
+ * Carousel: web component wrapper.
3080
+ * Attributes: `items`, `index`.
3081
+ */
1818
3082
  class ContourCarousel extends ContourBase {
1819
3083
  static get observed() { return ["items", "index"]; }
1820
3084
  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; });
3085
+ _items() {
1824
3086
  const items = this.getAttribute("items");
1825
3087
  let parsed = [];
1826
3088
  try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
3089
+ return Array.isArray(parsed) ? parsed : [];
3090
+ }
3091
+ _index() {
3092
+ const i = Number(this.getAttribute("index"));
3093
+ const items = this._items();
3094
+ if (Number.isFinite(i) && i >= 0 && i < items.length) return i;
3095
+ return 0;
3096
+ }
3097
+ render() {
3098
+ this.classList.add("c-carousel");
3099
+ this.setAttribute("role", "region");
3100
+ this.setAttribute("aria-roledescription", "carousel");
3101
+ 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; });
3102
+ const items = this._items();
1827
3103
  track.innerHTML = "";
1828
- parsed.forEach((it, i) => {
3104
+ const idx = this._index();
3105
+ items.forEach((it, i) => {
1829
3106
  const slide = document.createElement("div");
1830
- slide.className = "c-carousel__slide";
3107
+ slide.className = "c-carousel__slide" + (i === idx ? " is-active" : "");
3108
+ slide.setAttribute("role", "group");
3109
+ slide.setAttribute("aria-roledescription", "slide");
3110
+ slide.setAttribute("aria-label", (i + 1) + " of " + items.length);
3111
+ slide.setAttribute("aria-hidden", i === idx ? "false" : "true");
1831
3112
  slide.textContent = typeof it === "string" ? it : (it.label || it.text || "");
1832
3113
  slide.dataset.index = String(i);
1833
3114
  track.appendChild(slide);
1834
3115
  });
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; });
3116
+ 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; });
3117
+ 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; });
3118
+ const status = this.ensure(".c-carousel__status", () => { const el = document.createElement("span"); el.className = "c-carousel__status"; el.setAttribute("aria-live", "polite"); return el; });
3119
+ status.textContent = (idx + 1) + " of " + items.length;
1837
3120
  }
1838
3121
  enhance() {
1839
3122
  if (this._wiredCarousel) return;
1840
3123
  this._wiredCarousel = true;
3124
+ const go = (dir) => {
3125
+ const items = this._items();
3126
+ if (!items.length) return;
3127
+ let idx = this._index();
3128
+ if (dir === "prev") idx = (idx - 1 + items.length) % items.length;
3129
+ else idx = (idx + 1) % items.length;
3130
+ this.setAttribute("index", String(idx));
3131
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: idx, direction: dir } }));
3132
+ };
1841
3133
  this.addEventListener("click", (e) => {
1842
3134
  const prev = e.target && e.target.closest ? e.target.closest(".c-carousel__prev") : null;
1843
3135
  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" } }));
3136
+ if (prev && this.contains(prev)) go("prev");
3137
+ if (next && this.contains(next)) go("next");
3138
+ });
3139
+ this.addEventListener("keydown", (e) => {
3140
+ if (e.key === "ArrowLeft") { e.preventDefault(); go("prev"); }
3141
+ else if (e.key === "ArrowRight") { e.preventDefault(); go("next"); }
3142
+ 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" } })); }
3143
+ 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
3144
  });
1847
3145
  }
1848
3146
  }
1849
3147
  define("contour-carousel", ContourCarousel);
1850
3148
 
3149
+ /**
3150
+ * Data Grid: web component wrapper.
3151
+ * Attributes: `columns`, `rows`, `page`, `filter`, `page-size`, `resizable`.
3152
+ */
1851
3153
  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" } }; }
3154
+ static get updateMode() { return "keyed"; }
3155
+ static get observed() { return ["columns", "rows", "page", "filter", "page-size", "resizable", "virtual", "row-height"]; }
3156
+ 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
3157
  render() {
1855
3158
  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; });
3159
+ if (this.hasAttribute("loading") || this.hasAttribute("error") || this.hasAttribute("empty")) {
3160
+ 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; });
3161
+ const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
3162
+ if (tbody.parentNode !== table) table.appendChild(tbody);
3163
+ tbody.innerHTML = "";
3164
+ const tr = document.createElement("tr");
3165
+ const td = document.createElement("td");
3166
+ td.colSpan = 1;
3167
+ td.style.textAlign = "center";
3168
+ td.style.color = "var(--color-text-muted)";
3169
+ if (this.hasAttribute("loading")) td.textContent = this.getAttribute("loading") || "Loading…";
3170
+ else if (this.hasAttribute("error")) td.textContent = this.getAttribute("error") || "Error";
3171
+ else td.textContent = this.getAttribute("empty") || "No data";
3172
+ tr.appendChild(td);
3173
+ tbody.appendChild(tr);
3174
+ // Wrap in a scroll container for virtualization of large datasets.
3175
+ let wrap = this.querySelector(".c-data-grid__wrap");
3176
+ if (!wrap) { wrap = document.createElement("div"); wrap.className = "c-data-grid__wrap"; wrap.style.maxHeight = "400px"; wrap.style.overflow = "auto"; }
3177
+ if (table.parentNode !== wrap) wrap.appendChild(table);
3178
+ if (wrap.parentNode !== this) this.appendChild(wrap);
3179
+ return;
3180
+ }
3181
+ 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
3182
  const thead = this.ensure("thead", () => { const el = document.createElement("thead"); return el; });
1858
3183
  const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
1859
3184
  if (thead.parentNode !== table) table.appendChild(thead);
@@ -1865,53 +3190,366 @@ class ContourDataGrid extends ContourBase {
1865
3190
  const tr = document.createElement("tr");
1866
3191
  parsedCols.forEach((c) => {
1867
3192
  const th = document.createElement("th");
3193
+ th.setAttribute("role", "columnheader");
3194
+ th.setAttribute("aria-sort", "none");
3195
+ th.setAttribute("tabindex", "0");
1868
3196
  th.textContent = typeof c === "string" ? c : (c.label || c.key || "");
1869
3197
  tr.appendChild(th);
1870
3198
  });
1871
3199
  thead.appendChild(tr);
1872
3200
  }
3201
+ if (this.hasAttribute("resizable")) {
3202
+ Array.from(thead.querySelectorAll("th")).forEach((th) => {
3203
+ th.style.position = "relative";
3204
+ th.setAttribute("data-resizable", "true");
3205
+ });
3206
+ }
1873
3207
  const rows = this.getAttribute("rows");
1874
3208
  let parsedRows = [];
1875
3209
  try { parsedRows = rows ? JSON.parse(rows) : []; } catch (e) { parsedRows = []; }
3210
+ table.setAttribute("aria-rowcount", String(parsedRows.length));
3211
+ table.setAttribute("aria-colcount", String(parsedCols.length));
3212
+ const filter = this.getAttribute("filter");
3213
+ if (filter) {
3214
+ const q = filter.toLowerCase();
3215
+ parsedRows = parsedRows.filter((r) => JSON.stringify(r).toLowerCase().includes(q));
3216
+ }
3217
+ const page = Number(this.getAttribute("page") || 1);
3218
+ const pageSize = Number(this.getAttribute("page-size") || 0);
3219
+ if (pageSize > 0) {
3220
+ const start = (page - 1) * pageSize;
3221
+ parsedRows = parsedRows.slice(start, start + pageSize);
3222
+ }
3223
+ this._dgCols = parsedCols;
3224
+ this._dgRows = parsedRows;
3225
+ this._dgFilteredRows = parsedRows;
3226
+ const virtual = this.hasAttribute("virtual") && !(Number(this.getAttribute("page-size")) > 0);
3227
+ if (virtual) {
3228
+ this._renderDataGridWindow(0);
3229
+ } else {
3230
+ tbody.innerHTML = "";
3231
+ parsedRows.forEach((r) => {
3232
+ const tr = document.createElement("tr");
3233
+ parsedCols.forEach((c) => {
3234
+ const key = typeof c === "string" ? c : (c.key || c.label || "");
3235
+ const td = document.createElement("td");
3236
+ td.setAttribute("role", "gridcell");
3237
+ td.setAttribute("tabindex", "0");
3238
+ td.textContent = r && r[key] != null ? r[key] : "";
3239
+ if (!String(td.textContent).trim()) td.setAttribute("aria-label", "Empty");
3240
+ tr.appendChild(td);
3241
+ });
3242
+ tbody.appendChild(tr);
3243
+ });
3244
+ }
3245
+ // Wrap in a scroll container for virtualization of large datasets.
3246
+ let wrap = this.querySelector(".c-data-grid__wrap");
3247
+ if (!wrap) { wrap = document.createElement("div"); wrap.className = "c-data-grid__wrap"; wrap.style.maxHeight = "400px"; wrap.style.overflow = "auto"; }
3248
+ if (table.parentNode !== wrap) wrap.appendChild(table);
3249
+ if (wrap.parentNode !== this) this.appendChild(wrap);
3250
+ }
3251
+ _rowHeight() {
3252
+ const h = Number(this.getAttribute("row-height"));
3253
+ return Number.isFinite(h) && h > 0 ? h : 32;
3254
+ }
3255
+ _renderDataGridWindow(scrollTop) {
3256
+ const table = this.querySelector(".c-data-grid__table");
3257
+ const tbody = table && table.querySelector("tbody");
3258
+ if (!tbody) return;
3259
+ const cols = this._dgCols || [];
3260
+ const rows = this._dgRows || [];
3261
+ const rh = this._rowHeight();
3262
+ const viewport = 400;
3263
+ const visibleCount = Math.ceil(viewport / rh) + 6;
3264
+ let start = Math.floor((scrollTop || 0) / rh);
3265
+ if (start < 0) start = 0;
3266
+ if (start > Math.max(0, rows.length - visibleCount)) start = Math.max(0, rows.length - visibleCount);
3267
+ const end = Math.min(rows.length, start + visibleCount);
1876
3268
  tbody.innerHTML = "";
1877
- parsedRows.forEach((r) => {
3269
+ // top spacer
3270
+ if (start > 0) {
3271
+ const sp = document.createElement("tr");
3272
+ const td = document.createElement("td");
3273
+ td.colSpan = Math.max(1, cols.length);
3274
+ td.style.blockSize = (start * rh) + "px";
3275
+ td.style.padding = "0";
3276
+ sp.appendChild(td);
3277
+ tbody.appendChild(sp);
3278
+ }
3279
+ for (let i = start; i < end; i++) {
3280
+ const r = rows[i];
1878
3281
  const tr = document.createElement("tr");
1879
- parsedCols.forEach((c) => {
3282
+ tr.dataset.index = String(i);
3283
+ cols.forEach((c) => {
1880
3284
  const key = typeof c === "string" ? c : (c.key || c.label || "");
1881
3285
  const td = document.createElement("td");
3286
+ td.setAttribute("role", "gridcell");
3287
+ td.setAttribute("tabindex", "0");
1882
3288
  td.textContent = r && r[key] != null ? r[key] : "";
3289
+ if (!String(td.textContent).trim()) td.setAttribute("aria-label", "Empty");
1883
3290
  tr.appendChild(td);
1884
3291
  });
1885
3292
  tbody.appendChild(tr);
3293
+ }
3294
+ if (end < rows.length) {
3295
+ const sp = document.createElement("tr");
3296
+ const td = document.createElement("td");
3297
+ td.colSpan = Math.max(1, cols.length);
3298
+ td.style.blockSize = ((rows.length - end) * rh) + "px";
3299
+ td.style.padding = "0";
3300
+ sp.appendChild(td);
3301
+ tbody.appendChild(sp);
3302
+ }
3303
+ }
3304
+ enhance() {
3305
+ if (this._wiredDataGrid) return;
3306
+ this._wiredDataGrid = true;
3307
+ const wrap = () => this.querySelector(".c-data-grid__wrap");
3308
+ const onScroll = () => {
3309
+ const w = wrap();
3310
+ if (w && this.hasAttribute("virtual")) this._renderDataGridWindow(w.scrollTop);
3311
+ };
3312
+ // attach after render creates wrap; use delegated listener on host
3313
+ this.addEventListener("scroll", (e) => {
3314
+ const w = e.target && e.target.classList && e.target.classList.contains("c-data-grid__wrap") ? e.target : null;
3315
+ if (w && this.hasAttribute("virtual")) this._renderDataGridWindow(w.scrollTop);
3316
+ }, true);
3317
+ let sortCol = -1, sortDir = "asc";
3318
+ this.addEventListener("keydown", (e) => {
3319
+ const cell = e.target && e.target.closest ? e.target.closest("[role='gridcell'], [role='columnheader']") : null;
3320
+ if (!cell || !this.contains(cell)) return;
3321
+ const row = cell.parentElement;
3322
+ const table = this.querySelector(".c-data-grid__table");
3323
+ if (!table) return;
3324
+ const rows = Array.from(table.querySelectorAll("tr"));
3325
+ const ri = rows.indexOf(row);
3326
+ const ci = Array.from(row.children).indexOf(cell);
3327
+ let target = null;
3328
+ if (e.key === "ArrowRight") target = row.children[ci + 1];
3329
+ else if (e.key === "ArrowLeft") target = row.children[ci - 1];
3330
+ else if (e.key === "ArrowDown") target = rows[ri + 1] && rows[ri + 1].children[ci];
3331
+ else if (e.key === "ArrowUp") target = rows[ri - 1] && rows[ri - 1].children[ci];
3332
+ if (target) { e.preventDefault(); try { target.focus(); } catch (err) {} }
3333
+ });
3334
+ this.addEventListener("click", (e) => {
3335
+ const tr = e.target && e.target.closest ? e.target.closest("tr") : null;
3336
+ const th = e.target && e.target.closest ? e.target.closest("th") : null;
3337
+ if (tr && this.contains(tr) && !th) {
3338
+ const idx = Array.from(tr.parentElement.children).indexOf(tr);
3339
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { row: idx } }));
3340
+ }
3341
+ if (th && this.contains(th)) {
3342
+ const idx = Array.from(th.parentElement.children).indexOf(th);
3343
+ if (sortCol === idx) sortDir = sortDir === "asc" ? "desc" : "asc";
3344
+ else { sortCol = idx; sortDir = "asc"; }
3345
+ // Re-render sorted rows.
3346
+ const table = this.querySelector(".c-data-grid__table");
3347
+ const tbody = table && table.querySelector("tbody");
3348
+ const thead = table && table.querySelector("thead");
3349
+ if (tbody && thead) {
3350
+ const cols = Array.from(thead.querySelectorAll("th")).map((h) => h.textContent);
3351
+ const rows = Array.from(tbody.querySelectorAll("tr")).map((tr) => Array.from(tr.querySelectorAll("td")).map((td) => td.textContent));
3352
+ rows.sort((a, b) => {
3353
+ const va = a[idx] || "", vb = b[idx] || "";
3354
+ const na = Number(va), nb = Number(vb);
3355
+ const cmp = (!isNaN(na) && !isNaN(nb)) ? na - nb : String(va).localeCompare(String(vb));
3356
+ return sortDir === "asc" ? cmp : -cmp;
3357
+ });
3358
+ tbody.innerHTML = "";
3359
+ rows.forEach((r) => {
3360
+ const tr = document.createElement("tr");
3361
+ r.forEach((v) => { const td = document.createElement("td"); td.textContent = v; tr.appendChild(td); });
3362
+ tbody.appendChild(tr);
3363
+ });
3364
+ }
3365
+ // Update aria-sort on headers.
3366
+ Array.from(thead.querySelectorAll("th")).forEach((h, i) => {
3367
+ h.setAttribute("aria-sort", i === idx ? (sortDir === "asc" ? "ascending" : "descending") : "none");
3368
+ });
3369
+ this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: idx, direction: sortDir } }));
3370
+ }
3371
+ });
3372
+ this.addEventListener("pointerdown", (e) => {
3373
+ if (!this.hasAttribute("resizable")) return;
3374
+ const th = e.target && e.target.closest ? e.target.closest("th[data-resizable]") : null;
3375
+ if (!th || !this.contains(th) || th.getBoundingClientRect().right - e.clientX > 10) return;
3376
+ e.preventDefault();
3377
+ const startX = e.clientX;
3378
+ const startWidth = th.getBoundingClientRect().width;
3379
+ const index = Array.from(th.parentElement.children).indexOf(th);
3380
+ const move = (event) => {
3381
+ const width = Math.max(48, startWidth + event.clientX - startX);
3382
+ const table = this.querySelector(".c-data-grid__table");
3383
+ if (table) Array.from(table.rows).forEach((row) => { if (row.children[index]) row.children[index].style.inlineSize = width + "px"; });
3384
+ };
3385
+ const stop = () => window.removeEventListener("pointermove", move);
3386
+ window.addEventListener("pointermove", move);
3387
+ window.addEventListener("pointerup", stop, { once: true });
3388
+ onDispose(this, stop);
1886
3389
  });
1887
- if (table.parentNode !== this) this.appendChild(table);
1888
3390
  }
1889
3391
  }
1890
3392
  define("contour-data-grid", ContourDataGrid);
1891
3393
 
3394
+ /**
3395
+ * Tree Grid: web component wrapper.
3396
+ * Attributes: `items`, `expanded`.
3397
+ */
1892
3398
  class ContourTreeGrid extends ContourBase {
1893
- static get observed() { return ["items"]; }
1894
- static get properties() { return { items: { attribute: "items" } }; }
3399
+ static get updateMode() { return "keyed"; }
3400
+ static get observed() { return ["items", "expanded"]; }
3401
+ static get properties() { return { items: { attribute: "items" }, expanded: { attribute: "expanded" } }; }
3402
+ _expandedSet() {
3403
+ const raw = this.getAttribute("expanded");
3404
+ if (!raw) return new Set();
3405
+ try { return new Set(JSON.parse(raw)); } catch (e) { return new Set([raw]); }
3406
+ }
1895
3407
  render() {
1896
3408
  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; });
3409
+ 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; });
3410
+ table.setAttribute("aria-label", "Tree grid");
1898
3411
  const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
1899
3412
  if (tbody.parentNode !== table) table.appendChild(tbody);
1900
3413
  const items = this.getAttribute("items");
1901
3414
  let parsed = [];
1902
3415
  try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
3416
+ const expanded = this._expandedSet();
1903
3417
  tbody.innerHTML = "";
1904
- const renderNode = (node, depth) => {
3418
+ const rows = [];
3419
+ const renderNode = (node, depth, path) => {
1905
3420
  const tr = document.createElement("tr");
3421
+ tr.setAttribute("role", "row");
3422
+ tr.setAttribute("tabindex", "0");
3423
+ tr.setAttribute("aria-level", String(depth + 1));
3424
+ tr.dataset.path = path;
3425
+ const hasChildren = !!(node && Array.isArray(node.children) && node.children.length);
3426
+ if (hasChildren) {
3427
+ tr.setAttribute("aria-expanded", expanded.has(path) ? "true" : "false");
3428
+ }
1906
3429
  const td = document.createElement("td");
3430
+ td.setAttribute("role", "gridcell");
1907
3431
  td.style.paddingInlineStart = (depth * 1.25) + "rem";
1908
- td.textContent = (node && (node.label || node.text || node.name)) || "";
3432
+ const label = (node && (node.label || node.text || node.name)) || "";
3433
+ if (hasChildren) {
3434
+ const toggle = document.createElement("button");
3435
+ toggle.type = "button";
3436
+ toggle.className = "c-tree-grid__toggle";
3437
+ toggle.textContent = expanded.has(path) ? "▾" : "▸";
3438
+ toggle.setAttribute("aria-label", (expanded.has(path) ? "Collapse" : "Expand") + " " + label);
3439
+ td.appendChild(toggle);
3440
+ }
3441
+ const span = document.createElement("span");
3442
+ span.className = "c-tree-grid__label";
3443
+ span.textContent = label;
3444
+ td.appendChild(span);
1909
3445
  tr.appendChild(td);
1910
3446
  tbody.appendChild(tr);
1911
- if (node && Array.isArray(node.children)) node.children.forEach((c) => renderNode(c, depth + 1));
3447
+ rows.push(tr);
3448
+ if (hasChildren && expanded.has(path)) {
3449
+ node.children.forEach((c, i) => renderNode(c, depth + 1, path + "." + i));
3450
+ }
1912
3451
  };
1913
- parsed.forEach((n) => renderNode(n, 0));
3452
+ parsed.forEach((n, i) => renderNode(n, 0, String(i)));
1914
3453
  if (table.parentNode !== this) this.appendChild(table);
1915
3454
  }
3455
+ enhance() {
3456
+ if (this._wiredTreeGrid) return;
3457
+ this._wiredTreeGrid = true;
3458
+ const rows = () => Array.from(this.querySelectorAll("tr[role='row']"));
3459
+ this.addEventListener("click", (e) => {
3460
+ const toggle = e.target && e.target.closest ? e.target.closest(".c-tree-grid__toggle") : null;
3461
+ const tr = e.target && e.target.closest ? e.target.closest("tr[role='row']") : null;
3462
+ if (!tr || !this.contains(tr)) return;
3463
+ const path = tr.dataset.path;
3464
+ if (toggle) {
3465
+ e.preventDefault();
3466
+ const expanded = this._expandedSet();
3467
+ if (expanded.has(path)) expanded.delete(path); else expanded.add(path);
3468
+ this.setAttribute("expanded", JSON.stringify([...expanded]));
3469
+ this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: expanded.has(path) } }));
3470
+ } else {
3471
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { path } }));
3472
+ }
3473
+ });
3474
+ this.addEventListener("keydown", (e) => {
3475
+ const tr = e.target && e.target.closest ? e.target.closest("tr[role='row']") : null;
3476
+ if (!tr || !this.contains(tr)) return;
3477
+ const all = rows();
3478
+ const idx = all.indexOf(tr);
3479
+ const path = tr.dataset.path;
3480
+ const hasChildren = tr.getAttribute("aria-expanded") !== null;
3481
+ const expanded = this._expandedSet();
3482
+ if (e.key === "ArrowRight" && hasChildren && !expanded.has(path)) {
3483
+ e.preventDefault();
3484
+ expanded.add(path);
3485
+ this.setAttribute("expanded", JSON.stringify([...expanded]));
3486
+ this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: true } }));
3487
+ } else if (e.key === "ArrowLeft" && hasChildren && expanded.has(path)) {
3488
+ e.preventDefault();
3489
+ expanded.delete(path);
3490
+ this.setAttribute("expanded", JSON.stringify([...expanded]));
3491
+ this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: false } }));
3492
+ } else if (e.key === "ArrowDown") {
3493
+ e.preventDefault();
3494
+ if (all[idx + 1]) try { all[idx + 1].focus(); } catch (err) {}
3495
+ } else if (e.key === "ArrowUp") {
3496
+ e.preventDefault();
3497
+ if (all[idx - 1]) try { all[idx - 1].focus(); } catch (err) {}
3498
+ } else if (e.key === "Enter" || e.key === " ") {
3499
+ e.preventDefault();
3500
+ const toggle = tr.querySelector(".c-tree-grid__toggle");
3501
+ if (toggle) toggle.click();
3502
+ }
3503
+ });
3504
+ }
1916
3505
  }
1917
3506
  define("contour-tree-grid", ContourTreeGrid);
3507
+
3508
+ class ContourPullToRefresh extends ContourBase {
3509
+ static get observed() { return ["threshold"]; }
3510
+ static get properties() { return { threshold: { attribute: "threshold" } }; }
3511
+ render() {
3512
+ this.classList.add("c-pull-to-refresh");
3513
+ const ind = this.ensure(".c-pull-to-refresh__indicator", () => {
3514
+ const e = document.createElement("div");
3515
+ e.className = "c-pull-to-refresh__indicator";
3516
+ e.textContent = "Pull to refresh";
3517
+ return e;
3518
+ });
3519
+ if (ind.parentNode !== this) this.prepend(ind);
3520
+ }
3521
+ enhance() {
3522
+ if (this._wiredPullToRefresh) return;
3523
+ this._wiredPullToRefresh = true;
3524
+ let startY = 0;
3525
+ let pulling = false;
3526
+ this.addEventListener("touchstart", (e) => {
3527
+ if (this.scrollTop > 0) return;
3528
+ const t = e.touches && e.touches[0];
3529
+ if (t) { startY = t.clientY; pulling = true; }
3530
+ }, { passive: true });
3531
+ this.addEventListener("touchmove", (e) => {
3532
+ if (!pulling) return;
3533
+ const t = e.touches && e.touches[0];
3534
+ if (!t) return;
3535
+ const dy = t.clientY - startY;
3536
+ if (dy > 0 && dy < 120) {
3537
+ this.style.setProperty("--ptr-offset", dy + "px");
3538
+ }
3539
+ }, { passive: true });
3540
+ this.addEventListener("touchend", (e) => {
3541
+ if (!pulling) return;
3542
+ pulling = false;
3543
+ const t = e.changedTouches && e.changedTouches[0];
3544
+ const dy = t ? t.clientY - startY : 0;
3545
+ const thr = Number(this.getAttribute("threshold")) || 60;
3546
+ if (dy >= thr) {
3547
+ this.classList.add("is-refreshing");
3548
+ this.dispatchEvent(new CustomEvent("contour:refresh", { bubbles: true, composed: true }));
3549
+ setTimeout(() => this.classList.remove("is-refreshing"), 800);
3550
+ }
3551
+ this.style.removeProperty("--ptr-offset");
3552
+ }, { passive: true });
3553
+ }
3554
+ }
3555
+ define("contour-pull-to-refresh", ContourPullToRefresh);