libreria-astro-lefebvre 0.0.49 → 0.0.51

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 (45) hide show
  1. package/README.md +68 -0
  2. package/package.json +12 -4
  3. package/src/carbins/AstroButton.ts +2 -14
  4. package/src/carbins/Contenido_2025_Alcorcon.ts +1 -1
  5. package/src/carbins/Contenido_2025_Malaga.ts +1 -1
  6. package/src/carbins/Contenido_2025_Montevideo.ts +1 -1
  7. package/src/carbins/Formulario_2025_Seul.ts +1 -1
  8. package/src/carbins/Formulario_2025_Teruel.ts +2 -2
  9. package/src/carbins/GeometricShapeCard.ts +1 -1
  10. package/src/carbins/ImageTextSimple.ts +1 -1
  11. package/src/carbins/Imagen_2025_Bogota.ts +1 -1
  12. package/src/carbins/Imagen_2025_Fukushima.ts +1 -1
  13. package/src/carbins/TextImageBackground.ts +1 -1
  14. package/src/carbins/TextImageBlock.ts +1 -1
  15. package/src/carbins/TextImageCard.ts +1 -1
  16. package/src/carbins/TextImageHeader.ts +1 -1
  17. package/src/components/Astro/Cabecera_2025_Madrid.astro +1 -1
  18. package/src/components/Astro/Contenido_2025_Alcorcon.astro +5 -3
  19. package/src/components/Astro/Contenido_2025_Malaga.astro +4 -2
  20. package/src/components/Astro/Contenido_2025_Montevideo.astro +3 -3
  21. package/src/components/Astro/CorpFooter.astro +1 -1
  22. package/src/components/Astro/CorpNavigation.astro +2 -2
  23. package/src/components/Astro/Footer_2025_Napoles.astro +1 -1
  24. package/src/components/Astro/Formulario_2025_Seul.astro +3 -1
  25. package/src/components/Astro/Formulario_2025_Teruel.astro +5 -2
  26. package/src/components/Astro/GeometricShape.astro +4 -1
  27. package/src/components/Astro/GeometricShapeCard.astro +4 -1
  28. package/src/components/Astro/HeaderCorporativo.astro +2 -2
  29. package/src/components/Astro/ImageTextSimple.astro +5 -1
  30. package/src/components/Astro/Imagen_2025_Bogota.astro +30 -16
  31. package/src/components/Astro/Imagen_2025_Fukushima.astro +5 -2
  32. package/src/components/Astro/Repetidor_2025_Cabra.astro +1 -1
  33. package/src/components/Astro/Repetidor_2025_Orcasitas.astro +2 -2
  34. package/src/components/Astro/Repetidor_2025_Oslo.astro +1 -1
  35. package/src/components/Astro/Repetidor_2025_Yakarta.astro +1 -1
  36. package/src/components/Astro/TextImageBackground.astro +6 -1
  37. package/src/components/Astro/TextImageBlock.astro +5 -1
  38. package/src/components/Astro/TextImageCard.astro +5 -1
  39. package/src/components/Astro/TextImageHeader.astro +5 -1
  40. package/src/components/Astro/Video_2025_Polop.astro +1 -1
  41. package/src/components/LimboImage.astro +89 -0
  42. package/src/index.ts +2 -0
  43. package/src/lib/functions.js +171 -0
  44. package/src/limbo/LimboProvider.astro +17 -1
  45. package/src/limbo/init.ts +138 -17
package/src/limbo/init.ts CHANGED
@@ -1,16 +1,38 @@
1
1
  /**
2
2
  * Limbo Integration Module for libreria-astro-lefebvre
3
3
  *
4
+ * v2.0 - Actualizado para limbo-component v2.0
5
+ *
4
6
  * Este módulo gestiona la inicialización y configuración de limbo-component
5
7
  * para ser usado en cualquier portal que consuma esta librería.
8
+ *
9
+ * Soporta configuración via data attributes en inputs HTML:
10
+ * - data-mandatorycrops: JSON array de crops obligatorios
11
+ * - data-modeui: full | gallery-only | upload-only | crop-only
12
+ * - data-returntype: url | assetId | object | json | base64
13
+ * - data-allowadditionalcrops: true | false
14
+ * - data-maxcrops: number
15
+ * - data-buttontext: texto personalizado del botón
6
16
  */
7
17
 
