@alpha2-sh/editor 0.2.1 → 0.2.2
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/browser/bridge.js
CHANGED
|
@@ -7,6 +7,7 @@ import { ResourceRegistry } from "./resources.js";
|
|
|
7
7
|
import { ExportJob, requireExportFrameRate } from "./jobs.js";
|
|
8
8
|
import { attemptOptions } from "./runtime/budget.js";
|
|
9
9
|
import { createWorkerPreview } from "./worker.js";
|
|
10
|
+
import { registerCaptionFonts } from "./runtime/caption-fonts.js";
|
|
10
11
|
import { AssetLibrary, streamPeaks } from "./runtime/assets.js";
|
|
11
12
|
import { SourcePixels, providerSettings, sameProviderSettings, } from "./runtime/sources.js";
|
|
12
13
|
import { fingerprintFile } from "./runtime/fingerprint.js";
|
|
@@ -212,6 +213,8 @@ export function createBrowserBridge(options) {
|
|
|
212
213
|
};
|
|
213
214
|
/** The engine's asset decisions, from the wasm module, loaded on first use. */
|
|
214
215
|
const decisions = async () => (decisionBinding ??= await loadWasm());
|
|
216
|
+
/** What `measureText` lays text out with, made on first use, and the font stack it holds. */
|
|
217
|
+
let measurer = null, measuredFonts = null;
|
|
215
218
|
const registry = new ResourceRegistry(resourceLimit);
|
|
216
219
|
/**
|
|
217
220
|
* The runtimes this session holds, by {@link ownerKey}: a lease and the registry revision it was
|
|
@@ -1774,6 +1777,8 @@ export function createBrowserBridge(options) {
|
|
|
1774
1777
|
proxies.clear();
|
|
1775
1778
|
registry.dispose();
|
|
1776
1779
|
engine = null;
|
|
1780
|
+
measurer?.free();
|
|
1781
|
+
measurer = null;
|
|
1777
1782
|
detachOwner();
|
|
1778
1783
|
})();
|
|
1779
1784
|
return disposal;
|
|
@@ -1874,6 +1879,22 @@ export function createBrowserBridge(options) {
|
|
|
1874
1879
|
}
|
|
1875
1880
|
return families;
|
|
1876
1881
|
},
|
|
1882
|
+
async measureText(generator) {
|
|
1883
|
+
const { WasmTextMeasurer } = await loadWasm();
|
|
1884
|
+
if (disposed)
|
|
1885
|
+
throw new EditorError("disposed", "Bridge is disposed", "browser");
|
|
1886
|
+
// The fonts and canvas preview draws the draft with.
|
|
1887
|
+
const document = editor.draft;
|
|
1888
|
+
const fonts = fontStackOf(document);
|
|
1889
|
+
measurer ??= new WasmTextMeasurer();
|
|
1890
|
+
if (!sameList(measuredFonts, fonts)) {
|
|
1891
|
+
// A font the engine refuses is left out here as preview leaves it out, and reported there.
|
|
1892
|
+
registerCaptionFonts(measurer, fonts);
|
|
1893
|
+
measuredFonts = fonts;
|
|
1894
|
+
}
|
|
1895
|
+
const { width, height } = document.project.settings;
|
|
1896
|
+
return JSON.parse(measurer.measure(JSON.stringify(generator), width, height));
|
|
1897
|
+
},
|
|
1877
1898
|
conform,
|
|
1878
1899
|
/**
|
|
1879
1900
|
* Makes a proxy of a source whose original this session holds, keeps it, and previews from it
|
|
@@ -62,6 +62,7 @@ export function exportTimeline({ supplyFrame, renderFrame, sourceTransfer, engin
|
|
|
62
62
|
source: string;
|
|
63
63
|
};
|
|
64
64
|
appliedVideoRateControl: import("alpha2/mediabunny").AppliedVideoRateControl | null;
|
|
65
|
+
videoLatencyMode: import("alpha2/mediabunny").VideoEncoderLatencyMode | null;
|
|
65
66
|
audioCodec: "aac" | "opus" | undefined;
|
|
66
67
|
audioRateControl: {
|
|
67
68
|
bitrate: number;
|
|
@@ -386,6 +386,7 @@ export async function exportTimeline({ supplyFrame, renderFrame, sourceTransfer,
|
|
|
386
386
|
},
|
|
387
387
|
// `quantizer` when the encoder accepted constant-quantizer encoding, else the bitrate path.
|
|
388
388
|
appliedVideoRateControl: sink.appliedVideoRateControl ?? null,
|
|
389
|
+
videoLatencyMode: sink.videoLatencyMode ?? null,
|
|
389
390
|
audioCodec,
|
|
390
391
|
audioRateControl: audioBitrate === undefined
|
|
391
392
|
? null
|
package/dist/browser/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MediaFingerprint, Project } from "alpha2/project";
|
|
1
|
+
import type { Generator, MediaFingerprint, Project } from "alpha2/project";
|
|
2
2
|
import type { AssetBinding, ConformReport, MediaPurpose } from "alpha2/assets";
|
|
3
3
|
import type { BuiltinEffectCatalog } from "alpha2/effects";
|
|
4
4
|
import type { EditorSession } from "../core/session.js";
|
|
@@ -273,6 +273,37 @@ export interface ProxyRemoval {
|
|
|
273
273
|
* ticks (120000 per second). Methods that change the document dispatch through the session, so
|
|
274
274
|
* they are undoable.
|
|
275
275
|
*/
|
|
276
|
+
/** A rectangle in fractions of the canvas, y down, as a text style's `position` is. */
|
|
277
|
+
export interface CanvasRect {
|
|
278
|
+
readonly left: number;
|
|
279
|
+
readonly top: number;
|
|
280
|
+
readonly right: number;
|
|
281
|
+
readonly bottom: number;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Where a text generator's text lies on the picture it draws, before its clip's transform and
|
|
285
|
+
* effects: what {@link BrowserBridge.measureText} answers.
|
|
286
|
+
*/
|
|
287
|
+
export interface TextBounds {
|
|
288
|
+
/**
|
|
289
|
+
* The box the style's `anchor` and `position` place: `max_width` wide, every line's em box tall,
|
|
290
|
+
* and the whole pixels of outline and background padding around that.
|
|
291
|
+
*/
|
|
292
|
+
readonly layout: CanvasRect;
|
|
293
|
+
/**
|
|
294
|
+
* From the start of the line that starts farthest left to the end of the one that ends farthest
|
|
295
|
+
* right, as tall as `layout`, with the same decorations around it. It moves only as the lines'
|
|
296
|
+
* advances do, not as glyphs with more or less ink are typed: steady handles for a text clip.
|
|
297
|
+
*/
|
|
298
|
+
readonly content: CanvasRect;
|
|
299
|
+
/**
|
|
300
|
+
* What the text draws: its glyphs, their outline, and the background's boxes. Every pixel the
|
|
301
|
+
* frame gives the text meets it, give or take the pixel the texture's sampling spreads it by;
|
|
302
|
+
* `null` when the text draws nothing (only spaces).
|
|
303
|
+
*/
|
|
304
|
+
readonly ink: CanvasRect | null;
|
|
305
|
+
readonly lineCount: number;
|
|
306
|
+
}
|
|
276
307
|
export interface BrowserBridge {
|
|
277
308
|
/** Where the preview renders: nowhere until `bindPreview`, then a worker or the main thread. */
|
|
278
309
|
readonly previewBackend: "unbound" | "worker" | "main-thread";
|
|
@@ -418,6 +449,17 @@ export interface BrowserBridge {
|
|
|
418
449
|
* name tables.
|
|
419
450
|
*/
|
|
420
451
|
captionFontFamilies(): Promise<string[]>;
|
|
452
|
+
/**
|
|
453
|
+
* Where the engine draws a text generator's text (see {@link TextBounds}): laid out as preview
|
|
454
|
+
* lays it out, with the same fonts, at the draft's canvas size, without rendering. A clip's
|
|
455
|
+
* transform maps these rectangles as it maps the rest of its picture.
|
|
456
|
+
*
|
|
457
|
+
* Rejects a generator that is not a valid text generator (`INVALID_INPUT`), with no fonts to
|
|
458
|
+
* draw it, and once the bridge is disposed (`disposed`).
|
|
459
|
+
*/
|
|
460
|
+
measureText(generator: Extract<Generator, {
|
|
461
|
+
type: "text";
|
|
462
|
+
}>): Promise<TextBounds>;
|
|
421
463
|
/**
|
|
422
464
|
* The files a native export of `document` (the current one by default) needs, for upload:
|
|
423
465
|
* shown media (or their proxies with `media: "proxies"`), an image sequence's frames, font
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpha2-sh/editor",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Headless Project-based editing sessions and browser adapters for alpha2.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,11 +60,11 @@
|
|
|
60
60
|
"build": "rm -rf dist && tsc -p tsconfig.json"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"alpha2": "0.2.
|
|
63
|
+
"alpha2": "0.2.2",
|
|
64
64
|
"react": "^19.3.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"alpha2": "0.2.
|
|
67
|
+
"alpha2": "0.2.2",
|
|
68
68
|
"react": "19.3.0",
|
|
69
69
|
"react-dom": "19.3.0",
|
|
70
70
|
"@types/react": "19.3.0",
|