contour-ds 1.1.0 → 1.1.2

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 (54) hide show
  1. package/README.md +1 -1
  2. package/dist/build-manifest.json +43 -43
  3. package/dist/contour-wc.esm.js +794 -184
  4. package/dist/contour-wc.esm.min.js +1 -1
  5. package/dist/contour-wc.js +794 -184
  6. package/dist/contour-wc.min.js +1 -1
  7. package/dist/contour.components.json +67 -21
  8. package/dist/contour.css +113 -36
  9. package/dist/contour.d.ts +1 -0
  10. package/dist/contour.min.css +1 -1
  11. package/dist/contour.themes.json +4 -1
  12. package/dist/contour.tokens.json +3 -0
  13. package/dist/docs/actions.md +1 -1
  14. package/dist/docs/affordances.md +1 -1
  15. package/dist/docs/colour.md +1 -1
  16. package/dist/docs/data.md +1 -1
  17. package/dist/docs/docs.md +1 -1
  18. package/dist/docs/feedback.md +1 -1
  19. package/dist/docs/field.md +1 -1
  20. package/dist/docs/forms.md +1 -1
  21. package/dist/docs/index.json +3 -3
  22. package/dist/docs/install.md +1 -1
  23. package/dist/docs/landing.md +1 -1
  24. package/dist/docs/mapengine.md +1 -1
  25. package/dist/docs/motion.md +1 -1
  26. package/dist/docs/navigation.md +1 -1
  27. package/dist/docs/overlays.md +1 -1
  28. package/dist/docs/overview.md +1 -1
  29. package/dist/docs/patterns.md +1 -1
  30. package/dist/docs/playground.md +1 -1
  31. package/dist/docs/principles.md +1 -1
  32. package/dist/docs/recipes.md +1 -1
  33. package/dist/docs/space.md +1 -1
  34. package/dist/docs/status.md +1 -1
  35. package/dist/docs/surfaces.md +1 -1
  36. package/dist/docs/theming.md +1 -1
  37. package/dist/docs/type.md +1 -1
  38. package/dist/docs/webcomponents.md +1 -1
  39. package/dist/registry/items/contour-core.json +2 -2
  40. package/dist/registry/items/contour-data.json +2 -2
  41. package/dist/registry/items/contour-docs.json +2 -2
  42. package/dist/registry/items/contour-landing.json +2 -2
  43. package/dist/registry/registry.json +8 -8
  44. package/dist/surfaces/contour-core.min.css +1 -1
  45. package/dist/surfaces/contour-data.min.css +1 -1
  46. package/dist/surfaces/contour-docs.min.css +1 -1
  47. package/dist/surfaces/contour-landing.min.css +1 -1
  48. package/dist/wc/core.mjs +13 -3
  49. package/dist/wc/data.mjs +302 -36
  50. package/dist/wc/forms.mjs +119 -61
  51. package/dist/wc/map.mjs +190 -69
  52. package/dist/wc/navigation.mjs +66 -11
  53. package/dist/wc/ui.mjs +104 -4
  54. package/package.json +1 -1
package/dist/wc/forms.mjs CHANGED
@@ -191,72 +191,130 @@ class ContourField extends ContourBase {
191
191
  };
192
192
  define("contour-field", ContourField);