18
+ export interface MandatoryCrop {
19
+ label: string;
20
+ width?: number;
21
+ height?: number;
22
+ required?: boolean;
23
+ preset_aspect?: string;
24
+ }
25
+
8
26
  export interface LimboConfig {
9
27
  publicKey: string;
10
28
  prod?: boolean;
11
29
  selector?: string;
12
- defaultReturnType?: 'url' | 'assetId' | 'object' | 'json' | 'base64';
13
- sizeModal?: 'small' | 'medium' | 'large' | 'xlarge' | 'fullscreen';
30
+ defaultReturnType?: "url" | "assetId" | "object" | "json" | "base64";
31
+ defaultModeUI?: "full" | "gallery-only" | "upload-only" | "crop-only";
32
+ sizeModal?: "small" | "medium" | "large" | "xlarge" | "fullscreen";
33
+ defaultButtonText?: string;
34
+ allowAdditionalCrops?: boolean;
35
+ maxCrops?: number;
14
36
  onSelect?: (data: any) => void;
15
37
  onError?: (error: Error) => void;
16
38
  }
@@ -27,14 +49,18 @@ export function generateLimboInitScript(config: LimboConfig): string {
27
49
  const {
28
50
  publicKey,
29
51
  prod = false,
30
- selector = '.js-limbo',
31
- defaultReturnType = 'json',
32
- sizeModal = 'xlarge'
52
+ selector = ".js-limbo",
53
+ defaultReturnType = "json",
54
+ defaultModeUI = "full",
55
+ sizeModal = "xlarge",
56
+ defaultButtonText = "Seleccionar imagen",
57
+ allowAdditionalCrops = true,
58
+ maxCrops = 10,
33
59
  } = config;
34
60
 
35
61
  // URL del proxy para evitar CORS (usa endpoint local del portal)
36
62
  // El proxy está en /api/limbo-token del portal que consume la librería
37
- const tokenProxyUrl = '/api/limbo-token';
63
+ const tokenProxyUrl = "/api/limbo-token";
38
64
 
39
65
  return `
40
66
  (function() {
@@ -79,11 +105,41 @@ export function generateLimboInitScript(config: LimboConfig): string {
79
105
  }
80
106
  }
81
107
 
108
+ // Estado de inicialización
109
+ var initRetrys = 0;
110
+ var maxRetrys = 20;
111
+
112
+ // Función global para re-escanear inputs (útil después de hydration de Vue/React)
113
+ window.LimboRescan = function(selector) {
114
+ var targetSelector = selector || '${selector}';
115
+ var inputs = document.querySelectorAll(targetSelector);
116
+ var processed = 0;
117
+ console.log('[Limbo] Rescan manual: buscando inputs con selector', targetSelector);
118
+ inputs.forEach(function(input) {
119
+ if (input.tagName === 'INPUT' && !input.dataset.limboProcessed) {
120
+ try {
121
+ Limbo.autoInputs._processInput(input);
122
+ input.dataset.limboProcessed = 'true';
123
+ processed++;
124
+ } catch (e) {
125
+ console.error('[Limbo] Error procesando input:', e);
126
+ }
127
+ }
128
+ });
129
+ console.log('[Limbo] Rescan completado:', processed, 'inputs procesados de', inputs.length, 'encontrados');
130
+ return processed;
131
+ };
132
+
82
133
  // Esperamos a que Limbo esté disponible
83
134
  function initLimbo() {
84
135
  if (typeof Limbo === 'undefined') {
85
- console.warn('[Limbo] Limbo no está cargado. Reintentando...');
86
- setTimeout(initLimbo, 100);
136
+ initRetrys++;
137
+ if (initRetrys <= maxRetrys) {
138
+ console.warn('[Limbo] Limbo no está cargado. Reintentando... (' + initRetrys + '/' + maxRetrys + ')');
139
+ setTimeout(initLimbo, 100);
140
+ } else {
141
+ console.error('[Limbo] No se pudo cargar Limbo después de ' + maxRetrys + ' intentos.');
142
+ }
87
143
  return;
88
144
  }
89
145
 
@@ -104,10 +160,17 @@ export function generateLimboInitScript(config: LimboConfig): string {
104
160
  // Configurar auto-inputs para detectar elementos con el selector
105
161
  Limbo.configureAutoInputs({
106
162
  selector: '${selector}',
107
- buttonText: 'Seleccionar imagen',
163
+ buttonText: '${defaultButtonText}',
108
164
  returnType: '${defaultReturnType}',
165
+ modeUI: '${defaultModeUI}',
166
+ allowAdditionalCrops: ${allowAdditionalCrops},
167
+ maxCrops: ${maxCrops},
168
+ // 🔧 Los recortes se guardan en Limbo para garantizar persistencia
169
+ // Los recortes del page-builder se pueden identificar por su nombre (contienen dimensiones)
170
+ localCropsOnly: false,
109
171
 
110
172
  // Parsear configuración del input desde datasets
173
+ // Los valores del dataset tienen prioridad sobre los defaults
111
174
  parseInputConfig: function(input) {
112
175
  var config = {};
113
176
 
@@ -130,11 +193,68 @@ export function generateLimboInitScript(config: LimboConfig): string {
130
193
  config.modeUI = input.dataset.modeui;
131
194
  }
132
195
 
196
+ // Parsear allowAdditionalCrops
197
+ if (input.dataset.allowadditionalcrops !== undefined) {
198
+ config.allowAdditionalCrops = input.dataset.allowadditionalcrops === 'true';
199
+ }
200
+
201
+ // Parsear maxCrops
202
+ if (input.dataset.maxcrops) {
203
+ config.maxCrops = parseInt(input.dataset.maxcrops, 10);
204
+ }
205
+
206
+ // Parsear buttonText personalizado
207
+ if (input.dataset.buttontext) {
208
+ config.buttonText = input.dataset.buttontext;
209
+ }
210
+
133
211
  return config;
134
212
  }
135
213
  });
136
214
 
137
215
  console.log('[Limbo] Integración configurada. Buscando inputs con selector: ${selector}');
216
+
217
+ // Debug: Verificar que el observer esté activo
218
+ console.log('[Limbo] AutoInputs stats:', Limbo.autoInputs?.getStats?.() || 'N/A');
219
+
220
+ // Debug: Escanear manualmente después de un delay para Vue/React hydration
221
+ setTimeout(function() {
222
+ console.log('[Limbo] Re-escaneando inputs después de hydration...');
223
+ var inputs = document.querySelectorAll('${selector}');
224
+ console.log('[Limbo] Encontrados ' + inputs.length + ' inputs con selector ${selector}');
225
+ inputs.forEach(function(input, idx) {
226
+ console.log('[Limbo] Input ' + idx + ':', input.tagName, input.className, input.id || input.name);
227
+ // Forzar procesamiento si es un input válido
228
+ if (input.tagName === 'INPUT' && !input.dataset.limboProcessed) {
229
+ try {
230
+ Limbo.autoInputs._processInput(input);
231
+ input.dataset.limboProcessed = 'true';
232
+ console.log('[Limbo] Input procesado manualmente:', input.id || input.name);
233
+ } catch (e) {
234
+ console.error('[Limbo] Error procesando input:', e);
235
+ }
236
+ }
237
+ });
238
+ }, 1000); // Esperar 1 segundo para Vue hydration
239
+
240
+ // Segunda pasada después de 2.5 segundos para componentes Vue más lentos
241
+ setTimeout(function() {
242
+ var inputs = document.querySelectorAll('${selector}');
243
+ var pendingInputs = Array.from(inputs).filter(function(input) {
244
+ return input.tagName === 'INPUT' && !input.dataset.limboProcessed;
245
+ });
246
+ if (pendingInputs.length > 0) {
247
+ console.log('[Limbo] Segunda pasada: procesando ' + pendingInputs.length + ' inputs pendientes');
248
+ pendingInputs.forEach(function(input) {
249
+ try {
250
+ Limbo.autoInputs._processInput(input);
251
+ input.dataset.limboProcessed = 'true';
252
+ } catch (e) {
253
+ console.error('[Limbo] Error procesando input:', e);
254
+ }
255
+ });
256
+ }
257
+ }, 2500);
138
258
  }
139
259
 
140
260
  // Iniciar cuando el DOM esté listo
@@ -150,25 +270,26 @@ export function generateLimboInitScript(config: LimboConfig): string {
150
270
  /**
151
271
  * Genera las URLs de los assets de Limbo (CSS y JS)
152
272
  */
153
- export function getLimboAssetUrls(options: { prod?: boolean; version?: string } = {}) {
154
- const { prod = false, version = 'latest' } = options;
155
-
273
+ export function getLimboAssetUrls(
274
+ options: { prod?: boolean; version?: string } = {}
275
+ ) {
276
+ const { prod = false, version = "latest" } = options;
156
277
  // En producción, usar CDN de npm o URL de producción
157
278
  if (prod) {
158
279
  return {
159
280
  css: `https://unpkg.com/limbo-component@${version}/dist/limbo.css`,
160
- js: `https://unpkg.com/limbo-component@${version}/dist/limbo.min.js`
281
+ js: `https://unpkg.com/limbo-component@${version}/dist/limbo.min.js`,
161
282
  };
162
283
  }
163
284
 
164
- // En desarrollo, usar el build local (npm link)
285
+ // En desarrollo, usar el build local desde public/limbo
165
286
  return {
166
- css: '/node_modules/limbo-component/dist/limbo.css',
167
- js: '/node_modules/limbo-component/dist/limbo.min.js'
287
+ css: "/limbo/limbo.css",
288
+ js: "/limbo/limbo.min.js",
168
289
  };
169
290
  }
170
291
 
171
292
  export default {
172
293
  generateLimboInitScript,
173
- getLimboAssetUrls
294
+ getLimboAssetUrls,
174
295
  };