@xsynaptic/sonic-ui 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +0 -2
  2. package/dist/default/elements/dial.js +12 -3
  3. package/dist/default/elements/display-element.js +14 -2
  4. package/dist/default/elements/envelope.js +2 -2
  5. package/dist/default/elements/modulation.js +45 -0
  6. package/dist/default/elements/readout-claim.js +8 -3
  7. package/dist/default/elements/slider.js +16 -18
  8. package/dist/default/elements/spectrum.js +1 -0
  9. package/dist/default/elements/value-element.js +108 -330
  10. package/dist/default/elements/value-gestures.js +301 -0
  11. package/dist/default/elements/wave-element.js +5 -26
  12. package/dist/default/elements/waveform.js +6 -2
  13. package/dist/default/elements/wavestrip.js +5 -16
  14. package/dist/default/elements/xy.js +9 -20
  15. package/dist/default/lib/asked-value.js +21 -0
  16. package/dist/default/lib/canvas-surface.js +3 -0
  17. package/dist/default/lib/fill-watch.js +29 -0
  18. package/dist/default/lib/hover-preview.js +8 -3
  19. package/dist/default/lib/marker-rider.js +6 -3
  20. package/dist/default/lib/read-ms-property.js +10 -0
  21. package/dist/dev/elements/dial.js +12 -3
  22. package/dist/dev/elements/dial.js.map +1 -1
  23. package/dist/dev/elements/display-element.d.ts +4 -1
  24. package/dist/dev/elements/display-element.js +14 -2
  25. package/dist/dev/elements/display-element.js.map +1 -1
  26. package/dist/dev/elements/envelope.js +2 -2
  27. package/dist/dev/elements/envelope.js.map +1 -1
  28. package/dist/dev/elements/modulation.js +46 -0
  29. package/dist/dev/elements/modulation.js.map +1 -0
  30. package/dist/dev/elements/readout-claim.js +8 -3
  31. package/dist/dev/elements/readout-claim.js.map +1 -1
  32. package/dist/dev/elements/slider.d.ts +0 -1
  33. package/dist/dev/elements/slider.js +16 -18
  34. package/dist/dev/elements/slider.js.map +1 -1
  35. package/dist/dev/elements/spectrum.d.ts +1 -0
  36. package/dist/dev/elements/spectrum.js +1 -0
  37. package/dist/dev/elements/spectrum.js.map +1 -1
  38. package/dist/dev/elements/value-element.d.ts +11 -13
  39. package/dist/dev/elements/value-element.js +108 -330
  40. package/dist/dev/elements/value-element.js.map +1 -1
  41. package/dist/dev/elements/value-gestures.d.ts +10 -0
  42. package/dist/dev/elements/value-gestures.js +302 -0
  43. package/dist/dev/elements/value-gestures.js.map +1 -0
  44. package/dist/dev/elements/wave-element.js +5 -26
  45. package/dist/dev/elements/wave-element.js.map +1 -1
  46. package/dist/dev/elements/waveform.js +6 -2
  47. package/dist/dev/elements/waveform.js.map +1 -1
  48. package/dist/dev/elements/wavestrip.d.ts +0 -1
  49. package/dist/dev/elements/wavestrip.js +5 -16
  50. package/dist/dev/elements/wavestrip.js.map +1 -1
  51. package/dist/dev/elements/xy.js +9 -20
  52. package/dist/dev/elements/xy.js.map +1 -1
  53. package/dist/dev/lib/asked-value.js +22 -0
  54. package/dist/dev/lib/asked-value.js.map +1 -0
  55. package/dist/dev/lib/canvas-surface.d.ts +1 -0
  56. package/dist/dev/lib/canvas-surface.js +3 -0
  57. package/dist/dev/lib/canvas-surface.js.map +1 -1
  58. package/dist/dev/lib/fill-watch.js +30 -0
  59. package/dist/dev/lib/fill-watch.js.map +1 -0
  60. package/dist/dev/lib/hover-preview.js +8 -3
  61. package/dist/dev/lib/hover-preview.js.map +1 -1
  62. package/dist/dev/lib/marker-rider.js +6 -3
  63. package/dist/dev/lib/marker-rider.js.map +1 -1
  64. package/dist/dev/lib/read-ms-property.js +11 -0
  65. package/dist/dev/lib/read-ms-property.js.map +1 -0
  66. package/dist/styles/envelope.css +1 -1
  67. package/dist/styles/led.css +1 -1
  68. package/dist/styles/material.css +42 -8
  69. package/dist/styles/spectrum.css +5 -0
  70. package/dist/styles/switch.css +42 -33
  71. package/dist/styles/waveform.css +31 -2
  72. package/dist/styles/wavestrip.css +13 -7
  73. package/dist/styles/xy.css +4 -4
  74. package/package.json +1 -1
