@hussmartinez/audio-sdk 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,143 @@
1
1
  # audio-sdk
2
2
 
3
- A client-side audio SDK: layer recordings on tracks, trim, split, fade, adjust gain, play and export audio entirely in the browser. Audio never leaves the device. Its headless core is published; a React editor (`AudioEditor`) and a `<hm-audio-editor>` custom element come later.
3
+ A client-side audio SDK: layer recordings on tracks, trim, split, fade, adjust gain, play and export audio entirely in the browser. Audio never leaves the device. It offers a headless core, a React editor (`AudioEditor`) and a `<hm-audio-editor>` custom element.
4
4
 
5
5
  This repository publishes **[`@hussmartinez/audio-sdk`](https://www.npmjs.com/package/@hussmartinez/audio-sdk)**. It follows the family standards in [`sdk-core`'s `STANDARDS.md`](https://github.com/ie-huss-martinez/sdk-core/blob/main/STANDARDS.md), and in particular the decisions on [hostile input and no network](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0012-hostile-input-and-no-network.md), [workers and assets](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0011-worker-messaging-and-assets.md) and [ports and adapters](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0008-ports-adapters-and-session.md).
6
6
 
7
- > Status: pre-1.0. The headless core is published: opening, multitrack editing with undo, playback, and exporting to WAV ([ADR 0006](docs/adr/0006-multitrack.md)). The editor UI is next, and the API may change between minor versions until 1.0.
7
+ > Status: pre-1.0. The headless core, the React editor and the element are published: opening, multitrack editing with undo, playback, and exporting to WAV ([ADR 0006](docs/adr/0006-multitrack.md)). The API may change between minor versions until 1.0.
8
+
9
+ ## The React editor
10
+
11
+ ```tsx
12
+ import "@hussmartinez/ui/styles.css";
13
+ import "@hussmartinez/audio-sdk/styles.css";
14
+ import { AudioEditor, type AudioEditorHandle } from "@hussmartinez/audio-sdk/react";
15
+
16
+ const editor = useRef<AudioEditorHandle>(null);
17
+
18
+ <div style={{ height: "100dvh" }}>
19
+ <AudioEditor ref={editor} initialFile={file} onChange={(plan) => setPlan(plan)} />
20
+ </div>;
21
+
22
+ const { blob } = await editor.current!.export();
23
+ ```
24
+
25
+ It shows a toolbar, the timeline with a lane per track (its header, waveform and clips) and the playhead, the transport, an inspector, and the export dialog ([ADR 0005](docs/adr/0005-editor-shell.md), [ADR 0006](docs/adr/0006-multitrack.md)). People open a recording with its button or by dropping a file, and add more, each on a track of its own.
26
+
27
+ **Styles: ui's stylesheet is required.** Import `@hussmartinez/ui/styles.css` once in your application, before `@hussmartinez/audio-sdk/styles.css`, as above. The editor is built from [`@hussmartinez/ui`](https://www.npmjs.com/package/@hussmartinez/ui)'s components, whose focus rings, minimum target sizes, design tokens, themes and density are in ui's stylesheet ([sdk-core ADR 0036](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0036-ui-as-a-dependency-of-the-sdks.md)). The SDK's stylesheet never includes it, so a page with several SDKs loads it once. The SDK's styles are in the `hm.sdk` cascade layer and use `.hm-audio-*` classes with values from `--hm-*` tokens; `classNames` adds your classes to the editor's parts, and `unstyled` leaves out its own look.
28
+
29
+ **One copy of ui and sdk-core.** The SDK depends on `@hussmartinez/ui` `^0.14.0` and `@hussmartinez/sdk-core` `^0.4.4`. If your application uses either itself, depend on the same minor versions, and check that `npm ls @hussmartinez/ui @hussmartinez/sdk-core` lists one version of each: a second copy doesn't share providers with the first, so text falls back to English and announcements are lost.
30
+
31
+ **A bounded height.** `AudioEditor` fills the height of its container, and its timeline scrolls within it, so give it a bounded height: a fixed height, or a grid row such as `minmax(0, 1fr)`. Where the editor is at least 1080 px wide, the inspector sits beside the timeline; otherwise it's below the transport.
32
+
33
+ **Text.** `messages` overrides any text the editor shows, by key, including ui's, and `locale` sets the language for numbers and plurals ([sdk-core ADR 0046](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0046-ui-text-through-the-sdk.md)). `audioEditorMessages`, from `@hussmartinez/audio-sdk/react`, is the English catalogue, and `AudioEditorMessageOverrides` types your overrides. `audioMessages`, from the server-safe entry, holds only error and warning text.
34
+
35
+ | Prop | What it does |
36
+ |---|---|
37
+ | `initialFile` | A recording opened when the editor mounts |
38
+ | `onChange(plan)` | The plan, whenever it changes: when a recording opens or is added, after every edit, and after undo and redo |
39
+ | `fileName` | The name an export is downloaded under, without its extension; otherwise the recording's title, or `recording` |
40
+ | `onExport(blob, result)` | Takes an export's file instead of the download, and the dialog closes; `result` has the mix's `peakDb` and `clippedFrames` |
41
+ | `tools`, `toolbar` | Which tools are present, by id, and the toolbar's groups of them; an unknown id throws |
42
+ | `headingLevel` | The level of the editor's headings, from 2 to 6, so they fit your page's outline; 2 by default |
43
+ | `theme` | `light`, `dark` or `system`; without it, the editor follows the page's theme |
44
+ | `assetsUrl` | Where you serve the package's `dist/assets/`, to self-host the worker (see [Content Security Policy](#content-security-policy)) |
45
+ | `filePolicy` | Limits for untrusted files, as for `createAudioSession` |
46
+ | `engine`, `processor`, `output` | Your own adapters; the editor makes the SDK's own for any you leave out, and destroys only those |
47
+ | `messages`, `locale` | Text overrides and the locale, as above |
48
+ | `onEvent` | Anonymous usage events, as for `createAudioSession` |
49
+ | `className`, `classNames`, `unstyled` | Classes on the root and on the editor's parts, and leaving out the editor's own look |
50
+
51
+ The ref's `AudioEditorHandle` has `open(file)`, `insert(file, options)`, `export(options)`, `undo()`, `redo()`, `play()`, `pause()` and `seek(frame)`. `export()` exports the plan as it is, without the dialog, and resolves `{ blob, peakDb, clippedFrames }`.
52
+
53
+ ### Exporting
54
+
55
+ The Export tool opens the export dialog. Export is irreversible, so it shows a summary first: the length, the sample rate and channels, any track a mute or a solo leaves out, and the metadata that will be written. Then the format, 16-bit WAV (the default), 24-bit or 32-bit float, each with the file's exact size. While it runs, a progress bar and Stop; when it's done, Download, which gets focus. The download uses a `blob:` URL, so it makes no request. When the mix went over full scale, the dialog says by how much, and one button lowers the master gain by that and exports again. Closing the dialog stops an export that's running.
56
+
57
+ ### Tools, the toolbar and shortcuts
58
+
59
+ | Tool | Shortcut | What it does |
60
+ |---|---|---|
61
+ | `audio.open` | none: `Ctrl+O` is the browser's own | Opens a recording, replacing the current one |
62
+ | `audio.insert` | none | Adds a recording on a track of its own |
63
+ | `audio.export` | none | Opens the export dialog |
64
+ | `audio.undo` | `Ctrl+Z`, or `⌘Z` on Apple platforms | Undoes the last edit |
65
+ | `audio.redo` | `Ctrl+Shift+Z` or `Ctrl+Y`, or `⇧⌘Z` | Redoes the last undone edit |
66
+ | `audio.add-track`, `audio.remove-track` | none | Adds a track below the current one, or removes the current one; a plan keeps at least one |
67
+ | `audio.move-track-up`, `audio.move-track-down` | none | Moves the current track |
68
+ | `audio.mute` | `M` | Mutes or unmutes the current track |
69
+ | `audio.split` | `S` | Splits the clip under the playhead |
70
+ | `audio.delete` | `Delete` or `Backspace` | Deletes the selected range, or else the selected clip |
71
+ | `audio.trim-start`, `audio.trim-end` | `[`, `]` | Sets the selected clip's start or end to the playhead |
72
+ | `audio.fade-in`, `audio.fade-out` | none | Fades the selected range, or gives the selected clip a half-second fade |
73
+ | `audio.move-earlier`, `audio.move-later` | none: `Alt+←` and `Alt+→` on a clip | Moves the selected clip 10 ms |
74
+ | `audio.move-to-track-above`, `audio.move-to-track-below` | none: `Alt+↑` and `Alt+↓` on a clip | Moves the selected clip to the next track, at the same time |
75
+ | `audio.set-start`, `audio.set-end` | `I`, `O` | Starts or ends the selection at the playhead |
76
+ | `audio.clear-selection` | `Escape` | Clears the selection |
77
+ | `audio.ripple` | none | Whether deleting a range closes the gap on its tracks; on by default |
78
+ | `audio.zoom-in`, `audio.zoom-out`, `audio.zoom-fit` | `+`, `-`, `0` | Zooms the timeline |
79
+ | `audio.play-pause` | `Space` | Plays or pauses; not on a button or field, whose own key it is |
80
+ | `audio.start`, `audio.end` | `Home`, `End` | Moves the playhead to the start or the end; not in a list, toolbar or slider, whose own keys they are |
81
+
82
+ On the timeline, `←` and `→` move between a track's clips and `↑` and `↓` between tracks; `Alt+[` and `Alt+]` shorten a clip's start or end by 10 ms, and with `Shift` lengthen it. The playhead steps 10 ms with the arrows and a second with `Page Up` and `Page Down`, and `Shift` with its keys extends the selection. Dragging across the timeline selects a range, and dragging a clip's title moves it.
83
+
84
+ Shortcuts work only while focus is inside the editor, never on the rest of your page, and never while typing in a field. The toolbar is one tab stop, with arrow keys between its buttons; each button names its shortcut in `aria-keyshortcuts`, and one that can't run is disabled with `aria-disabled`, so it keeps focus. Track and clip edits, selections made with the keyboard, refused moves and finished exports are announced to screen readers.
85
+
86
+ ```tsx
87
+ <AudioEditor
88
+ tools={["audio.open", "audio.undo", "audio.redo", "audio.split", "audio.delete"]}
89
+ toolbar={[["audio.open"], ["audio.undo", "audio.redo"], ["audio.split", "audio.delete"]]}
90
+ />
91
+ ```
92
+
93
+ ### Building blocks
94
+
95
+ `AudioEditorProvider` holds the session, the output and the editor's state, and `AudioToolbar`, `AudioStage`, `AudioTimeline`, `AudioTransport`, `AudioInspector`, `AudioNotices` and `AudioExportDialog` render inside it, for a layout of your own. `useAudioSession`, `useAudioOutput`, `useAudioPlayhead` and `useAudioMessages` read it; `useAudioPlayhead` updates at most once a frame while playing.
96
+
97
+ ### Server rendering
98
+
99
+ `@hussmartinez/audio-sdk/react` starts with `"use client"`, so a Next.js Server Component can render the editor directly, and the server-safe entry can run there ([sdk-core ADR 0007](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0007-server-rendering-and-nextjs.md)). On the server it renders the empty editor, with no engine, worker or `AudioContext`; `examples/next` is a working App Router page.
100
+
101
+ ```tsx
102
+ import { audioLimits } from "@hussmartinez/audio-sdk";
103
+ import { AudioEditor } from "@hussmartinez/audio-sdk/react";
104
+
105
+ export default function Page() {
106
+ return (
107
+ <main style={{ height: "100%" }}>
108
+ <p>Up to {audioLimits.definitions.maxTracks.default} tracks</p>
109
+ <AudioEditor />
110
+ </main>
111
+ );
112
+ }
113
+ ```
114
+
115
+ ### Content Security Policy
116
+
117
+ By default the editor's worker is inlined and starts from a `blob:` URL, which needs `worker-src blob:`. Under a stricter policy, self-host it: serve the package's `dist/assets/` and pass its URL as `assetsUrl`, which needs only `worker-src 'self'`. [Worker and Content Security Policy](#worker-and-content-security-policy) has both modes. The editor makes no network requests of its own, and its download uses a `blob:` URL.
118
+
119
+ ## The element
120
+
121
+ ```ts
122
+ import "@hussmartinez/ui/styles.css";
123
+ import "@hussmartinez/audio-sdk/styles.css";
124
+ import {
125
+ type AudioEditorElementProps,
126
+ defineAudioEditorElement,
127
+ } from "@hussmartinez/audio-sdk/element";
128
+
129
+ defineAudioEditorElement();
130
+ const editor = document.querySelector("hm-audio-editor") as HTMLElement & AudioEditorElementProps;
131
+ editor.file = file;
132
+ editor.addEventListener("hm-audio-editor-change", (event) => save((event as CustomEvent).detail));
133
+ ```
134
+
135
+ `<hm-audio-editor>` renders `AudioEditor` into its light DOM, for pages without React of their own; React and React DOM, the package's optional peer dependencies, are still needed. Importing the entry registers nothing: call `defineAudioEditorElement()` once, for `hm-audio-editor` or a tag you name. The stylesheet makes the element a block, which you size.
136
+
137
+ - **Attributes:** `theme` (`light`, `dark` or `system`), `locale`, and `tools`, space-separated.
138
+ - **Properties:** `file`, which opens a recording when you set it, `fileName`, `headingLevel`, `filePolicy`, `assetsUrl`, `messages`, `engine`, `processor` and `output`.
139
+ - **Methods:** `open`, `insert`, `export`, `undo`, `redo`, `play`, `pause` and `seek`. `open`, `insert`, `export` and `play` wait for the editor's first render.
140
+ - **Events:** `hm-audio-editor-change` with the plan, `hm-audio-editor-event` with the usage event, `hm-audio-editor-export` with an `AudioExportReport` after the export dialog finishes (the sample format, size, peak and clamped frames, and no file), and `hm-audio-editor-error` with a failure's `code` and `details`. None carries a file name or contents.
8
141
 
9
142
  ## Editing and exporting
10
143
 
@@ -1 +1 @@
1
- var e=!1;function t(){e||=!0}var n=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),r=class extends Error{name=`SdkError`;code;constructor(e,r,i={}){super(r,`cause`in i?{cause:i.cause}:void 0),t(),this.code=e,Object.defineProperty(this,n,{value:!0}),i.details!==void 0&&(this.details=i.details)}};function i(e,t){if(typeof e!=`object`||!e)return!1;let i=e;return(e instanceof r||i[n]===!0)&&typeof i.code==`string`&&typeof i.message==`string`&&(t===void 0||i.code===t)}var a=1<<20;function o(e,t,n){if(!Number.isSafeInteger(t)||t<n)throw RangeError(`The ${e} must be an integer of at least ${n}, not ${String(t)}.`)}function s(e,t={}){let n=t.windowSize??a;o(`window size`,n,1);let r=e.size,i=0,s=/* @__PURE__ */ new Uint8Array;return{size:r,async bytes(t,a){o(`offset`,t,0),o(`length`,a,0);let c=Math.min(t,r),l=Math.min(r,c+a);if(c<i||l>i+s.length){let t=Math.min(r,c+Math.max(a,n));s=new Uint8Array(await e.slice(c,t).arrayBuffer()),i=c}return s.subarray(c-i,l-i)}}}var c=8,l=16,u=`UNKNOWN`;function d(e,t={}){let n=t.includeStack??!1,r=_(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=f(e),s=n&&h(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),h(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function f(e){if(i(e)){let t={name:e.name,code:e.code,message:e.message},n=p(e.details);return n!==void 0&&(t.details=n),t}if(h(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:u,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:u,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:u,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function p(e){if(!g(e))return;let t=m(e,0);return g(t)?t:void 0}function m(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(!(t>=l)){if(Array.isArray(e))return e.flatMap(e=>{let n=m(e,t+1);return n===void 0?[]:[n]});if(g(e)){let n={};for(let[r,i]of Object.entries(e)){let e=m(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function h(e){return typeof e==`object`&&!!e}function g(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function _(e){if(e===void 0)return c;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}[...Array.from({length:12},(e,t)=>`F${t+1}`)];var v=`hm-rpc`;function y(e){return{protocol:v,version:1,...e}}function b(e){if(typeof e!=`object`||!e)return;let t=e;if(t.protocol!==`hm-rpc`||typeof t.version!=`number`)return;let n=Number.isSafeInteger(t.id);switch(t.type){case`ready`:return t;case`call`:return n&&typeof t.method==`string`?t:void 0;case`cancel`:case`progress`:case`result`:return n?t:void 0;case`error`:return n?t:void 0;case`crash`:return t;default:return}}function x(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{if(typeof e!=`object`||!e)return e;if(r.has(e))return r.get(e);if(ArrayBuffer.isView(e)){let i=C(e)?e:w(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return E(e)?(t&&n.add(e),r.set(e,e),e):Array.isArray(e)?a(e,()=>[],(e,t)=>{t.forEach((t,n)=>{e[n]=i(t)})}):e instanceof Map?a(e,()=>/* @__PURE__ */ new Map,(e,t)=>{for(let[n,r]of t)e.set(i(n),i(r))}):e instanceof Set?a(e,()=>/* @__PURE__ */ new Set,(e,t)=>{for(let n of t)e.add(i(n))}):D(e)?a(e,()=>({}),(e,t)=>{for(let[n,r]of Object.entries(t))e[n]=i(r)}):(r.set(e,e),e)},a=(e,t,n)=>{let i=t();return r.set(e,i),n(i,e),ee(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function S(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function C(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function w(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();if(e instanceof DataView)return new DataView(t.buffer);let n=e.constructor;return new n(t.buffer)}var T=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function E(e){let t=globalThis;return T.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function D(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ee(e,t){if(Array.isArray(e)){let n=t;return e.length===n.length&&e.every((e,t)=>e===n[t])}if(e instanceof Map){let n=[...t];return[...e].every(([e,t],r)=>n[r]?.[0]===e&&n[r]?.[1]===t)}if(e instanceof Set){let n=[...t];return[...e].every((e,t)=>n[t]===e)}let n=t;return Object.entries(e).every(([e,t])=>n[e]===t)}function te(e,t={}){let n=t.scope??globalThis,i=t.includeStack??!1,a=/* @__PURE__ */ new Map,o=(e,t=[])=>{n.postMessage(e,t)},s=(e,t)=>{o(y({type:`error`,id:e,error:d(t,{includeStack:i})}))},c=(e,t,i)=>{let a=x(i,!0);try{S((e,t)=>n.postMessage(e,t),y({type:`result`,id:e,output:a.value}),a.transferables)}catch(n){s(e,new r(`WORKER_DATA_NOT_CLONEABLE`,`The result of "${t}" can't be sent to the page.`,{cause:n,details:{method:t}}))}},l=t=>{let{id:n,method:i}=t,l=Object.hasOwn(e,i)?e[i]:void 0;if(typeof l!=`function`){s(n,new r(`WORKER_METHOD_NOT_FOUND`,`The worker has no method "${i}".`,{details:{method:i}}));return}let u=new AbortController;a.set(n,u);let d={signal:u.signal,progress:e=>{a.get(n)===u&&o(y({type:`progress`,id:n,value:e}))}};Promise.resolve().then(()=>l.call(e,t.input,d)).then(e=>{a.delete(n),c(n,i,e)},e=>{a.delete(n),s(n,e)})},u=e=>{o(y({type:`crash`,error:d(e,{includeStack:i})}))};n.addEventListener(`message`,e=>{let t=b(e.data);t!==void 0&&t.version===1&&(t.type===`call`?l(t):t.type===`cancel`&&a.get(t.id)?.abort())}),n.addEventListener(`error`,e=>{let t=e;u(t.error??Error(t.message))}),n.addEventListener(`unhandledrejection`,e=>{u(e.reason)}),o(y({type:`ready`,...t.packageVersion===void 0?{}:{packageVersion:t.packageVersion}}))}var O=class extends r{name=`AudioError`},ne=1024;function k(e,t){return new O(`INVALID_AUDIO`,`Invalid ${e} file: ${t}.`,{details:{container:e,reason:t}})}function A(e,t){return new O(`UNSUPPORTED_FORMAT`,`Unsupported sample format in ${e}: ${t}.`,{details:{container:e,codec:t}})}async function j(e,t,n){let r=await e.slice(t,t+n).arrayBuffer();return new DataView(r)}function M(e,t=0){return e.byteLength<t+4?``:String.fromCharCode(e.getUint8(t),e.getUint8(t+1),e.getUint8(t+2),e.getUint8(t+3))}function re(e){let{container:t,channels:n,sampleRate:r,bytesPerSample:i,blockAlign:a,frames:o,dataOffset:s}=e;if(!Number.isInteger(n)||n<1||n>ne)throw k(t,`channel count out of range`);if(!Number.isInteger(r)||r<1)throw k(t,`sample rate out of range`);if(![1,2,3,4,8].includes(i))throw k(t,`sample size out of range`);if(a!==n*i)throw k(t,`frame size doesn't match the channels and sample size`);if(!Number.isSafeInteger(o)||o<0||!Number.isSafeInteger(s))throw k(t,`length out of range`);return e}var ie={NONE:{encoding:`int`,littleEndian:!1},twos:{encoding:`int`,littleEndian:!1},sowt:{encoding:`int`,littleEndian:!0},in24:{encoding:`int`,littleEndian:!1,bits:24},"42ni":{encoding:`int`,littleEndian:!0,bits:24},in32:{encoding:`int`,littleEndian:!1,bits:32},"23ni":{encoding:`int`,littleEndian:!0,bits:32},fl32:{encoding:`float`,littleEndian:!1,bits:32},FL32:{encoding:`float`,littleEndian:!1,bits:32},fl64:{encoding:`float`,littleEndian:!1,bits:64},FL64:{encoding:`float`,littleEndian:!1,bits:64}};function ae(e,t){let n=e.getUint16(t,!1),r=n&32767;return n&32768||r===0||r===32767?NaN:(e.getUint32(t+2,!1)*2**32+e.getUint32(t+6,!1))*2**(r-16383-63)}function oe(e,t){if(e.byteLength<(t?22:18))throw k(`aiff`,`truncated COMM chunk`);let n=ae(e,8);if(!Number.isInteger(n)||n<1||n>2**31)throw k(`aiff`,`sample rate out of range`);return{channels:e.getInt16(0,!1),frames:e.getUint32(2,!1),bits:e.getInt16(6,!1),sampleRate:n,type:t?M(e,18):`NONE`}}async function se(e){let t=await j(e,0,12),n=M(t,8);if(M(t)!==`FORM`||n!==`AIFF`&&n!==`AIFC`)throw k(`aiff`,`missing FORM header`);let r=n===`AIFC`,i,a,o=12;for(let t=0;o+8<=e.size;t+=1){if(t>=1024)throw k(`aiff`,`too many chunks`);let n=await j(e,o,8),s=M(n),c=n.getUint32(4,!1),l=o+8,u=e.size-l;if(s===`COMM`){if(c>u)throw k(`aiff`,`truncated COMM chunk`);i=oe(await j(e,l,Math.min(c,64)),r)}else if(s===`SSND`){let t=await j(e,l,8);if(c<8||t.byteLength<8)throw k(`aiff`,`truncated SSND chunk`);let n=l+8+t.getUint32(0,!1),r=Math.min(l+c,e.size);if(n>r)throw k(`aiff`,`sound data offset past the chunk`);a={offset:n,size:r-n}}if(i&&a)break;o=l+c+c%2}if(!i)throw k(`aiff`,`missing COMM chunk`);if(!a)throw k(`aiff`,`missing SSND chunk`);let s=ie[i.type];if(!s)throw A(`aiff`,i.type||`unknown`);let c=s.bits??i.bits;if(c<1||c>64)throw k(`aiff`,`sample size out of range`);if(s.encoding===`float`&&c!==32&&c!==64)throw A(`aiff`,`${c}-bit float`);if(s.encoding===`int`&&c>32)throw A(`aiff`,`${c}-bit integer`);let l=Math.ceil(c/8),u=re({container:`aiff`,sampleRate:i.sampleRate,channels:i.channels,encoding:s.encoding,bytesPerSample:l,littleEndian:s.littleEndian,dataOffset:a.offset,blockAlign:i.channels*l,frames:i.frames});return u.frames*u.blockAlign>a.size?{...u,frames:Math.floor(a.size/u.blockAlign),declaredFrames:u.frames}:u}function ce(e,t,n){let{channels:r,bytesPerSample:i,blockAlign:a,encoding:o,littleEndian:s}=t;if(e.byteLength<n*a)throw RangeError(`Expected ${n*a} bytes, got ${e.byteLength}.`);let c=Array.from({length:r},()=>new Float32Array(n)),l=le(o,i,s);for(let t=0;t<r;t+=1){let r=c[t],o=t*i;for(let t=0;t<n;t+=1)r[t]=l(e,o),o+=a}return c}function le(e,t,n){if(e===`float`)return t===8?(e,t)=>ue(Math.fround(e.getFloat64(t,n))):(e,t)=>ue(e.getFloat32(t,n));if(e===`uint`)return(e,t)=>(e.getUint8(t)-128)/128;switch(t){case 1:return(e,t)=>e.getInt8(t)/128;case 2:return(e,t)=>e.getInt16(t,n)/32768;case 3:return(e,t)=>{let r=e.getUint8(t),i=e.getUint8(t+1),a=e.getUint8(t+2);return((n?r|i<<8|a<<16:r<<16|i<<8|a)<<8>>8)/8388608};default:return(e,t)=>e.getInt32(t,n)/2147483648}}function ue(e){return Number.isFinite(e)?e:0}var de=1,fe=3,pe=65534,me=[0,0,0,0,16,0,128,0,0,170,0,56,155,113],he=4294967295;async function ge(e,t){let n=await j(e,t,8);if(n.byteLength<8)return!1;for(let e=0;e<4;e+=1){let t=n.getUint8(e);if(t<32||t>126)return!1}return n.getUint32(4,!0)<=e.size-t-8}function _e(e){if(e.byteLength<16)throw k(`wav`,`truncated fmt chunk`);let t=e.getUint16(0,!0),n={channels:e.getUint16(2,!0),sampleRate:e.getUint32(4,!0),blockAlign:e.getUint16(12,!0),bitsPerSample:e.getUint16(14,!0)};if(t===pe){if(e.byteLength<40)throw k(`wav`,`truncated extensible fmt chunk`);t=e.getUint16(24,!0);for(let[t,n]of me.entries())if(e.getUint8(26+t)!==n)throw A(`wav`,`extensible subformat`)}return{tag:t,...n}}function ve(e,t,n,r){let{tag:i,channels:a,sampleRate:o,blockAlign:s,bitsPerSample:c}=e;if(c%8!=0)throw k(`wav`,`sample size isn't whole bytes`);let l=c/8,u;if(i===de&&[1,2,3,4].includes(l))u=l===1?`uint`:`int`;else if(i===fe&&[4,8].includes(l))u=`float`;else throw A(`wav`,`format ${i} at ${c} bits`);if(s<1)throw k(`wav`,`frame size is zero`);return re({container:`wav`,sampleRate:o,channels:a,encoding:u,bytesPerSample:l,littleEndian:!0,dataOffset:t,blockAlign:s,frames:Math.floor(n/s),...r===void 0?{}:{declaredFrames:Math.floor(r/s)}})}async function ye(e){let t=await j(e,0,12),n=M(t);if(n!==`RIFF`&&n!==`RF64`||M(t,8)!==`WAVE`)throw k(`wav`,`missing RIFF header`);let r,i,a,o=12;for(let t=0;o+8<=e.size;t+=1){if(t>=1024)throw k(`wav`,`too many chunks`);let s=await j(e,o,8),c=M(s),l=s.getUint32(4,!0),u=o+8,d=e.size-u;if(c===`ds64`&&n===`RF64`){let t=await j(e,u,16);if(t.byteLength<16)throw k(`wav`,`truncated ds64 chunk`);let n=t.getUint32(12,!0);if(n>=2**21)throw k(`wav`,`data size out of range`);a=n*2**32+t.getUint32(8,!0)}else if(c===`fmt `){if(l>d)throw k(`wav`,`truncated fmt chunk`);r=_e(await j(e,u,Math.min(l,64)))}else if(c===`data`){let t=l;if(n===`RF64`&&l===he){if(a===void 0)throw k(`wav`,`RF64 file without ds64 chunk`);t=a}else(l===he||l===0&&!await ge(e,u))&&(t=d);if(i={offset:u,size:Math.min(t,d),declared:t>d?t:void 0},r)break;o=u+t+t%2;continue}if(r&&i)break;o=u+l+l%2}if(!r)throw k(`wav`,`missing fmt chunk`);if(!i)throw k(`wav`,`missing data chunk`);return ve(r,i.offset,i.size,i.declared)}async function be(e){let t=await j(e,0,12),n=M(t),r=M(t,8),i;if((n===`RIFF`||n===`RF64`)&&r===`WAVE`)i=await ye(e);else if(n===`FORM`&&(r===`AIFF`||r===`AIFC`))i=await se(e);else throw new O(`UNSUPPORTED_FORMAT`,`The file's container isn't recognised.`,{details:{container:`unknown`}});if(i.frames===0)throw k(i.container,`no audio frames`);return{layout:i,probe:{container:i.container,codec:`pcm`,sampleRate:i.sampleRate,channels:i.channels,frameBound:i.frames,expectedFrames:i.frames,...i.declaredFrames===void 0?{}:{declaredFrames:i.declaredFrames},frameTolerance:0}}}async function xe(e,t,n,r){if(!Number.isSafeInteger(n)||!Number.isSafeInteger(r)||n<0||r<0||n+r>t.frames)throw RangeError(`Frames ${n} to ${n+r} are outside the file.`);let i=r*t.blockAlign,a=await j(e,t.dataOffset+n*t.blockAlign,i);if(a.byteLength<i)throw k(t.container,`file shorter than probed`);return ce(a,t,r)}function Se(e,t){let n=[],r=[];for(let i of e){let e=Math.ceil(i.length/t),a=new Float32Array(e),o=new Float32Array(e);for(let n=0;n<e;n+=1){let e=Math.min(i.length,(n+1)*t),r=1/0,s=-1/0;for(let a=n*t;a<e;a+=1){let e=i[a];e<r&&(r=e),e>s&&(s=e)}a[n]=r,o[n]=s}n.push(a),r.push(o)}return{min:n,max:r}}var N=1<<20;async function Ce(e,t,n,r,i,a){let o=t;for(let s=t;s<e.size;s+=N){let t=await e.bytes(s,N+n),c=Math.min(N,e.size-s);for(let e=0;e<c;e+=1){if(t[e]!==255)continue;let n=r(t,e);if(n===void 0)continue;let c=s+e,l=c>=o;l&&(o=c+Math.max(1,i(n))),a(n,l)}}}async function P(e,t,n,r,i,a,o=3){let s=await e.bytes(t,n+65536);for(let c=0;c<Math.min(n,s.length);c+=1){if(s[c]!==255)continue;let n=r(s,c);if(n===void 0)continue;let l=c,u=n;for(let d=1;;d+=1){if(d===o)return{offset:t+c,first:n};let f=l+i(u);if(f===s.length&&t+s.length===e.size)return{offset:t+c,first:n};let p=r(s,f);if(p===void 0||!a(n,p))break;l=f,u=p}}}var we=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];function Te(e,t){let n=0,r=0,i=0,a=a=>{let o=0;for(let s=0;s<a;s+=1){if(n===0){if(i>=e.length)throw k(t,`truncated AudioSpecificConfig`);r=e[i],i+=1,n=8}--n,o=o*2+(r>>n&1)}return o};a(5)===31&&a(6);let o=a(4),s=o===15?a(24):we[o];if(s===void 0||s===0)throw k(t,`AAC sample rate out of range`);return{coreRate:s,channelConfiguration:a(4)}}function F(e){return e===0||e===7?8:Math.max(2,e)}function I(e){return e<=24e3?e*2:e}function L(e,t){let n=n=>e[t+n],r=n(1),i=n(2),a=n(3),o=n(4),s=n(5),c=n(6);if(n(0)!==255||r===void 0||i===void 0||a===void 0||o===void 0||s===void 0||c===void 0||(r&246)!=240)return;let l=we[i>>2&15];if(l===void 0)return;let u=(i&1)<<2|a>>6,d=(a&3)<<11|o<<3|s>>5;if(!(d<(r&1?7:9)))return{sampleRate:l,channelConfiguration:u,blocks:(c&3)+1,frameLength:d}}var Ee=(e,t)=>e.sampleRate===t.sampleRate&&e.channelConfiguration===t.channelConfiguration;async function De(e,t){return P(s(e),t,65536,L,e=>e.frameLength,Ee)}async function Oe(e,t){let n=s(e),r=await P(n,t,65536,L,e=>e.frameLength,Ee);if(!r)throw k(`adts`,`no frames`);let i=r.first.sampleRate,a=I(i),o=F(r.first.channelConfiguration),c=1024*Math.ceil(a/i),l=0,u=0;if(await Ce(n,r.offset,7,L,e=>e.frameLength,(e,t)=>{let n=Math.max(1,Math.ceil(a/e.sampleRate)),r=Math.ceil(F(e.channelConfiguration)/o);l+=e.blocks*1024*n*r,t&&(u+=e.blocks)}),l===0)throw k(`adts`,`no frames`);return{container:`adts`,codec:`aac`,sampleRate:a,channels:o,frameBound:l,expectedFrames:Math.min(u*c,l),frameTolerance:2*c}}function R(e,t){let n=2**(e-1),r=2**e-1,i=/* @__PURE__ */ new Uint32Array(256);for(let a=0;a<256;a+=1){let o=a*2**(e-8);for(let e=0;e<8;e+=1)o=o>=n?(o*2^t)&r:o*2&r,o>>>=0;i[a]=o>>>0}return i}var ke=R(8,7);R(16,32773),R(32,79764919);function Ae(e,t=0,n=e.length){let r=0;for(let i=t;i<n;i+=1)r=ke[r^e[i]];return r}function z(e,t){if(e.length<34)throw k(t,`truncated STREAMINFO`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint16(0),i=n.getUint16(2),a=n.getUint32(10),o=a>>>12,s=(a>>>9&7)+1,c=(a>>>4&31)+1,l=(a&15)*2**32+n.getUint32(14);if(r<16||i<r)throw k(t,`block sizes out of range`);if(o===0)throw k(t,`sample rate is zero`);if(c<4)throw k(t,`sample size out of range`);return{minBlockSize:r,maxBlockSize:i,sampleRate:o,channels:s,bitsPerSample:c,totalFrames:l}}var je=[void 0,88200,176400,192e3,8e3,16e3,22050,24e3,32e3,44100,48e3,96e3];function B(e,t){let n=n=>e[t+n];if(n(0)!==255||((n(1)??0)&254)!=248)return;let r=n(2),i=n(3);if(r===void 0||i===void 0)return;let a=r>>4,o=r&15,s=i>>4,c=i>>1&7;if(a===0||o===15||s>10||c===3||i&1)return;let l=4,u=n(l);if(u===void 0)return;let d;if(u<128)d=0;else if(u>=192&&u<224)d=1;else if(u>=224&&u<240)d=2;else if(u>=240&&u<248)d=3;else if(u>=248&&u<252)d=4;else if(u>=252&&u<254)d=5;else if(u===254)d=6;else return;l+=1;for(let e=0;e<d;e+=1,l+=1){let e=n(l);if(e===void 0||(e&192)!=128)return}let f;if(a===1)f=192;else if(a<=5)f=576*2**(a-2);else if(a===6||a===7){let e=n(l);if(e===void 0)return;if(a===6)f=e+1,l+=1;else{let t=n(l+1);if(t===void 0)return;f=e*256+t+1,l+=2}}else f=256*2**(a-8);let p=je[o];if(o>=12){let e=n(l);if(e===void 0)return;if(o===12)p=e*1e3,l+=1;else{let t=n(l+1);if(t===void 0)return;p=o===13?e*256+t:(e*256+t)*10,l+=2}if(p===0)return}let m=n(l);if(m!==void 0&&Ae(e,t,t+l)===m)return{blockSize:f,sampleRate:p,channels:s<8?s+1:2,length:l+1}}function Me(e){if(e.length<10||e[0]!==73||e[1]!==68||e[2]!==51)return 0;let t=0;for(let n=6;n<10;n+=1){let r=e[n];if(r&128)return 0;t=t*128+r}let n=e[5]&16?10:0;return 10+t+n}var V=1<<20;function Ne(e,t){let n=e.sampleRate!==void 0&&e.sampleRate<t.sampleRate?Math.ceil(t.sampleRate/e.sampleRate):1,r=Math.ceil(e.channels/t.channels);return e.blockSize*n*r}async function Pe(e){let t=s(e),n=Me(await t.bytes(0,10)),r=await t.bytes(n,4);if(String.fromCharCode(...r)!==`fLaC`)throw k(`flac`,`missing fLaC marker`);n+=4;let i;for(let e=0;;e+=1){if(e>=1024)throw k(`flac`,`too many metadata blocks`);let r=await t.bytes(n,4);if(r.length<4)throw k(`flac`,`truncated metadata`);let a=!!(r[0]&128),o=r[0]&127,s=r[1]<<16|r[2]<<8|r[3];if(o===127)throw k(`flac`,`invalid metadata block type`);if(e===0){if(o!==0||s!==34)throw k(`flac`,`STREAMINFO isn't first`);i=z(await t.bytes(n+4,34),`flac`)}if(n+=4+s,n>t.size)throw k(`flac`,`metadata exceeds the file`);if(a)break}if(!i)throw k(`flac`,`missing STREAMINFO`);let a=0,o=0;for(let e=n;e<t.size;e+=V){let n=await t.bytes(e,V+16),r=Math.min(V,t.size-e);for(let e=0;e<r;e+=1){if(n[e]!==255)continue;let t=B(n,e);t&&(a+=Ne(t,i),o+=1)}}if(o===0)throw k(`flac`,`no audio frames`);if(i.totalFrames>a)throw k(`flac`,`STREAMINFO claims more than the frames carry`);return{container:`flac`,codec:`flac`,sampleRate:i.sampleRate,channels:i.channels,frameBound:a,expectedFrames:i.totalFrames>0?i.totalFrames:a,frameTolerance:i.maxBlockSize}}var H=27,Fe=65307,Ie=-1;async function U(e,t){let n=s(e),r,i=Ie,a=[],o=0,c=0,l=0;for(;c+H<=n.size;){let e=await n.bytes(c,Fe);if(e[0]!==79||e[1]!==103||e[2]!==103||e[3]!==83){if(l===0)throw k(`ogg`,`missing first page`);c+=1;continue}let s=new DataView(e.buffer,e.byteOffset,e.byteLength),u=s.getUint8(4),d=s.getUint8(5),f=s.getUint8(26);if(u!==0||e.length<H+f){if(l===0)throw k(`ogg`,`malformed first page`);c+=1;continue}let p=0;for(let t=0;t<f;t+=1)p+=e[H+t];let m=H+f+p;if(m>e.length)break;let h=s.getUint32(14,!0),g=!!(d&2);if(r===void 0){if(!g)throw k(`ogg`,`first page doesn't begin a stream`);r=h}else if(h!==r){if(g)throw new O(`UNSUPPORTED_FORMAT`,`Ogg files with several streams aren't supported.`,{details:{container:`ogg`,reason:`multiplexed streams`}});c+=m,l+=1;continue}d&1||(a=[],o=0);let _=H+f;for(let n=0;n<f;n+=1){let r=e[H+n];if(a.length<64){let t=Math.min(r,64-a.length);for(let n=0;n<t;n+=1)a.push(e[_+n])}o+=r,_+=r,r<255&&(t({head:Uint8Array.from(a),length:o}),a=[],o=0)}let v=s.getInt32(10,!0),y=s.getUint32(6,!0);(v!==-1||y!==4294967295)&&(i=v*2**32+y),c+=m,l+=1}if(l===0)throw k(`ogg`,`missing first page`);return{lastGranule:i}}var Le=13;function Re(e){return e[0]===127&&e[1]===70&&e[2]===76&&e[3]===65&&e[4]===67}async function ze(e){let t,n=0,r=0,i=0,a=0,{lastGranule:o}=await U(e,({head:e})=>{if(n+=1,n===1){if(!Re(e)||e[5]!==1)throw k(`ogg`,`not a FLAC mapping version 1`);let n=String.fromCharCode(...e.subarray(9,13)),i=(e[Le]??127)&127;if(n!==`fLaC`||i!==0)throw k(`ogg`,`missing FLAC STREAMINFO`);t=z(e.subarray(17,51),`ogg`),r=(e[7]??0)<<8|(e[8]??0);return}if(!t)return;let o=e[0]===255&&((e[1]??0)&254)==248;if(n-1<=r||r===0&&!o&&a===0)return;a+=1;let s=B(e,0);if(!s)i+=t.maxBlockSize;else{if(s.channels!==t.channels)throw k(`ogg`,`a frame's channel count differs from STREAMINFO`);if(s.sampleRate!==void 0&&s.sampleRate!==t.sampleRate)throw k(`ogg`,`a frame's sample rate differs from STREAMINFO`);i+=s.blockSize}});if(!t)throw k(`ogg`,`missing FLAC header`);if(a===0)throw k(`ogg`,`no audio frames`);if(t.totalFrames>i||o>i)throw k(`ogg`,`a declared length exceeds the frames`);let s=o>0?o:t.totalFrames;return{container:`ogg`,codec:`flac`,sampleRate:t.sampleRate,channels:t.channels,frameBound:i,expectedFrames:s>0?s:i,frameTolerance:t.maxBlockSize}}var Be=48e3,W=5760;function Ve(e){return String.fromCharCode(...e.subarray(0,8))===`OpusHead`}function He(e){return e<12?[480,960,1920,2880][e%4]:e<16?[480,960][e%2]:[120,240,480,960][e%4]}function Ue(e,t){let n=e[0];if(t===0||n===void 0)return W;let r=He(n>>3),i=n&3,a;if(i===0)a=1;else if(i===1||i===2)a=2;else{let t=e[1];if(t===void 0)return W;a=t&63}let o=a*r;return o===0||o>5760?W:o}function We(e,t){if(!Ve(e)||e.length<19)throw k(t,`malformed OpusHead`);if(e[8]&240)throw k(t,`unsupported OpusHead version`);let n=e[9],r=e[10]|e[11]<<8,i=e[18];if(n===0)throw k(t,`no channels`);if(i===0?n>2:i!==1||n>8)throw new O(`UNSUPPORTED_FORMAT`,`Unsupported Opus channel mapping.`,{details:{container:t,codec:`opus`,reason:`channel mapping family ${i}`}});return{channels:n,preSkip:r}}async function Ge(e){let t=0,n=0,r=0,i=0,{lastGranule:a}=await U(e,({head:e,length:a})=>{if(r+=1,r===1)({channels:t,preSkip:n}=We(e,`ogg`));else if(r===2){if(String.fromCharCode(...e.subarray(0,8))!==`OpusTags`)throw k(`ogg`,`missing OpusTags`)}else i+=Ue(e,a)});if(r<2)throw k(`ogg`,`missing Opus headers`);if(i===0)throw k(`ogg`,`no audio packets`);if(a>i)throw k(`ogg`,`a declared length exceeds the packets`);let o=a>0?Math.max(0,a-n):i;return{container:`ogg`,codec:`opus`,sampleRate:Be,channels:t,frameBound:i,expectedFrames:o,frameTolerance:Math.max(W,n)}}var Ke=`vorbis`;function qe(e){return e[0]===1&&String.fromCharCode(...e.subarray(1,7))===Ke}function Je(e,t){if(!qe(e)||e.length<30)throw k(t,`malformed Vorbis header`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint32(7,!0)!==0)throw k(t,`unsupported Vorbis version`);let r=n.getUint8(11),i=n.getUint32(12,!0),a=n.getUint8(28),o=a&15,s=a>>4;if(o<6||s>13||o>s||(n.getUint8(29)&1)!=1)throw k(t,`Vorbis block sizes out of range`);if(r===0||i===0)throw k(t,`Vorbis format out of range`);return{channels:r,sampleRate:i,largeBlock:2**s}}async function Ye(e){let t=0,n=0,r=0,i=0,a=0,{lastGranule:o}=await U(e,({head:e})=>{if(i+=1,i===1)({channels:t,sampleRate:n,largeBlock:r}=Je(e,`ogg`));else if(i===2||i===3){let t=i===2?3:5;if(e[0]!==t||String.fromCharCode(...e.subarray(1,7))!==Ke)throw k(`ogg`,`missing Vorbis comment or setup header`)}else a+=1});if(i<3)throw k(`ogg`,`missing Vorbis headers`);if(a===0)throw k(`ogg`,`no audio packets`);let s=r/2*a;if(o>s)throw k(`ogg`,`a declared length exceeds the packets`);return{container:`ogg`,codec:`vorbis`,sampleRate:n,channels:t,frameBound:s,expectedFrames:o>0?o:s,frameTolerance:r}}var G=440786851,Xe=17026,Ze=408125543,Qe=357149030,$e=2807729,et=17545,tt=374648427,nt=174,rt=215,it=131,at=134,ot=25506,st=524531317,ct=163,lt=160,ut=161,dt=/* @__PURE__ */ new Set([st,475249515,307544935,272869232,423732329,290298740,Qe,tt,G]);function K(e,t){return new O(`UNSUPPORTED_FORMAT`,`Unsupported Matroska: ${e}.`,{details:t===void 0?{container:`webm`,reason:e}:{container:`webm`,codec:t,reason:e}})}function ft(e,t){let n=e[t];if(n===void 0||n===0)return;let r=Math.clz32(n)-23;if(r>4||t+r>e.length)return;let i=0;for(let n=0;n<r;n+=1)i=i*256+e[t+n];return{id:i,length:r}}function q(e,t){let n=e[t];if(n===void 0||n===0)return;let r=Math.clz32(n)-23;if(t+r>e.length)return;let i=n&255>>r,a=i===255>>r;for(let n=1;n<r;n+=1){let r=e[t+n];i=i*256+r,r!==255&&(a=!1)}return{value:i,length:r,unknown:a}}async function J(e,t){let n=await e.bytes(t,12),r=ft(n,0);if(!r)return;let i=q(n,r.length);if(i){if(!i.unknown&&!Number.isSafeInteger(i.value))throw k(`webm`,`element size out of range`);return{id:r.id,body:t+r.length+i.length,size:i.unknown?void 0:i.value}}}function Y(e){let t=[],n=0;for(;n<e.length;){let r=ft(e,n),i=r&&q(e,n+r.length);if(!r||!i||i.unknown)throw k(`webm`,`malformed element`);let a=n+r.length+i.length;if(a+i.value>e.length)throw k(`webm`,`element exceeds its parent`);t.push({id:r.id,data:e.subarray(a,a+i.value)}),n=a+i.value}return t}var X=e=>e.reduce((e,t)=>e*256+t,0);function pt(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return e.length===4?t.getFloat32(0):e.length===8?t.getFloat64(0):NaN}function mt(e,t){if(e===`A_OPUS`){if(!t)throw k(`webm`,`missing OpusHead`);let e=We(t,`webm`);return{codec:`opus`,sampleRate:Be,channels:e.channels,tolerance:Math.max(W,e.preSkip),frameSamples:Ue}}if(e===`A_VORBIS`){if(t?.[0]!==2)throw k(`webm`,`malformed Vorbis headers`);let e=1;for(let n=0;n<2;n+=1){for(;t[e]===255;)e+=1;if(t[e]===void 0)throw k(`webm`,`malformed Vorbis headers`);e+=1}let n=Je(t.subarray(e),`webm`),r=n.largeBlock/2;return{codec:`vorbis`,sampleRate:n.sampleRate,channels:n.channels,tolerance:n.largeBlock,frameSamples:()=>r}}if(e===`A_FLAC`){let e=t&&String.fromCharCode(...t.subarray(0,4));if(!t||e!==`fLaC`||(t[4]??127)&127)throw k(`webm`,`missing FLAC STREAMINFO`);let n=z(t.subarray(8,42),`webm`);return{codec:`flac`,sampleRate:n.sampleRate,channels:n.channels,tolerance:n.maxBlockSize,frameSamples(e){let t=B(e,0);if(!t)return n.maxBlockSize;if(t.channels!==n.channels)throw k(`webm`,`a frame's channel count differs from STREAMINFO`);if(t.sampleRate!==void 0&&t.sampleRate!==n.sampleRate)throw k(`webm`,`a frame's sample rate differs from STREAMINFO`);return t.blockSize}}}if(e.startsWith(`A_AAC`)){if(!t)throw K(`AAC without an AudioSpecificConfig`,`aac`);let e=Te(t,`webm`),n=I(e.coreRate),r=1024*Math.ceil(n/e.coreRate);return{codec:`aac`,sampleRate:n,channels:F(e.channelConfiguration),tolerance:2*r,frameSamples:()=>r}}throw K(`codec ${e}`,e)}function ht(e){let t=[];for(let n of Y(e)){if(n.id!==nt)continue;let e=Y(n.data),r=t=>e.find(e=>e.id===t)?.data,i=r(it);if(!i||X(i)!==2)continue;let a=r(rt),o=r(at);if(!a||!o)throw k(`webm`,`incomplete audio track`);let s=String.fromCharCode(...o).replace(/\0+$/,``);t.push({number:X(a),codec:mt(s,r(ot))})}if(t.length===0)throw k(`webm`,`no audio track`);if(t.length>1)throw K(`several audio tracks`);return t[0]}function gt(e,t){let n=q(e,0);if(!n||n.unknown)throw k(`webm`,`malformed block`);if(n.value!==t.number)return 0;let r=n.length+2,i=e[r];if(i===void 0)throw k(`webm`,`truncated block`);r+=1;let a=i>>1&3,o=[];if(a===0)o.push(e.length-r);else{let t=e[r];if(t===void 0)throw k(`webm`,`truncated block`);let n=t+1;if(r+=1,a===1)for(let t=0;t<n-1;t+=1){let t=0;for(;;){let n=e[r];if(n===void 0)throw k(`webm`,`truncated lacing`);if(r+=1,t+=n,n<255)break}o.push(t)}else if(a===3){let t=q(e,r);if(!t||t.unknown)throw k(`webm`,`malformed lacing`);r+=t.length,o.push(t.value);for(let t=1;t<n-1;t+=1){let n=q(e,r);if(!n||n.unknown)throw k(`webm`,`malformed lacing`);r+=n.length;let i=2**(7*n.length-1)-1;o.push(o[t-1]+n.value-i)}}let i=e.length-r;if(a===2){if(i%n!==0)throw k(`webm`,`fixed lacing doesn't divide the block`);for(let e=0;e<n;e+=1)o.push(i/n)}else{let e=o.reduce((e,t)=>e+t,0);o.push(i-e)}}if(o.some(e=>e<0)||r+o.reduce((e,t)=>e+t,0)>e.length)throw k(`webm`,`lacing exceeds the block`);let s=0;for(let n of o)s+=t.codec.frameSamples(e.subarray(r,r+Math.min(n,16)),n),r+=n;return s}async function _t(e){let t=s(e),n=await J(t,0);if(!n||n.id!==G||n.size===void 0)throw k(`webm`,`missing EBML header`);let r=Y(await t.bytes(n.body,n.size)).find(e=>e.id===Xe),i=r?String.fromCharCode(...r.data).replace(/\0+$/,``):``;if(i!==`webm`&&i!==`matroska`)throw K(`document type ${i||`missing`}`);let a=await J(t,n.body+n.size);if(!a||a.id!==Ze)throw k(`webm`,`missing Segment`);let o=Math.min(t.size,a.body+(a.size??t.size)),c,l=1e6,u,d=0,f=0,p,m=a.body;for(;m<o;){let e=await J(t,m);if(!e)throw k(`webm`,`malformed element`);if(p!==void 0&&(m>=p||dt.has(e.id))&&(p=void 0),p===void 0){if(e.id===G)throw K(`several segments`);if(e.id===st){if(!c)throw k(`webm`,`clusters before the tracks`);if(p=e.size===void 0?1/0:e.body+e.size,p!==1/0&&p>o)throw k(`webm`,`element exceeds its parent`);m=e.body;continue}if(e.size===void 0)throw k(`webm`,`unknown size outside a Segment or Cluster`);let n=e.body+e.size;if(n>o)throw k(`webm`,`element exceeds its parent`);if(e.id===Qe){let n=Y(await t.bytes(e.body,e.size)),r=n.find(e=>e.id===$e),i=n.find(e=>e.id===et);r&&(l=X(r.data)),i&&(u=pt(i.data))}else if(e.id===tt){if(c)throw K(`several Tracks elements`);c=ht(await t.bytes(e.body,e.size))}m=n;continue}if(e.size===void 0)throw k(`webm`,`unknown size inside a Cluster`);let n=e.body+e.size;if(n>Math.min(p,o))throw k(`webm`,`element exceeds its parent`);let r=c;if(e.id===ct)d+=gt(await t.bytes(e.body,e.size),r),f+=1;else if(e.id===lt)for(let n of Y(await t.bytes(e.body,e.size)))n.id===ut&&(d+=gt(n.data,r),f+=1);m=n}if(!c)throw k(`webm`,`missing Tracks`);if(f===0||d===0)throw k(`webm`,`no audio blocks`);let{codec:h}=c,g=d;if(u!==void 0){if(!Number.isFinite(u)||u<0)throw k(`webm`,`Duration out of range`);if(g=Math.round(u*l/1e9*h.sampleRate),g>d)throw k(`webm`,`the Duration claims more than the blocks carry`)}return{container:`webm`,codec:h.codec,sampleRate:h.sampleRate,channels:h.channels,frameBound:d,expectedFrames:g,frameTolerance:h.tolerance}}var vt=1e5;function Z(e,t){return new O(`UNSUPPORTED_FORMAT`,`Unsupported MP4: ${e}.`,{details:t===void 0?{container:`mp4`,reason:e}:{container:`mp4`,codec:t,reason:e}})}var yt=class{boxes=0;reader;constructor(e){this.reader=e}async u8(e){let t=await this.reader.bytes(e,1);if(t.length<1)throw k(`mp4`,`truncated box`);return t[0]}async view(e,t){let n=await this.reader.bytes(e,t);if(n.length<t)throw k(`mp4`,`truncated box`);return new DataView(n.buffer,n.byteOffset,n.byteLength)}async children(e,t,n=!1){let r=[],i=e;for(;i+8<=t;){if(this.boxes+=1,this.boxes>vt)throw k(`mp4`,`too many boxes`);let e=await this.view(i,8),a=e.getUint32(0),o=String.fromCharCode(e.getUint8(4),e.getUint8(5),e.getUint8(6),e.getUint8(7)),s=8;if(a===1){let e=await this.view(i+8,8),t=e.getUint32(0);if(t>=2**21)throw k(`mp4`,`box size out of range`);a=t*2**32+e.getUint32(4),s=16}else if(a===0){if(!n)throw k(`mp4`,`open-ended box inside another`);a=t-i}if(a<s||i+a>t)throw k(`mp4`,`box exceeds its parent`);r.push({type:o,body:i+s,end:i+a}),i+=a}return r}async child(e,t){return(await this.children(e.body,e.end)).find(e=>e.type===t)}async need(e,t){let n=await this.child(e,t);if(!n)throw k(`mp4`,`missing ${t} box`);return n}};async function bt(e,t){let n=0;for(let r=0;r<4;r+=1){let i=await e.u8(t+r);if(n=n*128+(i&127),!(i&128))return[n,r+1]}throw k(`mp4`,`malformed descriptor length`)}async function xt(e,t){let n=t.body+4,r=async r=>{if(await e.u8(n)!==r)throw Z(`unexpected ES descriptor`);let[i,a]=await bt(e,n+1);if(n+=1+a,n+i>t.end)throw k(`mp4`,`descriptor exceeds its box`)};await r(3);let i=await e.u8(n+2);n+=3,i&128&&(n+=2),i&64&&(n+=1+await e.u8(n)),i&32&&(n+=2),await r(4);let a=await e.u8(n);if(![64,102,103,104].includes(a))throw Z(`object type ${a}`,a===107||a===105?`mp3`:`unknown`);return n+=13,await r(5),Te(await e.reader.bytes(n,Math.min(5,t.end-n)),`mp4`)}async function St(e){let t=s(e),n=new yt(t),r=await n.children(0,t.size,!0);if(r.some(e=>e.type===`moof`))throw Z(`fragmented MP4`);let i=r.find(e=>e.type===`moov`);if(!i)throw k(`mp4`,`missing moov box`);let a=[];for(let e of(await n.children(i.body,i.end)).filter(e=>e.type===`trak`)){let t=await n.child(e,`mdia`),r=t&&await n.child(t,`hdlr`);t&&r&&(await n.view(r.body+8,4)).getUint32(0)===1936684398&&a.push({trak:e,mdia:t})}if(a.length===0)throw k(`mp4`,`no audio track`);if(a.length>1)throw Z(`several audio tracks`);let{trak:o,mdia:c}=a[0],l=await n.need(c,`mdhd`),u=await n.u8(l.body),d=await n.view(l.body+4,u===1?28:16),f=d.getUint32(u===1?16:8),p=u===1?d.getUint32(20)*2**32+d.getUint32(24):d.getUint32(12);if(f===0)throw k(`mp4`,`timescale is zero`);let m=await n.need(await n.need(c,`minf`),`stbl`),h=await n.need(m,`stsd`),[g]=await n.children(h.body+8,h.end);if(!g)throw k(`mp4`,`empty sample description`);let _=await n.view(g.body,28),v=_.getUint16(8);if(v>1)throw Z(`sound sample entry version 2`);let y=_.getUint16(16),b=_.getUint32(24)>>>16,x=g.body+28+(v===1?16:0),S,C,w,T;if(g.type===`mp4a`){let e=(await n.children(x,g.end)).find(e=>e.type===`esds`);if(!e)throw k(`mp4`,`missing esds box`);let{coreRate:t,channelConfiguration:r}=await xt(n,e);S=`aac`,C=I(t),w=F(r||y),T=1024*Math.ceil(C/t)}else if(g.type===`alac`){let e=(await n.children(x,g.end)).find(e=>e.type===`alac`);if(!e)throw k(`mp4`,`missing ALAC configuration`);let t=await n.view(e.body+4,24);if(S=`alac`,T=t.getUint32(0),w=t.getUint8(9),C=t.getUint32(20)||b,T===0||T>1<<20)throw k(`mp4`,`ALAC frame length out of range`);if(w===0||C===0)throw k(`mp4`,`ALAC format out of range`)}else throw Z(`codec ${g.type}`,g.type);await Ct(n,i,o,{timescale:f,duration:p,decodeRate:C,tolerance:2*T});let E=await wt(n,m,t.size);if(E===0)throw k(`mp4`,`no audio samples`);let D=E*T,ee=p===0?D:Math.round(p*C/f);if(ee>D)throw k(`mp4`,`the duration claims more than the samples carry`);return{container:`mp4`,codec:S,sampleRate:C,channels:w,frameBound:D,expectedFrames:ee,frameTolerance:2*T}}async function Ct(e,t,n,r){let i=(await e.children(n.body,n.end)).filter(e=>e.type===`edts`);if(i.length===0)return;if(i.length>1)throw Z(`several edit lists`);let a=(await e.children(i[0].body,i[0].end)).filter(e=>e.type===`elst`);if(a.length===0)return;if(a.length>1)throw Z(`several edit lists`);let o=a[0],s=await e.need(t,`mvhd`),c=await e.u8(s.body),l=(await e.view(s.body+(c===1?20:12),4)).getUint32(0);if(l===0)throw k(`mp4`,`movie timescale is zero`);let u=await e.u8(o.body),d=(await e.view(o.body+4,4)).getUint32(0),f=u===1?20:12;if(o.body+8+d*f>o.end)throw k(`mp4`,`edit list exceeds its box`);if(d>2)throw Z(`edit list with more than two edits`);let p=!1;for(let t=0;t<d;t+=1){let n=await e.view(o.body+8+t*f,f),i=u===1?n.getUint32(0)*2**32+n.getUint32(4):n.getUint32(0),a=u===1?n.getInt32(8)*2**32+n.getUint32(12):n.getInt32(4),s=n.getInt16(u===1?16:8),c=n.getUint16(u===1?18:10);if(a===-1){if(p||t>0)throw Z(`edit list with an empty edit after another edit`);if(i*r.decodeRate/l>r.tolerance)throw Z(`edit list with a long empty edit`)}else{if(p)throw Z(`edit list with several media edits`);if(p=!0,s!==1||c!==0)throw Z(`edit list with a media rate other than 1`);if(a<0||r.duration===0||a+Math.ceil(i*r.timescale/l)>r.duration)throw Z(`edit list beyond the media`)}}}async function wt(e,t,n){let r=await e.child(t,`stsz`);if(!r)throw await e.child(t,`stz2`)?Z(`compact sample sizes`):k(`mp4`,`missing stsz box`);let i=await e.view(r.body+4,8),a=i.getUint32(0),o=i.getUint32(4);if(a===0&&r.body+12+o*4>r.end)throw k(`mp4`,`stsz table exceeds its box`);let s=await e.need(t,`stsc`),c=(await e.view(s.body+4,4)).getUint32(0);if(s.body+8+c*12>s.end)throw k(`mp4`,`stsc table exceeds its box`);let l=await e.child(t,`stco`)??await e.child(t,`co64`);if(!l)throw k(`mp4`,`missing chunk offsets`);let u=l.type===`co64`,d=(await e.view(l.body+4,4)).getUint32(0);if(l.body+8+d*(u?8:4)>l.end)throw k(`mp4`,`chunk offsets exceed their box`);let f=0,p=0,m=0;for(let t=1;t<=d;t+=1){for(;p<c;){let n=await e.view(s.body+8+p*12,12);if(n.getUint32(0)>t)break;m=n.getUint32(4),p+=1}let i=await e.view(l.body+8+(t-1)*(u?8:4),u?8:4),d=u?i.getUint32(0)*2**32+i.getUint32(4):i.getUint32(0);for(let t=0;t<m;t+=1){if(f>=o)throw k(`mp4`,`the sample tables disagree`);let t=a===0?(await e.view(r.body+12+f*4,4)).getUint32(0):a;if(d+t>n)throw k(`mp4`,`a sample lies outside the file`);d+=t,f+=1}}if(f!==o)throw k(`mp4`,`the sample tables disagree`);return o}var Tt={1:[44100,48e3,32e3],2:[22050,24e3,16e3],2.5:[11025,12e3,8e3]},Et={"1-1":[0,32,64,96,128,160,192,224,256,288,320,352,384,416,448],"1-2":[0,32,48,56,64,80,96,112,128,160,192,224,256,320,384],"1-3":[0,32,40,48,56,64,80,96,112,128,160,192,224,256,320],"2-1":[0,32,48,56,64,80,96,112,128,144,160,176,192,224,256],"2-2":[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160],"2-3":[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160]};function Q(e,t){let n=e[t],r=e[t+1],i=e[t+2],a=e[t+3];if(n!==255||r===void 0||i===void 0||a===void 0||(r&224)!=224)return;let o=r>>3&3,s=r>>1&3,c=i>>4,l=i>>2&3;if(o===1||s===0||c===0||c===15||l===3||(a&3)==2)return;let u=o===3?1:o===2?2:2.5,d=4-s,f=Tt[u]?.[l],p=Et[`${u===1?1:2}-${d}`]?.[c]*1e3,m=i>>1&1,h=a>>6==3?1:2,g,_;if(d===1?(g=384,_=(Math.floor(12*p/f)+m)*4):d===2||u===1?(g=1152,_=Math.floor(144*p/f)+m):(g=576,_=Math.floor(72*p/f)+m),!(_<4))return{version:u,layer:d,sampleRate:f,channels:h,samplesPerFrame:g,frameLength:_,protected:!(r&1)}}function Dt(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=t=>t+4<=e.length?String.fromCharCode(...e.subarray(t,t+4)):``,i=t.version===1?t.channels===1?17:32:t.channels===1?9:17,a=4+(t.protected?2:0)+i,o=r(a);if(o===`Xing`||o===`Info`){if(a+8>e.length)return;let t=n.getUint32(a+4);a+=8;let i;if(t&1){if(a+4>e.length)return;i=n.getUint32(a),a+=4}if(t&2&&(a+=4),t&4&&(a+=100),t&8&&(a+=4),a+24<=e.length&&r(a)===`LAME`){let t=e[a+21]*65536+e[a+22]*256+e[a+23];return{...i===void 0?{}:{frames:i},delay:t>>12,padding:t&4095}}return i===void 0?{}:{frames:i}}if(r(36)===`VBRI`&&54<=e.length)return{delay:n.getUint16(42),frames:n.getUint32(50)}}var Ot=65536,kt=(e,t)=>e.version===t.version&&e.layer===t.layer&&e.sampleRate===t.sampleRate;async function At(e,t){return P(s(e),t,Ot,Q,e=>e.frameLength,kt)}function jt(e,t,n){let r=e.sampleRate<t?Math.ceil(t/e.sampleRate):1;return e.samplesPerFrame*r*Math.ceil(e.channels/n)}async function Mt(e,t){let n=s(e),r=await P(n,t,Ot,Q,e=>e.frameLength,kt);if(!r)throw k(`mp3`,`no frames`);let{sampleRate:i,channels:a,samplesPerFrame:o}=r.first,c=Dt(await n.bytes(r.offset,r.first.frameLength),r.first),l=0,u=0;if(await Ce(n,r.offset,4,Q,e=>e.frameLength,(e,t)=>{l+=jt(e,i,a),t&&(u+=1)}),l===0)throw k(`mp3`,`no frames`);let d=c?.delay??0,f=c?.padding??0,p=u*o;if(c?.frames!==void 0){let e=c.frames*o;if(e>l)throw k(`mp3`,`the tag claims more than the frames carry`);p=Math.max(0,e-d-f)}return{container:`mp3`,codec:`mp3`,sampleRate:i,channels:a,frameBound:l,expectedFrames:Math.min(p,l),frameTolerance:2*o+d+f}}function Nt(e,t){return new O(`UNSUPPORTED_FORMAT`,`This container or codec isn't supported.`,{details:t===void 0?{container:e}:{container:e,codec:t}})}async function Pt(e){let t=s(e),n=await t.bytes(0,64),r=(e,t)=>String.fromCharCode(...n.subarray(e,t)),i=r(0,4),a=r(8,12);if((i===`RIFF`||i===`RF64`)&&a===`WAVE`||i===`FORM`&&(a===`AIFF`||a===`AIFC`))return be(e);if(i===`fLaC`)return{probe:await Pe(e)};if(n[0]===26&&n[1]===69&&n[2]===223&&n[3]===163)return{probe:await _t(e)};if([`ftyp`,`moov`,`mdat`,`free`,`skip`,`wide`].includes(r(4,8)))return{probe:await St(e)};let o=Me(n);if(o>0){let n=await t.bytes(o,4);if(String.fromCharCode(...n)===`fLaC`)return{probe:await Pe(e)}}if(i===`OggS`){let r=n[26]??0,i=await t.bytes(27+r,8);if(Re(i))return{probe:await ze(e)};if(Ve(i))return{probe:await Ge(e)};if(qe(i))return{probe:await Ye(e)};throw Nt(`ogg`)}let[c,l]=await Promise.all([At(e,o),De(e,o)]);if(c&&(!l||c.offset<=l.offset))return{probe:await Mt(e,o)};if(l)return{probe:await Oe(e,o)};throw Nt(`unknown`)}var Ft=16,It=512,Lt=9,Rt=.945;function zt(e){let t=1,n=1,r=e*e/4;for(let e=1;n>t*1e-17;e+=1)n*=r/(e*e),t+=n;return t}var Bt;function Vt(){if(Bt)return Bt;let e=Ft*It,t=/* @__PURE__ */ new Float64Array(8194),n=zt(Lt);for(let r=0;r<=e;r+=1){let e=r/It,i=r===0?1:Math.sin(Math.PI*e)/(Math.PI*e),a=e/Ft,o=zt(Lt*Math.sqrt(Math.max(0,1-a*a)))/n;t[r]=i*o}return t[e]=0,Bt=t,t}var $=(e,t)=>Number.isSafeInteger(e)&&e>=t;function Ht(e,t){return Math.ceil(Ft/(Math.min(1,t/e)*Rt))}function Ut(e){let{input:t,inputStart:n,fromRate:r,toRate:i,start:a,frames:o}=e;if(!$(r,1)||!$(i,1)||!$(a,0)||!$(o,0)||!$(n,0)||!Number.isSafeInteger((a+o)*r))throw RangeError(`Rates and positions must be whole numbers, and rates positive.`);let s=Vt(),c=Math.min(1,i/r)*Rt,l=Ht(r,i),u=c*It,d=2*l,f=new Float32Array(o),p=t.length,m=i/Wt(r,i),h=i/m,g=[],_=e=>{let t=new Float64Array(d),n=e/m,r=0;for(let e=0;e<d;e+=1){let i=Math.abs(n-(e-l+1))*u,a=Math.floor(i);if(a>=s.length-1)continue;let o=s[a],c=o+(s[a+1]-o)*(i-a);t[e]=c,r+=c}for(let e=0;e<d;e+=1)t[e]=t[e]/r;return t};for(let e=0;e<o;e+=1){let o=(a+e)*r,s=Math.floor(o/i),c=(o-s*i)/h,u=g[c];u||(u=_(c),g[c]=u);let m=s-l+1-n,v=Math.max(0,-m),y=Math.min(d,p-m),b=0;for(let e=v;e<y;e+=1)b+=t[m+e]*u[e];f[e]=b}return f}function Wt(e,t){let[n,r]=[e,t];for(;r!==0;)[n,r]=[r,n%r];return n}function Gt(e){return 10**(e/20)}function Kt(e,t){return e===`equalPower`?Math.sin(t*Math.PI/2):t}function qt(e,t){let n=e.end-e.start,r=Gt(e.gainDb),{fadeIn:i,fadeOut:a}=e;i.frames>0&&t<i.frames&&(r*=Kt(i.curve,t/i.frames));let o=n-1-t;return a.frames>0&&o<a.frames&&(r*=Kt(a.curve,Math.max(0,o)/a.frames)),r}function Jt(e,t){let n=Array.from({length:t},()=>Array(e).fill(0)),r=(e,t,r)=>{n[e][t]=r},i=Math.SQRT1_2;switch(`${e}>${t}`){case`1>2`:r(0,0,1),r(1,0,1);break;case`1>4`:r(0,0,1),r(1,0,1);break;case`1>6`:r(2,0,1);break;case`2>4`:case`2>6`:r(0,0,1),r(1,1,1);break;case`4>6`:r(0,0,1),r(1,1,1),r(4,2,1),r(5,3,1);break;case`2>1`:r(0,0,.5),r(0,1,.5);break;case`4>1`:for(let e=0;e<4;e+=1)r(0,e,.25);break;case`6>1`:r(0,0,i),r(0,1,i),r(0,2,1),r(0,4,.5),r(0,5,.5);break;case`4>2`:r(0,0,.5),r(0,2,.5),r(1,1,.5),r(1,3,.5);break;case`6>2`:r(0,0,1),r(0,2,i),r(0,4,i),r(1,1,1),r(1,2,i),r(1,5,i);break;case`6>4`:r(0,0,1),r(0,2,i),r(1,1,1),r(1,2,i),r(2,4,1),r(3,5,1);break;default:for(let n=0;n<Math.min(e,t);n+=1)r(n,n,1)}return n}function Yt(e){let{channels:t,frames:n,segments:r}=e,i=Array.from({length:t},()=>new Float64Array(n));for(let e of r){let n=Jt(e.samples.length,t);for(let r=0;r<e.samples.length;r+=1){let a=e.samples[r];for(let o=0;o<t;o+=1){let t=n[o][r];if(t===0)continue;let s=i[o];for(let n=0;n<e.frames;n+=1){let r=qt(e.clip,e.within+n)*e.gain;s[e.at+n]=s[e.at+n]+t*a[n]*r}}}}let a=Array.from({length:t},()=>new Float32Array(n)),o=0,s=0;for(let r=0;r<n;r+=1){let n=!1;for(let s=0;s<t;s+=1){let t=i[s][r]*e.gain,c=Math.abs(t);c>o&&(o=c),c>1&&(n=!0),a[s][r]=Math.max(-1,Math.min(1,t))}n&&(s+=1)}return{channels:a,peak:o,clipped:s}}var Xt={pcm16:2,pcm24:3,float32:4};function Zt(e){return Xt[e]}function Qt(e){return e.frames*e.channels*Xt[e.sampleFormat]}var $t=4294967295,en=[[`title`,`INAM`],[`artist`,`IART`],[`album`,`IPRD`],[`year`,`ICRD`],[`comment`,`ICMT`]];function tn(e){let t=new TextEncoder;return en.flatMap(([n,r])=>{let i=e[n];return i===``?[]:[{id:r,value:t.encode(`${i}\0`)}]})}function nn(e){return e.length===0?0:4+e.reduce((e,{value:t})=>e+8+t.length+t.length%2,0)}function rn(e,t=tn(e.metadata)){let{channels:n,frames:r,sampleFormat:i}=e,a=Zt(i),o=i===`float32`,s=n>2||a>2,c=s?40:o?18:16,l=nn(t),u=Qt(e),d=u%2,f=8+c+(o?12:0)+(l?8+l:0)+8+u+d,p=4+f,m=p>$t||u>$t||r>$t,h=12+(m?36:0)+f;return{bytes:a,float:o,extensible:s,fmtSize:c,infoSize:l,data:u,pad:d,riffSize:p,rf64:m,headerSize:h-u-d,fileSize:h}}var an=1,on=3,sn=65534,cn=[0,0,0,0,16,0,128,0,0,170,0,56,155,113],ln={1:4,2:3,4:51,6:63},un=4294967295,dn=class{bytes;view;at=0;constructor(e){this.bytes=new Uint8Array(e),this.view=new DataView(this.bytes.buffer)}text(e){for(let t=0;t<e.length;t+=1)this.bytes[this.at+t]=e.charCodeAt(t);this.at+=e.length}u16(e){this.view.setUint16(this.at,e,!0),this.at+=2}u32(e){this.view.setUint32(this.at,e,!0),this.at+=4}u64(e){this.u32(e%2**32),this.u32(Math.floor(e/2**32))}raw(e){this.bytes.set(e,this.at),this.at+=e.length}};function fn(e){if(e.length===0)return;let t=new dn(nn(e));t.text(`INFO`);for(let{id:n,value:r}of e)t.text(n),t.u32(r.length),t.raw(r),r.length%2==1&&(t.at+=1);return t.bytes}function pn(e){let{sampleRate:t,channels:n,frames:r,metadata:i}=e,a=tn(i),{bytes:o,float:s,extensible:c,fmtSize:l,data:u,riffSize:d,rf64:f,headerSize:p}=rn(e,a),m=fn(a),h=new dn(p);h.text(f?`RF64`:`RIFF`),h.u32(f?un:d),h.text(`WAVE`),f&&(h.text(`ds64`),h.u32(28),h.u64(d+36),h.u64(u),h.u64(r),h.u32(0)),h.text(`fmt `),h.u32(l);let g=s?on:an;if(h.u16(c?sn:g),h.u16(n),h.u32(t),h.u32(t*n*o),h.u16(n*o),h.u16(o*8),c){h.u16(22),h.u16(o*8),h.u32(ln[n]??0),h.u16(g);for(let e of cn)h.bytes[h.at++]=e}else s&&h.u16(0);return s&&(h.text(`fact`),h.u32(4),h.u32(f?un:r)),m&&(h.text(`LIST`),h.u32(m.length),h.raw(m)),h.text(`data`),h.u32(f?un:u),h.bytes}function mn(e){return e<0?-Math.round(-e):Math.round(e)}function hn(e,t){let n=Number.isFinite(e)?Math.max(-1,Math.min(1,e)):0;if(t===`float32`)return Math.fround(n);let r=t===`pcm16`?32768:8388608;return Math.min(r-1,mn(n*r))+0}function gn(e,t,n){let r=Zt(n),i=new Uint8Array(t*e.length*r),a=new DataView(i.buffer),o=0;for(let i=0;i<t;i+=1)for(let t of e){let e=hn(t[i]??0,n);n===`float32`?a.setFloat32(o,e,!0):n===`pcm16`?a.setInt16(o,e,!0):(a.setUint8(o,e&255),a.setUint8(o+1,e>>8&255),a.setUint8(o+2,e>>16&255)),o+=r}return i}function _n(e){let{channels:t,peak:n,clipped:r}=Yt(e);return{bytes:gn(t,e.frames,e.sampleFormat),peak:n,clipped:r}}function vn(e){te({probe:({file:e})=>Pt(e),async readBlock({file:e,layout:t,start:n,frames:r,bucket:i}){let a=await xe(e,t,n,r);return{channels:a,...Se(a,i)}},peaks:({channels:e,bucket:t})=>Se(e,t),resample:({channels:e,...t})=>e.map(e=>Ut({input:e,...t})),wavHeader:e=>pn(e),renderBlock:e=>_n(e)},{...e,packageVersion:`0.7.0`})}vn();
1
+ var e=!1;function t(){e||=!0}var n=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),r=class extends Error{name=`SdkError`;code;constructor(e,r,i={}){super(r,`cause`in i?{cause:i.cause}:void 0),t(),this.code=e,Object.defineProperty(this,n,{value:!0}),i.details!==void 0&&(this.details=i.details)}};function i(e,t){if(typeof e!=`object`||!e)return!1;let i=e;return(e instanceof r||i[n]===!0)&&typeof i.code==`string`&&typeof i.message==`string`&&(t===void 0||i.code===t)}var a=1<<20;function o(e,t,n){if(!Number.isSafeInteger(t)||t<n)throw RangeError(`The ${e} must be an integer of at least ${n}, not ${String(t)}.`)}function s(e,t={}){let n=t.windowSize??a;o(`window size`,n,1);let r=e.size,i=0,s=/* @__PURE__ */ new Uint8Array;return{size:r,async bytes(t,a){o(`offset`,t,0),o(`length`,a,0);let c=Math.min(t,r),l=Math.min(r,c+a);if(c<i||l>i+s.length){let t=Math.min(r,c+Math.max(a,n));s=new Uint8Array(await e.slice(c,t).arrayBuffer()),i=c}return s.subarray(c-i,l-i)}}}var c=8,l=16,u=`UNKNOWN`;function d(e,t={}){let n=t.includeStack??!1,r=_(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=f(e),s=n&&h(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),h(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function f(e){if(i(e)){let t={name:e.name,code:e.code,message:e.message},n=p(e.details);return n!==void 0&&(t.details=n),t}if(h(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:u,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:u,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:u,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function p(e){if(!g(e))return;let t=m(e,0);return g(t)?t:void 0}function m(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(!(t>=l)){if(Array.isArray(e))return e.flatMap(e=>{let n=m(e,t+1);return n===void 0?[]:[n]});if(g(e)){let n={};for(let[r,i]of Object.entries(e)){let e=m(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function h(e){return typeof e==`object`&&!!e}function g(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function _(e){if(e===void 0)return c;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}[...Array.from({length:12},(e,t)=>`F${t+1}`)];var v=`hm-rpc`;function y(e){return{protocol:v,version:1,...e}}function b(e){if(typeof e!=`object`||!e)return;let t=e;if(t.protocol!==`hm-rpc`||typeof t.version!=`number`)return;let n=Number.isSafeInteger(t.id);switch(t.type){case`ready`:return t;case`call`:return n&&typeof t.method==`string`?t:void 0;case`cancel`:case`progress`:case`result`:return n?t:void 0;case`error`:return n?t:void 0;case`crash`:return t;default:return}}function x(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{if(typeof e!=`object`||!e)return e;if(r.has(e))return r.get(e);if(ArrayBuffer.isView(e)){let i=C(e)?e:w(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return E(e)?(t&&n.add(e),r.set(e,e),e):Array.isArray(e)?a(e,()=>[],(e,t)=>{t.forEach((t,n)=>{e[n]=i(t)})}):e instanceof Map?a(e,()=>/* @__PURE__ */ new Map,(e,t)=>{for(let[n,r]of t)e.set(i(n),i(r))}):e instanceof Set?a(e,()=>/* @__PURE__ */ new Set,(e,t)=>{for(let n of t)e.add(i(n))}):D(e)?a(e,()=>({}),(e,t)=>{for(let[n,r]of Object.entries(t))e[n]=i(r)}):(r.set(e,e),e)},a=(e,t,n)=>{let i=t();return r.set(e,i),n(i,e),ee(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function S(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function C(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function w(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();if(e instanceof DataView)return new DataView(t.buffer);let n=e.constructor;return new n(t.buffer)}var T=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function E(e){let t=globalThis;return T.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function D(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ee(e,t){if(Array.isArray(e)){let n=t;return e.length===n.length&&e.every((e,t)=>e===n[t])}if(e instanceof Map){let n=[...t];return[...e].every(([e,t],r)=>n[r]?.[0]===e&&n[r]?.[1]===t)}if(e instanceof Set){let n=[...t];return[...e].every((e,t)=>n[t]===e)}let n=t;return Object.entries(e).every(([e,t])=>n[e]===t)}function te(e,t={}){let n=t.scope??globalThis,i=t.includeStack??!1,a=/* @__PURE__ */ new Map,o=(e,t=[])=>{n.postMessage(e,t)},s=(e,t)=>{o(y({type:`error`,id:e,error:d(t,{includeStack:i})}))},c=(e,t,i)=>{let a=x(i,!0);try{S((e,t)=>n.postMessage(e,t),y({type:`result`,id:e,output:a.value}),a.transferables)}catch(n){s(e,new r(`WORKER_DATA_NOT_CLONEABLE`,`The result of "${t}" can't be sent to the page.`,{cause:n,details:{method:t}}))}},l=t=>{let{id:n,method:i}=t,l=Object.hasOwn(e,i)?e[i]:void 0;if(typeof l!=`function`){s(n,new r(`WORKER_METHOD_NOT_FOUND`,`The worker has no method "${i}".`,{details:{method:i}}));return}let u=new AbortController;a.set(n,u);let d={signal:u.signal,progress:e=>{a.get(n)===u&&o(y({type:`progress`,id:n,value:e}))}};Promise.resolve().then(()=>l.call(e,t.input,d)).then(e=>{a.delete(n),c(n,i,e)},e=>{a.delete(n),s(n,e)})},u=e=>{o(y({type:`crash`,error:d(e,{includeStack:i})}))};n.addEventListener(`message`,e=>{let t=b(e.data);t!==void 0&&t.version===1&&(t.type===`call`?l(t):t.type===`cancel`&&a.get(t.id)?.abort())}),n.addEventListener(`error`,e=>{let t=e;u(t.error??Error(t.message))}),n.addEventListener(`unhandledrejection`,e=>{u(e.reason)}),o(y({type:`ready`,...t.packageVersion===void 0?{}:{packageVersion:t.packageVersion}}))}var O=class extends r{name=`AudioError`},ne=1024;function k(e,t){return new O(`INVALID_AUDIO`,`Invalid ${e} file: ${t}.`,{details:{container:e,reason:t}})}function A(e,t){return new O(`UNSUPPORTED_FORMAT`,`Unsupported sample format in ${e}: ${t}.`,{details:{container:e,codec:t}})}async function j(e,t,n){let r=await e.slice(t,t+n).arrayBuffer();return new DataView(r)}function M(e,t=0){return e.byteLength<t+4?``:String.fromCharCode(e.getUint8(t),e.getUint8(t+1),e.getUint8(t+2),e.getUint8(t+3))}function re(e){let{container:t,channels:n,sampleRate:r,bytesPerSample:i,blockAlign:a,frames:o,dataOffset:s}=e;if(!Number.isInteger(n)||n<1||n>ne)throw k(t,`channel count out of range`);if(!Number.isInteger(r)||r<1)throw k(t,`sample rate out of range`);if(![1,2,3,4,8].includes(i))throw k(t,`sample size out of range`);if(a!==n*i)throw k(t,`frame size doesn't match the channels and sample size`);if(!Number.isSafeInteger(o)||o<0||!Number.isSafeInteger(s))throw k(t,`length out of range`);return e}var ie={NONE:{encoding:`int`,littleEndian:!1},twos:{encoding:`int`,littleEndian:!1},sowt:{encoding:`int`,littleEndian:!0},in24:{encoding:`int`,littleEndian:!1,bits:24},"42ni":{encoding:`int`,littleEndian:!0,bits:24},in32:{encoding:`int`,littleEndian:!1,bits:32},"23ni":{encoding:`int`,littleEndian:!0,bits:32},fl32:{encoding:`float`,littleEndian:!1,bits:32},FL32:{encoding:`float`,littleEndian:!1,bits:32},fl64:{encoding:`float`,littleEndian:!1,bits:64},FL64:{encoding:`float`,littleEndian:!1,bits:64}};function ae(e,t){let n=e.getUint16(t,!1),r=n&32767;return n&32768||r===0||r===32767?NaN:(e.getUint32(t+2,!1)*2**32+e.getUint32(t+6,!1))*2**(r-16383-63)}function oe(e,t){if(e.byteLength<(t?22:18))throw k(`aiff`,`truncated COMM chunk`);let n=ae(e,8);if(!Number.isInteger(n)||n<1||n>2**31)throw k(`aiff`,`sample rate out of range`);return{channels:e.getInt16(0,!1),frames:e.getUint32(2,!1),bits:e.getInt16(6,!1),sampleRate:n,type:t?M(e,18):`NONE`}}async function se(e){let t=await j(e,0,12),n=M(t,8);if(M(t)!==`FORM`||n!==`AIFF`&&n!==`AIFC`)throw k(`aiff`,`missing FORM header`);let r=n===`AIFC`,i,a,o=12;for(let t=0;o+8<=e.size;t+=1){if(t>=1024)throw k(`aiff`,`too many chunks`);let n=await j(e,o,8),s=M(n),c=n.getUint32(4,!1),l=o+8,u=e.size-l;if(s===`COMM`){if(c>u)throw k(`aiff`,`truncated COMM chunk`);i=oe(await j(e,l,Math.min(c,64)),r)}else if(s===`SSND`){let t=await j(e,l,8);if(c<8||t.byteLength<8)throw k(`aiff`,`truncated SSND chunk`);let n=l+8+t.getUint32(0,!1),r=Math.min(l+c,e.size);if(n>r)throw k(`aiff`,`sound data offset past the chunk`);a={offset:n,size:r-n}}if(i&&a)break;o=l+c+c%2}if(!i)throw k(`aiff`,`missing COMM chunk`);if(!a)throw k(`aiff`,`missing SSND chunk`);let s=ie[i.type];if(!s)throw A(`aiff`,i.type||`unknown`);let c=s.bits??i.bits;if(c<1||c>64)throw k(`aiff`,`sample size out of range`);if(s.encoding===`float`&&c!==32&&c!==64)throw A(`aiff`,`${c}-bit float`);if(s.encoding===`int`&&c>32)throw A(`aiff`,`${c}-bit integer`);let l=Math.ceil(c/8),u=re({container:`aiff`,sampleRate:i.sampleRate,channels:i.channels,encoding:s.encoding,bytesPerSample:l,littleEndian:s.littleEndian,dataOffset:a.offset,blockAlign:i.channels*l,frames:i.frames});return u.frames*u.blockAlign>a.size?{...u,frames:Math.floor(a.size/u.blockAlign),declaredFrames:u.frames}:u}function ce(e,t,n){let{channels:r,bytesPerSample:i,blockAlign:a,encoding:o,littleEndian:s}=t;if(e.byteLength<n*a)throw RangeError(`Expected ${n*a} bytes, got ${e.byteLength}.`);let c=Array.from({length:r},()=>new Float32Array(n)),l=le(o,i,s);for(let t=0;t<r;t+=1){let r=c[t],o=t*i;for(let t=0;t<n;t+=1)r[t]=l(e,o),o+=a}return c}function le(e,t,n){if(e===`float`)return t===8?(e,t)=>ue(Math.fround(e.getFloat64(t,n))):(e,t)=>ue(e.getFloat32(t,n));if(e===`uint`)return(e,t)=>(e.getUint8(t)-128)/128;switch(t){case 1:return(e,t)=>e.getInt8(t)/128;case 2:return(e,t)=>e.getInt16(t,n)/32768;case 3:return(e,t)=>{let r=e.getUint8(t),i=e.getUint8(t+1),a=e.getUint8(t+2);return((n?r|i<<8|a<<16:r<<16|i<<8|a)<<8>>8)/8388608};default:return(e,t)=>e.getInt32(t,n)/2147483648}}function ue(e){return Number.isFinite(e)?e:0}var de=1,fe=3,pe=65534,me=[0,0,0,0,16,0,128,0,0,170,0,56,155,113],he=4294967295;async function ge(e,t){let n=await j(e,t,8);if(n.byteLength<8)return!1;for(let e=0;e<4;e+=1){let t=n.getUint8(e);if(t<32||t>126)return!1}return n.getUint32(4,!0)<=e.size-t-8}function _e(e){if(e.byteLength<16)throw k(`wav`,`truncated fmt chunk`);let t=e.getUint16(0,!0),n={channels:e.getUint16(2,!0),sampleRate:e.getUint32(4,!0),blockAlign:e.getUint16(12,!0),bitsPerSample:e.getUint16(14,!0)};if(t===pe){if(e.byteLength<40)throw k(`wav`,`truncated extensible fmt chunk`);t=e.getUint16(24,!0);for(let[t,n]of me.entries())if(e.getUint8(26+t)!==n)throw A(`wav`,`extensible subformat`)}return{tag:t,...n}}function ve(e,t,n,r){let{tag:i,channels:a,sampleRate:o,blockAlign:s,bitsPerSample:c}=e;if(c%8!=0)throw k(`wav`,`sample size isn't whole bytes`);let l=c/8,u;if(i===de&&[1,2,3,4].includes(l))u=l===1?`uint`:`int`;else if(i===fe&&[4,8].includes(l))u=`float`;else throw A(`wav`,`format ${i} at ${c} bits`);if(s<1)throw k(`wav`,`frame size is zero`);return re({container:`wav`,sampleRate:o,channels:a,encoding:u,bytesPerSample:l,littleEndian:!0,dataOffset:t,blockAlign:s,frames:Math.floor(n/s),...r===void 0?{}:{declaredFrames:Math.floor(r/s)}})}async function ye(e){let t=await j(e,0,12),n=M(t);if(n!==`RIFF`&&n!==`RF64`||M(t,8)!==`WAVE`)throw k(`wav`,`missing RIFF header`);let r,i,a,o=12;for(let t=0;o+8<=e.size;t+=1){if(t>=1024)throw k(`wav`,`too many chunks`);let s=await j(e,o,8),c=M(s),l=s.getUint32(4,!0),u=o+8,d=e.size-u;if(c===`ds64`&&n===`RF64`){let t=await j(e,u,16);if(t.byteLength<16)throw k(`wav`,`truncated ds64 chunk`);let n=t.getUint32(12,!0);if(n>=2**21)throw k(`wav`,`data size out of range`);a=n*2**32+t.getUint32(8,!0)}else if(c===`fmt `){if(l>d)throw k(`wav`,`truncated fmt chunk`);r=_e(await j(e,u,Math.min(l,64)))}else if(c===`data`){let t=l;if(n===`RF64`&&l===he){if(a===void 0)throw k(`wav`,`RF64 file without ds64 chunk`);t=a}else(l===he||l===0&&!await ge(e,u))&&(t=d);if(i={offset:u,size:Math.min(t,d),declared:t>d?t:void 0},r)break;o=u+t+t%2;continue}if(r&&i)break;o=u+l+l%2}if(!r)throw k(`wav`,`missing fmt chunk`);if(!i)throw k(`wav`,`missing data chunk`);return ve(r,i.offset,i.size,i.declared)}async function be(e){let t=await j(e,0,12),n=M(t),r=M(t,8),i;if((n===`RIFF`||n===`RF64`)&&r===`WAVE`)i=await ye(e);else if(n===`FORM`&&(r===`AIFF`||r===`AIFC`))i=await se(e);else throw new O(`UNSUPPORTED_FORMAT`,`The file's container isn't recognised.`,{details:{container:`unknown`}});if(i.frames===0)throw k(i.container,`no audio frames`);return{layout:i,probe:{container:i.container,codec:`pcm`,sampleRate:i.sampleRate,channels:i.channels,frameBound:i.frames,expectedFrames:i.frames,...i.declaredFrames===void 0?{}:{declaredFrames:i.declaredFrames},frameTolerance:0}}}async function xe(e,t,n,r){if(!Number.isSafeInteger(n)||!Number.isSafeInteger(r)||n<0||r<0||n+r>t.frames)throw RangeError(`Frames ${n} to ${n+r} are outside the file.`);let i=r*t.blockAlign,a=await j(e,t.dataOffset+n*t.blockAlign,i);if(a.byteLength<i)throw k(t.container,`file shorter than probed`);return ce(a,t,r)}function Se(e,t){let n=[],r=[];for(let i of e){let e=Math.ceil(i.length/t),a=new Float32Array(e),o=new Float32Array(e);for(let n=0;n<e;n+=1){let e=Math.min(i.length,(n+1)*t),r=1/0,s=-1/0;for(let a=n*t;a<e;a+=1){let e=i[a];e<r&&(r=e),e>s&&(s=e)}a[n]=r,o[n]=s}n.push(a),r.push(o)}return{min:n,max:r}}var N=1<<20;async function Ce(e,t,n,r,i,a){let o=t;for(let s=t;s<e.size;s+=N){let t=await e.bytes(s,N+n),c=Math.min(N,e.size-s);for(let e=0;e<c;e+=1){if(t[e]!==255)continue;let n=r(t,e);if(n===void 0)continue;let c=s+e,l=c>=o;l&&(o=c+Math.max(1,i(n))),a(n,l)}}}async function P(e,t,n,r,i,a,o=3){let s=await e.bytes(t,n+65536);for(let c=0;c<Math.min(n,s.length);c+=1){if(s[c]!==255)continue;let n=r(s,c);if(n===void 0)continue;let l=c,u=n;for(let d=1;;d+=1){if(d===o)return{offset:t+c,first:n};let f=l+i(u);if(f===s.length&&t+s.length===e.size)return{offset:t+c,first:n};let p=r(s,f);if(p===void 0||!a(n,p))break;l=f,u=p}}}var we=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];function Te(e,t){let n=0,r=0,i=0,a=a=>{let o=0;for(let s=0;s<a;s+=1){if(n===0){if(i>=e.length)throw k(t,`truncated AudioSpecificConfig`);r=e[i],i+=1,n=8}--n,o=o*2+(r>>n&1)}return o};a(5)===31&&a(6);let o=a(4),s=o===15?a(24):we[o];if(s===void 0||s===0)throw k(t,`AAC sample rate out of range`);return{coreRate:s,channelConfiguration:a(4)}}function F(e){return e===0||e===7?8:Math.max(2,e)}function I(e){return e<=24e3?e*2:e}function L(e,t){let n=n=>e[t+n],r=n(1),i=n(2),a=n(3),o=n(4),s=n(5),c=n(6);if(n(0)!==255||r===void 0||i===void 0||a===void 0||o===void 0||s===void 0||c===void 0||(r&246)!=240)return;let l=we[i>>2&15];if(l===void 0)return;let u=(i&1)<<2|a>>6,d=(a&3)<<11|o<<3|s>>5;if(!(d<(r&1?7:9)))return{sampleRate:l,channelConfiguration:u,blocks:(c&3)+1,frameLength:d}}var Ee=(e,t)=>e.sampleRate===t.sampleRate&&e.channelConfiguration===t.channelConfiguration;async function De(e,t){return P(s(e),t,65536,L,e=>e.frameLength,Ee)}async function Oe(e,t){let n=s(e),r=await P(n,t,65536,L,e=>e.frameLength,Ee);if(!r)throw k(`adts`,`no frames`);let i=r.first.sampleRate,a=I(i),o=F(r.first.channelConfiguration),c=1024*Math.ceil(a/i),l=0,u=0;if(await Ce(n,r.offset,7,L,e=>e.frameLength,(e,t)=>{let n=Math.max(1,Math.ceil(a/e.sampleRate)),r=Math.ceil(F(e.channelConfiguration)/o);l+=e.blocks*1024*n*r,t&&(u+=e.blocks)}),l===0)throw k(`adts`,`no frames`);return{container:`adts`,codec:`aac`,sampleRate:a,channels:o,frameBound:l,expectedFrames:Math.min(u*c,l),frameTolerance:2*c}}function R(e,t){let n=2**(e-1),r=2**e-1,i=/* @__PURE__ */ new Uint32Array(256);for(let a=0;a<256;a+=1){let o=a*2**(e-8);for(let e=0;e<8;e+=1)o=o>=n?(o*2^t)&r:o*2&r,o>>>=0;i[a]=o>>>0}return i}var ke=R(8,7);R(16,32773),R(32,79764919);function Ae(e,t=0,n=e.length){let r=0;for(let i=t;i<n;i+=1)r=ke[r^e[i]];return r}function z(e,t){if(e.length<34)throw k(t,`truncated STREAMINFO`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint16(0),i=n.getUint16(2),a=n.getUint32(10),o=a>>>12,s=(a>>>9&7)+1,c=(a>>>4&31)+1,l=(a&15)*2**32+n.getUint32(14);if(r<16||i<r)throw k(t,`block sizes out of range`);if(o===0)throw k(t,`sample rate is zero`);if(c<4)throw k(t,`sample size out of range`);return{minBlockSize:r,maxBlockSize:i,sampleRate:o,channels:s,bitsPerSample:c,totalFrames:l}}var je=[void 0,88200,176400,192e3,8e3,16e3,22050,24e3,32e3,44100,48e3,96e3];function B(e,t){let n=n=>e[t+n];if(n(0)!==255||((n(1)??0)&254)!=248)return;let r=n(2),i=n(3);if(r===void 0||i===void 0)return;let a=r>>4,o=r&15,s=i>>4,c=i>>1&7;if(a===0||o===15||s>10||c===3||i&1)return;let l=4,u=n(l);if(u===void 0)return;let d;if(u<128)d=0;else if(u>=192&&u<224)d=1;else if(u>=224&&u<240)d=2;else if(u>=240&&u<248)d=3;else if(u>=248&&u<252)d=4;else if(u>=252&&u<254)d=5;else if(u===254)d=6;else return;l+=1;for(let e=0;e<d;e+=1,l+=1){let e=n(l);if(e===void 0||(e&192)!=128)return}let f;if(a===1)f=192;else if(a<=5)f=576*2**(a-2);else if(a===6||a===7){let e=n(l);if(e===void 0)return;if(a===6)f=e+1,l+=1;else{let t=n(l+1);if(t===void 0)return;f=e*256+t+1,l+=2}}else f=256*2**(a-8);let p=je[o];if(o>=12){let e=n(l);if(e===void 0)return;if(o===12)p=e*1e3,l+=1;else{let t=n(l+1);if(t===void 0)return;p=o===13?e*256+t:(e*256+t)*10,l+=2}if(p===0)return}let m=n(l);if(m!==void 0&&Ae(e,t,t+l)===m)return{blockSize:f,sampleRate:p,channels:s<8?s+1:2,length:l+1}}function Me(e){if(e.length<10||e[0]!==73||e[1]!==68||e[2]!==51)return 0;let t=0;for(let n=6;n<10;n+=1){let r=e[n];if(r&128)return 0;t=t*128+r}let n=e[5]&16?10:0;return 10+t+n}var V=1<<20;function Ne(e,t){let n=e.sampleRate!==void 0&&e.sampleRate<t.sampleRate?Math.ceil(t.sampleRate/e.sampleRate):1,r=Math.ceil(e.channels/t.channels);return e.blockSize*n*r}async function Pe(e){let t=s(e),n=Me(await t.bytes(0,10)),r=await t.bytes(n,4);if(String.fromCharCode(...r)!==`fLaC`)throw k(`flac`,`missing fLaC marker`);n+=4;let i;for(let e=0;;e+=1){if(e>=1024)throw k(`flac`,`too many metadata blocks`);let r=await t.bytes(n,4);if(r.length<4)throw k(`flac`,`truncated metadata`);let a=!!(r[0]&128),o=r[0]&127,s=r[1]<<16|r[2]<<8|r[3];if(o===127)throw k(`flac`,`invalid metadata block type`);if(e===0){if(o!==0||s!==34)throw k(`flac`,`STREAMINFO isn't first`);i=z(await t.bytes(n+4,34),`flac`)}if(n+=4+s,n>t.size)throw k(`flac`,`metadata exceeds the file`);if(a)break}if(!i)throw k(`flac`,`missing STREAMINFO`);let a=0,o=0;for(let e=n;e<t.size;e+=V){let n=await t.bytes(e,V+16),r=Math.min(V,t.size-e);for(let e=0;e<r;e+=1){if(n[e]!==255)continue;let t=B(n,e);t&&(a+=Ne(t,i),o+=1)}}if(o===0)throw k(`flac`,`no audio frames`);if(i.totalFrames>a)throw k(`flac`,`STREAMINFO claims more than the frames carry`);return{container:`flac`,codec:`flac`,sampleRate:i.sampleRate,channels:i.channels,frameBound:a,expectedFrames:i.totalFrames>0?i.totalFrames:a,frameTolerance:i.maxBlockSize}}var H=27,Fe=65307,Ie=-1;async function U(e,t){let n=s(e),r,i=Ie,a=[],o=0,c=0,l=0;for(;c+H<=n.size;){let e=await n.bytes(c,Fe);if(e[0]!==79||e[1]!==103||e[2]!==103||e[3]!==83){if(l===0)throw k(`ogg`,`missing first page`);c+=1;continue}let s=new DataView(e.buffer,e.byteOffset,e.byteLength),u=s.getUint8(4),d=s.getUint8(5),f=s.getUint8(26);if(u!==0||e.length<H+f){if(l===0)throw k(`ogg`,`malformed first page`);c+=1;continue}let p=0;for(let t=0;t<f;t+=1)p+=e[H+t];let m=H+f+p;if(m>e.length)break;let h=s.getUint32(14,!0),g=!!(d&2);if(r===void 0){if(!g)throw k(`ogg`,`first page doesn't begin a stream`);r=h}else if(h!==r){if(g)throw new O(`UNSUPPORTED_FORMAT`,`Ogg files with several streams aren't supported.`,{details:{container:`ogg`,reason:`multiplexed streams`}});c+=m,l+=1;continue}d&1||(a=[],o=0);let _=H+f;for(let n=0;n<f;n+=1){let r=e[H+n];if(a.length<64){let t=Math.min(r,64-a.length);for(let n=0;n<t;n+=1)a.push(e[_+n])}o+=r,_+=r,r<255&&(t({head:Uint8Array.from(a),length:o}),a=[],o=0)}let v=s.getInt32(10,!0),y=s.getUint32(6,!0);(v!==-1||y!==4294967295)&&(i=v*2**32+y),c+=m,l+=1}if(l===0)throw k(`ogg`,`missing first page`);return{lastGranule:i}}var Le=13;function Re(e){return e[0]===127&&e[1]===70&&e[2]===76&&e[3]===65&&e[4]===67}async function ze(e){let t,n=0,r=0,i=0,a=0,{lastGranule:o}=await U(e,({head:e})=>{if(n+=1,n===1){if(!Re(e)||e[5]!==1)throw k(`ogg`,`not a FLAC mapping version 1`);let n=String.fromCharCode(...e.subarray(9,13)),i=(e[Le]??127)&127;if(n!==`fLaC`||i!==0)throw k(`ogg`,`missing FLAC STREAMINFO`);t=z(e.subarray(17,51),`ogg`),r=(e[7]??0)<<8|(e[8]??0);return}if(!t)return;let o=e[0]===255&&((e[1]??0)&254)==248;if(n-1<=r||r===0&&!o&&a===0)return;a+=1;let s=B(e,0);if(!s)i+=t.maxBlockSize;else{if(s.channels!==t.channels)throw k(`ogg`,`a frame's channel count differs from STREAMINFO`);if(s.sampleRate!==void 0&&s.sampleRate!==t.sampleRate)throw k(`ogg`,`a frame's sample rate differs from STREAMINFO`);i+=s.blockSize}});if(!t)throw k(`ogg`,`missing FLAC header`);if(a===0)throw k(`ogg`,`no audio frames`);if(t.totalFrames>i||o>i)throw k(`ogg`,`a declared length exceeds the frames`);let s=o>0?o:t.totalFrames;return{container:`ogg`,codec:`flac`,sampleRate:t.sampleRate,channels:t.channels,frameBound:i,expectedFrames:s>0?s:i,frameTolerance:t.maxBlockSize}}var Be=48e3,W=5760;function Ve(e){return String.fromCharCode(...e.subarray(0,8))===`OpusHead`}function He(e){return e<12?[480,960,1920,2880][e%4]:e<16?[480,960][e%2]:[120,240,480,960][e%4]}function Ue(e,t){let n=e[0];if(t===0||n===void 0)return W;let r=He(n>>3),i=n&3,a;if(i===0)a=1;else if(i===1||i===2)a=2;else{let t=e[1];if(t===void 0)return W;a=t&63}let o=a*r;return o===0||o>5760?W:o}function We(e,t){if(!Ve(e)||e.length<19)throw k(t,`malformed OpusHead`);if(e[8]&240)throw k(t,`unsupported OpusHead version`);let n=e[9],r=e[10]|e[11]<<8,i=e[18];if(n===0)throw k(t,`no channels`);if(i===0?n>2:i!==1||n>8)throw new O(`UNSUPPORTED_FORMAT`,`Unsupported Opus channel mapping.`,{details:{container:t,codec:`opus`,reason:`channel mapping family ${i}`}});return{channels:n,preSkip:r}}async function Ge(e){let t=0,n=0,r=0,i=0,{lastGranule:a}=await U(e,({head:e,length:a})=>{if(r+=1,r===1)({channels:t,preSkip:n}=We(e,`ogg`));else if(r===2){if(String.fromCharCode(...e.subarray(0,8))!==`OpusTags`)throw k(`ogg`,`missing OpusTags`)}else i+=Ue(e,a)});if(r<2)throw k(`ogg`,`missing Opus headers`);if(i===0)throw k(`ogg`,`no audio packets`);if(a>i)throw k(`ogg`,`a declared length exceeds the packets`);let o=a>0?Math.max(0,a-n):i;return{container:`ogg`,codec:`opus`,sampleRate:Be,channels:t,frameBound:i,expectedFrames:o,frameTolerance:Math.max(W,n)}}var Ke=`vorbis`;function qe(e){return e[0]===1&&String.fromCharCode(...e.subarray(1,7))===Ke}function Je(e,t){if(!qe(e)||e.length<30)throw k(t,`malformed Vorbis header`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint32(7,!0)!==0)throw k(t,`unsupported Vorbis version`);let r=n.getUint8(11),i=n.getUint32(12,!0),a=n.getUint8(28),o=a&15,s=a>>4;if(o<6||s>13||o>s||(n.getUint8(29)&1)!=1)throw k(t,`Vorbis block sizes out of range`);if(r===0||i===0)throw k(t,`Vorbis format out of range`);return{channels:r,sampleRate:i,largeBlock:2**s}}async function Ye(e){let t=0,n=0,r=0,i=0,a=0,{lastGranule:o}=await U(e,({head:e})=>{if(i+=1,i===1)({channels:t,sampleRate:n,largeBlock:r}=Je(e,`ogg`));else if(i===2||i===3){let t=i===2?3:5;if(e[0]!==t||String.fromCharCode(...e.subarray(1,7))!==Ke)throw k(`ogg`,`missing Vorbis comment or setup header`)}else a+=1});if(i<3)throw k(`ogg`,`missing Vorbis headers`);if(a===0)throw k(`ogg`,`no audio packets`);let s=r/2*a;if(o>s)throw k(`ogg`,`a declared length exceeds the packets`);return{container:`ogg`,codec:`vorbis`,sampleRate:n,channels:t,frameBound:s,expectedFrames:o>0?o:s,frameTolerance:r}}var G=440786851,Xe=17026,Ze=408125543,Qe=357149030,$e=2807729,et=17545,tt=374648427,nt=174,rt=215,it=131,at=134,ot=25506,st=524531317,ct=163,lt=160,ut=161,dt=/* @__PURE__ */ new Set([st,475249515,307544935,272869232,423732329,290298740,Qe,tt,G]);function K(e,t){return new O(`UNSUPPORTED_FORMAT`,`Unsupported Matroska: ${e}.`,{details:t===void 0?{container:`webm`,reason:e}:{container:`webm`,codec:t,reason:e}})}function ft(e,t){let n=e[t];if(n===void 0||n===0)return;let r=Math.clz32(n)-23;if(r>4||t+r>e.length)return;let i=0;for(let n=0;n<r;n+=1)i=i*256+e[t+n];return{id:i,length:r}}function q(e,t){let n=e[t];if(n===void 0||n===0)return;let r=Math.clz32(n)-23;if(t+r>e.length)return;let i=n&255>>r,a=i===255>>r;for(let n=1;n<r;n+=1){let r=e[t+n];i=i*256+r,r!==255&&(a=!1)}return{value:i,length:r,unknown:a}}async function J(e,t){let n=await e.bytes(t,12),r=ft(n,0);if(!r)return;let i=q(n,r.length);if(i){if(!i.unknown&&!Number.isSafeInteger(i.value))throw k(`webm`,`element size out of range`);return{id:r.id,body:t+r.length+i.length,size:i.unknown?void 0:i.value}}}function Y(e){let t=[],n=0;for(;n<e.length;){let r=ft(e,n),i=r&&q(e,n+r.length);if(!r||!i||i.unknown)throw k(`webm`,`malformed element`);let a=n+r.length+i.length;if(a+i.value>e.length)throw k(`webm`,`element exceeds its parent`);t.push({id:r.id,data:e.subarray(a,a+i.value)}),n=a+i.value}return t}var X=e=>e.reduce((e,t)=>e*256+t,0);function pt(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return e.length===4?t.getFloat32(0):e.length===8?t.getFloat64(0):NaN}function mt(e,t){if(e===`A_OPUS`){if(!t)throw k(`webm`,`missing OpusHead`);let e=We(t,`webm`);return{codec:`opus`,sampleRate:Be,channels:e.channels,tolerance:Math.max(W,e.preSkip),frameSamples:Ue}}if(e===`A_VORBIS`){if(t?.[0]!==2)throw k(`webm`,`malformed Vorbis headers`);let e=1;for(let n=0;n<2;n+=1){for(;t[e]===255;)e+=1;if(t[e]===void 0)throw k(`webm`,`malformed Vorbis headers`);e+=1}let n=Je(t.subarray(e),`webm`),r=n.largeBlock/2;return{codec:`vorbis`,sampleRate:n.sampleRate,channels:n.channels,tolerance:n.largeBlock,frameSamples:()=>r}}if(e===`A_FLAC`){let e=t&&String.fromCharCode(...t.subarray(0,4));if(!t||e!==`fLaC`||(t[4]??127)&127)throw k(`webm`,`missing FLAC STREAMINFO`);let n=z(t.subarray(8,42),`webm`);return{codec:`flac`,sampleRate:n.sampleRate,channels:n.channels,tolerance:n.maxBlockSize,frameSamples(e){let t=B(e,0);if(!t)return n.maxBlockSize;if(t.channels!==n.channels)throw k(`webm`,`a frame's channel count differs from STREAMINFO`);if(t.sampleRate!==void 0&&t.sampleRate!==n.sampleRate)throw k(`webm`,`a frame's sample rate differs from STREAMINFO`);return t.blockSize}}}if(e.startsWith(`A_AAC`)){if(!t)throw K(`AAC without an AudioSpecificConfig`,`aac`);let e=Te(t,`webm`),n=I(e.coreRate),r=1024*Math.ceil(n/e.coreRate);return{codec:`aac`,sampleRate:n,channels:F(e.channelConfiguration),tolerance:2*r,frameSamples:()=>r}}throw K(`codec ${e}`,e)}function ht(e){let t=[];for(let n of Y(e)){if(n.id!==nt)continue;let e=Y(n.data),r=t=>e.find(e=>e.id===t)?.data,i=r(it);if(!i||X(i)!==2)continue;let a=r(rt),o=r(at);if(!a||!o)throw k(`webm`,`incomplete audio track`);let s=String.fromCharCode(...o).replace(/\0+$/,``);t.push({number:X(a),codec:mt(s,r(ot))})}if(t.length===0)throw k(`webm`,`no audio track`);if(t.length>1)throw K(`several audio tracks`);return t[0]}function gt(e,t){let n=q(e,0);if(!n||n.unknown)throw k(`webm`,`malformed block`);if(n.value!==t.number)return 0;let r=n.length+2,i=e[r];if(i===void 0)throw k(`webm`,`truncated block`);r+=1;let a=i>>1&3,o=[];if(a===0)o.push(e.length-r);else{let t=e[r];if(t===void 0)throw k(`webm`,`truncated block`);let n=t+1;if(r+=1,a===1)for(let t=0;t<n-1;t+=1){let t=0;for(;;){let n=e[r];if(n===void 0)throw k(`webm`,`truncated lacing`);if(r+=1,t+=n,n<255)break}o.push(t)}else if(a===3){let t=q(e,r);if(!t||t.unknown)throw k(`webm`,`malformed lacing`);r+=t.length,o.push(t.value);for(let t=1;t<n-1;t+=1){let n=q(e,r);if(!n||n.unknown)throw k(`webm`,`malformed lacing`);r+=n.length;let i=2**(7*n.length-1)-1;o.push(o[t-1]+n.value-i)}}let i=e.length-r;if(a===2){if(i%n!==0)throw k(`webm`,`fixed lacing doesn't divide the block`);for(let e=0;e<n;e+=1)o.push(i/n)}else{let e=o.reduce((e,t)=>e+t,0);o.push(i-e)}}if(o.some(e=>e<0)||r+o.reduce((e,t)=>e+t,0)>e.length)throw k(`webm`,`lacing exceeds the block`);let s=0;for(let n of o)s+=t.codec.frameSamples(e.subarray(r,r+Math.min(n,16)),n),r+=n;return s}async function _t(e){let t=s(e),n=await J(t,0);if(!n||n.id!==G||n.size===void 0)throw k(`webm`,`missing EBML header`);let r=Y(await t.bytes(n.body,n.size)).find(e=>e.id===Xe),i=r?String.fromCharCode(...r.data).replace(/\0+$/,``):``;if(i!==`webm`&&i!==`matroska`)throw K(`document type ${i||`missing`}`);let a=await J(t,n.body+n.size);if(!a||a.id!==Ze)throw k(`webm`,`missing Segment`);let o=Math.min(t.size,a.body+(a.size??t.size)),c,l=1e6,u,d=0,f=0,p,m=a.body;for(;m<o;){let e=await J(t,m);if(!e)throw k(`webm`,`malformed element`);if(p!==void 0&&(m>=p||dt.has(e.id))&&(p=void 0),p===void 0){if(e.id===G)throw K(`several segments`);if(e.id===st){if(!c)throw k(`webm`,`clusters before the tracks`);if(p=e.size===void 0?1/0:e.body+e.size,p!==1/0&&p>o)throw k(`webm`,`element exceeds its parent`);m=e.body;continue}if(e.size===void 0)throw k(`webm`,`unknown size outside a Segment or Cluster`);let n=e.body+e.size;if(n>o)throw k(`webm`,`element exceeds its parent`);if(e.id===Qe){let n=Y(await t.bytes(e.body,e.size)),r=n.find(e=>e.id===$e),i=n.find(e=>e.id===et);r&&(l=X(r.data)),i&&(u=pt(i.data))}else if(e.id===tt){if(c)throw K(`several Tracks elements`);c=ht(await t.bytes(e.body,e.size))}m=n;continue}if(e.size===void 0)throw k(`webm`,`unknown size inside a Cluster`);let n=e.body+e.size;if(n>Math.min(p,o))throw k(`webm`,`element exceeds its parent`);let r=c;if(e.id===ct)d+=gt(await t.bytes(e.body,e.size),r),f+=1;else if(e.id===lt)for(let n of Y(await t.bytes(e.body,e.size)))n.id===ut&&(d+=gt(n.data,r),f+=1);m=n}if(!c)throw k(`webm`,`missing Tracks`);if(f===0||d===0)throw k(`webm`,`no audio blocks`);let{codec:h}=c,g=d;if(u!==void 0){if(!Number.isFinite(u)||u<0)throw k(`webm`,`Duration out of range`);if(g=Math.round(u*l/1e9*h.sampleRate),g>d)throw k(`webm`,`the Duration claims more than the blocks carry`)}return{container:`webm`,codec:h.codec,sampleRate:h.sampleRate,channels:h.channels,frameBound:d,expectedFrames:g,frameTolerance:h.tolerance}}var vt=1e5;function Z(e,t){return new O(`UNSUPPORTED_FORMAT`,`Unsupported MP4: ${e}.`,{details:t===void 0?{container:`mp4`,reason:e}:{container:`mp4`,codec:t,reason:e}})}var yt=class{boxes=0;reader;constructor(e){this.reader=e}async u8(e){let t=await this.reader.bytes(e,1);if(t.length<1)throw k(`mp4`,`truncated box`);return t[0]}async view(e,t){let n=await this.reader.bytes(e,t);if(n.length<t)throw k(`mp4`,`truncated box`);return new DataView(n.buffer,n.byteOffset,n.byteLength)}async children(e,t,n=!1){let r=[],i=e;for(;i+8<=t;){if(this.boxes+=1,this.boxes>vt)throw k(`mp4`,`too many boxes`);let e=await this.view(i,8),a=e.getUint32(0),o=String.fromCharCode(e.getUint8(4),e.getUint8(5),e.getUint8(6),e.getUint8(7)),s=8;if(a===1){let e=await this.view(i+8,8),t=e.getUint32(0);if(t>=2**21)throw k(`mp4`,`box size out of range`);a=t*2**32+e.getUint32(4),s=16}else if(a===0){if(!n)throw k(`mp4`,`open-ended box inside another`);a=t-i}if(a<s||i+a>t)throw k(`mp4`,`box exceeds its parent`);r.push({type:o,body:i+s,end:i+a}),i+=a}return r}async child(e,t){return(await this.children(e.body,e.end)).find(e=>e.type===t)}async need(e,t){let n=await this.child(e,t);if(!n)throw k(`mp4`,`missing ${t} box`);return n}};async function bt(e,t){let n=0;for(let r=0;r<4;r+=1){let i=await e.u8(t+r);if(n=n*128+(i&127),!(i&128))return[n,r+1]}throw k(`mp4`,`malformed descriptor length`)}async function xt(e,t){let n=t.body+4,r=async r=>{if(await e.u8(n)!==r)throw Z(`unexpected ES descriptor`);let[i,a]=await bt(e,n+1);if(n+=1+a,n+i>t.end)throw k(`mp4`,`descriptor exceeds its box`)};await r(3);let i=await e.u8(n+2);n+=3,i&128&&(n+=2),i&64&&(n+=1+await e.u8(n)),i&32&&(n+=2),await r(4);let a=await e.u8(n);if(![64,102,103,104].includes(a))throw Z(`object type ${a}`,a===107||a===105?`mp3`:`unknown`);return n+=13,await r(5),Te(await e.reader.bytes(n,Math.min(5,t.end-n)),`mp4`)}async function St(e){let t=s(e),n=new yt(t),r=await n.children(0,t.size,!0);if(r.some(e=>e.type===`moof`))throw Z(`fragmented MP4`);let i=r.find(e=>e.type===`moov`);if(!i)throw k(`mp4`,`missing moov box`);let a=[];for(let e of(await n.children(i.body,i.end)).filter(e=>e.type===`trak`)){let t=await n.child(e,`mdia`),r=t&&await n.child(t,`hdlr`);t&&r&&(await n.view(r.body+8,4)).getUint32(0)===1936684398&&a.push({trak:e,mdia:t})}if(a.length===0)throw k(`mp4`,`no audio track`);if(a.length>1)throw Z(`several audio tracks`);let{trak:o,mdia:c}=a[0],l=await n.need(c,`mdhd`),u=await n.u8(l.body),d=await n.view(l.body+4,u===1?28:16),f=d.getUint32(u===1?16:8),p=u===1?d.getUint32(20)*2**32+d.getUint32(24):d.getUint32(12);if(f===0)throw k(`mp4`,`timescale is zero`);let m=await n.need(await n.need(c,`minf`),`stbl`),h=await n.need(m,`stsd`),[g]=await n.children(h.body+8,h.end);if(!g)throw k(`mp4`,`empty sample description`);let _=await n.view(g.body,28),v=_.getUint16(8);if(v>1)throw Z(`sound sample entry version 2`);let y=_.getUint16(16),b=_.getUint32(24)>>>16,x=g.body+28+(v===1?16:0),S,C,w,T;if(g.type===`mp4a`){let e=(await n.children(x,g.end)).find(e=>e.type===`esds`);if(!e)throw k(`mp4`,`missing esds box`);let{coreRate:t,channelConfiguration:r}=await xt(n,e);S=`aac`,C=I(t),w=F(r||y),T=1024*Math.ceil(C/t)}else if(g.type===`alac`){let e=(await n.children(x,g.end)).find(e=>e.type===`alac`);if(!e)throw k(`mp4`,`missing ALAC configuration`);let t=await n.view(e.body+4,24);if(S=`alac`,T=t.getUint32(0),w=t.getUint8(9),C=t.getUint32(20)||b,T===0||T>1<<20)throw k(`mp4`,`ALAC frame length out of range`);if(w===0||C===0)throw k(`mp4`,`ALAC format out of range`)}else throw Z(`codec ${g.type}`,g.type);await Ct(n,i,o,{timescale:f,duration:p,decodeRate:C,tolerance:2*T});let E=await wt(n,m,t.size);if(E===0)throw k(`mp4`,`no audio samples`);let D=E*T,ee=p===0?D:Math.round(p*C/f);if(ee>D)throw k(`mp4`,`the duration claims more than the samples carry`);return{container:`mp4`,codec:S,sampleRate:C,channels:w,frameBound:D,expectedFrames:ee,frameTolerance:2*T}}async function Ct(e,t,n,r){let i=(await e.children(n.body,n.end)).filter(e=>e.type===`edts`);if(i.length===0)return;if(i.length>1)throw Z(`several edit lists`);let a=(await e.children(i[0].body,i[0].end)).filter(e=>e.type===`elst`);if(a.length===0)return;if(a.length>1)throw Z(`several edit lists`);let o=a[0],s=await e.need(t,`mvhd`),c=await e.u8(s.body),l=(await e.view(s.body+(c===1?20:12),4)).getUint32(0);if(l===0)throw k(`mp4`,`movie timescale is zero`);let u=await e.u8(o.body),d=(await e.view(o.body+4,4)).getUint32(0),f=u===1?20:12;if(o.body+8+d*f>o.end)throw k(`mp4`,`edit list exceeds its box`);if(d>2)throw Z(`edit list with more than two edits`);let p=!1;for(let t=0;t<d;t+=1){let n=await e.view(o.body+8+t*f,f),i=u===1?n.getUint32(0)*2**32+n.getUint32(4):n.getUint32(0),a=u===1?n.getInt32(8)*2**32+n.getUint32(12):n.getInt32(4),s=n.getInt16(u===1?16:8),c=n.getUint16(u===1?18:10);if(a===-1){if(p||t>0)throw Z(`edit list with an empty edit after another edit`);if(i*r.decodeRate/l>r.tolerance)throw Z(`edit list with a long empty edit`)}else{if(p)throw Z(`edit list with several media edits`);if(p=!0,s!==1||c!==0)throw Z(`edit list with a media rate other than 1`);if(a<0||r.duration===0||a+Math.ceil(i*r.timescale/l)>r.duration)throw Z(`edit list beyond the media`)}}}async function wt(e,t,n){let r=await e.child(t,`stsz`);if(!r)throw await e.child(t,`stz2`)?Z(`compact sample sizes`):k(`mp4`,`missing stsz box`);let i=await e.view(r.body+4,8),a=i.getUint32(0),o=i.getUint32(4);if(a===0&&r.body+12+o*4>r.end)throw k(`mp4`,`stsz table exceeds its box`);let s=await e.need(t,`stsc`),c=(await e.view(s.body+4,4)).getUint32(0);if(s.body+8+c*12>s.end)throw k(`mp4`,`stsc table exceeds its box`);let l=await e.child(t,`stco`)??await e.child(t,`co64`);if(!l)throw k(`mp4`,`missing chunk offsets`);let u=l.type===`co64`,d=(await e.view(l.body+4,4)).getUint32(0);if(l.body+8+d*(u?8:4)>l.end)throw k(`mp4`,`chunk offsets exceed their box`);let f=0,p=0,m=0;for(let t=1;t<=d;t+=1){for(;p<c;){let n=await e.view(s.body+8+p*12,12);if(n.getUint32(0)>t)break;m=n.getUint32(4),p+=1}let i=await e.view(l.body+8+(t-1)*(u?8:4),u?8:4),d=u?i.getUint32(0)*2**32+i.getUint32(4):i.getUint32(0);for(let t=0;t<m;t+=1){if(f>=o)throw k(`mp4`,`the sample tables disagree`);let t=a===0?(await e.view(r.body+12+f*4,4)).getUint32(0):a;if(d+t>n)throw k(`mp4`,`a sample lies outside the file`);d+=t,f+=1}}if(f!==o)throw k(`mp4`,`the sample tables disagree`);return o}var Tt={1:[44100,48e3,32e3],2:[22050,24e3,16e3],2.5:[11025,12e3,8e3]},Et={"1-1":[0,32,64,96,128,160,192,224,256,288,320,352,384,416,448],"1-2":[0,32,48,56,64,80,96,112,128,160,192,224,256,320,384],"1-3":[0,32,40,48,56,64,80,96,112,128,160,192,224,256,320],"2-1":[0,32,48,56,64,80,96,112,128,144,160,176,192,224,256],"2-2":[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160],"2-3":[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160]};function Q(e,t){let n=e[t],r=e[t+1],i=e[t+2],a=e[t+3];if(n!==255||r===void 0||i===void 0||a===void 0||(r&224)!=224)return;let o=r>>3&3,s=r>>1&3,c=i>>4,l=i>>2&3;if(o===1||s===0||c===0||c===15||l===3||(a&3)==2)return;let u=o===3?1:o===2?2:2.5,d=4-s,f=Tt[u]?.[l],p=Et[`${u===1?1:2}-${d}`]?.[c]*1e3,m=i>>1&1,h=a>>6==3?1:2,g,_;if(d===1?(g=384,_=(Math.floor(12*p/f)+m)*4):d===2||u===1?(g=1152,_=Math.floor(144*p/f)+m):(g=576,_=Math.floor(72*p/f)+m),!(_<4))return{version:u,layer:d,sampleRate:f,channels:h,samplesPerFrame:g,frameLength:_,protected:!(r&1)}}function Dt(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=t=>t+4<=e.length?String.fromCharCode(...e.subarray(t,t+4)):``,i=t.version===1?t.channels===1?17:32:t.channels===1?9:17,a=4+(t.protected?2:0)+i,o=r(a);if(o===`Xing`||o===`Info`){if(a+8>e.length)return;let t=n.getUint32(a+4);a+=8;let i;if(t&1){if(a+4>e.length)return;i=n.getUint32(a),a+=4}if(t&2&&(a+=4),t&4&&(a+=100),t&8&&(a+=4),a+24<=e.length&&r(a)===`LAME`){let t=e[a+21]*65536+e[a+22]*256+e[a+23];return{...i===void 0?{}:{frames:i},delay:t>>12,padding:t&4095}}return i===void 0?{}:{frames:i}}if(r(36)===`VBRI`&&54<=e.length)return{delay:n.getUint16(42),frames:n.getUint32(50)}}var Ot=65536,kt=(e,t)=>e.version===t.version&&e.layer===t.layer&&e.sampleRate===t.sampleRate;async function At(e,t){return P(s(e),t,Ot,Q,e=>e.frameLength,kt)}function jt(e,t,n){let r=e.sampleRate<t?Math.ceil(t/e.sampleRate):1;return e.samplesPerFrame*r*Math.ceil(e.channels/n)}async function Mt(e,t){let n=s(e),r=await P(n,t,Ot,Q,e=>e.frameLength,kt);if(!r)throw k(`mp3`,`no frames`);let{sampleRate:i,channels:a,samplesPerFrame:o}=r.first,c=Dt(await n.bytes(r.offset,r.first.frameLength),r.first),l=0,u=0;if(await Ce(n,r.offset,4,Q,e=>e.frameLength,(e,t)=>{l+=jt(e,i,a),t&&(u+=1)}),l===0)throw k(`mp3`,`no frames`);let d=c?.delay??0,f=c?.padding??0,p=u*o;if(c?.frames!==void 0){let e=c.frames*o;if(e>l)throw k(`mp3`,`the tag claims more than the frames carry`);p=Math.max(0,e-d-f)}return{container:`mp3`,codec:`mp3`,sampleRate:i,channels:a,frameBound:l,expectedFrames:Math.min(p,l),frameTolerance:2*o+d+f}}function Nt(e,t){return new O(`UNSUPPORTED_FORMAT`,`This container or codec isn't supported.`,{details:t===void 0?{container:e}:{container:e,codec:t}})}async function Pt(e){let t=s(e),n=await t.bytes(0,64),r=(e,t)=>String.fromCharCode(...n.subarray(e,t)),i=r(0,4),a=r(8,12);if((i===`RIFF`||i===`RF64`)&&a===`WAVE`||i===`FORM`&&(a===`AIFF`||a===`AIFC`))return be(e);if(i===`fLaC`)return{probe:await Pe(e)};if(n[0]===26&&n[1]===69&&n[2]===223&&n[3]===163)return{probe:await _t(e)};if([`ftyp`,`moov`,`mdat`,`free`,`skip`,`wide`].includes(r(4,8)))return{probe:await St(e)};let o=Me(n);if(o>0){let n=await t.bytes(o,4);if(String.fromCharCode(...n)===`fLaC`)return{probe:await Pe(e)}}if(i===`OggS`){let r=n[26]??0,i=await t.bytes(27+r,8);if(Re(i))return{probe:await ze(e)};if(Ve(i))return{probe:await Ge(e)};if(qe(i))return{probe:await Ye(e)};throw Nt(`ogg`)}let[c,l]=await Promise.all([At(e,o),De(e,o)]);if(c&&(!l||c.offset<=l.offset))return{probe:await Mt(e,o)};if(l)return{probe:await Oe(e,o)};throw Nt(`unknown`)}var Ft=16,It=512,Lt=9,Rt=.945;function zt(e){let t=1,n=1,r=e*e/4;for(let e=1;n>t*1e-17;e+=1)n*=r/(e*e),t+=n;return t}var Bt;function Vt(){if(Bt)return Bt;let e=Ft*It,t=/* @__PURE__ */ new Float64Array(8194),n=zt(Lt);for(let r=0;r<=e;r+=1){let e=r/It,i=r===0?1:Math.sin(Math.PI*e)/(Math.PI*e),a=e/Ft,o=zt(Lt*Math.sqrt(Math.max(0,1-a*a)))/n;t[r]=i*o}return t[e]=0,Bt=t,t}var $=(e,t)=>Number.isSafeInteger(e)&&e>=t;function Ht(e,t){return Math.ceil(Ft/(Math.min(1,t/e)*Rt))}function Ut(e){let{input:t,inputStart:n,fromRate:r,toRate:i,start:a,frames:o}=e;if(!$(r,1)||!$(i,1)||!$(a,0)||!$(o,0)||!$(n,0)||!Number.isSafeInteger((a+o)*r))throw RangeError(`Rates and positions must be whole numbers, and rates positive.`);let s=Vt(),c=Math.min(1,i/r)*Rt,l=Ht(r,i),u=c*It,d=2*l,f=new Float32Array(o),p=t.length,m=i/Wt(r,i),h=i/m,g=[],_=e=>{let t=new Float64Array(d),n=e/m,r=0;for(let e=0;e<d;e+=1){let i=Math.abs(n-(e-l+1))*u,a=Math.floor(i);if(a>=s.length-1)continue;let o=s[a],c=o+(s[a+1]-o)*(i-a);t[e]=c,r+=c}for(let e=0;e<d;e+=1)t[e]=t[e]/r;return t};for(let e=0;e<o;e+=1){let o=(a+e)*r,s=Math.floor(o/i),c=(o-s*i)/h,u=g[c];u||(u=_(c),g[c]=u);let m=s-l+1-n,v=Math.max(0,-m),y=Math.min(d,p-m),b=0;for(let e=v;e<y;e+=1)b+=t[m+e]*u[e];f[e]=b}return f}function Wt(e,t){let[n,r]=[e,t];for(;r!==0;)[n,r]=[r,n%r];return n}function Gt(e){return 10**(e/20)}function Kt(e,t){return e===`equalPower`?Math.sin(t*Math.PI/2):t}function qt(e,t){let n=e.end-e.start,r=Gt(e.gainDb),{fadeIn:i,fadeOut:a}=e;i.frames>0&&t<i.frames&&(r*=Kt(i.curve,t/i.frames));let o=n-1-t;return a.frames>0&&o<a.frames&&(r*=Kt(a.curve,Math.max(0,o)/a.frames)),r}function Jt(e,t){let n=Array.from({length:t},()=>Array(e).fill(0)),r=(e,t,r)=>{n[e][t]=r},i=Math.SQRT1_2;switch(`${e}>${t}`){case`1>2`:r(0,0,1),r(1,0,1);break;case`1>4`:r(0,0,1),r(1,0,1);break;case`1>6`:r(2,0,1);break;case`2>4`:case`2>6`:r(0,0,1),r(1,1,1);break;case`4>6`:r(0,0,1),r(1,1,1),r(4,2,1),r(5,3,1);break;case`2>1`:r(0,0,.5),r(0,1,.5);break;case`4>1`:for(let e=0;e<4;e+=1)r(0,e,.25);break;case`6>1`:r(0,0,i),r(0,1,i),r(0,2,1),r(0,4,.5),r(0,5,.5);break;case`4>2`:r(0,0,.5),r(0,2,.5),r(1,1,.5),r(1,3,.5);break;case`6>2`:r(0,0,1),r(0,2,i),r(0,4,i),r(1,1,1),r(1,2,i),r(1,5,i);break;case`6>4`:r(0,0,1),r(0,2,i),r(1,1,1),r(1,2,i),r(2,4,1),r(3,5,1);break;default:for(let n=0;n<Math.min(e,t);n+=1)r(n,n,1)}return n}function Yt(e){let{channels:t,frames:n,segments:r}=e,i=Array.from({length:t},()=>new Float64Array(n));for(let e of r){let n=Jt(e.samples.length,t);for(let r=0;r<e.samples.length;r+=1){let a=e.samples[r];for(let o=0;o<t;o+=1){let t=n[o][r];if(t===0)continue;let s=i[o];for(let n=0;n<e.frames;n+=1){let r=qt(e.clip,e.within+n)*e.gain;s[e.at+n]=s[e.at+n]+t*a[n]*r}}}}let a=Array.from({length:t},()=>new Float32Array(n)),o=0,s=0;for(let r=0;r<n;r+=1){let n=!1;for(let s=0;s<t;s+=1){let t=i[s][r]*e.gain,c=Math.abs(t);c>o&&(o=c),c>1&&(n=!0),a[s][r]=Math.max(-1,Math.min(1,t))}n&&(s+=1)}return{channels:a,peak:o,clipped:s}}var Xt={pcm16:2,pcm24:3,float32:4};function Zt(e){return Xt[e]}function Qt(e){return e.frames*e.channels*Xt[e.sampleFormat]}var $t=4294967295,en=[[`title`,`INAM`],[`artist`,`IART`],[`album`,`IPRD`],[`year`,`ICRD`],[`comment`,`ICMT`]];function tn(e){let t=new TextEncoder;return en.flatMap(([n,r])=>{let i=e[n];return i===``?[]:[{id:r,value:t.encode(`${i}\0`)}]})}function nn(e){return e.length===0?0:4+e.reduce((e,{value:t})=>e+8+t.length+t.length%2,0)}function rn(e,t=tn(e.metadata)){let{channels:n,frames:r,sampleFormat:i}=e,a=Zt(i),o=i===`float32`,s=n>2||a>2,c=s?40:o?18:16,l=nn(t),u=Qt(e),d=u%2,f=8+c+(o?12:0)+(l?8+l:0)+8+u+d,p=4+f,m=p>$t||u>$t||r>$t,h=12+(m?36:0)+f;return{bytes:a,float:o,extensible:s,fmtSize:c,infoSize:l,data:u,pad:d,riffSize:p,rf64:m,headerSize:h-u-d,fileSize:h}}var an=1,on=3,sn=65534,cn=[0,0,0,0,16,0,128,0,0,170,0,56,155,113],ln={1:4,2:3,4:51,6:63},un=4294967295,dn=class{bytes;view;at=0;constructor(e){this.bytes=new Uint8Array(e),this.view=new DataView(this.bytes.buffer)}text(e){for(let t=0;t<e.length;t+=1)this.bytes[this.at+t]=e.charCodeAt(t);this.at+=e.length}u16(e){this.view.setUint16(this.at,e,!0),this.at+=2}u32(e){this.view.setUint32(this.at,e,!0),this.at+=4}u64(e){this.u32(e%2**32),this.u32(Math.floor(e/2**32))}raw(e){this.bytes.set(e,this.at),this.at+=e.length}};function fn(e){if(e.length===0)return;let t=new dn(nn(e));t.text(`INFO`);for(let{id:n,value:r}of e)t.text(n),t.u32(r.length),t.raw(r),r.length%2==1&&(t.at+=1);return t.bytes}function pn(e){let{sampleRate:t,channels:n,frames:r,metadata:i}=e,a=tn(i),{bytes:o,float:s,extensible:c,fmtSize:l,data:u,riffSize:d,rf64:f,headerSize:p}=rn(e,a),m=fn(a),h=new dn(p);h.text(f?`RF64`:`RIFF`),h.u32(f?un:d),h.text(`WAVE`),f&&(h.text(`ds64`),h.u32(28),h.u64(d+36),h.u64(u),h.u64(r),h.u32(0)),h.text(`fmt `),h.u32(l);let g=s?on:an;if(h.u16(c?sn:g),h.u16(n),h.u32(t),h.u32(t*n*o),h.u16(n*o),h.u16(o*8),c){h.u16(22),h.u16(o*8),h.u32(ln[n]??0),h.u16(g);for(let e of cn)h.bytes[h.at++]=e}else s&&h.u16(0);return s&&(h.text(`fact`),h.u32(4),h.u32(f?un:r)),m&&(h.text(`LIST`),h.u32(m.length),h.raw(m)),h.text(`data`),h.u32(f?un:u),h.bytes}function mn(e){return e<0?-Math.round(-e):Math.round(e)}function hn(e,t){let n=Number.isFinite(e)?Math.max(-1,Math.min(1,e)):0;if(t===`float32`)return Math.fround(n);let r=t===`pcm16`?32768:8388608;return Math.min(r-1,mn(n*r))+0}function gn(e,t,n){let r=Zt(n),i=new Uint8Array(t*e.length*r),a=new DataView(i.buffer),o=0;for(let i=0;i<t;i+=1)for(let t of e){let e=hn(t[i]??0,n);n===`float32`?a.setFloat32(o,e,!0):n===`pcm16`?a.setInt16(o,e,!0):(a.setUint8(o,e&255),a.setUint8(o+1,e>>8&255),a.setUint8(o+2,e>>16&255)),o+=r}return i}function _n(e){let{channels:t,peak:n,clipped:r}=Yt(e);return{bytes:gn(t,e.frames,e.sampleFormat),peak:n,clipped:r}}function vn(e){te({probe:({file:e})=>Pt(e),async readBlock({file:e,layout:t,start:n,frames:r,bucket:i}){let a=await xe(e,t,n,r);return{channels:a,...Se(a,i)}},peaks:({channels:e,bucket:t})=>Se(e,t),resample:({channels:e,...t})=>e.map(e=>Ut({input:e,...t})),wavHeader:e=>pn(e),renderBlock:e=>_n(e)},{...e,packageVersion:`0.7.2`})}vn();
package/dist/element.js CHANGED
@@ -1,4 +1,4 @@
1
- import { l as ElementListenersContext, t as AudioEditor } from "./shared/AudioEditor-C9yohR_Z.js";
1
+ import { l as ElementListenersContext, t as AudioEditor } from "./shared/AudioEditor-8YuNyAXN.js";
2
2
  import { useEffect, useMemo, useRef } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  import { createEditorElement } from "@hussmartinez/sdk-core/element";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as createAudioOutput, B as clipEnd, C as onlyFields, E as createAudioProcessor, F as MAX_TRACK_NAME_LENGTH, G as AudioError, H as planLength, I as MIN_GAIN_DB, K as isAudioError, L as NO_FADE, M as gainAt, N as EMPTY_METADATA, P as MAX_GAIN_DB, R as audibleTracks, S as longerThan, T as audioLimits, U as trackLength, V as clipLength, W as createAudioEngine, _ as MAX_METADATA_LENGTH, a as createAudioSession, b as isKey, c as formatTimecode, d as MAX_SOURCE_NAME_LENGTH, f as peakColumns, g as Invalid, h as refuse, i as watchPlayhead, j as dbToGain, k as mixLength, l as framesToSeconds, m as checkUniqueKeys, n as audioWarningText, p as checkTrack, r as audioMessages, s as connectOutput, t as audioErrorText, u as secondsToFrames, v as checkClipBody, w as audioLimitDefinitions, x as isRecord, y as invalid, z as clipAt } from "./shared/text-CgDrmmTa.js";
1
+ import { A as createAudioOutput, B as clipEnd, C as onlyFields, E as createAudioProcessor, F as MAX_TRACK_NAME_LENGTH, G as AudioError, H as planLength, I as MIN_GAIN_DB, K as isAudioError, L as NO_FADE, M as gainAt, N as EMPTY_METADATA, P as MAX_GAIN_DB, R as audibleTracks, S as longerThan, T as audioLimits, U as trackLength, V as clipLength, W as createAudioEngine, _ as MAX_METADATA_LENGTH, a as createAudioSession, b as isKey, c as formatTimecode, d as MAX_SOURCE_NAME_LENGTH, f as peakColumns, g as Invalid, h as refuse, i as watchPlayhead, j as dbToGain, k as mixLength, l as framesToSeconds, m as checkUniqueKeys, n as audioWarningText, p as checkTrack, r as audioMessages, s as connectOutput, t as audioErrorText, u as secondsToFrames, v as checkClipBody, w as audioLimitDefinitions, x as isRecord, y as invalid, z as clipAt } from "./shared/text-D74Ggdbh.js";
2
2
  // src/adapters/audio-adapters.ts
3
3
  function createAudioAdapters(options = {}) {
4
4
  const worker = {