@tremolo-ui/react 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/cjs/index.js +113 -119
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/types/components/AnimationCanvas/canvas.d.ts.map +1 -0
  4. package/dist/cjs/types/components/AnimationCanvas/index.d.ts +20 -0
  5. package/dist/cjs/types/components/AnimationCanvas/index.d.ts.map +1 -0
  6. package/dist/{esm/types/packages/react/src → cjs/types}/components/Knob/index.d.ts +16 -4
  7. package/dist/cjs/types/components/Knob/index.d.ts.map +1 -0
  8. package/dist/cjs/types/{packages/react/src/components → components}/NumberInput/index.d.ts +3 -5
  9. package/dist/cjs/types/components/NumberInput/index.d.ts.map +1 -0
  10. package/dist/{esm/types/packages/react/src → cjs/types}/components/Slider/Thumb.d.ts +2 -2
  11. package/dist/cjs/types/components/Slider/Thumb.d.ts.map +1 -0
  12. package/dist/cjs/types/{packages/react/src/components → components}/Slider/Track.d.ts +1 -1
  13. package/dist/cjs/types/components/Slider/Track.d.ts.map +1 -0
  14. package/dist/cjs/types/{packages/react/src/components → components}/Slider/index.d.ts +5 -5
  15. package/dist/cjs/types/components/Slider/index.d.ts.map +1 -0
  16. package/dist/cjs/types/components/Slider/type.d.ts +7 -0
  17. package/dist/cjs/types/components/Slider/type.d.ts.map +1 -0
  18. package/dist/cjs/types/hooks/useCallbackRef.d.ts.map +1 -0
  19. package/dist/cjs/types/hooks/useEventListener.d.ts.map +1 -0
  20. package/dist/cjs/types/hooks/useRefCallbackEvent.d.ts.map +1 -0
  21. package/dist/cjs/types/index.d.ts +5 -0
  22. package/dist/cjs/types/index.d.ts.map +1 -0
  23. package/dist/cjs/types/system/pseudo.d.ts.map +1 -0
  24. package/dist/esm/index.js +111 -109
  25. package/dist/esm/index.js.map +1 -1
  26. package/dist/esm/types/components/AnimationCanvas/canvas.d.ts.map +1 -0
  27. package/dist/esm/types/components/AnimationCanvas/index.d.ts +20 -0
  28. package/dist/esm/types/components/AnimationCanvas/index.d.ts.map +1 -0
  29. package/dist/{cjs/types/packages/react/src → esm/types}/components/Knob/index.d.ts +16 -4
  30. package/dist/esm/types/components/Knob/index.d.ts.map +1 -0
  31. package/dist/esm/types/{packages/react/src/components → components}/NumberInput/index.d.ts +3 -5
  32. package/dist/esm/types/components/NumberInput/index.d.ts.map +1 -0
  33. package/dist/{cjs/types/packages/react/src → esm/types}/components/Slider/Thumb.d.ts +2 -2
  34. package/dist/esm/types/components/Slider/Thumb.d.ts.map +1 -0
  35. package/dist/esm/types/{packages/react/src/components → components}/Slider/Track.d.ts +1 -1
  36. package/dist/esm/types/components/Slider/Track.d.ts.map +1 -0
  37. package/dist/esm/types/{packages/react/src/components → components}/Slider/index.d.ts +5 -5
  38. package/dist/esm/types/components/Slider/index.d.ts.map +1 -0
  39. package/dist/esm/types/components/Slider/type.d.ts +7 -0
  40. package/dist/esm/types/components/Slider/type.d.ts.map +1 -0
  41. package/dist/esm/types/hooks/useCallbackRef.d.ts.map +1 -0
  42. package/dist/esm/types/hooks/useEventListener.d.ts.map +1 -0
  43. package/dist/esm/types/hooks/useRefCallbackEvent.d.ts.map +1 -0
  44. package/dist/esm/types/index.d.ts +5 -0
  45. package/dist/esm/types/index.d.ts.map +1 -0
  46. package/dist/esm/types/system/pseudo.d.ts.map +1 -0
  47. package/dist/styles/variables.css +4 -0
  48. package/package.json +19 -4
  49. package/src/Globals.d.ts +2 -0
  50. package/src/components/AnimationCanvas/canvas.ts +30 -0
  51. package/src/components/AnimationCanvas/index.tsx +169 -0
  52. package/src/components/Knob/index.tsx +292 -0
  53. package/src/components/NumberInput/index.tsx +165 -0
  54. package/src/components/Slider/Thumb.tsx +54 -0
  55. package/src/components/Slider/Track.tsx +20 -0
  56. package/src/components/Slider/index.tsx +326 -0
  57. package/src/components/Slider/type.ts +16 -0
  58. package/src/hooks/useCallbackRef.ts +20 -0
  59. package/src/hooks/useEventListener.ts +49 -0
  60. package/src/hooks/useRefCallbackEvent.ts +32 -0
  61. package/src/index.ts +4 -0
  62. package/src/styles/variables.css +4 -0
  63. package/src/system/pseudo.ts +55 -0
  64. package/dist/cjs/index.d.ts +0 -140
  65. package/dist/cjs/packages/react/tsconfig.tsbuildinfo +0 -1
  66. package/dist/cjs/types/packages/functions/components/NumberInput/type.d.ts +0 -14
  67. package/dist/cjs/types/packages/functions/components/NumberInput/type.d.ts.map +0 -1
  68. package/dist/cjs/types/packages/functions/components/Slider/type.d.ts +0 -32
  69. package/dist/cjs/types/packages/functions/components/Slider/type.d.ts.map +0 -1
  70. package/dist/cjs/types/packages/functions/math.d.ts +0 -12
  71. package/dist/cjs/types/packages/functions/math.d.ts.map +0 -1
  72. package/dist/cjs/types/packages/functions/types.d.ts +0 -2
  73. package/dist/cjs/types/packages/functions/types.d.ts.map +0 -1
  74. package/dist/cjs/types/packages/functions/util.d.ts +0 -6
  75. package/dist/cjs/types/packages/functions/util.d.ts.map +0 -1
  76. package/dist/cjs/types/packages/react/src/components/AnimationCanvas/canvas.d.ts.map +0 -1
  77. package/dist/cjs/types/packages/react/src/components/AnimationCanvas/index.d.ts +0 -20
  78. package/dist/cjs/types/packages/react/src/components/AnimationCanvas/index.d.ts.map +0 -1
  79. package/dist/cjs/types/packages/react/src/components/Knob/index.d.ts.map +0 -1
  80. package/dist/cjs/types/packages/react/src/components/NumberInput/index.d.ts.map +0 -1
  81. package/dist/cjs/types/packages/react/src/components/Slider/Thumb.d.ts.map +0 -1
  82. package/dist/cjs/types/packages/react/src/components/Slider/Track.d.ts.map +0 -1
  83. package/dist/cjs/types/packages/react/src/components/Slider/index.d.ts.map +0 -1
  84. package/dist/cjs/types/packages/react/src/components/Slider/type.d.ts +0 -6
  85. package/dist/cjs/types/packages/react/src/components/Slider/type.d.ts.map +0 -1
  86. package/dist/cjs/types/packages/react/src/hooks/useCallbackRef.d.ts.map +0 -1
  87. package/dist/cjs/types/packages/react/src/hooks/useEventListener.d.ts.map +0 -1
  88. package/dist/cjs/types/packages/react/src/hooks/useRefCallbackEvent.d.ts.map +0 -1
  89. package/dist/cjs/types/packages/react/src/index.d.ts +0 -7
  90. package/dist/cjs/types/packages/react/src/index.d.ts.map +0 -1
  91. package/dist/cjs/types/packages/react/src/system/pseudo.d.ts.map +0 -1
  92. package/dist/esm/index.d.ts +0 -140
  93. package/dist/esm/packages/react/tsconfig.tsbuildinfo +0 -1
  94. package/dist/esm/types/packages/functions/components/NumberInput/type.d.ts +0 -14
  95. package/dist/esm/types/packages/functions/components/NumberInput/type.d.ts.map +0 -1
  96. package/dist/esm/types/packages/functions/components/Slider/type.d.ts +0 -32
  97. package/dist/esm/types/packages/functions/components/Slider/type.d.ts.map +0 -1
  98. package/dist/esm/types/packages/functions/math.d.ts +0 -12
  99. package/dist/esm/types/packages/functions/math.d.ts.map +0 -1
  100. package/dist/esm/types/packages/functions/types.d.ts +0 -2
  101. package/dist/esm/types/packages/functions/types.d.ts.map +0 -1
  102. package/dist/esm/types/packages/functions/util.d.ts +0 -6
  103. package/dist/esm/types/packages/functions/util.d.ts.map +0 -1
  104. package/dist/esm/types/packages/react/src/components/AnimationCanvas/canvas.d.ts.map +0 -1
  105. package/dist/esm/types/packages/react/src/components/AnimationCanvas/index.d.ts +0 -20
  106. package/dist/esm/types/packages/react/src/components/AnimationCanvas/index.d.ts.map +0 -1
  107. package/dist/esm/types/packages/react/src/components/Knob/index.d.ts.map +0 -1
  108. package/dist/esm/types/packages/react/src/components/NumberInput/index.d.ts.map +0 -1
  109. package/dist/esm/types/packages/react/src/components/Slider/Thumb.d.ts.map +0 -1
  110. package/dist/esm/types/packages/react/src/components/Slider/Track.d.ts.map +0 -1
  111. package/dist/esm/types/packages/react/src/components/Slider/index.d.ts.map +0 -1
  112. package/dist/esm/types/packages/react/src/components/Slider/type.d.ts +0 -6
  113. package/dist/esm/types/packages/react/src/components/Slider/type.d.ts.map +0 -1
  114. package/dist/esm/types/packages/react/src/hooks/useCallbackRef.d.ts.map +0 -1
  115. package/dist/esm/types/packages/react/src/hooks/useEventListener.d.ts.map +0 -1
  116. package/dist/esm/types/packages/react/src/hooks/useRefCallbackEvent.d.ts.map +0 -1
  117. package/dist/esm/types/packages/react/src/index.d.ts +0 -7
  118. package/dist/esm/types/packages/react/src/index.d.ts.map +0 -1
  119. package/dist/esm/types/packages/react/src/system/pseudo.d.ts.map +0 -1
  120. /package/dist/cjs/types/{packages/react/src/components → components}/AnimationCanvas/canvas.d.ts +0 -0
  121. /package/dist/cjs/types/{packages/react/src/hooks → hooks}/useCallbackRef.d.ts +0 -0
  122. /package/dist/cjs/types/{packages/react/src/hooks → hooks}/useEventListener.d.ts +0 -0
  123. /package/dist/cjs/types/{packages/react/src/hooks → hooks}/useRefCallbackEvent.d.ts +0 -0
  124. /package/dist/cjs/types/{packages/react/src/system → system}/pseudo.d.ts +0 -0
  125. /package/dist/esm/types/{packages/react/src/components → components}/AnimationCanvas/canvas.d.ts +0 -0
  126. /package/dist/esm/types/{packages/react/src/hooks → hooks}/useCallbackRef.d.ts +0 -0
  127. /package/dist/esm/types/{packages/react/src/hooks → hooks}/useEventListener.d.ts +0 -0
  128. /package/dist/esm/types/{packages/react/src/hooks → hooks}/useRefCallbackEvent.d.ts +0 -0
  129. /package/dist/esm/types/{packages/react/src/system → system}/pseudo.d.ts +0 -0
