@bebranded/bb-contents 1.0.47-beta → 1.0.49-beta

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 (2) hide show
  1. package/bb-contents.js +72 -26
  2. package/package.json +1 -1
package/bb-contents.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * BeBranded Contents
3
3
  * Contenus additionnels français pour Webflow
4
- * @version 1.0.47-beta
4
+ * @version 1.0.49-beta
5
5
  * @author BeBranded
6
6
  * @license MIT
7
7
  * @website https://www.bebranded.xyz
@@ -22,8 +22,8 @@
22
22
 
23
23
  // Configuration
24
24
  const config = {
25
- version: '1.0.47-beta',
26
- debug: true, // Activé temporairement pour debug
25
+ version: '1.0.49-beta',
26
+ debug: false, // Debug désactivé
27
27
  prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
28
28
  youtubeEndpoint: null, // URL du worker YouTube (à définir par l'utilisateur)
29
29
  i18n: {
@@ -175,14 +175,12 @@
175
175
  checkYouTubeConfig: function() {
176
176
  // Vérifier si la configuration a été définie après le chargement
177
177
  if (this.config.youtubeEndpoint) {
178
- console.log('[DEBUG] YouTube endpoint found:', this.config.youtubeEndpoint);
179
178
  return true;
180
179
  }
181
180
 
182
181
  // Vérifier dans l'objet temporaire
183
182
  if (window._bbContentsConfig && window._bbContentsConfig.youtubeEndpoint) {
184
183
  this.config.youtubeEndpoint = window._bbContentsConfig.youtubeEndpoint;
185
- console.log('[DEBUG] YouTube endpoint found in temp config:', this.config.youtubeEndpoint);
186
184
  return true;
187
185
  }
188
186
 
@@ -255,13 +253,31 @@
255
253
  if (scope.closest && scope.closest('[data-bb-disable]')) return;
256
254
  const elements = scope.querySelectorAll(bbContents._attrSelector('marquee'));
257
255
 
258
- elements.forEach(function(element) {
256
+ // Debug: Log du nombre d'éléments marquee trouvés
257
+ console.log(`[bb-contents] Marquee init: ${elements.length} éléments trouvés`);
258
+
259
+ elements.forEach(function(element, index) {
260
+ // Debug: Log de chaque élément
261
+ console.log(`[bb-contents] Marquee ${index + 1}:`, {
262
+ element: element,
263
+ alreadyProcessed: element.bbProcessed,
264
+ hasYouTubeProcessed: element.hasAttribute('data-bb-youtube-processed'),
265
+ hasMarqueeProcessed: element.hasAttribute('data-bb-marquee-processed'),
266
+ attributes: {
267
+ speed: element.getAttribute('bb-marquee-speed'),
268
+ direction: element.getAttribute('bb-marquee-direction'),
269
+ orientation: element.getAttribute('bb-marquee-orientation'),
270
+ height: element.getAttribute('bb-marquee-height')
271
+ }
272
+ });
259
273
  // Vérifier si l'élément a déjà été traité par un autre module
260
274
  if (element.bbProcessed || element.hasAttribute('data-bb-youtube-processed')) {
261
275
  // Élément marquee déjà traité par un autre module, ignoré
276
+ console.log(`[bb-contents] Marquee ${index + 1}: IGNORÉ (déjà traité)`);
262
277
  return;
263
278
  }
264
279
  element.bbProcessed = true;
280
+ console.log(`[bb-contents] Marquee ${index + 1}: TRAITEMENT EN COURS`);
265
281
 
266
282
  // Récupérer les options
267
283
  const speed = bbContents._getAttr(element, 'bb-marquee-speed') || '100';
@@ -338,10 +354,14 @@
338
354
 
339
355
  // Fonction pour initialiser l'animation avec vérification robuste des dimensions
340
356
  const initAnimation = (retryCount = 0) => {
357
+ console.log(`[bb-contents] Marquee ${index + 1}: initAnimation tentative ${retryCount + 1}`);
358
+
341
359
  // Vérifier que les images sont chargées
342
360
  const images = mainBlock.querySelectorAll('img');
343
361
  const imagesLoaded = Array.from(images).every(img => img.complete && img.naturalHeight > 0);
344
362
 
363
+ console.log(`[bb-contents] Marquee ${index + 1}: Images chargées: ${imagesLoaded} (${images.length} images)`);
364
+
345
365
  // Attendre que le contenu soit dans le DOM et que les images soient chargées
346
366
  requestAnimationFrame(() => {
347
367
  // Calcul plus robuste des dimensions
@@ -349,6 +369,13 @@
349
369
  const contentWidth = rect.width || mainBlock.offsetWidth;
350
370
  const contentHeight = rect.height || mainBlock.offsetHeight;
351
371
 
372
+ console.log(`[bb-contents] Marquee ${index + 1}: Dimensions calculées:`, {
373
+ rect: rect,
374
+ contentWidth: contentWidth,
375
+ contentHeight: contentHeight,
376
+ isVertical: isVertical
377
+ });
378
+
352
379
  // Pour les marquees verticaux, utiliser la largeur du parent si nécessaire
353
380
  let finalWidth = contentWidth;
354
381
  let finalHeight = contentHeight;
@@ -364,21 +391,49 @@
364
391
 
365
392
  // Vérifications robustes avant initialisation
366
393
  const hasValidDimensions = (isVertical && finalHeight > 50) || (!isVertical && finalWidth > 50);
394
+ const hasContent = mainBlock.innerHTML.trim().length > 0;
367
395
  const maxRetries = 8; // Plus de tentatives pour attendre les images
368
396
 
369
- // Si pas de contenu valide ou images pas chargées, réessayer
370
- if (!hasValidDimensions || !imagesLoaded) {
397
+ // Fallback: si pas de dimensions valides mais qu'il y a du contenu, forcer l'initialisation
398
+ const shouldForceInit = !hasValidDimensions && hasContent && retryCount >= 3;
399
+
400
+ console.log(`[bb-contents] Marquee ${index + 1}: Vérifications:`, {
401
+ hasValidDimensions: hasValidDimensions,
402
+ hasContent: hasContent,
403
+ imagesLoaded: imagesLoaded,
404
+ retryCount: retryCount,
405
+ maxRetries: maxRetries,
406
+ shouldForceInit: shouldForceInit
407
+ });
408
+
409
+ // Si pas de contenu valide ou images pas chargées, réessayer (sauf si on force)
410
+ if ((!hasValidDimensions || !imagesLoaded) && !shouldForceInit) {
371
411
  if (retryCount < maxRetries) {
372
412
  const delay = 300 + retryCount * 200; // Délais plus longs pour attendre les images
413
+ console.log(`[bb-contents] Marquee ${index + 1}: RETRY dans ${delay}ms (dimensions: ${hasValidDimensions}, images: ${imagesLoaded})`);
373
414
  // Contenu/images non prêts, nouvelle tentative
374
415
  setTimeout(() => initAnimation(retryCount + 1), delay);
375
416
  return;
376
417
  } else {
377
418
  // Échec d'initialisation après plusieurs tentatives
419
+ console.log(`[bb-contents] Marquee ${index + 1}: ÉCHEC après ${maxRetries} tentatives`);
378
420
  return;
379
421
  }
380
422
  }
381
423
 
424
+ if (shouldForceInit) {
425
+ console.log(`[bb-contents] Marquee ${index + 1}: FORÇAGE DE L'INITIALISATION (fallback)`);
426
+ // Utiliser des dimensions par défaut si les vraies dimensions ne sont pas disponibles
427
+ if (isVertical && finalHeight <= 50) {
428
+ finalHeight = 200; // Hauteur par défaut pour vertical
429
+ }
430
+ if (!isVertical && finalWidth <= 50) {
431
+ finalWidth = 300; // Largeur par défaut pour horizontal
432
+ }
433
+ }
434
+
435
+ console.log(`[bb-contents] Marquee ${index + 1}: INITIALISATION DE L'ANIMATION`);
436
+
382
437
  if (isVertical) {
383
438
  // Animation JavaScript pour le vertical
384
439
  const contentSize = finalHeight;
@@ -555,11 +610,17 @@
555
610
  if (document.readyState !== 'complete') {
556
611
  // Attente de window.load pour initialiser le marquee
557
612
  window.addEventListener('load', () => {
558
- setTimeout(() => initAnimation(0), initDelay);
613
+ setTimeout(() => {
614
+ initAnimation(0);
615
+ console.log(`[bb-contents] Marquee ${index + 1}: Animation démarrée`);
616
+ }, initDelay);
559
617
  });
560
618
  } else {
561
619
  // window.load déjà déclenché, initialiser directement
562
- setTimeout(() => initAnimation(0), initDelay);
620
+ setTimeout(() => {
621
+ initAnimation(0);
622
+ console.log(`[bb-contents] Marquee ${index + 1}: Animation démarrée`);
623
+ }, initDelay);
563
624
  }
564
625
  });
565
626
 
@@ -633,7 +694,6 @@
633
694
  this.cleanCache();
634
695
 
635
696
  const elements = scope.querySelectorAll('[bb-youtube-channel]');
636
- console.log('[DEBUG] YouTube elements found:', elements.length);
637
697
  if (elements.length === 0) return;
638
698
 
639
699
  // Module détecté: youtube
@@ -666,7 +726,6 @@
666
726
  // Vérifier la configuration au moment de l'initialisation
667
727
  const endpoint = bbContents.checkYouTubeConfig() ? bbContents.config.youtubeEndpoint : null;
668
728
 
669
- console.log('[DEBUG] YouTube element config:', {channelId, videoCount, allowShorts, language, endpoint});
670
729
 
671
730
  if (!channelId) {
672
731
  return;
@@ -678,7 +737,6 @@
678
737
  const retries = parseInt(retryCount);
679
738
 
680
739
  if (retries < 50) { // 50 * 100ms = 5 secondes max
681
- console.log('[DEBUG] YouTube endpoint not configured yet, waiting... (attempt', retries + 1, ')');
682
740
  element.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Configuration YouTube en cours...</div>';
683
741
  element.setAttribute('data-youtube-retry-count', (retries + 1).toString());
684
742
 
@@ -689,7 +747,6 @@
689
747
  return;
690
748
  } else {
691
749
  // Timeout après 5 secondes
692
- console.log('[DEBUG] YouTube endpoint configuration timeout');
693
750
  element.innerHTML = '<div style="padding: 20px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; color: #dc2626;"><strong>Configuration YouTube manquante</strong><br>Ajoutez dans le &lt;head&gt; :<br><code style="display: block; background: #f3f4f6; padding: 10px; margin: 10px 0; border-radius: 4px; font-family: monospace;">&lt;script&gt;<br>bbContents.config.youtubeEndpoint = \'votre-worker-url\';<br>&lt;/script&gt;</code></div>';
694
751
  return;
695
752
  }
@@ -725,7 +782,6 @@
725
782
 
726
783
  if (cachedData && cachedData.value) {
727
784
  // Données YouTube récupérées du cache (économie API)
728
- console.log('[DEBUG] Using cached YouTube data for element');
729
785
  this.generateYouTubeFeed(container, template, cachedData.value, allowShorts, language);
730
786
  return;
731
787
  }
@@ -733,7 +789,6 @@
733
789
  // Vérifier si un appel API est déjà en cours pour cette clé
734
790
  const loadingKey = `loading_${cacheKey}`;
735
791
  if (window[loadingKey]) {
736
- console.log('[DEBUG] API call already in progress, waiting...');
737
792
  // Attendre que l'autre appel se termine
738
793
  const checkLoading = () => {
739
794
  if (!window[loadingKey]) {
@@ -759,17 +814,14 @@
759
814
  container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Chargement des vidéos YouTube...</div>';
760
815
 
761
816
  // Appeler l'API via le Worker
762
- console.log('[DEBUG] Fetching YouTube data from:', `${endpoint}?channelId=${channelId}&maxResults=${videoCount}&allowShorts=${allowShorts}`);
763
817
  fetch(`${endpoint}?channelId=${channelId}&maxResults=${videoCount}&allowShorts=${allowShorts}`)
764
818
  .then(response => {
765
- console.log('[DEBUG] YouTube API response status:', response.status);
766
819
  if (!response.ok) {
767
820
  throw new Error(`HTTP ${response.status}`);
768
821
  }
769
822
  return response.json();
770
823
  })
771
824
  .then(data => {
772
- console.log('[DEBUG] YouTube API data received:', data);
773
825
  if (data.error) {
774
826
  throw new Error(data.error.message || 'Erreur API YouTube');
775
827
  }
@@ -784,7 +836,7 @@
784
836
  window[loadingKey] = false;
785
837
  })
786
838
  .catch(error => {
787
- console.error('[DEBUG] YouTube API error:', error);
839
+ console.error('Erreur API YouTube:', error);
788
840
  // Erreur dans le module youtube
789
841
 
790
842
  // Libérer le verrou en cas d'erreur
@@ -795,12 +847,10 @@
795
847
  if (expiredCache) {
796
848
  try {
797
849
  const cachedData = JSON.parse(expiredCache);
798
- console.log('[DEBUG] Using expired cache:', cachedData);
799
850
  // Utilisation du cache expiré en cas d'erreur API
800
851
  this.generateYouTubeFeed(container, template, cachedData.value, allowShorts, language);
801
852
  return;
802
853
  } catch (e) {
803
- console.error('[DEBUG] Cache parsing error:', e);
804
854
  // Ignorer les erreurs de parsing
805
855
  }
806
856
  }
@@ -810,16 +860,13 @@
810
860
  },
811
861
 
812
862
  generateYouTubeFeed: function(container, template, data, allowShorts, language = 'fr') {
813
- console.log('[DEBUG] generateYouTubeFeed called with data:', data);
814
863
  if (!data || !data.items || data.items.length === 0) {
815
- console.log('[DEBUG] No videos found in data or data is undefined');
816
864
  container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Aucune vidéo trouvée</div>';
817
865
  return;
818
866
  }
819
867
 
820
868
  // Les vidéos sont déjà filtrées par l'API YouTube selon allowShorts
821
869
  let videos = data.items;
822
- console.log('[DEBUG] Processing', videos.length, 'videos');
823
870
  // Vidéos reçues de l'API
824
871
 
825
872
  // Vider le conteneur (en préservant les éléments marquee)
@@ -1023,7 +1070,6 @@
1023
1070
  window.configureYouTube = function(endpoint) {
1024
1071
  if (bbContents) {
1025
1072
  bbContents.config.youtubeEndpoint = endpoint;
1026
- console.log('[DEBUG] YouTube endpoint configured globally:', endpoint);
1027
1073
  // Réinitialiser les modules YouTube
1028
1074
  bbContents.reinit();
1029
1075
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bebranded/bb-contents",
3
- "version": "1.0.47-beta",
3
+ "version": "1.0.49-beta",
4
4
  "description": "Contenus additionnels français pour Webflow",
5
5
  "main": "bb-contents.js",
6
6
  "scripts": {