@tremolo-ui/react 0.0.1 → 0.0.3

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 (110) hide show
  1. package/README.md +5 -53
  2. package/dist/cjs/index.d.ts +107 -46
  3. package/dist/cjs/index.js +525 -203
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/packages/react/tsconfig.tsbuildinfo +1 -0
  6. package/dist/cjs/types/packages/functions/components/NumberInput/type.d.ts +14 -0
  7. package/dist/cjs/types/packages/functions/components/NumberInput/type.d.ts.map +1 -0
  8. package/dist/cjs/types/{src → packages/functions}/components/Slider/type.d.ts +8 -2
  9. package/dist/cjs/types/packages/functions/components/Slider/type.d.ts.map +1 -0
  10. package/dist/cjs/types/{src → packages/functions}/math.d.ts +4 -0
  11. package/dist/cjs/types/packages/functions/math.d.ts.map +1 -0
  12. package/dist/cjs/types/packages/functions/types.d.ts.map +1 -0
  13. package/dist/cjs/types/packages/functions/util.d.ts +6 -0
  14. package/dist/cjs/types/packages/functions/util.d.ts.map +1 -0
  15. package/dist/cjs/types/packages/react/src/components/AnimationCanvas/canvas.d.ts +6 -0
  16. package/dist/cjs/types/packages/react/src/components/AnimationCanvas/canvas.d.ts.map +1 -0
  17. package/dist/cjs/types/packages/react/src/components/AnimationCanvas/index.d.ts +20 -0
  18. package/dist/cjs/types/packages/react/src/components/AnimationCanvas/index.d.ts.map +1 -0
  19. package/dist/cjs/types/packages/react/src/components/Knob/index.d.ts +36 -0
  20. package/dist/cjs/types/packages/react/src/components/Knob/index.d.ts.map +1 -0
  21. package/dist/cjs/types/packages/react/src/components/NumberInput/index.d.ts +47 -0
  22. package/dist/cjs/types/packages/react/src/components/NumberInput/index.d.ts.map +1 -0
  23. package/dist/cjs/types/packages/react/src/components/Slider/Thumb.d.ts +11 -0
  24. package/dist/cjs/types/packages/react/src/components/Slider/Thumb.d.ts.map +1 -0
  25. package/dist/cjs/types/packages/react/src/components/Slider/Track.d.ts +10 -0
  26. package/dist/cjs/types/packages/react/src/components/Slider/Track.d.ts.map +1 -0
  27. package/dist/cjs/types/packages/react/src/components/Slider/index.d.ts +34 -0
  28. package/dist/cjs/types/packages/react/src/components/Slider/index.d.ts.map +1 -0
  29. package/dist/cjs/types/packages/react/src/components/Slider/type.d.ts +6 -0
  30. package/dist/cjs/types/packages/react/src/components/Slider/type.d.ts.map +1 -0
  31. package/dist/cjs/types/packages/react/src/hooks/useCallbackRef.d.ts.map +1 -0
  32. package/dist/cjs/types/packages/react/src/hooks/useEventListener.d.ts.map +1 -0
  33. package/dist/cjs/types/packages/react/src/hooks/useRefCallbackEvent.d.ts +5 -0
  34. package/dist/cjs/types/packages/react/src/hooks/useRefCallbackEvent.d.ts.map +1 -0
  35. package/dist/cjs/types/packages/react/src/index.d.ts +7 -0
  36. package/dist/cjs/types/packages/react/src/index.d.ts.map +1 -0
  37. package/dist/cjs/types/packages/react/src/system/pseudo.d.ts +14 -0
  38. package/dist/cjs/types/packages/react/src/system/pseudo.d.ts.map +1 -0
  39. package/dist/esm/index.d.ts +107 -46
  40. package/dist/esm/index.js +513 -197
  41. package/dist/esm/index.js.map +1 -1
  42. package/dist/esm/packages/react/tsconfig.tsbuildinfo +1 -0
  43. package/dist/esm/types/packages/functions/components/NumberInput/type.d.ts +14 -0
  44. package/dist/esm/types/packages/functions/components/NumberInput/type.d.ts.map +1 -0
  45. package/dist/esm/types/{src → packages/functions}/components/Slider/type.d.ts +8 -2
  46. package/dist/esm/types/packages/functions/components/Slider/type.d.ts.map +1 -0
  47. package/dist/esm/types/{src → packages/functions}/math.d.ts +4 -0
  48. package/dist/esm/types/packages/functions/math.d.ts.map +1 -0
  49. package/dist/esm/types/packages/functions/types.d.ts.map +1 -0
  50. package/dist/esm/types/packages/functions/util.d.ts +6 -0
  51. package/dist/esm/types/packages/functions/util.d.ts.map +1 -0
  52. package/dist/esm/types/packages/react/src/components/AnimationCanvas/canvas.d.ts +6 -0
  53. package/dist/esm/types/packages/react/src/components/AnimationCanvas/canvas.d.ts.map +1 -0
  54. package/dist/esm/types/packages/react/src/components/AnimationCanvas/index.d.ts +20 -0
  55. package/dist/esm/types/packages/react/src/components/AnimationCanvas/index.d.ts.map +1 -0
  56. package/dist/esm/types/packages/react/src/components/Knob/index.d.ts +36 -0
  57. package/dist/esm/types/packages/react/src/components/Knob/index.d.ts.map +1 -0
  58. package/dist/esm/types/packages/react/src/components/NumberInput/index.d.ts +47 -0
  59. package/dist/esm/types/packages/react/src/components/NumberInput/index.d.ts.map +1 -0
  60. package/dist/esm/types/packages/react/src/components/Slider/Thumb.d.ts +11 -0
  61. package/dist/esm/types/packages/react/src/components/Slider/Thumb.d.ts.map +1 -0
  62. package/dist/esm/types/packages/react/src/components/Slider/Track.d.ts +10 -0
  63. package/dist/esm/types/packages/react/src/components/Slider/Track.d.ts.map +1 -0
  64. package/dist/esm/types/packages/react/src/components/Slider/index.d.ts +34 -0
  65. package/dist/esm/types/packages/react/src/components/Slider/index.d.ts.map +1 -0
  66. package/dist/esm/types/packages/react/src/components/Slider/type.d.ts +6 -0
  67. package/dist/esm/types/packages/react/src/components/Slider/type.d.ts.map +1 -0
  68. package/dist/esm/types/packages/react/src/hooks/useCallbackRef.d.ts.map +1 -0
  69. package/dist/esm/types/packages/react/src/hooks/useEventListener.d.ts.map +1 -0
  70. package/dist/esm/types/packages/react/src/hooks/useRefCallbackEvent.d.ts +5 -0
  71. package/dist/esm/types/packages/react/src/hooks/useRefCallbackEvent.d.ts.map +1 -0
  72. package/dist/esm/types/packages/react/src/index.d.ts +7 -0
  73. package/dist/esm/types/packages/react/src/index.d.ts.map +1 -0
  74. package/dist/esm/types/packages/react/src/system/pseudo.d.ts +14 -0
  75. package/dist/esm/types/packages/react/src/system/pseudo.d.ts.map +1 -0
  76. package/package.json +24 -39
  77. package/LICENSE +0 -21
  78. package/dist/cjs/types/src/components/Knob/index.d.ts +0 -23
  79. package/dist/cjs/types/src/components/Knob/index.d.ts.map +0 -1
  80. package/dist/cjs/types/src/components/Slider/index.d.ts +0 -27
  81. package/dist/cjs/types/src/components/Slider/index.d.ts.map +0 -1
  82. package/dist/cjs/types/src/components/Slider/type.d.ts.map +0 -1
  83. package/dist/cjs/types/src/hooks/useCallbackRef.d.ts.map +0 -1
  84. package/dist/cjs/types/src/hooks/useEventListener.d.ts.map +0 -1
  85. package/dist/cjs/types/src/index.d.ts +0 -5
  86. package/dist/cjs/types/src/index.d.ts.map +0 -1
  87. package/dist/cjs/types/src/math.d.ts.map +0 -1
  88. package/dist/cjs/types/src/types.d.ts.map +0 -1
  89. package/dist/cjs/types/src/util.d.ts +0 -2
  90. package/dist/cjs/types/src/util.d.ts.map +0 -1
  91. package/dist/esm/types/src/components/Knob/index.d.ts +0 -23
  92. package/dist/esm/types/src/components/Knob/index.d.ts.map +0 -1
  93. package/dist/esm/types/src/components/Slider/index.d.ts +0 -27
  94. package/dist/esm/types/src/components/Slider/index.d.ts.map +0 -1
  95. package/dist/esm/types/src/components/Slider/type.d.ts.map +0 -1
  96. package/dist/esm/types/src/hooks/useCallbackRef.d.ts.map +0 -1
  97. package/dist/esm/types/src/hooks/useEventListener.d.ts.map +0 -1
  98. package/dist/esm/types/src/index.d.ts +0 -5
  99. package/dist/esm/types/src/index.d.ts.map +0 -1
  100. package/dist/esm/types/src/math.d.ts.map +0 -1
  101. package/dist/esm/types/src/types.d.ts.map +0 -1
  102. package/dist/esm/types/src/util.d.ts +0 -2
  103. package/dist/esm/types/src/util.d.ts.map +0 -1
  104. package/dist/tsconfig.tsbuildinfo +0 -1
  105. /package/dist/cjs/types/{src → packages/functions}/types.d.ts +0 -0
  106. /package/dist/cjs/types/{src → packages/react/src}/hooks/useCallbackRef.d.ts +0 -0
  107. /package/dist/cjs/types/{src → packages/react/src}/hooks/useEventListener.d.ts +0 -0
  108. /package/dist/esm/types/{src → packages/functions}/types.d.ts +0 -0
  109. /package/dist/esm/types/{src → packages/react/src}/hooks/useCallbackRef.d.ts +0 -0
  110. /package/dist/esm/types/{src → packages/react/src}/hooks/useEventListener.d.ts +0 -0
