@alpha2-sh/editor 0.2.2 → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  import { addTransition, resizeTransition, removeTransition, } from "./transitions.js";
2
2
  import * as edit from "alpha2/edit";
3
- import { drawnEffectResources, effectStack, findComposition, freeCompositionId, freeNodeId, groupNodes, ungroupNode, inputKeys, correspondingCompositions, ownComposition, withEffectStack, withoutUndrawn, withInput, withoutNodes, shownSources, } from "./compositions.js";
3
+ import { drawnEffectResources, effectStack, findComposition, freeCompositionId, freeNodeId, groupNodes, ungroupNode, acceptsInput, correspondingCompositions, ownComposition, withEffectStack, withoutUndrawn, withInput, withoutNodes, shownSources, } from "./compositions.js";
4
4
  import { rememberValid, withValidated } from "./validated.js";
5
5
  import { EditorError, validateDocument, validateDocumentShape, assertProjection, indexDocument, transitionInstanceId, withInstanceIds, } from "./document.js";
6
6
  const NO_NAMES = Object.freeze({});
@@ -687,7 +687,7 @@ function reduce(document, command) {
687
687
  : n),
688
688
  };
689
689
  }
690
- if (!inputKeys(op).includes(key))
690
+ if (!acceptsInput(op, key))
691
691
  fail(`No input ${String(key)} on node ${command.to}`, command.to);
692
692
  const connected = withInput(op, key, command.type === "graph.connect" ? command.from : null);