package/dist/esm/index.js CHANGED
@@ -2,57 +2,6 @@ import { jsxs, Fragment, jsx } from '@emotion/react/jsx-runtime';
2
2
  import { css, Global } from '@emotion/react';
3
3
  import React, { useRef, useEffect, useInsertionEffect, useCallback, useMemo, useState } from 'react';
4
4
 
5
- function clamp(value, min, max) {
6
- return Math.max(min, Math.min(value, max));
7
- }
8
- function normalizeValue(rawValue, min, max, skew = 1) {
9
- if (min >= max)
10
- throw new RangeError('requirements: min < max');
11
- const v = clamp((rawValue - min) / (max - min), 0, 1);
12
- return Math.pow(v, skew);
13
- }
14
- function rawValue(normalizedValue, min, max, skew = 1) {
15
- if (min >= max)
16
- throw new RangeError('requirements: min < max');
17
- const v = skew == 1
18
- ? clamp(normalizedValue, 0, 1)
19
- : Math.exp(Math.log(clamp(normalizedValue, 0, 1)) / skew);
20
- return min + v * (max - min);
21
- }
22
- function skewWithCenterValue(centerValue, min, max) {
23
- if (!(min <= centerValue && centerValue <= max))
24
- throw new RangeError('requirements: min <= centerValue <= max');
25
- return Math.log(0.5) / Math.log((centerValue - min) / (max - min));
26
- }
27
- function stepValue(value, step) {
28
- var _a;
29
- if (step <= 0)
30
- throw new RangeError('requirements: step > 0');
31
- const quotient = Math.floor(value / step);
32
- const decimalDigits = (_a = decimalPart(step)) === null || _a === void 0 ? void 0 : _a.length;
33
- const v = toFixed(quotient * step, decimalDigits);
34
- const next = toFixed((quotient + 1) * step, decimalDigits);
35
- return Math.abs(value - v) < Math.abs(value - next) ? v : next;
36
- }
37
- function toFixed(x, fractionDigits) {
38
- return Number(x.toFixed(fractionDigits));
39
- }
40
- function decimalPart(x) {
41
- return String(x).split('.')[1];
42
- }
43
- function radian(degree) {
44
- return (Math.PI * degree) / 180;
45
- }
46
- function degree(radian) {
47
- return (180 * radian) / Math.PI;
48
- }
49
- function dbToGain(db) {
50
- return Math.pow(10, db / 20);
51
- }
52
- function gainToDb(gain) {
53
- return 20 * (Math.log(gain) / Math.LN10);
54
- }
55
-
56
5
  /******************************************************************************
57
6
  Copyright (c) Microsoft Corporation.
58
7
 
@@ -87,6 +36,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
87
36
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
88
37
  };
89
38
 
39
+ 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}
40
+
90
41
  // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
91
42
  const drawingState = [
92
43
  'strokeStyle',
@@ -120,7 +71,7 @@ function setDprConfig(canvas, context, width, height, dpr) {
120
71
  * A simple animatable canvas with requestAnimationFrame()
121
72
  */
