@alpha2-sh/editor 0.4.6 → 0.5.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.
Files changed (81) hide show
  1. package/dist/browser/bridge.d.ts +15 -16
  2. package/dist/browser/bridge.js +393 -312
  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 -28
  12. package/dist/browser/runtime/assets.js +136 -45
  13. package/dist/browser/runtime/audio.d.ts +16 -11
  14. package/dist/browser/runtime/audio.js +102 -59
  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 +44 -44
  20. package/dist/browser/runtime/engine.js +87 -64
  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 +19 -19
  37. package/dist/browser/runtime/proxies.js +72 -51
  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 +85 -103
  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 +244 -239
  51. package/dist/browser/worker.d.ts +10 -10
  52. package/dist/browser/worker.js +64 -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 -20
  79. package/dist/react/index.d.ts +5 -6
  80. package/dist/react/index.js +5 -6
  81. package/package.json +4 -4
@@ -5,15 +5,15 @@ import { type ExportFailure } from "alpha2/export-failure";
5
5
  import { ExportJob } from "../browser/jobs.js";
6
6
  import type { BrowserExportOptions } from "../browser/types.js";
7
7
  /**
8
- * A file uploaded for a native export, usually produced by the browser bridge's `nativeAssets`.
9
- * The host reads media only from these uploads, never from a filesystem path the document names.
8
+ * A file uploaded for a native export, usually from the browser bridge's `nativeAssets`. The host
9
+ * reads media only from these uploads, never from a path the document names.
10
10
  */
