@tremolo-ui/react 0.0.2 → 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.
- package/README.md +11 -0
- package/dist/cjs/index.js +326 -118
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AnimationCanvas/canvas.d.ts.map +1 -0
- package/dist/cjs/types/components/AnimationCanvas/index.d.ts +20 -0
- package/dist/cjs/types/components/AnimationCanvas/index.d.ts.map +1 -0
- package/dist/cjs/types/{src/components → components}/Knob/index.d.ts +16 -4
- package/dist/cjs/types/components/Knob/index.d.ts.map +1 -0
- package/dist/cjs/types/{src/components → components}/NumberInput/index.d.ts +3 -5
- package/dist/cjs/types/components/NumberInput/index.d.ts.map +1 -0
- package/dist/cjs/types/{src/components → components}/Slider/Thumb.d.ts +2 -2
- package/dist/cjs/types/components/Slider/Thumb.d.ts.map +1 -0
- package/dist/cjs/types/{src/components → components}/Slider/Track.d.ts +1 -1
- package/dist/cjs/types/components/Slider/Track.d.ts.map +1 -0
- package/dist/cjs/types/{src/components → components}/Slider/index.d.ts +5 -5
- package/dist/cjs/types/components/Slider/index.d.ts.map +1 -0
- package/dist/cjs/types/components/Slider/type.d.ts +7 -0
- package/dist/cjs/types/components/Slider/type.d.ts.map +1 -0
- package/dist/cjs/types/hooks/useCallbackRef.d.ts.map +1 -0
- package/dist/cjs/types/hooks/useEventListener.d.ts.map +1 -0
- package/dist/cjs/types/hooks/useRefCallbackEvent.d.ts.map +1 -0
- package/dist/cjs/types/index.d.ts +5 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/system/pseudo.d.ts.map +1 -0
- package/dist/esm/index.js +273 -65
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AnimationCanvas/canvas.d.ts.map +1 -0
- package/dist/esm/types/components/AnimationCanvas/index.d.ts +20 -0
- package/dist/esm/types/components/AnimationCanvas/index.d.ts.map +1 -0
- package/dist/esm/types/{src/components → components}/Knob/index.d.ts +16 -4
- package/dist/esm/types/components/Knob/index.d.ts.map +1 -0
- package/dist/esm/types/{src/components → components}/NumberInput/index.d.ts +3 -5
- package/dist/esm/types/components/NumberInput/index.d.ts.map +1 -0
- package/dist/esm/types/{src/components → components}/Slider/Thumb.d.ts +2 -2
- package/dist/esm/types/components/Slider/Thumb.d.ts.map +1 -0
- package/dist/esm/types/{src/components → components}/Slider/Track.d.ts +1 -1
- package/dist/esm/types/components/Slider/Track.d.ts.map +1 -0
- package/dist/esm/types/{src/components → components}/Slider/index.d.ts +5 -5
- package/dist/esm/types/components/Slider/index.d.ts.map +1 -0
- package/dist/esm/types/components/Slider/type.d.ts +7 -0
- package/dist/esm/types/components/Slider/type.d.ts.map +1 -0
- package/dist/esm/types/hooks/useCallbackRef.d.ts.map +1 -0
- package/dist/esm/types/hooks/useEventListener.d.ts.map +1 -0
- package/dist/esm/types/hooks/useRefCallbackEvent.d.ts.map +1 -0
- package/dist/esm/types/index.d.ts +5 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/system/pseudo.d.ts.map +1 -0
- package/dist/styles/variables.css +4 -0
- package/package.json +26 -9
- package/src/Globals.d.ts +2 -0
- package/src/components/AnimationCanvas/canvas.ts +30 -0
- package/src/components/AnimationCanvas/index.tsx +169 -0
- package/src/components/Knob/index.tsx +292 -0
- package/src/components/NumberInput/index.tsx +165 -0
- package/src/components/Slider/Thumb.tsx +54 -0
- package/src/components/Slider/Track.tsx +20 -0
- package/src/components/Slider/index.tsx +326 -0
- package/src/components/Slider/type.ts +16 -0
- package/src/hooks/useCallbackRef.ts +20 -0
- package/src/hooks/useEventListener.ts +49 -0
- package/src/hooks/useRefCallbackEvent.ts +32 -0
- package/src/index.ts +4 -0
- package/src/styles/variables.css +4 -0
- package/src/system/pseudo.ts +55 -0
- package/dist/cjs/index.d.ts +0 -75
- package/dist/cjs/types/src/components/AnimationCanvas/canvas.d.ts.map +0 -1
- package/dist/cjs/types/src/components/AnimationCanvas/index.d.ts +0 -20
- package/dist/cjs/types/src/components/AnimationCanvas/index.d.ts.map +0 -1
- package/dist/cjs/types/src/components/Knob/index.d.ts.map +0 -1
- package/dist/cjs/types/src/components/NumberInput/index.d.ts.map +0 -1
- package/dist/cjs/types/src/components/Slider/Thumb.d.ts.map +0 -1
- package/dist/cjs/types/src/components/Slider/Track.d.ts.map +0 -1
- package/dist/cjs/types/src/components/Slider/index.d.ts.map +0 -1
- package/dist/cjs/types/src/components/Slider/type.d.ts +0 -6
- package/dist/cjs/types/src/components/Slider/type.d.ts.map +0 -1
- package/dist/cjs/types/src/hooks/useCallbackRef.d.ts.map +0 -1
- package/dist/cjs/types/src/hooks/useEventListener.d.ts.map +0 -1
- package/dist/cjs/types/src/hooks/useRefCallbackEvent.d.ts.map +0 -1
- package/dist/cjs/types/src/index.d.ts +0 -5
- package/dist/cjs/types/src/index.d.ts.map +0 -1
- package/dist/cjs/types/src/math.d.ts +0 -8
- package/dist/cjs/types/src/math.d.ts.map +0 -1
- package/dist/cjs/types/src/system/pseudo.d.ts.map +0 -1
- package/dist/cjs/types/src/types.d.ts +0 -2
- package/dist/cjs/types/src/types.d.ts.map +0 -1
- package/dist/cjs/types/src/util.d.ts +0 -2
- package/dist/cjs/types/src/util.d.ts.map +0 -1
- package/dist/esm/index.d.ts +0 -75
- package/dist/esm/types/src/components/AnimationCanvas/canvas.d.ts.map +0 -1
- package/dist/esm/types/src/components/AnimationCanvas/index.d.ts +0 -20
- package/dist/esm/types/src/components/AnimationCanvas/index.d.ts.map +0 -1
- package/dist/esm/types/src/components/Knob/index.d.ts.map +0 -1
- package/dist/esm/types/src/components/NumberInput/index.d.ts.map +0 -1
- package/dist/esm/types/src/components/Slider/Thumb.d.ts.map +0 -1
- package/dist/esm/types/src/components/Slider/Track.d.ts.map +0 -1
- package/dist/esm/types/src/components/Slider/index.d.ts.map +0 -1
- package/dist/esm/types/src/components/Slider/type.d.ts +0 -6
- package/dist/esm/types/src/components/Slider/type.d.ts.map +0 -1
- package/dist/esm/types/src/hooks/useCallbackRef.d.ts.map +0 -1
- package/dist/esm/types/src/hooks/useEventListener.d.ts.map +0 -1
- package/dist/esm/types/src/hooks/useRefCallbackEvent.d.ts.map +0 -1
- package/dist/esm/types/src/index.d.ts +0 -5
- package/dist/esm/types/src/index.d.ts.map +0 -1
- package/dist/esm/types/src/math.d.ts +0 -8
- package/dist/esm/types/src/math.d.ts.map +0 -1
- package/dist/esm/types/src/system/pseudo.d.ts.map +0 -1
- package/dist/esm/types/src/types.d.ts +0 -2
- package/dist/esm/types/src/types.d.ts.map +0 -1
- package/dist/esm/types/src/util.d.ts +0 -2
- package/dist/esm/types/src/util.d.ts.map +0 -1
- /package/dist/cjs/types/{src/components → components}/AnimationCanvas/canvas.d.ts +0 -0
- /package/dist/cjs/types/{src/hooks → hooks}/useCallbackRef.d.ts +0 -0
- /package/dist/cjs/types/{src/hooks → hooks}/useEventListener.d.ts +0 -0
- /package/dist/cjs/types/{src/hooks → hooks}/useRefCallbackEvent.d.ts +0 -0
- /package/dist/cjs/types/{src/system → system}/pseudo.d.ts +0 -0
- /package/dist/esm/types/{src/components → components}/AnimationCanvas/canvas.d.ts +0 -0
- /package/dist/esm/types/{src/hooks → hooks}/useCallbackRef.d.ts +0 -0
- /package/dist/esm/types/{src/hooks → hooks}/useEventListener.d.ts +0 -0
- /package/dist/esm/types/{src/hooks → hooks}/useRefCallbackEvent.d.ts +0 -0
- /package/dist/esm/types/{src/system → system}/pseudo.d.ts +0 -0
package/README.md
ADDED
package/dist/cjs/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var math = require('common/math');
|
|
4
3
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
5
4
|
var react = require('@emotion/react');
|
|
6
5
|
var React = require('react');
|
|
7
|
-
var type = require('common/components/Slider/type');
|
|
8
|
-
var util = require('common/util');
|
|
9
6
|
|
|
10
7
|
/******************************************************************************
|
|
11
8
|
Copyright (c) Microsoft Corporation.
|
|
@@ -41,52 +38,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
41
38
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
42
39
|
};
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
* This hook is user-land implementation of the experimental `useEffectEvent` hook.
|
|
46
|
-
* React docs: https://react.dev/learn/separating-events-from-effects#declaring-an-effect-event
|
|
47
|
-
*/
|
|
48
|
-
function useCallbackRef(callback, deps = []) {
|
|
49
|
-
const callbackRef = React.useRef(() => {
|
|
50
|
-
throw new Error('Cannot call an event handler while rendering.');
|
|
51
|
-
});
|
|
52
|
-
React.useInsertionEffect(() => {
|
|
53
|
-
callbackRef.current = callback;
|
|
54
|
-
});
|
|
55
|
-
return React.useCallback((...args) => { var _a; return (_a = callbackRef.current) === null || _a === void 0 ? void 0 : _a.call(callbackRef, ...args); }, deps);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function useEventListener(target, event, handler, options) {
|
|
59
|
-
const listener = useCallbackRef(handler);
|
|
60
|
-
React.useEffect(() => {
|
|
61
|
-
const node = typeof target === 'function' ? target() : (target !== null && target !== void 0 ? target : document);
|
|
62
|
-
if (!handler || !node)
|
|
63
|
-
return;
|
|
64
|
-
node.addEventListener(event, listener, options);
|
|
65
|
-
return () => {
|
|
66
|
-
node.removeEventListener(event, listener, options);
|
|
67
|
-
};
|
|
68
|
-
}, [event, target, options, listener, handler]);
|
|
69
|
-
return () => {
|
|
70
|
-
const node = typeof target === 'function' ? target() : (target !== null && target !== void 0 ? target : document);
|
|
71
|
-
node === null || node === void 0 ? void 0 : node.removeEventListener(event, listener, options);
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function useRefCallbackEvent(event, handler, options, deps = []) {
|
|
76
|
-
return React.useMemo(() => {
|
|
77
|
-
let cleanup;
|
|
78
|
-
return (node) => {
|
|
79
|
-
if (!node) {
|
|
80
|
-
cleanup === null || cleanup === void 0 ? void 0 : cleanup();
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
node.addEventListener(event, handler, options);
|
|
84
|
-
cleanup = () => {
|
|
85
|
-
node.removeEventListener(event, handler, options);
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
}, deps);
|
|
89
|
-
}
|
|
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}
|
|
90
42
|
|
|
91
43
|
// https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
|
|
92
44
|
const drawingState = [
|
|
@@ -121,7 +73,7 @@ function setDprConfig(canvas, context, width, height, dpr) {
|
|
|
121
73
|
* A simple animatable canvas with requestAnimationFrame()
|
|
122
74
|
*/
|
|
123
75
|
function AnimationCanvas(_a) {
|
|
124
|
-
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"]);
|
|
125
77
|
const canvasRef = React.useRef(null);
|
|
126
78
|
const memoCanvasRef = React.useRef(null);
|
|
127
79
|
const reqIdRef = React.useRef();
|
|
@@ -146,7 +98,7 @@ function AnimationCanvas(_a) {
|
|
|
146
98
|
const memoCanvas = memoCanvasRef.current;
|
|
147
99
|
const memoContext = memoCanvas === null || memoCanvas === void 0 ? void 0 : memoCanvas.getContext('2d', options);
|
|
148
100
|
const resizeObserver = new ResizeObserver(() => {
|
|
149
|
-
console.log('resize')
|
|
101
|
+
// console.log('resize')
|
|
150
102
|
// Prevents loss of some context when the canvas is resized
|
|
151
103
|
const contextMemo = {};
|
|
152
104
|
for (const prop of drawingState) {
|
|
@@ -197,7 +149,117 @@ function AnimationCanvas(_a) {
|
|
|
197
149
|
};
|
|
198
150
|
}
|
|
199
151
|
}, [loop]);
|
|
200
|
-
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
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* This hook is user-land implementation of the experimental `useEffectEvent` hook.
|
|
220
|
+
* React docs: https://react.dev/learn/separating-events-from-effects#declaring-an-effect-event
|
|
221
|
+
*/
|
|
222
|
+
function useCallbackRef(callback, deps = []) {
|
|
223
|
+
const callbackRef = React.useRef(() => {
|
|
224
|
+
throw new Error('Cannot call an event handler while rendering.');
|
|
225
|
+
});
|
|
226
|
+
React.useInsertionEffect(() => {
|
|
227
|
+
callbackRef.current = callback;
|
|
228
|
+
});
|
|
229
|
+
return React.useCallback((...args) => { var _a; return (_a = callbackRef.current) === null || _a === void 0 ? void 0 : _a.call(callbackRef, ...args); }, deps);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function useEventListener(target, event, handler, options) {
|
|
233
|
+
const listener = useCallbackRef(handler);
|
|
234
|
+
React.useEffect(() => {
|
|
235
|
+
const node = typeof target === 'function' ? target() : (target !== null && target !== void 0 ? target : document);
|
|
236
|
+
if (!handler || !node)
|
|
237
|
+
return;
|
|
238
|
+
node.addEventListener(event, listener, options);
|
|
239
|
+
return () => {
|
|
240
|
+
node.removeEventListener(event, listener, options);
|
|
241
|
+
};
|
|
242
|
+
}, [event, target, options, listener, handler]);
|
|
243
|
+
return () => {
|
|
244
|
+
const node = typeof target === 'function' ? target() : (target !== null && target !== void 0 ? target : document);
|
|
245
|
+
node === null || node === void 0 ? void 0 : node.removeEventListener(event, listener, options);
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function useRefCallbackEvent(event, handler, options, deps = []) {
|
|
250
|
+
return React.useMemo(() => {
|
|
251
|
+
let cleanup;
|
|
252
|
+
return (node) => {
|
|
253
|
+
if (!node) {
|
|
254
|
+
cleanup === null || cleanup === void 0 ? void 0 : cleanup();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
node.addEventListener(event, handler, options);
|
|
258
|
+
cleanup = () => {
|
|
259
|
+
node.removeEventListener(event, handler, options);
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
}, deps);
|
|
201
263
|
}
|
|
202
264
|
|
|
203
265
|
const defaultOptions = {
|
|
@@ -212,9 +274,7 @@ const defaultOptions = {
|
|
|
212
274
|
* simple rotary Knob.
|
|
213
275
|
*/
|
|
214
276
|
function Knob(_a) {
|
|
215
|
-
var { value, min, max, defaultValue = min, startValue = min, step = 1, skew = 1, size, width = 50, height = 50, options = defaultOptions,
|
|
216
|
-
// draw,
|
|
217
|
-
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"]);
|
|
218
278
|
// -- state and ref ---
|
|
219
279
|
// const [privateValue, setPrivateValue] = useState(value);
|
|
220
280
|
const dragOffsetY = React.useRef(undefined);
|
|
@@ -240,9 +300,9 @@ function Knob(_a) {
|
|
|
240
300
|
const screenY = isTouch ? event.touches[0].screenY : event.screenY;
|
|
241
301
|
const delta = dragOffsetY.current - screenY;
|
|
242
302
|
dragOffsetY.current = screenY;
|
|
243
|
-
const n =
|
|
244
|
-
const v =
|
|
245
|
-
const v2 =
|
|
303
|
+
const n = normalizeValue(value, min, max, skew);
|
|
304
|
+
const v = rawValue(n + delta / 100, min, max, skew);
|
|
305
|
+
const v2 = clamp(stepValue(v, step), min, max);
|
|
246
306
|
if (onChange)
|
|
247
307
|
onChange(v2);
|
|
248
308
|
}
|
|
@@ -255,14 +315,14 @@ function Knob(_a) {
|
|
|
255
315
|
const x = event.deltaY > 0 ? -enableWheel[1] : enableWheel[1];
|
|
256
316
|
let v;
|
|
257
317
|
if (enableWheel[0] == 'normalized') {
|
|
258
|
-
const n =
|
|
259
|
-
v =
|
|
318
|
+
const n = normalizeValue(value, min, max, skew);
|
|
319
|
+
v = rawValue(n + x, min, max, skew);
|
|
260
320
|
}
|
|
261
321
|
else {
|
|
262
322
|
v = value + x;
|
|
263
323
|
}
|
|
264
324
|
if (onChange)
|
|
265
|
-
onChange(
|
|
325
|
+
onChange(clamp(stepValue(v, step), min, max));
|
|
266
326
|
}, { passive: false }, [enableWheel, value, min, max, skew, step, onChange]);
|
|
267
327
|
const touchMoveRefCallback = useRefCallbackEvent('touchmove', handleEvent, { passive: false }, [value, min, max, skew, step, onChange, bodyNoSelect]);
|
|
268
328
|
useEventListener(window, 'mousemove', handleEvent);
|
|
@@ -271,10 +331,10 @@ function Knob(_a) {
|
|
|
271
331
|
if (bodyNoSelect)
|
|
272
332
|
document.body.classList.remove('no-select');
|
|
273
333
|
});
|
|
274
|
-
return (jsxRuntime.jsxs("div", Object.assign({ className:
|
|
334
|
+
return (jsxRuntime.jsxs("div", Object.assign({ className: clsx('tremolo-knob', className), ref: (div) => {
|
|
275
335
|
wheelRefCallback(div);
|
|
276
336
|
touchMoveRefCallback(div);
|
|
277
|
-
}, role: "slider", tabIndex: 0, "aria-valuenow": value, "aria-valuemax": max, "aria-valuemin": min, css: react.css(Object.assign(Object.assign({ display: '
|
|
337
|
+
}, role: "slider", tabIndex: 0, "aria-valuenow": value, "aria-valuemax": max, "aria-valuemin": min, css: react.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) => {
|
|
278
338
|
dragOffsetY.current = event.screenY;
|
|
279
339
|
handleEvent(event);
|
|
280
340
|
}, onDoubleClick: () => {
|
|
@@ -288,12 +348,14 @@ function Knob(_a) {
|
|
|
288
348
|
} }), jsxRuntime.jsx(AnimationCanvas, { width: adaptSize(size !== null && size !== void 0 ? size : width), height: adaptSize(size !== null && size !== void 0 ? size : height), relativeSize: isRelativeSize,
|
|
289
349
|
// TODO
|
|
290
350
|
// reduceFlickering={false}
|
|
291
|
-
draw: (ctx,
|
|
292
|
-
const p =
|
|
293
|
-
const startP =
|
|
294
|
-
const w =
|
|
295
|
-
const h =
|
|
351
|
+
draw: draw ? draw : (ctx, width, height) => {
|
|
352
|
+
const p = normalizeValue(value, min, max, skew);
|
|
353
|
+
const startP = normalizeValue(startValue, min, max, skew);
|
|
354
|
+
const w = width.current, cx = w / 2;
|
|
355
|
+
const h = height.current, cy = h / 2;
|
|
296
356
|
const r = Math.min(cx, cy);
|
|
357
|
+
if (r <= 0)
|
|
358
|
+
return;
|
|
297
359
|
// reset
|
|
298
360
|
ctx.clearRect(0, 0, w, h);
|
|
299
361
|
ctx.lineCap = 'butt';
|
|
@@ -307,20 +369,20 @@ function Knob(_a) {
|
|
|
307
369
|
// inactive rotary
|
|
308
370
|
ctx.beginPath();
|
|
309
371
|
ctx.strokeStyle = opts.inactive;
|
|
310
|
-
ctx.arc(cx, cy, r - 0.5 - opts.lineWeight / 2,
|
|
372
|
+
ctx.arc(cx, cy, r - 0.5 - opts.lineWeight / 2, radian(135), radian(45));
|
|
311
373
|
ctx.stroke();
|
|
312
374
|
// active rotary
|
|
313
375
|
ctx.beginPath();
|
|
314
376
|
ctx.strokeStyle = opts.active;
|
|
315
|
-
ctx.arc(cx, cy, r - 0.5 - opts.lineWeight / 2,
|
|
377
|
+
ctx.arc(cx, cy, r - 0.5 - opts.lineWeight / 2, radian(135 + 270 * startP), radian(135 + 270 * p), p < startP);
|
|
316
378
|
ctx.stroke();
|
|
317
379
|
// thumb
|
|
318
380
|
ctx.beginPath();
|
|
319
381
|
ctx.moveTo(cx, cy);
|
|
320
382
|
ctx.lineTo(cx +
|
|
321
|
-
Math.cos(
|
|
383
|
+
Math.cos(radian(135 + 270 * p)) *
|
|
322
384
|
(r - 0.5 - opts.thumbWeight / 2), cy +
|
|
323
|
-
Math.sin(
|
|
385
|
+
Math.sin(radian(135 + 270 * p)) *
|
|
324
386
|
(r - 0.5 - opts.thumbWeight / 2));
|
|
325
387
|
ctx.strokeStyle = opts.thumb;
|
|
326
388
|
ctx.lineWidth = opts.thumbWeight;
|
|
@@ -328,12 +390,159 @@ function Knob(_a) {
|
|
|
328
390
|
} })] })));
|
|
329
391
|
}
|
|
330
392
|
|
|
393
|
+
function toFixed$1(x, fractionDigits) {
|
|
394
|
+
return Number(x.toFixed(fractionDigits));
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function selectUnit(units, value) {
|
|
398
|
+
if (typeof units == 'string')
|
|
399
|
+
return [units, 1];
|
|
400
|
+
let i = 0;
|
|
401
|
+
for (; i < units.length; i++) {
|
|
402
|
+
if (Math.abs(units[i][1]) > Math.abs(value))
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
return units[Math.max(0, i - 1)];
|
|
406
|
+
}
|
|
407
|
+
function parseValue(inputString, units, digit, defaultValue = 0) {
|
|
408
|
+
let str = inputString.trim();
|
|
409
|
+
if (str == '')
|
|
410
|
+
str = String(defaultValue);
|
|
411
|
+
if (!units) {
|
|
412
|
+
return {
|
|
413
|
+
rawValue: Number(str) || defaultValue,
|
|
414
|
+
formatValue: str,
|
|
415
|
+
unit: '',
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
else if (typeof units == 'string') {
|
|
419
|
+
return {
|
|
420
|
+
rawValue: Number(str) || defaultValue,
|
|
421
|
+
formatValue: `${str}${units}`,
|
|
422
|
+
unit: units,
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
const unitList = units.map(([u, _s]) => u);
|
|
426
|
+
const scaleList = units.map(([_u, s]) => s);
|
|
427
|
+
let rawValue = defaultValue;
|
|
428
|
+
let formatValue = `${scaleList[0]}`;
|
|
429
|
+
let unit = unitList[0];
|
|
430
|
+
const m = str.match(/^(-?\d+(\.\d+)?)\s*(\w*)$/);
|
|
431
|
+
if (m) {
|
|
432
|
+
rawValue = Number(m[1]) || 0;
|
|
433
|
+
const inputUnit = m[3];
|
|
434
|
+
if (inputUnit != '' && unitList.indexOf(inputUnit) != -1) {
|
|
435
|
+
rawValue *= scaleList[unitList.indexOf(inputUnit)];
|
|
436
|
+
const s = selectUnit(units, rawValue);
|
|
437
|
+
const v = rawValue / s[1];
|
|
438
|
+
formatValue = `${digit != undefined ? toFixed$1(v, digit) : v}${s[0]}`;
|
|
439
|
+
unit = s[0];
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
const [u, scale] = selectUnit(units, rawValue);
|
|
443
|
+
const v = rawValue / scale;
|
|
444
|
+
formatValue = `${digit != undefined ? toFixed$1(v, digit) : v}${u}`;
|
|
445
|
+
unit = u;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
rawValue: rawValue,
|
|
450
|
+
formatValue: formatValue,
|
|
451
|
+
unit: unit,
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Input with some useful functions for entering numerical values.
|
|
457
|
+
*/
|
|
458
|
+
function NumberInput(_a) {
|
|
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);
|
|
461
|
+
const calculatedStrict = units ? false : strict;
|
|
462
|
+
const { _active, _focus, _hover } = pseudo;
|
|
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: '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) => {
|
|
464
|
+
const v = event.currentTarget.value;
|
|
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);
|
|
467
|
+
if (onChange)
|
|
468
|
+
onChange(newValue, event);
|
|
469
|
+
}, onFocus: (event) => {
|
|
470
|
+
const v = event.currentTarget.value;
|
|
471
|
+
const parsed = parseValue(v, units, digit, defaultValue);
|
|
472
|
+
if (selectWithFocus == 'all') {
|
|
473
|
+
event.currentTarget.setSelectionRange(0, v.length);
|
|
474
|
+
}
|
|
475
|
+
else if (selectWithFocus == 'number') {
|
|
476
|
+
event.currentTarget.setSelectionRange(0, parsed.formatValue.length - parsed.unit.length);
|
|
477
|
+
}
|
|
478
|
+
if (onFocus)
|
|
479
|
+
onFocus(parsed.rawValue, event);
|
|
480
|
+
}, onBlur: (event) => {
|
|
481
|
+
// update value
|
|
482
|
+
const v = event.currentTarget.value;
|
|
483
|
+
const parsed = parseValue(v, units, digit, defaultValue);
|
|
484
|
+
setShowValue(parsed.formatValue);
|
|
485
|
+
if (onBlur)
|
|
486
|
+
onBlur(parsed.rawValue, event);
|
|
487
|
+
}, onKeyDown: (event) => {
|
|
488
|
+
if (blurWithEnter && event.key == 'Enter') {
|
|
489
|
+
event.currentTarget.blur();
|
|
490
|
+
}
|
|
491
|
+
} }));
|
|
492
|
+
}
|
|
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
|
+
|
|
501
|
+
function isHorizontal(d) {
|
|
502
|
+
return d == 'right' || d == 'left';
|
|
503
|
+
}
|
|
504
|
+
function isVertical(d) {
|
|
505
|
+
return d == 'up' || d == 'down';
|
|
506
|
+
}
|
|
507
|
+
function isReversed(d) {
|
|
508
|
+
return d == 'left' || d == 'up';
|
|
509
|
+
}
|
|
510
|
+
function gradientDirection(d) {
|
|
511
|
+
if (d == 'left' || d == 'right')
|
|
512
|
+
return d;
|
|
513
|
+
if (d == 'up')
|
|
514
|
+
return 'top';
|
|
515
|
+
if (d == 'down')
|
|
516
|
+
return 'bottom';
|
|
517
|
+
}
|
|
518
|
+
function parseScaleOrderList(scale, min, max, step) {
|
|
519
|
+
var _a;
|
|
520
|
+
let scalesList = [];
|
|
521
|
+
if (!scale) ;
|
|
522
|
+
else if (typeof scale[0] == 'object') {
|
|
523
|
+
scalesList = scale;
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
const per = scale[0] == 'step' ? step : scale[0];
|
|
527
|
+
const count = Math.floor(max / per) - Math.ceil(min / per) + 1;
|
|
528
|
+
for (let i = 0; i < count; i++) {
|
|
529
|
+
const at = toFixed(per * (Math.ceil(min / per) + i), (_a = decimalPart(per)) === null || _a === void 0 ? void 0 : _a.length);
|
|
530
|
+
scalesList.push({ at: at, type: scale[1] });
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return scalesList;
|
|
534
|
+
}
|
|
535
|
+
|
|
331
536
|
function SliderThumb({ color, children, style, __css, }) {
|
|
332
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) : (
|
|
333
538
|
// default slider thumb
|
|
334
539
|
jsxRuntime.jsx("div", { className: "tremolo-slider-thumb",
|
|
335
540
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
336
|
-
tabIndex: 0, css: react.css(Object.assign({ background: color, width: '1.4rem', height: '1.4rem', borderRadius: '50%'
|
|
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)) })) }));
|
|
337
546
|
}
|
|
338
547
|
|
|
339
548
|
function SliderTrack({ children, style, __css, }) {
|
|
@@ -348,10 +557,10 @@ function Slider(_a) {
|
|
|
348
557
|
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"]);
|
|
349
558
|
// -- state and ref ---
|
|
350
559
|
const trackElementRef = React.useRef(null);
|
|
351
|
-
const percent =
|
|
352
|
-
const percentRev =
|
|
353
|
-
const scalesList =
|
|
354
|
-
if (
|
|
560
|
+
const percent = normalizeValue(value, min, max, skew) * 100;
|
|
561
|
+
const percentRev = isReversed(direction) ? 100 - percent : percent;
|
|
562
|
+
const scalesList = parseScaleOrderList(scale, min, max, step);
|
|
563
|
+
if (isReversed(direction))
|
|
355
564
|
scalesList.reverse();
|
|
356
565
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
357
566
|
let trackProps;
|
|
@@ -387,11 +596,11 @@ function Slider(_a) {
|
|
|
387
596
|
const { left: x1, top: y1, right: x2, bottom: y2, } = trackElementRef.current.getBoundingClientRect();
|
|
388
597
|
const mouseX = isTouch ? event.touches[0].clientX : event.clientX;
|
|
389
598
|
const mouseY = isTouch ? event.touches[0].clientY : event.clientY;
|
|
390
|
-
const n =
|
|
391
|
-
?
|
|
392
|
-
:
|
|
393
|
-
const v =
|
|
394
|
-
const v2 =
|
|
599
|
+
const n = isHorizontal(direction)
|
|
600
|
+
? normalizeValue(mouseX, x1, x2)
|
|
601
|
+
: normalizeValue(mouseY, y1, y2);
|
|
602
|
+
const v = rawValue(isReversed(direction) ? 1 - n : n, min, max, skew);
|
|
603
|
+
const v2 = clamp(stepValue(v, step), min, max);
|
|
395
604
|
if (onChange)
|
|
396
605
|
onChange(v2);
|
|
397
606
|
};
|
|
@@ -402,18 +611,18 @@ function Slider(_a) {
|
|
|
402
611
|
return;
|
|
403
612
|
event.preventDefault();
|
|
404
613
|
let x = event.deltaY > 0 ? enableWheel[1] : -enableWheel[1];
|
|
405
|
-
if (
|
|
614
|
+
if (isReversed(direction) || isHorizontal(direction))
|
|
406
615
|
x *= -1;
|
|
407
616
|
let v;
|
|
408
617
|
if (enableWheel[0] == 'normalized') {
|
|
409
|
-
const n =
|
|
410
|
-
v =
|
|
618
|
+
const n = normalizeValue(value, min, max, skew);
|
|
619
|
+
v = rawValue(n + x, min, max, skew);
|
|
411
620
|
}
|
|
412
621
|
else {
|
|
413
622
|
v = value + x;
|
|
414
623
|
}
|
|
415
624
|
if (onChange)
|
|
416
|
-
onChange(
|
|
625
|
+
onChange(clamp(stepValue(v, step), min, max));
|
|
417
626
|
}, {
|
|
418
627
|
passive: false,
|
|
419
628
|
}, [enableWheel, value, min, max, skew, step]);
|
|
@@ -425,10 +634,10 @@ function Slider(_a) {
|
|
|
425
634
|
if (bodyNoSelect)
|
|
426
635
|
document.body.classList.remove('no-select');
|
|
427
636
|
});
|
|
428
|
-
return (jsxRuntime.jsxs("div", { className: 'tremolo-slider'
|
|
637
|
+
return (jsxRuntime.jsxs("div", { className: clsx('tremolo-slider', className), ref: (div) => {
|
|
429
638
|
wheelRefCallback(div);
|
|
430
639
|
touchMoveRefCallback(div);
|
|
431
|
-
}, tabIndex: -1, role: "slider", "aria-valuenow": value, "aria-valuemax": max, "aria-valuemin": min, "aria-orientation":
|
|
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) => {
|
|
432
641
|
thumbDragged.current = true;
|
|
433
642
|
handleValue(event);
|
|
434
643
|
}, children: [jsxRuntime.jsx(react.Global, { styles: {
|
|
@@ -437,54 +646,54 @@ function Slider(_a) {
|
|
|
437
646
|
},
|
|
438
647
|
} }), jsxRuntime.jsxs("div", { css: react.css({
|
|
439
648
|
display: 'flex',
|
|
440
|
-
flexDirection:
|
|
649
|
+
flexDirection: isHorizontal(direction) ? 'column' : 'row',
|
|
441
650
|
}), children: [jsxRuntime.jsxs("div", { className: "tremolo-slider-track-wrapper", ref: trackElementRef, css: react.css({ position: 'relative' }), children: [jsxRuntime.jsx(SliderTrack, Object.assign({ __css: {
|
|
442
|
-
background: `linear-gradient(to ${
|
|
443
|
-
borderRadius:
|
|
651
|
+
background: `linear-gradient(to ${gradientDirection(direction)}, ${color} ${percent}%, ${bg} ${percent}%)`,
|
|
652
|
+
borderRadius: styleHelper(thickness, '/', 2),
|
|
444
653
|
borderStyle: 'solid',
|
|
445
654
|
borderColor: '#ccc',
|
|
446
655
|
borderWidth: 2,
|
|
447
|
-
width:
|
|
448
|
-
height:
|
|
656
|
+
width: isHorizontal(direction) ? length : thickness,
|
|
657
|
+
height: isHorizontal(direction) ? thickness : length,
|
|
449
658
|
zIndex: 1,
|
|
450
659
|
} }, trackProps)), jsxRuntime.jsx(SliderThumb, Object.assign({ color: color, __css: {
|
|
451
|
-
top:
|
|
452
|
-
left:
|
|
453
|
-
} }, thumbProps))] }), scale && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-wrapper", css: react.css(Object.assign({ position: 'relative', width:
|
|
660
|
+
top: isHorizontal(direction) ? '50%' : `${percentRev}%`,
|
|
661
|
+
left: isHorizontal(direction) ? `${percentRev}%` : '50%',
|
|
662
|
+
} }, 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)
|
|
454
663
|
? 2
|
|
455
|
-
: ((_b = scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.gap) !== null && _b !== void 0 ? _b : `calc((1.4rem - ${
|
|
664
|
+
: ((_b = scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.gap) !== null && _b !== void 0 ? _b : `calc((1.4rem - ${styleHelper(thickness)}) / 2)`), marginTop: isVertical(direction)
|
|
456
665
|
? 2
|
|
457
|
-
: ((_c = scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.gap) !== null && _c !== void 0 ? _c : `calc((1.4rem - ${
|
|
666
|
+
: ((_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) => {
|
|
458
667
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
459
668
|
return (jsxRuntime.jsxs("div", { css: react.css({
|
|
460
669
|
display: 'flex',
|
|
461
|
-
flexDirection:
|
|
670
|
+
flexDirection: isHorizontal(direction) ? 'column' : 'row',
|
|
462
671
|
justifyContent: 'center',
|
|
463
672
|
alignItems: 'center',
|
|
464
673
|
position: 'absolute',
|
|
465
|
-
left:
|
|
466
|
-
? `${
|
|
467
|
-
? 100 -
|
|
468
|
-
:
|
|
674
|
+
left: isHorizontal(direction)
|
|
675
|
+
? `${isReversed(direction)
|
|
676
|
+
? 100 - normalizeValue(item.at, min, max, skew) * 100
|
|
677
|
+
: normalizeValue(item.at, min, max, skew) * 100}%`
|
|
469
678
|
: undefined,
|
|
470
|
-
top:
|
|
471
|
-
? `${
|
|
472
|
-
? 100 -
|
|
473
|
-
:
|
|
679
|
+
top: isVertical(direction)
|
|
680
|
+
? `${isReversed(direction)
|
|
681
|
+
? 100 - normalizeValue(item.at, min, max, skew) * 100
|
|
682
|
+
: normalizeValue(item.at, min, max, skew) * 100}%`
|
|
474
683
|
: undefined,
|
|
475
|
-
translate:
|
|
684
|
+
translate: isHorizontal(direction) ? '-50% 0' : '0 -50%',
|
|
476
685
|
zIndex: 10,
|
|
477
686
|
}), 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') !=
|
|
478
687
|
'number' && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-mark", css: react.css({
|
|
479
|
-
width:
|
|
688
|
+
width: isHorizontal(direction)
|
|
480
689
|
? ((_d = (_c = item.style) === null || _c === void 0 ? void 0 : _c.thickness) !== null && _d !== void 0 ? _d : 1)
|
|
481
690
|
: ((_f = (_e = item.style) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : '0.5rem'),
|
|
482
|
-
height:
|
|
691
|
+
height: isVertical(direction)
|
|
483
692
|
? ((_h = (_g = item.style) === null || _g === void 0 ? void 0 : _g.thickness) !== null && _h !== void 0 ? _h : 1)
|
|
484
693
|
: ((_k = (_j = item.style) === null || _j === void 0 ? void 0 : _j.length) !== null && _k !== void 0 ? _k : '0.5rem'),
|
|
485
694
|
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',
|
|
486
|
-
marginBottom:
|
|
487
|
-
marginRight:
|
|
695
|
+
marginBottom: isHorizontal(direction) ? 2 : undefined,
|
|
696
|
+
marginRight: isVertical(direction) ? 2 : undefined,
|
|
488
697
|
}) })), ((_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') !=
|
|
489
698
|
'mark' && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-number", css: react.css({
|
|
490
699
|
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,
|
|
@@ -494,12 +703,11 @@ function Slider(_a) {
|
|
|
494
703
|
}) }))] })] }));
|
|
495
704
|
}
|
|
496
705
|
|
|
706
|
+
exports.AnimationCanvas = AnimationCanvas;
|
|
497
707
|
exports.Knob = Knob;
|
|
708
|
+
exports.NumberInput = NumberInput;
|
|
498
709
|
exports.Slider = Slider;
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
get: function () { return math[k]; }
|
|
503
|
-
});
|
|
504
|
-
});
|
|
710
|
+
exports.SliderThumb = SliderThumb;
|
|
711
|
+
exports.SliderTrack = SliderTrack;
|
|
712
|
+
exports.gradientDirection = gradientDirection;
|
|
505
713
|
//# sourceMappingURL=index.js.map
|