@alpha2-sh/editor 0.4.6 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/bridge.d.ts +15 -16
- package/dist/browser/bridge.js +393 -312
- package/dist/browser/extensions-worker.d.ts +12 -16
- package/dist/browser/extensions-worker.js +17 -24
- package/dist/browser/hash-worker.d.ts +4 -5
- package/dist/browser/hash-worker.js +7 -8
- package/dist/browser/jobs.d.ts +17 -19
- package/dist/browser/jobs.js +41 -28
- package/dist/browser/resources.d.ts +6 -11
- package/dist/browser/resources.js +5 -9
- package/dist/browser/runtime/assets.d.ts +52 -28
- package/dist/browser/runtime/assets.js +136 -45
- package/dist/browser/runtime/audio.d.ts +16 -11
- package/dist/browser/runtime/audio.js +102 -59
- package/dist/browser/runtime/budget.d.ts +4 -5
- package/dist/browser/runtime/budget.js +4 -5
- package/dist/browser/runtime/caption-fonts.d.ts +3 -7
- package/dist/browser/runtime/caption-fonts.js +4 -8
- package/dist/browser/runtime/engine.d.ts +44 -44
- package/dist/browser/runtime/engine.js +87 -64
- package/dist/browser/runtime/export-audio.d.ts +6 -6
- package/dist/browser/runtime/export-audio.js +8 -9
- package/dist/browser/runtime/exporter.d.ts +33 -66
- package/dist/browser/runtime/exporter.js +111 -137
- package/dist/browser/runtime/extension-import.d.ts +28 -35
- package/dist/browser/runtime/extension-import.js +36 -46
- package/dist/browser/runtime/fingerprint.d.ts +11 -14
- package/dist/browser/runtime/fingerprint.js +20 -24
- package/dist/browser/runtime/generators.d.ts +2 -3
- package/dist/browser/runtime/generators.js +5 -7
- package/dist/browser/runtime/locks.d.ts +5 -7
- package/dist/browser/runtime/locks.js +5 -7
- package/dist/browser/runtime/output.d.ts +7 -9
- package/dist/browser/runtime/output.js +17 -21
- package/dist/browser/runtime/preview-utils.js +10 -6
- package/dist/browser/runtime/proxies.d.ts +19 -19
- package/dist/browser/runtime/proxies.js +72 -51
- package/dist/browser/runtime/proxy-storage.d.ts +15 -19
- package/dist/browser/runtime/proxy-storage.js +20 -24
- package/dist/browser/runtime/sources.d.ts +23 -31
- package/dist/browser/runtime/sources.js +85 -103
- package/dist/browser/runtime/staging.d.ts +2 -6
- package/dist/browser/runtime/staging.js +7 -11
- package/dist/browser/runtime/still.d.ts +2 -6
- package/dist/browser/runtime/still.js +6 -12
- package/dist/browser/runtime/text.d.ts +14 -0
- package/dist/browser/runtime/text.js +27 -0
- package/dist/browser/runtime/wasm.d.ts +4 -5
- package/dist/browser/runtime/wasm.js +4 -5
- package/dist/browser/types.d.ts +244 -239
- package/dist/browser/worker.d.ts +10 -10
- package/dist/browser/worker.js +64 -22
- package/dist/core/captions.d.ts +8 -10
- package/dist/core/captions.js +10 -18
- package/dist/core/clip-time.d.ts +8 -10
- package/dist/core/clip-time.js +12 -15
- package/dist/core/commands.d.ts +46 -46
- package/dist/core/commands.js +38 -36
- package/dist/core/compositions.d.ts +78 -112
- package/dist/core/compositions.js +66 -94
- package/dist/core/document.d.ts +59 -92
- package/dist/core/document.js +65 -90
- package/dist/core/keyframes.d.ts +11 -12
- package/dist/core/keyframes.js +11 -13
- package/dist/core/presets.d.ts +14 -20
- package/dist/core/presets.js +12 -18
- package/dist/core/session.d.ts +26 -38
- package/dist/core/session.js +38 -53
- package/dist/core/text.d.ts +2 -3
- package/dist/core/text.js +2 -3
- package/dist/core/timeline-index.d.ts +2 -3
- package/dist/core/timeline-index.js +11 -7
- package/dist/core/transitions.js +4 -5
- package/dist/core/validated.d.ts +6 -7
- package/dist/core/validated.js +8 -11
- package/dist/native-client/index.d.ts +31 -32
- package/dist/native-client/index.js +40 -41
- package/dist/ports/index.d.ts +19 -20
- package/dist/react/index.d.ts +5 -6
- package/dist/react/index.js +5 -6
- package/package.json +4 -4
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Whether the start of a file could be an SVG, a GIF, an animated WebP, an APNG, a Lottie or
|
|
3
|
-
* dotLottie, or an OpenEXR image.
|
|
4
|
-
*/
|
|
1
|
+
/** Whether a file's start could be SVG, GIF, animated WebP, APNG, Lottie, dotLottie or OpenEXR. */
|
|
5
2
|
export function mayBeExtension(head: any): boolean;
|
|
6
3
|
/**
|
|
7
|
-
* The
|
|
8
|
-
*
|
|
9
|
-
* `
|
|
10
|
-
*
|
|
11
|
-
* before it is read.
|
|
4
|
+
* The byte limit for a file that could be a document format a provider parses whole, by its start:
|
|
5
|
+
* dotLottie (ZIP, `MAX_PROVIDER_DOCUMENT_BYTES`), Lottie (JSON, `MAX_LOTTIE_DOCUMENT_BYTES`) or
|
|
6
|
+
* SVG (XML, `MAX_SVG_DOCUMENT_BYTES`), with the format's name; `null` for other files. Larger
|
|
7
|
+
* files are refused unread.
|
|
12
8
|
*/
|
|
13
9
|
export function providerDocumentLimit(head: any): {
|
|
14
10
|
limit: number;
|
|
@@ -17,8 +13,8 @@ export function providerDocumentLimit(head: any): {
|
|
|
17
13
|
/** The duration of a provider's timing in seconds, or 0 for a still. */
|
|
18
14
|
export function timingSeconds(timing: any): number;
|
|
19
15
|
/**
|
|
20
|
-
* A small preview of a rendered frame (premultiplied
|
|
21
|
-
* URL
|
|
16
|
+
* A small preview of a rendered frame (premultiplied sRGB RGBA8 or linear half floats) as an image
|
|
17
|
+
* URL at most {@link THUMBNAIL_WIDTH} wide. Only sampled pixels are converted.
|
|
22
18
|
*/
|
|
23
19
|
export function thumbnailOf(frame: any): Promise<{
|
|
24
20
|
dataUrl: any;
|
|
@@ -26,17 +22,15 @@ export function thumbnailOf(frame: any): Promise<{
|
|
|
26
22
|
height: number;
|
|
27
23
|
}>;
|
|
28
24
|
/**
|
|
29
|
-
* The provider a relinked file opens with: the defaults {@link stageProviderFile} staged
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* file is one whose primaries can be chosen.
|
|
25
|
+
* The provider a relinked file opens with: the defaults {@link stageProviderFile} staged, plus the
|
|
26
|
+
* choices `recorded` for the source where the new file still offers them (a package's animation,
|
|
27
|
+
* an OpenEXR still's primaries).
|
|
33
28
|
*/
|
|
34
29
|
export function keepProviderChoices(recorded: any, staged: any, report: any): any;
|
|
35
30
|
/**
|
|
36
|
-
* What import reads of
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* refused here.
|
|
31
|
+
* What import reads of `bytes` with provider module `extensions`: the claiming provider, the probe
|
|
32
|
+
* report and a first-frame thumbnail; `null` when no provider claims them. The source is opened as
|
|
33
|
+
* import records it, so a file that probes but does not open is refused here.
|
|
40
34
|
*
|
|
41
35
|
* @throws When a provider claims the bytes and cannot read them.
|
|
42
36
|
*/
|
|
@@ -55,13 +49,13 @@ export function readProviderFile(extensions: any, bytes: any): Promise<{
|
|
|
55
49
|
};
|
|
56
50
|
} | null>;
|
|
57
51
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
52
|
+
* An SVG's diagnostics when opened with font stack `fonts`, listing text no font draws
|
|
53
|
+
* (`missing_font`).
|
|
60
54
|
*/
|
|
61
55
|
export function svgDiagnostics(extensions: any, provider: any, bytes: any, fonts: any): any;
|
|
62
56
|
/**
|
|
63
|
-
* Stages a
|
|
64
|
-
*
|
|
57
|
+
* Stages a provider-claimed file from what {@link readProviderFile} read: a still SVG is an image
|
|
58
|
+
* source, an animation a video source of one cycle (repetition is the clip's).
|
|
65
59
|
*/
|
|
66
60
|
export function stageProviderFile(file: any, { report, provider, thumbnail }: {
|
|
67
61
|
report: any;
|
|
@@ -98,12 +92,11 @@ export function stageProviderFile(file: any, { report, provider, thumbnail }: {
|
|
|
98
92
|
};
|
|
99
93
|
};
|
|
100
94
|
/**
|
|
101
|
-
* How numbered files
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* between the first and last than a sequence may have. Nothing here walks the numbers between them.
|
|
95
|
+
* How numbered files form one image sequence from their names alone: the frame number before each
|
|
96
|
+
* name's extension fixes the order. Answers the first and last numbers, the frame count (every
|
|
97
|
+
* number between them), how many have no file, and the first few gaps. Otherwise answers why not:
|
|
98
|
+
* a name without a number, a duplicate number, a number past 2^53 - 1 (a document cannot hold it
|
|
99
|
+
* exactly), or too many frames. Never walks the numbers in between.
|
|
107
100
|
*
|
|
108
101
|
* @param {readonly string[]} names
|
|
109
102
|
* @returns {{ ok: true, first: number, last: number, frames: number, missing: number, gaps: number[] } | { ok: false, code: string, message: string }}
|
|
@@ -122,10 +115,10 @@ export function sequenceNumbering(names: readonly string[]): {
|
|
|
122
115
|
};
|
|
123
116
|
/**
|
|
124
117
|
* Stages numbered PNGs or OpenEXR images as one image sequence at `frameRate`. The numbers fix the
|
|
125
|
-
* order and
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
118
|
+
* order and first frame; a gap is refused unless `missing` holds or blanks it, and every frame must
|
|
119
|
+
* match the first one's format and size. `openExr(file)` returns the provider module's thumbnail
|
|
120
|
+
* and report for an OpenEXR first frame (see {@link exrFirstFrame}). `id` names the source (a
|
|
121
|
+
* relink uses the asset's own), new by default.
|
|
129
122
|
*/
|
|
130
123
|
export function stageSequence(files: any, { frameRate, missing, openExr, id }: {
|
|
131
124
|
frameRate: any;
|
|
@@ -183,8 +176,8 @@ export function stageSequence(files: any, { frameRate, missing, openExr, id }: {
|
|
|
183
176
|
dispose(): void;
|
|
184
177
|
}>;
|
|
185
178
|
/**
|
|
186
|
-
* An OpenEXR frame's thumbnail, sampled from the frame
|
|
187
|
-
* its own size
|
|
179
|
+
* An OpenEXR frame's thumbnail, sampled from the frame provider module `extensions` renders from
|
|
180
|
+
* `bytes` at its own size, with the provider's report.
|
|
188
181
|
*/
|
|
189
182
|
export function exrFirstFrame(extensions: any, bytes: any): Promise<{
|
|
190
183
|
thumbnail: {
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
// Importing media an extension provider reads. The provider is chosen by probing
|
|
2
|
-
//
|
|
1
|
+
// Importing media an extension provider reads. The provider is chosen by probing bytes, never by
|
|
2
|
+
// file name; the extensions wasm module loads only when the bytes could match one of its formats.
|
|
3
3
|
import { MAX_LOTTIE_DOCUMENT_BYTES, MAX_PROVIDER_DOCUMENT_BYTES, MAX_SEQUENCE_FRAMES, MAX_SVG_DOCUMENT_BYTES, } from "alpha2/project";
|
|
4
4
|
import { EditorError } from "../../core/document.js";
|
|
5
5
|
const TICKS_PER_SECOND = 120_000;
|
|
6
|
-
/**
|
|
7
|
-
* Whether the start of a file could be an SVG, a GIF, an animated WebP, an APNG, a Lottie or
|
|
8
|
-
* dotLottie, or an OpenEXR image.
|
|
9
|
-
*/
|
|
6
|
+
/** Whether a file's start could be SVG, GIF, animated WebP, APNG, Lottie, dotLottie or OpenEXR. */
|
|
10
7
|
export function mayBeExtension(head) {
|
|
11
8
|
const ascii = (at, text) => [...text].every((char, index) => head[at + index] === char.charCodeAt(0));
|
|
12
9
|
if (ascii(0, "GIF8") || isExr(head))
|
|
@@ -20,15 +17,14 @@ export function mayBeExtension(head) {
|
|
|
20
17
|
const text = new TextDecoder().decode(head);
|
|
21
18
|
if (/^\s*\{/.test(text))
|
|
22
19
|
return true;
|
|
23
|
-
// An SVG root may follow a prolog longer than the head, so XML
|
|
20
|
+
// An SVG root may follow a prolog longer than the head, so XML starting with one is probed.
|
|
24
21
|
return /<svg[\s>/]/.test(text) || /^\s*<[?!]/.test(text);
|
|
25
22
|
}
|
|
26
23
|
/**
|
|
27
|
-
* The
|
|
28
|
-
*
|
|
29
|
-
* `
|
|
30
|
-
*
|
|
31
|
-
* before it is read.
|
|
24
|
+
* The byte limit for a file that could be a document format a provider parses whole, by its start:
|
|
25
|
+
* dotLottie (ZIP, `MAX_PROVIDER_DOCUMENT_BYTES`), Lottie (JSON, `MAX_LOTTIE_DOCUMENT_BYTES`) or
|
|
26
|
+
* SVG (XML, `MAX_SVG_DOCUMENT_BYTES`), with the format's name; `null` for other files. Larger
|
|
27
|
+
* files are refused unread.
|
|
32
28
|
*/
|
|
33
29
|
export function providerDocumentLimit(head) {
|
|
34
30
|
if (head[0] === 0x50 &&
|
|
@@ -43,7 +39,6 @@ export function providerDocumentLimit(head) {
|
|
|
43
39
|
return { limit: MAX_SVG_DOCUMENT_BYTES, what: "SVG document" };
|
|
44
40
|
return null;
|
|
45
41
|
}
|
|
46
|
-
/** Whether bytes start as an OpenEXR file does. */
|
|
47
42
|
function isExr(head) {
|
|
48
43
|
return (head[0] === 0x76 && head[1] === 0x2f && head[2] === 0x31 && head[3] === 0x01);
|
|
49
44
|
}
|
|
@@ -68,7 +63,6 @@ export function timingSeconds(timing) {
|
|
|
68
63
|
return (timing.frames * timing.rate.den) / timing.rate.num;
|
|
69
64
|
return 0;
|
|
70
65
|
}
|
|
71
|
-
/** A half float's value from its bits. */
|
|
72
66
|
function halfValue(bits) {
|
|
73
67
|
const exponent = (bits >> 10) & 0x1f;
|
|
74
68
|
const fraction = bits & 0x3ff;
|
|
@@ -79,7 +73,7 @@ function halfValue(bits) {
|
|
|
79
73
|
return fraction ? Number.NaN : sign * Infinity;
|
|
80
74
|
return sign * (1 + fraction / 1024) * 2 ** (exponent - 15);
|
|
81
75
|
}
|
|
82
|
-
/**
|
|
76
|
+
/** The sRGB code (0 to 255) of a linear value, clipped to SDR. */
|
|
83
77
|
function srgbCode(linear) {
|
|
84
78
|
const value = Math.min(1, Math.max(0, linear));
|
|
85
79
|
const encoded = value <= 0.0031308 ? 12.92 * value : 1.055 * value ** (1 / 2.4) - 0.055;
|
|
@@ -88,8 +82,8 @@ function srgbCode(linear) {
|
|
|
88
82
|
/** A thumbnail's width, as an image sequence's PNG thumbnail has it. */
|
|
89
83
|
const THUMBNAIL_WIDTH = 160;
|
|
90
84
|
/**
|
|
91
|
-
* A small preview of a rendered frame (premultiplied
|
|
92
|
-
* URL
|
|
85
|
+
* A small preview of a rendered frame (premultiplied sRGB RGBA8 or linear half floats) as an image
|
|
86
|
+
* URL at most {@link THUMBNAIL_WIDTH} wide. Only sampled pixels are converted.
|
|
93
87
|
*/
|
|
94
88
|
export async function thumbnailOf(frame) {
|
|
95
89
|
const width = Math.min(THUMBNAIL_WIDTH, frame.width);
|
|
@@ -132,10 +126,9 @@ export async function thumbnailOf(frame) {
|
|
|
132
126
|
return { dataUrl, width, height };
|
|
133
127
|
}
|
|
134
128
|
/**
|
|
135
|
-
* The provider a relinked file opens with: the defaults {@link stageProviderFile} staged
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* file is one whose primaries can be chosen.
|
|
129
|
+
* The provider a relinked file opens with: the defaults {@link stageProviderFile} staged, plus the
|
|
130
|
+
* choices `recorded` for the source where the new file still offers them (a package's animation,
|
|
131
|
+
* an OpenEXR still's primaries).
|
|
139
132
|
*/
|
|
140
133
|
export function keepProviderChoices(recorded, staged, report) {
|
|
141
134
|
if (!recorded || !staged || recorded.format !== staged.format)
|
|
@@ -150,7 +143,7 @@ export function keepProviderChoices(recorded, staged, report) {
|
|
|
150
143
|
return { ...staged, primaries: recorded.primaries };
|
|
151
144
|
return staged;
|
|
152
145
|
}
|
|
153
|
-
/** The provider source import records for
|
|
146
|
+
/** The provider source import records for a probed file. */
|
|
154
147
|
function providerOf(report) {
|
|
155
148
|
if (report.format === "svg" || report.format === "exr")
|
|
156
149
|
return { format: report.format };
|
|
@@ -165,10 +158,9 @@ function providerOf(report) {
|
|
|
165
158
|
return { format: "animated_image" };
|
|
166
159
|
}
|
|
167
160
|
/**
|
|
168
|
-
* What import reads of
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* refused here.
|
|
161
|
+
* What import reads of `bytes` with provider module `extensions`: the claiming provider, the probe
|
|
162
|
+
* report and a first-frame thumbnail; `null` when no provider claims them. The source is opened as
|
|
163
|
+
* import records it, so a file that probes but does not open is refused here.
|
|
172
164
|
*
|
|
173
165
|
* @throws When a provider claims the bytes and cannot read them.
|
|
174
166
|
*/
|
|
@@ -190,8 +182,8 @@ export async function readProviderFile(extensions, bytes) {
|
|
|
190
182
|
}
|
|
191
183
|
}
|
|
192
184
|
/**
|
|
193
|
-
*
|
|
194
|
-
*
|
|
185
|
+
* An SVG's diagnostics when opened with font stack `fonts`, listing text no font draws
|
|
186
|
+
* (`missing_font`).
|
|
195
187
|
*/
|
|
196
188
|
export function svgDiagnostics(extensions, provider, bytes, fonts) {
|
|
197
189
|
extensions.setFonts(fonts);
|
|
@@ -204,8 +196,8 @@ export function svgDiagnostics(extensions, provider, bytes, fonts) {
|
|
|
204
196
|
}
|
|
205
197
|
}
|
|
206
198
|
/**
|
|
207
|
-
* Stages a
|
|
208
|
-
*
|
|
199
|
+
* Stages a provider-claimed file from what {@link readProviderFile} read: a still SVG is an image
|
|
200
|
+
* source, an animation a video source of one cycle (repetition is the clip's).
|
|
209
201
|
*/
|
|
210
202
|
export function stageProviderFile(file, { report, provider, thumbnail }, fingerprint) {
|
|
211
203
|
const kind = report.timing.kind === "static" ? "image" : "video";
|
|
@@ -262,12 +254,11 @@ function frameNumber(name) {
|
|
|
262
254
|
/** Missing numbers a description of a sequence lists. */
|
|
263
255
|
const LISTED_GAPS = 5;
|
|
264
256
|
/**
|
|
265
|
-
* How numbered files
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* between the first and last than a sequence may have. Nothing here walks the numbers between them.
|
|
257
|
+
* How numbered files form one image sequence from their names alone: the frame number before each
|
|
258
|
+
* name's extension fixes the order. Answers the first and last numbers, the frame count (every
|
|
259
|
+
* number between them), how many have no file, and the first few gaps. Otherwise answers why not:
|
|
260
|
+
* a name without a number, a duplicate number, a number past 2^53 - 1 (a document cannot hold it
|
|
261
|
+
* exactly), or too many frames. Never walks the numbers in between.
|
|
271
262
|
*
|
|
272
263
|
* @param {readonly string[]} names
|
|
273
264
|
* @returns {{ ok: true, first: number, last: number, frames: number, missing: number, gaps: number[] } | { ok: false, code: string, message: string }}
|
|
@@ -337,13 +328,12 @@ async function pngSize(file) {
|
|
|
337
328
|
/** Header bytes read for an OpenEXR file's display window. */
|
|
338
329
|
const EXR_HEADER_BYTES = 64 * 1024;
|
|
339
330
|
/**
|
|
340
|
-
*
|
|
341
|
-
* the header is no image's.
|
|
331
|
+
* Attributes read before the display window; writers use a few dozen, so more means not an image.
|
|
342
332
|
*/
|
|
343
333
|
const EXR_MAX_ATTRIBUTES = 1024;
|
|
344
334
|
/**
|
|
345
|
-
* An OpenEXR image's display window size from its header
|
|
346
|
-
*
|
|
335
|
+
* An OpenEXR image's display window size from its header, or `null` when not OpenEXR. The walk
|
|
336
|
+
* stops at an attribute that does not end past its start, so a crafted size cannot loop.
|
|
347
337
|
*/
|
|
348
338
|
async function exrSize(file) {
|
|
349
339
|
const head = new Uint8Array(await file.slice(0, EXR_HEADER_BYTES).arrayBuffer());
|
|
@@ -392,10 +382,10 @@ async function frameShape(file) {
|
|
|
392
382
|
}
|
|
393
383
|
/**
|
|
394
384
|
* Stages numbered PNGs or OpenEXR images as one image sequence at `frameRate`. The numbers fix the
|
|
395
|
-
* order and
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
385
|
+
* order and first frame; a gap is refused unless `missing` holds or blanks it, and every frame must
|
|
386
|
+
* match the first one's format and size. `openExr(file)` returns the provider module's thumbnail
|
|
387
|
+
* and report for an OpenEXR first frame (see {@link exrFirstFrame}). `id` names the source (a
|
|
388
|
+
* relink uses the asset's own), new by default.
|
|
399
389
|
*/
|
|
400
390
|
export async function stageSequence(files, { frameRate, missing = "reject", openExr, id = crypto.randomUUID() }) {
|
|
401
391
|
const numbering = sequenceNumbering(files.map((file) => file.name));
|
|
@@ -504,8 +494,8 @@ async function pngThumbnail(file, size) {
|
|
|
504
494
|
return { dataUrl, width: canvas.width, height: canvas.height };
|
|
505
495
|
}
|
|
506
496
|
/**
|
|
507
|
-
* An OpenEXR frame's thumbnail, sampled from the frame
|
|
508
|
-
* its own size
|
|
497
|
+
* An OpenEXR frame's thumbnail, sampled from the frame provider module `extensions` renders from
|
|
498
|
+
* `bytes` at its own size, with the provider's report.
|
|
509
499
|
*/
|
|
510
500
|
export async function exrFirstFrame(extensions, bytes) {
|
|
511
501
|
const source = extensions.open({ format: "exr" }, bytes);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The fingerprint of `file` as media of `kind`. `size` is an image's decoded size; video and audio
|
|
3
|
-
* are probed. `hash`
|
|
4
|
-
* elsewhere (`hashInWorker`).
|
|
3
|
+
* are probed. `hash` computes the content hash (`sha256Blob` on this thread by default).
|
|
5
4
|
* @param {File} file
|
|
6
5
|
* @param {string} kind
|
|
7
6
|
* @param {{ signal?: AbortSignal, onProgress?: (bytes: number) => void, size?: { width: number, height: number }, hash?: (file: Blob, options: { signal?: AbortSignal, onProgress?: (bytes: number) => void }) => Promise<string> }} [options]
|
|
@@ -19,7 +18,7 @@ export function fingerprintFile(file: File, kind: string, options?: {
|
|
|
19
18
|
onProgress?: (bytes: number) => void;
|
|
20
19
|
}) => Promise<string>;
|
|
21
20
|
}): Promise<import("alpha2/project").MediaFingerprint>;
|
|
22
|
-
/** What the demuxer sees:
|
|
21
|
+
/** What the demuxer sees: primary stream shapes, duration and declared color. */
|
|
23
22
|
export function probeEvidence(file: any): Promise<{
|
|
24
23
|
color?: import("alpha2/project").ColorMetadata | undefined;
|
|
25
24
|
duration_ticks?: number | undefined;
|
|
@@ -31,12 +30,11 @@ export function probeEvidence(file: any): Promise<{
|
|
|
31
30
|
} | undefined;
|
|
32
31
|
}>;
|
|
33
32
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* nearest pixel.
|
|
33
|
+
* A video track's displayed size in square pixels, rotated as shown, as every host computes it.
|
|
34
|
+
* The sample aspect ratio is the container's when it declares a non-square one, else the H.264 or
|
|
35
|
+
* HEVC parameter sets' (FFmpeg's `av_guess_sample_aspect_ratio`); mediabunny reads only the
|
|
36
|
+
* container's. The longer sample side grows, rounded to the nearest pixel, as in the engine's
|
|
37
|
+
* `SampleAspectRatio::square_pixel_size`.
|
|
40
38
|
* @param {import("mediabunny").InputVideoTrack} track
|
|
41
39
|
* @returns {Promise<{ width: number, height: number }>}
|
|
42
40
|
*/
|
|
@@ -45,11 +43,10 @@ export function displaySize(track: import("mediabunny").InputVideoTrack): Promis
|
|
|
45
43
|
height: number;
|
|
46
44
|
}>;
|
|
47
45
|
/**
|
|
48
|
-
* A measured frame rate as
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* the engine refuses.
|
|
46
|
+
* A measured frame rate as a declared rational: NTSC and whole rates exactly, others to a
|
|
47
|
+
* thousandth (mirrors the engine's `alpha2_assets::rational_rate`). `null` when no project rate
|
|
48
|
+
* fits (too slow to round to a frame, or a frame shorter than a tick from broken timestamps), so
|
|
49
|
+
* the fingerprint records no rate rather than one the engine refuses.
|
|
53
50
|
*/
|
|
54
51
|
export function rationalRate(rate: any): {
|
|
55
52
|
num: number;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
// Evidence of an imported file's media, recorded in the project so any host can tell
|
|
2
|
-
// media it finds is the same
|
|
3
|
-
// Whether two fingerprints match is the engine's decision (`alpha2/assets`), never made here.
|
|
1
|
+
// Evidence of an imported file's media, recorded in the project so any host can later tell whether
|
|
2
|
+
// media it finds is the same. Matching fingerprints is the engine's decision (`alpha2/assets`).
|
|
4
3
|
import { sha256Blob } from "alpha2/assets";
|
|
5
4
|
import { colorMetadataFromVideoColorSpace, sampleAspectForStream, } from "alpha2/hdr-frames";
|
|
6
5
|
import { TICKS_PER_SECOND, validFrameRate } from "alpha2/project";
|
|
7
6
|
import { ALL_FORMATS, BlobSource, EncodedPacketSink, Input } from "mediabunny";
|
|
8
7
|
/**
|
|
9
8
|
* The fingerprint of `file` as media of `kind`. `size` is an image's decoded size; video and audio
|
|
10
|
-
* are probed. `hash`
|
|
11
|
-
* elsewhere (`hashInWorker`).
|
|
9
|
+
* are probed. `hash` computes the content hash (`sha256Blob` on this thread by default).
|
|
12
10
|
* @param {File} file
|
|
13
11
|
* @param {string} kind
|
|
14
12
|
* @param {{ signal?: AbortSignal, onProgress?: (bytes: number) => void, size?: { width: number, height: number }, hash?: (file: Blob, options: { signal?: AbortSignal, onProgress?: (bytes: number) => void }) => Promise<string> }} [options]
|
|
@@ -35,7 +33,7 @@ export async function fingerprintFile(file, kind, options = {}) {
|
|
|
35
33
|
return fingerprint;
|
|
36
34
|
return { ...fingerprint, ...(await probeEvidence(file)) };
|
|
37
35
|
}
|
|
38
|
-
/** What the demuxer sees:
|
|
36
|
+
/** What the demuxer sees: primary stream shapes, duration and declared color. */
|
|
39
37
|
export async function probeEvidence(file) {
|
|
40
38
|
const input = new Input({
|
|
41
39
|
source: new BlobSource(file),
|
|
@@ -64,7 +62,7 @@ export async function probeEvidence(file) {
|
|
|
64
62
|
channels: audio.numberOfChannels,
|
|
65
63
|
sample_rate: audio.sampleRate,
|
|
66
64
|
};
|
|
67
|
-
// The latest end of any track
|
|
65
|
+
// The latest end of any track (a stream starting at 1.4 s and lasting 2 s ends at 3.4 s).
|
|
68
66
|
const seconds = await input.computeDuration().catch(() => null);
|
|
69
67
|
return {
|
|
70
68
|
...(video || audio ? { streams } : {}),
|
|
@@ -79,12 +77,11 @@ export async function probeEvidence(file) {
|
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
79
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* nearest pixel.
|
|
80
|
+
* A video track's displayed size in square pixels, rotated as shown, as every host computes it.
|
|
81
|
+
* The sample aspect ratio is the container's when it declares a non-square one, else the H.264 or
|
|
82
|
+
* HEVC parameter sets' (FFmpeg's `av_guess_sample_aspect_ratio`); mediabunny reads only the
|
|
83
|
+
* container's. The longer sample side grows, rounded to the nearest pixel, as in the engine's
|
|
84
|
+
* `SampleAspectRatio::square_pixel_size`.
|
|
88
85
|
* @param {import("mediabunny").InputVideoTrack} track
|
|
89
86
|
* @returns {Promise<{ width: number, height: number }>}
|
|
90
87
|
*/
|
|
@@ -109,14 +106,14 @@ export async function displaySize(track) {
|
|
|
109
106
|
? { width, height }
|
|
110
107
|
: { width: height, height: width };
|
|
111
108
|
}
|
|
112
|
-
/**
|
|
109
|
+
/** Minimum frames the rate is measured over, about four seconds at 30 fps. */
|
|
113
110
|
const RATE_FRAMES = 120;
|
|
114
111
|
/**
|
|
115
|
-
* The rate `track` presents its first frames at, from packet times
|
|
116
|
-
* demuxers)
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* `tests/cases/media-evidence-corpus.json`);
|
|
112
|
+
* The rate `track` presents its first frames at, from packet times only (durations differ between
|
|
113
|
+
* demuxers). Past {@link RATE_FRAMES}, packets run up to the first presented after every one taken,
|
|
114
|
+
* so reordered frames stay in the span. `null` with fewer than two frames or no span. Mirrors the
|
|
115
|
+
* engine's `alpha2_assets::FrameRateEvidence` (checked by
|
|
116
|
+
* `tests/cases/media-evidence-corpus.json`); declared rates are not consistent across hosts.
|
|
120
117
|
* @param {import("mediabunny").InputVideoTrack} track
|
|
121
118
|
* @returns {Promise<number | null>}
|
|
122
119
|
*/
|
|
@@ -137,11 +134,10 @@ async function presentedRate(track) {
|
|
|
137
134
|
return count >= 2 && last > first ? (count - 1) / (last - first) : null;
|
|
138
135
|
}
|
|
139
136
|
/**
|
|
140
|
-
* A measured frame rate as
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* the engine refuses.
|
|
137
|
+
* A measured frame rate as a declared rational: NTSC and whole rates exactly, others to a
|
|
138
|
+
* thousandth (mirrors the engine's `alpha2_assets::rational_rate`). `null` when no project rate
|
|
139
|
+
* fits (too slow to round to a frame, or a frame shorter than a tick from broken timestamps), so
|
|
140
|
+
* the fingerprint records no rate rather than one the engine refuses.
|
|
145
141
|
*/
|
|
146
142
|
export function rationalRate(rate) {
|
|
147
143
|
if (!Number.isFinite(rate) || rate <= 0)
|
|
@@ -151,9 +151,8 @@ export function encodeGenerator(generator: any): {
|
|
|
151
151
|
paint?: undefined;
|
|
152
152
|
};
|
|
153
153
|
/**
|
|
154
|
-
* Draws an
|
|
155
|
-
*
|
|
156
|
-
* in the preview.
|
|
154
|
+
* Draws an approximate library thumbnail of the generator. Canvas gradients interpolate in sRGB,
|
|
155
|
+
* not linear light, so gradient midpoints are slightly darker than in the preview.
|
|
157
156
|
*/
|
|
158
157
|
export function drawGenerator(context: any, generator: any, width: any, height: any): void;
|
|
159
158
|
/** Checks a generator read from a project file. */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// Generated sources
|
|
2
|
-
//
|
|
3
|
-
// side.
|
|
1
|
+
// Generated sources the engine draws itself (`kind: "generated"`). Positions are normalized ((0, 0)
|
|
2
|
+
// top-left, (1, 1) bottom-right); radii and strokes are fractions of the shorter side.
|
|
4
3
|
import { rgba } from "./color.js";
|
|
5
4
|
export const GENERATOR_KINDS = [
|
|
6
5
|
{ value: "solid", label: "Solid color" },
|
|
@@ -88,7 +87,7 @@ export function encodeGenerator(generator) {
|
|
|
88
87
|
: {}),
|
|
89
88
|
rotation_degrees: constant(generator.rotation),
|
|
90
89
|
};
|
|
91
|
-
//
|
|
90
|
+
// Listed first so the stroke draws over the fill.
|
|
92
91
|
return {
|
|
93
92
|
type: "shapes",
|
|
94
93
|
items: [
|
|
@@ -119,9 +118,8 @@ export function encodeGenerator(generator) {
|
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
/**
|
|
122
|
-
* Draws an
|
|
123
|
-
*
|
|
124
|
-
* in the preview.
|
|
121
|
+
* Draws an approximate library thumbnail of the generator. Canvas gradients interpolate in sRGB,
|
|
122
|
+
* not linear light, so gradient midpoints are slightly darker than in the preview.
|
|
125
123
|
*/
|
|
126
124
|
export function drawGenerator(context, generator, width, height) {
|
|
127
125
|
const [first, second] = generator.colors;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Holds the shared lock `name` until `release()`. Resolves once held;
|
|
3
|
-
*
|
|
4
|
-
* settles when the lock is let go.
|
|
2
|
+
* Holds the shared lock `name` until `release()`. Resolves once held; without Web Locks, or if
|
|
3
|
+
* refused, at once and holding nothing. `release()` settles when the lock is let go.
|
|
5
4
|
* @param {string} name
|
|
6
5
|
* @returns {Promise<{ release(): Promise<void> }>}
|
|
7
6
|
*/
|
|
@@ -17,10 +16,9 @@ export function holdShared(name: string): Promise<{
|
|
|
17
16
|
*/
|
|
18
17
|
export function whenUnheld(name: string, remove: () => Promise<void>): Promise<boolean>;
|
|
19
18
|
/**
|
|
20
|
-
* Runs `body` holding
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* `signal.reason` once `signal` aborts while it waits.
|
|
19
|
+
* Runs `body` holding lock `name` exclusively, waiting for any holder, and resolves to its result.
|
|
20
|
+
* `body` is told whether it holds the lock; without Web Locks, or if refused, it runs at once
|
|
21
|
+
* holding nothing. Rejects with `signal.reason` if `signal` aborts while waiting.
|
|
24
22
|
* @template T
|
|
25
23
|
* @param {string} name
|
|
26
24
|
* @param {{ signal?: AbortSignal }} options
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// only if unheld. Closed pages release their locks; without Web Locks nothing is held.
|
|
3
3
|
const locks = () => globalThis.navigator?.locks ?? null;
|
|
4
4
|
/**
|
|
5
|
-
* Holds the shared lock `name` until `release()`. Resolves once held;
|
|
6
|
-
*
|
|
7
|
-
* settles when the lock is let go.
|
|
5
|
+
* Holds the shared lock `name` until `release()`. Resolves once held; without Web Locks, or if
|
|
6
|
+
* refused, at once and holding nothing. `release()` settles when the lock is let go.
|
|
8
7
|
* @param {string} name
|
|
9
8
|
* @returns {Promise<{ release(): Promise<void> }>}
|
|
10
9
|
*/
|
|
@@ -55,10 +54,9 @@ export async function whenUnheld(name, remove) {
|
|
|
55
54
|
});
|
|
56
55
|
}
|
|
57
56
|
/**
|
|
58
|
-
* Runs `body` holding
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* `signal.reason` once `signal` aborts while it waits.
|
|
57
|
+
* Runs `body` holding lock `name` exclusively, waiting for any holder, and resolves to its result.
|
|
58
|
+
* `body` is told whether it holds the lock; without Web Locks, or if refused, it runs at once
|
|
59
|
+
* holding nothing. Rejects with `signal.reason` if `signal` aborts while waiting.
|
|
62
60
|
* @template T
|
|
63
61
|
* @param {string} name
|
|
64
62
|
* @param {{ signal?: AbortSignal }} options
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
/** Which storage APIs this page has, as an export
|
|
1
|
+
/** Which storage APIs this page has, as an export result reports them. */
|
|
2
2
|
export function storageSupport(): {
|
|
3
3
|
opfs: boolean;
|
|
4
4
|
savePicker: boolean;
|
|
5
5
|
estimate: boolean;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
|
-
* Opens where an export writes, refusing
|
|
9
|
-
* limit.
|
|
8
|
+
* Opens where an export writes, refusing up front only an in-memory output past its limit.
|
|
10
9
|
*
|
|
11
10
|
* Storage is never refused ahead: `navigator.storage.estimate()` is a guess, and WebKit's usage
|
|
12
11
|
* counts every write since its last disk scan, so `quota - usage` can be near zero on an empty
|
|
13
12
|
* disk. A full disk fails at the write (`STORAGE_QUOTA_EXCEEDED`); the estimate is only reported.
|
|
14
13
|
*
|
|
15
|
-
* `container` (default `mp4`)
|
|
16
|
-
* type.
|
|
14
|
+
* `container` (default `mp4`) sets the temporary file's extension and the artifact's MIME type.
|
|
17
15
|
* Returns `{ mode, destination, storageEstimate, abort, finish }`: `destination` is the sink's,
|
|
18
|
-
* `abort` discards the file, and `finish(sinkOutput)` turns the finished output into
|
|
16
|
+
* `abort` discards the file, and `finish(sinkOutput)` turns the finished output into artifact
|
|
19
17
|
* fields.
|
|
20
18
|
*/
|
|
21
19
|
export function openExportOutput({ jobId, name, container, target, durationSeconds, videoBitrate, audioBitrate, }: {
|
|
@@ -81,10 +79,10 @@ export function openExportOutput({ jobId, name, container, target, durationSecon
|
|
|
81
79
|
}>;
|
|
82
80
|
}>;
|
|
83
81
|
/**
|
|
84
|
-
* Deletes temporary export files left by pages
|
|
85
|
-
*
|
|
82
|
+
* Deletes temporary export files left by closed pages (started over a day ago, held by no page).
|
|
83
|
+
* Resolves to the names removed.
|
|
86
84
|
* @returns {Promise<string[]>}
|
|
87
85
|
*/
|
|
88
86
|
export function sweepStaleExports(now?: number): Promise<string[]>;
|
|
89
|
-
/**
|
|
87
|
+
/** Default peak size of an in-memory output. */
|
|
90
88
|
export const DEFAULT_MEMORY_OUTPUT_LIMIT: number;
|