@bebranded/bb-contents 1.0.137 → 1.0.139

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 +31 -14
  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.137
4
+ * @version 1.0.139
5
5
  * @author BeBranded
6
6
  * @license MIT
7
7
  * @website https://www.bebranded.xyz
@@ -32,11 +32,11 @@
32
32
  window._bbContentsInitialized = true;
33
33
 
34
34
  // Log de démarrage simple (une seule fois)
35
- console.log('bb-contents | v1.0.137');
35
+ console.log('bb-contents | v1.0.139');
36
36
 
37
37
  // Configuration
38
38
  const config = {
39
- version: '1.0.137',
39
+ version: '1.0.139',
40
40
  debug: false, // Debug désactivé pour rendu propre
41
41
  prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
42
42
  youtubeEndpoint: null, // URL du worker YouTube (à définir par l'utilisateur)
@@ -394,9 +394,10 @@
394
394
  const repeatBlock1 = mainBlock.cloneNode(true);
395
395
  const repeatBlock2 = mainBlock.cloneNode(true);
396
396
 
397
- // Pour les marquees horizontaux, calculer la hauteur avant de mettre en absolute
397
+ // Pour les marquees horizontaux, calculer la hauteur ET la largeur avant de mettre en absolute
398
+ let preCalculatedContentSize = null;
398
399
  if (!isVertical) {
399
- // Temporairement mettre scrollContainer en relative pour calculer la hauteur
400
+ // Temporairement mettre scrollContainer en relative pour calculer les dimensions
400
401
  scrollContainer.style.position = 'relative';
401
402
  scrollContainer.appendChild(mainBlock);
402
403
  scrollContainer.appendChild(repeatBlock1);
@@ -426,6 +427,10 @@
426
427
  mainContainer.style.height = maxHeight + 'px';
427
428
  }
428
429
 
430
+ // IMPORTANT: Calculer contentSize AVANT de mettre en absolute
431
+ // Car une fois en absolute, offsetWidth peut être 0
432
+ preCalculatedContentSize = mainBlock.offsetWidth;
433
+
429
434
  // Maintenant mettre scrollContainer en absolute
430
435
  scrollContainer.style.position = 'absolute';
431
436
  scrollContainer.style.height = '100%';
@@ -447,18 +452,23 @@
447
452
  const initDelay = isVertical ? 500 : 300;
448
453
  setTimeout(() => {
449
454
  this.initAnimation(element, scrollContainer, mainBlock, {
450
- speed, direction, pauseOnHover, gap, isVertical, useAutoHeight
455
+ speed, direction, pauseOnHover, gap, isVertical, useAutoHeight, preCalculatedContentSize
451
456
  });
452
457
  }, initDelay);
453
458
  });
454
459
  },
455
460
 
456
461
  initAnimation: function(element, scrollContainer, mainBlock, options) {
457
- const { speed, direction, pauseOnHover, gap, isVertical, useAutoHeight } = options;
462
+ const { speed, direction, pauseOnHover, gap, isVertical, useAutoHeight, preCalculatedContentSize } = options;
458
463
 
459
464
  // Calculer les dimensions
460
- const contentSize = isVertical ? mainBlock.offsetHeight : mainBlock.offsetWidth;
461
-
465
+ // Pour horizontal, utiliser la valeur pré-calculée si disponible (calculée avant position absolute)
466
+ let contentSize;
467
+ if (!isVertical && preCalculatedContentSize && preCalculatedContentSize > 0) {
468
+ contentSize = preCalculatedContentSize;
469
+ } else {
470
+ contentSize = isVertical ? mainBlock.offsetHeight : mainBlock.offsetWidth;
471
+ }
462
472
 
463
473
  if (contentSize === 0) {
464
474
  setTimeout(() => this.initAnimation(element, scrollContainer, mainBlock, options), 200);
@@ -478,11 +488,18 @@
478
488
  speed, direction, gap, isVertical, useAutoHeight, contentSize, gapSize
479
489
  });
480
490
  } else {
481
- // Solution standard : créer les copies maintenant (les navigateurs non-Safari gèrent mieux)
482
- const repeatBlock1 = mainBlock.cloneNode(true);
483
- const repeatBlock2 = mainBlock.cloneNode(true);
484
- scrollContainer.appendChild(repeatBlock1);
485
- scrollContainer.appendChild(repeatBlock2);
491
+ // Solution standard : créer les copies seulement si elles n'existent pas déjà
492
+ // (elles ont peut-être été créées pour le calcul de hauteur en horizontal)
493
+ // Utiliser children.length au lieu de querySelectorAll pour compter uniquement les enfants directs
494
+ const hasCopies = scrollContainer.children.length >= 3; // mainBlock + 2 copies
495
+
496
+ if (!hasCopies) {
497
+ // Créer les copies maintenant (les navigateurs non-Safari gèrent mieux)
498
+ const repeatBlock1 = mainBlock.cloneNode(true);
499
+ const repeatBlock2 = mainBlock.cloneNode(true);
500
+ scrollContainer.appendChild(repeatBlock1);
501
+ scrollContainer.appendChild(repeatBlock2);
502
+ }
486
503
 
487
504
  // Solution standard pour autres navigateurs
488
505
  this.initStandardAnimation(element, scrollContainer, mainBlock, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bebranded/bb-contents",
3
- "version": "1.0.137",
3
+ "version": "1.0.139",
4
4
  "description": "Contenus additionnels français pour Webflow",
5
5
  "main": "bb-contents.js",
6
6
  "scripts": {