visualfries 0.1.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.
- package/LICENSE +21 -0
- package/README.md +213 -0
- package/dist/DIContainer.d.ts +4 -0
- package/dist/DIContainer.js +145 -0
- package/dist/SceneBuilder.svelte.d.ts +8574 -0
- package/dist/SceneBuilder.svelte.js +409 -0
- package/dist/adapters/subtitleHelpers.d.ts +2 -0
- package/dist/adapters/subtitleHelpers.js +187 -0
- package/dist/animations/AnimationContext.d.ts +17 -0
- package/dist/animations/AnimationContext.js +72 -0
- package/dist/animations/AnimationPresetsRegister.d.ts +362 -0
- package/dist/animations/AnimationPresetsRegister.js +20 -0
- package/dist/animations/AnimationSetup.d.ts +8 -0
- package/dist/animations/AnimationSetup.js +30 -0
- package/dist/animations/SplitTextCache.d.ts +28 -0
- package/dist/animations/SplitTextCache.js +68 -0
- package/dist/animations/animationBuilder.d.ts +31 -0
- package/dist/animations/animationBuilder.js +255 -0
- package/dist/animations/animationPreset.d.ts +7 -0
- package/dist/animations/animationPreset.js +31 -0
- package/dist/animations/builders/AnimationPresetFactory.d.ts +43 -0
- package/dist/animations/builders/AnimationPresetFactory.js +139 -0
- package/dist/animations/builders/LineHighlighterAnimationBuilder.d.ts +16 -0
- package/dist/animations/builders/LineHighlighterAnimationBuilder.js +183 -0
- package/dist/animations/builders/WordHighlighterAnimationBuilder.d.ts +15 -0
- package/dist/animations/builders/WordHighlighterAnimationBuilder.js +180 -0
- package/dist/animations/engines/AnimationEngineAdaptor.d.ts +107 -0
- package/dist/animations/engines/AnimationEngineAdaptor.js +1 -0
- package/dist/animations/engines/GSAPEngineAdaptor.d.ts +21 -0
- package/dist/animations/engines/GSAPEngineAdaptor.js +145 -0
- package/dist/animations/presets/index.d.ts +2 -0
- package/dist/animations/presets/index.js +3 -0
- package/dist/animations/presets/lines.d.ts +52 -0
- package/dist/animations/presets/lines.js +547 -0
- package/dist/animations/presets/words.d.ts +31 -0
- package/dist/animations/presets/words.js +268 -0
- package/dist/animations/transformers/AnimationReferenceTransformer.d.ts +9 -0
- package/dist/animations/transformers/AnimationReferenceTransformer.js +114 -0
- package/dist/builders/PixiComponentBuilder.d.ts +63 -0
- package/dist/builders/PixiComponentBuilder.js +112 -0
- package/dist/builders/_ComponentState.svelte.d.ts +795 -0
- package/dist/builders/_ComponentState.svelte.js +203 -0
- package/dist/builders/html/HtmlBuilder.d.ts +66 -0
- package/dist/builders/html/HtmlBuilder.js +171 -0
- package/dist/builders/html/HtmlBuilderFactory.d.ts +27 -0
- package/dist/builders/html/HtmlBuilderFactory.js +30 -0
- package/dist/builders/html/StyleBuilder.d.ts +13 -0
- package/dist/builders/html/StyleBuilder.js +133 -0
- package/dist/builders/html/StyleProcessor.d.ts +9 -0
- package/dist/builders/html/StyleProcessor.js +1 -0
- package/dist/builders/html/TextComponentHtmlBuilder.d.ts +16 -0
- package/dist/builders/html/TextComponentHtmlBuilder.js +93 -0
- package/dist/builders/html/TextShadowBuilder.d.ts +60 -0
- package/dist/builders/html/TextShadowBuilder.js +227 -0
- package/dist/builders/html/processors/AppearanceStyleProcessor.d.ts +5 -0
- package/dist/builders/html/processors/AppearanceStyleProcessor.js +57 -0
- package/dist/builders/html/processors/TextAppearanceStyleProcessor.d.ts +5 -0
- package/dist/builders/html/processors/TextAppearanceStyleProcessor.js +37 -0
- package/dist/builders/html/processors/TextEffectsStyleProcessor.d.ts +6 -0
- package/dist/builders/html/processors/TextEffectsStyleProcessor.js +68 -0
- package/dist/commands/Command.d.ts +6 -0
- package/dist/commands/Command.js +1 -0
- package/dist/commands/CommandRunner.d.ts +28 -0
- package/dist/commands/CommandRunner.js +81 -0
- package/dist/commands/CommandTypes.d.ts +11 -0
- package/dist/commands/CommandTypes.js +13 -0
- package/dist/commands/PauseCommand.d.ts +4 -0
- package/dist/commands/PauseCommand.js +5 -0
- package/dist/commands/PlayCommand.d.ts +4 -0
- package/dist/commands/PlayCommand.js +6 -0
- package/dist/commands/RenderCommand.d.ts +15 -0
- package/dist/commands/RenderCommand.js +18 -0
- package/dist/commands/RenderFrameCommand.d.ts +17 -0
- package/dist/commands/RenderFrameCommand.js +93 -0
- package/dist/commands/ReplaceSourceOnTimeCommand.d.ts +4 -0
- package/dist/commands/ReplaceSourceOnTimeCommand.js +22 -0
- package/dist/commands/SeekCommand.d.ts +15 -0
- package/dist/commands/SeekCommand.js +39 -0
- package/dist/commands/UpdateComponentCommand.d.ts +4 -0
- package/dist/commands/UpdateComponentCommand.js +17 -0
- package/dist/components/AnimatedGIF.d.ts +201 -0
- package/dist/components/AnimatedGIF.js +391 -0
- package/dist/components/Component.svelte.d.ts +33 -0
- package/dist/components/Component.svelte.js +152 -0
- package/dist/components/ComponentContext.svelte.d.ts +33 -0
- package/dist/components/ComponentContext.svelte.js +105 -0
- package/dist/components/hooks/AnimationHook.d.ts +25 -0
- package/dist/components/hooks/AnimationHook.js +180 -0
- package/dist/components/hooks/CanvasShapeHook.d.ts +12 -0
- package/dist/components/hooks/CanvasShapeHook.js +229 -0
- package/dist/components/hooks/HtmlAnimationHook.d.ts +8 -0
- package/dist/components/hooks/HtmlAnimationHook.js +70 -0
- package/dist/components/hooks/HtmlTextHook.d.ts +16 -0
- package/dist/components/hooks/HtmlTextHook.js +102 -0
- package/dist/components/hooks/HtmlToCanvasHook.d.ts +16 -0
- package/dist/components/hooks/HtmlToCanvasHook.js +148 -0
- package/dist/components/hooks/ImageHook.d.ts +10 -0
- package/dist/components/hooks/ImageHook.js +45 -0
- package/dist/components/hooks/MediaHook.d.ts +15 -0
- package/dist/components/hooks/MediaHook.js +252 -0
- package/dist/components/hooks/MediaSeekingHook.d.ts +12 -0
- package/dist/components/hooks/MediaSeekingHook.js +204 -0
- package/dist/components/hooks/PixiDisplayObjectHook.d.ts +15 -0
- package/dist/components/hooks/PixiDisplayObjectHook.js +77 -0
- package/dist/components/hooks/PixiGifHook.d.ts +15 -0
- package/dist/components/hooks/PixiGifHook.js +97 -0
- package/dist/components/hooks/PixiProgressShapeHook.d.ts +12 -0
- package/dist/components/hooks/PixiProgressShapeHook.js +128 -0
- package/dist/components/hooks/PixiSplitScreenDisplayObjectHook.d.ts +21 -0
- package/dist/components/hooks/PixiSplitScreenDisplayObjectHook.js +210 -0
- package/dist/components/hooks/PixiTextureHook.d.ts +7 -0
- package/dist/components/hooks/PixiTextureHook.js +29 -0
- package/dist/components/hooks/PixiVideoTextureHook.d.ts +10 -0
- package/dist/components/hooks/PixiVideoTextureHook.js +35 -0
- package/dist/components/hooks/SubtitlesHook.d.ts +88 -0
- package/dist/components/hooks/SubtitlesHook.js +199 -0
- package/dist/components/hooks/VerifyGifHook.d.ts +7 -0
- package/dist/components/hooks/VerifyGifHook.js +27 -0
- package/dist/components/hooks/VerifyImageHook.d.ts +7 -0
- package/dist/components/hooks/VerifyImageHook.js +27 -0
- package/dist/components/hooks/VerifyMediaHook.d.ts +7 -0
- package/dist/components/hooks/VerifyMediaHook.js +21 -0
- package/dist/components/hooks/shapes/progress/CustomProgressRenderer.d.ts +8 -0
- package/dist/components/hooks/shapes/progress/CustomProgressRenderer.js +53 -0
- package/dist/components/hooks/shapes/progress/DoubleProgressRenderer.d.ts +8 -0
- package/dist/components/hooks/shapes/progress/DoubleProgressRenderer.js +69 -0
- package/dist/components/hooks/shapes/progress/LinearProgressRenderer.d.ts +8 -0
- package/dist/components/hooks/shapes/progress/LinearProgressRenderer.js +60 -0
- package/dist/components/hooks/shapes/progress/PerimeterProgressRenderer.d.ts +9 -0
- package/dist/components/hooks/shapes/progress/PerimeterProgressRenderer.js +213 -0
- package/dist/components/hooks/shapes/progress/ProgressRenderer.d.ts +17 -0
- package/dist/components/hooks/shapes/progress/ProgressRenderer.js +75 -0
- package/dist/components/hooks/shapes/progress/RadialProgressRenderer.d.ts +8 -0
- package/dist/components/hooks/shapes/progress/RadialProgressRenderer.js +50 -0
- package/dist/components/hooks/shapes/progress/index.d.ts +6 -0
- package/dist/components/hooks/shapes/progress/index.js +6 -0
- package/dist/composers/componentComposer.d.ts +55 -0
- package/dist/composers/componentComposer.js +118 -0
- package/dist/composers/layerComposer.d.ts +46 -0
- package/dist/composers/layerComposer.js +79 -0
- package/dist/composers/sceneComposer.d.ts +48 -0
- package/dist/composers/sceneComposer.js +92 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.js +14 -0
- package/dist/directors/ComponentDirector.d.ts +20 -0
- package/dist/directors/ComponentDirector.js +86 -0
- package/dist/factories/SceneBuilderFactory.d.ts +15 -0
- package/dist/factories/SceneBuilderFactory.js +51 -0
- package/dist/fonts/GoogleFontsProvider.d.ts +12 -0
- package/dist/fonts/GoogleFontsProvider.js +125 -0
- package/dist/fonts/fontLoader.d.ts +15 -0
- package/dist/fonts/fontLoader.js +41 -0
- package/dist/fonts/types.d.ts +1 -0
- package/dist/fonts/types.js +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +14 -0
- package/dist/layers/Layer.svelte.d.ts +8492 -0
- package/dist/layers/Layer.svelte.js +125 -0
- package/dist/managers/AppManager.svelte.d.ts +23 -0
- package/dist/managers/AppManager.svelte.js +89 -0
- package/dist/managers/ComponentsManager.svelte.d.ts +49 -0
- package/dist/managers/ComponentsManager.svelte.js +247 -0
- package/dist/managers/DomManager.d.ts +18 -0
- package/dist/managers/DomManager.js +73 -0
- package/dist/managers/EventManager.d.ts +7 -0
- package/dist/managers/EventManager.js +22 -0
- package/dist/managers/LayersManager.svelte.d.ts +8499 -0
- package/dist/managers/LayersManager.svelte.js +176 -0
- package/dist/managers/MediaManager.d.ts +32 -0
- package/dist/managers/MediaManager.js +243 -0
- package/dist/managers/RenderManager.d.ts +23 -0
- package/dist/managers/RenderManager.js +59 -0
- package/dist/managers/StateManager.svelte.d.ts +8746 -0
- package/dist/managers/StateManager.svelte.js +272 -0
- package/dist/managers/SubtitlesManager.svelte.d.ts +261 -0
- package/dist/managers/SubtitlesManager.svelte.js +1385 -0
- package/dist/managers/TimeManager.svelte.d.ts +6 -0
- package/dist/managers/TimeManager.svelte.js +18 -0
- package/dist/managers/TimelineManager.svelte.d.ts +25 -0
- package/dist/managers/TimelineManager.svelte.js +152 -0
- package/dist/registers.d.ts +12 -0
- package/dist/registers.js +29 -0
- package/dist/schemas/runtime/index.d.ts +3 -0
- package/dist/schemas/runtime/index.js +4 -0
- package/dist/schemas/runtime/types.d.ts +323 -0
- package/dist/schemas/runtime/types.js +12 -0
- package/dist/schemas/scene/animations.d.ts +89738 -0
- package/dist/schemas/scene/animations.js +211 -0
- package/dist/schemas/scene/components.js +515 -0
- package/dist/schemas/scene/core.js +160 -0
- package/dist/schemas/scene/index.d.ts +22 -0
- package/dist/schemas/scene/index.js +10 -0
- package/dist/schemas/scene/properties.d.ts +914 -0
- package/dist/schemas/scene/properties.js +398 -0
- package/dist/schemas/scene/subtitles.d.ts +1141 -0
- package/dist/schemas/scene/subtitles.js +111 -0
- package/dist/schemas/scene/utils.d.ts +1 -0
- package/dist/schemas/scene/utils.js +5 -0
- package/dist/seeds/SeedFactory.d.ts +59 -0
- package/dist/seeds/SeedFactory.js +99 -0
- package/dist/seeds/index.d.ts +8 -0
- package/dist/seeds/index.js +8 -0
- package/dist/transformers/ColorTransformer.d.ts +5 -0
- package/dist/transformers/ColorTransformer.js +67 -0
- package/dist/transformers/PixiColorTransformer.d.ts +22 -0
- package/dist/transformers/PixiColorTransformer.js +104 -0
- package/dist/utils/canvas.d.ts +6 -0
- package/dist/utils/canvas.js +18 -0
- package/dist/utils/document.d.ts +2 -0
- package/dist/utils/document.js +36 -0
- package/dist/utils/emoji.d.ts +10 -0
- package/dist/utils/emoji.js +51 -0
- package/dist/utils/html.d.ts +4 -0
- package/dist/utils/html.js +45 -0
- package/dist/utils/svgGenerator.d.ts +20 -0
- package/dist/utils/svgGenerator.js +103 -0
- package/dist/utils/utils.d.ts +5 -0
- package/dist/utils/utils.js +125 -0
- package/package.json +96 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class TimeManager {
|
|
2
|
+
fps = $state(30); // Default
|
|
3
|
+
duration = $state(0);
|
|
4
|
+
transformTime(time, skipDurationCheck = false) {
|
|
5
|
+
// Round to nearest frame boundary (1/fps seconds)
|
|
6
|
+
let frameAdjustedTime = Math.round(time * this.fps) / this.fps;
|
|
7
|
+
frameAdjustedTime = Math.max(frameAdjustedTime, 0);
|
|
8
|
+
if (!skipDurationCheck) {
|
|
9
|
+
// Keep duration check since endTime is always <= duration
|
|
10
|
+
return frameAdjustedTime > this.duration ? this.duration : frameAdjustedTime;
|
|
11
|
+
}
|
|
12
|
+
return frameAdjustedTime;
|
|
13
|
+
}
|
|
14
|
+
updateTimeConfig(newFps, newDuration) {
|
|
15
|
+
this.fps = newFps;
|
|
16
|
+
this.duration = newDuration;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StateManager } from './StateManager.svelte.js';
|
|
2
|
+
import { EventManager } from './EventManager.js';
|
|
3
|
+
export declare class TimelineManager {
|
|
4
|
+
#private;
|
|
5
|
+
playbackRate: number;
|
|
6
|
+
private state;
|
|
7
|
+
private eventManager;
|
|
8
|
+
private loop;
|
|
9
|
+
constructor(cradle: {
|
|
10
|
+
stateManager: StateManager;
|
|
11
|
+
eventManager: EventManager;
|
|
12
|
+
loop: boolean;
|
|
13
|
+
});
|
|
14
|
+
private initStateSyncWatchers;
|
|
15
|
+
private watch;
|
|
16
|
+
get timeline(): gsap.core.Timeline;
|
|
17
|
+
get duration(): number;
|
|
18
|
+
add(timeline: gsap.core.Timeline, position?: gsap.Position): void;
|
|
19
|
+
addLabel(label: string, position?: gsap.Position): void;
|
|
20
|
+
seek(requestedTime: number): void;
|
|
21
|
+
play(): void;
|
|
22
|
+
pause(): void;
|
|
23
|
+
setPlaybackRate(rate: number): void;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { StateManager } from './StateManager.svelte.js';
|
|
2
|
+
import { EventManager } from './EventManager.js';
|
|
3
|
+
import gsap from 'gsap';
|
|
4
|
+
const MIN_PLAYBACK_RATE = 0.25;
|
|
5
|
+
const MAX_PLAYBACK_RATE = 4;
|
|
6
|
+
export class TimelineManager {
|
|
7
|
+
#timeline;
|
|
8
|
+
#progressTimeline = undefined;
|
|
9
|
+
#watchTicker;
|
|
10
|
+
playbackRate;
|
|
11
|
+
state;
|
|
12
|
+
eventManager;
|
|
13
|
+
loop;
|
|
14
|
+
constructor(cradle) {
|
|
15
|
+
this.state = cradle.stateManager;
|
|
16
|
+
this.eventManager = cradle.eventManager;
|
|
17
|
+
this.#timeline = gsap.timeline({
|
|
18
|
+
id: this.state.data.id,
|
|
19
|
+
paused: true,
|
|
20
|
+
duration: this.state.duration,
|
|
21
|
+
smoothChildTiming: true,
|
|
22
|
+
repeat: cradle.loop ? -1 : 0,
|
|
23
|
+
onRepeat: () => {
|
|
24
|
+
// when looping, we need to manually reset the timeline's time to the start
|
|
25
|
+
// to prevent the internal time from accumulating indefinitely.
|
|
26
|
+
this.#timeline.seek(this.state.startTime);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
this.loop = cradle.loop;
|
|
30
|
+
// prevent unexpected duration changes when we add other child timelines
|
|
31
|
+
this.#createProgressTimeline();
|
|
32
|
+
if (this.#progressTimeline) {
|
|
33
|
+
this.#timeline.add(this.#progressTimeline, 0);
|
|
34
|
+
}
|
|
35
|
+
const rate = $state(1);
|
|
36
|
+
this.playbackRate = rate;
|
|
37
|
+
this.initStateSyncWatchers();
|
|
38
|
+
}
|
|
39
|
+
#createProgressTimeline() {
|
|
40
|
+
if (this.#progressTimeline) {
|
|
41
|
+
this.#timeline.remove(this.#progressTimeline);
|
|
42
|
+
this.#progressTimeline.kill();
|
|
43
|
+
this.#progressTimeline = undefined;
|
|
44
|
+
}
|
|
45
|
+
const progressObject = { progress: 0 };
|
|
46
|
+
this.#progressTimeline = gsap.to(progressObject, {
|
|
47
|
+
progress: 1,
|
|
48
|
+
duration: this.duration,
|
|
49
|
+
ease: 'none'
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
initStateSyncWatchers() {
|
|
53
|
+
this.#watchTicker = () => this.watch();
|
|
54
|
+
this.eventManager.on('changestate', this.#handleChangeState.bind(this));
|
|
55
|
+
}
|
|
56
|
+
watch() {
|
|
57
|
+
const rawTime = this.timeline.time();
|
|
58
|
+
if (rawTime >= this.state.endTime) {
|
|
59
|
+
if (this.loop) {
|
|
60
|
+
// handle looping - if gsap animation is longer than the timeline, we need to reset the time to the start
|
|
61
|
+
this.seek(this.state.startTime);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// we should pause let's check
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// handle disabled time zones
|
|
69
|
+
const time = Math.max(this.state.startTime, Math.min(rawTime, this.state.endTime));
|
|
70
|
+
this.state.setCurrentTime(time);
|
|
71
|
+
let shouldSeek = false;
|
|
72
|
+
let setTime = time;
|
|
73
|
+
for (const zone of this.state.disabledTimeZones) {
|
|
74
|
+
if (setTime > zone.start && setTime < zone.end) {
|
|
75
|
+
// If time is in a disabled zone, move to the end of the zone
|
|
76
|
+
setTime = zone.end;
|
|
77
|
+
shouldSeek = true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (shouldSeek) {
|
|
81
|
+
this.seek(setTime);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
#handleChangeState() {
|
|
85
|
+
if (this.state.isPlaying) {
|
|
86
|
+
this.state.state === 'playing' ? this.play() : this.pause();
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
this.pause();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// temporary
|
|
93
|
+
get timeline() {
|
|
94
|
+
return this.#timeline;
|
|
95
|
+
}
|
|
96
|
+
get duration() {
|
|
97
|
+
return this.state.duration;
|
|
98
|
+
}
|
|
99
|
+
add(timeline, position) {
|
|
100
|
+
// Defensive check: Forcibly set the duration of the incoming timeline
|
|
101
|
+
// to match the main scene's duration. This prevents any child animations
|
|
102
|
+
// with infinite repeats from breaking the main timeline's duration.
|
|
103
|
+
// timeline.duration(this.state.duration);
|
|
104
|
+
this.timeline.add(timeline, position);
|
|
105
|
+
if (this.timeline.duration() < this.state.duration) {
|
|
106
|
+
// we don't care about main timeline duration, as this is controlled by state
|
|
107
|
+
// we only care that it CAN NOT be shorter
|
|
108
|
+
this.timeline.duration(this.state.duration);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
addLabel(label, position) {
|
|
112
|
+
this.timeline.addLabel(label, position);
|
|
113
|
+
}
|
|
114
|
+
seek(requestedTime) {
|
|
115
|
+
const endTime = this.state.endTime;
|
|
116
|
+
const startTime = this.state.startTime;
|
|
117
|
+
let time = Math.max(startTime, Math.min(requestedTime, endTime));
|
|
118
|
+
// Check if the requested time falls within any disabled zone
|
|
119
|
+
for (const zone of this.state.disabledTimeZones) {
|
|
120
|
+
if (time > zone.start && time < zone.end) {
|
|
121
|
+
// If inside a disabled zone, snap to the nearest boundary
|
|
122
|
+
const distToStart = time - zone.start;
|
|
123
|
+
const distToEnd = zone.end - time;
|
|
124
|
+
time = distToStart < distToEnd ? zone.start : zone.end;
|
|
125
|
+
break; // Assume zones don't overlap, exit after finding the first match
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
this.timeline.seek(time, false);
|
|
129
|
+
this.state.setCurrentTime(this.timeline.time());
|
|
130
|
+
if (this.state.state !== 'playing') {
|
|
131
|
+
this.eventManager.emit('rerender');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
play() {
|
|
135
|
+
gsap.ticker.add(this.#watchTicker);
|
|
136
|
+
this.timeline.play();
|
|
137
|
+
}
|
|
138
|
+
pause() {
|
|
139
|
+
gsap.ticker.remove(this.#watchTicker);
|
|
140
|
+
this.timeline.pause();
|
|
141
|
+
}
|
|
142
|
+
setPlaybackRate(rate) {
|
|
143
|
+
const clampedRate = Math.max(MIN_PLAYBACK_RATE, Math.min(rate, MAX_PLAYBACK_RATE));
|
|
144
|
+
this.playbackRate = clampedRate;
|
|
145
|
+
this.timeline.timeScale(clampedRate);
|
|
146
|
+
}
|
|
147
|
+
destroy() {
|
|
148
|
+
gsap.ticker.remove(this.#watchTicker);
|
|
149
|
+
this.pause();
|
|
150
|
+
this.timeline.kill();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type _SplitText from 'gsap/SplitText';
|
|
2
|
+
type GsapRegistry = {
|
|
3
|
+
ExpoScaleEase: gsap.ExpoScaleEase;
|
|
4
|
+
RoughEase: gsap.RoughEase;
|
|
5
|
+
SlowMo: gsap.SlowMo;
|
|
6
|
+
MotionPathPlugin: gsap.plugins.MotionPathPlugin;
|
|
7
|
+
Physics2DPlugin: gsap.plugins.Physics2DPlugin;
|
|
8
|
+
SplitText: typeof _SplitText;
|
|
9
|
+
PixiPlugin: gsap.plugins.PixiPlugin;
|
|
10
|
+
};
|
|
11
|
+
export declare const registerGsapPlugins: () => Promise<GsapRegistry>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { gsap } from 'gsap';
|
|
2
|
+
let registered;
|
|
3
|
+
export const registerGsapPlugins = async function () {
|
|
4
|
+
if (registered) {
|
|
5
|
+
return registered;
|
|
6
|
+
}
|
|
7
|
+
const { PixiPlugin } = await import('gsap/PixiPlugin');
|
|
8
|
+
const { ExpoScaleEase, RoughEase, SlowMo } = await import('gsap/EasePack');
|
|
9
|
+
const { MotionPathPlugin } = await import('gsap/MotionPathPlugin');
|
|
10
|
+
const { Physics2DPlugin } = await import('gsap/Physics2DPlugin');
|
|
11
|
+
const SplitText = (await import('gsap/SplitText')).default;
|
|
12
|
+
gsap.registerPlugin(ExpoScaleEase, RoughEase, SlowMo, MotionPathPlugin, Physics2DPlugin, SplitText, PixiPlugin);
|
|
13
|
+
registered = {
|
|
14
|
+
ExpoScaleEase,
|
|
15
|
+
RoughEase,
|
|
16
|
+
SlowMo,
|
|
17
|
+
MotionPathPlugin,
|
|
18
|
+
Physics2DPlugin,
|
|
19
|
+
SplitText,
|
|
20
|
+
PixiPlugin
|
|
21
|
+
};
|
|
22
|
+
return registered;
|
|
23
|
+
};
|
|
24
|
+
const getGsapPlugins = function () {
|
|
25
|
+
if (!registered) {
|
|
26
|
+
throw new Error('Plugins were not registered yet.');
|
|
27
|
+
}
|
|
28
|
+
return registered;
|
|
29
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { BuilderState, StateEvents, TimelineEvents, RenderEvents, PlaybackEvents, LayerEvents, ComponentEvents, SubtitlesEvents, EventMap, EventType, EventPayload, ComponentRefreshType, HookType, SceneLayerComponentType, SplitScreenChunk, SplitScreen, } from './types.js';
|
|
2
|
+
export type { MediaComponent, ResourceManager, ComponentData, ComponentProps, PixiComponent, ResourceTypes, HookHandler, HookHandlers, } from './types.js';
|
|
3
|
+
export type { Component as IComponent, Layer as ILayer, SceneBuilder as ISceneBuilder, ComponentContext as IComponentContext, ComponentBuilder as IComponentBuilder, StateManager as IStateManager, ComponentHook as IComponentHook, ComponentBuildStrategy as IComponentBuildStrategy, } from './types.js';
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import type { Container, Texture, Sprite, Application, DisplayObject, RenderTexture, TextureSource } from 'pixi.js-legacy';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { ComponentsManager } from '../../managers/ComponentsManager.svelte.js';
|
|
4
|
+
import type { LayersManager } from '../../managers/LayersManager.svelte.js';
|
|
5
|
+
import type { SubtitlesManager } from '../../managers/SubtitlesManager.svelte.js';
|
|
6
|
+
import type { EventManager } from '../../managers/EventManager.js';
|
|
7
|
+
import type { Component as SceneLayerComponent, ComponentBase, AppearanceInput, Scene, RenderEnvironment, ComponentInput, SceneLayerInput, SceneLayer, VideoComponentShape, ImageComponentShape, GifComponentShape, Subtitle } from '../..';
|
|
8
|
+
declare const SCENE_LAYER_COMPONENT_TYPE: readonly ["IMAGE", "GIF", "VIDEO", "TEXT", "SHAPE", "AUDIO", "COLOR", "GRADIENT", "SUBTITLES"];
|
|
9
|
+
export type SceneLayerComponentType = (typeof SCENE_LAYER_COMPONENT_TYPE)[number];
|
|
10
|
+
type MediaShape = z.infer<typeof VideoComponentShape>;
|
|
11
|
+
type ImageShape = z.infer<typeof ImageComponentShape>;
|
|
12
|
+
type GifShape = z.infer<typeof GifComponentShape>;
|
|
13
|
+
export type BuilderState = 'playing' | 'paused' | 'loading' | 'loading-done' | 'ended';
|
|
14
|
+
export interface StateEvents {
|
|
15
|
+
changestate: {
|
|
16
|
+
state: BuilderState;
|
|
17
|
+
isPlaying: boolean;
|
|
18
|
+
};
|
|
19
|
+
rerender: void;
|
|
20
|
+
}
|
|
21
|
+
export interface TimelineEvents {
|
|
22
|
+
timeupdate: number;
|
|
23
|
+
seek: number;
|
|
24
|
+
}
|
|
25
|
+
export interface RenderEvents {
|
|
26
|
+
beforerender: void;
|
|
27
|
+
afterrender: void;
|
|
28
|
+
render: void;
|
|
29
|
+
}
|
|
30
|
+
export interface PlaybackEvents {
|
|
31
|
+
play: void;
|
|
32
|
+
pause: void;
|
|
33
|
+
}
|
|
34
|
+
export interface LayerEvents {
|
|
35
|
+
layerschange: void;
|
|
36
|
+
}
|
|
37
|
+
export interface ComponentEvents {
|
|
38
|
+
componentschange: void;
|
|
39
|
+
componentchange: ComponentData;
|
|
40
|
+
}
|
|
41
|
+
export interface SubtitlesEvents {
|
|
42
|
+
subtitleschange: void;
|
|
43
|
+
subtitlessettingschange: void;
|
|
44
|
+
subtitlechange: {
|
|
45
|
+
assetId: string;
|
|
46
|
+
language: string;
|
|
47
|
+
subtitleId: string;
|
|
48
|
+
subtitle: Subtitle;
|
|
49
|
+
};
|
|
50
|
+
subtitlesplit: {
|
|
51
|
+
assetId: string;
|
|
52
|
+
language: string;
|
|
53
|
+
subtitleId: string;
|
|
54
|
+
subtitle: Subtitle;
|
|
55
|
+
newSubtitle: Subtitle;
|
|
56
|
+
};
|
|
57
|
+
subtitlemerge: {
|
|
58
|
+
assetId: string;
|
|
59
|
+
language: string;
|
|
60
|
+
targetSubtitle: Subtitle;
|
|
61
|
+
sourceSubtitle: Subtitle;
|
|
62
|
+
mergeTo: 'start' | 'end';
|
|
63
|
+
};
|
|
64
|
+
subtitledelete: {
|
|
65
|
+
assetId: string;
|
|
66
|
+
language: string;
|
|
67
|
+
subtitleId: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export type EventMap = StateEvents & TimelineEvents & RenderEvents & PlaybackEvents & LayerEvents & ComponentEvents & SubtitlesEvents;
|
|
71
|
+
export type EventType = keyof EventMap;
|
|
72
|
+
export type EventPayload<T extends EventType> = EventMap[T];
|
|
73
|
+
export interface MediaComponent {
|
|
74
|
+
play: () => void;
|
|
75
|
+
pause: () => void;
|
|
76
|
+
seek: (time: number) => Promise<void>;
|
|
77
|
+
autoSeek: () => Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
export interface ResourceManager<T, D, F> {
|
|
80
|
+
get(id: string): T | undefined;
|
|
81
|
+
getAll(): T[];
|
|
82
|
+
update(id: string, data: Partial<F>, refreshType?: ComponentRefreshType): void;
|
|
83
|
+
delete(id: string): void;
|
|
84
|
+
create(data: D): Promise<T | null>;
|
|
85
|
+
setOrder(id: string, newOrder: number): void;
|
|
86
|
+
moveUp(id: string): void;
|
|
87
|
+
moveDown(id: string): void;
|
|
88
|
+
moveToTop(id: string): void;
|
|
89
|
+
moveToBottom(id: string): void;
|
|
90
|
+
bulkUpdate(updates: Array<{
|
|
91
|
+
id: string;
|
|
92
|
+
data: Partial<F>;
|
|
93
|
+
}>): void;
|
|
94
|
+
bulkDelete(ids: string[]): void;
|
|
95
|
+
hide(id: string): void;
|
|
96
|
+
show(id: string): void;
|
|
97
|
+
toggle(id: string): void;
|
|
98
|
+
filter(predicate: (item: T) => boolean): T[];
|
|
99
|
+
}
|
|
100
|
+
export type ComponentData = SceneLayerComponent;
|
|
101
|
+
export type ComponentProps = ComponentBase & {
|
|
102
|
+
checksum: string;
|
|
103
|
+
duration: number;
|
|
104
|
+
setStart(start: number): void;
|
|
105
|
+
setEnd(end: number): void;
|
|
106
|
+
getData(): ComponentData;
|
|
107
|
+
update(data: Partial<AppearanceInput>): void;
|
|
108
|
+
updateText(text: string): Promise<void>;
|
|
109
|
+
updateAppearance(appearance: Partial<AppearanceInput>): Promise<void>;
|
|
110
|
+
setVisible(visible: boolean): Promise<void>;
|
|
111
|
+
setOrder(order: number): Promise<void>;
|
|
112
|
+
};
|
|
113
|
+
export interface PixiComponent {
|
|
114
|
+
displayObject: Container;
|
|
115
|
+
}
|
|
116
|
+
export interface ComponentBuilder {
|
|
117
|
+
getComponent(): Component;
|
|
118
|
+
withMedia(): ComponentBuilder;
|
|
119
|
+
withMediaSeeking(): ComponentBuilder;
|
|
120
|
+
withVideoTexture(): ComponentBuilder;
|
|
121
|
+
withSplitScreen(): ComponentBuilder;
|
|
122
|
+
withHtmlText(): ComponentBuilder;
|
|
123
|
+
withHtmlAnimation(): ComponentBuilder;
|
|
124
|
+
withAnimation(): ComponentBuilder;
|
|
125
|
+
withSubtitles(): ComponentBuilder;
|
|
126
|
+
withDisplayObject(): ComponentBuilder;
|
|
127
|
+
withTexture(): ComponentBuilder;
|
|
128
|
+
withImage(): ComponentBuilder;
|
|
129
|
+
withDisplayObject(): ComponentBuilder;
|
|
130
|
+
withGif(): ComponentBuilder;
|
|
131
|
+
withShape(): ComponentBuilder;
|
|
132
|
+
withCanvasShape(): ComponentBuilder;
|
|
133
|
+
withProgressShape(): ComponentBuilder;
|
|
134
|
+
withHtmlToCanvasHook(): ComponentBuilder;
|
|
135
|
+
}
|
|
136
|
+
export interface Component {
|
|
137
|
+
readonly id: string;
|
|
138
|
+
readonly type: SceneLayerComponentType;
|
|
139
|
+
readonly props: ComponentProps;
|
|
140
|
+
readonly displayObject: Container | undefined;
|
|
141
|
+
readonly checksum: string;
|
|
142
|
+
readonly context: ComponentContext;
|
|
143
|
+
readonly autoRefresh: boolean;
|
|
144
|
+
setAutoRefresh(enabled: boolean): Component;
|
|
145
|
+
addHook(hook: ComponentHook, priority?: number): void;
|
|
146
|
+
setup(): void;
|
|
147
|
+
update(): void;
|
|
148
|
+
refresh(type?: ComponentRefreshType): void;
|
|
149
|
+
destroy(): void;
|
|
150
|
+
setStart(start: number): Component;
|
|
151
|
+
setEnd(end: number): Component;
|
|
152
|
+
updateAppearance(appearance: Partial<AppearanceInput>): Promise<Component>;
|
|
153
|
+
updateText(text: string): Promise<Component>;
|
|
154
|
+
setText(text: string): Promise<Component>;
|
|
155
|
+
setVisible(visible: boolean): Promise<Component>;
|
|
156
|
+
setOrder(order: number): Promise<Component>;
|
|
157
|
+
onChange(callback: (changes: ComponentData) => void): () => void;
|
|
158
|
+
onTimelineChange(callback: (time: number) => void): () => void;
|
|
159
|
+
}
|
|
160
|
+
export interface Layer {
|
|
161
|
+
readonly id: string;
|
|
162
|
+
readonly checksum: string;
|
|
163
|
+
readonly displayObject: Container | undefined;
|
|
164
|
+
components: Component[];
|
|
165
|
+
name: string;
|
|
166
|
+
order: number;
|
|
167
|
+
visible?: boolean;
|
|
168
|
+
update(layerData: Partial<SceneLayerInput>): void;
|
|
169
|
+
addComponent(component: Component): void;
|
|
170
|
+
removeComponent(component: Component): void;
|
|
171
|
+
build(): Promise<void>;
|
|
172
|
+
setOrder(order: number): void;
|
|
173
|
+
getData(): SceneLayer;
|
|
174
|
+
destroy(): void;
|
|
175
|
+
}
|
|
176
|
+
export interface ResourceTypes {
|
|
177
|
+
videoElement: HTMLVideoElement | undefined;
|
|
178
|
+
audioElement: HTMLAudioElement | undefined;
|
|
179
|
+
imageElement: HTMLImageElement | undefined;
|
|
180
|
+
pixiResource: TextureSource | undefined;
|
|
181
|
+
pixiTexture: Texture | undefined;
|
|
182
|
+
pixiSprite: Sprite | undefined;
|
|
183
|
+
pixiContainer: Container | undefined;
|
|
184
|
+
wrapperHtmlEl: HTMLElement | undefined;
|
|
185
|
+
htmlEl: HTMLElement | undefined;
|
|
186
|
+
animationTarget: HTMLElement | Container | undefined;
|
|
187
|
+
animationData: Record<string, any> | undefined;
|
|
188
|
+
pixiRenderObject: Container | undefined;
|
|
189
|
+
htmlRenderObject: HTMLDivElement | undefined;
|
|
190
|
+
mediaShape: MediaShape | undefined;
|
|
191
|
+
imageShape: ImageShape | undefined;
|
|
192
|
+
gifShape: GifShape | undefined;
|
|
193
|
+
}
|
|
194
|
+
export interface ComponentContext {
|
|
195
|
+
id: string;
|
|
196
|
+
type: string;
|
|
197
|
+
data: ComponentData;
|
|
198
|
+
contextData: ComponentData;
|
|
199
|
+
eventManager: EventManager;
|
|
200
|
+
isActive: boolean;
|
|
201
|
+
currentComponentTime: number;
|
|
202
|
+
componentTimelineTime?: number;
|
|
203
|
+
sceneState: StateManager;
|
|
204
|
+
disabled: boolean;
|
|
205
|
+
progress: number;
|
|
206
|
+
duration: number;
|
|
207
|
+
resources: Map<keyof ResourceTypes, ResourceTypes[keyof ResourceTypes]>;
|
|
208
|
+
setComponentProps(props: ComponentProps): void;
|
|
209
|
+
updateContextData(data: ComponentData): void;
|
|
210
|
+
resetContextData(): void;
|
|
211
|
+
getResource<K extends keyof ResourceTypes>(type: K): ResourceTypes[K];
|
|
212
|
+
setResource<K extends keyof ResourceTypes>(type: K, resource: ResourceTypes[K]): void;
|
|
213
|
+
removeResource<K extends keyof ResourceTypes>(type: K): void;
|
|
214
|
+
runHooks(handlers: ComponentHook[], type: HookType): Promise<void>;
|
|
215
|
+
destroy(): void;
|
|
216
|
+
}
|
|
217
|
+
type Zone = {
|
|
218
|
+
start: number;
|
|
219
|
+
end: number;
|
|
220
|
+
};
|
|
221
|
+
export interface SceneBuilder {
|
|
222
|
+
readonly sceneData: Scene;
|
|
223
|
+
readonly environment: RenderEnvironment;
|
|
224
|
+
readonly state: BuilderState;
|
|
225
|
+
readonly isPlaying: boolean;
|
|
226
|
+
readonly isLoading: boolean;
|
|
227
|
+
readonly currentTime: number;
|
|
228
|
+
readonly currentFrame: number;
|
|
229
|
+
readonly duration: number;
|
|
230
|
+
readonly progress: number;
|
|
231
|
+
readonly app: Application;
|
|
232
|
+
readonly timeline: gsap.core.Timeline;
|
|
233
|
+
readonly fps: number;
|
|
234
|
+
readonly layers: LayersManager;
|
|
235
|
+
readonly components: ComponentsManager;
|
|
236
|
+
readonly subtitles: SubtitlesManager;
|
|
237
|
+
readonly htmlContainer: HTMLElement;
|
|
238
|
+
readonly canvasContainer: HTMLElement;
|
|
239
|
+
readonly disabledTimeZones: Zone[];
|
|
240
|
+
syncChanges: () => void;
|
|
241
|
+
addExcludedTimestamp(start: number, end: number): void;
|
|
242
|
+
removeExcludedTimestampsBetween(start: number, end: number): void;
|
|
243
|
+
setStartAt(start: number | undefined): void;
|
|
244
|
+
setEndAt(end: number | undefined): void;
|
|
245
|
+
dispatchEvent<T extends EventType>(event: T, props?: EventPayload<T>): void;
|
|
246
|
+
addEventListener<K extends keyof EventMap>(event: K, callback: (event: CustomEvent<EventMap[K]>) => void, options?: boolean | AddEventListenerOptions): void;
|
|
247
|
+
removeEventListener<K extends keyof EventMap>(event: K, callback: (event: CustomEvent<EventMap[K]>) => void, options?: boolean | AddEventListenerOptions): void;
|
|
248
|
+
scale(scale: number): void;
|
|
249
|
+
initialize(): Promise<void>;
|
|
250
|
+
seek(time: number): Promise<void>;
|
|
251
|
+
replaceSourceOnTime(time: number, componentId: string, base64data: string): Promise<void>;
|
|
252
|
+
seekAndRenderFrame(time: number, target?: DisplayObject | RenderTexture, format?: string, quality?: number): Promise<string | ArrayBuffer | Blob>;
|
|
253
|
+
isSceneDirty(time: number): Promise<boolean>;
|
|
254
|
+
renderFrame(target?: DisplayObject | RenderTexture, format?: string, quality?: number): Promise<string | ArrayBuffer | Blob>;
|
|
255
|
+
log(message: string): void;
|
|
256
|
+
play(changeState?: boolean): void;
|
|
257
|
+
pause(changeState?: boolean): void;
|
|
258
|
+
setPlaybackRate(rate: number): void;
|
|
259
|
+
addLoadingComponent(componentId: string): void;
|
|
260
|
+
removeLoadingComponent(componentId: string): void;
|
|
261
|
+
buildCharactersList(): void;
|
|
262
|
+
render(): void;
|
|
263
|
+
destroy(): void;
|
|
264
|
+
addComponent(componentData: ComponentInput): Promise<ComponentData | undefined>;
|
|
265
|
+
addLayer(layerInput: SceneLayerInput): Promise<Layer | undefined>;
|
|
266
|
+
addNewLayerWithComponents(components: ComponentInput[]): Promise<Layer | undefined>;
|
|
267
|
+
splitComponent(component: Component): Promise<boolean>;
|
|
268
|
+
}
|
|
269
|
+
export interface StateManager {
|
|
270
|
+
state: BuilderState;
|
|
271
|
+
isPlaying: boolean;
|
|
272
|
+
renderAfterLoadingFinished: boolean;
|
|
273
|
+
currentTime: number;
|
|
274
|
+
currentFrame: number;
|
|
275
|
+
duration: number;
|
|
276
|
+
width: number;
|
|
277
|
+
height: number;
|
|
278
|
+
scale: number;
|
|
279
|
+
setScale(scale: number): void;
|
|
280
|
+
setCurrentTime(time: number): void;
|
|
281
|
+
changeState(updateState: 'playing' | 'paused'): void;
|
|
282
|
+
setDuration(dur: number): void;
|
|
283
|
+
setRenderAfterLoadingFinished(newVal: boolean): void;
|
|
284
|
+
addLoadingComponent(componentId: string): void;
|
|
285
|
+
removeLoadingComponent(componentId: string): void;
|
|
286
|
+
destroy(): void;
|
|
287
|
+
}
|
|
288
|
+
export type ComponentRefreshType = 'refresh' | 'refresh:content' | 'refresh:config' | 'refresh:metadata' | 'refresh:animation' | 'refresh:audio';
|
|
289
|
+
export type HookType = 'setup' | 'update' | 'destroy' | ComponentRefreshType;
|
|
290
|
+
export interface ComponentHook {
|
|
291
|
+
types: HookType[];
|
|
292
|
+
priority: number;
|
|
293
|
+
handle(type: HookType, context: ComponentContext): Promise<void>;
|
|
294
|
+
}
|
|
295
|
+
export type HookHandler = () => Promise<void>;
|
|
296
|
+
export type HookHandlers = {
|
|
297
|
+
[K in HookType]?: HookHandler;
|
|
298
|
+
};
|
|
299
|
+
export interface ComponentBuildStrategy {
|
|
300
|
+
build(data: ComponentData): Component;
|
|
301
|
+
}
|
|
302
|
+
export type SplitScreenChunk = {
|
|
303
|
+
group: {
|
|
304
|
+
x: number;
|
|
305
|
+
y: number;
|
|
306
|
+
width: number;
|
|
307
|
+
height: number;
|
|
308
|
+
};
|
|
309
|
+
component: {
|
|
310
|
+
x: number;
|
|
311
|
+
y: number;
|
|
312
|
+
width: number;
|
|
313
|
+
height: number;
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
export type SplitScreen = {
|
|
317
|
+
enabled: boolean;
|
|
318
|
+
pieces: number;
|
|
319
|
+
sceneWidth: number;
|
|
320
|
+
sceneHeight: number;
|
|
321
|
+
chunks: SplitScreenChunk[];
|
|
322
|
+
};
|
|
323
|
+
export {};
|