primocode 7.18.0 → 8.0.1
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/bin/primocode.js +0 -0
- package/lib/act.js +13 -3
- package/lib/catalogo.js +12 -0
- package/lib/desktop.js +3 -1
- package/lib/referencia.js +8 -4
- package/lib/studio.js +198 -0
- package/lib/tools.js +24 -22
- package/lib/ui.js +3 -1
- package/package.json +2 -1
- package/studio/PRIMOCODE.md +58 -0
- package/studio/README.md +154 -0
- package/studio/ferramentas/00-protocolo.md +111 -0
- package/studio/ferramentas/01-modelos.md +202 -0
- package/studio/ferramentas/README.md +32 -0
- package/studio/ferramentas/corte.md +193 -0
- package/studio/ferramentas/grade.md +92 -0
- package/studio/ferramentas/prisma.md +99 -0
- package/studio/ferramentas/prosa.md +86 -0
- package/studio/ferramentas/tela.md +72 -0
- package/studio/ferramentas/traco.md +79 -0
- package/studio/server.py +862 -0
- package/studio/web/core.css +723 -0
- package/studio/web/home.html +149 -0
- package/studio/web/js/audio.js +262 -0
- package/studio/web/js/editor.js +1270 -0
- package/studio/web/js/exportar.js +135 -0
- package/studio/web/js/ferramentas.js +105 -0
- package/studio/web/js/icones.js +91 -0
- package/studio/web/js/midia.js +157 -0
- package/studio/web/js/narracao.js +254 -0
- package/studio/web/js/player.js +504 -0
- package/studio/web/js/render-grade.js +243 -0
- package/studio/web/js/render-prosa.js +104 -0
- package/studio/web/js/render.js +622 -0
- package/studio/web/render.css +565 -0
- package/studio/web/tool.html +70 -0
- package/studio/web/view.html +20 -0
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
/* ==========================================================================
|
|
2
|
+
render.js — desenha uma CENA (Prisma, Tela, Corte, Traço).
|
|
3
|
+
Uma cena é uma tela de largura x altura com elementos dentro.
|
|
4
|
+
Dois modos: layout nomeado (o estúdio posiciona) ou "livre" (x/y/l/a).
|
|
5
|
+
========================================================================== */
|
|
6
|
+
|
|
7
|
+
var PAPEIS = {
|
|
8
|
+
chapeu: { classe: "chapeu" },
|
|
9
|
+
titulo: { tamanho: 84, peso: 660, altura: 1.06 },
|
|
10
|
+
subtitulo: { tamanho: 46, peso: 620, altura: 1.14 },
|
|
11
|
+
apoio: { tamanho: 30, peso: 400, altura: 1.45, cor: "var(--c-fraco)" },
|
|
12
|
+
corpo: { tamanho: 25, peso: 400, altura: 1.5, classe: "corpo" },
|
|
13
|
+
legenda: { tamanho: 18, peso: 400, altura: 1.45, cor: "var(--c-fraco)", classe: "corpo" },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
var LAYOUTS = ["capa", "titulo", "secao", "duas-colunas", "tres-colunas",
|
|
17
|
+
"citacao", "numeros", "imagem-direita", "imagem-esquerda",
|
|
18
|
+
"centro", "livre"];
|
|
19
|
+
|
|
20
|
+
function _fugir(s) {
|
|
21
|
+
return String(s == null ? "" : s)
|
|
22
|
+
.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function _rico(s) {
|
|
26
|
+
return _fugir(s)
|
|
27
|
+
.replace(/\*\*([^*]+)\*\*/g, "<b>$1</b>")
|
|
28
|
+
.replace(/(^|[^*])\*([^*\n]+)\*/g, "$1<i>$2</i>")
|
|
29
|
+
.replace(/`([^`]+)`/g, "<code>$1</code>");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _px(v) { return (typeof v === "number" ? v + "px" : v); }
|
|
33
|
+
|
|
34
|
+
/* Envolve cada palavra em um span, sem tocar nas tags que já existem. */
|
|
35
|
+
function _porPalavra(html) {
|
|
36
|
+
var p = 0;
|
|
37
|
+
return html.split(/(<[^>]*>)/).map(function (parte) {
|
|
38
|
+
if (parte.charAt(0) === "<") return parte; // tag: passa direto
|
|
39
|
+
return parte.replace(/(\S+)/g, function (w) {
|
|
40
|
+
return '<span class="pal" style="--p:' + (p++) + '">' + w + "</span>";
|
|
41
|
+
});
|
|
42
|
+
}).join("");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* ------------------------------------------------------------------ fundo */
|
|
46
|
+
|
|
47
|
+
function aplicarFundo(no, fundo) {
|
|
48
|
+
if (!fundo) return;
|
|
49
|
+
if (typeof fundo === "string") {
|
|
50
|
+
if (/^(malha|brilho|grade|pontos|suave|vinheta)$/.test(fundo)) no.setAttribute("data-fundo", fundo);
|
|
51
|
+
else no.style.background = fundo;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (fundo.tipo === "gradiente") {
|
|
55
|
+
no.style.background = "linear-gradient(" + (fundo.angulo != null ? fundo.angulo : 160) + "deg, " +
|
|
56
|
+
(fundo.de || "#111") + ", " + (fundo.para || "#333") + ")";
|
|
57
|
+
} else if (fundo.imagem) {
|
|
58
|
+
no.style.backgroundImage = "url('" + fundo.imagem + "')";
|
|
59
|
+
no.style.backgroundSize = "cover";
|
|
60
|
+
no.style.backgroundPosition = fundo.posicao || "center";
|
|
61
|
+
if (fundo.escurecer) {
|
|
62
|
+
var v = document.createElement("div");
|
|
63
|
+
v.className = "cobertura";
|
|
64
|
+
v.style.background = "rgba(4,6,10," + fundo.escurecer + ")";
|
|
65
|
+
no.appendChild(v);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* --------------------------------------------------------------- gráficos */
|
|
71
|
+
|
|
72
|
+
function svgGrafico(e, l, a) {
|
|
73
|
+
var dados = (e.dados || []).map(function (d) {
|
|
74
|
+
return Array.isArray(d) ? { r: d[0], v: +d[1] || 0 } : { r: d.rotulo, v: +d.valor || 0 };
|
|
75
|
+
});
|
|
76
|
+
if (!dados.length) return "";
|
|
77
|
+
var cores = e.cores || ["var(--c-tom)", "var(--c-tom2)", "#7c9cff", "#2fbf7f", "#f472b6", "#facc15"];
|
|
78
|
+
var max = Math.max.apply(null, dados.map(function (d) { return d.v; })) || 1;
|
|
79
|
+
var tipo = e.grafico || "barras";
|
|
80
|
+
var pad = { e: 8, d: 8, t: 14, b: 42 };
|
|
81
|
+
var iw = l - pad.e - pad.d, ih = a - pad.t - pad.b;
|
|
82
|
+
var p = ['<svg viewBox="0 0 ' + l + " " + a + '" width="' + l + '" height="' + a + '">'];
|
|
83
|
+
|
|
84
|
+
if (tipo === "pizza" || tipo === "rosca") {
|
|
85
|
+
var total = dados.reduce(function (s, d) { return s + d.v; }, 0) || 1;
|
|
86
|
+
var cx = l / 2, cy = a / 2 - 8, r = Math.min(l, a) / 2 - 34, ang = -Math.PI / 2;
|
|
87
|
+
dados.forEach(function (d, i) {
|
|
88
|
+
var fim = ang + (d.v / total) * Math.PI * 2;
|
|
89
|
+
var x1 = cx + r * Math.cos(ang), y1 = cy + r * Math.sin(ang);
|
|
90
|
+
var x2 = cx + r * Math.cos(fim), y2 = cy + r * Math.sin(fim);
|
|
91
|
+
p.push('<path d="M' + cx + " " + cy + " L" + x1 + " " + y1 +
|
|
92
|
+
" A" + r + " " + r + " 0 " + (fim - ang > Math.PI ? 1 : 0) + " 1 " + x2 + " " + y2 +
|
|
93
|
+
' Z" fill="' + cores[i % cores.length] + '"/>');
|
|
94
|
+
ang = fim;
|
|
95
|
+
});
|
|
96
|
+
if (tipo === "rosca") p.push('<circle cx="' + cx + '" cy="' + cy + '" r="' + (r * 0.58) + '" fill="var(--c-fundo)"/>');
|
|
97
|
+
} else if (tipo === "linha" || tipo === "area") {
|
|
98
|
+
var passo = dados.length > 1 ? iw / (dados.length - 1) : 0;
|
|
99
|
+
var pts = dados.map(function (d, i) {
|
|
100
|
+
return [pad.e + i * passo, pad.t + ih - (d.v / max) * ih];
|
|
101
|
+
});
|
|
102
|
+
var caminho = pts.map(function (q, i) { return (i ? "L" : "M") + q[0] + " " + q[1]; }).join(" ");
|
|
103
|
+
if (tipo === "area") {
|
|
104
|
+
p.push('<path d="' + caminho + " L" + pts[pts.length - 1][0] + " " + (pad.t + ih) +
|
|
105
|
+
" L" + pts[0][0] + " " + (pad.t + ih) + ' Z" fill="' + cores[0] + '" opacity=".18"/>');
|
|
106
|
+
}
|
|
107
|
+
p.push('<path d="' + caminho + '" fill="none" stroke="' + cores[0] + '" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>');
|
|
108
|
+
pts.forEach(function (q) { p.push('<circle cx="' + q[0] + '" cy="' + q[1] + '" r="6" fill="' + cores[0] + '"/>'); });
|
|
109
|
+
} else {
|
|
110
|
+
var larg = iw / dados.length;
|
|
111
|
+
var barra = Math.min(larg * 0.68, 130); // barra larga demais vira bloco
|
|
112
|
+
dados.forEach(function (d, i) {
|
|
113
|
+
var h = (d.v / max) * ih;
|
|
114
|
+
var x = pad.e + i * larg + (larg - barra) / 2;
|
|
115
|
+
p.push('<rect x="' + x + '" y="' + (pad.t + ih - h) + '" width="' + barra +
|
|
116
|
+
'" height="' + Math.max(h, 2) + '" rx="7" fill="' + cores[i % cores.length] + '"/>');
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (tipo !== "pizza" && tipo !== "rosca") {
|
|
121
|
+
var larg2 = iw / dados.length;
|
|
122
|
+
dados.forEach(function (d, i) {
|
|
123
|
+
p.push('<text x="' + (pad.e + i * larg2 + larg2 / 2) + '" y="' + (a - 16) +
|
|
124
|
+
'" text-anchor="middle" fill="var(--c-fraco)" font-size="17" font-family="inherit">' +
|
|
125
|
+
_fugir(d.r) + "</text>");
|
|
126
|
+
});
|
|
127
|
+
} else {
|
|
128
|
+
dados.forEach(function (d, i) {
|
|
129
|
+
p.push('<rect x="' + (16 + i * 132) + '" y="' + (a - 26) + '" width="12" height="12" rx="3" fill="' + cores[i % cores.length] + '"/>');
|
|
130
|
+
p.push('<text x="' + (34 + i * 132) + '" y="' + (a - 15) +
|
|
131
|
+
'" fill="var(--c-fraco)" font-size="16" font-family="inherit">' + _fugir(d.r) + "</text>");
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
p.push("</svg>");
|
|
135
|
+
return p.join("");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* -------------------------------------------------------------- elementos */
|
|
139
|
+
|
|
140
|
+
function renderElemento(e, ctx) {
|
|
141
|
+
var no = document.createElement("div");
|
|
142
|
+
var tipo = e.tipo || "texto";
|
|
143
|
+
no.className = "el " + tipo;
|
|
144
|
+
no.dataset.tipo = tipo;
|
|
145
|
+
|
|
146
|
+
/* posição — absoluta só quando o elemento traz coordenadas */
|
|
147
|
+
var absoluto = e.x != null || e.y != null;
|
|
148
|
+
if (absoluto) {
|
|
149
|
+
no.style.position = "absolute";
|
|
150
|
+
no.style.left = _px(e.x || 0);
|
|
151
|
+
no.style.top = _px(e.y || 0);
|
|
152
|
+
if (e.l != null) no.style.width = _px(e.l);
|
|
153
|
+
if (e.a != null) {
|
|
154
|
+
// em texto a altura é piso, não gaiola: assim nada é cortado nem colide
|
|
155
|
+
var elastico = tipo === "texto" || tipo === "lista" || tipo === "citacao" || tipo === "cartoes";
|
|
156
|
+
no.style[elastico ? "minHeight" : "height"] = _px(e.a);
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
no.style.position = "relative";
|
|
160
|
+
}
|
|
161
|
+
if (e.rotacao) no.style.transform = "rotate(" + e.rotacao + "deg)";
|
|
162
|
+
if (e.opacidade != null) no.style.opacity = e.opacidade;
|
|
163
|
+
if (e.sombra) no.style.boxShadow = e.sombra === true ? "0 30px 70px -25px rgba(0,0,0,.6)" : e.sombra;
|
|
164
|
+
if (e.z != null) no.style.zIndex = e.z;
|
|
165
|
+
|
|
166
|
+
/* animação */
|
|
167
|
+
var an = e.anim || ctx.animPadrao;
|
|
168
|
+
if (an && an !== "nenhuma") {
|
|
169
|
+
no.setAttribute("data-an", typeof an === "string" ? an : (an.entrada || "subir"));
|
|
170
|
+
no.style.setProperty("--atraso", (typeof an === "object" && an.atraso != null ? an.atraso : ctx.i * 0.09 + 0.1));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
switch (tipo) {
|
|
174
|
+
case "texto": {
|
|
175
|
+
var papel = PAPEIS[e.papel] || PAPEIS.corpo;
|
|
176
|
+
no.classList.add("txt");
|
|
177
|
+
if (papel.classe) no.classList.add(papel.classe);
|
|
178
|
+
// tamanho explícito manda; sem ele, o padrão cresce no formato vertical
|
|
179
|
+
no.style.fontSize = _px(e.tamanho || Math.round((papel.tamanho || 25) * (ctx.escalaTipo || 1)));
|
|
180
|
+
if (e.peso || papel.peso) no.style.fontWeight = e.peso || papel.peso;
|
|
181
|
+
if (papel.altura) no.style.lineHeight = papel.altura;
|
|
182
|
+
no.style.color = e.cor || papel.cor || "";
|
|
183
|
+
if (e.alinhar) { no.style.textAlign = e.alinhar; no.style.alignItems = e.alinhar === "centro" ? "center" : (e.alinhar === "direita" ? "flex-end" : "flex-start"); }
|
|
184
|
+
if (e.fonte === "mono") no.style.fontFamily = "var(--f-mono)";
|
|
185
|
+
if (e.fonte === "display") no.style.fontFamily = "var(--f-display)";
|
|
186
|
+
if (e.maiusculas) no.style.textTransform = "uppercase";
|
|
187
|
+
if (e.espacamento != null) no.style.letterSpacing = e.espacamento + "em";
|
|
188
|
+
if (e.altura != null) no.style.lineHeight = e.altura;
|
|
189
|
+
if (e.estilo) no.setAttribute("data-estilo", e.estilo);
|
|
190
|
+
|
|
191
|
+
var corpoTexto = _rico(e.texto);
|
|
192
|
+
|
|
193
|
+
// marcador e fita precisam envolver cada linha para o fundo acompanhar
|
|
194
|
+
if (e.estilo === "marcador" || e.estilo === "fita") {
|
|
195
|
+
corpoTexto = corpoTexto.split("\n").map(function (l) {
|
|
196
|
+
return l.trim() ? '<span class="linha">' + l + "</span>" : "";
|
|
197
|
+
}).join("\n");
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// palavra a palavra: cada palavra vira um span com atraso próprio
|
|
201
|
+
var animAtual = e.anim || ctx.animPadrao;
|
|
202
|
+
if (animAtual === "palavra") corpoTexto = _porPalavra(corpoTexto);
|
|
203
|
+
|
|
204
|
+
no.innerHTML = corpoTexto;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
case "lista": {
|
|
209
|
+
if (e.numerada) no.classList.add("numerada");
|
|
210
|
+
if (e.marcador) no.setAttribute("data-marcador", e.marcador);
|
|
211
|
+
(e.itens || []).forEach(function (it, k) {
|
|
212
|
+
var d = document.createElement("div");
|
|
213
|
+
d.className = "item";
|
|
214
|
+
if (e.tamanho) d.style.fontSize = _px(e.tamanho);
|
|
215
|
+
d.innerHTML = _rico(it);
|
|
216
|
+
if (e.revelar) {
|
|
217
|
+
d.setAttribute("data-an", "subir");
|
|
218
|
+
d.style.setProperty("--atraso", (e.atrasoBase != null ? e.atrasoBase : 0.2) + k * (e.intervalo || 0.14));
|
|
219
|
+
}
|
|
220
|
+
no.appendChild(d);
|
|
221
|
+
});
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
case "cartoes": {
|
|
226
|
+
var n = (e.itens || []).length;
|
|
227
|
+
no.style.gridTemplateColumns = "repeat(" + Math.min(n || 1, e.colunas || (n > 4 ? 3 : n)) + ", 1fr)";
|
|
228
|
+
(e.itens || []).forEach(function (it) {
|
|
229
|
+
var c = document.createElement("div");
|
|
230
|
+
c.className = "cartao";
|
|
231
|
+
var t = typeof it === "string" ? it.split("|") : [it.titulo, it.texto];
|
|
232
|
+
c.innerHTML = "<b>" + _rico((t[0] || "").trim()) + "</b>" +
|
|
233
|
+
(t[1] ? "<span>" + _rico(String(t[1]).trim()) + "</span>" : "");
|
|
234
|
+
no.appendChild(c);
|
|
235
|
+
});
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
case "numeros": {
|
|
240
|
+
var m = (e.itens || []).length;
|
|
241
|
+
no.style.gridTemplateColumns = "repeat(" + Math.min(m || 1, e.colunas || m) + ", 1fr)";
|
|
242
|
+
if (e.tamanho) no.style.setProperty("--tam-num", _px(e.tamanho));
|
|
243
|
+
(e.itens || []).forEach(function (it) {
|
|
244
|
+
var c = document.createElement("div");
|
|
245
|
+
c.className = "num";
|
|
246
|
+
var t = typeof it === "string" ? it.split("|") : [it.valor, it.rotulo];
|
|
247
|
+
var valor = (t[0] || "").toString().trim();
|
|
248
|
+
var b = document.createElement("b");
|
|
249
|
+
b.textContent = valor;
|
|
250
|
+
// conta do zero até o número quando a cena entra (o player dispara)
|
|
251
|
+
if (e.contar) {
|
|
252
|
+
var alvo = parseFloat(valor.replace(/[^\d,.-]/g, "").replace(",", "."));
|
|
253
|
+
if (!isNaN(alvo)) {
|
|
254
|
+
b.setAttribute("data-contar", alvo);
|
|
255
|
+
b.setAttribute("data-molde", valor);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
c.appendChild(b);
|
|
259
|
+
var s = document.createElement("span");
|
|
260
|
+
s.textContent = (t[1] || "").toString().trim();
|
|
261
|
+
c.appendChild(s);
|
|
262
|
+
no.appendChild(c);
|
|
263
|
+
});
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
case "tabela": {
|
|
268
|
+
var linhas = e.linhas || [];
|
|
269
|
+
var h = "<table>";
|
|
270
|
+
linhas.forEach(function (l, i) {
|
|
271
|
+
h += "<tr>";
|
|
272
|
+
l.forEach(function (c) { h += i === 0 ? "<th>" + _fugir(c) + "</th>" : "<td>" + _rico(c) + "</td>"; });
|
|
273
|
+
h += "</tr>";
|
|
274
|
+
});
|
|
275
|
+
no.innerHTML = h + "</table>";
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
case "codigo":
|
|
280
|
+
no.textContent = e.texto || "";
|
|
281
|
+
if (e.tamanho) no.style.fontSize = _px(e.tamanho);
|
|
282
|
+
break;
|
|
283
|
+
|
|
284
|
+
case "citacao":
|
|
285
|
+
no.innerHTML = '<div class="aspas">“' + _rico(e.texto) + '”</div>' +
|
|
286
|
+
(e.autor ? '<div class="autor">' + _fugir(e.autor) + "</div>" : "");
|
|
287
|
+
break;
|
|
288
|
+
|
|
289
|
+
case "forma": {
|
|
290
|
+
var f = e.forma || "retangulo";
|
|
291
|
+
no.style.background = e.preenchimento || "var(--c-tom)";
|
|
292
|
+
if (e.borda) no.style.border = (e.borda.largura || 2) + "px solid " + (e.borda.cor || "var(--c-linha)");
|
|
293
|
+
if (f === "circulo") no.style.borderRadius = "999px";
|
|
294
|
+
else no.style.borderRadius = _px(e.raio != null ? e.raio : 0);
|
|
295
|
+
if (f === "triangulo") { no.style.clipPath = "polygon(50% 0,100% 100%,0 100%)"; }
|
|
296
|
+
if (f === "linha") { no.style.height = _px(e.espessura || 3); no.style.borderRadius = "999px"; }
|
|
297
|
+
if (f === "seta") {
|
|
298
|
+
no.style.background = "none";
|
|
299
|
+
no.innerHTML = '<svg viewBox="0 0 100 24" preserveAspectRatio="none" style="width:100%;height:100%">' +
|
|
300
|
+
'<path d="M0 12h88M78 4l10 8-10 8" fill="none" stroke="' + (e.preenchimento || "var(--c-tom)") +
|
|
301
|
+
'" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" vector-effect="non-scaling-stroke"/></svg>';
|
|
302
|
+
}
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
case "imagem": {
|
|
307
|
+
var img = document.createElement("img");
|
|
308
|
+
img.src = e.src || "";
|
|
309
|
+
img.alt = e.alt || "";
|
|
310
|
+
img.style.objectFit = e.ajuste === "conter" ? "contain" : "cover";
|
|
311
|
+
if (e.posicao) img.style.objectPosition = e.posicao;
|
|
312
|
+
if (e.filtro) img.style.filter = e.filtro === "cinza" ? "grayscale(1)"
|
|
313
|
+
: e.filtro === "sepia" ? "sepia(.7)"
|
|
314
|
+
: e.filtro === "contraste" ? "contrast(1.35) saturate(1.15)"
|
|
315
|
+
: e.filtro === "desbotado" ? "saturate(.55) brightness(1.08)"
|
|
316
|
+
: e.filtro;
|
|
317
|
+
no.style.borderRadius = _px(e.raio != null ? e.raio : 18);
|
|
318
|
+
if (e.borda) no.style.border = (e.borda.largura || 2) + "px solid " + (e.borda.cor || "var(--c-linha)");
|
|
319
|
+
if (e.movimento) {
|
|
320
|
+
no.setAttribute("data-mov", e.movimento);
|
|
321
|
+
if (e.duracaoMov) img.style.animationDuration = e.duracaoMov + "s";
|
|
322
|
+
}
|
|
323
|
+
no.appendChild(img);
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
case "icone": {
|
|
328
|
+
var t = e.tamanho || 90;
|
|
329
|
+
no.style.width = _px(e.l || t);
|
|
330
|
+
no.style.height = _px(e.a || t);
|
|
331
|
+
no.style.color = e.cor || "var(--c-tom)";
|
|
332
|
+
no.innerHTML = svgIcone(e.nome || "estrela");
|
|
333
|
+
var s = no.querySelector("svg");
|
|
334
|
+
if (s) s.setAttribute("stroke-width", e.traco || 1.5);
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
case "grafico": {
|
|
339
|
+
var gl = e.l || 900, ga = e.a || 480;
|
|
340
|
+
if (!absoluto) { no.style.width = _px(gl); no.style.height = _px(ga); }
|
|
341
|
+
no.innerHTML = svgGrafico(e, gl, ga);
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
case "no": {
|
|
346
|
+
if (e.destaque) no.classList.add("destaque");
|
|
347
|
+
if (e.formato === "circulo") no.classList.add("circulo");
|
|
348
|
+
if (e.cor) no.style.background = e.cor;
|
|
349
|
+
if (e.corTexto) no.style.color = e.corTexto;
|
|
350
|
+
if (e.tamanho) no.style.fontSize = _px(e.tamanho);
|
|
351
|
+
no.innerHTML = _rico(e.texto);
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
default:
|
|
356
|
+
no.innerHTML = _rico(e.texto || "");
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return no;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/* ------------------------------------------------------- posição automática */
|
|
363
|
+
|
|
364
|
+
/* Dá x/y aos nós a partir dos conectores. O autor manda só o grafo. */
|
|
365
|
+
function posicionarAuto(elementos, W, H, modo) {
|
|
366
|
+
var nos = elementos.filter(function (e) { return e.id && e.tipo !== "conector"; });
|
|
367
|
+
if (!nos.length) return;
|
|
368
|
+
|
|
369
|
+
var links = elementos.filter(function (e) { return e.tipo === "conector" && e.de && e.para; });
|
|
370
|
+
var porId = {};
|
|
371
|
+
nos.forEach(function (n) { porId[n.id] = n; });
|
|
372
|
+
|
|
373
|
+
var entra = {}, sai = {};
|
|
374
|
+
nos.forEach(function (n) { entra[n.id] = []; sai[n.id] = []; });
|
|
375
|
+
links.forEach(function (c) {
|
|
376
|
+
if (!porId[c.de] || !porId[c.para]) return;
|
|
377
|
+
sai[c.de].push(c.para);
|
|
378
|
+
entra[c.para].push(c.de);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
/* nível = maior distância desde uma raiz, para a seta nunca voltar */
|
|
382
|
+
var nivel = {}, visto = {};
|
|
383
|
+
var fila = nos.filter(function (n) { return !entra[n.id].length; }).map(function (n) { return n.id; });
|
|
384
|
+
if (!fila.length) fila = [nos[0].id];
|
|
385
|
+
fila.forEach(function (id) { nivel[id] = 0; });
|
|
386
|
+
|
|
387
|
+
var guarda = 0;
|
|
388
|
+
while (fila.length && guarda++ < 4000) {
|
|
389
|
+
var id = fila.shift();
|
|
390
|
+
(sai[id] || []).forEach(function (destino) {
|
|
391
|
+
var novo = nivel[id] + 1;
|
|
392
|
+
if (nivel[destino] == null || novo > nivel[destino]) {
|
|
393
|
+
nivel[destino] = novo;
|
|
394
|
+
fila.push(destino);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
nos.forEach(function (n) { if (nivel[n.id] == null) nivel[n.id] = 0; });
|
|
399
|
+
|
|
400
|
+
var colunas = {};
|
|
401
|
+
nos.forEach(function (n) {
|
|
402
|
+
(colunas[nivel[n.id]] = colunas[nivel[n.id]] || []).push(n);
|
|
403
|
+
});
|
|
404
|
+
var chaves = Object.keys(colunas).map(Number).sort(function (a, b) { return a - b; });
|
|
405
|
+
|
|
406
|
+
var vertical = modo === "vertical" || modo === "arvore";
|
|
407
|
+
var margem = Math.round(W * 0.07);
|
|
408
|
+
|
|
409
|
+
// tamanho padrão coerente com o espaço disponível
|
|
410
|
+
var maxPorColuna = Math.max.apply(null, chaves.map(function (k) { return colunas[k].length; }));
|
|
411
|
+
var lPadrao = vertical
|
|
412
|
+
? Math.min(340, Math.floor((W - margem * 2 - (maxPorColuna - 1) * 60) / maxPorColuna))
|
|
413
|
+
: Math.min(340, Math.floor((W - margem * 2 - (chaves.length - 1) * 90) / Math.max(1, chaves.length)));
|
|
414
|
+
var aPadrao = vertical
|
|
415
|
+
? Math.min(150, Math.floor((H - margem * 2 - (chaves.length - 1) * 70) / Math.max(1, chaves.length)))
|
|
416
|
+
: 150;
|
|
417
|
+
lPadrao = Math.max(150, lPadrao);
|
|
418
|
+
aPadrao = Math.max(90, aPadrao);
|
|
419
|
+
|
|
420
|
+
var passoEixo = vertical
|
|
421
|
+
? (H - margem * 2 - aPadrao) / Math.max(1, chaves.length - 1)
|
|
422
|
+
: (W - margem * 2 - lPadrao) / Math.max(1, chaves.length - 1);
|
|
423
|
+
|
|
424
|
+
chaves.forEach(function (k, iCol) {
|
|
425
|
+
var grupo = colunas[k];
|
|
426
|
+
var vao = vertical ? W : H;
|
|
427
|
+
var tam = vertical ? lPadrao : aPadrao;
|
|
428
|
+
var espaco = (vao - margem * 2 - tam) / Math.max(1, grupo.length - 1);
|
|
429
|
+
|
|
430
|
+
grupo.forEach(function (n, i) {
|
|
431
|
+
if (n.l == null) n.l = lPadrao;
|
|
432
|
+
if (n.a == null) n.a = aPadrao;
|
|
433
|
+
var eixo = margem + (chaves.length > 1 ? passoEixo * iCol : (vao === W ? 0 : 0));
|
|
434
|
+
var cruz = grupo.length > 1 ? margem + espaco * i
|
|
435
|
+
: Math.round((vao - (vertical ? n.l : n.a)) / 2);
|
|
436
|
+
if (vertical) {
|
|
437
|
+
if (n.x == null) n.x = Math.round(cruz);
|
|
438
|
+
if (n.y == null) n.y = Math.round(margem + (chaves.length > 1 ? passoEixo * iCol : (H - n.a) / 2));
|
|
439
|
+
} else {
|
|
440
|
+
if (n.x == null) n.x = Math.round(margem + (chaves.length > 1 ? passoEixo * iCol : (W - n.l) / 2));
|
|
441
|
+
if (n.y == null) n.y = Math.round(cruz);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/* -------------------------------------------------------------- conectores */
|
|
448
|
+
|
|
449
|
+
function desenharConectores(cena, elementos, W, H) {
|
|
450
|
+
var links = elementos.filter(function (e) { return e.tipo === "conector"; });
|
|
451
|
+
if (!links.length) return;
|
|
452
|
+
|
|
453
|
+
var caixas = {};
|
|
454
|
+
elementos.forEach(function (e) {
|
|
455
|
+
if (e.id) caixas[e.id] = { x: e.x || 0, y: e.y || 0, l: e.l || 200, a: e.a || 100 };
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
var ns = "http://www.w3.org/2000/svg";
|
|
459
|
+
var svg = document.createElementNS(ns, "svg");
|
|
460
|
+
svg.setAttribute("class", "conectores");
|
|
461
|
+
svg.setAttribute("viewBox", "0 0 " + W + " " + H);
|
|
462
|
+
|
|
463
|
+
var def = document.createElementNS(ns, "defs");
|
|
464
|
+
def.innerHTML = '<marker id="pta" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">' +
|
|
465
|
+
'<path d="M0 0 L10 5 L0 10 z" fill="var(--c-fraco)"/></marker>';
|
|
466
|
+
svg.appendChild(def);
|
|
467
|
+
|
|
468
|
+
links.forEach(function (c) {
|
|
469
|
+
var a = caixas[c.de], b = caixas[c.para];
|
|
470
|
+
if (!a || !b) return;
|
|
471
|
+
var ac = { x: a.x + a.l / 2, y: a.y + a.a / 2 }, bc = { x: b.x + b.l / 2, y: b.y + b.a / 2 };
|
|
472
|
+
var horizontal = Math.abs(bc.x - ac.x) >= Math.abs(bc.y - ac.y);
|
|
473
|
+
var p1 = horizontal
|
|
474
|
+
? { x: bc.x > ac.x ? a.x + a.l : a.x, y: ac.y }
|
|
475
|
+
: { x: ac.x, y: bc.y > ac.y ? a.y + a.a : a.y };
|
|
476
|
+
var p2 = horizontal
|
|
477
|
+
? { x: bc.x > ac.x ? b.x : b.x + b.l, y: bc.y }
|
|
478
|
+
: { x: bc.x, y: bc.y > ac.y ? b.y : b.y + b.a };
|
|
479
|
+
|
|
480
|
+
var d;
|
|
481
|
+
if (c.estilo === "reta") {
|
|
482
|
+
d = "M" + p1.x + " " + p1.y + " L" + p2.x + " " + p2.y;
|
|
483
|
+
} else if (c.estilo === "cotovelo") {
|
|
484
|
+
d = horizontal
|
|
485
|
+
? "M" + p1.x + " " + p1.y + " H" + (p1.x + p2.x) / 2 + " V" + p2.y + " H" + p2.x
|
|
486
|
+
: "M" + p1.x + " " + p1.y + " V" + (p1.y + p2.y) / 2 + " H" + p2.x + " V" + p2.y;
|
|
487
|
+
} else {
|
|
488
|
+
d = horizontal
|
|
489
|
+
? "M" + p1.x + " " + p1.y + " C" + (p1.x + p2.x) / 2 + " " + p1.y + " " + (p1.x + p2.x) / 2 + " " + p2.y + " " + p2.x + " " + p2.y
|
|
490
|
+
: "M" + p1.x + " " + p1.y + " C" + p1.x + " " + (p1.y + p2.y) / 2 + " " + p2.x + " " + (p1.y + p2.y) / 2 + " " + p2.x + " " + p2.y;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
var path = document.createElementNS(ns, "path");
|
|
494
|
+
path.setAttribute("d", d);
|
|
495
|
+
path.setAttribute("fill", "none");
|
|
496
|
+
path.setAttribute("stroke", c.cor || "var(--c-fraco)");
|
|
497
|
+
path.setAttribute("stroke-width", c.espessura || 3);
|
|
498
|
+
if (c.tracejado) path.setAttribute("stroke-dasharray", "10 8");
|
|
499
|
+
if (c.seta !== false) path.setAttribute("marker-end", "url(#pta)");
|
|
500
|
+
svg.appendChild(path);
|
|
501
|
+
|
|
502
|
+
if (c.texto) {
|
|
503
|
+
var tx = document.createElementNS(ns, "text");
|
|
504
|
+
tx.setAttribute("x", (p1.x + p2.x) / 2);
|
|
505
|
+
tx.setAttribute("y", (p1.y + p2.y) / 2 - 12);
|
|
506
|
+
tx.setAttribute("text-anchor", "middle");
|
|
507
|
+
tx.setAttribute("fill", "var(--c-fraco)");
|
|
508
|
+
tx.setAttribute("font-size", "22");
|
|
509
|
+
tx.textContent = c.texto;
|
|
510
|
+
svg.appendChild(tx);
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
cena.appendChild(svg);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/* ------------------------------------------------------------------ cena */
|
|
518
|
+
|
|
519
|
+
function renderCena(cena, doc, op) {
|
|
520
|
+
op = op || {};
|
|
521
|
+
cena = cena || {};
|
|
522
|
+
var W = doc.largura || 1920, H = doc.altura || 1080;
|
|
523
|
+
|
|
524
|
+
var no = document.createElement("div");
|
|
525
|
+
no.className = "cena" + (op.animar ? " animar" : "");
|
|
526
|
+
no.style.width = W + "px";
|
|
527
|
+
no.style.height = H + "px";
|
|
528
|
+
no.setAttribute("data-tema", cena.tema || doc.tema || "meia-noite");
|
|
529
|
+
if (cena.acabamento || doc.acabamento) no.setAttribute("data-acabamento", cena.acabamento || doc.acabamento);
|
|
530
|
+
if (op.animar && (cena.transicao || doc.transicao)) {
|
|
531
|
+
no.setAttribute("data-transicao", cena.transicao || doc.transicao);
|
|
532
|
+
}
|
|
533
|
+
if (cena.tom) no.style.setProperty("--c-tom", cena.tom);
|
|
534
|
+
if (cena.tom2) no.style.setProperty("--c-tom2", cena.tom2);
|
|
535
|
+
aplicarFundo(no, cena.fundo);
|
|
536
|
+
|
|
537
|
+
var layout = cena.layout || (op.layoutPadrao || "titulo");
|
|
538
|
+
var elementos = (cena.elementos || []).slice();
|
|
539
|
+
var margem = Math.round(W * 0.068);
|
|
540
|
+
|
|
541
|
+
var fluxo = document.createElement("div");
|
|
542
|
+
fluxo.className = "fluxo";
|
|
543
|
+
fluxo.setAttribute("data-layout", layout);
|
|
544
|
+
fluxo.style.padding = margem + "px " + Math.round(W * 0.075) + "px";
|
|
545
|
+
no.appendChild(fluxo);
|
|
546
|
+
|
|
547
|
+
// tela vertical pede tipografia maior: os padrões são calibrados em 1920x1080
|
|
548
|
+
var escalaTipo = H > W ? 1.35 : 1;
|
|
549
|
+
no.style.setProperty("--esc", escalaTipo);
|
|
550
|
+
var ctx = { i: 0, escalaTipo: escalaTipo, animPadrao: op.animar ? (cena.anim || "subir") : null };
|
|
551
|
+
|
|
552
|
+
if (layout === "livre") {
|
|
553
|
+
fluxo.style.padding = "0";
|
|
554
|
+
if (cena.auto) posicionarAuto(elementos, W, H, cena.auto);
|
|
555
|
+
elementos.forEach(function (e) {
|
|
556
|
+
if (e.tipo === "conector") return;
|
|
557
|
+
ctx.i++;
|
|
558
|
+
var el = renderElemento(e, ctx);
|
|
559
|
+
el.style.position = "absolute";
|
|
560
|
+
if (e.x == null) el.style.left = "0px";
|
|
561
|
+
if (e.y == null) el.style.top = "0px";
|
|
562
|
+
fluxo.appendChild(el);
|
|
563
|
+
});
|
|
564
|
+
desenharConectores(no, elementos, W, H);
|
|
565
|
+
return no;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/* layouts de fluxo — cabeçalho em cima, corpo distribuído */
|
|
569
|
+
var cabecalho = [], corpo = [], flutuantes = [], imagem = null;
|
|
570
|
+
elementos.forEach(function (e) {
|
|
571
|
+
if (e.tipo === "conector") return;
|
|
572
|
+
if (e.x != null || e.y != null) { flutuantes.push(e); return; }
|
|
573
|
+
if ((layout === "imagem-direita" || layout === "imagem-esquerda") && e.tipo === "imagem" && !imagem) { imagem = e; return; }
|
|
574
|
+
if (e.papel === "chapeu" || e.papel === "titulo") cabecalho.push(e);
|
|
575
|
+
else corpo.push(e);
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
function solta(lista, alvo) {
|
|
579
|
+
lista.forEach(function (e) { ctx.i++; alvo.appendChild(renderElemento(e, ctx)); });
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
if (layout === "imagem-direita" || layout === "imagem-esquerda") {
|
|
583
|
+
fluxo.style.padding = "0";
|
|
584
|
+
var lado = document.createElement("div");
|
|
585
|
+
lado.className = "lado-texto";
|
|
586
|
+
lado.style.padding = margem + "px " + Math.round(W * 0.055) + "px";
|
|
587
|
+
solta(cabecalho, lado); solta(corpo, lado);
|
|
588
|
+
var box = document.createElement("div");
|
|
589
|
+
box.className = "lado-imagem";
|
|
590
|
+
if (imagem) {
|
|
591
|
+
var im = renderElemento({ tipo: "imagem", src: imagem.src, ajuste: imagem.ajuste, raio: 0 }, ctx);
|
|
592
|
+
im.style.position = "absolute";
|
|
593
|
+
im.style.inset = "0";
|
|
594
|
+
box.appendChild(im);
|
|
595
|
+
}
|
|
596
|
+
if (layout === "imagem-esquerda") { fluxo.appendChild(box); fluxo.appendChild(lado); }
|
|
597
|
+
else { fluxo.appendChild(lado); fluxo.appendChild(box); }
|
|
598
|
+
} else if ((layout === "duas-colunas" || layout === "tres-colunas") && corpo.length > 1) {
|
|
599
|
+
solta(cabecalho, fluxo);
|
|
600
|
+
var cols = document.createElement("div");
|
|
601
|
+
cols.className = "colunas";
|
|
602
|
+
cols.style.gridTemplateColumns = "repeat(" + (layout === "duas-colunas" ? 2 : 3) + ", 1fr)";
|
|
603
|
+
solta(corpo, cols);
|
|
604
|
+
fluxo.appendChild(cols);
|
|
605
|
+
} else {
|
|
606
|
+
// um bloco só (cartoes, numeros…) já se distribui sozinho: não engaiolar
|
|
607
|
+
solta(cabecalho, fluxo);
|
|
608
|
+
solta(corpo, fluxo);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
flutuantes.forEach(function (e) {
|
|
612
|
+
ctx.i++;
|
|
613
|
+
var el = renderElemento(e, ctx);
|
|
614
|
+
el.style.position = "absolute";
|
|
615
|
+
no.appendChild(el);
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
desenharConectores(no, elementos, W, H);
|
|
619
|
+
return no;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (typeof module !== "undefined" && module.exports) module.exports = { renderCena: renderCena };
|