alpha2 0.5.2 → 0.6.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 +71 -5
- package/THIRD_PARTY_NOTICES.md +191 -1
- package/dist/apply-edit.d.ts +124 -0
- package/dist/apply-edit.js +15 -0
- package/dist/assets.d.ts +12 -0
- package/dist/audio-layout.js +6 -3
- package/dist/audio-worklet-processor.js +27 -33
- package/dist/audio.d.ts +5 -4
- package/dist/audio.js +8 -6
- package/dist/compose.d.ts +105 -0
- package/dist/compose.js +63 -0
- package/dist/decoder-fallback.d.ts +3 -2
- package/dist/decoder-fallback.js +11 -3
- package/dist/decoder-stall.d.ts +15 -0
- package/dist/decoder-stall.js +52 -0
- package/dist/edit-data.d.ts +24 -0
- package/dist/edit-data.js +224 -0
- package/dist/edit-keys.d.ts +16 -0
- package/dist/edit-keys.js +233 -0
- package/dist/edit.d.ts +41 -8
- package/dist/edit.js +123 -30
- package/dist/export-failure.d.ts +10 -2
- package/dist/export-failure.js +55 -4
- package/dist/export-retry.d.ts +6 -1
- package/dist/export-retry.js +12 -1
- package/dist/exporter.d.ts +11 -7
- package/dist/exporter.js +10 -9
- package/dist/extensions.d.ts +86 -28
- package/dist/extensions.js +204 -61
- package/dist/extract.d.ts +65 -0
- package/dist/extract.js +291 -0
- package/dist/extractor.d.ts +151 -0
- package/dist/extractor.js +141 -0
- package/dist/float32.d.ts +2 -0
- package/dist/float32.js +10 -0
- package/dist/frame-intake.d.ts +5 -0
- package/dist/frame-intake.js +10 -3
- package/dist/generated/builtin-effects.d.ts +3 -0
- package/dist/generated/builtin-effects.js +1804 -0
- package/dist/generated/project-schema.d.ts +696 -41
- package/dist/generated/project-schema.js +67 -0
- package/dist/generated/project-shape.js +986 -383
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/json-text.js +14 -2
- package/dist/layout-values.js +7 -1
- package/dist/layout.d.ts +12 -4
- package/dist/media.d.ts +44 -11
- package/dist/media.js +256 -67
- package/dist/mediabunny.d.ts +32 -12
- package/dist/mediabunny.js +276 -90
- package/dist/player.d.ts +9 -3
- package/dist/player.js +114 -18
- package/dist/plugins.d.ts +62 -0
- package/dist/plugins.js +506 -0
- package/dist/project-data.d.ts +56 -0
- package/dist/project-data.js +765 -0
- package/dist/project.d.ts +36 -1
- package/dist/project.js +515 -42
- package/dist/robustness.d.ts +6 -33
- package/dist/robustness.js +2 -63
- package/dist/sha256.d.ts +3 -2
- package/dist/sha256.js +14 -6
- package/dist/wasm-module.d.ts +37 -0
- package/dist/wasm-module.js +47 -0
- package/dist/worker-error.d.ts +3 -2
- package/dist/worker-error.js +3 -1
- package/dist/worker.d.ts +13 -3
- package/dist/worker.js +36 -9
- package/package.json +36 -2
- package/wasm/alpha2_compose.d.ts +92 -0
- package/wasm/alpha2_compose.js +445 -0
- package/wasm/alpha2_compose_bg.wasm +0 -0
- package/wasm/alpha2_compose_bg.wasm.d.ts +17 -0
- package/wasm/alpha2_extensions.d.ts +4 -4
- package/wasm/alpha2_extensions.js +16 -4
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf.d.ts +227 -0
- package/wasm/alpha2_extensions_pdf.js +841 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm.d.ts +38 -0
- package/wasm/alpha2_wasm.d.ts +151 -18
- package/wasm/alpha2_wasm.js +403 -59
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +21 -6
- package/wasm/rust-crate-licenses.md +493 -54
- package/wasm/snippets/alpha2-wasm-1b02e9f302d283ba/inline3.js +7 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline1.js → alpha2-wasm-1b02e9f302d283ba/inline0.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline2.js → alpha2-wasm-1b02e9f302d283ba/inline1.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline3.js → alpha2-wasm-1b02e9f302d283ba/inline2.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline0.js → alpha2-wasm-1b02e9f302d283ba/inline4.js} +0 -0
package/dist/audio.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { raceAbort } from "./abort.js";
|
|
1
2
|
import { recordCleanupFailure } from "./export-failure.js";
|
|
2
3
|
/**
|
|
3
4
|
* Renders `totalFrames` frames through `render` into `sink`, one block at a time, with block
|
|
4
5
|
* sizes cycling through `blockSizes`.
|
|
5
6
|
*
|
|
6
7
|
* On success the sink's `finish` is awaited. On any failure, including `signal` aborting before
|
|
7
|
-
*
|
|
8
|
-
* (`signal.reason` or an `AbortError` for an abort). An
|
|
8
|
+
* `finish` resolves, the sink's `abort` is awaited and the promise rejects with the error
|
|
9
|
+
* (`signal.reason` or an `AbortError` for an abort). An abort after `finish` resolved is ignored.
|
|
10
|
+
* An error thrown by `abort` does not replace it.
|
|
9
11
|
*
|
|
10
12
|
* @throws RangeError When `totalFrames` is negative, `blockSizes` is empty or holds a size that is
|
|
11
13
|
* not a positive safe integer (checked before the sink is touched), or `render` returns a block
|
|
@@ -19,10 +21,11 @@ export async function renderOfflineAudio(totalFrames, blockSizes, render, sink,
|
|
|
19
21
|
}
|
|
20
22
|
let position = 0n;
|
|
21
23
|
let block = 0;
|
|
22
|
-
|
|
24
|
+
const abortReason = (aborted) => aborted.reason ??
|
|
25
|
+
new DOMException("Aborted", "AbortError");
|
|
23
26
|
const throwIfAborted = () => {
|
|
24
27
|
if (signal?.aborted === true)
|
|
25
|
-
throw signal
|
|
28
|
+
throw abortReason(signal);
|
|
26
29
|
};
|
|
27
30
|
try {
|
|
28
31
|
while (position < totalFrames) {
|
|
@@ -39,8 +42,7 @@ export async function renderOfflineAudio(totalFrames, blockSizes, render, sink,
|
|
|
39
42
|
block += 1;
|
|
40
43
|
}
|
|
41
44
|
throwIfAborted();
|
|
42
|
-
await sink.finish();
|
|
43
|
-
throwIfAborted();
|
|
45
|
+
await raceAbort(sink.finish(), signal, undefined, abortReason);
|
|
44
46
|
}
|
|
45
47
|
catch (error) {
|
|
46
48
|
const failure = error instanceof Error ? error : new Error(String(error));
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compose and its templates in the browser. The engine's own code runs through the wasm binding,
|
|
3
|
+
* so a spec compiles to the same bytes here as in Python or on a server.
|
|
4
|
+
*/
|
|
5
|
+
/** The binding functions {@link loadCompose} returns. */
|
|
6
|
+
export interface ComposeBinding {
|
|
7
|
+
composeRequirements(spec: string): string;
|
|
8
|
+
composeCompile(spec: string, facts: string, fonts: Uint8Array[]): string;
|
|
9
|
+
composeBind(document: string, data: string, options: string): string;
|
|
10
|
+
composeDataSchema(template: string): string;
|
|
11
|
+
composeLint(template: string, data: string, options: string): string;
|
|
12
|
+
composeTemplates(): string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The compose module, a wasm module of its own (`alpha2/compose-wasm`) so pages that only play
|
|
16
|
+
* and export projects never fetch it. `wasmUrl` locates its `.wasm` when a bundler moved it.
|
|
17
|
+
*
|
|
18
|
+
* @throws When the module cannot be fetched, compiled or instantiated.
|
|
19
|
+
*/
|
|
20
|
+
export declare function loadCompose(wasmUrl?: string | URL): Promise<ComposeBinding>;
|
|
21
|
+
/** A compose spec or template, as plain JSON data. */
|
|
22
|
+
export type ComposeDocument = Readonly<Record<string, unknown>>;
|
|
23
|
+
/** The media files a spec names, to gather facts about, and the caption texts it reads. */
|
|
24
|
+
export interface ComposeRequirements {
|
|
25
|
+
readonly media: readonly {
|
|
26
|
+
readonly path: string;
|
|
27
|
+
readonly kind: "video" | "image" | "audio";
|
|
28
|
+
}[];
|
|
29
|
+
readonly texts: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
/** Facts about a spec's files, keyed by path, as `compose` reads them. */
|
|
32
|
+
export interface ComposeFacts {
|
|
33
|
+
readonly media?: Readonly<Record<string, {
|
|
34
|
+
readonly width?: number;
|
|
35
|
+
readonly height?: number;
|
|
36
|
+
readonly frame_rate?: {
|
|
37
|
+
readonly num: number;
|
|
38
|
+
readonly den: number;
|
|
39
|
+
};
|
|
40
|
+
readonly duration_ticks?: number;
|
|
41
|
+
/** Required for a video that plays unmuted. */
|
|
42
|
+
readonly has_audio?: boolean;
|
|
43
|
+
}>>;
|
|
44
|
+
readonly texts?: Readonly<Record<string, string>>;
|
|
45
|
+
}
|
|
46
|
+
/** A compiled spec with its project, the file each media source reads, and notes. */
|
|
47
|
+
export interface CompiledCompose {
|
|
48
|
+
readonly project: Readonly<Record<string, unknown>>;
|
|
49
|
+
readonly assets: Readonly<Record<string, string>>;
|
|
50
|
+
readonly loudness: unknown;
|
|
51
|
+
readonly warnings: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
/** A problem `lintTemplate` finds. */
|
|
54
|
+
export interface TemplateIssue {
|
|
55
|
+
readonly path: string;
|
|
56
|
+
readonly code: string;
|
|
57
|
+
readonly message: string;
|
|
58
|
+
readonly severity: "error" | "warning";
|
|
59
|
+
}
|
|
60
|
+
/** What binding takes besides the template and its data. */
|
|
61
|
+
export interface BindOptions {
|
|
62
|
+
/** A theme for a video template, replacing the one it names. */
|
|
63
|
+
readonly theme?: string | Readonly<Record<string, unknown>>;
|
|
64
|
+
/** Node templates the document names, besides the built-in `alpha2/` ones. */
|
|
65
|
+
readonly templates?: readonly ComposeDocument[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The files `spec` names, to gather facts about before compiling.
|
|
69
|
+
*
|
|
70
|
+
* @throws The binding's `INVALID_INPUT` error, its message `path: problem`, for a spec that
|
|
71
|
+
* does not parse.
|
|
72
|
+
*/
|
|
73
|
+
export declare function composeRequirements(binding: ComposeBinding, spec: ComposeDocument): ComposeRequirements;
|
|
74
|
+
/**
|
|
75
|
+
* Compiles `spec` with facts about its files and the fonts its text is measured with. Built-in
|
|
76
|
+
* `alpha2/` template nodes expand; bind other templates with {@link bindTemplate} first.
|
|
77
|
+
*
|
|
78
|
+
* @throws The binding's `INVALID_INPUT` error, its message `path: problem`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function compileCompose(binding: ComposeBinding, spec: ComposeDocument, options?: {
|
|
81
|
+
readonly facts?: ComposeFacts;
|
|
82
|
+
readonly fonts?: Uint8Array[];
|
|
83
|
+
}): CompiledCompose;
|
|
84
|
+
/**
|
|
85
|
+
* Binds `template` to `data`, replacing its parameters and expanding its template nodes into a
|
|
86
|
+
* plain spec (or, for a node template, a node). A spec without a `template` header only has
|
|
87
|
+
* its template nodes expanded.
|
|
88
|
+
*
|
|
89
|
+
* @throws The binding's `INVALID_INPUT` error, naming where the template or data does not bind.
|
|
90
|
+
*/
|
|
91
|
+
export declare function bindTemplate(binding: ComposeBinding, template: ComposeDocument, data?: Readonly<Record<string, unknown>>, options?: BindOptions): Record<string, unknown>;
|
|
92
|
+
/**
|
|
93
|
+
* The JSON Schema of the data a form, an API or a model fills in for `template`.
|
|
94
|
+
*
|
|
95
|
+
* @throws The binding's `INVALID_INPUT` error for a template that does not parse.
|
|
96
|
+
*/
|
|
97
|
+
export declare function templateDataSchema(binding: ComposeBinding, template: ComposeDocument): Record<string, unknown>;
|
|
98
|
+
/**
|
|
99
|
+
* Lists `template`'s problems. It flags unknown or unused parameters, and literal files, colors
|
|
100
|
+
* and words a template takes from its data and theme. It also checks that it binds (to `data`,
|
|
101
|
+
* or to sample data) into a spec that parses.
|
|
102
|
+
*/
|
|
103
|
+
export declare function lintTemplate(binding: ComposeBinding, template: ComposeDocument, data?: Readonly<Record<string, unknown>>, options?: Pick<BindOptions, "templates">): TemplateIssue[];
|
|
104
|
+
/** The built-in `alpha2/` templates. */
|
|
105
|
+
export declare function builtinTemplates(binding: ComposeBinding): Record<string, unknown>[];
|
package/dist/compose.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compose and its templates in the browser. The engine's own code runs through the wasm binding,
|
|
3
|
+
* so a spec compiles to the same bytes here as in Python or on a server.
|
|
4
|
+
*/
|
|
5
|
+
import { WasmModule } from "./wasm-module.js";
|
|
6
|
+
const composeModule = new WasmModule(() => import("alpha2/compose-wasm"));
|
|
7
|
+
/**
|
|
8
|
+
* The compose module, a wasm module of its own (`alpha2/compose-wasm`) so pages that only play
|
|
9
|
+
* and export projects never fetch it. `wasmUrl` locates its `.wasm` when a bundler moved it.
|
|
10
|
+
*
|
|
11
|
+
* @throws When the module cannot be fetched, compiled or instantiated.
|
|
12
|
+
*/
|
|
13
|
+
export function loadCompose(wasmUrl) {
|
|
14
|
+
return composeModule.load(wasmUrl);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The files `spec` names, to gather facts about before compiling.
|
|
18
|
+
*
|
|
19
|
+
* @throws The binding's `INVALID_INPUT` error, its message `path: problem`, for a spec that
|
|
20
|
+
* does not parse.
|
|
21
|
+
*/
|
|
22
|
+
export function composeRequirements(binding, spec) {
|
|
23
|
+
return JSON.parse(binding.composeRequirements(JSON.stringify(spec)));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Compiles `spec` with facts about its files and the fonts its text is measured with. Built-in
|
|
27
|
+
* `alpha2/` template nodes expand; bind other templates with {@link bindTemplate} first.
|
|
28
|
+
*
|
|
29
|
+
* @throws The binding's `INVALID_INPUT` error, its message `path: problem`.
|
|
30
|
+
*/
|
|
31
|
+
export function compileCompose(binding, spec, options = {}) {
|
|
32
|
+
return JSON.parse(binding.composeCompile(JSON.stringify(spec), JSON.stringify(options.facts ?? {}), options.fonts ?? []));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Binds `template` to `data`, replacing its parameters and expanding its template nodes into a
|
|
36
|
+
* plain spec (or, for a node template, a node). A spec without a `template` header only has
|
|
37
|
+
* its template nodes expanded.
|
|
38
|
+
*
|
|
39
|
+
* @throws The binding's `INVALID_INPUT` error, naming where the template or data does not bind.
|
|
40
|
+
*/
|
|
41
|
+
export function bindTemplate(binding, template, data = {}, options = {}) {
|
|
42
|
+
return JSON.parse(binding.composeBind(JSON.stringify(template), JSON.stringify(data), JSON.stringify(options)));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The JSON Schema of the data a form, an API or a model fills in for `template`.
|
|
46
|
+
*
|
|
47
|
+
* @throws The binding's `INVALID_INPUT` error for a template that does not parse.
|
|
48
|
+
*/
|
|
49
|
+
export function templateDataSchema(binding, template) {
|
|
50
|
+
return JSON.parse(binding.composeDataSchema(JSON.stringify(template)));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Lists `template`'s problems. It flags unknown or unused parameters, and literal files, colors
|
|
54
|
+
* and words a template takes from its data and theme. It also checks that it binds (to `data`,
|
|
55
|
+
* or to sample data) into a spec that parses.
|
|
56
|
+
*/
|
|
57
|
+
export function lintTemplate(binding, template, data, options = {}) {
|
|
58
|
+
return JSON.parse(binding.composeLint(JSON.stringify(template), data === undefined ? "" : JSON.stringify(data), JSON.stringify(options)));
|
|
59
|
+
}
|
|
60
|
+
/** The built-in `alpha2/` templates. */
|
|
61
|
+
export function builtinTemplates(binding) {
|
|
62
|
+
return JSON.parse(binding.composeTemplates());
|
|
63
|
+
}
|
|
@@ -3,9 +3,10 @@ import { type TrackDecodeFacts } from "./hdr-frames.js";
|
|
|
3
3
|
export declare function isDecoderFailure(error: unknown): boolean;
|
|
4
4
|
/**
|
|
5
5
|
* Runs `decodeOnce`; on a decoder failure, if `reopenSoftware` is given, reopens in software and
|
|
6
|
-
* runs it once more.
|
|
6
|
+
* runs it once more. When that attempt fails in its decoder too, `restore` runs before the
|
|
7
|
+
* rejection, so the next request starts from the original choice.
|
|
7
8
|
*/
|
|
8
|
-
export declare function withSoftwareFallback<T>(decodeOnce: () => Promise<T>, reopenSoftware: ((cause: DOMException) => Promise<void>) | undefined): Promise<T>;
|
|
9
|
+
export declare function withSoftwareFallback<T>(decodeOnce: () => Promise<T>, reopenSoftware: ((cause: DOMException) => Promise<void>) | undefined, restore?: () => Promise<void>): Promise<T>;
|
|
9
10
|
/**
|
|
10
11
|
* Turns a decoder failure into {@link DecodeUnavailableError} when no frame of the track was ever
|
|
11
12
|
* decoded. Other errors are returned unchanged.
|
package/dist/decoder-fallback.js
CHANGED
|
@@ -8,9 +8,10 @@ export function isDecoderFailure(error) {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Runs `decodeOnce`; on a decoder failure, if `reopenSoftware` is given, reopens in software and
|
|
11
|
-
* runs it once more.
|
|
11
|
+
* runs it once more. When that attempt fails in its decoder too, `restore` runs before the
|
|
12
|
+
* rejection, so the next request starts from the original choice.
|
|
12
13
|
*/
|
|
13
|
-
export async function withSoftwareFallback(decodeOnce, reopenSoftware) {
|
|
14
|
+
export async function withSoftwareFallback(decodeOnce, reopenSoftware, restore) {
|
|
14
15
|
try {
|
|
15
16
|
return await decodeOnce();
|
|
16
17
|
}
|
|
@@ -18,7 +19,14 @@ export async function withSoftwareFallback(decodeOnce, reopenSoftware) {
|
|
|
18
19
|
if (reopenSoftware === undefined || !isDecoderFailure(error))
|
|
19
20
|
throw error;
|
|
20
21
|
await reopenSoftware(error);
|
|
21
|
-
|
|
22
|
+
try {
|
|
23
|
+
return await decodeOnce();
|
|
24
|
+
}
|
|
25
|
+
catch (retry) {
|
|
26
|
+
if (restore !== undefined && isDecoderFailure(retry))
|
|
27
|
+
await restore();
|
|
28
|
+
throw retry;
|
|
29
|
+
}
|
|
22
30
|
}
|
|
23
31
|
}
|
|
24
32
|
/**
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** A `DECODE_STALLED` error, classed as a GPU timeout in the decode phase. */
|
|
2
|
+
export declare function decoderStalled(message: string, stage: string): Error;
|
|
3
|
+
/**
|
|
4
|
+
* The iterator's next sample, raced against `stallMs` of active time (a frozen page does not
|
|
5
|
+
* count) and `signal`. On a stall (`DECODE_STALLED`) or an abort (the signal's reason) the
|
|
6
|
+
* iterator is ended and a sample that arrives late is closed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function nextSampleOrStall<T extends {
|
|
9
|
+
close(): void;
|
|
10
|
+
}>(iterator: AsyncIterator<T>, { stallMs, signal, sourceId, kind, }: {
|
|
11
|
+
readonly stallMs: number;
|
|
12
|
+
readonly signal?: AbortSignal | undefined;
|
|
13
|
+
readonly sourceId: string;
|
|
14
|
+
readonly kind: "video" | "audio";
|
|
15
|
+
}): Promise<IteratorResult<T>>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Stall limits shared by the video and audio decoder adapters.
|
|
2
|
+
import { activeTimeout } from "./active-clock.js";
|
|
3
|
+
/** A `DECODE_STALLED` error, classed as a GPU timeout in the decode phase. */
|
|
4
|
+
export function decoderStalled(message, stage) {
|
|
5
|
+
return Object.assign(new Error(message), {
|
|
6
|
+
code: "DECODE_STALLED",
|
|
7
|
+
failure: {
|
|
8
|
+
code: "GPU_TIMEOUT",
|
|
9
|
+
phase: "decode",
|
|
10
|
+
stage,
|
|
11
|
+
resource: "unknown",
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The iterator's next sample, raced against `stallMs` of active time (a frozen page does not
|
|
17
|
+
* count) and `signal`. On a stall (`DECODE_STALLED`) or an abort (the signal's reason) the
|
|
18
|
+
* iterator is ended and a sample that arrives late is closed.
|
|
19
|
+
*/
|
|
20
|
+
export async function nextSampleOrStall(iterator, { stallMs, signal, sourceId, kind, }) {
|
|
21
|
+
const pending = iterator.next();
|
|
22
|
+
const settled = new AbortController();
|
|
23
|
+
let abort;
|
|
24
|
+
const interrupted = new Promise((_, reject) => {
|
|
25
|
+
void activeTimeout(stallMs, settled.signal).then(() => reject(decoderStalled(`${kind} decoder ${sourceId} stalled: no ${kind === "video" ? "frame" : "samples"} for ${stallMs} ms`, `${kind}-decoder-stalled`)));
|
|
26
|
+
if (signal === undefined)
|
|
27
|
+
return;
|
|
28
|
+
abort = () => reject(signal.reason instanceof Error
|
|
29
|
+
? signal.reason
|
|
30
|
+
: new DOMException("Aborted", "AbortError"));
|
|
31
|
+
if (signal.aborted)
|
|
32
|
+
abort();
|
|
33
|
+
else
|
|
34
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
return await Promise.race([pending, interrupted]);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
void pending.then((late) => {
|
|
41
|
+
if (!late.done)
|
|
42
|
+
late.value.close();
|
|
43
|
+
}, () => { });
|
|
44
|
+
void iterator.return?.()?.catch(() => { });
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
settled.abort();
|
|
49
|
+
if (abort !== undefined)
|
|
50
|
+
signal?.removeEventListener("abort", abort);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DataSet, Project } from "./generated/project-schema.js";
|
|
2
|
+
/** Sorted, disjoint, non-empty `[start, end)` tick ranges. */
|
|
3
|
+
type Removal = readonly (readonly [number, number])[];
|
|
4
|
+
/**
|
|
5
|
+
* A timeline-anchored set with `removal` cut out and later times moved left; a sample set keeps
|
|
6
|
+
* the value read just after each cut, and a linear one also the value just before it (mirrors
|
|
7
|
+
* `split::cut_data`).
|
|
8
|
+
*/
|
|
9
|
+
export declare function cutData(set: DataSet, removal: Removal): DataSet;
|
|
10
|
+
/**
|
|
11
|
+
* Opens `delta > 0` ticks at `pivot` in a timeline-anchored set. Later times move right, an item
|
|
12
|
+
* across `pivot` lengthens, and a sample set holds the value read at `pivot` on both sides of the
|
|
13
|
+
* opening, so every moment outside it reads as before.
|
|
14
|
+
*/
|
|
15
|
+
export declare function openData(set: DataSet, pivot: number, delta: number): DataSet;
|
|
16
|
+
/**
|
|
17
|
+
* Edits `project`'s timeline-anchored data sets as a ripple of `delta` at `pivot` edits the
|
|
18
|
+
* timeline. A negative `delta` removes `[pivot + delta, pivot)` and a positive one opens that much
|
|
19
|
+
* time at `pivot`. Source-anchored sets never change.
|
|
20
|
+
*/
|
|
21
|
+
export declare function rippleTimelineData(project: Project, pivot: number, delta: number): Project;
|
|
22
|
+
/** `value` with every data binding that reads through clip `from` reading through `to`. */
|
|
23
|
+
export declare function renameVia<T>(value: T, from: string, to: string): T;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Timeline-anchored data and `via` under timeline edits, mirroring `alpha2_eval::edit`.
|
|
2
|
+
import { shortestFloat32 } from "./float32.js";
|
|
3
|
+
const F32_MAX = 3.4028234663852886e38;
|
|
4
|
+
/** The removed length before `tick` (mirrors `shift_of`). */
|
|
5
|
+
function shiftOf(tick, removal) {
|
|
6
|
+
let shift = 0;
|
|
7
|
+
for (const [from, to] of removal)
|
|
8
|
+
shift += to <= tick ? to - from : from < tick ? tick - from : 0;
|
|
9
|
+
return shift;
|
|
10
|
+
}
|
|
11
|
+
/** A kept tick's new position, `undefined` for a removed one (mirrors `new_time`). */
|
|
12
|
+
function newTime(tick, removal) {
|
|
13
|
+
if (removal.some(([from, to]) => from <= tick && tick < to))
|
|
14
|
+
return undefined;
|
|
15
|
+
return tick - shiftOf(tick, removal);
|
|
16
|
+
}
|
|
17
|
+
/** Mirrors `kept_windows_ticks`. */
|
|
18
|
+
function keptWindows(start, end, removal) {
|
|
19
|
+
const windows = [];
|
|
20
|
+
let cursor = start;
|
|
21
|
+
for (const [from, to] of removal) {
|
|
22
|
+
if (to <= cursor || from >= end)
|
|
23
|
+
continue;
|
|
24
|
+
if (from > cursor)
|
|
25
|
+
windows.push([cursor, from]);
|
|
26
|
+
cursor = Math.max(cursor, to);
|
|
27
|
+
}
|
|
28
|
+
if (cursor < end)
|
|
29
|
+
windows.push([cursor, end]);
|
|
30
|
+
return windows;
|
|
31
|
+
}
|
|
32
|
+
function arityOf(set) {
|
|
33
|
+
return set.kind === "points" ? 2 : set.kind === "similarity" ? 4 : 1;
|
|
34
|
+
}
|
|
35
|
+
function channelCount(set) {
|
|
36
|
+
return Math.max("channels" in set ? set.channels.length : 0, 1);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The 32-bit value of `channel` at `time`, or `undefined` when the channel has no known value
|
|
40
|
+
* (mirrors `sample_channel`).
|
|
41
|
+
*/
|
|
42
|
+
function sampleChannel(set, channel, arity, time) {
|
|
43
|
+
const width = channelCount(set) * arity;
|
|
44
|
+
const { times, values } = set;
|
|
45
|
+
const known = (sample) => {
|
|
46
|
+
const start = sample * width + channel * arity;
|
|
47
|
+
return sample < times.length && values[start] !== null
|
|
48
|
+
? values.slice(start, start + arity).map((v) => Math.fround(v ?? 0))
|
|
49
|
+
: undefined;
|
|
50
|
+
};
|
|
51
|
+
let next = 0;
|
|
52
|
+
for (let high = times.length; next < high;) {
|
|
53
|
+
const middle = (next + high) >> 1;
|
|
54
|
+
if (times[middle] <= time)
|
|
55
|
+
next = middle + 1;
|
|
56
|
+
else
|
|
57
|
+
high = middle;
|
|
58
|
+
}
|
|
59
|
+
const first = (from, to, step) => {
|
|
60
|
+
for (let sample = from; sample !== to; sample += step) {
|
|
61
|
+
const value = known(sample);
|
|
62
|
+
if (value)
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
};
|
|
67
|
+
const current = next - 1;
|
|
68
|
+
if (current < 0)
|
|
69
|
+
return first(0, times.length, 1);
|
|
70
|
+
const left = known(current);
|
|
71
|
+
if (left) {
|
|
72
|
+
const right = set.interpolation === "linear" && times[current] < time
|
|
73
|
+
? known(next)
|
|
74
|
+
: undefined;
|
|
75
|
+
if (!right)
|
|
76
|
+
return left;
|
|
77
|
+
const amount = (time - times[current]) / (times[next] - times[current]);
|
|
78
|
+
return left.map((from, index) => Math.fround(Math.min(F32_MAX, Math.max(-F32_MAX, from + (right[index] - from) * amount))));
|
|
79
|
+
}
|
|
80
|
+
return first(current - 1, -1, -1) ?? first(next, times.length, 1);
|
|
81
|
+
}
|
|
82
|
+
/** The values each channel reads at `time`, written as the engine writes 32-bit floats. */
|
|
83
|
+
function heldAt(set, time) {
|
|
84
|
+
const arity = arityOf(set);
|
|
85
|
+
const held = [];
|
|
86
|
+
for (let channel = 0; channel < channelCount(set); channel++) {
|
|
87
|
+
const value = sampleChannel(set, channel, arity, time);
|
|
88
|
+
held.push(...(value
|
|
89
|
+
? value.map(shortestFloat32)
|
|
90
|
+
: new Array(arity).fill(null)));
|
|
91
|
+
}
|
|
92
|
+
return held;
|
|
93
|
+
}
|
|
94
|
+
/** `set` with samples `entries` as `[tick, values]`, sorted by tick. */
|
|
95
|
+
function withSamples(set, entries) {
|
|
96
|
+
entries.sort((a, b) => a[0] - b[0]);
|
|
97
|
+
return {
|
|
98
|
+
...set,
|
|
99
|
+
times: entries.map(([tick]) => tick),
|
|
100
|
+
values: entries.flatMap(([, values]) => values),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function samplesOf(set, time) {
|
|
104
|
+
const width = channelCount(set) * arityOf(set);
|
|
105
|
+
const entries = [];
|
|
106
|
+
set.times.forEach((tick, index) => {
|
|
107
|
+
const moved = time(tick);
|
|
108
|
+
if (moved !== undefined)
|
|
109
|
+
entries.push([
|
|
110
|
+
moved,
|
|
111
|
+
set.values.slice(index * width, (index + 1) * width),
|
|
112
|
+
]);
|
|
113
|
+
});
|
|
114
|
+
return entries;
|
|
115
|
+
}
|
|
116
|
+
/** An item's new edges past removed ranges, `undefined` when none stays (mirrors `cut_item`). */
|
|
117
|
+
function cutItem(start, end, removal, instants) {
|
|
118
|
+
const windows = keptWindows(start, Math.max(end, start + 1), removal);
|
|
119
|
+
if (!windows.length)
|
|
120
|
+
return undefined;
|
|
121
|
+
const from = windows[0][0] - shiftOf(windows[0][0], removal);
|
|
122
|
+
const last = windows[windows.length - 1][1] - 1;
|
|
123
|
+
const to = end === start ? from : last - shiftOf(last, removal) + 1;
|
|
124
|
+
return instants || from < to ? [from, to] : undefined;
|
|
125
|
+
}
|
|
126
|
+
function byEdges(items) {
|
|
127
|
+
return items.sort((a, b) => a.start - b.start || a.end - b.end);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A timeline-anchored set with `removal` cut out and later times moved left; a sample set keeps
|
|
131
|
+
* the value read just after each cut, and a linear one also the value just before it (mirrors
|
|
132
|
+
* `split::cut_data`).
|
|
133
|
+
*/
|
|
134
|
+
export function cutData(set, removal) {
|
|
135
|
+
if (set.kind === "words" || set.kind === "intervals") {
|
|
136
|
+
const instants = set.kind === "intervals";
|
|
137
|
+
const cut = (items) => byEdges(items.flatMap((item) => {
|
|
138
|
+
const edges = cutItem(item.start, item.end, removal, instants);
|
|
139
|
+
return edges ? [{ ...item, start: edges[0], end: edges[1] }] : [];
|
|
140
|
+
}));
|
|
141
|
+
return set.kind === "words"
|
|
142
|
+
? { ...set, words: cut(set.words) }
|
|
143
|
+
: { ...set, intervals: cut(set.intervals) };
|
|
144
|
+
}
|
|
145
|
+
if (!set.times.length)
|
|
146
|
+
return set;
|
|
147
|
+
const entries = samplesOf(set, (tick) => newTime(tick, removal));
|
|
148
|
+
const ticks = new Set(entries.map(([tick]) => tick));
|
|
149
|
+
const linear = set.interpolation === "linear";
|
|
150
|
+
for (const [from, to] of removal) {
|
|
151
|
+
const reads = linear && from - 1 >= set.times[0] ? [from - 1, to] : [to];
|
|
152
|
+
for (const read of reads) {
|
|
153
|
+
const at = newTime(read, removal);
|
|
154
|
+
if (at === undefined || ticks.has(at))
|
|
155
|
+
continue;
|
|
156
|
+
ticks.add(at);
|
|
157
|
+
entries.push([at, heldAt(set, read)]);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return withSamples(set, entries);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Opens `delta > 0` ticks at `pivot` in a timeline-anchored set. Later times move right, an item
|
|
164
|
+
* across `pivot` lengthens, and a sample set holds the value read at `pivot` on both sides of the
|
|
165
|
+
* opening, so every moment outside it reads as before.
|
|
166
|
+
*/
|
|
167
|
+
export function openData(set, pivot, delta) {
|
|
168
|
+
if (set.kind === "words" || set.kind === "intervals") {
|
|
169
|
+
const open = (items) => byEdges(items.map((item) => item.start >= pivot
|
|
170
|
+
? { ...item, start: item.start + delta, end: item.end + delta }
|
|
171
|
+
: item.end > pivot
|
|
172
|
+
? { ...item, end: item.end + delta }
|
|
173
|
+
: item));
|
|
174
|
+
return set.kind === "words"
|
|
175
|
+
? { ...set, words: open(set.words) }
|
|
176
|
+
: { ...set, intervals: open(set.intervals) };
|
|
177
|
+
}
|
|
178
|
+
const entries = samplesOf(set, (tick) => tick >= pivot ? tick + delta : tick);
|
|
179
|
+
if (set.times.some((t) => t < pivot) && set.times.some((t) => t >= pivot)) {
|
|
180
|
+
const held = heldAt(set, pivot);
|
|
181
|
+
const ticks = new Set(entries.map(([tick]) => tick));
|
|
182
|
+
for (const at of [pivot, pivot + delta])
|
|
183
|
+
if (!ticks.has(at))
|
|
184
|
+
entries.push([at, held]);
|
|
185
|
+
}
|
|
186
|
+
return withSamples(set, entries);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Edits `project`'s timeline-anchored data sets as a ripple of `delta` at `pivot` edits the
|
|
190
|
+
* timeline. A negative `delta` removes `[pivot + delta, pivot)` and a positive one opens that much
|
|
191
|
+
* time at `pivot`. Source-anchored sets never change.
|
|
192
|
+
*/
|
|
193
|
+
export function rippleTimelineData(project, pivot, delta) {
|
|
194
|
+
if (!delta || !project.data?.some((set) => set.anchor.type === "timeline"))
|
|
195
|
+
return project;
|
|
196
|
+
const removal = [[pivot + delta, pivot]];
|
|
197
|
+
return {
|
|
198
|
+
...project,
|
|
199
|
+
data: project.data.map((set) => set.anchor.type !== "timeline"
|
|
200
|
+
? set
|
|
201
|
+
: delta < 0
|
|
202
|
+
? cutData(set, removal)
|
|
203
|
+
: openData(set, pivot, delta)),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/** `value` with every data binding that reads through clip `from` reading through `to`. */
|
|
207
|
+
export function renameVia(value, from, to) {
|
|
208
|
+
if (Array.isArray(value))
|
|
209
|
+
return value.map((item) => renameVia(item, from, to));
|
|
210
|
+
if (typeof value !== "object" || value === null)
|
|
211
|
+
return value;
|
|
212
|
+
const record = value;
|
|
213
|
+
if (record.mode === "data") {
|
|
214
|
+
const via = record.via;
|
|
215
|
+
return via?.clip === from ? { ...record, via: { clip: to } } : value;
|
|
216
|
+
}
|
|
217
|
+
let changed = false;
|
|
218
|
+
const next = {};
|
|
219
|
+
for (const [key, field] of Object.entries(record)) {
|
|
220
|
+
next[key] = renameVia(field, from, to);
|
|
221
|
+
changed ||= next[key] !== field;
|
|
222
|
+
}
|
|
223
|
+
return changed ? next : value;
|
|
224
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Animated } from "./generated/project-schema.js";
|
|
2
|
+
/** Sorted, disjoint, non-empty `[start, end)` tick ranges. */
|
|
3
|
+
type Removal = readonly (readonly [number, number])[];
|
|
4
|
+
/**
|
|
5
|
+
* Bus keyframes after `removal` leaves a rippled timeline: keys inside go, the rest move, the
|
|
6
|
+
* value at each cut is keyed on both sides, and every key takes the part of the old curve up to
|
|
7
|
+
* the next key (mirrors `shift_keys`).
|
|
8
|
+
*/
|
|
9
|
+
export declare function closeKeys(animation: Animated<number> | undefined, removal: Removal): Animated<number> | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Bus keyframes after `length` ticks open at `pivot`: keys at or after it move right, and when
|
|
12
|
+
* keys lie on both sides the value at `pivot` is held across the opening, so every moment outside
|
|
13
|
+
* it reads as before.
|
|
14
|
+
*/
|
|
15
|
+
export declare function openKeys(animation: Animated<number> | undefined, pivot: number, length: number): Animated<number> | undefined;
|
|
16
|
+
export {};
|