@tremolo-ui/react 0.0.3 → 0.0.5

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 (130) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/index.js +113 -119
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/types/components/AnimationCanvas/canvas.d.ts.map +1 -0
  5. package/dist/cjs/types/components/AnimationCanvas/index.d.ts +20 -0
  6. package/dist/cjs/types/components/AnimationCanvas/index.d.ts.map +1 -0
  7. package/dist/{esm/types/packages/react/src → cjs/types}/components/Knob/index.d.ts +16 -4
  8. package/dist/cjs/types/components/Knob/index.d.ts.map +1 -0
  9. package/dist/cjs/types/{packages/react/src/components → components}/NumberInput/index.d.ts +3 -5
  10. package/dist/cjs/types/components/NumberInput/index.d.ts.map +1 -0
  11. package/dist/{esm/types/packages/react/src → cjs/types}/components/Slider/Thumb.d.ts +2 -2
  12. package/dist/cjs/types/components/Slider/Thumb.d.ts.map +1 -0
  13. package/dist/cjs/types/{packages/react/src/components → components}/Slider/Track.d.ts +1 -1
  14. package/dist/cjs/types/components/Slider/Track.d.ts.map +1 -0
  15. package/dist/cjs/types/{packages/react/src/components → components}/Slider/index.d.ts +5 -5
  16. package/dist/cjs/types/components/Slider/index.d.ts.map +1 -0
  17. package/dist/cjs/types/components/Slider/type.d.ts +7 -0
  18. package/dist/cjs/types/components/Slider/type.d.ts.map +1 -0
  19. package/dist/cjs/types/hooks/useCallbackRef.d.ts.map +1 -0
  20. package/dist/cjs/types/hooks/useEventListener.d.ts.map +1 -0
  21. package/dist/cjs/types/hooks/useRefCallbackEvent.d.ts.map +1 -0
  22. package/dist/cjs/types/index.d.ts +5 -0
  23. package/dist/cjs/types/index.d.ts.map +1 -0
  24. package/dist/cjs/types/system/pseudo.d.ts.map +1 -0
  25. package/dist/esm/index.js +111 -109
  26. package/dist/esm/index.js.map +1 -1
  27. package/dist/esm/types/components/AnimationCanvas/canvas.d.ts.map +1 -0
  28. package/dist/esm/types/components/AnimationCanvas/index.d.ts +20 -0
  29. package/dist/esm/types/components/AnimationCanvas/index.d.ts.map +1 -0
  30. package/dist/{cjs/types/packages/react/src → esm/types}/components/Knob/index.d.ts +16 -4
  31. package/dist/esm/types/components/Knob/index.d.ts.map +1 -0
  32. package/dist/esm/types/{packages/react/src/components → components}/NumberInput/index.d.ts +3 -5
  33. package/dist/esm/types/components/NumberInput/index.d.ts.map +1 -0
  34. package/dist/{cjs/types/packages/react/src → esm/types}/components/Slider/Thumb.d.ts +2 -2
  35. package/dist/esm/types/components/Slider/Thumb.d.ts.map +1 -0
  36. package/dist/esm/types/{packages/react/src/components → components}/Slider/Track.d.ts +1 -1
  37. package/dist/esm/types/components/Slider/Track.d.ts.map +1 -0
  38. package/dist/esm/types/{packages/react/src/components → components}/Slider/index.d.ts +5 -5
  39. package/dist/esm/types/components/Slider/index.d.ts.map +1 -0
  40. package/dist/esm/types/components/Slider/type.d.ts +7 -0
  41. package/dist/esm/types/components/Slider/type.d.ts.map +1 -0
  42. package/dist/esm/types/hooks/useCallbackRef.d.ts.map +1 -0
  43. package/dist/esm/types/hooks/useEventListener.d.ts.map +1 -0
  44. package/dist/esm/types/hooks/useRefCallbackEvent.d.ts.map +1 -0
  45. package/dist/esm/types/index.d.ts +5 -0
  46. package/dist/esm/types/index.d.ts.map +1 -0
  47. package/dist/esm/types/system/pseudo.d.ts.map +1 -0
  48. package/dist/styles/variables.css +4 -0
  49. package/package.json +22 -11
  50. package/src/Globals.d.ts +2 -0
  51. package/src/components/AnimationCanvas/canvas.ts +30 -0
  52. package/src/components/AnimationCanvas/index.tsx +169 -0
  53. package/src/components/Knob/index.tsx +292 -0
  54. package/src/components/NumberInput/index.tsx +165 -0
  55. package/src/components/Slider/Thumb.tsx +54 -0
  56. package/src/components/Slider/Track.tsx +20 -0
  57. package/src/components/Slider/index.tsx +326 -0
  58. package/src/components/Slider/type.ts +16 -0
  59. package/src/hooks/useCallbackRef.ts +20 -0
  60. package/src/hooks/useEventListener.ts +49 -0
  61. package/src/hooks/useRefCallbackEvent.ts +32 -0
  62. package/src/index.ts +4 -0
  63. package/src/styles/variables.css +4 -0
  64. package/src/system/pseudo.ts +55 -0
  65. package/dist/cjs/index.d.ts +0 -140
  66. package/dist/cjs/packages/react/tsconfig.tsbuildinfo +0 -1
  67. package/dist/cjs/types/packages/functions/components/NumberInput/type.d.ts +0 -14
  68. package/dist/cjs/types/packages/functions/components/NumberInput/type.d.ts.map +0 -1
  69. package/dist/cjs/types/packages/functions/components/Slider/type.d.ts +0 -32
  70. package/dist/cjs/types/packages/functions/components/Slider/type.d.ts.map +0 -1
  71. package/dist/cjs/types/packages/functions/math.d.ts +0 -12
  72. package/dist/cjs/types/packages/functions/math.d.ts.map +0 -1
  73. package/dist/cjs/types/packages/functions/types.d.ts +0 -2
  74. package/dist/cjs/types/packages/functions/types.d.ts.map +0 -1
  75. package/dist/cjs/types/packages/functions/util.d.ts +0 -6
  76. package/dist/cjs/types/packages/functions/util.d.ts.map +0 -1
  77. package/dist/cjs/types/packages/react/src/components/AnimationCanvas/canvas.d.ts.map +0 -1
  78. package/dist/cjs/types/packages/react/src/components/AnimationCanvas/index.d.ts +0 -20
  79. package/dist/cjs/types/packages/react/src/components/AnimationCanvas/index.d.ts.map +0 -1
  80. package/dist/cjs/types/packages/react/src/components/Knob/index.d.ts.map +0 -1
  81. package/dist/cjs/types/packages/react/src/components/NumberInput/index.d.ts.map +0 -1
  82. package/dist/cjs/types/packages/react/src/components/Slider/Thumb.d.ts.map +0 -1
  83. package/dist/cjs/types/packages/react/src/components/Slider/Track.d.ts.map +0 -1
  84. package/dist/cjs/types/packages/react/src/components/Slider/index.d.ts.map +0 -1
  85. package/dist/cjs/types/packages/react/src/components/Slider/type.d.ts +0 -6
  86. package/dist/cjs/types/packages/react/src/components/Slider/type.d.ts.map +0 -1
  87. package/dist/cjs/types/packages/react/src/hooks/useCallbackRef.d.ts.map +0 -1
  88. package/dist/cjs/types/packages/react/src/hooks/useEventListener.d.ts.map +0 -1
  89. package/dist/cjs/types/packages/react/src/hooks/useRefCallbackEvent.d.ts.map +0 -1
  90. package/dist/cjs/types/packages/react/src/index.d.ts +0 -7
  91. package/dist/cjs/types/packages/react/src/index.d.ts.map +0 -1
  92. package/dist/cjs/types/packages/react/src/system/pseudo.d.ts.map +0 -1
  93. package/dist/esm/index.d.ts +0 -140
  94. package/dist/esm/packages/react/tsconfig.tsbuildinfo +0 -1
  95. package/dist/esm/types/packages/functions/components/NumberInput/type.d.ts +0 -14
  96. package/dist/esm/types/packages/functions/components/NumberInput/type.d.ts.map +0 -1
  97. package/dist/esm/types/packages/functions/components/Slider/type.d.ts +0 -32
  98. package/dist/esm/types/packages/functions/components/Slider/type.d.ts.map +0 -1
  99. package/dist/esm/types/packages/functions/math.d.ts +0 -12
  100. package/dist/esm/types/packages/functions/math.d.ts.map +0 -1
  101. package/dist/esm/types/packages/functions/types.d.ts +0 -2
  102. package/dist/esm/types/packages/functions/types.d.ts.map +0 -1
  103. package/dist/esm/types/packages/functions/util.d.ts +0 -6
  104. package/dist/esm/types/packages/functions/util.d.ts.map +0 -1
  105. package/dist/esm/types/packages/react/src/components/AnimationCanvas/canvas.d.ts.map +0 -1
  106. package/dist/esm/types/packages/react/src/components/AnimationCanvas/index.d.ts +0 -20
  107. package/dist/esm/types/packages/react/src/components/AnimationCanvas/index.d.ts.map +0 -1
  108. package/dist/esm/types/packages/react/src/components/Knob/index.d.ts.map +0 -1
  109. package/dist/esm/types/packages/react/src/components/NumberInput/index.d.ts.map +0 -1
  110. package/dist/esm/types/packages/react/src/components/Slider/Thumb.d.ts.map +0 -1
  111. package/dist/esm/types/packages/react/src/components/Slider/Track.d.ts.map +0 -1
  112. package/dist/esm/types/packages/react/src/components/Slider/index.d.ts.map +0 -1
  113. package/dist/esm/types/packages/react/src/components/Slider/type.d.ts +0 -6
  114. package/dist/esm/types/packages/react/src/components/Slider/type.d.ts.map +0 -1
  115. package/dist/esm/types/packages/react/src/hooks/useCallbackRef.d.ts.map +0 -1
  116. package/dist/esm/types/packages/react/src/hooks/useEventListener.d.ts.map +0 -1
  117. package/dist/esm/types/packages/react/src/hooks/useRefCallbackEvent.d.ts.map +0 -1
  118. package/dist/esm/types/packages/react/src/index.d.ts +0 -7
  119. package/dist/esm/types/packages/react/src/index.d.ts.map +0 -1
  120. package/dist/esm/types/packages/react/src/system/pseudo.d.ts.map +0 -1
  121. /package/dist/cjs/types/{packages/react/src/components → components}/AnimationCanvas/canvas.d.ts +0 -0
  122. /package/dist/cjs/types/{packages/react/src/hooks → hooks}/useCallbackRef.d.ts +0 -0
  123. /package/dist/cjs/types/{packages/react/src/hooks → hooks}/useEventListener.d.ts +0 -0
  124. /package/dist/cjs/types/{packages/react/src/hooks → hooks}/useRefCallbackEvent.d.ts +0 -0
  125. /package/dist/cjs/types/{packages/react/src/system → system}/pseudo.d.ts +0 -0
  126. /package/dist/esm/types/{packages/react/src/components → components}/AnimationCanvas/canvas.d.ts +0 -0
  127. /package/dist/esm/types/{packages/react/src/hooks → hooks}/useCallbackRef.d.ts +0 -0
  128. /package/dist/esm/types/{packages/react/src/hooks → hooks}/useEventListener.d.ts +0 -0
  129. /package/dist/esm/types/{packages/react/src/hooks → hooks}/useRefCallbackEvent.d.ts +0 -0
  130. /package/dist/esm/types/{packages/react/src/system → system}/pseudo.d.ts +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 mimoz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/cjs/index.js CHANGED
