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