@guilhermebkel/scenec 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +242 -2
- package/dist/catalog.d.ts +21 -0
- package/dist/catalog.js +35 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +118 -0
- package/dist/data/europe.json +1 -0
- package/dist/drawing/assets.d.ts +8 -0
- package/dist/drawing/assets.js +612 -0
- package/dist/drawing/kits.d.ts +7 -0
- package/dist/drawing/kits.js +92 -0
- package/dist/drawing/person.d.ts +18 -0
- package/dist/drawing/person.js +287 -0
- package/dist/drawing/themes.d.ts +4 -0
- package/dist/drawing/themes.js +45 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -0
- package/dist/modes/map.d.ts +5 -0
- package/dist/modes/map.js +365 -0
- package/dist/modes/plane.d.ts +5 -0
- package/dist/modes/plane.js +716 -0
- package/dist/pipeline/compile.d.ts +2 -0
- package/dist/pipeline/compile.js +581 -0
- package/dist/pipeline/custom.d.ts +2 -0
- package/dist/pipeline/custom.js +120 -0
- package/dist/pipeline/groups.d.ts +2 -0
- package/dist/pipeline/groups.js +189 -0
- package/dist/pipeline/index.d.ts +16 -0
- package/dist/pipeline/index.js +7 -0
- package/dist/pipeline/parse.d.ts +10 -0
- package/dist/pipeline/parse.js +80 -0
- package/dist/protocols/options.d.ts +14 -0
- package/dist/protocols/options.js +1 -0
- package/dist/protocols/scene.d.ts +299 -0
- package/dist/protocols/scene.js +118 -0
- package/dist/protocols/theme.d.ts +25 -0
- package/dist/protocols/theme.js +1 -0
- package/dist/render/check.d.ts +6 -0
- package/dist/render/check.js +10 -0
- package/dist/render/critic.d.ts +1 -0
- package/dist/render/critic.js +235 -0
- package/dist/render/files.d.ts +2 -0
- package/dist/render/files.js +16 -0
- package/dist/render/fonts.d.ts +2 -0
- package/dist/render/fonts.js +4 -0
- package/dist/render/png.d.ts +9 -0
- package/dist/render/png.js +13 -0
- package/dist/render.d.ts +5 -0
- package/dist/render.js +3 -0
- package/dist/schema.d.ts +3 -0
- package/dist/schema.js +6 -0
- package/dist/utils/color.d.ts +5 -0
- package/dist/utils/color.js +35 -0
- package/dist/utils/recolor.d.ts +1 -0
- package/dist/utils/recolor.js +56 -0
- package/dist/utils/sanitize.d.ts +5 -0
- package/dist/utils/sanitize.js +169 -0
- package/dist/utils/suggest.d.ts +1 -0
- package/dist/utils/suggest.js +22 -0
- package/dist/utils/svg.d.ts +2 -0
- package/dist/utils/svg.js +11 -0
- package/fonts/OFL.txt +50 -0
- package/fonts/Poppins-Bold.ttf +0 -0
- package/fonts/Poppins-Medium.ttf +0 -0
- package/fonts/Poppins-Regular.ttf +0 -0
- package/package.json +96 -4
- package/skills/scenec/SKILL.md +46 -0
- package/skills/scenec/recipes/anuncios-variacoes.yaml +58 -0
- package/skills/scenec/recipes/carrossel.yaml +58 -0
- package/skills/scenec/recipes/elearning.yaml +64 -0
- package/skills/scenec/recipes/historia-ilustrada.yaml +48 -0
- package/skills/scenec/recipes/ilustracoes-produto.yaml +44 -0
- package/skills/scenec/recipes/mapas-jornadas.yaml +27 -0
- package/skills/scenec/recipes/reels-explicativo.yaml +41 -0
- package/skills/scenec/recipes/wrapped-personalizado.yaml +64 -0
- package/skills/scenec/references/catalog.md +125 -0
- package/skills/scenec/references/dsl.md +111 -0
- package/skills/scenec/references/fontes.md +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Guilherme Mota
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,243 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">scenec</h1>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>Illustrate with text: a YAML scene in, an SVG out, and written feedback on what is wrong with it.</strong>
|
|
5
|
+
<br />
|
|
6
|
+
<em>Built for AIs that cannot see images: they still draw, check and fix an illustration without looking at it. CPU only, no image model. Works with Claude Code, Codex and Cursor.</em>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="#quick-start"><img src="https://img.shields.io/badge/Quick_start-d4a574" alt="Quick start" /></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@guilhermebkel/scenec"><img src="https://img.shields.io/npm/v/@guilhermebkel/scenec?color=d4a574&label=npm" alt="npm version" /></a>
|
|
12
|
+
<a href="https://github.com/guilhermebkel/scenec/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/guilhermebkel/scenec/ci.yml?branch=main&label=CI" alt="CI" /></a>
|
|
13
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow" alt="License: MIT" /></a>
|
|
14
|
+
<img src="https://img.shields.io/badge/Telemetry-none-2ea44f" alt="No telemetry" />
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<img src="docs/assets/banner.png" alt="An illustration made by scenec from a 40-line YAML scene" width="520" />
|
|
19
|
+
<br />
|
|
20
|
+
<sub>This image was drawn by scenec from <a href="skills/scenec/recipes/historia-ilustrada.yaml">a short YAML scene</a>.</sub>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
**An AI that cannot see its own drawing has no way to know if it is good.** Image models need a picture-capable model and are not repeatable. Hand-written SVG has no feedback loop.
|
|
26
|
+
|
|
27
|
+
`scenec` gives the AI a closed vocabulary (86 assets, ready-made groups, a map of Europe, 6 styles) and a compiler that **measures what it drew**: it returns the SVG plus warnings, an art director's critiques and a text description of where everything landed. The AI fixes the scene and runs it again until the report is clean.
|
|
28
|
+
|
|
29
|
+
> **Fix the scene, not the SVG.** The skill tells the agent to never edit the SVG by hand: every correction goes back through the scene, so the result stays repeatable.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## What you get
|
|
34
|
+
|
|
35
|
+
<table>
|
|
36
|
+
<tr>
|
|
37
|
+
<td width="50%" valign="top">
|
|
38
|
+
|
|
39
|
+
**Warnings**
|
|
40
|
+
|
|
41
|
+
Fields it did not understand, with a "did you mean"; missing assets; objects out of frame. A typo costs one more cycle, not a failure.
|
|
42
|
+
|
|
43
|
+
</td>
|
|
44
|
+
<td width="50%" valign="top">
|
|
45
|
+
|
|
46
|
+
**Art critiques**
|
|
47
|
+
|
|
48
|
+
An art director's remarks in text: empty bands, overlaps, low contrast, a crowded corner, a scene too small for its frame.
|
|
49
|
+
|
|
50
|
+
</td>
|
|
51
|
+
</tr>
|
|
52
|
+
<tr>
|
|
53
|
+
<td valign="top">
|
|
54
|
+
|
|
55
|
+
**A description of the layout**
|
|
56
|
+
|
|
57
|
+
Position, size and depth of every object, so the AI can reason about composition without seeing it.
|
|
58
|
+
|
|
59
|
+
</td>
|
|
60
|
+
<td valign="top">
|
|
61
|
+
|
|
62
|
+
**Repeatable output**
|
|
63
|
+
|
|
64
|
+
The same scene gives the same SVG on any machine. A bundled font makes the PNG look the same everywhere.
|
|
65
|
+
|
|
66
|
+
</td>
|
|
67
|
+
</tr>
|
|
68
|
+
</table>
|
|
69
|
+
|
|
70
|
+
## Quick start
|
|
71
|
+
|
|
72
|
+
### 1. Install the skill
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npx skills add guilhermebkel/scenec -g
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The [`skills`](https://github.com/vercel-labs/skills) CLI asks which of your agents (Claude Code, Codex, Cursor) should get the skill. Name them to skip the question (`-a claude-code -a codex -a cursor`), or drop `-g` to install only in the current project. Running scenec needs Node.js 20+; `npx` fetches it on first use.
|
|
79
|
+
|
|
80
|
+
### 2. Ask for an illustration
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
Draw a vertical cover for a reel explaining compound interest, flat blue style.
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The agent picks one of 8 recipes (reel, carousel, "wrapped" card, e-learning, illustrated story, route map, ad variations, product), changes the content, checks, fixes up to 5 times and renders.
|
|
87
|
+
|
|
88
|
+
### 3. Or use the CLI yourself
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npx @guilhermebkel/scenec@1 check scene.yaml # warnings and critiques; exit code 1 if there are any
|
|
92
|
+
npx @guilhermebkel/scenec@1 render scene.yaml -o out --png # out.svg and out.png, plus a JSON report
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Example
|
|
96
|
+
|
|
97
|
+
<sub>Real output of a first draft (messages are still in Portuguese, see the FAQ).</sub>
|
|
98
|
+
|
|
99
|
+
```yaml
|
|
100
|
+
canvas: { width: 1000, height: 1000, theme: flat-autumn, setting: outdoor, horizon: 0.6, base: 0.84 }
|
|
101
|
+
objects:
|
|
102
|
+
arvore: { asset: tree, at: 0.15, depth: mid }
|
|
103
|
+
menina: { asset: person, pose: hands_on_hips, at: 0.45, hair_color: red, size: large }
|
|
104
|
+
rex: { asset: dog, right_of: menina, facing: left }
|
|
105
|
+
banco: { asset: bench, at: 0.85 }
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```text
|
|
109
|
+
$ npx @guilhermebkel/scenec@1 check scene.yaml
|
|
110
|
+
warnings:
|
|
111
|
+
'banco' está 10% fora do quadro
|
|
112
|
+
'rex' sobrepõe 'banco' em 36%; use left_of/right_of ou depth diferente
|
|
113
|
+
art:
|
|
114
|
+
peso visual pende para a esquerda (centro de massa em 35% da largura); aproxime 'arvore' do centro ou ponha algo do lado direito
|
|
115
|
+
'rex' some contra o fundo na parte do meio (41% desse contorno sem contraste): mude a cor de um dos dois
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The agent moves the bench in, gives the dog another color, runs `check` again, and renders when the report is empty.
|
|
119
|
+
|
|
120
|
+
## What it draws
|
|
121
|
+
|
|
122
|
+
86 assets (people with poses and expressions, furniture, plants, food, vehicles, buildings), ready-made groups, a map of Europe with routes, and 6 kits:
|
|
123
|
+
|
|
124
|
+
| Kit | Look |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| `flat` | Flat vector with soft light (default) |
|
|
127
|
+
| `outline` | Cartoon outline: thick on the silhouette, thin inside |
|
|
128
|
+
| `hatch` | Engraving / comic: ink outline and hatched shadows |
|
|
129
|
+
| `riso` | Risograph: few vivid inks, print grain, slight misregistration |
|
|
130
|
+
| `paper` | Paper cut-out: each piece with its own shadow and fiber texture |
|
|
131
|
+
| `sketch` | Hand-drawn pencil look |
|
|
132
|
+
|
|
133
|
+
`npx @guilhermebkel/scenec@1 catalog assets` lists everything; the full language is in [`skills/scenec/references/dsl.md`](skills/scenec/references/dsl.md).
|
|
134
|
+
|
|
135
|
+
## How it works
|
|
136
|
+
|
|
137
|
+
```text
|
|
138
|
+
your scene ──▶ 1. PARSE ──▶ 2. COMPOSE ──▶ 3. DRAW ──▶ 4. CRITIQUE
|
|
139
|
+
(YAML) validate place objects SVG, kit measure and
|
|
140
|
+
and suggest in the frame and light write remarks
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The work is split on purpose:
|
|
144
|
+
|
|
145
|
+
| Part | Does | Why |
|
|
146
|
+
| --- | --- | --- |
|
|
147
|
+
| **Pure core** (`@guilhermebkel/scenec`) | Parses, lays out and draws the SVG | Same scene, same SVG, on any machine. No file system, clock or randomness. |
|
|
148
|
+
| **Renderer** (`@guilhermebkel/scenec/render`) | Measures boxes, rasterizes PNG, runs the critic | Needs the native renderer ([resvg](https://github.com/yisibl/resvg-js)); kept out of the core. |
|
|
149
|
+
| **Your agent**, running the skill | Picks a recipe, writes the scene, reads the report, fixes | Taste and intent are the agent's job. |
|
|
150
|
+
|
|
151
|
+
### As a library
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { compile } from "@guilhermebkel/scenec"; // pure: no native code, no file system
|
|
155
|
+
import { check, renderPng } from "@guilhermebkel/scenec/render"; // needs the native renderer
|
|
156
|
+
import { sceneJsonSchema, catalog } from "@guilhermebkel/scenec/schema";
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
<details>
|
|
160
|
+
<summary><b>CLI reference</b></summary>
|
|
161
|
+
|
|
162
|
+
| Command | What it does |
|
|
163
|
+
| --- | --- |
|
|
164
|
+
| `scenec render <scene.yaml> [-o name] [--png] [--width 1200]` | Writes the SVG (and PNG) and prints the JSON report. |
|
|
165
|
+
| `scenec check <scene.yaml>` | Compiles and critiques without writing files. Exit code 1 on a warning or critique, 2 when the scene is invalid. |
|
|
166
|
+
| `scenec catalog [assets\|groups\|kits\|themes\|poses\|layout]` | Lists the vocabulary a scene can use. |
|
|
167
|
+
| `scenec schema` | Prints the JSON Schema of the scene. |
|
|
168
|
+
|
|
169
|
+
Everything it prints is JSON (`schemaVersion: 1`).
|
|
170
|
+
|
|
171
|
+
</details>
|
|
172
|
+
|
|
173
|
+
## Privacy and safety
|
|
174
|
+
|
|
175
|
+
- **Everything runs locally.** No network calls, no telemetry. Nothing leaves your machine.
|
|
176
|
+
- **Files stay in the scene folder.** The file reader refuses `..` and absolute paths.
|
|
177
|
+
- **Custom SVG is allowlisted.** Scripts, `on*` handlers, external links, `<style>` and entities are removed or rejected.
|
|
178
|
+
- **Limits.** At most 200 objects and a 4096 px frame per scene.
|
|
179
|
+
|
|
180
|
+
Found a way around any of this? See [SECURITY.md](SECURITY.md).
|
|
181
|
+
|
|
182
|
+
## How it compares
|
|
183
|
+
|
|
184
|
+
- **Image-generation models** produce richer pictures, but need a model that can see, cost money per image and are not repeatable. `scenec` trades open-ended style for a closed vocabulary it can measure.
|
|
185
|
+
- **Hand-written SVG or diagram languages** (Mermaid, Graphviz) are repeatable, but give no feedback on composition and cover charts, not illustrated scenes.
|
|
186
|
+
- **Design tools with an API** need a canvas and a human eye in the loop.
|
|
187
|
+
|
|
188
|
+
## FAQ
|
|
189
|
+
|
|
190
|
+
<details>
|
|
191
|
+
<summary><b>Does it need an image model or a GPU?</b></summary>
|
|
192
|
+
|
|
193
|
+
No. It is plain CPU code: geometry, drawing and a rasterizer. Nothing is downloaded at run time.
|
|
194
|
+
|
|
195
|
+
</details>
|
|
196
|
+
|
|
197
|
+
<details>
|
|
198
|
+
<summary><b>Can I add my own drawings?</b></summary>
|
|
199
|
+
|
|
200
|
+
Yes. Under `assets:` a scene can bring an SVG (inline or a file next to the scene) or an image. Custom SVG goes through the sanitizer.
|
|
201
|
+
|
|
202
|
+
</details>
|
|
203
|
+
|
|
204
|
+
<details>
|
|
205
|
+
<summary><b>The messages are in Portuguese. Why?</b></summary>
|
|
206
|
+
|
|
207
|
+
It is known debt from the prototype and is tracked in [issue #1](https://github.com/guilhermebkel/scenec/issues/1), together with the move to English.
|
|
208
|
+
|
|
209
|
+
</details>
|
|
210
|
+
|
|
211
|
+
## Roadmap
|
|
212
|
+
|
|
213
|
+
- [x] **Core:** 86 assets, groups, map mode, 6 kits, warnings, critiques, CLI, skill, 108 visual baselines.
|
|
214
|
+
- [ ] **Tech debt** ([#1](https://github.com/guilhermebkel/scenec/issues/1)): classes, English messages, strict lint on every file.
|
|
215
|
+
- [ ] **More recipes and assets** driven by real use of the skill.
|
|
216
|
+
|
|
217
|
+
## Contributing
|
|
218
|
+
|
|
219
|
+
Issues and pull requests are welcome. Start with [CONTRIBUTING.md](CONTRIBUTING.md); vocabulary is in [GLOSSARY.md](GLOSSARY.md) and design decisions in [`docs/adr/`](docs/adr/).
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pnpm install
|
|
223
|
+
pnpm check # typecheck, lint, dead code, duplication, tests, build, package checks and visual baselines
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
<p align="center">
|
|
229
|
+
<strong>Let the AI draw. Let the compiler tell it what it drew.</strong>
|
|
230
|
+
</p>
|
|
231
|
+
|
|
232
|
+
<p align="center">
|
|
233
|
+
<a href="https://www.star-history.com/#guilhermebkel/scenec&Date">
|
|
234
|
+
<picture>
|
|
235
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=guilhermebkel/scenec&type=Date&theme=dark" />
|
|
236
|
+
<img alt="Star history" src="https://api.star-history.com/svg?repos=guilhermebkel/scenec&type=Date" width="600" />
|
|
237
|
+
</picture>
|
|
238
|
+
</a>
|
|
239
|
+
</p>
|
|
240
|
+
|
|
241
|
+
<p align="center">
|
|
242
|
+
MIT License © Guilherme Mota
|
|
243
|
+
</p>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const CATALOG_KINDS: readonly ["assets", "groups", "kits", "themes", "poses", "layout"];
|
|
2
|
+
export type CatalogKind = typeof CATALOG_KINDS[number];
|
|
3
|
+
export interface AssetEntry {
|
|
4
|
+
id: string;
|
|
5
|
+
kind: string;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
synonyms: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function listAssets(): AssetEntry[];
|
|
11
|
+
export declare function listGroups(): {
|
|
12
|
+
id: string;
|
|
13
|
+
description: string;
|
|
14
|
+
parts: Record<string, string>;
|
|
15
|
+
}[];
|
|
16
|
+
export declare function listKits(): {
|
|
17
|
+
id: string;
|
|
18
|
+
description: string;
|
|
19
|
+
}[];
|
|
20
|
+
export declare function listThemes(): string[];
|
|
21
|
+
export declare function catalog(kind: CatalogKind): unknown;
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ASSETS } from "./drawing/assets.js";
|
|
2
|
+
import { KITS } from "./drawing/kits.js";
|
|
3
|
+
import { EXPRESSION_NAMES, POSE_NAMES } from "./drawing/person.js";
|
|
4
|
+
import { THEMES } from "./drawing/themes.js";
|
|
5
|
+
import { GROUPS } from "./pipeline/groups.js";
|
|
6
|
+
import { DEPTH_NAMES, SETTING_NAMES, SHOT_NAMES, SIZE_NAMES, SLOT_NAMES } from "./protocols/scene.js";
|
|
7
|
+
export const CATALOG_KINDS = ["assets", "groups", "kits", "themes", "poses", "layout"];
|
|
8
|
+
export function listAssets() {
|
|
9
|
+
return Object.entries(ASSETS).map(([id, asset]) => ({
|
|
10
|
+
id, kind: asset.kind, width: asset.w, height: asset.h, synonyms: (asset.tags ?? []),
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
export function listGroups() {
|
|
14
|
+
return Object.entries(GROUPS).map(([id, group]) => {
|
|
15
|
+
const built = group.build({ at: 0.5 });
|
|
16
|
+
const parts = Object.fromEntries(Object.entries(built).map(([part, def]) => [part, def.asset]));
|
|
17
|
+
return { id, description: group.desc, parts };
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export function listKits() {
|
|
21
|
+
return Object.entries(KITS).map(([id, kit]) => ({ id, description: kit.desc }));
|
|
22
|
+
}
|
|
23
|
+
export function listThemes() {
|
|
24
|
+
return Object.keys(THEMES);
|
|
25
|
+
}
|
|
26
|
+
export function catalog(kind) {
|
|
27
|
+
switch (kind) {
|
|
28
|
+
case "assets": return listAssets();
|
|
29
|
+
case "groups": return listGroups();
|
|
30
|
+
case "kits": return listKits();
|
|
31
|
+
case "themes": return listThemes();
|
|
32
|
+
case "poses": return { ...POSE_NAMES, expressions: EXPRESSION_NAMES };
|
|
33
|
+
case "layout": return { slots: SLOT_NAMES, sizes: SIZE_NAMES, depths: DEPTH_NAMES, settings: SETTING_NAMES, shots: SHOT_NAMES };
|
|
34
|
+
}
|
|
35
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { CATALOG_KINDS, catalog, sceneJsonSchema } from "./schema.js";
|
|
6
|
+
import { SceneError } from "./pipeline/parse.js";
|
|
7
|
+
import { check, createFileReader, renderPng } from "./render.js";
|
|
8
|
+
const SCHEMA_VERSION = 1;
|
|
9
|
+
const CHARS_PER_TOKEN = 3.6;
|
|
10
|
+
const BYTES_PER_KB = 1024;
|
|
11
|
+
const DEFAULT_WIDTH = 1200;
|
|
12
|
+
const EXIT_FINDINGS = 1;
|
|
13
|
+
const EXIT_INVALID = 2;
|
|
14
|
+
const HELP = `scenec: turns a YAML scene into an illustrated SVG.
|
|
15
|
+
|
|
16
|
+
scenec render <scene.yaml> [-o <output without extension>] [--png] [--width 1200]
|
|
17
|
+
Compiles and writes the SVG (and a PNG with --png). Prints the JSON report.
|
|
18
|
+
scenec check <scene.yaml>
|
|
19
|
+
Compiles and critiques without writing files. Exit code 1 when there is a warning or a critique.
|
|
20
|
+
scenec catalog [${CATALOG_KINDS.join("|")}]
|
|
21
|
+
Lists the vocabulary a scene can use.
|
|
22
|
+
scenec schema
|
|
23
|
+
Prints the JSON Schema of the scene.
|
|
24
|
+
`;
|
|
25
|
+
function print(value) {
|
|
26
|
+
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
27
|
+
}
|
|
28
|
+
function round(value, digits = 1) {
|
|
29
|
+
return Number(value.toFixed(digits));
|
|
30
|
+
}
|
|
31
|
+
function runScene(file, shouldWrite, output, png, width) {
|
|
32
|
+
const source = fs.readFileSync(file, "utf8");
|
|
33
|
+
const started = performance.now();
|
|
34
|
+
const result = check(source, { files: createFileReader(path.dirname(path.resolve(file))) });
|
|
35
|
+
const compiled = performance.now();
|
|
36
|
+
const written = {};
|
|
37
|
+
let pngKb = null;
|
|
38
|
+
if (shouldWrite) {
|
|
39
|
+
const base = output ?? path.join("out", path.basename(file).replace(/\.ya?ml$/, ""));
|
|
40
|
+
fs.mkdirSync(path.dirname(base), { recursive: true });
|
|
41
|
+
fs.writeFileSync(`${base}.svg`, result.svg);
|
|
42
|
+
written.svg = `${base}.svg`;
|
|
43
|
+
if (png) {
|
|
44
|
+
const raster = renderPng(result.svg, width);
|
|
45
|
+
fs.writeFileSync(`${base}.png`, raster.png);
|
|
46
|
+
written.png = `${base}.png`;
|
|
47
|
+
pngKb = round(raster.png.length / BYTES_PER_KB);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const done = performance.now();
|
|
51
|
+
print({
|
|
52
|
+
schemaVersion: SCHEMA_VERSION,
|
|
53
|
+
file,
|
|
54
|
+
written,
|
|
55
|
+
warnings: result.warnings,
|
|
56
|
+
art: result.art,
|
|
57
|
+
description: result.description.split("\n"),
|
|
58
|
+
stats: {
|
|
59
|
+
sceneTokensApprox: Math.round(source.length / CHARS_PER_TOKEN),
|
|
60
|
+
svgTokensApprox: Math.round(result.svg.length / CHARS_PER_TOKEN),
|
|
61
|
+
compileMs: round(compiled - started),
|
|
62
|
+
renderMs: round(done - compiled),
|
|
63
|
+
svgKb: round(result.svg.length / BYTES_PER_KB),
|
|
64
|
+
pngKb,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
return result.warnings.length + result.art.length > 0 ? EXIT_FINDINGS : 0;
|
|
68
|
+
}
|
|
69
|
+
function main(argv) {
|
|
70
|
+
const [command, ...rest] = argv;
|
|
71
|
+
const { values, positionals } = parseArgs({
|
|
72
|
+
args: rest,
|
|
73
|
+
allowPositionals: true,
|
|
74
|
+
options: {
|
|
75
|
+
output: { type: "string", short: "o" },
|
|
76
|
+
png: { type: "boolean", default: false },
|
|
77
|
+
width: { type: "string", default: String(DEFAULT_WIDTH) },
|
|
78
|
+
help: { type: "boolean", short: "h", default: false },
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
if (!command || command === "help" || values.help) {
|
|
82
|
+
process.stdout.write(HELP);
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
if (command === "schema") {
|
|
86
|
+
print(sceneJsonSchema());
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
if (command === "catalog") {
|
|
90
|
+
const kind = positionals[0];
|
|
91
|
+
if (!kind) {
|
|
92
|
+
print({ kinds: CATALOG_KINDS });
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
if (!CATALOG_KINDS.includes(kind)) {
|
|
96
|
+
print({ schemaVersion: SCHEMA_VERSION, errors: [`catalog '${kind}' não existe; use ${CATALOG_KINDS.join(", ")}`] });
|
|
97
|
+
return EXIT_INVALID;
|
|
98
|
+
}
|
|
99
|
+
print(catalog(kind));
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
if ((command === "render" || command === "check") && positionals[0]) {
|
|
103
|
+
const file = positionals[0];
|
|
104
|
+
try {
|
|
105
|
+
return runScene(file, command === "render", values.output, values.png, Number(values.width));
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
if (error instanceof SceneError) {
|
|
109
|
+
print({ schemaVersion: SCHEMA_VERSION, file, errors: error.errors });
|
|
110
|
+
return EXIT_INVALID;
|
|
111
|
+
}
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
process.stderr.write(HELP);
|
|
116
|
+
return EXIT_INVALID;
|
|
117
|
+
}
|
|
118
|
+
process.exitCode = main(process.argv.slice(2));
|