@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.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +242 -2
  3. package/dist/catalog.d.ts +21 -0
  4. package/dist/catalog.js +35 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +118 -0
  7. package/dist/data/europe.json +1 -0
  8. package/dist/drawing/assets.d.ts +8 -0
  9. package/dist/drawing/assets.js +612 -0
  10. package/dist/drawing/kits.d.ts +7 -0
  11. package/dist/drawing/kits.js +92 -0
  12. package/dist/drawing/person.d.ts +18 -0
  13. package/dist/drawing/person.js +287 -0
  14. package/dist/drawing/themes.d.ts +4 -0
  15. package/dist/drawing/themes.js +45 -0
  16. package/dist/index.d.ts +6 -0
  17. package/dist/index.js +2 -0
  18. package/dist/modes/map.d.ts +5 -0
  19. package/dist/modes/map.js +365 -0
  20. package/dist/modes/plane.d.ts +5 -0
  21. package/dist/modes/plane.js +716 -0
  22. package/dist/pipeline/compile.d.ts +2 -0
  23. package/dist/pipeline/compile.js +581 -0
  24. package/dist/pipeline/custom.d.ts +2 -0
  25. package/dist/pipeline/custom.js +120 -0
  26. package/dist/pipeline/groups.d.ts +2 -0
  27. package/dist/pipeline/groups.js +189 -0
  28. package/dist/pipeline/index.d.ts +16 -0
  29. package/dist/pipeline/index.js +7 -0
  30. package/dist/pipeline/parse.d.ts +10 -0
  31. package/dist/pipeline/parse.js +80 -0
  32. package/dist/protocols/options.d.ts +14 -0
  33. package/dist/protocols/options.js +1 -0
  34. package/dist/protocols/scene.d.ts +299 -0
  35. package/dist/protocols/scene.js +118 -0
  36. package/dist/protocols/theme.d.ts +25 -0
  37. package/dist/protocols/theme.js +1 -0
  38. package/dist/render/check.d.ts +6 -0
  39. package/dist/render/check.js +10 -0
  40. package/dist/render/critic.d.ts +1 -0
  41. package/dist/render/critic.js +235 -0
  42. package/dist/render/files.d.ts +2 -0
  43. package/dist/render/files.js +16 -0
  44. package/dist/render/fonts.d.ts +2 -0
  45. package/dist/render/fonts.js +4 -0
  46. package/dist/render/png.d.ts +9 -0
  47. package/dist/render/png.js +13 -0
  48. package/dist/render.d.ts +5 -0
  49. package/dist/render.js +3 -0
  50. package/dist/schema.d.ts +3 -0
  51. package/dist/schema.js +6 -0
  52. package/dist/utils/color.d.ts +5 -0
  53. package/dist/utils/color.js +35 -0
  54. package/dist/utils/recolor.d.ts +1 -0
  55. package/dist/utils/recolor.js +56 -0
  56. package/dist/utils/sanitize.d.ts +5 -0
  57. package/dist/utils/sanitize.js +169 -0
  58. package/dist/utils/suggest.d.ts +1 -0
  59. package/dist/utils/suggest.js +22 -0
  60. package/dist/utils/svg.d.ts +2 -0
  61. package/dist/utils/svg.js +11 -0
  62. package/fonts/OFL.txt +50 -0
  63. package/fonts/Poppins-Bold.ttf +0 -0
  64. package/fonts/Poppins-Medium.ttf +0 -0
  65. package/fonts/Poppins-Regular.ttf +0 -0
  66. package/package.json +96 -4
  67. package/skills/scenec/SKILL.md +46 -0
  68. package/skills/scenec/recipes/anuncios-variacoes.yaml +58 -0
  69. package/skills/scenec/recipes/carrossel.yaml +58 -0
  70. package/skills/scenec/recipes/elearning.yaml +64 -0
  71. package/skills/scenec/recipes/historia-ilustrada.yaml +48 -0
  72. package/skills/scenec/recipes/ilustracoes-produto.yaml +44 -0
  73. package/skills/scenec/recipes/mapas-jornadas.yaml +27 -0
  74. package/skills/scenec/recipes/reels-explicativo.yaml +41 -0
  75. package/skills/scenec/recipes/wrapped-personalizado.yaml +64 -0
  76. package/skills/scenec/references/catalog.md +125 -0
  77. package/skills/scenec/references/dsl.md +111 -0
  78. package/skills/scenec/references/fontes.md +8 -0
