alpha2 0.5.2 → 0.5.3
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 +3 -2
- package/THIRD_PARTY_NOTICES.md +186 -0
- package/dist/extensions.d.ts +86 -28
- package/dist/extensions.js +204 -61
- package/dist/generated/project-schema.d.ts +60 -4
- package/dist/generated/project-schema.js +12 -0
- package/dist/generated/project-shape.js +34 -0
- package/dist/media.d.ts +1 -1
- package/dist/media.js +1 -1
- package/dist/project.d.ts +12 -0
- package/dist/project.js +60 -5
- package/dist/wasm-module.d.ts +37 -0
- package/dist/wasm-module.js +47 -0
- package/package.json +11 -2
- 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.js +18 -18
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/rust-crate-licenses.md +499 -4
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659 → alpha2-wasm-a6265983c9769e80}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659 → alpha2-wasm-a6265983c9769e80}/inline1.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659 → alpha2-wasm-a6265983c9769e80}/inline2.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659 → alpha2-wasm-a6265983c9769e80}/inline3.js +0 -0
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ engine.uploadRgbaImage("image-1", 1280, 720, new Uint8Array(1280 * 720 * 4).fill
|
|
|
35
35
|
engine.renderAt(0n); // draws the frame at time 0 on the canvas
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
- `init()` loads `alpha2_wasm_bg.wasm` from beside the module. A bundler that moves it passes its URL, a `Response`, its bytes or a compiled `WebAssembly.Module` as `init({ module_or_path })`; the files are `alpha2/wasm/alpha2_wasm_bg.wasm` (the engine), `alpha2/wasm/alpha2_audio_worklet.wasm` (the audio worklet)
|
|
38
|
+
- `init()` loads `alpha2_wasm_bg.wasm` from beside the module. A bundler that moves it passes its URL, a `Response`, its bytes or a compiled `WebAssembly.Module` as `init({ module_or_path })`; the files are `alpha2/wasm/alpha2_wasm_bg.wasm` (the engine), `alpha2/wasm/alpha2_audio_worklet.wasm` (the audio worklet) `alpha2/wasm/alpha2_extensions_bg.wasm` (SVG, animated images, Lottie, OpenEXR, image sequences and LaTeX, loaded only for such a source) and `alpha2/wasm/alpha2_extensions_pdf_bg.wasm` (PDF pages, loaded only for a PDF). `loadExtensions` takes the extension files' URLs by module name, `{ core, pdf }`.
|
|
39
39
|
- `createForHtmlCanvas` draws on a page canvas; a worker passes an `OffscreenCanvas` to `createForCanvas`. Either renders with WebGPU, or with WebGL2 when the browser has no WebGPU. The WebGPU device is opened before the canvas is bound, so a failure leaves the canvas free for another context. `{ softwareAdapter: "refuse" }` refuses software adapters (SwiftShader, llvmpipe, WARP, a WebGPU fallback adapter) and rejects `GPU_INIT_FAILED` when the browser offers nothing else.
|
|
40
40
|
- With neither (Chrome with acceleration off, a blocklisted GPU), `WebEffectRegistry.createCpu(canvas)` makes the engine's CPU renderer: the same calls, drawn in wasm on one thread, the preview put on the canvas's 2D context. It draws exactly what the native CPU renderer draws, refuses runtime WGSL effects with `EFFECT_ERROR`, and needs no canvas to export. `createRenderer(binding, canvas, mode)` in `alpha2/renderer-choice` makes the renderer a mode asks for (`"auto"` draws on a hardware GPU, else on the CPU renderer, as the native host's `auto` does) and says which it made. `detectBrowserCapabilities()` reports which renderer `"auto"` gets on the calling thread (`renderer`), probing WebGL2 on an `OffscreenCanvas`, as render hosts draw; a worker host's answer comes from `WorkerRenderBackend.detectCapabilities()`.
|
|
41
41
|
- A project is the engine's JSON document. `alpha2/project` has its TypeScript types, tick conversions and `validateProject`, which reports what the engine would refuse before the document is sent; `alpha2/builder` writes one with times in seconds. `loadProject` checks the document again and throws what it refuses.
|
|
@@ -91,7 +91,8 @@ For preview, `alpha2/audio-timeline` moves the mixed blocks to the audio thread
|
|
|
91
91
|
| `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
92
|
| `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). |
|
|
93
93
|
| `alpha2/effects` | Effect definitions and the built-in catalog's types; `RuntimeEffectRegistry`, a typed wrapper for registering WGSL effects and effect resources at run time. |
|
|
94
|
-
| `alpha2/extensions`, `alpha2/extensions-wasm` | SVG, animated image, Lottie, OpenEXR
|
|
94
|
+
| `alpha2/extensions`, `alpha2/extensions-wasm`, `alpha2/extensions-pdf-wasm` | SVG, animated image, Lottie, OpenEXR, image sequence, LaTeX and PDF sources, from their own WebAssembly modules (`loadExtensions`). After an abort a module restarts asynchronously; `ready()` resolves once it takes calls again. |
|
|
95
|
+
| `alpha2/wasm-module` | `WasmModule`, which loads a wasm-bindgen module once per realm and restarts it asynchronously. |
|
|
95
96
|
| `alpha2/text` | Text rasterizers: `WasmTextRasterizer` (the engine's, the same pixels as a native export) and `OffscreenTextRasterizer` (the browser's). |
|
|
96
97
|
| `alpha2/assets` | Media identity, proxies and conform reports. |
|
|
97
98
|
| `alpha2/frame-supply` | `FrameSupply`: decodes and uploads the frames a time needs. |
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -80,6 +80,192 @@ In addition, the Cisco-provided binary of this Software is licensed under Cisco'
|
|
|
80
80
|
v1.0
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
+
## STIX Two Math and the dvips color names
|
|
84
|
+
|
|
85
|
+
The `alpha2-extensions` crate, the extensions wasm module in the `alpha2` npm package, and the native archives 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
|
+
|
|
87
|
+
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
|
+
|
|
89
|
+
```
|
|
90
|
+
Copyright 2001-2021 The STIX Fonts Project Authors (https://github.com/stipub/stixfonts)
|
|
91
|
+
|
|
92
|
+
STIX Fonts(TM) is a trademark of The Institute of Electrical and
|
|
93
|
+
Electronics Engineers, Inc.
|
|
94
|
+
|
|
95
|
+
Portions copyright (c) 1998-2003 by MicroPress, Inc.
|
|
96
|
+
(www.micropress-inc.com), with Reserved Font Name TM Math.
|
|
97
|
+
To obtain additional mathematical fonts, please contact
|
|
98
|
+
MicroPress, Inc.,
|
|
99
|
+
68-30 Harrow Street,
|
|
100
|
+
Forest Hills, NY 11375,
|
|
101
|
+
USA
|
|
102
|
+
Phone: (718) 575-1816.
|
|
103
|
+
|
|
104
|
+
Portions copyright (c) 1990 by Elsevier, Inc.
|
|
105
|
+
|
|
106
|
+
Portions copyright (c) 2010, 2012, 2014 Adobe Systems Incorporated.
|
|
107
|
+
|
|
108
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
109
|
+
This license is copied below, and is also available with a FAQ at:
|
|
110
|
+
http://scripts.sil.org/OFL
|
|
111
|
+
|
|
112
|
+
-----------------------------------------------------------
|
|
113
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
114
|
+
-----------------------------------------------------------
|
|
115
|
+
|
|
116
|
+
PREAMBLE
|
|
117
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
118
|
+
development of collaborative font projects, to support the font creation
|
|
119
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
120
|
+
open framework in which fonts may be shared and improved in partnership
|
|
121
|
+
with others.
|
|
122
|
+
|
|
123
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
124
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
125
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
126
|
+
redistributed and/or sold with any software provided that any reserved
|
|
127
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
128
|
+
however, cannot be released under any other type of license. The
|
|
129
|
+
requirement for fonts to remain under this license does not apply
|
|
130
|
+
to any document created using the fonts or their derivatives.
|
|
131
|
+
|
|
132
|
+
DEFINITIONS
|
|
133
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
134
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
135
|
+
include source files, build scripts and documentation.
|
|
136
|
+
|
|
137
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
138
|
+
copyright statement(s).
|
|
139
|
+
|
|
140
|
+
"Original Version" refers to the collection of Font Software components as
|
|
141
|
+
distributed by the Copyright Holder(s).
|
|
142
|
+
|
|
143
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
144
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
145
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
146
|
+
new environment.
|
|
147
|
+
|
|
148
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
149
|
+
writer or other person who contributed to the Font Software.
|
|
150
|
+
|
|
151
|
+
PERMISSION & CONDITIONS
|
|
152
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
153
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
154
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
155
|
+
Software, subject to the following conditions:
|
|
156
|
+
|
|
157
|
+
1) Neither the Font Software nor any of its individual components,
|
|
158
|
+
in Original or Modified Versions, may be sold by itself.
|
|
159
|
+
|
|
160
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
161
|
+
redistributed and/or sold with any software, provided that each copy
|
|
162
|
+
contains the above copyright notice and this license. These can be
|
|
163
|
+
included either as stand-alone text files, human-readable headers or
|
|
164
|
+
in the appropriate machine-readable metadata fields within text or
|
|
165
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
166
|
+
|
|
167
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
168
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
169
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
170
|
+
presented to the users.
|
|
171
|
+
|
|
172
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
173
|
+
Software shall not be used to promote, endorse or advertise any
|
|
174
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
175
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
176
|
+
permission.
|
|
177
|
+
|
|
178
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
179
|
+
must be distributed entirely under this license, and must not be
|
|
180
|
+
distributed under any other license. The requirement for fonts to
|
|
181
|
+
remain under this license does not apply to any document created
|
|
182
|
+
using the Font Software.
|
|
183
|
+
|
|
184
|
+
TERMINATION
|
|
185
|
+
This license becomes null and void if any of the above conditions are
|
|
186
|
+
not met.
|
|
187
|
+
|
|
188
|
+
DISCLAIMER
|
|
189
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
190
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
191
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
192
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
193
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
194
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
195
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
196
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
197
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## PDF standard fonts and CMaps
|
|
201
|
+
|
|
202
|
+
The `alpha2-extensions` crate, the extensions wasm module in the `alpha2` npm package, and the native archives 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
|
+
|
|
204
|
+
The standard font substitutes:
|
|
205
|
+
|
|
206
|
+
```
|
|
207
|
+
Copyright 2014 PDFium Authors. All rights reserved.
|
|
208
|
+
|
|
209
|
+
Redistribution and use in source and binary forms, with or without
|
|
210
|
+
modification, are permitted provided that the following conditions are
|
|
211
|
+
met:
|
|
212
|
+
|
|
213
|
+
* Redistributions of source code must retain the above copyright
|
|
214
|
+
notice, this list of conditions and the following disclaimer.
|
|
215
|
+
* Redistributions in binary form must reproduce the above
|
|
216
|
+
copyright notice, this list of conditions and the following disclaimer
|
|
217
|
+
in the documentation and/or other materials provided with the
|
|
218
|
+
distribution.
|
|
219
|
+
* Neither the name of Google Inc. nor the names of its
|
|
220
|
+
contributors may be used to endorse or promote products derived from
|
|
221
|
+
this software without specific prior written permission.
|
|
222
|
+
|
|
223
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
224
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
225
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
226
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
227
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
228
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
229
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
230
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
231
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
232
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
233
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The CMaps:
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
Copyright 1990-2023 Adobe. All rights reserved.
|
|
240
|
+
|
|
241
|
+
Redistribution and use in source and binary forms, with or without
|
|
242
|
+
modification, are permitted provided that the following conditions are
|
|
243
|
+
met:
|
|
244
|
+
|
|
245
|
+
Redistributions of source code must retain the above copyright notice,
|
|
246
|
+
this list of conditions and the following disclaimer.
|
|
247
|
+
|
|
248
|
+
Redistributions in binary form must reproduce the above copyright
|
|
249
|
+
notice, this list of conditions and the following disclaimer in the
|
|
250
|
+
documentation and/or other materials provided with the distribution.
|
|
251
|
+
|
|
252
|
+
Neither the name of Adobe nor the names of its contributors may be
|
|
253
|
+
used to endorse or promote products derived from this software without
|
|
254
|
+
specific prior written permission.
|
|
255
|
+
|
|
256
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
257
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
258
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
259
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
260
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
261
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
262
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
263
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
264
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
265
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
266
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
267
|
+
```
|
|
268
|
+
|
|
83
269
|
## gl-transitions
|
|
84
270
|
|
|
85
271
|
The transitions in `crates/alpha2-shaders/shaders/runtime/transitions/` are WGSL ports of shaders from [gl-transitions](https://github.com/gl-transitions/gl-transitions) at commit `902218a1b63773ac0d0d9f491951da3392365bfe`. Each file names the shader it ports and its author.
|
package/dist/extensions.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { WasmModule, type WasmBindgenGlue } from "./wasm-module.js";
|
|
1
2
|
import type { LinearPrimaries, ProviderSource } from "./generated/project-schema.js";
|
|
2
|
-
export type ExtensionFormat = "svg" | "gif" | "apng" | "webp" | "png_sequence" | "lottie" | "dot_lottie" | "exr" | "exr_sequence";
|
|
3
|
+
export type ExtensionFormat = "svg" | "gif" | "apng" | "webp" | "png_sequence" | "lottie" | "dot_lottie" | "exr" | "exr_sequence" | "latex" | "pdf";
|
|
3
4
|
/** Frame timing in source ticks. */
|
|
4
5
|
export type ExtensionTiming = {
|
|
5
6
|
readonly kind: "static";
|
|
@@ -23,6 +24,11 @@ export type ExtensionDiagnostic = {
|
|
|
23
24
|
readonly kind: "missing_font";
|
|
24
25
|
readonly families: string;
|
|
25
26
|
}
|
|
27
|
+
/** Fonts a document does not embed, drawn with the nearest standard font. */
|
|
28
|
+
| {
|
|
29
|
+
readonly kind: "substituted_font";
|
|
30
|
+
readonly families: string;
|
|
31
|
+
}
|
|
26
32
|
/** A referenced image is not registered or is too large; it is not drawn. */
|
|
27
33
|
| {
|
|
28
34
|
readonly kind: "missing_image";
|
|
@@ -108,13 +114,11 @@ export type ExtensionFrame = {
|
|
|
108
114
|
*/
|
|
109
115
|
readonly pixels: Uint16Array;
|
|
110
116
|
});
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
module_or_path: string | URL;
|
|
114
|
-
}): Promise<unknown>;
|
|
117
|
+
/** The wasm-bindgen glue every provider module's build writes. */
|
|
118
|
+
export interface ExtensionModule extends WasmBindgenGlue {
|
|
115
119
|
ExtensionRegistry: new () => WasmExtensionRegistry;
|
|
116
|
-
/**
|
|
117
|
-
|
|
120
|
+
/** Added by the package build after `--experimental-reset-state-function`. */
|
|
121
|
+
__wbg_reset_state_async(): Promise<void>;
|
|
118
122
|
}
|
|
119
123
|
interface WasmRenderedFrame {
|
|
120
124
|
readonly width: number;
|
|
@@ -149,11 +153,19 @@ interface WasmExtensionRegistry {
|
|
|
149
153
|
free(): void;
|
|
150
154
|
}
|
|
151
155
|
/**
|
|
152
|
-
* The provider module aborted during this call (a panic or failed allocation)
|
|
153
|
-
*
|
|
156
|
+
* The provider module aborted during this call (a panic or failed allocation), or cannot be used.
|
|
157
|
+
* After an abort the module restarts; {@link Extensions.ready} resolves once later calls work. The
|
|
158
|
+
* source involved stays failed.
|
|
154
159
|
*/
|
|
155
160
|
export declare class ExtensionModuleError extends Error {
|
|
156
|
-
readonly name
|
|
161
|
+
readonly name: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The provider module is restarting after an abort. Await {@link Extensions.ready} and call again.
|
|
165
|
+
*/
|
|
166
|
+
export declare class ExtensionModuleRestartingError extends ExtensionModuleError {
|
|
167
|
+
readonly name = "ExtensionModuleRestartingError";
|
|
168
|
+
constructor();
|
|
157
169
|
}
|
|
158
170
|
/**
|
|
159
171
|
* The source was opened before the provider module restarted. Re-register its resources and open
|
|
@@ -169,32 +181,76 @@ interface ExtensionCalls {
|
|
|
169
181
|
call<T>(call: (wasm: WasmExtensionRegistry) => T): T;
|
|
170
182
|
generation(): number;
|
|
171
183
|
}
|
|
184
|
+
/** A provider wasm module, with the formats it opens and the file starts it reads. */
|
|
185
|
+
interface ProviderModule {
|
|
186
|
+
readonly name: ExtensionModuleName;
|
|
187
|
+
readonly loader: WasmModule<ExtensionModule>;
|
|
188
|
+
/** Provider source formats it opens; `null` for every format no other module lists. */
|
|
189
|
+
readonly formats: readonly string[] | null;
|
|
190
|
+
/** Whether a file's first bytes may be one this module reads, so probing should load it. */
|
|
191
|
+
claims(head: Uint8Array): boolean;
|
|
192
|
+
/** Whether its formats read registered resources and fonts (SVG, Lottie, image sequences). */
|
|
193
|
+
readonly readsResources: boolean;
|
|
194
|
+
}
|
|
195
|
+
/** The provider wasm modules of the package, probed in this order. */
|
|
196
|
+
export type ExtensionModuleName = "core" | "pdf";
|
|
197
|
+
/** Where each provider module's `.wasm` file is when a bundler moved it. */
|
|
198
|
+
export type ExtensionWasmUrls = {
|
|
199
|
+
readonly [name in ExtensionModuleName]?: string | URL;
|
|
200
|
+
};
|
|
172
201
|
/**
|
|
173
|
-
*
|
|
202
|
+
* One loaded provider module. A trap in a call restarts it asynchronously; until it is ready again
|
|
203
|
+
* every call throws {@link ExtensionModuleRestartingError}.
|
|
204
|
+
*/
|
|
205
|
+
declare class ModuleSession {
|
|
206
|
+
#private;
|
|
207
|
+
readonly module: ProviderModule;
|
|
208
|
+
readonly calls: ExtensionCalls;
|
|
209
|
+
constructor(module: ProviderModule, glue: ExtensionModule);
|
|
210
|
+
call<T>(call: (wasm: WasmExtensionRegistry) => T): T;
|
|
211
|
+
ready(): Promise<void>;
|
|
212
|
+
setFonts(fonts: readonly Uint8Array[]): void;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The provider modules, shared by every source on the page. Load it with {@link loadExtensions},
|
|
216
|
+
* which loads the core module; others load when {@link probe} or {@link prepare} needs them.
|
|
174
217
|
*
|
|
175
|
-
* Providers parse untrusted files, and a panic aborts
|
|
176
|
-
* throws {@link ExtensionModuleError} and the module restarts with its
|
|
177
|
-
* sources and resources are lost.
|
|
178
|
-
*
|
|
218
|
+
* Providers parse untrusted files, and a panic aborts that module's wasm instance. The call that
|
|
219
|
+
* aborted it throws {@link ExtensionModuleError} and the module restarts asynchronously with its
|
|
220
|
+
* fonts re-registered, but its sources and resources are lost. Until {@link ready} resolves, every
|
|
221
|
+
* call to that module throws {@link ExtensionModuleRestartingError}. Older sources throw
|
|
222
|
+
* {@link StaleExtensionSourceError} until reopened.
|
|
179
223
|
*/
|
|
180
224
|
export declare class Extensions {
|
|
181
225
|
#private;
|
|
182
226
|
/** Use {@link loadExtensions}. */
|
|
183
|
-
constructor(
|
|
184
|
-
/**
|
|
227
|
+
constructor(urls: ExtensionWasmUrls, core: ModuleSession);
|
|
228
|
+
/**
|
|
229
|
+
* Resolves when every loaded module takes calls, at once unless one is restarting.
|
|
230
|
+
*
|
|
231
|
+
* @throws {ExtensionModuleError} When a restart failed; every later call to that module throws.
|
|
232
|
+
*/
|
|
233
|
+
ready(): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Loads the module that opens `provider`, so {@link open} can open it, at once if it is loaded.
|
|
236
|
+
*
|
|
237
|
+
* @throws When the module cannot be fetched or instantiated.
|
|
238
|
+
*/
|
|
239
|
+
prepare(provider: ProviderSource): Promise<void>;
|
|
240
|
+
/** Built-in providers of the loaded modules, in priority order. */
|
|
185
241
|
get providers(): readonly string[];
|
|
186
|
-
/** Whether the
|
|
242
|
+
/** Whether the package can open this provider source; its module need not be loaded yet. */
|
|
187
243
|
supports(provider: ProviderSource): boolean;
|
|
188
244
|
/**
|
|
189
|
-
* Probes `bytes` with the first provider that claims them, or
|
|
190
|
-
* decoders can read them.
|
|
245
|
+
* Probes `bytes` with the first provider that claims them, or answers `null` so the host's own
|
|
246
|
+
* decoders can read them. Loads a module only when the bytes' start may be one of its formats.
|
|
191
247
|
*
|
|
192
|
-
* @throws When a provider claims the bytes and cannot read them.
|
|
248
|
+
* @throws When a provider claims the bytes and cannot read them, or a module cannot load.
|
|
193
249
|
*/
|
|
194
|
-
probe(bytes: Uint8Array): {
|
|
250
|
+
probe(bytes: Uint8Array): Promise<{
|
|
195
251
|
readonly provider: string;
|
|
196
252
|
readonly report: ExtensionReport;
|
|
197
|
-
} | null
|
|
253
|
+
} | null>;
|
|
198
254
|
/**
|
|
199
255
|
* Registers bytes under a locator, such as an image sequence frame or an image an SVG references.
|
|
200
256
|
* They stay until released or a module restart; {@link withResources} scopes them to one call.
|
|
@@ -235,8 +291,9 @@ export declare class Extensions {
|
|
|
235
291
|
*/
|
|
236
292
|
setFonts(fonts: readonly Uint8Array[]): void;
|
|
237
293
|
/**
|
|
238
|
-
* Opens a provider source. Image sequences take
|
|
239
|
-
* (see {@link openNeeds} and {@link withResources}).
|
|
294
|
+
* Opens a provider source. LaTeX takes no bytes. Image sequences take none either; their frames
|
|
295
|
+
* are registered resources (see {@link openNeeds} and {@link withResources}). The source's module
|
|
296
|
+
* must be loaded: {@link probe} loads it for the bytes it claims, {@link prepare} for a source.
|
|
240
297
|
*
|
|
241
298
|
* @throws When the source cannot be opened.
|
|
242
299
|
*/
|
|
@@ -290,8 +347,9 @@ export declare class ExtensionSource {
|
|
|
290
347
|
release(): void;
|
|
291
348
|
}
|
|
292
349
|
/**
|
|
293
|
-
* Loads the provider module once per page
|
|
294
|
-
*
|
|
350
|
+
* Loads the core provider module once per page; the others load when first needed. `wasmUrl`
|
|
351
|
+
* locates the core module's `alpha2_extensions_bg.wasm`, or each module's file by name, when a
|
|
352
|
+
* bundler moved them; it applies to the first call. A failed load is not cached.
|
|
295
353
|
*/
|
|
296
|
-
export declare function loadExtensions(wasmUrl?: string | URL): Promise<Extensions>;
|
|
354
|
+
export declare function loadExtensions(wasmUrl?: string | URL | ExtensionWasmUrls): Promise<Extensions>;
|
|
297
355
|
export {};
|