@alpha2-sh/editor 0.6.2 → 0.7.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/README.md +5 -4
- package/dist/browser/bridge.js +187 -27
- package/dist/browser/extensions-worker.js +2 -1
- package/dist/browser/extract-worker-entry.d.ts +1 -0
- package/dist/browser/extract-worker-entry.js +3 -0
- package/dist/browser/extract-worker.d.ts +44 -0
- package/dist/browser/extract-worker.js +172 -0
- package/dist/browser/hash-worker.js +2 -1
- package/dist/browser/runtime/assets.d.ts +2 -2
- package/dist/browser/runtime/assets.js +11 -7
- package/dist/browser/runtime/engine.d.ts +7 -0
- package/dist/browser/runtime/engine.js +16 -0
- package/dist/browser/runtime/exporter.js +4 -2
- package/dist/browser/runtime/extension-import.js +2 -1
- package/dist/browser/runtime/fingerprint.js +3 -2
- package/dist/browser/runtime/media-reference.d.ts +6 -0
- package/dist/browser/runtime/media-reference.js +40 -0
- package/dist/browser/runtime/proxies.js +3 -2
- package/dist/browser/runtime/range-file.d.ts +37 -0
- package/dist/browser/runtime/range-file.js +123 -0
- package/dist/browser/runtime/still.js +2 -1
- package/dist/browser/types.d.ts +97 -21
- package/dist/browser/worker.js +2 -1
- package/dist/native-client/index.d.ts +12 -5
- package/dist/native-client/index.js +82 -25
- package/package.json +9 -4
|
@@ -4,7 +4,8 @@ import { codecName, colorMetadataFromVideoColorSpace, DecodeUnavailableError, de
|
|
|
4
4
|
import { MediabunnyVideoDecoder, probeAudioSource, probeAudioStreams, probePlanarDecode, videoTrackFacts, } from "alpha2/mediabunny";
|
|
5
5
|
import { TICKS_PER_SECOND } from "alpha2/project";
|
|
6
6
|
import { OffscreenTextRasterizer } from "alpha2/text";
|
|
7
|
-
import { ALL_FORMATS, AudioSampleSink,
|
|
7
|
+
import { ALL_FORMATS, AudioSampleSink, Input } from "mediabunny";
|
|
8
|
+
import { isRangeFile, mediaSource } from "./range-file.js";
|
|
8
9
|
const uid = (prefix) => `${prefix}-${crypto.randomUUID()}`;
|
|
9
10
|
import { drawGenerator, generatorLabel } from "./generators.js";
|
|
10
11
|
import { loadedOrFailed, seekVideoFrame, unloadVideo, } from "./preview-utils.js";
|
|
@@ -272,9 +273,12 @@ export class AssetLibrary {
|
|
|
272
273
|
// hardware frames and no software decoder). Refuse it here by name rather than at its first
|
|
273
274
|
// frame, unless the library takes it for a degraded preview.
|
|
274
275
|
const planarDecode = await this.#planarDecode(file, probe);
|
|
275
|
-
const url = URL.createObjectURL(file);
|
|
276
|
-
|
|
276
|
+
const url = isRangeFile(file) ? file.url : URL.createObjectURL(file);
|
|
277
|
+
if (!isRangeFile(file))
|
|
278
|
+
this.#urls.push(url);
|
|
277
279
|
const video = document.createElement("video");
|
|
280
|
+
if (isRangeFile(file))
|
|
281
|
+
video.crossOrigin = "anonymous";
|
|
278
282
|
Object.assign(video, {
|
|
279
283
|
src: url,
|
|
280
284
|
muted: true,
|
|
@@ -507,7 +511,7 @@ function mediaKindForFile(file) {
|
|
|
507
511
|
*/
|
|
508
512
|
export async function probeVideo(file) {
|
|
509
513
|
const input = new Input({
|
|
510
|
-
source:
|
|
514
|
+
source: mediaSource(file),
|
|
511
515
|
formats: ALL_FORMATS,
|
|
512
516
|
});
|
|
513
517
|
try {
|
|
@@ -582,7 +586,7 @@ export function importFailureReason(error, kind, facts) {
|
|
|
582
586
|
/** A container's length in seconds, as its last packet ends; null when it cannot be read. */
|
|
583
587
|
async function containerDuration(file) {
|
|
584
588
|
const input = new Input({
|
|
585
|
-
source:
|
|
589
|
+
source: mediaSource(file),
|
|
586
590
|
formats: ALL_FORMATS,
|
|
587
591
|
});
|
|
588
592
|
try {
|
|
@@ -617,7 +621,7 @@ export async function audioDecoding(file) {
|
|
|
617
621
|
*/
|
|
618
622
|
async function probeAudio(file) {
|
|
619
623
|
const input = new Input({
|
|
620
|
-
source:
|
|
624
|
+
source: mediaSource(file),
|
|
621
625
|
formats: ALL_FORMATS,
|
|
622
626
|
});
|
|
623
627
|
try {
|
|
@@ -640,7 +644,7 @@ async function probeAudio(file) {
|
|
|
640
644
|
*/
|
|
641
645
|
export async function streamPeaks(file, { signal, bucketsPerSecond = 100, maxBuckets = 360_000 } = {}) {
|
|
642
646
|
const input = new Input({
|
|
643
|
-
source:
|
|
647
|
+
source: mediaSource(file),
|
|
644
648
|
formats: ALL_FORMATS,
|
|
645
649
|
});
|
|
646
650
|
try {
|
|
@@ -99,6 +99,13 @@ export class Engine {
|
|
|
99
99
|
supply(seconds: any, { context }: {
|
|
100
100
|
context: any;
|
|
101
101
|
}): Promise<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* The frame at `ticks` drawn at `width` x `height` from the sources it shows, uploaded for it
|
|
104
|
+
* and retired after, as straight-alpha sRGB RGBA8. Only the CPU renderer reads frames this way.
|
|
105
|
+
*/
|
|
106
|
+
readRgbaAt(ticks: any, width: any, height: any, { context }: {
|
|
107
|
+
context: any;
|
|
108
|
+
}): Promise<any>;
|
|
102
109
|
/**
|
|
103
110
|
* Renders the next export frame. Once a ticket is not `waiting`, the engine has consumed the
|
|
104
111
|
* frame's uploads, so they are retired here.
|
|
@@ -332,6 +332,22 @@ export class Engine {
|
|
|
332
332
|
this.#exportUploads.push(...supplied.uploaded);
|
|
333
333
|
return Boolean(supplied);
|
|
334
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* The frame at `ticks` drawn at `width` x `height` from the sources it shows, uploaded for it
|
|
337
|
+
* and retired after, as straight-alpha sRGB RGBA8. Only the CPU renderer reads frames this way.
|
|
338
|
+
*/
|
|
339
|
+
async readRgbaAt(ticks, width, height, { context }) {
|
|
340
|
+
if (!this.#registry)
|
|
341
|
+
throw new Error("the renderer is not initialized");
|
|
342
|
+
await this.supply(Number(ticks) / 120000, { context });
|
|
343
|
+
try {
|
|
344
|
+
return this.#registry.readRgbaAt(BigInt(ticks), width, height);
|
|
345
|
+
}
|
|
346
|
+
finally {
|
|
347
|
+
this.#supply.retire(this.#exportUploads);
|
|
348
|
+
this.#exportUploads = [];
|
|
349
|
+
}
|
|
350
|
+
}
|
|
335
351
|
/**
|
|
336
352
|
* Renders the next export frame. Once a ticket is not `waiting`, the engine has consumed the
|
|
337
353
|
* frame's uploads, so they are retired here.
|
|
@@ -649,6 +649,7 @@ function finishBrowserExportMetrics(metrics, encodeLatency, before, after) {
|
|
|
649
649
|
appendPoolMetrics(result, "uploadTextures", "uploadTextures", "uploadTexture", before, after);
|
|
650
650
|
appendPoolMetrics(result, "readbackBuffers", "readbackBuffers", "readbackBuffer", before, after);
|
|
651
651
|
appendPoolMetrics(result, "uniformBuffers", "uniformBuffers", "uniformBuffer", before, after);
|
|
652
|
+
appendPoolMetrics(result, "bindGroups", "bindGroups", null, before, after);
|
|
652
653
|
result.sourceUploads = Math.max(0, (after.sourceFrames?.uploads ?? 0) - (before.sourceFrames?.uploads ?? 0));
|
|
653
654
|
result.physicalSourceReuses = Math.max(0, (after.sourceFrames?.physicalReuses ?? 0) -
|
|
654
655
|
(before.sourceFrames?.physicalReuses ?? 0));
|
|
@@ -661,8 +662,9 @@ function appendPoolMetrics(result, input, counterPrefix, highWaterPrefix, before
|
|
|
661
662
|
continue;
|
|
662
663
|
result[`${counterPrefix}${counter}`] = Math.max(0, after[input][key] - (before[input]?.[key] ?? 0));
|
|
663
664
|
}
|
|
664
|
-
|
|
665
|
-
|
|
665
|
+
if (highWaterPrefix !== null)
|
|
666
|
+
result[`${highWaterPrefix}HighWaterBytes`] =
|
|
667
|
+
after[input]?.highWaterBytes ?? 0;
|
|
666
668
|
}
|
|
667
669
|
function rendererDiagnostics(engine) {
|
|
668
670
|
if (typeof engine?.diagnostics !== "function")
|
|
@@ -2,6 +2,7 @@
|
|
|
2
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_PDF_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
|
+
import { blobOf } from "./range-file.js";
|
|
5
6
|
const TICKS_PER_SECOND = 120_000;
|
|
6
7
|
/** Whether a file's start could be SVG, GIF, WebP, APNG, Lottie, dotLottie, OpenEXR or PDF. */
|
|
7
8
|
export function mayBeExtension(head) {
|
|
@@ -509,7 +510,7 @@ export async function stageSequence(files, { frameRate, missing = "reject", open
|
|
|
509
510
|
}
|
|
510
511
|
/** A PNG frame's thumbnail, {@link THUMBNAIL_WIDTH} pixels wide. */
|
|
511
512
|
async function pngThumbnail(file, size) {
|
|
512
|
-
const bitmap = await createImageBitmap(file);
|
|
513
|
+
const bitmap = await createImageBitmap(await blobOf(file));
|
|
513
514
|
const canvas = new OffscreenCanvas(THUMBNAIL_WIDTH, Math.max(1, Math.round((THUMBNAIL_WIDTH * size.height) / size.width)));
|
|
514
515
|
canvas.getContext("2d").drawImage(bitmap, 0, 0, canvas.width, canvas.height);
|
|
515
516
|
bitmap.close();
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import { sha256Blob } from "alpha2/assets";
|
|
4
4
|
import { colorMetadataFromVideoColorSpace, sampleAspectForStream, } from "alpha2/hdr-frames";
|
|
5
5
|
import { TICKS_PER_SECOND, validFrameRate } from "alpha2/project";
|
|
6
|
-
import { ALL_FORMATS,
|
|
6
|
+
import { ALL_FORMATS, EncodedPacketSink, Input } from "mediabunny";
|
|
7
|
+
import { mediaSource } from "./range-file.js";
|
|
7
8
|
/**
|
|
8
9
|
* The fingerprint of `file` as media of `kind`. `size` is an image's decoded size; video and audio
|
|
9
10
|
* are probed. `hash` computes the content hash (`sha256Blob` on this thread by default).
|
|
@@ -36,7 +37,7 @@ export async function fingerprintFile(file, kind, options = {}) {
|
|
|
36
37
|
/** What the demuxer sees: primary stream shapes, duration and declared color. */
|
|
37
38
|
export async function probeEvidence(file) {
|
|
38
39
|
const input = new Input({
|
|
39
|
-
source:
|
|
40
|
+
source: mediaSource(file),
|
|
40
41
|
formats: ALL_FORMATS,
|
|
41
42
|
});
|
|
42
43
|
try {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {import("../types.js").MediaReference} reference
|
|
3
|
+
* @param {AbortSignal} [signal]
|
|
4
|
+
*/
|
|
5
|
+
export function openMediaReference(reference: import("../types.js").MediaReference, signal?: AbortSignal): Promise<RangeFile>;
|
|
6
|
+
import { RangeFile } from "./range-file.js";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { EditorError } from "../../core/document.js";
|
|
2
|
+
import { RangeFile } from "./range-file.js";
|
|
3
|
+
/**
|
|
4
|
+
* @param {import("../types.js").MediaReference} reference
|
|
5
|
+
* @param {AbortSignal} [signal]
|
|
6
|
+
*/
|
|
7
|
+
export async function openMediaReference(reference, signal) {
|
|
8
|
+
const name = reference.name;
|
|
9
|
+
const url = new URL(String(reference.url), globalThis.document?.baseURI ?? globalThis.location?.href).href;
|
|
10
|
+
const refuse = (reason, cause) => new EditorError("unreadable_media", `Cannot read ${name}: ${reason}`, "import", undefined, true, cause === undefined ? undefined : { cause });
|
|
11
|
+
let response;
|
|
12
|
+
try {
|
|
13
|
+
response = await fetch(url, { headers: { range: "bytes=0-0" }, signal });
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (signal?.aborted)
|
|
17
|
+
throw signal.reason;
|
|
18
|
+
throw refuse(`${url} did not answer`, error);
|
|
19
|
+
}
|
|
20
|
+
await response.body?.cancel().catch(() => { });
|
|
21
|
+
const total = response.status === 206
|
|
22
|
+
? /\/(\d+)$/.exec(response.headers.get("content-range") ?? "")?.[1]
|
|
23
|
+
: undefined;
|
|
24
|
+
if (total === undefined)
|
|
25
|
+
throw refuse(response.ok
|
|
26
|
+
? `${url} does not answer range requests`
|
|
27
|
+
: `${url} answered ${response.status}`);
|
|
28
|
+
const modified = Date.parse(response.headers.get("last-modified") ?? "");
|
|
29
|
+
return new RangeFile({
|
|
30
|
+
url,
|
|
31
|
+
name,
|
|
32
|
+
size: Number(total),
|
|
33
|
+
type: reference.type ??
|
|
34
|
+
response.headers.get("content-type")?.split(";")[0].trim() ??
|
|
35
|
+
"",
|
|
36
|
+
lastModified: reference.lastModified ??
|
|
37
|
+
(Number.isFinite(modified) ? modified : undefined),
|
|
38
|
+
...(reference.path === undefined ? {} : { path: reference.path }),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// reopened project previews before its files are relinked. The engine decides whether a proxy may
|
|
3
3
|
// stand in for its source. Proxies stream to their file while encoding; only a browser without
|
|
4
4
|
// writable OPFS keeps them in memory, for this page and within a size limit.
|
|
5
|
-
import { ALL_FORMATS,
|
|
5
|
+
import { ALL_FORMATS, BufferTarget, Conversion, Input, Mp4OutputFormat, Output, StreamTarget, canEncodeAudio, } from "mediabunny";
|
|
6
6
|
import { MEMORY_OUTPUT_COPIES, WritableFileDestination, } from "alpha2/export-destination";
|
|
7
7
|
import { EditorError } from "../../core/document.js";
|
|
8
|
+
import { mediaSource } from "./range-file.js";
|
|
8
9
|
import { displaySize, probeEvidence } from "./fingerprint.js";
|
|
9
10
|
import { DEFAULT_MEMORY_OUTPUT_LIMIT } from "./output.js";
|
|
10
11
|
import { holdProxy, keptProxies, proxyDirectory, removeKeptProxies, removeUnfinishedProxies, unfinishedProxyName, whileMakingProxy, } from "./proxy-storage.js";
|
|
@@ -119,7 +120,7 @@ export class ProxyStore {
|
|
|
119
120
|
async #make(file, fingerprint, hash, { signal, onProgress }) {
|
|
120
121
|
signal?.throwIfAborted();
|
|
121
122
|
const input = new Input({
|
|
122
|
-
source:
|
|
123
|
+
source: mediaSource(file),
|
|
123
124
|
formats: ALL_FORMATS,
|
|
124
125
|
});
|
|
125
126
|
// Installed before setup awaits, so an earlier abort cancels the conversion once it exists.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function isRangeFile(value: any): boolean;
|
|
2
|
+
export function reviveRangeFile(value: any): any;
|
|
3
|
+
export function reviveAssetFiles(asset: any): any;
|
|
4
|
+
export function mediaSource(file: any): CustomSource | BlobSource;
|
|
5
|
+
export function blobOf(file: any): Promise<any>;
|
|
6
|
+
export class RangeFile {
|
|
7
|
+
/**
|
|
8
|
+
* @param {{ url: string, name: string, size: number, type?: string, lastModified?: number, path?: string, offset?: number }} fields
|
|
9
|
+
*/
|
|
10
|
+
constructor({ url, name, size, type, lastModified, path, offset }: {
|
|
11
|
+
url: string;
|
|
12
|
+
name: string;
|
|
13
|
+
size: number;
|
|
14
|
+
type?: string;
|
|
15
|
+
lastModified?: number;
|
|
16
|
+
path?: string;
|
|
17
|
+
offset?: number;
|
|
18
|
+
});
|
|
19
|
+
format: string;
|
|
20
|
+
url: string;
|
|
21
|
+
name: string;
|
|
22
|
+
size: number;
|
|
23
|
+
type: string;
|
|
24
|
+
lastModified: number;
|
|
25
|
+
path: string | undefined;
|
|
26
|
+
offset: number;
|
|
27
|
+
read(start: any, end: any): Promise<Uint8Array<ArrayBuffer>>;
|
|
28
|
+
slice(start?: number, end?: number, type?: string): RangeFile;
|
|
29
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
30
|
+
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
31
|
+
text(): Promise<string>;
|
|
32
|
+
stream(): ReadableStream<any>;
|
|
33
|
+
blob(): Promise<Blob>;
|
|
34
|
+
#private;
|
|
35
|
+
}
|
|
36
|
+
import { CustomSource } from "mediabunny";
|
|
37
|
+
import { BlobSource } from "mediabunny";
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { CustomSource, BlobSource } from "mediabunny";
|
|
2
|
+
const RANGE_FILE = "alpha2.range-file";
|
|
3
|
+
export class RangeFile {
|
|
4
|
+
/**
|
|
5
|
+
* @param {{ url: string, name: string, size: number, type?: string, lastModified?: number, path?: string, offset?: number }} fields
|
|
6
|
+
*/
|
|
7
|
+
constructor({ url, name, size, type = "", lastModified, path, offset = 0 }) {
|
|
8
|
+
this.format = RANGE_FILE;
|
|
9
|
+
this.url = url;
|
|
10
|
+
this.name = name;
|
|
11
|
+
this.size = size;
|
|
12
|
+
this.type = type;
|
|
13
|
+
this.lastModified = lastModified ?? Date.now();
|
|
14
|
+
if (path !== undefined)
|
|
15
|
+
this.path = path;
|
|
16
|
+
this.offset = offset;
|
|
17
|
+
}
|
|
18
|
+
async read(start, end) {
|
|
19
|
+
const from = Math.max(0, Math.min(start, this.size));
|
|
20
|
+
const to = Math.max(from, Math.min(end, this.size));
|
|
21
|
+
if (from === to)
|
|
22
|
+
return new Uint8Array(0);
|
|
23
|
+
const response = await this.#fetch(from, to);
|
|
24
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
25
|
+
if (bytes.length !== to - from)
|
|
26
|
+
throw new Error(`${this.url} sent ${bytes.length} bytes for a range of ${to - from}`);
|
|
27
|
+
return bytes;
|
|
28
|
+
}
|
|
29
|
+
slice(start = 0, end = this.size, type = "") {
|
|
30
|
+
const at = (value) => value < 0 ? Math.max(0, this.size + value) : Math.min(value, this.size);
|
|
31
|
+
const from = at(start);
|
|
32
|
+
const to = Math.max(from, at(end));
|
|
33
|
+
return new RangeFile({
|
|
34
|
+
...this,
|
|
35
|
+
size: to - from,
|
|
36
|
+
type,
|
|
37
|
+
offset: this.offset + from,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async arrayBuffer() {
|
|
41
|
+
return (await this.read(0, this.size)).buffer;
|
|
42
|
+
}
|
|
43
|
+
bytes() {
|
|
44
|
+
return this.read(0, this.size);
|
|
45
|
+
}
|
|
46
|
+
async text() {
|
|
47
|
+
return new TextDecoder().decode(await this.read(0, this.size));
|
|
48
|
+
}
|
|
49
|
+
stream() {
|
|
50
|
+
if (this.size === 0)
|
|
51
|
+
return new Blob([]).stream();
|
|
52
|
+
let body = null;
|
|
53
|
+
return new ReadableStream({
|
|
54
|
+
pull: async (controller) => {
|
|
55
|
+
body ??= (await this.#fetch(0, this.size)).body.getReader();
|
|
56
|
+
const { done, value } = await body.read();
|
|
57
|
+
if (done)
|
|
58
|
+
controller.close();
|
|
59
|
+
else
|
|
60
|
+
controller.enqueue(value);
|
|
61
|
+
},
|
|
62
|
+
cancel: (reason) => body?.cancel(reason),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async blob() {
|
|
66
|
+
return new Response(this.stream())
|
|
67
|
+
.blob()
|
|
68
|
+
.then((blob) => new Blob([blob], { type: this.type }));
|
|
69
|
+
}
|
|
70
|
+
async #fetch(from, to) {
|
|
71
|
+
const first = this.offset + from;
|
|
72
|
+
const last = this.offset + to - 1;
|
|
73
|
+
const response = await fetch(this.url, {
|
|
74
|
+
headers: { range: `bytes=${first}-${last}` },
|
|
75
|
+
});
|
|
76
|
+
const range = /^bytes (\d+)-(\d+)\//.exec(response.headers.get("content-range") ?? "");
|
|
77
|
+
if (response.status !== 206 ||
|
|
78
|
+
Number(range?.[1]) !== first ||
|
|
79
|
+
Number(range?.[2]) !== last) {
|
|
80
|
+
await response.body?.cancel().catch(() => { });
|
|
81
|
+
throw new Error(`${this.url} answered bytes ${first}-${last} with ${response.status} ${response.headers.get("content-range") ?? ""}`.trim());
|
|
82
|
+
}
|
|
83
|
+
return response;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export function isRangeFile(value) {
|
|
87
|
+
return (typeof value === "object" && value !== null && value.format === RANGE_FILE);
|
|
88
|
+
}
|
|
89
|
+
export function reviveRangeFile(value) {
|
|
90
|
+
return isRangeFile(value) && !(value instanceof RangeFile)
|
|
91
|
+
? new RangeFile(value)
|
|
92
|
+
: value;
|
|
93
|
+
}
|
|
94
|
+
export function reviveAssetFiles(asset) {
|
|
95
|
+
if (!isRangeFile(asset.file) && !asset.frameFiles)
|
|
96
|
+
return asset;
|
|
97
|
+
return {
|
|
98
|
+
...asset,
|
|
99
|
+
...(asset.file ? { file: reviveRangeFile(asset.file) } : {}),
|
|
100
|
+
...(asset.frameFiles
|
|
101
|
+
? {
|
|
102
|
+
frameFiles: new Map([...asset.frameFiles].map(([locator, file]) => [
|
|
103
|
+
locator,
|
|
104
|
+
reviveRangeFile(file),
|
|
105
|
+
])),
|
|
106
|
+
}
|
|
107
|
+
: {}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export function mediaSource(file) {
|
|
111
|
+
const range = reviveRangeFile(file);
|
|
112
|
+
return range instanceof RangeFile
|
|
113
|
+
? new CustomSource({
|
|
114
|
+
getSize: () => range.size,
|
|
115
|
+
read: (start, end) => range.read(start, end),
|
|
116
|
+
prefetchProfile: "network",
|
|
117
|
+
})
|
|
118
|
+
: new BlobSource(file);
|
|
119
|
+
}
|
|
120
|
+
export function blobOf(file) {
|
|
121
|
+
const range = reviveRangeFile(file);
|
|
122
|
+
return range instanceof RangeFile ? range.blob() : Promise.resolve(file);
|
|
123
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// exports match: upright per Exif `Orientation` (`imageOrientation: "from-image"`), in stored
|
|
3
3
|
// sRGB code values with no ICC conversion (the engine treats SDR input as sRGB and native decoding
|
|
4
4
|
// has no colour management), and at its own size.
|
|
5
|
+
import { blobOf } from "./range-file.js";
|
|
5
6
|
/** The longest side the engine decodes, renders, or composes (`MAX_FRAME_DIMENSION`). */
|
|
6
7
|
export const MAX_STILL_DIMENSION = 16_384;
|
|
7
8
|
/** The largest area the engine decodes, renders, or composes (`MAX_FRAME_PIXELS`). */
|
|
@@ -10,7 +11,7 @@ export const MAX_STILL_PIXELS = 67_108_864;
|
|
|
10
11
|
* Decodes an image upright without colour management, rejecting one larger than the engine takes.
|
|
11
12
|
*/
|
|
12
13
|
export async function decodeStill(file) {
|
|
13
|
-
const bitmap = await createImageBitmap(file, {
|
|
14
|
+
const bitmap = await createImageBitmap(await blobOf(file), {
|
|
14
15
|
imageOrientation: "from-image",
|
|
15
16
|
colorSpaceConversion: "none",
|
|
16
17
|
});
|
package/dist/browser/types.d.ts
CHANGED
|
@@ -29,6 +29,14 @@ export interface RuntimeAssets {
|
|
|
29
29
|
* page's thread.
|
|
30
30
|
*/
|
|
31
31
|
readonly extensionsWorkerFactory?: () => Worker;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a worker running the `@alpha2-sh/editor/extract-worker` entry, in which
|
|
34
|
+
* `bridge.extract` runs a plugin (one worker per run, terminated when it settles or is
|
|
35
|
+
* cancelled); the plugin is still fetched, checked and compiled on the page. Without one, or if
|
|
36
|
+
* it cannot start, the plugin runs on the page's thread. An app's own extractor always runs on
|
|
37
|
+
* the page.
|
|
38
|
+
*/
|
|
39
|
+
readonly extractWorkerFactory?: () => Worker;
|
|
32
40
|
/** The engine's wasm binary (`alpha2/wasm`). */
|
|
33
41
|
readonly wasmUrl?: string | URL;
|
|
34
42
|
/**
|
|
@@ -59,6 +67,45 @@ export interface RuntimeFont {
|
|
|
59
67
|
/** The face to read in a collection file (`.ttc`/`.otc`); 0 for a single-face file. */
|
|
60
68
|
readonly faceIndex: number;
|
|
61
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* A file the bridge reads by byte range from `url` instead of holding a `File`, for media an
|
|
72
|
+
* application keeps on disk or a server. `url` must answer `Range` requests (RFC 9110) with `206`
|
|
73
|
+
* and `Content-Range`, from the page and its workers (cross-origin: with CORS). The import learns
|
|
74
|
+
* the size from a first range request; `type` and `lastModified` default to the response's
|
|
75
|
+
* `Content-Type` and `Last-Modified`.
|
|
76
|
+
*/
|
|
77
|
+
export interface MediaReference {
|
|
78
|
+
readonly url: string | URL;
|
|
79
|
+
readonly name: string;
|
|
80
|
+
readonly type?: string;
|
|
81
|
+
readonly lastModified?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Where a native export service finds the same file on its machine. `nativeAssets` sends this
|
|
84
|
+
* path instead of the file's bytes; leave it out when the service runs elsewhere.
|
|
85
|
+
*/
|
|
86
|
+
readonly path?: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A {@link MediaReference} the bridge opened, as a media adapter and {@link RuntimeAsset.file} see
|
|
90
|
+
* it: the `Blob` reading methods over range requests, and `read(start, end)` for bytes
|
|
91
|
+
* `[start, end)`.
|
|
92
|
+
*/
|
|
93
|
+
export interface RangeFile {
|
|
94
|
+
readonly url: string;
|
|
95
|
+
readonly name: string;
|
|
96
|
+
readonly size: number;
|
|
97
|
+
readonly type: string;
|
|
98
|
+
readonly lastModified: number;
|
|
99
|
+
readonly path?: string;
|
|
100
|
+
read(start: number, end: number): Promise<Uint8Array>;
|
|
101
|
+
slice(start?: number, end?: number, type?: string): RangeFile;
|
|
102
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
103
|
+
bytes(): Promise<Uint8Array>;
|
|
104
|
+
text(): Promise<string>;
|
|
105
|
+
stream(): ReadableStream<Uint8Array>;
|
|
106
|
+
/** The whole file read into a `Blob`. */
|
|
107
|
+
blob(): Promise<Blob>;
|
|
108
|
+
}
|
|
62
109
|
/** A source's media as this browser session holds it; never part of the document or its history. */
|
|
63
110
|
export interface RuntimeAsset {
|
|
64
111
|
readonly id: string;
|
|
@@ -69,7 +116,7 @@ export interface RuntimeAsset {
|
|
|
69
116
|
* What the source is read from. A still is decoded from it on each raster cache miss; no decoded
|
|
70
117
|
* picture is kept with the asset.
|
|
71
118
|
*/
|
|
72
|
-
readonly file?: File;
|
|
119
|
+
readonly file?: File | RangeFile;
|
|
73
120
|
/** Small preview canvas; `dataUrl` is a ready-to-use image URL. */
|
|
74
121
|
readonly thumbnail?: {
|
|
75
122
|
readonly dataUrl?: string;
|
|
@@ -132,12 +179,12 @@ export interface BrowserMediaAdapter {
|
|
|
132
179
|
* `MAX_SVG_DOCUMENT_BYTES`),
|
|
133
180
|
* `provider_stalled` past `EXTENSIONS_CALL_TIMEOUT_MS`, and when `signal` aborts.
|
|
134
181
|
*/
|
|
135
|
-
stage(file: File, signal: AbortSignal, options?: {
|
|
182
|
+
stage(file: File | RangeFile, signal: AbortSignal, options?: {
|
|
136
183
|
/** Pass `false` to skip computing the fingerprint. Default `true`. */
|
|
137
184
|
readonly fingerprint?: boolean;
|
|
138
185
|
}): Promise<StagedAsset>;
|
|
139
186
|
/** Stages numbered PNGs or OpenEXR images as one image sequence. */
|
|
140
|
-
stageSequence?(files: readonly File[], options: {
|
|
187
|
+
stageSequence?(files: readonly (File | RangeFile)[], options: {
|
|
141
188
|
readonly frameRate: {
|
|
142
189
|
readonly num: number;
|
|
143
190
|
readonly den: number;
|
|
@@ -502,21 +549,23 @@ export interface BrowserBridge {
|
|
|
502
549
|
}>;
|
|
503
550
|
/**
|
|
504
551
|
* Stages `files` and adds them to the document in one undoable transaction. With `relinkId`,
|
|
505
|
-
* the single file replaces that asset's media, keeping its ID and clips.
|
|
552
|
+
* the single file replaces that asset's media, keeping its ID and clips. A
|
|
553
|
+
* {@link MediaReference} is read by range from its URL rather than held, and a reference whose
|
|
554
|
+
* URL does not answer range requests is refused (`unreadable_media`).
|
|
506
555
|
*
|
|
507
556
|
* Rejects when staging fails, when `signal` aborts, when the session loads another project
|
|
508
557
|
* meanwhile (`stale_import`), for an unknown relink target (`missing_asset`), and for a relink
|
|
509
558
|
* that is not one file of the same kind and recorded media (`relink_conflict`). Nothing is added
|
|
510
559
|
* when any file fails.
|
|
511
560
|
*/
|
|
512
|
-
importFiles(files: readonly File[], options?: {
|
|
561
|
+
importFiles(files: readonly (File | MediaReference)[], options?: {
|
|
513
562
|
signal?: AbortSignal;
|
|
514
563
|
relinkId?: string;
|
|
515
564
|
}): Promise<{
|
|
516
565
|
assetIds: string[];
|
|
517
566
|
}>;
|
|
518
567
|
/** `importFiles([file], { relinkId: id })`. */
|
|
519
|
-
relink(id: string, file: File, options?: {
|
|
568
|
+
relink(id: string, file: File | MediaReference, options?: {
|
|
520
569
|
signal?: AbortSignal;
|
|
521
570
|
}): Promise<{
|
|
522
571
|
assetIds: string[];
|
|
@@ -525,7 +574,7 @@ export interface BrowserBridge {
|
|
|
525
574
|
* Imports numbered PNGs as one image sequence at `frameRate` (the project's by default). A gap in
|
|
526
575
|
* the numbering is refused unless `missing` holds or blanks it.
|
|
527
576
|
*/
|
|
528
|
-
importSequence(files: readonly File[], options?: {
|
|
577
|
+
importSequence(files: readonly (File | MediaReference)[], options?: {
|
|
529
578
|
frameRate?: {
|
|
530
579
|
readonly num: number;
|
|
531
580
|
readonly den: number;
|
|
@@ -540,7 +589,7 @@ export interface BrowserBridge {
|
|
|
540
589
|
* and clips; the engine decides whether the frames match the recorded sequence. Refused for an
|
|
541
590
|
* asset that is not an image sequence.
|
|
542
591
|
*/
|
|
543
|
-
relinkSequence(id: string, files: readonly File[], options?: {
|
|
592
|
+
relinkSequence(id: string, files: readonly (File | MediaReference)[], options?: {
|
|
544
593
|
signal?: AbortSignal;
|
|
545
594
|
}): Promise<{
|
|
546
595
|
assetIds: string[];
|
|
@@ -613,8 +662,9 @@ export interface BrowserBridge {
|
|
|
613
662
|
/**
|
|
614
663
|
* The files a native export of `document` (the current one by default) needs, for upload:
|
|
615
664
|
* shown media (or their proxies with `media: "proxies"`), an image sequence's frames, font
|
|
616
|
-
* files, LUTs, and text rendered to PNG.
|
|
617
|
-
*
|
|
665
|
+
* files, LUTs, and text rendered to PNG. Media imported from a {@link MediaReference} with a
|
|
666
|
+
* `path` is sent as that path, and without one as its bytes read whole. Rejects as `startExport`
|
|
667
|
+
* does when the media is not ready (`ConformError`) or the document does not compile.
|
|
618
668
|
*/
|
|
619
669
|
nativeAssets(document?: import("../core/document.js").EditorDocument, options?: Pick<BrowserExportOptions, "media">): Promise<import("../native-client/index.js").NativeAsset[]>;
|
|
620
670
|
/**
|
|
@@ -636,13 +686,27 @@ export interface BrowserBridge {
|
|
|
636
686
|
readonly report: import("alpha2/apply-edit").EditReport;
|
|
637
687
|
}>;
|
|
638
688
|
/**
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
|
|
689
|
+
* What {@link extract} runs: the inputs it reads for each media, the artifacts it runs and
|
|
690
|
+
* whether it fills resource slots. `pluginProblem` from `alpha2/plugins` says, from a manifest,
|
|
691
|
+
* why a plugin would not run here.
|
|
692
|
+
*/
|
|
693
|
+
extractCapabilities(): import("alpha2/plugins").PluginCapabilities;
|
|
694
|
+
/**
|
|
695
|
+
* Runs an extractor over a source's original media or the timeline on this page (`runExtractor`
|
|
696
|
+
* from `alpha2/extract`), with an app's `extractor` or a `plugin`: one the app loaded with
|
|
697
|
+
* `loadPlugin` from `alpha2/plugins`, which many runs share (its module compiles once), or a
|
|
698
|
+
* manifest and its SHA-256 for the bridge to load for this run, with `fetch` when the app fetches
|
|
699
|
+
* the plugin's files itself (a cache, a proxy). `onProgress` reports the plugin's files as they
|
|
700
|
+
* arrive (`phase: "load"`), then the extraction. Resolves with the result and the read taken when
|
|
701
|
+
* the run started; commit them with `EditorSession.applyExtraction(result, { read })`.
|
|
643
702
|
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
703
|
+
* Timeline frames are drawn as the CPU renderer draws them at export quality, as every surface
|
|
704
|
+
* reads them; timeline audio is not supplied (`INVALID_INPUT`).
|
|
705
|
+
*
|
|
706
|
+
* Rejects without exactly one of `plugin` and `extractor` (`invalid_command`), without the
|
|
707
|
+
* source's original in this session or, for a timeline input, a file the timeline shows
|
|
708
|
+
* (`missing_asset`), for a timeline that draws runtime effects or HDR video this browser cannot
|
|
709
|
+
* read (`unsupported_media`),
|
|
646
710
|
* with the plugin loader's and the extractor's errors (`PLUGIN_*`, `INVALID_INPUT`,
|
|
647
711
|
* `INVALID_EMIT`, `EXTRACTOR_FAILED`, `DECODE_UNAVAILABLE`), with `cancelled` when `signal`
|
|
648
712
|
* aborts or the bridge is disposed, and after disposal (`disposed`).
|
|
@@ -653,10 +717,14 @@ export interface BrowserBridge {
|
|
|
653
717
|
readonly sha256: string;
|
|
654
718
|
/** The most linear memory the module may have; the loader's default when left out. */
|
|
655
719
|
readonly memoryBytes?: number;
|
|
656
|
-
|
|
720
|
+
/** Fetches the plugin's files; `globalThis.fetch` when left out. */
|
|
721
|
+
readonly fetch?: typeof fetch;
|
|
722
|
+
/** What fills each resource slot, as `loadPlugin` takes it. */
|
|
723
|
+
readonly supplied?: Readonly<Record<string, import("alpha2/plugins").SuppliedSource>>;
|
|
724
|
+
} | import("alpha2/plugins").LoadedPlugin;
|
|
657
725
|
readonly extractor?: import("alpha2/extractor").Extractor;
|
|
658
726
|
readonly signal?: AbortSignal;
|
|
659
|
-
readonly onProgress?: (progress: import("alpha2/extractor").ExtractProgress) => void;
|
|
727
|
+
readonly onProgress?: (progress: import("alpha2/plugins").PluginLoadProgress | import("alpha2/extractor").ExtractProgress) => void;
|
|
660
728
|
}): Promise<{
|
|
661
729
|
readonly result: import("alpha2/extractor").ExtractResult;
|
|
662
730
|
readonly read: import("../core/session.js").ExtractionRead;
|
|
@@ -731,11 +799,14 @@ export interface BrowserBridge {
|
|
|
731
799
|
/**
|
|
732
800
|
* Adds or replaces a source whose provider reads no file, such as `{ format: "latex", ... }`,
|
|
733
801
|
* in one undoable `asset.put`. With an existing `id` its clips keep showing it with the new
|
|
734
|
-
* settings. The source is opened first, so its bin thumbnail and size are known.
|
|
802
|
+
* settings. The source is opened first, so its bin thumbnail and size are known. `then` runs in
|
|
803
|
+
* the same undo step after the `asset.put`, such as the commands that place a clip of it; as a
|
|
804
|
+
* function it is called with the source's ID and the size it opened at (`null` without one).
|
|
735
805
|
*
|
|
736
806
|
* Rejects with `EditorError` `unsupported_media` for a provider that reads a file (use
|
|
737
|
-
* {@link BrowserBridge.importFiles}), `unreadable_media` when the source does not open,
|
|
738
|
-
* `stale_import` when the session loads another project meanwhile
|
|
807
|
+
* {@link BrowserBridge.importFiles}), `unreadable_media` when the source does not open,
|
|
808
|
+
* `stale_import` when the session loads another project meanwhile, and with the refusal of a
|
|
809
|
+
* `then` command (nothing is committed).
|
|
739
810
|
*/
|
|
740
811
|
putProviderSource(source: {
|
|
741
812
|
readonly id?: string;
|
|
@@ -743,6 +814,11 @@ export interface BrowserBridge {
|
|
|
743
814
|
readonly provider: import("alpha2/project").ProviderSource;
|
|
744
815
|
}, options?: {
|
|
745
816
|
signal?: AbortSignal;
|
|
817
|
+
then?: readonly import("../core/commands.js").Command[] | ((opened: {
|
|
818
|
+
readonly assetId: string;
|
|
819
|
+
readonly width: number | null;
|
|
820
|
+
readonly height: number | null;
|
|
821
|
+
}) => readonly import("../core/commands.js").Command[]);
|
|
746
822
|
}): Promise<{
|
|
747
823
|
assetId: string;
|
|
748
824
|
}>;
|
package/dist/browser/worker.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Alpha2WasmError, serializeError } from "alpha2/worker-error";
|
|
2
2
|
import { withinActiveTime } from "alpha2/active-clock";
|
|
3
3
|
import { SourcePixels } from "./runtime/sources.js";
|
|
4
|
+
import { reviveAssetFiles } from "./runtime/range-file.js";
|
|
4
5
|
import { extensionWasmUrls } from "./runtime/extension-import.js";
|
|
5
6
|
import { AudioWindowSupplier, mixBlock } from "./runtime/audio.js";
|
|
6
7
|
const INSTALLED = Symbol.for("alpha2.editorWorker");
|
|
@@ -106,7 +107,7 @@ function serveEditorWorker(scope) {
|
|
|
106
107
|
assets.delete(id);
|
|
107
108
|
await pixels.release(keep);
|
|
108
109
|
for (const asset of request.assets ?? [])
|
|
109
|
-
assets.set(asset.id, asset);
|
|
110
|
+
assets.set(asset.id, reviveAssetFiles(asset));
|
|
110
111
|
if (request.fonts)
|
|
111
112
|
engine.setCaptionFonts(request.fonts);
|
|
112
113
|
currentProject = request.project;
|