@@ -0,0 +1,2 @@
1
+ import type { CompileOptions } from "../protocols/options.ts";
2
+ export declare function compileInternal(scene: any, opts?: CompileOptions): any;
@@ -0,0 +1,581 @@
1
+ import { ASSETS, resolveAsset } from "../drawing/assets.js";
2
+ import { THEMES } from "../drawing/themes.js";
3
+ import { bodyScale } from "../drawing/person.js";
4
+ import { KITS, outlineFilter, dropFilter, innerStroke, hatchDefs, sceneFilter, texture } from "../drawing/kits.js";
5
+ import { compilePlane } from "../modes/plane.js";
6
+ import { compileMap } from "../modes/map.js";
7
+ import { sh, luminance, contrast } from "../utils/color.js";
8
+ import { flattenOpacity } from "../utils/svg.js";
9
+ import { loadCustomAssets } from "./custom.js";
10
+ import { expandGroups } from "./groups.js";
11
+ const SLOTS = { "far-left": 0.08, left: 0.2, "center-left": 0.35, center: 0.5, "center-right": 0.65, right: 0.8, "far-right": 0.92 };
12
+ const SIZES = { tiny: 0.5, small: 0.75, medium: 1, large: 1.3, huge: 1.7 };
13
+ const DEPTHS = ["far", "mid", "near"];
14
+ const GRIP = { cup: 6, suitcase: 44, books: 8, ball: 12 }; // altura do ponto de pegada (unidades)
15
+ const FONT = "Poppins";
16
+ function layoutLines(setting, _H) {
17
+ const L = structuredClone({
18
+ outdoor: { horizon: 0.64, base: { near: 0.92, mid: 0.8, far: 0.69 } },
19
+ indoor: { horizon: 0.68, base: { near: 0.93, mid: 0.84, far: 0.74 } },
20
+ beach: { horizon: 0.50, sea: 0.62, base: { near: 0.93, mid: 0.82, far: 0.71 } },
21
+ city: { horizon: 0.70, base: { near: 0.94, mid: 0.84, far: 0.74 } },
22
+ }[setting] || null);
23
+ return L;
24
+ }
25
+ const slotX = (at, def) => (typeof at === "number" ? at : SLOTS[at] ?? def);
26
+ const DEPTH_SCALE = { near: 1, mid: 0.8, far: 0.6 };
27
+ export function compileInternal(scene, opts = {}) {
28
+ const warnings = [];
29
+ const c = scene.canvas || {};
30
+ const W = c.width || 1200, H = c.height || ((c.mode === "2.5d" || c.mode === "board") ? 900 : 630);
31
+ const baseTheme = THEMES[c.theme || "flat-cool"] || (warnings.push(`tema '${c.theme}' não existe; usando 'flat-cool'. Disponíveis: ${Object.keys(THEMES).join(", ")}`), THEMES["flat-cool"]);
32
+ // `canvas.colors` sobrescreve cores do tema (ex.: wall, floor, wood) para casar com uma referência
33
+ // kit de estilo: muda a linguagem visual (contorno, hachura, risografia...), não só a paleta
34
+ const KIT = KITS[c.kit || "flat"] || (warnings.push(`kit '${c.kit}' não existe; disponíveis: ${Object.keys(KITS).join(", ")}`), KITS.flat);
35
+ const theme = { ...baseTheme, ...(KIT.colors || {}), ...(c.colors || {}) };
36
+ const setting = c.setting || ((c.mode === "2.5d" || c.mode === "board") ? "outdoor" : "outdoor");
37
+ const lines = layoutLines(setting, H) || (warnings.push(`setting '${setting}' inválido; use outdoor, indoor, beach ou city`), layoutLines("outdoor"));
38
+ const U = H * 0.0034 * (c.scale ?? 1); // px por unidade (pessoa = 100 un.)
39
+ if (c.horizon != null)
40
+ lines.horizon = c.horizon;
41
+ if (c.base != null) {
42
+ const d = c.base - lines.base.near;
43
+ lines.base = { near: c.base, mid: lines.base.mid + d * 0.6, far: lines.base.far + d * 0.3 };
44
+ }
45
+ const BASE = ASSETS;
46
+ const FAILED = new Set();
47
+ const CUSTOM = loadCustomAssets(scene.assets, opts, warnings, FAILED);
48
+ for (const id of Object.keys(CUSTOM))
49
+ if (BASE[id])
50
+ warnings.push(`asset custom '${id}' substitui o asset da biblioteca com o mesmo nome`);
51
+ const LIB = Object.keys(CUSTOM).length ? { ...BASE, ...CUSTOM } : BASE;
52
+ const wholeKit = (r) => {
53
+ if (KIT.outline || KIT.light?.mode === "hatch")
54
+ r.warnings?.push?.(`no modo ${c.mode}, o kit '${c.kit}' aplica só filtro e textura; contorno e hachura por objeto existem no modo clássico`);
55
+ if (!KIT.scene && !KIT.texture)
56
+ return r;
57
+ const HH = c.height || 900;
58
+ // texto fica fora do filtro (nítido) e por cima da textura
59
+ const svg = r.svg.replace(/(<svg[^>]*>)([\s\S]*)(<\/svg>\s*)$/, (m, a, body, z) => {
60
+ const texts = [];
61
+ const art = body.replace(/<text\b[\s\S]*?<\/text>/g, (tx) => (texts.push(tx), ""));
62
+ return `${a}<defs>${KIT.scene ? sceneFilter(KIT.scene, theme) : ""}</defs><g${KIT.scene ? " filter=\"url(#kitScene)\"" : ""}>${art}</g>${texture(KIT.texture, W, HH)}${texts.join("")}${z}`;
63
+ });
64
+ return { ...r, svg: flattenOpacity(svg) };
65
+ };
66
+ if (c.mode === "map")
67
+ return wholeKit(compileMap(scene, { theme, warnings, W, H: c.height || 900, contrast }));
68
+ if (c.mode === "2.5d" || c.mode === "board")
69
+ return wholeKit(compilePlane(scene, { LIB, theme, warnings, W, H: c.height || 900, resolveAsset, contrast }));
70
+ const objs = expandGroups(scene.objects || {}, warnings);
71
+ const placed = {};
72
+ // ---- ordem de resolução (dependências) ----
73
+ const deps = (o) => ["left_of", "right_of", "behind", "in_front_of", "on", "under", "above"].map((k) => o[k]).filter(Boolean);
74
+ const order = [], seen = new Set(), visiting = new Set();
75
+ const visit = (id) => {
76
+ if (seen.has(id))
77
+ return;
78
+ if (visiting.has(id)) {
79
+ warnings.push(`dependência circular envolvendo '${id}'`);
80
+ return;
81
+ }
82
+ visiting.add(id);
83
+ const o = objs[id];
84
+ if (!o)
85
+ return;
86
+ for (const d of deps(o)) {
87
+ if (!objs[d])
88
+ warnings.push(`'${id}' referencia '${d}', que não existe na cena`);
89
+ else
90
+ visit(d);
91
+ }
92
+ visiting.delete(id);
93
+ seen.add(id);
94
+ order.push(id);
95
+ };
96
+ Object.keys(objs).forEach(visit);
97
+ // quem segura (holds) vem antes do objeto segurado
98
+ const heldBy = {};
99
+ for (const [id, o] of Object.entries(objs))
100
+ if (o.holds) {
101
+ if (!objs[o.holds])
102
+ warnings.push(`'${id}' segura '${o.holds}', que não existe`);
103
+ else
104
+ heldBy[o.holds] = id;
105
+ }
106
+ const final = order.filter((id) => !heldBy[id]);
107
+ for (const id of order)
108
+ if (heldBy[id])
109
+ final.splice(final.indexOf(heldBy[id]) + 1, 0, id);
110
+ // ---- posicionamento ----
111
+ for (const id of final) {
112
+ const o = objs[id];
113
+ const res = resolveAsset(o.asset || id, LIB);
114
+ if (!res.id) {
115
+ if (FAILED.has(o.asset || id))
116
+ warnings.push(`'${id}' foi ignorado porque o asset custom '${o.asset || id}' não carregou`);
117
+ else
118
+ warnings.push(`asset '${o.asset || id}' (em '${id}') não existe; você quis dizer: ${res.suggest.join(", ")}?`);
119
+ continue;
120
+ }
121
+ const A = LIB[res.id];
122
+ const dims = A.size ? A.size(o) : { w: A.w, h: A.h };
123
+ const sizeK = typeof o.size === "number" ? o.size : (SIZES[o.size || "medium"] ?? (warnings.push(`size '${o.size}' inválido em '${id}' (use ${Object.keys(SIZES).join(", ")})`), 1));
124
+ let depth = o.depth || null, x = null, y = null, scale = null, z = 0;
125
+ const ref = (k) => placed[o[k]];
126
+ if (A.kind === "sky") {
127
+ scale = U * sizeK * 0.9;
128
+ const slot = o.at || "top-right";
129
+ const hx = String(slot).replace("top-", "").replace("sky-", "");
130
+ x = (SLOTS[hx] ?? (typeof o.at === "number" ? o.at : 0.5)) * W;
131
+ y = H * (o.altitude ?? 0.14) + (dims.h * scale) / 2;
132
+ if (res.id === "stars") {
133
+ x = W / 2;
134
+ y = H * 0.38;
135
+ scale = W / 620;
136
+ }
137
+ z = -900;
138
+ }
139
+ else if (A.kind === "wall") {
140
+ if (setting !== "indoor")
141
+ warnings.push(`'${id}' é de parede, mas o setting é '${setting}'`);
142
+ scale = U * sizeK * 0.85;
143
+ x = (SLOTS[o.at] ?? (typeof o.at === "number" ? o.at : 0.5)) * W;
144
+ if (ref("left_of"))
145
+ x = ref("left_of").bx0 - 0.03 * W - (dims.w * scale) / 2;
146
+ if (ref("right_of"))
147
+ x = ref("right_of").bx1 + 0.03 * W + (dims.w * scale) / 2;
148
+ if (ref("above"))
149
+ x = ref("above").x + (o.offset ?? 0) * ref("above").w;
150
+ y = H * lines.horizon - (o.elevation ?? A.elevation) * U * 0.85;
151
+ z = -800;
152
+ }
153
+ else if (A.kind === "ceiling") {
154
+ scale = U * sizeK;
155
+ x = slotX(o.at, 0.5) * W;
156
+ if (o.above && placed[o.above])
157
+ x = placed[o.above].x;
158
+ y = (o.hang ?? 95) * U;
159
+ z = 500;
160
+ }
161
+ else if (A.kind === "water") {
162
+ scale = U * sizeK * 0.55;
163
+ x = slotX(o.at, 0.7) * W;
164
+ y = H * ((lines.sea ?? lines.horizon) - 0.035);
165
+ z = -700;
166
+ if (!lines.sea)
167
+ warnings.push(`'${id}' é um objeto de água, mas a cena não tem mar (use setting: beach)`);
168
+ }
169
+ else if (o.on) {
170
+ const p = ref("on");
171
+ if (!p) {
172
+ warnings.push(`'${id}' está 'on: ${o.on}', mas '${o.on}' não foi posicionado`);
173
+ continue;
174
+ }
175
+ const PA = LIB[p.asset];
176
+ scale = p.scale * sizeK;
177
+ const SEATED = ["sitting", "typing", "reading", "drinking", "sitting_floor", "hugging_knees"];
178
+ if (PA.seat && SEATED.includes(o.pose)) {
179
+ const off = typeof o.align === "number" ? o.align : { left: -0.28, right: 0.28, center: 0 }[o.align || "center"] ?? 0;
180
+ const fx = o.facing === "left" ? 1 : -1; // quadril um pouco para trás do centro do assento
181
+ x = p.x + off * p.w + (A.peep ? 0 : fx * 4 * p.scale);
182
+ y = p.y - PA.seat * p.scale + 45 * (res.id === "person" ? bodyScale(o).by : 1) * p.scale * sizeK;
183
+ z = p.z + 0.5;
184
+ }
185
+ else if (!(p.top ?? PA.top)) {
186
+ warnings.push(`'${o.on}' não tem superfície de apoio; '${id}' não pode ficar em cima dele`);
187
+ x = p.x;
188
+ y = p.y - p.h;
189
+ z = p.z + 0.5;
190
+ }
191
+ else {
192
+ const off = typeof o.align === "number" ? o.align : { left: -0.3, right: 0.3, center: 0, "far-left": -0.42, "far-right": 0.42 }[o.align || "center"] ?? 0;
193
+ x = p.x + off * p.w;
194
+ y = p.y - (p.top ?? PA.top) * p.scale;
195
+ z = p.z + 0.5 + (o.layer === "back" ? -0.2 : o.layer === "front" ? 0.2 : 0);
196
+ }
197
+ depth = p.depth;
198
+ }
199
+ else if (heldBy[id]) {
200
+ const h = placed[heldBy[id]];
201
+ scale = h.scale * sizeK;
202
+ const hs = Math.sign(h.hand[0]) || 1;
203
+ x = h.x + h.hand[0] * h.scale + (A.kind === "any" ? hs * dims.w * 0.42 * scale : 0);
204
+ y = h.y + h.hand[1] * h.scale + (GRIP[res.id] ?? dims.h / 2) * scale;
205
+ z = h.z + 0.5;
206
+ depth = h.depth;
207
+ }
208
+ else {
209
+ // objetos de chão
210
+ if (A.kind === "surface")
211
+ warnings.push(`'${id}' (${res.id}) costuma ficar sobre uma superfície; adicione 'on: <mesa>'`);
212
+ const pref = ref("left_of") || ref("right_of") || ref("behind") || ref("in_front_of") || ref("under");
213
+ if (!depth) {
214
+ if (o.behind && pref)
215
+ depth = DEPTHS[Math.max(0, DEPTHS.indexOf(pref.depth) - 1)];
216
+ else if (o.in_front_of && pref)
217
+ depth = DEPTHS[Math.min(2, DEPTHS.indexOf(pref.depth) + 1)];
218
+ else
219
+ depth = (pref?.depth) || "near";
220
+ }
221
+ if (!DEPTHS.includes(depth)) {
222
+ warnings.push(`depth '${depth}' inválido em '${id}' (use near, mid, far)`);
223
+ depth = "near";
224
+ }
225
+ scale = U * sizeK * DEPTH_SCALE[depth];
226
+ const w = dims.w * scale;
227
+ const gap = (o.gap ?? 0.015) * W;
228
+ x = (SLOTS[o.at] ?? (typeof o.at === "number" ? o.at : 0.5)) * W;
229
+ if (o.left_of && pref)
230
+ x = pref.bx0 - gap - w / 2;
231
+ if (o.right_of && pref)
232
+ x = pref.bx1 + gap + w / 2;
233
+ if (o.behind && pref)
234
+ x = pref.x + (o.offset ?? 0.35) * pref.w;
235
+ if (o.in_front_of && pref)
236
+ x = pref.x + (o.offset ?? 0) * pref.w;
237
+ if (o.under && pref)
238
+ x = pref.x;
239
+ y = H * lines.base[depth];
240
+ z = DEPTHS.indexOf(depth) * 1000 + y;
241
+ if (A.kind === "floor")
242
+ z -= 400;
243
+ if (o.layer === "back")
244
+ z -= 300;
245
+ if (o.layer === "front")
246
+ z += 300;
247
+ }
248
+ const drawn = A.draw({ ...o }, theme);
249
+ if (drawn.box) {
250
+ dims.w = drawn.box.w;
251
+ dims.h = drawn.box.h;
252
+ }
253
+ const w = dims.w * scale, h = dims.h * scale;
254
+ let svg = typeof drawn === "string" ? drawn : drawn.svg;
255
+ if (A.outline)
256
+ svg = `<g stroke="${theme.ink}" stroke-width="${(1.6 / scale).toFixed(2)}" stroke-linejoin="round">${svg.replaceAll(`fill="${theme.shadow}"`, `fill="${theme.shadow}" stroke="none"`)}</g>`;
257
+ placed[id] = { id, asset: res.id, kind: A.kind, x, y, scale, w, h, z, depth, svg, top: A.topOf ? A.topOf(o) : A.top, noHaze: o.haze === false,
258
+ hand: drawn.hand, bx0: x - w / 2, bx1: x + w / 2, by0: y - h, by1: y, related: deps(o).concat(o.holds || [], heldBy[id] || []) };
259
+ }
260
+ // ---- olhar: `look: <id>` faz o personagem olhar para outro objeto da cena ----
261
+ for (const p of Object.values(placed)) {
262
+ const o = objs[p.id];
263
+ if (p.asset !== "person" || typeof o.look !== "string")
264
+ continue;
265
+ const tg = placed[o.look];
266
+ if (!tg) {
267
+ if (!["left", "right", "up", "down", "up-left", "up-right", "down-left", "down-right", "camera", "forward"].includes(o.look))
268
+ warnings.push(`'${p.id}' olha para '${o.look}', que não existe na cena`);
269
+ continue;
270
+ }
271
+ const dx = tg.x - p.x, dy = (tg.y - tg.h / 2) - (p.y - p.h * 0.85), len = Math.hypot(dx, dy) || 1;
272
+ const drawn = LIB.person.draw({ ...o, gaze: [dx / len, dy / len] }, theme);
273
+ p.svg = drawn.svg;
274
+ }
275
+ // ---- enquadramento (câmera) ----
276
+ // canvas.shot: wide (padrão) | full | medium | close; canvas.focus: id(s) ou grupo(s); canvas.frame: left | center | right | 0..1
277
+ const shot = c.shot || "wide";
278
+ const cam = { k: 1, tx: 0, ty: 0 };
279
+ if (shot !== "wide") {
280
+ const SHOT = { full: { fill: 0.55 }, medium: { show: 0.62, top: 0.12 }, close: { show: 0.3, top: 0.08 } }[shot];
281
+ if (!SHOT)
282
+ warnings.push(`shot '${shot}' inválido; use wide, full, medium ou close`);
283
+ else {
284
+ let ids = [];
285
+ for (const f of [].concat(c.focus || [])) {
286
+ const m = placed[f] ? [f] : Object.keys(placed).filter((k) => k.startsWith(f + "_"));
287
+ if (!m.length)
288
+ warnings.push(`focus '${f}' não existe na cena`);
289
+ ids.push(...m);
290
+ }
291
+ if (!ids.length)
292
+ ids = Object.keys(placed).filter((k) => placed[k].asset === "person");
293
+ if (!ids.length)
294
+ ids = Object.keys(placed).filter((k) => ["ground", "any"].includes(placed[k].kind));
295
+ let F = ids.map((i) => placed[i]);
296
+ // medium e close enquadram pessoas (cabeça e tronco); a mesa do grupo não deve ditar o zoom
297
+ if (SHOT.top != null && F.some((p) => p.asset === "person"))
298
+ F = F.filter((p) => p.asset === "person");
299
+ if (F.length) {
300
+ // braços abertos/erguidos passam da caixa do personagem: dá folga lateral às pessoas
301
+ const padX = (p) => (p.asset === "person" ? p.w * 0.5 : 0);
302
+ const fx0 = Math.min(...F.map((p) => p.bx0 - padX(p))), fx1 = Math.max(...F.map((p) => p.bx1 + padX(p)));
303
+ const fy0 = Math.min(...F.map((p) => p.by0)), fy1 = Math.max(...F.map((p) => p.by1));
304
+ // zoom pela altura do foco, limitado para o foco caber na largura (formatos verticais)
305
+ const top = c.headroom ?? SHOT.top, fh = Math.max(1, fy1 - fy0);
306
+ // full: o foco inteiro ocupa ~62% da altura; medium/close: no espaço abaixo do headroom cabe só
307
+ // a fração `show` do corpo (até o quadril / cabeça e ombros). Limitado para caber na largura.
308
+ const kh = SHOT.fill ? (SHOT.fill * H) / fh : ((1 - top) * H) / (SHOT.show * fh);
309
+ const k = Math.max(1, Math.min(6, kh, (0.8 * W) / Math.max(1, fx1 - fx0)));
310
+ const target = typeof c.frame === "number" ? c.frame : { left: 1 / 3, center: 0.5, right: 2 / 3 }[c.frame || "center"] ?? 0.5;
311
+ let tx = target * W - ((fx0 + fx1) / 2) * k;
312
+ let ty = top == null ? 0.55 * H - ((fy0 + fy1) / 2) * k : top * H - fy0 * k;
313
+ tx = Math.min(0, Math.max(W - W * k, tx));
314
+ ty = Math.min(0, Math.max(H - H * k, ty));
315
+ Object.assign(cam, { k, tx, ty });
316
+ for (const p of Object.values(placed)) {
317
+ p.x = p.x * k + tx;
318
+ p.y = p.y * k + ty;
319
+ p.scale *= k;
320
+ p.w *= k;
321
+ p.h *= k;
322
+ p.bx0 = p.bx0 * k + tx;
323
+ p.bx1 = p.bx1 * k + tx;
324
+ p.by0 = p.by0 * k + ty;
325
+ p.by1 = p.by1 * k + ty;
326
+ p.offView = p.bx1 < -0.02 * W || p.bx0 > 1.02 * W || p.by1 < -0.02 * H || p.by0 > 1.02 * H;
327
+ }
328
+ for (const p of F)
329
+ p.focus = true;
330
+ }
331
+ }
332
+ }
333
+ // ---- verificações (feedback em texto) ----
334
+ const list = Object.values(placed);
335
+ for (const p of list) {
336
+ if (LIB[p.asset].backdrop)
337
+ continue;
338
+ const ox = Math.max(0, -p.bx0, p.bx1 - W) / p.w, oy = Math.max(0, -p.by0) / p.h;
339
+ if (cam.k > 1) {
340
+ if (p.focus && p.offView)
341
+ warnings.push(`'${p.id}' é foco mas ficou fora do enquadramento (shot: ${shot}); mude frame ou focus`);
342
+ // lasca: objeto cortado pela borda mostrando tão pouco que vira ruído visual
343
+ const vis = (Math.max(0, Math.min(W, p.bx1) - Math.max(0, p.bx0)) * Math.max(0, Math.min(H, p.by1) - Math.max(0, p.by0))) / Math.max(1, p.w * p.h);
344
+ if (!p.offView && vis > 0 && vis < 0.18 && !objs[p.id].allow_crop)
345
+ warnings.push(`'${p.id}' aparece só uma lasca (${Math.round(vis * 100)}%) na borda do enquadramento; remova-o, mova-o ou mostre mais dele`);
346
+ continue;
347
+ }
348
+ if ((ox > 0.05 || oy > 0.05) && !objs[p.id].allow_crop)
349
+ warnings.push(`'${p.id}' está ${Math.round(Math.max(ox, oy) * 100)}% fora do quadro`);
350
+ }
351
+ const blocking = list.filter((p) => ["ground", "any"].includes(p.kind) && !objs[p.id].on && !heldBy[p.id]);
352
+ for (let i = 0; i < list.length; i++)
353
+ for (let j = i + 1; j < list.length; j++) {
354
+ const a = list[i], b = list[j];
355
+ if (!blocking.includes(a) || !blocking.includes(b) || a.depth !== b.depth)
356
+ continue;
357
+ if (a.related.includes(b.id) || b.related.includes(a.id))
358
+ continue;
359
+ if (LIB[a.asset].hollow || LIB[b.asset].hollow)
360
+ continue; // tampos/prateleiras: o espaço embaixo é livre
361
+ if ((objs[a.id].layer || "") !== (objs[b.id].layer || ""))
362
+ continue; // camadas diferentes de propósito
363
+ const ix = Math.max(0, Math.min(a.bx1, b.bx1) - Math.max(a.bx0, b.bx0));
364
+ const iy = Math.max(0, Math.min(a.by1, b.by1) - Math.max(a.by0, b.by0));
365
+ const frac = (ix * iy) / Math.min(a.w * a.h, b.w * b.h);
366
+ if (frac > 0.2)
367
+ warnings.push(`'${a.id}' sobrepõe '${b.id}' em ${Math.round(frac * 100)}%; use left_of/right_of ou depth diferente`);
368
+ }
369
+ // ---- fundo ----
370
+ const t = theme;
371
+ const hz = H * lines.horizon;
372
+ // perspectiva atmosférica: o que está longe se mistura à cor do ar e perde contraste
373
+ const air = setting === "indoor" ? t.wall : t.skyBottom;
374
+ const [ar, ag, ab] = [1, 3, 5].map((i) => parseInt(air.slice(i, i + 2), 16) / 255);
375
+ const HAZE = setting === "indoor" ? { far: 0.08, mid: 0.04 } : { far: 0.32, mid: 0.13 };
376
+ if (c.haze === false) {
377
+ HAZE.far = 0;
378
+ HAZE.mid = 0;
379
+ }
380
+ const hazeFilter = (id, k) => `<filter id="${id}" color-interpolation-filters="sRGB"><feColorMatrix type="matrix" values="${1 - k} 0 0 0 ${(ar * k).toFixed(3)} 0 ${1 - k} 0 0 ${(ag * k).toFixed(3)} 0 0 ${1 - k} 0 ${(ab * k).toFixed(3)} 0 0 0 1 0"/></filter>`;
381
+ const sm = (t.shadow.match(/[\d.]+/g) || [0, 0, 0, 0.15]).map(Number);
382
+ let bg = `<defs><linearGradient id="sky" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="${t.skyTop}"/><stop offset="1" stop-color="${t.skyBottom}"/></linearGradient>` +
383
+ `<radialGradient id="cshadow"><stop offset="0" stop-color="rgb(${sm[0]},${sm[1]},${sm[2]})" stop-opacity="${sm[3] * 1.5}"/><stop offset="0.55" stop-color="rgb(${sm[0]},${sm[1]},${sm[2]})" stop-opacity="${sm[3] * 1.1}"/><stop offset="1" stop-color="rgb(${sm[0]},${sm[1]},${sm[2]})" stop-opacity="0"/></radialGradient>` +
384
+ hazeFilter("hazeFar", HAZE.far) + hazeFilter("hazeMid", HAZE.mid) + `</defs>`;
385
+ let bgAtText = t.skyTop;
386
+ if (setting === "indoor") {
387
+ bgAtText = t.wall;
388
+ bg += `<rect width="${W}" height="${hz}" fill="${t.wall}"/><rect y="${hz}" width="${W}" height="${H - hz}" fill="${t.floor}"/>` +
389
+ `<rect y="${hz - 8}" width="${W}" height="10" fill="${t.woodDark}" opacity="0.35"/>`;
390
+ if (c.floor === "planks") {
391
+ // tábuas em perspectiva, convergindo para um ponto de fuga acima da parede
392
+ const vx = W * (c.vanish ?? 0.5), vy = hz - H * 0.9, n = 16;
393
+ const atY = (x0, y) => vx + (x0 - vx) * (y - vy) / (H - vy);
394
+ for (let i = -6; i < n + 6; i++) {
395
+ const x0 = (i / n) * W * 1.6 - W * 0.3, x1 = ((i + 1) / n) * W * 1.6 - W * 0.3;
396
+ bg += `<path d="M${atY(x0, hz).toFixed(1)} ${hz} L${atY(x1, hz).toFixed(1)} ${hz} L${x1.toFixed(1)} ${H} L${x0.toFixed(1)} ${H} Z" fill="${sh(t.floor, (i % 3) * 0.03 - 0.03)}"/>` +
397
+ `<path d="M${atY(x0, hz).toFixed(1)} ${hz} L${x0.toFixed(1)} ${H}" stroke="${sh(t.floor, -0.3)}" stroke-width="1.2" opacity="0.6"/>`;
398
+ }
399
+ }
400
+ else
401
+ for (let i = 1; i < 8; i++)
402
+ bg += `<rect x="0" y="${(hz + (H - hz) * (i / 8) ** 1.4 - 0.75).toFixed(1)}" width="${W}" height="1.5" fill="${t.woodDark}" opacity="0.15"/>`;
403
+ }
404
+ else if (setting === "beach") {
405
+ const sea = H * lines.sea;
406
+ bg += `<rect width="${W}" height="${H}" fill="url(#sky)"/><rect y="${hz}" width="${W}" height="${sea - hz}" fill="${t.sea}"/>` +
407
+ `<path d="M0 ${sea} Q${W * 0.25} ${sea - 14} ${W * 0.5} ${sea} T${W} ${sea} L${W} ${H} L0 ${H} Z" fill="${t.ground}"/>`;
408
+ for (let i = 0; i < 6; i++)
409
+ bg += `<path d="M${W * (0.08 + i * 0.17)} ${hz + 18 + (i % 3) * 22} q14 -6 28 0" stroke="${t.seaLight}" stroke-width="3" fill="none" stroke-linecap="round"/>`;
410
+ bg += `<path d="M0 ${sea - 4} Q${W * 0.25} ${sea - 18} ${W * 0.5} ${sea - 4} T${W} ${sea - 4}" stroke="${t.paper}" stroke-width="4" fill="none" opacity="0.7"/>`;
411
+ }
412
+ else {
413
+ bg += `<rect width="${W}" height="${H}" fill="url(#sky)"/>`;
414
+ if (setting === "outdoor")
415
+ bg += `<path d="M0 ${hz} Q${W * 0.2} ${hz - 50} ${W * 0.45} ${hz - 10} T${W} ${hz - 30} L${W} ${H} L0 ${H} Z" fill="${t.groundDark}" opacity="0.55"/>`;
416
+ bg += `<path d="M0 ${hz + 12} Q${W * 0.3} ${hz - 6} ${W * 0.6} ${hz + 10} T${W} ${hz + 4} L${W} ${H} L0 ${H} Z" fill="${t.ground}"/>`;
417
+ if (setting === "city")
418
+ bg += `<rect y="${H * 0.86}" width="${W}" height="${H * 0.14}" fill="${t.groundDark}"/>` +
419
+ Array.from({ length: 10 }, (_, i) => `<rect x="${i * W / 10 + 20}" y="${H * 0.925}" width="${W / 20}" height="5" fill="${t.primary}" opacity="0.5"/>`).join("");
420
+ }
421
+ // ---- texto ----
422
+ // Campos: content (\n quebra linha), at (top|bottom-left|center|right), role (title|subtitle|label|body),
423
+ // opcionais: y (fração da altura, linha de base), size (fração da altura), weight, color, box (cor de fundo), pad.
424
+ let textSvg = "";
425
+ const textRects = [];
426
+ for (const tx of scene.text || []) {
427
+ const role = tx.role || "title";
428
+ const fs = tx.size ? tx.size * H : ({ title: H * 0.075, subtitle: H * 0.036, label: H * 0.028, body: H * 0.032 }[role] || H * 0.04);
429
+ const [vy, hx] = (tx.at || "top-left").split("-");
430
+ const m = W * 0.06;
431
+ const anchor = hx === "center" ? "middle" : hx === "right" ? "end" : "start";
432
+ const xx = tx.x != null ? tx.x * W : hx === "center" ? W / 2 : hx === "right" ? W - m : m;
433
+ const lines = String(tx.content).split("\n");
434
+ const lh = fs * 1.2;
435
+ let yy = vy === "bottom" ? H - m * 0.7 - (lines.length - 1) * lh : m + fs * 0.9;
436
+ if (tx.y == null && role === "subtitle" && (scene.text || []).some((o) => (o.role || "title") === "title" && o.at === tx.at && o.y == null))
437
+ yy += H * 0.075 * 0.9 + fs * 0.8;
438
+ if (tx.y != null)
439
+ yy = tx.y * H;
440
+ const color = tx.color ? (t[tx.color] || tx.color) : t.text;
441
+ let ratio = contrast(color, bgAtText);
442
+ const estW = Math.max(...lines.map((l) => l.length)) * fs * (tx.weight >= 700 || role === "title" ? 0.6 : 0.565);
443
+ const x0 = anchor === "start" ? xx : anchor === "end" ? xx - estW : xx - estW / 2;
444
+ const blockH = fs + (lines.length - 1) * lh;
445
+ textRects.push({ x0, y0: yy - fs, x1: x0 + estW, y1: yy + blockH - fs * 0.75, box: !!tx.box });
446
+ if (tx.box) {
447
+ const bfill = t[tx.box] || tx.box, pad = (tx.pad ?? 0.45) * fs;
448
+ ratio = contrast(color, bfill);
449
+ textSvg += `<rect x="${(x0 - pad).toFixed(1)}" y="${(yy - fs * 1.05 - pad * 0.3).toFixed(1)}" width="${(estW + pad * 2).toFixed(1)}" height="${(blockH + fs * 0.45 + pad * 0.6).toFixed(1)}" rx="${(tx.radius ?? 0.35) * fs}" fill="${bfill}"/>`;
450
+ }
451
+ if (ratio < 4.5)
452
+ warnings.push(`texto "${lines[0]}" com contraste ${ratio.toFixed(1)}:1 (mín. 4.5); troque 'color' ou use 'box'`);
453
+ for (const p of list) {
454
+ if (LIB[p.asset].backdrop)
455
+ continue;
456
+ const ix = Math.max(0, Math.min(p.bx1, x0 + estW) - Math.max(p.bx0, x0)), iy = Math.max(0, Math.min(p.by1, yy + blockH - fs + fs * 0.25) - Math.max(p.by0, yy - fs));
457
+ if (ix * iy > 0.06 * estW * blockH || ix * iy > 0.12 * p.w * p.h)
458
+ warnings.push(`texto "${lines[0]}" cobre '${p.id}'`);
459
+ }
460
+ const weight = tx.weight || (role === "title" ? 700 : role === "body" ? 400 : 500);
461
+ const esc = (v) => v.replace(/&/g, "&amp;").replace(/</g, "&lt;");
462
+ textSvg += `<text x="${xx.toFixed(1)}" y="${yy.toFixed(1)}" font-family="${FONT}" font-size="${fs.toFixed(1)}" font-weight="${weight}" fill="${color}" text-anchor="${anchor}">` +
463
+ lines.map((l, i) => i === 0 ? `<tspan x="${xx.toFixed(1)}">${esc(l)}</tspan>` : `<tspan x="${xx.toFixed(1)}" dy="${lh.toFixed(1)}">${esc(l)}</tspan>`).join("") + `</text>`;
464
+ }
465
+ // ---- luz global ----
466
+ // canvas.light: false | { from: left|right|front|0..1, strength: 0..1 }. Sem valor: segue o sol/lua/janela da cena.
467
+ const KL = KIT.light || {};
468
+ const lc = c.light === false || (KL.mode === "none" && c.light == null) ? null : typeof c.light === "object" ? c.light : {};
469
+ const hatch = KL.mode === "hatch";
470
+ const night = luminance(setting === "indoor" ? t.wall : t.skyTop) < 0.12;
471
+ let light = null;
472
+ if (lc) {
473
+ let lx = typeof lc.from === "number" ? lc.from : { left: 0.05, right: 0.95, front: 0.5, top: 0.5 }[lc.from];
474
+ if (lx == null) {
475
+ const src = list.find((p) => ["sun", "moon"].includes(p.asset)) || (setting === "indoor" && list.find((p) => p.asset === "window"));
476
+ lx = src ? src.x / W : 0.15;
477
+ }
478
+ const s = lc.strength ?? KL.strength ?? 0.6, dir = lx < 0.4 ? 1 : lx > 0.6 ? -1 : 0;
479
+ const lcol = night ? "#C9D8FF" : "#FFF4DE", scol = `rgb(${sm[0]},${sm[1]},${sm[2]})`;
480
+ const [x1, x2] = dir >= 0 ? [0, 1] : [1, 0];
481
+ light = { lx, s, dir, lcol, scol };
482
+ bg = bg.replace("</defs>",
483
+ // sombreamento de volume: lado iluminado clareia, lado oposto escurece; base escurece (oclusão)
484
+ `<linearGradient id="lgShade" x1="${dir ? x1 : 0.5}" y1="0" x2="${dir ? x2 : 0.5}" y2="${dir ? 0.35 : 1}"><stop offset="0" stop-color="${lcol}" stop-opacity="${(0.26 * s).toFixed(3)}"/><stop offset="0.42" stop-color="${lcol}" stop-opacity="0"/><stop offset="0.6" stop-color="${scol}" stop-opacity="0"/><stop offset="1" stop-color="${scol}" stop-opacity="${(0.5 * s).toFixed(3)}"/></linearGradient>` +
485
+ `<linearGradient id="lgAO" x1="0" y1="0" x2="0" y2="1"><stop offset="0.72" stop-color="${scol}" stop-opacity="0"/><stop offset="1" stop-color="${scol}" stop-opacity="${(0.32 * s).toFixed(3)}"/></linearGradient>` +
486
+ `<filter id="toWhite" color-interpolation-filters="sRGB"><feColorMatrix values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/></filter>` +
487
+ `<filter id="castF" x="-30%" y="-30%" width="160%" height="160%" color-interpolation-filters="sRGB"><feColorMatrix values="0 0 0 0 ${(sm[0] / 255).toFixed(3)} 0 0 0 0 ${(sm[1] / 255).toFixed(3)} 0 0 0 0 ${(sm[2] / 255).toFixed(3)} 0 0 0 1 0"/><feGaussianBlur stdDeviation="${(H * (setting === "indoor" ? 0.006 : 0.003)).toFixed(1)}"/></filter>` +
488
+ `<clipPath id="groundClip"><rect y="${(hz * cam.k + cam.ty).toFixed(1)}" width="${W}" height="${H}"/></clipPath>` +
489
+ `<radialGradient id="glow" cx="${lx}" cy="${setting === "indoor" ? 0.25 : 0.15}" r="0.75"><stop offset="0" stop-color="${lcol}" stop-opacity="${(0.55 * s).toFixed(3)}"/><stop offset="1" stop-color="${lcol}" stop-opacity="0"/></radialGradient>` +
490
+ `<linearGradient id="falloff" x1="${x1}" y1="0" x2="${x2}" y2="0"><stop offset="0.35" stop-color="${scol}" stop-opacity="0"/><stop offset="1" stop-color="${scol}" stop-opacity="${dir ? (0.13 * s).toFixed(3) : 0}"/></linearGradient>` +
491
+ (hatch ? hatchDefs(t.ink) : "") +
492
+ `<radialGradient id="vignette" cx="0.5" cy="0.5" r="0.75"><stop offset="0.6" stop-color="${scol}" stop-opacity="0"/><stop offset="1" stop-color="${scol}" stop-opacity="${(0.17 * s).toFixed(3)}"/></radialGradient></defs>`);
493
+ if (hatch) { /* gravura: sem brilhos e degradês de ambiente */ }
494
+ else if (setting === "indoor")
495
+ bg += `<rect width="${W}" height="${hz}" fill="url(#glow)"/><rect width="${W}" height="${H}" fill="url(#falloff)"/>`;
496
+ else
497
+ bg += `<rect width="${W}" height="${H * 0.75}" fill="url(#glow)"/>`;
498
+ }
499
+ // ---- montagem ----
500
+ if (cam.k !== 1)
501
+ bg = `<g transform="translate(${cam.tx.toFixed(1)} ${cam.ty.toFixed(1)}) scale(${cam.k.toFixed(4)})">${bg}</g>`;
502
+ const SHADOW_RE = /<ellipse cx="([-\d.]+)" cy="0" rx="([\d.]+)" ry="([\d.]+)" fill="[^"]*"( stroke="none")?\s*\/>/;
503
+ const casts = [];
504
+ const pieces = list.sort((a, b) => a.z - b.z).filter((p) => !p.offView).map((p) => {
505
+ const cord = p.kind === "ceiling" ? `<path d="M${p.x.toFixed(1)} 0 L${p.x.toFixed(1)} ${(p.y - p.h).toFixed(1)}" stroke="${t.ink}" stroke-width="2"/>` : "";
506
+ const hz = p.noHaze ? "" : p.depth === "far" && HAZE.far ? " filter=\"url(#hazeFar)\"" : p.depth === "mid" && HAZE.mid ? " filter=\"url(#hazeMid)\"" : "";
507
+ let shadow = "";
508
+ const art = p.svg.replace(SHADOW_RE, (m, cx, rx, ry) => {
509
+ if (!m.includes(t.shadow))
510
+ return m;
511
+ shadow = `<ellipse cx="${cx}" cy="0" rx="${(rx * 1.25).toFixed(1)}" ry="${(ry * 1.4).toFixed(1)}" fill="url(#cshadow)"/>`;
512
+ return "";
513
+ });
514
+ const T = `translate(${p.x.toFixed(1)} ${p.y.toFixed(1)}) scale(${p.scale.toFixed(3)})`;
515
+ const o = objs[p.id] || {};
516
+ const A = LIB[p.asset] || {};
517
+ let shade = "";
518
+ const lit = light && !A.backdrop && !["sky", "floor"].includes(p.kind) && o.light !== false;
519
+ if (lit) {
520
+ const k = { near: 1, mid: 0.6, far: 0.3 }[p.depth] ?? 1;
521
+ const pad = 0.2;
522
+ const [rx, ry, rw, rh] = [p.bx0 - p.w * pad, p.by0 - p.h * pad, p.w * (1 + 2 * pad), p.h * (1 + pad)].map((v) => v.toFixed(1));
523
+ const mk = `<mask id="mk_${p.id}" maskUnits="userSpaceOnUse" x="${rx}" y="${ry}" width="${rw}" height="${rh}"><use href="#b_${p.id}" transform="${T}" filter="url(#toWhite)"/></mask>`;
524
+ if (hatch) {
525
+ // gravura: hachura só no lado da sombra (metade oposta à luz; de frente, a parte de baixo)
526
+ const d = light.dir, hx0 = d > 0 ? p.x + p.w * 0.08 : +rx, hx1 = d < 0 ? p.x - p.w * 0.08 : +rx + +rw;
527
+ const [hy0, hy1] = d ? [+ry, +ry + +rh] : [p.by0 + p.h * 0.6, +ry + +rh];
528
+ shade = mk + `<g mask="url(#mk_${p.id})" opacity="${k}"><rect x="${hx0.toFixed(1)}" y="${hy0.toFixed(1)}" width="${Math.max(0, hx1 - hx0).toFixed(1)}" height="${Math.max(0, hy1 - hy0).toFixed(1)}" fill="url(#hatchP)"/></g>`;
529
+ }
530
+ else
531
+ shade = mk + `<g mask="url(#mk_${p.id})" opacity="${k}"><rect x="${rx}" y="${ry}" width="${rw}" height="${rh}" fill="url(#lgShade)"/>` +
532
+ (["ground", "any"].includes(p.kind) && !o.on ? `<rect x="${p.bx0.toFixed(1)}" y="${p.by0.toFixed(1)}" width="${p.w.toFixed(1)}" height="${p.h.toFixed(1)}" fill="url(#lgAO)"/>` : "") + `</g>`;
533
+ // sombra projetada no chão: silhueta achatada e inclinada para longe da luz
534
+ if (KL.casts !== false && ["ground", "any"].includes(p.kind) && !o.on && !heldBy[p.id] && !(o.elevation > 0) && !["mountain", "cloud"].includes(p.asset)) {
535
+ const indoor = setting === "indoor";
536
+ const kk = indoor ? 0.13 : 0.24, sx = (indoor ? 0.35 : 0.75) * light.dir;
537
+ casts.push(`<use href="#b_${p.id}" transform="translate(${p.x.toFixed(1)} ${p.y.toFixed(1)}) matrix(1 0 ${(-sx).toFixed(3)} ${kk} 0 0) scale(${p.scale.toFixed(3)})"/>`);
538
+ }
539
+ }
540
+ p.bodySvg = `<g transform="${T}">${art}</g>`;
541
+ // contorno (outline/hatch) e sombra de recorte (paper), por objeto, com espessura constante em px
542
+ const deco = !A.backdrop && !["sky", "floor"].includes(p.kind) && o.kit !== false;
543
+ let art2 = art, fx = "", defs = "";
544
+ if (deco && KIT.outline) {
545
+ if (KIT.outline.inner)
546
+ art2 = innerStroke(art, KIT.outline.inner / p.scale, t.ink);
547
+ defs += outlineFilter(`ol_${p.id}`, KIT.outline.w / p.scale, t.ink);
548
+ fx = `ol_${p.id}`;
549
+ }
550
+ if (deco && KIT.drop) {
551
+ defs += dropFilter(`dr_${p.id}`, p.scale);
552
+ fx = `dr_${p.id}`;
553
+ }
554
+ // sombra de contato fica fora do contorno (senão vira um anel em volta da elipse)
555
+ const contact = shadow ? `<g transform="${T}"${hz}>${shadow}</g>` : "";
556
+ const inner = `<g id="${p.id}" transform="${T}"${hz}><g id="b_${p.id}">${art2}</g></g>`;
557
+ return cord + contact + (fx ? `${defs}<g filter="url(#${fx})">${inner}</g>` : inner) + shade;
558
+ });
559
+ const castLayer = !casts.length
560
+ ? ""
561
+ : hatch
562
+ ? `<mask id="castM" maskUnits="userSpaceOnUse" x="0" y="0" width="${W}" height="${H}"><g filter="url(#toWhite)">${casts.join("")}</g></mask><g clip-path="url(#groundClip)"><rect width="${W}" height="${H}" fill="url(#hatchC)" mask="url(#castM)"/></g>`
563
+ : `<g clip-path="url(#groundClip)" opacity="${((night ? 0.5 : setting === "indoor" ? 0.75 : 1) * 0.42 * light.s).toFixed(3)}"><g filter="url(#castF)">${casts.join("")}</g></g>`;
564
+ const body = pieces.join("\n");
565
+ const vignette = light && !hatch ? `<rect width="${W}" height="${H}" fill="url(#vignette)"/>` : "";
566
+ const grain = c.grain ? `<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="${W}" height="${H}" filter="url(#grain)" opacity="0.10"/>` : "";
567
+ const head = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}">`;
568
+ // filtro de cena (riso/sketch) envolve fundo + objetos; textura vai por cima, abaixo do texto
569
+ const sceneArt = KIT.scene ? `<defs>${sceneFilter(KIT.scene, t)}</defs><g filter="url(#kitScene)">${bg}\n${castLayer}\n${body}\n${vignette}</g>` : `${bg}\n${castLayer}\n${body}\n${vignette}`;
570
+ const svg = flattenOpacity(`${head}\n${sceneArt}\n${texture(KIT.texture, W, H)}\n${grain}\n${textSvg}\n</svg>`);
571
+ // ---- entrada do diretor de arte (a crítica em si roda em scenec/render, que usa o resvg) ----
572
+ const critiqueInput = c.critique === false
573
+ ? null
574
+ : { W, H, head, bg: flattenOpacity(bg), scene: flattenOpacity(sceneArt), theme: t, scale: c.scale ?? 1, textRects, skip: KIT.scene === "sketch" ? ["silhouette"] : [],
575
+ objects: list.filter((p) => !p.offView).map((p) => ({ id: p.id, asset: p.asset, kind: p.kind, z: p.z, body: flattenOpacity(p.bodySvg), related: p.related, ignore: !!(LIB[p.asset].backdrop || objs[p.id].critique === false) })) };
576
+ const description = list.map((p) => `${p.id} (${p.asset}): x=${Math.round((p.x / W) * 100)}%, base=${Math.round((p.y / H) * 100)}%, ` +
577
+ `${Math.round((p.w / W) * 100)}%×${Math.round((p.h / H) * 100)}% do quadro${p.depth ? ", " + p.depth : ""}`).join("\n");
578
+ const pct = (v, d) => +((v / d) * 100).toFixed(1);
579
+ const layout = list.map((p) => ({ id: p.id, asset: p.asset, x: pct(p.x, W), base: pct(p.y, H), w: pct(p.w, W), h: pct(p.h, H) }));
580
+ return { svg, warnings: [...new Set(warnings)], description, layout, critiqueInput };
581
+ }
@@ -0,0 +1,2 @@
1
+ import type { CompileOptions } from "../protocols/options.ts";
2
+ export declare function loadCustomAssets(defs?: Record<string, any>, io?: CompileOptions, warnings?: string[], failed?: Set<string>): Record<string, any>;