@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,365 @@
1
+ // Modo mapa: contornos reais (data/europe.json, extraído uma vez do Natural Earth), projeção cônica
2
+ // conforme de Lambert feita aqui mesmo, países destacados, rota com meio de transporte por trecho,
3
+ // pinos numerados, rótulos que evitam sobreposição e painel de roteiro.
4
+ import europeData from "../data/europe.json" with { type: "json" };
5
+ import { sh } from "../utils/color.js";
6
+ const EUROPE = europeData;
7
+ const FONT = "Poppins";
8
+ const f1 = (n) => (+n).toFixed(1);
9
+ const esc = (s) => String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;");
10
+ const norm = (s) => String(s).toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").trim();
11
+ // Cidades (lon, lat) com nomes em português; aceita também `at: [lon, lat]` na cena.
12
+ const CITIES = {
13
+ paris: [2.35, 48.86, "Paris"], roma: [12.5, 41.9, "Roma"], rome: [12.5, 41.9, "Roma"], munique: [11.58, 48.14, "Munique"], munich: [11.58, 48.14, "Munique"],
14
+ salzburgo: [13.04, 47.81, "Salzburgo"], saltzburg: [13.04, 47.81, "Salzburgo"], salzburg: [13.04, 47.81, "Salzburgo"], luxemburgo: [6.13, 49.61, "Luxemburgo"],
15
+ luxembourg: [6.13, 49.61, "Luxemburgo"], milao: [9.19, 45.46, "Milão"], milan: [9.19, 45.46, "Milão"], londres: [-0.13, 51.51, "Londres"],
16
+ madri: [-3.7, 40.42, "Madri"], barcelona: [2.17, 41.39, "Barcelona"], lisboa: [-9.14, 38.72, "Lisboa"], porto: [-8.61, 41.15, "Porto"],
17
+ berlim: [13.4, 52.52, "Berlim"], frankfurt: [8.68, 50.11, "Frankfurt"], hamburgo: [9.99, 53.55, "Hamburgo"], colonia: [6.96, 50.94, "Colônia"],
18
+ viena: [16.37, 48.21, "Viena"], innsbruck: [11.4, 47.27, "Innsbruck"], zurique: [8.54, 47.37, "Zurique"], genebra: [6.14, 46.2, "Genebra"],
19
+ berna: [7.45, 46.95, "Berna"], amsterda: [4.9, 52.37, "Amsterdã"], bruxelas: [4.35, 50.85, "Bruxelas"], praga: [14.42, 50.08, "Praga"],
20
+ budapeste: [19.04, 47.5, "Budapeste"], varsovia: [21.01, 52.23, "Varsóvia"], cracovia: [19.94, 50.06, "Cracóvia"], veneza: [12.32, 45.44, "Veneza"],
21
+ florenca: [11.26, 43.77, "Florença"], napoles: [14.27, 40.85, "Nápoles"], turim: [7.69, 45.07, "Turim"], bolonha: [11.34, 44.49, "Bolonha"],
22
+ nice: [7.27, 43.7, "Nice"], lyon: [4.84, 45.76, "Lyon"], marselha: [5.37, 43.3, "Marselha"], bordeaux: [-0.58, 44.84, "Bordeaux"],
23
+ estrasburgo: [7.75, 48.57, "Estrasburgo"], copenhague: [12.57, 55.68, "Copenhague"], estocolmo: [18.07, 59.33, "Estocolmo"], oslo: [10.75, 59.91, "Oslo"],
24
+ helsinque: [24.94, 60.17, "Helsinque"], dublin: [-6.26, 53.35, "Dublin"], edimburgo: [-3.19, 55.95, "Edimburgo"], atenas: [23.73, 37.98, "Atenas"],
25
+ istambul: [28.98, 41.01, "Istambul"], dubrovnik: [18.09, 42.65, "Dubrovnik"], zagreb: [15.98, 45.81, "Zagreb"], liubliana: [14.51, 46.06, "Liubliana"],
26
+ bratislava: [17.11, 48.15, "Bratislava"], sevilha: [-5.98, 37.39, "Sevilha"], valencia: [-0.38, 39.47, "Valência"], hallstatt: [13.65, 47.56, "Hallstatt"],
27
+ bruges: [3.22, 51.21, "Bruges"], interlaken: [7.86, 46.69, "Interlaken"], como: [9.09, 45.81, "Como"], pisa: [10.4, 43.72, "Pisa"], verona: [10.99, 45.44, "Verona"],
28
+ };
29
+ const byPt = Object.fromEntries(EUROPE.countries.flatMap((c) => [[norm(c.pt), c], [norm(c.name), c]]));
30
+ // ícones dos meios de transporte (desenhados em ~24 un., centrados)
31
+ const ICON = {
32
+ plane: (c) => `<path d="M12 0 Q12 1.6 10 1.6 L3 1.6 L-3 9 L-5.5 9 L-2 1.6 L-7 1.6 L-9 4 L-10.5 4 L-9.5 0.5 Q-11 0 -9.5 -0.5 L-10.5 -4 L-9 -4 L-7 -1.6 L-2 -1.6 L-5.5 -9 L-3 -9 L3 -1.6 L10 -1.6 Q12 -1.6 12 0 Z" fill="${c}"/>`,
33
+ train: (c, bg) => `<rect x="-7" y="-10" width="14" height="16" rx="4" fill="${c}"/><rect x="-5" y="-8" width="10" height="6" rx="1.5" fill="${bg}"/>` +
34
+ `<circle cx="-3.6" cy="2" r="1.4" fill="${bg}"/><circle cx="3.6" cy="2" r="1.4" fill="${bg}"/><path d="M-5 6 L-8 10 M5 6 L8 10" stroke="${c}" stroke-width="1.8" stroke-linecap="round"/>`,
35
+ car: (c, bg) => `<path d="M-10 3 L-10 -1 L-7 -2 L-4 -7 L5 -7 L8 -2 L10 -1 L10 3 Z" fill="${c}"/><rect x="-3" y="-6" width="7" height="4" rx="1" fill="${bg}"/><circle cx="-5.5" cy="3.5" r="2.6" fill="${c}" stroke="${bg}" stroke-width="1.2"/><circle cx="5.5" cy="3.5" r="2.6" fill="${c}" stroke="${bg}" stroke-width="1.2"/>`,
36
+ bus: (c, bg) => `<rect x="-9" y="-9" width="18" height="16" rx="3" fill="${c}"/><rect x="-7" y="-7" width="14" height="6" rx="1" fill="${bg}"/><circle cx="-5" cy="8" r="2" fill="${c}"/><circle cx="5" cy="8" r="2" fill="${c}"/>`,
37
+ boat: (c) => `<path d="M-11 1 L11 1 L7 7 L-7 7 Z" fill="${c}"/><path d="M0 1 L0 -10 L8 -1 Z" fill="${c}"/>`,
38
+ };
39
+ const TRANSPORT_PT = { plane: "avião", train: "trem", car: "carro", bus: "ônibus", boat: "barco" };
40
+ const TRANSPORT_ALIAS = { aviao: "plane", "avião": "plane", voo: "plane", trem: "train", carro: "car", onibus: "bus", "ônibus": "bus", barco: "boat", navio: "boat", ferry: "boat" };
41
+ function lambert(lon0 = 10, lat0 = 50, p1 = 43, p2 = 62) {
42
+ const r = Math.PI / 180, q = (p) => Math.tan(Math.PI / 4 + (p * r) / 2);
43
+ const n = Math.log(Math.cos(p1 * r) / Math.cos(p2 * r)) / Math.log(q(p2) / q(p1));
44
+ const F = (Math.cos(p1 * r) * q(p1) ** n) / n, rho = (p) => F / q(p) ** n, rho0 = rho(lat0);
45
+ return ([lon, lat]) => { const th = n * (lon - lon0) * r, rh = rho(lat); return [rh * Math.sin(th), -(rho0 - rh * Math.cos(th))]; };
46
+ }
47
+ export function compileMap(scene, { theme: t, warnings, W, H, contrast }) {
48
+ const c = scene.canvas || {}, m = scene.map || {};
49
+ const panelOn = m.panel !== false;
50
+ const PW = panelOn ? Math.round(W * 0.28) : 0, PAD = W * 0.025;
51
+ const area = { x0: PAD, y0: PAD, x1: W - PW - PAD * (panelOn ? 1.6 : 1), y1: H - PAD };
52
+ // ---------- rota ----------
53
+ const stops = [], legs = [];
54
+ let pendingBy = null;
55
+ for (const [i, item] of (scene.route || []).entries()) {
56
+ if (item.by) {
57
+ const by = TRANSPORT_ALIAS[norm(item.by)] || item.by;
58
+ if (!ICON[by])
59
+ warnings.push(`meio de transporte '${item.by}' desconhecido (use avião, trem, carro, ônibus ou barco)`);
60
+ pendingBy = by;
61
+ continue;
62
+ }
63
+ const key = norm(item.city || "");
64
+ const g = item.at ? [item.at[0], item.at[1], item.city] : CITIES[key.replace(/\s+/g, "")];
65
+ if (!g) {
66
+ warnings.push(`cidade '${item.city}' não está no dicionário; informe 'at: [lon, lat]'`);
67
+ continue;
68
+ }
69
+ const country = item.country ? byPt[norm(item.country)] : null;
70
+ if (item.country && !country)
71
+ warnings.push(`país '${item.country}' não encontrado no mapa`);
72
+ const stop = { i, lon: g[0], lat: g[1], city: item.label || g[2] || item.city, country, note: item.note };
73
+ if (stops.length)
74
+ legs.push({ a: stops[stops.length - 1], b: stop, by: pendingBy || "car" });
75
+ if (stops.length && !pendingBy)
76
+ warnings.push(`trecho até '${stop.city}' sem meio de transporte; usei carro (adicione '- {by: ...}')`);
77
+ pendingBy = null;
78
+ stops.push(stop);
79
+ }
80
+ if (stops.length < 2)
81
+ warnings.push("a rota precisa de pelo menos 2 cidades");
82
+ // ---------- projeção e enquadramento ----------
83
+ const lon0 = m.center?.[0] ?? (stops.reduce((s, p) => s + p.lon, 0) / (stops.length || 1));
84
+ const lat0 = m.center?.[1] ?? (stops.reduce((s, p) => s + p.lat, 0) / (stops.length || 1));
85
+ const P = lambert(lon0, lat0);
86
+ const padDeg = m.padding ?? 3.5;
87
+ const lons = stops.map((s) => s.lon), lats = stops.map((s) => s.lat);
88
+ const [a0, a1, b0, b1] = m.bounds || [Math.min(...lons) - padDeg, Math.max(...lons) + padDeg, Math.min(...lats) - padDeg * 0.8, Math.max(...lats) + padDeg * 0.8];
89
+ const frame = [];
90
+ for (let k = 0; k <= 10; k++) {
91
+ frame.push(P([a0 + (a1 - a0) * k / 10, b0]), P([a0 + (a1 - a0) * k / 10, b1]), P([a0, b0 + (b1 - b0) * k / 10]), P([a1, b0 + (b1 - b0) * k / 10]));
92
+ }
93
+ const fx0 = Math.min(...frame.map((p) => p[0])), fx1 = Math.max(...frame.map((p) => p[0]));
94
+ const fy0 = Math.min(...frame.map((p) => p[1])), fy1 = Math.max(...frame.map((p) => p[1]));
95
+ const aw = area.x1 - area.x0, ah = area.y1 - area.y0;
96
+ const k = Math.min(aw / (fx1 - fx0), ah / (fy1 - fy0));
97
+ const ox = area.x0 + (aw - (fx1 - fx0) * k) / 2 - fx0 * k, oy = area.y0 + (ah - (fy1 - fy0) * k) / 2 - fy0 * k;
98
+ const proj = (lon, lat) => { const [x, y] = P([lon, lat]); return [ox + x * k, oy + y * k]; };
99
+ stops.forEach((s) => { [s.x, s.y] = proj(s.lon, s.lat); });
100
+ // ---------- países ----------
101
+ const visited = [];
102
+ for (const s of stops)
103
+ if (s.country && !visited.includes(s.country))
104
+ visited.push(s.country);
105
+ for (const name of m.highlight || []) {
106
+ const cc = byPt[norm(name)];
107
+ if (cc && !visited.includes(cc))
108
+ visited.push(cc);
109
+ }
110
+ const palette = m.palette || ["#9DB8F0", "#F7C98A", "#9ED39A", "#E9A0B4", "#B9A3E3", "#8FD3D1", "#F2A68F", "#D8C27A"];
111
+ const colorOf = new Map(visited.map((cc, i) => [cc, palette[i % palette.length]]));
112
+ const sea = sh(t.glass, 0.25), land = sh(t.paper, -0.05), border = "#FFFFFF";
113
+ const toPath = (polys) => polys.map((poly) => {
114
+ const rings = poly.map((ring) => ring.map(([lo, la]) => proj(lo, la)));
115
+ const xs = rings[0].map((p) => p[0]), ys = rings[0].map((p) => p[1]);
116
+ if (Math.max(...xs) < -50 || Math.min(...xs) > W + 50 || Math.max(...ys) < -50 || Math.min(...ys) > H + 50)
117
+ return "";
118
+ return rings.map((r) => "M" + r.map((p) => p[0].toFixed(1) + " " + p[1].toFixed(1)).join("L") + "Z").join("");
119
+ }).join("");
120
+ let mapSvg = `<rect x="0" y="0" width="${W}" height="${H}" fill="${sea}"/>`;
121
+ // ondas sutis no mar
122
+ for (let yy = 30; yy < H; yy += 46)
123
+ for (let xx = (yy / 46 % 2) * 40 + 20; xx < W - PW; xx += 90)
124
+ mapSvg += `<path d="M${xx} ${yy} q8 -4 16 0 t16 0" stroke="${sh(sea, -0.1)}" stroke-width="1.5" fill="none" opacity="0.5"/>`;
125
+ // graticule leve
126
+ let grat = "";
127
+ // só os trechos visíveis (caminhos muito fora do quadro derrubam o renderizador)
128
+ const inView = (p) => p[0] > -60 && p[0] < W + 60 && p[1] > -60 && p[1] < H + 60;
129
+ const gline = (pts) => { const v = pts.filter(inView); return v.length > 1 ? `<path d="M${v.map((p) => p.map(f1).join(" ")).join("L")}" stroke="${t.paper}" stroke-width="0.8" fill="none" opacity="0.35"/>` : ""; };
130
+ for (let lo = -30; lo <= 50; lo += 5) {
131
+ const pts = [];
132
+ for (let la = 30; la <= 72; la += 1)
133
+ pts.push(proj(lo, la));
134
+ grat += gline(pts);
135
+ }
136
+ for (let la = 30; la <= 72; la += 5) {
137
+ const pts = [];
138
+ for (let lo = -30; lo <= 50; lo += 1)
139
+ pts.push(proj(lo, la));
140
+ grat += gline(pts);
141
+ }
142
+ mapSvg += grat;
143
+ const others = EUROPE.countries.filter((cc) => !colorOf.has(cc));
144
+ mapSvg += `<g stroke="${border}" stroke-width="1" stroke-linejoin="round">` + others.map((cc) => `<path d="${toPath(cc.polys)}" fill="${land}"/>`).join("") + "</g>";
145
+ // países visitados "levantados" (sombra deslocada + borda)
146
+ for (const cc of visited) {
147
+ const d = toPath(cc.polys), col = colorOf.get(cc);
148
+ mapSvg += `<path d="${d}" fill="${sh(col, -0.35)}" transform="translate(0 4)" opacity="0.55"/><path d="${d}" fill="${col}" stroke="${sh(col, -0.3)}" stroke-width="1.6" stroke-linejoin="round"/>`;
149
+ }
150
+ // ---------- rótulos dos países ----------
151
+ const occupied = []; // caixas já usadas (para evitar sobreposição)
152
+ const ov = (a, b) => Math.max(0, Math.min(a.x1, b.x1) - Math.max(a.x0, b.x0)) * Math.max(0, Math.min(a.y1, b.y1) - Math.max(a.y0, b.y0));
153
+ const inArea = (b) => b.x0 >= area.x0 && b.x1 <= area.x1 && b.y0 >= area.y0 && b.y1 <= area.y1;
154
+ let countryLabels = "";
155
+ const fsC = Math.max(12, H * 0.017);
156
+ for (const cc of EUROPE.countries) {
157
+ const isV = colorOf.has(cc);
158
+ if (!isV && cc.area < 0.004)
159
+ continue;
160
+ const [lx, ly] = proj(cc.label[0], cc.label[1]);
161
+ const fs = isV ? fsC * 1.05 : fsC * 0.9;
162
+ const txt = (isV ? cc.pt.toUpperCase() : cc.pt), w = txt.length * fs * (isV ? 0.66 : 0.58);
163
+ const b = { x0: lx - w / 2, x1: lx + w / 2, y0: ly - fs, y1: ly + fs * 0.3, kind: "country", visited: isV, cc, txt, fs, lx, ly };
164
+ if (!inArea(b))
165
+ continue;
166
+ occupied.push(b);
167
+ }
168
+ // ---------- trechos ----------
169
+ const legSvg = [], badges = [];
170
+ const pairCount = new Map();
171
+ legs.forEach((L, idx) => {
172
+ const { a, b } = L;
173
+ const dx = b.x - a.x, dy = b.y - a.y, len = Math.hypot(dx, dy) || 1;
174
+ const key = [a.city, b.city].sort().join("|");
175
+ const nth = pairCount.get(key) || 0;
176
+ pairCount.set(key, nth + 1);
177
+ const short = len < Math.max(13, H * 0.019) * 6;
178
+ L.short = short;
179
+ const bulge = short ? Math.max(26, len * 0.5) : (L.by === "plane" ? 0.22 : 0.12) * len + (nth ? 8 : 0);
180
+ const nx = -dy / len, ny = dx / len; // perpendicular (inverte com o sentido, então ida e volta ficam em lados opostos)
181
+ const cx = (a.x + b.x) / 2 + nx * bulge, cy = (a.y + b.y) / 2 + ny * bulge;
182
+ const pt = (u) => [(1 - u) ** 2 * a.x + 2 * (1 - u) * u * cx + u * u * b.x, (1 - u) ** 2 * a.y + 2 * (1 - u) * u * cy + u * u * b.y];
183
+ const tan = (u) => [2 * (1 - u) * (cx - a.x) + 2 * u * (b.x - cx), 2 * (1 - u) * (cy - a.y) + 2 * u * (b.y - cy)];
184
+ const d = `M${f1(a.x)} ${f1(a.y)} Q${f1(cx)} ${f1(cy)} ${f1(b.x)} ${f1(b.y)}`;
185
+ const col = L.by === "plane" ? t.primary : L.by === "train" ? t.secondary : t.accent;
186
+ let s = "";
187
+ if (L.by === "train")
188
+ s += `<path d="${d}" stroke="${col}" stroke-width="7" fill="none" stroke-linecap="round"/><path d="${d}" stroke="${t.paper}" stroke-width="2.6" fill="none" stroke-dasharray="7 6"/>`;
189
+ else if (L.by === "plane")
190
+ s += `<path d="${d}" stroke="${t.paper}" stroke-width="6.5" fill="none" stroke-linecap="round" opacity="0.8"/><path d="${d}" stroke="${col}" stroke-width="3.2" fill="none" stroke-dasharray="10 7" stroke-linecap="round"/>`;
191
+ else
192
+ s += `<path d="${d}" stroke="${col}" stroke-width="4" fill="none" stroke-linecap="round"/>`;
193
+ // seta de sentido
194
+ const [axp, ayp] = pt(0.78), [tx, ty] = tan(0.78), ang = Math.atan2(ty, tx) * 180 / Math.PI;
195
+ s += `<path d="M-6 -6 L4 0 L-6 6" transform="translate(${f1(axp)} ${f1(ayp)}) rotate(${f1(ang)})" stroke="${col}" stroke-width="3.2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>`;
196
+ legSvg.push(s);
197
+ // selo do transporte no meio do trecho
198
+ const [mx, my] = pt(0.5), [ux, uy] = tan(0.5), mang = Math.atan2(uy, ux) * 180 / Math.PI;
199
+ const r = Math.max(13, H * 0.019) * (short ? 0.72 : 1);
200
+ // em trechos curtos o selo vai para fora da curva, longe dos pinos
201
+ const bx = short ? mx + nx * r * 1.6 : mx, by2 = short ? my + ny * r * 1.6 : my;
202
+ badges.push({ x: bx, y: by2, r, by: L.by, col, ang: mang, idx });
203
+ occupied.push({ x0: bx - r, x1: bx + r, y0: by2 - r, y1: by2 + r, kind: "badge" });
204
+ for (let u = 0.08; u < 0.95; u += 0.06) {
205
+ const [qx, qy] = pt(u);
206
+ occupied.push({ x0: qx - 4, x1: qx + 4, y0: qy - 4, y1: qy + 4, kind: "line" });
207
+ }
208
+ });
209
+ // ---------- pinos ----------
210
+ const groups = [];
211
+ for (const [n, s] of stops.entries()) {
212
+ const g = groups.find((gg) => Math.hypot(gg.x - s.x, gg.y - s.y) < 2);
213
+ if (g)
214
+ g.nums.push(n + 1);
215
+ else
216
+ groups.push({ ...s, nums: [n + 1] });
217
+ }
218
+ const pinR = Math.max(11, H * 0.016);
219
+ // números extras de uma mesma cidade vão para o lado com mais espaço
220
+ for (const g of groups) {
221
+ const right = groups.some((o) => o !== g && o.x > g.x && o.x - g.x < pinR * 6 && Math.abs(o.y - g.y) < pinR * 3);
222
+ g.dir = right ? -1 : 1;
223
+ }
224
+ for (const g of groups) {
225
+ const ext = (g.nums.length - 1) * pinR * 1.6;
226
+ occupied.push({ x0: g.x - pinR - (g.dir < 0 ? ext : 0), x1: g.x + pinR + (g.dir > 0 ? ext : 0), y0: g.y - pinR, y1: g.y + pinR, kind: "pin" });
227
+ }
228
+ // rótulos das cidades: escolhe a posição com menos sobreposição
229
+ const cityLabels = [];
230
+ const fsCity = Math.max(14, H * 0.021);
231
+ for (const g of groups) {
232
+ const name = g.city, sub = g.country ? g.country.pt : "";
233
+ const w = Math.max(name.length * fsCity * 0.6, sub.length * fsCity * 0.45) + fsCity * 1.2, h = fsCity * (sub ? 2.35 : 1.6);
234
+ const ext = (g.nums.length - 1) * pinR * 1.6, offR = pinR + (g.dir > 0 ? ext : 0) + 8, offL = pinR + (g.dir < 0 ? ext : 0) + 8;
235
+ const offX = offR;
236
+ const cands = [[g.x + offR, g.y - h / 2], [g.x - offL - w, g.y - h / 2], [g.x - w / 2, g.y - pinR - 10 - h], [g.x - w / 2, g.y + pinR + 10],
237
+ [g.x + offX, g.y - h - 6], [g.x - pinR - 8 - w, g.y - h - 6], [g.x + offX, g.y + 6], [g.x - pinR - 8 - w, g.y + 6]];
238
+ let best = null, bs = Infinity;
239
+ for (const [x0, y0] of cands) {
240
+ const b = { x0, y0, x1: x0 + w, y1: y0 + h };
241
+ let sc = inArea(b) ? 0 : 1e7;
242
+ for (const o of occupied)
243
+ sc += ov(b, o) * (o.kind === "city" ? 6 : o.kind === "pin" ? 5 : o.kind === "badge" ? 4 : o.kind === "line" ? 3 : o.visited ? 1.5 : 0.6);
244
+ if (sc < bs) {
245
+ bs = sc;
246
+ best = b;
247
+ }
248
+ }
249
+ if (bs > 0.12 * w * h)
250
+ warnings.push(`rótulo da cidade '${name}' com sobreposição (${Math.round(bs / (w * h) * 100)}%); ajuste 'padding' do mapa ou use 'label_side'`);
251
+ best.kind = "city";
252
+ best.name = name;
253
+ best.sub = sub;
254
+ best.g = g;
255
+ occupied.push(best);
256
+ cityLabels.push(best);
257
+ }
258
+ // rótulos de países que não colidem com elementos da rota
259
+ for (const b of occupied.filter((o) => o.kind === "country")) {
260
+ const hit = occupied.some((o) => o !== b && o.kind !== "country" && o.kind !== "line" && ov(b, o) > 0.02 * (b.x1 - b.x0) * (b.y1 - b.y0));
261
+ if (hit && (!b.visited || b.cc.area < 0.002))
262
+ continue;
263
+ let moved = !hit;
264
+ let { lx, ly } = b;
265
+ if (hit) { // tenta deslocar o nome do país visitado
266
+ for (const [ddx, ddy] of [[0, 30], [0, -30], [40, 0], [-40, 0], [0, 55], [0, -55]]) {
267
+ const nb = { x0: b.x0 + ddx, x1: b.x1 + ddx, y0: b.y0 + ddy, y1: b.y1 + ddy };
268
+ if (!occupied.some((o) => o !== b && o.kind !== "country" && o.kind !== "line" && ov(nb, o) > 0)) {
269
+ lx += ddx;
270
+ ly += ddy;
271
+ moved = true;
272
+ break;
273
+ }
274
+ }
275
+ }
276
+ if (!moved)
277
+ continue;
278
+ countryLabels += b.visited
279
+ ? `<text x="${f1(lx)}" y="${f1(ly)}" font-family="${FONT}" font-weight="700" font-size="${f1(b.fs)}" letter-spacing="2" fill="${sh(colorOf.get(b.cc), -0.55)}" text-anchor="middle" opacity="0.8">${esc(b.txt)}</text>`
280
+ : `<text x="${f1(lx)}" y="${f1(ly)}" font-family="${FONT}" font-weight="500" font-size="${f1(b.fs)}" fill="${sh(land, -0.4)}" text-anchor="middle">${esc(b.txt)}</text>`;
281
+ }
282
+ // ---------- desenho de selos, pinos e rótulos ----------
283
+ const badgeSvg = badges.map((bd) => {
284
+ const rot = bd.by === "plane" ? ` rotate(${f1(bd.ang)})` : "";
285
+ const s = bd.r / 14;
286
+ return `<circle cx="${f1(bd.x)}" cy="${f1(bd.y + 2)}" r="${f1(bd.r)}" fill="${t.ink}" opacity="0.18"/><circle cx="${f1(bd.x)}" cy="${f1(bd.y)}" r="${f1(bd.r)}" fill="${t.paper}" stroke="${bd.col}" stroke-width="2.5"/>` +
287
+ `<g transform="translate(${f1(bd.x)} ${f1(bd.y)})${rot} scale(${s.toFixed(3)})">${ICON[bd.by] ? ICON[bd.by](bd.col, t.paper) : ""}</g>`;
288
+ }).join("");
289
+ const pinSvg = groups.map((g) => g.nums.map((n, j) => {
290
+ const x = g.x + g.dir * j * pinR * 1.6, last = n === stops.length, first = n === 1;
291
+ const col = last ? t.accent : first ? t.secondary : t.primary;
292
+ return `<circle cx="${f1(x)}" cy="${f1(g.y + 2.5)}" r="${f1(pinR)}" fill="${t.ink}" opacity="0.2"/><circle cx="${f1(x)}" cy="${f1(g.y)}" r="${f1(pinR)}" fill="${col}" stroke="${t.paper}" stroke-width="2.5"/>` +
293
+ `<text x="${f1(x)}" y="${f1(g.y + pinR * 0.4)}" font-family="${FONT}" font-weight="700" font-size="${f1(pinR * 1.15)}" fill="${t.paper}" text-anchor="middle">${n}</text>`;
294
+ }).join("")).join("");
295
+ const cityLabelSvg = cityLabels.map((b) => `<rect x="${f1(b.x0 + 1.5)}" y="${f1(b.y0 + 2.5)}" width="${f1(b.x1 - b.x0)}" height="${f1(b.y1 - b.y0)}" rx="8" fill="${t.ink}" opacity="0.14"/>` +
296
+ `<rect x="${f1(b.x0)}" y="${f1(b.y0)}" width="${f1(b.x1 - b.x0)}" height="${f1(b.y1 - b.y0)}" rx="8" fill="${t.paper}"/>` +
297
+ `<text x="${f1(b.x0 + fsCity * 0.6)}" y="${f1(b.y0 + fsCity * 1.15)}" font-family="${FONT}" font-weight="700" font-size="${f1(fsCity)}" fill="${t.text === t.paper ? t.ink : t.text}">${esc(b.name)}</text>` +
298
+ (b.sub ? `<text x="${f1(b.x0 + fsCity * 0.6)}" y="${f1(b.y0 + fsCity * 1.95)}" font-family="${FONT}" font-weight="500" font-size="${f1(fsCity * 0.68)}" fill="${sh(t.ink, 0.35)}">${esc(b.sub)}</text>` : "")).join("");
299
+ // ---------- painel do roteiro ----------
300
+ let panel = "";
301
+ if (panelOn) {
302
+ const px = W - PW - PAD * 0.6, py = PAD, ph = H - PAD * 2;
303
+ panel += `<rect x="${f1(px + 3)}" y="${f1(py + 5)}" width="${PW}" height="${f1(ph)}" rx="18" fill="${t.ink}" opacity="0.15"/><rect x="${f1(px)}" y="${f1(py)}" width="${PW}" height="${f1(ph)}" rx="18" fill="${t.paper}"/>`;
304
+ const title = (scene.text || []).find((x) => (x.role || "title") === "title")?.content || "Roteiro";
305
+ const subtitle = (scene.text || []).find((x) => x.role === "subtitle")?.content;
306
+ const tfs = H * 0.034;
307
+ const words = title.split(" ");
308
+ const lines = [];
309
+ let cur = "";
310
+ for (const wd of words) {
311
+ if ((cur + " " + wd).trim().length * tfs * 0.58 > PW - 44) {
312
+ lines.push(cur.trim());
313
+ cur = wd;
314
+ }
315
+ else
316
+ cur += " " + wd;
317
+ }
318
+ lines.push(cur.trim());
319
+ let yy = py + 28 + tfs;
320
+ for (const ln of lines) {
321
+ panel += `<text x="${f1(px + 24)}" y="${f1(yy)}" font-family="${FONT}" font-weight="700" font-size="${f1(tfs)}" fill="${t.text === t.paper ? t.ink : t.text}">${esc(ln)}</text>`;
322
+ yy += tfs * 1.15;
323
+ }
324
+ if (subtitle) {
325
+ panel += `<text x="${f1(px + 24)}" y="${f1(yy + 2)}" font-family="${FONT}" font-weight="500" font-size="${f1(tfs * 0.5)}" fill="${sh(t.ink, 0.4)}">${esc(subtitle)}</text>`;
326
+ yy += tfs * 0.9;
327
+ }
328
+ yy += 16;
329
+ const stepH = Math.min(H * 0.072, (py + ph - yy - 70) / Math.max(1, stops.length));
330
+ const rr = Math.min(pinR, stepH * 0.3);
331
+ stops.forEach((s, n) => {
332
+ const cy = yy + n * stepH + rr, last = n === stops.length - 1, first = n === 0;
333
+ const col = last ? t.accent : first ? t.secondary : t.primary;
334
+ if (n < legs.length) {
335
+ const L = legs[n], lc = L.by === "plane" ? t.primary : L.by === "train" ? t.secondary : t.accent;
336
+ panel += `<path d="M${f1(px + 24 + rr)} ${f1(cy + rr)} L${f1(px + 24 + rr)} ${f1(cy + stepH - rr)}" stroke="${lc}" stroke-width="3" ${L.by === "plane" ? "stroke-dasharray=\"5 4\"" : ""}/>`;
337
+ panel += `<g transform="translate(${f1(px + 24 + rr * 2 + 22)} ${f1(cy + stepH / 2)}) scale(${(rr / 15).toFixed(3)})">${ICON[L.by] ? ICON[L.by](lc, t.paper) : ""}</g>` +
338
+ `<text x="${f1(px + 24 + rr * 2 + 38)}" y="${f1(cy + stepH / 2 + 4)}" font-family="${FONT}" font-size="${f1(rr * 0.85)}" fill="${sh(t.ink, 0.4)}">${TRANSPORT_PT[L.by] || L.by}</text>`;
339
+ }
340
+ panel += `<circle cx="${f1(px + 24 + rr)}" cy="${f1(cy)}" r="${f1(rr)}" fill="${col}"/><text x="${f1(px + 24 + rr)}" y="${f1(cy + rr * 0.4)}" font-family="${FONT}" font-weight="700" font-size="${f1(rr * 1.1)}" fill="${t.paper}" text-anchor="middle">${n + 1}</text>` +
341
+ `<text x="${f1(px + 24 + rr * 2 + 12)}" y="${f1(cy + rr * 0.42)}" font-family="${FONT}" font-weight="600" font-size="${f1(rr * 1.15)}" fill="${t.text === t.paper ? t.ink : t.text}">${esc(s.city)}${s.country ? `<tspan dx="${f1(rr * 0.6)}" font-weight="400" fill="${sh(t.ink, 0.4)}">${esc(s.country.pt)}</tspan>` : ""}</text>`;
342
+ });
343
+ // legenda
344
+ const usedBy = [...new Set(legs.map((l) => l.by))];
345
+ let lx = px + 24;
346
+ const ly = py + ph - 26;
347
+ panel += `<path d="M${f1(px + 20)} ${f1(ly - 26)} L${f1(px + PW - 20)} ${f1(ly - 26)}" stroke="${sh(t.paper, -0.12)}" stroke-width="1.5"/>`;
348
+ for (const by of usedBy) {
349
+ const lc = by === "plane" ? t.primary : by === "train" ? t.secondary : t.accent;
350
+ panel += (by === "train"
351
+ ? `<path d="M${f1(lx)} ${f1(ly - 5)} L${f1(lx + 30)} ${f1(ly - 5)}" stroke="${lc}" stroke-width="6"/><path d="M${f1(lx)} ${f1(ly - 5)} L${f1(lx + 30)} ${f1(ly - 5)}" stroke="${t.paper}" stroke-width="2" stroke-dasharray="5 4"/>`
352
+ : `<path d="M${f1(lx)} ${f1(ly - 5)} L${f1(lx + 30)} ${f1(ly - 5)}" stroke="${lc}" stroke-width="3" stroke-dasharray="7 5"/>`) +
353
+ `<text x="${f1(lx + 38)}" y="${f1(ly)}" font-family="${FONT}" font-size="${f1(H * 0.016)}" fill="${sh(t.ink, 0.3)}">${TRANSPORT_PT[by] || by}</text>`;
354
+ lx += 38 + (TRANSPORT_PT[by] || by).length * H * 0.011 + 26;
355
+ }
356
+ }
357
+ const source = `<text x="${f1(area.x0 + 4)}" y="${f1(H - 8)}" font-family="${FONT}" font-size="10" fill="${sh(sea, -0.45)}">Contornos: Natural Earth (domínio público)</text>`;
358
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}">\n${mapSvg}\n${countryLabels}\n${legSvg.join("\n")}\n${badgeSvg}\n${pinSvg}\n${cityLabelSvg}\n${panel}\n${source}\n</svg>`;
359
+ const description = [
360
+ ...stops.map((s, n) => `${n + 1}. ${s.city}${s.country ? " (" + s.country.pt + ")" : ""}: tela (${Math.round(s.x / W * 100)}%, ${Math.round(s.y / H * 100)}%)`),
361
+ ...legs.map((l) => `${l.a.city} → ${l.b.city}: ${TRANSPORT_PT[l.by] || l.by}`),
362
+ `países destacados: ${visited.map((v) => v.pt).join(", ")}`,
363
+ ].join("\n");
364
+ return { svg, warnings: [...new Set(warnings)], description };
365
+ }
@@ -0,0 +1,5 @@
1
+ export declare function compilePlane(scene: any, { LIB, theme: t, warnings, W, H, resolveAsset, contrast }: any): {
2
+ svg: string;
3
+ warnings: unknown[];
4
+ description: string;
5
+ };