@minikeys/react 0.1.0

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/index.js ADDED
@@ -0,0 +1,1513 @@
1
+ // src/hooks/useKeyboardControl.ts
2
+ function _array_like_to_array(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length;
4
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
+ return arr2;
6
+ }
7
+ function _array_with_holes(arr) {
8
+ if (Array.isArray(arr)) return arr;
9
+ }
10
+ function _array_without_holes(arr) {
11
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
12
+ }
13
+ function _define_property(obj, key, value) {
14
+ if (key in obj) {
15
+ Object.defineProperty(obj, key, {
16
+ value: value,
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true
20
+ });
21
+ } else {
22
+ obj[key] = value;
23
+ }
24
+ return obj;
25
+ }
26
+ function _iterable_to_array(iter) {
27
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
28
+ }
29
+ function _iterable_to_array_limit(arr, i) {
30
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
31
+ if (_i == null) return;
32
+ var _arr = [];
33
+ var _n = true;
34
+ var _d = false;
35
+ var _s, _e;
36
+ try {
37
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
38
+ _arr.push(_s.value);
39
+ if (i && _arr.length === i) break;
40
+ }
41
+ } catch (err) {
42
+ _d = true;
43
+ _e = err;
44
+ } finally{
45
+ try {
46
+ if (!_n && _i["return"] != null) _i["return"]();
47
+ } finally{
48
+ if (_d) throw _e;
49
+ }
50
+ }
51
+ return _arr;
52
+ }
53
+ function _non_iterable_rest() {
54
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
55
+ }
56
+ function _non_iterable_spread() {
57
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
58
+ }
59
+ function _object_spread(target) {
60
+ for(var i = 1; i < arguments.length; i++){
61
+ var source = arguments[i] != null ? arguments[i] : {};
62
+ var ownKeys = Object.keys(source);
63
+ if (typeof Object.getOwnPropertySymbols === "function") {
64
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
65
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
66
+ }));
67
+ }
68
+ ownKeys.forEach(function(key) {
69
+ _define_property(target, key, source[key]);
70
+ });
71
+ }
72
+ return target;
73
+ }
74
+ function ownKeys(object, enumerableOnly) {
75
+ var keys = Object.keys(object);
76
+ if (Object.getOwnPropertySymbols) {
77
+ var symbols = Object.getOwnPropertySymbols(object);
78
+ if (enumerableOnly) {
79
+ symbols = symbols.filter(function(sym) {
80
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
81
+ });
82
+ }
83
+ keys.push.apply(keys, symbols);
84
+ }
85
+ return keys;
86
+ }
87
+ function _object_spread_props(target, source) {
88
+ source = source != null ? source : {};
89
+ if (Object.getOwnPropertyDescriptors) {
90
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
91
+ } else {
92
+ ownKeys(Object(source)).forEach(function(key) {
93
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
94
+ });
95
+ }
96
+ return target;
97
+ }
98
+ function _object_without_properties(source, excluded) {
99
+ if (source == null) return {};
100
+ var target = _object_without_properties_loose(source, excluded);
101
+ var key, i;
102
+ if (Object.getOwnPropertySymbols) {
103
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
104
+ for(i = 0; i < sourceSymbolKeys.length; i++){
105
+ key = sourceSymbolKeys[i];
106
+ if (excluded.indexOf(key) >= 0) continue;
107
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
108
+ target[key] = source[key];
109
+ }
110
+ }
111
+ return target;
112
+ }
113
+ function _object_without_properties_loose(source, excluded) {
114
+ if (source == null) return {};
115
+ var target = {};
116
+ var sourceKeys = Object.keys(source);
117
+ var key, i;
118
+ for(i = 0; i < sourceKeys.length; i++){
119
+ key = sourceKeys[i];
120
+ if (excluded.indexOf(key) >= 0) continue;
121
+ target[key] = source[key];
122
+ }
123
+ return target;
124
+ }
125
+ function _sliced_to_array(arr, i) {
126
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
127
+ }
128
+ function _tagged_template_literal(strings, raw) {
129
+ if (!raw) {
130
+ raw = strings.slice(0);
131
+ }
132
+ return Object.freeze(Object.defineProperties(strings, {
133
+ raw: {
134
+ value: Object.freeze(raw)
135
+ }
136
+ }));
137
+ }
138
+ function _to_consumable_array(arr) {
139
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
140
+ }
141
+ function _unsupported_iterable_to_array(o, minLen) {
142
+ if (!o) return;
143
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
144
+ var n = Object.prototype.toString.call(o).slice(8, -1);
145
+ if (n === "Object" && o.constructor) n = o.constructor.name;
146
+ if (n === "Map" || n === "Set") return Array.from(n);
147
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
148
+ }
149
+ function _templateObject() {
150
+ var data = _tagged_template_literal([
151
+ "\n background-color: #8eff00;\n box-shadow: 0px 0px calc(var(--height) * 0.08) calc(var(--height) * 0.04)\n rgba(0, 255, 0, 0.9);\n transform: translateY(calc(var(--height) * 0.03));\n "
152
+ ]);
153
+ _templateObject = function _templateObject() {
154
+ return data;
155
+ };
156
+ return data;
157
+ }
158
+ function _templateObject1() {
159
+ var data = _tagged_template_literal([
160
+ "\n position: absolute;\n right: calc(var(--height) * 0.23);\n top: calc(var(--height) * 0.23);\n width: calc(round(var(--height) * 0.06, 1px));\n height: calc(round(var(--height) * 0.06, 1px));\n border-radius: 50%;\n background-color: #ccc;\n transition: all 0.3s ease;\n\n ",
161
+ "\n"
162
+ ]);
163
+ _templateObject1 = function _templateObject() {
164
+ return data;
165
+ };
166
+ return data;
167
+ }
168
+ function _templateObject2() {
169
+ var data = _tagged_template_literal([
170
+ "\n transform: translateY(calc(var(--height) * 0.03));\n "
171
+ ]);
172
+ _templateObject2 = function _templateObject() {
173
+ return data;
174
+ };
175
+ return data;
176
+ }
177
+ function _templateObject3() {
178
+ var data = _tagged_template_literal([
179
+ "\n width: calc(round(var(--height) * 0.06, 1px));\n height: calc(round(var(--height) * 0.06, 1px));\n border-radius: calc(round(var(--height) * 0.03, 1px));\n position: absolute;\n right: calc(var(--height) * 0.23);\n top: calc(var(--height) * 0.23);\n transition: all 0.3s ease;\n\n ",
180
+ "\n"
181
+ ]);
182
+ _templateObject3 = function _templateObject() {
183
+ return data;
184
+ };
185
+ return data;
186
+ }
187
+ function _templateObject4() {
188
+ var data = _tagged_template_literal([
189
+ "\n opacity: 1;\n transform: translateY(0);\n "
190
+ ]);
191
+ _templateObject4 = function _templateObject() {
192
+ return data;
193
+ };
194
+ return data;
195
+ }
196
+ function _templateObject5() {
197
+ var data = _tagged_template_literal([
198
+ "\n --width: ",
199
+ "px;\n --height: ",
200
+ "px;\n width: var(--width);\n height: var(--height);\n /* opacity: ",
201
+ "; */\n display: ",
202
+ ";\n padding: calc(var(--height) * 0.05);\n\n transition: transform 0.3s ease, opacity 0.3s ease;\n opacity: 0;\n transform: translateY(calc(var(--height) * -0.1));\n ",
203
+ "\n"
204
+ ]);
205
+ _templateObject5 = function _templateObject() {
206
+ return data;
207
+ };
208
+ return data;
209
+ }
210
+ function _templateObject6() {
211
+ var data = _tagged_template_literal([
212
+ "\n opacity: 0.2;\n background-color: #eee;\n border: 1px solid #ccc;\n"
213
+ ]);
214
+ _templateObject6 = function _templateObject() {
215
+ return data;
216
+ };
217
+ return data;
218
+ }
219
+ function _templateObject7() {
220
+ var data = _tagged_template_literal([
221
+ "\n opacity: 0.2;\n background-color: #eee;\n border: 1px solid #ccc;\n"
222
+ ]);
223
+ _templateObject7 = function _templateObject() {
224
+ return data;
225
+ };
226
+ return data;
227
+ }
228
+ function _templateObject8() {
229
+ var data = _tagged_template_literal([
230
+ "\n transform: translateY(calc(var(--height) * 0.03));\n box-shadow: 0 calc(var(--height) * 0.01) calc(var(--height) * 0.03)\n calc(var(--height) * 0.01) rgba(0, 0, 0, 0),\n rgba(255, 255, 255, 0.2) 0px calc(var(--height) * 0.03)\n calc(var(--height) * 0.04) 0px inset;\n"
231
+ ]);
232
+ _templateObject8 = function _templateObject() {
233
+ return data;
234
+ };
235
+ return data;
236
+ }
237
+ function _templateObject9() {
238
+ var data = _tagged_template_literal([
239
+ "\n background-color: #222;\n color: #fff;\n\n &:hover {\n background-color: #111;\n }\n\n &:active {\n ",
240
+ "\n background-color: #000;\n }\n"
241
+ ]);
242
+ _templateObject9 = function _templateObject() {
243
+ return data;
244
+ };
245
+ return data;
246
+ }
247
+ function _templateObject10() {
248
+ var data = _tagged_template_literal([
249
+ "\n background-color: #fff;\n color: #444;\n border: 1px solid #ddd;\n\n &:hover {\n background-color: #f8f8f8;\n }\n\n &:active {\n ",
250
+ "\n background-color: #efefef;\n }\n"
251
+ ]);
252
+ _templateObject10 = function _templateObject() {
253
+ return data;
254
+ };
255
+ return data;
256
+ }
257
+ function _templateObject11() {
258
+ var data = _tagged_template_literal([
259
+ "\n ",
260
+ "\n background-color: #efefef;\n"
261
+ ]);
262
+ _templateObject11 = function _templateObject() {
263
+ return data;
264
+ };
265
+ return data;
266
+ }
267
+ function _templateObject12() {
268
+ var data = _tagged_template_literal([
269
+ "\n ",
270
+ "\n background-color: #000;\n"
271
+ ]);
272
+ _templateObject12 = function _templateObject() {
273
+ return data;
274
+ };
275
+ return data;
276
+ }
277
+ function _templateObject13() {
278
+ var data = _tagged_template_literal([
279
+ "\n ",
280
+ "\n filter: brightness(0.9);\n"
281
+ ]);
282
+ _templateObject13 = function _templateObject() {
283
+ return data;
284
+ };
285
+ return data;
286
+ }
287
+ function _templateObject14() {
288
+ var data = _tagged_template_literal([
289
+ "\n display: flex;\n justify-content: center;\n align-items: center;\n font-size: calc(var(--height) * 0.2);\n"
290
+ ]);
291
+ _templateObject14 = function _templateObject() {
292
+ return data;
293
+ };
294
+ return data;
295
+ }
296
+ function _templateObject15() {
297
+ var data = _tagged_template_literal([
298
+ "\n background-color: ",
299
+ ";\n color: ",
300
+ ";\n ",
301
+ "\n\n &:hover {\n filter: brightness(0.9);\n }\n\n &:active {\n ",
302
+ "\n }\n "
303
+ ]);
304
+ _templateObject15 = function _templateObject() {
305
+ return data;
306
+ };
307
+ return data;
308
+ }
309
+ function _templateObject16() {
310
+ var data = _tagged_template_literal([
311
+ "\n position: relative;\n box-sizing: border-box;\n width: 100%;\n height: 100%;\n border-radius: calc(var(--height) * 0.06);\n font-family: sans-serif;\n padding: calc(var(--height) * 0.08);\n font-size: calc(var(--height) * 0.15);\n cursor: pointer;\n user-select: none;\n box-shadow: 0 calc(var(--height) * 0.01) calc(var(--height) * 0.03)\n calc(var(--height) * 0.01) rgba(0, 0, 0, 0.1),\n rgba(255, 255, 255, 0.1) 0px calc(var(--height) * 0.03)\n calc(var(--height) * 0.04) 0px inset;\n transition: all 0.3s ease;\n\n ",
312
+ "\n\n ",
313
+ "\n\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n\n ",
314
+ "\n"
315
+ ]);
316
+ _templateObject16 = function _templateObject() {
317
+ return data;
318
+ };
319
+ return data;
320
+ }
321
+ function _templateObject17() {
322
+ var data = _tagged_template_literal([
323
+ "\n text-align: center;\n "
324
+ ]);
325
+ _templateObject17 = function _templateObject() {
326
+ return data;
327
+ };
328
+ return data;
329
+ }
330
+ function _templateObject18() {
331
+ var data = _tagged_template_literal([
332
+ "\n font-size: calc(var(--height) * 0.15);\n opacity: 0.8;\n\n ",
333
+ ";\n"
334
+ ]);
335
+ _templateObject18 = function _templateObject() {
336
+ return data;
337
+ };
338
+ return data;
339
+ }
340
+ function _templateObject19() {
341
+ var data = _tagged_template_literal([
342
+ "\n width: ",
343
+ "px;\n box-sizing: border-box;\n\n * {\n box-sizing: border-box;\n }\n"
344
+ ]);
345
+ _templateObject19 = function _templateObject() {
346
+ return data;
347
+ };
348
+ return data;
349
+ }
350
+ function _templateObject20() {
351
+ var data = _tagged_template_literal([
352
+ "\n display: ",
353
+ ";\n margin-left: ",
354
+ "px;\n"
355
+ ]);
356
+ _templateObject20 = function _templateObject() {
357
+ return data;
358
+ };
359
+ return data;
360
+ }
361
+ function _templateObject21() {
362
+ var data = _tagged_template_literal([
363
+ "\n cursor: pointer;\n\n &:hover {\n fill: ",
364
+ ";\n }\n\n &:active {\n fill: ",
365
+ ";\n }\n"
366
+ ]);
367
+ _templateObject21 = function _templateObject() {
368
+ return data;
369
+ };
370
+ return data;
371
+ }
372
+ function _templateObject22() {
373
+ var data = _tagged_template_literal([
374
+ "\n font-family: sans-serif;\n pointer-events: none;\n user-select: none;\n"
375
+ ]);
376
+ _templateObject22 = function _templateObject() {
377
+ return data;
378
+ };
379
+ return data;
380
+ }
381
+ function _templateObject23() {
382
+ var data = _tagged_template_literal([
383
+ "\n user-select: none;\n"
384
+ ]);
385
+ _templateObject23 = function _templateObject() {
386
+ return data;
387
+ };
388
+ return data;
389
+ }
390
+ import { midiToNote } from "minikeys";
391
+ import { useEffect, useState } from "react";
392
+ var useKeyboardControl = function(keyMap, playNoteFromMidi, modifierKeys) {
393
+ var _useState = _sliced_to_array(useState([]), 2), activeKeys = _useState[0], setActiveKeys = _useState[1];
394
+ useEffect(function() {
395
+ var handleKeyDown = function(event) {
396
+ var _keyMap_get;
397
+ var modifierKey = modifierKeys === null || modifierKeys === void 0 ? void 0 : modifierKeys.find(function(modifierKey2) {
398
+ return modifierKey2.keyCode === event.code;
399
+ });
400
+ if (!modifierKey && activeKeys.some(function(key) {
401
+ return key.keyCode === event.code;
402
+ })) {
403
+ return;
404
+ }
405
+ if (modifierKey && !(keyMap === null || keyMap === void 0 ? void 0 : keyMap.get(event.code))) {
406
+ modifierKey === null || modifierKey === void 0 ? void 0 : modifierKey.action();
407
+ }
408
+ var note = keyMap === null || keyMap === void 0 ? void 0 : (_keyMap_get = keyMap.get(event.code)) === null || _keyMap_get === void 0 ? void 0 : _keyMap_get.midiNote;
409
+ if (note && playNoteFromMidi) {
410
+ playNoteFromMidi(note);
411
+ }
412
+ setActiveKeys(function(prev) {
413
+ return _to_consumable_array(prev).concat([
414
+ {
415
+ keyCode: event.code,
416
+ note: note ? midiToNote[note] : void 0
417
+ }
418
+ ]);
419
+ });
420
+ };
421
+ var handleKeyUp = function(event) {
422
+ setActiveKeys(function(prev) {
423
+ return prev.filter(function(key) {
424
+ return key.keyCode !== event.code;
425
+ });
426
+ });
427
+ var modifierKey = modifierKeys === null || modifierKeys === void 0 ? void 0 : modifierKeys.find(function(modifierKey2) {
428
+ return modifierKey2.keyCode === event.code;
429
+ });
430
+ if (modifierKey && !(keyMap === null || keyMap === void 0 ? void 0 : keyMap.get(event.code))) {
431
+ (modifierKey === null || modifierKey === void 0 ? void 0 : modifierKey.actionOnRelease) && (modifierKey === null || modifierKey === void 0 ? void 0 : modifierKey.actionOnRelease());
432
+ }
433
+ };
434
+ window.addEventListener("keydown", handleKeyDown, true);
435
+ window.addEventListener("keyup", handleKeyUp, true);
436
+ return function() {
437
+ window.removeEventListener("keydown", handleKeyDown, true);
438
+ window.removeEventListener("keyup", handleKeyUp, true);
439
+ };
440
+ }, [
441
+ keyMap,
442
+ playNoteFromMidi,
443
+ modifierKeys
444
+ ]);
445
+ return {
446
+ activeKeys: activeKeys
447
+ };
448
+ };
449
+ // src/hooks/useMiniKeys.ts
450
+ import { MiniKeys } from "minikeys";
451
+ import { useEffect as useEffect2, useRef, useState as useState2 } from "react";
452
+ var useMiniKeys = function(samples) {
453
+ var minikeysRef = useRef(null);
454
+ var _useState2 = _sliced_to_array(useState2(0), 2), progress = _useState2[0], setProgress = _useState2[1];
455
+ var _useState21 = _sliced_to_array(useState2(true), 2), isLoading = _useState21[0], setIsLoading = _useState21[1];
456
+ var _useState22 = _sliced_to_array(useState2(false), 2), isSuccess = _useState22[0], setIsSuccess = _useState22[1];
457
+ var _useState23 = _sliced_to_array(useState2(false), 2), isError = _useState23[0], setIsError = _useState23[1];
458
+ var _useState24 = _sliced_to_array(useState2(false), 2), sustain = _useState24[0], setSustain = _useState24[1];
459
+ useEffect2(function() {
460
+ if (!minikeysRef.current) {
461
+ minikeysRef.current = new MiniKeys();
462
+ }
463
+ return function() {
464
+ minikeysRef.current = null;
465
+ };
466
+ }, []);
467
+ var setMiniKeysSustain = function(sustain2) {
468
+ if (minikeysRef.current) {
469
+ minikeysRef.current.setSustain(sustain2);
470
+ setSustain(sustain2);
471
+ }
472
+ };
473
+ useEffect2(function() {
474
+ if (minikeysRef.current) {
475
+ setIsLoading(true);
476
+ minikeysRef.current.loadNotes(samples, setProgress).then(function() {
477
+ setIsLoading(false);
478
+ setIsSuccess(true);
479
+ }).catch(function() {
480
+ setIsLoading(false);
481
+ setIsError(true);
482
+ });
483
+ }
484
+ }, [
485
+ samples
486
+ ]);
487
+ return {
488
+ playNoteFromName: minikeysRef.current ? minikeysRef.current.playNoteFromName : void 0,
489
+ playNoteFromMidi: minikeysRef.current ? minikeysRef.current.playNoteFromMidi : void 0,
490
+ setSustain: setMiniKeysSustain,
491
+ sustain: sustain,
492
+ isLoading: isLoading,
493
+ isSuccess: isSuccess,
494
+ isError: isError,
495
+ progress: progress
496
+ };
497
+ };
498
+ // src/hooks/useMiniKeysKeyboard.ts
499
+ import { MiniKeysKeyboard } from "minikeys";
500
+ import { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
501
+ var useMiniKeysKeyboard = function(mode) {
502
+ var _miniKeysKeyboardRef_current;
503
+ var miniKeysKeyboardRef = useRef2(null);
504
+ var _useState3 = _sliced_to_array(useState3(), 2), keyMap = _useState3[0], setKeyMap = _useState3[1];
505
+ var noteRange = (_miniKeysKeyboardRef_current = miniKeysKeyboardRef.current) === null || _miniKeysKeyboardRef_current === void 0 ? void 0 : _miniKeysKeyboardRef_current.getNoteRange();
506
+ useEffect3(function() {
507
+ if (!miniKeysKeyboardRef.current) {
508
+ miniKeysKeyboardRef.current = new MiniKeysKeyboard(mode);
509
+ setKeyMap(miniKeysKeyboardRef.current.getNoteMap());
510
+ }
511
+ return function() {
512
+ miniKeysKeyboardRef.current = null;
513
+ setKeyMap(void 0);
514
+ };
515
+ }, [
516
+ mode
517
+ ]);
518
+ var transposeDown = function() {
519
+ var _miniKeysKeyboardRef_current, _miniKeysKeyboardRef_current1;
520
+ (_miniKeysKeyboardRef_current = miniKeysKeyboardRef.current) === null || _miniKeysKeyboardRef_current === void 0 ? void 0 : _miniKeysKeyboardRef_current.shiftLeft();
521
+ setKeyMap((_miniKeysKeyboardRef_current1 = miniKeysKeyboardRef.current) === null || _miniKeysKeyboardRef_current1 === void 0 ? void 0 : _miniKeysKeyboardRef_current1.getNoteMap());
522
+ };
523
+ var transposeUp = function() {
524
+ var _miniKeysKeyboardRef_current, _miniKeysKeyboardRef_current1;
525
+ (_miniKeysKeyboardRef_current = miniKeysKeyboardRef.current) === null || _miniKeysKeyboardRef_current === void 0 ? void 0 : _miniKeysKeyboardRef_current.shiftRight();
526
+ setKeyMap((_miniKeysKeyboardRef_current1 = miniKeysKeyboardRef.current) === null || _miniKeysKeyboardRef_current1 === void 0 ? void 0 : _miniKeysKeyboardRef_current1.getNoteMap());
527
+ };
528
+ var octaveDown = function() {
529
+ var _miniKeysKeyboardRef_current, _miniKeysKeyboardRef_current1;
530
+ (_miniKeysKeyboardRef_current = miniKeysKeyboardRef.current) === null || _miniKeysKeyboardRef_current === void 0 ? void 0 : _miniKeysKeyboardRef_current.shiftLeftOctave();
531
+ setKeyMap((_miniKeysKeyboardRef_current1 = miniKeysKeyboardRef.current) === null || _miniKeysKeyboardRef_current1 === void 0 ? void 0 : _miniKeysKeyboardRef_current1.getNoteMap());
532
+ };
533
+ var octaveUp = function() {
534
+ var _miniKeysKeyboardRef_current, _miniKeysKeyboardRef_current1;
535
+ (_miniKeysKeyboardRef_current = miniKeysKeyboardRef.current) === null || _miniKeysKeyboardRef_current === void 0 ? void 0 : _miniKeysKeyboardRef_current.shiftRightOctave();
536
+ setKeyMap((_miniKeysKeyboardRef_current1 = miniKeysKeyboardRef.current) === null || _miniKeysKeyboardRef_current1 === void 0 ? void 0 : _miniKeysKeyboardRef_current1.getNoteMap());
537
+ };
538
+ return {
539
+ keyMap: keyMap,
540
+ noteRange: noteRange,
541
+ transposeDown: transposeDown,
542
+ transposeUp: transposeUp,
543
+ octaveDown: octaveDown,
544
+ octaveUp: octaveUp
545
+ };
546
+ };
547
+ // src/Keyboard/Keyboard.tsx
548
+ import { useMemo } from "react";
549
+ import styled3 from "styled-components";
550
+ // src/Keyboard/Key.tsx
551
+ import { useEffect as useEffect4, useState as useState4 } from "react";
552
+ import styled2, { css as css2 } from "styled-components";
553
+ // src/Keyboard/Indicator.tsx
554
+ import styled, { css } from "styled-components";
555
+ import { jsx } from "react/jsx-runtime";
556
+ var Indicator = function(param) {
557
+ var state = param.state;
558
+ return /* @__PURE__ */ jsx(ColourIndicator, {
559
+ $state: state
560
+ });
561
+ };
562
+ var ColourIndicator = styled.div(_templateObject1(), function(param) {
563
+ var $state = param.$state;
564
+ return $state === "active" && css(_templateObject());
565
+ });
566
+ var Container = styled.div(_templateObject3(), function(param) {
567
+ var $active = param.$active;
568
+ return $active && css(_templateObject2());
569
+ });
570
+ // src/Keyboard/Key.tsx
571
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
572
+ var Key = function(param) {
573
+ var label = param.label, size = param.size, hidden = param.hidden, hiddenOpacity = param.hiddenOpacity, baseWidth = param.baseWidth, active = param.active, keyType = param.keyType, modifier = param.modifier, delayDisplay = param.delayDisplay, indicator = param.indicator, onClick = param.onClick;
574
+ var _useState4 = _sliced_to_array(useState4(delayDisplay !== void 0 && delayDisplay !== null), 2), hide = _useState4[0], setHide = _useState4[1];
575
+ if (active) {
576
+ console.log(active);
577
+ }
578
+ useEffect4(function() {
579
+ if (hide) {
580
+ setTimeout(function() {
581
+ setHide(false);
582
+ }, (delayDisplay !== null && delayDisplay !== void 0 ? delayDisplay : 0) * 10);
583
+ }
584
+ }, []);
585
+ return /* @__PURE__ */ jsxs(Container2, {
586
+ $hidden: hidden,
587
+ $hiddenOpacity: hiddenOpacity,
588
+ $width: baseWidth * (size !== null && size !== void 0 ? size : 1),
589
+ $height: baseWidth,
590
+ $hide: hide,
591
+ children: [
592
+ /* @__PURE__ */ jsxs(Keycap, {
593
+ $size: size,
594
+ $active: active || false,
595
+ $keyType: modifier ? "modifier" : keyType,
596
+ onMouseDown: modifier ? modifier.action : onClick,
597
+ $bgColour: modifier === null || modifier === void 0 ? void 0 : modifier.bgColour,
598
+ $colour: modifier === null || modifier === void 0 ? void 0 : modifier.colour,
599
+ children: [
600
+ label,
601
+ modifier && /* @__PURE__ */ jsx2(Label, {
602
+ $size: size,
603
+ children: modifier.label
604
+ })
605
+ ]
606
+ }),
607
+ indicator && /* @__PURE__ */ jsx2(Indicator, {
608
+ state: indicator
609
+ })
610
+ ]
611
+ });
612
+ };
613
+ var Container2 = styled2.div(_templateObject5(), function(props) {
614
+ return props.$width;
615
+ }, function(props) {
616
+ return props.$height;
617
+ }, function(props) {
618
+ return props.$hiddenOpacity ? 0 : 1;
619
+ }, function(props) {
620
+ return props.$hidden ? "none" : "block";
621
+ }, function(param) {
622
+ var $hide = param.$hide, $hiddenOpacity = param.$hiddenOpacity;
623
+ return !$hide && !$hiddenOpacity && css2(_templateObject4());
624
+ });
625
+ var disabledKeycap = css2(_templateObject6());
626
+ var unplayableKeycap = css2(_templateObject7());
627
+ var activeKeycap = css2(_templateObject8());
628
+ var blackKeycap = css2(_templateObject9(), activeKeycap);
629
+ var whiteKeycap = css2(_templateObject10(), activeKeycap);
630
+ var activeKeycapWhite = css2(_templateObject11(), activeKeycap);
631
+ var activeKeycapBlack = css2(_templateObject12(), activeKeycap);
632
+ var activeKeycapModifier = css2(_templateObject13(), activeKeycap);
633
+ var playableKeycap = css2(_templateObject14());
634
+ var Keycap = styled2.div(_templateObject16(), function(param) {
635
+ var $keyType = param.$keyType, $bgColour = param.$bgColour, $colour = param.$colour;
636
+ if ($keyType === void 0) {
637
+ return unplayableKeycap;
638
+ } else if ($keyType === "disabled") {
639
+ return disabledKeycap;
640
+ } else if ($keyType === "black") {
641
+ return blackKeycap;
642
+ } else if ($keyType === "white") {
643
+ return whiteKeycap;
644
+ } else if ($keyType === "modifier") {
645
+ return css2(_templateObject15(), $bgColour || "#eee", $colour, !$bgColour && "border: 1px solid #ddd;", activeKeycapModifier);
646
+ }
647
+ }, function(param) {
648
+ var $active = param.$active, $keyType = param.$keyType;
649
+ if ($keyType !== "disabled" && $keyType !== "unplayable" && $active) {
650
+ if ($keyType === "white") return activeKeycapWhite;
651
+ if ($keyType === "black") return activeKeycapBlack;
652
+ if ($keyType === "modifier") return activeKeycapModifier;
653
+ }
654
+ }, function(param) {
655
+ var $size = param.$size, $keyType = param.$keyType;
656
+ if (!$size && $keyType !== "modifier") {
657
+ return playableKeycap;
658
+ }
659
+ });
660
+ var Label = styled2.span(_templateObject18(), function(param) {
661
+ var $size = param.$size;
662
+ return !$size && css2(_templateObject17());
663
+ });
664
+ // src/Keyboard/utils.ts
665
+ var keyCodeToLabel = /* @__PURE__ */ new Map([
666
+ [
667
+ "Digit1",
668
+ "1"
669
+ ],
670
+ [
671
+ "Digit2",
672
+ "2"
673
+ ],
674
+ [
675
+ "Digit3",
676
+ "3"
677
+ ],
678
+ [
679
+ "Digit4",
680
+ "4"
681
+ ],
682
+ [
683
+ "Digit5",
684
+ "5"
685
+ ],
686
+ [
687
+ "Digit6",
688
+ "6"
689
+ ],
690
+ [
691
+ "Digit7",
692
+ "7"
693
+ ],
694
+ [
695
+ "Digit8",
696
+ "8"
697
+ ],
698
+ [
699
+ "Digit9",
700
+ "9"
701
+ ],
702
+ [
703
+ "Digit0",
704
+ "0"
705
+ ],
706
+ [
707
+ "Minus",
708
+ "-"
709
+ ],
710
+ [
711
+ "Equal",
712
+ "="
713
+ ],
714
+ [
715
+ "KeyQ",
716
+ "q"
717
+ ],
718
+ [
719
+ "KeyW",
720
+ "w"
721
+ ],
722
+ [
723
+ "KeyE",
724
+ "e"
725
+ ],
726
+ [
727
+ "KeyR",
728
+ "r"
729
+ ],
730
+ [
731
+ "KeyT",
732
+ "t"
733
+ ],
734
+ [
735
+ "KeyY",
736
+ "y"
737
+ ],
738
+ [
739
+ "KeyU",
740
+ "u"
741
+ ],
742
+ [
743
+ "KeyI",
744
+ "i"
745
+ ],
746
+ [
747
+ "KeyO",
748
+ "o"
749
+ ],
750
+ [
751
+ "KeyP",
752
+ "p"
753
+ ],
754
+ [
755
+ "BracketLeft",
756
+ "["
757
+ ],
758
+ [
759
+ "BracketRight",
760
+ "]"
761
+ ],
762
+ [
763
+ "KeyA",
764
+ "a"
765
+ ],
766
+ [
767
+ "KeyS",
768
+ "s"
769
+ ],
770
+ [
771
+ "KeyD",
772
+ "d"
773
+ ],
774
+ [
775
+ "KeyF",
776
+ "f"
777
+ ],
778
+ [
779
+ "KeyG",
780
+ "g"
781
+ ],
782
+ [
783
+ "KeyH",
784
+ "h"
785
+ ],
786
+ [
787
+ "KeyJ",
788
+ "j"
789
+ ],
790
+ [
791
+ "KeyK",
792
+ "k"
793
+ ],
794
+ [
795
+ "KeyL",
796
+ "l"
797
+ ],
798
+ [
799
+ "Semicolon",
800
+ ";"
801
+ ],
802
+ [
803
+ "Quote",
804
+ "'"
805
+ ],
806
+ [
807
+ "KeyZ",
808
+ "z"
809
+ ],
810
+ [
811
+ "KeyX",
812
+ "x"
813
+ ],
814
+ [
815
+ "KeyC",
816
+ "c"
817
+ ],
818
+ [
819
+ "KeyV",
820
+ "v"
821
+ ],
822
+ [
823
+ "KeyB",
824
+ "b"
825
+ ],
826
+ [
827
+ "KeyN",
828
+ "n"
829
+ ],
830
+ [
831
+ "KeyM",
832
+ "m"
833
+ ],
834
+ [
835
+ "Comma",
836
+ ","
837
+ ],
838
+ [
839
+ "Period",
840
+ "."
841
+ ],
842
+ [
843
+ "Slash",
844
+ "/"
845
+ ]
846
+ ]);
847
+ var keyboardRows = [
848
+ [
849
+ "Digit1",
850
+ "Digit2",
851
+ "Digit3",
852
+ "Digit4",
853
+ "Digit5",
854
+ "Digit6",
855
+ "Digit7",
856
+ "Digit8",
857
+ "Digit9",
858
+ "Digit0",
859
+ "Minus",
860
+ "Equal"
861
+ ],
862
+ [
863
+ "KeyQ",
864
+ "KeyW",
865
+ "KeyE",
866
+ "KeyR",
867
+ "KeyT",
868
+ "KeyY",
869
+ "KeyU",
870
+ "KeyI",
871
+ "KeyO",
872
+ "KeyP",
873
+ "BracketLeft",
874
+ "BracketRight"
875
+ ],
876
+ [
877
+ "KeyA",
878
+ "KeyS",
879
+ "KeyD",
880
+ "KeyF",
881
+ "KeyG",
882
+ "KeyH",
883
+ "KeyJ",
884
+ "KeyK",
885
+ "KeyL",
886
+ "Semicolon",
887
+ "Quote"
888
+ ],
889
+ [
890
+ "KeyZ",
891
+ "KeyX",
892
+ "KeyC",
893
+ "KeyV",
894
+ "KeyB",
895
+ "KeyN",
896
+ "KeyM",
897
+ "Comma",
898
+ "Period",
899
+ "Slash"
900
+ ]
901
+ ];
902
+ var optionalModifier = function(keyCodes, modifierKeys) {
903
+ return modifierKeys === null || modifierKeys === void 0 ? void 0 : modifierKeys.find(function(modifierKey) {
904
+ return keyCodes.includes(modifierKey.keyCode);
905
+ });
906
+ };
907
+ var getDisplayMap = function(showFullKeyboard, dualMode, modifierKeys) {
908
+ var displayMap = /* @__PURE__ */ new Map();
909
+ displayMap.set("Escape", showFullKeyboard || !!optionalModifier([
910
+ "Escape",
911
+ "IntlBackslash"
912
+ ], modifierKeys) ? displayMap.size : null);
913
+ if (showFullKeyboard || dualMode) {
914
+ keyboardRows[0].forEach(function(key) {
915
+ return displayMap.set(key, displayMap.size);
916
+ });
917
+ } else {
918
+ keyboardRows[0].forEach(function(key) {
919
+ displayMap.set(key, !!optionalModifier([
920
+ key
921
+ ], modifierKeys) ? displayMap.size : null);
922
+ });
923
+ }
924
+ displayMap.set("Backspace", showFullKeyboard || !!optionalModifier([
925
+ "Backspace"
926
+ ], modifierKeys) ? displayMap.size : null);
927
+ displayMap.set("Tab", showFullKeyboard || !!optionalModifier([
928
+ "Tab",
929
+ "Backquote"
930
+ ], modifierKeys) ? displayMap.size : null);
931
+ keyboardRows[1].forEach(function(key) {
932
+ return displayMap.set(key, displayMap.size);
933
+ });
934
+ displayMap.set("Backquote", showFullKeyboard || !!optionalModifier([
935
+ "Backquote"
936
+ ], modifierKeys) ? displayMap.size : null);
937
+ displayMap.set("CapsLock", showFullKeyboard || !!optionalModifier([
938
+ "CapsLock"
939
+ ], modifierKeys) ? displayMap.size : null);
940
+ keyboardRows[2].forEach(function(key) {
941
+ return displayMap.set(key, displayMap.size);
942
+ });
943
+ displayMap.set("Enter", showFullKeyboard || !!optionalModifier([
944
+ "Enter"
945
+ ], modifierKeys) ? displayMap.size : null);
946
+ displayMap.set("ShiftLeft", showFullKeyboard || !!optionalModifier([
947
+ "ShiftLeft"
948
+ ], modifierKeys) ? displayMap.size : null);
949
+ if (showFullKeyboard || dualMode) {
950
+ keyboardRows[3].forEach(function(key) {
951
+ return displayMap.set(key, displayMap.size);
952
+ });
953
+ } else {
954
+ keyboardRows[3].forEach(function(key) {
955
+ displayMap.set(key, !!optionalModifier([
956
+ key
957
+ ], modifierKeys) ? displayMap.size : null);
958
+ });
959
+ }
960
+ displayMap.set("ShiftRight", showFullKeyboard || !!optionalModifier([
961
+ "ShiftRight"
962
+ ], modifierKeys) ? displayMap.size : null);
963
+ return displayMap;
964
+ };
965
+ // src/Keyboard/Keyboard.tsx
966
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
967
+ var activeKeysIncludes = function(activeKeys, key) {
968
+ return activeKeys.map(function(activeKey) {
969
+ return activeKey.keyCode;
970
+ }).includes(key);
971
+ };
972
+ var Keyboard = function(param) {
973
+ var _param_width = param.width, width = _param_width === void 0 ? 1200 : _param_width, _param_dualMode = param.dualMode, dualMode = _param_dualMode === void 0 ? false : _param_dualMode, _param_showFullKeyboard = param.showFullKeyboard, showFullKeyboard = _param_showFullKeyboard === void 0 ? false : _param_showFullKeyboard, modifierKeys = param.modifierKeys, activeKeys = param.activeKeys, keyMap = param.keyMap, _param_animate = param.animate, animate = _param_animate === void 0 ? false : _param_animate, onKeyClick = param.onKeyClick;
974
+ var nonPlayableModifierKey = modifierKeys === null || modifierKeys === void 0 ? void 0 : modifierKeys.some(function(modifierKey) {
975
+ return !Array.from(keyCodeToLabel.keys()).includes(modifierKey.keyCode);
976
+ });
977
+ var baseWidth = width / (showFullKeyboard || nonPlayableModifierKey ? 15 : 12.5);
978
+ var calculateRowShift = function(shift) {
979
+ if (showFullKeyboard) {
980
+ return 0;
981
+ } else {
982
+ if (dualMode || nonPlayableModifierKey) {
983
+ return baseWidth * shift;
984
+ } else {
985
+ return baseWidth * shift - baseWidth * 0.5;
986
+ }
987
+ }
988
+ };
989
+ var handleClick = function(midiNote) {
990
+ if (onKeyClick && midiNote !== null && midiNote !== void 0) {
991
+ onKeyClick(midiNote);
992
+ }
993
+ };
994
+ var displayMap = useMemo(function() {
995
+ return getDisplayMap(showFullKeyboard, dualMode, modifierKeys);
996
+ }, [
997
+ showFullKeyboard,
998
+ dualMode,
999
+ modifierKeys
1000
+ ]);
1001
+ console.log(activeKeys, keyboardRows[0][1], activeKeysIncludes(activeKeys, keyboardRows[0][1]));
1002
+ return /* @__PURE__ */ jsxs2(Container3, {
1003
+ $width: width,
1004
+ children: [
1005
+ /* @__PURE__ */ jsxs2(Row, {
1006
+ $shift: nonPlayableModifierKey ? (modifierKeys === null || modifierKeys === void 0 ? void 0 : modifierKeys.some(function(modifierKey) {
1007
+ return [
1008
+ "Escape",
1009
+ "IntlBackslash"
1010
+ ].includes(modifierKey.keyCode);
1011
+ })) ? 0 : calculateRowShift(1) : calculateRowShift(0),
1012
+ $show: displayMap.get("Escape") !== null || displayMap.get("Backspace") !== null || keyboardRows[0].some(function(key) {
1013
+ return displayMap.get(key) !== null;
1014
+ }),
1015
+ children: [
1016
+ /* @__PURE__ */ jsx3(Key, {
1017
+ delayDisplay: animate ? displayMap.get("Escape") : null,
1018
+ baseWidth: baseWidth,
1019
+ size: 1,
1020
+ hidden: displayMap.get("Escape") === null,
1021
+ label: "esc",
1022
+ active: activeKeysIncludes(activeKeys, "Escape") || activeKeysIncludes(activeKeys, "IntlBackslash"),
1023
+ modifier: optionalModifier([
1024
+ "Escape",
1025
+ "IntlBackslash"
1026
+ ], modifierKeys)
1027
+ }),
1028
+ Array.from({
1029
+ length: 12
1030
+ }).map(function(_, i) {
1031
+ var _keyMap_get;
1032
+ return /* @__PURE__ */ jsx3(Key, {
1033
+ delayDisplay: animate ? displayMap.get(keyboardRows[0][i]) : null,
1034
+ baseWidth: baseWidth,
1035
+ label: keyCodeToLabel.get(keyboardRows[0][i]),
1036
+ keyType: keyMap === null || keyMap === void 0 ? void 0 : (_keyMap_get = keyMap.get(keyboardRows[0][i])) === null || _keyMap_get === void 0 ? void 0 : _keyMap_get.type,
1037
+ active: activeKeysIncludes(activeKeys, keyboardRows[0][i]),
1038
+ onClick: function() {
1039
+ var _keyMap_get;
1040
+ return handleClick(keyMap === null || keyMap === void 0 ? void 0 : (_keyMap_get = keyMap.get(keyboardRows[0][i])) === null || _keyMap_get === void 0 ? void 0 : _keyMap_get.midiNote);
1041
+ },
1042
+ hiddenOpacity: !displayMap.get(keyboardRows[0][i]),
1043
+ modifier: dualMode ? void 0 : optionalModifier([
1044
+ keyboardRows[0][i]
1045
+ ], modifierKeys)
1046
+ }, i);
1047
+ }),
1048
+ /* @__PURE__ */ jsx3(Key, {
1049
+ delayDisplay: animate ? displayMap.get("Backspace") : null,
1050
+ baseWidth: baseWidth,
1051
+ size: 2,
1052
+ hidden: !displayMap.get("Backspace"),
1053
+ label: "backspace",
1054
+ active: activeKeysIncludes(activeKeys, "Backspace"),
1055
+ modifier: optionalModifier([
1056
+ "Backspace"
1057
+ ], modifierKeys)
1058
+ })
1059
+ ]
1060
+ }),
1061
+ /* @__PURE__ */ jsxs2(Row, {
1062
+ $shift: nonPlayableModifierKey ? (modifierKeys === null || modifierKeys === void 0 ? void 0 : modifierKeys.some(function(modifierKey) {
1063
+ return [
1064
+ "Tab"
1065
+ ].includes(modifierKey.keyCode);
1066
+ })) ? 0 : calculateRowShift(1.5) : calculateRowShift(0.5),
1067
+ $show: true,
1068
+ children: [
1069
+ /* @__PURE__ */ jsx3(Key, {
1070
+ delayDisplay: animate ? displayMap.get("Tab") : null,
1071
+ baseWidth: baseWidth,
1072
+ size: 1.5,
1073
+ hidden: !displayMap.get("Tab"),
1074
+ label: "tab",
1075
+ active: activeKeysIncludes(activeKeys, "Tab"),
1076
+ modifier: optionalModifier([
1077
+ "Tab"
1078
+ ], modifierKeys)
1079
+ }),
1080
+ Array.from({
1081
+ length: 12
1082
+ }).map(function(_, i) {
1083
+ var _keyMap_get;
1084
+ return /* @__PURE__ */ jsx3(Key, {
1085
+ delayDisplay: animate ? displayMap.get(keyboardRows[1][i]) : null,
1086
+ baseWidth: baseWidth,
1087
+ label: keyCodeToLabel.get(keyboardRows[1][i]),
1088
+ keyType: keyMap === null || keyMap === void 0 ? void 0 : (_keyMap_get = keyMap.get(keyboardRows[1][i])) === null || _keyMap_get === void 0 ? void 0 : _keyMap_get.type,
1089
+ active: activeKeysIncludes(activeKeys, keyboardRows[1][i]),
1090
+ onClick: function() {
1091
+ var _keyMap_get;
1092
+ return handleClick(keyMap === null || keyMap === void 0 ? void 0 : (_keyMap_get = keyMap.get(keyboardRows[1][i])) === null || _keyMap_get === void 0 ? void 0 : _keyMap_get.midiNote);
1093
+ }
1094
+ }, i);
1095
+ }),
1096
+ /* @__PURE__ */ jsx3(Key, {
1097
+ delayDisplay: animate ? displayMap.get("Backquote") : null,
1098
+ baseWidth: baseWidth,
1099
+ size: 1.5,
1100
+ hidden: !displayMap.get("Backquote"),
1101
+ label: "\\",
1102
+ active: activeKeysIncludes(activeKeys, "Backquote"),
1103
+ modifier: optionalModifier([
1104
+ "Backquote"
1105
+ ], modifierKeys)
1106
+ })
1107
+ ]
1108
+ }),
1109
+ /* @__PURE__ */ jsxs2(Row, {
1110
+ $shift: nonPlayableModifierKey ? (modifierKeys === null || modifierKeys === void 0 ? void 0 : modifierKeys.some(function(modifierKey) {
1111
+ return [
1112
+ "CapsLock"
1113
+ ].includes(modifierKey.keyCode);
1114
+ })) ? 0 : calculateRowShift(1.75) : calculateRowShift(0.75),
1115
+ $show: true,
1116
+ children: [
1117
+ /* @__PURE__ */ jsx3(Key, {
1118
+ delayDisplay: animate ? displayMap.get("CapsLock") : null,
1119
+ baseWidth: baseWidth,
1120
+ size: 1.75,
1121
+ hidden: !displayMap.get("CapsLock"),
1122
+ label: "caps lock",
1123
+ active: activeKeysIncludes(activeKeys, "CapsLock"),
1124
+ modifier: optionalModifier([
1125
+ "CapsLock"
1126
+ ], modifierKeys),
1127
+ indicator: optionalModifier([
1128
+ "CapsLock"
1129
+ ], modifierKeys) && (activeKeysIncludes(activeKeys, "CapsLock") ? "active" : "inactive")
1130
+ }),
1131
+ Array.from({
1132
+ length: 11
1133
+ }).map(function(_, i) {
1134
+ var _keyMap_get;
1135
+ return /* @__PURE__ */ jsx3(Key, {
1136
+ delayDisplay: animate ? displayMap.get(keyboardRows[2][i]) : null,
1137
+ baseWidth: baseWidth,
1138
+ label: keyCodeToLabel.get(keyboardRows[2][i]),
1139
+ keyType: keyMap === null || keyMap === void 0 ? void 0 : (_keyMap_get = keyMap.get(keyboardRows[2][i])) === null || _keyMap_get === void 0 ? void 0 : _keyMap_get.type,
1140
+ active: activeKeysIncludes(activeKeys, keyboardRows[2][i]),
1141
+ onClick: function() {
1142
+ var _keyMap_get;
1143
+ return handleClick(keyMap === null || keyMap === void 0 ? void 0 : (_keyMap_get = keyMap.get(keyboardRows[2][i])) === null || _keyMap_get === void 0 ? void 0 : _keyMap_get.midiNote);
1144
+ }
1145
+ }, i);
1146
+ }),
1147
+ /* @__PURE__ */ jsx3(Key, {
1148
+ delayDisplay: animate ? displayMap.get("Enter") : null,
1149
+ baseWidth: baseWidth,
1150
+ size: 2.25,
1151
+ hidden: !displayMap.get("Enter"),
1152
+ label: "enter",
1153
+ active: activeKeysIncludes(activeKeys, "Enter"),
1154
+ modifier: optionalModifier([
1155
+ "Enter"
1156
+ ], modifierKeys)
1157
+ })
1158
+ ]
1159
+ }),
1160
+ /* @__PURE__ */ jsxs2(Row, {
1161
+ $shift: nonPlayableModifierKey ? (modifierKeys === null || modifierKeys === void 0 ? void 0 : modifierKeys.some(function(modifierKey) {
1162
+ return modifierKey.keyCode === "ShiftLeft";
1163
+ })) ? 0 : calculateRowShift(2.25) : calculateRowShift(1.25),
1164
+ $show: displayMap.get("ShiftLeft") !== null || displayMap.get("ShiftRight") !== null || keyboardRows[3].some(function(key) {
1165
+ return displayMap.get(key) !== null;
1166
+ }),
1167
+ children: [
1168
+ /* @__PURE__ */ jsx3(Key, {
1169
+ delayDisplay: animate ? displayMap.get("ShiftLeft") : null,
1170
+ baseWidth: baseWidth,
1171
+ size: 2.25,
1172
+ hidden: !displayMap.get("ShiftLeft"),
1173
+ label: "shift",
1174
+ active: activeKeysIncludes(activeKeys, "ShiftLeft"),
1175
+ modifier: optionalModifier([
1176
+ "ShiftLeft"
1177
+ ], modifierKeys)
1178
+ }),
1179
+ Array.from({
1180
+ length: 10
1181
+ }).map(function(_, i) {
1182
+ var _keyMap_get;
1183
+ return /* @__PURE__ */ jsx3(Key, {
1184
+ delayDisplay: animate ? displayMap.get(keyboardRows[3][i]) : null,
1185
+ baseWidth: baseWidth,
1186
+ label: keyCodeToLabel.get(keyboardRows[3][i]),
1187
+ keyType: keyMap === null || keyMap === void 0 ? void 0 : (_keyMap_get = keyMap.get(keyboardRows[3][i])) === null || _keyMap_get === void 0 ? void 0 : _keyMap_get.type,
1188
+ active: activeKeysIncludes(activeKeys, keyboardRows[3][i]),
1189
+ onClick: function() {
1190
+ var _keyMap_get;
1191
+ return handleClick(keyMap === null || keyMap === void 0 ? void 0 : (_keyMap_get = keyMap.get(keyboardRows[3][i])) === null || _keyMap_get === void 0 ? void 0 : _keyMap_get.midiNote);
1192
+ },
1193
+ hiddenOpacity: !displayMap.get(keyboardRows[3][i]),
1194
+ modifier: dualMode ? void 0 : optionalModifier([
1195
+ keyboardRows[3][i]
1196
+ ], modifierKeys)
1197
+ }, i);
1198
+ }),
1199
+ /* @__PURE__ */ jsx3(Key, {
1200
+ delayDisplay: animate ? displayMap.get("ShiftRight") : null,
1201
+ baseWidth: baseWidth,
1202
+ size: 2.75,
1203
+ hidden: !displayMap.get("ShiftRight"),
1204
+ label: "shift",
1205
+ active: activeKeysIncludes(activeKeys, "ShiftRight"),
1206
+ modifier: optionalModifier([
1207
+ "ShiftRight"
1208
+ ], modifierKeys)
1209
+ })
1210
+ ]
1211
+ })
1212
+ ]
1213
+ });
1214
+ };
1215
+ var Container3 = styled3.div(_templateObject19(), function(props) {
1216
+ return props.$width;
1217
+ });
1218
+ var Row = styled3.div(_templateObject20(), function(props) {
1219
+ return props.$show ? "flex" : "none";
1220
+ }, function(props) {
1221
+ return props.$shift;
1222
+ });
1223
+ // src/Piano/Piano.tsx
1224
+ import { keyboardWhiteNotes as keyboardWhiteNotes3 } from "minikeys";
1225
+ import styled6 from "styled-components";
1226
+ // src/Piano/BlackNotes.tsx
1227
+ import { keyboardBlackNotes, noteToMidi } from "minikeys";
1228
+ // src/Piano/PianoKey.tsx
1229
+ import styled4 from "styled-components";
1230
+ import { jsx as jsx4 } from "react/jsx-runtime";
1231
+ var PianoKeyRect = function(param) {
1232
+ var width = param.width, height = param.height, offset = param.offset, fill = param.fill, strokeWidth = param.strokeWidth, strokeColour = param.strokeColour, noBorder = param.noBorder, type = param.type;
1233
+ var curve = height * 0.025;
1234
+ return /* @__PURE__ */ jsx4(Path, {
1235
+ $type: type,
1236
+ d: "\n M".concat(width + (noBorder ? offset - strokeWidth : offset), " ").concat(type === "white" ? noBorder ? 0 : strokeWidth / 2 : 0, ",\n L").concat(width + (noBorder ? offset - strokeWidth : offset), " ").concat(height - curve - strokeWidth / 2, ",\n q0,").concat(curve, " -").concat(curve, ",").concat(curve, ",\n L").concat(offset + curve + strokeWidth / 2, " ").concat(height - strokeWidth / 2, ",\n q-").concat(curve, ",0 -").concat(curve, ",-").concat(curve, ",\n L").concat(offset + strokeWidth / 2, " ").concat(type === "white" ? noBorder ? 0 : strokeWidth / 2 : 0, ",\n Z\n "),
1237
+ fill: fill !== null && fill !== void 0 ? fill : type === "white" ? "white" : "#222",
1238
+ stroke: noBorder ? "none" : type === "white" ? strokeColour !== null && strokeColour !== void 0 ? strokeColour : "black" : "none",
1239
+ strokeWidth: strokeWidth
1240
+ });
1241
+ };
1242
+ var Path = styled4.path(_templateObject21(), function(param) {
1243
+ var $type = param.$type;
1244
+ return $type === "white" ? "#ddd" : "black";
1245
+ }, function(param) {
1246
+ var $type = param.$type;
1247
+ return $type === "white" ? "#ccc" : "#444";
1248
+ });
1249
+ // src/Piano/commonStyles.tsx
1250
+ import styled5 from "styled-components";
1251
+ var NoteLabel = styled5.text(_templateObject22());
1252
+ // src/Piano/BlackNotes.tsx
1253
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
1254
+ var BlackNotes = function(param) {
1255
+ var numKeys = param.numKeys, width = param.width, height = param.height, strokeWidth = param.strokeWidth, baseNoteOffset = param.baseNoteOffset, showLabels = param.showLabels, highlights = param.highlights, noBorder = param.noBorder, handleClick = param.handleClick;
1256
+ var keyWidth = (width - strokeWidth / 2) / numKeys + strokeWidth / 2 * ((numKeys - 1) / numKeys);
1257
+ var getFill = function(i) {
1258
+ var note = keyboardBlackNotes[baseNoteOffset + i];
1259
+ if (note !== null) {
1260
+ var _highlights_activeNotes;
1261
+ if (highlights === null || highlights === void 0 ? void 0 : (_highlights_activeNotes = highlights.activeNotes) === null || _highlights_activeNotes === void 0 ? void 0 : _highlights_activeNotes.includes(note)) {
1262
+ return "#444";
1263
+ }
1264
+ }
1265
+ return "#222";
1266
+ };
1267
+ var nudgeDirection = function(i) {
1268
+ if (i > 0 && i < keyboardBlackNotes.length) {
1269
+ if (keyboardBlackNotes[i - 1] === null) {
1270
+ return -1;
1271
+ } else if (keyboardBlackNotes[i + 1] === null) {
1272
+ return 1;
1273
+ }
1274
+ }
1275
+ return 0;
1276
+ };
1277
+ var handleNoteClick = function(i) {
1278
+ if (!handleClick) {
1279
+ return;
1280
+ }
1281
+ var namedNote = keyboardBlackNotes[baseNoteOffset + i];
1282
+ if (namedNote === null) {
1283
+ return;
1284
+ }
1285
+ var midiNote = noteToMidi[namedNote];
1286
+ handleClick(midiNote);
1287
+ };
1288
+ return Array.from({
1289
+ length: numKeys + 1
1290
+ }).map(function(_, i) {
1291
+ return keyboardBlackNotes[baseNoteOffset + i] && /* @__PURE__ */ jsxs3("g", {
1292
+ onMouseDown: function() {
1293
+ return handleNoteClick(i);
1294
+ },
1295
+ children: [
1296
+ /* @__PURE__ */ jsx5(PianoKeyRect, {
1297
+ width: keyWidth * 0.65,
1298
+ height: height * 0.65,
1299
+ offset: i * keyWidth - i * (strokeWidth / 2) - (keyWidth * 0.65 - strokeWidth) / 2 + nudgeDirection(baseNoteOffset + i) * keyWidth * 0.1,
1300
+ strokeWidth: 1.5,
1301
+ fill: getFill(i),
1302
+ type: "black",
1303
+ noBorder: noBorder
1304
+ }),
1305
+ showLabels && i * keyWidth - i * strokeWidth / 2 > 5 && i * keyWidth - i * strokeWidth / 2 < width - 5 && /* @__PURE__ */ jsx5(NoteLabel, {
1306
+ x: i * keyWidth - i * strokeWidth / 2 + strokeWidth / 2 + nudgeDirection(baseNoteOffset + i) * keyWidth * 0.1,
1307
+ y: height * 0.65 - height * 0.03,
1308
+ textAnchor: "middle",
1309
+ fontSize: height * 0.04,
1310
+ fill: "white",
1311
+ opacity: 0.8,
1312
+ children: keyboardBlackNotes[baseNoteOffset + i]
1313
+ })
1314
+ ]
1315
+ }, "piano-key-black-".concat(i));
1316
+ });
1317
+ };
1318
+ // src/Piano/WhiteNotes.tsx
1319
+ import { keyboardWhiteNotes as keyboardWhiteNotes2, noteToMidi as noteToMidi2 } from "minikeys";
1320
+ // src/Piano/utils.ts
1321
+ var keyboardWhiteNotes = [
1322
+ "A0",
1323
+ "B0",
1324
+ "C1",
1325
+ "D1",
1326
+ "E1",
1327
+ "F1",
1328
+ "G1",
1329
+ "A1",
1330
+ "B1",
1331
+ "C2",
1332
+ "D2",
1333
+ "E2",
1334
+ "F2",
1335
+ "G2",
1336
+ "A2",
1337
+ "B2",
1338
+ "C3",
1339
+ "D3",
1340
+ "E3",
1341
+ "F3",
1342
+ "G3",
1343
+ "A3",
1344
+ "B3",
1345
+ "C4",
1346
+ "D4",
1347
+ "E4",
1348
+ "F4",
1349
+ "G4",
1350
+ "A4",
1351
+ "B4",
1352
+ "C5",
1353
+ "D5",
1354
+ "E5",
1355
+ "F5",
1356
+ "G5",
1357
+ "A5",
1358
+ "B5",
1359
+ "C6",
1360
+ "D6",
1361
+ "E6",
1362
+ "F6",
1363
+ "G6",
1364
+ "A6",
1365
+ "B6",
1366
+ "C7",
1367
+ "D7",
1368
+ "E7",
1369
+ "F7",
1370
+ "G7",
1371
+ "A7",
1372
+ "B7",
1373
+ "C8"
1374
+ ];
1375
+ var nextWhiteNoteIndex = function(note) {
1376
+ var whiteNote = note.replace("#", "");
1377
+ if (keyboardWhiteNotes.includes(whiteNote)) {
1378
+ if (note.includes("#")) {
1379
+ return keyboardWhiteNotes.indexOf(whiteNote) + 1;
1380
+ } else {
1381
+ return keyboardWhiteNotes.indexOf(whiteNote);
1382
+ }
1383
+ } else {
1384
+ throw new Error("Lower range note ".concat(note, " invalid"));
1385
+ }
1386
+ };
1387
+ var prevWhiteNoteIndex = function(note) {
1388
+ var whiteNote = note.replace("#", "");
1389
+ if (keyboardWhiteNotes.includes(whiteNote)) {
1390
+ return keyboardWhiteNotes.indexOf(whiteNote);
1391
+ } else {
1392
+ throw new Error("Lower range note ".concat(note, " invalid"));
1393
+ }
1394
+ };
1395
+ // src/Piano/WhiteNotes.tsx
1396
+ import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
1397
+ var WhiteNotes = function(param) {
1398
+ var numKeys = param.numKeys, width = param.width, height = param.height, strokeWidth = param.strokeWidth, strokeColour = param.strokeColour, baseNoteOffset = param.baseNoteOffset, showLabels = param.showLabels, highlights = param.highlights, noBorder = param.noBorder, handleClick = param.handleClick;
1399
+ var keyWidth = (width - strokeWidth / 2) / numKeys + strokeWidth / 2 * ((numKeys - 1) / numKeys);
1400
+ var getFill = function(i) {
1401
+ var _highlights_activeNotes;
1402
+ if (highlights === null || highlights === void 0 ? void 0 : (_highlights_activeNotes = highlights.activeNotes) === null || _highlights_activeNotes === void 0 ? void 0 : _highlights_activeNotes.includes(keyboardWhiteNotes2[baseNoteOffset + i])) {
1403
+ return "#ccc";
1404
+ } else if ((highlights === null || highlights === void 0 ? void 0 : highlights.rangeStart) || (highlights === null || highlights === void 0 ? void 0 : highlights.rangeEnd)) {
1405
+ var _highlights_rangeStart, _highlights_rangeEnd;
1406
+ if (keyboardWhiteNotes2.slice(nextWhiteNoteIndex((_highlights_rangeStart = highlights === null || highlights === void 0 ? void 0 : highlights.rangeStart) !== null && _highlights_rangeStart !== void 0 ? _highlights_rangeStart : "A0"), prevWhiteNoteIndex((_highlights_rangeEnd = highlights === null || highlights === void 0 ? void 0 : highlights.rangeEnd) !== null && _highlights_rangeEnd !== void 0 ? _highlights_rangeEnd : "C8") + 1).includes(keyboardWhiteNotes2[baseNoteOffset + i])) {
1407
+ var _highlights_rangeColor;
1408
+ return (_highlights_rangeColor = highlights === null || highlights === void 0 ? void 0 : highlights.rangeColor) !== null && _highlights_rangeColor !== void 0 ? _highlights_rangeColor : "#eee";
1409
+ }
1410
+ }
1411
+ return "white";
1412
+ };
1413
+ var handleNoteClick = function(i) {
1414
+ if (!handleClick) {
1415
+ return;
1416
+ }
1417
+ var namedNote = keyboardWhiteNotes2[baseNoteOffset + i];
1418
+ var midiNote = noteToMidi2[namedNote];
1419
+ handleClick(midiNote);
1420
+ };
1421
+ return Array.from({
1422
+ length: numKeys
1423
+ }).map(function(_, i) {
1424
+ return /* @__PURE__ */ jsxs4("g", {
1425
+ onMouseDown: function() {
1426
+ return handleNoteClick(i);
1427
+ },
1428
+ children: [
1429
+ /* @__PURE__ */ jsx6(PianoKeyRect, {
1430
+ width: keyWidth,
1431
+ height: height,
1432
+ offset: i * keyWidth - i * strokeWidth / 2,
1433
+ strokeWidth: strokeWidth,
1434
+ strokeColour: strokeColour,
1435
+ type: "white",
1436
+ fill: getFill(i),
1437
+ noBorder: noBorder
1438
+ }),
1439
+ showLabels && /* @__PURE__ */ jsx6(NoteLabel, {
1440
+ x: i * keyWidth - i * strokeWidth / 2 + keyWidth / 2,
1441
+ y: height - height * 0.03,
1442
+ textAnchor: "middle",
1443
+ fontSize: height * 0.04,
1444
+ fill: "black",
1445
+ opacity: 0.6,
1446
+ children: keyboardWhiteNotes2[baseNoteOffset + i]
1447
+ })
1448
+ ]
1449
+ }, "piano-key-white-".concat(i));
1450
+ });
1451
+ };
1452
+ // src/Piano/Piano.tsx
1453
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
1454
+ var Piano = function(_param) {
1455
+ var width = _param.width, _param_numKeys = _param.numKeys, numKeys = _param_numKeys === void 0 ? 15 : _param_numKeys, height = _param.height, _param_strokeWidth = _param.strokeWidth, strokeWidth = _param_strokeWidth === void 0 ? 1.5 : _param_strokeWidth, strokeColour = _param.strokeColour, _param_baseNote = _param.baseNote, baseNote = _param_baseNote === void 0 ? "C4" : _param_baseNote, _param_showLabels = _param.showLabels, showLabels = _param_showLabels === void 0 ? false : _param_showLabels, _param_noBorder = _param.noBorder, noBorder = _param_noBorder === void 0 ? false : _param_noBorder, highlights = _param.highlights, onClick = _param.onClick, props = _object_without_properties(_param, [
1456
+ "width",
1457
+ "numKeys",
1458
+ "height",
1459
+ "strokeWidth",
1460
+ "strokeColour",
1461
+ "baseNote",
1462
+ "showLabels",
1463
+ "noBorder",
1464
+ "highlights",
1465
+ "onClick"
1466
+ ]);
1467
+ var keyHeight = height !== null && height !== void 0 ? height : Math.min(width / numKeys * 5, width / 4);
1468
+ var maxNumKeys = Math.min(numKeys, 52);
1469
+ var baseNoteOffset = Math.min(keyboardWhiteNotes3.indexOf(baseNote), 52 - numKeys);
1470
+ var handleClick = function(midiNote) {
1471
+ if (onClick && midiNote !== null && midiNote !== void 0) {
1472
+ onClick(midiNote);
1473
+ }
1474
+ };
1475
+ return /* @__PURE__ */ jsxs5(Svg, _object_spread_props(_object_spread({
1476
+ viewBox: "0 0 ".concat(width, " ").concat(keyHeight),
1477
+ width: width,
1478
+ height: keyHeight,
1479
+ xmlns: "http://www.w3.org/2000/svg"
1480
+ }, props), {
1481
+ children: [
1482
+ /* @__PURE__ */ jsx7("g", {
1483
+ children: /* @__PURE__ */ jsx7(WhiteNotes, {
1484
+ numKeys: maxNumKeys,
1485
+ width: width,
1486
+ height: keyHeight,
1487
+ strokeWidth: strokeWidth,
1488
+ strokeColour: strokeColour,
1489
+ baseNoteOffset: baseNoteOffset,
1490
+ showLabels: showLabels,
1491
+ highlights: highlights,
1492
+ handleClick: handleClick,
1493
+ noBorder: noBorder
1494
+ })
1495
+ }),
1496
+ /* @__PURE__ */ jsx7("g", {
1497
+ children: /* @__PURE__ */ jsx7(BlackNotes, {
1498
+ numKeys: maxNumKeys,
1499
+ width: width,
1500
+ height: keyHeight,
1501
+ strokeWidth: strokeWidth,
1502
+ baseNoteOffset: baseNoteOffset,
1503
+ showLabels: showLabels,
1504
+ highlights: highlights,
1505
+ handleClick: handleClick,
1506
+ noBorder: noBorder
1507
+ })
1508
+ })
1509
+ ]
1510
+ }));
1511
+ };
1512
+ var Svg = styled6.svg(_templateObject23());
1513
+ export { Keyboard, Piano, useKeyboardControl, useMiniKeys, useMiniKeysKeyboard };