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.
- package/README.md +1 -1
- package/dist/build-manifest.json +43 -43
- package/dist/contour-wc.esm.js +794 -184
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +794 -184
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.components.json +67 -21
- package/dist/contour.css +113 -36
- package/dist/contour.d.ts +1 -0
- package/dist/contour.min.css +1 -1
- package/dist/contour.themes.json +4 -1
- package/dist/contour.tokens.json +3 -0
- package/dist/docs/actions.md +1 -1
- package/dist/docs/affordances.md +1 -1
- package/dist/docs/colour.md +1 -1
- package/dist/docs/data.md +1 -1
- package/dist/docs/docs.md +1 -1
- package/dist/docs/feedback.md +1 -1
- package/dist/docs/field.md +1 -1
- package/dist/docs/forms.md +1 -1
- package/dist/docs/index.json +3 -3
- package/dist/docs/install.md +1 -1
- package/dist/docs/landing.md +1 -1
- package/dist/docs/mapengine.md +1 -1
- package/dist/docs/motion.md +1 -1
- package/dist/docs/navigation.md +1 -1
- package/dist/docs/overlays.md +1 -1
- package/dist/docs/overview.md +1 -1
- package/dist/docs/patterns.md +1 -1
- package/dist/docs/playground.md +1 -1
- package/dist/docs/principles.md +1 -1
- package/dist/docs/recipes.md +1 -1
- package/dist/docs/space.md +1 -1
- package/dist/docs/status.md +1 -1
- package/dist/docs/surfaces.md +1 -1
- package/dist/docs/theming.md +1 -1
- package/dist/docs/type.md +1 -1
- package/dist/docs/webcomponents.md +1 -1
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/wc/core.mjs +13 -3
- package/dist/wc/data.mjs +302 -36
- package/dist/wc/forms.mjs +119 -61
- package/dist/wc/map.mjs +190 -69
- package/dist/wc/navigation.mjs +66 -11
- package/dist/wc/ui.mjs +104 -4
- 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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
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 (
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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
|
}
|