@hussmartinez/audio-sdk 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +133 -2
- package/dist/assets/audio/audio.worker.js +1 -0
- package/dist/element.d.ts +12 -0
- package/dist/element.js +0 -0
- package/dist/index.d.ts +1412 -0
- package/dist/index.js +1453 -0
- package/dist/index.js.map +1 -0
- package/dist/lazy/inline-worker-CkUV_wKW.js +30 -0
- package/dist/lazy/inline-worker-CkUV_wKW.js.map +1 -0
- package/dist/react.d.ts +12 -0
- package/dist/react.js +1 -0
- package/dist/styles.css +9 -0
- package/package.json +110 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,134 @@
|
|
|
1
|
-
#
|
|
1
|
+
# audio-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A client-side audio SDK: trim, split, fade, adjust gain 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
|
+
|
|
5
|
+
This repository will publish **`@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
|
+
|
|
7
|
+
> Status: being bootstrapped. No packages are published yet.
|
|
8
|
+
|
|
9
|
+
## Using the engine
|
|
10
|
+
|
|
11
|
+
> The session, editor and custom element come later. What's shipped so far is the engine: it reads audio files safely and decodes them on the user's device.
|
|
12
|
+
|
|
13
|
+
`createAudioEngine()` probes a file in a Web Worker, which reads its headers and walks its frames to bound how much audio it can decode to. Check that against your file policy, then decode it and build its waveform overview:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
audioLimits,
|
|
18
|
+
audioMessages,
|
|
19
|
+
createAudioEngine,
|
|
20
|
+
isAudioError,
|
|
21
|
+
} from "@hussmartinez/audio-sdk";
|
|
22
|
+
import { checkFile, createMessages, withProcessingTime } from "@hussmartinez/sdk-core";
|
|
23
|
+
|
|
24
|
+
const policy = audioLimits.resolve({ maxDuration: 30 * 60 * 1_000 }); // or {} for the defaults
|
|
25
|
+
const engine = createAudioEngine();
|
|
26
|
+
const messages = createMessages(audioMessages, { locale: navigator.language });
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
checkFile(policy, file); // the size, before anything is read
|
|
30
|
+
const probe = await engine.probe(file);
|
|
31
|
+
// The bound, never a length a header declares (docs/adr/0004).
|
|
32
|
+
policy.check("maxChannels", probe.channels);
|
|
33
|
+
policy.check("maxSampleRate", probe.sampleRate);
|
|
34
|
+
policy.check("maxDuration", (probe.frameBound / probe.sampleRate) * 1_000);
|
|
35
|
+
policy.check("maxDecodedSize", probe.frameBound * probe.channels * 4);
|
|
36
|
+
|
|
37
|
+
const audio = await withProcessingTime(policy, (signal) =>
|
|
38
|
+
engine.decode(file, probe, { signal, onProgress: (fraction) => showProgress(fraction) }),
|
|
39
|
+
);
|
|
40
|
+
const peaks = await engine.peaks(audio);
|
|
41
|
+
// audio is an AudioBuffer at the file's own sample rate.
|
|
42
|
+
} catch (error) {
|
|
43
|
+
showError(messages.error(error)); // text by code, never the error's message
|
|
44
|
+
if (isAudioError(error, "DECODE_FAILED")) suggestConvertingToWav();
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`check` returns `"warning"` from a limit's warning threshold, so you can tell people that a long file may be slow. `withProcessingTime` applies `maxProcessingTime`: when it runs out, the engine stops waiting at once and rejects with `PROCESSING_TIME_EXCEEDED`, even if the browser's decoder never finishes (sdk-core [ADR 0031](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0031-platform-decoders-on-the-page.md)).
|
|
49
|
+
|
|
50
|
+
### Formats
|
|
51
|
+
|
|
52
|
+
| Container | Codecs | Decoded by |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| WAV (RIFF, RF64) | PCM 8 to 32-bit, float 32 and 64-bit, plain and extensible | the SDK, in its worker |
|
|
55
|
+
| AIFF, AIFC | PCM 8 to 32-bit, big and little-endian, float 32 and 64-bit | the SDK, in its worker |
|
|
56
|
+
| FLAC | FLAC | the browser |
|
|
57
|
+
| MP3 | MPEG-1, 2 and 2.5, layers I to III; not free format | the browser |
|
|
58
|
+
| ADTS | AAC, including HE-AAC | the browser |
|
|
59
|
+
| MP4, M4A | AAC or ALAC, one audio track; not fragmented | the browser |
|
|
60
|
+
| Ogg | Opus, Vorbis or FLAC, one stream | the browser |
|
|
61
|
+
| WebM, Matroska | Opus, Vorbis, FLAC or AAC, one audio track, other tracks ignored | the browser |
|
|
62
|
+
|
|
63
|
+
**Compressed formats decode with the browser's own decoders**, on the page, so which of them open varies by browser: a file the browser can't decode fails with `DECODE_FAILED`. [`docs/capabilities.md`](docs/capabilities.md) shows which decode in Chromium, Firefox and WebKit, measured by the end-to-end suite. Before any decoder sees a file, the SDK's own readers bound it from its frames or packets, and refuse what they can't bound. [ADR 0001](docs/adr/0001-audio-engines.md) has the rules for each format.
|
|
64
|
+
|
|
65
|
+
### Worker and Content Security Policy
|
|
66
|
+
|
|
67
|
+
| Mode | How | Directives |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| Inline (the default) | `createAudioEngine()`: the worker is inlined and starts from a `blob:` URL | `worker-src blob:` |
|
|
70
|
+
| Self-hosted | `createAudioEngine({ assetsUrl: "/audio-sdk/" })`: serve the package's `dist/assets/` there; the worker is `audio/audio.worker.js` | `worker-src 'self'` |
|
|
71
|
+
|
|
72
|
+
Neither mode needs `'unsafe-eval'` or `'wasm-unsafe-eval'`, and the SDK makes no network requests of its own ([ADR 0002](docs/adr/0002-workers-and-assets.md)).
|
|
73
|
+
|
|
74
|
+
**Copy `dist/assets` again after every upgrade.** A self-hosted worker from another version of the SDK is refused with `WORKER_START_FAILED`, whose `details` name the file and both versions.
|
|
75
|
+
|
|
76
|
+
### Errors
|
|
77
|
+
|
|
78
|
+
Every failure is an `AudioError` with a stable `code` and structured `details`; `isAudioError(error, code)` checks one, across workers and copies of the package. Show people the text for the code from `audioMessages` through `createMessages`, never `error.message`. The codes are:
|
|
79
|
+
|
|
80
|
+
| Code | When |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `INVALID_AUDIO` | A file is malformed, its headers claim more than its frames carry, or it decodes to more than its bound |
|
|
83
|
+
| `UNSUPPORTED_FORMAT` | A container, codec or layout the SDK doesn't read, or a file it can't bound |
|
|
84
|
+
| `DECODE_FAILED` | The browser couldn't decode a file the SDK probed, or decoded no audio from it |
|
|
85
|
+
| `FILE_TOO_LARGE`, `DECODED_SIZE_TOO_LARGE`, `DURATION_TOO_LONG`, `TOO_MANY_CHANNELS`, `SAMPLE_RATE_TOO_HIGH` | A file exceeds a limit; `details` name it, with its maximum and the actual value ([ADR 0004](docs/adr/0004-audio-limits.md)) |
|
|
86
|
+
| `PROCESSING_TIME_EXCEEDED` | `maxProcessingTime` ran out |
|
|
87
|
+
| `ABORTED`, `TIMEOUT` | The call's `signal` aborted |
|
|
88
|
+
| `UNSUPPORTED_ENVIRONMENT` | The browser lacks a feature, such as Web Audio, which `details.feature` names |
|
|
89
|
+
| `WORKER_START_FAILED`, `WORKER_CRASHED` and other `WORKER_*` codes | The worker couldn't start, stopped unexpectedly, or is from another version |
|
|
90
|
+
|
|
91
|
+
`TOO_MANY_FILES`, `SESSION_TOO_LARGE`, `TOO_MANY_CLIPS` and `INVALID_COMMAND` come with the session.
|
|
92
|
+
|
|
93
|
+
## Development
|
|
94
|
+
|
|
95
|
+
The repository root is the published package, laid out as in the family's [standard layout](https://github.com/ie-huss-martinez/sdk-core/blob/main/STANDARDS.md#repository-layout): the source is in [`src`](src), and the pnpm workspace adds [`examples/`](examples), which consume the built package as hosts do, and [`e2e/`](e2e), the end-to-end suite.
|
|
96
|
+
|
|
97
|
+
You need Node 24 (see [`.node-version`](.node-version)) and pnpm. The exact pnpm version is pinned in `package.json`, and pnpm switches to it automatically.
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
pnpm install # also installs the git hooks
|
|
101
|
+
pnpm verify # everything CI runs
|
|
102
|
+
pnpm verify:fast # the subset the pre-push hook runs
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Browser tests need Playwright's browsers once: `pnpm exec playwright install chromium`, plus `firefox webkit` to run all three engines with `CI=1` or `pnpm test:browser:all`.
|
|
106
|
+
|
|
107
|
+
`pnpm verify` runs, in order:
|
|
108
|
+
|
|
109
|
+
| Step | Script | Tool |
|
|
110
|
+
|---|---|---|
|
|
111
|
+
| Format and lint | `lint` | Biome |
|
|
112
|
+
| CSS rules | `lint:css` | stylelint, with the `hm-` namespace and token rules |
|
|
113
|
+
| Types | `typecheck` | TypeScript |
|
|
114
|
+
| Dependency rules | `lint:deps` | dependency-cruiser, through `hm-lint-deps` |
|
|
115
|
+
| Build | `build` | Vite, then api-extractor for the type declarations |
|
|
116
|
+
| Unit tests | `test` | Vitest |
|
|
117
|
+
| Browser tests | `test:browser` | Vitest in Chromium, and in Firefox and WebKit too in CI |
|
|
118
|
+
| Examples | `build:examples` | Vite, building `examples/vite` against the built package |
|
|
119
|
+
| End-to-end tests | `test:e2e` | Playwright against the built example: the [codec capability matrix](docs/capabilities.md), no requests to other origins, and the self-hosted worker under a strict Content Security Policy |
|
|
120
|
+
| Size budgets | `check:size` | size-limit, brotli size of each entry point |
|
|
121
|
+
| API reports | `check:api` | api-extractor, one report per entry point in [`api`](api) |
|
|
122
|
+
| Package checks | `check:package` | publint and Are the Types Wrong? |
|
|
123
|
+
|
|
124
|
+
The configuration extends the shared presets in [`@hussmartinez/sdk-config`](https://www.npmjs.com/package/@hussmartinez/sdk-config). The git hooks ([ADR 0016](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0016-git-hooks-and-merge-guards.md)) run automatically: a secret scan and lint of staged files on commit, a Conventional Commits check of the message, and `pnpm verify:fast` on push.
|
|
125
|
+
|
|
126
|
+
When a change alters the public API on purpose, update the reports with `pnpm api:update` and commit them.
|
|
127
|
+
|
|
128
|
+
## Contributing
|
|
129
|
+
|
|
130
|
+
Read [`CONTRIBUTING.md`](CONTRIBUTING.md) before opening a pull request. Coding agents also start with [`AGENTS.md`](AGENTS.md). Everyone taking part follows the [code of conduct](CODE_OF_CONDUCT.md). Report vulnerabilities privately, as described in the [security policy](SECURITY.md).
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
[Apache-2.0](LICENSE)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),t=class extends Error{name=`SdkError`;code;constructor(t,n,r={}){super(n,`cause`in r?{cause:r.cause}:void 0),this.code=t,Object.defineProperty(this,e,{value:!0}),r.details!==void 0&&(this.details=r.details)}};function n(n,r){if(typeof n!=`object`||!n)return!1;let i=n;return(n instanceof t||i[e]===!0)&&typeof i.code==`string`&&typeof i.message==`string`&&(r===void 0||i.code===r)}var r=1<<20;function i(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 a(e,t={}){let n=t.windowSize??r;i(`window size`,n,1);let a=e.size,o=0,s=/* @__PURE__ */ new Uint8Array;return{size:a,async bytes(t,r){i(`offset`,t,0),i(`length`,r,0);let c=Math.min(t,a),l=Math.min(a,c+r);if(c<o||l>o+s.length){let t=Math.min(a,c+Math.max(r,n));s=new Uint8Array(await e.slice(c,t).arrayBuffer()),o=c}return s.subarray(c-o,l-o)}}}var o=8,s=16,c=`UNKNOWN`;function l(e,t={}){let n=t.includeStack??!1,r=h(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=u(e),s=n&&p(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),p(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function u(e){if(n(e)){let t={name:e.name,code:e.code,message:e.message},n=d(e.details);return n!==void 0&&(t.details=n),t}if(p(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:c,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:c,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:c,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function d(e){if(!m(e))return;let t=f(e,0);return m(t)?t:void 0}function f(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>=s)){if(Array.isArray(e))return e.flatMap(e=>{let n=f(e,t+1);return n===void 0?[]:[n]});if(m(e)){let n={};for(let[r,i]of Object.entries(e)){let e=f(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function p(e){return typeof e==`object`&&!!e}function m(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function h(e){if(e===void 0)return o;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 g=`hm-rpc`;function _(e){return{protocol:g,version:1,...e}}function v(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 y(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=x(e)?e:S(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return w(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))}):T(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),E(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function b(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function x(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function S(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 C=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function w(e){let t=globalThis;return C.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function T(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function E(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 D(e,n={}){let r=n.scope??globalThis,i=n.includeStack??!1,a=/* @__PURE__ */ new Map,o=(e,t=[])=>{r.postMessage(e,t)},s=(e,t)=>{o(_({type:`error`,id:e,error:l(t,{includeStack:i})}))},c=(e,n,i)=>{let a=y(i,!0);try{b((e,t)=>r.postMessage(e,t),_({type:`result`,id:e,output:a.value}),a.transferables)}catch(r){s(e,new t(`WORKER_DATA_NOT_CLONEABLE`,`The result of "${n}" can't be sent to the page.`,{cause:r,details:{method:n}}))}},u=n=>{let{id:r,method:i}=n,l=Object.hasOwn(e,i)?e[i]:void 0;if(typeof l!=`function`){s(r,new t(`WORKER_METHOD_NOT_FOUND`,`The worker has no method "${i}".`,{details:{method:i}}));return}let u=new AbortController;a.set(r,u);let d={signal:u.signal,progress:e=>{a.get(r)===u&&o(_({type:`progress`,id:r,value:e}))}};Promise.resolve().then(()=>l.call(e,n.input,d)).then(e=>{a.delete(r),c(r,i,e)},e=>{a.delete(r),s(r,e)})},d=e=>{o(_({type:`crash`,error:l(e,{includeStack:i})}))};r.addEventListener(`message`,e=>{let t=v(e.data);t!==void 0&&t.version===1&&(t.type===`call`?u(t):t.type===`cancel`&&a.get(t.id)?.abort())}),r.addEventListener(`error`,e=>{let t=e;d(t.error??Error(t.message))}),r.addEventListener(`unhandledrejection`,e=>{d(e.reason)}),o(_({type:`ready`,...n.packageVersion===void 0?{}:{packageVersion:n.packageVersion}}))}var O=class extends t{name=`AudioError`},ee=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 te(e){let{container:t,channels:n,sampleRate:r,bytesPerSample:i,blockAlign:a,frames:o,dataOffset:s}=e;if(!Number.isInteger(n)||n<1||n>ee)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 ne={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 re(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 ie(e,t){if(e.byteLength<(t?22:18))throw k(`aiff`,`truncated COMM chunk`);let n=re(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 ae(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=ie(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=ne[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=te({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 oe(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=se(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 se(e,t,n){if(e===`float`)return t===8?(e,t)=>ce(Math.fround(e.getFloat64(t,n))):(e,t)=>ce(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 ce(e){return Number.isFinite(e)?e:0}var le=1,ue=3,de=65534,fe=[0,0,0,0,16,0,128,0,0,170,0,56,155,113],pe=4294967295;async function me(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 he(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===de){if(e.byteLength<40)throw k(`wav`,`truncated extensible fmt chunk`);t=e.getUint16(24,!0);for(let[t,n]of fe.entries())if(e.getUint8(26+t)!==n)throw A(`wav`,`extensible subformat`)}return{tag:t,...n}}function ge(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===le&&[1,2,3,4].includes(l))u=l===1?`uint`:`int`;else if(i===ue&&[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 te({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 _e(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=he(await j(e,u,Math.min(l,64)))}else if(c===`data`){let t=l;if(n===`RF64`&&l===pe){if(a===void 0)throw k(`wav`,`RF64 file without ds64 chunk`);t=a}else(l===pe||l===0&&!await me(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 ge(r,i.offset,i.size,i.declared)}async function ve(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 _e(e);else if(n===`FORM`&&(r===`AIFF`||r===`AIFC`))i=await ae(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 ye(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 oe(a,t,r)}function be(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 xe(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 Se=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];function Ce(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):Se[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=Se[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 we=(e,t)=>e.sampleRate===t.sampleRate&&e.channelConfiguration===t.channelConfiguration;async function Te(e,t){return P(a(e),t,65536,L,e=>e.frameLength,we)}async function Ee(e,t){let n=a(e),r=await P(n,t,65536,L,e=>e.frameLength,we);if(!r)throw k(`adts`,`no frames`);let i=r.first.sampleRate,o=I(i),s=F(r.first.channelConfiguration),c=1024*Math.ceil(o/i),l=0,u=0;if(await xe(n,r.offset,7,L,e=>e.frameLength,(e,t)=>{let n=Math.max(1,Math.ceil(o/e.sampleRate)),r=Math.ceil(F(e.channelConfiguration)/s);l+=e.blocks*1024*n*r,t&&(u+=e.blocks)}),l===0)throw k(`adts`,`no frames`);return{container:`adts`,codec:`aac`,sampleRate:o,channels:s,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 De=R(8,7);R(16,32773),R(32,79764919);function Oe(e,t=0,n=e.length){let r=0;for(let i=t;i<n;i+=1)r=De[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 ke=[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=ke[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&&Oe(e,t,t+l)===m)return{blockSize:f,sampleRate:p,channels:s<8?s+1:2,length:l+1}}function Ae(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 je(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 Me(e){let t=a(e),n=Ae(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 o=0,s=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&&(o+=je(t,i),s+=1)}}if(s===0)throw k(`flac`,`no audio frames`);if(i.totalFrames>o)throw k(`flac`,`STREAMINFO claims more than the frames carry`);return{container:`flac`,codec:`flac`,sampleRate:i.sampleRate,channels:i.channels,frameBound:o,expectedFrames:i.totalFrames>0?i.totalFrames:o,frameTolerance:i.maxBlockSize}}var H=27,Ne=65307,Pe=-1;async function U(e,t){let n=a(e),r,i=Pe,o=[],s=0,c=0,l=0;for(;c+H<=n.size;){let e=await n.bytes(c,Ne);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 a=new DataView(e.buffer,e.byteOffset,e.byteLength),u=a.getUint8(4),d=a.getUint8(5),f=a.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=a.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||(o=[],s=0);let _=H+f;for(let n=0;n<f;n+=1){let r=e[H+n];if(o.length<64){let t=Math.min(r,64-o.length);for(let n=0;n<t;n+=1)o.push(e[_+n])}s+=r,_+=r,r<255&&(t({head:Uint8Array.from(o),length:s}),o=[],s=0)}let v=a.getInt32(10,!0),y=a.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 Fe=13;function Ie(e){return e[0]===127&&e[1]===70&&e[2]===76&&e[3]===65&&e[4]===67}async function Le(e){let t,n=0,r=0,i=0,a=0,{lastGranule:o}=await U(e,({head:e})=>{if(n+=1,n===1){if(!Ie(e)||e[5]!==1)throw k(`ogg`,`not a FLAC mapping version 1`);let n=String.fromCharCode(...e.subarray(9,13)),i=(e[Fe]??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 Re=48e3,W=5760;function ze(e){return String.fromCharCode(...e.subarray(0,8))===`OpusHead`}function Be(e){return e<12?[480,960,1920,2880][e%4]:e<16?[480,960][e%2]:[120,240,480,960][e%4]}function Ve(e,t){let n=e[0];if(t===0||n===void 0)return W;let r=Be(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 He(e,t){if(!ze(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 Ue(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}=He(e,`ogg`));else if(r===2){if(String.fromCharCode(...e.subarray(0,8))!==`OpusTags`)throw k(`ogg`,`missing OpusTags`)}else i+=Ve(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:Re,channels:t,frameBound:i,expectedFrames:o,frameTolerance:Math.max(W,n)}}var We=`vorbis`;function Ge(e){return e[0]===1&&String.fromCharCode(...e.subarray(1,7))===We}function Ke(e,t){if(!Ge(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 qe(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}=Ke(e,`ogg`));else if(i===2||i===3){let t=i===2?3:5;if(e[0]!==t||String.fromCharCode(...e.subarray(1,7))!==We)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,Je=17026,Ye=408125543,Xe=357149030,Ze=2807729,Qe=17545,$e=374648427,et=174,tt=215,nt=131,rt=134,it=25506,at=524531317,ot=163,st=160,ct=161,lt=/* @__PURE__ */ new Set([at,475249515,307544935,272869232,423732329,290298740,Xe,$e,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 ut(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=ut(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=ut(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 dt(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 ft(e,t){if(e===`A_OPUS`){if(!t)throw k(`webm`,`missing OpusHead`);let e=He(t,`webm`);return{codec:`opus`,sampleRate:Re,channels:e.channels,tolerance:Math.max(W,e.preSkip),frameSamples:Ve}}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=Ke(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=Ce(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 pt(e){let t=[];for(let n of Y(e)){if(n.id!==et)continue;let e=Y(n.data),r=t=>e.find(e=>e.id===t)?.data,i=r(nt);if(!i||X(i)!==2)continue;let a=r(tt),o=r(rt);if(!a||!o)throw k(`webm`,`incomplete audio track`);let s=String.fromCharCode(...o).replace(/\0+$/,``);t.push({number:X(a),codec:ft(s,r(it))})}if(t.length===0)throw k(`webm`,`no audio track`);if(t.length>1)throw K(`several audio tracks`);return t[0]}function Z(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 mt(e){let t=a(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===Je),i=r?String.fromCharCode(...r.data).replace(/\0+$/,``):``;if(i!==`webm`&&i!==`matroska`)throw K(`document type ${i||`missing`}`);let o=await J(t,n.body+n.size);if(!o||o.id!==Ye)throw k(`webm`,`missing Segment`);let s=Math.min(t.size,o.body+(o.size??t.size)),c,l=1e6,u,d=0,f=0,p,m=o.body;for(;m<s;){let e=await J(t,m);if(!e)throw k(`webm`,`malformed element`);if(p!==void 0&&(m>=p||lt.has(e.id))&&(p=void 0),p===void 0){if(e.id===G)throw K(`several segments`);if(e.id===at){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>s)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>s)throw k(`webm`,`element exceeds its parent`);if(e.id===Xe){let n=Y(await t.bytes(e.body,e.size)),r=n.find(e=>e.id===Ze),i=n.find(e=>e.id===Qe);r&&(l=X(r.data)),i&&(u=dt(i.data))}else if(e.id===$e){if(c)throw K(`several Tracks elements`);c=pt(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,s))throw k(`webm`,`element exceeds its parent`);let r=c;if(e.id===ot)d+=Z(await t.bytes(e.body,e.size),r),f+=1;else if(e.id===st)for(let n of Y(await t.bytes(e.body,e.size)))n.id===ct&&(d+=Z(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 ht=1e5;function Q(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 gt=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>ht)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 _t(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 vt(e,t){let n=t.body+4,r=async r=>{if(await e.u8(n)!==r)throw Q(`unexpected ES descriptor`);let[i,a]=await _t(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 Q(`object type ${a}`,a===107||a===105?`mp3`:`unknown`);return n+=13,await r(5),Ce(await e.reader.bytes(n,Math.min(5,t.end-n)),`mp4`)}async function yt(e){let t=a(e),n=new gt(t),r=await n.children(0,t.size,!0);if(r.some(e=>e.type===`moof`))throw Q(`fragmented MP4`);let i=r.find(e=>e.type===`moov`);if(!i)throw k(`mp4`,`missing moov box`);let o=[];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&&o.push({trak:e,mdia:t})}if(o.length===0)throw k(`mp4`,`no audio track`);if(o.length>1)throw Q(`several audio tracks`);let{trak:s,mdia:c}=o[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 Q(`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 vt(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 Q(`codec ${g.type}`,g.type);await bt(n,i,s,{timescale:f,duration:p,decodeRate:C,tolerance:2*T});let E=await xt(n,m,t.size);if(E===0)throw k(`mp4`,`no audio samples`);let D=E*T,O=p===0?D:Math.round(p*C/f);if(O>D)throw k(`mp4`,`the duration claims more than the samples carry`);return{container:`mp4`,codec:S,sampleRate:C,channels:w,frameBound:D,expectedFrames:O,frameTolerance:2*T}}async function bt(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 Q(`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 Q(`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 Q(`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 Q(`edit list with an empty edit after another edit`);if(i*r.decodeRate/l>r.tolerance)throw Q(`edit list with a long empty edit`)}else{if(p)throw Q(`edit list with several media edits`);if(p=!0,s!==1||c!==0)throw Q(`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 Q(`edit list beyond the media`)}}}async function xt(e,t,n){let r=await e.child(t,`stsz`);if(!r)throw await e.child(t,`stz2`)?Q(`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 St={1:[44100,48e3,32e3],2:[22050,24e3,16e3],2.5:[11025,12e3,8e3]},Ct={"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 $(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=St[u]?.[l],p=Ct[`${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 wt(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 Tt=65536,Et=(e,t)=>e.version===t.version&&e.layer===t.layer&&e.sampleRate===t.sampleRate;async function Dt(e,t){return P(a(e),t,Tt,$,e=>e.frameLength,Et)}function Ot(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 kt(e,t){let n=a(e),r=await P(n,t,Tt,$,e=>e.frameLength,Et);if(!r)throw k(`mp3`,`no frames`);let{sampleRate:i,channels:o,samplesPerFrame:s}=r.first,c=wt(await n.bytes(r.offset,r.first.frameLength),r.first),l=0,u=0;if(await xe(n,r.offset,4,$,e=>e.frameLength,(e,t)=>{l+=Ot(e,i,o),t&&(u+=1)}),l===0)throw k(`mp3`,`no frames`);let d=c?.delay??0,f=c?.padding??0,p=u*s;if(c?.frames!==void 0){let e=c.frames*s;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:o,frameBound:l,expectedFrames:Math.min(p,l),frameTolerance:2*s+d+f}}function At(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 jt(e){let t=a(e),n=await t.bytes(0,64),r=(e,t)=>String.fromCharCode(...n.subarray(e,t)),i=r(0,4),o=r(8,12);if((i===`RIFF`||i===`RF64`)&&o===`WAVE`||i===`FORM`&&(o===`AIFF`||o===`AIFC`))return ve(e);if(i===`fLaC`)return{probe:await Me(e)};if(n[0]===26&&n[1]===69&&n[2]===223&&n[3]===163)return{probe:await mt(e)};if([`ftyp`,`moov`,`mdat`,`free`,`skip`,`wide`].includes(r(4,8)))return{probe:await yt(e)};let s=Ae(n);if(s>0){let n=await t.bytes(s,4);if(String.fromCharCode(...n)===`fLaC`)return{probe:await Me(e)}}if(i===`OggS`){let r=n[26]??0,i=await t.bytes(27+r,8);if(Ie(i))return{probe:await Le(e)};if(ze(i))return{probe:await Ue(e)};if(Ge(i))return{probe:await qe(e)};throw At(`ogg`)}let[c,l]=await Promise.all([Dt(e,s),Te(e,s)]);if(c&&(!l||c.offset<=l.offset))return{probe:await kt(e,s)};if(l)return{probe:await Ee(e,s)};throw At(`unknown`)}function Mt(e){D({probe:({file:e})=>jt(e),async readBlock({file:e,layout:t,start:n,frames:r,bucket:i}){let a=await ye(e,t,n,r);return{channels:a,...be(a,i)}},peaks:({channels:e,bucket:t})=>be(e,t)},{...e,packageVersion:`0.2.0`})}Mt();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `<hm-audio-editor>` custom element of the audio SDK.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Importing this entry registers nothing: applications call
|
|
6
|
+
* `defineAudioEditorElement()` themselves, and importing it on a server does
|
|
7
|
+
* nothing (ADR 0004, ADR 0007). The element arrives in a later release.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export { }
|
package/dist/element.js
ADDED
|
File without changes
|