@bebranded/bb-contents 1.0.94-test → 1.0.95

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 +58 -32
  2. package/package.json +1 -1
package/bb-contents.js CHANGED
@@ -385,46 +385,69 @@
385
385
  const totalImages = images.length;
386
386
 
387
387
 
388
- // OPTIMISATION: Charger les images sans forcer les dimensions
388
+ // SOLUTION MOBILE : Amélioration du rendu des images sur mobile
389
+ const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) ||
390
+ (window.innerWidth <= 768 && /Chrome|CriOS/i.test(navigator.userAgent));
391
+
392
+ // OPTIMISATION: Charger les images en respectant le CSS Webflow
389
393
  images.forEach(img => {
390
- if (img.dataset.src && !img.src) {
391
- img.src = img.dataset.src;
392
- img.loading = 'eager';
393
- }
394
+ // Préserver les styles CSS existants AVANT toute modification
395
+ const computedStyle = getComputedStyle(img);
396
+ const originalObjectFit = img.style.objectFit || computedStyle.objectFit;
397
+ const originalObjectPosition = img.style.objectPosition || computedStyle.objectPosition;
398
+ const originalWidth = computedStyle.width;
399
+ const originalHeight = computedStyle.height;
394
400
 
395
- // OPTIMISATION: Préserver les styles CSS existants (object-fit, etc.)
396
- const originalObjectFit = img.style.objectFit || getComputedStyle(img).objectFit;
397
- const originalObjectPosition = img.style.objectPosition || getComputedStyle(img).objectPosition;
398
- const originalWidth = img.style.width;
399
- const originalHeight = img.style.height;
401
+ // OPTIMISATION MOBILE : Améliorer le rendu des images sur mobile
402
+ if (isMobile) {
403
+ // Forcer le rendu haute qualité sur mobile
404
+ img.style.imageRendering = 'auto';
405
+ img.style.backfaceVisibility = 'hidden';
406
+ img.style.webkitBackfaceVisibility = 'hidden';
407
+ img.style.transform = 'translateZ(0)';
408
+ img.style.webkitTransform = 'translateZ(0)';
409
+ }
400
410
 
401
- img.onload = () => {
402
- // OPTIMISATION: Restaurer les styles CSS après chargement
403
- if (originalObjectFit && originalObjectFit !== 'none') {
404
- img.style.objectFit = originalObjectFit;
405
- }
406
- if (originalObjectPosition && originalObjectPosition !== 'initial') {
407
- img.style.objectPosition = originalObjectPosition;
411
+ // Charger l'image si nécessaire
412
+ if (img.complete && img.naturalWidth > 0) {
413
+ // Image déjà chargée, ne rien toucher
414
+ imagesLoaded++;
415
+ } else {
416
+ if (img.dataset.src && !img.src) {
417
+ img.src = img.dataset.src;
408
418
  }
409
419
 
410
- // OPTIMISATION: Préserver les dimensions naturelles des images
411
- if (!originalWidth || originalWidth === '') {
412
- img.style.width = 'auto';
413
- }
414
- if (!originalHeight || originalHeight === '') {
415
- img.style.height = 'auto';
420
+ // OPTIMISATION MOBILE : Utiliser lazy loading natif au lieu de eager sur mobile
421
+ if (!img.loading) {
422
+ img.loading = isMobile ? 'lazy' : 'eager';
416
423
  }
417
424
 
418
- imagesLoaded++;
419
- };
420
- img.onerror = () => {
421
- imagesLoaded++;
422
- };
425
+ img.onload = () => {
426
+ // OPTIMISATION: Restaurer les styles CSS après chargement
427
+ if (originalObjectFit && originalObjectFit !== 'none') {
428
+ img.style.objectFit = originalObjectFit;
429
+ }
430
+ if (originalObjectPosition && originalObjectPosition !== 'initial') {
431
+ img.style.objectPosition = originalObjectPosition;
432
+ }
433
+
434
+ // OPTIMISATION MOBILE : Respecter les dimensions CSS de Webflow
435
+ // Ne PAS forcer auto si les dimensions CSS sont définies dans Webflow
436
+ // Le CSS de Webflow prend toujours le dessus
437
+
438
+ // Forcer le recalcul pour mobile (important pour le rendu)
439
+ if (isMobile) {
440
+ img.offsetHeight; // Force reflow pour meilleur rendu
441
+ }
442
+
443
+ imagesLoaded++;
444
+ };
445
+ img.onerror = () => {
446
+ imagesLoaded++;
447
+ };
448
+ }
423
449
  });
424
450
 
425
- // SOLUTION SAFARI MOBILE SIMPLE : Attendre plus longtemps
426
- const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
427
-
428
451
  // Timeout plus long sur mobile pour laisser le temps aux images de se charger
429
452
  const maxWaitTime = isMobile ? 5000 : 3000; // 5 secondes sur mobile
430
453
  let waitTimeout = 0;
@@ -451,7 +474,10 @@
451
474
  images.forEach(img => {
452
475
  if (img.dataset.src && !img.src) {
453
476
  img.src = img.dataset.src;
454
- img.loading = 'eager';
477
+ // Ne pas forcer eager sur mobile, laisser le lazy loading
478
+ if (!img.loading && !isMobile) {
479
+ img.loading = 'eager';
480
+ }
455
481
  }
456
482
  });
457
483
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bebranded/bb-contents",
3
- "version": "1.0.94-test",
3
+ "version": "1.0.95",
4
4
  "description": "Contenus additionnels français pour Webflow",
5
5
  "main": "bb-contents.js",
6
6
  "scripts": {