122
73
  function AnimationCanvas(_a) {
123
- 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"]);
74
+ 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"]);
124
75
  const canvasRef = useRef(null);
125
76
  const memoCanvasRef = useRef(null);
126
77
  const reqIdRef = useRef();
@@ -145,7 +96,7 @@ function AnimationCanvas(_a) {
145
96
  const memoCanvas = memoCanvasRef.current;
146
97
  const memoContext = memoCanvas === null || memoCanvas === void 0 ? void 0 : memoCanvas.getContext('2d', options);
147
98
  const resizeObserver = new ResizeObserver(() => {
148
- console.log('resize');
99
+ // console.log('resize')
149
100
  // Prevents loss of some context when the canvas is resized
150
101
  const contextMemo = {};
151
102
  for (const prop of drawingState) {
@@ -196,7 +147,70 @@ function AnimationCanvas(_a) {
196
147
  };
197
148
  }
198
149
  }, [loop]);
199
- return (jsxs(Fragment, { children: [jsx("canvas", Object.assign({ width: relativeSize ? 0 : width, height: relativeSize ? 0 : height, css: css(style), ref: canvasRef }, props)), relativeSize && reduceFlickering && (jsx("canvas", { style: { display: 'none' }, width: relativeSize ? 0 : width, height: relativeSize ? 0 : height, ref: memoCanvasRef }))] }));
150
+ return (jsxs(Fragment, { children: [jsx("canvas", Object.assign({ className: clsx('tremolo-animation-canvas', className), width: relativeSize ? 0 : width, height: relativeSize ? 0 : height, css: css(style), ref: canvasRef }, props)), relativeSize && reduceFlickering && (jsx("canvas", { style: { display: 'none' }, width: relativeSize ? 0 : width, height: relativeSize ? 0 : height, ref: memoCanvasRef }))] }));
151
+ }
152
+
153
+ function clamp(value, min, max) {
154
+ return Math.max(min, Math.min(value, max));
155
+ }
156
+ function normalizeValue(rawValue, min, max, skew = 1) {
157
+ if (min >= max)
158
+ throw new RangeError('requirements: min < max');
159
+ const v = clamp((rawValue - min) / (max - min), 0, 1);
160
+ return Math.pow(v, skew);
161
+ }
162
+ function rawValue(normalizedValue, min, max, skew = 1) {
163
+ if (min >= max)
164
+ throw new RangeError('requirements: min < max');
165
+ const v = skew == 1
166
+ ? clamp(normalizedValue, 0, 1)
167
+ : Math.exp(Math.log(clamp(normalizedValue, 0, 1)) / skew);
168
+ return min + v * (max - min);
169
+ }
170
+ function stepValue(value, step) {
171
+ var _a;
172
+ if (step <= 0)
173
+ throw new RangeError('requirements: step > 0');
174
+ const quotient = Math.floor(value / step);
175
+ const decimalDigits = (_a = decimalPart$1(step)) === null || _a === void 0 ? void 0 : _a.length;
176
+ const v = toFixed$2(quotient * step, decimalDigits);
177
+ const next = toFixed$2((quotient + 1) * step, decimalDigits);
178
+ return Math.abs(value - v) < Math.abs(value - next) ? v : next;
179
+ }
180
+ function toFixed$2(x, fractionDigits) {
181
+ return Number(x.toFixed(fractionDigits));
182
+ }
183
+ function decimalPart$1(x) {
184
+ return String(x).split('.')[1];
185
+ }
186
+ function radian(degree) {
187
+ return (Math.PI * degree) / 180;
188
+ }
189
+
190
+ function styleHelper(value, op, influencer) {
191
+ if (op && influencer) {
192
+ if (typeof value == 'number') {
193
+ if (op == '+')
194
+ return `${value + influencer}px`;
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
+ }
202
+ else {
203
+ return `calc(${value}px ${op} ${influencer})`;
204
+ }
205
+ }
206
+ else {
207
+ if (typeof value == 'number') {
208
+ return `${value}px`;
209
+ }
210
+ else {
211
+ return value;
212
+ }
213
+ }
200
214
  }
201
215
 
202
216
  /**
@@ -258,9 +272,7 @@ const defaultOptions = {
258
272
  * simple rotary Knob.
259
273
  */
260
274
  function Knob(_a) {
261
- var { value, min, max, defaultValue = min, startValue = min, step = 1, skew = 1, size, width = 50, height = 50, options = defaultOptions,
262
- // draw,
263
- 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"]);
275
+ 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"]);
264
276
  // -- state and ref ---
265
277
  // const [privateValue, setPrivateValue] = useState(value);
266
278
  const dragOffsetY = useRef(undefined);
@@ -317,10 +329,10 @@ function Knob(_a) {
317
329
  if (bodyNoSelect)
318
330
  document.body.classList.remove('no-select');
319
331
  });
320
- return (jsxs("div", Object.assign({ className: "tremolo-knob", ref: (div) => {
332
+ return (jsxs("div", Object.assign({ className: clsx('tremolo-knob', className), ref: (div) => {
321
333
  wheelRefCallback(div);
322
334
  touchMoveRefCallback(div);
323
- }, role: "slider", tabIndex: 0, "aria-valuenow": value, "aria-valuemax": max, "aria-valuemin": min, css: 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) => {
335
+ }, role: "slider", tabIndex: 0, "aria-valuenow": value, "aria-valuemax": max, "aria-valuemin": min, css: css(Object.assign(Object.assign({ display: '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) => {
324
336
  dragOffsetY.current = event.screenY;
325
337
  handleEvent(event);
326
338
  }, onDoubleClick: () => {
@@ -334,11 +346,11 @@ function Knob(_a) {
334
346
  } }), jsx(AnimationCanvas, { width: adaptSize(size !== null && size !== void 0 ? size : width), height: adaptSize(size !== null && size !== void 0 ? size : height), relativeSize: isRelativeSize,
335
347
  // TODO
336
348
  // reduceFlickering={false}
337
- draw: (ctx, _w, _h) => {
349
+ draw: draw ? draw : (ctx, width, height) => {
338
350
  const p = normalizeValue(value, min, max, skew);
339
351
  const startP = normalizeValue(startValue, min, max, skew);
340
- const w = _w.current, cx = w / 2;
341
- const h = _h.current, cy = h / 2;
352
+ const w = width.current, cx = w / 2;
353
+ const h = height.current, cy = h / 2;
342
354
  const r = Math.min(cx, cy);
343
355
  if (r <= 0)
344
356
  return;
@@ -376,6 +388,10 @@ function Knob(_a) {
376
388
  } })] })));
377
389
  }
378
390
 
391
+ function toFixed$1(x, fractionDigits) {
392
+ return Number(x.toFixed(fractionDigits));
393
+ }
394
+
379
395
  function selectUnit(units, value) {
380
396
  if (typeof units == 'string')
381
397
  return [units, 1];
@@ -386,27 +402,30 @@ function selectUnit(units, value) {
386
402
  }
387
403
  return units[Math.max(0, i - 1)];
388
404
  }
389
- function parseValue(inputString, units, digit) {
405
+ function parseValue(inputString, units, digit, defaultValue = 0) {
406
+ let str = inputString.trim();
407
+ if (str == '')
408
+ str = String(defaultValue);
390
409
  if (!units) {
391
410
  return {
392
- rawValue: Number(inputString.trim()) || 0,
393
- formatValue: inputString.trim(),
411
+ rawValue: Number(str) || defaultValue,
412
+ formatValue: str,
394
413
  unit: '',
395
414
  };
396
415
  }
397
416
  else if (typeof units == 'string') {
398
417
  return {
399
- rawValue: Number(inputString.trim()) || 0,
400
- formatValue: `${inputString.trim()}${units}`,
418
+ rawValue: Number(str) || defaultValue,
419
+ formatValue: `${str}${units}`,
401
420
  unit: units,
402
421
  };
403
422
  }
404
423
  const unitList = units.map(([u, _s]) => u);
405
424
  const scaleList = units.map(([_u, s]) => s);
406
- let rawValue = 0;
425
+ let rawValue = defaultValue;
407
426
  let formatValue = `${scaleList[0]}`;
408
427
  let unit = unitList[0];
409
- const m = inputString.trim().match(/^(-?\d+(\.\d+)?)\s*(\w*)$/);
428
+ const m = str.match(/^(-?\d+(\.\d+)?)\s*(\w*)$/);
410
429
  if (m) {
411
430
  rawValue = Number(m[1]) || 0;
412
431
  const inputUnit = m[3];
@@ -414,13 +433,13 @@ function parseValue(inputString, units, digit) {
414
433
  rawValue *= scaleList[unitList.indexOf(inputUnit)];
415
434
  const s = selectUnit(units, rawValue);
416
435
  const v = rawValue / s[1];
417
- formatValue = `${digit != undefined ? toFixed(v, digit) : v}${s[0]}`;
436
+ formatValue = `${digit != undefined ? toFixed$1(v, digit) : v}${s[0]}`;
418
437
  unit = s[0];
419
438
  }
420
439
  else {
421
440
  const [u, scale] = selectUnit(units, rawValue);
422
441
  const v = rawValue / scale;
423
- formatValue = `${digit != undefined ? toFixed(v, digit) : v}${u}`;
442
+ formatValue = `${digit != undefined ? toFixed$1(v, digit) : v}${u}`;
424
443
  unit = u;
425
444
  }
426
445
  }
@@ -435,21 +454,19 @@ function parseValue(inputString, units, digit) {
435
454
  * Input with some useful functions for entering numerical values.
436
455
  */
437
456
  function NumberInput(_a) {
438
- var { value, min, // TODO
439
- max, // TODO
440
- step, // TODO
441
- 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"]);
442
- const [showValue, setShowValue] = useState(parseValue(String(value), units, digit).formatValue);
457
+ 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"]);
458
+ const [showValue, setShowValue] = useState(parseValue(String(value), units, digit, defaultValue).formatValue);
443
459
  const calculatedStrict = units ? false : strict;
444
460
  const { _active, _focus, _hover } = pseudo;
445
- return (jsx("input", { className: 'tremolo-slider' + (className ? ` ${className}` : ''), value: showValue, type: calculatedStrict ? 'number' : 'text', spellCheck: 'false', disabled: disabled, placeholder: placeholder, readOnly: readOnly, tabIndex: tabIndex, css: 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) => {
461
+ return (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: css(Object.assign(Object.assign({ display: '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) => {
446
462
  const v = event.currentTarget.value;
447
463
  setShowValue(v);
464
+ const newValue = clamp(parseValue(v, units, digit, defaultValue).rawValue, min !== null && min !== void 0 ? min : -Infinity, max !== null && max !== void 0 ? max : Infinity);
448
465
  if (onChange)
449
- onChange(parseValue(v, units, digit).rawValue, event);
466
+ onChange(newValue, event);
450
467
  }, onFocus: (event) => {
451
468
  const v = event.currentTarget.value;
452
- const parsed = parseValue(v, units, digit);
469
+ const parsed = parseValue(v, units, digit, defaultValue);
453
470
  if (selectWithFocus == 'all') {
454
471
  event.currentTarget.setSelectionRange(0, v.length);
455
472
  }
@@ -461,7 +478,7 @@ function NumberInput(_a) {
461
478
  }, onBlur: (event) => {
462
479
  // update value
463
480
  const v = event.currentTarget.value;
464
- const parsed = parseValue(v, units, digit);
481
+ const parsed = parseValue(v, units, digit, defaultValue);
465
482
  setShowValue(parsed.formatValue);
466
483
  if (onBlur)
467
484
  onBlur(parsed.rawValue, event);
@@ -472,6 +489,13 @@ function NumberInput(_a) {
472
489
  } }));
473
490
  }
474
491
 
492
+ function toFixed(x, fractionDigits) {
493
+ return Number(x.toFixed(fractionDigits));
494
+ }
495
+ function decimalPart(x) {
496
+ return String(x).split('.')[1];
497
+ }
498
+
475
499
  function isHorizontal(d) {
476
500
  return d == 'right' || d == 'left';
477
501
  }
@@ -507,38 +531,16 @@ function parseScaleOrderList(scale, min, max, step) {
507
531
  return scalesList;
508
532
  }
509
533
 
510
- function styleHelper(value, op, influencer) {
511
- if (op && influencer) {
512
- if (typeof value == 'number') {
513
- if (op == '+')
514
- return `${value + influencer}px`;
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
- }
522
- else {
523
- return `calc(${value}px ${op} ${influencer})`;
524
- }
525
- }
526
- else {
527
- if (typeof value == 'number') {
528
- return `${value}px`;
529
- }
530
- else {
531
- return value;
532
- }
533
- }
534
- }
535
-
536
534
  function SliderThumb({ color, children, style, __css, }) {
537
535
  return (jsx("div", { className: "tremolo-slider-thumb-wrapper", css: css(Object.assign({ width: 'fit-content', height: 'fit-content', position: 'absolute', translate: '-50% -50%', zIndex: 100 }, __css)), children: children ? (children) : (
538
536
  // default slider thumb
539
537
  jsx("div", { className: "tremolo-slider-thumb",
540
538
  // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
541
- tabIndex: 0, css: css(Object.assign({ background: color, width: '1.4rem', height: '1.4rem', borderRadius: '50%' }, style)) })) }));
539
+ tabIndex: 0, css: css(Object.assign({ background: color, width: '1.4rem', height: '1.4rem', borderRadius: '50%', '&:hover': {
540
+ background: `color-mix(in srgb, ${color} 95%, black)`
541
+ }, '&:active': {
542
+ boxShadow: '0px 0px 0px 3px rgba(var(--tremolo-theme-color-rgb), 0.2)',
543
+ } }, style)) })) }));
542
544
  }
543
545
 
544
546
  function SliderTrack({ children, style, __css, }) {
@@ -630,7 +632,7 @@ function Slider(_a) {
630
632
  if (bodyNoSelect)
631
633
  document.body.classList.remove('no-select');
632
634
  });
633
- return (jsxs("div", { className: 'tremolo-slider' + (className ? ` ${className}` : ''), ref: (div) => {
635
+ return (jsxs("div", { className: clsx('tremolo-slider', className), ref: (div) => {
634
636
  wheelRefCallback(div);
635
637
  touchMoveRefCallback(div);
636
638
  }, tabIndex: -1, role: "slider", "aria-valuenow": value, "aria-valuemax": max, "aria-valuemin": min, "aria-orientation": isHorizontal(direction) ? 'horizontal' : 'vertical', css: css(Object.assign({ display: 'inline-block', boxSizing: 'border-box', margin: '0.7rem', padding: 0, cursor: 'pointer' }, style)), onPointerDown: (event) => {
@@ -699,5 +701,5 @@ function Slider(_a) {
699
701
  }) }))] })] }));
700
702
  }
701
703
 
702
- export { AnimationCanvas, Knob, NumberInput, Slider, clamp, dbToGain, decimalPart, degree, gainToDb, normalizeValue, radian, rawValue, skewWithCenterValue, stepValue, toFixed };
704
+ export { AnimationCanvas, Knob, NumberInput, Slider, SliderThumb, SliderTrack, gradientDirection };
703
705
  //# sourceMappingURL=index.js.map