@@ -4,57 +4,6 @@ var jsxRuntime = require('@emotion/react/jsx-runtime');
4
4
  var react = require('@emotion/react');
5
5
  var React = require('react');
6
6
 
7
- function clamp(value, min, max) {
8
- return Math.max(min, Math.min(value, max));
9
- }
10
- function normalizeValue(rawValue, min, max, skew = 1) {
11
- if (min >= max)
12
- throw new RangeError('requirements: min < max');
13
- const v = clamp((rawValue - min) / (max - min), 0, 1);
14
- return Math.pow(v, skew);
15
- }
16
- function rawValue(normalizedValue, min, max, skew = 1) {
17
- if (min >= max)
18
- throw new RangeError('requirements: min < max');
19
- const v = skew == 1
20
- ? clamp(normalizedValue, 0, 1)
21
- : Math.exp(Math.log(clamp(normalizedValue, 0, 1)) / skew);
22
- return min + v * (max - min);
23
- }
24
- function skewWithCenterValue(centerValue, min, max) {
25
- if (!(min <= centerValue && centerValue <= max))
26
- throw new RangeError('requirements: min <= centerValue <= max');
27
- return Math.log(0.5) / Math.log((centerValue - min) / (max - min));
28
- }
29
- function stepValue(value, step) {
30
- var _a;
31
- if (step <= 0)
32
- throw new RangeError('requirements: step > 0');
33
- const quotient = Math.floor(value / step);
34
- const decimalDigits = (_a = decimalPart(step)) === null || _a === void 0 ? void 0 : _a.length;
35
- const v = toFixed(quotient * step, decimalDigits);
36
- const next = toFixed((quotient + 1) * step, decimalDigits);
37
- return Math.abs(value - v) < Math.abs(value - next) ? v : next;
38
- }
39
- function toFixed(x, fractionDigits) {
40
- return Number(x.toFixed(fractionDigits));
41
- }
42
- function decimalPart(x) {
43
- return String(x).split('.')[1];
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
7
  /******************************************************************************
59
8
  Copyright (c) Microsoft Corporation.
60
9
 
@@ -89,6 +38,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
89
38
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
90
39
  };
91
40
 
41
+ function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
42
+
92
43
  // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
93
44
  const drawingState = [
94
45
  'strokeStyle',
@@ -122,7 +73,7 @@ function setDprConfig(canvas, context, width, height, dpr) {
122
73
  * A simple animatable canvas with requestAnimationFrame()
123
74
  */
124
75
  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"]);
76
+ var { width = 100, height = 100, style, relativeSize = false, reduceFlickering = true, options, init, draw, className } = _a, props = __rest(_a, ["width", "height", "style", "relativeSize", "reduceFlickering", "options", "init", "draw", "className"]);
126
77
  const canvasRef = React.useRef(null);
127
78
  const memoCanvasRef = React.useRef(null);
128
79
  const reqIdRef = React.useRef();
@@ -147,7 +98,7 @@ function AnimationCanvas(_a) {
147
98
  const memoCanvas = memoCanvasRef.current;
148
99
  const memoContext = memoCanvas === null || memoCanvas === void 0 ? void 0 : memoCanvas.getContext('2d', options);
149
100
  const resizeObserver = new ResizeObserver(() => {
150
- console.log('resize');
101
+ // console.log('resize')
151
102
  // Prevents loss of some context when the canvas is resized
152
103
  const contextMemo = {};
153
104
  for (const prop of drawingState) {
@@ -198,7 +149,70 @@ function AnimationCanvas(_a) {
198
149
  };
199
150
  }
200
151
  }, [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 }))] }));
