@smoove/core 0.1.8 → 0.3.0

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 (94) hide show
  1. package/dist/engine/composition.d.ts.map +1 -1
  2. package/dist/engine/composition.js +1 -1
  3. package/dist/engine/composition.js.map +1 -1
  4. package/dist/engine/runtime-defaults.d.ts +5 -5
  5. package/dist/engine/runtime-defaults.d.ts.map +1 -1
  6. package/dist/engine/runtime-defaults.js +12 -9
  7. package/dist/engine/runtime-defaults.js.map +1 -1
  8. package/dist/engine/sequence.js +1 -1
  9. package/dist/engine/sequence.js.map +1 -1
  10. package/dist/index.d.ts +5 -10
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +9 -6
  13. package/dist/index.js.map +1 -1
  14. package/dist/layout/group.d.ts +15 -0
  15. package/dist/layout/group.d.ts.map +1 -0
  16. package/dist/layout/group.js +20 -0
  17. package/dist/layout/group.js.map +1 -0
  18. package/dist/layout/image.js +1 -1
  19. package/dist/layout/image.js.map +1 -1
  20. package/dist/layout/text/font.js +1 -1
  21. package/dist/layout/text/font.js.map +1 -1
  22. package/dist/layout/text/text.d.ts +17 -0
  23. package/dist/layout/text/text.d.ts.map +1 -1
  24. package/dist/layout/text/text.js +66 -1
  25. package/dist/layout/text/text.js.map +1 -1
  26. package/dist/markers.d.ts +43 -0
  27. package/dist/markers.d.ts.map +1 -0
  28. package/dist/markers.js +46 -0
  29. package/dist/markers.js.map +1 -0
  30. package/package.json +2 -3
  31. package/dist/media/audio/audio-driver.d.ts +0 -34
  32. package/dist/media/audio/audio-driver.d.ts.map +0 -1
  33. package/dist/media/audio/audio-driver.js +0 -2
  34. package/dist/media/audio/audio-driver.js.map +0 -1
  35. package/dist/media/audio/audio-for-preview.d.ts +0 -47
  36. package/dist/media/audio/audio-for-preview.d.ts.map +0 -1
  37. package/dist/media/audio/audio-for-preview.js +0 -232
  38. package/dist/media/audio/audio-for-preview.js.map +0 -1
  39. package/dist/media/audio/audio-for-rendering.d.ts +0 -16
  40. package/dist/media/audio/audio-for-rendering.d.ts.map +0 -1
  41. package/dist/media/audio/audio-for-rendering.js +0 -32
  42. package/dist/media/audio/audio-for-rendering.js.map +0 -1
  43. package/dist/media/audio/audio-source-browser.d.ts +0 -30
  44. package/dist/media/audio/audio-source-browser.d.ts.map +0 -1
  45. package/dist/media/audio/audio-source-browser.js +0 -139
  46. package/dist/media/audio/audio-source-browser.js.map +0 -1
  47. package/dist/media/audio/audio-source-mediabunny.d.ts +0 -45
  48. package/dist/media/audio/audio-source-mediabunny.d.ts.map +0 -1
  49. package/dist/media/audio/audio-source-mediabunny.js +0 -79
  50. package/dist/media/audio/audio-source-mediabunny.js.map +0 -1
  51. package/dist/media/audio/index.d.ts +0 -57
  52. package/dist/media/audio/index.d.ts.map +0 -1
  53. package/dist/media/audio/index.js +0 -170
  54. package/dist/media/audio/index.js.map +0 -1
  55. package/dist/media/audio/shared-audio-context.d.ts +0 -30
  56. package/dist/media/audio/shared-audio-context.d.ts.map +0 -1
  57. package/dist/media/audio/shared-audio-context.js +0 -68
  58. package/dist/media/audio/shared-audio-context.js.map +0 -1
  59. package/dist/media/audio/types.d.ts +0 -31
  60. package/dist/media/audio/types.d.ts.map +0 -1
  61. package/dist/media/audio/types.js +0 -2
  62. package/dist/media/audio/types.js.map +0 -1
  63. package/dist/media/media-marker.d.ts +0 -26
  64. package/dist/media/media-marker.d.ts.map +0 -1
  65. package/dist/media/media-marker.js +0 -26
  66. package/dist/media/media-marker.js.map +0 -1
  67. package/dist/media/video/driver.d.ts +0 -31
  68. package/dist/media/video/driver.d.ts.map +0 -1
  69. package/dist/media/video/driver.js +0 -3
  70. package/dist/media/video/driver.js.map +0 -1
  71. package/dist/media/video/index.d.ts +0 -66
  72. package/dist/media/video/index.d.ts.map +0 -1
  73. package/dist/media/video/index.js +0 -372
  74. package/dist/media/video/index.js.map +0 -1
  75. package/dist/media/video/types.d.ts +0 -36
  76. package/dist/media/video/types.d.ts.map +0 -1
  77. package/dist/media/video/types.js +0 -2
  78. package/dist/media/video/types.js.map +0 -1
  79. package/dist/media/video/video-for-preview.d.ts +0 -17
  80. package/dist/media/video/video-for-preview.d.ts.map +0 -1
  81. package/dist/media/video/video-for-preview.js +0 -30
  82. package/dist/media/video/video-for-preview.js.map +0 -1
  83. package/dist/media/video/video-for-rendering.d.ts +0 -17
  84. package/dist/media/video/video-for-rendering.d.ts.map +0 -1
  85. package/dist/media/video/video-for-rendering.js +0 -59
  86. package/dist/media/video/video-for-rendering.js.map +0 -1
  87. package/dist/media/video/video-source-browser.d.ts +0 -37
  88. package/dist/media/video/video-source-browser.d.ts.map +0 -1
  89. package/dist/media/video/video-source-browser.js +0 -171
  90. package/dist/media/video/video-source-browser.js.map +0 -1
  91. package/dist/media/video/video-source-mediabunny.d.ts +0 -69
  92. package/dist/media/video/video-source-mediabunny.d.ts.map +0 -1
  93. package/dist/media/video/video-source-mediabunny.js +0 -236
  94. package/dist/media/video/video-source-mediabunny.js.map +0 -1
