pa_encoder 0.2.2 → 0.2.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.
Files changed (2) hide show
  1. package/README.md +84 -114
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,169 +1,139 @@
1
- # pa_encoder
1
+ HTML canvas frame encoder made for personal use (ツ)
2
2
 
3
- pa_encoder는 브라우저에서 실행되는 canvas 기반 스케치/애니메이션을 **프레임 이미지(PNG)로 추출**하는 인코더입니다.
3
+ # Installation
4
4
 
5
- Live(실시간) 캡처와 Frame(결정적/정밀) 캡처를 모두 지원하며, **DOM에 `<canvas>`가 존재하는 모든 웹 프로젝트**에서 사용할 수 있습니다.
6
-
7
- ---
5
+ ```bash
6
+ npm install pa_encoder
7
+ ```
8
8
 
9
- pa_encoder is an encoder that **extracts browser-based canvas sketches and animations into image frames (PNG)**.
9
+ Provides:
10
10
 
11
- It supports both **Live (realtime) capture** and **Frame (deterministic) capture**, and can be used with **any web project that renders to a DOM `<canvas>`**.
11
+ - JavaScript API (ES module)
12
+ - CLI tool (`pa_encoder`)
12
13
 
13
14
  ---
14
15
 
15
- ### 설치
16
+ # Usage
16
17
 
17
- ```bash
18
- npm install pa_encoder
19
- ```
18
+ ## CLI (recommended)
20
19
 
21
- 또는
20
+ Starts a local proxy server and opens a browser UI.
22
21
 
23
22
  ```bash
24
- pnpm add pa_encoder
23
+ pa_encoder --url http://localhost:5173 --entry /src/main.js
25
24
  ```
26
25
 
27
- ### 빠른 시작
26
+ ### Options
28
27
 
29
- 프로젝트 루트에서 실행:
28
+ - `--url` Target site URL
29
+ - `--entry` Entry script imported in preview iframe
30
+ - `--port` UI server port (default: `8787`)
30
31
 
31
- ```bash
32
- npx pa_encoder
33
- ```
32
+ The UI shows a live preview, capture controls, and progress logs.
34
33
 
35
- 기본 가정:
34
+ ---
36
35
 
37
- - dev 서버: http://localhost:5173
38
- - entry 파일: /src/main.js
36
+ ## JavaScript API
39
37
 
40
- 브라우저가 열리며 encoder UI가 표시됩니다.
38
+ ### Live capture (real-time)
41
39
 
42
- ### CLI 옵션
40
+ ```js
41
+ import { startLiveCapture, createZipExporter } from "pa_encoder";
43
42
 
44
- ```bash
45
- npx pa_encoder --url <dev_server_url> --entry <entry_path> --port <ui_port>
46
- ```
43
+ const canvas = document.querySelector("canvas");
44
+ const exporter = await createZipExporter({ zipName: "frames.zip" });
47
45
 
48
- 예시:
46
+ const { stop } = await startLiveCapture({
47
+ canvas,
48
+ exporter,
49
+ fps: 30,
50
+ });
49
51
 
50
- ```bash
51
- npx pa_encoder --url http://localhost:3000 --entry /src/sketch.js
52
+ await stop();
52
53
  ```
53
54
 
54
- ### UI 사용 방법
55
-
56
- 1. **Entry**에 스케치 엔트리 파일 경로를 입력합니다(예: `/src/main.js`).
57
- 2. **Mode**를 선택합니다.
58
- - Live: 실시간 인터랙션 포함 캡처
59
- - Frame: fps/frames 기반 정밀 캡처
60
- 3. **Canvas**에서 캡처할 캔버스를 선택합니다(기본: auto).
61
- 4. **Start**로 시작, **Stop**으로 종료합니다.
55
+ ---
62
56
 
63
- #### 키보드 인터랙션과 단축키 동작
57
+ ### Deterministic frame capture (virtual time)
64
58
 
65
- - 녹화 **시작 전(Idle)** 에는 UI 단축키가 동작합니다.
66
- - `H`: UI 숨김
67
- - `P`: Passthrough 토글
68
- - `C`: Compact 토글
69
- - `D`: Dock 위치 변경
70
- - `Space`: Start
71
- - 녹화 **진행 중(Running)** 에는 UI가 키보드를 가로채지 않습니다.
72
- 즉, 키 입력이 스케치(캔버스) 쪽으로 들어가도록 설계되어 있습니다.
73
- 필요 시 `Focus Sketch` 버튼을 누른 뒤 캔버스를 한 번 클릭하면 포커스가 확실해집니다(브라우저 정책에 따라 자동 포커스가 제한될 수 있음).
59
+ ```js
60
+ import { virtualTimeCaptureFromStart, createZipExporter } from "pa_encoder";
74
61
 
75
- ### Exporter
62
+ const exporter = await createZipExporter({ zipName: "frames.zip" });
76
63
 
77
- - **ZIP (download)**: 프레임 PNG를 ZIP으로 묶어 다운로드
78
- - **FS (directory)**: File System Access API로 디렉토리에 저장
79
- - **Best (auto)**: 환경에 맞춰 ZIP 또는 FS 자동 선택
64
+ await virtualTimeCaptureFromStart({
65
+ fps: 60,
66
+ frameCount: 300,
67
+ start: async () => {
68
+ await import("/src/main.js");
69
+ },
70
+ onFrame: async (canvas, i) => {
71
+ const blob = await new Promise((r) => canvas.toBlob(r, "image/png"));
72
+ await exporter.write(i, blob);
73
+ },
74
+ });
80
75
 