152
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("canvas", Object.assign({ className: clsx('tremolo-animation-canvas', className), 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 }))] }));
153
+ }
154
+
155
+ function clamp(value, min, max) {
156
+ return Math.max(min, Math.min(value, max));
157
+ }
158
+ function normalizeValue(rawValue, min, max, skew = 1) {
159
+ if (min >= max)
160
+ throw new RangeError('requirements: min < max');
161
+ const v = clamp((rawValue - min) / (max - min), 0, 1);
162
+ return Math.pow(v, skew);
163
+ }
164
+ function rawValue(normalizedValue, min, max, skew = 1) {
165
+ if (min >= max)
166
+ throw new RangeError('requirements: min < max');
167
+ const v = skew == 1
168
+ ? clamp(normalizedValue, 0, 1)
169
+ : Math.exp(Math.log(clamp(normalizedValue, 0, 1)) / skew);
170
+ return min + v * (max - min);
171
+ }
172
+ function stepValue(value, step) {
173
+ var _a;
174
+ if (step <= 0)
175
+ throw new RangeError('requirements: step > 0');
176
+ const quotient = Math.floor(value / step);
177
+ const decimalDigits = (_a = decimalPart$1(step)) === null || _a === void 0 ? void 0 : _a.length;
178
+ const v = toFixed$2(quotient * step, decimalDigits);
179
+ const next = toFixed$2((quotient + 1) * step, decimalDigits);
180
+ return Math.abs(value - v) < Math.abs(value - next) ? v : next;
181
+ }
182
+ function toFixed$2(x, fractionDigits) {
183
+ return Number(x.toFixed(fractionDigits));
184
+ }
185
+ function decimalPart$1(x) {
186
+ return String(x).split('.')[1];
187
+ }
188
+ function radian(degree) {
189
+ return (Math.PI * degree) / 180;
190
+ }
191
+
192
+ function styleHelper(value, op, influencer) {
193
+ if (op && influencer) {
194
+ if (typeof value == 'number') {
195
+ if (op == '+')
196
+ return `${value + influencer}px`;
197
+ if (op == '-')
198
+ return `${value - influencer}px`;
199
+ if (op == '*')
200
+ return `${value * influencer}px`;
201
+ if (op == '/')
202
+ return `${value / influencer}px`;
203
+ }
204
+ else {
205
+ return `calc(${value}px ${op} ${influencer})`;
206
+ }
207
+ }
208
+ else {
209
+ if (typeof value == 'number') {
210
+ return `${value}px`;
211
+ }
212
+ else {
213
+ return value;
214
+ }
215
+ }
202
216
  }
