@motionscript/browser 0.0.0-stage → 0.1.0-alpha.10

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 (133) hide show
  1. package/CHANGELOG.md +192 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +49 -0
  4. package/README.md +140 -3
  5. package/dist/asset-bytes.d.ts +59 -0
  6. package/dist/asset-bytes.d.ts.map +1 -0
  7. package/dist/asset-bytes.js +78 -0
  8. package/dist/asset-bytes.js.map +1 -0
  9. package/dist/audio/bus-graph.d.ts +52 -0
  10. package/dist/audio/bus-graph.d.ts.map +1 -0
  11. package/dist/audio/bus-graph.js +108 -0
  12. package/dist/audio/bus-graph.js.map +1 -0
  13. package/dist/audio/effect-graph.d.ts +62 -0
  14. package/dist/audio/effect-graph.d.ts.map +1 -0
  15. package/dist/audio/effect-graph.js +234 -0
  16. package/dist/audio/effect-graph.js.map +1 -0
  17. package/dist/audio/index.d.ts +5 -0
  18. package/dist/audio/index.d.ts.map +1 -0
  19. package/dist/audio/index.js +11 -0
  20. package/dist/audio/index.js.map +1 -0
  21. package/dist/audio/loop-region.d.ts +31 -0
  22. package/dist/audio/loop-region.d.ts.map +1 -0
  23. package/dist/audio/loop-region.js +43 -0
  24. package/dist/audio/loop-region.js.map +1 -0
  25. package/dist/audio/mixer.d.ts +59 -0
  26. package/dist/audio/mixer.d.ts.map +1 -0
  27. package/dist/audio/mixer.js +192 -0
  28. package/dist/audio/mixer.js.map +1 -0
  29. package/dist/audio/player.d.ts +55 -0
  30. package/dist/audio/player.d.ts.map +1 -0
  31. package/dist/audio/player.js +217 -0
  32. package/dist/audio/player.js.map +1 -0
  33. package/dist/browser/THIRD_PARTY_LICENSES.txt +784 -0
  34. package/dist/browser/audio.js +2 -0
  35. package/dist/browser/audio.js.map +7 -0
  36. package/dist/browser/chunks/chunk-F3AZKPHU.js +2 -0
  37. package/dist/browser/chunks/chunk-F3AZKPHU.js.map +7 -0
  38. package/dist/browser/chunks/chunk-KLXMRKTL.js +2 -0
  39. package/dist/browser/chunks/chunk-KLXMRKTL.js.map +7 -0
  40. package/dist/browser/chunks/chunk-L5UFQACH.js +163 -0
  41. package/dist/browser/chunks/chunk-L5UFQACH.js.map +7 -0
  42. package/dist/browser/chunks/mediabunny-mp3-encoder-ZCIHVVTJ.js +14 -0
  43. package/dist/browser/chunks/mediabunny-mp3-encoder-ZCIHVVTJ.js.map +7 -0
  44. package/dist/browser/esbuild.wasm +0 -0
  45. package/dist/browser/index.js +734 -0
  46. package/dist/browser/index.js.map +7 -0
  47. package/dist/browser/manifest.json +32 -0
  48. package/dist/browser/ms_renderer_bg.wasm +0 -0
  49. package/dist/concat.d.ts +121 -0
  50. package/dist/concat.d.ts.map +1 -0
  51. package/dist/concat.js +219 -0
  52. package/dist/concat.js.map +1 -0
  53. package/dist/deliver.d.ts +10 -0
  54. package/dist/deliver.d.ts.map +1 -0
  55. package/dist/deliver.js +22 -0
  56. package/dist/deliver.js.map +1 -0
  57. package/dist/dynamic-nodes.d.ts +9 -0
  58. package/dist/dynamic-nodes.d.ts.map +1 -0
  59. package/dist/dynamic-nodes.js +53 -0
  60. package/dist/dynamic-nodes.js.map +1 -0
  61. package/dist/engine.d.ts +87 -0
  62. package/dist/engine.d.ts.map +1 -0
  63. package/dist/engine.js +193 -0
  64. package/dist/engine.js.map +1 -0
  65. package/dist/export-audio.d.ts +36 -0
  66. package/dist/export-audio.d.ts.map +1 -0
  67. package/dist/export-audio.js +56 -0
  68. package/dist/export-audio.js.map +1 -0
  69. package/dist/exporter.d.ts +282 -0
  70. package/dist/exporter.d.ts.map +1 -0
  71. package/dist/exporter.js +308 -0
  72. package/dist/exporter.js.map +1 -0
  73. package/dist/formats.d.ts +36 -0
  74. package/dist/formats.d.ts.map +1 -0
  75. package/dist/formats.js +83 -0
  76. package/dist/formats.js.map +1 -0
  77. package/dist/frame-loop.d.ts +190 -0
  78. package/dist/frame-loop.d.ts.map +1 -0
  79. package/dist/frame-loop.js +304 -0
  80. package/dist/frame-loop.js.map +1 -0
  81. package/dist/index.d.ts +24 -0
  82. package/dist/index.d.ts.map +1 -0
  83. package/dist/index.js +43 -0
  84. package/dist/index.js.map +1 -0
  85. package/dist/mix-timeline-audio.d.ts +42 -0
  86. package/dist/mix-timeline-audio.d.ts.map +1 -0
  87. package/dist/mix-timeline-audio.js +60 -0
  88. package/dist/mix-timeline-audio.js.map +1 -0
  89. package/dist/parallel/export-parallel.d.ts +32 -0
  90. package/dist/parallel/export-parallel.d.ts.map +1 -0
  91. package/dist/parallel/export-parallel.js +114 -0
  92. package/dist/parallel/export-parallel.js.map +1 -0
  93. package/dist/parallel/governor.d.ts +57 -0
  94. package/dist/parallel/governor.d.ts.map +1 -0
  95. package/dist/parallel/governor.js +79 -0
  96. package/dist/parallel/governor.js.map +1 -0
  97. package/dist/parallel/lane.d.ts +45 -0
  98. package/dist/parallel/lane.d.ts.map +1 -0
  99. package/dist/parallel/lane.js +2 -0
  100. package/dist/parallel/lane.js.map +1 -0
  101. package/dist/parallel/lanes.d.ts +20 -0
  102. package/dist/parallel/lanes.d.ts.map +1 -0
  103. package/dist/parallel/lanes.js +152 -0
  104. package/dist/parallel/lanes.js.map +1 -0
  105. package/dist/parallel/plan.d.ts +23 -0
  106. package/dist/parallel/plan.d.ts.map +1 -0
  107. package/dist/parallel/plan.js +30 -0
  108. package/dist/parallel/plan.js.map +1 -0
  109. package/dist/parallel/run-lanes.d.ts +38 -0
  110. package/dist/parallel/run-lanes.d.ts.map +1 -0
  111. package/dist/parallel/run-lanes.js +164 -0
  112. package/dist/parallel/run-lanes.js.map +1 -0
  113. package/dist/parallel/session.d.ts +9 -0
  114. package/dist/parallel/session.d.ts.map +1 -0
  115. package/dist/parallel/session.js +79 -0
  116. package/dist/parallel/session.js.map +1 -0
  117. package/dist/renderer.d.ts +22 -0
  118. package/dist/renderer.d.ts.map +1 -0
  119. package/dist/renderer.js +23 -0
  120. package/dist/renderer.js.map +1 -0
  121. package/dist/screenshot.d.ts +45 -0
  122. package/dist/screenshot.d.ts.map +1 -0
  123. package/dist/screenshot.js +31 -0
  124. package/dist/screenshot.js.map +1 -0
  125. package/dist/still.d.ts +159 -0
  126. package/dist/still.d.ts.map +1 -0
  127. package/dist/still.js +222 -0
  128. package/dist/still.js.map +1 -0
  129. package/dist/ticker.d.ts +74 -0
  130. package/dist/ticker.d.ts.map +1 -0
  131. package/dist/ticker.js +215 -0
  132. package/dist/ticker.js.map +1 -0
  133. package/package.json +75 -3
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@motionscript/browser",
3
+ "version": "0.1.0-alpha.9",
4
+ "exports": {
5
+ ".": "dist/browser/index.js",
6
+ "./audio": "dist/browser/audio.js"
7
+ },
8
+ "peers": [
9
+ "@motionscript/core"
10
+ ],
11
+ "assets": {
12
+ "esbuild.wasm": "dist/browser/esbuild.wasm",
13
+ "ms_renderer_bg.wasm": "dist/browser/ms_renderer_bg.wasm"
14
+ },
15
+ "thirdParty": [
16
+ {
17
+ "name": "@mediabunny/mp3-encoder",
18
+ "version": "1.62.1",
19
+ "license": "MPL-2.0"
20
+ },
21
+ {
22
+ "name": "esbuild-wasm",
23
+ "version": "0.28.2",
24
+ "license": "MIT"
25
+ },
26
+ {
27
+ "name": "mediabunny",
28
+ "version": "1.49.0",
29
+ "license": "MPL-2.0"
30
+ }
31
+ ]
32
+ }
Binary file
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Join encoded MP4 or WebM segments end to end, without re-encoding.
3
+ *
4
+ * The point of this is what it *doesn't* do: no decode, no encode, no pixels.
5
+ * Each segment is demuxed to its encoded packets, the packets are re-stamped onto
6
+ * one continuous timeline, and a single muxer writes them into one container. The
7
+ * bytes of every frame survive untouched, so the result is bit-identical to the
8
+ * segments and the whole thing runs at I/O speed rather than encode speed.
9
+ *
10
+ * It exists so an export can be **split across workers**. Rendering a timeline is
11
+ * embarrassingly parallel per scene — each scene's generator is independent — but
12
+ * the output has to be one file, and re-encoding the parts to join them would give
13
+ * back everything the parallelism won (and lose a generation of quality). Joining
14
+ * at the packet level is what makes splitting worth doing.
15
+ *
16
+ * ## What the caller has to guarantee
17
+ *
18
+ * **Every segment must be encoded with an identical configuration** — same
19
+ * container, codec, resolution and bitrate settings. A container carries exactly one decoder
20
+ * configuration for a track, so a segment whose parameter sets differ from the
21
+ * first would be described by a configuration that isn't its own, and decode as
22
+ * garbage from that point on. That is not a theoretical concern: hardware encoders
23
+ * are free to pick different parameter sets for the same nominal settings. This is
24
+ * checked rather than assumed — see {@link ConcatMismatchError} — because the
25
+ * failure is silent corruption rather than an exception.
26
+ *
27
+ * **Every segment must begin with a key frame.** Otherwise its first packets refer
28
+ * back to frames that lived in the previous segment's GOP and no longer precede
29
+ * them. Encoders start with a key frame by default; a caller choosing an explicit
30
+ * `keyFrameInterval` needs it to divide the segment length.
31
+ *
32
+ * Audio is *muxed* here but never *joined*: the segments' own audio is ignored
33
+ * entirely, and a single already-mixed buffer is encoded once across the whole
34
+ * result (see {@link ConcatOptions.audio}). Concatenating separately-encoded AAC
35
+ * would put the encoder's priming delay at every join — a click at each boundary
36
+ * and a track that drifts further out of sync with every one — so the timeline's
37
+ * audio is mixed in one pass by whoever owns the timeline, and arrives here as
38
+ * one buffer.
39
+ */
40
+ /** Thrown when segments can't be joined losslessly. Carries which segment disagreed. */
41
+ export declare class ConcatMismatchError extends Error {
42
+ /** Index of the offending segment in the input array. */
43
+ readonly segment: number;
44
+ constructor(
45
+ /** Index of the offending segment in the input array. */
46
+ segment: number, message: string);
47
+ }
48
+ export interface ConcatOptions {
49
+ /**
50
+ * One continuous audio track for the whole joined timeline.
51
+ *
52
+ * Mixed once by the caller (see `mixTimelineAudio`) rather than per segment,
53
+ * and that is not a convenience: separately-encoded AAC carries an encoder
54
+ * priming delay at the head of each piece, so joining them puts a click at
55
+ * every scene boundary and drifts the track further out of sync with each
56
+ * one. One buffer in, one encode, no seams.
57
+ */
58
+ audio?: AudioBuffer | null;
59
+ /** Bitrate for that track: AAC in an MP4, Opus in a WebM. Defaults to 192 kbps. */
60
+ audioBitrate?: number;
61
+ /**
62
+ * Write the result out as it is muxed instead of returning it.
63
+ *
64
+ * With this the joined file never exists in memory as one buffer, which is
65
+ * the difference between an export the process can hold and one it can't:
66
+ * a 4× 60fps render is hundreds of megabytes, and the default path costs
67
+ * roughly twice that at the tail once the `Blob` copy is counted.
68
+ *
69
+ * **Chunks carry a byte `position` and do not arrive in file order** — a
70
+ * muxer seeks back to patch atom sizes. A sink that appends will produce a
71
+ * file of exactly the right length whose size fields belong to a different
72
+ * one: unplayable, and indistinguishable from success until it is opened.
73
+ * Honour `position`.
74
+ *
75
+ * `concatVideoSegments` resolves to an empty array when this is used; the
76
+ * bytes went to the sink.
77
+ */
78
+ stream?: WritableStream<{
79
+ type: "write";
80
+ data: Uint8Array;
81
+ position: number;
82
+ }>;
83
+ }
84
+ /** Joins segments one at a time, in timeline order, as each becomes available. */
85
+ export interface SegmentJoiner {
86
+ /**
87
+ * Mux the next segment after the ones already appended. Appends must not
88
+ * overlap: await each before starting the next.
89
+ *
90
+ * @throws {ConcatMismatchError} as {@link concatVideoSegments} does.
91
+ */
92
+ append(segment: Uint8Array): Promise<void>;
93
+ /** Finish the container. The bytes, or an empty array when they went to `stream`. */
94
+ finish(): Promise<Uint8Array>;
95
+ /** Abandon the join; nothing more is written. */
96
+ cancel(): Promise<void>;
97
+ }
98
+ /**
99
+ * {@link concatVideoSegments} one segment at a time, so a split export can write
100
+ * each piece the moment it and every piece before it exist, instead of holding
101
+ * every segment until the last one lands.
102
+ *
103
+ * The audio, when given, is encoded as soon as the first segment fixes the
104
+ * container, ahead of the video: the muxer holds the (small) audio packets and
105
+ * interleaves them as the video catches up.
106
+ */
107
+ export declare function createSegmentJoiner(options?: ConcatOptions): SegmentJoiner;
108
+ /**
109
+ * Concatenate `segments` (each a complete MP4, or each a complete WebM) into one
110
+ * file of the same container.
111
+ *
112
+ * Segments are joined in array order. Returns the muxed bytes.
113
+ *
114
+ * @throws {ConcatMismatchError} if a segment carries no video track, is in another
115
+ * container than the first, or has a decoder configuration that differs
116
+ * from the first segment's. Callers that can
117
+ * fall back to a single-threaded export should catch this and do so — the
118
+ * alternative is shipping a file that decodes into garbage halfway through.
119
+ */
120
+ export declare function concatVideoSegments(segments: Uint8Array[], options?: ConcatOptions): Promise<Uint8Array>;
121
+ //# sourceMappingURL=concat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concat.d.ts","sourceRoot":"","sources":["../src/concat.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,wFAAwF;AACxF,qBAAa,mBAAoB,SAAQ,KAAK;IAEtC,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM;;IADxB,yDAAyD;IAChD,OAAO,EAAE,MAAM,EACxB,OAAO,EAAE,MAAM;CAKtB;AA2CD,MAAM,WAAW,aAAa;IAC1B;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3B,mFAAmF;IACnF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClF;AAED,kFAAkF;AAClF,MAAM,WAAW,aAAa;IAC1B;;;;;OAKG;IACH,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,qFAAqF;IACrF,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAC9B,iDAAiD;IACjD,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,aAAkB,GAAG,aAAa,CAoE9E;AAuBD;;;;;;;;;;;GAWG;AACH,wBAAsB,mBAAmB,CACrC,QAAQ,EAAE,UAAU,EAAE,EACtB,OAAO,GAAE,aAAkB,GAC5B,OAAO,CAAC,UAAU,CAAC,CAcrB"}
package/dist/concat.js ADDED
@@ -0,0 +1,219 @@
1
+ import { BufferSource, BufferTarget, EncodedPacketSink, EncodedVideoPacketSource, Input, MP4, Output, StreamTarget, WEBM, } from "mediabunny";
2
+ import { audioTrackSource, formatSpec } from "./formats";
3
+ /**
4
+ * Join encoded MP4 or WebM segments end to end, without re-encoding.
5
+ *
6
+ * The point of this is what it *doesn't* do: no decode, no encode, no pixels.
7
+ * Each segment is demuxed to its encoded packets, the packets are re-stamped onto
8
+ * one continuous timeline, and a single muxer writes them into one container. The
9
+ * bytes of every frame survive untouched, so the result is bit-identical to the
10
+ * segments and the whole thing runs at I/O speed rather than encode speed.
11
+ *
12
+ * It exists so an export can be **split across workers**. Rendering a timeline is
13
+ * embarrassingly parallel per scene — each scene's generator is independent — but
14
+ * the output has to be one file, and re-encoding the parts to join them would give
15
+ * back everything the parallelism won (and lose a generation of quality). Joining
16
+ * at the packet level is what makes splitting worth doing.
17
+ *
18
+ * ## What the caller has to guarantee
19
+ *
20
+ * **Every segment must be encoded with an identical configuration** — same
21
+ * container, codec, resolution and bitrate settings. A container carries exactly one decoder
22
+ * configuration for a track, so a segment whose parameter sets differ from the
23
+ * first would be described by a configuration that isn't its own, and decode as
24
+ * garbage from that point on. That is not a theoretical concern: hardware encoders
25
+ * are free to pick different parameter sets for the same nominal settings. This is
26
+ * checked rather than assumed — see {@link ConcatMismatchError} — because the
27
+ * failure is silent corruption rather than an exception.
28
+ *
29
+ * **Every segment must begin with a key frame.** Otherwise its first packets refer
30
+ * back to frames that lived in the previous segment's GOP and no longer precede
31
+ * them. Encoders start with a key frame by default; a caller choosing an explicit
32
+ * `keyFrameInterval` needs it to divide the segment length.
33
+ *
34
+ * Audio is *muxed* here but never *joined*: the segments' own audio is ignored
35
+ * entirely, and a single already-mixed buffer is encoded once across the whole
36
+ * result (see {@link ConcatOptions.audio}). Concatenating separately-encoded AAC
37
+ * would put the encoder's priming delay at every join — a click at each boundary
38
+ * and a track that drifts further out of sync with every one — so the timeline's
39
+ * audio is mixed in one pass by whoever owns the timeline, and arrives here as
40
+ * one buffer.
41
+ */
42
+ /** Thrown when segments can't be joined losslessly. Carries which segment disagreed. */
43
+ export class ConcatMismatchError extends Error {
44
+ segment;
45
+ constructor(
46
+ /** Index of the offending segment in the input array. */
47
+ segment, message) {
48
+ super(message);
49
+ this.segment = segment;
50
+ this.name = "ConcatMismatchError";
51
+ }
52
+ }
53
+ /**
54
+ * Two decoder configurations describe the same bitstream.
55
+ *
56
+ * `description` holds the codec's parameter sets (the `avcC` box for H.264) and is
57
+ * the field that actually decides decodability — a differing one is exactly the
58
+ * silent-corruption case. Compared bytewise; the rest are compared by value.
59
+ */
60
+ function sameDecoderConfig(a, b) {
61
+ if (a.codec !== b.codec)
62
+ return false;
63
+ if (a.codedWidth !== b.codedWidth)
64
+ return false;
65
+ if (a.codedHeight !== b.codedHeight)
66
+ return false;
67
+ const da = toBytes(a.description);
68
+ const db = toBytes(b.description);
69
+ if (da === null || db === null)
70
+ return da === db;
71
+ if (da.length !== db.length)
72
+ return false;
73
+ for (let i = 0; i < da.length; i++) {
74
+ if (da[i] !== db[i])
75
+ return false;
76
+ }
77
+ return true;
78
+ }
79
+ function toBytes(description) {
80
+ if (!description)
81
+ return null;
82
+ // `description` is a BufferSource: an ArrayBuffer, a SharedArrayBuffer, or any
83
+ // view over one. Views carry an offset into a larger buffer, so they must be
84
+ // narrowed rather than wrapped whole.
85
+ if (ArrayBuffer.isView(description)) {
86
+ return new Uint8Array(description.buffer, description.byteOffset, description.byteLength);
87
+ }
88
+ return new Uint8Array(description);
89
+ }
90
+ /**
91
+ * {@link concatVideoSegments} one segment at a time, so a split export can write
92
+ * each piece the moment it and every piece before it exist, instead of holding
93
+ * every segment until the last one lands.
94
+ *
95
+ * The audio, when given, is encoded as soon as the first segment fixes the
96
+ * container, ahead of the video: the muxer holds the (small) audio packets and
97
+ * interleaves them as the video catches up.
98
+ */
99
+ export function createSegmentJoiner(options = {}) {
100
+ let first = null;
101
+ let output = null;
102
+ let source = null;
103
+ let audioSource = null;
104
+ let target = null;
105
+ let index = 0;
106
+ let offset = 0;
107
+ const start = async (segment) => {
108
+ target = options.stream
109
+ ? new StreamTarget(options.stream)
110
+ : new BufferTarget();
111
+ output = new Output({ format: formatSpec(segment.format).container(), target });
112
+ // `codec` comes off the track rather than the decoder config: the latter's
113
+ // `codec` is the full codec *string* (`avc1.64001f`), while the source wants
114
+ // the family.
115
+ source = new EncodedVideoPacketSource(segment.track.codec);
116
+ output.addVideoTrack(source);
117
+ // Declared before `start()`: a muxer fixes its track list up front.
118
+ audioSource = options.audio ? audioTrackSource(segment.format, options.audioBitrate) : null;
119
+ if (audioSource)
120
+ output.addAudioTrack(audioSource);
121
+ await output.start();
122
+ if (audioSource && options.audio)
123
+ await audioSource.add(options.audio);
124
+ };
125
+ return {
126
+ async append(bytes) {
127
+ const i = index++;
128
+ const input = new Input({ source: new BufferSource(bytes), formats: [MP4, WEBM] });
129
+ try {
130
+ const segment = await openSegment(input, i, first);
131
+ if (!first) {
132
+ first = segment;
133
+ await start(segment);
134
+ }
135
+ // The decoder config is handed over with each segment's first packet.
136
+ // Only the first can take effect (a container holds one per track), but
137
+ // every one has been checked equal to it.
138
+ let leading = true;
139
+ for await (const packet of new EncodedPacketSink(segment.track).packets()) {
140
+ await source.add(packet.clone({ timestamp: packet.timestamp + offset }), leading ? { decoderConfig: segment.config } : undefined);
141
+ leading = false;
142
+ }
143
+ // The segment's own duration rather than its last packet's end: summing
144
+ // packet durations accumulates rounding into a drift across many segments.
145
+ offset += segment.duration;
146
+ }
147
+ finally {
148
+ input.dispose();
149
+ }
150
+ },
151
+ async finish() {
152
+ if (!output)
153
+ throw new Error("concatVideoSegments: no segments");
154
+ source.close();
155
+ audioSource?.close();
156
+ await output.finalize();
157
+ if (options.stream)
158
+ return new Uint8Array(0);
159
+ const buffer = target.buffer;
160
+ if (!buffer)
161
+ throw new Error("concatVideoSegments produced no data");
162
+ return new Uint8Array(buffer);
163
+ },
164
+ async cancel() {
165
+ if (output && output.state !== "finalized" && output.state !== "canceled")
166
+ await output.cancel();
167
+ },
168
+ };
169
+ }
170
+ /** Demux one segment and check it can follow `first`. */
171
+ async function openSegment(input, i, first) {
172
+ const format = (await input.getFormat()) === WEBM ? "webm" : "mp4";
173
+ if (first && format !== first.format) {
174
+ throw new ConcatMismatchError(i, `Segment ${i} is ${format} and segment 0 is ${first.format}.`);
175
+ }
176
+ const track = await input.getPrimaryVideoTrack();
177
+ if (!track)
178
+ throw new ConcatMismatchError(i, `Segment ${i} has no video track.`);
179
+ const config = await track.getDecoderConfig();
180
+ if (!config)
181
+ throw new ConcatMismatchError(i, `Segment ${i} has no decoder configuration.`);
182
+ if (first && !sameDecoderConfig(first.config, config)) {
183
+ throw new ConcatMismatchError(i, `Segment ${i} was encoded differently from segment 0 (${first.config.codec} `
184
+ + `${first.config.codedWidth}x${first.config.codedHeight} vs ${config.codec} `
185
+ + `${config.codedWidth}x${config.codedHeight}); joining them would decode as garbage.`);
186
+ }
187
+ return { format, track, config, duration: await track.computeDuration() };
188
+ }
189
+ /**
190
+ * Concatenate `segments` (each a complete MP4, or each a complete WebM) into one
191
+ * file of the same container.
192
+ *
193
+ * Segments are joined in array order. Returns the muxed bytes.
194
+ *
195
+ * @throws {ConcatMismatchError} if a segment carries no video track, is in another
196
+ * container than the first, or has a decoder configuration that differs
197
+ * from the first segment's. Callers that can
198
+ * fall back to a single-threaded export should catch this and do so — the
199
+ * alternative is shipping a file that decodes into garbage halfway through.
200
+ */
201
+ export async function concatVideoSegments(segments, options = {}) {
202
+ if (segments.length === 0)
203
+ throw new Error("concatVideoSegments: no segments");
204
+ // A lone segment is already the finished file — unless a track has to be added
205
+ // to it, or it has to go to a sink, either of which means muxing after all.
206
+ if (segments.length === 1 && !options.audio && !options.stream)
207
+ return segments[0];
208
+ const joiner = createSegmentJoiner(options);
209
+ try {
210
+ for (const segment of segments)
211
+ await joiner.append(segment);
212
+ return await joiner.finish();
213
+ }
214
+ catch (error) {
215
+ await joiner.cancel().catch(() => { });
216
+ throw error;
217
+ }
218
+ }
219
+ //# sourceMappingURL=concat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concat.js","sourceRoot":"","sources":["../src/concat.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,EACxB,KAAK,EACL,GAAG,EACH,MAAM,EACN,YAAY,EACZ,IAAI,GAGP,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAoB,MAAM,WAAW,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,wFAAwF;AACxF,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAG7B;IAFb;IACI,yDAAyD;IAChD,OAAe,EACxB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,YAAO,GAAP,OAAO,CAAQ;QAIxB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACtC,CAAC;CACJ;AAUD;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAC,CAAqB,EAAE,CAAqB;IACnE,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC;IAElD,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAClC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,WAAW,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MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC,eAAe,EAAE,EAAE,CAAC;AAC9E,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACrC,QAAsB,EACtB,UAAyB,EAAE;IAE3B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAC/E,+EAA+E;IAC/E,4EAA4E;IAC5E,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEnF,MAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,CAAC;QACD,KAAK,MAAM,OAAO,IAAI,QAAQ;YAAE,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7D,OAAO,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACtC,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC","sourcesContent":["import {\n BufferSource,\n BufferTarget,\n EncodedPacketSink,\n EncodedVideoPacketSource,\n Input,\n MP4,\n Output,\n StreamTarget,\n WEBM,\n type InputVideoTrack,\n type VideoCodec,\n} from \"mediabunny\";\n\nimport { audioTrackSource, formatSpec, type VideoFormat } from \"./formats\";\n\n/**\n * Join encoded MP4 or WebM segments end to end, without re-encoding.\n *\n * The point of this is what it *doesn't* do: no decode, no encode, no pixels.\n * Each segment is demuxed to its encoded packets, the packets are re-stamped onto\n * one continuous timeline, and a single muxer writes them into one container. The\n * bytes of every frame survive untouched, so the result is bit-identical to the\n * segments and the whole thing runs at I/O speed rather than encode speed.\n *\n * It exists so an export can be **split across workers**. Rendering a timeline is\n * embarrassingly parallel per scene — each scene's generator is independent — but\n * the output has to be one file, and re-encoding the parts to join them would give\n * back everything the parallelism won (and lose a generation of quality). Joining\n * at the packet level is what makes splitting worth doing.\n *\n * ## What the caller has to guarantee\n *\n * **Every segment must be encoded with an identical configuration** — same\n * container, codec, resolution and bitrate settings. A container carries exactly one decoder\n * configuration for a track, so a segment whose parameter sets differ from the\n * first would be described by a configuration that isn't its own, and decode as\n * garbage from that point on. That is not a theoretical concern: hardware encoders\n * are free to pick different parameter sets for the same nominal settings. This is\n * checked rather than assumed — see {@link ConcatMismatchError} — because the\n * failure is silent corruption rather than an exception.\n *\n * **Every segment must begin with a key frame.** Otherwise its first packets refer\n * back to frames that lived in the previous segment's GOP and no longer precede\n * them. Encoders start with a key frame by default; a caller choosing an explicit\n * `keyFrameInterval` needs it to divide the segment length.\n *\n * Audio is *muxed* here but never *joined*: the segments' own audio is ignored\n * entirely, and a single already-mixed buffer is encoded once across the whole\n * result (see {@link ConcatOptions.audio}). Concatenating separately-encoded AAC\n * would put the encoder's priming delay at every join — a click at each boundary\n * and a track that drifts further out of sync with every one — so the timeline's\n * audio is mixed in one pass by whoever owns the timeline, and arrives here as\n * one buffer.\n */\n\n/** Thrown when segments can't be joined losslessly. Carries which segment disagreed. */\nexport class ConcatMismatchError extends Error {\n constructor(\n /** Index of the offending segment in the input array. */\n readonly segment: number,\n message: string,\n ) {\n super(message);\n this.name = \"ConcatMismatchError\";\n }\n}\n\n/** One segment's demuxed video track, plus the config that describes it. */\ninterface Segment {\n format: VideoFormat;\n track: InputVideoTrack;\n config: VideoDecoderConfig;\n duration: number;\n}\n\n/**\n * Two decoder configurations describe the same bitstream.\n *\n * `description` holds the codec's parameter sets (the `avcC` box for H.264) and is\n * the field that actually decides decodability — a differing one is exactly the\n * silent-corruption case. Compared bytewise; the rest are compared by value.\n */\nfunction sameDecoderConfig(a: VideoDecoderConfig, b: VideoDecoderConfig): boolean {\n if (a.codec !== b.codec) return false;\n if (a.codedWidth !== b.codedWidth) return false;\n if (a.codedHeight !== b.codedHeight) return false;\n\n const da = toBytes(a.description);\n const db = toBytes(b.description);\n if (da === null || db === null) return da === db;\n if (da.length !== db.length) return false;\n for (let i = 0; i < da.length; i++) {\n if (da[i] !== db[i]) return false;\n }\n return true;\n}\n\nfunction toBytes(description: VideoDecoderConfig[\"description\"]): Uint8Array | null {\n if (!description) return null;\n // `description` is a BufferSource: an ArrayBuffer, a SharedArrayBuffer, or any\n // view over one. Views carry an offset into a larger buffer, so they must be\n // narrowed rather than wrapped whole.\n if (ArrayBuffer.isView(description)) {\n return new Uint8Array(description.buffer, description.byteOffset, description.byteLength);\n }\n return new Uint8Array(description);\n}\n\nexport interface ConcatOptions {\n /**\n * One continuous audio track for the whole joined timeline.\n *\n * Mixed once by the caller (see `mixTimelineAudio`) rather than per segment,\n * and that is not a convenience: separately-encoded AAC carries an encoder\n * priming delay at the head of each piece, so joining them puts a click at\n * every scene boundary and drifts the track further out of sync with each\n * one. One buffer in, one encode, no seams.\n */\n audio?: AudioBuffer | null;\n /** Bitrate for that track: AAC in an MP4, Opus in a WebM. Defaults to 192 kbps. */\n audioBitrate?: number;\n /**\n * Write the result out as it is muxed instead of returning it.\n *\n * With this the joined file never exists in memory as one buffer, which is\n * the difference between an export the process can hold and one it can't:\n * a 4× 60fps render is hundreds of megabytes, and the default path costs\n * roughly twice that at the tail once the `Blob` copy is counted.\n *\n * **Chunks carry a byte `position` and do not arrive in file order** — a\n * muxer seeks back to patch atom sizes. A sink that appends will produce a\n * file of exactly the right length whose size fields belong to a different\n * one: unplayable, and indistinguishable from success until it is opened.\n * Honour `position`.\n *\n * `concatVideoSegments` resolves to an empty array when this is used; the\n * bytes went to the sink.\n */\n stream?: WritableStream<{ type: \"write\"; data: Uint8Array; position: number }>;\n}\n\n/** Joins segments one at a time, in timeline order, as each becomes available. */\nexport interface SegmentJoiner {\n /**\n * Mux the next segment after the ones already appended. Appends must not\n * overlap: await each before starting the next.\n *\n * @throws {ConcatMismatchError} as {@link concatVideoSegments} does.\n */\n append(segment: Uint8Array): Promise<void>;\n /** Finish the container. The bytes, or an empty array when they went to `stream`. */\n finish(): Promise<Uint8Array>;\n /** Abandon the join; nothing more is written. */\n cancel(): Promise<void>;\n}\n\n/**\n * {@link concatVideoSegments} one segment at a time, so a split export can write\n * each piece the moment it and every piece before it exist, instead of holding\n * every segment until the last one lands.\n *\n * The audio, when given, is encoded as soon as the first segment fixes the\n * container, ahead of the video: the muxer holds the (small) audio packets and\n * interleaves them as the video catches up.\n */\nexport function createSegmentJoiner(options: ConcatOptions = {}): SegmentJoiner {\n let first: Segment | null = null;\n let output: Output | null = null;\n let source: EncodedVideoPacketSource | null = null;\n let audioSource: ReturnType<typeof audioTrackSource> | null = null;\n let target: StreamTarget | BufferTarget | null = null;\n let index = 0;\n let offset = 0;\n\n const start = async (segment: Segment) => {\n target = options.stream\n ? new StreamTarget(options.stream as ConstructorParameters<typeof StreamTarget>[0])\n : new BufferTarget();\n output = new Output({ format: formatSpec(segment.format).container(), target });\n // `codec` comes off the track rather than the decoder config: the latter's\n // `codec` is the full codec *string* (`avc1.64001f`), while the source wants\n // the family.\n source = new EncodedVideoPacketSource(segment.track.codec as VideoCodec);\n output.addVideoTrack(source);\n // Declared before `start()`: a muxer fixes its track list up front.\n audioSource = options.audio ? audioTrackSource(segment.format, options.audioBitrate) : null;\n if (audioSource) output.addAudioTrack(audioSource);\n await output.start();\n if (audioSource && options.audio) await audioSource.add(options.audio);\n };\n\n return {\n async append(bytes) {\n const i = index++;\n const input = new Input({ source: new BufferSource(bytes), formats: [MP4, WEBM] });\n try {\n const segment = await openSegment(input, i, first);\n if (!first) {\n first = segment;\n await start(segment);\n }\n // The decoder config is handed over with each segment's first packet.\n // Only the first can take effect (a container holds one per track), but\n // every one has been checked equal to it.\n let leading = true;\n for await (const packet of new EncodedPacketSink(segment.track).packets()) {\n await source!.add(\n packet.clone({ timestamp: packet.timestamp + offset }),\n leading ? { decoderConfig: segment.config } : undefined,\n );\n leading = false;\n }\n // The segment's own duration rather than its last packet's end: summing\n // packet durations accumulates rounding into a drift across many segments.\n offset += segment.duration;\n } finally {\n input.dispose();\n }\n },\n async finish() {\n if (!output) throw new Error(\"concatVideoSegments: no segments\");\n source!.close();\n audioSource?.close();\n await output.finalize();\n if (options.stream) return new Uint8Array(0);\n const buffer = (target as BufferTarget).buffer;\n if (!buffer) throw new Error(\"concatVideoSegments produced no data\");\n return new Uint8Array(buffer);\n },\n async cancel() {\n if (output && output.state !== \"finalized\" && output.state !== \"canceled\") await output.cancel();\n },\n };\n}\n\n/** Demux one segment and check it can follow `first`. */\nasync function openSegment(input: Input, i: number, first: Segment | null): Promise<Segment> {\n const format: VideoFormat = (await input.getFormat()) === WEBM ? \"webm\" : \"mp4\";\n if (first && format !== first.format) {\n throw new ConcatMismatchError(i, `Segment ${i} is ${format} and segment 0 is ${first.format}.`);\n }\n const track = await input.getPrimaryVideoTrack();\n if (!track) throw new ConcatMismatchError(i, `Segment ${i} has no video track.`);\n const config = await track.getDecoderConfig();\n if (!config) throw new ConcatMismatchError(i, `Segment ${i} has no decoder configuration.`);\n if (first && !sameDecoderConfig(first.config, config)) {\n throw new ConcatMismatchError(\n i,\n `Segment ${i} was encoded differently from segment 0 (${first.config.codec} `\n + `${first.config.codedWidth}x${first.config.codedHeight} vs ${config.codec} `\n + `${config.codedWidth}x${config.codedHeight}); joining them would decode as garbage.`,\n );\n }\n return { format, track, config, duration: await track.computeDuration() };\n}\n\n/**\n * Concatenate `segments` (each a complete MP4, or each a complete WebM) into one\n * file of the same container.\n *\n * Segments are joined in array order. Returns the muxed bytes.\n *\n * @throws {ConcatMismatchError} if a segment carries no video track, is in another\n * container than the first, or has a decoder configuration that differs\n * from the first segment's. Callers that can\n * fall back to a single-threaded export should catch this and do so — the\n * alternative is shipping a file that decodes into garbage halfway through.\n */\nexport async function concatVideoSegments(\n segments: Uint8Array[],\n options: ConcatOptions = {},\n): Promise<Uint8Array> {\n if (segments.length === 0) throw new Error(\"concatVideoSegments: no segments\");\n // A lone segment is already the finished file — unless a track has to be added\n // to it, or it has to go to a sink, either of which means muxing after all.\n if (segments.length === 1 && !options.audio && !options.stream) return segments[0];\n\n const joiner = createSegmentJoiner(options);\n try {\n for (const segment of segments) await joiner.append(segment);\n return await joiner.finish();\n } catch (error) {\n await joiner.cancel().catch(() => {});\n throw error;\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Hand an export's bytes back, or download them through an `<a download>`.
3
+ * Headless callers capture the bytes and write the file themselves.
4
+ */
5
+ export declare function deliver(bytes: Uint8Array, options: {
6
+ returnBytes: boolean;
7
+ filename: string;
8
+ mimeType: string;
9
+ }): Uint8Array | undefined;
10
+ //# sourceMappingURL=deliver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deliver.d.ts","sourceRoot":"","sources":["../src/deliver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,OAAO,CACnB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE;IAAE,WAAW,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACtE,UAAU,GAAG,SAAS,CAgBxB"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Hand an export's bytes back, or download them through an `<a download>`.
3
+ * Headless callers capture the bytes and write the file themselves.
4
+ */
5
+ export function deliver(bytes, options) {
6
+ if (options.returnBytes)
7
+ return bytes;
8
+ // Every encoder here builds its Uint8Array over a whole, plain ArrayBuffer, so
9
+ // the cast is sound — TS only balks because the generic parameter admits a
10
+ // SharedArrayBuffer, which a BlobPart may not be.
11
+ const blob = new Blob([bytes.buffer], { type: options.mimeType });
12
+ const url = URL.createObjectURL(blob);
13
+ const link = document.createElement("a");
14
+ link.href = url;
15
+ link.download = options.filename;
16
+ document.body.appendChild(link);
17
+ link.click();
18
+ document.body.removeChild(link);
19
+ URL.revokeObjectURL(url);
20
+ return undefined;
21
+ }
22
+ //# sourceMappingURL=deliver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deliver.js","sourceRoot":"","sources":["../src/deliver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,OAAO,CACnB,KAAiB,EACjB,OAAqE;IAErE,IAAI,OAAO,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC;IAEtC,+EAA+E;IAC/E,2EAA2E;IAC3E,kDAAkD;IAClD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,MAAqB,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACjF,MAAM,GAAG,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAChB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IACjC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK,EAAE,CAAC;IACb,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IACzB,OAAO,SAAS,CAAC;AACrB,CAAC","sourcesContent":["/**\n * Hand an export's bytes back, or download them through an `<a download>`.\n * Headless callers capture the bytes and write the file themselves.\n */\nexport function deliver(\n bytes: Uint8Array,\n options: { returnBytes: boolean; filename: string; mimeType: string },\n): Uint8Array | undefined {\n if (options.returnBytes) return bytes;\n\n // Every encoder here builds its Uint8Array over a whole, plain ArrayBuffer, so\n // the cast is sound — TS only balks because the generic parameter admits a\n // SharedArrayBuffer, which a BlobPart may not be.\n const blob = new Blob([bytes.buffer as ArrayBuffer], { type: options.mimeType });\n const url = URL.createObjectURL(blob);\n const link = document.createElement(\"a\");\n link.href = url;\n link.download = options.filename;\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n URL.revokeObjectURL(url);\n return undefined;\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { DynamicNodeConfig } from "@motionscript/core";
2
+ /**
3
+ * Resolves a full `DynamicNodeConfig`, filling in whatever the caller left
4
+ * unset with `browser`'s own default. Synchronous — the WASM import happens
5
+ * on `compile`'s first actual call, not here, so attaching this to every
6
+ * engine costs nothing until a source string is genuinely registered.
7
+ */
8
+ export declare function resolveDynamicNodes(partial: Partial<DynamicNodeConfig> | undefined, compilerWasmUrl?: string): DynamicNodeConfig;
9
+ //# sourceMappingURL=dynamic-nodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic-nodes.d.ts","sourceRoot":"","sources":["../src/dynamic-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AA6C5D;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAC/B,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,SAAS,EAC/C,eAAe,CAAC,EAAE,MAAM,GACzB,iBAAiB,CAMnB"}
@@ -0,0 +1,53 @@
1
+ import * as sdk from "@motionscript/core/sdk";
2
+ import * as esbuild from "esbuild-wasm";
3
+ /**
4
+ * `browser`'s real, working default for `Registry.addNodeFromSource` — the
5
+ * `sdk` half is cheap (re-exports, no WASM) and imported eagerly; the compiler
6
+ * is the expensive half, and stays behind a lazy `import()` so an app that
7
+ * never registers a source-string node never pays for it, however long the
8
+ * engine has been running.
9
+ *
10
+ * `core` has no compiler dependency of its own and cannot import the published
11
+ * `@motionscript/sdk` barrel (that package depends on `core`, so the reverse
12
+ * would be circular) — `browser` is where this concern actually belongs: the
13
+ * package whose entire job is "what running in an actual browser tab looks
14
+ * like" already owns the renderer, `WebAudioSink` and `WebTicker` on exactly that
15
+ * basis.
16
+ */
17
+ // Default to the wasm shipped by esbuild-wasm, resolved lazily — `import.meta.url`
18
+ // is empty in a non-ESM output (an IIFE bundle, which is what the headless page
19
+ // loads), and `new URL("…", "")` throws on import, before a caller has had the
20
+ // chance to pass an explicit URL that would have made the default irrelevant.
21
+ function defaultCompilerWasmUrl() {
22
+ return new URL("esbuild-wasm/esbuild.wasm", import.meta.url).href;
23
+ }
24
+ let compilerPromise;
25
+ /** Loaded once, memoized process-wide. */
26
+ function defaultCompiler(wasmUrl) {
27
+ return (compilerPromise ??= (async () => {
28
+ await esbuild.initialize({ wasmURL: wasmUrl ?? defaultCompilerWasmUrl() });
29
+ return async (source) => {
30
+ const { code } = await esbuild.transform(source, {
31
+ // A component is written with calls: there is no JSX to compile.
32
+ loader: "ts",
33
+ format: "cjs",
34
+ target: "es2020",
35
+ });
36
+ return code;
37
+ };
38
+ })());
39
+ }
40
+ /**
41
+ * Resolves a full `DynamicNodeConfig`, filling in whatever the caller left
42
+ * unset with `browser`'s own default. Synchronous — the WASM import happens
43
+ * on `compile`'s first actual call, not here, so attaching this to every
44
+ * engine costs nothing until a source string is genuinely registered.
45
+ */
46
+ export function resolveDynamicNodes(partial, compilerWasmUrl) {
47
+ return {
48
+ sdk: partial?.sdk ?? sdk,
49
+ modules: partial?.modules,
50
+ compile: partial?.compile ?? (async (source) => (await defaultCompiler(compilerWasmUrl))(source)),
51
+ };
52
+ }
53
+ //# sourceMappingURL=dynamic-nodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic-nodes.js","sourceRoot":"","sources":["../src/dynamic-nodes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,wBAAwB,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC;;;;;;;;;;;;;GAaG;AAEH,mFAAmF;AACnF,gFAAgF;AAChF,+EAA+E;AAC/E,8EAA8E;AAC9E,SAAS,sBAAsB;IAC3B,OAAO,IAAI,GAAG,CAAC,2BAA2B,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AACtE,CAAC;AAED,IAAI,eAAyE,CAAC;AAE9E,0CAA0C;AAC1C,SAAS,eAAe,CAAC,OAAgB;IACrC,OAAO,CAAC,eAAe,KAAK,CAAC,KAAK,IAAI,EAAE;QACpC,MAAM,OAAO,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,EAAE,CAAC,CAAC;QAC3E,OAAO,KAAK,EAAE,MAAc,EAAE,EAAE;YAC5B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE;gBAC7C,iEAAiE;gBACjE,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,KAAK;gBACb,MAAM,EAAE,QAAQ;aACnB,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC;IACN,CAAC,CAAC,EAAE,CAAC,CAAC;AACV,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAC/B,OAA+C,EAC/C,eAAwB;IAExB,OAAO;QACH,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,GAAG;QACxB,OAAO,EAAE,OAAO,EAAE,OAAO;QACzB,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;KACpG,CAAC;AACN,CAAC","sourcesContent":["import type { DynamicNodeConfig } from \"@motionscript/core\";\nimport * as sdk from \"@motionscript/core/sdk\";\nimport * as esbuild from \"esbuild-wasm\";\n\n/**\n * `browser`'s real, working default for `Registry.addNodeFromSource` — the\n * `sdk` half is cheap (re-exports, no WASM) and imported eagerly; the compiler\n * is the expensive half, and stays behind a lazy `import()` so an app that\n * never registers a source-string node never pays for it, however long the\n * engine has been running.\n *\n * `core` has no compiler dependency of its own and cannot import the published\n * `@motionscript/sdk` barrel (that package depends on `core`, so the reverse\n * would be circular) — `browser` is where this concern actually belongs: the\n * package whose entire job is \"what running in an actual browser tab looks\n * like\" already owns the renderer, `WebAudioSink` and `WebTicker` on exactly that\n * basis.\n */\n\n// Default to the wasm shipped by esbuild-wasm, resolved lazily — `import.meta.url`\n// is empty in a non-ESM output (an IIFE bundle, which is what the headless page\n// loads), and `new URL(\"…\", \"\")` throws on import, before a caller has had the\n// chance to pass an explicit URL that would have made the default irrelevant.\nfunction defaultCompilerWasmUrl(): string {\n return new URL(\"esbuild-wasm/esbuild.wasm\", import.meta.url).href;\n}\n\nlet compilerPromise: Promise<(source: string) => Promise<string>> | undefined;\n\n/** Loaded once, memoized process-wide. */\nfunction defaultCompiler(wasmUrl?: string): Promise<(source: string) => Promise<string>> {\n return (compilerPromise ??= (async () => {\n await esbuild.initialize({ wasmURL: wasmUrl ?? defaultCompilerWasmUrl() });\n return async (source: string) => {\n const { code } = await esbuild.transform(source, {\n // A component is written with calls: there is no JSX to compile.\n loader: \"ts\",\n format: \"cjs\",\n target: \"es2020\",\n });\n return code;\n };\n })());\n}\n\n/**\n * Resolves a full `DynamicNodeConfig`, filling in whatever the caller left\n * unset with `browser`'s own default. Synchronous — the WASM import happens\n * on `compile`'s first actual call, not here, so attaching this to every\n * engine costs nothing until a source string is genuinely registered.\n */\nexport function resolveDynamicNodes(\n partial: Partial<DynamicNodeConfig> | undefined,\n compilerWasmUrl?: string,\n): DynamicNodeConfig {\n return {\n sdk: partial?.sdk ?? sdk,\n modules: partial?.modules,\n compile: partial?.compile ?? (async (source) => (await defaultCompiler(compilerWasmUrl))(source)),\n };\n}\n"]}
@@ -0,0 +1,87 @@
1
+ import { Engine, EngineOptions, EngineRenderContext, MeasureContext2D, PlatformDeps, StorageAdapter, type DynamicNodeConfig, type NodeConstructor, type NodeTypeMap } from "@motionscript/core";
2
+ import type { WgpuStorageAdapter } from "@motionscript/renderer";
3
+ import { type RendererWasmOption } from "./renderer";
4
+ import { type AudioEncoderOptions, type VideoEncoderOptions } from "./exporter";
5
+ import { type ExportFormat } from "./formats";
6
+ export interface BrowserEngineOptions extends Omit<EngineOptions, "nodes" | "dynamicNodes">, RendererWasmOption {
7
+ /**
8
+ * Node types any document opened here may name — components as an array
9
+ * or a record naming each key outright, same as `EngineOptions`, plus a
10
+ * TS source string in the **array** form only. A string default-exports a
11
+ * component, whose `key` is its key — the record form takes no string, so
12
+ * there is exactly one place a dynamic node's key comes from, not two that
13
+ * could disagree.
14
+ */
15
+ nodes?: readonly (NodeConstructor | string)[] | NodeTypeMap;
16
+ /**
17
+ * Enables a source string in `nodes`, and `engine.registerNode(source)`
18
+ * at any point afterward. Any field left unset falls back to `browser`'s
19
+ * own default — `@motionscript/core/sdk` for `sdk`, a lazily-loaded
20
+ * `esbuild-wasm` for `compile` — so this never needs to be passed at all
21
+ * for the common case. `modules` has no default: only the host knows
22
+ * which loaded packages a script it compiles may reach.
23
+ */
24
+ dynamicNodes?: Partial<DynamicNodeConfig>;
25
+ /**
26
+ * Where `esbuild-wasm`'s own `.wasm` binary is served — only read if the
27
+ * default compiler is actually used.
28
+ */
29
+ compilerWasmUrl?: string;
30
+ /** Default video encoder settings for `session.export()`. Overridable per call. */
31
+ video?: VideoEncoderOptions;
32
+ /** Default audio encoder settings for `session.export()`. Overridable per call. */
33
+ audio?: AudioEncoderOptions;
34
+ }
35
+ /** What a session's frames are drawn with, and the storage and measurement it reads from. */
36
+ export interface BrowserRenderer<TStorage extends StorageAdapter = StorageAdapter> {
37
+ createStorageAdapter(deps: PlatformDeps): TStorage;
38
+ createRenderContext(storage: TStorage): BrowserRenderContext;
39
+ createMeasureContext(storage: TStorage): MeasureContext2D;
40
+ dispose?(): void;
41
+ }
42
+ /** A render context as this package drives it: an engine one, plus what exports and stills ask of it. */
43
+ export type BrowserRenderContext = EngineRenderContext & {
44
+ /**
45
+ * Settles once the surface `mount` began can draw. A backend whose surface
46
+ * comes up asynchronously (a GPU device) must have it, or the first frame
47
+ * draws onto nothing.
48
+ */
49
+ whenMounted?(): Promise<void>;
50
+ /**
51
+ * The frame last drawn, copied into a fresh 2D canvas, or `undefined` before
52
+ * one was. What a still encodes; a WebGPU canvas is readable only in the task
53
+ * that drew it, so a backend may draw it again here.
54
+ */
55
+ snapshotCanvas?(): HTMLCanvasElement | undefined;
56
+ };
57
+ /** What `session.export({ encode })` accepts in this environment. */
58
+ export interface BrowserEncodeOptions {
59
+ /**
60
+ * Defaults to `'mp4'`. An audio format (`'wav'`, `'mp3'`, `'m4a'`) renders no
61
+ * frames and ignores `scale`, `frames`, `includeAudio`, `video` and `supersample`.
62
+ */
63
+ format?: ExportFormat;
64
+ video?: VideoEncoderOptions;
65
+ audio?: AudioEncoderOptions;
66
+ supersample?: number;
67
+ /** Set false to get the bytes back instead of triggering a browser download. */
68
+ download?: boolean;
69
+ filename?: string;
70
+ }
71
+ /**
72
+ * An engine backed by the browser: WebGPU surfaces, Web Audio, WebCodecs.
73
+ * Rejects with `WebGpuUnavailableError` where this browser has no WebGPU adapter.
74
+ *
75
+ * Async because the renderer is a wasm module and every seam below needs it. Await
76
+ * once, at app start, and share the result — the caches underneath (registered
77
+ * fonts, decoded images, shaped paragraphs) are the point of keeping one engine
78
+ * rather than one per canvas.
79
+ *
80
+ * ```ts
81
+ * const engine = await createBrowserEngine({ nodes: { pulseRing: PulseRing } });
82
+ * const session = engine.open({ document, target: canvasEl });
83
+ * session.playback!.play();
84
+ * ```
85
+ */
86
+ export declare function createBrowserEngine(options?: BrowserEngineOptions): Promise<Engine<WgpuStorageAdapter>>;
87
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,MAAM,EACN,aAAa,EAEb,mBAAmB,EAOnB,gBAAgB,EAChB,YAAY,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