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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ContentFries
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# VisualFries
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/visualfries)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
**VisualFries** is a **Svelte 5** library for programmatically creating (not just) bite-sized video content for social media. Built on PIXI.js and GSAP (for powerful animations), it's designed primarily for headless rendering of dynamic scenes.
|
|
7
|
+
|
|
8
|
+
A key feature of VisualFries is its unique approach to text rendering. It uses SVG `<foreignObject>` to render standard HTML and CSS, allowing you to style scenes and create complex text animations with familiar tools and the full power of GSAP.
|
|
9
|
+
|
|
10
|
+
> ⚠️ **Alpha Software Notice** ⚠️
|
|
11
|
+
>
|
|
12
|
+
> This library is currently in an **alpha** stage. It is not recommended for production use. The API is unstable and may change without notice. There are known bugs and likely many unknown ones. I welcome feedback and bug reports, but please be aware of its experimental nature.
|
|
13
|
+
|
|
14
|
+
## Project Philosophy & Status
|
|
15
|
+
|
|
16
|
+
**VisualFries is currently a solo project maintained by me, its creator.** I use this as a backbone of my SaaS, ContentFries.
|
|
17
|
+
|
|
18
|
+
This means development is driven by a singular vision and you have a direct line to the person who built it. It also means resources are limited. I'm opening this up to the community to share what I've built, get feedback, and see where it goes. I wholeheartedly welcome contributions, bug reports, and ideas.
|
|
19
|
+
|
|
20
|
+
## Key Features
|
|
21
|
+
|
|
22
|
+
- **Built for Svelte 5:**
|
|
23
|
+
- **Declarative, JSON-based Scenes:** Define your entire video as a structured, type-safe JSON object.
|
|
24
|
+
- **HTML & CSS for Text:** Style text and overlays with standard CSS. No need to learn a proprietary canvas styling API.
|
|
25
|
+
- **Powerful Animation Engine:** Leverage the full GSAP ecosystem for complex, timeline-based animations.
|
|
26
|
+
- **Component-Based Architecture:** Build scenes by composing Videos, Images, Text, Shapes, and Subtitles.
|
|
27
|
+
- **Fluent Scene Composition:** Use composer utilities to programmatically build scenes, layers, and components with a clean, chainable API.
|
|
28
|
+
- **Headless & Server-Side Ready:** Designed for automated, server-side video generation.
|
|
29
|
+
- **MIT Licensed:** Truly open-source and free for all uses.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
**Prerequisite:** Your project must be using **Svelte 5** or newer.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install visualfries
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
The best way to use VisualFries is within a Svelte component.
|
|
42
|
+
|
|
43
|
+
```svelte
|
|
44
|
+
<!-- src/routes/+page.svelte -->
|
|
45
|
+
<script lang="ts">
|
|
46
|
+
import { onMount, onDestroy } from 'svelte';
|
|
47
|
+
import { createSceneBuilder, type ISceneBuilder, type Scene } from 'visualfries';
|
|
48
|
+
|
|
49
|
+
let canvasContainer: HTMLDivElement;
|
|
50
|
+
let sceneBuilder: ISceneBuilder;
|
|
51
|
+
|
|
52
|
+
// Define your scene using a declarative JSON object
|
|
53
|
+
const myScene: Scene = {
|
|
54
|
+
id: 'my-first-scene',
|
|
55
|
+
version: '2.0',
|
|
56
|
+
settings: {
|
|
57
|
+
width: 1080,
|
|
58
|
+
height: 1080,
|
|
59
|
+
duration: 10,
|
|
60
|
+
fps: 30,
|
|
61
|
+
backgroundColor: '#1a1a1a'
|
|
62
|
+
},
|
|
63
|
+
layers: [
|
|
64
|
+
// ... your layers and components defined here
|
|
65
|
+
],
|
|
66
|
+
assets: []
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
onMount(async () => {
|
|
70
|
+
if (canvasContainer) {
|
|
71
|
+
sceneBuilder = await createSceneBuilder(myScene, canvasContainer, {
|
|
72
|
+
environment: 'client',
|
|
73
|
+
autoPlay: true
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
onDestroy(() => {
|
|
79
|
+
sceneBuilder?.destroy();
|
|
80
|
+
});
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<div class="scene-container" bind:this={canvasContainer} />
|
|
84
|
+
|
|
85
|
+
<style>
|
|
86
|
+
.scene-container {
|
|
87
|
+
width: 540px; /* Example scaled size */
|
|
88
|
+
height: 540px;
|
|
89
|
+
border: 1px solid #333;
|
|
90
|
+
}
|
|
91
|
+
</style>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Scene Composition API
|
|
95
|
+
|
|
96
|
+
While you can write the scene JSON by hand, the library includes a fluent API to make this process simple and type-safe.
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { createSceneComposer, createLayerComposer, createComponentComposer } from 'visualfries';
|
|
100
|
+
|
|
101
|
+
// 1. Create a composer for a TEXT component
|
|
102
|
+
const headline = createComponentComposer('headline-text', 'TEXT', { startAt: 0, endAt: 5 })
|
|
103
|
+
.setAppearance({
|
|
104
|
+
x: 50,
|
|
105
|
+
y: 100,
|
|
106
|
+
width: 980,
|
|
107
|
+
height: 250,
|
|
108
|
+
text: {
|
|
109
|
+
fontFamily: 'Montserrat',
|
|
110
|
+
fontSize: 90,
|
|
111
|
+
fontWeight: '800',
|
|
112
|
+
color: '#FFFFFF',
|
|
113
|
+
textAlign: 'center'
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
.setText('Hello, VisualFries!')
|
|
117
|
+
.compose();
|
|
118
|
+
|
|
119
|
+
// 2. Create a layer and add the component
|
|
120
|
+
const mainLayer = createLayerComposer('layer-1').addComponent(headline).compose();
|
|
121
|
+
|
|
122
|
+
// 3. Create the scene
|
|
123
|
+
const myScene = createSceneComposer('my-scene', {
|
|
124
|
+
width: 1080,
|
|
125
|
+
height: 1080,
|
|
126
|
+
duration: 10,
|
|
127
|
+
fps: 30
|
|
128
|
+
})
|
|
129
|
+
.addLayer(mainLayer)
|
|
130
|
+
.compose();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Custom Fonts Support
|
|
134
|
+
|
|
135
|
+
VisualFries needs to load font files (.ttf, .woff2, etc.) to render text. The library uses a flexible font provider chain to allow you to load fonts from any source while retaining default support for Google Fonts.
|
|
136
|
+
|
|
137
|
+
### Default Behavior: Google Fonts
|
|
138
|
+
|
|
139
|
+
By default, with no configuration, VisualFries will automatically fetch fonts from Google Fonts. This works out of the box for any client-side application.
|
|
140
|
+
|
|
141
|
+
### Extending Font Loading
|
|
142
|
+
|
|
143
|
+
Instead of replacing the default behavior, you can add your own font providers to the front of the chain. This is the recommended approach for loading local or custom fonts.
|
|
144
|
+
|
|
145
|
+
A font provider is a simple async function that receives a font family and must return a Promise<ArrayBuffer | null>. If it returns null, the library will try the next provider in the chain.
|
|
146
|
+
|
|
147
|
+
**Example:** Adding a provider for local fonts while keeping Google Fonts as a fallback.
|
|
148
|
+
|
|
149
|
+
Create your custom provider:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// src/lib/localFontProvider.ts
|
|
153
|
+
import type { FontProvider } from 'visualfries';
|
|
154
|
+
|
|
155
|
+
export const localFontProvider: FontProvider = async (fontFamily) => {
|
|
156
|
+
// We only handle fonts that start with our special prefix
|
|
157
|
+
if (!fontFamily.startsWith('local://')) {
|
|
158
|
+
// For all other fonts (e.g., "Roboto"), we do nothing and
|
|
159
|
+
// let the next provider in the chain (the Google provider) handle it.
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const fontName = fontFamily.replace('local://', '');
|
|
164
|
+
const fontUrl = `/fonts/${fontName}.ttf`; // Assuming fonts are in /static/fonts
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
const response = await fetch(fontUrl);
|
|
168
|
+
if (!response.ok) {
|
|
169
|
+
console.error(`Failed to load local font: ${fontUrl}`);
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
return response.arrayBuffer();
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error(`Error fetching local font: ${fontUrl}`, error);
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Configure the fontProviders array:
|
|
181
|
+
|
|
182
|
+
When initializing the SceneBuilder, provide your custom provider and the default Google Fonts provider. The library will check yours first.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
// In your Svelte component
|
|
186
|
+
import { createSceneBuilder, createGoogleFontsProvider } from 'visualfries';
|
|
187
|
+
import { localFontProvider } from '$lib/localFontProvider';
|
|
188
|
+
|
|
189
|
+
const builder = await createSceneBuilder(sceneData, container, {
|
|
190
|
+
environment: 'client',
|
|
191
|
+
fontProviders: [
|
|
192
|
+
// 1. Your provider is checked first.
|
|
193
|
+
localFontProvider,
|
|
194
|
+
|
|
195
|
+
// 2. If your provider returns null, the default provider is checked next.
|
|
196
|
+
createGoogleFontsProvider()
|
|
197
|
+
]
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Contributing
|
|
202
|
+
|
|
203
|
+
As an early-stage, solo-developed project, contributions are highly encouraged! The best way to contribute right now is by:
|
|
204
|
+
|
|
205
|
+
- Opening an issue to report a bug or suggest a feature
|
|
206
|
+
- Improving the documentation by clarifying confusing sections or adding new examples
|
|
207
|
+
- Sharing your creations! Seeing what people build is the best motivation
|
|
208
|
+
|
|
209
|
+
Please feel free to get in touch through GitHub Issues.
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
VisualFries is licensed under the MIT License.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type AwilixContainer } from 'awilix/browser';
|
|
2
|
+
import type { Scene as SceneData } from './';
|
|
3
|
+
export declare const registerNewContainer: (data: SceneData, instances: [string, unknown][]) => AwilixContainer;
|
|
4
|
+
export declare const removeContainer: (sceneId: string) => void;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { createContainer, asClass, asValue, Lifetime } from 'awilix/browser';
|
|
2
|
+
import { SceneBuilder } from './SceneBuilder.svelte.js';
|
|
3
|
+
import { RenderManager } from './managers/RenderManager.js';
|
|
4
|
+
import { StateManager } from './managers/StateManager.svelte.js';
|
|
5
|
+
import { TimelineManager } from './managers/TimelineManager.svelte.js';
|
|
6
|
+
import { EventManager } from './managers/EventManager.js';
|
|
7
|
+
import { DomManager } from './managers/DomManager.js';
|
|
8
|
+
import { AppManager } from './managers/AppManager.svelte.js';
|
|
9
|
+
import { ComponentsManager } from './managers/ComponentsManager.svelte.js';
|
|
10
|
+
import { MediaManager } from './managers/MediaManager.js';
|
|
11
|
+
import { SubtitlesManager } from './managers/SubtitlesManager.svelte.js';
|
|
12
|
+
import { ComponentDirector } from './directors/ComponentDirector.js';
|
|
13
|
+
import { PixiComponentBuilder } from './builders/PixiComponentBuilder.js';
|
|
14
|
+
import { MediaHook } from './components/hooks/MediaHook.js';
|
|
15
|
+
import { VerifyMediaHook } from './components/hooks/VerifyMediaHook.js';
|
|
16
|
+
import { ImageHook } from './components/hooks/ImageHook.js';
|
|
17
|
+
import { VerifyImageHook } from './components/hooks/VerifyImageHook.js';
|
|
18
|
+
import { PixiVideoTextureHook } from './components/hooks/PixiVideoTextureHook.js';
|
|
19
|
+
import { PixiSplitScreenDisplayObjectHook } from './components/hooks/PixiSplitScreenDisplayObjectHook.js';
|
|
20
|
+
import { HtmlTextHook } from './components/hooks/HtmlTextHook.js';
|
|
21
|
+
import { HtmlAnimationHook } from './components/hooks/HtmlAnimationHook.js';
|
|
22
|
+
import { AnimationHook } from './components/hooks/AnimationHook.js';
|
|
23
|
+
import { SubtitlesHook } from './components/hooks/SubtitlesHook.js';
|
|
24
|
+
import { PixiTextureHook } from './components/hooks/PixiTextureHook.js';
|
|
25
|
+
import { PixiDisplayObjectHook } from './components/hooks/PixiDisplayObjectHook.js';
|
|
26
|
+
import { PixiGifHook } from './components/hooks/PixiGifHook.js';
|
|
27
|
+
import { CanvasShapeHook } from './components/hooks/CanvasShapeHook.js';
|
|
28
|
+
import { PixiProgressShapeHook } from './components/hooks/PixiProgressShapeHook.js';
|
|
29
|
+
import { HtmlToCanvasHook } from './components/hooks/HtmlToCanvasHook.js';
|
|
30
|
+
import { PlayCommand } from './commands/PlayCommand.js';
|
|
31
|
+
import { PauseCommand } from './commands/PauseCommand.js';
|
|
32
|
+
import { SeekCommand } from './commands/SeekCommand.js';
|
|
33
|
+
import { ReplaceSourceOnTimeCommand } from './commands/ReplaceSourceOnTimeCommand.js';
|
|
34
|
+
import { RenderFrameCommand } from './commands/RenderFrameCommand.js';
|
|
35
|
+
import { UpdateComponentCommand } from './commands/UpdateComponentCommand.js';
|
|
36
|
+
import { RenderCommand } from './commands/RenderCommand.js';
|
|
37
|
+
import { CommandRunner } from './commands/CommandRunner.js';
|
|
38
|
+
import { Component } from './components/Component.svelte.js';
|
|
39
|
+
import { ComponentContext } from './components/ComponentContext.svelte.js';
|
|
40
|
+
import { Layer } from './layers/Layer.svelte.js';
|
|
41
|
+
import { LayersManager } from './managers/LayersManager.svelte.js';
|
|
42
|
+
import { MediaSeekingHook } from './components/hooks/MediaSeekingHook.js';
|
|
43
|
+
import { VerifyGifHook } from './components/hooks/VerifyGifHook.js';
|
|
44
|
+
import { ComponentAnimationTransformer } from './animations/transformers/AnimationReferenceTransformer.js';
|
|
45
|
+
import { AnimationPresetsRegister } from './animations/AnimationPresetsRegister.js';
|
|
46
|
+
import { SplitTextCache } from './animations/SplitTextCache.js';
|
|
47
|
+
import { TimeManager } from './managers/TimeManager.svelte.js';
|
|
48
|
+
const containers = new Map();
|
|
49
|
+
export const registerNewContainer = function (data, instances) {
|
|
50
|
+
if (containers.has(data.id)) {
|
|
51
|
+
return containers.get(data.id);
|
|
52
|
+
}
|
|
53
|
+
const childContainer = createContainer();
|
|
54
|
+
const paramMap = new Map(instances);
|
|
55
|
+
const subtitlesCollection = paramMap.get('subtitlesCollection') || {};
|
|
56
|
+
// Register constant values
|
|
57
|
+
childContainer.register({
|
|
58
|
+
containerId: asValue(data.id),
|
|
59
|
+
sceneData: asValue(data),
|
|
60
|
+
container: asValue(childContainer),
|
|
61
|
+
...Object.fromEntries(instances.map(([name, value]) => [
|
|
62
|
+
name, // Awilix uses lowercase by convention
|
|
63
|
+
asValue(value)
|
|
64
|
+
]))
|
|
65
|
+
});
|
|
66
|
+
// Register all managers as singletons
|
|
67
|
+
childContainer.register({
|
|
68
|
+
timeManager: asClass(TimeManager, { lifetime: Lifetime.SINGLETON }),
|
|
69
|
+
subtitlesManager: asClass(SubtitlesManager, { lifetime: Lifetime.SINGLETON }),
|
|
70
|
+
stateManager: asClass(StateManager, { lifetime: Lifetime.SINGLETON }),
|
|
71
|
+
appManager: asClass(AppManager, { lifetime: Lifetime.SINGLETON }),
|
|
72
|
+
eventManager: asClass(EventManager, { lifetime: Lifetime.SINGLETON }),
|
|
73
|
+
timelineManager: asClass(TimelineManager, { lifetime: Lifetime.SINGLETON }),
|
|
74
|
+
componentsManager: asClass(ComponentsManager, { lifetime: Lifetime.SINGLETON }),
|
|
75
|
+
renderManager: asClass(RenderManager, { lifetime: Lifetime.SINGLETON }),
|
|
76
|
+
domManager: asClass(DomManager, { lifetime: Lifetime.SINGLETON }),
|
|
77
|
+
mediaManager: asClass(MediaManager, { lifetime: Lifetime.SINGLETON }),
|
|
78
|
+
sceneBuilder: asClass(SceneBuilder, { lifetime: Lifetime.SINGLETON }),
|
|
79
|
+
layersManager: asClass(LayersManager, { lifetime: Lifetime.SINGLETON }),
|
|
80
|
+
// transients
|
|
81
|
+
// SceneBuilder ?
|
|
82
|
+
componentDirector: asClass(ComponentDirector),
|
|
83
|
+
pixiComponentBuilder: asClass(PixiComponentBuilder),
|
|
84
|
+
mediaHook: asClass(MediaHook, { lifetime: Lifetime.TRANSIENT }),
|
|
85
|
+
mediaSeekingHook: asClass(MediaSeekingHook, { lifetime: Lifetime.TRANSIENT }),
|
|
86
|
+
verifyMediaHook: asClass(VerifyMediaHook, { lifetime: Lifetime.TRANSIENT }),
|
|
87
|
+
imageHook: asClass(ImageHook, { lifetime: Lifetime.TRANSIENT }),
|
|
88
|
+
verifyImageHook: asClass(VerifyImageHook, { lifetime: Lifetime.TRANSIENT }),
|
|
89
|
+
verifyGifHook: asClass(VerifyGifHook, { lifetime: Lifetime.TRANSIENT }),
|
|
90
|
+
videoTextureHook: asClass(PixiVideoTextureHook, { lifetime: Lifetime.TRANSIENT }),
|
|
91
|
+
splitScreenHook: asClass(PixiSplitScreenDisplayObjectHook, { lifetime: Lifetime.TRANSIENT }),
|
|
92
|
+
htmlTextHook: asClass(HtmlTextHook, { lifetime: Lifetime.TRANSIENT }),
|
|
93
|
+
htmlAnimationHook: asClass(HtmlAnimationHook, { lifetime: Lifetime.TRANSIENT }),
|
|
94
|
+
animationHook: asClass(AnimationHook, { lifetime: Lifetime.TRANSIENT }),
|
|
95
|
+
subtitlesHook: asClass(SubtitlesHook, { lifetime: Lifetime.TRANSIENT }),
|
|
96
|
+
textureHook: asClass(PixiTextureHook, { lifetime: Lifetime.TRANSIENT }),
|
|
97
|
+
objectHook: asClass(PixiDisplayObjectHook, { lifetime: Lifetime.TRANSIENT }),
|
|
98
|
+
gifHook: asClass(PixiGifHook, { lifetime: Lifetime.TRANSIENT }),
|
|
99
|
+
canvasShapeHook: asClass(CanvasShapeHook, { lifetime: Lifetime.TRANSIENT }),
|
|
100
|
+
pixiProgressShapeHook: asClass(PixiProgressShapeHook, { lifetime: Lifetime.TRANSIENT }),
|
|
101
|
+
htmlToCanvasHook: asClass(HtmlToCanvasHook, { lifetime: Lifetime.TRANSIENT }),
|
|
102
|
+
componentAnimationTransformer: asClass(ComponentAnimationTransformer, {
|
|
103
|
+
lifetime: Lifetime.TRANSIENT
|
|
104
|
+
}),
|
|
105
|
+
animationPresetsRegister: asClass(AnimationPresetsRegister, { lifetime: Lifetime.SINGLETON }),
|
|
106
|
+
splitTextCache: asClass(SplitTextCache, { lifetime: Lifetime.SINGLETON }),
|
|
107
|
+
// Register commands
|
|
108
|
+
playCommand: asClass(PlayCommand, { lifetime: Lifetime.SINGLETON }),
|
|
109
|
+
pauseCommand: asClass(PauseCommand, { lifetime: Lifetime.SINGLETON }),
|
|
110
|
+
seekCommand: asClass(SeekCommand, { lifetime: Lifetime.SINGLETON }),
|
|
111
|
+
replaceSourceOnTimeCommand: asClass(ReplaceSourceOnTimeCommand, {
|
|
112
|
+
lifetime: Lifetime.SINGLETON
|
|
113
|
+
}),
|
|
114
|
+
renderFrameCommand: asClass(RenderFrameCommand, { lifetime: Lifetime.SINGLETON }),
|
|
115
|
+
updateComponentCommand: asClass(UpdateComponentCommand, { lifetime: Lifetime.SINGLETON }),
|
|
116
|
+
renderCommand: asClass(RenderCommand, { lifetime: Lifetime.SINGLETON }),
|
|
117
|
+
// Register the command runner
|
|
118
|
+
commandRunner: asClass(CommandRunner, { lifetime: Lifetime.SINGLETON }),
|
|
119
|
+
component: asClass(Component, {
|
|
120
|
+
lifetime: Lifetime.TRANSIENT // New instance per component
|
|
121
|
+
}),
|
|
122
|
+
layer: asClass(Layer),
|
|
123
|
+
componentContext: asClass(ComponentContext, {
|
|
124
|
+
lifetime: Lifetime.TRANSIENT // New instance per component
|
|
125
|
+
})
|
|
126
|
+
});
|
|
127
|
+
// Resolve core dependencies to ensure initialization
|
|
128
|
+
childContainer.resolve('stateManager');
|
|
129
|
+
childContainer.resolve('eventManager');
|
|
130
|
+
childContainer.resolve('timelineManager');
|
|
131
|
+
childContainer.resolve('domManager');
|
|
132
|
+
childContainer.resolve('appManager');
|
|
133
|
+
childContainer.resolve('componentsManager');
|
|
134
|
+
childContainer.resolve('renderManager');
|
|
135
|
+
childContainer.resolve('subtitlesManager');
|
|
136
|
+
containers.set(data.id, childContainer);
|
|
137
|
+
return childContainer;
|
|
138
|
+
};
|
|
139
|
+
export const removeContainer = function (sceneId) {
|
|
140
|
+
if (containers.has(sceneId)) {
|
|
141
|
+
const container = containers.get(sceneId);
|
|
142
|
+
container.dispose();
|
|
143
|
+
containers.delete(sceneId);
|
|
144
|
+
}
|
|
145
|
+
};
|