@framevideo/shader-transitions 0.0.3

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/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # @framevideo/shader-transitions
2
+
3
+ WebGL shader transitions for FrameVideo compositions. Renders GPU-accelerated scene-to-scene transitions using fragment shaders, driven by GSAP timelines.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @framevideo/shader-transitions
9
+ ```
10
+
11
+ Or load directly via CDN:
12
+
13
+ ```html
14
+ <script src="https://cdn.jsdelivr.net/npm/@framevideo/shader-transitions/dist/index.global.js"></script>
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```typescript
20
+ import { init } from "@framevideo/shader-transitions";
21
+
22
+ const tl = init({
23
+ bgColor: "#0a0a0a",
24
+ accentColor: "#ff6b2b",
25
+ scenes: ["scene-1", "scene-2", "scene-3"],
26
+ transitions: [
27
+ { time: 3, shader: "domain-warp", duration: 0.8 },
28
+ { time: 8, shader: "light-leak", duration: 0.7 },
29
+ ],
30
+ });
31
+ ```
32
+
33
+ The `init()` function pre-captures animated scene samples for every transition, composites cached samples with the selected shader during playback, and returns a GSAP timeline. Scene animations keep advancing through shader transitions without running DOM captures in the playback loop. If WebGL is unavailable, it falls back to normal timeline playback without shader compositing.
34
+
35
+ When the browser exposes Chrome's experimental CanvasDrawElement API, scene
36
+ capture uses native HTML-in-canvas via `drawElementImage()`. Other browsers keep
37
+ using the existing `html2canvas` fallback. You can feature-detect the native path
38
+ with `isHtmlInCanvasCaptureSupported()`.
39
+
40
+ ### With an existing timeline
41
+
42
+ Pass your own GSAP timeline to layer transitions onto it:
43
+
44
+ ```typescript
45
+ const tl = gsap.timeline({ paused: true });
46
+ // ... add your scene animations ...
47
+
48
+ init({
49
+ bgColor: "#000",
50
+ scenes: ["intro", "demo", "outro"],
51
+ transitions: [
52
+ { time: 5, shader: "cinematic-zoom" },
53
+ { time: 12, shader: "glitch", duration: 0.5 },
54
+ ],
55
+ timeline: tl,
56
+ });
57
+ ```
58
+
59
+ ## Available shaders
60
+
61
+ | Shader | Description |
62
+ | --------------------- | ---------------------------------------------------- |
63
+ | `domain-warp` | Organic noise-based warp with glowing edge |
64
+ | `ridged-burn` | Ridged noise burn with sparks and heat glow |
65
+ | `whip-pan` | Horizontal motion blur simulating a fast camera pan |
66
+ | `sdf-iris` | Circular iris wipe with glowing ring edge |
67
+ | `ripple-waves` | Concentric ripple distortion radiating from center |
68
+ | `gravitational-lens` | Warping gravity well with chromatic aberration |
69
+ | `cinematic-zoom` | Radial zoom blur with chromatic fringing |
70
+ | `chromatic-split` | RGB channel separation expanding from center |
71
+ | `glitch` | Digital glitch with block displacement and scanlines |
72
+ | `swirl-vortex` | Spiral rotation with noise-based warping |
73
+ | `thermal-distortion` | Heat shimmer rising from the bottom |
74
+ | `flash-through-white` | Flash to white then reveal the next scene |
75
+ | `cross-warp-morph` | Noise-driven morph blending both scenes |
76
+ | `light-leak` | Warm cinematic light leak with lens flare |
77
+
78
+ ## API
79
+
80
+ ### `init(config): GsapTimeline`
81
+
82
+ | Option | Type | Required | Description |
83
+ | ------------------- | -------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
84
+ | `bgColor` | `string` | yes | Fallback background color (hex) for scene capture. Use the composition's body/canvas background — individual scenes set their own `background-color` via CSS. |
85
+ | `accentColor` | `string` | no | Accent color (hex) for shader glow effects |
86
+ | `scenes` | `string[]` | yes | Element IDs of each scene, in order |
87
+ | `transitions` | `TransitionConfig[]` | yes | Transition definitions (see below) |
88
+ | `timeline` | `GsapTimeline` | no | Existing timeline to attach transitions to |
89
+ | `compositionId` | `string` | no | Override the `data-composition-id` for timeline registration |
90
+ | `previewCaptureFps` | `number` | no | Browser preview pre-capture samples per transition second. Defaults to `30`; rendering uses deterministic per-frame compositing instead. |
91
+
92
+ Browser preview capture scale and transition-prep loading UI ownership are controlled by `<framevideo-player>` (`shader-capture-scale`, `shader-loading`) instead of composition code. Direct non-player previews keep the built-in full-fidelity loading fallback.
93
+
94
+ Browser previews store captured transition snapshots in IndexedDB using a key derived from composition ID, scene DOM/style signatures, transition timing, capture FPS, scale, and dimensions. On refresh, matching snapshots are reloaded into WebGL textures instead of being captured again. Runtime scene or stylesheet edits mark only adjacent transition caches dirty; recapture is deferred until playback so editing stays responsive.
95
+
96
+ ### `TransitionConfig`
97
+
98
+ | Option | Type | Default | Description |
99
+ | ---------- | ------------ | ---------------- | -------------------------------- |
100
+ | `time` | `number` | — | Start time in seconds |
101
+ | `shader` | `ShaderName` | — | Shader name from the table above |
102
+ | `duration` | `number` | `0.7` | Transition duration in seconds |
103
+ | `ease` | `string` | `"power2.inOut"` | GSAP easing function |
104
+
105
+ ### `SHADER_NAMES`
106
+
107
+ Array of all available shader name strings, useful for validation or building UIs.
108
+
109
+ ```typescript
110
+ import { SHADER_NAMES } from "@framevideo/shader-transitions";
111
+ // ["domain-warp", "ridged-burn", "whip-pan", ...]
112
+ ```
113
+
114
+ ## Distribution
115
+
116
+ | Format | File | Use case |
117
+ | ------ | ---------------------- | ------------------------------------------- |
118
+ | ESM | `dist/index.js` | Bundlers (Vite, webpack, etc.) |
119
+ | CJS | `dist/index.cjs` | Node.js / require() |
120
+ | IIFE | `dist/index.global.js` | `<script>` tag, CDN (global: `HyperShader`) |
121
+
122
+ All formats include source maps. TypeScript definitions included.
123
+
124
+ ## Related packages
125
+
126
+ - [`@framevideo/core`](../core) -- types, parsers, runtime
127
+ - [`@framevideo/engine`](../engine) -- rendering engine
128
+ - [`framevideo`](../cli) -- CLI
129
+
130
+ ## License
131
+
132
+ MIT