alpha2 0.5.3 → 0.6.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/README.md +68 -3
- package/THIRD_PARTY_NOTICES.md +7 -3
- 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/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 +636 -37
- package/dist/generated/project-schema.js +55 -0
- package/dist/generated/project-shape.js +950 -381
- 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 +43 -10
- package/dist/media.js +255 -66
- 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 +24 -1
- package/dist/project.js +456 -38
- 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/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 +26 -1
- 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_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm +0 -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 +5 -61
- package/wasm/snippets/alpha2-wasm-6749ed8b34a74067/inline3.js +7 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline1.js → alpha2-wasm-6749ed8b34a74067/inline0.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline2.js → alpha2-wasm-6749ed8b34a74067/inline1.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline3.js → alpha2-wasm-6749ed8b34a74067/inline2.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline0.js → alpha2-wasm-6749ed8b34a74067/inline4.js} +0 -0
package/README.md
CHANGED
|
@@ -75,9 +75,67 @@ The engine mixes the project's audio. The application uploads each source's deco
|
|
|
75
75
|
|
|
76
76
|
For preview, `alpha2/audio-timeline` moves the mixed blocks to the audio thread through a ring in shared memory, which needs a cross-origin isolated page (`canShareAudioMemory()` says whether this page is one), and `alpha2/audio-worklet` plays them in an AudioWorklet. `alpha2/loudness` measures loudness (ITU-R BS.1770-4, EBU R128) and plans normalization; `alpha2/waveform` computes waveform summaries.
|
|
77
77
|
|
|
78
|
+
## Extract data
|
|
79
|
+
|
|
80
|
+
`runExtractor` in `alpha2/extract` runs an extractor of your own over a source or the timeline and resolves with data sets ready to put in `project.data`. The browser decodes the source in software (mediabunny), the engine's session in wasm presents and checks every step, and each value is validated as the project validates data:
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
import { runExtractor } from "alpha2/extract";
|
|
84
|
+
|
|
85
|
+
const { dataSets } = await runExtractor(
|
|
86
|
+
{
|
|
87
|
+
binding: wasm,
|
|
88
|
+
project,
|
|
89
|
+
media: { interview: file },
|
|
90
|
+
request: {
|
|
91
|
+
extractor: "com.example.brightness",
|
|
92
|
+
version: 1,
|
|
93
|
+
input: { from: "source", source_id: "interview", range: { start: 0, end: 600_000 }, size: 64 },
|
|
94
|
+
outputs: { level: "interview-brightness" },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
describe: () => ({
|
|
99
|
+
id: "com.example.brightness",
|
|
100
|
+
version: 1,
|
|
101
|
+
input: { media: "video", from: ["source"], format: "luma8" },
|
|
102
|
+
outputs: [{ name: "level", kind: "scalars", channels: ["y"] }],
|
|
103
|
+
}),
|
|
104
|
+
video(frame, out) {
|
|
105
|
+
const sum = frame.data.reduce((total, value) => total + value, 0);
|
|
106
|
+
out.sample("level", frame.time, [sum / frame.data.length / 255]);
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
A timeline input needs `timelineFrame(time, width, height)`, such as the CPU renderer's `readRgbaAt`, and an audio input `audioBinding: wasm`. `loadPlugin(manifest, sha256)` in `alpha2/plugins` loads an [extractor plugin](https://github.com/alpha2-sh/alpha2/blob/main/docs/plugin-abi.md)'s wasm artifact, checked against its pinned hashes; pass it as `plugin` with `plugin.extractor(params)`. `applyEdit` in `alpha2/apply-edit` then applies data to the project, such as `remove_ranges` over silences.
|
|
113
|
+
|
|
114
|
+
## Compose
|
|
115
|
+
|
|
116
|
+
`alpha2/compose` compiles compose specs (videos described by intent: sequences, stacks, grids, media, text and templates) into projects in the browser, with the engine's own compose code, so a spec compiles to the same project here as in Python or in `alpha2-host`. It runs in a wasm module of its own (`alpha2/compose-wasm`, file `alpha2/wasm/alpha2_compose_bg.wasm`), which a page that only plays and exports projects never fetches:
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
import { bindTemplate, compileCompose, composeRequirements, loadCompose } from "alpha2/compose";
|
|
120
|
+
|
|
121
|
+
const compose = await loadCompose(); // or loadCompose(wasmUrl) when a bundler moved the .wasm
|
|
122
|
+
const spec = bindTemplate(compose, template, { headline: "Summer sale", photo: "beach.jpg" });
|
|
123
|
+
const { media, texts } = composeRequirements(compose, spec); // the files to gather facts about
|
|
124
|
+
const facts = await describeFiles(media, texts); // the application's own probe, shape below
|
|
125
|
+
const fonts = [new Uint8Array(await (await fetch("/fonts/Inter.ttf")).arrayBuffer())];
|
|
126
|
+
const { project, assets, loudness, warnings } = compileCompose(compose, spec, { facts, fonts });
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- `facts` describes the files the spec names: `{ media: { [path]: { width, height, frame_rate, duration_ticks, has_audio } }, texts: { [path]: text } }`. A video the spec plays unmuted needs `has_audio`.
|
|
130
|
+
- Fonts are font file bytes; text needs at least one font.
|
|
131
|
+
- `compileCompose` takes no templates: bind a spec's own templates with `bindTemplate` first (its `templates` option names node templates; `theme` replaces a video template's theme). Built-in `alpha2/` template nodes expand at compile time; `builtinTemplates` lists them.
|
|
132
|
+
- The result's `project` is a project document; `assets` maps each source id to the path it reads, `loudness` is `null` or the spec's target (`{ target_lufs, true_peak_ceiling_dbtp }`), and `warnings` are notes for the author.
|
|
133
|
+
- `templateDataSchema` gives the JSON Schema of a template's data, for a form, an API or a model to fill in, and `lintTemplate` lists a template's problems (`{ path, code, message, severity }`).
|
|
134
|
+
- A spec, template or data that does not compile or bind throws an `Error` whose message is `path: problem`, with `path` and `problem` as properties.
|
|
135
|
+
|
|
78
136
|
## Preview in a worker
|
|
79
137
|
|
|
80
|
-
`alpha2/worker` runs the engine in a worker that owns the GPU device and an `OffscreenCanvas` (`installRenderWorker`, `createWasmRenderWorkerHost`), and `WorkerRenderBackend` drives it from the page. The host's `renderer` option is `"auto"` (WebGPU, else WebGL2, on a hardware adapter, else the CPU renderer), `"gpu"` (any adapter, software ones included) or `"cpu"`; `WorkerRenderBackend.rendererChoice` says which renderer the worker made and why it draws on the CPU, as the native host's `renderer` and `rendererReason` do. `Alpha2Player` in `alpha2/player` presents times through such a backend: it serializes presentations, asks for the frames a presentation lacks and shows them once they arrive, and recovers a lost GPU through `GpuRecoveryLadder` (`alpha2/gpu-recovery`): the GPU again after a first external loss, the CPU renderer once the loss was the work's own (`GPU_DEVICE_HUNG`), recurred at the same frame, or the page has lost the GPU twice (the browser withdraws GPU access after its next reset). A recovery that needs a new canvas takes one from the player's `replaceSurface` option; `@alpha2-sh/react` supplies it.
|
|
138
|
+
`alpha2/worker` runs the engine in a worker that owns the GPU device and an `OffscreenCanvas` (`installRenderWorker`, `createWasmRenderWorkerHost`), and `WorkerRenderBackend` drives it from the page. The host's `renderer` option is `"auto"` (WebGPU, else WebGL2, on a hardware adapter, else the CPU renderer), `"gpu"` (any adapter, software ones included) or `"cpu"`; `WorkerRenderBackend.rendererChoice` says which renderer the worker made and why it draws on the CPU, as the native host's `renderer` and `rendererReason` do. `Alpha2Player` in `alpha2/player` presents times through such a backend: it serializes presentations (one runs and only the latest request waits), asks for the frames a presentation lacks and shows them once they arrive, and recovers a lost GPU through `GpuRecoveryLadder` (`alpha2/gpu-recovery`): the GPU again after a first external loss, the CPU renderer once the loss was the work's own (`GPU_DEVICE_HUNG`), recurred at the same frame, or the page has lost the GPU twice (the browser withdraws GPU access after its next reset). A recovery that needs a new canvas takes one from the player's `replaceSurface` option; `@alpha2-sh/react` supplies it.
|
|
81
139
|
|
|
82
140
|
## Subpaths
|
|
83
141
|
|
|
@@ -87,6 +145,10 @@ For preview, `alpha2/audio-timeline` moves the mixed blocks to the audio thread
|
|
|
87
145
|
| `alpha2/project` | The project document's types and limits, tick conversions, `validateProject`. |
|
|
88
146
|
| `alpha2/builder` | `ProjectBuilder`: documents from seconds, with generated ids. |
|
|
89
147
|
| `alpha2/edit` | Editing operations on a project: split, trim, ripple, roll, slip, slide, retime, insert, overwrite, append, move. |
|
|
148
|
+
| `alpha2/apply-edit` | `applyEdit`: the engine's edit operations that apply data to a project (`remove_ranges`, `split_at`, `bake`), the same canonical result on every surface. |
|
|
149
|
+
| `alpha2/extract`, `alpha2/plugins` | `runExtractor`: extractors of your own over a source or the timeline, decoded in the browser; `loadPlugin`: [extractor plugins](https://github.com/alpha2-sh/alpha2/blob/main/docs/plugin-abi.md) run sandboxed. |
|
|
150
|
+
| `alpha2/extractor` | The extractor contract every surface shares (`Extractor`, `ExtractorDescriptor`, `ExtractRun`, `ExtractResult`), types only, without a media library. |
|
|
151
|
+
| `alpha2/compose`, `alpha2/compose-wasm` | Compose specs and templates (`loadCompose`, `composeRequirements`, `compileCompose`, `bindTemplate`, `templateDataSchema`, `lintTemplate`, `builtinTemplates`), and the wasm module they load. See [Compose](#compose). |
|
|
90
152
|
| `alpha2/captions` | SRT and WebVTT import into caption tracks. |
|
|
91
153
|
| `alpha2/geometry` | Shape geometry for editors, from the engine's own code: item bounds, hit tests, nearest points, path lengths, trims, resampling, convert to path, motion paths. |
|
|
92
154
|
| `alpha2/layout` | Layout generators: `measureLayout` (where every box lies and what overflows, laid out with the engine's fonts, pixels those of the project canvas) and a builder from CSS-like props, flexbox and grid. See [docs/layout.md](https://github.com/alpha2-sh/alpha2/blob/main/docs/layout.md). |
|
|
@@ -104,13 +166,16 @@ For preview, `alpha2/audio-timeline` moves the mixed blocks to the audio thread
|
|
|
104
166
|
| `alpha2/exporter` | `Alpha2Exporter` and `exportToSink`. |
|
|
105
167
|
| `alpha2/export-destination` | Where an export's bytes go: a file, or memory. |
|
|
106
168
|
| `alpha2/export-failure`, `alpha2/export-retry` | How export failures are classified, and a retry policy over them. |
|
|
169
|
+
| `alpha2/export-metrics` | `ExportMetrics` and `BrowserExportPerformance`: the timing and memory of a browser export, under the names the native host's `performance` uses for the same quantities, and the encoder probe results. |
|
|
170
|
+
| `alpha2/worker-error` | Errors as plain data across a worker boundary, keeping their code and failure class (`serializeError`, `Alpha2WasmError`), and `wasmTrapCode`. |
|
|
171
|
+
| `alpha2/abort`, `alpha2/active-clock` | `AbortSignal` helpers (`abortError`, `throwIfAborted`, `raceAbort`); timeouts that count active time, so a frozen or sleeping page does not count as a stall (`activeTimeout`, `withinActiveTime`, `ActiveStopwatch`). |
|
|
107
172
|
| `alpha2/containers` | The export containers (MP4, MOV, MKV, WebM) and the codecs each offers. |
|
|
108
173
|
| `alpha2/rate-control` | Output bitrates for the engine's quality levels. |
|
|
109
174
|
| `alpha2/audio`, `alpha2/audio-worker` | Offline audio rendering into a sink, in a worker or not. |
|
|
110
175
|
| `alpha2/audio-timeline`, `alpha2/audio-worklet`, `alpha2/audio-worklet-processor` | Real-time audio: the shared ring, its pump, and the AudioWorklet and its processor module. |
|
|
111
176
|
| `alpha2/loudness`, `alpha2/waveform` | Loudness measurement and normalization; waveform summaries. |
|
|
112
|
-
| `alpha2/robustness` | Browser capability detection
|
|
113
|
-
| `alpha2` | `alpha2/assets`, `audio`, `audio-timeline`, `audio-worker`, `audio-worklet`, `containers`, `effects`, `exporter`, `extensions`, `frame-supply`, `hdr-frames`, `loudness`, `media`, `player`, `project`, `rate-control`, `robustness`, `text`, `waveform` and `worker` in one import. |
|
|
177
|
+
| `alpha2/robustness` | Browser capability detection. |
|
|
178
|
+
| `alpha2` | `alpha2/assets`, `audio`, `audio-timeline`, `audio-worker`, `audio-worklet`, `compose`, `containers`, `effects`, `exporter`, `export-metrics`, `extensions`, `frame-supply`, `gpu-recovery`, `hdr-frames`, `loudness`, `media`, `player`, `project`, `rate-control`, `renderer-choice`, `robustness`, `text`, `waveform` and `worker` in one import. |
|
|
114
179
|
|
|
115
180
|
Each module's declarations document its API.
|
|
116
181
|
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -4,7 +4,11 @@ alpha2 is under the MIT License (`LICENSE.md`). It also contains third-party wor
|
|
|
4
4
|
|
|
5
5
|
## Rust crates
|
|
6
6
|
|
|
7
|
-
The `alpha2` npm package
|
|
7
|
+
The `alpha2` npm package, the native archives, the `alpha2` Python wheels and the mobile packages each list the third-party Rust crates compiled into them, with their license texts: `wasm/rust-crate-licenses.md` in the npm package, `licenses/rust-crate-licenses.md` in each archive (and in the `alpha2-host` wheel built from it), `rust-crate-licenses.md` in the `.dist-info/licenses/` directory of each `alpha2` wheel, in `META-INF/alpha2/` of the Android library and in each framework of the Swift package's XCFramework. The wheels and the mobile packages carry this file and `LICENSE.md` beside that list.
|
|
8
|
+
|
|
9
|
+
## uniffi (iOS and Android packages)
|
|
10
|
+
|
|
11
|
+
The Swift package and the Android library contain the runtime of uniffi 0.32 (https://github.com/mozilla/uniffi-rs), unmodified, and Swift and Kotlin sources it generated. uniffi is under the Mozilla Public License 2.0 (https://mozilla.org/MPL/2.0/); its source is available from that repository at the tag `v0.32.2`. The packages' crate lists carry the license text. The mobile packages contain no FFmpeg.
|
|
8
12
|
|
|
9
13
|
## FFmpeg
|
|
10
14
|
|
|
@@ -82,7 +86,7 @@ In addition, the Cisco-provided binary of this Software is licensed under Cisco'
|
|
|
82
86
|
|
|
83
87
|
## STIX Two Math and the dvips color names
|
|
84
88
|
|
|
85
|
-
The `alpha2-extensions` crate, the extensions wasm module in the `alpha2` npm package,
|
|
89
|
+
The `alpha2-extensions` crate, the extensions wasm module in the `alpha2` npm package, the native archives (and the `alpha2-host` wheels built from them) and the mobile packages contain the STIX Two Math font (version 2.13) and a modified copy of the dvips color names, both embedded by the `latex-rust` crate (https://github.com/jscarr64/latex-rust) to typeset LaTeX math. The font is under the SIL Open Font License 1.1, below with its copyright and trademark signs and dashes written in ASCII.
|
|
86
90
|
|
|
87
91
|
The color names are a modified copy of `dvipsnam.def` from the `%<*dvipsnames>` section of `drivers.dtx` in the LaTeX graphics bundle, Copyright 1994 David Carlisle and Sebastian Rahtz, Copyright 1995-1999 David Carlisle, Copyright 2000-2026 The LaTeX Project, under the LaTeX Project Public License 1.3c or later (https://www.latex-project.org/lppl.txt). The definitions were rewritten as a tab-separated table and re-sorted by name; the original authors and The LaTeX Project do not maintain or support it. The unmodified graphics bundle is at https://github.com/latex3/latex2e/tree/develop/required/graphics (CTAN: macros/latex/required/graphics).
|
|
88
92
|
|
|
@@ -199,7 +203,7 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
|
199
203
|
|
|
200
204
|
## PDF standard fonts and CMaps
|
|
201
205
|
|
|
202
|
-
The `alpha2-extensions` crate, the extensions wasm module in the `alpha2` npm package,
|
|
206
|
+
The `alpha2-extensions` crate, the extensions wasm module in the `alpha2` npm package, the native archives (and the `alpha2-host` wheels built from them) and the mobile packages contain data the `hayro` crates (https://github.com/LaurenzV/hayro) embed to draw PDF pages: substitutes for the 14 standard PDF fonts, extracted from PDFium (original code copyright 2014 Foxit Software Inc.), and Adobe's predefined CMaps.
|
|
203
207
|
|
|
204
208
|
The standard font substitutes:
|
|
205
209
|
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edit operations that apply data to a project once, run by the engine's wasm.
|
|
3
|
+
*
|
|
4
|
+
* The operations are named for primitives: `remove_ranges` (drop silences, keep highlights),
|
|
5
|
+
* `split_at` (cut on beats) and `bake` (data bindings to keyframes, words to cues). Kept moments
|
|
6
|
+
* render as before for clip picture and sound, clip keyframes, captions, timeline-anchored data and
|
|
7
|
+
* track and master automation; a matte or a `via` binding follows the part beside it or the edit is
|
|
8
|
+
* refused (`matte_source`, `read_through`). `split_at` leaves out cuts it cannot make exactly
|
|
9
|
+
* (`report.skipped`); `remove_ranges` refuses them. The result is canonical on every runtime.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const { project: tight } = applyEdit(wasm, project, {
|
|
13
|
+
* op: "remove_ranges",
|
|
14
|
+
* ranges: { data: "silence" },
|
|
15
|
+
* target: { track: "v1" },
|
|
16
|
+
* padding: 12_000,
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { DataAnchor, Project } from "./generated/project-schema.js";
|
|
21
|
+
/** Ticks on an anchor's clock, `start <= end`. */
|
|
22
|
+
export interface TickRange {
|
|
23
|
+
readonly start: number;
|
|
24
|
+
readonly end: number;
|
|
25
|
+
}
|
|
26
|
+
/** The clips an operation works on: every clip of a track, or these clips. */
|
|
27
|
+
export type EditTarget = {
|
|
28
|
+
readonly track: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly clips: readonly string[];
|
|
31
|
+
};
|
|
32
|
+
/** One edit operation. Times are ticks. */
|
|
33
|
+
export type EditRequest = {
|
|
34
|
+
readonly op: "remove_ranges";
|
|
35
|
+
/** An `intervals` data set, or a list on an anchor's clock. */
|
|
36
|
+
readonly ranges: {
|
|
37
|
+
readonly data: string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly list: readonly TickRange[];
|
|
40
|
+
readonly anchor: DataAnchor;
|
|
41
|
+
};
|
|
42
|
+
readonly target: EditTarget;
|
|
43
|
+
/** What closes the gaps; `timeline` by default. */
|
|
44
|
+
readonly ripple?: "none" | "track" | "timeline";
|
|
45
|
+
/** Keeps only the ranges, removing their complement within the target clips' extent. */
|
|
46
|
+
readonly invert?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Ticks kept at each edge of every removed range; a negative value widens each range, which
|
|
49
|
+
* never starts before time 0.
|
|
50
|
+
*/
|
|
51
|
+
readonly padding?: number;
|
|
52
|
+
/** Removed ranges shorter than this, after padding, are kept. */
|
|
53
|
+
readonly min_duration?: number;
|
|
54
|
+
} | {
|
|
55
|
+
readonly op: "split_at";
|
|
56
|
+
/** An `intervals` data set's starts, or a list of ticks on an anchor's clock. */
|
|
57
|
+
readonly times: {
|
|
58
|
+
readonly data: string;
|
|
59
|
+
} | {
|
|
60
|
+
readonly list: readonly number[];
|
|
61
|
+
readonly anchor: DataAnchor;
|
|
62
|
+
};
|
|
63
|
+
readonly target: EditTarget;
|
|
64
|
+
} | {
|
|
65
|
+
readonly op: "bake";
|
|
66
|
+
/** Property paths use the lint path syntax (`visual.position`, `effect.params.radius`). */
|
|
67
|
+
readonly targets: readonly ({
|
|
68
|
+
readonly clip: string;
|
|
69
|
+
readonly property: string;
|
|
70
|
+
} | {
|
|
71
|
+
readonly composition: string;
|
|
72
|
+
readonly node: string;
|
|
73
|
+
readonly property: string;
|
|
74
|
+
} | {
|
|
75
|
+
readonly track: string;
|
|
76
|
+
readonly property: string;
|
|
77
|
+
})[];
|
|
78
|
+
};
|
|
79
|
+
/** What an operation changed, so a caller can show and select it. */
|
|
80
|
+
export interface EditReport {
|
|
81
|
+
/** Timeline ranges removed, in the old timeline's time. */
|
|
82
|
+
readonly removed: readonly TickRange[];
|
|
83
|
+
/** Kept stretches that moved. */
|
|
84
|
+
readonly moved: readonly {
|
|
85
|
+
readonly from: TickRange;
|
|
86
|
+
readonly to: TickRange;
|
|
87
|
+
}[];
|
|
88
|
+
/** Clips the operation created, each with the clip it was cut from (which keeps its id). */
|
|
89
|
+
readonly created: readonly {
|
|
90
|
+
readonly id: string;
|
|
91
|
+
readonly from: string;
|
|
92
|
+
}[];
|
|
93
|
+
/**
|
|
94
|
+
* Cuts `split_at` left out because they would change what a clip shows, in clip and time
|
|
95
|
+
* order; absent when it left none out.
|
|
96
|
+
*/
|
|
97
|
+
readonly skipped?: readonly {
|
|
98
|
+
readonly clip: string;
|
|
99
|
+
/** The cut, in timeline ticks. */
|
|
100
|
+
readonly time: number;
|
|
101
|
+
readonly reason: "in_transition" | "in_fade" | "matte_source" | "read_through";
|
|
102
|
+
}[];
|
|
103
|
+
}
|
|
104
|
+
/** An operation's result. */
|
|
105
|
+
export interface AppliedEdit {
|
|
106
|
+
readonly project: Project;
|
|
107
|
+
/** The engine's canonical text of `project`, byte for byte what every surface answers. */
|
|
108
|
+
readonly projectJson: string;
|
|
109
|
+
readonly report: EditReport;
|
|
110
|
+
}
|
|
111
|
+
/** Why an operation refused, as `Alpha2Error.details.refusal` names it. */
|
|
112
|
+
export type EditRefusal = "invalid_project" | "invalid_request" | "unknown_data" | "wrong_kind" | "unknown_target" | "empty_target" | "missing_anchor" | "invalid_range" | "nothing_to_bake" | "correction_not_bakeable" | "unbounded_parameter" | "matte_source" | "read_through" | "in_transition" | "in_fade" | "too_many_clips" | "too_many_cues" | "result_too_large" | "invalid_result";
|
|
113
|
+
/** The generated wasm function this wrapper calls. */
|
|
114
|
+
export interface ApplyEditBinding {
|
|
115
|
+
applyEdit(project: string, request: string): [string, string];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Applies `request` to `project`; neither is changed.
|
|
119
|
+
*
|
|
120
|
+
* @throws An `Alpha2Error` with code `INVALID_INPUT` for an invalid project or request and for
|
|
121
|
+
* every refusal (`ALPHA2_ERROR` for an edited project that fails validation, a defect);
|
|
122
|
+
* `details.refusal` names why.
|
|
123
|
+
*/
|
|
124
|
+
export declare function applyEdit(binding: ApplyEditBinding, project: Project, request: EditRequest): AppliedEdit;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies `request` to `project`; neither is changed.
|
|
3
|
+
*
|
|
4
|
+
* @throws An `Alpha2Error` with code `INVALID_INPUT` for an invalid project or request and for
|
|
5
|
+
* every refusal (`ALPHA2_ERROR` for an edited project that fails validation, a defect);
|
|
6
|
+
* `details.refusal` names why.
|
|
7
|
+
*/
|
|
8
|
+
export function applyEdit(binding, project, request) {
|
|
9
|
+
const [projectJson, report] = binding.applyEdit(JSON.stringify(project), JSON.stringify(request));
|
|
10
|
+
return {
|
|
11
|
+
project: JSON.parse(projectJson),
|
|
12
|
+
projectJson,
|
|
13
|
+
report: JSON.parse(report),
|
|
14
|
+
};
|
|
15
|
+
}
|
package/dist/assets.d.ts
CHANGED
|
@@ -170,6 +170,18 @@ export interface ConformReport {
|
|
|
170
170
|
readonly ready: boolean;
|
|
171
171
|
/** Each host-supplied source a render reads, in project order. */
|
|
172
172
|
readonly sources: readonly SourceConform[];
|
|
173
|
+
/**
|
|
174
|
+
* Data sets made from other media than their source's original now is, in data order. This
|
|
175
|
+
* never blocks, since the data still reads, but it may no longer describe the media.
|
|
176
|
+
*/
|
|
177
|
+
readonly stale_data: readonly StaleData[];
|
|
178
|
+
}
|
|
179
|
+
/** A data set whose `made_from` differs from its source's current original. */
|
|
180
|
+
export interface StaleData {
|
|
181
|
+
readonly data: string;
|
|
182
|
+
readonly source: string;
|
|
183
|
+
/** The parts of the fingerprint that differ. */
|
|
184
|
+
readonly fields: readonly FingerprintField[];
|
|
173
185
|
}
|
|
174
186
|
/** Lists every blocking issue with its source id. */
|
|
175
187
|
export declare function blockingIssues(report: ConformReport): readonly {
|
package/dist/audio-layout.js
CHANGED
|
@@ -314,6 +314,8 @@ function findLayoutBox(bytes, start, end) {
|
|
|
314
314
|
if (box.type === "stsd") {
|
|
315
315
|
// Skip the full-box header and entry count.
|
|
316
316
|
for (const entry of boxes(bytes, box.payload + 8, box.end)) {
|
|
317
|
+
if (entry.payload + 10 > entry.end)
|
|
318
|
+
continue;
|
|
317
319
|
const view = new DataView(bytes.buffer, bytes.byteOffset);
|
|
318
320
|
const version = view.getUint16(entry.payload + 8);
|
|
319
321
|
// QuickTime sound descriptions grow by 16 (v1) or 36 (v2) bytes; ISO v1 does not, so try
|
|
@@ -334,9 +336,10 @@ function trackId(bytes, trak) {
|
|
|
334
336
|
for (const box of boxes(bytes, trak.payload, trak.end)) {
|
|
335
337
|
if (box.type !== "tkhd")
|
|
336
338
|
continue;
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
339
|
+
const at = box.payload + (bytes[box.payload] === 1 ? 20 : 12);
|
|
340
|
+
if (at + 4 > box.end)
|
|
341
|
+
return null;
|
|
342
|
+
return new DataView(bytes.buffer, bytes.byteOffset).getUint32(at);
|
|
340
343
|
}
|
|
341
344
|
return null;
|
|
342
345
|
}
|
|
@@ -115,6 +115,8 @@ class Alpha2Processor extends AudioWorkletProcessor {
|
|
|
115
115
|
#sourcePointer = 0;
|
|
116
116
|
#sourceFrames = 0;
|
|
117
117
|
#sourceViews;
|
|
118
|
+
/** Why the module stopped; once set, nothing reaches the module again. */
|
|
119
|
+
#failure;
|
|
118
120
|
constructor() {
|
|
119
121
|
super();
|
|
120
122
|
this.port.onmessage = (event) => {
|
|
@@ -131,13 +133,14 @@ class Alpha2Processor extends AudioWorkletProcessor {
|
|
|
131
133
|
else if (message.type === "alpha2-ring" ||
|
|
132
134
|
message.type === "alpha2-config" ||
|
|
133
135
|
message.type === "alpha2-reset") {
|
|
134
|
-
let error;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
let error = this.#failure;
|
|
137
|
+
if (error === undefined)
|
|
138
|
+
try {
|
|
139
|
+
error = this.#apply(message);
|
|
140
|
+
}
|
|
141
|
+
catch (thrown) {
|
|
142
|
+
error = thrown instanceof Error ? thrown.message : String(thrown);
|
|
143
|
+
}
|
|
141
144
|
// Posted after any `alpha2-latency` the request caused. Without an id, a refusal is an
|
|
142
145
|
// error.
|
|
143
146
|
if (message.id !== undefined)
|
|
@@ -379,19 +382,10 @@ class Alpha2Processor extends AudioWorkletProcessor {
|
|
|
379
382
|
status = exports.alpha2_worklet_process(this.#handle, length, this.#channels);
|
|
380
383
|
}
|
|
381
384
|
catch (error) {
|
|
382
|
-
this
|
|
383
|
-
type: "alpha2-error",
|
|
384
|
-
message: `AudioWorklet DSP module trapped (${this.#panicMessage(exports) ?? String(error)}); the node has stopped`,
|
|
385
|
-
});
|
|
386
|
-
return false;
|
|
387
|
-
}
|
|
388
|
-
if (status !== 0) {
|
|
389
|
-
this.port.postMessage({
|
|
390
|
-
type: "alpha2-error",
|
|
391
|
-
message: `AudioWorklet processing failed (${status}); the node has stopped`,
|
|
392
|
-
});
|
|
393
|
-
return false;
|
|
385
|
+
return this.#fail(`AudioWorklet DSP module trapped (${this.#panicMessage(exports) ?? String(error)}); the node has stopped`);
|
|
394
386
|
}
|
|
387
|
+
if (status !== 0)
|
|
388
|
+
return this.#fail(`AudioWorklet processing failed (${status}); the node has stopped`);
|
|
395
389
|
const views = this.#viewsFor(exports, length);
|
|
396
390
|
const produced = this.#transparent ? views.input : views.output;
|
|
397
391
|
for (let channel = 0; channel < this.#channels; channel += 1) {
|
|
@@ -402,8 +396,17 @@ class Alpha2Processor extends AudioWorkletProcessor {
|
|
|
402
396
|
}
|
|
403
397
|
return true;
|
|
404
398
|
}
|
|
399
|
+
/**
|
|
400
|
+
* Records a module failure and reports it once. A node with a connected input keeps being
|
|
401
|
+
* called after it returns false, so later calls stop before the module.
|
|
402
|
+
*/
|
|
403
|
+
#fail(message) {
|
|
404
|
+
this.#failure = message;
|
|
405
|
+
this.port.postMessage({ type: "alpha2-error", message });
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
405
408
|
process(inputs, outputs) {
|
|
406
|
-
if (this.#disposed)
|
|
409
|
+
if (this.#disposed || this.#failure !== undefined)
|
|
407
410
|
return false;
|
|
408
411
|
const exports = this.#exports;
|
|
409
412
|
const output = outputs[0];
|
|
@@ -439,20 +442,11 @@ class Alpha2Processor extends AudioWorkletProcessor {
|
|
|
439
442
|
}
|
|
440
443
|
catch (error) {
|
|
441
444
|
// A Rust panic traps, and the trap carries no message of its own.
|
|
442
|
-
this
|
|
443
|
-
type: "alpha2-error",
|
|
444
|
-
message: `AudioWorklet DSP module trapped (${this.#panicMessage(exports) ?? String(error)}); the node has stopped`,
|
|
445
|
-
});
|
|
446
|
-
return false;
|
|
447
|
-
}
|
|
448
|
-
if (status !== 0) {
|
|
449
|
-
// Returning false retires the node; this message is the host's only signal.
|
|
450
|
-
this.port.postMessage({
|
|
451
|
-
type: "alpha2-error",
|
|
452
|
-
message: `AudioWorklet processing failed (${status}); the node has stopped`,
|
|
453
|
-
});
|
|
454
|
-
return false;
|
|
445
|
+
return this.#fail(`AudioWorklet DSP module trapped (${this.#panicMessage(exports) ?? String(error)}); the node has stopped`);
|
|
455
446
|
}
|
|
447
|
+
// Returning false retires the node; this message is the host's only signal.
|
|
448
|
+
if (status !== 0)
|
|
449
|
+
return this.#fail(`AudioWorklet processing failed (${status}); the node has stopped`);
|
|
456
450
|
// Recheck: processing may have grown memory and detached the views.
|
|
457
451
|
const produced = this.#viewsFor(exports, length).output;
|
|
458
452
|
for (let channel = 0; channel < this.#channels; channel += 1) {
|
package/dist/audio.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export interface BrowserAudioBlockSink {
|
|
|
9
9
|
/** Called once after the last block was written. */
|
|
10
10
|
finish(): Promise<void>;
|
|
11
11
|
/**
|
|
12
|
-
* Called once instead of `finish` when the render fails or is
|
|
13
|
-
* render rejects with.
|
|
12
|
+
* Called once instead of `finish`, or while `finish` is pending, when the render fails or is
|
|
13
|
+
* aborted; `reason` is the error the render rejects with.
|
|
14
14
|
*/
|
|
15
15
|
abort(reason: Error): Promise<void> | void;
|
|
16
16
|
}
|
|
@@ -24,8 +24,9 @@ export type OfflineAudioRenderer = (startSample: bigint, frameCount: number) =>
|
|
|
24
24
|
* sizes cycling through `blockSizes`.
|
|
25
25
|
*
|
|
26
26
|
* On success the sink's `finish` is awaited. On any failure, including `signal` aborting before
|
|
27
|
-
*
|
|
28
|
-
* (`signal.reason` or an `AbortError` for an abort). An
|
|
27
|
+
* `finish` resolves, the sink's `abort` is awaited and the promise rejects with the error
|
|
28
|
+
* (`signal.reason` or an `AbortError` for an abort). An abort after `finish` resolved is ignored.
|
|
29
|
+
* An error thrown by `abort` does not replace it.
|
|
29
30
|
*
|
|
30
31
|
* @throws RangeError When `totalFrames` is negative, `blockSizes` is empty or holds a size that is
|
|
31
32
|
* not a positive safe integer (checked before the sink is touched), or `render` returns a block
|
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
|
+
}
|