@alpha2-sh/editor 0.4.5 → 0.5.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.
Files changed (81) hide show
  1. package/dist/browser/bridge.d.ts +15 -16
  2. package/dist/browser/bridge.js +533 -387
  3. package/dist/browser/extensions-worker.d.ts +12 -16
  4. package/dist/browser/extensions-worker.js +17 -24
  5. package/dist/browser/hash-worker.d.ts +4 -5
  6. package/dist/browser/hash-worker.js +7 -8
  7. package/dist/browser/jobs.d.ts +17 -19
  8. package/dist/browser/jobs.js +41 -28
  9. package/dist/browser/resources.d.ts +6 -11
  10. package/dist/browser/resources.js +5 -9
  11. package/dist/browser/runtime/assets.d.ts +52 -31
  12. package/dist/browser/runtime/assets.js +206 -47
  13. package/dist/browser/runtime/audio.d.ts +16 -11
  14. package/dist/browser/runtime/audio.js +58 -31
  15. package/dist/browser/runtime/budget.d.ts +4 -5
  16. package/dist/browser/runtime/budget.js +4 -5
  17. package/dist/browser/runtime/caption-fonts.d.ts +3 -7
  18. package/dist/browser/runtime/caption-fonts.js +4 -8
  19. package/dist/browser/runtime/engine.d.ts +40 -43
  20. package/dist/browser/runtime/engine.js +82 -63
  21. package/dist/browser/runtime/export-audio.d.ts +6 -6
  22. package/dist/browser/runtime/export-audio.js +8 -9
  23. package/dist/browser/runtime/exporter.d.ts +33 -66
  24. package/dist/browser/runtime/exporter.js +111 -137
  25. package/dist/browser/runtime/extension-import.d.ts +28 -35
  26. package/dist/browser/runtime/extension-import.js +36 -46
  27. package/dist/browser/runtime/fingerprint.d.ts +11 -14
  28. package/dist/browser/runtime/fingerprint.js +20 -24
  29. package/dist/browser/runtime/generators.d.ts +2 -3
  30. package/dist/browser/runtime/generators.js +5 -7
  31. package/dist/browser/runtime/locks.d.ts +5 -7
  32. package/dist/browser/runtime/locks.js +5 -7
  33. package/dist/browser/runtime/output.d.ts +7 -9
  34. package/dist/browser/runtime/output.js +17 -21
  35. package/dist/browser/runtime/preview-utils.js +10 -6
  36. package/dist/browser/runtime/proxies.d.ts +10 -17
  37. package/dist/browser/runtime/proxies.js +33 -45
  38. package/dist/browser/runtime/proxy-storage.d.ts +15 -19
  39. package/dist/browser/runtime/proxy-storage.js +20 -24
  40. package/dist/browser/runtime/sources.d.ts +23 -31
  41. package/dist/browser/runtime/sources.js +98 -105
  42. package/dist/browser/runtime/staging.d.ts +2 -6
  43. package/dist/browser/runtime/staging.js +7 -11
  44. package/dist/browser/runtime/still.d.ts +2 -6
  45. package/dist/browser/runtime/still.js +6 -12
  46. package/dist/browser/runtime/text.d.ts +14 -0
  47. package/dist/browser/runtime/text.js +27 -0
  48. package/dist/browser/runtime/wasm.d.ts +4 -5
  49. package/dist/browser/runtime/wasm.js +4 -5
  50. package/dist/browser/types.d.ts +243 -221
  51. package/dist/browser/worker.d.ts +8 -9
  52. package/dist/browser/worker.js +55 -22
  53. package/dist/core/captions.d.ts +8 -10
  54. package/dist/core/captions.js +10 -18
  55. package/dist/core/clip-time.d.ts +8 -10
  56. package/dist/core/clip-time.js +12 -15
  57. package/dist/core/commands.d.ts +46 -46
  58. package/dist/core/commands.js +38 -36
  59. package/dist/core/compositions.d.ts +78 -112
  60. package/dist/core/compositions.js +66 -94
  61. package/dist/core/document.d.ts +59 -92
  62. package/dist/core/document.js +65 -90
  63. package/dist/core/keyframes.d.ts +11 -12
  64. package/dist/core/keyframes.js +11 -13
  65. package/dist/core/presets.d.ts +14 -20
  66. package/dist/core/presets.js +12 -18
  67. package/dist/core/session.d.ts +26 -38
  68. package/dist/core/session.js +38 -53
  69. package/dist/core/text.d.ts +2 -3
  70. package/dist/core/text.js +2 -3
  71. package/dist/core/timeline-index.d.ts +2 -3
  72. package/dist/core/timeline-index.js +11 -7
  73. package/dist/core/transitions.js +4 -5
  74. package/dist/core/validated.d.ts +6 -7
  75. package/dist/core/validated.js +8 -11
  76. package/dist/native-client/index.d.ts +31 -32
  77. package/dist/native-client/index.js +40 -41
  78. package/dist/ports/index.d.ts +19 -19
  79. package/dist/react/index.d.ts +5 -6
  80. package/dist/react/index.js +5 -6
  81. package/package.json +4 -4
