@wix/editor-react-components 1.2500.0 → 1.2501.0

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.
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
- import { f as fastdom } from "./fastdom.js";
3
- import { i as imageKit, g as getPlaceholder, a as getData, b as alignTypes, f as fittingTypes, c as getFileExtension, d as fileType, M as MEDIA_ROOT_URL, S as STATIC_MEDIA_URL$1 } from "./index5.js";
2
+ import { f as fastdom, i as initCustomElement$1 } from "./customElementInit.js";
3
+ import { I as Image } from "./Image.js";
4
4
  function _extends() {
5
5
  return _extends = Object.assign ? Object.assign.bind() : function(n) {
6
6
  for (var e = 1; e < arguments.length; e++) {
@@ -12,7 +12,7 @@ function _extends() {
12
12
  }
13
13
  const videoContainer = "videoContainer__Eyxxe";
14
14
  const video = "video__YuKrH";
15
- const styles$1 = {
15
+ const styles = {
16
16
  videoContainer,
17
17
  video
18
18
  };
@@ -346,7 +346,7 @@ function wowVideoFactory(services, contextWindow) {
346
346
  }
347
347
  };
348
348
  }
349
- function init$1(contextWindow, services) {
349
+ function init(contextWindow, services) {
350
350
  contextWindow = contextWindow || window;
351
351
  const elementName = "wow-video";
352
352
  if (contextWindow.customElements.get(elementName) === void 0) {
@@ -372,7 +372,7 @@ function init$1(contextWindow, services) {
372
372
  }
373
373
  return;
374
374
  }
375
- function initCustomElement$1(contextWindow, services) {
375
+ function initCustomElement(contextWindow, services) {
376
376
  if (contextWindow === void 0) {
377
377
  contextWindow = null;
378
378
  }
@@ -380,657 +380,19 @@ function initCustomElement$1(contextWindow, services) {
380
380
  services = {};
381
381
  }
382
382
  const actualWindow = contextWindow || window;
383
- init$1(actualWindow, services);
384
- }
385
- const image = "image__OIbFL";
386
- const styles = {
387
- image
388
- };
389
- const { STATIC_MEDIA_URL } = imageKit;
390
- const fetchLQIP = ({ fittingType, src, target, options }) => {
391
- const placeholder = getPlaceholder(fittingType, src, target, {
392
- ...options,
393
- autoEncode: true
394
- });
395
- if ((placeholder == null ? void 0 : placeholder.uri) && !/^[a-z]+:/.test(placeholder.uri)) {
396
- placeholder.uri = `${STATIC_MEDIA_URL}${placeholder.uri}`;
397
- }
398
- return placeholder;
399
- };
400
- const SCHEME_RE = /^[a-z]+:/;
401
- const Image = (props) => {
402
- var _a, _b;
403
- const { id, containerId, uri, alt, name = "", role, width, height, displayMode, devicePixelRatio, quality, alignType, bgEffectName = "", focalPoint, upscaleMethod, className = "", crop, imageStyles = {}, targetWidth, targetHeight, targetScale, onLoad = () => {
404
- }, onError = () => {
405
- }, shouldUseLQIP, containerWidth, containerHeight, getPlaceholder: getPlaceholder2, isInFirstFold, placeholderTransition, socialAttrs, isSEOBot, skipMeasure, hasAnimation, encoding, isFluidLayout, baseHostURL } = props;
406
- const imageRef = React.useRef(null);
407
- let hasSsrSrc = "";
408
- const hasBlurTransition = placeholderTransition === "blur";
409
- const ssrImageData = React.useRef(null);
410
- if (!ssrImageData.current) {
411
- if (getPlaceholder2 || shouldUseLQIP || isInFirstFold || isSEOBot) {
412
- const options = {
413
- upscaleMethod,
414
- ...quality ? quality : {},
415
- shouldLoadHQImage: isInFirstFold,
416
- isSEOBot,
417
- hasAnimation,
418
- encoding,
419
- baseHostURL
420
- };
421
- ssrImageData.current = (getPlaceholder2 || fetchLQIP)({
422
- fittingType: displayMode,
423
- src: {
424
- id: uri,
425
- width,
426
- height,
427
- crop,
428
- name,
429
- focalPoint
430
- },
431
- target: {
432
- width: containerWidth,
433
- height: containerHeight,
434
- alignment: alignType,
435
- htmlTag: "img"
436
- },
437
- options
438
- });
439
- hasSsrSrc = !ssrImageData.current.transformed || isInFirstFold || isSEOBot ? "" : "true";
440
- } else {
441
- ssrImageData.current = {
442
- uri: void 0,
443
- css: { img: {} },
444
- attr: { img: {}, container: {} },
445
- transformed: false
446
- };
447
- }
448
- }
449
- const isLQIP = !isSEOBot && (getPlaceholder2 || shouldUseLQIP) && !isInFirstFold && ssrImageData.current.transformed;
450
- const imageInfo = React.useMemo(() => JSON.stringify({
451
- containerId,
452
- ...containerId && { containerId },
453
- ...alignType && { alignType },
454
- ...skipMeasure && { skipMeasure: true },
455
- displayMode,
456
- ...containerWidth && { targetWidth: containerWidth },
457
- ...containerHeight && { targetHeight: containerHeight },
458
- ...targetWidth && { targetWidth },
459
- ...targetHeight && { targetHeight },
460
- ...targetScale && { targetScale },
461
- isLQIP,
462
- isSEOBot,
463
- lqipTransition: placeholderTransition,
464
- encoding,
465
- imageData: {
466
- width,
467
- height,
468
- uri,
469
- name,
470
- displayMode,
471
- hasAnimation,
472
- ...quality && { quality },
473
- ...devicePixelRatio && { devicePixelRatio },
474
- ...focalPoint && { focalPoint },
475
- ...crop && { crop },
476
- ...upscaleMethod && { upscaleMethod }
477
- }
478
- }), [
479
- containerId,
480
- alignType,
481
- skipMeasure,
482
- displayMode,
483
- containerWidth,
484
- containerHeight,
485
- targetWidth,
486
- targetHeight,
487
- targetScale,
488
- isLQIP,
489
- isSEOBot,
490
- placeholderTransition,
491
- encoding,
492
- width,
493
- height,
494
- uri,
495
- name,
496
- hasAnimation,
497
- quality,
498
- devicePixelRatio,
499
- focalPoint,
500
- crop,
501
- upscaleMethod
502
- ]);
503
- const ssrResult = ssrImageData.current;
504
- const src = ssrResult == null ? void 0 : ssrResult.uri;
505
- const srcset = ssrResult == null ? void 0 : ssrResult.srcset;
506
- const placeholderStyle = (_a = ssrResult.css) == null ? void 0 : _a.img;
507
- const classNames = `${styles.image} ${className}`;
508
- React.useEffect(() => {
509
- const imgElement = imageRef.current;
510
- if (onLoad && (imgElement == null ? void 0 : imgElement.currentSrc) && (imgElement == null ? void 0 : imgElement.complete)) {
511
- onLoad({
512
- target: imgElement
513
- });
514
- }
515
- }, []);
516
- const maxWidth = ssrResult && !(ssrResult == null ? void 0 : ssrResult.transformed) ? `max(${width}px, 100%)` : targetWidth ? `${targetWidth}px` : null;
517
- return React.createElement(
518
- "wow-image",
519
- { id, class: classNames, "data-image-info": imageInfo, "data-motion-part": `BG_IMG ${containerId}`, "data-bg-effect-name": bgEffectName, "data-has-ssr-src": hasSsrSrc, "data-animate-blur": !isSEOBot && isLQIP && hasBlurTransition ? "" : void 0, "data-is-responsive": isFluidLayout ? "true" : void 0, style: maxWidth ? { "--wix-img-max-width": maxWidth } : {} },
520
- React.createElement("img", {
521
- src,
522
- ref: imageRef,
523
- alt: alt || "",
524
- role,
525
- style: { ...placeholderStyle, ...imageStyles },
526
- onLoad,
527
- onError,
528
- width: containerWidth ? containerWidth : void 0,
529
- height: containerHeight ? containerHeight : void 0,
530
- ...socialAttrs,
531
- srcSet: isInFirstFold ? (_b = srcset == null ? void 0 : srcset.dpr) == null ? void 0 : _b.map((s) => SCHEME_RE.test(s) ? s : `${STATIC_MEDIA_URL}${s}`).join(", ") : void 0,
532
- // @ts-expect-error fetchpriority type should work in react > 18.3 https://github.com/facebook/react/pull/25927
533
- fetchpriority: isInFirstFold ? "high" : void 0,
534
- loading: isInFirstFold === false ? "lazy" : void 0,
535
- // The src attribute triggers a mismatch warning because wow-image updates its src outside of the React lifecycle. This causes React to retain the old value in the virtual DOM, which could potentially lead to a bug where the old value is re-rendered during updates. However, we’re confident that this issue is not reproducing in current (16-18) React versions
536
- suppressHydrationWarning: true
537
- })
538
- );
539
- };
540
- const CSS_NUMERIC_VALUES = {
541
- columnCount: 1,
542
- columns: 1,
543
- fontWeight: 1,
544
- lineHeight: 1,
545
- opacity: 1,
546
- zIndex: 1,
547
- zoom: 1
548
- };
549
- const pick = (obj, props) => {
550
- const propsArr = Array.isArray(props) ? props : [props];
551
- return propsArr.reduce((subObj, prop) => {
552
- const val = obj[prop];
553
- return val !== void 0 ? Object.assign(subObj, { [prop]: val }) : subObj;
554
- }, {});
555
- };
556
- const addDefaultUnitIfNeeded = (prop, value) => typeof value === "number" && !CSS_NUMERIC_VALUES[prop] ? `${value}px` : value.toString();
557
- const setStyle = (node, styleProperties) => node && styleProperties && Object.keys(styleProperties).forEach((prop) => {
558
- const styleProp = prop;
559
- const propValue = styleProperties[styleProp];
560
- if (propValue !== void 0) {
561
- node.style[styleProp] = addDefaultUnitIfNeeded(styleProp, propValue);
562
- } else {
563
- node.style.removeProperty(styleProp);
564
- }
565
- });
566
- const getScreenHeight = (heightOverride) => heightOverride || document.documentElement.clientHeight || window.innerHeight || 0;
567
- const matchesUserDomainMediaPrefix = (uri, prefixes) => prefixes.some((prefix) => uri.startsWith(`${prefix}_`));
568
- const ensureTrailingSlash = (value) => value.endsWith("/") ? value : `${value}/`;
569
- const resolveStaticMediaBaseUrl = ({ uri, envConsts }) => {
570
- const { externalBaseUrl, userDomainMediaPrefixes = [], staticMediaUrl } = envConsts;
571
- if (matchesUserDomainMediaPrefix(uri, userDomainMediaPrefixes) && externalBaseUrl) {
572
- return `${ensureTrailingSlash(externalBaseUrl)}_media/`;
573
- }
574
- return ensureTrailingSlash(staticMediaUrl);
575
- };
576
- const getImageComputedProperties = (extendedImageInfo, envConsts, htmlTag) => {
577
- if (!extendedImageInfo.targetWidth || !extendedImageInfo.targetHeight || !extendedImageInfo.imageData.uri) {
578
- return { uri: "", css: {}, transformed: false };
579
- }
580
- const { imageData } = extendedImageInfo;
581
- const fittingType = extendedImageInfo.displayMode || fittingTypes.SCALE_TO_FILL;
582
- const imageOptions = Object.assign(pick(imageData, ["upscaleMethod"]), pick(extendedImageInfo, [
583
- "filters",
584
- "encoding",
585
- "allowFullGIFTransformation",
586
- "allowWebpAvifTransforms"
587
- ]), extendedImageInfo.quality || imageData.quality, {
588
- hasAnimation: (extendedImageInfo == null ? void 0 : extendedImageInfo.hasAnimation) || (imageData == null ? void 0 : imageData.hasAnimation)
589
- });
590
- const devicePixelRatioFromData = extendedImageInfo.imageData.devicePixelRatio || envConsts.devicePixelRatio;
591
- const devicePixelRatio = getDevicePixelRatio$1(devicePixelRatioFromData);
592
- const src = Object.assign(pick(imageData, ["width", "height", "crop", "name", "focalPoint"]), { id: imageData.uri });
593
- const target = {
594
- width: extendedImageInfo.targetWidth,
595
- height: extendedImageInfo.targetHeight,
596
- htmlTag,
597
- pixelAspectRatio: devicePixelRatio,
598
- alignment: extendedImageInfo.alignType || alignTypes.CENTER
599
- };
600
- const imageComputedProperties = getData(fittingType, src, target, imageOptions);
601
- const staticMediaUrl = imageData.userDomainMediaURL ? imageData.userDomainMediaURL : resolveStaticMediaBaseUrl({
602
- uri: imageData.uri,
603
- envConsts
604
- });
605
- imageComputedProperties.uri = getMediaUrlByContext(imageComputedProperties.uri, staticMediaUrl, envConsts.mediaRootUrl);
606
- return imageComputedProperties;
607
- };
608
- const getMediaUrlByContext = (imageUri, staticMediaUrl, mediaRootUrl) => {
609
- var _a;
610
- const isExternalUrl = /(^https?)|(^data)|(^blob)|(^\/\/)/.test(imageUri);
611
- if (isExternalUrl) {
612
- return imageUri;
613
- }
614
- let path = ensureTrailingSlash(staticMediaUrl);
615
- if (imageUri) {
616
- if (/^micons\//.test(imageUri)) {
617
- path = ensureTrailingSlash(mediaRootUrl);
618
- } else if (((_a = /[^.]+$/.exec(imageUri)) == null ? void 0 : _a[0]) === "ico") {
619
- path = path.replace("media", "ficons");
620
- }
621
- }
622
- return path + imageUri;
623
- };
624
- const getDevicePixelRatio$1 = (devicePixelRatio) => {
625
- const queryParams = window.location.search.split("&").map((query) => query.split("="));
626
- const devicePixelRatioQueryParam = queryParams.find((query) => {
627
- var _a;
628
- return (_a = query[0]) == null ? void 0 : _a.toLowerCase().includes("devicepixelratio");
629
- });
630
- const devicePixelRatioValueForceFromUrl = (devicePixelRatioQueryParam == null ? void 0 : devicePixelRatioQueryParam[1]) ? Number(devicePixelRatioQueryParam[1]) : null;
631
- return devicePixelRatioValueForceFromUrl || devicePixelRatio || 1;
632
- };
633
- const getImageSrc = (imageNode) => imageNode.getAttribute("src");
634
- const imageIsAnimated = (uri, hasAnimation) => getFileExtension(uri) === fileType.GIF || getFileExtension(uri) === fileType.WEBP && hasAnimation;
635
- const MOBILE_SAFE_ADDRESSBAR_HEIGHT = 80;
636
- function getHeightOverride(height, mediaHeightOverrideType) {
637
- return mediaHeightOverrideType === "fixed" || mediaHeightOverrideType === "viewport" ? document.documentElement.clientHeight + MOBILE_SAFE_ADDRESSBAR_HEIGHT : height;
638
- }
639
- function computeScaleOverrides(imageStyle, targetScale = 1) {
640
- return targetScale !== 1 ? {
641
- ...imageStyle,
642
- width: "100%",
643
- height: "100%"
644
- } : imageStyle;
645
- }
646
- function computeStyleOverrides(mediaHeightOverrideType, imageStyle, displayMode, targetScale, isResponsive) {
647
- const styleWithScale = computeScaleOverrides(imageStyle, targetScale);
648
- if (isResponsive) {
649
- delete styleWithScale.height;
650
- styleWithScale.width = "100%";
651
- }
652
- if (!mediaHeightOverrideType) {
653
- return styleWithScale;
654
- }
655
- const style = { ...styleWithScale };
656
- if (displayMode === "fill") {
657
- style.position = "absolute";
658
- style.top = "0";
659
- } else if (displayMode === "fit") {
660
- style.height = "100%";
661
- }
662
- if (mediaHeightOverrideType === "fixed") {
663
- style["will-change"] = "transform";
664
- }
665
- if (style.objectPosition) {
666
- style.objectPosition = imageStyle.objectPosition.replace(/(center|bottom)$/, "top");
667
- }
668
- return style;
669
- }
670
- function getSourceSetsTargetHeightByEffect(sourceSets, offsetWidth, offsetHeight, screenHeight, services) {
671
- const sourceSetsTargetHeights = {};
672
- sourceSets.forEach(({ mediaQuery, scrollEffect }) => {
673
- var _a;
674
- sourceSetsTargetHeights[mediaQuery] = ((_a = services.getMediaDimensionsByEffect) == null ? void 0 : _a.call(services, scrollEffect, offsetWidth, offsetHeight, screenHeight).height) || offsetHeight;
675
- });
676
- return sourceSetsTargetHeights;
677
- }
678
- function computeSrcSets(measures, imageInfo, envConsts) {
679
- const { sourceSets } = imageInfo;
680
- if (!sourceSets || !sourceSets.length) {
681
- return;
682
- }
683
- const mediaToUri = {};
684
- sourceSets.forEach(({ mediaQuery, crop, focalPoint }) => {
685
- const imageInfoClone = {
686
- ...imageInfo,
687
- targetHeight: (measures.sourceSetsTargetHeights || {})[mediaQuery] || 0,
688
- imageData: {
689
- ...imageInfo.imageData,
690
- crop,
691
- focalPoint
692
- }
693
- };
694
- const imageComputedProperties = getImageComputedProperties(imageInfoClone, envConsts, "img");
695
- mediaToUri[mediaQuery] = imageComputedProperties.uri || "";
696
- });
697
- return mediaToUri;
698
- }
699
- function measure(id, measures, domNodes, { containerElm, bgEffect = "none", sourceSets }, services) {
700
- var _a, _b;
701
- const innerImage = domNodes.image;
702
- const wixImage = domNodes[id];
703
- const screenHeight = getScreenHeight((_a = services.getScreenHeightOverride) == null ? void 0 : _a.call(services));
704
- const mediaHeightOverrideType = containerElm == null ? void 0 : containerElm.dataset.mediaHeightOverrideType;
705
- const hasBgEffect = bgEffect && bgEffect !== "none" || sourceSets && sourceSets.some((srcset) => srcset.scrollEffect);
706
- const sourceOfDimensions = containerElm && hasBgEffect ? containerElm : wixImage;
707
- const cssBgEffect = window.getComputedStyle(wixImage).getPropertyValue("--bg-scrub-effect");
708
- const { width, height } = ((_b = services.getMediaDimensionsByEffect) == null ? void 0 : _b.call(services, cssBgEffect || bgEffect, sourceOfDimensions.offsetWidth, sourceOfDimensions.offsetHeight, screenHeight)) || {
709
- width: wixImage.offsetWidth,
710
- height: wixImage.offsetHeight
711
- };
712
- if (sourceSets) {
713
- measures.sourceSetsTargetHeights = getSourceSetsTargetHeightByEffect(sourceSets, sourceOfDimensions.offsetWidth, sourceOfDimensions.offsetHeight, screenHeight, services);
714
- }
715
- if (!innerImage) {
716
- return;
717
- }
718
- const imgSrc = getImageSrc(innerImage);
719
- if (cssBgEffect) {
720
- measures.top = 0.5 * (wixImage.offsetHeight - height);
721
- measures.left = 0.5 * (wixImage.offsetWidth - width);
722
- }
723
- measures.width = width;
724
- measures.height = getHeightOverride(height, mediaHeightOverrideType);
725
- measures.screenHeight = screenHeight;
726
- measures.imgSrc = imgSrc;
727
- measures.boundingRect = wixImage.getBoundingClientRect();
728
- measures.mediaHeightOverrideType = mediaHeightOverrideType;
729
- measures.srcset = innerImage.srcset;
730
- }
731
- function patch(id, measures, domNodes, imageInfo, services, envConsts, loadImage, isResponsive, bgEffect, loadImageImmediately) {
732
- var _a, _b, _c;
733
- if (!Object.keys(measures).length) {
734
- return;
735
- }
736
- const { imageData } = imageInfo;
737
- const wixImageNode = domNodes[id];
738
- const image2 = domNodes.image;
739
- if (bgEffect) {
740
- imageData.devicePixelRatio = 1;
741
- }
742
- const targetScale = imageInfo.targetScale || 1;
743
- const allowFullGIFTransformation = (_a = services.isExperimentOpen) == null ? void 0 : _a.call(services, "specs.thunderbolt.allowFullGIFTransformation");
744
- const allowWebpAvifTransforms = (_b = services.isExperimentOpen) == null ? void 0 : _b.call(services, "specs.thunderbolt.allowWebpAvifTransforms");
745
- const extendedImageInfo = {
746
- ...imageInfo,
747
- ...!imageInfo.skipMeasure && {
748
- targetWidth: (measures.width || 0) * targetScale,
749
- targetHeight: (measures.height || 0) * targetScale
750
- },
751
- displayMode: imageData.displayMode,
752
- allowFullGIFTransformation,
753
- allowWebpAvifTransforms
754
- };
755
- const imageComputedProperties = getImageComputedProperties(extendedImageInfo, envConsts, "img");
756
- const computedStyle = ((_c = imageComputedProperties == null ? void 0 : imageComputedProperties.css) == null ? void 0 : _c.img) || {};
757
- const imageStyle = computeStyleOverrides(measures.mediaHeightOverrideType, computedStyle, imageData.displayMode, targetScale, isResponsive);
758
- setStyle(image2, imageStyle);
759
- if (measures.top || measures.left) {
760
- setStyle(wixImageNode, {
761
- top: `${measures.top}px`,
762
- left: `${measures.left}px`
763
- });
764
- }
765
- const src = (imageComputedProperties == null ? void 0 : imageComputedProperties.uri) || "";
766
- const hasAnimation = (imageData == null ? void 0 : imageData.hasAnimation) || (imageInfo == null ? void 0 : imageInfo.hasAnimation);
767
- const mediaToUri = computeSrcSets(measures, extendedImageInfo, envConsts);
768
- if (loadImageImmediately) {
769
- image2.dataset.ssrSrcDone = "true";
770
- }
771
- if (imageInfo.isLQIP && imageInfo.lqipTransition && !("transitioned" in wixImageNode.dataset)) {
772
- wixImageNode.dataset.transitioned = "";
773
- if (image2.complete) {
774
- image2.onload = function() {
775
- image2.dataset.loadDone = "";
776
- };
777
- } else {
778
- image2.onload = function() {
779
- if (image2.complete) {
780
- image2.dataset.loadDone = "";
781
- } else {
782
- image2.onload = function() {
783
- image2.dataset.loadDone = "";
784
- };
785
- }
786
- };
787
- }
788
- }
789
- if (loadImage) {
790
- if (imageIsAnimated(imageData.uri, hasAnimation)) {
791
- image2.setAttribute("fetchpriority", "low");
792
- image2.setAttribute("loading", "lazy");
793
- image2.setAttribute("decoding", "async");
794
- } else {
795
- image2.setAttribute("fetchpriority", "high");
796
- }
797
- image2.currentSrc !== src && image2.setAttribute("src", src);
798
- const srcIsMissingFromSrcset = measures.srcset && !measures.srcset.split(", ").some((source) => source.split(" ")[0] === src);
799
- if (srcIsMissingFromSrcset) {
800
- image2.setAttribute("srcset", src);
801
- }
802
- if (domNodes.picture && extendedImageInfo.sourceSets) {
803
- Array.from(domNodes.picture.querySelectorAll("source")).forEach((sourceNode) => {
804
- const mediaQuery = sourceNode.media || "";
805
- const uri = mediaToUri == null ? void 0 : mediaToUri[mediaQuery];
806
- if (sourceNode.srcset !== uri) {
807
- sourceNode.setAttribute("srcset", uri || "");
808
- }
809
- });
810
- }
811
- }
812
- }
813
- const imageLayout = {
814
- measure,
815
- patch
816
- };
817
- const TIMEOUT = 250;
818
- const imageEffectMap = {
819
- parallax: "ImageParallax",
820
- fixed: "ImageReveal"
821
- };
822
- function wowImageFactory(services, environmentConsts, contextWindow) {
823
- return class WowImage extends contextWindow.HTMLElement {
824
- constructor() {
825
- super();
826
- this.childListObserver = null;
827
- this.timeoutId = null;
828
- }
829
- attributeChangedCallback(_, oldValue) {
830
- if (oldValue) {
831
- this.reLayout();
832
- }
833
- }
834
- connectedCallback() {
835
- if (environmentConsts.disableImagesLazyLoading) {
836
- this.reLayout();
837
- } else {
838
- this.observeIntersect();
839
- }
840
- }
841
- disconnectedCallback() {
842
- this.unobserveResize();
843
- this.unobserveIntersect();
844
- this.unobserveChildren();
845
- }
846
- static get observedAttributes() {
847
- return ["data-image-info"];
848
- }
849
- reLayout() {
850
- const domNodes = {};
851
- const measures = {};
852
- const imageId = this.getAttribute("id");
853
- const imageInfo = JSON.parse(this.dataset.imageInfo || "");
854
- const isResponsive = this.dataset.isResponsive === "true";
855
- const { bgEffectName } = this.dataset;
856
- const { scrollEffect } = imageInfo.imageData;
857
- const { sourceSets } = imageInfo;
858
- const bgEffect = bgEffectName || scrollEffect && imageEffectMap[scrollEffect];
859
- if (sourceSets && sourceSets.length) {
860
- sourceSets.forEach((sourceSet) => {
861
- if (sourceSet.scrollEffect) {
862
- sourceSet.scrollEffect = imageEffectMap[sourceSet.scrollEffect];
863
- }
864
- });
865
- }
866
- domNodes[imageId] = this;
867
- if (imageInfo.containerId) {
868
- domNodes[imageInfo.containerId] = contextWindow.document.getElementById(`${imageInfo.containerId}`);
869
- }
870
- const containerElm = imageInfo.containerId ? domNodes[imageInfo.containerId] : void 0;
871
- domNodes.image = this.querySelector("img");
872
- domNodes.picture = this.querySelector("picture");
873
- if (!domNodes.image) {
874
- const target = this;
875
- this.observeChildren(target);
876
- return;
877
- }
878
- this.unobserveChildren();
879
- this.observeChildren(this);
880
- services.mutationService.measure(() => {
881
- imageLayout.measure(imageId, measures, domNodes, {
882
- containerElm,
883
- bgEffect,
884
- sourceSets
885
- }, services);
886
- });
887
- const patchImage = (shouldLoadImage, loadImageImmediately2) => {
888
- services.mutationService.mutate(() => {
889
- imageLayout.patch(imageId, measures, domNodes, imageInfo, services, environmentConsts, shouldLoadImage, isResponsive, bgEffect, loadImageImmediately2);
890
- });
891
- };
892
- const imageElement = domNodes.image;
893
- const ssrSrcNeedProcessing = this.dataset.hasSsrSrc && !imageElement.dataset.ssrSrcDone;
894
- const loadImageImmediately = !getImageSrc(imageElement) || ssrSrcNeedProcessing;
895
- if (loadImageImmediately) {
896
- patchImage(true, true);
897
- } else {
898
- this.debounceImageLoad(patchImage);
899
- }
900
- }
901
- /**
902
- * Debounce consecutive image loads
903
- *
904
- * @param {function} patchImage closure for patching the image
905
- */
906
- debounceImageLoad(patchImage) {
907
- clearTimeout(this.timeoutId);
908
- this.timeoutId = contextWindow.setTimeout(() => {
909
- patchImage(true);
910
- }, TIMEOUT);
911
- patchImage(false);
912
- }
913
- observeResize() {
914
- var _a;
915
- (_a = services.resizeService) == null ? void 0 : _a.observe(this);
916
- }
917
- unobserveResize() {
918
- var _a;
919
- (_a = services.resizeService) == null ? void 0 : _a.unobserve(this);
920
- }
921
- observeIntersect() {
922
- var _a;
923
- (_a = services.intersectionService) == null ? void 0 : _a.observe(this);
924
- }
925
- unobserveIntersect() {
926
- var _a;
927
- (_a = services.intersectionService) == null ? void 0 : _a.unobserve(this);
928
- }
929
- /**
930
- * Observe DOM mutations to wait for addition of missing children
931
- *
932
- * @param {HTMLElement} parent
933
- */
934
- observeChildren(parent) {
935
- if (!this.childListObserver) {
936
- this.childListObserver = new contextWindow.MutationObserver(() => {
937
- this.reLayout();
938
- });
939
- }
940
- this.childListObserver.observe(parent, { childList: true });
941
- }
942
- /**
943
- * Remove DOM MutationObserver if one was created
944
- */
945
- unobserveChildren() {
946
- if (this.childListObserver) {
947
- this.childListObserver.disconnect();
948
- this.childListObserver = null;
949
- }
950
- }
951
- };
952
- }
953
- function init(contextWindow, services) {
954
- const elementName = "wow-image";
955
- contextWindow = contextWindow || window;
956
- if (contextWindow.customElements.get(elementName) === void 0) {
957
- let resizeObserver;
958
- if (contextWindow.ResizeObserver) {
959
- resizeObserver = new contextWindow.ResizeObserver((entries) => entries.map((entry) => entry.target.reLayout()));
960
- }
961
- let intersectionObserver;
962
- if (contextWindow.IntersectionObserver) {
963
- intersectionObserver = new IntersectionObserver((entries) => entries.map((entry) => {
964
- if (entry.isIntersecting) {
965
- const wowImage = entry.target;
966
- wowImage.unobserveIntersect();
967
- wowImage.observeResize();
968
- }
969
- return entry;
970
- }), {
971
- /**
972
- * old: 50% from 1080 (desktop) is 540px, 800 (mobile) 400px
973
- * new: 150% from 1080 (desktop) is 1620, 800 (mobile) 1200
974
- * chrome [loading=lazy]: 4g - 1250px, lower then 3g - 2500px
975
- * @see https://web.dev/articles/browser-level-image-lazy-loading#improved-thresholds
976
- */
977
- rootMargin: "150% 100%"
978
- });
979
- }
980
- return function(env) {
981
- const WowImage = wowImageFactory({
982
- resizeService: resizeObserver,
983
- intersectionService: intersectionObserver,
984
- mutationService: fastdom,
985
- ...services
986
- }, env, contextWindow);
987
- contextWindow.customElements.define(elementName, WowImage);
988
- };
989
- }
990
- return;
991
- }
992
- const getDevicePixelRatio = () => {
993
- const isMSMobileDevice = /iemobile/i.test(navigator.userAgent);
994
- if (isMSMobileDevice) {
995
- return Math.round(window.screen.availWidth / (window.screen.width || window.document.documentElement.clientWidth));
996
- }
997
- return window.devicePixelRatio;
998
- };
999
- const getIsImagesLazyLoadingDisabled = () => {
1000
- try {
1001
- return new URL(window.location.href).searchParams.get("disableLazyLoading") === "true";
1002
- } catch {
1003
- return false;
1004
- }
1005
- };
1006
- function initCustomElement(services = {}, contextWindow = null, envConsts = {}) {
1007
- if (typeof window === "undefined") {
1008
- return;
1009
- }
1010
- const env = {
1011
- staticMediaUrl: STATIC_MEDIA_URL$1,
1012
- mediaRootUrl: MEDIA_ROOT_URL,
1013
- experiments: {},
1014
- devicePixelRatio: getDevicePixelRatio(),
1015
- disableImagesLazyLoading: getIsImagesLazyLoadingDisabled(),
1016
- ...envConsts
1017
- };
1018
- const define = init(contextWindow, services);
1019
- if (define) {
1020
- define(env);
1021
- }
383
+ init(actualWindow, services);
1022
384
  }
1023
385
  if (typeof window !== "undefined") {
1024
386
  if (document.readyState === "loading") {
1025
387
  document.addEventListener("DOMContentLoaded", () => {
1026
- initCustomElement$1();
1027
388
  initCustomElement();
389
+ initCustomElement$1();
1028
390
  }, {
1029
391
  once: true
1030
392
  });
1031
393
  } else {
1032
- initCustomElement$1();
1033
394
  initCustomElement();
395
+ initCustomElement$1();
1034
396
  }
1035
397
  }
1036
398
  const Video = (props) => {
@@ -1099,10 +461,10 @@ const Video = (props) => {
1099
461
  ref: wowVideoRef,
1100
462
  "data-video-info": videoInfoString,
1101
463
  "data-motion-part": motionPart || "",
1102
- class: styles$1.videoContainer
464
+ class: styles.videoContainer
1103
465
  }, /* @__PURE__ */ React.createElement("video", {
1104
466
  ref: videoRef,
1105
- className: styles$1.video,
467
+ className: styles.video,
1106
468
  crossOrigin: "anonymous",
1107
469
  playsInline: true,
1108
470
  muted,