193
193
  class ContourRange extends ContourBase {
194
- static get observed() { return ["min", "max", "value", "label"]; }
194
+ static get observed() { return ["min", "max", "value", "low", "high", "range", "sparkline", "label"]; }
195
195
  static get formAssociated() { return true; }
196
196
  static get properties() { return { min: { attribute: "min" }, max: { attribute: "max" }, value: { attribute: "value" }, label: { attribute: "label" } }; }
197
- render() {
198
- this.classList.add("c-range");
199
- const input = this.ensure("input", () => { const el = document.createElement("input"); el.type = "range"; return el; });
200
- input.type = "range";
201
- input.className = "c-range";
202
- input.min = this.getAttribute("min") || "0";
203
- input.max = this.getAttribute("max") || "100";
204
- const attrVal = this.getAttribute("value") || "50";
205
- if (this._rangeUserValue !== null && this._rangeAttrAtDirty === (this.getAttribute("value") || "50")) {
206
- input.value = this._rangeUserValue;
207
- } else {
208
- input.value = attrVal;
209
- this._rangeUserValue = null;
210
- this._rangeAttrAtDirty = null;
211
- }
212
- const label = this.getAttribute("label");
213
- if (label) input.setAttribute("aria-label", label);
214
- else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Range");
215
- // Fill the track to the left of the thumb.
216
- const updateFill = () => {
217
- const min = Number(input.min) || 0;
218
- const max = Number(input.max) || 100;
219
- const val = Number(input.value) || 0;
220
- const pct = max > min ? ((val - min) / (max - min)) * 100 : 0;
221
- input.style.setProperty("--fill", pct + "%");
222
- };
223
- updateFill();
224
- if (!input._fillWired) {
225
- input._fillWired = true;
226
- input.addEventListener("input", updateFill);
227
- }
228
- }
197
+ render() {
198
+ this.classList.add("c-range");
199
+ const min = this.getAttribute("min") || "0";
200
+ const max = this.getAttribute("max") || "100";
201
+ const rangeMode = this.hasAttribute("range") || this.hasAttribute("low") || this.hasAttribute("high");
202
+ // sparkline canvas
203
+ const spark = this.getAttribute("sparkline");
204
+ if (spark) {
205
+ let canvas = this.querySelector(".c-range__sparkline");
206
+ if (!canvas) { canvas = document.createElement("canvas"); canvas.className = "c-range__sparkline"; canvas.setAttribute("part", "sparkline-canvas"); this.insertBefore(canvas, this.firstChild); }
207
+ } else {
208
+ const c = this.querySelector(".c-range__sparkline");
209
+ if (c) c.remove();
210
+ }
211
+ if (rangeMode) {
212
+ // remove single input if present
213
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
214
+ // keep generic input? We'll use two named inputs
215
+ let lowInput = this.querySelector("input.c-range__low");
216
+ if (!lowInput) { lowInput = document.createElement("input"); lowInput.type = "range"; lowInput.className = "c-range c-range__low"; this.appendChild(lowInput); }
217
+ let highInput = this.querySelector("input.c-range__high");
218
+ if (!highInput) { highInput = document.createElement("input"); highInput.type = "range"; highInput.className = "c-range c-range__high"; this.appendChild(highInput); }
219
+ lowInput.min = min; lowInput.max = max;
220
+ highInput.min = min; highInput.max = max;
221
+ const lowVal = this.getAttribute("low") || min;
222
+ const highVal = this.getAttribute("high") || max;
223
+ if (this._rangeUserLow !== null && this._rangeAttrLowAtDirty === (this.getAttribute("low") || min)) lowInput.value = this._rangeUserLow;
224
+ else { lowInput.value = lowVal; this._rangeUserLow = null; this._rangeAttrLowAtDirty = null; }
225
+ if (this._rangeUserHigh !== null && this._rangeAttrHighAtDirty === (this.getAttribute("high") || max)) highInput.value = this._rangeUserHigh;
226
+ else { highInput.value = highVal; this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
227
+ const label = this.getAttribute("label");
228
+ if (label) { lowInput.setAttribute("aria-label", label + " low"); highInput.setAttribute("aria-label", label + " high"); }
229
+ } else {
230
+ // remove dual inputs
231
+ Array.from(this.querySelectorAll("input.c-range__low, input.c-range__high")).forEach((n) => n.remove());
232
+ const input = this.ensure("input.c-range", () => { const el = document.createElement("input"); el.type = "range"; return el; });
233
+ // ensure class
234
+ input.className = "c-range";
235
+ input.type = "range";
236
+ input.min = min;
237
+ input.max = max;
238
+ const attrVal = this.getAttribute("value") || "50";
239
+ if (this._rangeUserValue !== null && this._rangeAttrAtDirty === (this.getAttribute("value") || "50")) {
240
+ input.value = this._rangeUserValue;
241
+ } else {
242
+ input.value = attrVal;
243
+ this._rangeUserValue = null;
244
+ this._rangeAttrAtDirty = null;
245
+ }
246
+ const label = this.getAttribute("label");
247
+ if (label) input.setAttribute("aria-label", label);
248
+ else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Range");
249
+ const updateFill = () => {
250
+ const mn = Number(input.min) || 0;
251
+ const mx = Number(input.max) || 100;
252
+ const val = Number(input.value) || 0;
253
+ const pct = mx > mn ? ((val - mn) / (mx - mn)) * 100 : 0;
254
+ input.style.setProperty("--fill", pct + "%");
255
+ };
256
+ updateFill();
257
+ if (!input._fillWired) {
258
+ input._fillWired = true;
259
+ input.addEventListener("input", updateFill);
260
+ }
261
+ }
262
+ }
229
263
  }
230
264
  // patch enhance onto ContourRange
231
265
  const _origRangeRender = ContourRange.prototype.render;
232
- ContourRange.prototype.attributeChangedCallback = function(name, oldValue, newValue) {
233
- if (name === "value") { this._rangeUserValue = null; this._rangeAttrAtDirty = null; }
234
- return ContourBase.prototype.attributeChangedCallback.call(this, name, oldValue, newValue);
235
- };
236
- ContourRange.prototype.enhance = function() {
237
- if (this._wiredRange) return;
238
- this._wiredRange = true;
239
- const sync = () => {
240
- const input = this.querySelector("input");
241
- if (!input || !this._internals) return;
242
- this._internals.setFormValue(input.value);
243
- };
244
- this.addEventListener("input", (e) => {
245
- const input = this.querySelector("input");
246
- if (!input || e.target !== input) return;
247
- this._rangeUserValue = input.value;
248
- this._rangeAttrAtDirty = this.getAttribute("value") || "50";
249
- sync();
250
- this._emitForm("contour:input");
251
- });
252
- this.addEventListener("change", (e) => {
253
- const input = this.querySelector("input");
254
- if (!input || e.target !== input) return;
255
- sync();
256
- this._emitForm("contour:change");
257
- });
258
- sync();
259
- };
266
+ ContourRange.prototype.attributeChangedCallback = function(name, oldValue, newValue) {
267
+ if (name === "value") { this._rangeUserValue = null; this._rangeAttrAtDirty = null; }
268
+ if (name === "low") { this._rangeUserLow = null; this._rangeAttrLowAtDirty = null; }
269
+ if (name === "high") { this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
270
+ return ContourBase.prototype.attributeChangedCallback.call(this, name, oldValue, newValue);
271
+ };
272
+ ContourRange.prototype.enhance = function() {
273
+ if (this._wiredRange) return;
274
+ this._wiredRange = true;
275
+ const sync = () => {
276
+ const low = this.querySelector("input.c-range__low");
277
+ const high = this.querySelector("input.c-range__high");
278
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
279
+ if (this._internals) {
280
+ if (low && high) this._internals.setFormValue(low.value + "," + high.value);
281
+ else if (single) this._internals.setFormValue(single.value);
282
+ }
283
+ };
284
+ this.addEventListener("input", (e) => {
285
+ const low = this.querySelector("input.c-range__low");
286
+ const high = this.querySelector("input.c-range__high");
287
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
288
+ if (low && high && (e.target === low || e.target === high)) {
289
+ this._rangeUserLow = low.value;
290
+ this._rangeUserHigh = high.value;
291
+ this._rangeAttrLowAtDirty = this.getAttribute("low") || (this.getAttribute("min") || "0");
292
+ this._rangeAttrHighAtDirty = this.getAttribute("high") || (this.getAttribute("max") || "100");
293
+ sync();
294
+ this._emitForm("contour:input", { low: Number(low.value), high: Number(high.value) });
295
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { low: Number(low.value), high: Number(high.value) } }));
296
+ } else if (single && e.target === single) {
297
+ this._rangeUserValue = single.value;
298
+ this._rangeAttrAtDirty = this.getAttribute("value") || "50";
299
+ sync();
300
+ this._emitForm("contour:input");
301
+ }
302
+ });
303
+ this.addEventListener("change", (e) => {
304
+ const low = this.querySelector("input.c-range__low");
305
+ const high = this.querySelector("input.c-range__high");
306
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
307
+ if (low && high && (e.target === low || e.target === high)) {
308
+ sync();
309
+ this._emitForm("contour:change", { low: Number(low.value), high: Number(high.value) });
310
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { low: Number(low.value), high: Number(high.value) } }));
311
+ } else if (single && e.target === single) {
312
+ sync();
313
+ this._emitForm("contour:change");
314
+ }
315
+ });
316
+ sync();
317
+ };
260
318
  define("contour-range", ContourRange);