package/dist/cjs/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('@emotion/react/jsx-runtime');
4
- var react$1 = require('@emotion/react');
5
- var react = require('react');
4
+ var react = require('@emotion/react');
5
+ var React = require('react');
6
6
 
7
7
  function clamp(value, min, max) {
8
8
  return Math.max(min, Math.min(value, max));
@@ -42,24 +42,182 @@ function toFixed(x, fractionDigits) {
42
42
  function decimalPart(x) {
43
43
  return String(x).split('.')[1];
44
44
  }
45
+ function radian(degree) {
46
+ return (Math.PI * degree) / 180;
47
+ }
48
+ function degree(radian) {
49
+ return (180 * radian) / Math.PI;
50
+ }
51
+ function dbToGain(db) {
52
+ return Math.pow(10, db / 20);
53
+ }
54
+ function gainToDb(gain) {
55
+ return 20 * (Math.log(gain) / Math.LN10);
56
+ }
57
+
58
+ /******************************************************************************
59
+ Copyright (c) Microsoft Corporation.
60
+
61
+ Permission to use, copy, modify, and/or distribute this software for any
62
+ purpose with or without fee is hereby granted.
63
+
64
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
65
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
66
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
67
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
68
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
69
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
70
+ PERFORMANCE OF THIS SOFTWARE.
71
+ ***************************************************************************** */
72
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
73
+
74
+
75
+ function __rest(s, e) {
76
+ var t = {};
77
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
78
+ t[p] = s[p];
79
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
80
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
81
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
82
+ t[p[i]] = s[p[i]];
83
+ }
84
+ return t;
85
+ }
86
+
87
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
88
+ var e = new Error(message);
89
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
90
+ };
91
+
92
+ // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
93
+ const drawingState = [
94
+ 'strokeStyle',
95
+ 'fillStyle',
96
+ 'globalAlpha',
97
+ 'lineWidth',
98
+ 'lineCap',
99
+ 'lineJoin',
100
+ 'miterLimit',
101
+ 'lineDashOffset',
102
+ 'shadowOffsetX',
103
+ 'shadowOffsetY',
104
+ 'shadowBlur',
105
+ 'shadowColor',
106
+ 'globalCompositeOperation',
107
+ 'font',
108
+ 'textAlign',
109
+ 'textBaseline',
110
+ 'direction',
111
+ 'imageSmoothingEnabled',
112
+ ];
113
+
114
+ function setDprConfig(canvas, context, width, height, dpr) {
115
+ canvas.width = width * dpr;
116
+ canvas.height = height * dpr;
117
+ context.scale(dpr, dpr);
118
+ canvas.style.width = `${width}px`;
119
+ canvas.style.height = `${height}px`;
120
+ }
121
+ /**
122
+ * A simple animatable canvas with requestAnimationFrame()
123
+ */
124
+ function AnimationCanvas(_a) {
125
+ var { width = 100, height = 100, style, relativeSize = false, reduceFlickering = true, options, init, draw } = _a, props = __rest(_a, ["width", "height", "style", "relativeSize", "reduceFlickering", "options", "init", "draw"]);
126
+ const canvasRef = React.useRef(null);
127
+ const memoCanvasRef = React.useRef(null);
128
+ const reqIdRef = React.useRef();
129
+ const widthRef = React.useRef(0);
130
+ const heightRef = React.useRef(0);
131
+ const loop = (context, width, height, count) => {
132
+ reqIdRef.current = requestAnimationFrame(() => loop(context, width, height, count + 1));
133
+ draw(context, width, height, count + 1);
134
+ };
135
+ React.useEffect(() => {
136
+ if (!canvasRef.current)
137
+ return;
138
+ const canvas = canvasRef.current;
139
+ const context = canvas.getContext('2d', options);
140
+ if (!context)
141
+ throw new Error('Cannot get canvas context.');
142
+ const dpr = window.devicePixelRatio;
143
+ if (relativeSize) {
144
+ const parent = canvas.parentElement;
145
+ if (!parent)
146
+ throw new Error("Canvas doesn't have a parent element.");
147
+ const memoCanvas = memoCanvasRef.current;
148
+ const memoContext = memoCanvas === null || memoCanvas === void 0 ? void 0 : memoCanvas.getContext('2d', options);
149
+ const resizeObserver = new ResizeObserver(() => {
150
+ console.log('resize');
151
+ // Prevents loss of some context when the canvas is resized
152
+ const contextMemo = {};
153
+ for (const prop of drawingState) {
154
+ contextMemo[prop] = context[prop];
155
+ }
156
+ const w = Math.floor(parent.clientWidth);
157
+ const h = Math.floor(parent.clientHeight);
158
+ if (reduceFlickering && memoCanvas && memoContext) {
159
+ memoCanvas.width = w * dpr;
160
+ memoCanvas.height = h * dpr;
161
+ memoContext.scale(1 / dpr, 1 / dpr);
162
+ memoContext.drawImage(context.canvas, 0, 0);
163
+ }
164
+ setDprConfig(canvas, context, w, h, dpr);
165
+ widthRef.current = w;
166
+ heightRef.current = h;
167
+ for (const prop of drawingState) {
168
+ context[prop] = contextMemo[prop];
169
+ }
170
+ if (reduceFlickering && memoContext) {
171
+ context.drawImage(memoContext.canvas, 0, 0);
172
+ }
173
+ });
174
+ resizeObserver.observe(parent);
175
+ const w = Math.floor(parent.clientWidth);
176
+ const h = Math.floor(parent.clientHeight);
177
+ setDprConfig(canvas, context, w, h, dpr);
178
+ if (init)
179
+ init(context, widthRef, heightRef, 0);
180
+ loop(context, widthRef, heightRef, 0);
181
+ return () => {
182
+ if (reqIdRef.current)
183
+ cancelAnimationFrame(reqIdRef.current);
184
+ resizeObserver.unobserve(parent);
185
+ };
186
+ }
187
+ else {
188
+ const rect = canvas.getBoundingClientRect();
189
+ setDprConfig(canvas, context, rect.width, rect.height, dpr);
190
+ widthRef.current = rect.width;
191
+ heightRef.current = rect.height;
192
+ if (init)
193
+ init(context, widthRef, heightRef, 0);
194
+ loop(context, widthRef, heightRef, 0);
195
+ return () => {
196
+ if (reqIdRef.current)
197
+ cancelAnimationFrame(reqIdRef.current);
198
+ };
199
+ }
200
+ }, [loop]);
201
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("canvas", Object.assign({ width: relativeSize ? 0 : width, height: relativeSize ? 0 : height, css: react.css(style), ref: canvasRef }, props)), relativeSize && reduceFlickering && (jsxRuntime.jsx("canvas", { style: { display: 'none' }, width: relativeSize ? 0 : width, height: relativeSize ? 0 : height, ref: memoCanvasRef }))] }));
202
+ }
45
203
 
