@bebranded/bb-contents 1.0.39-beta → 1.0.41-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 +39 -204
  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.33-beta
4
+ * @version 1.0.41-beta
5
5
  * @author BeBranded
6
6
  * @license MIT
7
7
  * @website https://www.bebranded.xyz
@@ -17,9 +17,10 @@
17
17
 
18
18
  // Configuration
19
19
  const config = {
20
- version: '1.0.39-beta',
20
+ version: '1.0.41-beta',
21
21
  debug: true, // Activé temporairement pour debug
22
22
  prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
23
+ youtubeEndpoint: null, // URL du worker YouTube (à définir par l'utilisateur)
23
24
  i18n: {
24
25
  copied: 'Lien copié !'
25
26
  }
@@ -84,18 +85,12 @@
84
85
 
85
86
  this.utils.log('Initialisation v' + this.config.version);
86
87
 
87
- // Debug: Analyser l'environnement
88
- this.utils.log('=== DEBUG ENVIRONNEMENT ===');
89
- this.utils.log('Body attributes:', Array.from(document.body.attributes).map(attr => attr.name + '=' + attr.value));
90
- this.utils.log('Scripts chargés:', document.querySelectorAll('script').length);
91
- this.utils.log('Stylesheets chargés:', document.querySelectorAll('link[rel="stylesheet"]').length);
92
- this.utils.log('Marquees détectés:', document.querySelectorAll('[bb-marquee]').length);
93
- this.utils.log('Marquees déjà traités:', document.querySelectorAll('[bb-marquee][data-bb-marquee-processed]').length);
88
+ // Debug environnement supprimé pour console propre
94
89
 
95
90
  // Détection du bb-performance-boost
96
91
  this._performanceBoostDetected = document.body.hasAttribute('bb-performance-boost');
97
92
  if (this._performanceBoostDetected) {
98
- this.utils.log('bb-performance-boost détecté - mode de compatibilité activé');
93
+ // bb-performance-boost détecté - mode de compatibilité activé
99
94
  }
100
95
 
101
96
  // Déterminer la portée
@@ -105,7 +100,7 @@
105
100
  Object.keys(this.modules).forEach(function(moduleName) {
106
101
  const module = bbContents.modules[moduleName];
107
102
  if (module.detect && module.detect(scope)) {
108
- bbContents.utils.log('Module détecté:', moduleName);
103
+ // Module détecté
109
104
  try {
110
105
  module.init(scope);
111
106
  } catch (error) {
@@ -130,7 +125,7 @@
130
125
  // Vérifier les marquees non initialisés
131
126
  const marqueeElements = scope.querySelectorAll('[bb-marquee]:not([data-bb-marquee-processed])');
132
127
  if (marqueeElements.length > 0) {
133
- bbContents.utils.log('Marquees non initialisés détectés:', marqueeElements.length);
128
+ // Marquees non initialisés détectés
134
129
  needsReinit = true;
135
130
  }
136
131
 
@@ -138,7 +133,7 @@
138
133
  Object.keys(this.modules).forEach(function(moduleName) {
139
134
  const module = bbContents.modules[moduleName];
140
135
  if (module.checkFailed && module.checkFailed(scope)) {
141
- bbContents.utils.log('Module', moduleName, 'a des éléments échoués');
136
+ // Module a des éléments échoués
142
137
  needsReinit = true;
143
138
  }
144
139
  });
@@ -146,7 +141,7 @@
146
141
  // Réinitialiser si nécessaire et si on n'a pas dépassé le nombre max de tentatives
147
142
  if (needsReinit && this._initRetryCount < this._maxInitRetries) {
148
143
  this._initRetryCount++;
149
- bbContents.utils.log('Tentative de réinitialisation', this._initRetryCount, '/', this._maxInitRetries);
144
+ // Tentative de réinitialisation
150
145
 
151
146
  const delay = this._performanceBoostDetected ? 1000 * this._initRetryCount : 500 * this._initRetryCount;
152
147
  setTimeout(() => {
@@ -208,166 +203,7 @@
208
203
 
209
204
  // Modules
210
205
  bbContents.modules = {
211
- // Module SEO
212
- seo: {
213
- detect: function(scope) {
214
- return scope.querySelector('[bb-seo]') !== null;
215
- },
216
-
217
- init: function(scope) {
218
- const elements = scope.querySelectorAll('[bb-seo]');
219
- if (elements.length === 0) return;
220
-
221
- bbContents.utils.log('Module détecté: seo');
222
-
223
- elements.forEach(element => {
224
- if (element.bbProcessed) return;
225
- element.bbProcessed = true;
226
-
227
- const title = bbContents._getAttr(element, 'bb-seo-title');
228
- const description = bbContents._getAttr(element, 'bb-seo-description');
229
- const keywords = bbContents._getAttr(element, 'bb-seo-keywords');
230
-
231
- if (title) {
232
- document.title = title;
233
- }
234
-
235
- if (description) {
236
- let meta = document.querySelector('meta[name="description"]');
237
- if (!meta) {
238
- meta = document.createElement('meta');
239
- meta.name = 'description';
240
- document.head.appendChild(meta);
241
- }
242
- meta.content = description;
243
- }
244
-
245
- if (keywords) {
246
- let meta = document.querySelector('meta[name="keywords"]');
247
- if (!meta) {
248
- meta = document.createElement('meta');
249
- meta.name = 'keywords';
250
- document.head.appendChild(meta);
251
- }
252
- meta.content = keywords;
253
- }
254
- });
255
-
256
- bbContents.utils.log('Module SEO initialisé:', elements.length, 'éléments');
257
- }
258
- },
259
-
260
- // Module Images
261
- images: {
262
- detect: function(scope) {
263
- return scope.querySelector('[bb-images]') !== null;
264
- },
265
-
266
- init: function(scope) {
267
- const elements = scope.querySelectorAll('[bb-images]');
268
- if (elements.length === 0) return;
269
-
270
- bbContents.utils.log('Module détecté: images');
271
-
272
- elements.forEach(element => {
273
- if (element.bbProcessed) return;
274
- element.bbProcessed = true;
275
-
276
- const lazy = bbContents._getAttr(element, 'bb-images-lazy');
277
- const webp = bbContents._getAttr(element, 'bb-images-webp');
278
-
279
- if (lazy === 'true') {
280
- // Implémentation lazy loading basique
281
- const images = element.querySelectorAll('img');
282
- images.forEach(img => {
283
- if (!img.loading) {
284
- img.loading = 'lazy';
285
- }
286
- });
287
- }
288
-
289
- if (webp === 'true') {
290
- // Support WebP basique
291
- const images = element.querySelectorAll('img');
292
- images.forEach(img => {
293
- const src = img.src;
294
- if (src && !src.includes('.webp')) {
295
- // Logique de conversion WebP (à implémenter selon les besoins)
296
- bbContents.utils.log('Support WebP activé pour:', src);
297
- }
298
- });
299
- }
300
- });
301
-
302
- bbContents.utils.log('Module Images initialisé:', elements.length, 'éléments');
303
- }
304
- },
305
-
306
- // Module Infinite Scroll
307
- infinite: {
308
- detect: function(scope) {
309
- return scope.querySelector('[bb-infinite]') !== null;
310
- },
311
-
312
- init: function(scope) {
313
- const elements = scope.querySelectorAll('[bb-infinite]');
314
- if (elements.length === 0) return;
315
-
316
- bbContents.utils.log('Module détecté: infinite');
317
-
318
- elements.forEach(element => {
319
- if (element.bbProcessed) return;
320
- element.bbProcessed = true;
321
-
322
- const threshold = bbContents._getAttr(element, 'bb-infinite-threshold') || '0.1';
323
- const url = bbContents._getAttr(element, 'bb-infinite-url');
324
-
325
- if (!url) {
326
- bbContents.utils.log('Erreur: bb-infinite-url manquant');
327
- return;
328
- }
329
-
330
- // Implémentation basique d'infinite scroll
331
- let loading = false;
332
- let page = 1;
333
-
334
- const loadMore = () => {
335
- if (loading) return;
336
- loading = true;
337
-
338
- fetch(`${url}?page=${page}`)
339
- .then(response => response.json())
340
- .then(data => {
341
- if (data.items && data.items.length > 0) {
342
- // Ajouter le contenu
343
- element.innerHTML += data.html || '';
344
- page++;
345
- loading = false;
346
- }
347
- })
348
- .catch(error => {
349
- bbContents.utils.log('Erreur infinite scroll:', error);
350
- loading = false;
351
- });
352
- };
353
-
354
- // Observer d'intersection pour déclencher le chargement
355
- const observer = new IntersectionObserver((entries) => {
356
- entries.forEach(entry => {
357
- if (entry.isIntersecting) {
358
- loadMore();
359
- }
360
- });
361
- }, { threshold: parseFloat(threshold) });
362
-
363
- observer.observe(element);
364
- });
365
-
366
- bbContents.utils.log('Module Infinite Scroll initialisé:', elements.length, 'éléments');
367
- }
368
- },
369
-
370
- // Module Marquee - Version live 1.0.33-beta avec améliorations d'initialisation
206
+ // Module Marquee - Version live 1.0.41-beta avec modules parasites supprimés
371
207
  marquee: {
372
208
  detect: function(scope) {
373
209
  const s = scope || document;
@@ -389,7 +225,7 @@
389
225
  elements.forEach(function(element) {
390
226
  // Vérifier si l'élément a déjà été traité par un autre module
391
227
  if (element.bbProcessed || element.hasAttribute('data-bb-youtube-processed')) {
392
- bbContents.utils.log('Élément marquee déjà traité par un autre module, ignoré:', element);
228
+ // Élément marquee déjà traité par un autre module, ignoré
393
229
  return;
394
230
  }
395
231
  element.bbProcessed = true;
@@ -488,11 +324,10 @@
488
324
  // Si largeur trop petite, utiliser la largeur du parent
489
325
  const parentRect = mainBlock.parentElement.getBoundingClientRect();
490
326
  finalWidth = parentRect.width || mainBlock.parentElement.offsetWidth;
491
- bbContents.utils.log('Largeur corrigée pour marquee vertical:', finalWidth, 'px (était:', contentWidth, 'px)');
327
+ // Largeur corrigée pour marquee vertical
492
328
  }
493
329
 
494
- // Debug amélioré avec statut des images
495
- bbContents.utils.log('Debug - Largeur:', finalWidth, 'px, Hauteur:', finalHeight, 'px, Images chargées:', imagesLoaded, 'Enfants:', mainBlock.children.length, 'Vertical:', isVertical, 'Direction:', direction, 'Tentative:', retryCount + 1);
330
+ // Debug supprimé pour console propre
496
331
 
497
332
  // Vérifications robustes avant initialisation
498
333
  const hasValidDimensions = (isVertical && finalHeight > 50) || (!isVertical && finalWidth > 50);
@@ -502,11 +337,11 @@
502
337
  if (!hasValidDimensions || !imagesLoaded) {
503
338
  if (retryCount < maxRetries) {
504
339
  const delay = 300 + retryCount * 200; // Délais plus longs pour attendre les images
505
- bbContents.utils.log('Contenu/images non prêts, nouvelle tentative dans', delay, 'ms');
340
+ // Contenu/images non prêts, nouvelle tentative
506
341
  setTimeout(() => initAnimation(retryCount + 1), delay);
507
342
  return;
508
343
  } else {
509
- bbContents.utils.log('Échec d\'initialisation après', maxRetries, 'tentatives - dimensions:', finalWidth + 'x' + finalHeight, 'images chargées:', imagesLoaded);
344
+ // Échec d'initialisation après plusieurs tentatives
510
345
  return;
511
346
  }
512
347
  }
@@ -553,7 +388,7 @@
553
388
  // Démarrer l'animation
554
389
  animationId = requestAnimationFrame(animate);
555
390
 
556
- bbContents.utils.log('Marquee vertical créé avec animation JS - direction:', direction, 'taille:', contentSize + 'px', 'total:', totalSize + 'px', 'hauteur-wrapper:', height + 'px');
391
+ // Marquee vertical créé avec animation JS
557
392
 
558
393
  // Pause au survol avec transition fluide CSS + JS
559
394
  if (pauseOnHover === 'true') {
@@ -632,7 +467,7 @@
632
467
  // Démarrer l'animation
633
468
  animationId = requestAnimationFrame(animate);
634
469
 
635
- bbContents.utils.log('Marquee horizontal créé avec animation JS - direction:', direction, 'taille:', contentSize + 'px', 'total:', totalSize + 'px');
470
+ // Marquee horizontal créé avec animation JS
636
471
 
637
472
  // Pause au survol avec transition fluide CSS + JS
638
473
  if (pauseOnHover === 'true') {
@@ -685,7 +520,7 @@
685
520
 
686
521
  // Attendre window.load si pas encore déclenché
687
522
  if (document.readyState !== 'complete') {
688
- bbContents.utils.log('Attente de window.load pour initialiser le marquee');
523
+ // Attente de window.load pour initialiser le marquee
689
524
  window.addEventListener('load', () => {
690
525
  setTimeout(() => initAnimation(0), initDelay);
691
526
  });
@@ -695,7 +530,7 @@
695
530
  }
696
531
  });
697
532
 
698
- bbContents.utils.log('Module Marquee initialisé:', elements.length, 'éléments');
533
+ // Module Marquee initialisé
699
534
  }
700
535
  },
701
536
 
@@ -757,7 +592,7 @@
757
592
  init: function(scope) {
758
593
  // Vérifier si c'est un bot - pas d'appel API
759
594
  if (this.isBot()) {
760
- bbContents.utils.log('Bot détecté, pas de chargement YouTube (économie API)');
595
+ // Bot détecté, pas de chargement YouTube (économie API)
761
596
  return;
762
597
  }
763
598
 
@@ -767,12 +602,12 @@
767
602
  const elements = scope.querySelectorAll('[bb-youtube-channel]');
768
603
  if (elements.length === 0) return;
769
604
 
770
- bbContents.utils.log('Module détecté: youtube');
605
+ // Module détecté: youtube
771
606
 
772
607
  elements.forEach(element => {
773
608
  // Vérifier si l'élément a déjà été traité par un autre module
774
609
  if (element.bbProcessed || element.hasAttribute('data-bb-marquee-processed')) {
775
- bbContents.utils.log('Élément youtube déjà traité par un autre module, ignoré:', element);
610
+ // Élément youtube déjà traité par un autre module, ignoré
776
611
  return;
777
612
  }
778
613
  element.bbProcessed = true;
@@ -784,13 +619,13 @@
784
619
  const endpoint = bbContents.config.youtubeEndpoint;
785
620
 
786
621
  if (!channelId) {
787
- bbContents.utils.log('Erreur: bb-youtube-channel manquant');
622
+ // Erreur: bb-youtube-channel manquant
788
623
  return;
789
624
  }
790
625
 
791
626
  if (!endpoint) {
792
- bbContents.utils.log('Erreur: youtubeEndpoint non configuré. Utilisez bbContents.config.youtubeEndpoint = "votre-worker-url"');
793
- element.innerHTML = '<div style="padding: 20px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; color: #dc2626;"><strong>Configuration YouTube manquante</strong><br>Ajoutez : bbContents.config.youtubeEndpoint = "votre-worker-url"</div>';
627
+ // Erreur: youtubeEndpoint non configuré
628
+ 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>';
794
629
  return;
795
630
  }
796
631
 
@@ -808,7 +643,7 @@
808
643
  }
809
644
 
810
645
  if (!template) {
811
- bbContents.utils.log('Erreur: élément [bb-youtube-item] manquant');
646
+ // Erreur: élément [bb-youtube-item] manquant
812
647
  element.innerHTML = '<div style="padding: 20px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; color: #dc2626;"><strong>Template manquant</strong><br>Ajoutez un élément avec l\'attribut bb-youtube-item</div>';
813
648
  return;
814
649
  }
@@ -824,8 +659,8 @@
824
659
  const cachedData = this.cache.get(cacheKey);
825
660
 
826
661
  if (cachedData) {
827
- bbContents.utils.log('Données YouTube récupérées du cache (économie API)');
828
- this.generateYouTubeFeed(container, template, cachedData, allowShorts, language);
662
+ // Données YouTube récupérées du cache (économie API)
663
+ this.generateYouTubeFeed(container, template, cachedData.value, allowShorts, language);
829
664
  return;
830
665
  }
831
666
 
@@ -847,20 +682,20 @@
847
682
 
848
683
  // Sauvegarder en cache pour 24h
849
684
  this.cache.set(cacheKey, data);
850
- bbContents.utils.log('Données YouTube mises en cache pour 24h (économie API)');
685
+ // Données YouTube mises en cache pour 24h (économie API)
851
686
 
852
687
  this.generateYouTubeFeed(container, template, data, allowShorts, language);
853
688
  })
854
689
  .catch(error => {
855
- bbContents.utils.log('Erreur dans le module youtube:', error);
690
+ // Erreur dans le module youtube
856
691
 
857
692
  // En cas d'erreur, essayer de récupérer du cache même expiré
858
693
  const expiredCache = localStorage.getItem(cacheKey);
859
694
  if (expiredCache) {
860
695
  try {
861
696
  const cachedData = JSON.parse(expiredCache);
862
- bbContents.utils.log('Utilisation du cache expiré en cas d\'erreur API');
863
- this.generateYouTubeFeed(container, template, cachedData.value, allowShorts);
697
+ // Utilisation du cache expiré en cas d'erreur API
698
+ this.generateYouTubeFeed(container, template, cachedData.value, allowShorts, language);
864
699
  return;
865
700
  } catch (e) {
866
701
  // Ignorer les erreurs de parsing
@@ -880,7 +715,7 @@
880
715
 
881
716
  // Les vidéos sont déjà filtrées par l'API YouTube selon allowShorts
882
717
  let videos = data.items;
883
- bbContents.utils.log(`Vidéos reçues de l'API: ${videos.length} (allowShorts: ${allowShorts})`);
718
+ // Vidéos reçues de l'API
884
719
 
885
720
  // Vider le conteneur (en préservant les éléments marquee)
886
721
  const marqueeElements = container.querySelectorAll('[data-bb-marquee-processed]');
@@ -907,7 +742,7 @@
907
742
  container.appendChild(clone);
908
743
  });
909
744
 
910
- bbContents.utils.log(`YouTube Feed généré: ${videos.length} vidéos`);
745
+ // YouTube Feed généré
911
746
  },
912
747
 
913
748
  fillVideoData: function(element, videoId, snippet, language = 'fr') {
@@ -953,10 +788,10 @@
953
788
 
954
789
  // Debug: logger la qualité utilisée (en mode debug seulement)
955
790
  if (bbContents.config.debug) {
956
- bbContents.utils.log(`Thumbnail optimisée pour ${snippet.title}: ${bestQuality}`);
791
+ // Thumbnail optimisée
957
792
  }
958
793
  } else {
959
- bbContents.utils.log('Aucune thumbnail disponible pour:', snippet.title);
794
+ // Aucune thumbnail disponible
960
795
  }
961
796
  }
962
797
 
@@ -1067,7 +902,7 @@
1067
902
  });
1068
903
 
1069
904
  if (cleaned > 0) {
1070
- bbContents.utils.log(`Cache YouTube nettoyé: ${cleaned} entrées supprimées`);
905
+ // Cache YouTube nettoyé
1071
906
  }
1072
907
  } catch (e) {
1073
908
  // Ignorer les erreurs de nettoyage
@@ -1105,7 +940,7 @@
1105
940
  // Vérifier s'il y a des éléments non initialisés
1106
941
  const unprocessedMarquees = document.querySelectorAll('[bb-marquee]:not([data-bb-marquee-processed])');
1107
942
  if (unprocessedMarquees.length > 0) {
1108
- bbContents.utils.log('Éléments marquee non initialisés détectés après load, réinitialisation...');
943
+ // Éléments marquee non initialisés détectés après load, réinitialisation
1109
944
  bbContents.reinit();
1110
945
  }
1111
946
 
@@ -1113,7 +948,7 @@
1113
948
  const allImages = document.querySelectorAll('img');
1114
949
  const unloadedImages = Array.from(allImages).filter(img => !img.complete || img.naturalHeight === 0);
1115
950
  if (unloadedImages.length > 0) {
1116
- bbContents.utils.log('Images non chargées détectées:', unloadedImages.length, '- attente supplémentaire...');
951
+ // Images non chargées détectées, attente supplémentaire
1117
952
  setTimeout(() => {
1118
953
  bbContents.reinit();
1119
954
  }, 1000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bebranded/bb-contents",
3
- "version": "1.0.39-beta",
3
+ "version": "1.0.41-beta",
4
4
  "description": "Contenus additionnels français pour Webflow",
5
5
  "main": "bb-contents.js",
6
6
  "scripts": {