pellicule 0.0.0 → 0.0.2

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/bin/cli.js ADDED
@@ -0,0 +1,255 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { parseArgs } from 'node:util'
4
+ import { resolve, extname, basename, dirname } from 'node:path'
5
+ import { existsSync, readFileSync } from 'node:fs'
6
+ import { fileURLToPath } from 'node:url'
7
+ import { renderToMp4 } from '../src/render.js'
8
+
9
+ // Read version from package.json
10
+ const __dirname = dirname(fileURLToPath(import.meta.url))
11
+ const pkg = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf-8'))
12
+ const VERSION = pkg.version
13
+
14
+ // ANSI color codes (no dependencies needed)
15
+ const colors = {
16
+ reset: '\x1b[0m',
17
+ bold: '\x1b[1m',
18
+ dim: '\x1b[2m',
19
+ red: '\x1b[31m',
20
+ yellow: '\x1b[33m',
21
+ cyan: '\x1b[36m',
22
+ white: '\x1b[37m',
23
+ pellicule: '\x1b[38;2;66;184;131m', // #42b883 - Vue green
24
+ bgPellicule: '\x1b[48;2;66;184;131m'
25
+ }
26
+
27
+ const c = {
28
+ error: (s) => `${colors.red}${s}${colors.reset}`,
29
+ warn: (s) => `${colors.yellow}${s}${colors.reset}`,
30
+ info: (s) => `${colors.cyan}${s}${colors.reset}`,
31
+ dim: (s) => `${colors.dim}${s}${colors.reset}`,
32
+ bold: (s) => `${colors.bold}${s}${colors.reset}`,
33
+ highlight: (s) => `${colors.pellicule}${s}${colors.reset}`,
34
+ brand: (s) => `${colors.bgPellicule}${colors.white}${colors.bold}${s}${colors.reset}`
35
+ }
36
+
37
+ function fail(msg, hint) {
38
+ console.error(c.error(`\nError: ${msg}\n`))
39
+ if (hint) console.error(c.dim(` ${hint}\n`))
40
+ process.exit(1)
41
+ }
42
+
43
+ const HELP = `
44
+ ${c.bold('pellicule')} ${c.dim(`v${VERSION}`)} - Render Vue components to video
45
+
46
+ ${c.bold('USAGE')}
47
+ ${c.highlight('pellicule')} ${c.dim('→ renders Video.vue to output.mp4')}
48
+ ${c.highlight('pellicule')} <input.vue> ${c.dim('→ custom input file')}
49
+ ${c.highlight('pellicule')} <input.vue> -o <file> ${c.dim('→ custom output path')}
50
+
51
+ ${c.bold('OPTIONS')}
52
+ ${c.info('-o, --output')} <file> Output file path ${c.dim('(default: ./output.mp4)')}
53
+ ${c.info('-d, --duration')} <frames> Duration in frames ${c.dim('(default: 90)')}
54
+ ${c.info('-f, --fps')} <number> Frames per second ${c.dim('(default: 30)')}
55
+ ${c.info('-w, --width')} <pixels> Video width ${c.dim('(default: 1920)')}
56
+ ${c.info('-h, --height')} <pixels> Video height ${c.dim('(default: 1080)')}
57
+ ${c.info('-r, --range')} <start:end> Frame range for partial render ${c.dim('(e.g., 100:200)')}
58
+ ${c.info('--help')} Show this help message
59
+ ${c.info('--version')} Show version number
60
+
61
+ ${c.bold('EXAMPLES')}
62
+ ${c.dim('# Zero-config (renders Video.vue → output.mp4)')}
63
+ ${c.highlight('pellicule')}
64
+
65
+ ${c.dim('# Specify input file (.vue extension is optional)')}
66
+ ${c.highlight('pellicule')} MyVideo
67
+
68
+ ${c.dim('# Custom output and duration')}
69
+ ${c.highlight('pellicule')} Video.vue -o intro.mp4 -d 150
70
+
71
+ ${c.dim('# 4K video at 60fps')}
72
+ ${c.highlight('pellicule')} Video.vue -w 3840 -h 2160 -f 60
73
+
74
+ ${c.dim('# 10 second video')}
75
+ ${c.highlight('pellicule')} Video.vue -d 300 -f 30
76
+
77
+ ${c.dim('# Render only frames 100-200 (for faster iteration)')}
78
+ ${c.highlight('pellicule')} Video.vue -d 300 -r 100:200
79
+
80
+ ${c.dim('# Render from frame 150 to 250')}
81
+ ${c.highlight('pellicule')} Video.vue -d 300 --range 150:250
82
+
83
+ ${c.bold('DURATION HELPER')}
84
+ frames = seconds * fps
85
+ ${c.dim('3 seconds at 30fps = 90 frames')}
86
+ ${c.dim('5 seconds at 30fps = 150 frames')}
87
+ ${c.dim('10 seconds at 60fps = 600 frames')}
88
+
89
+ ${c.dim('Documentation: https://docs.sailscasts.com/pellicule')}
90
+ `
91
+
92
+ function printBanner() {
93
+ console.log()
94
+ console.log(` ${c.brand(' PELLICULE ')} ${c.dim(`v${VERSION}`)}`)
95
+ console.log()
96
+ }
97
+
98
+ function formatTime(ms) {
99
+ if (ms < 1000) return `${ms}ms`
100
+ const seconds = (ms / 1000).toFixed(1)
101
+ return `${seconds}s`
102
+ }
103
+
104
+ function formatProgress(frame, total, fps) {
105
+ const percent = Math.round(((frame + 1) / total) * 100)
106
+ const barWidth = 30
107
+ const filled = Math.round((percent / 100) * barWidth)
108
+ const empty = barWidth - filled
109
+ const bar = c.highlight('█'.repeat(filled)) + c.dim('░'.repeat(empty))
110
+ return ` ${bar} ${c.bold(percent + '%')} ${c.dim(`(${frame + 1}/${total} @ ${fps.toFixed(1)} fps)`)}`
111
+ }
112
+
113
+ async function main() {
114
+ const { values, positionals } = parseArgs({
115
+ allowPositionals: true,
116
+ options: {
117
+ output: { type: 'string', short: 'o' },
118
+ duration: { type: 'string', short: 'd' },
119
+ fps: { type: 'string', short: 'f' },
120
+ width: { type: 'string', short: 'w' },
121
+ height: { type: 'string', short: 'h' },
122
+ range: { type: 'string', short: 'r' },
123
+ help: { type: 'boolean' },
124
+ version: { type: 'boolean' }
125
+ }
126
+ })
127
+
128
+ // Handle help and version
129
+ if (values.help) {
130
+ console.log(HELP)
131
+ process.exit(0)
132
+ }
133
+
134
+ if (values.version) {
135
+ console.log(VERSION)
136
+ process.exit(0)
137
+ }
138
+
139
+ // Default to Video.vue if no input provided
140
+ const input = positionals[0] || 'Video.vue'
141
+
142
+ // Try to resolve the input file, auto-appending .vue if needed
143
+ let inputPath = resolve(input)
144
+
145
+ if (!existsSync(inputPath) && !input.endsWith('.vue')) {
146
+ const withVue = resolve(input + '.vue')
147
+ if (existsSync(withVue)) {
148
+ inputPath = withVue
149
+ }
150
+ }
151
+
152
+ if (!existsSync(inputPath)) fail(`File not found: ${input}`)
153
+ if (extname(inputPath) !== '.vue') fail(`Input must be a .vue file, got: ${extname(inputPath) || '(no extension)'}`)
154
+
155
+ // Parse options with defaults
156
+ const fps = parseInt(values.fps || '30', 10)
157
+ const durationInFrames = parseInt(values.duration || '90', 10)
158
+ const width = parseInt(values.width || '1920', 10)
159
+ const height = parseInt(values.height || '1080', 10)
160
+ const output = values.output || './output.mp4'
161
+ const outputPath = resolve(output)
162
+
163
+ // Parse optional range (start:end format)
164
+ let startFrame = 0
165
+ let endFrame = durationInFrames
166
+
167
+ if (values.range) {
168
+ const rangeParts = values.range.split(':')
169
+ if (rangeParts.length !== 2) fail(`Invalid range format: ${values.range}`, 'Expected format: start:end (e.g., 100:200)')
170
+ const [startStr, endStr] = rangeParts
171
+ startFrame = parseInt(startStr, 10)
172
+ endFrame = parseInt(endStr, 10)
173
+ if (isNaN(startFrame) || startFrame < 0) fail(`Invalid start frame in range: ${startStr}`)
174
+ if (isNaN(endFrame) || endFrame <= 0) fail(`Invalid end frame in range: ${endStr}`)
175
+ }
176
+
177
+ // Validate options
178
+ if (isNaN(fps) || fps <= 0) fail(`Invalid fps value: ${values.fps}`)
179
+ if (isNaN(durationInFrames) || durationInFrames <= 0) fail(`Invalid duration value: ${values.duration}`)
180
+ if (isNaN(width) || width <= 0) fail(`Invalid width value: ${values.width}`)
181
+ if (isNaN(height) || height <= 0) fail(`Invalid height value: ${values.height}`)
182
+ if (startFrame >= endFrame) fail(`Start frame (${startFrame}) must be less than end frame (${endFrame})`)
183
+ if (endFrame > durationInFrames) fail(`End frame (${endFrame}) exceeds duration (${durationInFrames})`)
184
+
185
+ // Print banner and config
186
+ printBanner()
187
+
188
+ const isPartialRender = startFrame > 0 || endFrame < durationInFrames
189
+ const framesToRender = endFrame - startFrame
190
+ const durationSeconds = (durationInFrames / fps).toFixed(1)
191
+ const partialSeconds = (framesToRender / fps).toFixed(1)
192
+
193
+ console.log(` ${c.bold('Input')} ${c.info(basename(inputPath))}`)
194
+ console.log(` ${c.bold('Output')} ${c.info(basename(outputPath))}`)
195
+ console.log(` ${c.bold('Resolution')} ${width}x${height}`)
196
+ console.log(` ${c.bold('Duration')} ${durationInFrames} frames @ ${fps}fps ${c.dim(`(${durationSeconds}s)`)}`)
197
+ if (isPartialRender) {
198
+ console.log(` ${c.bold('Range')} ${c.highlight(`frames ${startFrame}-${endFrame - 1}`)} ${c.dim(`(${framesToRender} frames, ${partialSeconds}s)`)}`)
199
+ }
200
+ console.log()
201
+
202
+ const startTime = Date.now()
203
+
204
+ // ANSI escape codes for line control
205
+ const clearLine = '\x1b[2K' // Clear entire line
206
+ const cursorToStart = '\r' // Move cursor to start of line
207
+
208
+ try {
209
+ // Render with progress callback
210
+ await renderToMp4({
211
+ input: inputPath,
212
+ fps,
213
+ durationInFrames,
214
+ startFrame,
215
+ endFrame,
216
+ width,
217
+ height,
218
+ output: outputPath,
219
+ silent: true,
220
+ onProgress: ({ frame, total, fps: currentFps }) => {
221
+ // Clear line and print progress (stays on same line)
222
+ process.stdout.write(clearLine + cursorToStart + formatProgress(frame, total, currentFps || fps))
223
+ }
224
+ })
225
+
226
+ // Clear progress line when done
227
+ process.stdout.write(clearLine + cursorToStart)
228
+
229
+ const totalTime = Date.now() - startTime
230
+ console.log()
231
+ console.log(` ${c.highlight('Done!')} Rendered ${framesToRender} frames in ${formatTime(totalTime)}`)
232
+ console.log(` ${c.dim('Output:')} ${outputPath}`)
233
+ console.log()
234
+
235
+ } catch (error) {
236
+ // Clear progress line on error
237
+ process.stdout.write(clearLine + cursorToStart)
238
+ console.error()
239
+ console.error(c.error(` Error: ${error.message}`))
240
+ console.error()
241
+
242
+ if (error.message.includes('ffmpeg')) {
243
+ console.error(c.warn(' Hint: Make sure FFmpeg is installed and available in your PATH'))
244
+ console.error(c.dim(' Install: https://ffmpeg.org/download.html'))
245
+ console.error()
246
+ }
247
+
248
+ process.exit(1)
249
+ }
250
+ }
251
+
252
+ main().catch((error) => {
253
+ console.error(c.error(`\nUnexpected error: ${error.message}\n`))
254
+ process.exit(1)
255
+ })
package/package.json CHANGED
@@ -1,42 +1,37 @@
1
1
  {
2
2
  "name": "pellicule",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
4
4
  "description": "Deterministic video rendering with Vue",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "bin": {
8
+ "pellicule": "./bin/cli.js"
9
+ },
10
+ "exports": {
11
+ ".": "./src/index.js",
12
+ "./render": "./src/render.js"
13
+ },
5
14
  "keywords": [
6
15
  "vue",
7
16
  "video",
8
17
  "rendering",
9
18
  "animation",
10
19
  "frames",
11
- "remotion",
12
20
  "programmatic-video"
13
21
  ],
14
- "author": "",
22
+ "author": "Kelvin Omereshone <kelvin@sailscasts.com>",
15
23
  "license": "MIT",
24
+ "homepage": "https://docs.sailscasts.com/pellicule",
16
25
  "repository": {
17
26
  "type": "git",
18
- "url": ""
27
+ "url": "https://github.com/sailscastshq/pellicule"
19
28
  },
20
- "homepage": "",
21
- "type": "module",
22
- "main": "./dist/index.cjs",
23
- "module": "./dist/index.js",
24
- "types": "./dist/index.d.ts",
25
- "exports": {
26
- ".": {
27
- "import": "./dist/index.js",
28
- "require": "./dist/index.cjs",
29
- "types": "./dist/index.d.ts"
30
- }
29
+ "dependencies": {
30
+ "vite": "^5.0.0",
31
+ "@vitejs/plugin-vue": "^5.0.0",
32
+ "playwright": "^1.40.0"
31
33
  },
32
- "files": [
33
- "dist"
34
- ],
35
34
  "peerDependencies": {
36
35
  "vue": "^3.0.0"
37
- },
38
- "devDependencies": {
39
- "vue": "^3.4.0",
40
- "typescript": "^5.0.0"
41
36
  }
42
37
  }
@@ -0,0 +1,124 @@
1
+ import { createServer } from 'vite'
2
+ import vue from '@vitejs/plugin-vue'
3
+ import { writeFile, mkdir, rm } from 'fs/promises'
4
+ import { join, resolve, dirname, basename } from 'path'
5
+ import { fileURLToPath } from 'url'
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url))
8
+ const pelliculeSrc = resolve(__dirname, '..')
9
+
10
+ /**
11
+ * Creates a Vite dev server in the user's project directory.
12
+ * This way Vite naturally finds their node_modules with Vue installed.
13
+ *
14
+ * @param {object} options
15
+ * @param {string} options.input - Path to the .vue file
16
+ * @param {number} options.width - Video width
17
+ * @param {number} options.height - Video height
18
+ * @returns {Promise<{ server: object, url: string, cleanup: function }>}
19
+ */
20
+ export async function createVideoServer(options) {
21
+ const { input, width = 1920, height = 1080 } = options
22
+
23
+ const inputPath = resolve(input)
24
+ const inputDir = dirname(inputPath)
25
+ const inputFile = basename(inputPath)
26
+
27
+ // Create .pellicule temp folder in user's project
28
+ const tempDir = join(inputDir, '.pellicule')
29
+ await mkdir(tempDir, { recursive: true })
30
+
31
+ // Create entry HTML
32
+ const htmlContent = `<!DOCTYPE html>
33
+ <html>
34
+ <head>
35
+ <meta charset="UTF-8">
36
+ <style>
37
+ * { margin: 0; padding: 0; box-sizing: border-box; }
38
+ html, body { width: ${width}px; height: ${height}px; overflow: hidden; }
39
+ #app { width: 100%; height: 100%; }
40
+ </style>
41
+ </head>
42
+ <body>
43
+ <div id="app"></div>
44
+ <script type="module" src="./entry.js"></script>
45
+ </body>
46
+ </html>`
47
+
48
+ // Create entry JS with setFrame function for fast frame updates
49
+ const entryContent = `
50
+ import { createApp, ref, provide, h, nextTick } from 'vue'
51
+ import VideoComponent from '../${inputFile}'
52
+
53
+ // Pellicule injection keys (must match composables.js)
54
+ const FRAME_KEY = Symbol.for('pellicule-frame')
55
+ const CONFIG_KEY = Symbol.for('pellicule-config')
56
+
57
+ // Get initial config from URL
58
+ const params = new URLSearchParams(window.location.search)
59
+ const fps = parseInt(params.get('fps') || '30', 10)
60
+ const durationInFrames = parseInt(params.get('duration') || '90', 10)
61
+ const width = parseInt(params.get('width') || '${width}', 10)
62
+ const height = parseInt(params.get('height') || '${height}', 10)
63
+
64
+ const config = { fps, durationInFrames, width, height }
65
+
66
+ // Frame ref - reactive, will trigger re-render when changed
67
+ const frameRef = ref(0)
68
+
69
+ // Expose setFrame function for the renderer to call
70
+ window.__PELLICULE_SET_FRAME__ = async (frame) => {
71
+ frameRef.value = frame
72
+ await nextTick() // Wait for Vue to re-render
73
+ }
74
+
75
+ try {
76
+ // Create app with frame context
77
+ const app = createApp({
78
+ setup() {
79
+ provide(FRAME_KEY, frameRef)
80
+ provide(CONFIG_KEY, config)
81
+ return () => h(VideoComponent)
82
+ }
83
+ })
84
+
85
+ app.mount('#app')
86
+ window.__PELLICULE_READY__ = true
87
+ } catch (error) {
88
+ console.error('Pellicule render error:', error)
89
+ window.__PELLICULE_READY__ = true
90
+ window.__PELLICULE_ERROR__ = error.message
91
+ }
92
+ `
93
+
94
+ await writeFile(join(tempDir, 'index.html'), htmlContent)
95
+ await writeFile(join(tempDir, 'entry.js'), entryContent)
96
+
97
+ // Create Vite server rooted in the user's project directory
98
+ const server = await createServer({
99
+ root: tempDir,
100
+ plugins: [vue()],
101
+ server: {
102
+ port: 0,
103
+ strictPort: false
104
+ },
105
+ resolve: {
106
+ alias: {
107
+ 'pellicule': pelliculeSrc
108
+ }
109
+ },
110
+ logLevel: 'warn'
111
+ })
112
+
113
+ await server.listen()
114
+
115
+ const address = server.httpServer.address()
116
+ const url = `http://localhost:${address.port}`
117
+
118
+ const cleanup = async () => {
119
+ await server.close()
120
+ await rm(tempDir, { recursive: true, force: true })
121
+ }
122
+
123
+ return { server, url, cleanup, tempDir }
124
+ }
@@ -0,0 +1,34 @@
1
+ <script setup>
2
+ import { computed } from 'vue'
3
+ import { useFrame } from '../composables/frame.js'
4
+ import { provideSequence } from '../composables/sequence.js'
5
+
6
+ const props = defineProps({
7
+ /**
8
+ * The frame number where this sequence starts
9
+ */
10
+ from: {
11
+ type: Number,
12
+ required: true
13
+ },
14
+ /**
15
+ * Duration of this sequence in frames
16
+ */
17
+ durationInFrames: {
18
+ type: Number,
19
+ required: true
20
+ }
21
+ })
22
+
23
+ const globalFrame = useFrame()
24
+
25
+ // Provide sequence context to children
26
+ const { isActive } = provideSequence(props.from, props.durationInFrames)
27
+
28
+ // Compute whether to show content
29
+ const shouldRender = computed(() => isActive.value)
30
+ </script>
31
+
32
+ <template>
33
+ <slot v-if="shouldRender" />
34
+ </template>
@@ -0,0 +1,24 @@
1
+ import { inject, computed } from 'vue'
2
+ import { FRAME_KEY } from './keys.js'
3
+
4
+ /**
5
+ * Get the current frame number.
6
+ * Must be used within a Pellicule render context.
7
+ *
8
+ * @returns {import('vue').ComputedRef<number>} Current frame number
9
+ *
10
+ * @example
11
+ * const frame = useFrame()
12
+ * const opacity = computed(() => frame.value / 30) // fade in over 1 second at 30fps
13
+ */
14
+ export function useFrame() {
15
+ const frame = inject(FRAME_KEY)
16
+
17
+ if (frame === undefined) {
18
+ throw new Error(
19
+ 'useFrame() must be used within a Pellicule render context'
20
+ )
21
+ }
22
+
23
+ return computed(() => frame.value)
24
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Injection keys for Pellicule context
3
+ * Using Symbol.for() so keys are shared across module instances
4
+ */
5
+ export const FRAME_KEY = Symbol.for('pellicule-frame')
6
+ export const CONFIG_KEY = Symbol.for('pellicule-config')
7
+ export const SEQUENCE_KEY = Symbol.for('pellicule-sequence')
@@ -0,0 +1,82 @@
1
+ import { inject, computed, provide } from 'vue'
2
+ import { SEQUENCE_KEY } from './keys.js'
3
+ import { useFrame } from './frame.js'
4
+
5
+ /**
6
+ * Get sequence timing information.
7
+ * Can be used in two ways:
8
+ *
9
+ * 1. Inside a <Sequence> component - returns timing for that sequence
10
+ * 2. With explicit timing - useSequence(from, durationInFrames)
11
+ *
12
+ * @param {number} [from] - Start frame (optional if inside <Sequence>)
13
+ * @param {number} [durationInFrames] - Duration in frames (optional if inside <Sequence>)
14
+ * @returns {{ localFrame: ComputedRef<number>, progress: ComputedRef<number>, isActive: ComputedRef<boolean> }}
15
+ *
16
+ * @example
17
+ * // Inside a <Sequence> component
18
+ * const { localFrame, progress, isActive } = useSequence()
19
+ *
20
+ * @example
21
+ * // With explicit timing
22
+ * const verse1 = useSequence(0, 90)
23
+ * const verse2 = useSequence(90, 90)
24
+ */
25
+ export function useSequence(from, durationInFrames) {
26
+ const globalFrame = useFrame()
27
+
28
+ // If arguments provided, use them directly
29
+ if (from !== undefined && durationInFrames !== undefined) {
30
+ const end = from + durationInFrames
31
+
32
+ const localFrame = computed(() => Math.max(0, globalFrame.value - from))
33
+ const progress = computed(() => {
34
+ if (globalFrame.value < from) return 0
35
+ if (globalFrame.value >= end) return 1
36
+ return (globalFrame.value - from) / durationInFrames
37
+ })
38
+ const isActive = computed(() =>
39
+ globalFrame.value >= from && globalFrame.value < end
40
+ )
41
+
42
+ return { localFrame, progress, isActive }
43
+ }
44
+
45
+ // Otherwise, try to get from parent <Sequence>
46
+ const sequenceContext = inject(SEQUENCE_KEY, null)
47
+
48
+ if (!sequenceContext) {
49
+ throw new Error(
50
+ 'useSequence() must be used within a <Sequence> component or called with (from, durationInFrames) arguments'
51
+ )
52
+ }
53
+
54
+ return sequenceContext
55
+ }
56
+
57
+ /**
58
+ * Provide sequence context to children.
59
+ * Used internally by the <Sequence> component.
60
+ *
61
+ * @param {number} from - Start frame
62
+ * @param {number} durationInFrames - Duration in frames
63
+ */
64
+ export function provideSequence(from, durationInFrames) {
65
+ const globalFrame = useFrame()
66
+ const end = from + durationInFrames
67
+
68
+ const localFrame = computed(() => Math.max(0, globalFrame.value - from))
69
+ const progress = computed(() => {
70
+ if (globalFrame.value < from) return 0
71
+ if (globalFrame.value >= end) return 1
72
+ return (globalFrame.value - from) / durationInFrames
73
+ })
74
+ const isActive = computed(() =>
75
+ globalFrame.value >= from && globalFrame.value < end
76
+ )
77
+
78
+ const context = { localFrame, progress, isActive, from, durationInFrames }
79
+ provide(SEQUENCE_KEY, context)
80
+
81
+ return context
82
+ }
@@ -0,0 +1,23 @@
1
+ import { inject } from 'vue'
2
+ import { CONFIG_KEY } from './keys.js'
3
+
4
+ /**
5
+ * Get the video configuration (fps, duration, dimensions).
6
+ * Must be used within a Pellicule render context.
7
+ *
8
+ * @returns {{ fps: number, durationInFrames: number, width: number, height: number }}
9
+ *
10
+ * @example
11
+ * const { fps, durationInFrames, width, height } = useVideoConfig()
12
+ */
13
+ export function useVideoConfig() {
14
+ const config = inject(CONFIG_KEY)
15
+
16
+ if (!config) {
17
+ throw new Error(
18
+ 'useVideoConfig() must be used within a Pellicule render context'
19
+ )
20
+ }
21
+
22
+ return config
23
+ }
package/src/index.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Pellicule - Deterministic video rendering with Vue
3
+ *
4
+ * This is the browser-safe entry point.
5
+ * For rendering (Node.js), import from 'pellicule/render'
6
+ */
7
+
8
+ // Composables
9
+ export { useFrame } from './composables/frame.js'
10
+ export { useVideoConfig } from './composables/video-config.js'
11
+ export { useSequence } from './composables/sequence.js'
12
+ export { FRAME_KEY, CONFIG_KEY, SEQUENCE_KEY } from './composables/keys.js'
13
+
14
+ // Components
15
+ export { default as Sequence } from './components/Sequence.vue'
16
+
17
+ // Animation utilities
18
+ export { interpolate, sequence, Easing } from './utils/math.js'
package/src/render.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Pellicule Renderer - Node.js only
3
+ *
4
+ * This module requires Node.js and cannot run in the browser.
5
+ */
6
+
7
+ export { renderVideo } from './renderer/render.js'
8
+ export { encodeVideo, renderToMp4 } from './renderer/encode.js'
@@ -0,0 +1,95 @@
1
+ import { spawn } from 'child_process'
2
+ import path from 'path'
3
+
4
+ /**
5
+ * Encodes PNG frames into an MP4 video using FFmpeg.
6
+ *
7
+ * @param {object} options
8
+ * @param {string} options.framesDir - Directory containing frame-XXXXX.png files
9
+ * @param {string} options.output - Output video path (default: './output.mp4')
10
+ * @param {number} options.fps - Frames per second (default: 30)
11
+ * @param {boolean} options.silent - Suppress console output (default: false)
12
+ * @returns {Promise<string>} Path to the output video
13
+ */
14
+ export function encodeVideo(options) {
15
+ const {
16
+ framesDir,
17
+ output = './output.mp4',
18
+ fps = 30,
19
+ silent = false
20
+ } = options
21
+
22
+ return new Promise((resolve, reject) => {
23
+ const framePattern = path.join(framesDir, 'frame-%05d.png')
24
+
25
+ const args = [
26
+ '-y', // Overwrite output
27
+ '-framerate', String(fps),
28
+ '-i', framePattern,
29
+ '-c:v', 'libx264',
30
+ '-pix_fmt', 'yuv420p', // Compatibility
31
+ '-preset', 'fast',
32
+ output
33
+ ]
34
+
35
+ if (!silent) {
36
+ console.log(`Encoding video: ffmpeg ${args.join(' ')}`)
37
+ }
38
+
39
+ const ffmpeg = spawn('ffmpeg', args)
40
+
41
+ ffmpeg.stderr.on('data', (data) => {
42
+ // FFmpeg outputs progress to stderr
43
+ if (!silent) {
44
+ const line = data.toString()
45
+ if (line.includes('frame=')) {
46
+ process.stdout.write(`\r${line.trim()}`)
47
+ }
48
+ }
49
+ })
50
+
51
+ ffmpeg.on('close', (code) => {
52
+ if (!silent) {
53
+ console.log('') // New line after progress
54
+ }
55
+ if (code === 0) {
56
+ if (!silent) {
57
+ console.log(`Video saved to ${output}`)
58
+ }
59
+ resolve(output)
60
+ } else {
61
+ reject(new Error(`FFmpeg exited with code ${code}`))
62
+ }
63
+ })
64
+
65
+ ffmpeg.on('error', (err) => {
66
+ reject(new Error(`ffmpeg error: ${err.message}. Is ffmpeg installed?`))
67
+ })
68
+ })
69
+ }
70
+
71
+ /**
72
+ * Full render pipeline: Vue component → frames → MP4
73
+ *
74
+ * @param {object} options - Same as renderVideo, plus output path
75
+ * @param {boolean} options.silent - Suppress console output (default: false)
76
+ * @returns {Promise<string>} Path to the output video
77
+ */
78
+ export async function renderToMp4(options) {
79
+ const { renderVideo } = await import('./render.js')
80
+
81
+ const { output = './output.mp4', silent = false, ...renderOptions } = options
82
+
83
+ // Step 1: Render frames
84
+ const { framesDir } = await renderVideo({ ...renderOptions, silent })
85
+
86
+ // Step 2: Encode to MP4
87
+ const videoPath = await encodeVideo({
88
+ framesDir,
89
+ output,
90
+ fps: renderOptions.fps || 30,
91
+ silent
92
+ })
93
+
94
+ return videoPath
95
+ }
@@ -0,0 +1,134 @@
1
+ import { chromium } from 'playwright'
2
+ import { createVideoServer } from '../bundler/vite.js'
3
+ import { mkdir } from 'fs/promises'
4
+ import { join } from 'path'
5
+
6
+ /**
7
+ * Renders a .vue component to video frames.
8
+ *
9
+ * @param {object} options
10
+ * @param {string} options.input - Path to the .vue file
11
+ * @param {number} options.fps - Frames per second (default: 30)
12
+ * @param {number} options.durationInFrames - Total frames in the video (for animation calculations)
13
+ * @param {number} options.startFrame - First frame to render (default: 0)
14
+ * @param {number} options.endFrame - Last frame to render, exclusive (default: durationInFrames)
15
+ * @param {number} options.width - Video width in pixels (default: 1920)
16
+ * @param {number} options.height - Video height in pixels (default: 1080)
17
+ * @param {string} options.outputDir - Directory for frame images (default: './frames')
18
+ * @param {function} options.onProgress - Progress callback
19
+ * @returns {Promise<{ framesDir: string, totalFrames: number }>}
20
+ */
21
+ export async function renderVideo(options) {
22
+ const {
23
+ input,
24
+ fps = 30,
25
+ durationInFrames,
26
+ startFrame = 0,
27
+ endFrame,
28
+ width = 1920,
29
+ height = 1080,
30
+ outputDir = './frames',
31
+ onProgress,
32
+ silent = false
33
+ } = options
34
+
35
+ // Calculate actual frame range to render
36
+ const actualEndFrame = endFrame !== undefined ? endFrame : durationInFrames
37
+ const framesToRender = actualEndFrame - startFrame
38
+
39
+ const log = silent ? () => {} : console.log.bind(console)
40
+
41
+ const startTime = Date.now()
42
+
43
+ // Start Vite server with the video component
44
+ log(`Starting Vite server for ${input}...`)
45
+ const viteStart = Date.now()
46
+ const { url, cleanup } = await createVideoServer({ input, width, height })
47
+ log(`Server ready in ${Date.now() - viteStart}ms`)
48
+
49
+ // Ensure output directory exists
50
+ await mkdir(outputDir, { recursive: true })
51
+
52
+ // Launch browser
53
+ const browser = await chromium.launch()
54
+ const context = await browser.newContext({
55
+ viewport: { width, height },
56
+ deviceScaleFactor: 1
57
+ })
58
+ const page = await context.newPage()
59
+
60
+ // Capture console errors (only log if not silent)
61
+ page.on('console', msg => {
62
+ if (msg.type() === 'error' && !silent) {
63
+ console.error('Browser error:', msg.text())
64
+ }
65
+ })
66
+
67
+ page.on('pageerror', error => {
68
+ if (!silent) {
69
+ console.error('Page error:', error.message)
70
+ }
71
+ })
72
+
73
+ const rangeInfo = startFrame > 0 || actualEndFrame < durationInFrames
74
+ ? ` (frames ${startFrame}-${actualEndFrame - 1})`
75
+ : ''
76
+ log(`Rendering ${framesToRender} frames at ${fps}fps (${width}x${height})${rangeInfo}`)
77
+
78
+ try {
79
+ // Load page ONCE with config (durationInFrames stays full for correct animation calculations)
80
+ const pageUrl = `${url}?fps=${fps}&duration=${durationInFrames}&width=${width}&height=${height}`
81
+ await page.goto(pageUrl, { waitUntil: 'networkidle' })
82
+
83
+ // Wait for Vue to mount
84
+ await page.waitForFunction(() => window.__PELLICULE_READY__ === true, { timeout: 10000 })
85
+
86
+ // Check for errors
87
+ const error = await page.evaluate(() => window.__PELLICULE_ERROR__)
88
+ if (error) {
89
+ throw new Error(`Render error: ${error}`)
90
+ }
91
+
92
+ const renderStart = Date.now()
93
+
94
+ // Render each frame in the specified range
95
+ for (let frame = startFrame; frame < actualEndFrame; frame++) {
96
+ // Update frame number - Vue reactivity handles re-render
97
+ await page.evaluate((f) => window.__PELLICULE_SET_FRAME__(f), frame)
98
+
99
+ // Screenshot - output frames are numbered from 0
100
+ const outputFrameNum = frame - startFrame
101
+ const framePath = join(outputDir, `frame-${String(outputFrameNum).padStart(5, '0')}.png`)
102
+ await page.screenshot({ path: framePath })
103
+
104
+ // Progress callback
105
+ if (onProgress) {
106
+ const elapsed = Date.now() - renderStart
107
+ const framesRendered = outputFrameNum + 1
108
+ const currentFps = framesRendered / (elapsed / 1000)
109
+ onProgress({ frame: outputFrameNum, total: framesToRender, fps: currentFps })
110
+ }
111
+
112
+ // Log progress every 10 frames
113
+ const outputFrameIndex = frame - startFrame
114
+ if (outputFrameIndex % 10 === 0 || frame === actualEndFrame - 1) {
115
+ const percent = Math.round(((outputFrameIndex + 1) / framesToRender) * 100)
116
+ const elapsed = Date.now() - renderStart
117
+ const framesPerSec = ((outputFrameIndex + 1) / (elapsed / 1000)).toFixed(1)
118
+ log(`Frame ${outputFrameIndex + 1}/${framesToRender} (${percent}%) - ${framesPerSec} fps`)
119
+ }
120
+ }
121
+
122
+ const renderTime = Date.now() - renderStart
123
+ log(`Rendered ${framesToRender} frames in ${renderTime}ms (${(framesToRender / (renderTime / 1000)).toFixed(1)} fps)`)
124
+
125
+ } finally {
126
+ await browser.close()
127
+ await cleanup()
128
+ }
129
+
130
+ log(`Total time: ${Date.now() - startTime}ms`)
131
+ log(`Frames saved to ${outputDir}`)
132
+
133
+ return { framesDir: outputDir, totalFrames: framesToRender }
134
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Easing functions for smooth animations
3
+ */
4
+ export const Easing = {
5
+ linear: (t) => t,
6
+ easeIn: (t) => t * t,
7
+ easeOut: (t) => t * (2 - t),
8
+ easeInOut: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t)
9
+ }
10
+
11
+ /**
12
+ * Maps a value from one range to another.
13
+ * The core animation primitive in Pellicule.
14
+ *
15
+ * @param {number} frame - Current frame number
16
+ * @param {[number, number]} inputRange - [startFrame, endFrame]
17
+ * @param {[number, number]} outputRange - [startValue, endValue]
18
+ * @param {object} options - Optional settings
19
+ * @param {function} options.easing - Easing function (default: linear)
20
+ * @param {'clamp'|'extend'} options.extrapolate - Behavior outside input range
21
+ * @returns {number} Interpolated value
22
+ *
23
+ * @example
24
+ * // Fade in over first 30 frames
25
+ * const opacity = interpolate(frame, [0, 30], [0, 1])
26
+ *
27
+ * @example
28
+ * // Slide from left with easing
29
+ * const x = interpolate(frame, [0, 60], [-100, 0], { easing: Easing.easeOut })
30
+ */
31
+ export function interpolate(frame, inputRange, outputRange, options = {}) {
32
+ const { easing = Easing.linear, extrapolate = 'clamp' } = options
33
+
34
+ const [inStart, inEnd] = inputRange
35
+ const [outStart, outEnd] = outputRange
36
+
37
+ // Calculate progress (0 to 1)
38
+ let progress = (frame - inStart) / (inEnd - inStart)
39
+
40
+ // Handle extrapolation
41
+ if (extrapolate === 'clamp') {
42
+ progress = Math.max(0, Math.min(1, progress))
43
+ }
44
+
45
+ // Apply easing
46
+ const easedProgress = easing(progress)
47
+
48
+ // Map to output range
49
+ return outStart + (outEnd - outStart) * easedProgress
50
+ }
51
+
52
+ /**
53
+ * Creates a sequence of timed animations.
54
+ * Useful for staggered or chained animations.
55
+ *
56
+ * @param {number} frame - Current frame number
57
+ * @param {Array<{start: number, end: number, from: number, to: number}>} sequence
58
+ * @returns {number} Current value in the sequence
59
+ *
60
+ * @example
61
+ * const scale = sequence(frame, [
62
+ * { start: 0, end: 15, from: 0, to: 1 }, // grow
63
+ * { start: 45, end: 60, from: 1, to: 0 } // shrink
64
+ * ])
65
+ */
66
+ export function sequence(frame, steps) {
67
+ for (const step of steps) {
68
+ if (frame >= step.start && frame <= step.end) {
69
+ return interpolate(frame, [step.start, step.end], [step.from, step.to])
70
+ }
71
+ if (frame < step.start) {
72
+ return step.from
73
+ }
74
+ }
75
+ // Return last value if past all steps
76
+ const lastStep = steps[steps.length - 1]
77
+ return lastStep ? lastStep.to : 0
78
+ }
package/dist/index.cjs DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * Pellicule - Deterministic video rendering with Vue
3
- */
4
- "use strict";
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.VERSION = '0.0.0';
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * Pellicule - Deterministic video rendering with Vue
3
- */
4
- export declare const VERSION = "0.0.0";
package/dist/index.js DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * Pellicule - Deterministic video rendering with Vue
3
- */
4
- export const VERSION = '0.0.0';