693
693
  return {
@@ -97,9 +97,10 @@ export declare function shownSources(project: Project, tracks?: Project["timelin
97
97
  */
98
98
  export declare function drawnEffectResources(project: Project, tracks?: Project["timeline"]["tracks"]): Set<string>;
99
99
  /**
100
- * A node input as graph commands name it: `input`, `from`, `to`, `matte`, or a merge layer's index.
100
+ * A node input as graph commands name it: `input`, `from`, `to`, `matte`, an effect's named input
101
+ * as `inputs.<name>`, or a merge layer's or group port's index.
101
102
  */
102
- export type InputKey = "input" | "from" | "to" | "matte" | number;
103
+ export type InputKey = "input" | "from" | "to" | "matte" | `inputs.${string}` | number;
103
104
  /** The input keys of a node's operation, in order. */
104
105
  export declare function inputKeys(op: CompositionNode["op"]): InputKey[];
105
106
  /**
@@ -137,10 +138,21 @@ export declare function compositionReads(compositions: readonly Composition[]):
137
138
  /** The node an input reads, or `undefined` when it is unconnected or absent. */
138
139
  export declare function inputOf(op: CompositionNode["op"], key: InputKey): string | undefined;
139
140
  /**
140
- * `op` with input `key` reading `node` (`null` disconnects it). Throws when `op` has no input
141
- * `key`.
141
+ * Whether `op` has input `key`, or can take it: an effect node takes any well-named
142
+ * `inputs.<name>`, whether or not its definition declares it.
143
+ */
144
+ export declare function acceptsInput(op: CompositionNode["op"], key: InputKey): boolean;
145
+ /**
146
+ * `op` with input `key` reading `node` (`null` disconnects it, keeping an effect's named input).
147
+ * An effect's named input is added when it has none of the name. Throws when `op` cannot take
148
+ * input `key`.
142
149
  */
143
150
  export declare function withInput(op: CompositionNode["op"], key: InputKey, node: string | null): CompositionNode["op"];
151
+ /**
152
+ * `op` without its effect input `name`; an effect left with none has no `inputs`, as the model
153
+ * writes it. Any other operation is returned as it is.
154
+ */
155
+ export declare function withoutEffectInput(op: CompositionNode["op"], name: string): CompositionNode["op"];
144
156
  /**
145
157
  * How a composition is drawn, which decides what its clip nodes and group inputs read, as the
146
158
  * engine plans it.
@@ -44,7 +44,10 @@ export function effectStack(project, clip) {
44
44
  if (node.op.type === "clip") {
45
45
  return stack.length + 1 === nodes.size ? stack.reverse() : undefined;
46
46
  }
47
- if (node.op.type !== "effect" || node.op.input == null)
47
+ // An effect reading named inputs reads another branch, which a stack cannot show.
48
+ if (node.op.type !== "effect" ||
49
+ node.op.input == null ||
50
+ Object.keys(node.op.inputs ?? {}).length > 0)
48
51
  return undefined;
49
52
  stack.push({ id: node.id, effect: node.op.effect, bypass: !!node.bypass });
50
53
  at = node.op.input;
@@ -302,6 +305,10 @@ function divide(value, num, den, rounding) {
302
305
  function inputsOf(op) {
303
306
  switch (op.type) {
304
307
  case "effect":
308
+ return [
309
+ op.input,
310
+ ...effectInputNames(op).map((name) => op.inputs[name]),
311
+ ].filter((id) => id != null);
305
312
  case "transform":
306
313
  case "shape_mask":
307
314
  return op.input != null ? [op.input] : [];
@@ -393,10 +400,26 @@ function drawn(project, tracks) {
393
400
  }
394
401
  return { sources: used, resources };
395
402
  }
403
+ /** A name an effect node may give a named input, as the model requires. */
404
+ const EFFECT_INPUT_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
405
+ /** The name of the effect input `key` names, or `undefined` for any other key. */
406
+ function effectInputName(key) {
407
+ return typeof key === "string" && key.startsWith("inputs.")
408
+ ? key.slice("inputs.".length)
409
+ : undefined;
410
+ }
411
+ /** An effect node's named inputs, in name order, as the model keeps them. */
412
+ function effectInputNames(op) {
413
+ return Object.keys(op.inputs ?? {}).sort();
414
+ }
396
415
  /** The input keys of a node's operation, in order. */
397
416
  export function inputKeys(op) {
398
417
  switch (op.type) {
399
418
  case "effect":
419
+ return [
420
+ "input",
421
+ ...effectInputNames(op).map((name) => `inputs.${name}`),
422
+ ];
400
423
  case "transform":
401
424
  case "shape_mask":
402
425
  return ["input"];
@@ -508,16 +531,37 @@ export function inputOf(op, key) {
508
531
  : op.type === "group"
509
532
  ? (op.inputs?.[key] ?? undefined)
510
533
  : undefined;
534
+ const name = effectInputName(key);
535
+ if (name !== undefined)
536
+ return op.type === "effect"
537
+ ? Object.hasOwn(op.inputs ?? {}, name)
538
+ ? (op.inputs[name] ?? undefined)
539
+ : undefined
540
+ : undefined;
511
541
  const value = op[key];
512
542
  return typeof value === "string" ? value : undefined;
513
543
  }
514
544
  /**
515
- * `op` with input `key` reading `node` (`null` disconnects it). Throws when `op` has no input
516
- * `key`.
545
+ * Whether `op` has input `key`, or can take it: an effect node takes any well-named
546
+ * `inputs.<name>`, whether or not its definition declares it.
547
+ */
548
+ export function acceptsInput(op, key) {
549
+ const name = effectInputName(key);
550
+ if (name !== undefined)
551
+ return op.type === "effect" && EFFECT_INPUT_NAME.test(name);
552
+ return inputKeys(op).includes(key);
553
+ }
554
+ /**
555
+ * `op` with input `key` reading `node` (`null` disconnects it, keeping an effect's named input).
556
+ * An effect's named input is added when it has none of the name. Throws when `op` cannot take
557
+ * input `key`.
517
558
  */
518
559
  export function withInput(op, key, node) {
519
- if (!inputKeys(op).includes(key))
560
+ if (!acceptsInput(op, key))
520
561
  throw new Error(`A ${op.type} node has no input ${String(key)}`);
562
+ const name = effectInputName(key);
563
+ if (name !== undefined && op.type === "effect")
564
+ return { ...op, inputs: { ...(op.inputs ?? {}), [name]: node } };
521
565
  if (typeof key === "number" && op.type === "merge")
522
566
  return {
523
567
  ...op,
@@ -530,6 +574,17 @@ export function withInput(op, key, node) {
530
574
  };
531
575
  return { ...op, [key]: node };
532
576
  }
577
+ /**
578
+ * `op` without its effect input `name`; an effect left with none has no `inputs`, as the model
579
+ * writes it. Any other operation is returned as it is.
580
+ */
581
+ export function withoutEffectInput(op, name) {
582
+ if (op.type !== "effect" || !Object.hasOwn(op.inputs ?? {}, name))
583
+ return op;
584
+ const { [name]: _removed, ...rest } = op.inputs;
585
+ const { inputs: _inputs, ...without } = op;
586
+ return Object.keys(rest).length > 0 ? { ...without, inputs: rest } : without;
587
+ }
533
588
  /**
534
589
  * What stops `composition`'s output from rendering when it is drawn as `use`: no output, an
535
590
  * unconnected input a node the output reaches uses (only the pass-through input of a bypassed node,
@@ -16,22 +16,26 @@ const EDITOR_FAILURE_CODES = Object.freeze({
16
16
  conform_pending: "UNKNOWN",
17
17
  disposed: "UNKNOWN",
18
18
  duplicate_resource: "INVALID_INPUT",
19
+ effect_conflict: "INVALID_INPUT",
19
20
  empty_export: "INVALID_INPUT",
20
21
  export_busy: "UNKNOWN",
21
22
  invalid_asset: "INVALID_INPUT",
22
23
  invalid_captions: "INVALID_INPUT",
23
24
  invalid_command: "INVALID_INPUT",
24
25
  invalid_document: "INVALID_INPUT",
26
+ invalid_effect: "INVALID_INPUT",
25
27
  invalid_effect_resource: "INVALID_INPUT",
26
28
  invalid_font: "INVALID_INPUT",
27
29
  invalid_frame_rate: "INVALID_INPUT",
28
30
  invalid_metadata: "INVALID_INPUT",
29
31
  invalid_policy: "INVALID_INPUT",
32
+ invalid_preview_scale: "INVALID_INPUT",
30
33
  invalid_project: "INVALID_INPUT",
31
34
  invalid_projection: "INVALID_INPUT",
32
35
  invalid_rate: "INVALID_INPUT",
33
36
  invalid_time: "INVALID_INPUT",
34
37
  invalid_transition: "INVALID_INPUT",
38
+ invalid_video_decode: "INVALID_INPUT",
35
39
  locked: "INVALID_INPUT",
36
40
  missing_asset: "INVALID_INPUT",
37
41
  preview_worker_failed: "UNKNOWN",
@@ -24,7 +24,8 @@ export interface NativeAsset {
24
24
  }
25
25
  /**
26
26
  * Export settings for a native job: the browser export's options, plus the MPEG-4 Part 2 codec the
27
- * host can encode.
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.
28
29
  */
29
30
  export interface NativeExportOptions extends Omit<BrowserExportOptions, "videoCodec"> {
30
31
  readonly videoCodec?: BrowserExportOptions["videoCodec"] | "mpeg4-part2";
@@ -96,8 +96,10 @@ export type ExportArtifact = ({
96
96
  readonly bytes?: number;
97
97
  /**
98
98
  * What the exporter reported about the run: timings, `performance` (with `memory` and `output`),
99
- * rates. A browser export adds `decodeFallbacks`: the sources whose frames were read by element
100
- * seeks rather than decoded, with why, how many frames, and whether for good.
99
+ * rates. A browser export adds `videoDecode`, the decode mode it ran with, and `decodeFallbacks`:
100
+ * per source, frames read by element seeks rather than decoded (`kind: "element-seek"`), with
101
+ * why, how many frames, and whether for good, and sources `videoDecode: "software"` could not
102
+ * decode in software (`kind: "software-unavailable"`).
101
103
  */
102
104
  readonly report?: Readonly<Record<string, unknown>>;
103
105
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpha2-sh/editor",
3
- "version": "0.2.2",
3
+ "version": "0.3.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.2",
63
+ "alpha2": "0.3.1",
64
64
  "react": "^19.3.0"
65
65
  },
66
66
  "devDependencies": {
67
- "alpha2": "0.2.2",
67
+ "alpha2": "0.3.1",
68
68
  "react": "19.3.0",
69
69
  "react-dom": "19.3.0",
70
70
  "@types/react": "19.3.0",