package/README.md CHANGED
@@ -23,8 +23,6 @@ import '@xsynaptic/sonic-ui/define';
23
23
  <sonic-dial aria-label="Cutoff" value="40"></sonic-dial>
24
24
  ```
25
25
 
26
- A `-size` token takes any CSS length and scales its control as one piece; a `-length` token also takes a percentage of the parent.
27
-
28
26
  A display takes its signal as data: `spectrum.analyser = node`, or `spectrum.push(frame)`.
29
27
 
30
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.
@@ -1,4 +1,5 @@
1
1
  import { requireChild, template } from "../lib/render.js";
2
+ import { createModulation } from "./modulation.js";
2
3
  import { SonicValueElement } from "./value-element.js";
3
4
  import { bindScale } from "./scale.js";
4
5
 
@@ -43,12 +44,15 @@ var SonicDial = class extends SonicValueElement {
43
44
  this.reflect("modulation", amount);
44
45
  }
45
46
  get modulationValue() {
46
- return this.readModulationValue();
47
+ return this.#modulation.value();
47
48
  }
48
49
  set modulationValue(value) {
49
- this.writeModulationValue(this.#dial, "dial", value);
50
+ this.#modulation.write(value, this.isBound() ? this.mapping() : void 0);
50
51
  }
51
52
  #dial = renderDial();
53
+ #modulation = createModulation(this.#dial, "dial", (isModulated) => {
54
+ this.toggleState("modulated", isModulated);
55
+ });
52
56
  connectedCallback() {
53
57
  this.upgradeProperties("endless", "modulationValue", "modulation");
54
58
  super.connectedCallback();
@@ -67,7 +71,12 @@ var SonicDial = class extends SonicValueElement {
67
71
  }));
68
72
  }
69
73
  draw() {
70
- this.writeProportions(this.#dial, "dial", this.endless ? 0 : this.modulation);
74
+ this.#modulation.draw({
75
+ mapping: this.mapping(),
76
+ modulation: this.endless ? 0 : this.modulation,
77
+ origin: this.originValue(),
78
+ value: this.value
79
+ });
71
80
  }
72
81
  focusTarget() {
73
82
  return this.#dial;
@@ -1,10 +1,12 @@
1
1
  import { SonicElement } from "./sonic-element.js";
2
2
  import { bindSurface } from "../lib/canvas-surface.js";
3
+ import { bindFill } from "../lib/fill-watch.js";
3
4
 
4
5
  //#region src/elements/display-element.ts
5
6
  var SonicDisplayElement = class extends SonicElement {
6
7
  static observedAttributes = [
7
8
  ...SonicElement.observedAttributes,
9
+ "fill",
8
10
  "max",
9
11
  "min"
10
12
  ];
@@ -15,6 +17,12 @@ var SonicDisplayElement = class extends SonicElement {
15
17
  this.#analyser = node ?? void 0;
16
18
  this.#surface?.requestFrame();
17
19
  }
20
+ get fill() {
21
+ return this.hasAttribute("fill");
22
+ }
23
+ set fill(isFilling) {
24
+ this.reflect("fill", isFilling);
25
+ }
18
26
  get max() {
19
27
  return this.numberAttribute("max", 0);
20
28
  }
@@ -30,11 +38,13 @@ var SonicDisplayElement = class extends SonicElement {
30
38
  #analyser;
31
39
  #buffer = /* @__PURE__ */ new Float32Array(0);
32
40
  #surface;
33
- attributeChangedCallback() {
41
+ #syncFill;
42
+ attributeChangedCallback(name) {
43
+ if (name === "fill") this.#syncFill?.(this.fill);
34
44
  this.#surface?.invalidate();
35
45
  }
36
46
  connectedCallback() {
37
- this.upgradeProperties("analyser", "max", "min");
47
+ this.upgradeProperties("analyser", "fill", "max", "min");
38
48
  super.connectedCallback();
39
49
  }
40
50
  push(frame) {
@@ -57,6 +67,8 @@ var SonicDisplayElement = class extends SonicElement {
57
67
  signal
58
68
  });
59
69
  this.checkStyles(control, this.sheet);
70
+ this.#syncFill = bindFill(control, this.sizeProperty, signal);
71
+ this.#syncFill(this.fill);
60
72
  }
61
73
  surface() {
62
74
  return this.#surface;
@@ -2,8 +2,8 @@ import { writeAttribute } from "../lib/write-attribute.js";
2
2
  import { SonicElement } from "./sonic-element.js";
3
3
  import { requireChild, template } from "../lib/render.js";
4
4
  import { bindDrag } from "../lib/pointer-drag.js";
5
- import { ReadoutClaim } from "./readout-claim.js";
6
5
  import { Readout } from "./readout.js";
6
+ import { ReadoutClaim, revealDelay } from "./readout-claim.js";
7
7
  import { dragThresholdPx } from "../lib/drag-step.js";
8
8
  import { SonicValueElement, linkValue } from "./value-element.js";
9
9
  import { adsrPath, adsrShape, adsrStages, timeStages } from "../lib/adsr-shape.js";
@@ -269,7 +269,7 @@ var SonicEnvelope = class extends SonicElement {
269
269
  const pressed = this.#pressed(event);
270
270
  if (!pressed || pressed.drives.length === 0) return void 0;
271
271
  const { drives, isFlipped, part } = pressed;
272
- this.#claim.press(true);
272
+ this.#claim.press(true, revealDelay(this.#envelope));
273
273
  this.#held = part;
274
274
  this.#drawBracket();
275
275
  const box = this.#graph.getBoundingClientRect();
@@ -0,0 +1,45 @@
1
+ import { toNumber } from "../lib/math.js";
2
+
3
+ //#region src/elements/modulation.ts
4
+ function createModulation(control, prefix, toggle) {
5
+ const { style } = control;
6
+ let isModulated = false;
7
+ let modulationValue;
8
+ const writeProportion = (mapping) => {
9
+ const shown = mapping.isWrapping ? void 0 : modulationValue;
10
+ const isShown = shown !== void 0;
11
+ if (isShown !== isModulated) {
12
+ isModulated = isShown;
13
+ toggle(isShown);
14
+ }
15
+ if (shown === void 0) {
16
+ style.removeProperty(`--_sonic-${prefix}-modulation-value`);
17
+ return;
18
+ }
19
+ style.setProperty(`--_sonic-${prefix}-modulation-value`, String(mapping.proportionOf(shown)));
20
+ };
21
+ return {
22
+ draw: ({ mapping, modulation, origin, value }) => {
23
+ const at = mapping.proportionOf(value);
24
+ const reach = mapping.proportionOf(value + modulation);
25
+ const { positionCount } = mapping;
26
+ style.setProperty(`--_sonic-${prefix}-value`, String(at));
27
+ style.setProperty(`--_sonic-${prefix}-origin`, String(mapping.proportionOf(origin)));
28
+ style.setProperty(`--_sonic-${prefix}-modulation-from`, String(Math.min(at, reach)));
29
+ style.setProperty(`--_sonic-${prefix}-modulation-to`, String(Math.max(at, reach)));
30
+ if (positionCount === void 0) style.removeProperty(`--_sonic-${prefix}-position-count`);
31
+ else style.setProperty(`--_sonic-${prefix}-position-count`, String(positionCount));
32
+ writeProportion(mapping);
33
+ },
34
+ value: () => modulationValue,
35
+ write: (next, mapping) => {
36
+ const value = next === void 0 || next === null ? void 0 : toNumber(next);
37
+ if (value !== void 0 && !Number.isFinite(value)) return;
38
+ modulationValue = value;
39
+ if (mapping) writeProportion(mapping);
40
+ }
41
+ };
42
+ }
43
+
44
+ //#endregion
45
+ export { createModulation };
@@ -1,6 +1,11 @@
1
+ import { readMsProperty } from "../lib/read-ms-property.js";
2
+
1
3
  //#region src/elements/readout-claim.ts
2
4
  const keyRevealMs = 1e3;
3
5
  const revealMs = 250;
6
+ function revealDelay(control) {
7
+ return Math.max(0, readMsProperty(getComputedStyle(control), "--_sonic-reveal-delay", revealMs));
8
+ }
4
9
  var ReadoutClaim = class {
5
10
  get isRevealed() {
6
11
  return this.#isDragging || this.#keyTimer !== void 0;
@@ -24,7 +29,7 @@ var ReadoutClaim = class {
24
29
  this.#keyTimer = void 0;
25
30
  return wasTimed;
26
31
  }
27
- press(isDown) {
32
+ press(isDown, delayMs = revealMs) {
28
33
  this.conceal("drag");
29
34
  if (!isDown) {
30
35
  this.#onLapse();
@@ -33,7 +38,7 @@ var ReadoutClaim = class {
33
38
  this.#holdTimer = setTimeout(() => {
34
39
  this.reveal("drag");
35
40
  this.#onLapse();
36
- }, 250);
41
+ }, delayMs);
37
42
  }
38
43
  reveal(by) {
39
44
  if (by === "drag") {
@@ -49,4 +54,4 @@ var ReadoutClaim = class {
49
54
  };
50
55
 
51
56
  //#endregion
52
- export { ReadoutClaim };
57
+ export { ReadoutClaim, revealDelay };
@@ -1,8 +1,8 @@
1
1
  import { clampProportion } from "../lib/math.js";
2
2
  import { requireChild, template } from "../lib/render.js";
3
+ import { createModulation } from "./modulation.js";
3
4
  import { SonicValueElement } from "./value-element.js";
4
5
  import { bindScale } from "./scale.js";
5
- import { bindHoverPreview } from "../lib/hover-preview.js";
6
6
  import { sortedRegions } from "../lib/time-regions.js";
7
7
 
8
8
  //#region src/elements/slider.ts
@@ -59,10 +59,10 @@ var SonicSlider = class extends SonicValueElement {
59
59
  this.reflect("modulation", amount);
60
60
  }
61
61
  get modulationValue() {
62
- return this.readModulationValue();
62
+ return this.#modulation.value();
63
63
  }
64
64
  set modulationValue(value) {
65
- this.writeModulationValue(this.#slider, "slider", value);
65
+ this.#modulation.write(value, this.isBound() ? this.mapping() : void 0);
66
66
  }
67
67
  get orientation() {
68
68
  return this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal";
@@ -83,8 +83,10 @@ var SonicSlider = class extends SonicValueElement {
83
83
  this.reflect("spring", isSpring);
84
84
  }
85
85
  #buffered = [];
86
- #hover;
87
86
  #slider = renderSlider();
87
+ #modulation = createModulation(this.#slider, "slider", (isModulated) => {
88
+ this.toggleState("modulated", isModulated);
89
+ });
88
90
  connectedCallback() {
89
91
  this.upgradeProperties("buffered", "groovePress", "modulationValue", "modulation", "orientation", "scrub", "spring");
90
92
  super.connectedCallback();
@@ -99,14 +101,9 @@ var SonicSlider = class extends SonicValueElement {
99
101
  slider.addEventListener("transitionend", (event) => {
100
102
  if (event.propertyName === "--_sonic-slider-value") this.toggleState("springing", false);
101
103
  }, { signal });
102
- this.#hover = bindHoverPreview(slider, {
103
- canShow: () => this.scrub && this.readout && this.orientation === "horizontal",
104
- dismiss: () => {
105
- this.render();
106
- },
107
- isTaken: () => this.isEditing() || this.isRevealed(),
108
- show: () => {
109
- this.renderReadout();
104
+ this.bindHover(slider, signal, {
105
+ canShow: () => this.scrub && this.orientation === "horizontal",
106
+ place: () => {
110
107
  this.#placeReadout(slider);
111
108
  },
112
109
  valueAt: (event) => {
@@ -115,7 +112,7 @@ var SonicSlider = class extends SonicValueElement {
115
112
  const mapping = this.mapping();
116
113
  return mapping.snap(mapping.valueAt(at));
117
114
  }
118
- }, signal);
115
+ });
119
116
  this.render();
120
117
  this.checkStyles(slider, "slider.css");
121
118
  this.bindGestures(slider, signal, (event) => {
@@ -130,8 +127,12 @@ var SonicSlider = class extends SonicValueElement {
130
127
  return this.orientation;
131
128
  }
132
129
  draw() {
133
- if (this.isEditing() || this.isRevealed()) this.#hover?.clear();
134
- this.writeProportions(this.#slider, "slider", this.modulation);
130
+ this.#modulation.draw({
131
+ mapping: this.mapping(),
132
+ modulation: this.modulation,
133
+ origin: this.originValue(),
134
+ value: this.value
135
+ });
135
136
  this.#renderBuffered(this.#slider);
136
137
  this.#renderScrub(this.#slider);
137
138
  this.#placeReadout(this.#slider);
@@ -146,9 +147,6 @@ var SonicSlider = class extends SonicValueElement {
146
147
  holdChanged() {
147
148
  if (this.scrub) this.render();
148
149
  }
149
- previewValue() {
150
- return this.#hover?.value();
151
- }
152
150
  scrubsKeyRepeat() {
153
151
  return this.scrub;
154
152
  }
@@ -119,6 +119,7 @@ var SonicSpectrum = class extends SonicDisplayElement {
119
119
  colours = colours;
120
120
  numbers = numbers;
121
121
  sheet = "spectrum.css";
122
+ sizeProperty = "--_sonic-spectrum-size";
122
123
  #columns;
123
124
  #isSettled = true;
124
125
  #lastFrameMs;