@hussmartinez/audio-sdk 0.6.0 → 0.7.1

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.
@@ -0,0 +1,2801 @@
1
+ import { A as createAudioOutput, B as clipEnd, D as bytesPerSample, E as createAudioProcessor, H as planLength, I as MIN_GAIN_DB, K as isAudioError, L as NO_FADE, M as gainAt, O as dataSize, R as audibleTracks, W as createAudioEngine, _ as MAX_METADATA_LENGTH, a as createAudioSession, c as formatTimecode, f as peakColumns, i as watchPlayhead, j as dbToGain, n as audioWarningText, o as cleanFileName, r as audioMessages, s as connectOutput, t as audioErrorText, z as clipAt } from "./text-2gfztfJE.js";
2
+ import { createMessages, createShortcutRegistry, createToolRegistry, defineMessages, defineTool, isSdkError, plural } from "@hussmartinez/sdk-core";
3
+ import { AddIcon, AnnouncerProvider, Button, ChevronLeftIcon, ChevronRightIcon, CloseIcon, DeleteIcon, Dialog, DownloadIcon, FadeInIcon, FadeOutIcon, Field, FileDropZone, FitIcon, IconButton, MoveDownIcon, MoveUpIcon, MutedIcon, NumberField, OpenIcon, PauseIcon, PlayIcon, ProgressBar, RangeEndIcon, RangeStartIcon, RedoIcon, RemoveIcon, RippleIcon, SegmentedControl, SkipBackIcon, SkipForwardIcon, Slider, SplitIcon, TextField, Timeline, TimelineClips, TimelineLane, TimelineLayer, TimelinePlayhead, ToggleButton, Toolbar, ToolbarGroup, TrimEndIcon, TrimStartIcon, UiMessagesProvider, UndoIcon, UploadIcon, ZoomInIcon, ZoomOutIcon, useAnnounce, usePlatform, useTimelineLanes, useTimelineScale } from "@hussmartinez/ui/react";
4
+ import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore } from "react";
5
+ import { uiMessages } from "@hussmartinez/ui";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ // src/adapters/wav/wav-layout.ts
8
+ var MAX_32 = 4294967295;
9
+ var INFO_IDS = [
10
+ ["title", "INAM"],
11
+ ["artist", "IART"],
12
+ ["album", "IPRD"],
13
+ ["year", "ICRD"],
14
+ ["comment", "ICMT"]
15
+ ];
16
+ function infoFields(metadata) {
17
+ const encoder = new TextEncoder();
18
+ return INFO_IDS.flatMap(([field, id]) => {
19
+ const text = metadata[field];
20
+ return text === "" ? [] : [{
21
+ id,
22
+ value: encoder.encode(`${text}\0`)
23
+ }];
24
+ });
25
+ }
26
+ function infoSize(fields) {
27
+ if (fields.length === 0) return 0;
28
+ return 4 + fields.reduce((sum, { value }) => sum + 8 + value.length + value.length % 2, 0);
29
+ }
30
+ function wavLayout(spec, fields = infoFields(spec.metadata)) {
31
+ const { channels, frames, sampleFormat } = spec;
32
+ const bytes = bytesPerSample(sampleFormat);
33
+ const float = sampleFormat === "float32";
34
+ const extensible = channels > 2 || bytes > 2;
35
+ const fmtSize = extensible ? 40 : float ? 18 : 16;
36
+ const info = infoSize(fields);
37
+ const data = dataSize(spec);
38
+ const pad = data % 2;
39
+ const chunks = 8 + fmtSize + (float ? 12 : 0) + (info ? 8 + info : 0) + 8 + data + pad;
40
+ const riffSize = 4 + chunks;
41
+ const rf64 = riffSize > MAX_32 || data > MAX_32 || frames > MAX_32;
42
+ const fileSize = 12 + (rf64 ? 36 : 0) + chunks;
43
+ return {
44
+ bytes,
45
+ float,
46
+ extensible,
47
+ fmtSize,
48
+ infoSize: info,
49
+ data,
50
+ pad,
51
+ riffSize,
52
+ rf64,
53
+ headerSize: fileSize - data - pad,
54
+ fileSize
55
+ };
56
+ }
57
+ function wavFileSize(spec) {
58
+ return wavLayout(spec).fileSize;
59
+ }
60
+ // src/features/export-name/export-name.ts
61
+ var AUDIO_EXTENSION = /\.(wav|wave|mp3|m4a|mp4|aac|adts|flac|ogg|oga|opus|weba|webm)$/iu;
62
+ function withoutAudioExtension(raw) {
63
+ const clean = cleanFileName(raw);
64
+ return clean === void 0 ? void 0 : cleanFileName(clean.replace(AUDIO_EXTENSION, ""));
65
+ }
66
+ function exportFileName(fileName, title) {
67
+ return withoutAudioExtension(fileName) ?? withoutAudioExtension(title) ?? "recording";
68
+ }
69
+ // src/features/range/range.ts
70
+ function selectRange(context, start, end) {
71
+ const { plan, selection } = context.state;
72
+ if (!plan || start >= end) return;
73
+ const keys = selection?.tracks;
74
+ context.select(keys ? {
75
+ start,
76
+ end,
77
+ tracks: keys
78
+ } : {
79
+ start,
80
+ end
81
+ });
82
+ const tracks = keys ? plan.tracks.filter((track) => keys.includes(track.key)) : plan.tracks;
83
+ context.announce({
84
+ key: "announce.selected",
85
+ frame: start,
86
+ end,
87
+ tracks
88
+ });
89
+ }
90
+ function deleteRange(context) {
91
+ const { plan, selection, ripple } = context.state;
92
+ if (!plan || !selection) return;
93
+ const { start, end } = selection;
94
+ if (context.execute({
95
+ type: "audio.deleteRange",
96
+ start,
97
+ end,
98
+ tracks: selection.tracks,
99
+ ripple
100
+ })) {
101
+ context.announce({ key: "announce.refused" });
102
+ return;
103
+ }
104
+ context.seek(start);
105
+ context.focusPlayhead();
106
+ context.announce({
107
+ key: ripple ? "announce.rangeDeleted.ripple" : "announce.rangeDeleted",
108
+ frame: start,
109
+ end,
110
+ tracks: plan.tracks.filter((track) => selection.tracks.includes(track.key))
111
+ });
112
+ }
113
+ var hasLength = (state) => state.plan !== void 0 && planLength(state.plan) > 0;
114
+ var rangeTools = [
115
+ defineTool({
116
+ id: "audio.set-start",
117
+ label: "tools.setStart",
118
+ icon: "range-start",
119
+ group: "range",
120
+ shortcuts: ["I"],
121
+ isEnabled: hasLength,
122
+ run: (context) => {
123
+ const { plan, selection } = context.state;
124
+ if (!plan) return;
125
+ const frame = context.playhead();
126
+ selectRange(context, frame, selection && selection.end > frame ? selection.end : planLength(plan));
127
+ }
128
+ }),
129
+ defineTool({
130
+ id: "audio.set-end",
131
+ label: "tools.setEnd",
132
+ icon: "range-end",
133
+ group: "range",
134
+ shortcuts: ["O"],
135
+ isEnabled: hasLength,
136
+ run: (context) => {
137
+ const { selection } = context.state;
138
+ const frame = context.playhead();
139
+ selectRange(context, selection && selection.start < frame ? selection.start : 0, frame);
140
+ }
141
+ }),
142
+ defineTool({
143
+ id: "audio.clear-selection",
144
+ label: "tools.clearSelection",
145
+ icon: "close",
146
+ group: "range",
147
+ shortcuts: "cancel",
148
+ isEnabled: (state) => state.selection !== void 0,
149
+ run: (context) => {
150
+ context.select(void 0);
151
+ context.announce({ key: "announce.selectionCleared" });
152
+ }
153
+ }),
154
+ defineTool({
155
+ id: "audio.ripple",
156
+ label: "tools.ripple",
157
+ icon: "ripple",
158
+ group: "range",
159
+ isEnabled: (state) => state.plan !== void 0,
160
+ isActive: (state) => state.ripple,
161
+ run: (context) => {
162
+ context.setRipple(!context.state.ripple);
163
+ context.announce({ key: context.state.ripple ? "announce.rippleOff" : "announce.rippleOn" });
164
+ }
165
+ })
166
+ ];
167
+ // src/features/clips/clips.ts
168
+ function findClip(plan, key) {
169
+ for (const track of plan.tracks) {
170
+ const clip = track.clips.find((each) => each.key === key);
171
+ if (clip) return {
172
+ clip,
173
+ track
174
+ };
175
+ }
176
+ }
177
+ function nudgeFrames(plan) {
178
+ return Math.max(1, Math.round(plan.sampleRate / 100));
179
+ }
180
+ function canPlace(plan, keys, by, track) {
181
+ if (track !== void 0 && !plan.tracks.some((each) => each.key === track)) return false;
182
+ const moving = new Set(keys);
183
+ const spans = /* @__PURE__ */ new Map();
184
+ const add = (key, span) => {
185
+ const list = spans.get(key);
186
+ if (list) list.push(span);
187
+ else spans.set(key, [span]);
188
+ };
189
+ for (const each of plan.tracks) for (const clip of each.clips) if (!moving.has(clip.key)) add(each.key, [clip.at, clipEnd(clip)]);
190
+ for (const key of moving) {
191
+ const placed = findClip(plan, key);
192
+ if (!placed) return false;
193
+ const at = placed.clip.at + by;
194
+ if (at < 0) return false;
195
+ add(track ?? placed.track.key, [at, at + clipEnd(placed.clip) - placed.clip.at]);
196
+ }
197
+ for (const list of spans.values()) {
198
+ list.sort((a, b) => a[0] - b[0]);
199
+ for (let i = 1; i < list.length; i++) if (list[i][0] < list[i - 1][1]) return false;
200
+ }
201
+ return true;
202
+ }
203
+ function trimLimits(plan, sourceFrames, key, edge) {
204
+ const placed = findClip(plan, key);
205
+ if (!placed) return {
206
+ min: 0,
207
+ max: 0
208
+ };
209
+ const { clip, track } = placed;
210
+ const index = track.clips.indexOf(clip);
211
+ const min = -(clip.end - clip.start - 1);
212
+ if (edge === "start") {
213
+ const before = track.clips[index - 1];
214
+ return {
215
+ min,
216
+ max: Math.min(clip.start, clip.at - (before ? clipEnd(before) : 0))
217
+ };
218
+ }
219
+ const after = track.clips[index + 1];
220
+ const room = after ? after.at - clipEnd(clip) : Number.POSITIVE_INFINITY;
221
+ return {
222
+ min,
223
+ max: Math.max(0, Math.min(sourceFrames(clip.source) - clip.end, room))
224
+ };
225
+ }
226
+ function moveClips(context, keys, by, track) {
227
+ const { plan } = context.state;
228
+ if (!plan || keys.length === 0) return false;
229
+ if (!canPlace(plan, keys, by, track)) {
230
+ context.announce({ key: "announce.noRoom" });
231
+ return false;
232
+ }
233
+ const command = {
234
+ type: "audio.moveClips",
235
+ keys,
236
+ by
237
+ };
238
+ if (context.execute(track === void 0 ? command : {
239
+ ...command,
240
+ track
241
+ })) {
242
+ context.announce({ key: "announce.refused" });
243
+ return false;
244
+ }
245
+ return true;
246
+ }
247
+ function moveClipsToTrack(context, keys, direction) {
248
+ const { plan } = context.state;
249
+ const first = keys[0];
250
+ const placed = plan && first !== void 0 ? findClip(plan, first) : void 0;
251
+ if (!plan || !placed || first === void 0) return;
252
+ const target = plan.tracks[plan.tracks.indexOf(placed.track) + direction];
253
+ if (!target) return;
254
+ if (moveClips(context, keys, 0, target.key)) {
255
+ context.focusClip(first);
256
+ context.announce({
257
+ key: "announce.clipMovedTo",
258
+ track: target
259
+ });
260
+ }
261
+ }
262
+ function trimClip(context, key, edge, delta) {
263
+ const { plan } = context.state;
264
+ const placed = plan ? findClip(plan, key) : void 0;
265
+ if (!plan || !placed || delta === 0) return false;
266
+ const limits = trimLimits(plan, context.sourceFrames, key, edge);
267
+ if (delta < limits.min || delta > limits.max) {
268
+ context.announce({ key: "announce.noRoom" });
269
+ return false;
270
+ }
271
+ const { clip } = placed;
272
+ const refused = context.execute({
273
+ type: "audio.trimClip",
274
+ key,
275
+ start: edge === "start" ? clip.start - delta : clip.start,
276
+ end: edge === "end" ? clip.end + delta : clip.end
277
+ });
278
+ if (refused) context.announce({ key: "announce.refused" });
279
+ return refused === void 0;
280
+ }
281
+ function trimClipToPlayhead(context, key, edge) {
282
+ const { plan } = context.state;
283
+ const placed = plan ? findClip(plan, key) : void 0;
284
+ if (!placed) return;
285
+ const frame = context.playhead();
286
+ const { clip } = placed;
287
+ const delta = edge === "start" ? clip.at - frame : frame - clipEnd(clip);
288
+ if (delta === 0) return;
289
+ if (trimClip(context, key, edge, delta)) {
290
+ const at = edge === "start" ? frame : clip.at;
291
+ const end = edge === "end" ? frame : clipEnd(clip);
292
+ context.announce({
293
+ key: "announce.trimmed",
294
+ frame: at,
295
+ end
296
+ });
297
+ }
298
+ }
299
+ function split(context) {
300
+ const track = context.state.clip?.track ?? context.state.track;
301
+ if (!track) return;
302
+ const frame = context.playhead();
303
+ const clip = clipAt(track, frame);
304
+ if (!clip || clip.at === frame) {
305
+ context.announce({
306
+ key: "announce.noClipToSplit",
307
+ track
308
+ });
309
+ return;
310
+ }
311
+ const newKey = context.newKey();
312
+ if (context.execute({
313
+ type: "audio.splitClip",
314
+ key: clip.key,
315
+ at: frame,
316
+ newKey
317
+ })) {
318
+ context.announce({ key: "announce.refused" });
319
+ return;
320
+ }
321
+ context.focusClip(newKey);
322
+ context.announce({
323
+ key: "announce.split",
324
+ frame
325
+ });
326
+ }
327
+ var editable$1 = (state) => state.plan !== void 0 && !state.busy;
328
+ var withClip = (state) => editable$1(state) && state.clip !== void 0;
329
+ var trackIndex$1 = (state) => state.plan && state.clip ? state.plan.tracks.indexOf(state.clip.track) : -1;
330
+ var clipTools = [
331
+ defineTool({
332
+ id: "audio.split",
333
+ label: "tools.split",
334
+ icon: "split",
335
+ group: "clips",
336
+ shortcuts: ["S"],
337
+ isEnabled: (state) => editable$1(state) && (state.clip ?? state.track) !== void 0,
338
+ run: split
339
+ }),
340
+ defineTool({
341
+ id: "audio.delete",
342
+ label: "tools.delete",
343
+ icon: "delete",
344
+ group: "clips",
345
+ shortcuts: "delete",
346
+ isEnabled: (state) => withClip(state) || editable$1(state) && state.selection !== void 0,
347
+ run: (context) => {
348
+ if (context.state.selection) {
349
+ deleteRange(context);
350
+ return;
351
+ }
352
+ const placed = context.state.clip;
353
+ if (!placed) return;
354
+ if (context.execute({
355
+ type: "audio.removeClips",
356
+ keys: [placed.clip.key]
357
+ })) {
358
+ context.announce({ key: "announce.refused" });
359
+ return;
360
+ }
361
+ context.announce({ key: "announce.clipDeleted" });
362
+ }
363
+ }),
364
+ defineTool({
365
+ id: "audio.trim-start",
366
+ label: "tools.trimStart",
367
+ icon: "trim-start",
368
+ group: "clips",
369
+ shortcuts: ["["],
370
+ isEnabled: withClip,
371
+ run: (context) => {
372
+ const placed = context.state.clip;
373
+ if (placed) trimClipToPlayhead(context, placed.clip.key, "start");
374
+ }
375
+ }),
376
+ defineTool({
377
+ id: "audio.trim-end",
378
+ label: "tools.trimEnd",
379
+ icon: "trim-end",
380
+ group: "clips",
381
+ shortcuts: ["]"],
382
+ isEnabled: withClip,
383
+ run: (context) => {
384
+ const placed = context.state.clip;
385
+ if (placed) trimClipToPlayhead(context, placed.clip.key, "end");
386
+ }
387
+ }),
388
+ defineTool({
389
+ id: "audio.move-earlier",
390
+ label: "tools.moveEarlier",
391
+ icon: "chevron-left",
392
+ group: "clips",
393
+ isEnabled: (state) => withClip(state) && (state.clip?.clip.at ?? 0) > 0,
394
+ run: (context) => {
395
+ const { plan, clip } = context.state;
396
+ if (plan && clip) moveClips(context, [clip.clip.key], -nudgeFrames(plan));
397
+ }
398
+ }),
399
+ defineTool({
400
+ id: "audio.move-later",
401
+ label: "tools.moveLater",
402
+ icon: "chevron-right",
403
+ group: "clips",
404
+ isEnabled: withClip,
405
+ run: (context) => {
406
+ const { plan, clip } = context.state;
407
+ if (plan && clip) moveClips(context, [clip.clip.key], nudgeFrames(plan));
408
+ }
409
+ }),
410
+ defineTool({
411
+ id: "audio.move-to-track-above",
412
+ label: "tools.moveToTrackAbove",
413
+ icon: "move-up",
414
+ group: "clips",
415
+ isEnabled: (state) => withClip(state) && trackIndex$1(state) > 0,
416
+ run: (context) => {
417
+ const placed = context.state.clip;
418
+ if (placed) moveClipsToTrack(context, [placed.clip.key], -1);
419
+ }
420
+ }),
421
+ defineTool({
422
+ id: "audio.move-to-track-below",
423
+ label: "tools.moveToTrackBelow",
424
+ icon: "move-down",
425
+ group: "clips",
426
+ isEnabled: (state) => withClip(state) && trackIndex$1(state) >= 0 && trackIndex$1(state) < (state.plan?.tracks.length ?? 0) - 1,
427
+ run: (context) => {
428
+ const placed = context.state.clip;
429
+ if (placed) moveClipsToTrack(context, [placed.clip.key], 1);
430
+ }
431
+ })
432
+ ];
433
+ // src/features/range/edits.ts
434
+ var DEFAULT_FADE_SECONDS = .5;
435
+ function splitAtRange(plan, selection, newKey) {
436
+ const commands = [];
437
+ const pieces = [];
438
+ const { start, end } = selection;
439
+ for (const track of plan.tracks) {
440
+ if (!selection.tracks.includes(track.key)) continue;
441
+ for (const clip of track.clips) {
442
+ const from = clip.at;
443
+ const to = clipEnd(clip);
444
+ if (to <= start || from >= end) continue;
445
+ let key = clip.key;
446
+ if (from < start) {
447
+ const after = newKey();
448
+ commands.push({
449
+ type: "audio.splitClip",
450
+ key,
451
+ at: start,
452
+ newKey: after
453
+ });
454
+ key = after;
455
+ }
456
+ if (to > end) commands.push({
457
+ type: "audio.splitClip",
458
+ key,
459
+ at: end,
460
+ newKey: newKey()
461
+ });
462
+ pieces.push({
463
+ key,
464
+ track: track.key,
465
+ at: Math.max(from, start),
466
+ end: Math.min(to, end),
467
+ fadeIn: from < start ? NO_FADE : clip.fadeIn,
468
+ fadeOut: to > end ? NO_FADE : clip.fadeOut,
469
+ gainDb: clip.gainDb
470
+ });
471
+ }
472
+ }
473
+ return {
474
+ commands,
475
+ pieces
476
+ };
477
+ }
478
+ function clipsInRange(plan, selection) {
479
+ return plan.tracks.filter((track) => selection.tracks.includes(track.key)).flatMap((track) => track.clips.filter((clip) => clip.at < selection.end && clipEnd(clip) > selection.start));
480
+ }
481
+ function setRangeGain(context, gainDb) {
482
+ const { plan, selection } = context.state;
483
+ if (!plan || !selection) return;
484
+ const { commands, pieces } = splitAtRange(plan, selection, context.newKey);
485
+ if (pieces.length === 0) {
486
+ context.announce({ key: "announce.nothingInRange" });
487
+ return;
488
+ }
489
+ if (context.execute([...commands, {
490
+ type: "audio.setGain",
491
+ keys: pieces.map((piece) => piece.key),
492
+ gainDb
493
+ }])) {
494
+ context.announce({ key: "announce.refused" });
495
+ return;
496
+ }
497
+ context.announce({
498
+ key: "announce.rangeGain",
499
+ frame: selection.start,
500
+ end: selection.end,
501
+ tracks: plan.tracks.filter((track) => selection.tracks.includes(track.key)),
502
+ gain: gainDb
503
+ });
504
+ }
505
+ function fadeRange(context, edge) {
506
+ const { plan, selection } = context.state;
507
+ if (!plan || !selection) return;
508
+ const { commands, pieces } = splitAtRange(plan, selection, context.newKey);
509
+ const byTrack = /* @__PURE__ */ new Map();
510
+ for (const piece of pieces) byTrack.set(piece.track, [...byTrack.get(piece.track) ?? [], piece]);
511
+ const fades = [];
512
+ for (const list of byTrack.values()) {
513
+ const piece = edge === "in" ? list[0] : list[list.length - 1];
514
+ if (!piece) continue;
515
+ const own = edge === "in" ? piece.fadeIn : piece.fadeOut;
516
+ const other = edge === "in" ? piece.fadeOut : piece.fadeIn;
517
+ const frames = piece.end - piece.at - other.frames;
518
+ if (frames > 0) fades.push({
519
+ type: "audio.setFade",
520
+ key: piece.key,
521
+ edge,
522
+ frames,
523
+ curve: own.curve
524
+ });
525
+ }
526
+ if (fades.length === 0) {
527
+ context.announce({ key: "announce.nothingInRange" });
528
+ return;
529
+ }
530
+ if (context.execute([...commands, ...fades])) {
531
+ context.announce({ key: "announce.refused" });
532
+ return;
533
+ }
534
+ context.announce({
535
+ key: edge === "in" ? "announce.fadedIn" : "announce.fadedOut",
536
+ frame: selection.start,
537
+ end: selection.end,
538
+ tracks: plan.tracks.filter((track) => byTrack.has(track.key))
539
+ });
540
+ }
541
+ function fadeClip(context, edge) {
542
+ const { plan, clip: placed } = context.state;
543
+ if (!plan || !placed) return;
544
+ const { clip } = placed;
545
+ const own = edge === "in" ? clip.fadeIn : clip.fadeOut;
546
+ const other = edge === "in" ? clip.fadeOut : clip.fadeIn;
547
+ const frames = Math.min(Math.round(DEFAULT_FADE_SECONDS * plan.sampleRate), clip.end - clip.start - other.frames);
548
+ if (frames <= 0) {
549
+ context.announce({ key: "announce.noRoomForFade" });
550
+ return;
551
+ }
552
+ if (context.execute({
553
+ type: "audio.setFade",
554
+ key: clip.key,
555
+ edge,
556
+ frames,
557
+ curve: own.curve
558
+ })) {
559
+ context.announce({ key: "announce.refused" });
560
+ return;
561
+ }
562
+ context.announce({
563
+ key: edge === "in" ? "announce.clipFadedIn" : "announce.clipFadedOut",
564
+ frame: frames
565
+ });
566
+ }
567
+ var canFade = (state) => state.plan !== void 0 && !state.busy && (state.selection !== void 0 || state.clip !== void 0);
568
+ var fadeTools = [defineTool({
569
+ id: "audio.fade-in",
570
+ label: "tools.fadeIn",
571
+ icon: "fade-in",
572
+ group: "clips",
573
+ isEnabled: canFade,
574
+ run: (context) => context.state.selection ? fadeRange(context, "in") : fadeClip(context, "in")
575
+ }), defineTool({
576
+ id: "audio.fade-out",
577
+ label: "tools.fadeOut",
578
+ icon: "fade-out",
579
+ group: "clips",
580
+ isEnabled: canFade,
581
+ run: (context) => context.state.selection ? fadeRange(context, "out") : fadeClip(context, "out")
582
+ })];
583
+ var length = (state) => state.plan ? planLength(state.plan) : 0;
584
+ var trackIndex = (state) => state.plan && state.track ? state.plan.tracks.indexOf(state.track) : -1;
585
+ var editable = (state) => state.plan !== void 0 && !state.busy;
586
+ var audioTools = [
587
+ defineTool({
588
+ id: "audio.open",
589
+ label: "tools.open",
590
+ icon: "open",
591
+ group: "file",
592
+ run: (context) => context.chooseFile("open")
593
+ }),
594
+ defineTool({
595
+ id: "audio.insert",
596
+ label: "tools.insert",
597
+ icon: "upload",
598
+ group: "file",
599
+ isEnabled: editable,
600
+ run: (context) => context.chooseFile("insert")
601
+ }),
602
+ defineTool({
603
+ id: "audio.export",
604
+ label: "tools.export",
605
+ icon: "download",
606
+ group: "file",
607
+ isEnabled: (state) => editable(state) && length(state) > 0,
608
+ run: (context) => context.openDialog("export")
609
+ }),
610
+ defineTool({
611
+ id: "audio.undo",
612
+ label: "tools.undo",
613
+ icon: "undo",
614
+ group: "history",
615
+ shortcuts: "undo",
616
+ isEnabled: (state) => state.canUndo && !state.busy,
617
+ run: (context) => {
618
+ context.undo();
619
+ context.announce({ key: "announce.undone" });
620
+ }
621
+ }),
622
+ defineTool({
623
+ id: "audio.redo",
624
+ label: "tools.redo",
625
+ icon: "redo",
626
+ group: "history",
627
+ shortcuts: "redo",
628
+ isEnabled: (state) => state.canRedo && !state.busy,
629
+ run: (context) => {
630
+ context.redo();
631
+ context.announce({ key: "announce.redone" });
632
+ }
633
+ }),
634
+ defineTool({
635
+ id: "audio.add-track",
636
+ label: "tools.addTrack",
637
+ icon: "add",
638
+ group: "tracks",
639
+ isEnabled: editable,
640
+ run: (context) => {
641
+ const key = context.newKey();
642
+ const index = trackIndex(context.state) + 1 || (context.state.plan?.tracks.length ?? 0);
643
+ if (context.execute({
644
+ type: "audio.addTrack",
645
+ key,
646
+ index
647
+ })) return;
648
+ context.focusTrack(key);
649
+ context.announce({ key: "announce.trackAdded" });
650
+ }
651
+ }),
652
+ defineTool({
653
+ id: "audio.remove-track",
654
+ label: "tools.removeTrack",
655
+ icon: "remove",
656
+ group: "tracks",
657
+ isEnabled: (state) => editable(state) && state.track !== void 0 && (state.plan?.tracks.length ?? 0) > 1,
658
+ run: (context) => {
659
+ const { plan, track } = context.state;
660
+ if (!plan || !track) return;
661
+ const index = plan.tracks.indexOf(track);
662
+ if (context.execute({
663
+ type: "audio.removeTracks",
664
+ keys: [track.key]
665
+ })) return;
666
+ const next = plan.tracks[index + 1] ?? plan.tracks[index - 1];
667
+ if (next) context.focusTrack(next.key);
668
+ context.announce({
669
+ key: "announce.trackRemoved",
670
+ track
671
+ });
672
+ }
673
+ }),
674
+ defineTool({
675
+ id: "audio.move-track-up",
676
+ label: "tools.moveTrackUp",
677
+ icon: "move-up",
678
+ group: "tracks",
679
+ isEnabled: (state) => editable(state) && trackIndex(state) > 0,
680
+ run: (context) => {
681
+ const { track } = context.state;
682
+ if (!track) return;
683
+ const to = trackIndex(context.state) - 1;
684
+ if (context.execute({
685
+ type: "audio.moveTrack",
686
+ key: track.key,
687
+ to
688
+ })) return;
689
+ context.focusTrack(track.key);
690
+ context.announce({
691
+ key: "announce.trackMoved",
692
+ track
693
+ });
694
+ }
695
+ }),
696
+ defineTool({
697
+ id: "audio.move-track-down",
698
+ label: "tools.moveTrackDown",
699
+ icon: "move-down",
700
+ group: "tracks",
701
+ isEnabled: (state) => editable(state) && trackIndex(state) >= 0 && trackIndex(state) < (state.plan?.tracks.length ?? 0) - 1,
702
+ run: (context) => {
703
+ const { track } = context.state;
704
+ if (!track) return;
705
+ const to = trackIndex(context.state) + 1;
706
+ if (context.execute({
707
+ type: "audio.moveTrack",
708
+ key: track.key,
709
+ to
710
+ })) return;
711
+ context.focusTrack(track.key);
712
+ context.announce({
713
+ key: "announce.trackMoved",
714
+ track
715
+ });
716
+ }
717
+ }),
718
+ defineTool({
719
+ id: "audio.mute",
720
+ label: "tools.mute",
721
+ icon: "muted",
722
+ group: "tracks",
723
+ shortcuts: ["M"],
724
+ isEnabled: (state) => editable(state) && state.track !== void 0,
725
+ isActive: (state) => state.track?.muted ?? false,
726
+ run: (context) => {
727
+ const { track } = context.state;
728
+ if (!track) return;
729
+ if (context.execute({
730
+ type: "audio.setTrack",
731
+ key: track.key,
732
+ muted: !track.muted
733
+ })) return;
734
+ context.announce({
735
+ key: track.muted ? "announce.unmuted" : "announce.muted",
736
+ track
737
+ });
738
+ }
739
+ }),
740
+ defineTool({
741
+ id: "audio.zoom-out",
742
+ label: "tools.zoomOut",
743
+ icon: "zoom-out",
744
+ group: "view",
745
+ shortcuts: "zoom-out",
746
+ isEnabled: (state) => state.plan !== void 0 && state.zoom > 1,
747
+ run: (context) => context.setZoom(Math.max(1, context.state.zoom / 2))
748
+ }),
749
+ defineTool({
750
+ id: "audio.zoom-in",
751
+ label: "tools.zoomIn",
752
+ icon: "zoom-in",
753
+ group: "view",
754
+ shortcuts: "zoom-in",
755
+ isEnabled: (state) => state.plan !== void 0 && state.zoom < state.maxZoom,
756
+ run: (context) => context.setZoom(Math.min(context.state.maxZoom, context.state.zoom * 2))
757
+ }),
758
+ defineTool({
759
+ id: "audio.zoom-fit",
760
+ label: "tools.zoomFit",
761
+ icon: "fit",
762
+ group: "view",
763
+ shortcuts: "zoom-reset",
764
+ isEnabled: (state) => state.plan !== void 0 && state.zoom !== 1,
765
+ run: (context) => context.setZoom(1)
766
+ }),
767
+ ...clipTools,
768
+ ...fadeTools,
769
+ ...rangeTools,
770
+ defineTool({
771
+ id: "audio.play-pause",
772
+ label: "tools.playPause",
773
+ icon: "play",
774
+ group: "playback",
775
+ shortcuts: "play-pause",
776
+ isEnabled: (state) => length(state) > 0,
777
+ run: (context) => context.state.playing ? context.pause() : context.play()
778
+ }),
779
+ defineTool({
780
+ id: "audio.start",
781
+ label: "tools.start",
782
+ icon: "skip-back",
783
+ group: "playback",
784
+ shortcuts: ["Home"],
785
+ isEnabled: (state) => length(state) > 0,
786
+ run: (context) => context.seek(0)
787
+ }),
788
+ defineTool({
789
+ id: "audio.end",
790
+ label: "tools.end",
791
+ icon: "skip-forward",
792
+ group: "playback",
793
+ shortcuts: ["End"],
794
+ isEnabled: (state) => length(state) > 0,
795
+ run: (context) => context.seek(length(context.state))
796
+ })
797
+ ];
798
+ var defaultAudioToolbar = [
799
+ [
800
+ "audio.open",
801
+ "audio.insert",
802
+ "audio.export"
803
+ ],
804
+ ["audio.undo", "audio.redo"],
805
+ [
806
+ "audio.add-track",
807
+ "audio.remove-track",
808
+ "audio.move-track-up",
809
+ "audio.move-track-down"
810
+ ],
811
+ [
812
+ "audio.split",
813
+ "audio.delete",
814
+ "audio.trim-start",
815
+ "audio.trim-end",
816
+ "audio.fade-in",
817
+ "audio.fade-out",
818
+ "audio.move-earlier",
819
+ "audio.move-later",
820
+ "audio.move-to-track-above",
821
+ "audio.move-to-track-below"
822
+ ],
823
+ [
824
+ "audio.set-start",
825
+ "audio.set-end",
826
+ "audio.clear-selection",
827
+ "audio.ripple"
828
+ ],
829
+ [
830
+ "audio.zoom-out",
831
+ "audio.zoom-in",
832
+ "audio.zoom-fit"
833
+ ]
834
+ ];
835
+ // src/messages/editor-en.ts
836
+ var audioEditorText = {
837
+ "editor.label": "Audio editor",
838
+ "editor.empty": "Drop an audio file here, or choose one. It stays on your device.",
839
+ "editor.opening": "Opening the recording",
840
+ "editor.inserting": "Adding the recording",
841
+ "editor.cancel": "Cancel",
842
+ "editor.opened": "Recording opened.",
843
+ "editor.inserted": "Recording added.",
844
+ "editor.notices": "Notices",
845
+ "editor.dismiss": "Dismiss",
846
+ "editor.historyTrimmed": "The earliest edits can no longer be undone, to make room for the recordings.",
847
+ "timeline.label": "Timeline",
848
+ "timeline.summary": /* @__PURE__ */ plural("count", {
849
+ one: "{count} track, {duration} long.",
850
+ other: "{count} tracks, {duration} long."
851
+ }),
852
+ "timeline.playhead": "Playhead",
853
+ "timeline.track": "Track {index}",
854
+ "timeline.track.named": "Track {index}, {name}",
855
+ "timeline.lane": "{track}",
856
+ "timeline.lane.muted": "{track}, muted",
857
+ "timeline.lane.silenced": "{track}, silenced by solo",
858
+ "timeline.lane.ripple": "{lane}, later clips move when the selection is deleted",
859
+ "timeline.selection": "Selected {start} to {end} on {tracks}",
860
+ "track.ripple": "Ripple",
861
+ "tracks.every": "every track",
862
+ "tracks.count": /* @__PURE__ */ plural("count", {
863
+ one: "{count} track",
864
+ other: "{count} tracks"
865
+ }),
866
+ "timeline.clips": "Clips on {track}",
867
+ "timeline.clip": "Clip {index} of {count} on {track}, {start} to {end}",
868
+ "timeline.clip.named": "{name}, clip {index} of {count} on {track}, {start} to {end}",
869
+ "timeline.clip.gain": "Clip {index} of {count} on {track}, {start} to {end}, {gain, number} dB",
870
+ "timeline.clip.named.gain": "{name}, clip {index} of {count} on {track}, {start} to {end}, {gain, number} dB",
871
+ "toolbar.label": "Tools",
872
+ "toolbar.file": "File",
873
+ "toolbar.history": "History",
874
+ "toolbar.tracks": "Tracks",
875
+ "toolbar.clips": "Clip",
876
+ "toolbar.range": "Selection",
877
+ "toolbar.view": "Zoom",
878
+ "toolbar.withKeys": "{label} ({keys})",
879
+ "tools.open": "Open",
880
+ "tools.insert": "Add recording",
881
+ "tools.export": "Export",
882
+ "tools.undo": "Undo",
883
+ "tools.redo": "Redo",
884
+ "tools.addTrack": "Add track",
885
+ "tools.removeTrack": "Remove track",
886
+ "tools.moveTrackUp": "Move track up",
887
+ "tools.moveTrackDown": "Move track down",
888
+ "tools.mute": "Mute track",
889
+ "tools.split": "Split at the playhead",
890
+ "tools.delete": "Delete",
891
+ "tools.trimStart": "Trim the start to the playhead",
892
+ "tools.trimEnd": "Trim the end to the playhead",
893
+ "tools.moveEarlier": "Move the clip earlier",
894
+ "tools.moveLater": "Move the clip later",
895
+ "tools.moveToTrackAbove": "Move the clip to the track above",
896
+ "tools.moveToTrackBelow": "Move the clip to the track below",
897
+ "tools.setStart": "Start the selection at the playhead",
898
+ "tools.setEnd": "End the selection at the playhead",
899
+ "tools.clearSelection": "Clear the selection",
900
+ "tools.ripple": "Ripple",
901
+ "tools.fadeIn": "Fade in",
902
+ "tools.fadeOut": "Fade out",
903
+ "tools.zoomIn": "Zoom in",
904
+ "tools.zoomOut": "Zoom out",
905
+ "tools.zoomFit": "Fit to width",
906
+ "tools.playPause": "Play or pause",
907
+ "tools.start": "Go to the start",
908
+ "tools.end": "Go to the end",
909
+ "track.rename": "{track}, rename",
910
+ "track.mute": "Mute",
911
+ "track.solo": "Solo",
912
+ "track.gain": "Gain",
913
+ "track.gainValue": "{gain, number} dB",
914
+ "rename.title": "Rename the track",
915
+ "rename.name": "Name",
916
+ "rename.description": "Leave it empty for no name.",
917
+ "rename.save": "Rename",
918
+ "announce.undone": "Undone.",
919
+ "announce.redone": "Redone.",
920
+ "announce.trackAdded": "Track added.",
921
+ "announce.trackRemoved": "{track} removed.",
922
+ "announce.trackMoved": "{track} moved.",
923
+ "announce.muted": "{track} muted.",
924
+ "announce.unmuted": "{track} unmuted.",
925
+ "announce.soloed": "{track} soloed.",
926
+ "announce.unsoloed": "{track} no longer soloed.",
927
+ "announce.split": "Split at {time}.",
928
+ "announce.noClipToSplit": "There's no clip on {track} at the playhead to split.",
929
+ "announce.clipDeleted": "Clip deleted.",
930
+ "announce.clipMovedTo": "Clip moved to {track}.",
931
+ "announce.trimmed": "The clip is now {time} to {end}.",
932
+ "announce.noRoom": "There's no room for the clip there.",
933
+ "announce.refused": "That edit isn't possible.",
934
+ "announce.selected": "Selected {time} to {end} on {tracks}.",
935
+ "announce.selectionCleared": "Selection cleared.",
936
+ "announce.rangeDeleted": "Deleted {time} to {end} from {tracks}.",
937
+ "announce.rangeDeleted.ripple": "Deleted {time} to {end} from {tracks}. Later clips there moved earlier.",
938
+ "announce.rippleOn": "Ripple on: deleting a range closes the gap.",
939
+ "announce.rippleOff": "Ripple off: deleting a range leaves silence.",
940
+ "announce.nothingInRange": "There's no audio in the selection to change.",
941
+ "announce.rangeGain": "{time} to {end} on {tracks} set to {gain, number} dB.",
942
+ "announce.fadedIn": "Fade in from {time} to {end} on {tracks}.",
943
+ "announce.fadedOut": "Fade out from {time} to {end} on {tracks}.",
944
+ "announce.noRoomForFade": "The clip has no room for that fade: shorten its other fade first.",
945
+ "announce.clipFadedIn": "The clip fades in over {time}. Set its length in the inspector.",
946
+ "announce.clipFadedOut": "The clip fades out over {time}. Set its length in the inspector.",
947
+ "inspector.clip": "Clip on {track}",
948
+ "inspector.recording": "Recording",
949
+ "inspector.selection": "Selection",
950
+ "inspector.selectionGain": "Gain of the selection, in decibels",
951
+ "inspector.start": "Start",
952
+ "inspector.gain": "Gain",
953
+ "inspector.gainExact": "Gain, in decibels",
954
+ "inspector.fadeIn": "Fade in, in seconds",
955
+ "inspector.fadeOut": "Fade out, in seconds",
956
+ "inspector.fadeInCurve": "Fade in curve",
957
+ "inspector.fadeOutCurve": "Fade out curve",
958
+ "inspector.curve.linear": "Linear",
959
+ "inspector.curve.equalPower": "Equal power",
960
+ "inspector.length": "Length",
961
+ "inspector.sampleRate": "Sample rate",
962
+ "inspector.sampleRateValue": "{rate, number} Hz",
963
+ "inspector.tracks": "Tracks",
964
+ "inspector.masterGain": "Master gain",
965
+ "inspector.masterGainExact": "Master gain, in decibels",
966
+ "inspector.channels": "Channels",
967
+ "inspector.mono": "Mono",
968
+ "inspector.stereo": "Stereo",
969
+ "inspector.channelCount": "{count} channels",
970
+ "metadata.title": "Title",
971
+ "metadata.artist": "Artist",
972
+ "metadata.album": "Album",
973
+ "metadata.year": "Year",
974
+ "metadata.comment": "Comment",
975
+ "export.title": "Export",
976
+ "export.description": "Write the recording to a WAV file on your device.",
977
+ "export.summary": "What will be written",
978
+ "export.audio": "{length} long, at {rate, number} Hz, {channels}.",
979
+ "export.muted": "{track} is muted, so it won't be in the file.",
980
+ "export.silenced": "{track} isn't soloed, so it won't be in the file.",
981
+ "export.silent": "{track} won't be heard in the file.",
982
+ "export.nothingHeard": "Every track with audio is muted or silenced by a solo, so there's nothing to export.",
983
+ "export.metadata": "Written to the file: {fields}.",
984
+ "export.noMetadata": "No metadata is written to the file.",
985
+ "export.private": "Only the mix and this metadata are written. Nothing leaves your device.",
986
+ "export.format": "Format",
987
+ "export.formats.pcm16": "16-bit, {size, fileSize}",
988
+ "export.formats.pcm24": "24-bit, {size, fileSize}",
989
+ "export.formats.float32": "32-bit float, {size, fileSize}",
990
+ "export.cancel": "Cancel",
991
+ "export.confirm": "Export",
992
+ "export.progress": "Exporting",
993
+ "export.stop": "Stop",
994
+ "export.done": "Done",
995
+ "export.download": "Download",
996
+ "export.ready": "The WAV file is ready: {size, fileSize}.",
997
+ "export.cancelled": "Export stopped.",
998
+ "export.clipped": "The mix went {db, number} dB over full scale, so {frames, number} frames were clipped.",
999
+ "export.lower": "Lower the master gain by {db, number} dB and export again",
1000
+ "export.unavailable": "This editor has nothing to export with.",
1001
+ "transport.label": "Playback",
1002
+ "transport.play": "Play",
1003
+ "transport.pause": "Pause",
1004
+ "transport.start": "Back to the start",
1005
+ "transport.time": "{position} / {duration}"
1006
+ };
1007
+ // src/react/editor-messages.ts
1008
+ var audioEditorMessages = /* @__PURE__ */ defineMessages({
1009
+ ...audioMessages,
1010
+ ...uiMessages,
1011
+ ...audioEditorText
1012
+ });
1013
+ // src/react/context.tsx
1014
+ var Context = createContext(null);
1015
+ function useAudioEditorContext() {
1016
+ const context = useContext(Context);
1017
+ if (!context) throw new TypeError("Audio editor components need an AudioEditorProvider.");
1018
+ return context;
1019
+ }
1020
+ function make(props, onEvent) {
1021
+ const worker = props.assetsUrl !== void 0 && typeof location !== "undefined" ? { assetsUrl: props.assetsUrl } : {};
1022
+ const made = [];
1023
+ const keep = (adapter) => {
1024
+ made.push(adapter);
1025
+ return adapter;
1026
+ };
1027
+ const engine = props.engine ?? keep(createAudioEngine(worker));
1028
+ const processor = props.processor ?? keep(createAudioProcessor(worker));
1029
+ const output = props.output ?? keep(createAudioOutput());
1030
+ const session = createAudioSession({
1031
+ engine,
1032
+ processor,
1033
+ ...props.filePolicy ? { filePolicy: props.filePolicy } : {},
1034
+ onEvent
1035
+ });
1036
+ return {
1037
+ session,
1038
+ output,
1039
+ release() {
1040
+ session.close().finally(() => {
1041
+ for (const adapter of made) adapter.destroy().catch(() => {});
1042
+ });
1043
+ }
1044
+ };
1045
+ }
1046
+ function AudioEditorProvider(props) {
1047
+ const onEvent = useRef(props.onEvent);
1048
+ onEvent.current = props.onEvent;
1049
+ const [owned] = useState(() => make(props, (event) => onEvent.current?.(event)));
1050
+ const { session, output } = owned;
1051
+ const pending = useRef(void 0);
1052
+ useEffect(() => {
1053
+ clearTimeout(pending.current);
1054
+ const disconnect = connectOutput(session, output);
1055
+ return () => {
1056
+ disconnect();
1057
+ pending.current = setTimeout(() => owned.release(), 0);
1058
+ };
1059
+ }, [
1060
+ owned,
1061
+ session,
1062
+ output
1063
+ ]);
1064
+ const { locale, messages: overrides } = props;
1065
+ const messages = useMemo(() => createMessages(audioEditorMessages, {
1066
+ ...locale ? { locale } : {},
1067
+ ...overrides ? { overrides } : {}
1068
+ }), [locale, overrides]);
1069
+ const [load, setLoad] = useState();
1070
+ const controller = useRef(void 0);
1071
+ const run = useCallback(async (kind, work) => {
1072
+ controller.current?.abort();
1073
+ const own = new AbortController();
1074
+ controller.current = own;
1075
+ setLoad({
1076
+ kind,
1077
+ fraction: 0
1078
+ });
1079
+ try {
1080
+ await work({
1081
+ signal: own.signal,
1082
+ onProgress: (fraction) => {
1083
+ if (controller.current === own) setLoad({
1084
+ kind,
1085
+ fraction
1086
+ });
1087
+ }
1088
+ });
1089
+ } catch (error) {
1090
+ if (!isAudioError(error, "ABORTED")) throw error;
1091
+ } finally {
1092
+ if (controller.current === own) {
1093
+ controller.current = void 0;
1094
+ setLoad(void 0);
1095
+ }
1096
+ }
1097
+ }, []);
1098
+ const open = useCallback((file) => run("open", (options) => session.open(file, options)), [run, session]);
1099
+ const insert = useCallback((file, options = {}) => run("insert", (progress) => session.insert(file, {
1100
+ ...options,
1101
+ ...progress
1102
+ })), [run, session]);
1103
+ const cancelLoad = useCallback(() => controller.current?.abort(), []);
1104
+ const [zoom, setZoom] = useState(1);
1105
+ const [maxZoom, setMaxZoom] = useState(1);
1106
+ const [selectedClip, setSelectedClip] = useState();
1107
+ const [ripple, setRipple] = useState(true);
1108
+ const [dialog, setDialog] = useState();
1109
+ const playhead = useRef(null);
1110
+ const [currentTrack, setCurrentTrack] = useState();
1111
+ const [renaming, setRenaming] = useState();
1112
+ const pendingFocus = useRef(void 0);
1113
+ const pendingClipFocus = useRef(void 0);
1114
+ const fileChooser = useRef(null);
1115
+ const platform = usePlatform();
1116
+ const toolIds = JSON.stringify(props.tools ?? null);
1117
+ const toolbarIds = JSON.stringify(props.toolbar ?? null);
1118
+ const tools = useMemo(() => createToolRegistry(audioTools, {
1119
+ ...props.tools ? { tools: props.tools } : {},
1120
+ toolbar: (props.toolbar ?? defaultAudioToolbar).map((group) => group.filter((id) => !props.tools || props.tools.includes(id)))
1121
+ }), [toolIds, toolbarIds]);
1122
+ const shortcuts = useMemo(() => createShortcutRegistry({
1123
+ platform,
1124
+ tools: tools.tools
1125
+ }), [platform, tools]);
1126
+ const value = useMemo(() => ({
1127
+ session,
1128
+ output,
1129
+ messages,
1130
+ load,
1131
+ open,
1132
+ insert,
1133
+ cancelLoad,
1134
+ zoom,
1135
+ setZoom,
1136
+ maxZoom,
1137
+ setMaxZoom,
1138
+ selectedClip,
1139
+ setSelectedClip,
1140
+ ripple,
1141
+ setRipple,
1142
+ dialog,
1143
+ setDialog,
1144
+ playhead,
1145
+ currentTrack,
1146
+ setCurrentTrack,
1147
+ pendingFocus,
1148
+ pendingClipFocus,
1149
+ tools,
1150
+ shortcuts,
1151
+ fileChooser,
1152
+ renaming,
1153
+ setRenaming
1154
+ }), [
1155
+ session,
1156
+ output,
1157
+ messages,
1158
+ load,
1159
+ open,
1160
+ insert,
1161
+ cancelLoad,
1162
+ zoom,
1163
+ maxZoom,
1164
+ selectedClip,
1165
+ ripple,
1166
+ dialog,
1167
+ currentTrack,
1168
+ tools,
1169
+ shortcuts,
1170
+ renaming
1171
+ ]);
1172
+ return /* @__PURE__ */ jsx(Context.Provider, {
1173
+ value,
1174
+ children: props.children
1175
+ });
1176
+ }
1177
+ function useAudioSession() {
1178
+ const { session } = useAudioEditorContext();
1179
+ return {
1180
+ session,
1181
+ snapshot: useSyncExternalStore(session.subscribe, session.getSnapshot, session.getSnapshot)
1182
+ };
1183
+ }
1184
+ function useAudioOutput() {
1185
+ const { output } = useAudioEditorContext();
1186
+ return {
1187
+ output,
1188
+ snapshot: useSyncExternalStore(output.subscribe, output.getSnapshot, output.getSnapshot)
1189
+ };
1190
+ }
1191
+ function useAudioPlayhead() {
1192
+ const { output } = useAudioEditorContext();
1193
+ const [frame, setFrame] = useState(() => output.position());
1194
+ useEffect(() => watchPlayhead(output, setFrame), [output]);
1195
+ return frame;
1196
+ }
1197
+ function useAudioMessages() {
1198
+ return useAudioEditorContext().messages;
1199
+ }
1200
+ // src/react/element/listeners.ts
1201
+ var ElementListenersContext = createContext({});
1202
+ // src/react/names.ts
1203
+ function trackName(messages, track, index) {
1204
+ return track.name ? messages.t("timeline.track.named", {
1205
+ index: index + 1,
1206
+ name: track.name
1207
+ }) : messages.t("timeline.track", { index: index + 1 });
1208
+ }
1209
+ function tracksText(messages, plan, tracks) {
1210
+ if (plan && tracks.length === plan.tracks.length && tracks.length > 1) return messages.t("tracks.every");
1211
+ const [only] = tracks;
1212
+ if (tracks.length === 1 && only) return trackName(messages, only, plan ? plan.tracks.indexOf(only) : 0);
1213
+ return messages.t("tracks.count", { count: tracks.length });
1214
+ }
1215
+ // src/react/parts.ts
1216
+ function classes(...names) {
1217
+ return names.filter(Boolean).join(" ");
1218
+ }
1219
+ // src/react/tools.ts
1220
+ function useAudioTools() {
1221
+ const editor = useAudioEditorContext();
1222
+ const { messages, tools, shortcuts, zoom, maxZoom, setZoom, currentTrack, selectedClip, ripple } = editor;
1223
+ const { session, snapshot } = useAudioSession();
1224
+ const { output, snapshot: playback } = useAudioOutput();
1225
+ const announce = useAnnounce();
1226
+ const platform = usePlatform();
1227
+ const { plan, sources } = snapshot;
1228
+ const state = useMemo(() => ({
1229
+ plan,
1230
+ track: plan?.tracks.find((track) => track.key === currentTrack) ?? plan?.tracks[0],
1231
+ clip: plan && selectedClip !== void 0 ? findClip(plan, selectedClip) : void 0,
1232
+ selection: snapshot.selection,
1233
+ ripple,
1234
+ playing: playback.state === "playing",
1235
+ canUndo: snapshot.canUndo,
1236
+ canRedo: snapshot.canRedo,
1237
+ busy: snapshot.busy,
1238
+ zoom,
1239
+ maxZoom
1240
+ }), [
1241
+ plan,
1242
+ currentTrack,
1243
+ selectedClip,
1244
+ ripple,
1245
+ playback,
1246
+ snapshot,
1247
+ zoom,
1248
+ maxZoom
1249
+ ]);
1250
+ const flags = useMemo(() => new Map(tools.tools.map((tool) => [tool.id, {
1251
+ enabled: tool.isEnabled?.(state) ?? true,
1252
+ active: tool.isActive?.(state) ?? false
1253
+ }])), [tools, state]);
1254
+ const context = useCallback(() => {
1255
+ const frames = new Map(sources.map((source) => [source.id, source.frames]));
1256
+ const say = (message) => {
1257
+ const index = message.track && plan ? plan.tracks.indexOf(message.track) : 0;
1258
+ const rate = plan?.sampleRate ?? 1;
1259
+ announce(messages.t(message.key, {
1260
+ track: message.track ? trackName(messages, message.track, index) : "",
1261
+ time: message.frame === void 0 ? "" : formatTimecode(message.frame, rate),
1262
+ end: message.end === void 0 ? "" : formatTimecode(message.end, rate),
1263
+ tracks: message.tracks ? tracksText(messages, plan, message.tracks) : "",
1264
+ gain: message.gain ?? 0
1265
+ }));
1266
+ };
1267
+ return {
1268
+ state,
1269
+ execute: (commands) => {
1270
+ try {
1271
+ session.execute(commands);
1272
+ return;
1273
+ } catch (error) {
1274
+ if (isSdkError(error) && error.code === "INVALID_COMMAND") return error.details?.reason ?? "failed";
1275
+ return "failed";
1276
+ }
1277
+ },
1278
+ undo: () => session.undo(),
1279
+ redo: () => session.redo(),
1280
+ play: () => void output.play().catch(() => {}),
1281
+ pause: () => output.pause(),
1282
+ seek: (frame) => output.seek(frame),
1283
+ playhead: () => output.position(),
1284
+ select: (range) => session.select(range),
1285
+ setRipple: editor.setRipple,
1286
+ focusPlayhead: () => editor.playhead.current?.focus(),
1287
+ openDialog: (dialog) => editor.setDialog(dialog),
1288
+ sourceFrames: (source) => frames.get(source) ?? 0,
1289
+ setZoom,
1290
+ chooseFile: (purpose) => editor.fileChooser.current?.(purpose),
1291
+ newKey: () => session.createKey(),
1292
+ focusTrack: (key) => {
1293
+ editor.pendingFocus.current = key;
1294
+ },
1295
+ focusClip: (key) => {
1296
+ editor.pendingClipFocus.current = key;
1297
+ editor.setSelectedClip(key);
1298
+ },
1299
+ announce: say
1300
+ };
1301
+ }, [
1302
+ state,
1303
+ plan,
1304
+ sources,
1305
+ session,
1306
+ output,
1307
+ setZoom,
1308
+ editor,
1309
+ announce,
1310
+ messages
1311
+ ]);
1312
+ const run = useCallback((id) => {
1313
+ const tool = tools.get(id);
1314
+ if (!tool || tool.isEnabled && !tool.isEnabled(state)) return false;
1315
+ tool.run(context());
1316
+ return true;
1317
+ }, [
1318
+ tools,
1319
+ state,
1320
+ context
1321
+ ]);
1322
+ const describe = useCallback((parts) => parts.map((part) => part.message ? messages.t(part.message) : part.value).join(platform === "apple" ? "" : "+"), [messages, platform]);
1323
+ return useMemo(() => ({
1324
+ flags,
1325
+ run,
1326
+ context,
1327
+ ariaKeyShortcuts: (id) => shortcuts.ariaKeyShortcuts(id),
1328
+ labelWithKeys: (id) => {
1329
+ const tool = tools.get(id);
1330
+ const label = tool ? messages.t(tool.label) : id;
1331
+ const [first] = shortcuts.describe(id);
1332
+ return first ? messages.t("toolbar.withKeys", {
1333
+ label,
1334
+ keys: describe(first)
1335
+ }) : label;
1336
+ }
1337
+ }), [
1338
+ flags,
1339
+ run,
1340
+ context,
1341
+ shortcuts,
1342
+ tools,
1343
+ messages,
1344
+ describe
1345
+ ]);
1346
+ }
1347
+ // src/react/AudioExportDialog.tsx
1348
+ var FORMATS = [
1349
+ "pcm16",
1350
+ "pcm24",
1351
+ "float32"
1352
+ ];
1353
+ var FIELDS = [
1354
+ "title",
1355
+ "artist",
1356
+ "album",
1357
+ "year",
1358
+ "comment"
1359
+ ];
1360
+ function clippedBy(peakDb) {
1361
+ return Math.ceil(peakDb * 10) / 10;
1362
+ }
1363
+ function trackLines(messages, plan) {
1364
+ const heard = new Set(audibleTracks(plan));
1365
+ const soloing = plan.tracks.some((track) => track.soloed);
1366
+ return plan.tracks.flatMap((track, index) => {
1367
+ if (track.clips.length === 0 || heard.has(track)) return [];
1368
+ const name = trackName(messages, track, index);
1369
+ return [track.muted ? messages.t("export.muted", { track: name }) : soloing ? messages.t("export.silenced", { track: name }) : messages.t("export.silent", { track: name })];
1370
+ });
1371
+ }
1372
+ function AudioExportDialog(props) {
1373
+ const { onExport, fileName } = props;
1374
+ const { messages, dialog, setDialog } = useAudioEditorContext();
1375
+ const { session, snapshot } = useAudioSession();
1376
+ const tools = useAudioTools();
1377
+ const announce = useAnnounce();
1378
+ const listeners = useContext(ElementListenersContext);
1379
+ const [format, setFormat] = useState("pcm16");
1380
+ const [phase, setPhase] = useState({ kind: "choose" });
1381
+ const [error, setError] = useState(null);
1382
+ const controller = useRef(null);
1383
+ const objectUrl = useRef(null);
1384
+ const downloadButton = useRef(null);
1385
+ const { plan } = snapshot;
1386
+ const length = plan ? planLength(plan) : 0;
1387
+ const open = dialog === "export" && plan !== void 0 && length > 0;
1388
+ useEffect(() => {
1389
+ if (open) return;
1390
+ const running = controller.current;
1391
+ controller.current = null;
1392
+ running?.abort();
1393
+ if (objectUrl.current) URL.revokeObjectURL(objectUrl.current);
1394
+ objectUrl.current = null;
1395
+ setFormat("pcm16");
1396
+ setPhase((now) => now.kind === "choose" ? now : { kind: "choose" });
1397
+ setError(null);
1398
+ if (dialog === "export") setDialog(void 0);
1399
+ }, [
1400
+ open,
1401
+ dialog,
1402
+ setDialog
1403
+ ]);
1404
+ useEffect(() => () => {
1405
+ controller.current?.abort();
1406
+ controller.current = null;
1407
+ if (objectUrl.current) URL.revokeObjectURL(objectUrl.current);
1408
+ }, []);
1409
+ const done = phase.kind === "done";
1410
+ useEffect(() => {
1411
+ if (done) downloadButton.current?.focus();
1412
+ }, [done]);
1413
+ if (!plan) return null;
1414
+ const close = () => setDialog(void 0);
1415
+ const run = async () => {
1416
+ setError(null);
1417
+ const running = new AbortController();
1418
+ controller.current = running;
1419
+ setPhase({
1420
+ kind: "exporting",
1421
+ progress: 0
1422
+ });
1423
+ try {
1424
+ const result = await session.export({
1425
+ format: {
1426
+ container: "wav",
1427
+ sampleFormat: format
1428
+ },
1429
+ signal: running.signal,
1430
+ onProgress: (progress) => setPhase((now) => now.kind === "exporting" ? {
1431
+ ...now,
1432
+ progress
1433
+ } : now)
1434
+ });
1435
+ if (controller.current !== running) return;
1436
+ controller.current = null;
1437
+ announce(messages.t("export.ready", { size: result.blob.size }));
1438
+ listeners.onExport?.({
1439
+ sampleFormat: format,
1440
+ size: result.blob.size,
1441
+ peakDb: result.peakDb,
1442
+ clippedFrames: result.clippedFrames
1443
+ });
1444
+ if (onExport) {
1445
+ onExport(result.blob, result);
1446
+ close();
1447
+ return;
1448
+ }
1449
+ setPhase({
1450
+ kind: "done",
1451
+ result
1452
+ });
1453
+ } catch (reason) {
1454
+ if (controller.current !== running) return;
1455
+ controller.current = null;
1456
+ setPhase({ kind: "choose" });
1457
+ if (isAudioError(reason, "ABORTED")) {
1458
+ announce(messages.t("export.cancelled"));
1459
+ return;
1460
+ }
1461
+ setError(reason);
1462
+ }
1463
+ };
1464
+ const lowerAndRetry = (by) => {
1465
+ const edit = tools.context();
1466
+ if (edit.execute({
1467
+ type: "audio.setMasterGain",
1468
+ gainDb: plan.gainDb - by
1469
+ })) {
1470
+ edit.announce({ key: "announce.refused" });
1471
+ return;
1472
+ }
1473
+ run();
1474
+ };
1475
+ const stop = () => controller.current?.abort();
1476
+ const download = () => {
1477
+ if (phase.kind !== "done") return;
1478
+ if (objectUrl.current) URL.revokeObjectURL(objectUrl.current);
1479
+ objectUrl.current = URL.createObjectURL(phase.result.blob);
1480
+ const link = document.createElement("a");
1481
+ link.href = objectUrl.current;
1482
+ link.download = `${exportFileName(fileName, plan.metadata.title)}.wav`;
1483
+ link.click();
1484
+ };
1485
+ const rate = plan.sampleRate;
1486
+ const channels = plan.channels === 1 ? messages.t("inspector.mono") : plan.channels === 2 ? messages.t("inspector.stereo") : messages.t("inspector.channelCount", { count: plan.channels });
1487
+ const kept = FIELDS.filter((field) => plan.metadata[field] !== "");
1488
+ const list = new Intl.ListFormat(messages.locale, { type: "conjunction" });
1489
+ const leftOut = trackLines(messages, plan);
1490
+ const nothingHeard = audibleTracks(plan).every((track) => track.clips.length === 0);
1491
+ const exporting = phase.kind === "exporting";
1492
+ const size = (sampleFormat) => wavFileSize({
1493
+ sampleRate: rate,
1494
+ channels: plan.channels,
1495
+ frames: length,
1496
+ sampleFormat,
1497
+ metadata: plan.metadata
1498
+ });
1499
+ const footer = phase.kind === "done" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
1500
+ variant: "secondary",
1501
+ onClick: close,
1502
+ children: messages.t("export.done")
1503
+ }), /* @__PURE__ */ jsx(Button, {
1504
+ ref: downloadButton,
1505
+ variant: "primary",
1506
+ onClick: download,
1507
+ children: messages.t("export.download")
1508
+ })] }) : exporting ? /* @__PURE__ */ jsx(Button, {
1509
+ variant: "secondary",
1510
+ onClick: stop,
1511
+ children: messages.t("export.stop")
1512
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
1513
+ variant: "secondary",
1514
+ onClick: close,
1515
+ children: messages.t("export.cancel")
1516
+ }), /* @__PURE__ */ jsx(Button, {
1517
+ variant: "primary",
1518
+ disabled: nothingHeard,
1519
+ focusableWhenDisabled: true,
1520
+ onClick: () => void run(),
1521
+ children: messages.t("export.confirm")
1522
+ })] });
1523
+ return /* @__PURE__ */ jsx(Dialog, {
1524
+ open,
1525
+ onOpenChange: (next) => {
1526
+ if (!next) close();
1527
+ },
1528
+ title: messages.t("export.title"),
1529
+ description: messages.t("export.description"),
1530
+ footer,
1531
+ className: classes("hm-audio-export", props.className),
1532
+ children: phase.kind === "done" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
1533
+ className: "hm-audio-export-result",
1534
+ children: messages.t("export.ready", { size: phase.result.blob.size })
1535
+ }), phase.result.clippedFrames > 0 ? /* @__PURE__ */ jsxs("div", {
1536
+ className: "hm-audio-export-clipped",
1537
+ role: "status",
1538
+ children: [/* @__PURE__ */ jsx("p", { children: messages.t("export.clipped", {
1539
+ db: clippedBy(phase.result.peakDb),
1540
+ frames: phase.result.clippedFrames
1541
+ }) }), /* @__PURE__ */ jsx(Button, {
1542
+ variant: "secondary",
1543
+ onClick: () => lowerAndRetry(clippedBy(phase.result.peakDb)),
1544
+ children: messages.t("export.lower", { db: clippedBy(phase.result.peakDb) })
1545
+ })]
1546
+ }) : null] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1547
+ /* @__PURE__ */ jsxs("section", {
1548
+ className: "hm-audio-export-summary",
1549
+ "aria-label": messages.t("export.summary"),
1550
+ children: [
1551
+ /* @__PURE__ */ jsx("p", { children: messages.t("export.audio", {
1552
+ length: formatTimecode(length, rate),
1553
+ rate,
1554
+ channels
1555
+ }) }),
1556
+ leftOut.map((line) => /* @__PURE__ */ jsx("p", { children: line }, line)),
1557
+ nothingHeard ? /* @__PURE__ */ jsx("p", { children: messages.t("export.nothingHeard") }) : null,
1558
+ /* @__PURE__ */ jsx("p", { children: kept.length > 0 ? messages.t("export.metadata", { fields: list.format(kept.map((field) => messages.t(`metadata.${field}`))) }) : messages.t("export.noMetadata") }),
1559
+ /* @__PURE__ */ jsx("p", { children: messages.t("export.private") })
1560
+ ]
1561
+ }),
1562
+ /* @__PURE__ */ jsx(SegmentedControl, {
1563
+ label: messages.t("export.format"),
1564
+ size: "small",
1565
+ value: format,
1566
+ onValueChange: (next) => {
1567
+ if (!exporting) setFormat(next);
1568
+ },
1569
+ options: FORMATS.map((value) => ({
1570
+ value,
1571
+ label: messages.t(`export.formats.${value}`, { size: size(value) })
1572
+ }))
1573
+ }),
1574
+ exporting ? /* @__PURE__ */ jsx(ProgressBar, {
1575
+ label: messages.t("export.progress"),
1576
+ value: Math.round(phase.progress * 100),
1577
+ max: 100
1578
+ }) : null,
1579
+ error ? /* @__PURE__ */ jsx("p", {
1580
+ className: "hm-audio-export-error",
1581
+ role: "alert",
1582
+ children: error instanceof TypeError ? messages.t("export.unavailable") : audioErrorText(messages, error)
1583
+ }) : null
1584
+ ] })
1585
+ });
1586
+ }
1587
+ // src/react/draft.ts
1588
+ function useFollowing(value) {
1589
+ const [local, setLocal] = useState(value);
1590
+ useEffect(() => setLocal(value), [value]);
1591
+ return [local, setLocal];
1592
+ }
1593
+ function useDraft(value, onCommit) {
1594
+ const [draft, setDraft] = useFollowing(value);
1595
+ const commit = () => {
1596
+ if (!Object.is(draft, value)) onCommit(draft);
1597
+ };
1598
+ return [
1599
+ draft,
1600
+ setDraft,
1601
+ commit
1602
+ ];
1603
+ }
1604
+ // src/react/timecode.ts
1605
+ function parseTimecode(text, sampleRate) {
1606
+ const match = /^(?:(?:(\d+):)?(\d+):)?(\d+(?:\.\d*)?|\.\d+)$/.exec(text.trim());
1607
+ if (!match) return void 0;
1608
+ const [, hours, minutes, seconds] = match;
1609
+ if (minutes !== void 0 && Number(seconds) >= 60 || hours !== void 0 && Number(minutes) >= 60) return;
1610
+ const total = Number(hours ?? 0) * 3600 + Number(minutes ?? 0) * 60 + Number(seconds);
1611
+ return Number.isFinite(total) ? Math.round(total * sampleRate) : void 0;
1612
+ }
1613
+ // src/react/AudioInspector.tsx
1614
+ var SLIDER_GAIN = {
1615
+ min: -60,
1616
+ max: 12
1617
+ };
1618
+ var METADATA_FIELDS = [
1619
+ "title",
1620
+ "artist",
1621
+ "album",
1622
+ "year",
1623
+ "comment"
1624
+ ];
1625
+ function AudioInspector({ className, headingLevel }) {
1626
+ return /* @__PURE__ */ jsx(EditorInspector, {
1627
+ className,
1628
+ classNames: void 0,
1629
+ headingLevel
1630
+ });
1631
+ }
1632
+ function EditorInspector({ className, classNames, headingLevel = 2 }) {
1633
+ const { messages, selectedClip } = useAudioEditorContext();
1634
+ const { snapshot } = useAudioSession();
1635
+ const tools = useAudioTools();
1636
+ const title = useId();
1637
+ const { plan } = snapshot;
1638
+ if (!plan) return null;
1639
+ const { selection } = snapshot;
1640
+ const placed = selectedClip === void 0 ? void 0 : findClip(plan, selectedClip);
1641
+ const Heading = `h${headingLevel}`;
1642
+ const run = (command) => {
1643
+ const edit = tools.context();
1644
+ if (edit.execute(command)) edit.announce({ key: "announce.refused" });
1645
+ };
1646
+ return /* @__PURE__ */ jsx("section", {
1647
+ className: classes("hm-audio-editor-inspector", classNames?.inspector, className),
1648
+ "aria-labelledby": title,
1649
+ children: selection ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Heading, {
1650
+ id: title,
1651
+ className: "hm-audio-editor-inspector-title",
1652
+ children: messages.t("inspector.selection")
1653
+ }), /* @__PURE__ */ jsx(SelectionFields, {
1654
+ plan,
1655
+ selection,
1656
+ messages,
1657
+ setGain: (gainDb) => setRangeGain(tools.context(), gainDb)
1658
+ })] }) : placed ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Heading, {
1659
+ id: title,
1660
+ className: "hm-audio-editor-inspector-title",
1661
+ children: messages.t("inspector.clip", { track: trackName(messages, placed.track, plan.tracks.indexOf(placed.track)) })
1662
+ }), /* @__PURE__ */ jsx(ClipFields, {
1663
+ plan,
1664
+ clip: placed.clip,
1665
+ messages,
1666
+ run,
1667
+ move: (by) => moveClips(tools.context(), [placed.clip.key], by)
1668
+ }, placed.clip.key)] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Heading, {
1669
+ id: title,
1670
+ className: "hm-audio-editor-inspector-title",
1671
+ children: messages.t("inspector.recording")
1672
+ }), /* @__PURE__ */ jsx(RecordingFields, {
1673
+ plan,
1674
+ messages,
1675
+ run
1676
+ })] })
1677
+ });
1678
+ }
1679
+ function Gain({ label, exactLabel, value, messages, onCommit }) {
1680
+ const [live, setLive] = useFollowing(value);
1681
+ return /* @__PURE__ */ jsxs("div", {
1682
+ className: "hm-audio-editor-inspector-gain",
1683
+ children: [/* @__PURE__ */ jsx(Field, {
1684
+ label,
1685
+ children: /* @__PURE__ */ jsx(Slider, {
1686
+ min: SLIDER_GAIN.min,
1687
+ max: SLIDER_GAIN.max,
1688
+ step: 1,
1689
+ value: Math.min(SLIDER_GAIN.max, Math.max(SLIDER_GAIN.min, live)),
1690
+ onValueChange: setLive,
1691
+ formatValue: (gain) => messages.t("track.gainValue", { gain }),
1692
+ onValueCommit: (gainDb) => {
1693
+ if (gainDb !== value) onCommit(gainDb);
1694
+ }
1695
+ })
1696
+ }), /* @__PURE__ */ jsx(Field, {
1697
+ label: exactLabel,
1698
+ children: /* @__PURE__ */ jsx(NumberField, {
1699
+ value,
1700
+ min: MIN_GAIN_DB,
1701
+ max: 120,
1702
+ step: .5,
1703
+ largeStep: 6,
1704
+ locale: messages.locale,
1705
+ onValueChange: (gainDb) => {
1706
+ if (gainDb !== value) onCommit(gainDb);
1707
+ }
1708
+ })
1709
+ })]
1710
+ });
1711
+ }
1712
+ function Fade({ edge, clip, plan, messages, run }) {
1713
+ const rate = plan.sampleRate;
1714
+ const fade = edge === "in" ? clip.fadeIn : clip.fadeOut;
1715
+ const other = edge === "in" ? clip.fadeOut : clip.fadeIn;
1716
+ const set = (frames, curve) => run({
1717
+ type: "audio.setFade",
1718
+ key: clip.key,
1719
+ edge,
1720
+ frames,
1721
+ curve
1722
+ });
1723
+ return /* @__PURE__ */ jsxs("div", {
1724
+ className: "hm-audio-editor-inspector-fade",
1725
+ children: [/* @__PURE__ */ jsx(Field, {
1726
+ label: messages.t(edge === "in" ? "inspector.fadeIn" : "inspector.fadeOut"),
1727
+ children: /* @__PURE__ */ jsx(NumberField, {
1728
+ value: fade.frames / rate,
1729
+ min: 0,
1730
+ max: (clip.end - clip.start - other.frames) / rate,
1731
+ step: .01,
1732
+ largeStep: .1,
1733
+ locale: messages.locale,
1734
+ onValueChange: (seconds) => {
1735
+ const frames = Math.round(seconds * rate);
1736
+ if (frames !== fade.frames) set(frames, fade.curve);
1737
+ }
1738
+ })
1739
+ }), /* @__PURE__ */ jsx(SegmentedControl, {
1740
+ size: "small",
1741
+ label: messages.t(edge === "in" ? "inspector.fadeInCurve" : "inspector.fadeOutCurve"),
1742
+ value: fade.curve,
1743
+ onValueChange: (curve) => set(fade.frames, curve),
1744
+ options: [{
1745
+ value: "linear",
1746
+ label: messages.t("inspector.curve.linear")
1747
+ }, {
1748
+ value: "equalPower",
1749
+ label: messages.t("inspector.curve.equalPower")
1750
+ }]
1751
+ })]
1752
+ });
1753
+ }
1754
+ function ClipFields({ plan, clip, messages, run, move }) {
1755
+ const rate = plan.sampleRate;
1756
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1757
+ /* @__PURE__ */ jsx(Field, {
1758
+ label: messages.t("inspector.start"),
1759
+ children: /* @__PURE__ */ jsx(NumberField, {
1760
+ value: clip.at,
1761
+ min: 0,
1762
+ step: nudgeFrames(plan),
1763
+ largeStep: rate,
1764
+ format: (frames) => formatTimecode(Math.max(0, Math.round(frames)), rate),
1765
+ parse: (text) => parseTimecode(text, rate),
1766
+ onValueChange: (at) => {
1767
+ if (at !== clip.at) move(at - clip.at);
1768
+ }
1769
+ })
1770
+ }),
1771
+ /* @__PURE__ */ jsx(Gain, {
1772
+ label: messages.t("inspector.gain"),
1773
+ exactLabel: messages.t("inspector.gainExact"),
1774
+ value: clip.gainDb,
1775
+ messages,
1776
+ onCommit: (gainDb) => run({
1777
+ type: "audio.setGain",
1778
+ keys: [clip.key],
1779
+ gainDb
1780
+ })
1781
+ }),
1782
+ /* @__PURE__ */ jsx(Fade, {
1783
+ edge: "in",
1784
+ clip,
1785
+ plan,
1786
+ messages,
1787
+ run
1788
+ }),
1789
+ /* @__PURE__ */ jsx(Fade, {
1790
+ edge: "out",
1791
+ clip,
1792
+ plan,
1793
+ messages,
1794
+ run
1795
+ })
1796
+ ] });
1797
+ }
1798
+ function SelectionFields({ plan, selection, messages, setGain }) {
1799
+ const rate = plan.sampleRate;
1800
+ const clips = clipsInRange(plan, selection);
1801
+ const gain = clips[0]?.gainDb ?? 0;
1802
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
1803
+ className: "hm-audio-editor-inspector-range",
1804
+ children: messages.t("timeline.selection", {
1805
+ start: formatTimecode(selection.start, rate),
1806
+ end: formatTimecode(selection.end, rate),
1807
+ tracks: tracksText(messages, plan, plan.tracks.filter((track) => selection.tracks.includes(track.key)))
1808
+ })
1809
+ }), /* @__PURE__ */ jsx(Field, {
1810
+ label: messages.t("inspector.selectionGain"),
1811
+ children: /* @__PURE__ */ jsx(NumberField, {
1812
+ value: gain,
1813
+ min: MIN_GAIN_DB,
1814
+ max: 120,
1815
+ step: .5,
1816
+ largeStep: 6,
1817
+ locale: messages.locale,
1818
+ disabled: clips.length === 0,
1819
+ onValueChange: (gainDb) => {
1820
+ if (clips.some((clip) => clip.gainDb !== gainDb)) setGain(gainDb);
1821
+ }
1822
+ })
1823
+ })] });
1824
+ }
1825
+ function RecordingFields({ plan, messages, run }) {
1826
+ const channels = (count) => count === 1 ? messages.t("inspector.mono") : count === 2 ? messages.t("inspector.stereo") : messages.t("inspector.channelCount", { count });
1827
+ const choices = [.../* @__PURE__ */ new Set([
1828
+ 1,
1829
+ 2,
1830
+ plan.channels
1831
+ ])].sort((a, b) => a - b);
1832
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1833
+ /* @__PURE__ */ jsxs("dl", {
1834
+ className: "hm-audio-editor-facts",
1835
+ children: [
1836
+ /* @__PURE__ */ jsx("dt", { children: messages.t("inspector.length") }),
1837
+ /* @__PURE__ */ jsx("dd", { children: formatTimecode(planLength(plan), plan.sampleRate) }),
1838
+ /* @__PURE__ */ jsx("dt", { children: messages.t("inspector.sampleRate") }),
1839
+ /* @__PURE__ */ jsx("dd", { children: messages.t("inspector.sampleRateValue", { rate: plan.sampleRate }) }),
1840
+ /* @__PURE__ */ jsx("dt", { children: messages.t("inspector.tracks") }),
1841
+ /* @__PURE__ */ jsx("dd", { children: messages.t("tracks.count", { count: plan.tracks.length }) })
1842
+ ]
1843
+ }),
1844
+ /* @__PURE__ */ jsx(Gain, {
1845
+ label: messages.t("inspector.masterGain"),
1846
+ exactLabel: messages.t("inspector.masterGainExact"),
1847
+ value: plan.gainDb,
1848
+ messages,
1849
+ onCommit: (gainDb) => run({
1850
+ type: "audio.setMasterGain",
1851
+ gainDb
1852
+ })
1853
+ }),
1854
+ /* @__PURE__ */ jsx(SegmentedControl, {
1855
+ size: "small",
1856
+ label: messages.t("inspector.channels"),
1857
+ value: String(plan.channels),
1858
+ onValueChange: (value) => run({
1859
+ type: "audio.setChannels",
1860
+ channels: Number(value)
1861
+ }),
1862
+ options: choices.map((count) => ({
1863
+ value: String(count),
1864
+ label: channels(count)
1865
+ }))
1866
+ }),
1867
+ METADATA_FIELDS.map((field) => /* @__PURE__ */ jsx(MetadataField, {
1868
+ field,
1869
+ value: plan.metadata[field],
1870
+ messages,
1871
+ run
1872
+ }, field))
1873
+ ] });
1874
+ }
1875
+ function MetadataField({ field, value, messages, run }) {
1876
+ const [draft, setDraft, commit] = useDraft(value, (next) => run({
1877
+ type: "audio.setMetadata",
1878
+ field,
1879
+ value: next
1880
+ }));
1881
+ return /* @__PURE__ */ jsx(Field, {
1882
+ label: messages.t(`metadata.${field}`),
1883
+ children: /* @__PURE__ */ jsx(TextField, {
1884
+ value: draft,
1885
+ maxLength: MAX_METADATA_LENGTH,
1886
+ onValueChange: setDraft,
1887
+ onBlur: commit,
1888
+ onKeyDown: (event) => {
1889
+ if (event.key === "Enter") commit();
1890
+ else if (event.key === "Escape" && draft !== value) {
1891
+ event.preventDefault();
1892
+ setDraft(value);
1893
+ }
1894
+ }
1895
+ })
1896
+ });
1897
+ }
1898
+ // src/react/AudioNotices.tsx
1899
+ function warningKey(warning) {
1900
+ return warning.type === "limit" ? `limit:${warning.limit}:${warning.source ?? ""}` : `${warning.type}:${warning.source}`;
1901
+ }
1902
+ function AudioNotices({ className }) {
1903
+ return /* @__PURE__ */ jsx(Notices, {
1904
+ className,
1905
+ classNames: void 0
1906
+ });
1907
+ }
1908
+ function Notices({ className, classNames }) {
1909
+ const { messages } = useAudioEditorContext();
1910
+ const { snapshot } = useAudioSession();
1911
+ const announce = useAnnounce();
1912
+ const [dismissed, setDismissed] = useState(() => /* @__PURE__ */ new Set());
1913
+ const trimmed = useRef(snapshot.historyTrimmed);
1914
+ useEffect(() => {
1915
+ if (snapshot.historyTrimmed && !trimmed.current) announce(messages.t("editor.historyTrimmed"));
1916
+ trimmed.current = snapshot.historyTrimmed;
1917
+ }, [
1918
+ snapshot.historyTrimmed,
1919
+ announce,
1920
+ messages
1921
+ ]);
1922
+ const items = [...snapshot.warnings.map((warning) => ({
1923
+ key: warningKey(warning),
1924
+ text: audioWarningText(messages, warning)
1925
+ })), ...snapshot.historyTrimmed ? [{
1926
+ key: "historyTrimmed",
1927
+ text: messages.t("editor.historyTrimmed")
1928
+ }] : []].filter((item) => !dismissed.has(item.key));
1929
+ if (items.length === 0) return null;
1930
+ return /* @__PURE__ */ jsx("section", {
1931
+ className: classes("hm-audio-editor-notices", classNames?.notices, className),
1932
+ "aria-label": messages.t("editor.notices"),
1933
+ children: /* @__PURE__ */ jsx("ul", { children: items.map((item) => /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsx("p", { children: item.text }), /* @__PURE__ */ jsx(IconButton, {
1934
+ variant: "quiet",
1935
+ size: "small",
1936
+ label: messages.t("editor.dismiss"),
1937
+ icon: /* @__PURE__ */ jsx(CloseIcon, {}),
1938
+ onClick: () => setDismissed((keys) => /* @__PURE__ */ new Set([...keys, item.key]))
1939
+ })] }, item.key)) })
1940
+ });
1941
+ }
1942
+ // src/react/AudioRenameDialog.tsx
1943
+ function AudioRenameDialog() {
1944
+ const { messages, renaming, setRenaming } = useAudioEditorContext();
1945
+ const { session, snapshot } = useAudioSession();
1946
+ const track = snapshot.plan?.tracks.find((each) => each.key === renaming);
1947
+ const [draft, setDraft] = useState("");
1948
+ const form = useId();
1949
+ const field = useRef(null);
1950
+ const [opened, setOpened] = useState(renaming);
1951
+ if (opened !== renaming) {
1952
+ setOpened(renaming);
1953
+ setDraft(track?.name ?? "");
1954
+ }
1955
+ const save = (event) => {
1956
+ event.preventDefault();
1957
+ if (track) {
1958
+ const next = [...draft.trim()].slice(0, 100).join("");
1959
+ if (next !== track.name) try {
1960
+ session.execute({
1961
+ type: "audio.setTrack",
1962
+ key: track.key,
1963
+ name: next
1964
+ });
1965
+ } catch {}
1966
+ }
1967
+ setRenaming(void 0);
1968
+ };
1969
+ return /* @__PURE__ */ jsx(Dialog, {
1970
+ open: track !== void 0,
1971
+ onOpenChange: (open) => {
1972
+ if (!open) setRenaming(void 0);
1973
+ },
1974
+ title: messages.t("rename.title"),
1975
+ size: "small",
1976
+ initialFocus: field,
1977
+ closeLabel: messages.t("editor.cancel"),
1978
+ footer: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
1979
+ onClick: () => setRenaming(void 0),
1980
+ children: messages.t("editor.cancel")
1981
+ }), /* @__PURE__ */ jsx(Button, {
1982
+ variant: "primary",
1983
+ type: "submit",
1984
+ form,
1985
+ children: messages.t("rename.save")
1986
+ })] }),
1987
+ children: /* @__PURE__ */ jsx("form", {
1988
+ id: form,
1989
+ onSubmit: save,
1990
+ children: /* @__PURE__ */ jsx(Field, {
1991
+ label: messages.t("rename.name"),
1992
+ description: messages.t("rename.description"),
1993
+ children: /* @__PURE__ */ jsx(TextField, {
1994
+ ref: field,
1995
+ value: draft,
1996
+ onValueChange: setDraft,
1997
+ autoComplete: "off"
1998
+ })
1999
+ })
2000
+ })
2001
+ });
2002
+ }
2003
+ // src/react/AudioRange.tsx
2004
+ var DRAG_THRESHOLD = 4;
2005
+ function RangeGestures() {
2006
+ const { session, output } = useAudioEditorContext();
2007
+ const scale = useTimelineScale();
2008
+ const { lanes, laneAt } = useTimelineLanes();
2009
+ const press = useRef(void 0);
2010
+ const onPointerDown = (event) => {
2011
+ if (event.button !== 0 || press.current || scale.pixelsPerUnit === 0) return;
2012
+ const lane = laneAt(event.clientY);
2013
+ const touch = event.pointerType === "touch";
2014
+ press.current = {
2015
+ id: event.pointerId,
2016
+ x: event.clientX,
2017
+ unit: scale.unitAt(event.clientX, { snap: !event.altKey }),
2018
+ lane,
2019
+ touch,
2020
+ lastLane: lane,
2021
+ dragging: false
2022
+ };
2023
+ if (!touch) {
2024
+ try {
2025
+ event.currentTarget.setPointerCapture(event.pointerId);
2026
+ } catch {}
2027
+ event.preventDefault();
2028
+ }
2029
+ };
2030
+ const onPointerMove = (event) => {
2031
+ const current = press.current;
2032
+ if (!current || event.pointerId !== current.id || current.touch) return;
2033
+ if (!current.dragging && Math.abs(event.clientX - current.x) < DRAG_THRESHOLD) return;
2034
+ current.dragging = true;
2035
+ current.lastLane = laneAt(event.clientY) ?? current.lastLane;
2036
+ const unit = scale.unitAt(event.clientX, { snap: !event.altKey });
2037
+ const from = current.lane === void 0 ? -1 : lanes.indexOf(current.lane);
2038
+ const to = current.lastLane === void 0 ? -1 : lanes.indexOf(current.lastLane);
2039
+ const tracks = from < 0 || to < 0 ? void 0 : lanes.slice(Math.min(from, to), Math.max(from, to) + 1);
2040
+ session.select({
2041
+ start: Math.min(current.unit, unit),
2042
+ end: Math.max(current.unit, unit),
2043
+ ...tracks ? { tracks } : {}
2044
+ });
2045
+ };
2046
+ const onPointerUp = (event) => {
2047
+ const done = press.current;
2048
+ if (!done || event.pointerId !== done.id) return;
2049
+ press.current = void 0;
2050
+ if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
2051
+ if (done.dragging) return;
2052
+ if (done.touch && Math.abs(event.clientX - done.x) >= DRAG_THRESHOLD) return;
2053
+ output.seek(done.unit);
2054
+ session.select(void 0);
2055
+ };
2056
+ const onPointerCancel = (event) => {
2057
+ if (press.current && event.pointerId === press.current.id) press.current = void 0;
2058
+ };
2059
+ return /* @__PURE__ */ jsx(TimelineLayer, {
2060
+ className: "hm-audio-editor-press-layer",
2061
+ "aria-hidden": "true",
2062
+ onPointerDown,
2063
+ onPointerMove,
2064
+ onPointerUp,
2065
+ onPointerCancel
2066
+ });
2067
+ }
2068
+ function RangeMark({ selection }) {
2069
+ const { toPixels } = useTimelineScale();
2070
+ const start = toPixels(selection.start);
2071
+ return /* @__PURE__ */ jsx("div", {
2072
+ className: "hm-audio-editor-range",
2073
+ style: {
2074
+ insetInlineStart: `${start}px`,
2075
+ inlineSize: `${toPixels(selection.end) - start}px`
2076
+ }
2077
+ });
2078
+ }
2079
+ // src/react/AudioTrackHeader.tsx
2080
+ var GAIN = {
2081
+ min: -60,
2082
+ max: 12
2083
+ };
2084
+ function AudioTrackHeader({ track, index, rippling = false }) {
2085
+ const { session, messages, pendingFocus, setRenaming } = useAudioEditorContext();
2086
+ const { ariaKeyShortcuts } = useAudioTools();
2087
+ const announce = useAnnounce();
2088
+ const name = trackName(messages, track, index);
2089
+ const rename = useRef(null);
2090
+ useEffect(() => {
2091
+ if (pendingFocus.current !== track.key) return;
2092
+ pendingFocus.current = void 0;
2093
+ rename.current?.focus();
2094
+ });
2095
+ const execute = (command) => {
2096
+ try {
2097
+ session.execute(command);
2098
+ return true;
2099
+ } catch {
2100
+ return false;
2101
+ }
2102
+ };
2103
+ const [gain, setGain] = useFollowing(track.gainDb);
2104
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2105
+ /* @__PURE__ */ jsx(Button, {
2106
+ ref: rename,
2107
+ variant: "quiet",
2108
+ size: "small",
2109
+ className: "hm-audio-editor-track-name",
2110
+ "aria-label": messages.t("track.rename", { track: name }),
2111
+ onClick: () => setRenaming(track.key),
2112
+ children: /* @__PURE__ */ jsx("bdi", { children: name })
2113
+ }),
2114
+ /* @__PURE__ */ jsx(ToggleButton, {
2115
+ variant: "quiet",
2116
+ size: "small",
2117
+ label: messages.t("track.mute"),
2118
+ icon: /* @__PURE__ */ jsx(MutedIcon, {}),
2119
+ "aria-keyshortcuts": ariaKeyShortcuts("audio.mute"),
2120
+ pressed: track.muted,
2121
+ onPressedChange: (muted) => {
2122
+ if (execute({
2123
+ type: "audio.setTrack",
2124
+ key: track.key,
2125
+ muted
2126
+ })) announce(messages.t(muted ? "announce.muted" : "announce.unmuted", { track: name }));
2127
+ }
2128
+ }),
2129
+ /* @__PURE__ */ jsx(ToggleButton, {
2130
+ variant: "quiet",
2131
+ size: "small",
2132
+ pressed: track.soloed,
2133
+ onPressedChange: (soloed) => {
2134
+ if (execute({
2135
+ type: "audio.setTrack",
2136
+ key: track.key,
2137
+ soloed
2138
+ })) announce(messages.t(soloed ? "announce.soloed" : "announce.unsoloed", { track: name }));
2139
+ },
2140
+ children: messages.t("track.solo")
2141
+ }),
2142
+ /* @__PURE__ */ jsx(Slider, {
2143
+ className: "hm-audio-editor-track-gain",
2144
+ label: messages.t("track.gain"),
2145
+ min: GAIN.min,
2146
+ max: GAIN.max,
2147
+ step: 1,
2148
+ value: Math.min(GAIN.max, Math.max(GAIN.min, gain)),
2149
+ onValueChange: setGain,
2150
+ formatValue: (value) => messages.t("track.gainValue", { gain: value }),
2151
+ onValueCommit: (gainDb) => {
2152
+ if (gainDb !== track.gainDb) execute({
2153
+ type: "audio.setTrack",
2154
+ key: track.key,
2155
+ gainDb
2156
+ });
2157
+ }
2158
+ }),
2159
+ rippling ? /* @__PURE__ */ jsx("span", {
2160
+ className: "hm-audio-editor-track-ripple",
2161
+ children: messages.t("track.ripple")
2162
+ }) : null
2163
+ ] });
2164
+ }
2165
+ // src/react/AudioWaveform.tsx
2166
+ function draw(canvas, track, scale, peaksOf) {
2167
+ const range = scale.visibleRange();
2168
+ const left = scale.toPixels(range.start);
2169
+ const cssWidth = Math.max(0, scale.toPixels(range.end) - left);
2170
+ canvas.style.insetInlineStart = `${left}px`;
2171
+ canvas.style.inlineSize = `${cssWidth}px`;
2172
+ const ratio = window.devicePixelRatio || 1;
2173
+ const width = Math.round(cssWidth * ratio);
2174
+ const height = Math.round(canvas.clientHeight * ratio);
2175
+ canvas.width = width;
2176
+ canvas.height = height;
2177
+ const context = canvas.getContext("2d");
2178
+ if (!context || width === 0 || height === 0 || scale.pixelsPerUnit === 0) return;
2179
+ const style = getComputedStyle(canvas);
2180
+ context.fillStyle = style.color;
2181
+ const mirrored = style.direction === "rtl";
2182
+ const middle = height / 2;
2183
+ const trackGain = dbToGain(track.gainDb);
2184
+ for (const clip of track.clips) {
2185
+ const from = Math.max(clip.at, range.start);
2186
+ const to = Math.min(clipEnd(clip), range.end);
2187
+ if (to <= from) continue;
2188
+ const peaks = peaksOf(clip.source);
2189
+ if (!peaks) continue;
2190
+ const x0 = (scale.toPixels(from) - left) * ratio;
2191
+ const x1 = (scale.toPixels(to) - left) * ratio;
2192
+ const columns = Math.max(1, Math.round(x1 - x0));
2193
+ const { min, max } = peakColumns(peaks, {
2194
+ from: clip.start + (from - clip.at),
2195
+ to: clip.start + (to - clip.at),
2196
+ columns
2197
+ });
2198
+ const framesPerColumn = (to - from) / columns;
2199
+ for (let column = 0; column < columns; column += 1) {
2200
+ const frame = Math.min(to - 1, Math.floor(from + (column + .5) * framesPerColumn));
2201
+ const gain = gainAt(clip, frame - clip.at) * trackGain;
2202
+ const high = Math.min(1, Math.max(-1, max[column] * gain));
2203
+ const low = Math.min(1, Math.max(-1, min[column] * gain));
2204
+ const x = Math.floor(x0) + column;
2205
+ context.fillRect(mirrored ? width - x - 1 : x, middle - high * middle, 1, Math.max(1, (high - low) * middle));
2206
+ }
2207
+ }
2208
+ }
2209
+ function AudioWaveform({ track, peaksOf, subscribeRange }) {
2210
+ const canvas = useRef(null);
2211
+ const scale = useTimelineScale();
2212
+ useEffect(() => {
2213
+ const element = canvas.current;
2214
+ if (!element) return;
2215
+ let request = 0;
2216
+ const schedule = () => {
2217
+ cancelAnimationFrame(request);
2218
+ request = requestAnimationFrame(() => draw(element, track, scale, peaksOf));
2219
+ };
2220
+ const observer = new ResizeObserver(schedule);
2221
+ observer.observe(element);
2222
+ const queries = ["(prefers-color-scheme: dark)", "(forced-colors: active)"].map((query) => matchMedia(query));
2223
+ for (const query of queries) query.addEventListener("change", schedule);
2224
+ const unsubscribe = subscribeRange(schedule);
2225
+ schedule();
2226
+ return () => {
2227
+ cancelAnimationFrame(request);
2228
+ observer.disconnect();
2229
+ unsubscribe();
2230
+ for (const query of queries) query.removeEventListener("change", schedule);
2231
+ };
2232
+ }, [
2233
+ track,
2234
+ scale,
2235
+ peaksOf,
2236
+ subscribeRange
2237
+ ]);
2238
+ return /* @__PURE__ */ jsx("canvas", {
2239
+ ref: canvas,
2240
+ className: "hm-audio-editor-waveform"
2241
+ });
2242
+ }
2243
+ // src/react/AudioTimeline.tsx
2244
+ var EXTEND_KEYS = /* @__PURE__ */ new Set([
2245
+ "ArrowLeft",
2246
+ "ArrowRight",
2247
+ "ArrowUp",
2248
+ "ArrowDown",
2249
+ "PageUp",
2250
+ "PageDown",
2251
+ "Home",
2252
+ "End"
2253
+ ]);
2254
+ function laneLabel(messages, plan, track, name, audible) {
2255
+ if (track.muted) return messages.t("timeline.lane.muted", { track: name });
2256
+ if (!audible.has(track) && plan.tracks.some((each) => each.soloed)) return messages.t("timeline.lane.silenced", { track: name });
2257
+ return messages.t("timeline.lane", { track: name });
2258
+ }
2259
+ function AudioTimeline({ className }) {
2260
+ return /* @__PURE__ */ jsx(EditorTimeline, {
2261
+ className,
2262
+ classNames: void 0
2263
+ });
2264
+ }
2265
+ function EditorTimeline({ className, classNames }) {
2266
+ const context = useAudioEditorContext();
2267
+ const { messages, output, session, zoom, setMaxZoom, playhead, setCurrentTrack } = context;
2268
+ const { snapshot } = useAudioSession();
2269
+ const { snapshot: playback } = useAudioOutput();
2270
+ const position = useAudioPlayhead();
2271
+ const tools = useAudioTools();
2272
+ const clipTracks = useRef(/* @__PURE__ */ new Map());
2273
+ const { pendingClipFocus } = context;
2274
+ useEffect(() => {
2275
+ const key = pendingClipFocus.current;
2276
+ if (key === void 0) return;
2277
+ for (const handle of clipTracks.current.values()) if (handle.focusClip(key)) {
2278
+ pendingClipFocus.current = void 0;
2279
+ return;
2280
+ }
2281
+ });
2282
+ const { selection } = snapshot;
2283
+ const extending = useRef(void 0);
2284
+ const anchor = useRef({
2285
+ selection,
2286
+ position: 0
2287
+ });
2288
+ anchor.current = {
2289
+ selection,
2290
+ position: output.position()
2291
+ };
2292
+ useEffect(() => {
2293
+ const slider = playhead.current;
2294
+ if (!slider) return;
2295
+ const onKeyDown = (event) => {
2296
+ if (!event.shiftKey || !EXTEND_KEYS.has(event.key)) {
2297
+ extending.current = void 0;
2298
+ return;
2299
+ }
2300
+ const { selection: current, position: at } = anchor.current;
2301
+ extending.current = current && at === current.start ? current.end : current && at === current.end ? current.start : at;
2302
+ };
2303
+ slider.addEventListener("keydown", onKeyDown, true);
2304
+ return () => slider.removeEventListener("keydown", onKeyDown, true);
2305
+ });
2306
+ const listeners = useRef(/* @__PURE__ */ new Set());
2307
+ const subscribeRange = useCallback((listener) => {
2308
+ listeners.current.add(listener);
2309
+ return () => {
2310
+ listeners.current.delete(listener);
2311
+ };
2312
+ }, []);
2313
+ const peaksOf = useCallback((source) => session.getPeaks(source), [session]);
2314
+ const { plan, sources } = snapshot;
2315
+ if (!plan) return null;
2316
+ const length = Math.max(1, planLength(plan));
2317
+ const rate = plan.sampleRate;
2318
+ const time = (frame) => formatTimecode(frame, rate);
2319
+ const audible = new Set(audibleTracks(plan));
2320
+ const names = new Map(sources.map((source) => [source.id, source.name]));
2321
+ const frames = new Map(sources.map((source) => [source.id, source.frames]));
2322
+ const sourceFrames = (source) => frames.get(source) ?? 0;
2323
+ const nudge = nudgeFrames(plan);
2324
+ const rippling = context.ripple && selection && selection.tracks.length < plan.tracks.length ? new Set(selection.tracks) : void 0;
2325
+ return /* @__PURE__ */ jsx("div", {
2326
+ className: classes("hm-audio-editor-timeline", classNames?.timeline, className),
2327
+ children: /* @__PURE__ */ jsxs(Timeline, {
2328
+ label: messages.t("timeline.label"),
2329
+ length,
2330
+ zoom,
2331
+ onMaxZoomChange: setMaxZoom,
2332
+ onVisibleRangeChange: () => {
2333
+ for (const listener of listeners.current) listener();
2334
+ },
2335
+ children: [
2336
+ /* @__PURE__ */ jsx(TimelinePlayhead, {
2337
+ ref: playhead,
2338
+ label: messages.t("timeline.playhead"),
2339
+ position: Math.min(position, length),
2340
+ onPositionChange: (frame) => {
2341
+ const from = extending.current;
2342
+ extending.current = void 0;
2343
+ output.seek(frame);
2344
+ if (from !== void 0 && from !== frame) selectRange(tools.context(), Math.min(from, frame), Math.max(from, frame));
2345
+ },
2346
+ seekOnPress: false,
2347
+ step: Math.max(1, Math.round(rate / 100)),
2348
+ largeStep: rate,
2349
+ formatValue: time,
2350
+ following: playback.state === "playing"
2351
+ }),
2352
+ /* @__PURE__ */ jsx(RangeGestures, {}),
2353
+ plan.tracks.map((track, index) => {
2354
+ const name = trackName(messages, track, index);
2355
+ return /* @__PURE__ */ jsxs(TimelineLane, {
2356
+ id: track.key,
2357
+ label: rippling?.has(track.key) ? messages.t("timeline.lane.ripple", { lane: laneLabel(messages, plan, track, name, audible) }) : laneLabel(messages, plan, track, name, audible),
2358
+ header: /* @__PURE__ */ jsx(AudioTrackHeader, {
2359
+ track,
2360
+ index,
2361
+ rippling: rippling?.has(track.key) ?? false
2362
+ }),
2363
+ "data-hm-silent": audible.has(track) ? void 0 : "",
2364
+ "data-hm-ripple": rippling?.has(track.key) ? "" : void 0,
2365
+ onFocus: () => setCurrentTrack(track.key),
2366
+ children: [
2367
+ selection?.tracks.includes(track.key) ? /* @__PURE__ */ jsx(TimelineLayer, {
2368
+ className: "hm-audio-editor-range-layer",
2369
+ "aria-hidden": "true",
2370
+ children: /* @__PURE__ */ jsx(RangeMark, { selection })
2371
+ }) : null,
2372
+ /* @__PURE__ */ jsx(TimelineLayer, {
2373
+ className: "hm-audio-editor-wave-layer",
2374
+ "aria-hidden": "true",
2375
+ children: /* @__PURE__ */ jsx(AudioWaveform, {
2376
+ track,
2377
+ peaksOf,
2378
+ subscribeRange
2379
+ })
2380
+ }),
2381
+ /* @__PURE__ */ jsx(TimelineClips, {
2382
+ ref: (handle) => {
2383
+ if (handle) clipTracks.current.set(track.key, handle);
2384
+ else clipTracks.current.delete(track.key);
2385
+ },
2386
+ label: messages.t("timeline.clips", { track: name }),
2387
+ clips: track.clips.map((clip, at) => {
2388
+ const shown = names.get(clip.source);
2389
+ const place = {
2390
+ index: at + 1,
2391
+ count: track.clips.length,
2392
+ track: name,
2393
+ start: time(clip.at),
2394
+ end: time(clipEnd(clip))
2395
+ };
2396
+ const label = clip.gainDb === 0 ? shown ? messages.t("timeline.clip.named", {
2397
+ ...place,
2398
+ name: shown
2399
+ }) : messages.t("timeline.clip", place) : shown ? messages.t("timeline.clip.named.gain", {
2400
+ ...place,
2401
+ name: shown,
2402
+ gain: clip.gainDb
2403
+ }) : messages.t("timeline.clip.gain", {
2404
+ ...place,
2405
+ gain: clip.gainDb
2406
+ });
2407
+ return {
2408
+ key: clip.key,
2409
+ at: clip.at,
2410
+ length: clip.end - clip.start,
2411
+ label,
2412
+ ...shown ? { content: /* @__PURE__ */ jsx("bdi", { children: shown }) } : {}
2413
+ };
2414
+ }),
2415
+ selectionMode: "single",
2416
+ selectedKeys: context.selectedClip && track.clips.some((clip) => clip.key === context.selectedClip) ? [context.selectedClip] : [],
2417
+ onSelectedKeysChange: (keys) => context.setSelectedClip(keys[0]),
2418
+ moveHandle: "title",
2419
+ classNames: { content: "hm-audio-editor-clip-title" },
2420
+ onMove: (keys, direction) => moveClips(tools.context(), keys, direction * nudge),
2421
+ onMoveLane: (keys, direction) => moveClipsToTrack(tools.context(), keys, direction),
2422
+ canDrop: (keys, drop) => canPlace(plan, keys, drop.by, drop.lane),
2423
+ onDrop: (keys, drop) => {
2424
+ const edit = tools.context();
2425
+ if (moveClips(edit, keys, drop.by, drop.lane) && drop.lane !== void 0) {
2426
+ const first = keys[0];
2427
+ if (first !== void 0) edit.focusClip(first);
2428
+ }
2429
+ },
2430
+ trimStep: nudge,
2431
+ trimLimits: (key, edge) => trimLimits(plan, sourceFrames, key, edge),
2432
+ onTrim: (key, edge, delta) => trimClip(tools.context(), key, edge, delta),
2433
+ onTrimToPlayhead: (key, edge) => trimClipToPlayhead(tools.context(), key, edge)
2434
+ })
2435
+ ]
2436
+ }, track.key);
2437
+ })
2438
+ ]
2439
+ })
2440
+ });
2441
+ }
2442
+ // src/react/AudioStage.tsx
2443
+ var ACCEPT = "audio/*,.wav,.wave,.aif,.aiff,.aifc,.flac,.mp3,.aac,.m4a,.mp4,.ogg,.oga,.opus,.webm,.mka";
2444
+ function AudioStage({ className }) {
2445
+ return /* @__PURE__ */ jsx(Stage, {
2446
+ className,
2447
+ classNames: void 0
2448
+ });
2449
+ }
2450
+ function Stage({ className, classNames }) {
2451
+ const { messages, load, open, cancelLoad } = useAudioEditorContext();
2452
+ const { snapshot } = useAudioSession();
2453
+ const { plan, error } = snapshot;
2454
+ const failure = error && !isAudioError(error, "ABORTED") ? /* @__PURE__ */ jsx("p", {
2455
+ className: "hm-audio-editor-error",
2456
+ role: "alert",
2457
+ children: audioErrorText(messages, error)
2458
+ }) : null;
2459
+ return /* @__PURE__ */ jsxs("div", {
2460
+ className: classes("hm-audio-editor-stage", classNames?.stage, className),
2461
+ "data-hm-empty": plan ? void 0 : "",
2462
+ children: [load ? /* @__PURE__ */ jsxs("div", {
2463
+ className: "hm-audio-editor-progress",
2464
+ children: [/* @__PURE__ */ jsx(ProgressBar, {
2465
+ value: load.fraction,
2466
+ max: 1,
2467
+ label: messages.t(load.kind === "open" ? "editor.opening" : "editor.inserting")
2468
+ }), /* @__PURE__ */ jsx(Button, {
2469
+ size: "small",
2470
+ onClick: cancelLoad,
2471
+ children: messages.t("editor.cancel")
2472
+ })]
2473
+ }) : null, plan ? /* @__PURE__ */ jsxs(Fragment, { children: [
2474
+ failure,
2475
+ /* @__PURE__ */ jsx("p", {
2476
+ className: "hm-audio-editor-summary",
2477
+ children: messages.t("timeline.summary", {
2478
+ count: plan.tracks.length,
2479
+ duration: formatTimecode(planLength(plan), plan.sampleRate)
2480
+ })
2481
+ }),
2482
+ /* @__PURE__ */ jsx(EditorTimeline, { classNames })
2483
+ ] }) : load ? null : /* @__PURE__ */ jsx(FileDropZone, {
2484
+ className: "hm-audio-editor-drop",
2485
+ accept: ACCEPT,
2486
+ hint: messages.t("editor.empty"),
2487
+ onFiles: ([file]) => {
2488
+ if (file) open(file).catch(() => {});
2489
+ },
2490
+ children: failure
2491
+ })]
2492
+ });
2493
+ }
2494
+ // src/react/AudioToolbar.tsx
2495
+ var ICONS = {
2496
+ open: OpenIcon,
2497
+ upload: UploadIcon,
2498
+ undo: UndoIcon,
2499
+ redo: RedoIcon,
2500
+ add: AddIcon,
2501
+ remove: RemoveIcon,
2502
+ "move-up": MoveUpIcon,
2503
+ "move-down": MoveDownIcon,
2504
+ muted: MutedIcon,
2505
+ "zoom-in": ZoomInIcon,
2506
+ "zoom-out": ZoomOutIcon,
2507
+ fit: FitIcon,
2508
+ play: PlayIcon,
2509
+ "skip-back": SkipBackIcon,
2510
+ "skip-forward": SkipForwardIcon,
2511
+ split: SplitIcon,
2512
+ delete: DeleteIcon,
2513
+ "trim-start": TrimStartIcon,
2514
+ "trim-end": TrimEndIcon,
2515
+ "chevron-left": ChevronLeftIcon,
2516
+ "chevron-right": ChevronRightIcon,
2517
+ close: CloseIcon,
2518
+ download: DownloadIcon,
2519
+ "fade-in": FadeInIcon,
2520
+ "fade-out": FadeOutIcon,
2521
+ "range-start": RangeStartIcon,
2522
+ "range-end": RangeEndIcon,
2523
+ ripple: RippleIcon
2524
+ };
2525
+ var GROUP_LABELS = {
2526
+ file: "toolbar.file",
2527
+ history: "toolbar.history",
2528
+ tracks: "toolbar.tracks",
2529
+ clips: "toolbar.clips",
2530
+ range: "toolbar.range",
2531
+ view: "toolbar.view"
2532
+ };
2533
+ function AudioToolbar({ className }) {
2534
+ return /* @__PURE__ */ jsx(EditorToolbar, {
2535
+ className,
2536
+ classNames: void 0
2537
+ });
2538
+ }
2539
+ function EditorToolbar({ className, classNames }) {
2540
+ const { messages, tools, fileChooser, open, insert } = useAudioEditorContext();
2541
+ const { flags, run, ariaKeyShortcuts, labelWithKeys } = useAudioTools();
2542
+ const picker = useRef(null);
2543
+ const purpose = useRef("open");
2544
+ useEffect(() => {
2545
+ const chooser = (next) => {
2546
+ purpose.current = next;
2547
+ picker.current?.click();
2548
+ };
2549
+ fileChooser.current = chooser;
2550
+ return () => {
2551
+ if (fileChooser.current === chooser) fileChooser.current = null;
2552
+ };
2553
+ }, [fileChooser]);
2554
+ if (tools.toolbar.length === 0) return null;
2555
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Toolbar, {
2556
+ className: classes("hm-audio-editor-toolbar", classNames?.toolbar, className),
2557
+ label: messages.t("toolbar.label"),
2558
+ children: tools.toolbar.map((group) => {
2559
+ const name = group[0]?.group;
2560
+ const label = name && GROUP_LABELS[name] ? messages.t(GROUP_LABELS[name]) : "";
2561
+ return /* @__PURE__ */ jsx(ToolbarGroup, {
2562
+ label,
2563
+ children: group.map((tool) => {
2564
+ const state = flags.get(tool.id) ?? {
2565
+ enabled: false,
2566
+ active: false
2567
+ };
2568
+ const Icon = ICONS[tool.icon] ?? AddIcon;
2569
+ const common = {
2570
+ label: messages.t(tool.label),
2571
+ icon: /* @__PURE__ */ jsx(Icon, {}),
2572
+ title: labelWithKeys(tool.id),
2573
+ "aria-keyshortcuts": ariaKeyShortcuts(tool.id),
2574
+ variant: "quiet",
2575
+ disabled: !state.enabled,
2576
+ focusableWhenDisabled: true,
2577
+ "data-hm-tool": tool.id
2578
+ };
2579
+ return tool.isActive ? /* @__PURE__ */ jsx(ToggleButton, {
2580
+ ...common,
2581
+ pressed: state.active,
2582
+ onPressedChange: () => run(tool.id)
2583
+ }, tool.id) : /* @__PURE__ */ jsx(IconButton, {
2584
+ ...common,
2585
+ onClick: () => run(tool.id)
2586
+ }, tool.id);
2587
+ })
2588
+ }, group.map((tool) => tool.id).join(" "));
2589
+ })
2590
+ }), /* @__PURE__ */ jsx("input", {
2591
+ ref: picker,
2592
+ type: "file",
2593
+ accept: ACCEPT,
2594
+ hidden: true,
2595
+ className: "hm-audio-editor-picker",
2596
+ onChange: (event) => {
2597
+ const file = event.currentTarget.files?.[0];
2598
+ event.currentTarget.value = "";
2599
+ if (!file) return;
2600
+ (purpose.current === "open" ? open(file) : insert(file)).catch(() => {});
2601
+ }
2602
+ })] });
2603
+ }
2604
+ // src/react/AudioTransport.tsx
2605
+ function AudioTransport({ className }) {
2606
+ return /* @__PURE__ */ jsx(Transport, {
2607
+ className,
2608
+ classNames: void 0
2609
+ });
2610
+ }
2611
+ var Transport = forwardRef(function Transport({ className, classNames }, ref) {
2612
+ const { messages } = useAudioEditorContext();
2613
+ const { snapshot } = useAudioSession();
2614
+ const { output, snapshot: playback } = useAudioOutput();
2615
+ const position = useAudioPlayhead();
2616
+ const [notice, setNotice] = useState();
2617
+ const { plan } = snapshot;
2618
+ const length = plan ? planLength(plan) : 0;
2619
+ const rate = plan?.sampleRate ?? 1;
2620
+ const playing = playback.state === "playing";
2621
+ const playPause = () => {
2622
+ if (playing) {
2623
+ output.pause();
2624
+ return;
2625
+ }
2626
+ setNotice(void 0);
2627
+ output.play().catch((error) => setNotice(audioErrorText(messages, error)));
2628
+ };
2629
+ return /* @__PURE__ */ jsxs("section", {
2630
+ className: classes("hm-audio-editor-transport", classNames?.transport, className),
2631
+ "aria-label": messages.t("transport.label"),
2632
+ children: [
2633
+ /* @__PURE__ */ jsx(IconButton, {
2634
+ ref,
2635
+ variant: "primary",
2636
+ label: messages.t(playing ? "transport.pause" : "transport.play"),
2637
+ icon: playing ? /* @__PURE__ */ jsx(PauseIcon, {}) : /* @__PURE__ */ jsx(PlayIcon, {}),
2638
+ disabled: length === 0,
2639
+ focusableWhenDisabled: true,
2640
+ onClick: playPause
2641
+ }),
2642
+ /* @__PURE__ */ jsx(IconButton, {
2643
+ label: messages.t("transport.start"),
2644
+ icon: /* @__PURE__ */ jsx(SkipBackIcon, {}),
2645
+ disabled: length === 0,
2646
+ focusableWhenDisabled: true,
2647
+ onClick: () => output.seek(0)
2648
+ }),
2649
+ /* @__PURE__ */ jsx("p", {
2650
+ className: "hm-audio-editor-time",
2651
+ children: messages.t("transport.time", {
2652
+ position: formatTimecode(Math.min(position, length), rate),
2653
+ duration: formatTimecode(length, rate)
2654
+ })
2655
+ }),
2656
+ snapshot.selection && plan ? /* @__PURE__ */ jsx("p", {
2657
+ className: "hm-audio-editor-selection",
2658
+ children: messages.t("timeline.selection", {
2659
+ start: formatTimecode(snapshot.selection.start, rate),
2660
+ end: formatTimecode(snapshot.selection.end, rate),
2661
+ tracks: tracksText(messages, plan, plan.tracks.filter((track) => snapshot.selection?.tracks.includes(track.key)))
2662
+ })
2663
+ }) : null,
2664
+ notice ? /* @__PURE__ */ jsx("p", {
2665
+ className: "hm-audio-editor-transport-notice",
2666
+ role: "status",
2667
+ children: notice
2668
+ }) : null
2669
+ ]
2670
+ });
2671
+ });
2672
+ // src/react/AudioEditor.tsx
2673
+ var CONTROL_KEYS = /* @__PURE__ */ new Set(["audio.start", "audio.end"]);
2674
+ function ownsHomeAndEnd(target) {
2675
+ return target instanceof Element && target.closest("[role=\"listbox\"],[role=\"toolbar\"],[role=\"slider\"],input,textarea,select") !== null;
2676
+ }
2677
+ var Shell = forwardRef(function Shell(props, ref) {
2678
+ const { session, output, messages, open, insert } = useAudioEditorContext();
2679
+ useImperativeHandle(ref, () => ({
2680
+ open,
2681
+ insert,
2682
+ undo: () => session.undo(),
2683
+ redo: () => session.redo(),
2684
+ play: () => output.play(),
2685
+ pause: () => output.pause(),
2686
+ seek: (frame) => output.seek(frame),
2687
+ export: (options) => session.export(options)
2688
+ }), [
2689
+ session,
2690
+ output,
2691
+ open,
2692
+ insert
2693
+ ]);
2694
+ const opened = useRef(false);
2695
+ useEffect(() => {
2696
+ if (opened.current || !props.initialFile) return;
2697
+ opened.current = true;
2698
+ open(props.initialFile).catch(() => {});
2699
+ }, [props.initialFile, open]);
2700
+ return /* @__PURE__ */ jsx(UiMessagesProvider, {
2701
+ messages,
2702
+ children: /* @__PURE__ */ jsx(AnnouncerProvider, { children: /* @__PURE__ */ jsx(Root, { ...props }) })
2703
+ });
2704
+ });
2705
+ function Root({ onChange, theme, headingLevel, fileName, onExport, className, classNames, unstyled }) {
2706
+ const { messages, playhead, shortcuts } = useAudioEditorContext();
2707
+ const { run } = useAudioTools();
2708
+ const { snapshot } = useAudioSession();
2709
+ const announce = useAnnounce();
2710
+ const play = useRef(null);
2711
+ const { plan, sources } = snapshot;
2712
+ const change = useRef(onChange);
2713
+ change.current = onChange;
2714
+ useEffect(() => {
2715
+ if (plan) change.current?.(plan);
2716
+ }, [plan]);
2717
+ const { onError } = useContext(ElementListenersContext);
2718
+ const { error } = snapshot;
2719
+ useEffect(() => {
2720
+ if (error) onError?.({
2721
+ code: error.code,
2722
+ details: error.details ?? {}
2723
+ });
2724
+ }, [error, onError]);
2725
+ const first = sources[0]?.id;
2726
+ const count = sources.length;
2727
+ const seen = useRef({
2728
+ first,
2729
+ count
2730
+ });
2731
+ useEffect(() => {
2732
+ const before = seen.current;
2733
+ seen.current = {
2734
+ first,
2735
+ count
2736
+ };
2737
+ if (first !== void 0 && first !== before.first) {
2738
+ announce(messages.t("editor.opened"));
2739
+ (playhead.current ?? play.current)?.focus();
2740
+ } else if (first !== void 0 && count > before.count) announce(messages.t("editor.inserted"));
2741
+ }, [
2742
+ first,
2743
+ count,
2744
+ announce,
2745
+ messages,
2746
+ playhead
2747
+ ]);
2748
+ return /* @__PURE__ */ jsxs("section", {
2749
+ className: classes(unstyled ? void 0 : "hm-text", "hm-audio-editor", className, classNames?.root),
2750
+ "aria-label": messages.t("editor.label"),
2751
+ "data-hm-theme": theme,
2752
+ "data-hm-unstyled": unstyled ? "" : void 0,
2753
+ onKeyDown: (event) => {
2754
+ const id = shortcuts.match(event.nativeEvent, { root: event.currentTarget });
2755
+ if (!id || CONTROL_KEYS.has(id) && ownsHomeAndEnd(event.target)) return;
2756
+ if (run(id)) event.preventDefault();
2757
+ },
2758
+ children: [
2759
+ /* @__PURE__ */ jsx(EditorToolbar, { classNames }),
2760
+ /* @__PURE__ */ jsx(Notices, { classNames }),
2761
+ /* @__PURE__ */ jsxs("div", {
2762
+ className: "hm-audio-editor-main",
2763
+ children: [/* @__PURE__ */ jsxs("div", {
2764
+ className: "hm-audio-editor-work",
2765
+ children: [/* @__PURE__ */ jsx(Stage, { classNames }), /* @__PURE__ */ jsx(Transport, {
2766
+ ref: play,
2767
+ classNames
2768
+ })]
2769
+ }), /* @__PURE__ */ jsx(EditorInspector, {
2770
+ classNames,
2771
+ headingLevel
2772
+ })]
2773
+ }),
2774
+ /* @__PURE__ */ jsx(AudioRenameDialog, {}),
2775
+ /* @__PURE__ */ jsx(AudioExportDialog, {
2776
+ ...fileName === void 0 ? {} : { fileName },
2777
+ ...onExport === void 0 ? {} : { onExport }
2778
+ })
2779
+ ]
2780
+ });
2781
+ }
2782
+ var AudioEditor = /* @__PURE__ */ forwardRef(function AudioEditor({ initialFile, onChange, theme, headingLevel, fileName, onExport, className, classNames, unstyled = false, ...provider }, ref) {
2783
+ return /* @__PURE__ */ jsx(AudioEditorProvider, {
2784
+ ...provider,
2785
+ children: /* @__PURE__ */ jsx(Shell, {
2786
+ ref,
2787
+ initialFile,
2788
+ onChange,
2789
+ theme,
2790
+ headingLevel,
2791
+ fileName,
2792
+ onExport,
2793
+ className,
2794
+ classNames,
2795
+ unstyled
2796
+ })
2797
+ });
2798
+ });
2799
+ export { AudioTimeline as a, AudioExportDialog as c, useAudioMessages as d, useAudioOutput as f, audioEditorMessages as h, AudioStage as i, ElementListenersContext as l, useAudioSession as m, AudioTransport as n, AudioNotices as o, useAudioPlayhead as p, AudioToolbar as r, AudioInspector as s, AudioEditor as t, AudioEditorProvider as u };
2800
+
2801
+ //# sourceMappingURL=AudioEditor-_EPL0XcW.js.map