@alpha2-sh/editor 0.2.0 → 0.2.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.
@@ -240,6 +240,8 @@ export function createBrowserBridge(options) {
240
240
  let previewSelection = new Map();
241
241
  /** What that selection was decided from (see `loaded`). */
242
242
  let previewConformKey = null;
243
+ /** What preview prefers where a source has a fresh proxy (see `setPreviewMedia`). */
244
+ let preferredPreviewMedia = "original";
243
245
  const hashOf = (asset) => asset?.fingerprint?.content_sha256;
244
246
  const originalOf = (document, id) => {
245
247
  const descriptor = document.assets[id];
@@ -335,7 +337,10 @@ export function createBrowserBridge(options) {
335
337
  * A proxy this session makes is adopted directly.
336
338
  */
337
339
  let absentProxies = new Set();
338
- /** Finds the kept proxies of sources this session has no original for. */
340
+ /**
341
+ * Finds the kept proxies of sources this session has no original for, and of every source while
342
+ * preview prefers proxies.
343
+ */
339
344
  async function discoverProxies(document) {
340
345
  for (const source of document.project.sources) {
341
346
  const descriptor = document.assets[source.id];
@@ -343,7 +348,8 @@ export function createBrowserBridge(options) {
343
348
  if (!hash ||
344
349
  proxies.has(hash) ||
345
350
  absentProxies.has(hash) ||
346
- originalOf(document, source.id))
351
+ (preferredPreviewMedia === "original" &&
352
+ originalOf(document, source.id)))
347
353
  continue;
348
354
  // Held before it is read, so no page removes it between.
349
355
  const hold = await proxyStore.hold(hash);
@@ -683,13 +689,18 @@ export function createBrowserBridge(options) {
683
689
  const catalog = catalogOf(document);
684
690
  const conformKey = checked.revisionKey +
685
691
  JSON.stringify(previewOutput) +
692
+ preferredPreviewMedia +
686
693
  JSON.stringify(catalog);
694
+ const before = JSON.stringify([...previewSelection]);
687
695
  if (conformKey !== previewConformKey) {
688
- const selected = conformProject(await decisions(), compiled.project, catalog, "preview");
696
+ const selected = conformProject(await decisions(), compiled.project, catalog, preferredPreviewMedia === "proxies" ? "preview_proxy" : "preview");
689
697
  previewSelection = new Map(selected.sources.map((source) => [source.source_id, source.selection]));
690
698
  previewConformKey = conformKey;
691
699
  }
692
700
  const selectionKey = JSON.stringify([...previewSelection]);
701
+ // `proxyStatus` reports what preview reads.
702
+ if (selectionKey !== before)
703
+ notifyAssets();
693
704
  const used = shownSources(compiled.project);
694
705
  for (const source of compiled.project.sources)
695
706
  if (!drawnByEngine(source) &&
@@ -1866,7 +1877,7 @@ export function createBrowserBridge(options) {
1866
1877
  conform,
1867
1878
  /**
1868
1879
  * Makes a proxy of a source whose original this session holds, keeps it, and previews from it
1869
- * wherever the original goes offline.
1880
+ * wherever the original goes offline, or while preview prefers proxies.
1870
1881
  */
1871
1882
  async generateProxy(id, { signal } = {}) {
1872
1883
  const descriptor = editor.document.assets[id];
@@ -1951,6 +1962,24 @@ export function createBrowserBridge(options) {
1951
1962
  get previewOutput() {
1952
1963
  return previewOutput;
1953
1964
  },
1965
+ /**
1966
+ * Makes preview read a fresh proxy wherever a source has one (`proxies`), or the original
1967
+ * wherever it is online (`original`, the default). Preview only: an export reads what its own
1968
+ * `media` says.
1969
+ */
1970
+ setPreviewMedia(media) {
1971
+ if (media !== "original" && media !== "proxies")
1972
+ throw Error("Preview media must be original or proxies");
1973
+ if (media === preferredPreviewMedia)
1974
+ return;
1975
+ preferredPreviewMedia = media;
1976
+ renderKey = null;
1977
+ if (engine)
1978
+ void seek(tick).catch(onError);
1979
+ },
1980
+ get previewMedia() {
1981
+ return preferredPreviewMedia;
1982
+ },
1954
1983
  hasOriginal: (id) => !!originalOf(editor.document, id),
1955
1984
  /**
1956
1985
  * Which video codecs this browser encodes for an export of the current document at
@@ -2146,7 +2175,11 @@ export function createBrowserBridge(options) {
2146
2175
  get catalog() {
2147
2176
  return engine?.catalog ?? null;
2148
2177
  },
2149
- getAsset: (id) => library.get(id),
2178
+ // A source's own media while it is online, whichever preview reads: its size, file and peaks
2179
+ // are the original's.
2180
+ getAsset: (id) => (preferredPreviewMedia === "proxies" &&
2181
+ sourceView(editor.draft, id, originalOf(editor.draft, id))) ||
2182
+ library.get(id),
2150
2183
  };
2151
2184
  }
2152
2185
  /**
@@ -302,9 +302,10 @@ export interface BrowserBridge {
302
302
  /** The engine's built-in effects and transitions; `null` until a preview is bound. */
303
303
  readonly catalog: BuiltinEffectCatalog | null;
304
304
  /**
305
- * What preview reads for source `id` of the draft: its original, or the kept proxy standing in
306
- * while the original is offline; opened with the provider settings the document names. Use {@link
307
- * BrowserBridge.hasOriginal} to ask whether the original itself is linked.
305
+ * Source `id` of the draft: its original while it is online, even where preview reads a proxy
306
+ * (see {@link BrowserBridge.setPreviewMedia}), else the kept proxy standing in for it; opened
307
+ * with the provider settings the document names. Use {@link BrowserBridge.hasOriginal} to ask
308
+ * whether the original itself is linked.
308
309
  */
309
310
  getAsset(id: string): RuntimeAsset | null;
310
311
  /**
@@ -481,6 +482,14 @@ export interface BrowserBridge {
481
482
  readonly compositionId: string;
482
483
  readonly nodeId: string;
483
484
  } | null;
485
+ /**
486
+ * Makes preview read a fresh proxy wherever a source has one (`proxies`), or the original
487
+ * wherever it is online (`original`, the default). Preview only: an export reads what its own
488
+ * `media` says. {@link BrowserBridge.proxyStatus} reports what each source reads.
489
+ */
490
+ setPreviewMedia(media: "original" | "proxies"): void;
491
+ /** What {@link BrowserBridge.setPreviewMedia} last set. */
492
+ readonly previewMedia: "original" | "proxies";
484
493
  /**
485
494
  * Shows another animation of a dotLottie source, keeping its clips. Throws `EditorError`
486
495
  * `unsupported_media` for another kind of source or an animation the package lacks.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpha2-sh/editor",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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.0",
63
+ "alpha2": "0.2.1",
64
64
  "react": "^19.3.0"
65
65
  },
66
66
  "devDependencies": {
67
- "alpha2": "0.2.0",
67
+ "alpha2": "0.2.1",
68
68
  "react": "19.3.0",
69
69
  "react-dom": "19.3.0",
70
70
  "@types/react": "19.3.0",