@mihirsarya/manim-scroll-react 0.2.0 → 0.2.1

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 (2) hide show
  1. package/README.md +230 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # @mihirsarya/manim-scroll-react
2
+
3
+ React components and hooks for scroll-driven Manim animations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mihirsarya/manim-scroll-react
9
+ ```
10
+
11
+ Or use the unified package (recommended):
12
+
13
+ ```bash
14
+ npm install @mihirsarya/manim-scroll
15
+ ```
16
+
17
+ ## Requirements
18
+
19
+ - React 18+
20
+ - `@mihirsarya/manim-scroll-runtime` (peer dependency, installed automatically)
21
+
22
+ ## Quick Start
23
+
24
+ ### With Next.js Plugin (Recommended)
25
+
26
+ When using with `@mihirsarya/manim-scroll-next`, animations are automatically resolved:
27
+
28
+ ```tsx
29
+ import { ManimScroll } from "@mihirsarya/manim-scroll-react";
30
+
31
+ export default function Page() {
32
+ return (
33
+ <ManimScroll
34
+ scene="TextScene"
35
+ fontSize={72}
36
+ color="#ffffff"
37
+ scrollRange="viewport"
38
+ >
39
+ Welcome to my site
40
+ </ManimScroll>
41
+ );
42
+ }
43
+ ```
44
+
45
+ ### Manual Mode
46
+
47
+ Without the Next.js plugin, provide an explicit manifest URL:
48
+
49
+ ```tsx
50
+ import { ManimScroll } from "@mihirsarya/manim-scroll-react";
51
+
52
+ export default function Page() {
53
+ return (
54
+ <ManimScroll
55
+ manifestUrl="/assets/scene/manifest.json"
56
+ scrollRange="viewport"
57
+ >
58
+ Scroll-driven text
59
+ </ManimScroll>
60
+ );
61
+ }
62
+ ```
63
+
64
+ ### Native Mode
65
+
66
+ For text animations without pre-rendered assets:
67
+
68
+ ```tsx
69
+ <ManimScroll mode="native" fontSize={48} color="#ffffff">
70
+ Animate this text
71
+ </ManimScroll>
72
+ ```
73
+
74
+ ## Exports
75
+
76
+ ### Components
77
+
78
+ - **`ManimScroll`** - Scroll-driven animation component
79
+
80
+ ### Hooks
81
+
82
+ - **`useManimScroll`** - Hook for custom integrations with pre-rendered assets
83
+ - **`useNativeAnimation`** - Hook for native SVG text animation
84
+
85
+ ### Utilities
86
+
87
+ - **`computePropsHash`** - Compute hash for animation props
88
+ - **`extractChildrenText`** - Extract text from React children
89
+
90
+ ### Types
91
+
92
+ - `ManimScrollProps`, `ManimAnimationProps`
93
+ - `UseManimScrollOptions`, `UseManimScrollResult`
94
+ - `UseNativeAnimationOptions`, `UseNativeAnimationResult`
95
+
96
+ ## ManimScroll Props
97
+
98
+ | Prop | Type | Default | Description |
99
+ |------|------|---------|-------------|
100
+ | `scene` | `string` | `"TextScene"` | Manim scene name |
101
+ | `fontSize` | `number` | - | Font size for text animations |
102
+ | `color` | `string` | - | Color as hex string |
103
+ | `font` | `string` | - | Font family |
104
+ | `inline` | `boolean` | `false` | Enable inline mode |
105
+ | `padding` | `number` | `0.2` | Padding in inline mode (Manim units) |
106
+ | `mode` | `"auto" \| "video" \| "frames" \| "native"` | `"auto"` | Playback mode |
107
+ | `scrollRange` | `ScrollRangeValue` | `"viewport"` | Scroll range configuration |
108
+ | `manifestUrl` | `string` | - | Explicit manifest URL |
109
+ | `fontUrl` | `string` | - | Font file URL for native mode |
110
+ | `strokeWidth` | `number` | `2` | Stroke width for native mode |
111
+ | `onReady` | `() => void` | - | Called when animation is loaded |
112
+ | `onProgress` | `(progress: number) => void` | - | Called on scroll progress |
113
+ | `canvas` | `{ width?, height? }` | - | Canvas dimensions |
114
+ | `className` | `string` | - | CSS class |
115
+ | `style` | `CSSProperties` | - | Inline styles |
116
+ | `children` | `ReactNode` | - | Text content |
117
+
118
+ ## useManimScroll Hook
119
+
120
+ For advanced use cases requiring custom control:
121
+
122
+ ```tsx
123
+ import { useRef } from "react";
124
+ import { useManimScroll } from "@mihirsarya/manim-scroll-react";
125
+
126
+ function CustomAnimation() {
127
+ const containerRef = useRef<HTMLDivElement>(null);
128
+
129
+ const { progress, isReady, error, pause, resume, seek } = useManimScroll({
130
+ ref: containerRef,
131
+ manifestUrl: "/assets/scene/manifest.json",
132
+ scrollRange: "viewport",
133
+ });
134
+
135
+ return (
136
+ <div ref={containerRef} style={{ height: "100vh" }}>
137
+ {!isReady && <div>Loading...</div>}
138
+ {error && <div>Error: {error.message}</div>}
139
+ <div>Progress: {Math.round(progress * 100)}%</div>
140
+ <button onClick={pause}>Pause</button>
141
+ <button onClick={resume}>Resume</button>
142
+ </div>
143
+ );
144
+ }
145
+ ```
146
+
147
+ ### Hook Options
148
+
149
+ | Option | Type | Description |
150
+ |--------|------|-------------|
151
+ | `ref` | `RefObject<HTMLElement>` | Container element ref (required) |
152
+ | `manifestUrl` | `string` | Explicit manifest URL |
153
+ | `scene` | `string` | Scene name for auto-resolution |
154
+ | `animationProps` | `Record<string, unknown>` | Props for auto-resolution |
155
+ | `mode` | `"auto" \| "frames" \| "video"` | Playback mode |
156
+ | `scrollRange` | `ScrollRangeValue` | Scroll range configuration |
157
+ | `canvasDimensions` | `{ width?, height? }` | Canvas size |
158
+ | `enabled` | `boolean` | Whether the hook is active |
159
+
160
+ ### Hook Return Value
161
+
162
+ | Property | Type | Description |
163
+ |----------|------|-------------|
164
+ | `progress` | `number` | Current scroll progress (0 to 1) |
165
+ | `isReady` | `boolean` | Whether animation is loaded |
166
+ | `error` | `Error \| null` | Loading error, if any |
167
+ | `canvasRef` | `RefObject<HTMLCanvasElement>` | Canvas element ref |
168
+ | `seek` | `(progress: number) => void` | Seek to specific progress |
169
+ | `pause` | `() => void` | Pause scroll-driven updates |
170
+ | `resume` | `() => void` | Resume scroll-driven updates |
171
+ | `isPaused` | `boolean` | Whether updates are paused |
172
+
173
+ ## useNativeAnimation Hook
174
+
175
+ For native SVG text animation without pre-rendered assets:
176
+
177
+ ```tsx
178
+ import { useRef } from "react";
179
+ import { useNativeAnimation } from "@mihirsarya/manim-scroll-react";
180
+
181
+ function NativeTextAnimation() {
182
+ const containerRef = useRef<HTMLDivElement>(null);
183
+
184
+ const { progress, isReady } = useNativeAnimation({
185
+ ref: containerRef,
186
+ text: "Hello World",
187
+ fontSize: 48,
188
+ color: "#ffffff",
189
+ });
190
+
191
+ return (
192
+ <div ref={containerRef} style={{ height: "100vh" }}>
193
+ {!isReady && <div>Loading...</div>}
194
+ </div>
195
+ );
196
+ }
197
+ ```
198
+
199
+ ### Hook Options
200
+
201
+ | Option | Type | Description |
202
+ |--------|------|-------------|
203
+ | `ref` | `RefObject<HTMLElement>` | Container element ref (required) |
204
+ | `text` | `string` | Text to animate (required) |
205
+ | `fontSize` | `number` | Font size in pixels (inherits from parent if not set) |
206
+ | `color` | `string` | Text color |
207
+ | `fontUrl` | `string` | URL to font file for opentype.js |
208
+ | `strokeWidth` | `number` | Stroke width for drawing phase |
209
+ | `scrollRange` | `ScrollRangeValue` | Scroll range configuration |
210
+ | `enabled` | `boolean` | Whether the hook is active |
211
+
212
+ ## Scroll Range Configuration
213
+
214
+ ```tsx
215
+ // Presets
216
+ scrollRange="viewport" // Animation plays as element crosses viewport
217
+ scrollRange="element" // Tied to element's own scroll position
218
+ scrollRange="full" // Spans entire document scroll
219
+
220
+ // Relative units
221
+ scrollRange={["100vh", "-50%"]}
222
+
223
+ // Pixel values
224
+ scrollRange={[800, -400]}
225
+ scrollRange={{ start: 800, end: -400 }}
226
+ ```
227
+
228
+ ## License
229
+
230
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mihirsarya/manim-scroll-react",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "React wrapper for scroll-driven Manim animations.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,7 +12,7 @@
12
12
  "react-dom": ">=18.0.0"
13
13
  },
14
14
  "dependencies": {
15
- "@mihirsarya/manim-scroll-runtime": "0.2.0"
15
+ "@mihirsarya/manim-scroll-runtime": "0.2.1"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/react": "^18.2.61",