@xsynaptic/sonic-ui 0.10.2 → 0.10.4

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 (40) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +23 -0
  3. package/dist/default/elements/envelope.js +6 -0
  4. package/dist/default/elements/sonic-element.js +11 -2
  5. package/dist/default/elements/switch.js +2 -2
  6. package/dist/default/elements/value-element.js +10 -1
  7. package/dist/default/elements/value-gestures.js +19 -12
  8. package/dist/default/elements/waveform.js +12 -13
  9. package/dist/default/elements/wavestrip.js +2 -1
  10. package/dist/default/elements/xy.js +13 -3
  11. package/dist/default/lib/hover-preview.js +4 -1
  12. package/dist/default/lib/strip-scene.js +4 -3
  13. package/dist/dev/elements/envelope.d.ts +1 -0
  14. package/dist/dev/elements/envelope.js +6 -0
  15. package/dist/dev/elements/envelope.js.map +1 -1
  16. package/dist/dev/elements/sonic-element.d.ts +1 -0
  17. package/dist/dev/elements/sonic-element.js +11 -2
  18. package/dist/dev/elements/sonic-element.js.map +1 -1
  19. package/dist/dev/elements/switch.js +2 -2
  20. package/dist/dev/elements/switch.js.map +1 -1
  21. package/dist/dev/elements/value-element.d.ts +3 -0
  22. package/dist/dev/elements/value-element.js +10 -1
  23. package/dist/dev/elements/value-element.js.map +1 -1
  24. package/dist/dev/elements/value-gestures.js +19 -12
  25. package/dist/dev/elements/value-gestures.js.map +1 -1
  26. package/dist/dev/elements/waveform.js +12 -13
  27. package/dist/dev/elements/waveform.js.map +1 -1
  28. package/dist/dev/elements/wavestrip.d.ts +2 -0
  29. package/dist/dev/elements/wavestrip.js +2 -1
  30. package/dist/dev/elements/wavestrip.js.map +1 -1
  31. package/dist/dev/elements/xy.d.ts +1 -0
  32. package/dist/dev/elements/xy.js +13 -3
  33. package/dist/dev/elements/xy.js.map +1 -1
  34. package/dist/dev/lib/hover-preview.js +4 -1
  35. package/dist/dev/lib/hover-preview.js.map +1 -1
  36. package/dist/dev/lib/strip-scene.js +4 -3
  37. package/dist/dev/lib/strip-scene.js.map +1 -1
  38. package/dist/styles/waveform.css +5 -2
  39. package/dist/styles/wavestrip.css +7 -0
  40. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @xsynaptic/sonic-ui
2
2
 
3
+ ## 0.10.4
4
+
5
+ ### Patch Changes
6
+
7
+ - - Value controls: `dragging`, `revealed` and `cancelling` read the states of the same names as properties, so script need not match `:state()`.
8
+ - Waveform: every promise `requestPeaks` returns repaints as it settles, not only the latest; connecting no longer throws where `document.fonts` is missing.
9
+ - Wave strip: `--sonic-wavestrip-groove-size`, a length, overrides `--sonic-wavestrip-groove-ratio` so the empty groove keeps its thickness on a `fill` strip.
10
+ - Waveform: `--sonic-waveform-label-font-size`, a length, overrides `--sonic-waveform-label-font-ratio`; `--sonic-waveform-label-line-height` sets the label's line height.
11
+ - Wave strip: the marker band holds one part per marker in the order `markers` reads back; the README now lists what the wave controls make public.
12
+
13
+ ## 0.10.3
14
+
15
+ ### Patch Changes
16
+
17
+ - - Value controls: a release outside the control fires no `sonic-hover`, and `pointerType` holds through the `change` of a release, a tap or a reset press.
18
+ - XY pad: `:state(dragging)` is set before a press's first `input`.
19
+ - XY pad and envelope: `pointerType`, as on value controls.
20
+
3
21
  ## 0.10.2
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -27,4 +27,27 @@ A display takes its signal as data: `spectrum.analyser = node`, or `spectrum.pus
27
27
 
28
28
  Under a hydrating framework, register the definitions once hydration is done (in React, from an effect); a control owns one child of its host and uses only the children it documents.
29
29
 
30
+ ## Wave controls
31
+
32
+ `<sonic-wavestrip>` is the overview of a track, scrubbed to seek; `<sonic-waveform>` is the close-up that scrolls under a fixed playhead. Both are value controls in seconds (`min`, `max`, `step`, `value`) and take their data as properties.
33
+
34
+ | | Both | Wave strip | Waveform |
35
+ | --- | --- | --- | --- |
36
+ | Attributes | `fill`, `readout`, `disabled`, `dimmed` | `cancellable` | `playing`, `playback-rate`, `zoom`, `pending-delay`, `reduced-motion` |
37
+ | Properties | `markers`, `currentMarker`, `formatValue`, `formatSpokenValue`, `repaint()` | `peaks`, `buffered` | `peaks`, `pending`, `readTime`, `requestPeaks` |
38
+ | Gesture, read only | `dragging`, `revealed`, `cancelling`, `pointerType` | `hoverValue` | |
39
+ | Events, all bubbling | `input`, `change`, `sonic-reveal`, `sonic-marker` | `sonic-hover` | |
40
+ | States | `dragging`, `revealed`, `cancelling`, `editing`, `empty` | | `pending` |
41
+ | Hook classes | | `sonic-wavestrip`, `-canvas`, `-markers`, `-marker`, `-region`, `-readout`, `-entry` | `sonic-waveform`, `-canvas`, `-scrim`, `-playhead`, `-ghost`, `-label`, `-readout`, `-entry` |
42
+
43
+ The events carry no detail; read the properties when one fires. `sonic-reveal` reports `revealed` changing, and a drag crossing the cancel zone reports through it or through `input`.
44
+
45
+ A marker is `{ start, end?, label?, kind?, dimmed? }`; `markers` reads back sorted by `start`. The strip's `.sonic-wavestrip-markers` holds one part per marker in that order, a `.sonic-wavestrip-marker` dot or, with an `end`, a `.sonic-wavestrip-region`, so a dot's box gives the row it was laid on.
46
+
47
+ Marker labels are drawn parts and hidden from assistive technology. To speak the current marker with the time, fold `currentMarker` into `formatSpokenValue`; to announce it during playback, feed a live region of your own from `sonic-marker`.
48
+
49
+ `requestPeaks(fromSeconds, toSeconds)` is called whenever the window the waveform wants moves, often every frame, so it should return at once for a span already loaded or on its way. Return a promise and the waveform repaints when it settles, resolved or rejected. `peaks` holds no record of what has loaded, so `pending` stays yours: list the spans you are fetching, and clear them as each lands.
50
+
51
+ Sizes are ratios of the control's own size (`--sonic-wavestrip-size`, `--sonic-waveform-size`). Where a `fill` control should keep an absolute length, these override their ratios: `--sonic-wavestrip-marker-size`, `--sonic-wavestrip-groove-size`, `--sonic-waveform-label-font-size`, `--sonic-waveform-label-inset-inline` and `--sonic-waveform-label-inset-block`. `--sonic-waveform-label-line-height` defaults to 1.
52
+
30
53
  Targets current Chrome and Edge, Safari 26 and Firefox 147. MIT licensed.
@@ -103,6 +103,9 @@ var SonicEnvelope = class extends SonicElement {
103
103
  set hold(id) {
104
104
  this.reflect("hold", id);
105
105
  }
106
+ get pointerType() {
107
+ return this.#pointerType;
108
+ }
106
109
  get readout() {
107
110
  return this.hasAttribute("readout");
108
111
  }
@@ -142,6 +145,7 @@ var SonicEnvelope = class extends SonicElement {
142
145
  #isDriving = false;
143
146
  #line = requireChild(this.#envelope, ".sonic-envelope-line", SVGElement);
144
147
  #pointerDrag;
148
+ #pointerType;
145
149
  #readout = new Readout(requireChild(this.#envelope, ".sonic-envelope-readout", HTMLDivElement));
146
150
  #shape = adsrShape({});
147
151
  #signal;
@@ -206,6 +210,7 @@ var SonicEnvelope = class extends SonicElement {
206
210
  if (binding.link.value() === from) continue;
207
211
  binding.element.dispatchEvent(new Event("change", { bubbles: true }));
208
212
  }
213
+ this.#pointerType = void 0;
209
214
  },
210
215
  toggle: (isDragging) => {
211
216
  this.toggleState("dragging", isDragging);
@@ -269,6 +274,7 @@ var SonicEnvelope = class extends SonicElement {
269
274
  const pressed = this.#pressed(event);
270
275
  if (!pressed || pressed.drives.length === 0) return void 0;
271
276
  const { drives, isFlipped, part } = pressed;
277
+ this.#pointerType = event.pointerType;
272
278
  this.#claim.press(true, revealDelay(this.#envelope));
273
279
  this.#held = part;
274
280
  this.#drawBracket();
@@ -23,6 +23,7 @@ var SonicElement = class extends HTMLElement {
23
23
  }
24
24
  internals = "attachInternals" in HTMLElement.prototype ? this.attachInternals() : void 0;
25
25
  #connection;
26
+ #states = /* @__PURE__ */ new Set();
26
27
  blur() {
27
28
  this.#focused()?.blur();
28
29
  }
@@ -68,6 +69,9 @@ var SonicElement = class extends HTMLElement {
68
69
  }
69
70
  if (labels.length > 0) writeLabelledBy(target, labels);
70
71
  }
72
+ hasState(state) {
73
+ return this.#states.has(state);
74
+ }
71
75
  isBound() {
72
76
  return this.#connection !== void 0;
73
77
  }
@@ -104,8 +108,13 @@ var SonicElement = class extends HTMLElement {
104
108
  this.setAttribute(name, value === true ? "" : value.toString());
105
109
  }
106
110
  toggleState(state, isOn) {
107
- if (isOn) this.internals?.states.add(state);
108
- else this.internals?.states.delete(state);
111
+ if (isOn) {
112
+ this.#states.add(state);
113
+ this.internals?.states.add(state);
114
+ return;
115
+ }
116
+ this.#states.delete(state);
117
+ this.internals?.states.delete(state);
109
118
  }
110
119
  upgradeProperties(...names) {
111
120
  for (const name of names) {
@@ -18,10 +18,10 @@ const renderPosition = template(`
18
18
  </button>