46
204
  /**
47
205
  * This hook is user-land implementation of the experimental `useEffectEvent` hook.
48
206
  * React docs: https://react.dev/learn/separating-events-from-effects#declaring-an-effect-event
49
207
  */
50
208
  function useCallbackRef(callback, deps = []) {
51
- const callbackRef = react.useRef(() => {
209
+ const callbackRef = React.useRef(() => {
52
210
  throw new Error('Cannot call an event handler while rendering.');
53
211
  });
54
- react.useInsertionEffect(() => {
212
+ React.useInsertionEffect(() => {
55
213
  callbackRef.current = callback;
56
214
  });
57
- return react.useCallback((...args) => { var _a; return (_a = callbackRef.current) === null || _a === void 0 ? void 0 : _a.call(callbackRef, ...args); }, deps);
215
+ return React.useCallback((...args) => { var _a; return (_a = callbackRef.current) === null || _a === void 0 ? void 0 : _a.call(callbackRef, ...args); }, deps);
58
216
  }
59
217
 
60
218
  function useEventListener(target, event, handler, options) {
61
219
  const listener = useCallbackRef(handler);
62
- react.useEffect(() => {
220
+ React.useEffect(() => {
63
221
  const node = typeof target === 'function' ? target() : (target !== null && target !== void 0 ? target : document);
64
222
  if (!handler || !node)
65
223
  return;
@@ -74,27 +232,62 @@ function useEventListener(target, event, handler, options) {
74
232
  };
75
233
  }
76
234
 
77
- function styleHelper(property) {
78
- if (typeof property == 'number') {
79
- return `${property}px`;
80
- }
81
- else {
82
- return property;
83
- }
235
+ function useRefCallbackEvent(event, handler, options, deps = []) {
236
+ return React.useMemo(() => {
237
+ let cleanup;
238
+ return (node) => {
239
+ if (!node) {
240
+ cleanup === null || cleanup === void 0 ? void 0 : cleanup();
241
+ return;
242
+ }
243
+ node.addEventListener(event, handler, options);
244
+ cleanup = () => {
245
+ node.removeEventListener(event, handler, options);
246
+ };
247
+ };
248
+ }, deps);
84
249
  }
85
250
 
86
- function Knob({ value, min, max, step = 1, skew = 1, size = 50, active = '#7998ec', inactive = '#eee', bg = '#ccc', thumb = '#4e76e6', lineWeight = 12, thumbWeight = 4, cursor = 'pointer', style, bodyNoSelect = true, enableWheel, onChange, }) {
251
+ const defaultOptions = {
252
+ active: '#7998ec',
253
+ inactive: '#eee',
254
+ bg: '#ccc',
255
+ thumb: '#4e76e6',
256
+ lineWeight: 6,
257
+ thumbWeight: 4,
258
+ };
259
+ /**
260
+ * simple rotary Knob.
261
+ */
262
+ function Knob(_a) {
263
+ var { value, min, max, defaultValue = min, startValue = min, step = 1, skew = 1, size, width = 50, height = 50, options = defaultOptions,
264
+ // draw,
265
+ cursor = 'pointer', style, bodyNoSelect = true, enableWheel, enableDoubleClickDefault = true, onChange, _active, _focus, _hover } = _a, props = __rest(_a, ["value", "min", "max", "defaultValue", "startValue", "step", "skew", "size", "width", "height", "options", "cursor", "style", "bodyNoSelect", "enableWheel", "enableDoubleClickDefault", "onChange", "_active", "_focus", "_hover"]);
87
266
  // -- state and ref ---
88
267
  // const [privateValue, setPrivateValue] = useState(value);
89
- const dragOffsetY = react.useRef(undefined);
268
+ const dragOffsetY = React.useRef(undefined);
90
269
  // --- interpret props ---
91
- const percent = normalizeValue(value, min, max, skew);
92
- const handleValue = (event) => {
270
+ const opts = Object.assign(Object.assign({}, defaultOptions), options);
271
+ // const percent = normalizeValue(value, min, max, skew)
272
+ const isRelativeSize = typeof (size !== null && size !== void 0 ? size : width) == 'string';
273
+ const adaptSize = (size) => {
274
+ if (typeof size == 'string') {
275
+ return Number(size.slice(0, -1));
276
+ }
277
+ else {
278
+ return size;
279
+ }
280
+ };
281
+ const handleEvent = (event) => {
282
+ const isTouch = event instanceof TouchEvent;
283
+ if (isTouch && event.cancelable)
284
+ event.preventDefault();
93
285
  if (dragOffsetY.current) {
94
286
  if (bodyNoSelect)
95
287
  document.body.classList.add('no-select');
96
- const delta = dragOffsetY.current - event.screenY;
97
- dragOffsetY.current = event.screenY;
288
+ const screenY = isTouch ? event.touches[0].screenY : event.screenY;
289
+ const delta = dragOffsetY.current - screenY;
290
+ dragOffsetY.current = screenY;
98
291
  const n = normalizeValue(value, min, max, skew);
99
292
  const v = rawValue(n + delta / 100, min, max, skew);
100
293
  const v2 = clamp(stepValue(v, step), min, max);
@@ -103,93 +296,182 @@ function Knob({ value, min, max, step = 1, skew = 1, size = 50, active = '#7998e
103
296
  }
104
297
  };
105
298
  // --- hooks ---
106
- const wrapperRef = react.useMemo(() => {
107
- let cleanup;
108
- return (div) => {
109
- if (!div) {
110
- cleanup === null || cleanup === void 0 ? void 0 : cleanup();
111
- return;
112
- }
113
- const controller = new AbortController();
114
- div.addEventListener('wheel', (event) => {
115
- if (!enableWheel)
116
- return;
117
- event.preventDefault();
118
- const x = event.deltaY > 0 ? -enableWheel[1] : enableWheel[1];
119
- let v;
120
- if (enableWheel[0] == 'normalized') {
121
- const n = normalizeValue(value, min, max, skew);
122
- v = rawValue(n + x, min, max, skew);
123
- }
124
- else {
125
- v = value + x;
126
- }
127
- if (onChange)
128
- onChange(clamp(stepValue(v, step), min, max));
129
- }, {
130
- signal: controller.signal,
131
- passive: false,
132
- });
133
- cleanup = () => {
134
- // console.log("cleanup")
135
- controller.abort();
136
- };
137
- };
138
- }, [value]);
139
- useEventListener(window, 'mousemove', (event) => {
140
- handleValue(event);
141
- });
142
- useEventListener(window, 'mouseup', () => {
299
+ const wheelRefCallback = useRefCallbackEvent('wheel', (event) => {
300
+ if (!enableWheel)
301
+ return;
302
+ event.preventDefault();
303
+ const x = event.deltaY > 0 ? -enableWheel[1] : enableWheel[1];
304
+ let v;
305
+ if (enableWheel[0] == 'normalized') {
306
+ const n = normalizeValue(value, min, max, skew);
307
+ v = rawValue(n + x, min, max, skew);
308
+ }
309
+ else {
310
+ v = value + x;
311
+ }
312
+ if (onChange)
313
+ onChange(clamp(stepValue(v, step), min, max));
314
+ }, { passive: false }, [enableWheel, value, min, max, skew, step, onChange]);
315
+ const touchMoveRefCallback = useRefCallbackEvent('touchmove', handleEvent, { passive: false }, [value, min, max, skew, step, onChange, bodyNoSelect]);
316
+ useEventListener(window, 'mousemove', handleEvent);
317
+ useEventListener(window, 'pointerup', () => {
143
318
  dragOffsetY.current = undefined;
144
319
  if (bodyNoSelect)
145
320
  document.body.classList.remove('no-select');
146
321
  });
147
- return (jsxRuntime.jsx("div", { className: "tremolo-knob", ref: wrapperRef, onMouseDown: (event) => {
322
+ return (jsxRuntime.jsxs("div", Object.assign({ className: "tremolo-knob", ref: (div) => {
323
+ wheelRefCallback(div);
324
+ touchMoveRefCallback(div);
325
+ }, role: "slider", tabIndex: 0, "aria-valuenow": value, "aria-valuemax": max, "aria-valuemin": min, css: react.css(Object.assign(Object.assign({ display: 'inline-block', width: size !== null && size !== void 0 ? size : width, height: size !== null && size !== void 0 ? size : height, cursor: cursor }, style), { ':active': Object.assign({}, _active), ':focus': Object.assign({}, _focus), ':hover': Object.assign({}, _hover) })), onPointerDown: (event) => {
148
326
  dragOffsetY.current = event.screenY;
149
- handleValue(event);
150
- }, style: Object.assign({ display: 'inline-block', width: size, height: size }, style), children: jsxRuntime.jsx("div", { css: react$1.css({
151
- display: 'inline-block',
152
- width: size,
153
- height: size,
154
- background: `conic-gradient(${active} ${percent * 270}deg, ${inactive} ${percent * 270}deg, ${inactive} ${270}deg, ${bg} 90deg)`,
155
- borderRadius: '50%',
156
- position: 'relative',
157
- cursor: cursor,
158
- rotate: '-135deg',
159
- '&::before': {
160
- display: 'block',
161
- position: 'absolute',
162
- right: 0,
163
- left: 0,
164
- top: 0,
165
- bottom: 0,
166
- margin: 'auto',
167
- content: '""',
168
- width: `calc(${styleHelper(size)} - ${styleHelper(lineWeight)})`,
169
- height: `calc(${styleHelper(size)} - ${styleHelper(lineWeight)})`,
170
- backgroundColor: bg,
171
- borderRadius: '50%',
172
- },
173
- '&::after': {
174
- display: 'block',
175
- position: 'absolute',
176
- top: 0,
177
- bottom: 0,
178
- // left: lineWeight,
179
- margin: 'auto 0',
180
- content: '""',
181
- width: `calc(0.5 * ${styleHelper(size)})`,
182
- height: thumbWeight,
183
- borderRadius: thumbWeight,
184
- backgroundColor: thumb,
185
- rotate: `${90 + percent * 270}deg`,
186
- transformOrigin: '100% 50%',
187
- },
188
- }), children: jsxRuntime.jsx(react$1.Global, { styles: {
327
+ handleEvent(event);
328
+ }, onDoubleClick: () => {
329
+ if (enableDoubleClickDefault && onChange) {
330
+ onChange(defaultValue);
331
+ }
332
+ } }, props, { children: [jsxRuntime.jsx(react.Global, { styles: {
189
333
  '.no-select': {
190
334
  userSelect: 'none',
191
335
  },
192
- } }) }) }));
336
+ } }), jsxRuntime.jsx(AnimationCanvas, { width: adaptSize(size !== null && size !== void 0 ? size : width), height: adaptSize(size !== null && size !== void 0 ? size : height), relativeSize: isRelativeSize,
337
+ // TODO
338
+ // reduceFlickering={false}
339
+ draw: (ctx, _w, _h) => {
340
+ const p = normalizeValue(value, min, max, skew);
341
+ const startP = normalizeValue(startValue, min, max, skew);
342
+ const w = _w.current, cx = w / 2;
343
+ const h = _h.current, cy = h / 2;
344
+ const r = Math.min(cx, cy);
345
+ if (r <= 0)
346
+ return;
347
+ // reset
348
+ ctx.clearRect(0, 0, w, h);
349
+ ctx.lineCap = 'butt';
350
+ // bg
351
+ ctx.beginPath();
352
+ ctx.fillStyle = opts.bg;
353
+ ctx.arc(cx, cy, r - 0.5, 0, 2 * Math.PI);
354
+ ctx.fill();
355
+ ctx.lineCap = 'round';
356
+ ctx.lineWidth = opts.lineWeight;
357
+ // inactive rotary
358
+ ctx.beginPath();
359
+ ctx.strokeStyle = opts.inactive;
360
+ ctx.arc(cx, cy, r - 0.5 - opts.lineWeight / 2, radian(135), radian(45));
361
+ ctx.stroke();
362
+ // active rotary
363
+ ctx.beginPath();
364
+ ctx.strokeStyle = opts.active;
365
+ ctx.arc(cx, cy, r - 0.5 - opts.lineWeight / 2, radian(135 + 270 * startP), radian(135 + 270 * p), p < startP);
366
+ ctx.stroke();
367
+ // thumb
368
+ ctx.beginPath();
369
+ ctx.moveTo(cx, cy);
370
+ ctx.lineTo(cx +
371
+ Math.cos(radian(135 + 270 * p)) *
372
+ (r - 0.5 - opts.thumbWeight / 2), cy +
373
+ Math.sin(radian(135 + 270 * p)) *
374
+ (r - 0.5 - opts.thumbWeight / 2));
375
+ ctx.strokeStyle = opts.thumb;
376
+ ctx.lineWidth = opts.thumbWeight;
377
+ ctx.stroke();
378
+ } })] })));
379
+ }
380
+
381
+ function selectUnit(units, value) {
382
+ if (typeof units == 'string')
383
+ return [units, 1];
384
+ let i = 0;
385
+ for (; i < units.length; i++) {
386
+ if (Math.abs(units[i][1]) > Math.abs(value))
387
+ break;
388
+ }
389
+ return units[Math.max(0, i - 1)];
390
+ }
391
+ function parseValue(inputString, units, digit) {
392
+ if (!units) {
393
+ return {
394
+ rawValue: Number(inputString.trim()) || 0,
395
+ formatValue: inputString.trim(),
396
+ unit: '',
397
+ };
398
+ }
399
+ else if (typeof units == 'string') {
400
+ return {
401
+ rawValue: Number(inputString.trim()) || 0,
402
+ formatValue: `${inputString.trim()}${units}`,
403
+ unit: units,
404
+ };
405
+ }
406
+ const unitList = units.map(([u, _s]) => u);
407
+ const scaleList = units.map(([_u, s]) => s);
408
+ let rawValue = 0;
409
+ let formatValue = `${scaleList[0]}`;
410
+ let unit = unitList[0];
411
+ const m = inputString.trim().match(/^(-?\d+(\.\d+)?)\s*(\w*)$/);
412
+ if (m) {
413
+ rawValue = Number(m[1]) || 0;
414
+ const inputUnit = m[3];
415
+ if (inputUnit != '' && unitList.indexOf(inputUnit) != -1) {
416
+ rawValue *= scaleList[unitList.indexOf(inputUnit)];
417
+ const s = selectUnit(units, rawValue);
418
+ const v = rawValue / s[1];
419
+ formatValue = `${digit != undefined ? toFixed(v, digit) : v}${s[0]}`;
420
+ unit = s[0];
421
+ }
422
+ else {
423
+ const [u, scale] = selectUnit(units, rawValue);
424
+ const v = rawValue / scale;
425
+ formatValue = `${digit != undefined ? toFixed(v, digit) : v}${u}`;
426
+ unit = u;
427
+ }
428
+ }
429
+ return {
430
+ rawValue: rawValue,
431
+ formatValue: formatValue,
432
+ unit: unit,
433
+ };
434
+ }
435
+
436
+ /**
437
+ * Input with some useful functions for entering numerical values.
438
+ */
439
+ function NumberInput(_a) {
440
+ var { value, min, // TODO
441
+ max, // TODO
442
+ step, // TODO
443
+ units, disabled = false, placeholder, readOnly, tabIndex, strict = false, digit, selectWithFocus = 'none', blurWithEnter = true, className, style, onChange, onFocus, onBlur } = _a, pseudo = __rest(_a, ["value", "min", "max", "step", "units", "disabled", "placeholder", "readOnly", "tabIndex", "strict", "digit", "selectWithFocus", "blurWithEnter", "className", "style", "onChange", "onFocus", "onBlur"]);
444
+ const [showValue, setShowValue] = React.useState(parseValue(String(value), units, digit).formatValue);
445
+ const calculatedStrict = units ? false : strict;
446
+ const { _active, _focus, _hover } = pseudo;
447
+ return (jsxRuntime.jsx("input", { className: 'tremolo-slider' + (className ? ` ${className}` : ''), value: showValue, type: calculatedStrict ? 'number' : 'text', spellCheck: 'false', disabled: disabled, placeholder: placeholder, readOnly: readOnly, tabIndex: tabIndex, css: react.css(Object.assign(Object.assign({ display: 'inline-block', height: '2rem', font: 'inherit', margin: 0, paddingLeft: 10, paddingRight: 10, outlineColor: 'transparent', outlineStyle: 'solid', outlineWidth: 1, background: 'inherit', appearance: 'none', borderStyle: 'solid', borderWidth: 1, borderColor: '#bbb', borderRadius: 4, '&:hover': Object.assign({ outlineColor: '#bbb' }, _hover), '&:focus': Object.assign({ outlineColor: '#4e76e6', outlineWidth: 2 }, _focus) }, (_active && { '&:active': Object.assign({}, _active) })), style)), onChange: (event) => {
448
+ const v = event.currentTarget.value;
449
+ setShowValue(v);
450
+ if (onChange)
451
+ onChange(parseValue(v, units, digit).rawValue, event);
452
+ }, onFocus: (event) => {
453
+ const v = event.currentTarget.value;
454
+ const parsed = parseValue(v, units, digit);
455
+ if (selectWithFocus == 'all') {
456
+ event.currentTarget.setSelectionRange(0, v.length);
457
+ }
458
+ else if (selectWithFocus == 'number') {
459
+ event.currentTarget.setSelectionRange(0, parsed.formatValue.length - parsed.unit.length);
460
+ }
461
+ if (onFocus)
462
+ onFocus(parsed.rawValue, event);
463
+ }, onBlur: (event) => {
464
+ // update value
465
+ const v = event.currentTarget.value;
466
+ const parsed = parseValue(v, units, digit);
467
+ setShowValue(parsed.formatValue);
468
+ if (onBlur)
469
+ onBlur(parsed.rawValue, event);
470
+ }, onKeyDown: (event) => {
471
+ if (blurWithEnter && event.key == 'Enter') {
472
+ event.currentTarget.blur();
473
+ }
474
+ } }));
193
475
  }
194
476
 
195
477
  function isHorizontal(d) {
@@ -227,85 +509,121 @@ function parseScaleOrderList(scale, min, max, step) {
227
509
  return scalesList;
228
510
  }
229
511
 
230
- // interface SliderThumbProps {}
231
- function SliderThumb( /* {}: SliderThumbProps */) {
232
- return jsxRuntime.jsx("div", {});
512
+ function styleHelper(value, op, influencer) {
513
+ if (op && influencer) {
514
+ if (typeof value == 'number') {
515
+ if (op == '+')
516
+ return `${value + influencer}px`;
517
+ if (op == '-')
518
+ return `${value - influencer}px`;
519
+ if (op == '*')
520
+ return `${value * influencer}px`;
521
+ if (op == '/')
522
+ return `${value / influencer}px`;
523
+ }
524
+ else {
525
+ return `calc(${value}px ${op} ${influencer})`;
526
+ }
527
+ }
528
+ else {
529
+ if (typeof value == 'number') {
530
+ return `${value}px`;
531
+ }
532
+ else {
533
+ return value;
534
+ }
535
+ }
233
536
  }
234
- function Slider({ value, min, max, step = 1, length = 140, thickness = 10, direction = 'right', skew = 1, scale, scaleOption, color = '#4e76e6', bg = '#eee', cursor = 'pointer', style, bodyNoSelect = true, enableWheel, onChange, children, }) {
235
- var _a, _b;
537
+
538
+ function SliderThumb({ color, children, style, __css, }) {
539
+ return (jsxRuntime.jsx("div", { className: "tremolo-slider-thumb-wrapper", css: react.css(Object.assign({ width: 'fit-content', height: 'fit-content', position: 'absolute', translate: '-50% -50%', zIndex: 100 }, __css)), children: children ? (children) : (
540
+ // default slider thumb
541
+ jsxRuntime.jsx("div", { className: "tremolo-slider-thumb",
542
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
543
+ tabIndex: 0, css: react.css(Object.assign({ background: color, width: '1.4rem', height: '1.4rem', borderRadius: '50%' }, style)) })) }));
544
+ }
545
+
546
+ function SliderTrack({ children, style, __css, }) {
547
+ return (jsxRuntime.jsx("div", { className: "tremolo-slider-track", css: react.css(Object.assign(Object.assign({}, __css), style)), children: children }));
548
+ }
549
+
550
+ /**
551
+ * Customizable slider
552
+ */
553
+ function Slider(_a) {
554
+ var _b, _c;
555
+ var { value, min, max, step = 1, skew = 1, length = 140, thickness = 10, direction = 'right', scale, scaleOption, color = '#4e76e6', bg = '#eee', className, style, bodyNoSelect = true, enableWheel, onChange, children } = _a; __rest(_a, ["value", "min", "max", "step", "skew", "length", "thickness", "direction", "scale", "scaleOption", "color", "bg", "className", "style", "bodyNoSelect", "enableWheel", "onChange", "children"]);
236
556
  // -- state and ref ---
237
- const baseWrapperElement = react.useRef(null);
238
- // --- interpret props ---
557
+ const trackElementRef = React.useRef(null);
239
558
  const percent = normalizeValue(value, min, max, skew) * 100;
240
559
  const percentRev = isReversed(direction) ? 100 - percent : percent;
241
560
  const scalesList = parseScaleOrderList(scale, min, max, step);
242
561
  if (isReversed(direction))
243
562
  scalesList.reverse();
244
- // let defaultThumb = true
563
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
564
+ let trackProps;
565
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
566
+ let thumbProps;
245
567
  if (children != undefined) {
246
- const childElements = react.Children.toArray(children);
247
- const lastElement = childElements[childElements.length - 1];
248
- if (react.isValidElement(lastElement)) {
249
- // defaultThumb = false
250
- if (lastElement.type == SliderThumb) ;
251
- }
252
- else {
253
- throw new Error('children is an invalid element.');
254
- }
568
+ React.Children.forEach(children, (child) => {
569
+ if (React.isValidElement(child)) {
570
+ if (child.type == SliderThumb) {
571
+ thumbProps = child.props;
572
+ }
573
+ else if (child.type == SliderTrack) {
574
+ trackProps = child.props;
575
+ }
576
+ else {
577
+ throw new Error('only <SliderThumb> or <SliderTrack>');
578
+ }
579
+ }
580
+ else {
581
+ throw new Error('children is an invalid element.');
582
+ }
583
+ });
255
584
  }
256
- const thumbDragged = react.useRef(false);
585
+ const thumbDragged = React.useRef(false);
257
586
  const handleValue = (event) => {
258
- if (baseWrapperElement.current && thumbDragged.current) {
259
- if (bodyNoSelect)
260
- document.body.classList.add('no-select');
261
- const { left: x1, top: y1, right: x2, bottom: y2, } = baseWrapperElement.current.getBoundingClientRect();
262
- const mouseX = event.clientX;
263
- const mouseY = event.clientY;
264
- const n = isHorizontal(direction)
265
- ? normalizeValue(mouseX, x1, x2)
266
- : normalizeValue(mouseY, y1, y2);
267
- const v = rawValue(isReversed(direction) ? 1 - n : n, min, max, skew);
268
- const v2 = clamp(stepValue(v, step), min, max);
269
- if (onChange)
270
- onChange(v2);
271
- }
587
+ if (!trackElementRef.current || !thumbDragged.current)
588
+ return;
589
+ const isTouch = event instanceof TouchEvent;
590
+ if (isTouch && event.cancelable)
591
+ event.preventDefault();
592
+ if (bodyNoSelect)
593
+ document.body.classList.add('no-select');
594
+ const { left: x1, top: y1, right: x2, bottom: y2, } = trackElementRef.current.getBoundingClientRect();
595
+ const mouseX = isTouch ? event.touches[0].clientX : event.clientX;
596
+ const mouseY = isTouch ? event.touches[0].clientY : event.clientY;
597
+ const n = isHorizontal(direction)
598
+ ? normalizeValue(mouseX, x1, x2)
599
+ : normalizeValue(mouseY, y1, y2);
600
+ const v = rawValue(isReversed(direction) ? 1 - n : n, min, max, skew);
601
+ const v2 = clamp(stepValue(v, step), min, max);
602
+ if (onChange)
603
+ onChange(v2);
272
604
  };
273
605
  // --- hooks ---
274
- const wrapperRef = react.useMemo(() => {
275
- let cleanup;
276
- return (div) => {
277
- if (!div) {
278
- cleanup === null || cleanup === void 0 ? void 0 : cleanup();
279
- return;
280
- }
281
- const controller = new AbortController();
282
- div.addEventListener('wheel', (event) => {
283
- if (!enableWheel)
284
- return;
285
- event.preventDefault();
286
- let x = event.deltaY > 0 ? enableWheel[1] : -enableWheel[1];
287
- if (isReversed(direction))
288
- x *= -1;
289
- let v;
290
- if (enableWheel[0] == 'normalized') {
291
- const n = normalizeValue(value, min, max, skew);
292
- v = rawValue(n + x, min, max, skew);
293
- }
294
- else {
295
- v = value + x;
296
- }
297
- if (onChange)
298
- onChange(clamp(stepValue(v, step), min, max));
299
- }, {
300
- signal: controller.signal,
301
- passive: false,
302
- });
303
- cleanup = () => {
304
- // console.log("cleanup")
305
- controller.abort();
306
- };
307
- };
308
- }, [value]);
606
+ const touchMoveRefCallback = useRefCallbackEvent('touchmove', handleValue, { passive: false }, [min, max, skew, step, direction, onChange]);
607
+ const wheelRefCallback = useRefCallbackEvent('wheel', (event) => {
608
+ if (!enableWheel)
609
+ return;
610
+ event.preventDefault();
611
+ let x = event.deltaY > 0 ? enableWheel[1] : -enableWheel[1];
612
+ if (isReversed(direction) || isHorizontal(direction))
613
+ x *= -1;
614
+ let v;
615
+ if (enableWheel[0] == 'normalized') {
616
+ const n = normalizeValue(value, min, max, skew);
617
+ v = rawValue(n + x, min, max, skew);
618
+ }
619
+ else {
620
+ v = value + x;
621
+ }
622
+ if (onChange)
623
+ onChange(clamp(stepValue(v, step), min, max));
624
+ }, {
625
+ passive: false,
626
+ }, [enableWheel, value, min, max, skew, step]);
309
627
  useEventListener(window, 'mousemove', (event) => {
310
628
  handleValue(event);
311
629
  });
@@ -314,44 +632,38 @@ function Slider({ value, min, max, step = 1, length = 140, thickness = 10, direc
314
632
  if (bodyNoSelect)
315
633
  document.body.classList.remove('no-select');
316
634
  });
317
- return (jsxRuntime.jsxs("div", { ref: wrapperRef, className: "tremolo-slider", style: {
318
- display: 'inline-block',
319
- boxSizing: 'border-box',
320
- margin: '0.7rem',
321
- padding: 0,
322
- cursor: cursor,
323
- }, onMouseDown: (event) => {
635
+ return (jsxRuntime.jsxs("div", { className: 'tremolo-slider' + (className ? ` ${className}` : ''), ref: (div) => {
636
+ wheelRefCallback(div);
637
+ touchMoveRefCallback(div);
638
+ }, tabIndex: -1, role: "slider", "aria-valuenow": value, "aria-valuemax": max, "aria-valuemin": min, "aria-orientation": isHorizontal(direction) ? 'horizontal' : 'vertical', css: react.css(Object.assign({ display: 'inline-block', boxSizing: 'border-box', margin: '0.7rem', padding: 0, cursor: 'pointer' }, style)), onPointerDown: (event) => {
324
639
  thumbDragged.current = true;
325
640
  handleValue(event);
326
- }, children: [jsxRuntime.jsx(react$1.Global, { styles: {
641
+ }, children: [jsxRuntime.jsx(react.Global, { styles: {
327
642
  '.no-select': {
328
643
  userSelect: 'none',
329
644
  },
330
- } }), jsxRuntime.jsxs("div", { style: {
645
+ } }), jsxRuntime.jsxs("div", { css: react.css({
331
646
  display: 'flex',
332
647
  flexDirection: isHorizontal(direction) ? 'column' : 'row',
333
- }, children: [jsxRuntime.jsx("div", { ref: baseWrapperElement, css: react$1.css(Object.assign({ background: `linear-gradient(to ${gradientDirection(direction)}, ${color} ${percent}%, ${bg} ${percent}%)`, borderRadius: typeof thickness == 'number'
334
- ? thickness / 2
335
- : `calc(${thickness} / 2)`, borderStyle: 'solid', borderColor: '#ccc', borderWidth: 2, width: isHorizontal(direction) ? length : thickness, height: isHorizontal(direction) ? thickness : length, position: 'relative', zIndex: 1 }, style)), children: jsxRuntime.jsx("div", { className: "tremolo-slider-thumb-wrapper", style: {
336
- width: 'fix-content',
337
- height: 'fix-content',
338
- position: 'absolute',
339
- top: isHorizontal(direction) ? '50%' : `${percentRev}%`,
340
- left: isHorizontal(direction) ? `${percentRev}%` : '50%',
341
- translate: '-50% -50%',
342
- zIndex: 100,
343
- }, children: children ? (children) : (jsxRuntime.jsx("div", { className: "tremolo-slider-thumb", style: {
344
- background: color,
345
- width: '1.4rem',
346
- height: '1.4rem',
347
- borderRadius: '50%',
348
- } })) }) }), scale && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-wrapper", style: Object.assign({ position: 'relative', width: isHorizontal(direction) ? length : undefined, height: isVertical(direction) ? length : undefined, marginLeft: isHorizontal(direction)
648
+ }), children: [jsxRuntime.jsxs("div", { className: "tremolo-slider-track-wrapper", ref: trackElementRef, css: react.css({ position: 'relative' }), children: [jsxRuntime.jsx(SliderTrack, Object.assign({ __css: {
649
+ background: `linear-gradient(to ${gradientDirection(direction)}, ${color} ${percent}%, ${bg} ${percent}%)`,
650
+ borderRadius: styleHelper(thickness, '/', 2),
651
+ borderStyle: 'solid',
652
+ borderColor: '#ccc',
653
+ borderWidth: 2,
654
+ width: isHorizontal(direction) ? length : thickness,
655
+ height: isHorizontal(direction) ? thickness : length,
656
+ zIndex: 1,
657
+ } }, trackProps)), jsxRuntime.jsx(SliderThumb, Object.assign({ color: color, __css: {
658
+ top: isHorizontal(direction) ? '50%' : `${percentRev}%`,
659
+ left: isHorizontal(direction) ? `${percentRev}%` : '50%',
660
+ } }, thumbProps))] }), scale && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-wrapper", css: react.css(Object.assign({ position: 'relative', width: isHorizontal(direction) ? length : undefined, height: isVertical(direction) ? length : undefined, marginLeft: isHorizontal(direction)
349
661
  ? 2
350
- : ((_a = scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.gap) !== null && _a !== void 0 ? _a : `calc((1.4rem - ${styleHelper(thickness)}) / 2)`), marginTop: isVertical(direction)
662
+ : ((_b = scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.gap) !== null && _b !== void 0 ? _b : `calc((1.4rem - ${styleHelper(thickness)}) / 2)`), marginTop: isVertical(direction)
351
663
  ? 2
352
- : ((_b = scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.gap) !== null && _b !== void 0 ? _b : `calc((1.4rem - ${styleHelper(thickness)}) / 2)`) }, scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.style), children: scalesList.map((item, index) => {
353
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
354
- return (jsxRuntime.jsxs("div", { style: {
664
+ : ((_c = scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.gap) !== null && _c !== void 0 ? _c : `calc((1.4rem - ${styleHelper(thickness)}) / 2)`) }, scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.style)), children: scalesList.map((item, index) => {
665
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
666
+ return (jsxRuntime.jsxs("div", { css: react.css({
355
667
  display: 'flex',
356
668
  flexDirection: isHorizontal(direction) ? 'column' : 'row',
357
669
  justifyContent: 'center',
@@ -369,27 +681,37 @@ function Slider({ value, min, max, step = 1, length = 140, thickness = 10, direc
369
681
  : undefined,
370
682
  translate: isHorizontal(direction) ? '-50% 0' : '0 -50%',
371
683
  zIndex: 10,
372
- }, children: [item.type != 'number' && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-mark", style: {
684
+ }), children: [((_b = (_a = item.type) !== null && _a !== void 0 ? _a : scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.defaultType) !== null && _b !== void 0 ? _b : 'mark-number') !=
685
+ 'number' && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-mark", css: react.css({
373
686
  width: isHorizontal(direction)
374
- ? ((_b = (_a = item.style) === null || _a === void 0 ? void 0 : _a.thickness) !== null && _b !== void 0 ? _b : 1)
375
- : ((_d = (_c = item.style) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : '0.5rem'),
687
+ ? ((_d = (_c = item.style) === null || _c === void 0 ? void 0 : _c.thickness) !== null && _d !== void 0 ? _d : 1)
688
+ : ((_f = (_e = item.style) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : '0.5rem'),
376
689
  height: isVertical(direction)
377
- ? ((_f = (_e = item.style) === null || _e === void 0 ? void 0 : _e.thickness) !== null && _f !== void 0 ? _f : 1)
378
- : ((_h = (_g = item.style) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : '0.5rem'),
379
- backgroundColor: (_l = (_k = (_j = item.style) === null || _j === void 0 ? void 0 : _j.markColor) !== null && _k !== void 0 ? _k : scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.markColor) !== null && _l !== void 0 ? _l : '#222',
690
+ ? ((_h = (_g = item.style) === null || _g === void 0 ? void 0 : _g.thickness) !== null && _h !== void 0 ? _h : 1)
691
+ : ((_k = (_j = item.style) === null || _j === void 0 ? void 0 : _j.length) !== null && _k !== void 0 ? _k : '0.5rem'),
692
+ backgroundColor: (_o = (_m = (_l = item.style) === null || _l === void 0 ? void 0 : _l.markColor) !== null && _m !== void 0 ? _m : scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.markColor) !== null && _o !== void 0 ? _o : '#222',
380
693
  marginBottom: isHorizontal(direction) ? 2 : undefined,
381
694
  marginRight: isVertical(direction) ? 2 : undefined,
382
- } })), item.type != 'mark' && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-number", style: {
383
- color: (_o = (_m = item.style) === null || _m === void 0 ? void 0 : _m.labelColor) !== null && _o !== void 0 ? _o : scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.labelColor,
384
- }, children: item.at }))] }, index));
695
+ }) })), ((_q = (_p = item.type) !== null && _p !== void 0 ? _p : scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.defaultType) !== null && _q !== void 0 ? _q : 'mark-number') !=
696
+ 'mark' && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-number", css: react.css({
697
+ color: (_s = (_r = item.style) === null || _r === void 0 ? void 0 : _r.labelColor) !== null && _s !== void 0 ? _s : scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.labelColor,
698
+ width: scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.labelWidth,
699
+ textAlign: 'right',
700
+ }), children: (_t = item.text) !== null && _t !== void 0 ? _t : item.at }))] }, index));
385
701
  }) }))] })] }));
386
702
  }
387
703
 
704
+ exports.AnimationCanvas = AnimationCanvas;
388
705
  exports.Knob = Knob;
706
+ exports.NumberInput = NumberInput;
389
707
  exports.Slider = Slider;
390
708
  exports.clamp = clamp;
709
+ exports.dbToGain = dbToGain;
391
710
  exports.decimalPart = decimalPart;
711
+ exports.degree = degree;
712
+ exports.gainToDb = gainToDb;
392
713
  exports.normalizeValue = normalizeValue;
714
+ exports.radian = radian;
393
715
  exports.rawValue = rawValue;
394
716
  exports.skewWithCenterValue = skewWithCenterValue;
395
717
  exports.stepValue = stepValue;