@@ -1,68 +0,0 @@
1
- /**
2
- * Browser-only Web Audio bus, one per {@link Composition}. Owns the single
3
- * {@link AudioContext} every preview audio clip schedules against, plus a master
4
- * {@link GainNode} feeding the speakers. Created lazily on first use (so nothing
5
- * touches `AudioContext` in Node) and cached per composition.
6
- *
7
- * It deliberately knows nothing about clips or timing — the per-clip
8
- * {@link PreviewAudioDriver} owns the schedule-ahead pump and the timeline↔context
9
- * clock anchor. This just hands out a context, a channel gain, and `resume()`.
10
- */
11
- export class SharedAudioContext {
12
- _ctx = null;
13
- _master = null;
14
- /** The live context, created on first access. Null only if Web Audio is absent. */
15
- get context() {
16
- if (this._ctx)
17
- return this._ctx;
18
- const Ctor = typeof globalThis.AudioContext === "function"
19
- ? globalThis.AudioContext
20
- : globalThis
21
- .webkitAudioContext;
22
- if (!Ctor)
23
- return null;
24
- this._ctx = new Ctor();
25
- this._master = this._ctx.createGain();
26
- this._master.connect(this._ctx.destination);
27
- return this._ctx;
28
- }
29
- /** Current context clock in seconds, or 0 if Web Audio is absent. */
30
- now() {
31
- return this.context?.currentTime ?? 0;
32
- }
33
- /**
34
- * Resume the context — `AudioContext` starts suspended until a user gesture.
35
- * Safe to call repeatedly; resolves once running (or immediately if no context).
36
- */
37
- async resume() {
38
- const ctx = this.context;
39
- if (ctx && ctx.state === "suspended") {
40
- await ctx.resume().catch(() => { });
41
- }
42
- }
43
- /** A fresh per-clip {@link GainNode} wired into the master bus. */
44
- createChannelGain() {
45
- const ctx = this.context;
46
- if (!ctx || !this._master)
47
- return null;
48
- const gain = ctx.createGain();
49
- gain.connect(this._master);
50
- return gain;
51
- }
52
- destroy() {
53
- void this._ctx?.close().catch(() => { });
54
- this._ctx = null;
55
- this._master = null;
56
- }
57
- }
58
- const perComposition = new WeakMap();
59
- /** Lazily get (and cache) the {@link SharedAudioContext} for a composition. */
60
- export function getSharedAudioContext(comp) {
61
- let shared = perComposition.get(comp);
62
- if (!shared) {
63
- shared = new SharedAudioContext();
64
- perComposition.set(comp, shared);
65
- }
66
- return shared;
67
- }
68
- //# sourceMappingURL=shared-audio-context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shared-audio-context.js","sourceRoot":"","sources":["../../../src/media/audio/shared-audio-context.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,OAAO,kBAAkB;IACrB,IAAI,GAAwB,IAAI,CAAC;IACjC,OAAO,GAAoB,IAAI,CAAC;IAExC,mFAAmF;IACnF,IAAI,OAAO;QACT,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,IAAI,CAAC;QAChC,MAAM,IAAI,GACR,OAAO,UAAU,CAAC,YAAY,KAAK,UAAU;YAC3C,CAAC,CAAC,UAAU,CAAC,YAAY;YACzB,CAAC,CAAE,UAAsE;iBACpE,kBAAkB,CAAC;QAC5B,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,EA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GAAG,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAClC,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,31 +0,0 @@
1
- import type { AudioSourceFactory } from "./audio-source.js";
2
- /**
3
- * Config for {@link Audio}. Mirrors Remotion's `<Audio>` playback props
4
- * (`trimBefore`/`trimAfter`/`loop`/`muted`/`volume`/`playbackRate`) plus a
5
- * `sourceFactory` dependency-injection seam. Unlike {@link VideoConfig} there
6
- * are no visual/layout props — audio produces no pixels.
7
- */
8
- export type AudioConfig = {
9
- src: string;
10
- /** Stable id used for the Konva node and rendered {@link AudioAsset}s. */
11
- id?: string;
12
- /** Human label for the audio mixer channel / UIs. Defaults to {@link src}. */
13
- name?: string;
14
- /** Frames trimmed from the start of the media (composition fps). Remotion v4 name. */
15
- trimBefore?: number;
16
- /** Exclusive frame bound — media past this offset is trimmed (composition fps). */
17
- trimAfter?: number;
18
- /** @deprecated alias of {@link trimBefore} (Remotion's pre-v4.0.319 name). */
19
- startFrom?: number;
20
- /** @deprecated alias of {@link trimAfter} (Remotion's pre-v4.0.319 name). */
21
- endAt?: number;
22
- /** Repeat the trimmed clip within its sequence window instead of freezing on the last frame. */
23
- loop?: boolean;
24
- muted?: boolean;
25
- /** 0..1 */
26
- volume?: number;
27
- playbackRate?: number;
28
- /** Inject an alternative AudioSource. Defaults to BrowserAudioSource. */
29
- sourceFactory?: AudioSourceFactory;
30
- };
31
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/media/audio/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,0EAA0E;IAC1E,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sFAAsF;IACtF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mFAAmF;IACnF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gGAAgG;IAChG,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACpC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/media/audio/types.ts"],"names":[],"mappings":""}
@@ -1,26 +0,0 @@
1
- /**
2
- * Marker attrs stamped on media nodes ({@link Video}, {@link Audio}) and
3
- * inspected by `Sequence`/`Composition`. Kept in a dependency-free leaf so
4
- * `composition.ts` can discover media by string without importing `video/` or
5
- * `audio/` (which would create an import cycle).
6
- */
7
- /** Set by every tickable media node — drives Sequence discovery + mixer registration. */
8
- export declare const MEDIA_MARK = "__kmIsMedia";
9
- /** Additionally set by {@link Video} — backs `isVideoNode`. */
10
- export declare const VIDEO_MARK = "__kmIsVideo";
11
- /** Additionally set by {@link Audio} — backs `isAudioNode`. */
12
- export declare const AUDIO_MARK = "__kmIsAudio";
13
- /**
14
- * Set by non-media nodes that still want a per-frame `_kmTick` callback (e.g.
15
- * {@link Text}'s typewriter). Discovered by `Sequence` alongside media, but
16
- * NOT registered with the audio mixer.
17
- */
18
- export declare const TICK_MARK = "__kmIsTick";
19
- /**
20
- * Set by {@link Font} nodes. Walked by `Composition.add` so a scene-declared
21
- * font is loaded (and buffered on) before playback. Kept here, like the other
22
- * markers, so `composition.ts` discovers fonts by string without importing
23
- * `layout/text/` (avoiding an import cycle).
24
- */
25
- export declare const FONT_MARK = "__kmIsFont";
26
- //# sourceMappingURL=media-marker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"media-marker.d.ts","sourceRoot":"","sources":["../../src/media/media-marker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,yFAAyF;AACzF,eAAO,MAAM,UAAU,gBAAgB,CAAC;AACxC,+DAA+D;AAC/D,eAAO,MAAM,UAAU,gBAAgB,CAAC;AACxC,+DAA+D;AAC/D,eAAO,MAAM,UAAU,gBAAgB,CAAC;AACxC;;;;GAIG;AACH,eAAO,MAAM,SAAS,eAAe,CAAC;AACtC;;;;;GAKG;AACH,eAAO,MAAM,SAAS,eAAe,CAAC"}
@@ -1,26 +0,0 @@
1
- /**
2
- * Marker attrs stamped on media nodes ({@link Video}, {@link Audio}) and
3
- * inspected by `Sequence`/`Composition`. Kept in a dependency-free leaf so
4
- * `composition.ts` can discover media by string without importing `video/` or
5
- * `audio/` (which would create an import cycle).
6
- */
7
- /** Set by every tickable media node — drives Sequence discovery + mixer registration. */
8
- export const MEDIA_MARK = "__kmIsMedia";
9
- /** Additionally set by {@link Video} — backs `isVideoNode`. */
10
- export const VIDEO_MARK = "__kmIsVideo";
11
- /** Additionally set by {@link Audio} — backs `isAudioNode`. */
12
- export const AUDIO_MARK = "__kmIsAudio";
13
- /**
14
- * Set by non-media nodes that still want a per-frame `_kmTick` callback (e.g.
15
- * {@link Text}'s typewriter). Discovered by `Sequence` alongside media, but
16
- * NOT registered with the audio mixer.
17
- */
18
- export const TICK_MARK = "__kmIsTick";
19
- /**
20
- * Set by {@link Font} nodes. Walked by `Composition.add` so a scene-declared
21
- * font is loaded (and buffered on) before playback. Kept here, like the other
22
- * markers, so `composition.ts` discovers fonts by string without importing
23
- * `layout/text/` (avoiding an import cycle).
24
- */
25
- export const FONT_MARK = "__kmIsFont";
26
- //# sourceMappingURL=media-marker.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"media-marker.js","sourceRoot":"","sources":["../../src/media/media-marker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,yFAAyF;AACzF,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;AACxC,+DAA+D;AAC/D,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;AACxC,+DAA+D;AAC/D,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;AACxC;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,YAAY,CAAC;AACtC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,YAAY,CAAC"}
@@ -1,31 +0,0 @@
1
- import type { Composition } from "../../engine/composition.js";
2
- import type { MediaTiming } from "../media-time.js";
3
- import { getMediaTime } from "../media-time.js";
4
- import type { VideoSource } from "./video-source.js";
5
- /** Resolved per-video timing — alias of the shared {@link MediaTiming}. */
6
- export type VideoTiming = MediaTiming;
7
- export { getMediaTime };
8
- /**
9
- * What a driver needs from the host {@link Video}: the media source, the
10
- * resolved timing, the owning composition (for the render gate + play state),
11
- * and a redraw hook (relayout + batchDraw).
12
- */
13
- export type VideoDriverContext = {
14
- readonly source: VideoSource;
15
- readonly timing: VideoTiming;
16
- readonly comp: Composition;
17
- redraw(): void;
18
- };
19
- /**
20
- * Strategy that maps the composition's current frame onto the media. Mirrors
21
- * Remotion's split between `VideoForRendering` and `VideoForPreview`.
22
- */
23
- export interface VideoDriver {
24
- /** Called by Sequence each tick while the video is on-stage (`localFrame` = frame - sequence.from). */
25
- tick(localFrame: number): void;
26
- /** Called by Sequence when the video leaves range. */
27
- deactivate(): void;
28
- /** Release any subscriptions; called on `Video.destroy()`. */
29
- dispose(): void;
30
- }
31
- //# sourceMappingURL=driver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../../src/media/video/driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,2EAA2E;AAC3E,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,MAAM,IAAI,IAAI,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,uGAAuG;IACvG,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,sDAAsD;IACtD,UAAU,IAAI,IAAI,CAAC;IACnB,8DAA8D;IAC9D,OAAO,IAAI,IAAI,CAAC;CACjB"}
@@ -1,3 +0,0 @@
1
- import { getMediaTime } from "../media-time.js";
2
- export { getMediaTime };
3
- //# sourceMappingURL=driver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"driver.js","sourceRoot":"","sources":["../../../src/media/video/driver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAMhD,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,66 +0,0 @@
1
- import Konva from "konva";
2
- import { type ReadonlySignal } from "../../engine/signal.js";
3
- import type { KMLayoutNode, LayoutBox } from "../../layout/contract.js";
4
- import { type FlexilyNode } from "../../layout/flex/engine.js";
5
- import type { AudioChannel, AudioMixer } from "../audio/mixer.js";
6
- import type { VideoConfig } from "./types.js";
7
- /**
8
- * Timeline-driven video. API mirrors {@link Image} (`new Video({src, ...ImageProps})`)
9
- * but the frame source is a runtime-agnostic {@link VideoSource} and playback is
10
- * driven by the composition's frame clock. Picks a {@link RenderingVideoDriver}
11
- * or {@link PreviewVideoDriver} based on the composition's {@link Environment}.
12
- */
13
- export declare class Video extends Konva.Group implements AudioChannel, KMLayoutNode {
14
- readonly _kmRole: "leaf";
15
- /** Human label for mixer UIs — `config.name`, falling back to `config.src`. */
16
- readonly label: string;
17
- /** Intrinsic audio level, 0..1 — scaled by the composition mixer's master. */
18
- readonly volume: ReadonlySignal<number>;
19
- readonly muted: ReadonlySignal<boolean>;
20
- private readonly _img;
21
- private _source;
22
- private readonly _env;
23
- private readonly _factory;
24
- private _suspended;
25
- private readonly _trimBefore;
26
- private readonly _trimAfter?;
27
- private readonly _loop;
28
- private readonly _playbackRate;
29
- private readonly _volume;
30
- private readonly _muted;
31
- private _mixer;
32
- private _driver;
33
- private _audioDriver;
34
- private readonly _src;
35
- constructor(config: VideoConfig);
36
- /**
37
- * Create the media source and start loading it. Called once at construction
38
- * and again by {@link _kmResume} after {@link _kmSuspend} dropped it.
39
- */
40
- private _acquireSource;
41
- /** @internal — {@link Composition.suspend}: drop the source to stop downloading/decoding. */
42
- _kmSuspend(): void;
43
- /** @internal — {@link Composition.resume}: re-acquire the dropped source. */
44
- _kmResume(): void;
45
- /** @internal — called by Sequence on each tick while this video is on-stage. */
46
- _kmTick(localFrame: number): void;
47
- /** @internal — called by Sequence when it goes out of range. */
48
- _kmDeactivate(): void;
49
- /** @internal — {@link KMLayoutNode}: size from explicit width/height (cover/contain handle the rest). */
50
- _kmMeasure(node: FlexilyNode): void;
51
- /** @internal — {@link KMLayoutNode}: write the computed box back + re-fit the frame. */
52
- _kmPlace(box: LayoutBox): void;
53
- private _ensureDriver;
54
- setMuted(muted: boolean): void;
55
- setVolume(volume: number): void;
56
- /** @internal — {@link AudioMixer} hands us the bus (or null on unregister). */
57
- _bindMixer(mixer: AudioMixer | null): void;
58
- /** @internal — push effective level (master × intrinsic) to the source. */
59
- _applyAudio(): void;
60
- setPlaybackRate(rate: number): void;
61
- destroy(): this;
62
- /** @internal */
63
- _layoutImage(): void;
64
- }
65
- export declare function isVideoNode(node: Konva.Node): node is Video;
66
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/media/video/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAgB,KAAK,cAAc,EAAe,MAAM,wBAAwB,CAAC;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAa,KAAK,WAAW,EAAa,MAAM,6BAA6B,CAAC;AAOrF,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGlE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAoC9C;;;;;GAKG;AACH,qBAAa,KAAM,SAAQ,KAAK,CAAC,KAAM,YAAW,YAAY,EAAE,YAAY;IAC1E,QAAQ,CAAC,OAAO,EAAG,MAAM,CAAU;IACnC,+EAA+E;IAC/E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IAExC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAc;IAEnC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAc;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,O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,GAAG,IAAI,IAAI,KAAK,CAE3D"}
@@ -1,372 +0,0 @@
1
- import Konva from "konva";
2
- import { getComposition } from "../../engine/composition.js";
3
- import { detectEnvironment, getEnvironment } from "../../engine/environment.js";
4
- import { getDefaultVideoSourceFactory } from "../../engine/runtime-defaults.js";
5
- import { createSignal } from "../../engine/signal.js";
6
- import { applySize, parseSize } from "../../layout/flex/engine.js";
7
- import { PreviewAudioDriver } from "../audio/audio-for-preview.js";
8
- import { RenderingAudioDriver } from "../audio/audio-for-rendering.js";
9
- import { isSchedulable } from "../audio/audio-source-mediabunny.js";
10
- import { MEDIA_MARK, VIDEO_MARK } from "../media-marker.js";
11
- import { PreviewVideoDriver } from "./video-for-preview.js";
12
- import { RenderingVideoDriver } from "./video-for-rendering.js";
13
- const VIDEO_KEYS = [
14
- "src",
15
- "trimBefore",
16
- "trimAfter",
17
- "startFrom",
18
- "endAt",
19
- "loop",
20
- "muted",
21
- "volume",
22
- "playbackRate",
23
- "objectFit",
24
- "objectPosition",
25
- "flexGrow",
26
- "flexShrink",
27
- "flexBasis",
28
- "alignSelf",
29
- "margin",
30
- "sourceFactory",
31
- ];
32
- function pickKonvaConfig(config) {
33
- const out = { ...config };
34
- for (const k of VIDEO_KEYS)
35
- delete out[k];
36
- const w = parseSize(config.width);
37
- const h = parseSize(config.height);
38
- out.width = w?.kind === "px" ? w.value : undefined;
39
- out.height = h?.kind === "px" ? h.value : undefined;
40
- out.cornerRadius = undefined;
41
- return out;
42
- }
43
- /**
44
- * Timeline-driven video. API mirrors {@link Image} (`new Video({src, ...ImageProps})`)
45
- * but the frame source is a runtime-agnostic {@link VideoSource} and playback is
46
- * driven by the composition's frame clock. Picks a {@link RenderingVideoDriver}
47
- * or {@link PreviewVideoDriver} based on the composition's {@link Environment}.
48
- */
49
- export class Video extends Konva.Group {
50
- _kmRole = "leaf";
51
- /** Human label for mixer UIs — `config.name`, falling back to `config.src`. */
52
- label;
53
- /** Intrinsic audio level, 0..1 — scaled by the composition mixer's master. */
54
- volume;
55
- muted;
56
- _img;
57
- // Reassigned on suspend/resume, so not readonly; `!` = set via _acquireSource().
58
- _source;
59
- _env;
60
- _factory;
61
- _suspended = false;
62
- _trimBefore;
63
- _trimAfter;
64
- _loop;
65
- _playbackRate;
66
- _volume;
67
- _muted;
68
- _mixer = null;
69
- _driver = null;
70
- _audioDriver = null;
71
- _src;
72
- constructor(config) {
73
- super(pickKonvaConfig(config));
74
- this.setAttr(MEDIA_MARK, true);
75
- this.setAttr(VIDEO_MARK, true);
76
- this._src = config.src;
77
- this._trimBefore = config.trimBefore ?? config.startFrom ?? 0;
78
- this._trimAfter = config.trimAfter ?? config.endAt;
79
- this._loop = config.loop ?? false;
80
- this._playbackRate = config.playbackRate ?? 1;
81
- this.label = config.name ?? config.src;
82
- this._volume = createSignal(config.volume ?? 1);
83
- this._muted = createSignal(config.muted ?? false);
84
- this.volume = this._volume;
85
- this.muted = this._muted;
86
- this._img = new Konva.Image({ image: undefined, listening: false });
87
- super.add(this._img);
88
- this.setAttrs({
89
- flexGrow: config.flexGrow,
90
- flexShrink: config.flexShrink,
91
- flexBasis: config.flexBasis,
92
- alignSelf: config.alignSelf,
93
- margin: config.margin,
94
- objectFit: config.objectFit ?? "cover",
95
- objectPosition: config.objectPosition ?? "center",
96
- cornerRadius: config.cornerRadius,
97
- flexWidth: config.width,
98
- flexHeight: config.height,
99
- });
100
- if (config.cornerRadius !== undefined) {
101
- const cr = normalizeCorners(config.cornerRadius);
102
- this.clipFunc((ctx) => roundRectPath(ctx, 0, 0, this.width(), this.height(), cr));
103
- }
104
- this.on("widthChange heightChange", () => this._layoutImage());
105
- // Build the source eagerly so loading starts immediately. The driver (which
106
- // needs the attached stage's composition) is resolved lazily on first tick.
107
- this._env = detectEnvironment();
108
- this._factory = config.sourceFactory ?? getDefaultVideoSourceFactory();
109
- this._acquireSource();
110
- this._layoutImage();
111
- }
112
- /**
113
- * Create the media source and start loading it. Called once at construction
114
- * and again by {@link _kmResume} after {@link _kmSuspend} dropped it.
115
- */
116
- _acquireSource() {
117
- this._source = this._factory(this._env);
118
- this._applyAudio(); // honor config/mixer volume+muted before playback
119
- this._source.setPlaybackRate(this._playbackRate);
120
- this._source.onReady(() => {
121
- const el = this._source.element;
122
- if (el)
123
- this._img.image(el);
124
- this._layoutImage();
125
- this.getLayer()?.batchDraw();
126
- });
127
- this._source.onFrame(() => {
128
- this.getLayer()?.batchDraw();
129
- });
130
- this._source.load(this._src).catch((err) => {
131
- console.error("[smoove] Video load failed:", err);
132
- });
133
- }
134
- /** @internal — {@link Composition.suspend}: drop the source to stop downloading/decoding. */
135
- _kmSuspend() {
136
- if (this._suspended)
137
- return;
138
- this._suspended = true;
139
- this._driver?.dispose();
140
- this._driver = null;
141
- this._audioDriver?.dispose();
142
- this._audioDriver = null;
143
- this._source.destroy();
144
- this._img.image(undefined);
145
- this.getLayer()?.batchDraw();
146
- }
147
- /** @internal — {@link Composition.resume}: re-acquire the dropped source. */
148
- _kmResume() {
149
- if (!this._suspended)
150
- return;
151
- this._suspended = false;
152
- this._acquireSource();
153
- }
154
- /** @internal — called by Sequence on each tick while this video is on-stage. */
155
- _kmTick(localFrame) {
156
- const driver = this._ensureDriver();
157
- driver?.tick(localFrame);
158
- this._audioDriver?.tick(localFrame);
159
- }
160
- /** @internal — called by Sequence when it goes out of range. */
161
- _kmDeactivate() {
162
- this._driver?.deactivate();
163
- this._audioDriver?.deactivate();
164
- }
165
- /** @internal — {@link KMLayoutNode}: size from explicit width/height (cover/contain handle the rest). */
166
- _kmMeasure(node) {
167
- applySize(node, this.attrs.flexWidth, this.attrs.flexHeight);
168
- }
169
- /** @internal — {@link KMLayoutNode}: write the computed box back + re-fit the frame. */
170
- _kmPlace(box) {
171
- this.x(box.left);
172
- this.y(box.top);
173
- this.width(box.width);
174
- this.height(box.height);
175
- this._layoutImage();
176
- }
177
- _ensureDriver() {
178
- if (this._driver)
179
- return this._driver;
180
- const stage = this.getStage();
181
- if (!stage)
182
- return null;
183
- const comp = getComposition(stage);
184
- if (!comp)
185
- return null;
186
- // Lazy fallback for videos added after their sequence was registered.
187
- comp.mixer.register(this);
188
- const timing = {
189
- fps: comp.fps,
190
- trimBefore: this._trimBefore,
191
- trimAfter: this._trimAfter,
192
- loop: this._loop,
193
- playbackRate: this._playbackRate,
194
- };
195
- const ctx = {
196
- source: this._source,
197
- timing,
198
- comp,
199
- redraw: () => {
200
- this._layoutImage();
201
- this.getLayer()?.batchDraw();
202
- },
203
- };
204
- if (getEnvironment(stage).isRendering) {
205
- this._driver = new RenderingVideoDriver(ctx);
206
- // Record the file's soundtrack as audio assets so the server mux can decode
207
- // and mix it (videos with no audio track simply yield no audible PCM).
208
- const audioCtx = {
209
- source: this._source,
210
- timing,
211
- comp,
212
- id: this.id() || `video-${this._id}`,
213
- src: this._src,
214
- effectiveVolume: () => {
215
- const m = this._mixer;
216
- return (m ? m.volume.get() : 1) * this._volume.get();
217
- },
218
- effectiveMuted: () => {
219
- const m = this._mixer;
220
- return (m ? m.muted.get() : false) || this._muted.get();
221
- },
222
- };
223
- this._audioDriver = new RenderingAudioDriver(audioCtx);
224
- }
225
- else {
226
- this._driver = new PreviewVideoDriver(ctx);
227
- // In preview, schedule the file's own soundtrack through the shared Web
228
- // Audio context — same scheduler the standalone Audio node uses. (The
229
- // rendering branch above records it as audio assets for the server mux.)
230
- if (isSchedulable(this._source)) {
231
- const audioCtx = {
232
- source: this._source,
233
- timing,
234
- comp,
235
- id: this.id() || `video-${this._id}`,
236
- src: this._src,
237
- effectiveVolume: () => {
238
- const m = this._mixer;
239
- return (m ? m.volume.get() : 1) * this._volume.get();
240
- },
241
- effectiveMuted: () => {
242
- const m = this._mixer;
243
- return (m ? m.muted.get() : false) || this._muted.get();
244
- },
245
- };
246
- this._audioDriver = new PreviewAudioDriver(audioCtx);
247
- }
248
- }
249
- return this._driver;
250
- }
251
- setMuted(muted) {
252
- this._muted.set(muted);
253
- this._applyAudio();
254
- }
255
- setVolume(volume) {
256
- this._volume.set(Math.max(0, Math.min(1, volume)));
257
- this._applyAudio();
258
- }
259
- /** @internal — {@link AudioMixer} hands us the bus (or null on unregister). */
260
- _bindMixer(mixer) {
261
- this._mixer = mixer;
262
- this._applyAudio();
263
- }
264
- /** @internal — push effective level (master × intrinsic) to the source. */
265
- _applyAudio() {
266
- const m = this._mixer;
267
- const master = m ? m.volume.get() : 1;
268
- const masterMuted = m ? m.muted.get() : false;
269
- this._source.setVolume(master * this._volume.get());
270
- this._source.setMuted(masterMuted || this._muted.get());
271
- }
272
- setPlaybackRate(rate) {
273
- this._source.setPlaybackRate(rate);
274
- }
275
- destroy() {
276
- this._mixer?.unregister(this);
277
- this._mixer = null;
278
- this._driver?.dispose();
279
- this._driver = null;
280
- this._audioDriver?.dispose();
281
- this._audioDriver = null;
282
- this._source.destroy();
283
- return super.destroy();
284
- }
285
- /** @internal */
286
- _layoutImage() {
287
- const w = this.width();
288
- const h = this.height();
289
- if (w <= 0 || h <= 0)
290
- return;
291
- const fit = (this.attrs.objectFit ?? "cover");
292
- const pos = (this.attrs.objectPosition ?? "center");
293
- const nw = this._source.naturalWidth;
294
- const nh = this._source.naturalHeight;
295
- if (!this._source.isReady || nw === 0 || nh === 0)
296
- return;
297
- if (fit === "fill") {
298
- this._img.position({ x: 0, y: 0 });
299
- this._img.size({ width: w, height: h });
300
- this._img.crop({ x: 0, y: 0, width: nw, height: nh });
301
- return;
302
- }
303
- if (fit === "none") {
304
- const { x, y } = positionOffset(pos, w - nw, h - nh);
305
- this._img.position({ x, y });
306
- this._img.size({ width: nw, height: nh });
307
- this._img.crop({ x: 0, y: 0, width: nw, height: nh });
308
- return;
309
- }
310
- if (fit === "contain") {
311
- const scale = Math.min(w / nw, h / nh);
312
- const dw = nw * scale;
313
- const dh = nh * scale;
314
- const { x, y } = positionOffset(pos, w - dw, h - dh);
315
- this._img.position({ x, y });
316
- this._img.size({ width: dw, height: dh });
317
- this._img.crop({ x: 0, y: 0, width: nw, height: nh });
318
- return;
319
- }
320
- const scale = Math.max(w / nw, h / nh);
321
- const cropW = w / scale;
322
- const cropH = h / scale;
323
- const { x: cx, y: cy } = positionOffset(pos, nw - cropW, nh - cropH);
324
- this._img.position({ x: 0, y: 0 });
325
- this._img.size({ width: w, height: h });
326
- this._img.crop({ x: cx, y: cy, width: cropW, height: cropH });
327
- }
328
- }
329
- export function isVideoNode(node) {
330
- return node.getAttr(VIDEO_MARK) === true;
331
- }
332
- function positionOffset(pos, freeX, freeY) {
333
- let fx = 0.5;
334
- let fy = 0.5;
335
- if (pos.includes("left"))
336
- fx = 0;
337
- else if (pos.includes("right"))
338
- fx = 1;
339
- if (pos.includes("top"))
340
- fy = 0;
341
- else if (pos.includes("bottom"))
342
- fy = 1;
343
- if (pos === "center") {
344
- fx = 0.5;
345
- fy = 0.5;
346
- }
347
- return { x: freeX * fx, y: freeY * fy };
348
- }
349
- function normalizeCorners(c) {
350
- if (typeof c === "number")
351
- return [c, c, c, c];
352
- if (c.length === 1)
353
- return [c[0] ?? 0, c[0] ?? 0, c[0] ?? 0, c[0] ?? 0];
354
- if (c.length === 2)
355
- return [c[0] ?? 0, c[1] ?? 0, c[0] ?? 0, c[1] ?? 0];
356
- return [c[0] ?? 0, c[1] ?? 0, c[2] ?? 0, c[3] ?? 0];
357
- }
358
- function roundRectPath(ctx, x, y, w, h, r) {
359
- const [tl, tr, br, bl] = r;
360
- ctx.beginPath();
361
- ctx.moveTo(x + (tl ?? 0), y);
362
- ctx.lineTo(x + w - (tr ?? 0), y);
363
- ctx.quadraticCurveTo(x + w, y, x + w, y + (tr ?? 0));
364
- ctx.lineTo(x + w, y + h - (br ?? 0));
365
- ctx.quadraticCurveTo(x + w, y + h, x + w - (br ?? 0), y + h);
366
- ctx.lineTo(x + (bl ?? 0), y + h);
367
- ctx.quadraticCurveTo(x, y + h, x, y + h - (bl ?? 0));
368
- ctx.lineTo(x, y + (tl ?? 0));
369
- ctx.quadraticCurveTo(x, y, x + (tl ?? 0), y);
370
- ctx.closePath();
371
- }
372
- //# sourceMappingURL=index.js.map