19
19
  `, HTMLButtonElement);
20
20
  const renderBare = template(`<button class="sonic-switch-position" role="switch" type="button"></button>`, HTMLButtonElement);
21
- const pressCentreZone = .08;
21
+ const pressCenterZone = .08;
22
22
  function pressedIndex(index, count, offset) {
23
23
  if (count === 2) return index === 0 ? 1 : 0;
24
- const side = Math.abs(offset) < pressCentreZone ? 1 : Math.sign(offset);
24
+ const side = Math.abs(offset) < pressCenterZone ? 1 : Math.sign(offset);
25
25
  const next = index + side;
26
26
  return next < 0 || next >= count ? index - side : next;
27
27
  }
@@ -72,6 +72,9 @@ var SonicValueElement = class extends SonicFormElement {
72
72
  }
73
73
  });
74
74
  }
75
+ get cancelling() {
76
+ return this.hasState("cancelling");
77
+ }
75
78
  get default() {
76
79
  return this.optionalNumberAttribute("default");
77
80
  }
@@ -97,6 +100,9 @@ var SonicValueElement = class extends SonicFormElement {
97
100
  set doublePress(gesture) {
98
101
  this.reflect("double-press", gesture);
99
102
  }
103
+ get dragging() {
104
+ return this.hasState("dragging");
105
+ }
100
106
  get formatEntry() {
101
107
  return this.#formatEntry;
102
108
  }
@@ -177,6 +183,9 @@ var SonicValueElement = class extends SonicFormElement {
177
183
  set readout(isShown) {
178
184
  this.reflect("readout", isShown);
179
185
  }
186
+ get revealed() {
187
+ return this.hasState("revealed");
188
+ }
180
189
  get spokenStep() {
181
190
  return this.optionalNumberAttribute("spoken-step");
182
191
  }
@@ -291,7 +300,7 @@ var SonicValueElement = class extends SonicFormElement {
291
300
  }, control);
292
301
  this.#gestures.bind(signal, grab);
293
302
  control.addEventListener("pointerup", (event) => {
294
- this.#hover?.at(event);
303
+ this.#hover?.lift(event);
295
304
  }, { signal });
296
305
  }
297
306
  bindHover(control, signal, { canShow = () => true, place, valueAt }) {
@@ -40,13 +40,14 @@ var ValueGestures = class {
40
40
  host.toggleState("springing", false);
41
41
  if (event.pointerType === "touch") event.preventDefault();
42
42
  focusByPointer(control);
43
+ this.#pointerType = event.pointerType;
43
44
  if (isResetPress(event)) {
44
45
  this.#reset();
46
+ this.#pointerType = void 0;
45
47
  return;
46
48
  }
47
49
  const fromValue = host.value();
48
50
  host.toggleState("dragging", true);
49
- this.#pointerType = event.pointerType;
50
51
  const axis = grab(event);
51
52
  if (!axis) {
52
53
  host.toggleState("dragging", false);
@@ -67,16 +68,9 @@ var ValueGestures = class {
67
68
  return drag;
68
69
  },
69
70
  lift: (drag, event) => {
70
- const tap = drag.state.isEngaged ? void 0 : host.tapTarget();
71
- if (tap !== void 0) {
72
- entry.forgetPress();
73
- this.#commit(tap);
74
- return;
75
- }
76
- if (!entry.press(event) || host.springTarget() !== void 0) return;
77
- const gesture = host.doublePress();
78
- if (gesture === "reset") this.#reset();
79
- else if (gesture === "entry") entry.open();
71
+ this.#pointerType = event.pointerType;
72
+ this.#lift(drag, event, entry);
73
+ this.#pointerType = void 0;
80
74
  },
81
75
  move: (drag, event) => {
82
76
  this.#dragTo(drag, event);
@@ -229,16 +223,29 @@ var ValueGestures = class {
229
223
  this.#endKeyScrub();
230
224
  this.#commit(next, next > host.value() ? 1 : -1);
231
225
  }
226
+ #lift(drag, event, entry) {
227
+ const host = this.#host;
228
+ const tap = drag.state.isEngaged ? void 0 : host.tapTarget();
229
+ if (tap !== void 0) {
230
+ entry.forgetPress();
231
+ this.#commit(tap);
232
+ return;
233
+ }
234
+ if (!entry.press(event) || host.springTarget() !== void 0) return;
235
+ const gesture = host.doublePress();
236
+ if (gesture === "reset") this.#reset();
237
+ else if (gesture === "entry") entry.open();
238
+ }
232
239
  #releaseDrag(drag) {
233
240
  const host = this.#host;
234
241
  clearTimeout(drag.revealTimer);
235
- this.#pointerType = void 0;
236
242
  this.#claim.conceal("drag");
237
243
  host.toggleState("cancelling", false);
238
244
  host.holdChanged();
239
245
  this.#showRevealed();
240
246
  if (host.value() !== drag.fromValue) host.dispatch("change");
241
247
  this.#springBack();
248
+ this.#pointerType = void 0;
242
249
  }
243
250
  #renderDragReveal(drag) {
244
251
  if (drag.isRevealed && !drag.isOutside) this.#claim.reveal("drag");
@@ -73,9 +73,9 @@ function paintPlaceholders(context, scene) {
73
73
  if (scene.pending.length === 0) return;
74
74
  const { dpr, height, pixelsPerSecond, startSeconds } = scene;
75
75
  const wavelength = placeholderWavelengthPx * dpr;
76
- const centre = height / 2;
76
+ const center = height / 2;
77
77
  const origin = startSeconds * pixelsPerSecond;
78
- const waveY = (x) => centre - Math.sin(((x + origin) / wavelength + scene.phase) * 2 * Math.PI) * centre * placeholderAmplitude;
78
+ const waveY = (x) => center - Math.sin(((x + origin) / wavelength + scene.phase) * 2 * Math.PI) * center * placeholderAmplitude;
79
79
  context.beginPath();
80
80
  for (const [from, to] of scene.pending) {
81
81
  const opening = (from - startSeconds) * pixelsPerSecond;
@@ -100,13 +100,13 @@ function paintWave(context, scene, peaks) {
100
100
  const buckets = waveformBuckets(peaks, scene);
101
101
  const [first] = buckets;
102
102
  if (!first) return;
103
- const centre = scene.height / 2;
104
- const amplitudePx = centre * amplitudeMargin;
103
+ const center = scene.height / 2;
104
+ const amplitudePx = center * amplitudeMargin;
105
105
  context.fillStyle = waveFill(context, scene);
106
106
  context.beginPath();
107
- context.moveTo(first.x, centre);
108
- for (const bucket of buckets) context.lineTo(bucket.x, centre - bucket.high * amplitudePx);
109
- for (const bucket of buckets.toReversed()) context.lineTo(bucket.x, centre - bucket.low * amplitudePx);
107
+ context.moveTo(first.x, center);
108
+ for (const bucket of buckets) context.lineTo(bucket.x, center - bucket.high * amplitudePx);
109
+ for (const bucket of buckets.toReversed()) context.lineTo(bucket.x, center - bucket.low * amplitudePx);
110
110
  context.closePath();
111
111
  context.fill();
112
112
  }
@@ -177,7 +177,6 @@ var SonicWaveform = class extends SonicWaveElement {
177
177
  }
178
178
  set requestPeaks(request) {
179
179
  this.#requestPeaks = request;
180
- this.#asked = void 0;
181
180
  this.surface()?.invalidate();
182
181
  }
183
182
  get zoom() {
@@ -193,7 +192,7 @@ var SonicWaveform = class extends SonicWaveElement {
193
192
  lengths = {};
194
193
  sheet = "waveform.css";
195
194
  sizeProperty = "--_sonic-waveform-size";
196
- #asked;
195
+ #asked = /* @__PURE__ */ new Set();
197
196
  #clock = createTrackingClock();
198
197
  #drawn;
199
198
  #ghost = requireChild(this.control, ".sonic-waveform-ghost", HTMLDivElement);
@@ -220,6 +219,7 @@ var SonicWaveform = class extends SonicWaveElement {
220
219
  connect(signal) {
221
220
  super.connect(signal);
222
221
  this.bindGestures(this.control, signal, () => this.#grab());
222
+ if (!("fonts" in document)) return;
223
223
  document.fonts.addEventListener("loadingdone", () => {
224
224
  this.renderMarkers();
225
225
  }, { signal });
@@ -288,8 +288,8 @@ var SonicWaveform = class extends SonicWaveElement {
288
288
  }
289
289
  #ask(wanted) {
290
290
  const asked = this.#requestPeaks?.(...wanted);
291
- if (!(asked instanceof Promise)) return;
292
- this.#asked = asked;
291
+ if (!(asked instanceof Promise) || this.#asked.has(asked)) return;
292
+ this.#asked.add(asked);
293
293
  this.#repaintAfter(asked);
294
294
  }
295
295
  #duePending() {
@@ -365,8 +365,7 @@ var SonicWaveform = class extends SonicWaveElement {
365
365
  }
366
366
  async #repaintAfter(asked) {
367
367
  await Promise.allSettled([asked]);
368
- if (this.#asked !== asked) return;
369
- this.#asked = void 0;
368
+ this.#asked.delete(asked);
370
369
  this.surface()?.invalidate();
371
370
  }
372
371
  #sourceSeconds() {
@@ -16,6 +16,7 @@ const colours = {
16
16
  const lengths = {
17
17
  gapRatio: "--_sonic-wavestrip-bar-gap-ratio",
18
18
  grooveRatio: "--_sonic-wavestrip-groove-ratio",
19
+ grooveSize: "--_sonic-wavestrip-groove-size",
19
20
  pitch: "--_sonic-wavestrip-bar-pitch",
20
21
  radiusRatio: "--_sonic-wavestrip-bar-radius-ratio"
21
22
  };
@@ -141,7 +142,7 @@ var SonicWavestrip = class extends SonicWaveElement {
141
142
  #barsFor({ isDirty, look, size }) {
142
143
  if (!isDirty && this.#bars) return this.#bars;
143
144
  const peaks = this.#peaks;
144
- const groove = stripGroove(size, look.lengths.grooveRatio);
145
+ const groove = stripGroove(size, look.lengths);
145
146
  const drawn = groove ? [groove] : [];
146
147
  const bars = peaks && peaks.length > 0 ? stripBars(peaks, size, look.lengths) : drawn;
147
148
  this.#bars = void 0;
@@ -74,6 +74,9 @@ var SonicXy = class extends SonicFormElement {
74
74
  this.#formatValue = format;
75
75
  this.render();
76
76
  }
77
+ get pointerType() {
78
+ return this.#pointerType;
79
+ }
77
80
  get readout() {
78
81
  return this.hasAttribute("readout");
79
82
  }
@@ -201,6 +204,7 @@ var SonicXy = class extends SonicFormElement {
201
204
  y: requireChild(this.#xy, "[data-sonic-axis=\"y\"]", HTMLDivElement)
202
205
  };
203
206
  #pointerDrag;
207
+ #pointerType;
204
208
  #puck = requireChild(this.#xy, ".sonic-xy-puck", HTMLDivElement);
205
209
  #readout = new Readout(requireChild(this.#xy, ".sonic-xy-readout", HTMLDivElement));
206
210
  #values = {
@@ -294,8 +298,13 @@ var SonicXy = class extends SonicFormElement {
294
298
  grab: (event) => {
295
299
  if (this.isDisabled() || isMenuPress(event)) return;
296
300
  focusByPointer(this.focusTarget());
297
- if (!isResetPress(event)) return this.#grab(event);
301
+ this.#pointerType = event.pointerType;
302
+ if (!isResetPress(event)) {
303
+ this.toggleState("dragging", true);
304
+ return this.#grab(event);
305
+ }
298
306
  this.#reset();
307
+ this.#pointerType = void 0;
299
308
  },
300
309
  move: (drag, event) => {
301
310
  const step = stepFieldDrag(this.#mappings(), drag.state, pointerMove(event));
@@ -304,9 +313,10 @@ var SonicXy = class extends SonicFormElement {
304
313
  if (!this.#input(step)) this.#renderReadout();
305
314
  },
306
315
  release: (drag) => {
316
+ const hasMoved = this.x !== drag.from.x || this.y !== drag.from.y;
307
317
  this.#claim.press(false);
308
- if (this.x === drag.from.x && this.y === drag.from.y) return;
309
- this.dispatchEvent(new Event("change", { bubbles: true }));
318
+ if (hasMoved) this.dispatchEvent(new Event("change", { bubbles: true }));
319
+ this.#pointerType = void 0;
310
320
  },
311
321
  toggle: (isDragging) => {
312
322
  this.toggleState("dragging", isDragging);
@@ -43,10 +43,13 @@ function bindHoverPreview(target, options, signal) {
43
43
  watchEscape(false);
44
44
  }, { once: true });
45
45
  return {
46
- at,
47
46
  clear: () => {
48
47
  hold(void 0);
49
48
  },
49
+ lift: (event) => {
50
+ const box = target.getBoundingClientRect();
51
+ if (event.clientX >= box.left && event.clientX <= box.right && event.clientY >= box.top && event.clientY <= box.bottom) at(event);
52
+ },
50
53
  restore: () => {
51
54
  if (under !== void 0) hoverAt(under);
52
55
  },
@@ -18,9 +18,10 @@ function stripBars(peaks, size, grid) {
18
18
  };
19
19
  });
20
20
  }
21
- function stripGroove(size, ratio) {
22
- if (ratio <= 0) return void 0;
23
- const height = Math.max(1, Math.round(size.height * ratio));
21
+ function stripGroove(size, { grooveRatio, grooveSize }) {
22
+ const thickness = grooveSize > 0 ? grooveSize * size.dpr : size.height * grooveRatio;
23
+ if (thickness <= 0) return void 0;
24
+ const height = Math.max(1, Math.round(Math.min(thickness, size.height)));
24
25
  return {
25
26
  height,
26
27
  radius: height / 2,
@@ -20,6 +20,7 @@ export declare class SonicEnvelope extends SonicElement {
20
20
  set delay(id: string | undefined);
21
21
  get hold(): string;
22
22
  set hold(id: string | undefined);
23
+ get pointerType(): string | undefined;
23
24
  get readout(): boolean;
24
25
  set readout(isOn: boolean);
25
26
  get release(): string;
@@ -103,6 +103,9 @@ var SonicEnvelope = class extends SonicElement {
103
103
  set hold(id) {
104
104
  this.reflect("hold", id);
105
105
  }
106
+ get pointerType() {
107
+ return this.#pointerType;
108
+ }
106
109
  get readout() {
107
110
  return this.hasAttribute("readout");
108
111
  }
@@ -142,6 +145,7 @@ var SonicEnvelope = class extends SonicElement {
142
145
  #isDriving = false;
143
146
  #line = requireChild(this.#envelope, ".sonic-envelope-line", SVGElement);
144
147
  #pointerDrag;
148
+ #pointerType;
145
149
  #readout = new Readout(requireChild(this.#envelope, ".sonic-envelope-readout", HTMLDivElement));
146
150
  #shape = adsrShape({});
147
151
  #signal;
@@ -206,6 +210,7 @@ var SonicEnvelope = class extends SonicElement {
206
210
  if (binding.link.value() === from) continue;
207
211
  binding.element.dispatchEvent(new Event("change", { bubbles: true }));
208
212
  }
213
+ this.#pointerType = void 0;
209
214
  },
210
215
  toggle: (isDragging) => {
211
216
  this.toggleState("dragging", isDragging);
@@ -269,6 +274,7 @@ var SonicEnvelope = class extends SonicElement {
269
274
  const pressed = this.#pressed(event);
270
275
  if (!pressed || pressed.drives.length === 0) return void 0;
271
276
  const { drives, isFlipped, part } = pressed;
277
+ this.#pointerType = event.pointerType;
272
278
  this.#claim.press(true, revealDelay(this.#envelope));
273
279
  this.#held = part;
274
280
  this.#drawBracket();
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.js","names":[],"sources":["../../../src/elements/envelope.ts"],"sourcesContent":["import type { ValueLink } from '#elements/value-element.ts';\nimport type { AdsrCurves, AdsrProportions, AdsrShape } from '#lib/adsr-shape.ts';\nimport type { FieldAxis, FieldDragState, FieldMappings, FieldPoint } from '#lib/field.ts';\nimport type { PointerDrag } from '#lib/pointer-drag.ts';\n\nimport { ReadoutClaim, revealDelay } from '#elements/readout-claim.ts';\nimport { Readout } from '#elements/readout.ts';\nimport { SonicElement } from '#elements/sonic-element.ts';\nimport { linkValue, SonicValueElement } from '#elements/value-element.ts';\nimport { adsrPath, adsrShape, adsrStages, timeStages } from '#lib/adsr-shape.ts';\nimport { dragThresholdPx } from '#lib/drag-step.ts';\nimport { pointerMove, pointerPosition, startFieldDrag, stepFieldDrag } from '#lib/field.ts';\nimport { bindDrag } from '#lib/pointer-drag.ts';\nimport { requireChild, template } from '#lib/render.ts';\nimport { writeAttribute } from '#lib/write-attribute.ts';\n\n// eslint-disable-next-line unicorn/consistent-boolean-name -- the name bundlers and other kits use\ndeclare const __DEV__: boolean;\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'sonic-envelope': SonicEnvelope;\n\t}\n}\n\ninterface Binding {\n\telement: SonicValueElement;\n\tlink: ValueLink;\n\tunwatch: () => void;\n}\n\ninterface Drive {\n\taxis: FieldAxis;\n\tbinding: Binding;\n}\n\ninterface HandleDrag {\n\tdrives: Array<Drive & { from: number }>;\n\tisFlipped: boolean;\n\tpart: HTMLElement;\n\tstate: FieldDragState;\n}\n\nconst curveStages = ['attack', 'decay', 'release'] as const;\n\nconst bindable = [...adsrStages, 'attack-curve', 'decay-curve', 'release-curve'] as const;\n\nconst bindableNames = new Set<string>(bindable);\n\nfunction flip<Point extends FieldPoint>(point: Point, isFlipped: boolean): Point {\n\treturn isFlipped ? { ...point, y: -point.y } : point;\n}\n\nfunction isParent(node: Node): node is Node & ParentNode {\n\treturn 'querySelector' in node;\n}\n\nconst emptyPath = { fill: '', floor: { from: 0, to: 0 }, stroke: '' };\n\nfunction stageParts<Stage extends string>(\n\tenvelope: Element,\n\thook: string,\n\tstages: ReadonlyArray<Stage>,\n): Map<Stage, HTMLDivElement> {\n\treturn new Map(\n\t\tstages.map((stage) => [\n\t\t\tstage,\n\t\t\trequireChild(envelope, `.${hook}[data-sonic-stage=\"${stage}\"]`, HTMLDivElement),\n\t\t]),\n\t);\n}\n\nconst renderEnvelope = template(\n\t/* HTML */ `\n\t\t<div class=\"sonic-envelope\" aria-hidden=\"true\">\n\t\t\t<div class=\"sonic-envelope-bracket\"></div>\n\t\t\t<svg class=\"sonic-envelope-graph\" preserveAspectRatio=\"none\" viewBox=\"0 0 1 1\">\n\t\t\t\t<path class=\"sonic-envelope-fill\" />\n\t\t\t\t<rect class=\"sonic-envelope-fill sonic-envelope-floor\" y=\"1\" />\n\t\t\t\t<path class=\"sonic-envelope-line\" />\n\t\t\t</svg>\n\t\t\t<div class=\"sonic-envelope-handle\" data-sonic-stage=\"delay\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-handle\" data-sonic-stage=\"attack\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-handle\" data-sonic-stage=\"hold\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-handle\" data-sonic-stage=\"decay\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-handle\" data-sonic-stage=\"release\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-curve\" data-sonic-stage=\"attack\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-curve\" data-sonic-stage=\"decay\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-curve\" data-sonic-stage=\"release\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-readout\" popover=\"manual\"><span></span></div>\n\t\t</div>\n\t`,\n\tHTMLDivElement,\n);\n\nexport class SonicEnvelope extends SonicElement {\n\tstatic override readonly observedAttributes = [\n\t\t...SonicElement.observedAttributes,\n\t\t...bindable,\n\t\t'readout',\n\t];\n\n\tget attack(): string {\n\t\treturn this.getAttribute('attack') ?? '';\n\t}\n\n\tset attack(id: string | undefined) {\n\t\tthis.reflect('attack', id);\n\t}\n\n\tget attackCurve(): string {\n\t\treturn this.getAttribute('attack-curve') ?? '';\n\t}\n\n\tset attackCurve(id: string | undefined) {\n\t\tthis.reflect('attack-curve', id);\n\t}\n\n\tget decay(): string {\n\t\treturn this.getAttribute('decay') ?? '';\n\t}\n\n\tset decay(id: string | undefined) {\n\t\tthis.reflect('decay', id);\n\t}\n\n\tget decayCurve(): string {\n\t\treturn this.getAttribute('decay-curve') ?? '';\n\t}\n\n\tset decayCurve(id: string | undefined) {\n\t\tthis.reflect('decay-curve', id);\n\t}\n\n\tget delay(): string {\n\t\treturn this.getAttribute('delay') ?? '';\n\t}\n\n\tset delay(id: string | undefined) {\n\t\tthis.reflect('delay', id);\n\t}\n\n\tget hold(): string {\n\t\treturn this.getAttribute('hold') ?? '';\n\t}\n\n\tset hold(id: string | undefined) {\n\t\tthis.reflect('hold', id);\n\t}\n\n\tget readout(): boolean {\n\t\treturn this.hasAttribute('readout');\n\t}\n\n\tset readout(isOn: boolean) {\n\t\tthis.reflect('readout', isOn);\n\t}\n\n\tget release(): string {\n\t\treturn this.getAttribute('release') ?? '';\n\t}\n\n\tset release(id: string | undefined) {\n\t\tthis.reflect('release', id);\n\t}\n\n\tget releaseCurve(): string {\n\t\treturn this.getAttribute('release-curve') ?? '';\n\t}\n\n\tset releaseCurve(id: string | undefined) {\n\t\tthis.reflect('release-curve', id);\n\t}\n\n\tget sustain(): string {\n\t\treturn this.getAttribute('sustain') ?? '';\n\t}\n\n\tset sustain(id: string | undefined) {\n\t\tthis.reflect('sustain', id);\n\t}\n\n\treadonly #bindings = new Map<string, Binding>();\n\n\treadonly #envelope = renderEnvelope();\n\n\treadonly #bracket = requireChild(this.#envelope, '.sonic-envelope-bracket', HTMLDivElement);\n\n\treadonly #claim = new ReadoutClaim(() => {\n\t\tthis.#renderReadout();\n\t});\n\n\treadonly #curveHandles = stageParts(this.#envelope, 'sonic-envelope-curve', curveStages);\n\n\treadonly #fill = requireChild(this.#envelope, '.sonic-envelope-fill', SVGElement);\n\n\treadonly #floor = requireChild(this.#envelope, '.sonic-envelope-floor', SVGElement);\n\n\treadonly #graph = requireChild(this.#envelope, '.sonic-envelope-graph', SVGElement);\n\n\treadonly #handles = stageParts(this.#envelope, 'sonic-envelope-handle', timeStages);\n\n\t#held: HTMLElement | undefined;\n\n\t#isDriving = false;\n\n\treadonly #line = requireChild(this.#envelope, '.sonic-envelope-line', SVGElement);\n\n\t#pointerDrag: PointerDrag<HandleDrag> | undefined;\n\n\treadonly #readout = new Readout(\n\t\trequireChild(this.#envelope, '.sonic-envelope-readout', HTMLDivElement),\n\t);\n\n\t#shape: AdsrShape = adsrShape({});\n\n\t#signal: AbortSignal | undefined;\n\n\treadonly #waiting = new Set<unknown>();\n\n\treadonly #warned = new Set<string>();\n\n\tattributeChangedCallback(name: string): void {\n\t\tif (!this.#signal) return;\n\t\tif (name === 'disabled') {\n\t\t\tthis.#pointerDrag?.end();\n\t\t\tthis.#draw();\n\t\t\treturn;\n\t\t}\n\t\tif (bindableNames.has(name)) this.#bind();\n\t\telse this.#renderReadout();\n\t}\n\n\toverride connectedCallback(): void {\n\t\tthis.upgradeProperties(...adsrStages, 'attackCurve', 'decayCurve', 'readout', 'releaseCurve');\n\t\tsuper.connectedCallback();\n\t}\n\n\tprotected connect(signal: AbortSignal): void {\n\t\tconst envelope = this.#envelope;\n\n\t\tthis.#signal = signal;\n\t\tthis.keepControl(envelope, signal);\n\t\tthis.#bind();\n\t\tthis.checkStyles(envelope, 'envelope.css');\n\t\tthis.#bindPointer(envelope, signal);\n\t\tsignal.addEventListener(\n\t\t\t'abort',\n\t\t\t() => {\n\t\t\t\tthis.#signal = undefined;\n\t\t\t\tthis.#unbind();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t}\n\n\t#bind(): void {\n\t\tthis.#pointerDrag?.end();\n\t\tthis.#unbind();\n\t\tfor (const name of bindable) {\n\t\t\tconst element = this.#resolve(name);\n\t\t\tif (!element) continue;\n\n\t\t\tconst link = linkValue(element);\n\t\t\tconst unwatch = link.watch(() => {\n\t\t\t\tif (!this.#isDriving) this.#draw();\n\t\t\t});\n\n\t\t\tthis.#bindings.set(name, { element, link, unwatch });\n\t\t}\n\t\tthis.#draw();\n\t}\n\n\t#bindPointer(envelope: HTMLElement, signal: AbortSignal): void {\n\t\tthis.#pointerDrag = bindDrag(\n\t\t\tenvelope,\n\t\t\t{\n\t\t\t\tcancel: (drag) => {\n\t\t\t\t\tfor (const { binding, from } of drag.drives) binding.link.input(from);\n\t\t\t\t},\n\t\t\t\tgrab: (event) => this.#grab(event),\n\t\t\t\tmove: (drag, event) => {\n\t\t\t\t\tthis.#moveDrag(drag, event);\n\t\t\t\t},\n\t\t\t\trelease: (drag) => {\n\t\t\t\t\tthis.#claim.press(false);\n\t\t\t\t\tfor (const { binding, from } of drag.drives) {\n\t\t\t\t\t\tif (binding.link.value() === from) continue;\n\n\t\t\t\t\t\tbinding.element.dispatchEvent(new Event('change', { bubbles: true }));\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\ttoggle: (isDragging) => {\n\t\t\t\t\tthis.toggleState('dragging', isDragging);\n\t\t\t\t},\n\t\t\t},\n\t\t\tsignal,\n\t\t);\n\t}\n\n\t#curveDrives(stage: string): Array<Drive> {\n\t\tconst binding = this.#bindings.get(`${stage}-curve`);\n\n\t\treturn binding ? [{ axis: 'y', binding }] : [];\n\t}\n\n\t#draw(): void {\n\t\tconst shape = this.#readShape();\n\t\tconst path = this.#bindings.size === 0 ? emptyPath : adsrPath(shape);\n\n\t\tthis.#shape = shape;\n\t\twriteAttribute(this.#line, 'd', path.stroke);\n\t\twriteAttribute(this.#fill, 'd', path.fill);\n\t\twriteAttribute(this.#floor, 'x', String(path.floor.from));\n\t\twriteAttribute(this.#floor, 'width', String(path.floor.to - path.floor.from));\n\t\tfor (const [stage, part] of this.#handles) {\n\t\t\tthis.#drawPoint(part, {\n\t\t\t\tat: shape.handles.find((point) => point.stage === stage),\n\t\t\t\tdrives: this.#drives(stage),\n\t\t\t});\n\t\t}\n\t\tfor (const [stage, part] of this.#curveHandles) {\n\t\t\tthis.#drawPoint(part, {\n\t\t\t\tat: shape.curveHandles.find((point) => point.stage === stage),\n\t\t\t\tdrives: this.#curveDrives(stage),\n\t\t\t});\n\t\t}\n\t\tthis.#drawBracket();\n\t\tthis.#renderReadout();\n\t}\n\n\t#drawBracket(): void {\n\t\tconst part = this.#held;\n\t\tif (!part) return;\n\n\t\tfor (const name of ['--_sonic-envelope-x', '--_sonic-envelope-y']) {\n\t\t\tthis.#bracket.style.setProperty(name, part.style.getPropertyValue(name));\n\t\t}\n\t\twriteAttribute(\n\t\t\tthis.#bracket,\n\t\t\t'data-sonic-part',\n\t\t\tpart.classList.contains('sonic-envelope-curve') ? 'curve' : undefined,\n\t\t);\n\t}\n\n\t#drawPoint(\n\t\tpart: HTMLDivElement,\n\t\tpoint: { at: FieldPoint | undefined; drives: Array<Drive> },\n\t): void {\n\t\tconst { at, drives } = point;\n\n\t\twriteAttribute(part, 'hidden', at ? undefined : '');\n\t\tif (!at) return;\n\n\t\tconst isStill = this.isDisabled() || drives.every(({ binding }) => binding.link.isDisabled());\n\n\t\tpart.style.setProperty('--_sonic-envelope-x', String(at.x));\n\t\tpart.style.setProperty('--_sonic-envelope-y', String(at.y));\n\t\twriteAttribute(part, 'data-sonic-axes', drives.map(({ axis }) => axis).join(''));\n\t\twriteAttribute(part, 'data-sonic-disabled', isStill ? '' : undefined);\n\t}\n\n\t#drives(stage: string): Array<Drive> {\n\t\tconst x = this.#bindings.get(stage);\n\t\tconst y = stage === 'decay' ? this.#bindings.get('sustain') : undefined;\n\n\t\treturn [\n\t\t\t...(x ? [{ axis: 'x' as const, binding: x }] : []),\n\t\t\t...(y ? [{ axis: 'y' as const, binding: y }] : []),\n\t\t];\n\t}\n\n\t#grab(event: PointerEvent): HandleDrag | undefined {\n\t\tconst pressed = this.#pressed(event);\n\t\tif (!pressed || pressed.drives.length === 0) return undefined;\n\n\t\tconst { drives, isFlipped, part } = pressed;\n\n\t\tthis.#claim.press(true, revealDelay(this.#envelope));\n\t\tthis.#held = part;\n\t\tthis.#drawBracket();\n\t\tconst box = this.#graph.getBoundingClientRect();\n\t\tconst travel = { x: Math.max(1, box.width * this.#shape.share), y: Math.max(1, box.height) };\n\t\tconst start = (axis: FieldAxis) => {\n\t\t\tconst link = drives.find((drive) => drive.axis === axis)?.binding.link;\n\t\t\tif (!link) return;\n\n\t\t\tconst mapping = link.mapping();\n\t\t\tconst from = link.value();\n\n\t\t\treturn { from, mapping, proportion: mapping.proportionOf(from), travelPx: travel[axis] };\n\t\t};\n\n\t\treturn {\n\t\t\tdrives: drives.map((drive) => ({ ...drive, from: drive.binding.link.value() })),\n\t\t\tisFlipped,\n\t\t\tpart,\n\t\t\tstate: startFieldDrag({\n\t\t\t\tposition: flip(pointerPosition(event), isFlipped),\n\t\t\t\tthresholdPx: dragThresholdPx(event.pointerType),\n\t\t\t\tx: start('x'),\n\t\t\t\ty: start('y'),\n\t\t\t}),\n\t\t};\n\t}\n\n\t#moveDrag(drag: HandleDrag, event: PointerEvent): void {\n\t\tconst mappings: FieldMappings = {};\n\n\t\tfor (const { axis, binding } of drag.drives) mappings[axis] = binding.link.mapping();\n\n\t\tconst step = stepFieldDrag(mappings, drag.state, flip(pointerMove(event), drag.isFlipped));\n\n\t\tdrag.state = step.state;\n\t\tif (step.state.isEngaged) this.#claim.reveal('drag');\n\t\tthis.#isDriving = true;\n\t\tfor (const { axis, binding } of drag.drives) {\n\t\t\tconst next = step[axis];\n\n\t\t\tif (next !== undefined) binding.link.input(next);\n\t\t}\n\t\tthis.#isDriving = false;\n\t\tthis.#draw();\n\t}\n\n\t#pressed(\n\t\tevent: PointerEvent,\n\t): (Pick<HandleDrag, 'isFlipped' | 'part'> & { drives: Array<Drive> }) | undefined {\n\t\tconst part =\n\t\t\tevent.target instanceof Element\n\t\t\t\t? event.target.closest<HTMLElement>('.sonic-envelope-handle, .sonic-envelope-curve')\n\t\t\t\t: undefined;\n\t\tconst stage = part?.dataset.sonicStage;\n\t\tif (!part || stage === undefined || this.isDisabled()) return undefined;\n\n\t\tconst isCurveHandle = part.classList.contains('sonic-envelope-curve');\n\t\tconst drives = isCurveHandle ? this.#curveDrives(stage) : this.#drives(stage);\n\n\t\treturn {\n\t\t\tdrives: drives.filter(({ binding }) => !binding.link.isDisabled()),\n\t\t\tisFlipped: isCurveHandle && stage === 'attack',\n\t\t\tpart,\n\t\t};\n\t}\n\n\t#readShape(): AdsrShape {\n\t\tconst proportions: AdsrProportions = {};\n\t\tconst curves: AdsrCurves = {};\n\n\t\tfor (const stage of adsrStages) {\n\t\t\tconst link = this.#bindings.get(stage)?.link;\n\n\t\t\tproportions[stage] = link?.mapping().proportionOf(link.value());\n\t\t}\n\t\tfor (const stage of curveStages) {\n\t\t\tcurves[stage] = this.#bindings.get(`${stage}-curve`)?.link.value();\n\t\t}\n\n\t\treturn adsrShape(proportions, curves);\n\t}\n\n\t#rebindOnce(key: unknown, arrives: (rebind: () => void) => void): void {\n\t\tif (this.#waiting.has(key)) return;\n\n\t\tthis.#waiting.add(key);\n\t\tarrives(() => {\n\t\t\tthis.#waiting.delete(key);\n\t\t\tif (this.#signal) this.#bind();\n\t\t});\n\t}\n\n\t#renderReadout(): void {\n\t\tconst drag = this.#pointerDrag?.current();\n\n\t\tif (!drag) {\n\t\t\tthis.#readout.close();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#readout.show({\n\t\t\tanchor: drag.part,\n\t\t\tisOpen: this.#claim.isRevealed && this.readout,\n\t\t\ttext: drag.drives.map(({ binding }) => binding.element.valueText).join(', '),\n\t\t});\n\t}\n\n\t#resolve(name: string): SonicValueElement | undefined {\n\t\tconst id = this.getAttribute(name);\n\t\tconst root = this.getRootNode();\n\t\tif (!id || !isParent(root)) return undefined;\n\n\t\tconst found = root.querySelector(`#${CSS.escape(id)}`);\n\t\tif (found instanceof SonicValueElement) return found;\n\n\t\tthis.#wait(id, found);\n\n\t\treturn undefined;\n\t}\n\n\t#unbind(): void {\n\t\tfor (const { unwatch } of this.#bindings.values()) unwatch();\n\n\t\tthis.#bindings.clear();\n\t}\n\n\t#wait(id: string, found: Element | null): void {\n\t\tconst tag = found?.localName;\n\t\tconst { ownerDocument } = this;\n\n\t\tif (tag?.includes('-') && !customElements.get(tag)) {\n\t\t\tthis.#rebindOnce(tag, (rebind) => {\n\t\t\t\tvoid customElements.whenDefined(tag).then(rebind);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tif (!found && ownerDocument.readyState === 'loading') {\n\t\t\tthis.#rebindOnce(ownerDocument, (rebind) => {\n\t\t\t\townerDocument.addEventListener('DOMContentLoaded', rebind, { once: true });\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#warn(id);\n\t}\n\n\t#warn(id: string): void {\n\t\tif (!__DEV__) return;\n\t\tif (this.#warned.has(id)) return;\n\n\t\tthis.#warned.add(id);\n\t\tconsole.warn(`<sonic-envelope> found no dial, slider or number box with the id \"${id}\"`);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AA2CA,MAAM,cAAc;CAAC;CAAU;CAAS;AAAS;AAEjD,MAAM,WAAW;CAAC,GAAG;CAAY;CAAgB;CAAe;AAAe;AAE/E,MAAM,gBAAgB,IAAI,IAAY,QAAQ;AAE9C,SAAS,KAA+B,OAAc,WAA2B;CAChF,OAAO,YAAY;EAAE,GAAG;EAAO,GAAG,CAAC,MAAM;CAAE,IAAI;AAChD;AAEA,SAAS,SAAS,MAAuC;CACxD,OAAO,mBAAmB;AAC3B;AAEA,MAAM,YAAY;CAAE,MAAM;CAAI,OAAO;EAAE,MAAM;EAAG,IAAI;CAAE;CAAG,QAAQ;AAAG;AAEpE,SAAS,WACR,UACA,MACA,QAC6B;CAC7B,OAAO,IAAI,IACV,OAAO,KAAK,UAAU,CACrB,OACA,aAAa,UAAU,IAAI,KAAK,qBAAqB,MAAM,KAAK,cAAc,CAC/E,CAAC,CACF;AACD;AAEA,MAAM,iBAAiB,SACX;;;;;;;;;;;;;;;;;;IAmBX,cACD;AAEA,IAAa,gBAAb,cAAmC,aAAa;CAC/C,OAAyB,qBAAqB;EAC7C,GAAG,aAAa;EAChB,GAAG;EACH;CACD;CAEA,IAAI,SAAiB;EACpB,OAAO,KAAK,aAAa,QAAQ,KAAK;CACvC;CAEA,IAAI,OAAO,IAAwB;EAClC,KAAK,QAAQ,UAAU,EAAE;CAC1B;CAEA,IAAI,cAAsB;EACzB,OAAO,KAAK,aAAa,cAAc,KAAK;CAC7C;CAEA,IAAI,YAAY,IAAwB;EACvC,KAAK,QAAQ,gBA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,IAAI,EAAE,GAAG;EAE1B,KAAK,QAAQ,IAAI,EAAE;EACnB,QAAQ,KAAK,qEAAqE,GAAG,EAAE;CACxF;AACD"}
1
+ {"version":3,"file":"envelope.js","names":[],"sources":["../../../src/elements/envelope.ts"],"sourcesContent":["import type { ValueLink } from '#elements/value-element.ts';\nimport type { AdsrCurves, AdsrProportions, AdsrShape } from '#lib/adsr-shape.ts';\nimport type { FieldAxis, FieldDragState, FieldMappings, FieldPoint } from '#lib/field.ts';\nimport type { PointerDrag } from '#lib/pointer-drag.ts';\n\nimport { ReadoutClaim, revealDelay } from '#elements/readout-claim.ts';\nimport { Readout } from '#elements/readout.ts';\nimport { SonicElement } from '#elements/sonic-element.ts';\nimport { linkValue, SonicValueElement } from '#elements/value-element.ts';\nimport { adsrPath, adsrShape, adsrStages, timeStages } from '#lib/adsr-shape.ts';\nimport { dragThresholdPx } from '#lib/drag-step.ts';\nimport { pointerMove, pointerPosition, startFieldDrag, stepFieldDrag } from '#lib/field.ts';\nimport { bindDrag } from '#lib/pointer-drag.ts';\nimport { requireChild, template } from '#lib/render.ts';\nimport { writeAttribute } from '#lib/write-attribute.ts';\n\n// eslint-disable-next-line unicorn/consistent-boolean-name -- the name bundlers and other kits use\ndeclare const __DEV__: boolean;\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'sonic-envelope': SonicEnvelope;\n\t}\n}\n\ninterface Binding {\n\telement: SonicValueElement;\n\tlink: ValueLink;\n\tunwatch: () => void;\n}\n\ninterface Drive {\n\taxis: FieldAxis;\n\tbinding: Binding;\n}\n\ninterface HandleDrag {\n\tdrives: Array<Drive & { from: number }>;\n\tisFlipped: boolean;\n\tpart: HTMLElement;\n\tstate: FieldDragState;\n}\n\nconst curveStages = ['attack', 'decay', 'release'] as const;\n\nconst bindable = [...adsrStages, 'attack-curve', 'decay-curve', 'release-curve'] as const;\n\nconst bindableNames = new Set<string>(bindable);\n\nfunction flip<Point extends FieldPoint>(point: Point, isFlipped: boolean): Point {\n\treturn isFlipped ? { ...point, y: -point.y } : point;\n}\n\nfunction isParent(node: Node): node is Node & ParentNode {\n\treturn 'querySelector' in node;\n}\n\nconst emptyPath = { fill: '', floor: { from: 0, to: 0 }, stroke: '' };\n\nfunction stageParts<Stage extends string>(\n\tenvelope: Element,\n\thook: string,\n\tstages: ReadonlyArray<Stage>,\n): Map<Stage, HTMLDivElement> {\n\treturn new Map(\n\t\tstages.map((stage) => [\n\t\t\tstage,\n\t\t\trequireChild(envelope, `.${hook}[data-sonic-stage=\"${stage}\"]`, HTMLDivElement),\n\t\t]),\n\t);\n}\n\nconst renderEnvelope = template(\n\t/* HTML */ `\n\t\t<div class=\"sonic-envelope\" aria-hidden=\"true\">\n\t\t\t<div class=\"sonic-envelope-bracket\"></div>\n\t\t\t<svg class=\"sonic-envelope-graph\" preserveAspectRatio=\"none\" viewBox=\"0 0 1 1\">\n\t\t\t\t<path class=\"sonic-envelope-fill\" />\n\t\t\t\t<rect class=\"sonic-envelope-fill sonic-envelope-floor\" y=\"1\" />\n\t\t\t\t<path class=\"sonic-envelope-line\" />\n\t\t\t</svg>\n\t\t\t<div class=\"sonic-envelope-handle\" data-sonic-stage=\"delay\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-handle\" data-sonic-stage=\"attack\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-handle\" data-sonic-stage=\"hold\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-handle\" data-sonic-stage=\"decay\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-handle\" data-sonic-stage=\"release\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-curve\" data-sonic-stage=\"attack\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-curve\" data-sonic-stage=\"decay\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-curve\" data-sonic-stage=\"release\" hidden></div>\n\t\t\t<div class=\"sonic-envelope-readout\" popover=\"manual\"><span></span></div>\n\t\t</div>\n\t`,\n\tHTMLDivElement,\n);\n\nexport class SonicEnvelope extends SonicElement {\n\tstatic override readonly observedAttributes = [\n\t\t...SonicElement.observedAttributes,\n\t\t...bindable,\n\t\t'readout',\n\t];\n\n\tget attack(): string {\n\t\treturn this.getAttribute('attack') ?? '';\n\t}\n\n\tset attack(id: string | undefined) {\n\t\tthis.reflect('attack', id);\n\t}\n\n\tget attackCurve(): string {\n\t\treturn this.getAttribute('attack-curve') ?? '';\n\t}\n\n\tset attackCurve(id: string | undefined) {\n\t\tthis.reflect('attack-curve', id);\n\t}\n\n\tget decay(): string {\n\t\treturn this.getAttribute('decay') ?? '';\n\t}\n\n\tset decay(id: string | undefined) {\n\t\tthis.reflect('decay', id);\n\t}\n\n\tget decayCurve(): string {\n\t\treturn this.getAttribute('decay-curve') ?? '';\n\t}\n\n\tset decayCurve(id: string | undefined) {\n\t\tthis.reflect('decay-curve', id);\n\t}\n\n\tget delay(): string {\n\t\treturn this.getAttribute('delay') ?? '';\n\t}\n\n\tset delay(id: string | undefined) {\n\t\tthis.reflect('delay', id);\n\t}\n\n\tget hold(): string {\n\t\treturn this.getAttribute('hold') ?? '';\n\t}\n\n\tset hold(id: string | undefined) {\n\t\tthis.reflect('hold', id);\n\t}\n\n\tget pointerType(): string | undefined {\n\t\treturn this.#pointerType;\n\t}\n\n\tget readout(): boolean {\n\t\treturn this.hasAttribute('readout');\n\t}\n\n\tset readout(isOn: boolean) {\n\t\tthis.reflect('readout', isOn);\n\t}\n\n\tget release(): string {\n\t\treturn this.getAttribute('release') ?? '';\n\t}\n\n\tset release(id: string | undefined) {\n\t\tthis.reflect('release', id);\n\t}\n\n\tget releaseCurve(): string {\n\t\treturn this.getAttribute('release-curve') ?? '';\n\t}\n\n\tset releaseCurve(id: string | undefined) {\n\t\tthis.reflect('release-curve', id);\n\t}\n\n\tget sustain(): string {\n\t\treturn this.getAttribute('sustain') ?? '';\n\t}\n\n\tset sustain(id: string | undefined) {\n\t\tthis.reflect('sustain', id);\n\t}\n\n\treadonly #bindings = new Map<string, Binding>();\n\n\treadonly #envelope = renderEnvelope();\n\n\treadonly #bracket = requireChild(this.#envelope, '.sonic-envelope-bracket', HTMLDivElement);\n\n\treadonly #claim = new ReadoutClaim(() => {\n\t\tthis.#renderReadout();\n\t});\n\n\treadonly #curveHandles = stageParts(this.#envelope, 'sonic-envelope-curve', curveStages);\n\n\treadonly #fill = requireChild(this.#envelope, '.sonic-envelope-fill', SVGElement);\n\n\treadonly #floor = requireChild(this.#envelope, '.sonic-envelope-floor', SVGElement);\n\n\treadonly #graph = requireChild(this.#envelope, '.sonic-envelope-graph', SVGElement);\n\n\treadonly #handles = stageParts(this.#envelope, 'sonic-envelope-handle', timeStages);\n\n\t#held: HTMLElement | undefined;\n\n\t#isDriving = false;\n\n\treadonly #line = requireChild(this.#envelope, '.sonic-envelope-line', SVGElement);\n\n\t#pointerDrag: PointerDrag<HandleDrag> | undefined;\n\n\t#pointerType: string | undefined;\n\n\treadonly #readout = new Readout(\n\t\trequireChild(this.#envelope, '.sonic-envelope-readout', HTMLDivElement),\n\t);\n\n\t#shape: AdsrShape = adsrShape({});\n\n\t#signal: AbortSignal | undefined;\n\n\treadonly #waiting = new Set<unknown>();\n\n\treadonly #warned = new Set<string>();\n\n\tattributeChangedCallback(name: string): void {\n\t\tif (!this.#signal) return;\n\t\tif (name === 'disabled') {\n\t\t\tthis.#pointerDrag?.end();\n\t\t\tthis.#draw();\n\t\t\treturn;\n\t\t}\n\t\tif (bindableNames.has(name)) this.#bind();\n\t\telse this.#renderReadout();\n\t}\n\n\toverride connectedCallback(): void {\n\t\tthis.upgradeProperties(...adsrStages, 'attackCurve', 'decayCurve', 'readout', 'releaseCurve');\n\t\tsuper.connectedCallback();\n\t}\n\n\tprotected connect(signal: AbortSignal): void {\n\t\tconst envelope = this.#envelope;\n\n\t\tthis.#signal = signal;\n\t\tthis.keepControl(envelope, signal);\n\t\tthis.#bind();\n\t\tthis.checkStyles(envelope, 'envelope.css');\n\t\tthis.#bindPointer(envelope, signal);\n\t\tsignal.addEventListener(\n\t\t\t'abort',\n\t\t\t() => {\n\t\t\t\tthis.#signal = undefined;\n\t\t\t\tthis.#unbind();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t}\n\n\t#bind(): void {\n\t\tthis.#pointerDrag?.end();\n\t\tthis.#unbind();\n\t\tfor (const name of bindable) {\n\t\t\tconst element = this.#resolve(name);\n\t\t\tif (!element) continue;\n\n\t\t\tconst link = linkValue(element);\n\t\t\tconst unwatch = link.watch(() => {\n\t\t\t\tif (!this.#isDriving) this.#draw();\n\t\t\t});\n\n\t\t\tthis.#bindings.set(name, { element, link, unwatch });\n\t\t}\n\t\tthis.#draw();\n\t}\n\n\t#bindPointer(envelope: HTMLElement, signal: AbortSignal): void {\n\t\tthis.#pointerDrag = bindDrag(\n\t\t\tenvelope,\n\t\t\t{\n\t\t\t\tcancel: (drag) => {\n\t\t\t\t\tfor (const { binding, from } of drag.drives) binding.link.input(from);\n\t\t\t\t},\n\t\t\t\tgrab: (event) => this.#grab(event),\n\t\t\t\tmove: (drag, event) => {\n\t\t\t\t\tthis.#moveDrag(drag, event);\n\t\t\t\t},\n\t\t\t\trelease: (drag) => {\n\t\t\t\t\tthis.#claim.press(false);\n\t\t\t\t\tfor (const { binding, from } of drag.drives) {\n\t\t\t\t\t\tif (binding.link.value() === from) continue;\n\n\t\t\t\t\t\tbinding.element.dispatchEvent(new Event('change', { bubbles: true }));\n\t\t\t\t\t}\n\t\t\t\t\tthis.#pointerType = undefined;\n\t\t\t\t},\n\t\t\t\ttoggle: (isDragging) => {\n\t\t\t\t\tthis.toggleState('dragging', isDragging);\n\t\t\t\t},\n\t\t\t},\n\t\t\tsignal,\n\t\t);\n\t}\n\n\t#curveDrives(stage: string): Array<Drive> {\n\t\tconst binding = this.#bindings.get(`${stage}-curve`);\n\n\t\treturn binding ? [{ axis: 'y', binding }] : [];\n\t}\n\n\t#draw(): void {\n\t\tconst shape = this.#readShape();\n\t\tconst path = this.#bindings.size === 0 ? emptyPath : adsrPath(shape);\n\n\t\tthis.#shape = shape;\n\t\twriteAttribute(this.#line, 'd', path.stroke);\n\t\twriteAttribute(this.#fill, 'd', path.fill);\n\t\twriteAttribute(this.#floor, 'x', String(path.floor.from));\n\t\twriteAttribute(this.#floor, 'width', String(path.floor.to - path.floor.from));\n\t\tfor (const [stage, part] of this.#handles) {\n\t\t\tthis.#drawPoint(part, {\n\t\t\t\tat: shape.handles.find((point) => point.stage === stage),\n\t\t\t\tdrives: this.#drives(stage),\n\t\t\t});\n\t\t}\n\t\tfor (const [stage, part] of this.#curveHandles) {\n\t\t\tthis.#drawPoint(part, {\n\t\t\t\tat: shape.curveHandles.find((point) => point.stage === stage),\n\t\t\t\tdrives: this.#curveDrives(stage),\n\t\t\t});\n\t\t}\n\t\tthis.#drawBracket();\n\t\tthis.#renderReadout();\n\t}\n\n\t#drawBracket(): void {\n\t\tconst part = this.#held;\n\t\tif (!part) return;\n\n\t\tfor (const name of ['--_sonic-envelope-x', '--_sonic-envelope-y']) {\n\t\t\tthis.#bracket.style.setProperty(name, part.style.getPropertyValue(name));\n\t\t}\n\t\twriteAttribute(\n\t\t\tthis.#bracket,\n\t\t\t'data-sonic-part',\n\t\t\tpart.classList.contains('sonic-envelope-curve') ? 'curve' : undefined,\n\t\t);\n\t}\n\n\t#drawPoint(\n\t\tpart: HTMLDivElement,\n\t\tpoint: { at: FieldPoint | undefined; drives: Array<Drive> },\n\t): void {\n\t\tconst { at, drives } = point;\n\n\t\twriteAttribute(part, 'hidden', at ? undefined : '');\n\t\tif (!at) return;\n\n\t\tconst isStill = this.isDisabled() || drives.every(({ binding }) => binding.link.isDisabled());\n\n\t\tpart.style.setProperty('--_sonic-envelope-x', String(at.x));\n\t\tpart.style.setProperty('--_sonic-envelope-y', String(at.y));\n\t\twriteAttribute(part, 'data-sonic-axes', drives.map(({ axis }) => axis).join(''));\n\t\twriteAttribute(part, 'data-sonic-disabled', isStill ? '' : undefined);\n\t}\n\n\t#drives(stage: string): Array<Drive> {\n\t\tconst x = this.#bindings.get(stage);\n\t\tconst y = stage === 'decay' ? this.#bindings.get('sustain') : undefined;\n\n\t\treturn [\n\t\t\t...(x ? [{ axis: 'x' as const, binding: x }] : []),\n\t\t\t...(y ? [{ axis: 'y' as const, binding: y }] : []),\n\t\t];\n\t}\n\n\t#grab(event: PointerEvent): HandleDrag | undefined {\n\t\tconst pressed = this.#pressed(event);\n\t\tif (!pressed || pressed.drives.length === 0) return undefined;\n\n\t\tconst { drives, isFlipped, part } = pressed;\n\n\t\tthis.#pointerType = event.pointerType;\n\t\tthis.#claim.press(true, revealDelay(this.#envelope));\n\t\tthis.#held = part;\n\t\tthis.#drawBracket();\n\t\tconst box = this.#graph.getBoundingClientRect();\n\t\tconst travel = { x: Math.max(1, box.width * this.#shape.share), y: Math.max(1, box.height) };\n\t\tconst start = (axis: FieldAxis) => {\n\t\t\tconst link = drives.find((drive) => drive.axis === axis)?.binding.link;\n\t\t\tif (!link) return;\n\n\t\t\tconst mapping = link.mapping();\n\t\t\tconst from = link.value();\n\n\t\t\treturn { from, mapping, proportion: mapping.proportionOf(from), travelPx: travel[axis] };\n\t\t};\n\n\t\treturn {\n\t\t\tdrives: drives.map((drive) => ({ ...drive, from: drive.binding.link.value() })),\n\t\t\tisFlipped,\n\t\t\tpart,\n\t\t\tstate: startFieldDrag({\n\t\t\t\tposition: flip(pointerPosition(event), isFlipped),\n\t\t\t\tthresholdPx: dragThresholdPx(event.pointerType),\n\t\t\t\tx: start('x'),\n\t\t\t\ty: start('y'),\n\t\t\t}),\n\t\t};\n\t}\n\n\t#moveDrag(drag: HandleDrag, event: PointerEvent): void {\n\t\tconst mappings: FieldMappings = {};\n\n\t\tfor (const { axis, binding } of drag.drives) mappings[axis] = binding.link.mapping();\n\n\t\tconst step = stepFieldDrag(mappings, drag.state, flip(pointerMove(event), drag.isFlipped));\n\n\t\tdrag.state = step.state;\n\t\tif (step.state.isEngaged) this.#claim.reveal('drag');\n\t\tthis.#isDriving = true;\n\t\tfor (const { axis, binding } of drag.drives) {\n\t\t\tconst next = step[axis];\n\n\t\t\tif (next !== undefined) binding.link.input(next);\n\t\t}\n\t\tthis.#isDriving = false;\n\t\tthis.#draw();\n\t}\n\n\t#pressed(\n\t\tevent: PointerEvent,\n\t): (Pick<HandleDrag, 'isFlipped' | 'part'> & { drives: Array<Drive> }) | undefined {\n\t\tconst part =\n\t\t\tevent.target instanceof Element\n\t\t\t\t? event.target.closest<HTMLElement>('.sonic-envelope-handle, .sonic-envelope-curve')\n\t\t\t\t: undefined;\n\t\tconst stage = part?.dataset.sonicStage;\n\t\tif (!part || stage === undefined || this.isDisabled()) return undefined;\n\n\t\tconst isCurveHandle = part.classList.contains('sonic-envelope-curve');\n\t\tconst drives = isCurveHandle ? this.#curveDrives(stage) : this.#drives(stage);\n\n\t\treturn {\n\t\t\tdrives: drives.filter(({ binding }) => !binding.link.isDisabled()),\n\t\t\tisFlipped: isCurveHandle && stage === 'attack',\n\t\t\tpart,\n\t\t};\n\t}\n\n\t#readShape(): AdsrShape {\n\t\tconst proportions: AdsrProportions = {};\n\t\tconst curves: AdsrCurves = {};\n\n\t\tfor (const stage of adsrStages) {\n\t\t\tconst link = this.#bindings.get(stage)?.link;\n\n\t\t\tproportions[stage] = link?.mapping().proportionOf(link.value());\n\t\t}\n\t\tfor (const stage of curveStages) {\n\t\t\tcurves[stage] = this.#bindings.get(`${stage}-curve`)?.link.value();\n\t\t}\n\n\t\treturn adsrShape(proportions, curves);\n\t}\n\n\t#rebindOnce(key: unknown, arrives: (rebind: () => void) => void): void {\n\t\tif (this.#waiting.has(key)) return;\n\n\t\tthis.#waiting.add(key);\n\t\tarrives(() => {\n\t\t\tthis.#waiting.delete(key);\n\t\t\tif (this.#signal) this.#bind();\n\t\t});\n\t}\n\n\t#renderReadout(): void {\n\t\tconst drag = this.#pointerDrag?.current();\n\n\t\tif (!drag) {\n\t\t\tthis.#readout.close();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#readout.show({\n\t\t\tanchor: drag.part,\n\t\t\tisOpen: this.#claim.isRevealed && this.readout,\n\t\t\ttext: drag.drives.map(({ binding }) => binding.element.valueText).join(', '),\n\t\t});\n\t}\n\n\t#resolve(name: string): SonicValueElement | undefined {\n\t\tconst id = this.getAttribute(name);\n\t\tconst root = this.getRootNode();\n\t\tif (!id || !isParent(root)) return undefined;\n\n\t\tconst found = root.querySelector(`#${CSS.escape(id)}`);\n\t\tif (found instanceof SonicValueElement) return found;\n\n\t\tthis.#wait(id, found);\n\n\t\treturn undefined;\n\t}\n\n\t#unbind(): void {\n\t\tfor (const { unwatch } of this.#bindings.values()) unwatch();\n\n\t\tthis.#bindings.clear();\n\t}\n\n\t#wait(id: string, found: Element | null): void {\n\t\tconst tag = found?.localName;\n\t\tconst { ownerDocument } = this;\n\n\t\tif (tag?.includes('-') && !customElements.get(tag)) {\n\t\t\tthis.#rebindOnce(tag, (rebind) => {\n\t\t\t\tvoid customElements.whenDefined(tag).then(rebind);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tif (!found && ownerDocument.readyState === 'loading') {\n\t\t\tthis.#rebindOnce(ownerDocument, (rebind) => {\n\t\t\t\townerDocument.addEventListener('DOMContentLoaded', rebind, { once: true });\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#warn(id);\n\t}\n\n\t#warn(id: string): void {\n\t\tif (!__DEV__) return;\n\t\tif (this.#warned.has(id)) return;\n\n\t\tthis.#warned.add(id);\n\t\tconsole.warn(`<sonic-envelope> found no dial, slider or number box with the id \"${id}\"`);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AA2CA,MAAM,cAAc;CAAC;CAAU;CAAS;AAAS;AAEjD,MAAM,WAAW;CAAC,GAAG;CAAY;CAAgB;CAAe;AAAe;AAE/E,MAAM,gBAAgB,IAAI,IAAY,QAAQ;AAE9C,SAAS,KAA+B,OAAc,WAA2B;CAChF,OAAO,YAAY;EAAE,GAAG;EAAO,GAAG,CAAC,MAAM;CAAE,IAAI;AAChD;AAE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,YAAY;EAC9B,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,GAAG,OAAO;EAEnC,MAAM,QAAQ,KAAK,cAAc,IAAI,IAAI,OAAO,EAAE,GAAG;EACrD,IAAI,iBAAiB,mBAAmB,OAAO;EAE/C,KAAK,MAAM,IAAI,KAAK;CAGrB;CAEA,UAAgB;EACf,KAAK,MAAM,EAAE,aAAa,KAAK,UAAU,OAAO,GAAG,QAAQ;EAE3D,KAAK,UAAU,MAAM;CACtB;CAEA,MAAM,IAAY,OAA6B;EAC9C,MAAM,MAAM,OAAO;EACnB,MAAM,EAAE,kBAAkB;EAE1B,IAAI,KAAK,SAAS,GAAG,KAAK,CAAC,eAAe,IAAI,GAAG,GAAG;GACnD,KAAK,YAAY,MAAM,WAAW;IACjC,AAAK,eAAe,YAAY,GAAG,CAAC,CAAC,KAAK,MAAM;GACjD,CAAC;GACD;EACD;EACA,IAAI,CAAC,SAAS,cAAc,eAAe,WAAW;GACrD,KAAK,YAAY,gBAAgB,WAAW;IAC3C,cAAc,iBAAiB,oBAAoB,QAAQ,EAAE,MAAM,KAAK,CAAC;GAC1E,CAAC;GACD;EACD;EAEA,KAAK,MAAM,EAAE;CACd;CAEA,MAAM,IAAkB;EAEvB,IAAI,KAAK,QAAQ,IAAI,EAAE,GAAG;EAE1B,KAAK,QAAQ,IAAI,EAAE;EACnB,QAAQ,KAAK,qEAAqE,GAAG,EAAE;CACxF;AACD"}
@@ -14,6 +14,7 @@ export declare abstract class SonicElement extends HTMLElement {
14
14
  protected abstract connect(signal: AbortSignal): void;
15
15
  protected focusTarget(): HTMLElement | undefined;
16
16
  protected forwardNaming(target: Element, isNamed: boolean): void;
17
+ protected hasState(state: string): boolean;
17
18
  protected isBound(): boolean;
18
19
  protected isDisabled(): boolean;
19
20
  protected keepControl(control: Element, signal: AbortSignal): void;
@@ -24,6 +24,7 @@ var SonicElement = class extends HTMLElement {
24
24
  }
25
25
  internals = "attachInternals" in HTMLElement.prototype ? this.attachInternals() : void 0;
26
26
  #connection;
27
+ #states = /* @__PURE__ */ new Set();
27
28
  blur() {
28
29
  this.#focused()?.blur();
29
30
  }
@@ -101,6 +102,9 @@ var SonicElement = class extends HTMLElement {
101
102
  }
102
103
  if (labels.length > 0) writeLabelledBy(target, labels);
103
104
  }
105
+ hasState(state) {
106
+ return this.#states.has(state);
107
+ }
104
108
  isBound() {
105
109
  return this.#connection !== void 0;
106
110
  }
@@ -138,8 +142,13 @@ var SonicElement = class extends HTMLElement {
138
142
  this.setAttribute(name, value === true ? "" : value.toString());
139
143
  }
140
144
  toggleState(state, isOn) {
141
- if (isOn) this.internals?.states.add(state);
142
- else this.internals?.states.delete(state);
145
+ if (isOn) {
146
+ this.#states.add(state);
147
+ this.internals?.states.add(state);
148
+ return;
149
+ }
150
+ this.#states.delete(state);
151
+ this.internals?.states.delete(state);
143
152
  }
144
153
  upgradeProperties(...names) {
145
154
  for (const name of names) {