route-graphics 1.8.3 → 1.9.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/README.md +110 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -85,12 +85,122 @@ For complete usage details, go to:
|
|
|
85
85
|
- [Events & Render Complete](http://route-graphics.routevn.com/docs/guides/events-render-complete/)
|
|
86
86
|
- [Custom Plugins](http://route-graphics.routevn.com/docs/guides/custom-plugins/)
|
|
87
87
|
|
|
88
|
+
## PNG Render CLI Scaffold
|
|
89
|
+
|
|
90
|
+
This repo now includes a repo-local CLI scaffold that renders YAML into a PNG by:
|
|
91
|
+
|
|
92
|
+
1. reading YAML in Node,
|
|
93
|
+
2. launching headless Chromium through Playwright,
|
|
94
|
+
3. rendering with the bundled `dist/RouteGraphics.js`, and
|
|
95
|
+
4. exporting pixels with `app.extractBase64()`.
|
|
96
|
+
|
|
97
|
+
It is intentionally scaffolded as a repo workflow first, not a published package entrypoint yet.
|
|
98
|
+
|
|
99
|
+
Full CLI reference: [`docs/png-render-cli.md`](./docs/png-render-cli.md)
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# one-time browser install if Chromium is not already available
|
|
103
|
+
npx playwright install chromium
|
|
104
|
+
|
|
105
|
+
# render a YAML file to PNG
|
|
106
|
+
bun run render:png -- ./examples/hello.yaml -o ./out/hello.png
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Supported top-level YAML shapes:
|
|
110
|
+
|
|
111
|
+
- A single state object
|
|
112
|
+
- An array of states
|
|
113
|
+
- A wrapper object with `width`, `height`, `backgroundColor`, optional `assets`, and either `state` or `states`
|
|
114
|
+
- Multiple YAML documents separated by `---` (treated as a state list)
|
|
115
|
+
|
|
116
|
+
Minimal example:
|
|
117
|
+
|
|
118
|
+
```yaml
|
|
119
|
+
width: 1280
|
|
120
|
+
height: 720
|
|
121
|
+
backgroundColor: "#101820"
|
|
122
|
+
elements:
|
|
123
|
+
- id: title
|
|
124
|
+
type: text
|
|
125
|
+
x: 80
|
|
126
|
+
y: 80
|
|
127
|
+
content: "Hello PNG"
|
|
128
|
+
textStyle:
|
|
129
|
+
fill: "#ffffff"
|
|
130
|
+
fontSize: 48
|
|
131
|
+
- id: bar
|
|
132
|
+
type: rect
|
|
133
|
+
x: 80
|
|
134
|
+
y: 160
|
|
135
|
+
width: 320
|
|
136
|
+
height: 24
|
|
137
|
+
fill: "#4fd1c5"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Asset handling:
|
|
141
|
+
|
|
142
|
+
- Asset-bearing render-state fields such as `src`, `thumbSrc`, `barSrc`, `inactiveBarSrc`, and `soundSrc` must reference top-level `assets` aliases.
|
|
143
|
+
- Direct file paths and URLs are allowed inside top-level `assets` values.
|
|
144
|
+
- Direct asset references inside `elements`, `audio`, or nested interaction config are rejected.
|
|
145
|
+
|
|
146
|
+
Example with asset aliases:
|
|
147
|
+
|
|
148
|
+
```yaml
|
|
149
|
+
width: 1280
|
|
150
|
+
height: 720
|
|
151
|
+
assets:
|
|
152
|
+
hero: ./assets/hero.png
|
|
153
|
+
uiFont:
|
|
154
|
+
path: ./assets/fonts/NotoSans-Regular.ttf
|
|
155
|
+
type: font/ttf
|
|
156
|
+
elements:
|
|
157
|
+
- id: title
|
|
158
|
+
type: text
|
|
159
|
+
x: 60
|
|
160
|
+
y: 60
|
|
161
|
+
content: "Alias-backed render"
|
|
162
|
+
textStyle:
|
|
163
|
+
fill: "#ffffff"
|
|
164
|
+
fontSize: 42
|
|
165
|
+
fontFamily: uiFont
|
|
166
|
+
- id: avatar
|
|
167
|
+
type: sprite
|
|
168
|
+
x: 60
|
|
169
|
+
y: 140
|
|
170
|
+
width: 128
|
|
171
|
+
height: 128
|
|
172
|
+
src: hero
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Invalid example:
|
|
176
|
+
|
|
177
|
+
```yaml
|
|
178
|
+
elements:
|
|
179
|
+
- id: avatar
|
|
180
|
+
type: sprite
|
|
181
|
+
x: 60
|
|
182
|
+
y: 140
|
|
183
|
+
width: 128
|
|
184
|
+
height: 128
|
|
185
|
+
src: ./assets/hero.png # rejected by the CLI
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Useful flags:
|
|
189
|
+
|
|
190
|
+
- `--state <index>` selects a state from an array or multi-document YAML file.
|
|
191
|
+
- `--time <ms>` samples animations at a specific manual timeline position.
|
|
192
|
+
- `--wait-for-render-complete` waits for a `renderComplete` event before capture.
|
|
193
|
+
- `--browser-executable <path>` uses a system Chrome/Chromium instead of Playwright's managed browser.
|
|
194
|
+
|
|
88
195
|
## Development
|
|
89
196
|
|
|
90
197
|
```bash
|
|
91
198
|
# Run tests
|
|
92
199
|
bun run test
|
|
93
200
|
|
|
201
|
+
# Render a YAML file into a PNG
|
|
202
|
+
bun run render:png -- ./examples/hello.yaml -o ./out/hello.png
|
|
203
|
+
|
|
94
204
|
# Ensure VT assets are real binaries, not Git LFS pointer files
|
|
95
205
|
git lfs pull
|
|
96
206
|
git lfs checkout
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "route-graphics",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "A 2D graphics rendering interface that takes JSON input and renders pixels using PixiJS",
|
|
5
5
|
"main": "dist/RouteGraphics.js",
|
|
6
6
|
"type": "module",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"lint:fix": "bunx prettier --write src",
|
|
31
31
|
"prepare": "husky",
|
|
32
32
|
"build": "bunx esbuild ./src/index.js --bundle --minify --format=esm --outfile=./dist/RouteGraphics.js && bunx esbuild ./src/index.js --bundle --sourcemap --format=esm --outfile=./vt/static/RouteGraphics.js && mkdir -p ./.rettangoli/vt/_site && cp ./vt/static/RouteGraphics.js ./.rettangoli/vt/_site/RouteGraphics.js && cp ./vt/static/RouteGraphics.js.map ./.rettangoli/vt/_site/RouteGraphics.js.map",
|
|
33
|
+
"render:png": "bun run build && node ./bin/route-graphics-render.js",
|
|
33
34
|
"vt:docker:pull": "docker pull docker.io/han4wluc/rtgl:playwright-v1.57.0-rtgl-v1.1.0",
|
|
34
35
|
"vt:generate": "bun run build && docker run --rm --user $(id -u):$(id -g) -e RTGL_VT_DEBUG=true -v \"$PWD:/workspace\" docker.io/han4wluc/rtgl:playwright-v1.57.0-rtgl-v1.1.0 rtgl vt generate --wait-event vt:ready",
|
|
35
36
|
"vt:screenshot": "bun run build && docker run --rm --user $(id -u):$(id -g) -e RTGL_VT_DEBUG=true -e RTGL_VT_CONCURRENCY=${RTGL_VT_CONCURRENCY:-8} -v \"$PWD:/workspace\" docker.io/han4wluc/rtgl:playwright-v1.57.0-rtgl-v1.1.0 rtgl vt screenshot --wait-event vt:ready --concurrency ${RTGL_VT_CONCURRENCY:-8}",
|