@@ -1,11 +1,11 @@
1
- // What an export frame holds in flight, computed without loading the runtime.
2
- // `tests/cases/staging-bytes-corpus.json` holds these to the renderer's `yuv420p_staging_bytes`.
1
+ // What an export frame holds in flight, computed without loading the runtime. Checked against the
2
+ // renderer's `yuv420p_staging_bytes` by `tests/cases/staging-bytes-corpus.json`.
3
3
  /** The canary the renderer stages after the planes, to prove the GPU wrote them. */
4
4
  const CANARY_BYTES = 16;
5
5
  /**
6
- * The bytes of the planes of a `width`x`height` I420 readback: each plane's rows padded to the copy
7
- * alignment (256), each plane starting on a 512-byte placement boundary, as the renderer lays them
8
- * out. The packed frame the encoder takes is this long.
6
+ * Plane bytes of a `width`x`height` I420 readback as the renderer lays them out: rows padded to
7
+ * 256-byte copy alignment, each plane on a 512-byte boundary. The packed encoder frame is this
8
+ * long.
9
9
  */
10
10
  function planeBytes(width, height) {
11
11
  const row = (bytes) => Math.ceil(bytes / 256) * 256;
@@ -17,16 +17,12 @@ function planeBytes(width, height) {
17
17
  return v + chroma;
18
18
  }
19
19
  /**
20
- * The bytes the engine's I420 readback of a `width`x`height` frame keeps staged: its planes and
21
- * the renderer's 16-byte canary, what a readback ticket reports as `retainedBytes`.
20
+ * Staged bytes of the engine's I420 readback (planes plus canary), as a ticket's `retainedBytes`.
22
21
  */
23
22
  export function estimatedStagingBytes(width, height) {
24
23
  return planeBytes(width, height) + CANARY_BYTES;
25
24
  }
26
- /**
27
- * The least an export of `width`x`height` frames can run with in flight: one frame's readback
28
- * staged and the packed copy of one frame the encoder holds.
29
- */
25
+ /** The minimum in-flight bytes of an export: one staged readback plus one packed encoder frame. */
30
26
  export function minimumExportWorkingSet(width, height) {
31
27
  return estimatedStagingBytes(width, height) + planeBytes(width, height);
32
28
  }
@@ -1,12 +1,8 @@
1
1
  /**
2
- * Decodes an image file upright and without colour management. Rejects a picture larger than the
3
- * engine takes, as native decoding refuses one.
2
+ * Decodes an image upright without colour management, rejecting one larger than the engine takes.
4
3
  */
5
4
  export function decodeStill(file: any): Promise<ImageBitmap>;
6
- /**
7
- * A decoded still's pixels at its own size, in straight alpha as decoded, as a raster frame the
8
- * engine presents into the output.
9
- */
5
+ /** A decoded still's pixels at its own size, in straight alpha, as a raster frame. */
10
6
  export function stillRaster(bitmap: any): {
11
7
  kind: string;
12
8
  width: any;
@@ -1,16 +1,13 @@
1
- // Reads a still image by the same rule as native decoding, so it shows alike in preview and in
2
- // browser and native exports:
3
- // - Upright per Exif `Orientation` (`imageOrientation: "from-image"`; Chrome reads `"none"` as it).
4
- // - In stored sRGB code values: no ICC profile (`colorSpaceConversion: "none"`), since the engine
5
- // treats SDR input as sRGB and native decoding has no colour management.
6
- // - At its own size; the engine scales it into the output.
1
+ // Reads a still image by the same rules as native decoding, so preview and browser and native
2
+ // exports match: upright per Exif `Orientation` (`imageOrientation: "from-image"`), in stored
3
+ // sRGB code values with no ICC conversion (the engine treats SDR input as sRGB and native decoding
4
+ // has no colour management), and at its own size.
7
5
  /** The longest side the engine decodes, renders, or composes (`MAX_FRAME_DIMENSION`). */
8
6
  export const MAX_STILL_DIMENSION = 16_384;
9
7
  /** The largest area the engine decodes, renders, or composes (`MAX_FRAME_PIXELS`). */
10
8
  export const MAX_STILL_PIXELS = 67_108_864;
11
9
  /**
12
- * Decodes an image file upright and without colour management. Rejects a picture larger than the
13
- * engine takes, as native decoding refuses one.
10
+ * Decodes an image upright without colour management, rejecting one larger than the engine takes.
14
11
  */
15
12
  export async function decodeStill(file) {
16
13
  const bitmap = await createImageBitmap(file, {
@@ -26,10 +23,7 @@ export async function decodeStill(file) {
26
23
  }
27
24
  return bitmap;
28
25
  }
29
- /**
30
- * A decoded still's pixels at its own size, in straight alpha as decoded, as a raster frame the
31
- * engine presents into the output.
32
- */
26
+ /** A decoded still's pixels at its own size, in straight alpha, as a raster frame. */
33
27
  export function stillRaster(bitmap) {
34
28
  const { width, height } = bitmap;
35
29
  const canvas = new OffscreenCanvas(width, height);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The text of a user's file (a subtitle file, a `.cube` LUT) by the rule every alpha2 runtime uses:
3
+ * UTF-8 (a byte order mark is dropped), or UTF-16 when the file starts with a little- or big-endian
4
+ * byte order mark (as Windows PowerShell 5.1 writes). Anything else, such as a legacy code page,
5
+ * throws an `invalid_text` {@link EditorError} naming the file instead of decoding to replacement
6
+ * characters.
7
+ *
8
+ * @param {Blob & { name?: string }} file
9
+ * @param {string} [operation] The operation the error names. Defaults to `import`.
10
+ * @returns {Promise<string>}
11
+ */
12
+ export function readUserText(file: Blob & {
13
+ name?: string;
14
+ }, operation?: string): Promise<string>;
@@ -0,0 +1,27 @@
1
+ import { EditorError } from "../../core/document.js";
2
+ /**
3
+ * The text of a user's file (a subtitle file, a `.cube` LUT) by the rule every alpha2 runtime uses:
4
+ * UTF-8 (a byte order mark is dropped), or UTF-16 when the file starts with a little- or big-endian
5
+ * byte order mark (as Windows PowerShell 5.1 writes). Anything else, such as a legacy code page,
6
+ * throws an `invalid_text` {@link EditorError} naming the file instead of decoding to replacement
7
+ * characters.
8
+ *
9
+ * @param {Blob & { name?: string }} file
10
+ * @param {string} [operation] The operation the error names. Defaults to `import`.
11
+ * @returns {Promise<string>}
12
+ */
13
+ export async function readUserText(file, operation = "import") {
14
+ const bytes = new Uint8Array(await file.arrayBuffer());
15
+ const encoding = bytes[0] === 0xff && bytes[1] === 0xfe
16
+ ? "utf-16le"
17
+ : bytes[0] === 0xfe && bytes[1] === 0xff
18
+ ? "utf-16be"
19
+ : "utf-8";
20
+ try {
21
+ // Each decoder drops its own byte order mark.
22
+ return new TextDecoder(encoding, { fatal: true }).decode(bytes);
23
+ }
24
+ catch {
25
+ throw new EditorError("invalid_text", `${file.name ?? "the file"} is not UTF-8 text; save it as UTF-8`, operation);
26
+ }
27
+ }
@@ -1,9 +1,8 @@
1
1
  /**
2
- * Instantiates `alpha2/wasm` once for this realm and resolves to its exports. wasm-bindgen's own
3
- * init reuses an instance only after one has finished: two calls in flight instantiate twice, and
4
- * the later instance replaces the module's memory under objects made from the first, whose next
5
- * call reads out of bounds. Every caller goes through here. A failed load is retried by the next
6
- * call.
2
+ * Instantiates `alpha2/wasm` once per realm and resolves to its exports. wasm-bindgen's init only
3
+ * reuses a finished instance, so two concurrent calls would instantiate twice and the second would
4
+ * replace the module's memory under objects made from the first. Every caller goes through here; a
5
+ * failed load is retried by the next call.
7
6
  * @param {string | URL | undefined} wasmUrl
8
7
  */
9
8
  export function loadEngineWasm(wasmUrl: string | URL | undefined): any;
@@ -2,11 +2,10 @@ import init from "alpha2/wasm";
2
2
  import * as binding from "alpha2/wasm";
3
3
  let loading = null;
4
4
  /**
5
- * Instantiates `alpha2/wasm` once for this realm and resolves to its exports. wasm-bindgen's own
6
- * init reuses an instance only after one has finished: two calls in flight instantiate twice, and
7
- * the later instance replaces the module's memory under objects made from the first, whose next
8
- * call reads out of bounds. Every caller goes through here. A failed load is retried by the next
9
- * call.
5
+ * Instantiates `alpha2/wasm` once per realm and resolves to its exports. wasm-bindgen's init only
6
+ * reuses a finished instance, so two concurrent calls would instantiate twice and the second would
7
+ * replace the module's memory under objects made from the first. Every caller goes through here; a
8
+ * failed load is retried by the next call.
10
9
  * @param {string | URL | undefined} wasmUrl
11
10
  */
12
11
  export function loadEngineWasm(wasmUrl) {