11
11
  export interface NativeAsset {
12
12
  /** The source, resource or font id the file belongs to (for `frames`, the upload's own id). */
13
13
  readonly id: string;
14
14
  /**
15
- * `proxies`: a proxy standing in for source `id`, made from `madeFrom`. `frames`: one frame of an
16
- * image sequence, the file at `locator`.
15
+ * `proxies`: a proxy for source `id`, made from `madeFrom`. `frames`: one image sequence frame,
16
+ * the file at `locator`.
17
17
  */
18
18
  readonly kind: "assets" | "effect-assets" | "caption-fonts" | "proxies" | "frames";
19
19
  readonly blob: Blob;
@@ -23,9 +23,9 @@ export interface NativeAsset {
23
23
  readonly locator?: string;
24
24
  }
25
25
  /**
26
- * Export settings for a native job: the browser export's options, plus the MPEG-4 Part 2 codec the
27
- * host can encode. `container`, `videoCodec` and `audioCodec` go to the host as given; an absent
28
- * one is the container's default there, as in the browser.
26
+ * Export settings for a native job: the browser export's options plus the MPEG-4 Part 2 codec the
27
+ * host can encode. An absent `container`, `videoCodec` or `audioCodec` takes the host's default, as
28
+ * in the browser.
29
29
  */
30
30
  export interface NativeExportOptions extends Omit<BrowserExportOptions, "videoCodec"> {
31
31
  readonly videoCodec?: BrowserExportOptions["videoCodec"] | "mpeg4-part2";
@@ -51,9 +51,9 @@ export type NativeArtifactStatus = {
51
51
  readonly status: "missing" | "unreachable";
52
52
  };
53
53
  /**
54
- * Asks the service whether the file at `url` (an artifact's) can still be downloaded, without
55
- * downloading it. Never rejects: a network error is `unreachable`, a 404 is `missing`, and a 410
56
- * is `gone` with the reason the service gives (`expired` when it gives none).
54
+ * Asks the service whether an artifact's `url` can still be downloaded, without downloading it.
55
+ * Never rejects: a network error is `unreachable`, a 404 is `missing`, and a 410 is `gone` with the
56
+ * service's reason (`expired` when it gives none).
57
57
  */
58
58
  export declare function nativeArtifactStatus(url: string, request?: typeof fetch): Promise<NativeArtifactStatus>;
59
59
  /** A native job's state as the service reports it. */
@@ -61,7 +61,7 @@ export interface NativeJobState {
61
61
  readonly phase: "preparing" | "rendering" | "finalizing" | "publishing" | "completed" | "failed" | "cancelled";
62
62
  /** The finished file, once `completed`. */
63
63
  readonly artifact?: NativeArtifactDescriptor;
64
- /** The share done, from 0 to 1. */
64
+ /** Share done, from 0 to 1. */
65
65
  readonly fraction: number;
66
66
  readonly frames?: {
67
67
  readonly completed: number;
@@ -72,9 +72,9 @@ export interface NativeJobState {
72
72
  /** The host's classified failure, when `failed`. */
73
73
  readonly failure?: ExportFailure;
74
74
  /**
75
- * The host's report on the render cache of the last attempt to finish rendering: `used` with its
76
- * counts, or `unavailable` with why (the GPU-resident path bakes nothing); `null` for an attempt
77
- * rendered without one (a first attempt, a short export). Absent until an attempt reports.
75
+ * Render cache report of the last attempt that finished rendering: `used` with its counts, or
76
+ * `unavailable` with the reason. `null` when the attempt rendered without one. Absent until an
77
+ * attempt reports.
78
78
  */
79
79
  readonly resume?: {
80
80
  readonly status: "used";
@@ -91,42 +91,41 @@ export interface NativeClientOptions {
91
91
  readonly fetch?: typeof fetch;
92
92
  }
93
93
  /**
94
- * A client for the native export service (`@alpha2-sh/node`'s HTTP host). Exports run on the service
95
- * with the editor's retry policy; each job uploads its assets once and reuses them across attempts.
94
+ * A client for the native export service (`@alpha2-sh/node`'s HTTP host). Exports run with the
95
+ * editor's retry policy; each job uploads its assets once and reuses them across attempts.
96
96
  */
97
97
  export declare function createNativeClient(options: NativeClientOptions): {
98
98
  /** The service's `/health` report. Rejects when the service answers with an error status. */
99
99
  capabilities(): Promise<Record<string, unknown>>;
100
100
  /**
101
- * Starts an export of `editor.document` on the service and returns its job. The document,
102
- * `assets` and `settings` are captured now; later edits do not reach the job. `assets` may be
103
- * a function, called once per upload with the document and the attempt's signal. The range is
104
- * the document's export range, else the whole timeline. Throws when the client is disposed,
105
- * and an `EditorError` `invalid_frame_rate` for a `frameRate` the engine does not read.
101
+ * Starts an export of `editor.document` on the service. The document, `assets` and `settings`
102
+ * are captured now, so later edits do not reach the job. `assets` may be a function, called
103
+ * once per upload with the document and the attempt's signal. The range is the document's
104
+ * export range, else the whole timeline. Throws when the client is disposed, and an
105
+ * `EditorError` `invalid_frame_rate` for a `frameRate` the engine does not read.
106
106
  */
107
107
  startExport(editor: Pick<EditorSnapshot, "document" | "revision">, assets: readonly NativeAsset[] | ((document: EditorDocument, signal: AbortSignal) => Promise<readonly NativeAsset[]>), settings?: NativeExportOptions): ExportJob;
108
108
  /**
109
- * What the service knows of job `id`, for a page that lost the job it started (it was
110
- * reloaded): its state, and where its file can be downloaded once it is complete. Null when the
111
- * service no longer has the job. Rejects on any other error status.
109
+ * What the service knows of job `id`, for a reloaded page that lost the job it started: its
110
+ * state and, once complete, where to download its file. `null` when the service no longer has
111
+ * the job. Rejects on any other error status.
112
112
  */
113
113
  jobState(id: string): Promise<(NativeJobState & {
114
114
  readonly url?: string;
115
115
  }) | null>;
116
116
  /**
117
- * Removes job `id` from the service: a render it runs stops, and its kept file is deleted. For
118
- * a job this client did not start, such as one a page that is gone left (see
119
- * {@link jobState}). Rejects when the service answers with an error status.
117
+ * Removes job `id` from the service, stopping its render and deleting its kept file. Meant for
118
+ * a job another page left behind (see {@link jobState}). Rejects on an error status.
120
119
  */
121
120
  releaseJob(id: string): Promise<void>;
122
121
  /** Cancels every running job and refuses new ones. Resolves once the cancellations settle. */
123
122
  dispose(): Promise<void>;
124
123
  /**
125
- * Lets go of every running job and refuses new ones, for a page that is leaving, without
126
- * cancelling what the service already renders: a job whose render was asked for goes on there
127
- * and keeps its file, for a later page to find with {@link jobState}. A job still uploading is
128
- * removed, since only this client could send the rest. The jobs here settle as cancelled.
129
- * Resolves once they settle; a removal that fails is left to the service's lease.
124
+ * Releases every running job and refuses new ones, for a page that is leaving, without
125
+ * cancelling renders already requested: those continue on the service and keep their files for
126
+ * a later page to find with {@link jobState}. Jobs still uploading are removed, since only this
127
+ * client could send the rest. Local jobs settle as cancelled; resolves once they do. A failed
128
+ * removal is left to the service's lease.
130
129
  */
131
130
  detach(): Promise<void>;
132
131
  };
@@ -2,9 +2,9 @@ import { compileEditorDocument, EditorError, sequenceEnd, } from "../core/docume
2
2
  import { ExportFailureError } from "alpha2/export-failure";
3
3
  import { ExportJob, requireExportFrameRate } from "../browser/jobs.js";
4
4
  /**
5
- * Asks the service whether the file at `url` (an artifact's) can still be downloaded, without
6
- * downloading it. Never rejects: a network error is `unreachable`, a 404 is `missing`, and a 410
7
- * is `gone` with the reason the service gives (`expired` when it gives none).
5
+ * Asks the service whether an artifact's `url` can still be downloaded, without downloading it.
6
+ * Never rejects: a network error is `unreachable`, a 404 is `missing`, and a 410 is `gone` with the
7
+ * service's reason (`expired` when it gives none).
8
8
  */
9
9
  export async function nativeArtifactStatus(url, request = fetch) {
10
10
  let response;
@@ -22,7 +22,7 @@ export async function nativeArtifactStatus(url, request = fetch) {
22
22
  };
23
23
  }
24
24
  if (response.status === 410) {
25
- // A HEAD answer has no body to say why; ask once more for it.
25
+ // A HEAD response has no body, so ask again for the reason.
26
26
  const detail = (await request(url)
27
27
  .then((full) => full.json())
28
28
  .catch(() => ({})));
@@ -46,9 +46,9 @@ function nativeFailure(state, jobId) {
46
46
  };
47
47
  return new ExportFailureError({ ...failure, message, jobId });
48
48
  }
49
- /** How many times a job's state is asked for in a row before an attempt gives up on it. */
49
+ /** Consecutive failed status requests before an attempt gives up on the job. */
50
50
  const STATUS_ATTEMPTS = 5;
51
- /** The wait before asking for a job's state again, doubled each time (0.25 s to 2 s). */
51
+ /** Status retry delay, doubled each time (0.25 s to 2 s). */
52
52
  const STATUS_RETRY_MS = 250;
53
53
  function delay(ms, signal) {
54
54
  return new Promise((resolve, reject) => {
@@ -66,15 +66,15 @@ function delay(ms, signal) {
66
66
  });
67
67
  }
68
68
  /**
69
- * A client for the native export service (`@alpha2-sh/node`'s HTTP host). Exports run on the service
70
- * with the editor's retry policy; each job uploads its assets once and reuses them across attempts.
69
+ * A client for the native export service (`@alpha2-sh/node`'s HTTP host). Exports run with the
70
+ * editor's retry policy; each job uploads its assets once and reuses them across attempts.
71
71
  */
72
72
  export function createNativeClient(options) {
73
73
  const request = options.fetch ?? fetch;
74
74
  const base = options.baseUrl.replace(/\/$/, "");
75
75
  const jobs = new Set();
76
76
  let disposed = false;
77
- // Set by `detach`: a job whose render was asked for is let go of, not removed.
77
+ // Set by `detach`: jobs whose render was requested are released, not removed.
78
78
  let detached = false;
79
79
  async function checked(path, init) {
80
80
  const response = await request(`${base}${path}`, init);
@@ -88,11 +88,11 @@ export function createNativeClient(options) {
88
88
  return (await checked("/health")).json();
89
89
  },
90
90
  /**
91
- * Starts an export of `editor.document` on the service and returns its job. The document,
92
- * `assets` and `settings` are captured now; later edits do not reach the job. `assets` may be
93
- * a function, called once per upload with the document and the attempt's signal. The range is
94
- * the document's export range, else the whole timeline. Throws when the client is disposed,
95
- * and an `EditorError` `invalid_frame_rate` for a `frameRate` the engine does not read.
91
+ * Starts an export of `editor.document` on the service. The document, `assets` and `settings`
92
+ * are captured now, so later edits do not reach the job. `assets` may be a function, called
93
+ * once per upload with the document and the attempt's signal. The range is the document's
94
+ * export range, else the whole timeline. Throws when the client is disposed, and an
95
+ * `EditorError` `invalid_frame_rate` for a `frameRate` the engine does not read.
96
96
  */
97
97
  startExport(editor, assets, settings = {}) {
98
98
  if (disposed)
@@ -103,13 +103,13 @@ export function createNativeClient(options) {
103
103
  const capturedAssets = typeof assets === "function" ? assets : [...assets];
104
104
  const id = crypto.randomUUID();
105
105
  const path = `/jobs/${id}`;
106
- // Shared by attempts: an attempt resumes, and starts over only when the service lost the job.
106
+ // Shared by attempts; an attempt starts over only when the service lost the job.
107
107
  let captured = null;
108
- // Whether the service holds a job to clean up: from the acknowledged PUT on, uploads or not.
108
+ // Whether the service holds a job to clean up, from the acknowledged PUT on.
109
109
  let allocated = false;
110
110
  const acknowledged = new Set();
111
111
  let uploaded = null;
112
- // Whether a render was asked for: the service may be running one an earlier attempt started.
112
+ // Whether a render was requested; the service may still run one from an earlier attempt.
113
113
  let posted = false;
114
114
  const lost = () => {
115
115
  allocated = false;
@@ -118,13 +118,13 @@ export function createNativeClient(options) {
118
118
  posted = false;
119
119
  };
120
120
  const allocate = async () => {
121
- // Allocate without the cancellation signal: even a cancelled allocation is acknowledged
122
- // before DELETE, so an orphan job cannot win that race.
121
+ // Allocate without the cancellation signal so a cancelled allocation is still acknowledged
122
+ // before DELETE and cannot leave an orphan job.
123
123
  try {
124
124
  await checked(path, { method: "PUT" });
125
125
  }
126
126
  catch (error) {
127
- // An allocation whose answer was lost: the id is this job's alone, so a job there is it.
127
+ // The allocation's response was lost. The id is unique to this job, so a job there is it.
128
128
  const existing = await request(`${base}${path}`).catch(() => null);
129
129
  if (!existing?.ok)
130
130
  throw error;
@@ -161,9 +161,9 @@ export function createNativeClient(options) {
161
161
  };
162
162
  };
163
163
  /**
164
- * The job's state. A request that fails for a moment (the network, a proxy's 502) is asked
165
- * again, backing off, so a long render is not given up for one lost answer; a 404 means the
166
- * service lost the job, and the next attempt starts over.
164
+ * The job's state. Transient failures (network, a proxy's 502) are retried with backoff so a
165
+ * long render is not abandoned over one lost response. A 404 means the service lost the job
166
+ * and the next attempt starts over.
167
167
  */
168
168
  const status = async (signal, attempt) => {
169
169
  for (let failures = 1;; failures += 1) {
@@ -209,8 +209,8 @@ export function createNativeClient(options) {
209
209
  if (diagnostics.length)
210
210
  throw Error(diagnostics.map((d) => d.message).join("; "));
211
211
  signal.throwIfAborted();
212
- // A render an earlier attempt asked for is followed, not asked again (the service refuses that
213
- // while it runs). One that failed or never started is asked anew.
212
+ // Follow a render an earlier attempt requested instead of requesting it again (the service
213
+ // refuses that while it runs). Request anew if it failed or never started.
214
214
  const running = posted
215
215
  ? !["preparing", "failed"].includes((await status(signal, attempt)).phase)
216
216
  : false;
@@ -227,7 +227,6 @@ export function createNativeClient(options) {
227
227
  fonts: captured
228
228
  .filter((a) => a.kind === "caption-fonts")
229
229
  .map((a) => a.id),
230
- // Each image sequence's frame uploads, in project order.
231
230
  frames: Object.fromEntries(project.sources.flatMap((source) => source.provider?.format === "image_sequence"
232
231
  ? [
233
232
  [
@@ -242,7 +241,7 @@ export function createNativeClient(options) {
242
241
  .filter((a) => a.kind === "proxies")
243
242
  .map((a) => [a.id, { madeFrom: a.madeFrom }])),
244
243
  media: capturedSettings.media ?? "original",
245
- // A retry asks for less in flight: the host scales its own budgets.
244
+ // Retries keep less in flight; the host scales its own budgets.
246
245
  ...(attempt.profile.memoryScale < 1 || capturedSettings.memory
247
246
  ? {
248
247
  memory: {
@@ -278,7 +277,8 @@ export function createNativeClient(options) {
278
277
  const artifact = published;
279
278
  if (!artifact)
280
279
  throw Error("The native service finished without a file to download");
281
- // The file stays on the service until released, so a failed download retries without a rerender.
280
+ // The file stays on the service until released, so a failed download can retry without a
281
+ // rerender.
282
282
  return {
283
283
  kind: "url",
284
284
  url: `${base}${path}/artifact`,
@@ -292,8 +292,8 @@ export function createNativeClient(options) {
292
292
  };
293
293
  const job = new ExportJob(editor.revision, document, {
294
294
  run: render,
295
- // Cleaned up once the job settles, never between attempts (a retry reuses the uploads). DELETE
296
- // resolves only after the host exits and its files are removed.
295
+ // Clean up once the job settles, never between attempts (retries reuse the uploads).
296
+ // DELETE resolves only after the host exits and its files are removed.
297
297
  async dispose({ ok }) {
298
298
  if (ok || !allocated || (detached && posted))
299
299
  return;
@@ -310,9 +310,9 @@ export function createNativeClient(options) {
310
310
  return job;
311
311
  },
312
312
  /**
313
- * What the service knows of job `id`, for a page that lost the job it started (it was
314
- * reloaded): its state, and where its file can be downloaded once it is complete. Null when the
315
- * service no longer has the job. Rejects on any other error status.
313
+ * What the service knows of job `id`, for a reloaded page that lost the job it started: its
314
+ * state and, once complete, where to download its file. `null` when the service no longer has
315
+ * the job. Rejects on any other error status.
316
316
  */
317
317
  async jobState(id) {
318
318
  const response = await request(`${base}/jobs/${encodeURIComponent(id)}`);
@@ -326,9 +326,8 @@ export function createNativeClient(options) {
326
326
  : state;
327
327
  },
328
328
  /**
329
- * Removes job `id` from the service: a render it runs stops, and its kept file is deleted. For
330
- * a job this client did not start, such as one a page that is gone left (see
331
- * {@link jobState}). Rejects when the service answers with an error status.
329
+ * Removes job `id` from the service, stopping its render and deleting its kept file. Meant for
330
+ * a job another page left behind (see {@link jobState}). Rejects on an error status.
332
331
  */
333
332
  async releaseJob(id) {
334
333
  await checked(`/jobs/${encodeURIComponent(id)}`, { method: "DELETE" });
@@ -339,11 +338,11 @@ export function createNativeClient(options) {
339
338
  await Promise.all([...jobs].map((job) => job.cancel()));
340
339
  },
341
340
  /**
342
- * Lets go of every running job and refuses new ones, for a page that is leaving, without
343
- * cancelling what the service already renders: a job whose render was asked for goes on there
344
- * and keeps its file, for a later page to find with {@link jobState}. A job still uploading is
345
- * removed, since only this client could send the rest. The jobs here settle as cancelled.
346
- * Resolves once they settle; a removal that fails is left to the service's lease.
341
+ * Releases every running job and refuses new ones, for a page that is leaving, without
342
+ * cancelling renders already requested: those continue on the service and keep their files for
343
+ * a later page to find with {@link jobState}. Jobs still uploading are removed, since only this
344
+ * client could send the rest. Local jobs settle as cancelled; resolves once they do. A failed
345
+ * removal is left to the service's lease.
347
346
  */
348
347
  async detach() {
349
348
  disposed = true;
@@ -1,13 +1,11 @@
1
1
  import type { Selection } from "alpha2/assets";
2
2
  import type { ExportFailure } from "alpha2/export-failure";
3
- import type { RetryProfile } from "alpha2/export-retry";
3
+ import type { AttemptRenderer, AttemptVideoEncoder, RetryProfile } from "alpha2/export-retry";
4
4
  import type { Project } from "alpha2/project";
5
5
  import type { EditorDocument, AssetDescriptor } from "../core/document.js";
6
6
  /** Shows a project in a preview surface. Implemented by the browser bridge and native previews. */
7
7
  export interface PreviewBridge {
8
- /**
9
- * Replaces the shown project. `revision` identifies this version and increases with every call.
10
- */
8
+ /** Replaces the shown project. `revision` increases with every call. */
11
9
  replaceProject(project: Project, revision: number): Promise<void>;
12
10
  /** Shows the frame at `tick` (timeline ticks). */
13
11
  seek(tick: number): Promise<void>;
@@ -40,10 +38,10 @@ export interface AudioTransport {
40
38
  /** An export job's progress, as its backends report it and `ExportJob.progress` holds it. */
41
39
  export interface ExportProgress {
42
40
  /**
43
- * Where the job is. `rendering` counts frames; `finalizing` means every frame is encoded and the
44
- * output is being flushed and closed; `publishing` that the file is being made available;
45
- * `downloading` that a native result is crossing to this browser. Only `completed` means the
46
- * result exists: 100 % of frames does not.
41
+ * `rendering` counts frames; `finalizing` means every frame is encoded and the output is being
42
+ * flushed; `publishing` that the file is being made available; `downloading` that a native result
43
+ * is transferring to this browser. Only `completed` means the result exists, even at 100 % of
44
+ * frames.
47
45
  */
48
46
  readonly phase: "preparing" | "rendering" | "finalizing" | "publishing" | "downloading" | "retrying" | "completed" | "cancelling" | "cancelled" | "failed";
49
47
  /** The whole job's share done, from 0 to 1. */
@@ -95,28 +93,29 @@ export type ExportArtifact = ({
95
93
  /** The file's length, when known. */
96
94
  readonly bytes?: number;
97
95
  /**
98
- * What the exporter reported about the run: timings, `performance` (with `memory` and `output`),
99
- * rates. A browser export adds `videoDecode`, the decode mode it ran with, `videoConversion`, who
100
- * converted decoded SDR frames (`engine` or `browser`), and `decodeFallbacks`:
101
- * per source, frames read by element seeks rather than decoded (`kind: "element-seek"`), with
102
- * why, how many frames, and whether for good, and sources `videoDecode: "software"` could not
103
- * decode in software (`kind: "software-unavailable"`).
96
+ * The exporter's run report: timings, `performance` (with `memory` and `output`), rates. A
97
+ * browser export adds `videoDecode` (the decode mode used), `videoConversion` (`engine` or
98
+ * `browser`), and `decodeFallbacks`. Those list, per source, frames read by element seeks instead
99
+ * of decoding (`kind: "element-seek"`, with reason, count and whether permanent), and sources
100
+ * that `videoDecode: "software"` could not decode in software (`kind: "software-unavailable"`).
104
101
  */
105
102
  readonly report?: Readonly<Record<string, unknown>>;
106
103
  };
107
104
  /** One run of an export job: a fresh device or host process, from the job's pinned document. */
108
105
  export interface ExportAttempt {
109
- /**
110
- * `<job id>/<number>`: what a backend tags this run's work with, so a late answer from an earlier
111
- * one is told apart.
112
- */
106
+ /** `<job id>/<number>`, tagging this run's work so late answers from earlier runs are ignored. */
113
107
  readonly id: string;
114
108
  /** From 1. */
115
109
  readonly number: number;
110
+ /** A backend scales its byte budgets by `profile.memoryScale`. */
111
+ readonly profile: RetryProfile;
116
112
  /**
117
- * How much this run keeps in flight: a backend scales its byte budgets by `profile.memoryScale`.
113
+ * `cpu` after the GPU hung on this export's own work (`DEVICE_HUNG`), when the retry policy says
114
+ * the backend has a CPU renderer.
118
115
  */
119
- readonly profile: RetryProfile;
116
+ readonly renderer: AttemptRenderer;
117
+ /** The video encoder this run asks for: `software` after an encode failure. */
118
+ readonly videoEncoder: AttemptVideoEncoder;
120
119
  /** Why the previous attempt failed, when this one is a retry. */
121
120
  readonly previous?: ExportFailure;
122
121
  }
@@ -13,16 +13,15 @@ export declare function EditorProvider({ editor, children, }: {
13
13
  export declare function useEditor(): EditorSession;
14
14
  /**
15
15
  * Subscribes to one value derived from the session's snapshot; the component re-renders when it
16
- * changes by `equal` (`Object.is` by default). Inline selectors are fine: the result is cached per
17
- * snapshot and an `equal` result keeps the previous reference, even when the selector function
18
- * itself is new on every render, so a selector that builds arrays or objects does not re-render
19
- * in a loop. Throws without an {@link EditorProvider}.
16
+ * changes by `equal` (`Object.is` by default). Inline selectors are fine, even ones that build
17
+ * arrays or objects: the result is cached per snapshot and an `equal` result keeps the previous
18
+ * reference. Throws without an {@link EditorProvider}.
20
19
  */
21
20
  export declare function useEditorSelector<T>(selector: (snapshot: EditorSnapshot) => T, equal?: (a: T, b: T) => boolean): T;
22
21
  /**
23
22
  * Shows `bridge`'s preview in a canvas filling a `div` (styled by `className` and `style`). The
24
- * canvas is bound on mount and released on unmount; binds of one bridge run one at a time.
25
- * `onReady` fires once the canvas is bound; `onError` receives a bind or release failure.
23
+ * canvas is bound on mount and released on unmount. `onReady` fires once it is bound; `onError`
24
+ * receives a bind or release failure.
26
25
  */
27
26
  export declare function EditorPreview({ bridge, className, style, onReady, onError, }: {
28
27
  bridge: BrowserBridge;
@@ -16,10 +16,9 @@ export function useEditor() {
16
16
  }
17
17
  /**
18
18
  * Subscribes to one value derived from the session's snapshot; the component re-renders when it
19
- * changes by `equal` (`Object.is` by default). Inline selectors are fine: the result is cached per
20
- * snapshot and an `equal` result keeps the previous reference, even when the selector function
21
- * itself is new on every render, so a selector that builds arrays or objects does not re-render
22
- * in a loop. Throws without an {@link EditorProvider}.
19
+ * changes by `equal` (`Object.is` by default). Inline selectors are fine, even ones that build
20
+ * arrays or objects: the result is cached per snapshot and an `equal` result keeps the previous
21
+ * reference. Throws without an {@link EditorProvider}.
23
22
  */
24
23
  export function useEditorSelector(selector, equal = Object.is) {
25
24
  const editor = useEditor();
@@ -46,8 +45,8 @@ export function useEditorSelector(selector, equal = Object.is) {
46
45
  const bindings = new WeakMap();
47
46
  /**
48
47
  * Shows `bridge`'s preview in a canvas filling a `div` (styled by `className` and `style`). The
49
- * canvas is bound on mount and released on unmount; binds of one bridge run one at a time.
50
- * `onReady` fires once the canvas is bound; `onError` receives a bind or release failure.
48
+ * canvas is bound on mount and released on unmount. `onReady` fires once it is bound; `onError`
49
+ * receives a bind or release failure.
51
50
  */
52
51
  export function EditorPreview({ bridge, className, style, onReady, onError, }) {
53
52
  const host = useRef(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpha2-sh/editor",
3
- "version": "0.4.6",
3
+ "version": "0.5.1",
4
4
  "description": "Headless Project-based editing sessions and browser adapters for alpha2.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -57,14 +57,14 @@
57
57
  }
58
58
  },
59
59
  "scripts": {
60
- "build": "rm -rf dist && tsc -p tsconfig.json"
60
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json"
61
61
  },
62
62
  "peerDependencies": {
63
- "alpha2": "0.4.6",
63
+ "alpha2": "0.5.1",
64
64
  "react": "^19.3.0"
65
65
  },
66
66
  "devDependencies": {
67
- "alpha2": "0.4.6",
67
+ "alpha2": "0.5.1",
68
68
  "react": "19.3.0",
69
69
  "react-dom": "19.3.0",
70
70
  "@types/react": "19.3.0",