alpha2 0.4.5 → 0.4.6

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/dist/effects.d.ts CHANGED
@@ -256,6 +256,11 @@ export interface WasmCanvasRenderer extends WasmEffectRegistry {
256
256
  * The same font files as the export host give identical text.
257
257
  */
258
258
  addFont(family: string, bytes: Uint8Array, faceIndex: number): void;
259
+ /**
260
+ * Appends every face of an OpenType font file, in the file's order: each weight of a collection
261
+ * (`.ttc`), as the export host registers a font file.
262
+ */
263
+ addFontFile(family: string, bytes: Uint8Array): void;
259
264
  /** Drops every font. */
260
265
  clearFonts(): void;
261
266
  /** JSON source ids the most recent renderAudio call could not mix. */
@@ -108,8 +108,10 @@ export interface FrameSupplyDecodeOptions {
108
108
  /**
109
109
  * `"software"`: decode this frame on the CPU, on a cursor of its own beside `consumerId`'s, and
110
110
  * resolve with a `VideoFrame`. The supply asks for it when the browser could not read a
111
- * hardware-decoded frame back; a host that cannot decode the source in software rejects. Absent
112
- * for every other request.
111
+ * hardware-decoded frame back, and when a frame the engine must convert (HDR, or color the
112
+ * project declares) has no planar format it reads (an opaque hardware frame), and then for every
113
+ * later frame of that source until its content changes; a host that cannot decode the source in
114
+ * software rejects. Absent for every other request.
113
115
  */
114
116
  readonly decode?: "software";
115
117
  }
@@ -171,13 +173,18 @@ export interface FrameSupplyConfig extends FrameRetentionOptions {
171
173
  * has failed: `"redecode"` (the default) decodes it again in software, which decodes the same
172
174
  * picture, and fails the supply if that fails too; `"present"` gives it to the browser's
173
175
  * conversion instead, unless the engine must convert it (HDR, or color the project declares),
174
- * for a preview, where a frame shown at once matters more than the engine's conversion.
176
+ * for a preview, where a frame shown at once matters more than the engine's conversion. A frame
177
+ * the engine must convert that has no planar format it reads is decoded again in software either
178
+ * way.
175
179
  */
176
180
  readonly unreadableFrames?: "redecode" | "present";
177
181
  }
178
182
  /** How a {@link FrameSupply} recovered frames the browser could not read back; cumulative. */
179
183
  export interface ReadbackRecoveryStats {
180
- /** Frames whose planes the browser still could not read back after the repeated reads. */
184
+ /**
185
+ * Frames whose planes the browser still could not read back after the repeated reads, and frames
186
+ * the engine had to convert that had no planar format it reads.
187
+ */
181
188
  readonly unreadableFrames: number;
182
189
  /** Reads repeated on the same frame. */
183
190
  readonly readbackRetries: number;
@@ -1,6 +1,6 @@
1
1
  // The engine's immutable project snapshot is the sole authority for frame keys. The host must not
2
2
  // derive them itself, for example by rounding (timelineSeconds - clip.start).
3
- import { isHdrVideoFrame, isPlanarVideoFrame, PlanarCopyPool, readPlanarYuvFrame, uploadPlanarYuvFrame, } from "./hdr-frames.js";
3
+ import { isHdrVideoFrame, isPlanarVideoFrame, NonPlanarVideoFrameError, PlanarCopyPool, readPlanarYuvFrame, uploadPlanarYuvFrame, } from "./hdr-frames.js";
4
4
  import { decoderConsumerId } from "./media.js";
5
5
  import { sendsBitmaps, uploadPresentedFrame, } from "./presented-frames.js";
6
6
  import { PhysicalFrameAliases, } from "./physical-frames.js";
@@ -390,10 +390,15 @@ export class FrameSupply {
390
390
  (planar &&
391
391
  layer.kind === "video" &&
392
392
  this.#engine.hdrSource?.(need.sourceId) === true);
393
- const decoded = await this.#decodeCursor(keyForNeed(need, layer), () => pixelsFor(layer, Number(sourceTicks) / TICKS_PER_SECOND, {
393
+ const software = layer.kind === "video" &&
394
+ this.#contents.get(need.sourceId)?.softwareDecode === true;
395
+ const decoded = await this.#decodeCursor(software
396
+ ? `${keyForNeed(need, layer)}\u0000software`
397
+ : keyForNeed(need, layer), () => pixelsFor(layer, Number(sourceTicks) / TICKS_PER_SECOND, {
394
398
  preferVideoFrame: directVideo || enginesColor,
395
399
  consumerId: consumerOf(need),
396
400
  sourceId: need.sourceId,
401
+ ...(software ? { decode: "software" } : {}),
397
402
  }));
398
403
  results[index] = this.#planarRoute(need, layer, decoded, enginesColor, declared, planar);
399
404
  }
@@ -452,8 +457,10 @@ export class FrameSupply {
452
457
  * frames) is read again, then decoded again in software and copied from that decode: the codecs
453
458
  * define their decoding exactly, so the engine converts the planes it would have. With
454
459
  * `unreadableFrames: "present"`, a frame the engine need not convert resolves `undefined`
455
- * instead, left open for the browser's conversion. Rejects, the frame closed, when the copy
456
- * fails otherwise or the software decode cannot serve it.
460
+ * instead, left open for the browser's conversion. A frame with no planar format the engine
461
+ * reads (an opaque hardware frame, routed here only when the engine must convert it) is decoded
462
+ * again in software at once, as every later frame of its source is. Rejects, the frame closed,
463
+ * when the copy fails otherwise or the software decode cannot serve it.
457
464
  */
458
465
  async #copyPlanar(need, layer, source, planar, pixelsFor) {
459
466
  let copied;
@@ -461,12 +468,14 @@ export class FrameSupply {
461
468
  copied = await this.#readPlanes(source, planar.declared);
462
469
  }
463
470
  catch (error) {
464
- if (!isUnreadableFrame(error)) {
471
+ const nonPlanar = error instanceof NonPlanarVideoFrameError;
472
+ if (!nonPlanar && !isUnreadableFrame(error)) {
465
473
  source.frame.close();
466
474
  throw error;
467
475
  }
468
476
  this.#readback.unreadableFrames += 1;
469
- if (this.#unreadableFrames === "present" &&
477
+ if (!nonPlanar &&
478
+ this.#unreadableFrames === "present" &&
470
479
  !planar.required &&
471
480
  takesPresentedFrames(this.#engine)) {
472
481
  this.#readback.presentedFrames += 1;
@@ -474,6 +483,11 @@ export class FrameSupply {
474
483
  }
475
484
  const timestamp = source.physicalTimeMicroseconds ?? source.frame.timestamp;
476
485
  source.frame.close();
486
+ if (nonPlanar) {
487
+ const content = this.#contents.get(need.sourceId);
488
+ if (content !== undefined)
489
+ content.softwareDecode = true;
490
+ }
477
491
  copied = await this.#redecodePlanar(need, layer, planar, timestamp, pixelsFor, error);
478
492
  }
479
493
  source.frame.close();
@@ -505,7 +519,12 @@ export class FrameSupply {
505
519
  * copy fails too.
506
520
  */
507
521
  async #redecodePlanar(need, layer, planar, timestamp, pixelsFor, cause) {
508
- const unrecovered = (reason, error = cause) => new Error(`the browser could not read back the frame of ${need.sourceId} at ${need.mediaTimeTicks}, and ${reason}`, { cause: error });
522
+ const what = cause instanceof NonPlanarVideoFrameError
523
+ ? `the browser decoded the frame of ${need.sourceId} at ${need.mediaTimeTicks} to ${cause.format === null
524
+ ? "an opaque frame"
525
+ : `a ${cause.format} frame`} the engine must convert from planes (HDR, or color the project declares)`
526
+ : `the browser could not read back the frame of ${need.sourceId} at ${need.mediaTimeTicks}`;
527
+ const unrecovered = (reason, error = cause) => new Error(`${what}, and ${reason}`, { cause: error });
509
528
  let decoded;
510
529
  try {
511
530
  decoded = await this.#decodeCursor(`${keyForNeed(need, layer)}\u0000software`, () => pixelsFor(layer, Number(BigInt(need.mediaTimeTicks)) / TICKS_PER_SECOND, {
@@ -50,6 +50,8 @@ export declare const MAX_EQ_GAIN_DB = 36;
50
50
  export declare const MAX_EQ_Q = 50;
51
51
  /** Mirrors `alpha2_model::MAX_FONT_FAMILY_BYTES`. */
52
52
  export declare const MAX_FONT_FAMILY_BYTES = 256;
53
+ /** Mirrors `alpha2_model::MAX_FONT_WEIGHT`. */
54
+ export declare const MAX_FONT_WEIGHT = 1000;
53
55
  /** Mirrors `alpha2_model::MAX_FRAME_INLINED_NODES`. */
54
56
  export declare const MAX_FRAME_INLINED_NODES = 65536;
55
57
  /** Mirrors `alpha2_model::MAX_GAIN`. */
@@ -74,6 +76,8 @@ export declare const MAX_LAYOUT_ISOLATED = 16;
74
76
  export declare const MAX_LAYOUT_NODES = 256;
75
77
  /** Mirrors `alpha2_model::MAX_LAYOUT_TEXTS`. */
76
78
  export declare const MAX_LAYOUT_TEXTS = 64;
79
+ /** Mirrors `alpha2_model::MAX_LETTER_SPACING`. */
80
+ export declare const MAX_LETTER_SPACING = 1;
77
81
  /** Mirrors `alpha2_model::MAX_LINE_HEIGHT`. */
78
82
  export declare const MAX_LINE_HEIGHT = 3;
79
83
  /** Mirrors `alpha2_model::MAX_LOOKAHEAD_MS`. */
@@ -118,8 +122,12 @@ export declare const MAX_TRANSITIONS_PER_TRACK = 4096;
118
122
  export declare const MIN_EQ_FREQUENCY_HZ = 10;
119
123
  /** Mirrors `alpha2_model::MIN_EQ_Q`. */
120
124
  export declare const MIN_EQ_Q = 0.05;
125
+ /** Mirrors `alpha2_model::MIN_FONT_WEIGHT`. */
126
+ export declare const MIN_FONT_WEIGHT = 1;
121
127
  /** Mirrors `alpha2_model::MIN_HDR_PEAK_NITS`. */
122
128
  export declare const MIN_HDR_PEAK_NITS = 100;
129
+ /** Mirrors `alpha2_model::MIN_LETTER_SPACING`. */
130
+ export declare const MIN_LETTER_SPACING = -0.5;
123
131
  /** Mirrors `alpha2_model::MIN_LEVEL_DB`. */
124
132
  export declare const MIN_LEVEL_DB = -96;
125
133
  /** Mirrors `alpha2_model::MIN_LINE_HEIGHT`. */
@@ -1289,6 +1297,12 @@ export interface LayoutNode {
1289
1297
  * picture's shorter side. Inherited; the root's is 0.05.
1290
1298
  */
1291
1299
  readonly font_size?: Animated<LayoutSize> | null;
1300
+ /**
1301
+ * The weight, in `[1, 1000]`, the family's faces are matched by, as
1302
+ * CSS Fonts 4 matches `font-weight`; a variable face draws at it. Not
1303
+ * animated. Inherited; the root's is 400.
1304
+ */
1305
+ readonly font_weight?: number | null;
1292
1306
  /**
1293
1307
  * Space between children, on both axes. At least 0; default 0.
1294
1308
  */
@@ -1348,7 +1362,16 @@ export interface LayoutNode {
1348
1362
  */
1349
1363
  readonly justify_self?: AlignItems | null;
1350
1364
  /**
1351
- * Baseline-to-baseline distance in font sizes, in `[0.5, 3]`.
1365
+ * Space after each character, as a fraction of the font size, in
1366
+ * `[-0.5, 1]`, as CSS `letter-spacing` adds it: none after a line's
1367
+ * last character, and none after a character of a cursive script.
1368
+ * Not animated. Inherited; the root's is 0.
1369
+ */
1370
+ readonly letter_spacing?: number | null;
1371
+ /**
1372
+ * Baseline-to-baseline distance in font sizes, in `[0.5, 3]`. Each
1373
+ * line's em box, 0.8 of a font size above its baseline and 0.2 below,
1374
+ * is centred in its line when the line is taller than an em.
1352
1375
  * Inherited; the root's is 1.2.
1353
1376
  */
1354
1377
  readonly line_height?: number | null;
@@ -2223,7 +2246,8 @@ export type ShapeGeometry = {
2223
2246
  */
2224
2247
  readonly rotation_degrees?: Animated<number>;
2225
2248
  /**
2226
- * Full width and height, before rotation. Non-negative.
2249
+ * Full width and height, before rotation, per axis: x a fraction of
2250
+ * the picture's width, y of its height. Non-negative.
2227
2251
  */
2228
2252
  readonly size: Animated<Vec2>;
2229
2253
  /**
@@ -2242,7 +2266,8 @@ export type ShapeGeometry = {
2242
2266
  */
2243
2267
  readonly rotation_degrees?: Animated<number>;
2244
2268
  /**
2245
- * Full width and height, before rotation. Non-negative.
2269
+ * Full width and height, before rotation, per axis: x a fraction of
2270
+ * the picture's width, y of its height. Non-negative.
2246
2271
  */
2247
2272
  readonly size: Animated<Vec2>;
2248
2273
  /**
@@ -2352,7 +2377,8 @@ export type ShapeItem = {
2352
2377
  */
2353
2378
  readonly rotation_degrees?: Animated<number>;
2354
2379
  /**
2355
- * Full width and height, before rotation. Non-negative.
2380
+ * Full width and height, before rotation, per axis: x a fraction of
2381
+ * the picture's width, y of its height. Non-negative.
2356
2382
  */
2357
2383
  readonly size: Animated<Vec2>;
2358
2384
  /**
@@ -2371,7 +2397,8 @@ export type ShapeItem = {
2371
2397
  */
2372
2398
  readonly rotation_degrees?: Animated<number>;
2373
2399
  /**
2374
- * Full width and height, before rotation. Non-negative.
2400
+ * Full width and height, before rotation, per axis: x a fraction of
2401
+ * the picture's width, y of its height. Non-negative.
2375
2402
  */
2376
2403
  readonly size: Animated<Vec2>;
2377
2404
  /**
@@ -2687,10 +2714,11 @@ export interface TextOutline {
2687
2714
  * `Generator`.
2688
2715
  *
2689
2716
  * Sizes are resolution-independent: the font size is a fraction of the
2690
- * canvas height, the wrapping width a fraction of the canvas width, and the
2691
- * outline and background padding fractions of the font size. The engine
2692
- * draws with the fonts its host registered: those of `font_family` first,
2693
- * then the rest in their fallback order.
2717
+ * canvas's shorter side, as every other length is, the wrapping width a
2718
+ * fraction of the canvas width, and the outline and background padding
2719
+ * fractions of the font size. The engine draws with the fonts its host
2720
+ * registered: those of `font_family` first, then the rest in their
2721
+ * fallback order.
2694
2722
  */
2695
2723
  export interface TextStyle {
2696
2724
  /**
@@ -2728,15 +2756,36 @@ export interface TextStyle {
2728
2756
  */
2729
2757
  readonly font_family?: string | null;
2730
2758
  /**
2731
- * Font size as a fraction of the canvas height: positive, at most
2732
- * `MAX_CAPTION_FONT_SIZE` on a caption track and
2759
+ * Font size as a fraction of the canvas's shorter side: positive, at
2760
+ * most `MAX_CAPTION_FONT_SIZE` on a caption track and
2733
2761
  * `MAX_TEXT_GENERATOR_FONT_SIZE` in a text generator.
2734
2762
  *
2735
2763
  * @defaultValue `0.05`
2736
2764
  */
2737
2765
  readonly font_size?: number;
2738
2766
  /**
2739
- * Baseline-to-baseline distance in font sizes, in `[0.5, 3]`.
2767
+ * The weight, in `[1, 1000]`, a family's faces are matched by, as CSS
2768
+ * Fonts 4 matches `font-weight`; a variable face draws at it, clamped
2769
+ * to its `wght` axis. No face is emboldened: a weight the family lacks
2770
+ * draws its nearest face.
2771
+ *
2772
+ * @defaultValue `400`
2773
+ */
2774
+ readonly font_weight?: number;
2775
+ /**
2776
+ * Space after each character, as a fraction of the font size, in
2777
+ * `[-0.5, 1]`, as CSS `letter-spacing` adds it: none after a line's
2778
+ * last character, and none after a character of a cursive script
2779
+ * (Arabic, say), whose joins it would break. Not zero, it turns optional
2780
+ * ligatures off.
2781
+ *
2782
+ * @defaultValue `0`
2783
+ */
2784
+ readonly letter_spacing?: number;
2785
+ /**
2786
+ * Baseline-to-baseline distance in font sizes, in `[0.5, 3]`. Each
2787
+ * line's em box, 0.8 of a font size above its baseline and 0.2 below,
2788
+ * is centred in its line when the line is taller than an em.
2740
2789
  *
2741
2790
  * @defaultValue `1.2`
2742
2791
  */
@@ -2974,27 +3023,40 @@ export interface VideoStreamShape {
2974
3023
  }
2975
3024
  /**
2976
3025
  * Resolution-independent visual presentation controls for a clip.
3026
+ *
3027
+ * Each field a document leaves out takes its default: the
3028
+ * source centred on the canvas, unscaled, unrotated and opaque.
2977
3029
  */
2978
3030
  export interface VisualProperties {
2979
3031
  /**
2980
3032
  * Unanimated normalized point within the source rectangle.
3033
+ *
3034
+ * @defaultValue `{"x":0.5,"y":0.5}`
2981
3035
  */
2982
- readonly anchor: Vec2;
3036
+ readonly anchor?: Vec2;
2983
3037
  /**
2984
3038
  * Animated opacity constrained to `0..=1`.
3039
+ *
3040
+ * @defaultValue `{"mode":"constant","value":1}`
2985
3041
  */
2986
- readonly opacity: Animated<number>;
3042
+ readonly opacity?: Animated<number>;
2987
3043
  /**
2988
3044
  * Animated normalized canvas translation, along spatial curves where its
2989
3045
  * keyframes have tangents.
3046
+ *
3047
+ * @defaultValue `{"mode":"constant","value":{"x":0.5,"y":0.5}}`
2990
3048
  */
2991
- readonly position: AnimatedPoint;
3049
+ readonly position?: AnimatedPoint;
2992
3050
  /**
2993
3051
  * Animated clockwise rotation in degrees.
3052
+ *
3053
+ * @defaultValue `{"mode":"constant","value":0}`
2994
3054
  */
2995
- readonly rotation_degrees: Animated<number>;
3055
+ readonly rotation_degrees?: Animated<number>;
2996
3056
  /**
2997
3057
  * Animated per-axis scale.
3058
+ *
3059
+ * @defaultValue `{"mode":"constant","value":{"x":1,"y":1}}`
2998
3060
  */
2999
- readonly scale: Animated<Vec2>;
3061
+ readonly scale?: Animated<Vec2>;
3000
3062
  }
@@ -53,6 +53,8 @@ export const MAX_EQ_GAIN_DB = 36;
53
53
  export const MAX_EQ_Q = 50;
54
54
  /** Mirrors `alpha2_model::MAX_FONT_FAMILY_BYTES`. */
55
55
  export const MAX_FONT_FAMILY_BYTES = 256;
56
+ /** Mirrors `alpha2_model::MAX_FONT_WEIGHT`. */
57
+ export const MAX_FONT_WEIGHT = 1000;
56
58
  /** Mirrors `alpha2_model::MAX_FRAME_INLINED_NODES`. */
57
59
  export const MAX_FRAME_INLINED_NODES = 65536;
58
60
  /** Mirrors `alpha2_model::MAX_GAIN`. */
@@ -77,6 +79,8 @@ export const MAX_LAYOUT_ISOLATED = 16;
77
79
  export const MAX_LAYOUT_NODES = 256;
78
80
  /** Mirrors `alpha2_model::MAX_LAYOUT_TEXTS`. */
79
81
  export const MAX_LAYOUT_TEXTS = 64;
82
+ /** Mirrors `alpha2_model::MAX_LETTER_SPACING`. */
83
+ export const MAX_LETTER_SPACING = 1;
80
84
  /** Mirrors `alpha2_model::MAX_LINE_HEIGHT`. */
81
85
  export const MAX_LINE_HEIGHT = 3;
82
86
  /** Mirrors `alpha2_model::MAX_LOOKAHEAD_MS`. */
@@ -121,8 +125,12 @@ export const MAX_TRANSITIONS_PER_TRACK = 4096;
121
125
  export const MIN_EQ_FREQUENCY_HZ = 10;
122
126
  /** Mirrors `alpha2_model::MIN_EQ_Q`. */
123
127
  export const MIN_EQ_Q = 0.05;
128
+ /** Mirrors `alpha2_model::MIN_FONT_WEIGHT`. */
129
+ export const MIN_FONT_WEIGHT = 1;
124
130
  /** Mirrors `alpha2_model::MIN_HDR_PEAK_NITS`. */
125
131
  export const MIN_HDR_PEAK_NITS = 100;
132
+ /** Mirrors `alpha2_model::MIN_LETTER_SPACING`. */
133
+ export const MIN_LETTER_SPACING = -0.5;
126
134
  /** Mirrors `alpha2_model::MIN_LEVEL_DB`. */
127
135
  export const MIN_LEVEL_DB = -96;
128
136
  /** Mirrors `alpha2_model::MIN_LINE_HEIGHT`. */