261
319
  class ContourSwitch extends ContourBase {
262
320
  static get observed() { return ["label", "required", "checked"]; }
package/dist/wc/map.mjs CHANGED
@@ -185,7 +185,7 @@ class ContourCoordinate extends ContourBase {
185
185
  }
186
186
  define("contour-coordinate", ContourCoordinate);
187
187
  class ContourLayerPanel extends ContourBase {
188
- static get observed() { return ["label", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
188
+ static get observed() { return ["label", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "allow-rename", "allow-remove", "allow-duplicate", "allow-zoom"]; }
189
189
  static get properties() { return { label: { attribute: "label" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
190
190
  render() {
191
191
  this.classList.add("c-layer-panel");
@@ -206,19 +206,24 @@ class ContourLayerPanel extends ContourBase {
206
206
  const authoredLayerItems = Array.from(this.querySelectorAll(":scope > .c-layer-panel__item"));
207
207
  // Preserve user-toggled visibility across re-renders (B3-09): a src
208
208
  // reload must not re-check a layer the user un-checked.
209
- const savedVisibility = new Map();
210
- this.querySelectorAll(".c-layer-panel__item").forEach((el) => {
211
- const nm = el.querySelector(".c-layer-panel__name");
212
- const tg = el.querySelector(".c-layer-panel__toggle");
213
- if (nm && tg) savedVisibility.set(nm.textContent, tg.checked);
214
- });
209
+ const savedVisibility = new Map();
210
+ this.querySelectorAll(".c-layer-panel__item").forEach((el) => {
211
+ const nm = el.querySelector(".c-layer-panel__name");
212
+ const tg = el.querySelector(".c-layer-panel__toggle");
213
+ if (nm && tg) {
214
+ const v = tg.hasAttribute("aria-pressed") ? tg.getAttribute("aria-pressed") === "true" : !!tg.checked;
215
+ savedVisibility.set(nm.textContent, v);
216
+ }
217
+ });
215
218
  let parsed = null;
216
219
  if (authoredLayerItems.length) {
217
- parsed = authoredLayerItems.map((el) => {
218
- const nm = el.querySelector(".c-layer-panel__name");
219
- const tg = el.querySelector(".c-layer-panel__toggle");
220
- return { name: nm ? nm.textContent : "", visible: tg ? tg.checked : true };
221
- });
220
+ parsed = authoredLayerItems.map((el) => {
221
+ const nm = el.querySelector(".c-layer-panel__name");
222
+ const tg = el.querySelector(".c-layer-panel__toggle");
223
+ const visible = tg ? (tg.hasAttribute("aria-pressed") ? tg.getAttribute("aria-pressed") === "true" : !!tg.checked) : true;
224
+ const cap = el.querySelector(".c-layer-panel__caption");
225
+ return { name: nm ? nm.textContent : "", visible, caption: cap ? cap.textContent : (el.dataset.caption || undefined) };
226
+ });
222
227
  authoredLayerItems.forEach((el) => el.remove());
223
228
  } else if (items) {
224
229
  try {
@@ -227,21 +232,31 @@ class ContourLayerPanel extends ContourBase {
227
232
  } catch (e) { /* keep existing */ }
228
233
  }
229
234
  if (parsed) { parsed.forEach((it) => {
230
- const name = typeof it === "string" ? it : (it.name || it.label || "");
231
- const item = document.createElement("div");
232
- item.className = "c-layer-panel__item" + (it.dragging ? " c-layer-panel__item--dragging" : "");
233
- const toggle = document.createElement("input");
234
- toggle.type = "checkbox";
235
- toggle.className = "c-layer-panel__toggle";
236
- toggle.setAttribute("aria-label", "Toggle " + (name || "layer"));
237
- if (savedVisibility.has(name)) toggle.checked = savedVisibility.get(name);
238
- else if (typeof it === "object" && it.visible !== false) toggle.checked = true;
235
+ const name = typeof it === "string" ? it : (it.name || it.label || "");
236
+ const caption = (typeof it === "object" && it) ? (it.caption || it.subtitle || "") : "";
237
+ const item = document.createElement("div");
238
+ item.className = "c-layer-panel__item" + (it.dragging ? " c-layer-panel__item--dragging" : "");
239
+ const toggle = document.createElement("button");
240
+ toggle.type = "button";
241
+ toggle.className = "c-layer-panel__toggle";
242
+ toggle.setAttribute("part", "visibility-toggle");
243
+ toggle.setAttribute("aria-label", "Toggle " + (name || "layer"));
244
+ const isVisible = savedVisibility.has(name) ? savedVisibility.get(name) : (typeof it === "object" && it.visible !== false);
245
+ toggle.setAttribute("aria-pressed", String(!!isVisible));
246
+ toggle.checked = !!isVisible;
247
+ toggle.textContent = isVisible ? "●" : "○";
239
248
  item.appendChild(toggle);
240
249
  const nm = document.createElement("span");
241
250
  nm.className = "c-layer-panel__name";
242
251
  nm.textContent = name;
243
252
  item.appendChild(nm);
244
- const opacity = document.createElement("input");
253
+ if (caption) {
254
+ const cap = document.createElement("span");
255
+ cap.className = "c-layer-panel__caption";
256
+ cap.textContent = caption;
257
+ item.appendChild(cap);
258
+ }
259
+ const opacity = document.createElement("input");
245
260
  opacity.type = "range";
246
261
  opacity.className = "c-layer-panel__opacity";
247
262
  opacity.min = "0";
@@ -250,24 +265,38 @@ class ContourLayerPanel extends ContourBase {
250
265
  opacity.value = (typeof it === "object" && it.opacity != null) ? it.opacity : "100";
251
266
  item.appendChild(opacity);
252
267
  // rename input (hidden by default, toggled via button)
268
+ if (this.getAttribute("allow-rename") !== "false") {
253
269
  const renameBtn = document.createElement("button");
254
270
  renameBtn.type = "button";
255
271
  renameBtn.className = "c-layer-panel__rename";
256
272
  renameBtn.textContent = "Rename";
257
273
  renameBtn.setAttribute("aria-label", "Rename " + (name || "layer"));
258
274
  item.appendChild(renameBtn);
275
+ }
276
+ if (this.getAttribute("allow-duplicate") !== "false") {
259
277
  const dupBtn = document.createElement("button");
260
278
  dupBtn.type = "button";
261
279
  dupBtn.className = "c-layer-panel__duplicate";
262
280
  dupBtn.textContent = "Duplicate";
263
281
  dupBtn.setAttribute("aria-label", "Duplicate " + (name || "layer"));
264
282
  item.appendChild(dupBtn);
283
+ }
284
+ if (this.getAttribute("allow-zoom") !== "false") {
265
285
  const zoomBtn = document.createElement("button");
266
286
  zoomBtn.type = "button";
267
287
  zoomBtn.className = "c-layer-panel__zoom";
268
288
  zoomBtn.textContent = "Zoom";
269
289
  zoomBtn.setAttribute("aria-label", "Zoom to " + (name || "layer"));
270
290
  item.appendChild(zoomBtn);
291
+ }
292
+ if (this.getAttribute("allow-remove") !== "false") {
293
+ const removeBtn = document.createElement("button");
294
+ removeBtn.type = "button";
295
+ removeBtn.className = "c-layer-panel__remove";
296
+ removeBtn.textContent = "✕";
297
+ removeBtn.setAttribute("aria-label", "Remove " + (name || "layer"));
298
+ item.appendChild(removeBtn);
299
+ }
271
300
  const projSel = document.createElement("select");
272
301
  projSel.className = "c-layer-panel__projection";
273
302
  projSel.setAttribute("aria-label", "Projection of " + (name || "layer"));
@@ -286,43 +315,83 @@ class ContourLayerPanel extends ContourBase {
286
315
  this._wiredLayerPanel = true;
287
316
  // The panel's two controls (visibility toggle, opacity range) are rebuilt
288
317
  // on every render, so both keep the host-delegated pattern (rule 12).
289
- this.addEventListener("change", (e) => {
290
- const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
291
- if (!item || !this.contains(item)) return;
292
- const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
293
- if (e.target.classList.contains("c-layer-panel__toggle")) {
294
- this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { name, visible: e.target.checked } }));
295
- } else if (e.target.classList.contains("c-layer-panel__opacity")) {
296
- this.dispatchEvent(new CustomEvent("contour:layer-opacity", { bubbles: true, composed: true, detail: { name, opacity: Number(e.target.value) } }));
297
- } else if (e.target.classList.contains("c-layer-panel__projection")) {
298
- this.dispatchEvent(new CustomEvent("contour:layer-projection", { bubbles: true, composed: true, detail: { name, projection: e.target.value } }));
299
- }
300
- });
301
- this.addEventListener("click", (e) => {
302
- const btn = e.target && e.target.closest ? e.target.closest("button") : null;
303
- if (!btn || !this.contains(btn)) return;
304
- const item = btn.closest(".c-layer-panel__item");
305
- if (!item) return;
306
- const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
307
- if (btn.classList.contains("c-layer-panel__rename")) {
308
- const newName = prompt("Rename layer", name);
309
- const trimmed = newName ? newName.trim() : "";
310
- if (trimmed && trimmed !== name) {
311
- const nm = item.querySelector(".c-layer-panel__name");
312
- if (nm) nm.textContent = trimmed;
313
- this.dispatchEvent(new CustomEvent("contour:layer-rename", { bubbles: true, composed: true, detail: { name, newName: trimmed } }));
318
+ this.addEventListener("change", (e) => {
319
+ const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
320
+ if (!item || !this.contains(item)) return;
321
+ const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
322
+ if (e.target.classList.contains("c-layer-panel__toggle")) {
323
+ const now = (typeof e.target.checked === "boolean") ? e.target.checked : (e.target.getAttribute("aria-pressed") !== "true");
324
+ e.target.checked = now;
325
+ e.target.setAttribute("aria-pressed", String(now));
326
+ e.target.textContent = now ? "●" : "○";
327
+ this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { name, visible: now } }));
328
+ } else if (e.target.classList.contains("c-layer-panel__opacity")) {
329
+ this.dispatchEvent(new CustomEvent("contour:layer-opacity", { bubbles: true, composed: true, detail: { name, opacity: Number(e.target.value) } }));
330
+ } else if (e.target.classList.contains("c-layer-panel__projection")) {
331
+ this.dispatchEvent(new CustomEvent("contour:layer-projection", { bubbles: true, composed: true, detail: { name, projection: e.target.value } }));
332
+ }
333
+ });
334
+ this.addEventListener("click", (e) => {
335
+ const btn = e.target && e.target.closest ? e.target.closest("button") : null;
336
+ if (!btn || !this.contains(btn)) return;
337
+ const item = btn.closest(".c-layer-panel__item");
338
+ if (btn.classList.contains("c-layer-panel__toggle")) {
339
+ if (!item) return;
340
+ const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
341
+ const now = btn.getAttribute("aria-pressed") !== "true";
342
+ btn.setAttribute("aria-pressed", String(now));
343
+ btn.checked = now;
344
+ btn.textContent = now ? "●" : "○";
345
+ this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { name, visible: now } }));
346
+ return;
347
+ }
348
+ if (!item) return;
349
+ const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
350
+ if (btn.classList.contains("c-layer-panel__rename")) {
351
+ const newName = prompt("Rename layer", name);
352
+ const trimmed = newName ? newName.trim() : "";
353
+ if (trimmed && trimmed !== name) {
354
+ const nm = item.querySelector(".c-layer-panel__name");
355
+ if (nm) nm.textContent = trimmed;
356
+ this.dispatchEvent(new CustomEvent("contour:layer-rename", { bubbles: true, composed: true, detail: { name, newName: trimmed } }));
357
+ }
358
+ } else if (btn.classList.contains("c-layer-panel__duplicate")) {
359
+ this.dispatchEvent(new CustomEvent("contour:layer-duplicate", { bubbles: true, composed: true, detail: { name } }));
360
+ } else if (btn.classList.contains("c-layer-panel__zoom")) {
361
+ this.dispatchEvent(new CustomEvent("contour:layer-zoom", { bubbles: true, composed: true, detail: { name } }));
362
+ } else if (btn.classList.contains("c-layer-panel__remove")) {
363
+ this.dispatchEvent(new CustomEvent("contour:layer-remove", { bubbles: true, composed: true, detail: { name } }));
364
+ }
365
+ });
366
+ this.addEventListener("keydown", (e) => {
367
+ if (e.target && e.target.classList && e.target.classList.contains("c-layer-panel__toggle") && (e.key === "Enter" || e.key === " ")) {
368
+ e.preventDefault();
369
+ e.target.click();
370
+ return;
314
371
  }
315
- } else if (btn.classList.contains("c-layer-panel__duplicate")) {
316
- this.dispatchEvent(new CustomEvent("contour:layer-duplicate", { bubbles: true, composed: true, detail: { name } }));
317
- } else if (btn.classList.contains("c-layer-panel__zoom")) {
318
- this.dispatchEvent(new CustomEvent("contour:layer-zoom", { bubbles: true, composed: true, detail: { name } }));
319
- }
320
- });
321
- }
372
+ const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
373
+ if (!item || !this.contains(item)) return;
374
+ if (!(e.altKey) || (e.key !== "ArrowUp" && e.key !== "ArrowDown")) return;
375
+ e.preventDefault();
376
+ const items = Array.from(this.querySelectorAll(".c-layer-panel__item"));
377
+ const idx = items.indexOf(item);
378
+ if (idx < 0) return;
379
+ const dir = e.key === "ArrowUp" ? -1 : 1;
380
+ const newIdx = idx + dir;
381
+ if (newIdx < 0 || newIdx >= items.length) return;
382
+ item.classList.add("c-layer-panel__item--dragging");
383
+ if (dir < 0) this.insertBefore(item, items[newIdx]);
384
+ else this.insertBefore(items[newIdx], item);
385
+ item.focus();
386
+ setTimeout(() => item.classList.remove("c-layer-panel__item--dragging"), 200);
387
+ const layerIds = Array.from(this.querySelectorAll(".c-layer-panel__item")).map((el) => el.querySelector(".c-layer-panel__name")?.textContent || "");
388
+ this.dispatchEvent(new CustomEvent("contour:layer-reorder", { bubbles: true, composed: true, detail: { layerIds } }));
389
+ });
390
+ }
322
391
  }
323
392
  define("contour-layer-panel", ContourLayerPanel);
324
393
  class ContourTimeSlider extends ContourBase {
325
- static get observed() { return ["label", "value", "loop", "speed"]; }
394
+ static get observed() { return ["label", "value", "loop", "speed", "speeds", "show-loop", "loop-label", "current-time", "time-format", "is-playing"]; }
326
395
  static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, src: { attribute: "src" } }; }
327
396
  render() {
328
397
  this.classList.add("c-time-slider");
@@ -348,7 +417,41 @@ class ContourTimeSlider extends ContourBase {
348
417
  }
349
418
  track.setAttribute("aria-label", this.getAttribute("label") || "Time");
350
419
  const time = this.ensure(".c-time-slider__time", () => { const el = document.createElement("span"); el.className = "c-time-slider__time"; return el; });
351
- time.textContent = this.getAttribute("label") || "";
420
+ const ct = this.getAttribute("current-time");
421
+ time.textContent = ct ? ct : (this.getAttribute("label") || "");
422
+ // speed selector
423
+ let speeds = null;
424
+ const speedsAttr = this.getAttribute("speeds");
425
+ if (speedsAttr) { try { speeds = JSON.parse(speedsAttr); } catch (e) { speeds = null; } }
426
+ const speedSel = this.ensure(".c-time-slider__speed", () => { const el = document.createElement("select"); el.className = "c-time-slider__speed"; el.setAttribute("aria-label", "Speed"); return el; });
427
+ speedSel.innerHTML = "";
428
+ const speedList = Array.isArray(speeds) ? speeds : [0.5, 1, 2, 5, 10];
429
+ speedList.forEach((sp) => {
430
+ const opt = document.createElement("option");
431
+ opt.value = String(sp);
432
+ opt.textContent = String(sp);
433
+ if (String(sp) === (this.getAttribute("speed") || "")) opt.selected = true;
434
+ speedSel.appendChild(opt);
435
+ });
436
+ const speedAttr = this.getAttribute("speed");
437
+ if (speedAttr) speedSel.value = speedAttr;
438
+ // loop toggle
439
+ const showLoop = this.hasAttribute("show-loop");
440
+ if (showLoop) {
441
+ const loopBtn = this.ensure(".c-time-slider__loop", () => { const el = document.createElement("button"); el.className = "c-time-slider__loop"; el.type = "button"; el.setAttribute("aria-label", this.getAttribute("loop-label") || "Loop"); return el; });
442
+ loopBtn.setAttribute("aria-pressed", this.hasAttribute("loop") ? "true" : "false");
443
+ loopBtn.textContent = this.getAttribute("loop-label") || "Loop";
444
+ } else {
445
+ const lb = this.querySelector(".c-time-slider__loop");
446
+ if (lb) lb.remove();
447
+ }
448
+ // is-playing reflects on play button
449
+ if (this.hasAttribute("is-playing")) {
450
+ play.setAttribute("data-state", "pause");
451
+ play.setAttribute("aria-label", "Pause");
452
+ const use = play.querySelector("use");
453
+ if (use) use.setAttribute("href", "#i-pause");
454
+ }
352
455
  }
353
456
  enhance() {
354
457
  if (this._wiredTimeSlider) return;
@@ -384,20 +487,38 @@ class ContourTimeSlider extends ContourBase {
384
487
  };
385
488
  this.addEventListener("click", (e) => {
386
489
  const btn = e.target && e.target.closest ? e.target.closest(".c-time-slider__play") : null;
387
- if (!btn) return;
388
- const playing = btn.getAttribute("data-state") === "play";
389
- btn.setAttribute("data-state", playing ? "pause" : "play");
390
- btn.setAttribute("aria-label", playing ? "Pause" : "Play");
391
- const use = btn.querySelector("use");
392
- if (use) use.setAttribute("href", playing ? "#i-pause" : "#i-play");
393
- if (playing) {
394
- stop();
395
- const speed = parseFloat(this.getAttribute("speed") || "1") || 1;
396
- const delay = Math.max(100, 1000 / speed);
397
- timer = setInterval(step, delay);
398
- } else {
399
- stop();
490
+ if (btn) {
491
+ const playing = btn.getAttribute("data-state") === "play";
492
+ btn.setAttribute("data-state", playing ? "pause" : "play");
493
+ btn.setAttribute("aria-label", playing ? "Pause" : "Play");
494
+ const use = btn.querySelector("use");
495
+ if (use) use.setAttribute("href", playing ? "#i-pause" : "#i-play");
496
+ if (playing) {
497
+ stop();
498
+ const speed = parseFloat(this.getAttribute("speed") || "1") || 1;
499
+ const delay = Math.max(100, 1000 / speed);
500
+ timer = setInterval(step, delay);
501
+ this.dispatchEvent(new CustomEvent("contour:play", { bubbles: true, composed: true }));
502
+ } else {
503
+ stop();
504
+ this.dispatchEvent(new CustomEvent("contour:pause", { bubbles: true, composed: true }));
505
+ }
506
+ return;
400
507
  }
508
+ const loopBtn = e.target && e.target.closest ? e.target.closest(".c-time-slider__loop") : null;
509
+ if (loopBtn) {
510
+ const next = loopBtn.getAttribute("aria-pressed") !== "true";
511
+ loopBtn.setAttribute("aria-pressed", String(next));
512
+ this.toggleAttribute("loop", next);
513
+ this.dispatchEvent(new CustomEvent("contour:loop-change", { detail: { loop: next }, bubbles: true, composed: true }));
514
+ }
515
+ });
516
+ // speed select change (delegated)
517
+ this.addEventListener("change", (e) => {
518
+ const sel = e.target && e.target.closest ? e.target.closest(".c-time-slider__speed") : null;
519
+ if (!sel) return;
520
+ const speed = Number(sel.value);
521
+ this.dispatchEvent(new CustomEvent("contour:speed-change", { detail: { speed }, bubbles: true, composed: true }));
401
522
  });
402
523
  onDispose(this, stop);
403
524
  }