@tremolo-ui/react 0.0.7 → 0.0.8
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/dist/cjs/index.js +674 -253
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AnimationCanvas/index.d.ts +16 -9
- package/dist/cjs/types/components/AnimationCanvas/index.d.ts.map +1 -1
- package/dist/cjs/types/components/AnimationKnob/index.d.ts +53 -0
- package/dist/cjs/types/components/AnimationKnob/index.d.ts.map +1 -0
- package/dist/cjs/types/components/DragObserver/index.d.ts +19 -0
- package/dist/cjs/types/components/DragObserver/index.d.ts.map +1 -0
- package/dist/cjs/types/components/Knob/index.d.ts +26 -26
- package/dist/cjs/types/components/Knob/index.d.ts.map +1 -1
- package/dist/cjs/types/components/NumberInput/index.d.ts +2 -5
- package/dist/cjs/types/components/NumberInput/index.d.ts.map +1 -1
- package/dist/cjs/types/components/Piano/BlackKey.d.ts +3 -3
- package/dist/cjs/types/components/Piano/BlackKey.d.ts.map +1 -1
- package/dist/cjs/types/components/Piano/KeyLabel.d.ts +5 -8
- package/dist/cjs/types/components/Piano/KeyLabel.d.ts.map +1 -1
- package/dist/cjs/types/components/Piano/WhiteKey.d.ts +3 -3
- package/dist/cjs/types/components/Piano/WhiteKey.d.ts.map +1 -1
- package/dist/cjs/types/components/Piano/index.d.ts +3 -4
- package/dist/cjs/types/components/Piano/index.d.ts.map +1 -1
- package/dist/cjs/types/components/Piano/key.d.ts +4 -7
- package/dist/cjs/types/components/Piano/key.d.ts.map +1 -1
- package/dist/cjs/types/components/Piano/keyboardShortcuts.d.ts.map +1 -1
- package/dist/cjs/types/components/Slider/Scale.d.ts +11 -0
- package/dist/cjs/types/components/Slider/Scale.d.ts.map +1 -0
- package/dist/cjs/types/components/Slider/ScaleOption.d.ts +25 -0
- package/dist/cjs/types/components/Slider/ScaleOption.d.ts.map +1 -0
- package/dist/cjs/types/components/Slider/Thumb.d.ts +5 -13
- package/dist/cjs/types/components/Slider/Thumb.d.ts.map +1 -1
- package/dist/cjs/types/components/Slider/Track.d.ts +10 -21
- package/dist/cjs/types/components/Slider/Track.d.ts.map +1 -1
- package/dist/cjs/types/components/Slider/context.d.ts +21 -0
- package/dist/cjs/types/components/Slider/context.d.ts.map +1 -0
- package/dist/cjs/types/components/Slider/index.d.ts +18 -12
- package/dist/cjs/types/components/Slider/index.d.ts.map +1 -1
- package/dist/cjs/types/components/WheelObserver/index.d.ts +24 -0
- package/dist/cjs/types/components/WheelObserver/index.d.ts.map +1 -0
- package/dist/cjs/types/components/XYPad/Area.d.ts +13 -0
- package/dist/cjs/types/components/XYPad/Area.d.ts.map +1 -0
- package/dist/cjs/types/components/XYPad/Thumb.d.ts +19 -0
- package/dist/cjs/types/components/XYPad/Thumb.d.ts.map +1 -0
- package/dist/cjs/types/components/XYPad/index.d.ts +39 -0
- package/dist/cjs/types/components/XYPad/index.d.ts.map +1 -0
- package/dist/cjs/types/hooks/useCallbackRef.d.ts.map +1 -1
- package/dist/cjs/types/index.d.ts +10 -0
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/esm/index.js +657 -254
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AnimationCanvas/index.d.ts +16 -9
- package/dist/esm/types/components/AnimationCanvas/index.d.ts.map +1 -1
- package/dist/esm/types/components/AnimationKnob/index.d.ts +53 -0
- package/dist/esm/types/components/AnimationKnob/index.d.ts.map +1 -0
- package/dist/esm/types/components/DragObserver/index.d.ts +19 -0
- package/dist/esm/types/components/DragObserver/index.d.ts.map +1 -0
- package/dist/esm/types/components/Knob/index.d.ts +26 -26
- package/dist/esm/types/components/Knob/index.d.ts.map +1 -1
- package/dist/esm/types/components/NumberInput/index.d.ts +2 -5
- package/dist/esm/types/components/NumberInput/index.d.ts.map +1 -1
- package/dist/esm/types/components/Piano/BlackKey.d.ts +3 -3
- package/dist/esm/types/components/Piano/BlackKey.d.ts.map +1 -1
- package/dist/esm/types/components/Piano/KeyLabel.d.ts +5 -8
- package/dist/esm/types/components/Piano/KeyLabel.d.ts.map +1 -1
- package/dist/esm/types/components/Piano/WhiteKey.d.ts +3 -3
- package/dist/esm/types/components/Piano/WhiteKey.d.ts.map +1 -1
- package/dist/esm/types/components/Piano/index.d.ts +3 -4
- package/dist/esm/types/components/Piano/index.d.ts.map +1 -1
- package/dist/esm/types/components/Piano/key.d.ts +4 -7
- package/dist/esm/types/components/Piano/key.d.ts.map +1 -1
- package/dist/esm/types/components/Piano/keyboardShortcuts.d.ts.map +1 -1
- package/dist/esm/types/components/Slider/Scale.d.ts +11 -0
- package/dist/esm/types/components/Slider/Scale.d.ts.map +1 -0
- package/dist/esm/types/components/Slider/ScaleOption.d.ts +25 -0
- package/dist/esm/types/components/Slider/ScaleOption.d.ts.map +1 -0
- package/dist/esm/types/components/Slider/Thumb.d.ts +5 -13
- package/dist/esm/types/components/Slider/Thumb.d.ts.map +1 -1
- package/dist/esm/types/components/Slider/Track.d.ts +10 -21
- package/dist/esm/types/components/Slider/Track.d.ts.map +1 -1
- package/dist/esm/types/components/Slider/context.d.ts +21 -0
- package/dist/esm/types/components/Slider/context.d.ts.map +1 -0
- package/dist/esm/types/components/Slider/index.d.ts +18 -12
- package/dist/esm/types/components/Slider/index.d.ts.map +1 -1
- package/dist/esm/types/components/WheelObserver/index.d.ts +24 -0
- package/dist/esm/types/components/WheelObserver/index.d.ts.map +1 -0
- package/dist/esm/types/components/XYPad/Area.d.ts +13 -0
- package/dist/esm/types/components/XYPad/Area.d.ts.map +1 -0
- package/dist/esm/types/components/XYPad/Thumb.d.ts +19 -0
- package/dist/esm/types/components/XYPad/Thumb.d.ts.map +1 -0
- package/dist/esm/types/components/XYPad/index.d.ts +39 -0
- package/dist/esm/types/components/XYPad/index.d.ts.map +1 -0
- package/dist/esm/types/hooks/useCallbackRef.d.ts.map +1 -1
- package/dist/esm/types/index.d.ts +10 -0
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/styles/index.css +241 -0
- package/package.json +2 -5
- package/src/components/AnimationCanvas/index.tsx +87 -57
- package/src/components/AnimationKnob/index.tsx +305 -0
- package/src/components/DragObserver/index.tsx +94 -0
- package/src/components/Knob/index.css +48 -0
- package/src/components/Knob/index.tsx +152 -165
- package/src/components/NumberInput/index.css +25 -0
- package/src/components/NumberInput/index.tsx +8 -41
- package/src/components/Piano/BlackKey.tsx +104 -98
- package/src/components/Piano/KeyLabel.tsx +18 -40
- package/src/components/Piano/WhiteKey.tsx +92 -87
- package/src/components/Piano/index.css +63 -0
- package/src/components/Piano/index.tsx +76 -59
- package/src/components/Piano/key.ts +4 -7
- package/src/components/Piano/keyboardShortcuts.ts +23 -4
- package/src/components/Slider/Scale.tsx +55 -0
- package/src/components/Slider/ScaleOption.tsx +103 -0
- package/src/components/Slider/Thumb.tsx +69 -76
- package/src/components/Slider/Track.tsx +37 -48
- package/src/components/Slider/context.tsx +66 -0
- package/src/components/Slider/index.css +76 -0
- package/src/components/Slider/index.tsx +256 -298
- package/src/components/WheelObserver/index.tsx +47 -0
- package/src/components/XYPad/Area.tsx +40 -0
- package/src/components/XYPad/Thumb.tsx +92 -0
- package/src/components/XYPad/index.css +24 -0
- package/src/components/XYPad/index.tsx +317 -0
- package/src/hooks/useCallbackRef.ts +1 -0
- package/src/hooks/useRefCallbackEvent.ts +1 -0
- package/src/index.ts +11 -0
- package/dist/cjs/types/components/Slider/type.d.ts +0 -7
- package/dist/cjs/types/components/Slider/type.d.ts.map +0 -1
- package/dist/cjs/types/system/pseudo.d.ts +0 -14
- package/dist/cjs/types/system/pseudo.d.ts.map +0 -1
- package/dist/esm/types/components/Slider/type.d.ts +0 -7
- package/dist/esm/types/components/Slider/type.d.ts.map +0 -1
- package/dist/esm/types/system/pseudo.d.ts +0 -14
- package/dist/esm/types/system/pseudo.d.ts.map +0 -1
- package/src/components/Slider/type.ts +0 -16
- package/src/system/pseudo.ts +0 -55
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var jsxRuntime = require('
|
|
4
|
-
var react = require('@emotion/react');
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
4
|
var React = require('react');
|
|
6
5
|
|
|
7
6
|
/******************************************************************************
|
|
@@ -69,20 +68,17 @@ function setDprConfig(canvas, context, width, height, dpr) {
|
|
|
69
68
|
canvas.style.width = `${width}px`;
|
|
70
69
|
canvas.style.height = `${height}px`;
|
|
71
70
|
}
|
|
72
|
-
/**
|
|
73
|
-
* A simple animatable canvas with requestAnimationFrame()
|
|
74
|
-
*/
|
|
75
71
|
function AnimationCanvas(_a) {
|
|
76
|
-
var { width = 100, height = 100,
|
|
72
|
+
var { width = 100, height = 100, relativeSize = false, reduceFlickering = true, options, init, draw, className } = _a, props = __rest(_a, ["width", "height", "relativeSize", "reduceFlickering", "options", "init", "draw", "className"]);
|
|
77
73
|
const canvasRef = React.useRef(null);
|
|
78
74
|
const memoCanvasRef = React.useRef(null);
|
|
79
75
|
const reqIdRef = React.useRef();
|
|
80
76
|
const widthRef = React.useRef(0);
|
|
81
77
|
const heightRef = React.useRef(0);
|
|
82
|
-
const loop = (context, width, height, count) => {
|
|
78
|
+
const loop = React.useCallback((context, width, height, count) => {
|
|
83
79
|
reqIdRef.current = requestAnimationFrame(() => loop(context, width, height, count + 1));
|
|
84
80
|
draw(context, width, height, count + 1);
|
|
85
|
-
};
|
|
81
|
+
}, [draw]);
|
|
86
82
|
React.useEffect(() => {
|
|
87
83
|
if (!canvasRef.current)
|
|
88
84
|
return;
|
|
@@ -96,30 +92,34 @@ function AnimationCanvas(_a) {
|
|
|
96
92
|
if (!parent)
|
|
97
93
|
throw new Error("Canvas doesn't have a parent element.");
|
|
98
94
|
const memoCanvas = memoCanvasRef.current;
|
|
99
|
-
const memoContext = memoCanvas === null || memoCanvas ===
|
|
100
|
-
const resizeObserver = new ResizeObserver(() => {
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
for (const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
95
|
+
const memoContext = memoCanvas === null || memoCanvas === void 0 ? void 0 : memoCanvas.getContext('2d', options);
|
|
96
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
97
|
+
// TODO: If the parent element has no absolute height, the height increases infinitely.
|
|
98
|
+
// : 親要素に絶対的な高さを持たない場合、高さは無限に増加します。
|
|
99
|
+
// https://zenn.dev/megeton/articles/be1c677e174c84#%E6%A0%B9%E6%9C%AC%E7%9A%84%E3%81%AB-resizeobserver-loop-limit-exceeded-%E3%81%8C%E5%87%BA%E3%82%8B%E5%95%8F%E9%A1%8C%E3%81%AB%E5%90%91%E3%81%8D%E5%90%88%E3%81%86
|
|
100
|
+
for (const entry of entries) {
|
|
101
|
+
// Prevents loss of some context when the canvas is resized
|
|
102
|
+
const contextMemo = {};
|
|
103
|
+
for (const prop of drawingState) {
|
|
104
|
+
contextMemo[prop] = context[prop];
|
|
105
|
+
}
|
|
106
|
+
const w = Math.floor(entry.contentRect.width);
|
|
107
|
+
const h = Math.floor(entry.contentRect.height);
|
|
108
|
+
if (reduceFlickering && memoCanvas && memoContext) {
|
|
109
|
+
memoCanvas.width = w * dpr;
|
|
110
|
+
memoCanvas.height = h * dpr;
|
|
111
|
+
memoContext.scale(1 / dpr, 1 / dpr);
|
|
112
|
+
memoContext.drawImage(context.canvas, 0, 0);
|
|
113
|
+
}
|
|
114
|
+
setDprConfig(canvas, context, w, h, dpr);
|
|
115
|
+
widthRef.current = w;
|
|
116
|
+
heightRef.current = h;
|
|
117
|
+
for (const prop of drawingState) {
|
|
118
|
+
context[prop] = contextMemo[prop];
|
|
119
|
+
}
|
|
120
|
+
if (reduceFlickering && memoContext) {
|
|
121
|
+
context.drawImage(memoContext.canvas, 0, 0);
|
|
122
|
+
}
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
125
|
resizeObserver.observe(parent);
|
|
@@ -148,8 +148,8 @@ function AnimationCanvas(_a) {
|
|
|
148
148
|
cancelAnimationFrame(reqIdRef.current);
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
|
-
}, [loop]);
|
|
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,
|
|
151
|
+
}, [loop, init, options, reduceFlickering, relativeSize]);
|
|
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, ref: canvasRef }, props)), relativeSize && reduceFlickering && (jsxRuntime.jsx("canvas", { style: { display: 'none' }, ref: memoCanvasRef }))] }));
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
@@ -190,7 +190,7 @@ function stepValue(value, step) {
|
|
|
190
190
|
if (step <= 0)
|
|
191
191
|
throw new RangeError('requirements: step > 0');
|
|
192
192
|
const quotient = Math.floor(value / step);
|
|
193
|
-
const decimalDigits = (_a = decimalPart$1(step)) === null || _a ===
|
|
193
|
+
const decimalDigits = (_a = decimalPart$1(step)) === null || _a === void 0 ? void 0 : _a.length;
|
|
194
194
|
const v = toFixed$2(quotient * step, decimalDigits);
|
|
195
195
|
const next = toFixed$2((quotient + 1) * step, decimalDigits);
|
|
196
196
|
return Math.abs(value - v) < Math.abs(value - next) ? v : next;
|
|
@@ -246,12 +246,31 @@ function styleHelper(value, op, influencer) {
|
|
|
246
246
|
* @category Utility
|
|
247
247
|
*/
|
|
248
248
|
function mod(n, m) {
|
|
249
|
-
return ((
|
|
249
|
+
return ((n % m) + m) % m;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* @category Utility
|
|
253
|
+
*/
|
|
254
|
+
function xor(a = false, b = false) {
|
|
255
|
+
return (a || b) && a != b;
|
|
250
256
|
}
|
|
251
257
|
/**
|
|
252
258
|
* @category MIDI
|
|
253
259
|
*/
|
|
254
|
-
const noteNames = [
|
|
260
|
+
const noteNames = [
|
|
261
|
+
'C',
|
|
262
|
+
'C#',
|
|
263
|
+
'D',
|
|
264
|
+
'D#',
|
|
265
|
+
'E',
|
|
266
|
+
'F',
|
|
267
|
+
'F#',
|
|
268
|
+
'G',
|
|
269
|
+
'G#',
|
|
270
|
+
'A',
|
|
271
|
+
'A#',
|
|
272
|
+
'B',
|
|
273
|
+
];
|
|
255
274
|
/**
|
|
256
275
|
* @category MIDI
|
|
257
276
|
*/
|
|
@@ -271,7 +290,7 @@ function parseNoteName(noteName) {
|
|
|
271
290
|
* @category MIDI
|
|
272
291
|
*/
|
|
273
292
|
function noteNumber(noteName) {
|
|
274
|
-
const { letter, accidental, octave
|
|
293
|
+
const { letter, accidental, octave } = parseNoteName(noteName);
|
|
275
294
|
const noteIndex = noteNames.indexOf(letter.toLocaleUpperCase());
|
|
276
295
|
const accidentalValue = (accidental[0] == 'b' ? -1 : 1) * accidental.length;
|
|
277
296
|
return noteIndex + 12 * (Number(octave) + 1) + accidentalValue;
|
|
@@ -310,13 +329,14 @@ function useCallbackRef(callback, deps = []) {
|
|
|
310
329
|
React.useInsertionEffect(() => {
|
|
311
330
|
callbackRef.current = callback;
|
|
312
331
|
});
|
|
313
|
-
|
|
332
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
333
|
+
return React.useCallback((...args) => { var _a; return (_a = callbackRef.current) === null || _a === void 0 ? void 0 : _a.call(callbackRef, ...args); }, deps);
|
|
314
334
|
}
|
|
315
335
|
|
|
316
336
|
function useEventListener(target, event, handler, options) {
|
|
317
337
|
const listener = useCallbackRef(handler);
|
|
318
338
|
React.useEffect(() => {
|
|
319
|
-
const node = typeof target === 'function' ? target() : (target !== null && target !==
|
|
339
|
+
const node = typeof target === 'function' ? target() : (target !== null && target !== void 0 ? target : document);
|
|
320
340
|
if (!handler || !node)
|
|
321
341
|
return;
|
|
322
342
|
node.addEventListener(event, listener, options);
|
|
@@ -325,8 +345,8 @@ function useEventListener(target, event, handler, options) {
|
|
|
325
345
|
};
|
|
326
346
|
}, [event, target, options, listener, handler]);
|
|
327
347
|
return () => {
|
|
328
|
-
const node = typeof target === 'function' ? target() : (target !== null && target !==
|
|
329
|
-
node === null || node ===
|
|
348
|
+
const node = typeof target === 'function' ? target() : (target !== null && target !== void 0 ? target : document);
|
|
349
|
+
node === null || node === void 0 ? void 0 : node.removeEventListener(event, listener, options);
|
|
330
350
|
};
|
|
331
351
|
}
|
|
332
352
|
|
|
@@ -335,7 +355,7 @@ function useRefCallbackEvent(event, handler, options, deps = []) {
|
|
|
335
355
|
let cleanup;
|
|
336
356
|
return (node) => {
|
|
337
357
|
if (!node) {
|
|
338
|
-
cleanup === null || cleanup ===
|
|
358
|
+
cleanup === null || cleanup === void 0 ? void 0 : cleanup();
|
|
339
359
|
return;
|
|
340
360
|
}
|
|
341
361
|
node.addEventListener(event, handler, options);
|
|
@@ -343,6 +363,7 @@ function useRefCallbackEvent(event, handler, options, deps = []) {
|
|
|
343
363
|
node.removeEventListener(event, handler, options);
|
|
344
364
|
};
|
|
345
365
|
};
|
|
366
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
346
367
|
}, deps);
|
|
347
368
|
}
|
|
348
369
|
|
|
@@ -353,34 +374,17 @@ function removeNoSelect() {
|
|
|
353
374
|
document.body.classList.remove('tremolo-no-select');
|
|
354
375
|
}
|
|
355
376
|
|
|
356
|
-
const defaultOptions = {
|
|
357
|
-
active: '#7998ec',
|
|
358
|
-
inactive: '#eee',
|
|
359
|
-
bg: '#ccc',
|
|
360
|
-
thumb: '#4e76e6',
|
|
361
|
-
lineWeight: 6,
|
|
362
|
-
thumbWeight: 4,
|
|
363
|
-
};
|
|
364
377
|
/**
|
|
365
378
|
* simple rotary Knob.
|
|
366
379
|
*/
|
|
367
|
-
function
|
|
368
|
-
var { value, min, max, defaultValue = min, startValue = min, step = 1, skew = 1, size, width = 50, height = 50,
|
|
380
|
+
function AnimationKnob(_a) {
|
|
381
|
+
var { value, min, max, defaultValue = min, startValue = min, step = 1, skew = 1, size, width = 50, height = 50, activeColor = '#7998ec', inactiveColor = '#eee', bg = '#ccc', thumb = '#4e76e6', lineWeight = 6, thumbWeight = 4, draw, bodyNoSelect = true, wheel = ['raw', 1], keyboard = ['raw', 1], enableDoubleClickDefault = true, style, className, onChange } = _a, props = __rest(_a, ["value", "min", "max", "defaultValue", "startValue", "step", "skew", "size", "width", "height", "activeColor", "inactiveColor", "bg", "thumb", "lineWeight", "thumbWeight", "draw", "bodyNoSelect", "wheel", "keyboard", "enableDoubleClickDefault", "style", "className", "onChange"]);
|
|
369
382
|
// -- state and ref ---
|
|
370
383
|
// const [privateValue, setPrivateValue] = useState(value);
|
|
371
384
|
const dragOffsetY = React.useRef(undefined);
|
|
372
385
|
// --- interpret props ---
|
|
373
|
-
const opts = Object.assign(Object.assign({}, defaultOptions), options);
|
|
374
386
|
// const percent = normalizeValue(value, min, max, skew)
|
|
375
|
-
const isRelativeSize = typeof (size !== null && size !==
|
|
376
|
-
const adaptSize = (size) => {
|
|
377
|
-
if (typeof size == 'string') {
|
|
378
|
-
return Number(size.slice(0, -1));
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
return size;
|
|
382
|
-
}
|
|
383
|
-
};
|
|
387
|
+
const isRelativeSize = typeof (size !== null && size !== void 0 ? size : width) == 'string' || typeof height == 'string';
|
|
384
388
|
const handleEvent = (event) => {
|
|
385
389
|
const isTouch = event instanceof TouchEvent;
|
|
386
390
|
if (isTouch && event.cancelable)
|
|
@@ -390,6 +394,8 @@ function Knob(_a) {
|
|
|
390
394
|
addNoSelect();
|
|
391
395
|
const screenY = isTouch ? event.touches[0].screenY : event.screenY;
|
|
392
396
|
const delta = dragOffsetY.current - screenY;
|
|
397
|
+
if (Math.abs(delta) < 1)
|
|
398
|
+
return;
|
|
393
399
|
dragOffsetY.current = screenY;
|
|
394
400
|
const n = normalizeValue(value, min, max, skew);
|
|
395
401
|
const v = rawValue(n + delta / 100, min, max, skew);
|
|
@@ -398,6 +404,24 @@ function Knob(_a) {
|
|
|
398
404
|
onChange(v2);
|
|
399
405
|
}
|
|
400
406
|
};
|
|
407
|
+
const handleKeyDown = React.useCallback((event) => {
|
|
408
|
+
if (!keyboard || !onChange)
|
|
409
|
+
return;
|
|
410
|
+
const key = event.key;
|
|
411
|
+
if (['ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown'].includes(key)) {
|
|
412
|
+
event.preventDefault();
|
|
413
|
+
const x = key == 'ArrowRight' || key == 'ArrowUp' ? keyboard[1] : -keyboard[1];
|
|
414
|
+
let v;
|
|
415
|
+
if (keyboard[0] == 'normalized') {
|
|
416
|
+
const n = normalizeValue(value, min, max, skew);
|
|
417
|
+
v = rawValue(n + x, min, max, skew);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
v = value + x;
|
|
421
|
+
}
|
|
422
|
+
onChange(clamp(stepValue(v, step), min, max));
|
|
423
|
+
}
|
|
424
|
+
}, [value, min, max, step, skew, keyboard, onChange]);
|
|
401
425
|
// --- hooks ---
|
|
402
426
|
const wheelRefCallback = useRefCallbackEvent('wheel', (event) => {
|
|
403
427
|
if (!wheel)
|
|
@@ -422,24 +446,24 @@ function Knob(_a) {
|
|
|
422
446
|
if (bodyNoSelect)
|
|
423
447
|
removeNoSelect();
|
|
424
448
|
});
|
|
425
|
-
return (jsxRuntime.
|
|
449
|
+
return (jsxRuntime.jsx("div", Object.assign({ className: clsx('tremolo-animation-knob', className), ref: (div) => {
|
|
426
450
|
wheelRefCallback(div);
|
|
427
451
|
touchMoveRefCallback(div);
|
|
428
|
-
}, role: "slider", tabIndex: 0, "aria-valuenow": value, "aria-valuemax": max, "aria-valuemin": min,
|
|
452
|
+
}, role: "slider", tabIndex: 0, "aria-valuenow": value, "aria-valuemax": max, "aria-valuemin": min, style: Object.assign({ display: 'inline-block', width: size !== null && size !== void 0 ? size : width, height: size !== null && size !== void 0 ? size : height, cursor: 'pointer', WebkitTapHighlightColor: 'transparent' }, style), onPointerDown: (event) => {
|
|
429
453
|
dragOffsetY.current = event.screenY;
|
|
430
454
|
handleEvent(event);
|
|
431
455
|
}, onDoubleClick: () => {
|
|
432
456
|
if (enableDoubleClickDefault && onChange) {
|
|
433
457
|
onChange(defaultValue);
|
|
434
458
|
}
|
|
435
|
-
} }, props, { children:
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
459
|
+
}, onKeyDown: handleKeyDown, onContextMenu: (e) => e.preventDefault() }, props, { children: jsxRuntime.jsx(AnimationCanvas, Object.assign({}, (isRelativeSize
|
|
460
|
+
? { relativeSize: true }
|
|
461
|
+
: {
|
|
462
|
+
width: size !== null && size !== void 0 ? size : width,
|
|
463
|
+
height: size !== null && size !== void 0 ? size : height,
|
|
464
|
+
}), { draw: draw
|
|
465
|
+
? draw
|
|
466
|
+
: (ctx, width, height) => {
|
|
443
467
|
const p = normalizeValue(value, min, max, skew);
|
|
444
468
|
const startP = normalizeValue(startValue, min, max, skew);
|
|
445
469
|
const w = width.current, cx = w / 2;
|
|
@@ -452,33 +476,172 @@ function Knob(_a) {
|
|
|
452
476
|
ctx.lineCap = 'butt';
|
|
453
477
|
// bg
|
|
454
478
|
ctx.beginPath();
|
|
455
|
-
ctx.fillStyle =
|
|
479
|
+
ctx.fillStyle = bg;
|
|
456
480
|
ctx.arc(cx, cy, r - 0.5, 0, 2 * Math.PI);
|
|
457
481
|
ctx.fill();
|
|
458
|
-
ctx.
|
|
459
|
-
ctx.lineWidth = opts.lineWeight;
|
|
482
|
+
ctx.lineWidth = lineWeight;
|
|
460
483
|
// inactive rotary
|
|
461
484
|
ctx.beginPath();
|
|
462
|
-
ctx.strokeStyle =
|
|
463
|
-
ctx.arc(cx, cy, r - 0.5 -
|
|
485
|
+
ctx.strokeStyle = inactiveColor;
|
|
486
|
+
ctx.arc(cx, cy, r - 0.5 - lineWeight / 2, radian(135), radian(45));
|
|
464
487
|
ctx.stroke();
|
|
465
488
|
// active rotary
|
|
466
489
|
ctx.beginPath();
|
|
467
|
-
ctx.strokeStyle =
|
|
468
|
-
ctx.arc(cx, cy, r - 0.5 -
|
|
490
|
+
ctx.strokeStyle = activeColor;
|
|
491
|
+
ctx.arc(cx, cy, r - 0.5 - lineWeight / 2, radian(135 + 270 * startP), radian(135 + 270 * p), p < startP);
|
|
469
492
|
ctx.stroke();
|
|
470
493
|
// thumb
|
|
494
|
+
ctx.lineCap = 'round';
|
|
471
495
|
ctx.beginPath();
|
|
472
496
|
ctx.moveTo(cx, cy);
|
|
473
497
|
ctx.lineTo(cx +
|
|
474
498
|
Math.cos(radian(135 + 270 * p)) *
|
|
475
|
-
(r - 0.5 -
|
|
499
|
+
(r - 0.5 - thumbWeight / 2), cy +
|
|
476
500
|
Math.sin(radian(135 + 270 * p)) *
|
|
477
|
-
(r - 0.5 -
|
|
478
|
-
ctx.strokeStyle =
|
|
479
|
-
ctx.lineWidth =
|
|
501
|
+
(r - 0.5 - thumbWeight / 2));
|
|
502
|
+
ctx.strokeStyle = thumb;
|
|
503
|
+
ctx.lineWidth = thumbWeight;
|
|
480
504
|
ctx.stroke();
|
|
481
|
-
} })
|
|
505
|
+
} })) })));
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function DragObserver(props) {
|
|
509
|
+
const { children, onDrag, onDragStart, onDragEnd, as: Component = 'div' } = props, attributes = __rest(props, ["children", "onDrag", "onDragStart", "onDragEnd", "as"]);
|
|
510
|
+
const dragOffsetX = React.useRef(undefined);
|
|
511
|
+
const dragOffsetY = React.useRef(undefined);
|
|
512
|
+
const handleEvent = (event) => {
|
|
513
|
+
const isTouch = event instanceof TouchEvent;
|
|
514
|
+
if (isTouch && event.cancelable)
|
|
515
|
+
event.preventDefault();
|
|
516
|
+
const screenX = isTouch ? event.touches[0].screenX : event.screenX;
|
|
517
|
+
const screenY = isTouch ? event.touches[0].screenY : event.screenY;
|
|
518
|
+
let deltaX = 0, deltaY = 0;
|
|
519
|
+
if (dragOffsetX.current) {
|
|
520
|
+
deltaX = screenX - dragOffsetX.current;
|
|
521
|
+
dragOffsetX.current = screenX;
|
|
522
|
+
}
|
|
523
|
+
if (dragOffsetY.current) {
|
|
524
|
+
deltaY = screenY - dragOffsetY.current;
|
|
525
|
+
dragOffsetY.current = screenY;
|
|
526
|
+
}
|
|
527
|
+
if (Math.abs(deltaX) < 1 && Math.abs(deltaY) < 1)
|
|
528
|
+
return;
|
|
529
|
+
if (onDrag)
|
|
530
|
+
onDrag(deltaX, deltaY);
|
|
531
|
+
};
|
|
532
|
+
const touchMoveRefCallback = useRefCallbackEvent('touchmove', handleEvent, { passive: false }, [onDrag]);
|
|
533
|
+
useEventListener(window, 'mousemove', handleEvent);
|
|
534
|
+
useEventListener(window, 'pointerup', () => {
|
|
535
|
+
dragOffsetX.current = undefined;
|
|
536
|
+
dragOffsetY.current = undefined;
|
|
537
|
+
onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd();
|
|
538
|
+
});
|
|
539
|
+
return (jsxRuntime.jsx(Component, Object.assign({ ref: touchMoveRefCallback, onPointerDown: (event) => {
|
|
540
|
+
dragOffsetX.current = event.screenX;
|
|
541
|
+
dragOffsetY.current = event.screenY;
|
|
542
|
+
handleEvent(event);
|
|
543
|
+
onDragStart === null || onDragStart === void 0 ? void 0 : onDragStart();
|
|
544
|
+
} }, attributes, { children: children })));
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function Knob(_a) {
|
|
548
|
+
var { value, min, max, step = 1, skew = 1, defaultValue = min, startValue = min, size = 50, bodyNoSelect = true, wheel = ['raw', 1], keyboard = ['raw', 1], enableDoubleClickDefault = true, disabled = false, readonly = false, activeLine, inactiveLine, thumb, thumbLine, onChange, className, classes } = _a, props = __rest(_a, ["value", "min", "max", "step", "skew", "defaultValue", "startValue", "size", "bodyNoSelect", "wheel", "keyboard", "enableDoubleClickDefault", "disabled", "readonly", "activeLine", "inactiveLine", "thumb", "thumbLine", "onChange", "className", "classes"]);
|
|
549
|
+
// -- state and ref ---
|
|
550
|
+
const dragOffsetY = React.useRef(undefined);
|
|
551
|
+
// --- interpret props ---
|
|
552
|
+
const padding = 8; // %
|
|
553
|
+
const thumbLineWeight = 6; // %
|
|
554
|
+
const thumbLength = 35; // %
|
|
555
|
+
const lineWeight = 3; // px
|
|
556
|
+
const p = normalizeValue(value, min, max, skew);
|
|
557
|
+
const s = normalizeValue(startValue, min, max, skew);
|
|
558
|
+
// --- internal functions ---
|
|
559
|
+
const handleEvent = (event) => {
|
|
560
|
+
if (!onChange || readonly)
|
|
561
|
+
return;
|
|
562
|
+
const isTouch = event instanceof TouchEvent;
|
|
563
|
+
if (isTouch && event.cancelable)
|
|
564
|
+
event.preventDefault();
|
|
565
|
+
if (dragOffsetY.current) {
|
|
566
|
+
if (bodyNoSelect)
|
|
567
|
+
addNoSelect();
|
|
568
|
+
const screenY = isTouch ? event.touches[0].screenY : event.screenY;
|
|
569
|
+
const delta = dragOffsetY.current - screenY;
|
|
570
|
+
if (Math.abs(delta) < 1)
|
|
571
|
+
return;
|
|
572
|
+
dragOffsetY.current = screenY;
|
|
573
|
+
const n = normalizeValue(value, min, max, skew);
|
|
574
|
+
const v = rawValue(n + delta / 100, min, max, skew);
|
|
575
|
+
const v2 = clamp(stepValue(v, step), min, max);
|
|
576
|
+
onChange(v2);
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
const handleKeyDown = React.useCallback((event) => {
|
|
580
|
+
if (!keyboard || !onChange || readonly)
|
|
581
|
+
return;
|
|
582
|
+
const key = event.key;
|
|
583
|
+
if (['ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown'].includes(key)) {
|
|
584
|
+
event.preventDefault();
|
|
585
|
+
const x = key == 'ArrowRight' || key == 'ArrowUp' ? keyboard[1] : -keyboard[1];
|
|
586
|
+
let v;
|
|
587
|
+
if (keyboard[0] == 'normalized') {
|
|
588
|
+
const n = normalizeValue(value, min, max, skew);
|
|
589
|
+
v = rawValue(n + x, min, max, skew);
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
v = value + x;
|
|
593
|
+
}
|
|
594
|
+
onChange(clamp(stepValue(v, step), min, max));
|
|
595
|
+
}
|
|
596
|
+
}, [value, min, max, step, skew, keyboard, readonly, onChange]);
|
|
597
|
+
// --- hooks ---
|
|
598
|
+
const wheelRefCallback = useRefCallbackEvent('wheel', (event) => {
|
|
599
|
+
if (!wheel)
|
|
600
|
+
return;
|
|
601
|
+
event.preventDefault();
|
|
602
|
+
const x = event.deltaY > 0 ? -wheel[1] : wheel[1];
|
|
603
|
+
let v;
|
|
604
|
+
if (wheel[0] == 'normalized') {
|
|
605
|
+
const n = normalizeValue(value, min, max, skew);
|
|
606
|
+
v = rawValue(n + x, min, max, skew);
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
v = value + x;
|
|
610
|
+
}
|
|
611
|
+
if (onChange)
|
|
612
|
+
onChange(clamp(stepValue(v, step), min, max));
|
|
613
|
+
}, { passive: false }, [wheel, value, min, max, skew, step, onChange]);
|
|
614
|
+
const touchMoveRefCallback = useRefCallbackEvent('touchmove', handleEvent, { passive: false }, [value, min, max, skew, step, onChange, bodyNoSelect]);
|
|
615
|
+
useEventListener(window, 'mousemove', handleEvent);
|
|
616
|
+
useEventListener(window, 'pointerup', () => {
|
|
617
|
+
dragOffsetY.current = undefined;
|
|
618
|
+
if (bodyNoSelect)
|
|
619
|
+
removeNoSelect();
|
|
620
|
+
});
|
|
621
|
+
const center = size / 2;
|
|
622
|
+
const r1 = -135;
|
|
623
|
+
const r2 = -135 + Math.min(p, s) * 270;
|
|
624
|
+
const r3 = -135 + Math.max(p, s) * 270;
|
|
625
|
+
const r4 = 135;
|
|
626
|
+
const x1 = center + center * Math.cos(radian(r1 - 90));
|
|
627
|
+
const y1 = center + center * Math.sin(radian(r1 - 90));
|
|
628
|
+
const x2 = center + center * Math.cos(radian(r2 - 90));
|
|
629
|
+
const y2 = center + center * Math.sin(radian(r2 - 90));
|
|
630
|
+
const x3 = center + center * Math.cos(radian(r3 - 90));
|
|
631
|
+
const y3 = center + center * Math.sin(radian(r3 - 90));
|
|
632
|
+
const x4 = center + center * Math.cos(radian(r4 - 90));
|
|
633
|
+
const y4 = center + center * Math.sin(radian(r4 - 90));
|
|
634
|
+
return (jsxRuntime.jsxs("svg", Object.assign({ className: clsx('tremolo-knob', className), ref: (div) => {
|
|
635
|
+
wheelRefCallback(div);
|
|
636
|
+
touchMoveRefCallback(div);
|
|
637
|
+
}, width: size, height: size, tabIndex: 0, "aria-valuenow": value, "aria-valuemin": min, "aria-valuemax": max, "aria-disabled": disabled, "aria-readonly": readonly, onPointerDown: (event) => {
|
|
638
|
+
dragOffsetY.current = event.screenY;
|
|
639
|
+
handleEvent(event);
|
|
640
|
+
}, onDoubleClick: () => {
|
|
641
|
+
if (enableDoubleClickDefault && onChange) {
|
|
642
|
+
onChange(defaultValue);
|
|
643
|
+
}
|
|
644
|
+
}, onKeyDown: handleKeyDown, onContextMenu: (e) => e.preventDefault() }, props, { children: [startValue > min && (jsxRuntime.jsx("path", { className: clsx('tremolo-knob-inactive-line', classes === null || classes === void 0 ? void 0 : classes.inactiveLine), d: `M ${x1} ${y1} A ${center} ${center} -135 ${r2 - r1 > 180 ? 1 : 0} 1 ${x2}, ${y2}`, fill: "none", stroke: inactiveLine || 'currentColor', strokeWidth: lineWeight })), jsxRuntime.jsx("path", { className: clsx('tremolo-knob-active-line', classes === null || classes === void 0 ? void 0 : classes.activeLine), d: `M ${x2} ${y2} A ${center} ${center} -135 ${r3 - r2 > 180 ? 1 : 0} 1 ${x3}, ${y3}`, fill: "none", stroke: activeLine || 'currentColor', strokeWidth: lineWeight }), startValue < max && (jsxRuntime.jsx("path", { className: clsx('tremolo-knob-inactive-line', classes === null || classes === void 0 ? void 0 : classes.inactiveLine), d: `M ${x3} ${y3} A ${center} ${center} -135 ${r4 - r3 > 180 ? 1 : 0} 1 ${x4}, ${y4}`, fill: "none", stroke: inactiveLine || 'currentColor', strokeWidth: lineWeight })), jsxRuntime.jsxs("svg", { className: clsx('tremolo-knob-thumb', classes === null || classes === void 0 ? void 0 : classes.thumb), children: [jsxRuntime.jsx("circle", { cx: "50%", cy: "50%", r: `${50 - padding}%`, fill: thumb || 'currentColor' }), jsxRuntime.jsx("line", { className: clsx('tremolo-knob-thumb-line', classes === null || classes === void 0 ? void 0 : classes.thumbLine), x1: "50%", y1: `${padding}%`, x2: "50%", y2: `${thumbLength}%`, stroke: thumbLine || 'currentColor', strokeWidth: `${thumbLineWeight}%`, transform: `rotate(${ -135 + p * 270})`, "transform-origin": "50% 50%" })] })] })));
|
|
482
645
|
}
|
|
483
646
|
|
|
484
647
|
/**
|
|
@@ -495,7 +658,7 @@ function toFixed$1(x, fractionDigits) {
|
|
|
495
658
|
|
|
496
659
|
/**
|
|
497
660
|
* @module NumberInput
|
|
498
|
-
*/
|
|
661
|
+
*/
|
|
499
662
|
function selectUnit(units, value) {
|
|
500
663
|
if (typeof units == 'string')
|
|
501
664
|
return [units, 1];
|
|
@@ -558,14 +721,13 @@ function parseValue(inputString, units, digit, defaultValue = 0) {
|
|
|
558
721
|
* Input with some useful functions for entering numerical values.
|
|
559
722
|
*/
|
|
560
723
|
function NumberInput(_a) {
|
|
561
|
-
var { value, min, max, step, defaultValue = min, units, disabled = false, placeholder, readOnly, tabIndex, typeNumber = false, digit, selectWithFocus = 'none', blurWithEnter = true, className,
|
|
724
|
+
var { value, min, max, step, defaultValue = min, units, disabled = false, placeholder, readOnly, tabIndex, typeNumber = false, digit, selectWithFocus = 'none', blurWithEnter = true, className, onChange, onFocus, onBlur } = _a, props = __rest(_a, ["value", "min", "max", "step", "defaultValue", "units", "disabled", "placeholder", "readOnly", "tabIndex", "typeNumber", "digit", "selectWithFocus", "blurWithEnter", "className", "onChange", "onFocus", "onBlur"]);
|
|
562
725
|
const [showValue, setShowValue] = React.useState(parseValue(String(value), units, digit, defaultValue).formatValue);
|
|
563
726
|
const calculatedTypeNumber = units ? false : typeNumber;
|
|
564
|
-
|
|
565
|
-
return (jsxRuntime.jsx("input", Object.assign({ className: clsx('tremolo-number-input', className), value: showValue, min: min, max: max, step: step, type: calculatedTypeNumber ? 'number' : 'text', spellCheck: 'false', disabled: disabled, placeholder: placeholder, readOnly: readOnly, tabIndex: tabIndex, css: react.css(Object.assign(Object.assign({ display: 'inline-block', font: 'inherit', margin: 0, paddingTop: 6, paddingBottom: 6, paddingLeft: 10, paddingRight: 10, borderStyle: 'solid', borderWidth: 1, borderColor: '#bbb', borderRadius: 4, outline: 0, transition: 'all 0.1s linear', appearance: 'textfield', '&:hover': Object.assign({ borderColor: 'var(--tremolo-theme-color)' }, _hover), '&:focus': Object.assign({ borderColor: 'var(--tremolo-theme-color)', boxShadow: '0px 0px 0px 2px rgba(var(--tremolo-theme-color-rgb), 0.1)' }, _focus) }, (_active && { '&:active': Object.assign({}, _active) })), style)), onChange: (event) => {
|
|
727
|
+
return (jsxRuntime.jsx("input", Object.assign({ className: clsx('tremolo-number-input', className), value: showValue, min: min, max: max, step: step, type: calculatedTypeNumber ? 'number' : 'text', spellCheck: 'false', disabled: disabled, placeholder: placeholder, readOnly: readOnly, tabIndex: tabIndex, onChange: (event) => {
|
|
566
728
|
const v = event.currentTarget.value;
|
|
567
729
|
setShowValue(v);
|
|
568
|
-
const newValue = clamp(parseValue(v, units, digit, defaultValue).rawValue, min !== null && min !==
|
|
730
|
+
const newValue = clamp(parseValue(v, units, digit, defaultValue).rawValue, min !== null && min !== void 0 ? min : -Infinity, max !== null && max !== void 0 ? max : Infinity);
|
|
569
731
|
if (onChange)
|
|
570
732
|
onChange(newValue, event);
|
|
571
733
|
}, onFocus: (event) => {
|
|
@@ -590,16 +752,19 @@ function NumberInput(_a) {
|
|
|
590
752
|
if (blurWithEnter && event.key == 'Enter') {
|
|
591
753
|
event.currentTarget.blur();
|
|
592
754
|
}
|
|
593
|
-
} },
|
|
755
|
+
} }, props)));
|
|
594
756
|
}
|
|
595
757
|
|
|
596
|
-
function KeyLabel(
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
758
|
+
function KeyLabel(_a) {
|
|
759
|
+
var { label, className, wrapperClassName, wrapperStyle, __note, __index, __label } = _a, props = __rest(_a, ["label", "className", "wrapperClassName", "wrapperStyle", "__note", "__index", "__label"]);
|
|
760
|
+
const content = label
|
|
761
|
+
? label(__note, __index)
|
|
762
|
+
: __label && __label(__note, __index);
|
|
763
|
+
return ((content != undefined || content != null) && (jsxRuntime.jsx("div", { className: clsx('tremolo-piano-key-label-wrapper', wrapperClassName), style: wrapperStyle, children: jsxRuntime.jsx("div", Object.assign({ className: clsx('tremolo-piano-key-label', className) }, props, { children: content })) })));
|
|
600
764
|
}
|
|
601
765
|
|
|
602
|
-
const
|
|
766
|
+
const BlackKey = React.forwardRef((_a, ref) => {
|
|
767
|
+
var { width = 40 * 0.65, height = '60%', className, style, children, __glissando, __position, __note, __disabled, __index, __fill, __width, __playNote, __stopNote, __label } = _a, props = __rest(_a, ["width", "height", "className", "style", "children", "__glissando", "__position", "__note", "__disabled", "__index", "__fill", "__width", "__playNote", "__stopNote", "__label"]);
|
|
603
768
|
const [played, setPlayed] = React.useState(false);
|
|
604
769
|
React.useImperativeHandle(ref, () => {
|
|
605
770
|
return {
|
|
@@ -617,11 +782,10 @@ const WhiteKey = React.forwardRef(({ width = 40, height = '100%', bg = 'white',
|
|
|
617
782
|
},
|
|
618
783
|
played() {
|
|
619
784
|
return played;
|
|
620
|
-
}
|
|
785
|
+
},
|
|
621
786
|
};
|
|
622
|
-
}, []);
|
|
623
|
-
|
|
624
|
-
let keyLabelProps;
|
|
787
|
+
}, [__disabled, __note, __playNote, __stopNote, played]);
|
|
788
|
+
let keyLabelProps = {};
|
|
625
789
|
if (children != undefined) {
|
|
626
790
|
React.Children.forEach(children, (child) => {
|
|
627
791
|
if (React.isValidElement(child)) {
|
|
@@ -637,7 +801,7 @@ const WhiteKey = React.forwardRef(({ width = 40, height = '100%', bg = 'white',
|
|
|
637
801
|
}
|
|
638
802
|
});
|
|
639
803
|
}
|
|
640
|
-
return (jsxRuntime.jsx("div", { className: `tremolo-piano-
|
|
804
|
+
return (jsxRuntime.jsx("div", Object.assign({ className: clsx(`tremolo-piano-black-key`, className), "aria-disabled": __disabled, "data-active": played, style: Object.assign({ left: __position, width: __fill ? __width : (width !== null && width !== void 0 ? width : __width), height: height }, style), onPointerDown: () => {
|
|
641
805
|
if (__disabled)
|
|
642
806
|
return;
|
|
643
807
|
setPlayed(true);
|
|
@@ -663,10 +827,11 @@ const WhiteKey = React.forwardRef(({ width = 40, height = '100%', bg = 'white',
|
|
|
663
827
|
setPlayed(false);
|
|
664
828
|
if (__stopNote)
|
|
665
829
|
__stopNote(__note);
|
|
666
|
-
}, children: jsxRuntime.jsx(KeyLabel, Object.assign({ __note: __note, __label: __label, __index: __index }, keyLabelProps)) }));
|
|
830
|
+
} }, props, { children: jsxRuntime.jsx(KeyLabel, Object.assign({ __note: __note, __label: __label, __index: __index }, keyLabelProps)) })));
|
|
667
831
|
});
|
|
668
832
|
|
|
669
|
-
const
|
|
833
|
+
const WhiteKey = React.forwardRef((_a, ref) => {
|
|
834
|
+
var { width = 40, height = '100%', className, style, children, __glissando, __position, __note, __disabled, __index, __fill, __width, __playNote, __stopNote, __label } = _a, props = __rest(_a, ["width", "height", "className", "style", "children", "__glissando", "__position", "__note", "__disabled", "__index", "__fill", "__width", "__playNote", "__stopNote", "__label"]);
|
|
670
835
|
const [played, setPlayed] = React.useState(false);
|
|
671
836
|
React.useImperativeHandle(ref, () => {
|
|
672
837
|
return {
|
|
@@ -684,11 +849,10 @@ const BlackKey = React.forwardRef(({ width = 40 * 0.65, height = '60%', bg = '#3
|
|
|
684
849
|
},
|
|
685
850
|
played() {
|
|
686
851
|
return played;
|
|
687
|
-
}
|
|
852
|
+
},
|
|
688
853
|
};
|
|
689
|
-
}, []);
|
|
690
|
-
|
|
691
|
-
let keyLabelProps;
|
|
854
|
+
}, [__disabled, __note, __playNote, __stopNote, played]);
|
|
855
|
+
let keyLabelProps = {};
|
|
692
856
|
if (children != undefined) {
|
|
693
857
|
React.Children.forEach(children, (child) => {
|
|
694
858
|
if (React.isValidElement(child)) {
|
|
@@ -704,7 +868,7 @@ const BlackKey = React.forwardRef(({ width = 40 * 0.65, height = '60%', bg = '#3
|
|
|
704
868
|
}
|
|
705
869
|
});
|
|
706
870
|
}
|
|
707
|
-
return (jsxRuntime.jsx("div", { className: `tremolo-piano-
|
|
871
|
+
return (jsxRuntime.jsx("div", Object.assign({ className: clsx(`tremolo-piano-white-key`, className), "aria-disabled": __disabled, "data-active": played, style: Object.assign({ left: __position, width: __fill ? __width : (width !== null && width !== void 0 ? width : __width), height: height }, style), onPointerDown: () => {
|
|
708
872
|
if (__disabled)
|
|
709
873
|
return;
|
|
710
874
|
setPlayed(true);
|
|
@@ -730,16 +894,35 @@ const BlackKey = React.forwardRef(({ width = 40 * 0.65, height = '60%', bg = '#3
|
|
|
730
894
|
setPlayed(false);
|
|
731
895
|
if (__stopNote)
|
|
732
896
|
__stopNote(__note);
|
|
733
|
-
}, children: jsxRuntime.jsx(KeyLabel, Object.assign({ __note: __note, __label: __label, __index: __index }, keyLabelProps)) }));
|
|
897
|
+
} }, props, { children: jsxRuntime.jsx(KeyLabel, Object.assign({ __note: __note, __label: __label, __index: __index }, keyLabelProps)) })));
|
|
734
898
|
});
|
|
735
899
|
|
|
736
900
|
const Shortcuts = {
|
|
737
901
|
HOME_ROW: {
|
|
738
|
-
keys: [
|
|
739
|
-
|
|
902
|
+
keys: [
|
|
903
|
+
'a',
|
|
904
|
+
'w',
|
|
905
|
+
's',
|
|
906
|
+
'e',
|
|
907
|
+
'd',
|
|
908
|
+
'f',
|
|
909
|
+
't',
|
|
910
|
+
'g',
|
|
911
|
+
'y',
|
|
912
|
+
'h',
|
|
913
|
+
'u',
|
|
914
|
+
'j',
|
|
915
|
+
'k',
|
|
916
|
+
'o',
|
|
917
|
+
'l',
|
|
918
|
+
'p',
|
|
919
|
+
';',
|
|
920
|
+
],
|
|
921
|
+
},
|
|
740
922
|
};
|
|
741
923
|
|
|
742
|
-
function Piano(
|
|
924
|
+
function Piano(_a) {
|
|
925
|
+
var { noteRange, glissando = true, midiMax = 127, keyboardShortcuts, fill = false, height = fill ? '100%' : 160, style, className, playNote, stopNote, label, children } = _a, props = __rest(_a, ["noteRange", "glissando", "midiMax", "keyboardShortcuts", "fill", "height", "style", "className", "playNote", "stopNote", "label", "children"]);
|
|
743
926
|
// -- state and ref ---
|
|
744
927
|
const [pressed, setPressed] = React.useState(false);
|
|
745
928
|
const [whiteNoteWidth, setWhiteNoteWidth] = React.useState(-1);
|
|
@@ -751,8 +934,7 @@ function Piano({ noteRange, glissando = true, midiMax = 127, keyboardShortcuts,
|
|
|
751
934
|
// --- interpret props ---
|
|
752
935
|
const noteRangeArray = Array.from({ length: noteRange.last - noteRange.first + 1 }, (_, i) => i + noteRange.first);
|
|
753
936
|
const whiteNoteCount = noteRangeArray.filter((v) => isWhiteKey(v)).length;
|
|
754
|
-
|
|
755
|
-
let whiteKeyProps, blackKeyProps;
|
|
937
|
+
let whiteKeyProps = {}, blackKeyProps = {};
|
|
756
938
|
if (children != undefined) {
|
|
757
939
|
React.Children.forEach(children, (child) => {
|
|
758
940
|
if (React.isValidElement(child)) {
|
|
@@ -812,9 +994,9 @@ function Piano({ noteRange, glissando = true, midiMax = 127, keyboardShortcuts,
|
|
|
812
994
|
resizeObserver.observe(parent);
|
|
813
995
|
}
|
|
814
996
|
else {
|
|
815
|
-
setWhiteNoteWidth((whiteKeyProps === null || whiteKeyProps ===
|
|
997
|
+
setWhiteNoteWidth((whiteKeyProps === null || whiteKeyProps === void 0 ? void 0 : whiteKeyProps.width) || 40);
|
|
816
998
|
}
|
|
817
|
-
}, []);
|
|
999
|
+
}, [fill, whiteKeyProps === null || whiteKeyProps === void 0 ? void 0 : whiteKeyProps.width, whiteNoteCount]);
|
|
818
1000
|
useEventListener(window, 'keydown', (e) => {
|
|
819
1001
|
var _a, _b, _c, _d;
|
|
820
1002
|
if (e.repeat)
|
|
@@ -823,8 +1005,8 @@ function Piano({ noteRange, glissando = true, midiMax = 127, keyboardShortcuts,
|
|
|
823
1005
|
return;
|
|
824
1006
|
const index = keyboardShortcuts.keys.indexOf(e.key);
|
|
825
1007
|
if (index != -1) {
|
|
826
|
-
if (!((_b = (_a = keyRefs.current[index]) === null || _a ===
|
|
827
|
-
(_d = (_c = keyRefs.current[index]) === null || _c ===
|
|
1008
|
+
if (!((_b = (_a = keyRefs.current[index]) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.played())) {
|
|
1009
|
+
(_d = (_c = keyRefs.current[index]) === null || _c === void 0 ? void 0 : _c.current) === null || _d === void 0 ? void 0 : _d.play();
|
|
828
1010
|
}
|
|
829
1011
|
}
|
|
830
1012
|
});
|
|
@@ -836,18 +1018,48 @@ function Piano({ noteRange, glissando = true, midiMax = 127, keyboardShortcuts,
|
|
|
836
1018
|
return;
|
|
837
1019
|
const index = keyboardShortcuts.keys.indexOf(e.key);
|
|
838
1020
|
if (index != -1) {
|
|
839
|
-
(_b = (_a = keyRefs.current[index]) === null || _a ===
|
|
1021
|
+
(_b = (_a = keyRefs.current[index]) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.stop();
|
|
840
1022
|
}
|
|
841
1023
|
});
|
|
842
|
-
return (jsxRuntime.jsx("div", { ref: pianoRef, className:
|
|
1024
|
+
return (jsxRuntime.jsx("div", Object.assign({ ref: pianoRef, className: clsx('tremolo-piano', className), style: Object.assign({ width: fill ? '100%' : undefined, height: height }, style), onPointerDown: (e) => {
|
|
1025
|
+
if (props.onPointerDown)
|
|
1026
|
+
props.onPointerDown(e);
|
|
843
1027
|
setPressed(true);
|
|
844
|
-
}, onPointerUp: () => {
|
|
1028
|
+
}, onPointerUp: (e) => {
|
|
1029
|
+
if (props.onPointerUp)
|
|
1030
|
+
props.onPointerUp(e);
|
|
845
1031
|
setPressed(false);
|
|
846
|
-
}, children: noteRangeArray.map((note, index) => {
|
|
847
|
-
return
|
|
848
|
-
}) }));
|
|
1032
|
+
} }, props, { children: noteRangeArray.map((note, index) => {
|
|
1033
|
+
return isWhiteKey(note) ? (jsxRuntime.jsx(WhiteKey, Object.assign({ ref: keyRefs.current[index], __glissando: glissando && pressed, __position: notePosition(note), __note: note, __disabled: note > midiMax, __index: index, __fill: fill, __width: whiteNoteWidth, __playNote: playNote, __stopNote: stopNote, __label: label }, whiteKeyProps), note)) : (jsxRuntime.jsx(BlackKey, Object.assign({ ref: keyRefs.current[index], __glissando: glissando && pressed, __position: notePosition(note), __note: note, __disabled: note > midiMax, __index: index, __fill: fill, __width: whiteNoteWidth * 0.65, __playNote: playNote, __stopNote: stopNote, __label: label }, blackKeyProps), note));
|
|
1034
|
+
}) })));
|
|
849
1035
|
}
|
|
850
1036
|
|
|
1037
|
+
const minContext = React.createContext(0);
|
|
1038
|
+
const maxContext = React.createContext(0);
|
|
1039
|
+
const stepContext = React.createContext(0);
|
|
1040
|
+
const skewContext = React.createContext(0);
|
|
1041
|
+
const verticalContext = React.createContext(false);
|
|
1042
|
+
const reverseContext = React.createContext(false);
|
|
1043
|
+
const disabledContext = React.createContext(false);
|
|
1044
|
+
function SliderValuesProvider({ min: _min, max: _max, step: _step, skew: _skew, vertical: _vertical, reverse: _reverse, disabled: _disabled, children, }) {
|
|
1045
|
+
const [min] = React.useState(_min);
|
|
1046
|
+
const [max] = React.useState(_max);
|
|
1047
|
+
const [step] = React.useState(_step);
|
|
1048
|
+
const [skew] = React.useState(_skew);
|
|
1049
|
+
const [vertical] = React.useState(_vertical);
|
|
1050
|
+
const [reverse] = React.useState(_reverse);
|
|
1051
|
+
const [disabled] = React.useState(_disabled);
|
|
1052
|
+
return (jsxRuntime.jsx(minContext.Provider, { value: min, children: jsxRuntime.jsx(maxContext.Provider, { value: max, children: jsxRuntime.jsx(stepContext.Provider, { value: step, children: jsxRuntime.jsx(skewContext.Provider, { value: skew, children: jsxRuntime.jsx(verticalContext.Provider, { value: vertical, children: jsxRuntime.jsx(reverseContext.Provider, { value: reverse, children: jsxRuntime.jsx(disabledContext.Provider, { value: disabled, children: children }) }) }) }) }) }) }));
|
|
1053
|
+
}
|
|
1054
|
+
const useMin = () => React.useContext(minContext);
|
|
1055
|
+
const useMax = () => React.useContext(maxContext);
|
|
1056
|
+
const useStep = () => React.useContext(stepContext);
|
|
1057
|
+
const useSkew = () => React.useContext(skewContext);
|
|
1058
|
+
const useVertical = () => React.useContext(verticalContext);
|
|
1059
|
+
// export const useSetVertical = () => useContext(setVerticalContext)
|
|
1060
|
+
const useReverse = () => React.useContext(reverseContext);
|
|
1061
|
+
const useDisabled = () => React.useContext(disabledContext);
|
|
1062
|
+
|
|
851
1063
|
/**
|
|
852
1064
|
* clamp value between min and max
|
|
853
1065
|
* @category Math
|
|
@@ -869,105 +1081,119 @@ function decimalPart(x) {
|
|
|
869
1081
|
|
|
870
1082
|
/**
|
|
871
1083
|
* @module Slider
|
|
872
|
-
*/
|
|
873
|
-
function
|
|
874
|
-
return d == 'right' || d == 'left';
|
|
875
|
-
}
|
|
876
|
-
function isVertical(d) {
|
|
877
|
-
return d == 'up' || d == 'down';
|
|
878
|
-
}
|
|
879
|
-
function isReversed(d) {
|
|
880
|
-
return d == 'left' || d == 'up';
|
|
881
|
-
}
|
|
882
|
-
function gradientDirection(d) {
|
|
883
|
-
if (d == 'left' || d == 'right')
|
|
884
|
-
return d;
|
|
885
|
-
if (d == 'up')
|
|
886
|
-
return 'top';
|
|
887
|
-
if (d == 'down')
|
|
888
|
-
return 'bottom';
|
|
889
|
-
}
|
|
890
|
-
function parseScaleOrderList(scale, min, max, step) {
|
|
1084
|
+
*/
|
|
1085
|
+
function generateOptionsList(options, min, max, step) {
|
|
891
1086
|
var _a;
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
const per = scale[0] == 'step' ? step : scale[0];
|
|
899
|
-
const count = Math.floor(max / per) - Math.ceil(min / per) + 1;
|
|
900
|
-
for (let i = 0; i < count; i++) {
|
|
901
|
-
const at = toFixed(per * (Math.ceil(min / per) + i), (_a = decimalPart(per)) === null || _a === undefined ? undefined : _a.length);
|
|
902
|
-
scalesList.push({ at: at, type: scale[1] });
|
|
903
|
-
}
|
|
1087
|
+
const optionsList = [];
|
|
1088
|
+
const per = options[0] == 'step' ? step : options[0];
|
|
1089
|
+
const count = Math.floor(max / per) - Math.ceil(min / per) + 1;
|
|
1090
|
+
for (let i = 0; i < count; i++) {
|
|
1091
|
+
const value = toFixed(per * (Math.ceil(min / per) + i), (_a = decimalPart(per)) === null || _a === void 0 ? void 0 : _a.length);
|
|
1092
|
+
optionsList.push({ value: value, type: options[1] });
|
|
904
1093
|
}
|
|
905
|
-
return
|
|
1094
|
+
return optionsList;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
function ScaleOption(_a) {
|
|
1098
|
+
var { value, type = 'mark-number', label, thickness = 1, length = '0.5rem', gap = 2, labelWidth, classes, styles, className, style } = _a, props = __rest(_a, ["value", "type", "label", "thickness", "length", "gap", "labelWidth", "classes", "styles", "className", "style"]);
|
|
1099
|
+
const min = useMin();
|
|
1100
|
+
const max = useMax();
|
|
1101
|
+
const skew = useSkew();
|
|
1102
|
+
const vertical = useVertical();
|
|
1103
|
+
const reverse = useReverse();
|
|
1104
|
+
const calcPercent = React.useCallback((rawValue) => {
|
|
1105
|
+
return toFixed$2(xor(vertical, reverse)
|
|
1106
|
+
? 100 - normalizeValue(rawValue, min, max, skew) * 100
|
|
1107
|
+
: normalizeValue(rawValue, min, max, skew) * 100);
|
|
1108
|
+
}, [vertical, reverse, max, min, skew]);
|
|
1109
|
+
return (jsxRuntime.jsxs("div", Object.assign({ className: clsx('tremolo-slider-scale-option', className), style: Object.assign({ left: !vertical ? `${calcPercent(value)}%` : undefined, top: vertical ? `${calcPercent(value)}%` : undefined }, style), "data-vertical": vertical }, props, { children: [type != 'number' && (jsxRuntime.jsx("div", { className: clsx('tremolo-slider-scale-option-mark', classes === null || classes === void 0 ? void 0 : classes.mark), style: Object.assign({ width: !vertical ? thickness : length, height: vertical ? thickness : length, marginBottom: !vertical ? gap : undefined, marginRight: vertical ? gap : undefined }, styles === null || styles === void 0 ? void 0 : styles.mark), "data-vertical": vertical })), type != 'mark' && (jsxRuntime.jsx("div", { className: clsx('tremolo-slider-scale-option-label', classes === null || classes === void 0 ? void 0 : classes.label), style: Object.assign({ width: labelWidth }, styles === null || styles === void 0 ? void 0 : styles.label), children: label || value }))] })));
|
|
906
1110
|
}
|
|
907
1111
|
|
|
908
|
-
|
|
1112
|
+
function Scale(_a) {
|
|
1113
|
+
var { gap = 6, options, children, className, style } = _a, props = __rest(_a, ["gap", "options", "children", "className", "style"]);
|
|
1114
|
+
const min = useMin();
|
|
1115
|
+
const max = useMax();
|
|
1116
|
+
const step = useStep();
|
|
1117
|
+
const vertical = useVertical();
|
|
1118
|
+
const reverse = useReverse();
|
|
1119
|
+
const optionsList = options
|
|
1120
|
+
? generateOptionsList(options, min, max, step)
|
|
1121
|
+
: [];
|
|
1122
|
+
if (xor(vertical, reverse))
|
|
1123
|
+
optionsList.reverse();
|
|
1124
|
+
return (jsxRuntime.jsx("div", Object.assign({ className: clsx('tremolo-slider-scale', className), style: Object.assign({ marginLeft: vertical ? gap : undefined, marginTop: !vertical ? gap : undefined }, style) }, props, { children: options
|
|
1125
|
+
? optionsList.map(({ value, type }, index) => {
|
|
1126
|
+
return jsxRuntime.jsx(ScaleOption, { value: value, type: type }, index);
|
|
1127
|
+
})
|
|
1128
|
+
: children })));
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
const defaultThumbSize = 22;
|
|
1132
|
+
const SliderThumb = React.forwardRef(({ size, width = defaultThumbSize, height = defaultThumbSize, children, className, style, __percent, }, ref) => {
|
|
909
1133
|
const wrapperRef = React.useRef(null);
|
|
1134
|
+
const vertical = useVertical();
|
|
1135
|
+
const disabled = useDisabled();
|
|
910
1136
|
React.useImperativeHandle(ref, () => {
|
|
911
1137
|
return {
|
|
912
1138
|
focus() {
|
|
913
1139
|
var _a;
|
|
914
|
-
(_a = wrapperRef.current) === null || _a ===
|
|
1140
|
+
(_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
915
1141
|
},
|
|
916
1142
|
blur() {
|
|
917
1143
|
var _a;
|
|
918
|
-
(_a = wrapperRef.current) === null || _a ===
|
|
1144
|
+
(_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
919
1145
|
},
|
|
920
1146
|
};
|
|
921
1147
|
}, []);
|
|
922
|
-
return (jsxRuntime.jsx("div", { className: "tremolo-slider-thumb-wrapper",
|
|
1148
|
+
return (jsxRuntime.jsx("div", { className: "tremolo-slider-thumb-wrapper", style: {
|
|
1149
|
+
top: vertical ? `${__percent}%` : '50%',
|
|
1150
|
+
left: !vertical ? `${__percent}%` : '50%',
|
|
1151
|
+
}, children: children ? (children) : (
|
|
923
1152
|
// default slider thumb
|
|
924
1153
|
jsxRuntime.jsx("div", { ref: wrapperRef, className: clsx('tremolo-slider-thumb', className),
|
|
925
1154
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
926
|
-
tabIndex: 0,
|
|
927
|
-
background: __disabled ? disabledHoverColor : hoverColor
|
|
928
|
-
}, '&:focus': !__disabled && {
|
|
929
|
-
boxShadow: '0px 0px 0px 3px rgba(var(--tremolo-theme-color-rgb), 0.2)',
|
|
930
|
-
} }, style)) })) }));
|
|
1155
|
+
tabIndex: 0, "aria-disabled": disabled, style: Object.assign({ width: size !== null && size !== void 0 ? size : width, height: size !== null && size !== void 0 ? size : height }, style) })) }));
|
|
931
1156
|
});
|
|
932
1157
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
const
|
|
937
|
-
const
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
1158
|
+
const defaultLength = 140;
|
|
1159
|
+
const defaultThickness = 10;
|
|
1160
|
+
function SliderTrack({ length = defaultLength, thickness = defaultThickness, active, inactive, children, className, style, __thumb, __percent, }) {
|
|
1161
|
+
const vertical = useVertical();
|
|
1162
|
+
const reverse = useReverse();
|
|
1163
|
+
const disabled = useDisabled();
|
|
1164
|
+
const direction = vertical ? 'bottom' : 'right';
|
|
1165
|
+
const colors = {
|
|
1166
|
+
'--active': active,
|
|
1167
|
+
'--inactive': inactive,
|
|
1168
|
+
};
|
|
1169
|
+
return (jsxRuntime.jsxs("div", { className: clsx('tremolo-slider-track', className), "aria-disabled": disabled, style: Object.assign(Object.assign(Object.assign({}, colors), { background: xor(vertical, reverse)
|
|
1170
|
+
? `linear-gradient(to ${direction}, var(--inactive, #eee) ${__percent}%, var(--active, #7998ec) ${__percent}%)`
|
|
1171
|
+
: `linear-gradient(to ${direction}, var(--active, #7998ec) ${__percent}%, var(--inactive, #eee) ${__percent}%)`, borderRadius: styleHelper(thickness, '/', 2), width: !vertical ? length : thickness, height: vertical ? length : thickness }), style), children: [children, __thumb] }));
|
|
941
1172
|
}
|
|
942
1173
|
|
|
943
1174
|
/**
|
|
944
1175
|
* Customizable slider
|
|
945
1176
|
*/
|
|
946
1177
|
const Slider = React.forwardRef((_a, ref) => {
|
|
947
|
-
var _b, _c, _d
|
|
948
|
-
var { value, min, max, step = 1, skew = 1,
|
|
1178
|
+
var _b, _c, _d;
|
|
1179
|
+
var { value, min, max, step = 1, skew = 1, vertical = false, reverse = false, className, style, bodyNoSelect = true, wheel = ['raw', 1], keyboard = ['raw', 1], disabled = false, readonly = false, onChange, children } = _a, props = __rest(_a, ["value", "min", "max", "step", "skew", "vertical", "reverse", "className", "style", "bodyNoSelect", "wheel", "keyboard", "disabled", "readonly", "onChange", "children"]);
|
|
949
1180
|
// -- state and ref ---
|
|
950
1181
|
const trackElementRef = React.useRef(null);
|
|
951
1182
|
const thumbRef = React.useRef(null);
|
|
952
1183
|
const thumbDragged = React.useRef(false);
|
|
953
|
-
|
|
954
|
-
const
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
const scalesList = parseScaleOrderList(scale, min, max, step);
|
|
967
|
-
if (isReversed(direction))
|
|
968
|
-
scalesList.reverse();
|
|
969
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
970
|
-
let trackProps, thumbProps;
|
|
1184
|
+
// --- interpret props ---
|
|
1185
|
+
const p = toFixed$2(normalizeValue(value, min, max, skew) * 100);
|
|
1186
|
+
const rev = toFixed$2(100 - p);
|
|
1187
|
+
// NOTE
|
|
1188
|
+
// normal -> normal (right)
|
|
1189
|
+
// vertical -> rev (up)
|
|
1190
|
+
// reverse -> rev (left)
|
|
1191
|
+
// vertical & reverse -> normal (down)
|
|
1192
|
+
const displayReversed = React.useMemo(() => xor(vertical, reverse), [vertical, reverse]);
|
|
1193
|
+
const percent = displayReversed ? rev : p;
|
|
1194
|
+
let trackProps = {};
|
|
1195
|
+
let thumbProps = {};
|
|
1196
|
+
let scaleComponent = undefined;
|
|
971
1197
|
if (children != undefined) {
|
|
972
1198
|
React.Children.forEach(children, (child) => {
|
|
973
1199
|
if (React.isValidElement(child)) {
|
|
@@ -977,6 +1203,9 @@ const Slider = React.forwardRef((_a, ref) => {
|
|
|
977
1203
|
else if (child.type == SliderTrack) {
|
|
978
1204
|
trackProps = child.props;
|
|
979
1205
|
}
|
|
1206
|
+
else if (child.type == Scale) {
|
|
1207
|
+
scaleComponent = child;
|
|
1208
|
+
}
|
|
980
1209
|
else {
|
|
981
1210
|
throw new Error('only <SliderThumb> or <SliderTrack>');
|
|
982
1211
|
}
|
|
@@ -988,8 +1217,12 @@ const Slider = React.forwardRef((_a, ref) => {
|
|
|
988
1217
|
}
|
|
989
1218
|
// --- internal functions ---
|
|
990
1219
|
const handleValue = (event) => {
|
|
991
|
-
if (!trackElementRef.current ||
|
|
1220
|
+
if (!trackElementRef.current ||
|
|
1221
|
+
!thumbDragged.current ||
|
|
1222
|
+
!onChange ||
|
|
1223
|
+
readonly) {
|
|
992
1224
|
return;
|
|
1225
|
+
}
|
|
993
1226
|
const isTouch = event instanceof TouchEvent;
|
|
994
1227
|
if (isTouch && event.cancelable)
|
|
995
1228
|
event.preventDefault();
|
|
@@ -998,10 +1231,10 @@ const Slider = React.forwardRef((_a, ref) => {
|
|
|
998
1231
|
const { left: x1, top: y1, right: x2, bottom: y2, } = trackElementRef.current.getBoundingClientRect();
|
|
999
1232
|
const mouseX = isTouch ? event.touches[0].clientX : event.clientX;
|
|
1000
1233
|
const mouseY = isTouch ? event.touches[0].clientY : event.clientY;
|
|
1001
|
-
const n =
|
|
1002
|
-
? normalizeValue(
|
|
1003
|
-
: normalizeValue(
|
|
1004
|
-
const v = rawValue(
|
|
1234
|
+
const n = vertical
|
|
1235
|
+
? normalizeValue(mouseY, y1, y2)
|
|
1236
|
+
: normalizeValue(mouseX, x1, x2);
|
|
1237
|
+
const v = rawValue(displayReversed ? 1 - n : n, min, max, skew);
|
|
1005
1238
|
onChange(clamp(stepValue(v, step), min, max));
|
|
1006
1239
|
};
|
|
1007
1240
|
const handleKeyDown = React.useCallback((event) => {
|
|
@@ -1010,8 +1243,8 @@ const Slider = React.forwardRef((_a, ref) => {
|
|
|
1010
1243
|
const key = event.key;
|
|
1011
1244
|
if (['ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown'].includes(key)) {
|
|
1012
1245
|
event.preventDefault();
|
|
1013
|
-
let x =
|
|
1014
|
-
if (
|
|
1246
|
+
let x = key == 'ArrowRight' || key == 'ArrowUp' ? keyboard[1] : -keyboard[1];
|
|
1247
|
+
if (reverse)
|
|
1015
1248
|
x *= -1;
|
|
1016
1249
|
let v;
|
|
1017
1250
|
if (keyboard[0] == 'normalized') {
|
|
@@ -1023,15 +1256,23 @@ const Slider = React.forwardRef((_a, ref) => {
|
|
|
1023
1256
|
}
|
|
1024
1257
|
onChange(clamp(stepValue(v, step), min, max));
|
|
1025
1258
|
}
|
|
1026
|
-
}, [value, min, max, step, skew,
|
|
1259
|
+
}, [value, min, max, step, skew, reverse, keyboard, onChange, readonly]);
|
|
1027
1260
|
// --- hooks ---
|
|
1028
|
-
const touchMoveRefCallback = useRefCallbackEvent('touchmove', handleValue, { passive: false }, [min, max, skew, step,
|
|
1261
|
+
const touchMoveRefCallback = useRefCallbackEvent('touchmove', handleValue, { passive: false }, [min, max, skew, step, vertical, reverse, onChange, readonly]);
|
|
1029
1262
|
const wheelRefCallback = useRefCallbackEvent('wheel', (event) => {
|
|
1030
1263
|
if (!wheel || !onChange || readonly)
|
|
1031
1264
|
return;
|
|
1032
1265
|
event.preventDefault();
|
|
1033
|
-
let x
|
|
1034
|
-
if (
|
|
1266
|
+
let x;
|
|
1267
|
+
if (!vertical && event.deltaX != 0) {
|
|
1268
|
+
x = event.deltaX > 0 ? wheel[1] : -wheel[1];
|
|
1269
|
+
}
|
|
1270
|
+
else {
|
|
1271
|
+
if (event.deltaY == 0)
|
|
1272
|
+
return;
|
|
1273
|
+
x = event.deltaY > 0 ? -wheel[1] : wheel[1];
|
|
1274
|
+
}
|
|
1275
|
+
if (vertical && reverse)
|
|
1035
1276
|
x *= -1;
|
|
1036
1277
|
let v;
|
|
1037
1278
|
if (wheel[0] == 'normalized') {
|
|
@@ -1057,76 +1298,256 @@ const Slider = React.forwardRef((_a, ref) => {
|
|
|
1057
1298
|
return {
|
|
1058
1299
|
focus() {
|
|
1059
1300
|
var _a;
|
|
1060
|
-
(_a = thumbRef.current) === null || _a ===
|
|
1301
|
+
(_a = thumbRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
1302
|
+
},
|
|
1303
|
+
blur() {
|
|
1304
|
+
var _a;
|
|
1305
|
+
(_a = thumbRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
1306
|
+
},
|
|
1307
|
+
};
|
|
1308
|
+
}, []);
|
|
1309
|
+
return (jsxRuntime.jsx(SliderValuesProvider, { min: min, max: max, step: step, skew: skew, vertical: vertical, reverse: reverse, disabled: disabled, children: jsxRuntime.jsx("div", Object.assign({ className: clsx('tremolo-slider', className), ref: (div) => {
|
|
1310
|
+
wheelRefCallback(div);
|
|
1311
|
+
touchMoveRefCallback(div);
|
|
1312
|
+
}, tabIndex: -1, role: "slider", "aria-valuenow": value, "aria-valuemin": min, "aria-valuemax": max, "aria-orientation": vertical ? 'vertical' : 'horizontal', "aria-disabled": disabled, "aria-readonly": readonly, style: Object.assign({ margin: `calc(${styleHelper((_b = thumbProps === null || thumbProps === void 0 ? void 0 : thumbProps.size) !== null && _b !== void 0 ? _b : 22)} / 2)` }, style), onPointerDown: (event) => {
|
|
1313
|
+
thumbDragged.current = true;
|
|
1314
|
+
handleValue(event);
|
|
1315
|
+
}, onKeyDown: handleKeyDown, onFocus: (_c = thumbRef.current) === null || _c === void 0 ? void 0 : _c.focus, onBlur: (_d = thumbRef.current) === null || _d === void 0 ? void 0 : _d.blur }, props, { children: jsxRuntime.jsxs("div", { style: {
|
|
1316
|
+
display: 'flex',
|
|
1317
|
+
flexDirection: vertical ? 'row' : 'column',
|
|
1318
|
+
}, children: [jsxRuntime.jsx("div", { className: "tremolo-slider-track-wrapper", ref: trackElementRef, children: jsxRuntime.jsx(SliderTrack, Object.assign({ __percent: percent, __thumb: jsxRuntime.jsx(SliderThumb, Object.assign({ ref: thumbRef, __percent: percent }, thumbProps)) }, trackProps)) }), scaleComponent] }) })) }));
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
function WheelObserver(props) {
|
|
1322
|
+
const { children, onWheel, as: Component = 'div' } = props, attributes = __rest(props, ["children", "onWheel", "as"]);
|
|
1323
|
+
const wheelRefCallback = useRefCallbackEvent('wheel', (event) => {
|
|
1324
|
+
if (onWheel)
|
|
1325
|
+
onWheel(event);
|
|
1326
|
+
}, { passive: false }, [onWheel]);
|
|
1327
|
+
return (jsxRuntime.jsx(Component, Object.assign({ ref: wheelRefCallback }, attributes, { children: children })));
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
function XYPadArea({ width = 120, height = 120, bg = '#eee', children, className, style, __thumb, }) {
|
|
1331
|
+
return (jsxRuntime.jsxs("div", { className: clsx('tremolo-xy-pad-area', className), style: Object.assign({ position: 'relative', width: width, height: height, background: bg }, style), children: [children, __thumb] }));
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
const XYPadThumb = React.forwardRef(({ size, width = 22, height = 22, children, wrapperClassName, wrapperStyle, className, style, __disabled, __css, }, ref) => {
|
|
1335
|
+
const wrapperRef = React.useRef(null);
|
|
1336
|
+
React.useImperativeHandle(ref, () => {
|
|
1337
|
+
return {
|
|
1338
|
+
focus() {
|
|
1339
|
+
var _a;
|
|
1340
|
+
(_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
1061
1341
|
},
|
|
1062
1342
|
blur() {
|
|
1063
1343
|
var _a;
|
|
1064
|
-
(_a =
|
|
1344
|
+
(_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
1065
1345
|
},
|
|
1066
1346
|
};
|
|
1067
1347
|
}, []);
|
|
1068
|
-
return (jsxRuntime.
|
|
1348
|
+
return (jsxRuntime.jsx("div", { className: clsx('tremolo-xy-pad-thumb-wrapper', wrapperClassName), style: Object.assign(Object.assign({}, __css), wrapperStyle), children: children ? (children) : (
|
|
1349
|
+
// default thumb
|
|
1350
|
+
jsxRuntime.jsx("div", { ref: wrapperRef, className: clsx('tremolo-xy-pad-thumb', className),
|
|
1351
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
1352
|
+
tabIndex: 0, "aria-disabled": __disabled, style: Object.assign({ width: size !== null && size !== void 0 ? size : width, height: size !== null && size !== void 0 ? size : height }, style) })) }));
|
|
1353
|
+
});
|
|
1354
|
+
|
|
1355
|
+
const defaultValueOptions = {
|
|
1356
|
+
skew: 1,
|
|
1357
|
+
step: 1,
|
|
1358
|
+
reverse: false,
|
|
1359
|
+
wheel: ['raw', 1],
|
|
1360
|
+
keyboard: ['raw', 1],
|
|
1361
|
+
};
|
|
1362
|
+
/**
|
|
1363
|
+
* Simple XYPad
|
|
1364
|
+
*/
|
|
1365
|
+
const XYPad = React.forwardRef((_a, ref) => {
|
|
1366
|
+
var _b, _c, _d;
|
|
1367
|
+
var { x: _x, y: _y, className, style, bodyNoSelect = true, disabled = false, readonly = false, onChange, children } = _a, props = __rest(_a, ["x", "y", "className", "style", "bodyNoSelect", "disabled", "readonly", "onChange", "children"]);
|
|
1368
|
+
const x = React.useMemo(() => {
|
|
1369
|
+
return Object.assign(Object.assign({}, defaultValueOptions), _x);
|
|
1370
|
+
}, [_x]);
|
|
1371
|
+
const y = React.useMemo(() => {
|
|
1372
|
+
return Object.assign(Object.assign({}, defaultValueOptions), _y);
|
|
1373
|
+
}, [_y]);
|
|
1374
|
+
// -- state and ref ---
|
|
1375
|
+
const areaElementRef = React.useRef(null);
|
|
1376
|
+
const thumbRef = React.useRef(null);
|
|
1377
|
+
const thumbDragged = React.useRef(false);
|
|
1378
|
+
// --- interpret props ---
|
|
1379
|
+
const nx = normalizeValue(x.value, x.min, x.max, x.skew);
|
|
1380
|
+
const ny = normalizeValue(y.value, y.min, y.max, y.skew);
|
|
1381
|
+
const percentX = toFixed$2((x.reverse ? 1 - nx : nx) * 100);
|
|
1382
|
+
const percentY = toFixed$2((y.reverse ? 1 - ny : ny) * 100);
|
|
1383
|
+
let areaProps = {}, thumbProps = {};
|
|
1384
|
+
if (children != undefined) {
|
|
1385
|
+
React.Children.forEach(children, (child) => {
|
|
1386
|
+
if (React.isValidElement(child)) {
|
|
1387
|
+
if (child.type == XYPadThumb) {
|
|
1388
|
+
thumbProps = child.props;
|
|
1389
|
+
}
|
|
1390
|
+
else if (child.type == XYPadArea) {
|
|
1391
|
+
areaProps = child.props;
|
|
1392
|
+
}
|
|
1393
|
+
else {
|
|
1394
|
+
throw new Error('only <XYPadThumb> or <XYPadArea>');
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
else {
|
|
1398
|
+
throw new Error('children is an invalid element.');
|
|
1399
|
+
}
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
// --- internal functions ---
|
|
1403
|
+
const handleValue = (event) => {
|
|
1404
|
+
if (!areaElementRef.current ||
|
|
1405
|
+
!thumbDragged.current ||
|
|
1406
|
+
!onChange ||
|
|
1407
|
+
readonly)
|
|
1408
|
+
return;
|
|
1409
|
+
const isTouch = event instanceof TouchEvent;
|
|
1410
|
+
if (isTouch && event.cancelable)
|
|
1411
|
+
event.preventDefault();
|
|
1412
|
+
if (bodyNoSelect)
|
|
1413
|
+
addNoSelect();
|
|
1414
|
+
const { left: x1, top: y1, right: x2, bottom: y2, } = areaElementRef.current.getBoundingClientRect();
|
|
1415
|
+
const mouseX = isTouch ? event.touches[0].clientX : event.clientX;
|
|
1416
|
+
const mouseY = isTouch ? event.touches[0].clientY : event.clientY;
|
|
1417
|
+
const nx = normalizeValue(mouseX, x1, x2);
|
|
1418
|
+
const ny = normalizeValue(mouseY, y1, y2);
|
|
1419
|
+
const vx = rawValue(x.reverse ? 1 - nx : nx, x.min, x.max, x.skew);
|
|
1420
|
+
const vy = rawValue(y.reverse ? 1 - ny : ny, y.min, y.max, y.skew);
|
|
1421
|
+
const newX = clamp(stepValue(vx, x.step), x.min, x.max);
|
|
1422
|
+
const newY = clamp(stepValue(vy, y.step), y.min, y.max);
|
|
1423
|
+
onChange(newX, newY);
|
|
1424
|
+
};
|
|
1425
|
+
const handleKeyDown = React.useCallback((event) => {
|
|
1426
|
+
if (!onChange || readonly)
|
|
1427
|
+
return;
|
|
1428
|
+
const key = event.key;
|
|
1429
|
+
if (['ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown'].includes(key)) {
|
|
1430
|
+
const isHorizontal = key == 'ArrowRight' || key == 'ArrowLeft';
|
|
1431
|
+
const target = isHorizontal ? x : y;
|
|
1432
|
+
if (!target.keyboard)
|
|
1433
|
+
return;
|
|
1434
|
+
event.preventDefault();
|
|
1435
|
+
let delta = target.keyboard[1];
|
|
1436
|
+
if (key == 'ArrowLeft' || key == 'ArrowUp')
|
|
1437
|
+
delta *= -1;
|
|
1438
|
+
if (target.reverse)
|
|
1439
|
+
delta *= -1;
|
|
1440
|
+
let v;
|
|
1441
|
+
if (target.keyboard[0] == 'normalized') {
|
|
1442
|
+
const n = normalizeValue(target.value, target.min, target.max, target.skew);
|
|
1443
|
+
v = rawValue(n + delta, target.min, target.max, target.skew);
|
|
1444
|
+
}
|
|
1445
|
+
else {
|
|
1446
|
+
v = target.value + delta;
|
|
1447
|
+
}
|
|
1448
|
+
const newValue = clamp(stepValue(v, target.step), target.min, target.max);
|
|
1449
|
+
if (isHorizontal) {
|
|
1450
|
+
onChange(newValue, y.value);
|
|
1451
|
+
}
|
|
1452
|
+
else {
|
|
1453
|
+
onChange(x.value, newValue);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
}, [x, y, onChange, readonly]);
|
|
1457
|
+
// --- hooks ---
|
|
1458
|
+
const touchMoveRefCallback = useRefCallbackEvent('touchmove', handleValue, { passive: false }, [x, onChange, readonly]);
|
|
1459
|
+
const wheelRefCallback = useRefCallbackEvent('wheel', (event) => {
|
|
1460
|
+
if (!onChange || readonly)
|
|
1461
|
+
return;
|
|
1462
|
+
const target = event.shiftKey ? x : y;
|
|
1463
|
+
if (!target.wheel)
|
|
1464
|
+
return;
|
|
1465
|
+
event.preventDefault();
|
|
1466
|
+
let delta = target.wheel[1];
|
|
1467
|
+
if (event.deltaY < 0)
|
|
1468
|
+
delta *= -1;
|
|
1469
|
+
if (target.reverse)
|
|
1470
|
+
delta *= -1;
|
|
1471
|
+
let v;
|
|
1472
|
+
if (target.wheel[0] == 'normalized') {
|
|
1473
|
+
const n = normalizeValue(target.value, target.min, target.max, target.skew);
|
|
1474
|
+
v = rawValue(n + delta, target.min, target.max, target.skew);
|
|
1475
|
+
}
|
|
1476
|
+
else {
|
|
1477
|
+
v = target.value + delta;
|
|
1478
|
+
}
|
|
1479
|
+
const newValue = clamp(stepValue(v, target.step), target.min, target.max);
|
|
1480
|
+
if (event.shiftKey) {
|
|
1481
|
+
onChange(newValue, y.value);
|
|
1482
|
+
}
|
|
1483
|
+
else {
|
|
1484
|
+
onChange(x.value, newValue);
|
|
1485
|
+
}
|
|
1486
|
+
}, {
|
|
1487
|
+
passive: false,
|
|
1488
|
+
}, [x, y]);
|
|
1489
|
+
useEventListener(window, 'mousemove', (event) => {
|
|
1490
|
+
handleValue(event);
|
|
1491
|
+
});
|
|
1492
|
+
useEventListener(window, 'mouseup', () => {
|
|
1493
|
+
thumbDragged.current = false;
|
|
1494
|
+
if (bodyNoSelect)
|
|
1495
|
+
removeNoSelect();
|
|
1496
|
+
});
|
|
1497
|
+
React.useImperativeHandle(ref, () => {
|
|
1498
|
+
return {
|
|
1499
|
+
focus() {
|
|
1500
|
+
var _a;
|
|
1501
|
+
(_a = thumbRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
1502
|
+
},
|
|
1503
|
+
blur() {
|
|
1504
|
+
var _a;
|
|
1505
|
+
(_a = thumbRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
1506
|
+
},
|
|
1507
|
+
};
|
|
1508
|
+
}, []);
|
|
1509
|
+
return (
|
|
1510
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
1511
|
+
jsxRuntime.jsx("div", Object.assign({ className: clsx('tremolo-xy-pad', className), ref: (div) => {
|
|
1069
1512
|
wheelRefCallback(div);
|
|
1070
1513
|
touchMoveRefCallback(div);
|
|
1071
|
-
}, tabIndex: -1,
|
|
1514
|
+
}, tabIndex: -1, "aria-disabled": disabled, "aria-readonly": readonly, style: Object.assign({ margin: `calc(${styleHelper((_b = thumbProps === null || thumbProps === void 0 ? void 0 : thumbProps.size) !== null && _b !== void 0 ? _b : 22)} / 2)`, cursor: readonly ? 'not-allowed' : 'pointer', WebkitTapHighlightColor: 'transparent' }, style), onPointerDown: (event) => {
|
|
1072
1515
|
thumbDragged.current = true;
|
|
1073
1516
|
handleValue(event);
|
|
1074
|
-
}, onKeyDown: handleKeyDown, onFocus: (_c = thumbRef.current) === null || _c ===
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
},
|
|
1078
|
-
} }), jsxRuntime.jsxs("div", { css: react.css({
|
|
1079
|
-
display: 'flex',
|
|
1080
|
-
flexDirection: isHorizontal(direction) ? 'column' : 'row',
|
|
1081
|
-
}), children: [jsxRuntime.jsx("div", { className: "tremolo-slider-track-wrapper", ref: trackElementRef, children: jsxRuntime.jsx(SliderTrack, Object.assign({ __direction: direction, __disabled: disabled, __percent: percent, __thumb: jsxRuntime.jsx(SliderThumb, Object.assign({ ref: thumbRef, __disabled: disabled, __css: {
|
|
1082
|
-
top: isHorizontal(direction) ? '50%' : `${percentRev}%`,
|
|
1083
|
-
left: isHorizontal(direction) ? `${percentRev}%` : '50%',
|
|
1084
|
-
} }, thumbProps)) }, trackProps)) }), scale && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-wrapper", css: react.css(Object.assign({ display: 'block', position: 'relative', marginLeft: isVertical(direction)
|
|
1085
|
-
? ((_e = scaleOption === null || scaleOption === undefined ? undefined : scaleOption.gap) !== null && _e !== undefined ? _e : `calc((22px - ${styleHelper((_f = trackProps === null || trackProps === undefined ? undefined : trackProps.thickness) !== null && _f !== undefined ? _f : 10)}) / 2)`)
|
|
1086
|
-
: undefined, marginTop: isHorizontal(direction)
|
|
1087
|
-
? ((_g = scaleOption === null || scaleOption === undefined ? undefined : scaleOption.gap) !== null && _g !== undefined ? _g : `calc((22px - ${styleHelper((_h = trackProps === null || trackProps === undefined ? undefined : trackProps.thickness) !== null && _h !== undefined ? _h : 10)}) / 2)`)
|
|
1088
|
-
: undefined }, scaleOption === null || scaleOption === undefined ? undefined : scaleOption.style)), children: scalesList.map((item, index) => {
|
|
1089
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
1090
|
-
return (jsxRuntime.jsxs("div", { css: react.css({
|
|
1091
|
-
display: 'flex',
|
|
1092
|
-
flexDirection: isHorizontal(direction) ? 'column' : 'row',
|
|
1093
|
-
justifyContent: 'center',
|
|
1094
|
-
alignItems: 'center',
|
|
1095
|
-
position: 'absolute',
|
|
1096
|
-
left: isHorizontal(direction) ? `${calcPercent(item.at)}%` : undefined,
|
|
1097
|
-
top: isVertical(direction) ? `${calcPercent(item.at)}%` : undefined,
|
|
1098
|
-
translate: isHorizontal(direction) ? '-50% 0' : '0 -50%',
|
|
1099
|
-
zIndex: 10,
|
|
1100
|
-
}), children: [((_b = (_a = item.type) !== null && _a !== undefined ? _a : scaleOption === null || scaleOption === undefined ? undefined : scaleOption.defaultType) !== null && _b !== undefined ? _b : 'mark-number') !=
|
|
1101
|
-
'number' && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-mark", css: react.css({
|
|
1102
|
-
width: isHorizontal(direction)
|
|
1103
|
-
? ((_d = (_c = item.style) === null || _c === undefined ? undefined : _c.thickness) !== null && _d !== undefined ? _d : 1)
|
|
1104
|
-
: ((_f = (_e = item.style) === null || _e === undefined ? undefined : _e.length) !== null && _f !== undefined ? _f : '0.5rem'),
|
|
1105
|
-
height: isVertical(direction)
|
|
1106
|
-
? ((_h = (_g = item.style) === null || _g === undefined ? undefined : _g.thickness) !== null && _h !== undefined ? _h : 1)
|
|
1107
|
-
: ((_k = (_j = item.style) === null || _j === undefined ? undefined : _j.length) !== null && _k !== undefined ? _k : '0.5rem'),
|
|
1108
|
-
backgroundColor: (_o = (_m = (_l = item.style) === null || _l === undefined ? undefined : _l.markColor) !== null && _m !== undefined ? _m : scaleOption === null || scaleOption === undefined ? undefined : scaleOption.markColor) !== null && _o !== undefined ? _o : '#222',
|
|
1109
|
-
marginBottom: isHorizontal(direction) ? 2 : undefined,
|
|
1110
|
-
marginRight: isVertical(direction) ? 2 : undefined,
|
|
1111
|
-
}) })), ((_q = (_p = item.type) !== null && _p !== undefined ? _p : scaleOption === null || scaleOption === undefined ? undefined : scaleOption.defaultType) !== null && _q !== undefined ? _q : 'mark-number') !=
|
|
1112
|
-
'mark' && (jsxRuntime.jsx("div", { className: "tremolo-slider-scale-number", css: react.css({
|
|
1113
|
-
color: (_s = (_r = item.style) === null || _r === undefined ? undefined : _r.labelColor) !== null && _s !== undefined ? _s : scaleOption === null || scaleOption === undefined ? undefined : scaleOption.labelColor,
|
|
1114
|
-
width: scaleOption === null || scaleOption === undefined ? undefined : scaleOption.labelWidth,
|
|
1115
|
-
textAlign: 'right',
|
|
1116
|
-
}), children: (_t = item.text) !== null && _t !== undefined ? _t : item.at }))] }, index));
|
|
1117
|
-
}) }))] })] }));
|
|
1517
|
+
}, onKeyDown: handleKeyDown, onFocus: (_c = thumbRef.current) === null || _c === void 0 ? void 0 : _c.focus, onBlur: (_d = thumbRef.current) === null || _d === void 0 ? void 0 : _d.blur }, props, { children: jsxRuntime.jsx("div", { className: "tremolo-xy-pad-area-wrapper", ref: areaElementRef, children: jsxRuntime.jsx(XYPadArea, Object.assign({ __thumb: jsxRuntime.jsx(XYPadThumb, Object.assign({ ref: thumbRef, __disabled: disabled, __css: {
|
|
1518
|
+
top: `${percentY}%`,
|
|
1519
|
+
left: `${percentX}%`,
|
|
1520
|
+
} }, thumbProps)) }, areaProps)) }) })));
|
|
1118
1521
|
});
|
|
1119
1522
|
|
|
1120
1523
|
exports.AnimationCanvas = AnimationCanvas;
|
|
1524
|
+
exports.AnimationKnob = AnimationKnob;
|
|
1121
1525
|
exports.BlackKey = BlackKey;
|
|
1526
|
+
exports.DragObserver = DragObserver;
|
|
1122
1527
|
exports.KeyLabel = KeyLabel;
|
|
1123
1528
|
exports.Knob = Knob;
|
|
1124
1529
|
exports.NumberInput = NumberInput;
|
|
1125
1530
|
exports.Piano = Piano;
|
|
1531
|
+
exports.Scale = Scale;
|
|
1532
|
+
exports.ScaleOption = ScaleOption;
|
|
1126
1533
|
exports.Shortcuts = Shortcuts;
|
|
1127
1534
|
exports.Slider = Slider;
|
|
1128
1535
|
exports.SliderThumb = SliderThumb;
|
|
1129
1536
|
exports.SliderTrack = SliderTrack;
|
|
1537
|
+
exports.SliderValuesProvider = SliderValuesProvider;
|
|
1538
|
+
exports.WheelObserver = WheelObserver;
|
|
1130
1539
|
exports.WhiteKey = WhiteKey;
|
|
1131
|
-
exports.
|
|
1540
|
+
exports.XYPad = XYPad;
|
|
1541
|
+
exports.XYPadArea = XYPadArea;
|
|
1542
|
+
exports.XYPadThumb = XYPadThumb;
|
|
1543
|
+
exports.defaultLength = defaultLength;
|
|
1544
|
+
exports.defaultThickness = defaultThickness;
|
|
1545
|
+
exports.defaultThumbSize = defaultThumbSize;
|
|
1546
|
+
exports.useDisabled = useDisabled;
|
|
1547
|
+
exports.useMax = useMax;
|
|
1548
|
+
exports.useMin = useMin;
|
|
1549
|
+
exports.useReverse = useReverse;
|
|
1550
|
+
exports.useSkew = useSkew;
|
|
1551
|
+
exports.useStep = useStep;
|
|
1552
|
+
exports.useVertical = useVertical;
|
|
1132
1553
|
//# sourceMappingURL=index.js.map
|