@guilhermebkel/scenec 0.2.0 → 0.2.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/README.md +23 -12
- package/dist/Adapters/FontAdapter.js +5 -1
- package/dist/Commands/BestCommand.d.ts +11 -0
- package/dist/Commands/BestCommand.js +73 -0
- package/dist/Commands/RenderCommand.d.ts +2 -0
- package/dist/Commands/RenderCommand.js +7 -0
- package/dist/Modules/BestModule.d.ts +41 -0
- package/dist/Modules/BestModule.js +159 -0
- package/dist/Modules/CompilationModule.d.ts +5 -0
- package/dist/Modules/CompilationModule.js +92 -19
- package/dist/Modules/CritiqueModule.d.ts +3 -0
- package/dist/Modules/CritiqueModule.js +60 -5
- package/dist/Protocols/AssetProtocol.d.ts +6 -1
- package/dist/Protocols/AssetProtocol.js +17 -1
- package/dist/Protocols/CommandProtocol.d.ts +2 -0
- package/dist/Protocols/CompilationProtocol.d.ts +27 -1
- package/dist/Protocols/CritiqueProtocol.d.ts +17 -1
- package/dist/Protocols/CritiqueProtocol.js +11 -1
- package/dist/Protocols/KitProtocol.d.ts +8 -2
- package/dist/Protocols/KitProtocol.js +8 -2
- package/dist/Protocols/PersonProtocol.d.ts +4 -0
- package/dist/Protocols/PersonProtocol.js +2 -0
- package/dist/Protocols/SceneProtocol.d.ts +204 -5
- package/dist/Protocols/SceneProtocol.js +60 -7
- package/dist/Resources/Assets/BaseAsset.d.ts +1 -0
- package/dist/Resources/Assets/BaseAsset.js +1 -0
- package/dist/Resources/Assets/BigPlantAsset.js +8 -1
- package/dist/Resources/Assets/BlackboardAsset.d.ts +11 -0
- package/dist/Resources/Assets/BlackboardAsset.js +20 -0
- package/dist/Resources/Assets/BushAsset.js +1 -1
- package/dist/Resources/Assets/ChairAsset.d.ts +5 -0
- package/dist/Resources/Assets/ChairAsset.js +23 -0
- package/dist/Resources/Assets/ChatBubbleAsset.d.ts +11 -0
- package/dist/Resources/Assets/ChatBubbleAsset.js +18 -0
- package/dist/Resources/Assets/CloudAsset.js +3 -1
- package/dist/Resources/Assets/ConfettiAsset.d.ts +10 -0
- package/dist/Resources/Assets/ConfettiAsset.js +18 -0
- package/dist/Resources/Assets/CursorAsset.d.ts +11 -0
- package/dist/Resources/Assets/CursorAsset.js +17 -0
- package/dist/Resources/Assets/DeskAsset.js +7 -2
- package/dist/Resources/Assets/FirstAidKitAsset.d.ts +10 -0
- package/dist/Resources/Assets/FirstAidKitAsset.js +19 -0
- package/dist/Resources/Assets/GlobeAsset.d.ts +10 -0
- package/dist/Resources/Assets/GlobeAsset.js +18 -0
- package/dist/Resources/Assets/HouseAsset.js +22 -6
- package/dist/Resources/Assets/LaptopAsset.js +5 -1
- package/dist/Resources/Assets/PlantAsset.js +1 -1
- package/dist/Resources/Assets/PodiumAsset.d.ts +11 -0
- package/dist/Resources/Assets/PodiumAsset.js +20 -0
- package/dist/Resources/Assets/RefrigeratorAsset.d.ts +11 -0
- package/dist/Resources/Assets/RefrigeratorAsset.js +21 -0
- package/dist/Resources/Assets/SinkAsset.d.ts +11 -0
- package/dist/Resources/Assets/SinkAsset.js +21 -0
- package/dist/Resources/Assets/SofaAsset.d.ts +5 -0
- package/dist/Resources/Assets/SofaAsset.js +30 -2
- package/dist/Resources/Assets/StarsAsset.d.ts +6 -0
- package/dist/Resources/Assets/StarsAsset.js +37 -24
- package/dist/Resources/Assets/StethoscopeAsset.d.ts +10 -0
- package/dist/Resources/Assets/StethoscopeAsset.js +18 -0
- package/dist/Resources/Assets/StoveAsset.d.ts +11 -0
- package/dist/Resources/Assets/StoveAsset.js +20 -0
- package/dist/Resources/Assets/ToggleAsset.d.ts +11 -0
- package/dist/Resources/Assets/ToggleAsset.js +21 -0
- package/dist/Resources/Assets/TreeAsset.d.ts +5 -0
- package/dist/Resources/Assets/TreeAsset.js +32 -7
- package/dist/Resources/Assets/WaterCoolerAsset.d.ts +11 -0
- package/dist/Resources/Assets/WaterCoolerAsset.js +20 -0
- package/dist/Resources/Assets/WhiteboardAsset.d.ts +10 -0
- package/dist/Resources/Assets/WhiteboardAsset.js +18 -0
- package/dist/Resources/Kits/BaseKit.d.ts +2 -1
- package/dist/Resources/Kits/BaseKit.js +1 -0
- package/dist/Resources/Kits/ClayKit.d.ts +9 -0
- package/dist/Resources/Kits/ClayKit.js +11 -0
- package/dist/Resources/Kits/DuotoneKit.d.ts +16 -0
- package/dist/Resources/Kits/DuotoneKit.js +18 -0
- package/dist/Resources/Kits/IsometricKit.d.ts +8 -0
- package/dist/Resources/Kits/IsometricKit.js +10 -0
- package/dist/Resources/Kits/OutlineKit.d.ts +3 -0
- package/dist/Resources/Kits/OutlineKit.js +1 -1
- package/dist/Resources/Kits/PaperKit.d.ts +2 -0
- package/dist/Resources/Kits/PaperKit.js +1 -0
- package/dist/Resources/Kits/PosterKit.d.ts +14 -0
- package/dist/Resources/Kits/PosterKit.js +16 -0
- package/dist/Resources/Kits/SketchKit.d.ts +2 -1
- package/dist/Resources/Kits/SketchKit.js +1 -0
- package/dist/Services/AssetService.js +29 -1
- package/dist/Services/BackgroundService.d.ts +10 -2
- package/dist/Services/BackgroundService.js +52 -11
- package/dist/Services/CatalogService.d.ts +1 -0
- package/dist/Services/CatalogService.js +8 -3
- package/dist/Services/ColorCritiqueService.d.ts +42 -0
- package/dist/Services/ColorCritiqueService.js +232 -0
- package/dist/Services/ContextService.js +9 -5
- package/dist/Services/DescriptionService.d.ts +2 -1
- package/dist/Services/DescriptionService.js +8 -2
- package/dist/Services/DetailService.d.ts +7 -0
- package/dist/Services/DetailService.js +18 -0
- package/dist/Services/FocusCritiqueService.d.ts +23 -0
- package/dist/Services/FocusCritiqueService.js +166 -0
- package/dist/Services/FramingService.d.ts +31 -0
- package/dist/Services/FramingService.js +108 -0
- package/dist/Services/GazeService.js +3 -1
- package/dist/Services/GroundDetailService.d.ts +50 -0
- package/dist/Services/GroundDetailService.js +115 -0
- package/dist/Services/KitService.d.ts +11 -2
- package/dist/Services/KitService.js +45 -10
- package/dist/Services/LightingService.d.ts +15 -0
- package/dist/Services/LightingService.js +124 -6
- package/dist/Services/PaletteService.d.ts +108 -0
- package/dist/Services/PaletteService.js +282 -0
- package/dist/Services/PieceService.d.ts +4 -0
- package/dist/Services/PieceService.js +28 -7
- package/dist/Services/PlacementService.js +7 -1
- package/dist/Services/PlaneBackgroundService.d.ts +4 -0
- package/dist/Services/PlaneBackgroundService.js +42 -3
- package/dist/Services/PlaneProjectionService.d.ts +4 -0
- package/dist/Services/PlaneProjectionService.js +33 -4
- package/dist/Services/RasterService.js +20 -3
- package/dist/Services/RidgeService.d.ts +31 -0
- package/dist/Services/RidgeService.js +85 -0
- package/dist/Services/ScaleCritiqueService.d.ts +11 -0
- package/dist/Services/ScaleCritiqueService.js +57 -0
- package/dist/Services/SkyDetailService.d.ts +39 -0
- package/dist/Services/SkyDetailService.js +95 -0
- package/dist/Services/{ContactCritiqueService.d.ts → TangentCritiqueService.d.ts} +10 -6
- package/dist/Services/TangentCritiqueService.js +136 -0
- package/dist/Services/TextService.d.ts +43 -3
- package/dist/Services/TextService.js +288 -32
- package/dist/Services/ThumbnailCritiqueService.d.ts +30 -0
- package/dist/Services/ThumbnailCritiqueService.js +130 -0
- package/dist/Utils/ColorUtil.d.ts +14 -0
- package/dist/Utils/ColorUtil.js +68 -5
- package/dist/Utils/DetailUtil.d.ts +7 -0
- package/dist/Utils/DetailUtil.js +15 -0
- package/dist/Utils/FontMetricsUtil.d.ts +7 -0
- package/dist/Utils/FontMetricsUtil.js +694 -0
- package/dist/Utils/OklabUtil.d.ts +18 -0
- package/dist/Utils/OklabUtil.js +89 -0
- package/dist/Utils/PersonArmUtil.d.ts +13 -1
- package/dist/Utils/PersonArmUtil.js +53 -5
- package/dist/Utils/PersonHeadUtil.js +3 -1
- package/dist/Utils/PersonOutfitUtil.d.ts +16 -0
- package/dist/Utils/PersonOutfitUtil.js +89 -13
- package/dist/Utils/PersonUtil.d.ts +2 -0
- package/dist/Utils/PersonUtil.js +14 -4
- package/dist/Utils/SanitizeUtil.js +1 -0
- package/dist/Utils/ShapeUtil.d.ts +9 -0
- package/dist/Utils/ShapeUtil.js +26 -0
- package/dist/Utils/TypesettingUtil.d.ts +17 -0
- package/dist/Utils/TypesettingUtil.js +92 -0
- package/dist/cli.js +32 -3
- package/dist/render.d.ts +3 -1
- package/dist/render.js +5 -0
- package/fonts/DMSerifDisplay-Regular.ttf +0 -0
- package/fonts/OFL.txt +2 -0
- package/fonts/PatrickHand-Regular.ttf +0 -0
- package/package.json +1 -1
- package/skills/draw-scene/SKILL.md +2 -1
- package/skills/draw-scene/recipes/carousel.yaml +1 -1
- package/skills/draw-scene/recipes/conference-keynote.yaml +43 -0
- package/skills/draw-scene/recipes/product-feature.yaml +41 -0
- package/skills/draw-scene/recipes/product-illustration.yaml +2 -1
- package/skills/draw-scene/references/catalog.md +19 -1
- package/skills/draw-scene/references/dsl.md +24 -6
- package/dist/Services/ContactCritiqueService.js +0 -101
package/README.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
<h1 align="center">
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="design/svg/horizontal-dark.svg" />
|
|
4
|
+
<img src="design/svg/horizontal-light.svg" alt="scenec" width="360" />
|
|
5
|
+
</picture>
|
|
6
|
+
</h1>
|
|
2
7
|
|
|
3
8
|
<p align="center">
|
|
4
9
|
<strong>Illustrate with text: a YAML scene in, an SVG out, and written feedback on what is wrong with it.</strong>
|
|
@@ -9,22 +14,23 @@
|
|
|
9
14
|
<p align="center">
|
|
10
15
|
<a href="#quick-start"><img src="https://img.shields.io/badge/Quick_start-d4a574" alt="Quick start" /></a>
|
|
11
16
|
<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>
|
|
17
|
+
<a href="https://www.npmjs.com/package/@guilhermebkel/scenec"><img src="https://img.shields.io/npm/dm/@guilhermebkel/scenec.svg?style=flat-square" alt="npm downloads per month" /></a>
|
|
12
18
|
<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
19
|
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow" alt="License: MIT" /></a>
|
|
14
20
|
<img src="https://img.shields.io/badge/Telemetry-none-2ea44f" alt="No telemetry" />
|
|
15
21
|
</p>
|
|
16
22
|
|
|
17
23
|
<p align="center">
|
|
18
|
-
<img src="docs/assets/
|
|
24
|
+
<img src="docs/assets/showcase.png" alt="A sunny park scene: a sun, a tree, a bench with a seated woman, a child and a dog" width="720" />
|
|
19
25
|
<br />
|
|
20
|
-
<sub>
|
|
26
|
+
<sub>Drawn by scenec itself from <a href="docs/assets/showcase.yaml">a short YAML scene</a>.</sub>
|
|
21
27
|
</p>
|
|
22
28
|
|
|
23
29
|
---
|
|
24
30
|
|
|
25
31
|
**Image generation should be cheap, repeatable and checked.** An image model is slow and costly per picture, and two runs never give the same result. Hand-written SVG is cheap but has no feedback loop.
|
|
26
32
|
|
|
27
|
-
`scenec` gives any AI a closed vocabulary (
|
|
33
|
+
`scenec` gives any AI a closed vocabulary (100 assets, ready-made groups, a map of Europe, 10 styles) and a compiler, a fast script that runs on the CPU in a blink. It **measures what it drew** and 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, and it never needs to look at the picture to do so.
|
|
28
34
|
|
|
29
35
|
> **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
36
|
|
|
@@ -83,12 +89,13 @@ The [`skills`](https://github.com/vercel-labs/skills) CLI asks which of your age
|
|
|
83
89
|
Draw a vertical cover for a reel explaining compound interest, flat blue style.
|
|
84
90
|
```
|
|
85
91
|
|
|
86
|
-
The agent picks one of
|
|
92
|
+
The agent picks one of 10 recipes (reel, carousel, "wrapped" card, e-learning, illustrated story, route map, ad variations, product, keynote, feature), changes the content, checks, fixes up to 5 times and renders.
|
|
87
93
|
|
|
88
94
|
### 3. Or use the CLI yourself
|
|
89
95
|
|
|
90
96
|
```bash
|
|
91
97
|
npx @guilhermebkel/scenec check scene.yaml # warnings and critiques; exit code 1 if there are any
|
|
98
|
+
npx @guilhermebkel/scenec best scene.yaml -n 8 -o out --png # picks the best-scoring variant and writes it
|
|
92
99
|
npx @guilhermebkel/scenec render scene.yaml -o out --png # out.svg and out.png, plus a JSON report
|
|
93
100
|
```
|
|
94
101
|
|
|
@@ -119,7 +126,7 @@ The agent moves the bench in, gives the dog another color, runs `check` again, a
|
|
|
119
126
|
|
|
120
127
|
## What it draws
|
|
121
128
|
|
|
122
|
-
|
|
129
|
+
100 assets (people with poses and expressions, furniture, plants, food, vehicles, buildings), ready-made groups, a map of Europe with routes, and 10 kits:
|
|
123
130
|
|
|
124
131
|
| Kit | Look |
|
|
125
132
|
| --- | --- |
|
|
@@ -129,6 +136,10 @@ The agent moves the bench in, gives the dog another color, runs `check` again, a
|
|
|
129
136
|
| `riso` | Risograph: few vivid inks, print grain, slight misregistration |
|
|
130
137
|
| `paper` | Paper cut-out: each piece with its own shadow and fiber texture |
|
|
131
138
|
| `sketch` | Hand-drawn pencil look |
|
|
139
|
+
| `clay` | Clay / soft 3D: rounded shapes, rim light and ambient occlusion |
|
|
140
|
+
| `duotone` | Duotone: two inks mapped across luminance with halftone |
|
|
141
|
+
| `poster` | Vintage poster: limited 4–5 colors, coarse halftone shadows, sun-faded grade |
|
|
142
|
+
| `isometric` | Isometric: 30° axonometric projection with crisp outline and directional light |
|
|
132
143
|
|
|
133
144
|
`npx @guilhermebkel/scenec catalog assets` lists everything; the full language is in [`skills/draw-scene/references/dsl.md`](skills/draw-scene/references/dsl.md).
|
|
134
145
|
|
|
@@ -152,7 +163,7 @@ The work is split on purpose:
|
|
|
152
163
|
|
|
153
164
|
```ts
|
|
154
165
|
import { compile } from "@guilhermebkel/scenec"; // pure: no native code, no file system
|
|
155
|
-
import { check, renderPng } from "@guilhermebkel/scenec/render"; // needs the native renderer
|
|
166
|
+
import { best, check, renderPng } from "@guilhermebkel/scenec/render"; // needs the native renderer
|
|
156
167
|
import { sceneJsonSchema, catalog } from "@guilhermebkel/scenec/schema";
|
|
157
168
|
```
|
|
158
169
|
|
|
@@ -161,8 +172,9 @@ import { sceneJsonSchema, catalog } from "@guilhermebkel/scenec/schema";
|
|
|
161
172
|
|
|
162
173
|
| Command | What it does |
|
|
163
174
|
| --- | --- |
|
|
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. |
|
|
175
|
+
| `scenec render <scene.yaml> [-o name] [--png] [--width 1200]` | Writes the SVG (and PNG) and prints the JSON report. Exit code 0; 2 when the scene is invalid or the file is missing. Critiques do not change the exit code. |
|
|
176
|
+
| `scenec check <scene.yaml>` | Compiles and critiques without writing files. Exit code 1 on a warning or critique (use it in CI), 2 when the scene is invalid or the file is missing. |
|
|
177
|
+
| `scenec best <scene.yaml> [-n 8] [-o name] [--png] [--width 1200]` | Renders N variants of free parameters and writes the one with the best critique score as `name.svg` and `name.yaml`. The input scene is not changed. |
|
|
166
178
|
| `scenec catalog [assets\|groups\|kits\|themes\|poses\|layout]` | Lists the vocabulary a scene can use. |
|
|
167
179
|
| `scenec schema` | Prints the JSON Schema of the scene. |
|
|
168
180
|
|
|
@@ -203,9 +215,8 @@ Yes. Under `assets:` a scene can bring an SVG (inline or a file next to the scen
|
|
|
203
215
|
|
|
204
216
|
## Roadmap
|
|
205
217
|
|
|
206
|
-
- [x] **Core:**
|
|
207
|
-
- [
|
|
208
|
-
- [ ] **More recipes and assets** driven by real use of the skill.
|
|
218
|
+
- [x] **Core:** 100 assets, groups, map mode, 10 kits, warnings, critiques, CLI, skill, 157 visual baselines.
|
|
219
|
+
- [x] **More recipes and assets** driven by real use of the skill.
|
|
209
220
|
|
|
210
221
|
## Contributing
|
|
211
222
|
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
2
|
class FontAdapter {
|
|
3
3
|
static WEIGHTS = ["Regular", "Medium", "Bold"];
|
|
4
|
-
static FONT_FILES =
|
|
4
|
+
static FONT_FILES = [
|
|
5
|
+
...FontAdapter.WEIGHTS.map((weight) => fileURLToPath(new URL(`../../fonts/Poppins-${weight}.ttf`, import.meta.url))),
|
|
6
|
+
fileURLToPath(new URL("../../fonts/DMSerifDisplay-Regular.ttf", import.meta.url)),
|
|
7
|
+
fileURLToPath(new URL("../../fonts/PatrickHand-Regular.ttf", import.meta.url))
|
|
8
|
+
];
|
|
5
9
|
static FONT_FAMILY = "Poppins";
|
|
6
10
|
}
|
|
7
11
|
export {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from "./BaseCommand.js";
|
|
2
|
+
import type { CommandArguments } from "../Protocols/CommandProtocol.js";
|
|
3
|
+
export declare class BestCommand extends BaseCommand {
|
|
4
|
+
private static readonly CHARS_PER_TOKEN;
|
|
5
|
+
private static readonly BYTES_PER_KB;
|
|
6
|
+
readonly name = "best";
|
|
7
|
+
readonly isFileRequired = true;
|
|
8
|
+
private static round;
|
|
9
|
+
run(args: CommandArguments): number;
|
|
10
|
+
private runBest;
|
|
11
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { SceneError } from "../Errors/SceneError.js";
|
|
4
|
+
import { best, createFileReader, renderPng } from "../render.js";
|
|
5
|
+
import { BaseCommand } from "./BaseCommand.js";
|
|
6
|
+
class BestCommand extends BaseCommand {
|
|
7
|
+
static CHARS_PER_TOKEN = 3.6;
|
|
8
|
+
static BYTES_PER_KB = 1024;
|
|
9
|
+
name = "best";
|
|
10
|
+
isFileRequired = true;
|
|
11
|
+
static round(value, digits = 1) {
|
|
12
|
+
return Number(value.toFixed(digits));
|
|
13
|
+
}
|
|
14
|
+
run(args) {
|
|
15
|
+
const file = args.positionals[0];
|
|
16
|
+
if (!file) {
|
|
17
|
+
return BaseCommand.EXIT_INVALID;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
return this.runBest(file, args);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error instanceof SceneError) {
|
|
23
|
+
BaseCommand.print({ schemaVersion: BaseCommand.SCHEMA_VERSION, file, errors: error.errors });
|
|
24
|
+
return BaseCommand.EXIT_INVALID;
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
runBest(file, args) {
|
|
30
|
+
const source = fs.readFileSync(file, "utf8");
|
|
31
|
+
const started = performance.now();
|
|
32
|
+
const sceneFolder = path.dirname(path.resolve(file));
|
|
33
|
+
const result = best(source, { count: args.count, files: createFileReader(sceneFolder) });
|
|
34
|
+
const compiled = performance.now();
|
|
35
|
+
const base = args.output ?? path.join("out", path.basename(file).replace(/\.ya?ml$/, ""));
|
|
36
|
+
fs.mkdirSync(path.dirname(base), { recursive: true });
|
|
37
|
+
fs.writeFileSync(`${base}.svg`, result.svg);
|
|
38
|
+
fs.writeFileSync(`${base}.yaml`, result.updatedSceneYaml);
|
|
39
|
+
const kindToPath = {
|
|
40
|
+
svg: `${base}.svg`,
|
|
41
|
+
scene: `${base}.yaml`
|
|
42
|
+
};
|
|
43
|
+
let pngKb = null;
|
|
44
|
+
if (args.shouldWritePng) {
|
|
45
|
+
const raster = renderPng(result.svg, args.width);
|
|
46
|
+
fs.writeFileSync(`${base}.png`, raster.png);
|
|
47
|
+
kindToPath.png = `${base}.png`;
|
|
48
|
+
pngKb = BestCommand.round(raster.png.length / BestCommand.BYTES_PER_KB);
|
|
49
|
+
}
|
|
50
|
+
const done = performance.now();
|
|
51
|
+
BaseCommand.print({
|
|
52
|
+
schemaVersion: BaseCommand.SCHEMA_VERSION,
|
|
53
|
+
file,
|
|
54
|
+
winner: result.winner,
|
|
55
|
+
written: kindToPath,
|
|
56
|
+
warnings: result.warnings,
|
|
57
|
+
art: result.art,
|
|
58
|
+
description: result.description.split("\n"),
|
|
59
|
+
stats: {
|
|
60
|
+
sceneTokensApprox: Math.round(source.length / BestCommand.CHARS_PER_TOKEN),
|
|
61
|
+
svgTokensApprox: Math.round(result.svg.length / BestCommand.CHARS_PER_TOKEN),
|
|
62
|
+
compileMs: BestCommand.round(compiled - started),
|
|
63
|
+
renderMs: BestCommand.round(done - compiled),
|
|
64
|
+
svgKb: BestCommand.round(result.svg.length / BestCommand.BYTES_PER_KB),
|
|
65
|
+
pngKb
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return result.warnings.length + result.art.length > 0 ? BaseCommand.EXIT_FINDINGS : BaseCommand.EXIT_OK;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
BestCommand
|
|
73
|
+
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SceneCommand } from "./SceneCommand.js";
|
|
2
|
+
import type { CommandArguments } from "../Protocols/CommandProtocol.js";
|
|
2
3
|
export declare class RenderCommand extends SceneCommand {
|
|
3
4
|
readonly name = "render";
|
|
4
5
|
protected readonly shouldWrite = true;
|
|
6
|
+
run(args: CommandArguments): number;
|
|
5
7
|
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { BestCommand } from "./BestCommand.js";
|
|
1
2
|
import { SceneCommand } from "./SceneCommand.js";
|
|
2
3
|
class RenderCommand extends SceneCommand {
|
|
3
4
|
name = "render";
|
|
4
5
|
shouldWrite = true;
|
|
6
|
+
run(args) {
|
|
7
|
+
if (args.isBest) {
|
|
8
|
+
return new BestCommand().run(args);
|
|
9
|
+
}
|
|
10
|
+
return super.run(args);
|
|
11
|
+
}
|
|
5
12
|
}
|
|
6
13
|
export {
|
|
7
14
|
RenderCommand
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CheckResult } from "./CheckModule.js";
|
|
2
|
+
import type { CompileOptions } from "../Protocols/OptionsProtocol.js";
|
|
3
|
+
export interface BestWinner {
|
|
4
|
+
variant: number;
|
|
5
|
+
score: number;
|
|
6
|
+
parameters: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export interface BestResult extends CheckResult {
|
|
9
|
+
winner: BestWinner;
|
|
10
|
+
updatedSceneYaml: string;
|
|
11
|
+
}
|
|
12
|
+
export interface BestOptions extends CompileOptions {
|
|
13
|
+
count?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class BestModule {
|
|
16
|
+
private static readonly DEFAULT_COUNT;
|
|
17
|
+
private static readonly BASE_SCORE;
|
|
18
|
+
private static readonly WARNING_PENALTY;
|
|
19
|
+
private static readonly CRITIQUE_PENALTY;
|
|
20
|
+
private static readonly OVERLAP_PENALTY;
|
|
21
|
+
private static readonly BLEND_PENALTY;
|
|
22
|
+
private static readonly LEAN_PENALTY;
|
|
23
|
+
private static readonly EMPTY_PENALTY;
|
|
24
|
+
private static readonly BALANCE_BONUS_WEIGHT;
|
|
25
|
+
private static readonly TARGET_CENTER;
|
|
26
|
+
private static readonly SCORE_DECIMALS;
|
|
27
|
+
private static readonly RIDGE_COUNT_OPTIONS;
|
|
28
|
+
private static readonly CLOUD_OPTIONS;
|
|
29
|
+
private static readonly LIGHT_DIRECTIONS;
|
|
30
|
+
private static readonly FRAME_POSITIONS;
|
|
31
|
+
private static readonly HARMONIES;
|
|
32
|
+
private static readonly CRITIQUE_PENALTIES;
|
|
33
|
+
private static isRecord;
|
|
34
|
+
private static detectFree;
|
|
35
|
+
private static buildParameters;
|
|
36
|
+
private static generateCandidates;
|
|
37
|
+
private static critiquePenalty;
|
|
38
|
+
private static layoutBalanceBonus;
|
|
39
|
+
private static score;
|
|
40
|
+
static best(input: unknown, options?: BestOptions): BestResult;
|
|
41
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as yaml from "js-yaml";
|
|
2
|
+
import { SceneError } from "../Errors/SceneError.js";
|
|
3
|
+
import { CheckModule } from "./CheckModule.js";
|
|
4
|
+
import { ParsingModule } from "./ParsingModule.js";
|
|
5
|
+
import { RIDGES_MAX } from "../Protocols/SceneProtocol.js";
|
|
6
|
+
class BestModule {
|
|
7
|
+
static DEFAULT_COUNT = 8;
|
|
8
|
+
static BASE_SCORE = 100;
|
|
9
|
+
static WARNING_PENALTY = 40;
|
|
10
|
+
static CRITIQUE_PENALTY = 15;
|
|
11
|
+
static OVERLAP_PENALTY = 25;
|
|
12
|
+
static BLEND_PENALTY = 20;
|
|
13
|
+
static LEAN_PENALTY = 15;
|
|
14
|
+
static EMPTY_PENALTY = 25;
|
|
15
|
+
static BALANCE_BONUS_WEIGHT = 5;
|
|
16
|
+
static TARGET_CENTER = 0.5;
|
|
17
|
+
static SCORE_DECIMALS = 1;
|
|
18
|
+
static RIDGE_COUNT_OPTIONS = [1, 2, RIDGES_MAX];
|
|
19
|
+
static CLOUD_OPTIONS = ["few", "many"];
|
|
20
|
+
static LIGHT_DIRECTIONS = ["left", "right"];
|
|
21
|
+
static FRAME_POSITIONS = ["center", "left", "right"];
|
|
22
|
+
static HARMONIES = ["analogous", "split", "triad", "complementary"];
|
|
23
|
+
static CRITIQUE_PENALTIES = [
|
|
24
|
+
["overlaps", BestModule.OVERLAP_PENALTY],
|
|
25
|
+
["barely touching", BestModule.OVERLAP_PENALTY],
|
|
26
|
+
["blends into the background", BestModule.BLEND_PENALTY],
|
|
27
|
+
["visual weight leans", BestModule.LEAN_PENALTY],
|
|
28
|
+
["empty scene", BestModule.EMPTY_PENALTY],
|
|
29
|
+
["empty band", BestModule.EMPTY_PENALTY]
|
|
30
|
+
];
|
|
31
|
+
static isRecord(value) {
|
|
32
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
static detectFree(rawCanvas) {
|
|
35
|
+
const isSeedFree = rawCanvas.seed === void 0;
|
|
36
|
+
const isLightFree = rawCanvas.light !== false && (rawCanvas.light === void 0 || BestModule.isRecord(rawCanvas.light) && rawCanvas.light.from === void 0);
|
|
37
|
+
const isFrameFree = rawCanvas.frame === void 0;
|
|
38
|
+
const isCloudsFree = rawCanvas.clouds === void 0;
|
|
39
|
+
const isRidgeFree = rawCanvas.ridges === void 0 && (rawCanvas.setting === "outdoor" || rawCanvas.setting === void 0);
|
|
40
|
+
const isHarmonyFree = BestModule.isRecord(rawCanvas.theme) && rawCanvas.theme.harmony === void 0;
|
|
41
|
+
return { isSeedFree, isLightFree, isFrameFree, isCloudsFree, isRidgeFree, isHarmonyFree };
|
|
42
|
+
}
|
|
43
|
+
static buildParameters(rawCanvas, flags, index) {
|
|
44
|
+
const parameters = {};
|
|
45
|
+
if (flags.isSeedFree) {
|
|
46
|
+
parameters.seed = index + 1;
|
|
47
|
+
}
|
|
48
|
+
if (flags.isLightFree) {
|
|
49
|
+
const baseLight = BestModule.isRecord(rawCanvas.light) ? rawCanvas.light : {};
|
|
50
|
+
const direction = BestModule.LIGHT_DIRECTIONS[index % BestModule.LIGHT_DIRECTIONS.length];
|
|
51
|
+
parameters.light = { ...baseLight, from: direction };
|
|
52
|
+
}
|
|
53
|
+
if (flags.isFrameFree) {
|
|
54
|
+
parameters.frame = BestModule.FRAME_POSITIONS[index % BestModule.FRAME_POSITIONS.length];
|
|
55
|
+
}
|
|
56
|
+
if (flags.isCloudsFree) {
|
|
57
|
+
parameters.clouds = BestModule.CLOUD_OPTIONS[index % BestModule.CLOUD_OPTIONS.length];
|
|
58
|
+
}
|
|
59
|
+
if (flags.isRidgeFree) {
|
|
60
|
+
parameters.ridges = BestModule.RIDGE_COUNT_OPTIONS[index % BestModule.RIDGE_COUNT_OPTIONS.length];
|
|
61
|
+
}
|
|
62
|
+
if (flags.isHarmonyFree && BestModule.isRecord(rawCanvas.theme)) {
|
|
63
|
+
const harmony = BestModule.HARMONIES[index % BestModule.HARMONIES.length];
|
|
64
|
+
parameters.theme = { ...rawCanvas.theme, harmony };
|
|
65
|
+
}
|
|
66
|
+
return parameters;
|
|
67
|
+
}
|
|
68
|
+
static generateCandidates(raw, count) {
|
|
69
|
+
const rawCanvas = BestModule.isRecord(raw.canvas) ? raw.canvas : {};
|
|
70
|
+
const flags = BestModule.detectFree(rawCanvas);
|
|
71
|
+
const candidates = [];
|
|
72
|
+
for (let variantIndex = 0; variantIndex < count; variantIndex++) {
|
|
73
|
+
const parameters = BestModule.buildParameters(rawCanvas, flags, variantIndex);
|
|
74
|
+
const scene = {
|
|
75
|
+
...raw,
|
|
76
|
+
canvas: {
|
|
77
|
+
...rawCanvas,
|
|
78
|
+
...parameters
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
candidates.push({ variantIndex, scene, parameters });
|
|
82
|
+
}
|
|
83
|
+
return candidates;
|
|
84
|
+
}
|
|
85
|
+
static critiquePenalty(message) {
|
|
86
|
+
const match = BestModule.CRITIQUE_PENALTIES.find(([keyword]) => message.includes(keyword));
|
|
87
|
+
return match ? match[1] : BestModule.CRITIQUE_PENALTY;
|
|
88
|
+
}
|
|
89
|
+
static layoutBalanceBonus(result) {
|
|
90
|
+
const layout = result.layout ?? [];
|
|
91
|
+
if (layout.length === 0) {
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
let totalWeight = 0;
|
|
95
|
+
let weightedX = 0;
|
|
96
|
+
for (const item of layout) {
|
|
97
|
+
const weight = item.w * item.h;
|
|
98
|
+
totalWeight += weight;
|
|
99
|
+
weightedX += weight * item.x;
|
|
100
|
+
}
|
|
101
|
+
if (totalWeight <= 0) {
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
const centerOfMass = weightedX / totalWeight;
|
|
105
|
+
const offsetFromCenter = Math.abs(centerOfMass - BestModule.TARGET_CENTER);
|
|
106
|
+
return Math.max(0, BestModule.BALANCE_BONUS_WEIGHT * (1 - offsetFromCenter * 2));
|
|
107
|
+
}
|
|
108
|
+
static score(checkResult) {
|
|
109
|
+
let penalty = checkResult.warnings.length * BestModule.WARNING_PENALTY;
|
|
110
|
+
for (const artMessage of checkResult.art) {
|
|
111
|
+
penalty += BestModule.critiquePenalty(artMessage);
|
|
112
|
+
}
|
|
113
|
+
const bonus = BestModule.layoutBalanceBonus(checkResult);
|
|
114
|
+
const rawScore = BestModule.BASE_SCORE - penalty + bonus;
|
|
115
|
+
return Number(Math.max(0, rawScore).toFixed(BestModule.SCORE_DECIMALS));
|
|
116
|
+
}
|
|
117
|
+
static best(input, options = {}) {
|
|
118
|
+
let raw = input;
|
|
119
|
+
if (typeof input === "string") {
|
|
120
|
+
try {
|
|
121
|
+
raw = yaml.load(input);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
throw new SceneError([`invalid YAML: ${error instanceof Error ? error.message : String(error)}`]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (!BestModule.isRecord(raw)) {
|
|
127
|
+
throw new SceneError(["scene must be a YAML mapping"]);
|
|
128
|
+
}
|
|
129
|
+
ParsingModule.parseScene(raw);
|
|
130
|
+
const count = options.count && options.count > 0 ? options.count : BestModule.DEFAULT_COUNT;
|
|
131
|
+
const candidates = BestModule.generateCandidates(raw, count);
|
|
132
|
+
let bestScore = -1;
|
|
133
|
+
let winningCandidate = candidates[0] ?? { variantIndex: 0, scene: raw, parameters: {} };
|
|
134
|
+
let winningResult;
|
|
135
|
+
for (const candidate of candidates) {
|
|
136
|
+
const checkResult = CheckModule.check(candidate.scene, options);
|
|
137
|
+
const score = BestModule.score(checkResult);
|
|
138
|
+
if (score > bestScore) {
|
|
139
|
+
bestScore = score;
|
|
140
|
+
winningCandidate = candidate;
|
|
141
|
+
winningResult = checkResult;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const winnerResult = winningResult ?? CheckModule.check(winningCandidate.scene, options);
|
|
145
|
+
const updatedSceneYaml = yaml.dump(winningCandidate.scene, { indent: 2, lineWidth: -1, noRefs: true });
|
|
146
|
+
return {
|
|
147
|
+
...winnerResult,
|
|
148
|
+
winner: {
|
|
149
|
+
variant: winningCandidate.variantIndex,
|
|
150
|
+
score: bestScore,
|
|
151
|
+
parameters: winningCandidate.parameters
|
|
152
|
+
},
|
|
153
|
+
updatedSceneYaml
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
BestModule
|
|
159
|
+
};
|
|
@@ -5,7 +5,10 @@ import type { Scene } from "../Protocols/SceneProtocol.js";
|
|
|
5
5
|
export declare class CompilationModule {
|
|
6
6
|
private static readonly PLANE_HEIGHT;
|
|
7
7
|
private static readonly ZOOM_DIGITS;
|
|
8
|
+
private static readonly SETTING_TO_TEXT_BACKDROP;
|
|
8
9
|
private static readonly SCENE_TO_SKIPPED_CRITIQUES;
|
|
10
|
+
private static readonly DEFAULT_GRAIN_OPACITY;
|
|
11
|
+
private static readonly GRAIN_DIGITS;
|
|
9
12
|
private static readonly MODE_TO_COMPILER;
|
|
10
13
|
static compile(input: unknown, options?: CompileOptions): CompileResult;
|
|
11
14
|
static compileInternal(scene: Scene, options?: CompileOptions): CompilationOutput;
|
|
@@ -14,5 +17,7 @@ export declare class CompilationModule {
|
|
|
14
17
|
private static compileClassic;
|
|
15
18
|
private static finishBackground;
|
|
16
19
|
private static grain;
|
|
20
|
+
private static readonly FRAMING_CRITIQUE_Z;
|
|
21
|
+
private static readonly DEFAULT_TITLE_SIZE;
|
|
17
22
|
private static critiqueInput;
|
|
18
23
|
}
|
|
@@ -7,6 +7,7 @@ import { ContextService } from "../Services/ContextService.js";
|
|
|
7
7
|
import { DependencyOrderService } from "../Services/DependencyOrderService.js";
|
|
8
8
|
import { DescriptionService } from "../Services/DescriptionService.js";
|
|
9
9
|
import { FramingCheckService } from "../Services/FramingCheckService.js";
|
|
10
|
+
import { FramingService } from "../Services/FramingService.js";
|
|
10
11
|
import { GazeService } from "../Services/GazeService.js";
|
|
11
12
|
import { GroupService } from "../Services/GroupService.js";
|
|
12
13
|
import { KitService } from "../Services/KitService.js";
|
|
@@ -19,9 +20,14 @@ import { SvgUtil } from "../Utils/SvgUtil.js";
|
|
|
19
20
|
class CompilationModule {
|
|
20
21
|
static PLANE_HEIGHT = 900;
|
|
21
22
|
static ZOOM_DIGITS = 4;
|
|
23
|
+
static SETTING_TO_TEXT_BACKDROP = {
|
|
24
|
+
indoor: "wall"
|
|
25
|
+
};
|
|
22
26
|
static SCENE_TO_SKIPPED_CRITIQUES = {
|
|
23
27
|
sketch: ["silhouette"]
|
|
24
28
|
};
|
|
29
|
+
static DEFAULT_GRAIN_OPACITY = 0.1;
|
|
30
|
+
static GRAIN_DIGITS = 2;
|
|
25
31
|
static MODE_TO_COMPILER = {
|
|
26
32
|
"classic": (scene, context) => CompilationModule.compileClassic(scene, context),
|
|
27
33
|
"2.5d": (scene, context) => CompilationModule.compilePlane(scene, context),
|
|
@@ -59,8 +65,10 @@ class CompilationModule {
|
|
|
59
65
|
const camera = CameraService.frame(placed, context);
|
|
60
66
|
const list = Object.values(placed);
|
|
61
67
|
FramingCheckService.check(list, context, camera, resolution.heldToHolder);
|
|
62
|
-
const
|
|
63
|
-
const
|
|
68
|
+
const backdropKey = IdUtil.lookup(CompilationModule.SETTING_TO_TEXT_BACKDROP, context.setting) ?? "skyTop";
|
|
69
|
+
const textBackdrop = context.theme[backdropKey];
|
|
70
|
+
const text = TextService.render(scene.text ?? [], context, list, textBackdrop);
|
|
71
|
+
const background = BackgroundService.build(context, { textRects: text.rects, placements: list });
|
|
64
72
|
const light = LightingService.resolve(context, list, background);
|
|
65
73
|
const backgroundSvg = CompilationModule.finishBackground(background, light, context, camera);
|
|
66
74
|
const ordered = [...list].sort((first, second) => first.z - second.z);
|
|
@@ -68,14 +76,19 @@ class CompilationModule {
|
|
|
68
76
|
const pieces = PieceService.assemble(ordered, { context, light, haze: background.haze, heldToHolder });
|
|
69
77
|
const castLayer = PieceService.castLayer(pieces.casts, light, context);
|
|
70
78
|
const { width, height } = context;
|
|
71
|
-
const vignette = light && !light.isHatch ? `<rect width="${width}" height="${height}" fill="url(#vignette)"/>` : "";
|
|
79
|
+
const vignette = light && !light.isHatch ? `<rect width="${width}" height="${height}" fill="url(#vignette)" style="mix-blend-mode: multiply;"/>` : "";
|
|
80
|
+
const framing = FramingService.render(context, ordered, text.rects);
|
|
81
|
+
const framingSvg = framing.svg ? `
|
|
82
|
+
${framing.svg}` : "";
|
|
72
83
|
const head = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">`;
|
|
73
84
|
const artwork = `${backgroundSvg}
|
|
74
85
|
${castLayer}
|
|
75
86
|
${pieces.body}
|
|
76
|
-
${vignette}`;
|
|
87
|
+
${vignette}${framingSvg}`;
|
|
88
|
+
const timeFilter = context.canvas.time ? LightingService.timeGradeFilter(context.canvas.time) : "";
|
|
89
|
+
const graded = context.canvas.time ? `<defs>${timeFilter}</defs><g filter="url(#timeGrade)">${artwork}</g>` : artwork;
|
|
77
90
|
const sceneFilter = context.kit.scene ? KitService.sceneFilter(context.kit.scene) : "";
|
|
78
|
-
const sceneArt = context.kit.scene ? `<defs>${sceneFilter}</defs><g filter="url(#kitScene)">${
|
|
91
|
+
const sceneArt = context.kit.scene ? `<defs>${sceneFilter}</defs><g filter="url(#kitScene)">${graded}</g>` : graded;
|
|
79
92
|
const grain = CompilationModule.grain(context);
|
|
80
93
|
const texture = KitService.texture(context.kit.texture, context.width, context.height);
|
|
81
94
|
const svg = SvgUtil.flattenOpacity(`${head}
|
|
@@ -87,10 +100,19 @@ ${text.svg}
|
|
|
87
100
|
const result = {
|
|
88
101
|
svg,
|
|
89
102
|
warnings: [...new Set(context.warnings)],
|
|
90
|
-
description: DescriptionService.describe(ordered, context),
|
|
103
|
+
description: DescriptionService.describe(ordered, context, framing.corner),
|
|
91
104
|
layout: DescriptionService.layout(ordered, context)
|
|
92
105
|
};
|
|
93
|
-
const parts = {
|
|
106
|
+
const parts = {
|
|
107
|
+
context,
|
|
108
|
+
head,
|
|
109
|
+
background: backgroundSvg,
|
|
110
|
+
sceneArt,
|
|
111
|
+
textRects: text.rects,
|
|
112
|
+
ordered,
|
|
113
|
+
framing: framing.svg,
|
|
114
|
+
scene
|
|
115
|
+
};
|
|
94
116
|
const critique = context.canvas.critique === false ? null : CompilationModule.critiqueInput(parts);
|
|
95
117
|
return { result, critique };
|
|
96
118
|
}
|
|
@@ -103,13 +125,68 @@ ${text.svg}
|
|
|
103
125
|
return `<g transform="${move} scale(${camera.zoom.toFixed(CompilationModule.ZOOM_DIGITS)})">${lit}</g>`;
|
|
104
126
|
}
|
|
105
127
|
static grain(context) {
|
|
106
|
-
|
|
128
|
+
const { grain } = context.canvas;
|
|
129
|
+
if (!grain) {
|
|
130
|
+
return "";
|
|
131
|
+
}
|
|
132
|
+
const opacity = grain === true ? CompilationModule.DEFAULT_GRAIN_OPACITY : Number(grain.toFixed(CompilationModule.GRAIN_DIGITS));
|
|
133
|
+
if (opacity <= 0) {
|
|
107
134
|
return "";
|
|
108
135
|
}
|
|
109
|
-
return `<filter id="grain"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2" stitchTiles="stitch"/><feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.55 0"/></filter><rect width="${context.width}" height="${context.height}" filter="url(#grain)" opacity="
|
|
136
|
+
return `<filter id="grain"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2" stitchTiles="stitch"/><feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.55 0"/></filter><rect width="${context.width}" height="${context.height}" filter="url(#grain)" style="mix-blend-mode: soft-light;" opacity="${opacity.toFixed(CompilationModule.GRAIN_DIGITS)}"/>`;
|
|
110
137
|
}
|
|
138
|
+
static FRAMING_CRITIQUE_Z = 999;
|
|
139
|
+
// Why: 0.075 is the standard title height ratio used when no explicit size is set.
|
|
140
|
+
static DEFAULT_TITLE_SIZE = 0.075;
|
|
111
141
|
static critiqueInput(parts) {
|
|
112
|
-
const { context, head, background, sceneArt, textRects, ordered } = parts;
|
|
142
|
+
const { context, head, background, sceneArt, textRects, ordered, framing, scene } = parts;
|
|
143
|
+
const objects = ordered.filter((placement) => !placement.isOffView).map((placement) => ({
|
|
144
|
+
id: placement.id,
|
|
145
|
+
asset: placement.asset,
|
|
146
|
+
kind: placement.kind,
|
|
147
|
+
z: placement.z,
|
|
148
|
+
body: SvgUtil.flattenOpacity(placement.bodySvg),
|
|
149
|
+
related: placement.related,
|
|
150
|
+
isIgnored: placement.isBackdrop || context.idToObject[placement.id]?.critique === false,
|
|
151
|
+
isFocus: placement.isFocus,
|
|
152
|
+
height: placement.height,
|
|
153
|
+
depth: placement.depth
|
|
154
|
+
}));
|
|
155
|
+
if (framing) {
|
|
156
|
+
objects.push({
|
|
157
|
+
id: "framing",
|
|
158
|
+
asset: "framing",
|
|
159
|
+
kind: "any",
|
|
160
|
+
z: CompilationModule.FRAMING_CRITIQUE_Z,
|
|
161
|
+
body: SvgUtil.flattenOpacity(framing),
|
|
162
|
+
related: [],
|
|
163
|
+
isIgnored: false,
|
|
164
|
+
isFocus: false,
|
|
165
|
+
height: 0,
|
|
166
|
+
depth: null
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const titles = (scene?.text ?? []).filter((item) => (item.role ?? "title") === "title");
|
|
170
|
+
const titleItem = titles.toSorted((first, second) => {
|
|
171
|
+
const firstRatio = typeof first.size === "number" ? first.size : CompilationModule.DEFAULT_TITLE_SIZE;
|
|
172
|
+
const secondRatio = typeof second.size === "number" ? second.size : CompilationModule.DEFAULT_TITLE_SIZE;
|
|
173
|
+
return secondRatio - firstRatio;
|
|
174
|
+
})[0];
|
|
175
|
+
let title;
|
|
176
|
+
if (titleItem) {
|
|
177
|
+
const sizeRatio = typeof titleItem.size === "number" ? titleItem.size : CompilationModule.DEFAULT_TITLE_SIZE;
|
|
178
|
+
title = {
|
|
179
|
+
content: String(titleItem.content),
|
|
180
|
+
fontSize: sizeRatio * context.height
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const focus = context.canvas.focus;
|
|
184
|
+
let focusId;
|
|
185
|
+
if (Array.isArray(focus)) {
|
|
186
|
+
focusId = focus[0];
|
|
187
|
+
} else {
|
|
188
|
+
focusId = focus;
|
|
189
|
+
}
|
|
113
190
|
return {
|
|
114
191
|
width: context.width,
|
|
115
192
|
height: context.height,
|
|
@@ -120,15 +197,11 @@ ${text.svg}
|
|
|
120
197
|
scale: context.canvas.scale ?? 1,
|
|
121
198
|
textRects,
|
|
122
199
|
skip: IdUtil.lookup(CompilationModule.SCENE_TO_SKIPPED_CRITIQUES, context.kit.scene) ?? [],
|
|
123
|
-
objects
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
body: SvgUtil.flattenOpacity(placement.bodySvg),
|
|
129
|
-
related: placement.related,
|
|
130
|
-
isIgnored: placement.isBackdrop || context.idToObject[placement.id]?.critique === false
|
|
131
|
-
}))
|
|
200
|
+
objects,
|
|
201
|
+
horizon: context.lines.horizon,
|
|
202
|
+
setting: context.setting,
|
|
203
|
+
focusId,
|
|
204
|
+
title
|
|
132
205
|
};
|
|
133
206
|
}
|
|
134
207
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { CritiqueInput } from "../Protocols/CompilationProtocol.js";
|
|
2
2
|
export declare class CritiqueModule {
|
|
3
3
|
private static readonly ANALYSIS_WIDTH;
|
|
4
|
+
private static readonly THUMBNAIL_WIDTH;
|
|
4
5
|
private static readonly DEFS;
|
|
5
6
|
static critique(input: CritiqueInput): string[];
|
|
7
|
+
private static runThumbnailCritique;
|
|
8
|
+
private static findFocusObject;
|
|
6
9
|
}
|