lumina-slides 8.8.1 → 8.9.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,192 @@
1
+ # Implementing lumina-slides
2
+
3
+ Guía para integrar la librería `lumina-slides` en tu aplicación. Pensada para desarrolladores y para **agentes de código** (Cursor, Copilot, etc.) que escriben el código que consume la librería.
4
+
5
+ ---
6
+
7
+ ## 1. Instalación
8
+
9
+ ```bash
10
+ npm install lumina-slides
11
+ # Opcional, solo si usas slides tipo "chart":
12
+ npm install lumina-slides chart.js
13
+ ```
14
+
15
+ ---
16
+
17
+ ## 2. Imports principales
18
+
19
+ ```ts
20
+ import { Lumina, parsePartialJson, generateSystemPrompt, getLuminaJsonSchema } from "lumina-slides";
21
+ import "lumina-slides/style.css";
22
+ ```
23
+
24
+ Otras exportaciones útiles: `createDebouncedLoader`, `isSlideReady`, `generateThemePrompt`, tipos `Deck`, `LuminaOptions`, `LuminaEventMap`, etc.
25
+
26
+ ---
27
+
28
+ ## 3. Crear el motor y cargar un deck
29
+
30
+ ```ts
31
+ const engine = new Lumina("#app", {
32
+ theme: "ocean", // preset: default, ocean, midnight, forest, cyber, latte, sunset, monochrome
33
+ loop: true,
34
+ navigation: true,
35
+ touch: true,
36
+ });
37
+
38
+ engine.load({
39
+ meta: { title: "Mi presentación" },
40
+ slides: [
41
+ { type: "statement", title: "Título", subtitle: "Subtítulo" },
42
+ { type: "features", title: "Features", features: [
43
+ { title: "A", desc: "Desc A", icon: "star" },
44
+ { title: "B", desc: "Desc B", icon: "zap" },
45
+ ]},
46
+ ],
47
+ });
48
+ ```
49
+
50
+ ---
51
+
52
+ ## 4. Actualizar el deck (patch)
53
+
54
+ Para cambios incrementales sin recargar todo:
55
+
56
+ ```ts
57
+ engine.patch({ meta: { title: "Nuevo título" } });
58
+ // slides se reemplaza por completo si lo pasas:
59
+ // engine.patch({ slides: [...nuevosSlides] });
60
+ ```
61
+
62
+ ---
63
+
64
+ ## 5. Eventos
65
+
66
+ ```ts
67
+ engine.on("ready", (deck) => { /* deck cargado */ });
68
+ engine.on("slideChange", ({ index, previousIndex, slide }) => { /* cambió la diapositiva */ });
69
+ engine.on("action", (p) => {
70
+ // p: { type, label?, value? } — p.ej. clicks en botones
71
+ });
72
+ engine.on("error", (err) => { /* error interno */ });
73
+ ```
74
+
75
+ Para desuscribirse: `engine.off("slideChange", handler)` con la misma referencia de función.
76
+
77
+ ---
78
+
79
+ ## 6. Navegación programática
80
+
81
+ ```ts
82
+ engine.next();
83
+ engine.prev();
84
+ engine.goTo(3);
85
+ const i = engine.currentSlideIndex;
86
+ ```
87
+
88
+ ---
89
+
90
+ ## 7. Estado para el agente / LLM
91
+
92
+ ```ts
93
+ const state = engine.exportState();
94
+ // { status, currentSlide: { index, id, type, title }, narrative, engagementLevel, history }
95
+ // Útil para incluir en el contexto de un LLM: "El usuario está en la diapositiva X, ha hecho Y".
96
+ ```
97
+
98
+ ---
99
+
100
+ ## 8. Streaming desde un LLM
101
+
102
+ Cuando el modelo va devolviendo JSON por chunks:
103
+
104
+ ```ts
105
+ import { Lumina, parsePartialJson } from "lumina-slides";
106
+
107
+ const engine = new Lumina("#app", { theme: "midnight" });
108
+ let buffer = "";
109
+
110
+ async function onStream(chunk: string) {
111
+ buffer += chunk;
112
+ const json = parsePartialJson(buffer);
113
+ if (json) engine.load(json);
114
+ }
115
+ ```
116
+
117
+ O con debounce para evitar parpadeos:
118
+
119
+ ```ts
120
+ import { createDebouncedLoader } from "lumina-slides";
121
+
122
+ const onChunk = createDebouncedLoader((deck) => engine.load(deck), 80);
123
+ // En el bucle de stream: onChunk(buffer);
124
+ ```
125
+
126
+ ---
127
+
128
+ ## 9. Generar el system prompt para un LLM que crea slides
129
+
130
+ Si un LLM va a generar el JSON del deck:
131
+
132
+ ```ts
133
+ const systemPrompt = generateSystemPrompt({
134
+ mode: "fast", // 'reasoning' si quieres CoT antes del JSON
135
+ includeSchema: true,
136
+ includeTheming: true,
137
+ });
138
+ // Usar systemPrompt como mensaje de sistema en OpenAI, Anthropic, etc.
139
+ ```
140
+
141
+ Solo temas: `generateThemePrompt()`.
142
+
143
+ ---
144
+
145
+ ## 10. Schema JSON
146
+
147
+ Para validar o para dárselo al LLM:
148
+
149
+ ```ts
150
+ const schema = getLuminaJsonSchema();
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 11. Destruir la instancia
156
+
157
+ Al desmontar el componente o salir de la vista:
158
+
159
+ ```ts
160
+ engine.destroy();
161
+ ```
162
+
163
+ ---
164
+
165
+ ## Estructura de un `Deck`
166
+
167
+ ```ts
168
+ interface Deck {
169
+ meta: { title: string; author?: string; theme?: string; themeConfig?: ThemeConfig; [k: string]: any };
170
+ slides: Array<
171
+ | { type: "statement"; title: string; subtitle?: string; tag?: string; notes?: string }
172
+ | { type: "features"; title: string; features: { title: string; desc: string; icon?: string }[]; description?: string; notes?: string }
173
+ | { type: "timeline"; title: string; timeline: { date: string; title: string; description: string }[]; subtitle?: string; notes?: string }
174
+ | { type: "steps"; title: string; steps: { step: string; title: string; description?: string }[]; notes?: string }
175
+ | { type: "half"; imageSide: "left"|"right"; image: string; title: string; paragraphs: string[]; tag?: string; cta?: string; notes?: string }
176
+ | { type: "flex"; direction?: "horizontal"|"vertical"; elements: FlexElement[]; gap?: SpacingToken; padding?: SpacingToken; notes?: string }
177
+ | { type: "chart"; chartType: "bar"|"line"|"pie"|"doughnut"; data: { labels: string[]; datasets: { label: string; values: number[]; color?: string }[] }; title?: string; subtitle?: string; notes?: string }
178
+ | { type: "custom"; html: string; css?: string; notes?: string }
179
+ // + diagram, video, etc.
180
+ >;
181
+ }
182
+ ```
183
+
184
+ Los tipos detallados están en el paquete: `Deck`, `SlideStatement`, `SlideFeatures`, `LuminaOptions`, `LuminaEventMap`, etc.
185
+
186
+ ---
187
+
188
+ ## Dónde seguir
189
+
190
+ - **API y tipos**: los JSDoc en el código y los `.d.ts` generados.
191
+ - **Guía para agentes que generan slides**: [AGENTS.md](./AGENTS.md).
192
+ - **Docs y playground**: [lumina-slides](https://pailletjuanpablo.github.io/lumina-slides/).