morfeo 0.3.4 → 0.5.0

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.
@@ -0,0 +1,483 @@
1
+ // Capas para series interactivas, historias y documental (medidas en los videos de referencia de "elige tú" y de biografías):
2
+ // bloqueo (pantalla de bloqueo con la hora gigante y notificaciones), llamada (entrante o en curso, con contador),
3
+ // recuento (lo que votaron en el capítulo anterior), capitulo (fin de capítulo con opciones A/B y horario),
4
+ // vigilancia (vista de cámara: REC, hora corriendo, esquinas y mira), cintillo (nombre y cargo de una persona),
5
+ // fecha (tarjeta de año: "1985 · SE CASARON"), calendario (hoja que cambia: "MESES 5") y dividida (pantalla A | B).
6
+ import React from 'react';
7
+ import {clamp, easeIO, easeOut, lerp, resorte} from '../estilo';
8
+ import {Capas} from './capas';
9
+ import {TIERRA} from './tierra-datos';
10
+ import {azar, cuando, type CtxEscena} from './util';
11
+
12
+ type C = Record<string, any>;
13
+ const desde = (c: C, ctx: CtxEscena) => ctx.t - cuando(c.en, ctx, 0);
14
+ const MESES = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'];
15
+ const DIAS = ['domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado'];
16
+
17
+ /** Marco de teléfono sostenido (sin mano: solo el aparato). `ancho` en px. */
18
+ const Aparato: React.FC<{ancho: number; children: React.ReactNode; fondo?: string}> = ({ancho, children, fondo}) => {
19
+ const alto = ancho * 2.05;
20
+ return (
21
+ <div style={{position: 'relative', width: ancho, height: alto, borderRadius: ancho * 0.13, background: '#0D0D10', padding: ancho * 0.03, boxShadow: '0 30px 60px rgba(0,0,0,0.5), inset 0 0 0 3px #2A2A30'}}>
22
+ <div style={{position: 'relative', width: '100%', height: '100%', borderRadius: ancho * 0.105, overflow: 'hidden', background: fondo ?? 'linear-gradient(170deg, #4A2C6E 0%, #D96B4A 55%, #F2B45C 75%, #2B2340 100%)'}}>
23
+ {children}
24
+ <div style={{position: 'absolute', top: ancho * 0.035, left: '50%', transform: 'translateX(-50%)', width: ancho * 0.3, height: ancho * 0.075, borderRadius: 99, background: '#000'}} />
25
+ </div>
26
+ </div>
27
+ );
28
+ };
29
+
30
+ /**
31
+ * Pantalla de bloqueo: fecha, hora gigante (y año abajo si lo das: los videos de viajes en el tiempo lo usan) y
32
+ * notificaciones que entran en su palabra. `hora: '18:40'`, `fecha: 'lunes, 10 de noviembre'`, `anio: 2031`,
33
+ * `notificaciones: [{app: 'Mensajes', titulo: 'Tú', texto: 'No llames a casa.', en: 'vibra'}]`, `fondo` (CSS).
34
+ */
35
+ export const Bloqueo: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
36
+ const ancho = c.ancho ?? 520;
37
+ const notifs: C[] = c.notificaciones ?? [];
38
+ // el año puede "saltar" de uno a otro: anio: [2026, 2031] con anioEn
39
+ const anios = Array.isArray(c.anio) ? c.anio : c.anio != null ? [c.anio] : [];
40
+ const cambio = anios.length > 1 ? clamp((ctx.t - cuando(c.anioEn, ctx, 0.6)) / 0.35) : 1;
41
+ const anio = anios.length > 1 ? (cambio < 0.5 ? anios[0] : anios[anios.length - 1]) : anios[0];
42
+ const sacudida = anios.length > 1 && cambio > 0 && cambio < 1 ? Math.sin(cambio * 40) * 6 : 0;
43
+ return (
44
+ <Aparato ancho={ancho} fondo={c.fondo}>
45
+ <div style={{position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column', alignItems: 'center', paddingTop: ancho * 0.2, color: '#FFFFFF', fontFamily: 'Montserrat, sans-serif', textShadow: '0 2px 12px rgba(0,0,0,0.35)'}}>
46
+ <div style={{fontSize: ancho * 0.05, fontWeight: 600, opacity: 0.9}}>{c.fecha ?? 'lunes, 10 de noviembre'}</div>
47
+ <div style={{fontSize: ancho * 0.3, fontWeight: 800, letterSpacing: -ancho * 0.01, lineHeight: 1}}>{c.hora ?? '18:40'}</div>
48
+ {anio != null ? (
49
+ <div style={{marginTop: ancho * 0.02, fontSize: ancho * 0.085, fontWeight: 900, letterSpacing: ancho * 0.02, padding: `${ancho * 0.01}px ${ancho * 0.05}px`, borderRadius: ancho * 0.03, background: cambio >= 1 && anios.length > 1 ? 'rgba(229,72,77,0.85)' : 'rgba(0,0,0,0.25)', transform: `translateX(${sacudida}px)`}}>
50
+ {anio}
51
+ </div>
52
+ ) : null}
53
+ <div style={{marginTop: 'auto', marginBottom: ancho * 0.12, width: '88%', display: 'flex', flexDirection: 'column', gap: ancho * 0.025}}>
54
+ {notifs.map((n, i) => {
55
+ const k = clamp((ctx.t - cuando(n.en, ctx, 0.4 + i * 0.5)) / 0.35);
56
+ if (k <= 0) return null;
57
+ return (
58
+ <div key={i} style={{opacity: k, transform: `translateY(${(1 - easeOut(k)) * 30}px) scale(${lerp(0.94, 1, easeOut(k))})`, background: 'rgba(245,245,250,0.82)', color: '#111', borderRadius: ancho * 0.05, padding: `${ancho * 0.03}px ${ancho * 0.04}px`, textShadow: 'none'}}>
59
+ <div style={{fontSize: ancho * 0.034, fontWeight: 700, opacity: 0.6, textTransform: 'uppercase', letterSpacing: 1}}>{n.app ?? 'Mensajes'}</div>
60
+ <div style={{fontSize: ancho * 0.045, fontWeight: 800}}>{n.titulo}</div>
61
+ <div style={{fontSize: ancho * 0.045, fontWeight: 500, lineHeight: 1.25}}>{n.texto}</div>
62
+ </div>
63
+ );
64
+ })}
65
+ </div>
66
+ </div>
67
+ </Aparato>
68
+ );
69
+ };
70
+
71
+ /**
72
+ * Llamada en el teléfono. `estado: 'entrante'` (botones colgar/contestar que laten) o `'curso'` (contador que corre
73
+ * desde `desde` segundos y onda de voz). `'terminada'` muestra "Llamada finalizada" y la duración fija. `nombre`, `numero`.
74
+ */
75
+ export const Llamada: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
76
+ const ancho = c.ancho ?? 520;
77
+ const t = Math.max(0, desde(c, ctx));
78
+ const estado = c.estado ?? 'entrante';
79
+ const seg = estado === 'terminada' ? c.duracion ?? 33 : (c.desde ?? 0) + Math.floor(t);
80
+ const mmss = `${Math.floor(seg / 60)}:${String(seg % 60).padStart(2, '0')}`;
81
+ const late = 1 + Math.sin(t * 7) * 0.06;
82
+ return (
83
+ <Aparato ancho={ancho} fondo={c.fondo ?? 'linear-gradient(180deg, #1C2238 0%, #0B0E1A 100%)'}>
84
+ <div style={{position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column', alignItems: 'center', paddingTop: ancho * 0.22, color: '#FFFFFF', fontFamily: 'Montserrat, sans-serif'}}>
85
+ {estado === 'entrante' && c.aviso !== false ? <div style={{background: '#E5484D', fontWeight: 800, fontSize: ancho * 0.04, padding: `${ancho * 0.008}px ${ancho * 0.03}px`, borderRadius: 6, marginBottom: ancho * 0.03, letterSpacing: 1}}>{c.aviso ?? 'LLAMADA ENTRANTE'}</div> : null}
86
+ <div style={{width: ancho * 0.26, height: ancho * 0.26, borderRadius: '50%', background: '#8E93A6', display: 'flex', alignItems: 'flex-end', justifyContent: 'center', overflow: 'hidden'}}>
87
+ <div style={{width: ancho * 0.12, height: ancho * 0.12, borderRadius: '50%', background: '#D9DCE5', marginBottom: ancho * 0.015, boxShadow: `0 ${ancho * 0.1}px 0 ${ancho * 0.05}px #D9DCE5`}} />
88
+ </div>
89
+ <div style={{fontSize: ancho * 0.1, fontWeight: 800, marginTop: ancho * 0.04}}>{c.nombre ?? 'Desconocido'}</div>
90
+ <div style={{fontSize: ancho * 0.042, opacity: 0.7}}>{estado === 'terminada' ? 'Llamada finalizada' : estado === 'curso' ? mmss : c.numero ?? 'móvil'}</div>
91
+ {estado === 'terminada' ? <div style={{fontSize: ancho * 0.2, fontWeight: 800, marginTop: ancho * 0.08}}>{mmss}</div> : null}
92
+ {estado === 'curso' ? (
93
+ <div style={{display: 'flex', alignItems: 'center', gap: 4, height: ancho * 0.12, marginTop: ancho * 0.08}}>
94
+ {Array.from({length: 22}, (_, i) => (
95
+ <div key={i} style={{width: 4, borderRadius: 2, background: '#FFFFFF', height: `${20 + 80 * Math.abs(Math.sin(t * 6 + i * 0.9) * azar(`onda${i}`))}%`, opacity: 0.85}} />
96
+ ))}
97
+ </div>
98
+ ) : null}
99
+ <div style={{marginTop: 'auto', marginBottom: ancho * 0.16, display: 'flex', gap: ancho * 0.22}}>
100
+ {(estado === 'entrante' ? ['#E5484D', '#30A46C'] : estado === 'curso' ? ['#E5484D'] : []).map((col, i) => (
101
+ <div key={i} style={{width: ancho * 0.17, height: ancho * 0.17, borderRadius: '50%', background: col, transform: `scale(${estado === 'entrante' && i === 1 ? late : 1})`, display: 'flex', alignItems: 'center', justifyContent: 'center', boxShadow: `0 0 ${estado === 'entrante' && i === 1 ? 30 : 0}px ${col}`}}>
102
+ <div style={{width: ancho * 0.08, height: ancho * 0.03, borderRadius: 99, background: '#FFFFFF', transform: i === 0 ? 'rotate(0deg)' : 'rotate(-35deg)'}} />
103
+ </div>
104
+ ))}
105
+ </div>
106
+ </div>
107
+ </Aparato>
108
+ );
109
+ };
110
+
111
+ /**
112
+ * Recuento de la votación del capítulo anterior: "VOTACIÓN · CAPÍTULO 1 / LA MAYORÍA DE USTEDES VOTÓ" y barras
113
+ * que se llenan; la ganadora en color. `opciones: [{texto: 'SÍ', sub: 'no tomas el metro', valor: 90}]`.
114
+ */
115
+ export const Recuento: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
116
+ const t = desde(c, ctx);
117
+ const ops: C[] = c.opciones ?? [];
118
+ const max = Math.max(...ops.map((o) => o.valor ?? 0));
119
+ const color = c.color ?? '#E5484D';
120
+ return (
121
+ <div style={{width: c.ancho ?? 820, fontFamily: 'Montserrat, sans-serif', color: '#FFFFFF'}}>
122
+ <div style={{textAlign: 'center', fontSize: 26, letterSpacing: 6, opacity: 0.6, fontWeight: 600}}>{c.cabecera ?? 'VOTACIÓN · CAPÍTULO 1'}</div>
123
+ <div style={{textAlign: 'center', fontSize: 62, fontWeight: 900, lineHeight: 1.08, margin: '18px 0 44px'}}>{c.titulo ?? 'LA MAYORÍA DE USTEDES VOTÓ'}</div>
124
+ {ops.map((o, i) => {
125
+ const k = easeOut(clamp((t - 0.35 - i * 0.18) / 1));
126
+ const gana = (o.valor ?? 0) === max;
127
+ return (
128
+ <div key={i} style={{marginBottom: 38, opacity: gana ? 1 : 0.55}}>
129
+ <div style={{display: 'flex', justifyContent: 'space-between', alignItems: 'baseline'}}>
130
+ <span style={{fontSize: 54, fontWeight: 900}}>{o.texto}</span>
131
+ <span style={{fontSize: 46, fontWeight: 900, color: gana ? color : '#FFFFFF'}}>{Math.round((o.valor ?? 0) * k)}%</span>
132
+ </div>
133
+ <div style={{height: 14, borderRadius: 99, background: 'rgba(255,255,255,0.14)', marginTop: 10}}>
134
+ <div style={{width: `${(o.valor ?? 0) * k}%`, height: '100%', borderRadius: 99, background: gana ? '#FFFFFF' : 'rgba(255,255,255,0.5)'}} />
135
+ </div>
136
+ {o.sub ? <div style={{fontSize: 26, opacity: 0.6, marginTop: 8}}>{o.sub}</div> : null}
137
+ </div>
138
+ );
139
+ })}
140
+ </div>
141
+ );
142
+ };
143
+
144
+ /**
145
+ * Fin de capítulo: nombre de la serie, "CAPÍTULO 2", la pregunta y dos (o más) opciones como botones, "comenta tu
146
+ * opción · la más votada gana" y el botón de seguir con el horario del siguiente.
147
+ * `serie`, `capitulo`, `pregunta`, `opciones: [{texto: 'ABRIR', sub: 'le abres la puerta'}]`, `siguiente: 'CAPÍTULO 3'`, `horario`.
148
+ */
149
+ export const Capitulo: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
150
+ const t = desde(c, ctx);
151
+ const ops: C[] = c.opciones ?? [{texto: 'A'}, {texto: 'B'}];
152
+ const color = c.color ?? '#E5484D';
153
+ const pasa = (d: number) => easeOut(clamp((t - d) / 0.4));
154
+ return (
155
+ <div style={{width: c.ancho ?? 860, fontFamily: 'Montserrat, sans-serif', color: '#FFFFFF', textAlign: 'center'}}>
156
+ <div style={{opacity: pasa(0), fontSize: 30, fontWeight: 900, letterSpacing: 6, color}}>{c.serie ?? 'MI SERIE'}</div>
157
+ <div style={{opacity: pasa(0.1) * 0.6, fontSize: 22, letterSpacing: 8, marginTop: 6}}>{(c.capitulo ?? 'CAPÍTULO 1').toUpperCase()}</div>
158
+ <div style={{opacity: pasa(0.25), transform: `translateY(${(1 - pasa(0.25)) * 20}px)`, fontSize: 74, fontWeight: 900, lineHeight: 1.05, margin: '40px 0 46px'}}>{c.pregunta ?? '¿QUÉ HACES?'}</div>
159
+ <div style={{display: 'flex', gap: 28, justifyContent: 'center'}}>
160
+ {ops.map((o, i) => (
161
+ <div key={i} style={{opacity: pasa(0.5 + i * 0.12), transform: `scale(${resorte(pasa(0.5 + i * 0.12), 0.3)})`, flex: 1, maxWidth: 380}}>
162
+ <div style={{border: `4px solid ${i === 0 ? '#FFFFFF' : color}`, color: i === 0 ? '#FFFFFF' : color, borderRadius: 99, padding: '18px 10px', fontSize: 40, fontWeight: 900}}>{o.texto}</div>
163
+ {o.sub ? <div style={{fontSize: 24, opacity: 0.6, marginTop: 10}}>{o.sub}</div> : null}
164
+ </div>
165
+ ))}
166
+ </div>
167
+ <div style={{opacity: pasa(0.9) * 0.6, fontSize: 22, letterSpacing: 3, marginTop: 40}}>{c.pie ?? 'COMENTA TU OPCIÓN · LA MÁS VOTADA GANA'}</div>
168
+ <div style={{opacity: pasa(1.1), display: 'inline-block', marginTop: 34, background: color, borderRadius: 99, padding: '18px 44px', fontSize: 32, fontWeight: 900, boxShadow: `0 0 ${20 + 14 * Math.sin(t * 4)}px ${color}`}}>
169
+ SÍGUEME PARA EL {(c.siguiente ?? 'SIGUIENTE CAPÍTULO').toUpperCase()}
170
+ </div>
171
+ {c.horario ? <div style={{opacity: pasa(1.2) * 0.65, fontSize: 24, marginTop: 14}}>{c.horario}</div> : null}
172
+ </div>
173
+ );
174
+ };
175
+
176
+ /**
177
+ * Vista de cámara de vigilancia sobre toda la pantalla: REC que parpadea, fecha y hora corriendo, esquinas, mira al
178
+ * centro y zoom. `hora: '23:47:14'`, `fecha`, `etiqueta: 'CAM 03'`, `mira: false` la quita. Va encima del mundo.
179
+ */
180
+ export const Vigilancia: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
181
+ const t = Math.max(0, desde(c, ctx));
182
+ const [h, m, s] = String(c.hora ?? '23:47:14').split(':').map(Number);
183
+ const total = (h || 0) * 3600 + (m || 0) * 60 + (s || 0) + Math.floor(t);
184
+ const hh = (n: number) => String(n).padStart(2, '0');
185
+ const reloj = `${hh(Math.floor(total / 3600) % 24)}:${hh(Math.floor(total / 60) % 60)}:${hh(total % 60)}`;
186
+ const color = c.color ?? '#FFFFFF';
187
+ const esquina = (st: React.CSSProperties) => <div style={{position: 'absolute', width: 90, height: 90, borderColor: color, borderStyle: 'solid', borderWidth: 0, ...st}} />;
188
+ return (
189
+ <div style={{position: 'relative', width: 1080, height: 1920, fontFamily: 'JetBrains Mono, monospace', color, pointerEvents: 'none'}}>
190
+ <div style={{position: 'absolute', inset: 0, background: 'repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0 2px, transparent 2px 5px)', mixBlendMode: 'overlay'}} />
191
+ <div style={{position: 'absolute', inset: 0, background: 'radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.55) 100%)'}} />
192
+ {esquina({left: 70, top: 260, borderLeftWidth: 6, borderTopWidth: 6})}
193
+ {esquina({right: 70, top: 260, borderRightWidth: 6, borderTopWidth: 6})}
194
+ {esquina({left: 70, bottom: 260, borderLeftWidth: 6, borderBottomWidth: 6})}
195
+ {esquina({right: 70, bottom: 260, borderRightWidth: 6, borderBottomWidth: 6})}
196
+ <div style={{position: 'absolute', left: 100, top: 290, display: 'flex', alignItems: 'center', gap: 14, fontSize: 34, fontWeight: 800}}>
197
+ <span style={{width: 22, height: 22, borderRadius: '50%', background: '#FF3B30', opacity: Math.floor(t * 2) % 2 ? 0.25 : 1}} /> REC
198
+ </div>
199
+ <div style={{position: 'absolute', right: 100, top: 290, fontSize: 30, fontWeight: 700, textAlign: 'right'}}>
200
+ {c.etiqueta ?? 'CAM 03'}
201
+ <div style={{fontSize: 26, opacity: 0.8}}>{c.fecha ?? ''}</div>
202
+ </div>
203
+ <div style={{position: 'absolute', right: 100, bottom: 290, fontSize: 36, fontWeight: 800}}>{reloj}</div>
204
+ <div style={{position: 'absolute', left: 100, bottom: 290, fontSize: 24, opacity: 0.8}}>ZOOM {(c.zoom ?? 3.8).toFixed(1)}x</div>
205
+ {c.mira !== false ? (
206
+ <div style={{position: 'absolute', left: 540 + (c.miraX ?? 0), top: 960 + (c.miraY ?? 0), transform: 'translate(-50%, -50%)'}}>
207
+ <div style={{width: 120, height: 120, borderRadius: '50%', border: `3px solid ${color}`, opacity: 0.9}} />
208
+ <div style={{position: 'absolute', left: -30, top: 59, width: 180, height: 3, background: color}} />
209
+ <div style={{position: 'absolute', left: 59, top: -30, width: 3, height: 180, background: color}} />
210
+ </div>
211
+ ) : null}
212
+ </div>
213
+ );
214
+ };
215
+
216
+ /**
217
+ * Cintillo de persona (documental): nombre en grande y cargo abajo, con barra de color a la izquierda; entra
218
+ * deslizándose. `nombre`, `cargo`, `color`. Pensado abajo a la izquierda (x ~ 300, y ~ 1560).
219
+ */
220
+ export const Cintillo: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
221
+ const k = easeIO(clamp(desde(c, ctx) / 0.45));
222
+ const color = c.color ?? ctx.tema.colores.acento;
223
+ return (
224
+ <div style={{display: 'flex', alignItems: 'stretch', fontFamily: 'Montserrat, sans-serif', clipPath: `inset(0 ${(1 - k) * 100}% 0 0)`}}>
225
+ <div style={{width: 12, background: color}} />
226
+ <div style={{background: 'rgba(12,12,16,0.88)', padding: '14px 28px 16px 22px'}}>
227
+ <div style={{color: '#FFFFFF', fontWeight: 900, fontSize: c.tam ?? 56, lineHeight: 1.05}}>{c.nombre}</div>
228
+ {c.cargo ? <div style={{color: 'rgba(255,255,255,0.7)', fontWeight: 600, fontSize: (c.tam ?? 56) * 0.48, marginTop: 6, textTransform: 'uppercase', letterSpacing: 2}}>{c.cargo}</div> : null}
229
+ </div>
230
+ </div>
231
+ );
232
+ };
233
+
234
+ /** Tarjeta de año: el año en grande (dorado por defecto) y qué pasó abajo: "1985 · SE CASARON". El año cuenta hacia su valor. */
235
+ export const Fecha: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
236
+ const t = desde(c, ctx);
237
+ const k = easeOut(clamp(t / 0.7));
238
+ const fin = Number(c.anio ?? c.valor ?? 2000);
239
+ const ini = c.de != null ? Number(c.de) : fin;
240
+ const anio = Math.round(lerp(ini, fin, k));
241
+ const color = c.color ?? '#E8C66A';
242
+ return (
243
+ <div style={{transform: `scale(${resorte(clamp(t / 0.4), 0.3)})`, background: 'rgba(14,12,10,0.86)', border: `4px solid ${color}`, borderRadius: 14, padding: '10px 34px 14px', textAlign: 'center', fontFamily: 'Montserrat, sans-serif', boxShadow: '0 16px 34px rgba(0,0,0,0.45)'}}>
244
+ <div style={{color, fontWeight: 900, fontSize: c.tam ?? 96, lineHeight: 1}}>{c.texto ?? anio}</div>
245
+ {c.pie ? <div style={{color: '#FFFFFF', fontWeight: 800, fontSize: (c.tam ?? 96) * 0.26, letterSpacing: 2, textTransform: 'uppercase', marginTop: 4}}>{c.pie}</div> : null}
246
+ </div>
247
+ );
248
+ };
249
+
250
+ /**
251
+ * Calendario de hoja: encabezado de color con el título ("MESES", "DÍA", un mes) y el número grande, que cambia de
252
+ * `de` a `a` volteando la hoja. `titulo`, `de`, `a`, `color`.
253
+ */
254
+ export const Calendario: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
255
+ const t = desde(c, ctx);
256
+ const de = Number(c.de ?? c.a ?? c.valor ?? 1);
257
+ const a = Number(c.a ?? c.valor ?? de);
258
+ const pasos = Math.abs(a - de);
259
+ const dur = c.duracion ?? Math.min(1.6, 0.25 * pasos + 0.3);
260
+ const k = clamp((t - 0.3) / dur);
261
+ const v = pasos ? Math.round(lerp(de, a, easeOut(k))) : a;
262
+ // la hoja se voltea cada vez que cambia el número
263
+ const frac = pasos ? ((easeOut(k) * pasos) % 1) : 1;
264
+ const tam = c.tam ?? 220;
265
+ const color = c.color ?? '#E5484D';
266
+ return (
267
+ <div style={{width: tam, borderRadius: tam * 0.08, overflow: 'hidden', background: '#FFFFFF', boxShadow: '0 16px 34px rgba(0,0,0,0.35)', fontFamily: 'Montserrat, sans-serif', textAlign: 'center', transform: `scale(${resorte(clamp(t / 0.35), 0.3)})`}}>
268
+ <div style={{background: color, color: '#FFFFFF', fontWeight: 900, fontSize: tam * 0.13, padding: `${tam * 0.04}px 0`, letterSpacing: 2}}>{(c.titulo ?? 'DÍA').toUpperCase()}</div>
269
+ <div style={{fontWeight: 900, fontSize: tam * 0.46, color: '#1B1B1F', lineHeight: 1.25, transform: `perspective(400px) rotateX(${k < 1 && pasos ? (1 - frac) * 50 : 0}deg)`}}>{v}</div>
270
+ </div>
271
+ );
272
+ };
273
+
274
+ /**
275
+ * Pantalla dividida en dos (lado a lado o arriba/abajo): cada mitad tiene su etiqueta y sus capas, con una línea
276
+ * al centro. `izq: {etiqueta: 'CINTA', capas: [...]}`, `der: {...}`, `vertical: true` para arriba/abajo, `fondo`.
277
+ * Las capas de cada mitad usan coordenadas de su mitad (540×1920 o 1080×960).
278
+ */
279
+ export const Dividida: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
280
+ const k = easeIO(clamp(desde(c, ctx) / 0.5));
281
+ const vertical = !!c.vertical;
282
+ const W2 = vertical ? 1080 : 540;
283
+ const H2 = vertical ? 960 : 1920;
284
+ const mitad = (m: C | undefined, i: number) => (
285
+ <div key={i} style={{position: 'absolute', left: vertical ? 0 : i * 540, top: vertical ? i * 960 : 0, width: W2, height: H2, overflow: 'hidden', background: m?.fondo ?? c.fondo ?? (i === 0 ? '#1A1C24' : '#22252F'), clipPath: vertical ? `inset(0 ${(1 - k) * 100}% 0 0)` : `inset(${(1 - k) * 100}% 0 0 0)`}}>
286
+ <div style={{position: 'absolute', left: 0, top: 0, width: 1080, height: 1920, transform: vertical ? `translateY(${-480}px)` : `translateX(${-270}px)`}}>
287
+ <Capas capas={(m?.capas ?? []) as any} ctx={ctx} />
288
+ </div>
289
+ {m?.etiqueta ? (
290
+ <div style={{position: 'absolute', left: '50%', top: vertical ? 40 : (c.etiquetaY ?? 430), transform: 'translateX(-50%)', background: m.color ?? '#1B1B1F', color: '#FFFFFF', fontFamily: 'Montserrat, sans-serif', fontWeight: 900, fontSize: 34, letterSpacing: 3, padding: '8px 22px', borderRadius: 10}}>{m.etiqueta}</div>
291
+ ) : null}
292
+ </div>
293
+ );
294
+ return (
295
+ <div style={{position: 'relative', width: 1080, height: 1920}}>
296
+ {mitad(c.izq ?? c.arriba, 0)}
297
+ {mitad(c.der ?? c.abajo, 1)}
298
+ <div style={{position: 'absolute', background: c.linea ?? '#FFFFFF', ...(vertical ? {left: 0, top: 957, width: 1080 * k, height: 6} : {left: 537, top: 0, width: 6, height: 1920 * k})}} />
299
+ </div>
300
+ );
301
+ };
302
+
303
+ /**
304
+ * Globo terráqueo que gira hasta dejar `lat`/`lon` al frente y clava un pin con su etiqueta ("Taiwán · 1963").
305
+ * Proyección ortográfica de los contornos de Natural Earth (dominio público). `tam`, `color` (del pin), `girar: false`
306
+ * lo deja quieto. Pensado como plano de apertura de una biografía o un "¿dónde pasó?".
307
+ */
308
+ export const Tierra: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
309
+ const t = desde(c, ctx);
310
+ const tam = c.tam ?? 760;
311
+ const R = tam / 2 - 30;
312
+ const k = c.girar === false ? 1 : easeIO(clamp(t / (c.duracion ?? 1.8)));
313
+ const lon0 = Number(c.lon) + lerp(-110, 0, k) + (c.girar === false ? 0 : t * 1.5 * (1 - k));
314
+ const lat0 = lerp(0, Math.max(-50, Math.min(50, Number(c.lat))) * 0.7, k);
315
+ const rad = Math.PI / 180;
316
+ const [sl0, cl0] = [Math.sin(lat0 * rad), Math.cos(lat0 * rad)];
317
+ const proy = (lon: number, lat: number): [number, number, number] => {
318
+ const dl = (lon - lon0) * rad;
319
+ const [sl, cl] = [Math.sin(lat * rad), Math.cos(lat * rad)];
320
+ const x = cl * Math.sin(dl);
321
+ const y = cl0 * sl - sl0 * cl * Math.cos(dl);
322
+ const z = sl0 * sl + cl0 * cl * Math.cos(dl); // > 0: cara visible
323
+ return [x, y, z];
324
+ };
325
+ const cx = tam / 2;
326
+ // Recorte en el horizonte: cada polígono se camina arista por arista; donde cruza al otro lado se corta en el
327
+ // borde del disco y el tramo de atrás se reemplaza por el arco del borde. La Antártida solo si se mira hacia el sur.
328
+ const borde = (a: [number, number, number], b: [number, number, number]): [number, number] => {
329
+ const f = a[2] / (a[2] - b[2]);
330
+ const x = a[0] + (b[0] - a[0]) * f;
331
+ const y = a[1] + (b[1] - a[1]) * f;
332
+ const n = Math.hypot(x, y) || 1;
333
+ return [x / n, y / n];
334
+ };
335
+ const P = (x: number, y: number) => `${(cx + x * R).toFixed(1)} ${(cx - y * R).toFixed(1)}`;
336
+ const caminos = TIERRA.map((poly) => {
337
+ if (lat0 > -30 && poly.every((v, i) => i % 2 === 0 || v < -60)) return '';
338
+ const pts: [number, number, number][] = [];
339
+ for (let i = 0; i < poly.length; i += 2) pts.push(proy(poly[i], poly[i + 1]));
340
+ if (!pts.some((p) => p[2] > 0)) return '';
341
+ // empezar en un punto visible para que el camino abra bien
342
+ const i0 = pts.findIndex((p) => p[2] > 0);
343
+ const ord = [...pts.slice(i0), ...pts.slice(0, i0)];
344
+ let d = `M${P(ord[0][0], ord[0][1])}`;
345
+ let salida: [number, number] | null = null;
346
+ for (let i = 1; i <= ord.length; i++) {
347
+ const a = ord[i - 1];
348
+ const b = ord[i % ord.length];
349
+ if (a[2] > 0 && b[2] > 0) d += `L${P(b[0], b[1])}`;
350
+ else if (a[2] > 0 && b[2] <= 0) {
351
+ salida = borde(a, b);
352
+ d += `L${P(salida[0], salida[1])}`;
353
+ } else if (a[2] <= 0 && b[2] > 0) {
354
+ const entrada = borde(a, b);
355
+ if (salida) {
356
+ // arco por el borde: el sentido corto entre la salida y la entrada
357
+ const cruz = salida[0] * entrada[1] - salida[1] * entrada[0];
358
+ d += `A${R} ${R} 0 0 ${cruz > 0 ? 0 : 1} ${P(entrada[0], entrada[1])}`;
359
+ } else d += `L${P(entrada[0], entrada[1])}`;
360
+ d += `L${P(b[0], b[1])}`;
361
+ salida = null;
362
+ }
363
+ }
364
+ return d + 'Z';
365
+ }).filter(Boolean);
366
+ const [px, py, pz] = proy(Number(c.lon), Number(c.lat));
367
+ const pin = clamp((t - (c.girar === false ? 0.2 : (c.duracion ?? 1.8) * 0.85)) / 0.35);
368
+ const X = cx + px * R;
369
+ const Y = cx - py * R;
370
+ // `acercar: 4`: después del pin, la cámara vuela hacia el sitio (el globo crece alrededor del pin)
371
+ const tPin = c.girar === false ? 0.2 : (c.duracion ?? 1.8) * 0.85;
372
+ const vuelo = c.acercar ? easeIO(clamp((t - tPin - 0.6) / (c.duracionVuelo ?? 1.2))) : 0;
373
+ const zoom = 1 + ((c.acercar ?? 1) - 1) * vuelo;
374
+ const color = c.color ?? '#E5484D';
375
+ return (
376
+ <div style={{position: 'relative', width: tam, height: tam, transform: `scale(${zoom})`, transformOrigin: `${X}px ${Y}px`}}>
377
+ <svg width={tam} height={tam} style={{overflow: 'visible'}}>
378
+ <defs>
379
+ <radialGradient id="tierra-mar" cx="38%" cy="32%" r="75%">
380
+ <stop offset="0" stopColor="#3C8DE0" />
381
+ <stop offset="0.65" stopColor="#1C4FA3" />
382
+ <stop offset="1" stopColor="#0B2457" />
383
+ </radialGradient>
384
+ <radialGradient id="tierra-luz" cx="35%" cy="30%" r="80%">
385
+ <stop offset="0" stopColor="rgba(255,255,255,0.28)" />
386
+ <stop offset="0.5" stopColor="rgba(255,255,255,0)" />
387
+ <stop offset="1" stopColor="rgba(0,0,20,0.55)" />
388
+ </radialGradient>
389
+ <clipPath id="tierra-disco">
390
+ <circle cx={cx} cy={cx} r={R} />
391
+ </clipPath>
392
+ </defs>
393
+ <circle cx={cx} cy={cx} r={R + 18} fill="none" stroke="rgba(120,190,255,0.25)" strokeWidth={22} style={{filter: 'blur(8px)'}} />
394
+ <circle cx={cx} cy={cx} r={R} fill="url(#tierra-mar)" />
395
+ <g clipPath="url(#tierra-disco)">
396
+ {caminos.map((d, i) => (
397
+ <path key={i} d={d} fill="#6FBF73" stroke="#4E9A55" strokeWidth={1.2} strokeLinejoin="round" vectorEffect="non-scaling-stroke" />
398
+ ))}
399
+ </g>
400
+ <circle cx={cx} cy={cx} r={R} fill="url(#tierra-luz)" />
401
+ {pin > 0 && pz > 0 ? (
402
+ <g transform={`translate(${X} ${Y}) scale(${resorte(pin, 0.3)})`}>
403
+ <circle r={26 + 30 * ((t * 1.2) % 1)} fill="none" stroke={color} strokeWidth={4} opacity={1 - ((t * 1.2) % 1)} />
404
+ <path d="M0 0 C -16 -22 -22 -34 -22 -46 A 22 22 0 1 1 22 -46 C 22 -34 16 -22 0 0 Z" fill={color} stroke="#FFFFFF" strokeWidth={4} />
405
+ <circle cy={-46} r={8} fill="#FFFFFF" />
406
+ </g>
407
+ ) : null}
408
+ </svg>
409
+ {c.etiqueta && pin > 0 && pz > 0 ? (
410
+ <div style={{position: 'absolute', left: X, top: Y + 18, transform: `translateX(-50%) scale(${resorte(clamp((t - (c.duracion ?? 1.8) * 0.85 - 0.15) / 0.35), 0.3)})`, background: color, color: '#FFFFFF', fontFamily: 'Montserrat, sans-serif', fontWeight: 900, fontSize: tam * 0.045, padding: '6px 18px', borderRadius: 10, whiteSpace: 'nowrap', boxShadow: '0 8px 18px rgba(0,0,0,0.35)'}}>
411
+ {c.etiqueta}
412
+ </div>
413
+ ) : null}
414
+ </div>
415
+ );
416
+ };
417
+
418
+ /**
419
+ * Línea de tiempo vertical: la línea se dibuja hacia abajo y cada hito entra en su palabra (`en`), con el año en
420
+ * grande y su texto. `hitos: [{anio: 1963, texto: 'Nace en Taiwán', en: 'nació'}]`, `color`, `ancho`. El último que
421
+ * ya entró queda resaltado.
422
+ */
423
+ export const Linea: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
424
+ const hitos: C[] = c.hitos ?? [];
425
+ const color = c.color ?? ctx.tema.colores.acento;
426
+ const paso = c.paso ?? 190;
427
+ const tiempos = hitos.map((h, i) => cuando(h.en, ctx, 0.3 + i * 0.8));
428
+ const visibles = tiempos.filter((t0) => ctx.t >= t0).length;
429
+ const ultimo = visibles - 1;
430
+ // la línea llega hasta el último hito que ya entró (y avanza mientras entra)
431
+ const kUlt = ultimo >= 0 ? easeOut(clamp((ctx.t - tiempos[ultimo]) / 0.4)) : 0;
432
+ const largo = ultimo >= 0 ? (ultimo - 1 + kUlt) * paso + paso * 0.15 : 0;
433
+ return (
434
+ <div style={{position: 'relative', width: c.ancho ?? 820, height: hitos.length * paso, fontFamily: 'Montserrat, sans-serif'}}>
435
+ <div style={{position: 'absolute', left: 38, top: 30, width: 8, height: (hitos.length - 1) * paso, borderRadius: 4, background: 'rgba(255,255,255,0.18)'}} />
436
+ <div style={{position: 'absolute', left: 38, top: 30, width: 8, height: Math.max(0, largo + paso * 0.85), borderRadius: 4, background: color}} />
437
+ {hitos.map((h, i) => {
438
+ const k = easeOut(clamp((ctx.t - tiempos[i]) / 0.4));
439
+ if (k <= 0) return null;
440
+ const actual = i === ultimo;
441
+ return (
442
+ <div key={i} style={{position: 'absolute', left: 0, top: i * paso, display: 'flex', alignItems: 'flex-start', gap: 34, opacity: k, transform: `translateX(${(1 - k) * 40}px)`}}>
443
+ <div style={{width: 84, height: 84, borderRadius: '50%', background: actual ? color : '#1B1B1F', border: `6px solid ${color}`, boxShadow: actual ? `0 0 24px ${color}` : undefined, transform: `scale(${resorte(k, 0.3)})`, flex: 'none'}} />
444
+ <div style={{paddingTop: 2}}>
445
+ <div style={{color: actual ? color : '#FFFFFF', fontWeight: 900, fontSize: 64, lineHeight: 1}}>{h.anio ?? h.titulo}</div>
446
+ {h.texto ? <div style={{color: '#FFFFFF', fontWeight: 700, fontSize: 36, marginTop: 6, maxWidth: (c.ancho ?? 820) - 140, textShadow: '0 2px 10px rgba(0,0,0,0.5)'}}>{h.texto}</div> : null}
447
+ </div>
448
+ </div>
449
+ );
450
+ })}
451
+ </div>
452
+ );
453
+ };
454
+
455
+ export const HISTORIAS = ['linea', 'tierra', 'bloqueo', 'llamada', 'recuento', 'capitulo', 'vigilancia', 'cintillo', 'fecha', 'calendario', 'dividida'];
456
+ export const Historias: React.FC<{c: C; ctx: CtxEscena}> = ({c, ctx}) => {
457
+ switch (c.tipo) {
458
+ case 'linea':
459
+ return <Linea c={c} ctx={ctx} />;
460
+ case 'tierra':
461
+ return <Tierra c={c} ctx={ctx} />;
462
+ case 'bloqueo':
463
+ return <Bloqueo c={c} ctx={ctx} />;
464
+ case 'llamada':
465
+ return <Llamada c={c} ctx={ctx} />;
466
+ case 'recuento':
467
+ return <Recuento c={c} ctx={ctx} />;
468
+ case 'capitulo':
469
+ return <Capitulo c={c} ctx={ctx} />;
470
+ case 'vigilancia':
471
+ return <Vigilancia c={c} ctx={ctx} />;
472
+ case 'cintillo':
473
+ return <Cintillo c={c} ctx={ctx} />;
474
+ case 'fecha':
475
+ return <Fecha c={c} ctx={ctx} />;
476
+ case 'calendario':
477
+ return <Calendario c={c} ctx={ctx} />;
478
+ case 'dividida':
479
+ return <Dividida c={c} ctx={ctx} />;
480
+ default:
481
+ return null;
482
+ }
483
+ };
@@ -0,0 +1,44 @@
1
+ // Portada del video (salida/<título> (portada).jpg): el cuadro de la miniatura con el título grande abajo, la palabra
2
+ // clave en color y la marca arriba. Distinta de la miniatura (que es el cuadro limpio): la portada es la que se ve en
3
+ // el perfil y en la cuadrícula del canal, así que el título tiene que leerse en chiquito.
4
+ import React from 'react';
5
+ import {AbsoluteFill} from 'remotion';
6
+ import {ANTON, ancho} from '../estilo';
7
+ import {Avatar, MarcaContexto} from '../piezas';
8
+ import type {Marca} from '../tipos';
9
+ import {partesResaltadas} from './util';
10
+
11
+ export const Portada: React.FC<{texto: string; marca: Marca; acento?: string}> = ({texto, marca, acento = marca.color ?? '#FFD400'}) => {
12
+ const letra = marca.letra ?? ANTON;
13
+ const limpio = texto.replace(/\*/g, '').toUpperCase();
14
+ // sin *palabra*, se resalta la última palabra larga
15
+ const marcado = texto.includes('*') ? texto : texto.replace(/([^\s]{5,})(?![\s\S]*\s[^\s]{5,})/, '*$1*');
16
+ let tam = 150;
17
+ try {
18
+ // en 2–3 renglones de 940 px
19
+ const w = ancho(limpio, letra, tam, 400);
20
+ if (w > 940 * 2.6) tam = Math.max(84, Math.floor((tam * 940 * 2.6) / w));
21
+ } catch {}
22
+ return (
23
+ <MarcaContexto.Provider value={marca}>
24
+ <AbsoluteFill>
25
+ <AbsoluteFill style={{background: 'linear-gradient(180deg, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 22%, rgba(0,0,0,0) 45%, rgba(0,0,0,0.82) 78%, rgba(0,0,0,0.92) 100%)'}} />
26
+ {marca.nombre || marca.logo ? (
27
+ <div style={{position: 'absolute', left: 56, top: 110, display: 'flex', alignItems: 'center', gap: 18}}>
28
+ <div style={{position: 'relative', width: 96, height: 96}}>
29
+ <Avatar x={0} y={0} size={88} aro={5} />
30
+ </div>
31
+ {marca.nombre ? <div style={{fontFamily: 'Montserrat, sans-serif', fontWeight: 900, fontSize: 44, color: '#FFFFFF', textShadow: '0 3px 12px rgba(0,0,0,0.6)'}}>{marca.nombre}</div> : null}
32
+ </div>
33
+ ) : null}
34
+ <div style={{position: 'absolute', left: 60, right: 60, bottom: 230, fontFamily: letra, fontSize: tam, lineHeight: 1.02, color: '#FFFFFF', textTransform: 'uppercase', textShadow: '0 8px 30px rgba(0,0,0,0.6)', WebkitTextStroke: `${Math.round(tam * 0.04)}px #000`, paintOrder: 'stroke fill'}}>
35
+ {partesResaltadas(marcado).map(([p, r], i) => (
36
+ <span key={i} style={r ? {color: acento} : undefined}>
37
+ {p}
38
+ </span>
39
+ ))}
40
+ </div>
41
+ </AbsoluteFill>
42
+ </MarcaContexto.Provider>
43
+ );
44
+ };