203
217
 
204
218
  /**
@@ -260,9 +274,7 @@ const defaultOptions = {
260
274
  * simple rotary Knob.
261
275
  */
262
276
  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"]);
277
+ var { value, min, max, defaultValue = min, startValue = min, step = 1, skew = 1, size, width = 50, height = 50, options = defaultOptions, draw, bodyNoSelect = true, enableWheel, enableDoubleClickDefault = true, style, className, onChange, _active, _focus, _hover } = _a, props = __rest(_a, ["value", "min", "max", "defaultValue", "startValue", "step", "skew", "size", "width", "height", "options", "draw", "bodyNoSelect", "enableWheel", "enableDoubleClickDefault", "style", "className", "onChange", "_active", "_focus", "_hover"]);
266
278
  // -- state and ref ---
267
279
  // const [privateValue, setPrivateValue] = useState(value);
268
280
  const dragOffsetY = React.useRef(undefined);
@@ -319,10 +331,10 @@ function Knob(_a) {
319
331
  if (bodyNoSelect)
320
332
  document.body.classList.remove('no-select');
321
333
  });
322
- return (jsxRuntime.jsxs("div", Object.assign({ className: "tremolo-knob", ref: (div) => {
334
+ return (jsxRuntime.jsxs("div", Object.assign({ className: clsx('tremolo-knob', className), ref: (div) => {
323
335
  wheelRefCallback(div);
324
336
  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) => {
337
+ }, 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: 'pointer' }, style), { ':active': Object.assign({}, _active), ':focus': Object.assign({}, _focus), ':hover': Object.assign({}, _hover) })), onPointerDown: (event) => {
326
338
  dragOffsetY.current = event.screenY;
327
339
  handleEvent(event);
328
340
  }, onDoubleClick: () => {
@@ -336,11 +348,11 @@ function Knob(_a) {
336
348
  } }), jsxRuntime.jsx(AnimationCanvas, { width: adaptSize(size !== null && size !== void 0 ? size : width), height: adaptSize(size !== null && size !== void 0 ? size : height), relativeSize: isRelativeSize,
337
349
  // TODO
338
350
  // reduceFlickering={false}
339
- draw: (ctx, _w, _h) => {
351
+ draw: draw ? draw : (ctx, width, height) => {
340
352
  const p = normalizeValue(value, min, max, skew);
341
353
  const startP = normalizeValue(startValue, min, max, skew);
342
- const w = _w.current, cx = w / 2;
343
- const h = _h.current, cy = h / 2;
354
+ const w = width.current, cx = w / 2;
355
+ const h = height.current, cy = h / 2;
344
356
  const r = Math.min(cx, cy);
345
357
  if (r <= 0)
346
358
  return;
@@ -378,6 +390,10 @@ function Knob(_a) {
378
390
  } })] })));
379
391
  }
