@wix/editor-react-components 1.2500.0 → 1.2502.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.
@@ -0,0 +1,658 @@
1
+ import { a as getData, b as getFileExtension, f as fileType, c as alignTypes, d as fittingTypes, M as MEDIA_ROOT_URL, S as STATIC_MEDIA_URL } from "./index5.js";
2
+ import { g as getDefaultExportFromCjs } from "./_commonjsHelpers.js";
3
+ var fastdom$2 = { exports: {} };
4
+ var fastdom$1 = fastdom$2.exports;
5
+ var hasRequiredFastdom;
6
+ function requireFastdom() {
7
+ if (hasRequiredFastdom) return fastdom$2.exports;
8
+ hasRequiredFastdom = 1;
9
+ (function(module) {
10
+ !(function(win) {
11
+ var debug = function() {
12
+ };
13
+ var raf = win.requestAnimationFrame || win.webkitRequestAnimationFrame || win.mozRequestAnimationFrame || win.msRequestAnimationFrame || function(cb) {
14
+ return setTimeout(cb, 16);
15
+ };
16
+ function FastDom() {
17
+ var self = this;
18
+ self.reads = [];
19
+ self.writes = [];
20
+ self.raf = raf.bind(win);
21
+ }
22
+ FastDom.prototype = {
23
+ constructor: FastDom,
24
+ /**
25
+ * We run this inside a try catch
26
+ * so that if any jobs error, we
27
+ * are able to recover and continue
28
+ * to flush the batch until it's empty.
29
+ *
30
+ * @param {Array} tasks
31
+ */
32
+ runTasks: function(tasks) {
33
+ var task;
34
+ while (task = tasks.shift()) task();
35
+ },
36
+ /**
37
+ * Adds a job to the read batch and
38
+ * schedules a new frame if need be.
39
+ *
40
+ * @param {Function} fn
41
+ * @param {Object} ctx the context to be bound to `fn` (optional).
42
+ * @public
43
+ */
44
+ measure: function(fn, ctx) {
45
+ var task = !ctx ? fn : fn.bind(ctx);
46
+ this.reads.push(task);
47
+ scheduleFlush(this);
48
+ return task;
49
+ },
50
+ /**
51
+ * Adds a job to the
52
+ * write batch and schedules
53
+ * a new frame if need be.
54
+ *
55
+ * @param {Function} fn
56
+ * @param {Object} ctx the context to be bound to `fn` (optional).
57
+ * @public
58
+ */
59
+ mutate: function(fn, ctx) {
60
+ var task = !ctx ? fn : fn.bind(ctx);
61
+ this.writes.push(task);
62
+ scheduleFlush(this);
63
+ return task;
64
+ },
65
+ /**
66
+ * Clears a scheduled 'read' or 'write' task.
67
+ *
68
+ * @param {Object} task
69
+ * @return {Boolean} success
70
+ * @public
71
+ */
72
+ clear: function(task) {
73
+ return remove(this.reads, task) || remove(this.writes, task);
74
+ },
75
+ /**
76
+ * Extend this FastDom with some
77
+ * custom functionality.
78
+ *
79
+ * Because fastdom must *always* be a
80
+ * singleton, we're actually extending
81
+ * the fastdom instance. This means tasks
82
+ * scheduled by an extension still enter
83
+ * fastdom's global task queue.
84
+ *
85
+ * The 'super' instance can be accessed
86
+ * from `this.fastdom`.
87
+ *
88
+ * @example
89
+ *
90
+ * var myFastdom = fastdom.extend({
91
+ * initialize: function() {
92
+ * // runs on creation
93
+ * },
94
+ *
95
+ * // override a method
96
+ * measure: function(fn) {
97
+ * // do extra stuff ...
98
+ *
99
+ * // then call the original
100
+ * return this.fastdom.measure(fn);
101
+ * },
102
+ *
103
+ * ...
104
+ * });
105
+ *
106
+ * @param {Object} props properties to mixin
107
+ * @return {FastDom}
108
+ */
109
+ extend: function(props) {
110
+ if (typeof props != "object") throw new Error("expected object");
111
+ var child = Object.create(this);
112
+ mixin(child, props);
113
+ child.fastdom = this;
114
+ if (child.initialize) child.initialize();
115
+ return child;
116
+ },
117
+ // override this with a function
118
+ // to prevent Errors in console
119
+ // when tasks throw
120
+ catch: null
121
+ };
122
+ function scheduleFlush(fastdom2) {
123
+ if (!fastdom2.scheduled) {
124
+ fastdom2.scheduled = true;
125
+ fastdom2.raf(flush.bind(null, fastdom2));
126
+ }
127
+ }
128
+ function flush(fastdom2) {
129
+ var writes = fastdom2.writes;
130
+ var reads = fastdom2.reads;
131
+ var error;
132
+ try {
133
+ debug("flushing reads", reads.length);
134
+ fastdom2.runTasks(reads);
135
+ debug("flushing writes", writes.length);
136
+ fastdom2.runTasks(writes);
137
+ } catch (e) {
138
+ error = e;
139
+ }
140
+ fastdom2.scheduled = false;
141
+ if (reads.length || writes.length) scheduleFlush(fastdom2);
142
+ if (error) {
143
+ debug("task errored", error.message);
144
+ if (fastdom2.catch) fastdom2.catch(error);
145
+ else throw error;
146
+ }
147
+ }
148
+ function remove(array, item) {
149
+ var index = array.indexOf(item);
150
+ return !!~index && !!array.splice(index, 1);
151
+ }
152
+ function mixin(target, source) {
153
+ for (var key in source) {
154
+ if (source.hasOwnProperty(key)) target[key] = source[key];
155
+ }
156
+ }
157
+ var exports$1 = win.fastdom = win.fastdom || new FastDom();
158
+ module.exports = exports$1;
159
+ })(typeof window !== "undefined" ? window : typeof fastdom$1 != "undefined" ? fastdom$1 : globalThis);
160
+ })(fastdom$2);
161
+ return fastdom$2.exports;
162
+ }
163
+ var fastdomExports = requireFastdom();
164
+ const fastdom = /* @__PURE__ */ getDefaultExportFromCjs(fastdomExports);
165
+ const camelToKebab = (str) => str.replace(/[A-Z]+(?![^A-Z])|[A-Z]/g, (a, b) => (b ? "-" : "") + a.toLowerCase());
166
+ const CSS_NUMERIC_VALUES = {
167
+ columnCount: 1,
168
+ columns: 1,
169
+ fontWeight: 1,
170
+ lineHeight: 1,
171
+ opacity: 1,
172
+ zIndex: 1,
173
+ zoom: 1
174
+ };
175
+ const pick = (obj, props) => {
176
+ const propsArr = Array.isArray(props) ? props : [props];
177
+ return propsArr.reduce((subObj, prop) => {
178
+ const val = obj[prop];
179
+ return val !== void 0 ? Object.assign(subObj, { [prop]: val }) : subObj;
180
+ }, {});
181
+ };
182
+ const addDefaultUnitIfNeeded = (prop, value) => typeof value === "number" && !CSS_NUMERIC_VALUES[prop] ? `${value}px` : value.toString();
183
+ const setStyle = (node, styleProperties) => node && styleProperties && Object.keys(styleProperties).forEach((prop) => {
184
+ const styleProp = prop;
185
+ const propValue = styleProperties[styleProp];
186
+ if (propValue !== void 0) {
187
+ node.style[styleProp] = addDefaultUnitIfNeeded(styleProp, propValue);
188
+ } else {
189
+ node.style.removeProperty(styleProp);
190
+ }
191
+ });
192
+ const getScreenHeight = (heightOverride) => heightOverride || document.documentElement.clientHeight || window.innerHeight || 0;
193
+ const matchesUserDomainMediaPrefix = (uri, prefixes) => prefixes.some((prefix) => uri.startsWith(`${prefix}_`));
194
+ const ensureTrailingSlash = (value) => value.endsWith("/") ? value : `${value}/`;
195
+ const resolveStaticMediaBaseUrl = ({ uri, envConsts }) => {
196
+ const { externalBaseUrl, userDomainMediaPrefixes = [], staticMediaUrl } = envConsts;
197
+ if (matchesUserDomainMediaPrefix(uri, userDomainMediaPrefixes) && externalBaseUrl) {
198
+ return `${ensureTrailingSlash(externalBaseUrl)}_media/`;
199
+ }
200
+ return ensureTrailingSlash(staticMediaUrl);
201
+ };
202
+ const getImageComputedProperties = (extendedImageInfo, envConsts, htmlTag) => {
203
+ if (!extendedImageInfo.targetWidth || !extendedImageInfo.targetHeight || !extendedImageInfo.imageData.uri) {
204
+ return { uri: "", css: {}, transformed: false };
205
+ }
206
+ const { imageData } = extendedImageInfo;
207
+ const fittingType = extendedImageInfo.displayMode || fittingTypes.SCALE_TO_FILL;
208
+ const imageOptions = Object.assign(pick(imageData, ["upscaleMethod"]), pick(extendedImageInfo, [
209
+ "filters",
210
+ "encoding",
211
+ "allowFullGIFTransformation",
212
+ "allowWebpAvifTransforms"
213
+ ]), extendedImageInfo.quality || imageData.quality, {
214
+ hasAnimation: (extendedImageInfo == null ? void 0 : extendedImageInfo.hasAnimation) || (imageData == null ? void 0 : imageData.hasAnimation)
215
+ });
216
+ const devicePixelRatioFromData = extendedImageInfo.imageData.devicePixelRatio || envConsts.devicePixelRatio;
217
+ const devicePixelRatio = getDevicePixelRatio$1(devicePixelRatioFromData);
218
+ const src = Object.assign(pick(imageData, ["width", "height", "crop", "name", "focalPoint"]), { id: imageData.uri });
219
+ const target = {
220
+ width: extendedImageInfo.targetWidth,
221
+ height: extendedImageInfo.targetHeight,
222
+ htmlTag,
223
+ pixelAspectRatio: devicePixelRatio,
224
+ alignment: extendedImageInfo.alignType || alignTypes.CENTER
225
+ };
226
+ const imageComputedProperties = getData(fittingType, src, target, imageOptions);
227
+ const staticMediaUrl = imageData.userDomainMediaURL ? imageData.userDomainMediaURL : resolveStaticMediaBaseUrl({
228
+ uri: imageData.uri,
229
+ envConsts
230
+ });
231
+ imageComputedProperties.uri = getMediaUrlByContext(imageComputedProperties.uri, staticMediaUrl, envConsts.mediaRootUrl);
232
+ return imageComputedProperties;
233
+ };
234
+ const getMediaUrlByContext = (imageUri, staticMediaUrl, mediaRootUrl) => {
235
+ var _a;
236
+ const isExternalUrl = /(^https?)|(^data)|(^blob)|(^\/\/)/.test(imageUri);
237
+ if (isExternalUrl) {
238
+ return imageUri;
239
+ }
240
+ let path = ensureTrailingSlash(staticMediaUrl);
241
+ if (imageUri) {
242
+ if (/^micons\//.test(imageUri)) {
243
+ path = ensureTrailingSlash(mediaRootUrl);
244
+ } else if (((_a = /[^.]+$/.exec(imageUri)) == null ? void 0 : _a[0]) === "ico") {
245
+ path = path.replace("media", "ficons");
246
+ }
247
+ }
248
+ return path + imageUri;
249
+ };
250
+ const getDevicePixelRatio$1 = (devicePixelRatio) => {
251
+ const queryParams = window.location.search.split("&").map((query) => query.split("="));
252
+ const devicePixelRatioQueryParam = queryParams.find((query) => {
253
+ var _a;
254
+ return (_a = query[0]) == null ? void 0 : _a.toLowerCase().includes("devicepixelratio");
255
+ });
256
+ const devicePixelRatioValueForceFromUrl = (devicePixelRatioQueryParam == null ? void 0 : devicePixelRatioQueryParam[1]) ? Number(devicePixelRatioQueryParam[1]) : null;
257
+ return devicePixelRatioValueForceFromUrl || devicePixelRatio || 1;
258
+ };
259
+ const getImageSrc = (imageNode) => imageNode.getAttribute("src");
260
+ const imageIsAnimated = (uri, hasAnimation) => getFileExtension(uri) === fileType.GIF || getFileExtension(uri) === fileType.WEBP && hasAnimation;
261
+ const getMediaSizeQueryString = (media) => {
262
+ return Object.entries(media).filter(([_, value]) => value || value === 0).map(([key, value]) => `(${camelToKebab(key)}: ${value}px)`).join(" and ");
263
+ };
264
+ const MOBILE_SAFE_ADDRESSBAR_HEIGHT = 80;
265
+ function getHeightOverride(height, mediaHeightOverrideType) {
266
+ return mediaHeightOverrideType === "fixed" || mediaHeightOverrideType === "viewport" ? document.documentElement.clientHeight + MOBILE_SAFE_ADDRESSBAR_HEIGHT : height;
267
+ }
268
+ function computeScaleOverrides(imageStyle, targetScale = 1) {
269
+ return targetScale !== 1 ? {
270
+ ...imageStyle,
271
+ width: "100%",
272
+ height: "100%"
273
+ } : imageStyle;
274
+ }
275
+ function computeStyleOverrides(mediaHeightOverrideType, imageStyle, displayMode, targetScale, isResponsive) {
276
+ const styleWithScale = computeScaleOverrides(imageStyle, targetScale);
277
+ if (isResponsive) {
278
+ delete styleWithScale.height;
279
+ styleWithScale.width = "100%";
280
+ }
281
+ if (!mediaHeightOverrideType) {
282
+ return styleWithScale;
283
+ }
284
+ const style = { ...styleWithScale };
285
+ if (displayMode === "fill") {
286
+ style.position = "absolute";
287
+ style.top = "0";
288
+ } else if (displayMode === "fit") {
289
+ style.height = "100%";
290
+ }
291
+ if (mediaHeightOverrideType === "fixed") {
292
+ style["will-change"] = "transform";
293
+ }
294
+ if (style.objectPosition) {
295
+ style.objectPosition = imageStyle.objectPosition.replace(/(center|bottom)$/, "top");
296
+ }
297
+ return style;
298
+ }
299
+ function getSourceSetsTargetHeightByEffect(sourceSets, offsetWidth, offsetHeight, screenHeight, services) {
300
+ const sourceSetsTargetHeights = {};
301
+ sourceSets.forEach(({ mediaQuery, scrollEffect }) => {
302
+ var _a;
303
+ sourceSetsTargetHeights[mediaQuery] = ((_a = services.getMediaDimensionsByEffect) == null ? void 0 : _a.call(services, scrollEffect, offsetWidth, offsetHeight, screenHeight).height) || offsetHeight;
304
+ });
305
+ return sourceSetsTargetHeights;
306
+ }
307
+ function computeSrcSets(measures, imageInfo, envConsts) {
308
+ const { sourceSets } = imageInfo;
309
+ if (!sourceSets || !sourceSets.length) {
310
+ return;
311
+ }
312
+ const mediaToUri = {};
313
+ sourceSets.forEach(({ mediaQuery, crop, focalPoint }) => {
314
+ const imageInfoClone = {
315
+ ...imageInfo,
316
+ targetHeight: (measures.sourceSetsTargetHeights || {})[mediaQuery] || 0,
317
+ imageData: {
318
+ ...imageInfo.imageData,
319
+ crop,
320
+ focalPoint
321
+ }
322
+ };
323
+ const imageComputedProperties = getImageComputedProperties(imageInfoClone, envConsts, "img");
324
+ mediaToUri[mediaQuery] = imageComputedProperties.uri || "";
325
+ });
326
+ return mediaToUri;
327
+ }
328
+ function measure(id, measures, domNodes, { containerElm, bgEffect = "none", sourceSets }, services) {
329
+ var _a, _b;
330
+ const innerImage = domNodes.image;
331
+ const wixImage = domNodes[id];
332
+ const screenHeight = getScreenHeight((_a = services.getScreenHeightOverride) == null ? void 0 : _a.call(services));
333
+ const mediaHeightOverrideType = containerElm == null ? void 0 : containerElm.dataset.mediaHeightOverrideType;
334
+ const hasBgEffect = bgEffect && bgEffect !== "none" || sourceSets && sourceSets.some((srcset) => srcset.scrollEffect);
335
+ const sourceOfDimensions = containerElm && hasBgEffect ? containerElm : wixImage;
336
+ const cssBgEffect = window.getComputedStyle(wixImage).getPropertyValue("--bg-scrub-effect");
337
+ const { width, height } = ((_b = services.getMediaDimensionsByEffect) == null ? void 0 : _b.call(services, cssBgEffect || bgEffect, sourceOfDimensions.offsetWidth, sourceOfDimensions.offsetHeight, screenHeight)) || {
338
+ width: wixImage.offsetWidth,
339
+ height: wixImage.offsetHeight
340
+ };
341
+ if (sourceSets) {
342
+ measures.sourceSetsTargetHeights = getSourceSetsTargetHeightByEffect(sourceSets, sourceOfDimensions.offsetWidth, sourceOfDimensions.offsetHeight, screenHeight, services);
343
+ }
344
+ if (!innerImage) {
345
+ return;
346
+ }
347
+ const imgSrc = getImageSrc(innerImage);
348
+ if (cssBgEffect) {
349
+ measures.top = 0.5 * (wixImage.offsetHeight - height);
350
+ measures.left = 0.5 * (wixImage.offsetWidth - width);
351
+ }
352
+ measures.width = width;
353
+ measures.height = getHeightOverride(height, mediaHeightOverrideType);
354
+ measures.screenHeight = screenHeight;
355
+ measures.imgSrc = imgSrc;
356
+ measures.boundingRect = wixImage.getBoundingClientRect();
357
+ measures.mediaHeightOverrideType = mediaHeightOverrideType;
358
+ measures.srcset = innerImage.srcset;
359
+ }
360
+ function patch(id, measures, domNodes, imageInfo, services, envConsts, loadImage, isResponsive, bgEffect, loadImageImmediately) {
361
+ var _a, _b, _c;
362
+ if (!Object.keys(measures).length) {
363
+ return;
364
+ }
365
+ const { imageData } = imageInfo;
366
+ const wixImageNode = domNodes[id];
367
+ const image = domNodes.image;
368
+ if (bgEffect) {
369
+ imageData.devicePixelRatio = 1;
370
+ }
371
+ const targetScale = imageInfo.targetScale || 1;
372
+ const allowFullGIFTransformation = (_a = services.isExperimentOpen) == null ? void 0 : _a.call(services, "specs.thunderbolt.allowFullGIFTransformation");
373
+ const allowWebpAvifTransforms = (_b = services.isExperimentOpen) == null ? void 0 : _b.call(services, "specs.thunderbolt.allowWebpAvifTransforms");
374
+ const extendedImageInfo = {
375
+ ...imageInfo,
376
+ ...!imageInfo.skipMeasure && {
377
+ targetWidth: (measures.width || 0) * targetScale,
378
+ targetHeight: (measures.height || 0) * targetScale
379
+ },
380
+ displayMode: imageData.displayMode,
381
+ allowFullGIFTransformation,
382
+ allowWebpAvifTransforms
383
+ };
384
+ const imageComputedProperties = getImageComputedProperties(extendedImageInfo, envConsts, "img");
385
+ const computedStyle = ((_c = imageComputedProperties == null ? void 0 : imageComputedProperties.css) == null ? void 0 : _c.img) || {};
386
+ const imageStyle = computeStyleOverrides(measures.mediaHeightOverrideType, computedStyle, imageData.displayMode, targetScale, isResponsive);
387
+ setStyle(image, imageStyle);
388
+ if (measures.top || measures.left) {
389
+ setStyle(wixImageNode, {
390
+ top: `${measures.top}px`,
391
+ left: `${measures.left}px`
392
+ });
393
+ }
394
+ const src = (imageComputedProperties == null ? void 0 : imageComputedProperties.uri) || "";
395
+ const hasAnimation = (imageData == null ? void 0 : imageData.hasAnimation) || (imageInfo == null ? void 0 : imageInfo.hasAnimation);
396
+ const mediaToUri = computeSrcSets(measures, extendedImageInfo, envConsts);
397
+ if (loadImageImmediately) {
398
+ image.dataset.ssrSrcDone = "true";
399
+ }
400
+ if (imageInfo.isLQIP && imageInfo.lqipTransition && !("transitioned" in wixImageNode.dataset)) {
401
+ wixImageNode.dataset.transitioned = "";
402
+ if (image.complete) {
403
+ image.onload = function() {
404
+ image.dataset.loadDone = "";
405
+ };
406
+ } else {
407
+ image.onload = function() {
408
+ if (image.complete) {
409
+ image.dataset.loadDone = "";
410
+ } else {
411
+ image.onload = function() {
412
+ image.dataset.loadDone = "";
413
+ };
414
+ }
415
+ };
416
+ }
417
+ }
418
+ if (loadImage) {
419
+ if (imageIsAnimated(imageData.uri, hasAnimation)) {
420
+ image.setAttribute("fetchpriority", "low");
421
+ image.setAttribute("loading", "lazy");
422
+ image.setAttribute("decoding", "async");
423
+ } else {
424
+ image.setAttribute("fetchpriority", "high");
425
+ }
426
+ image.currentSrc !== src && image.setAttribute("src", src);
427
+ const srcIsMissingFromSrcset = measures.srcset && !measures.srcset.split(", ").some((source) => source.split(" ")[0] === src);
428
+ if (srcIsMissingFromSrcset) {
429
+ image.setAttribute("srcset", src);
430
+ }
431
+ if (domNodes.picture && extendedImageInfo.sourceSets) {
432
+ Array.from(domNodes.picture.querySelectorAll("source")).forEach((sourceNode) => {
433
+ const mediaQuery = sourceNode.media || "";
434
+ const uri = mediaToUri == null ? void 0 : mediaToUri[mediaQuery];
435
+ if (sourceNode.srcset !== uri) {
436
+ sourceNode.setAttribute("srcset", uri || "");
437
+ }
438
+ });
439
+ }
440
+ }
441
+ }
442
+ const imageLayout = {
443
+ measure,
444
+ patch
445
+ };
446
+ const TIMEOUT = 250;
447
+ const imageEffectMap = {
448
+ parallax: "ImageParallax",
449
+ fixed: "ImageReveal"
450
+ };
451
+ function wowImageFactory(services, environmentConsts, contextWindow) {
452
+ return class WowImage extends contextWindow.HTMLElement {
453
+ constructor() {
454
+ super();
455
+ this.childListObserver = null;
456
+ this.timeoutId = null;
457
+ }
458
+ attributeChangedCallback(_, oldValue) {
459
+ if (oldValue) {
460
+ this.reLayout();
461
+ }
462
+ }
463
+ connectedCallback() {
464
+ if (environmentConsts.disableImagesLazyLoading) {
465
+ this.reLayout();
466
+ } else {
467
+ this.observeIntersect();
468
+ }
469
+ }
470
+ disconnectedCallback() {
471
+ this.unobserveResize();
472
+ this.unobserveIntersect();
473
+ this.unobserveChildren();
474
+ }
475
+ static get observedAttributes() {
476
+ return ["data-image-info"];
477
+ }
478
+ reLayout() {
479
+ const domNodes = {};
480
+ const measures = {};
481
+ const imageId = this.getAttribute("id");
482
+ const imageInfo = JSON.parse(this.dataset.imageInfo || "");
483
+ const isResponsive = this.dataset.isResponsive === "true";
484
+ const { bgEffectName } = this.dataset;
485
+ const { scrollEffect } = imageInfo.imageData;
486
+ const { sourceSets } = imageInfo;
487
+ const bgEffect = bgEffectName || scrollEffect && imageEffectMap[scrollEffect];
488
+ if (sourceSets && sourceSets.length) {
489
+ sourceSets.forEach((sourceSet) => {
490
+ if (sourceSet.scrollEffect) {
491
+ sourceSet.scrollEffect = imageEffectMap[sourceSet.scrollEffect];
492
+ }
493
+ });
494
+ }
495
+ domNodes[imageId] = this;
496
+ if (imageInfo.containerId) {
497
+ domNodes[imageInfo.containerId] = contextWindow.document.getElementById(`${imageInfo.containerId}`);
498
+ }
499
+ const containerElm = imageInfo.containerId ? domNodes[imageInfo.containerId] : void 0;
500
+ domNodes.image = this.querySelector("img");
501
+ domNodes.picture = this.querySelector("picture");
502
+ if (!domNodes.image) {
503
+ const target = this;
504
+ this.observeChildren(target);
505
+ return;
506
+ }
507
+ this.unobserveChildren();
508
+ this.observeChildren(this);
509
+ services.mutationService.measure(() => {
510
+ imageLayout.measure(imageId, measures, domNodes, {
511
+ containerElm,
512
+ bgEffect,
513
+ sourceSets
514
+ }, services);
515
+ });
516
+ const patchImage = (shouldLoadImage, loadImageImmediately2) => {
517
+ services.mutationService.mutate(() => {
518
+ imageLayout.patch(imageId, measures, domNodes, imageInfo, services, environmentConsts, shouldLoadImage, isResponsive, bgEffect, loadImageImmediately2);
519
+ });
520
+ };
521
+ const imageElement = domNodes.image;
522
+ const ssrSrcNeedProcessing = this.dataset.hasSsrSrc && !imageElement.dataset.ssrSrcDone;
523
+ const loadImageImmediately = !getImageSrc(imageElement) || ssrSrcNeedProcessing;
524
+ if (loadImageImmediately) {
525
+ patchImage(true, true);
526
+ } else {
527
+ this.debounceImageLoad(patchImage);
528
+ }
529
+ }
530
+ /**
531
+ * Debounce consecutive image loads
532
+ *
533
+ * @param {function} patchImage closure for patching the image
534
+ */
535
+ debounceImageLoad(patchImage) {
536
+ clearTimeout(this.timeoutId);
537
+ this.timeoutId = contextWindow.setTimeout(() => {
538
+ patchImage(true);
539
+ }, TIMEOUT);
540
+ patchImage(false);
541
+ }
542
+ observeResize() {
543
+ var _a;
544
+ (_a = services.resizeService) == null ? void 0 : _a.observe(this);
545
+ }
546
+ unobserveResize() {
547
+ var _a;
548
+ (_a = services.resizeService) == null ? void 0 : _a.unobserve(this);
549
+ }
550
+ observeIntersect() {
551
+ var _a;
552
+ (_a = services.intersectionService) == null ? void 0 : _a.observe(this);
553
+ }
554
+ unobserveIntersect() {
555
+ var _a;
556
+ (_a = services.intersectionService) == null ? void 0 : _a.unobserve(this);
557
+ }
558
+ /**
559
+ * Observe DOM mutations to wait for addition of missing children
560
+ *
561
+ * @param {HTMLElement} parent
562
+ */
563
+ observeChildren(parent) {
564
+ if (!this.childListObserver) {
565
+ this.childListObserver = new contextWindow.MutationObserver(() => {
566
+ this.reLayout();
567
+ });
568
+ }
569
+ this.childListObserver.observe(parent, { childList: true });
570
+ }
571
+ /**
572
+ * Remove DOM MutationObserver if one was created
573
+ */
574
+ unobserveChildren() {
575
+ if (this.childListObserver) {
576
+ this.childListObserver.disconnect();
577
+ this.childListObserver = null;
578
+ }
579
+ }
580
+ };
581
+ }
582
+ function init(contextWindow, services) {
583
+ const elementName = "wow-image";
584
+ contextWindow = contextWindow || window;
585
+ if (contextWindow.customElements.get(elementName) === void 0) {
586
+ let resizeObserver;
587
+ if (contextWindow.ResizeObserver) {
588
+ resizeObserver = new contextWindow.ResizeObserver((entries) => entries.map((entry) => entry.target.reLayout()));
589
+ }
590
+ let intersectionObserver;
591
+ if (contextWindow.IntersectionObserver) {
592
+ intersectionObserver = new IntersectionObserver((entries) => entries.map((entry) => {
593
+ if (entry.isIntersecting) {
594
+ const wowImage = entry.target;
595
+ wowImage.unobserveIntersect();
596
+ wowImage.observeResize();
597
+ }
598
+ return entry;
599
+ }), {
600
+ /**
601
+ * old: 50% from 1080 (desktop) is 540px, 800 (mobile) 400px
602
+ * new: 150% from 1080 (desktop) is 1620, 800 (mobile) 1200
603
+ * chrome [loading=lazy]: 4g - 1250px, lower then 3g - 2500px
604
+ * @see https://web.dev/articles/browser-level-image-lazy-loading#improved-thresholds
605
+ */
606
+ rootMargin: "150% 100%"
607
+ });
608
+ }
609
+ return function(env) {
610
+ const WowImage = wowImageFactory({
611
+ resizeService: resizeObserver,
612
+ intersectionService: intersectionObserver,
613
+ mutationService: fastdom,
614
+ ...services
615
+ }, env, contextWindow);
616
+ contextWindow.customElements.define(elementName, WowImage);
617
+ };
618
+ }
619
+ return;
620
+ }
621
+ const getDevicePixelRatio = () => {
622
+ const isMSMobileDevice = /iemobile/i.test(navigator.userAgent);
623
+ if (isMSMobileDevice) {
624
+ return Math.round(window.screen.availWidth / (window.screen.width || window.document.documentElement.clientWidth));
625
+ }
626
+ return window.devicePixelRatio;
627
+ };
628
+ const getIsImagesLazyLoadingDisabled = () => {
629
+ try {
630
+ return new URL(window.location.href).searchParams.get("disableLazyLoading") === "true";
631
+ } catch {
632
+ return false;
633
+ }
634
+ };
635
+ function initCustomElement(services = {}, contextWindow = null, envConsts = {}) {
636
+ if (typeof window === "undefined") {
637
+ return;
638
+ }
639
+ const env = {
640
+ staticMediaUrl: STATIC_MEDIA_URL,
641
+ mediaRootUrl: MEDIA_ROOT_URL,
642
+ experiments: {},
643
+ devicePixelRatio: getDevicePixelRatio(),
644
+ disableImagesLazyLoading: getIsImagesLazyLoadingDisabled(),
645
+ ...envConsts
646
+ };
647
+ const define = init(contextWindow, services);
648
+ if (define) {
649
+ define(env);
650
+ }
651
+ }
652
+ export {
653
+ getMediaUrlByContext as a,
654
+ camelToKebab as c,
655
+ fastdom as f,
656
+ getMediaSizeQueryString as g,
657
+ initCustomElement as i
658
+ };
@@ -1460,10 +1460,10 @@ export {
1460
1460
  MEDIA_ROOT_URL as M,
1461
1461
  STATIC_MEDIA_URL as S,
1462
1462
  getData as a,
1463
- alignTypes as b,
1464
- getFileExtension as c,
1465
- fileType as d,
1466
- fittingTypes as f,
1463
+ getFileExtension as b,
1464
+ alignTypes as c,
1465
+ fittingTypes as d,
1466
+ fileType as f,
1467
1467
  getPlaceholder as g,
1468
1468
  imageKit as i
1469
1469
  };