81
- ### 지원 범위 / 제한 사항
76
+ await exporter.finalize();
77
+ ```
82
78
 
83
- - DOM에 붙어 있는 `<canvas>`만 캡처합니다.
84
- - WebGL FBO/render target 텍스처를 “직접 선택”해 인코딩하는 기능은 없습니다.
85
- 오프스크린 결과를 화면 canvas로 출력하면 캡처 가능합니다.
86
- - OffscreenCanvas + Worker 렌더링은 Live에서는 동작할 수 있으나, Frame에서 결정성을 보장하지 않습니다.
87
- - cross-origin 이미지/비디오 등을 CORS 설정 없이 텍스처로 사용하면 canvas가 tainted 되어 `toBlob()` 캡처가 실패할 수 있습니다.
79
+ Hooks `requestAnimationFrame`, time APIs, and timers to ensure deterministic output.
88
80
 
89
81
  ---
90
82
 
91
- ### Installation
83
+ ## Exporters
92
84
 
93
- ```bash
94
- npm install pa_encoder
95
- ```
96
-
97
- Or:
85
+ All exporters share the same interface:
98
86
 
99
- ```bash
100
- pnpm add pa_encoder
87
+ ```ts
88
+ {
89
+ write(frameIndex, blob);
90
+ finalize();
91
+ }
101
92
  ```
102
93
 
103
- ### Quick Start
104
-
105
- Run from your project root:
94
+ ### ZIP exporter
106
95
 
107
- ```bash
108
- npx pa_encoder
96
+ ```js
97
+ import { createZipExporter } from "pa_encoder";
98
+ await createZipExporter({ zipName: "frames.zip" });
109
99
  ```
110
100
 
111
- Default assumptions:
112
-
113
- - dev server: http://localhost:5173
114
- - entry file: /src/main.js
115
-
116
- The encoder UI opens in your browser.
117
-
118
- ### CLI Options
101
+ Downloads a ZIP of PNG frames.
119
102
 
120
- ```bash
121
- npx pa_encoder --url <dev_server_url> --entry <entry_path> --port <ui_port>
122
- ```
103
+ ---
123
104
 
124
- Example:
105
+ ### File System exporter (Chromium)
125
106
 
126
- ```bash
127
- npx pa_encoder --url http://localhost:3000 --entry /src/sketch.js
107
+ ```js
108
+ import { createFsExporter } from "pa_encoder";
109
+ await createFsExporter({ dirNameHint: "frames" });
128
110
  ```
129
111
 
130
- ### UI Usage
112
+ Writes directly to a directory (secure context required).
131
113
 
132
- 1. Set **Entry** (e.g. `/src/main.js`).
133
- 2. Choose **Mode**:
134
- - Live: realtime capture with interaction
135
- - Frame: deterministic capture by fps/frames
136
- 3. Select **Canvas** (default: auto).
137
- 4. Click **Start** to begin and **Stop** to finish.
114
+ ---
138
115
 
139
- #### Keyboard interaction vs hotkeys
116
+ ### Best exporter
140
117
 
141
- - When **Idle (not recording)**, UI hotkeys work:
142
- - `H`: hide UI
143
- - `P`: toggle passthrough
144
- - `C`: toggle compact
145
- - `D`: change dock position
146
- - `Space`: start
147
- - When **Running (recording)**, the UI does not consume keyboard events.
148
- This is intended to keep keyboard input going to the sketch/canvas.
149
- If focus is not acquired automatically (browser-dependent), click `Focus Sketch` and then click the canvas once.
118
+ ```js
119
+ import { createBestExporter } from "pa_encoder";
120
+ await createBestExporter({ prefer: "fs" });
121
+ ```
150
122
 
151
- ### Exporters
123
+ Uses File System export when available, otherwise ZIP.
152
124
 
153
- - **ZIP (download)**: bundles PNG frames into a ZIP file
154
- - **FS (directory)**: writes files via the File System Access API
155
- - **Best (auto)**: chooses ZIP or FS depending on the environment
125
+ ---
156
126
 
157
- ### Notes and Limitations
127
+ ## Supported Environments
158
128
 
159
- - Only DOM-attached `<canvas>` elements can be captured.
160
- - Direct selection/encoding of WebGL FBO/render-target textures is not supported.
161
- If the result is drawn to a visible canvas, it can be captured.
162
- - OffscreenCanvas + Worker rendering may work in Live mode, but deterministic behavior is not guaranteed in Frame mode.
163
- - Cross-origin media without proper CORS headers can taint the canvas and make `toBlob()` fail.
129
+ - Modern Chromium-based browsers recommended
130
+ - Requires:
131
+ - ES module Web Workers
132
+ - `OffscreenCanvas`
133
+ - `createImageBitmap`
134
+ - ZIP export works in most modern browsers
135
+ - File System export requires Chromium + secure context
164
136
 
165
137
  ---
166
138
 
167
- ## License
168
-
169
- MIT
139
+ (ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)(ツ)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pa_encoder",
3
3
  "license": "MIT",
4
- "version": "0.2.2",
4
+ "version": "0.2.3",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "files": [