380
392
 
393
+ function toFixed$1(x, fractionDigits) {
394
+ return Number(x.toFixed(fractionDigits));
395
+ }
396
+
381
397
  function selectUnit(units, value) {
382
398
  if (typeof units == 'string')
383
399
  return [units, 1];
@@ -388,27 +404,30 @@ function selectUnit(units, value) {
388
404
  }
389
405
  return units[Math.max(0, i - 1)];
390
406
  }
391
- function parseValue(inputString, units, digit) {
407
+ function parseValue(inputString, units, digit, defaultValue = 0) {
408
+ let str = inputString.trim();
409
+ if (str == '')
410
+ str = String(defaultValue);
392
411
  if (!units) {
393
412
  return {
394
- rawValue: Number(inputString.trim()) || 0,
395
- formatValue: inputString.trim(),
413
+ rawValue: Number(str) || defaultValue,
414
+ formatValue: str,
396
415
  unit: '',
397
416
  };
398
417
  }
399
418
  else if (typeof units == 'string') {
400
419
  return {
401
- rawValue: Number(inputString.trim()) || 0,
402
- formatValue: `${inputString.trim()}${units}`,
420
+ rawValue: Number(str) || defaultValue,
421
+ formatValue: `${str}${units}`,
403
422
  unit: units,
404
423
  };
405
424
  }
406
425
  const unitList = units.map(([u, _s]) => u);
407
426
  const scaleList = units.map(([_u, s]) => s);
408
- let rawValue = 0;
427
+ let rawValue = defaultValue;
409
428
  let formatValue = `${scaleList[0]}`;
410
429
  let unit = unitList[0];
411
- const m = inputString.trim().match(/^(-?\d+(\.\d+)?)\s*(\w*)$/);
430
+ const m = str.match(/^(-?\d+(\.\d+)?)\s*(\w*)$/);
412
431
  if (m) {
413
432
  rawValue = Number(m[1]) || 0;
414
433
  const inputUnit = m[3];
@@ -416,13 +435,13 @@ function parseValue(inputString, units, digit) {
416
435
  rawValue *= scaleList[unitList.indexOf(inputUnit)];
417
436
  const s = selectUnit(units, rawValue);
418
437
  const v = rawValue / s[1];
419
- formatValue = `${digit != undefined ? toFixed(v, digit) : v}${s[0]}`;
438
+ formatValue = `${digit != undefined ? toFixed$1(v, digit) : v}${s[0]}`;
420
439
  unit = s[0];
421
440
  }
422
441
  else {
423
442
  const [u, scale] = selectUnit(units, rawValue);
424
443
  const v = rawValue / scale;
425
- formatValue = `${digit != undefined ? toFixed(v, digit) : v}${u}`;
444
+ formatValue = `${digit != undefined ? toFixed$1(v, digit) : v}${u}`;
426
445
  unit = u;
427
446
  }
428
447
  }
@@ -437,21 +456,19 @@ function parseValue(inputString, units, digit) {
437
456
  * Input with some useful functions for entering numerical values.
438
457
  */
439
458
  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);
459
+ var { value, min, max, step, defaultValue = min, 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", "defaultValue", "units", "disabled", "placeholder", "readOnly", "tabIndex", "strict", "digit", "selectWithFocus", "blurWithEnter", "className", "style", "onChange", "onFocus", "onBlur"]);
460
+ const [showValue, setShowValue] = React.useState(parseValue(String(value), units, digit, defaultValue).formatValue);
445
461
  const calculatedStrict = units ? false : strict;
446
462
  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) => {
463
+ return (jsxRuntime.jsx("input", { className: clsx('tremolo-number-input', className), value: showValue, min: min, max: max, step: step, type: calculatedStrict ? 'number' : 'text', spellCheck: 'false', disabled: disabled, placeholder: placeholder, readOnly: readOnly, tabIndex: tabIndex, css: react.css(Object.assign(Object.assign({ display: 'inline-block', font: 'inherit', margin: 0, paddingTop: 6, paddingBottom: 6, paddingLeft: 10, paddingRight: 10, borderStyle: 'solid', borderWidth: 1, borderColor: '#bbb', borderRadius: 4, outline: 0, transition: 'all 0.1s linear', appearance: 'textfield', '&:hover': Object.assign({ borderColor: 'var(--tremolo-theme-color)' }, _hover), '&:focus': Object.assign({ borderColor: 'var(--tremolo-theme-color)', boxShadow: '0px 0px 0px 2px rgba(var(--tremolo-theme-color-rgb), 0.1)' }, _focus) }, (_active && { '&:active': Object.assign({}, _active) })), style)), onChange: (event) => {
448
464
  const v = event.currentTarget.value;
449
465
  setShowValue(v);
466
+ const newValue = clamp(parseValue(v, units, digit, defaultValue).rawValue, min !== null && min !== void 0 ? min : -Infinity, max !== null && max !== void 0 ? max : Infinity);
450
467
  if (onChange)
451
- onChange(parseValue(v, units, digit).rawValue, event);
468
+ onChange(newValue, event);
452
469
  }, onFocus: (event) => {
453
470
  const v = event.currentTarget.value;
454
- const parsed = parseValue(v, units, digit);
471
+ const parsed = parseValue(v, units, digit, defaultValue);
455
472
  if (selectWithFocus == 'all') {
456
473
  event.currentTarget.setSelectionRange(0, v.length);
457
474
  }
@@ -463,7 +480,7 @@ function NumberInput(_a) {
463
480
  }, onBlur: (event) => {
464
481
  // update value
465
482
  const v = event.currentTarget.value;
466
- const parsed = parseValue(v, units, digit);
483
+ const parsed = parseValue(v, units, digit, defaultValue);
467
484
  setShowValue(parsed.formatValue);
468
485
  if (onBlur)
469
486
  onBlur(parsed.rawValue, event);
@@ -474,6 +491,13 @@ function NumberInput(_a) {
474
491
  } }));
475
492
  }
476
493
 
494
+ function toFixed(x, fractionDigits) {
495
+ return Number(x.toFixed(fractionDigits));
496
+ }
497
+ function decimalPart(x) {
498
+ return String(x).split('.')[1];
499
+ }
500
+
477
501
  function isHorizontal(d) {
478
502
  return d == 'right' || d == 'left';
479
503
  }
@@ -509,38 +533,16 @@ function parseScaleOrderList(scale, min, max, step) {
509
533
  return scalesList;
510
534
  }
511
535
 
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
- }
536
- }
537
-
538
536
  function SliderThumb({ color, children, style, __css, }) {
539
537
  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
538
  // default slider thumb
541
539
  jsxRuntime.jsx("div", { className: "tremolo-slider-thumb",
542
540
  // 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)) })) }));
541
+ tabIndex: 0, css: react.css(Object.assign({ background: color, width: '1.4rem', height: '1.4rem', borderRadius: '50%', '&:hover': {
542
+ background: `color-mix(in srgb, ${color} 95%, black)`
543
+ }, '&:active': {
544
+ boxShadow: '0px 0px 0px 3px rgba(var(--tremolo-theme-color-rgb), 0.2)',
545
+ } }, style)) })) }));
544
546
  }
545
547
 
546
548
  function SliderTrack({ children, style, __css, }) {
@@ -632,7 +634,7 @@ function Slider(_a) {
632
634
  if (bodyNoSelect)
633
635
  document.body.classList.remove('no-select');
634
636
  });
635
- return (jsxRuntime.jsxs("div", { className: 'tremolo-slider' + (className ? ` ${className}` : ''), ref: (div) => {
637
+ return (jsxRuntime.jsxs("div", { className: clsx('tremolo-slider', className), ref: (div) => {
636
638
  wheelRefCallback(div);
637
639
  touchMoveRefCallback(div);
638
640
  }, 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) => {
@@ -705,15 +707,7 @@ exports.AnimationCanvas = AnimationCanvas;
705
707
  exports.Knob = Knob;
706
708
  exports.NumberInput = NumberInput;
707
709
  exports.Slider = Slider;
708
- exports.clamp = clamp;
709
- exports.dbToGain = dbToGain;
710
- exports.decimalPart = decimalPart;
711
- exports.degree = degree;
712
- exports.gainToDb = gainToDb;
713
- exports.normalizeValue = normalizeValue;
714
- exports.radian = radian;
715
- exports.rawValue = rawValue;
716
- exports.skewWithCenterValue = skewWithCenterValue;
717
- exports.stepValue = stepValue;
718
- exports.toFixed = toFixed;
710
+ exports.SliderThumb = SliderThumb;
711
+ exports.SliderTrack = SliderTrack;
712
+ exports.gradientDirection = gradientDirection;
719
713
  //# sourceMappingURL=index.js.map