PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / assets / js / interactions-shared-utils.js

interactions-shared-utils.js in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at assets/js/interactions-shared-utils.js

432 lines 15.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 'use strict';
2
3 (function() {
4
5 //#region \0rolldown/runtime.js
6 var __defProp = Object.defineProperty;
7 var __name = (target, value) => __defProp(target, "name", {
8 value,
9 configurable: true
10 });
11
12 //#endregion
13
14 //#region node_modules/@babel/runtime/helpers/esm/typeof.js
15 function _typeof(o) {
16 "@babel/helpers - typeof";
17 return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
18 return typeof o;
19 } : function(o) {
20 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
21 }, _typeof(o);
22 }
23
24 //#endregion
25 //#region node_modules/@babel/runtime/helpers/esm/toPrimitive.js
26 function toPrimitive(t, r) {
27 if ("object" != _typeof(t) || !t) return t;
28 var e = t[Symbol.toPrimitive];
29 if (void 0 !== e) {
30 var i = e.call(t, r || "default");
31 if ("object" != _typeof(i)) return i;
32 throw new TypeError("@@toPrimitive must return a primitive value.");
33 }
34 return ("string" === r ? String : Number)(t);
35 }
36
37 //#endregion
38 //#region node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
39 function toPropertyKey(t) {
40 var i = toPrimitive(t, "string");
41 return "symbol" == _typeof(i) ? i : i + "";
42 }
43
44 //#endregion
45 //#region node_modules/@babel/runtime/helpers/esm/defineProperty.js
46 function _defineProperty(e, r, t) {
47 return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
48 value: t,
49 enumerable: !0,
50 configurable: !0,
51 writable: !0
52 }) : e[r] = t, e;
53 }
54
55 //#endregion
56 //#region node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js
57 function _arrayWithHoles(r) {
58 if (Array.isArray(r)) return r;
59 }
60
61 //#endregion
62 //#region node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js
63 function _iterableToArrayLimit(r, l) {
64 var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
65 if (null != t) {
66 var e;
67 var n;
68 var i;
69 var u;
70 var a = [];
71 var f = !0;
72 var o = !1;
73 try {
74 if (i = (t = t.call(r)).next, 0 === l) {
75 if (Object(t) !== t) return;
76 f = !1;
77 } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
78 } catch (r) {
79 o = !0, n = r;
80 } finally {
81 try {
82 if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
83 } finally {
84 if (o) throw n;
85 }
86 }
87 return a;
88 }
89 }
90
91 //#endregion
92 //#region node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
93 function _arrayLikeToArray$1(r, a) {
94 (null == a || a > r.length) && (a = r.length);
95 for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
96 return n;
97 }
98 __name(_arrayLikeToArray$1, "_arrayLikeToArray");
99
100 //#endregion
101 //#region node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
102 function _unsupportedIterableToArray$1(r, a) {
103 if (r) {
104 if ("string" == typeof r) return _arrayLikeToArray$1(r, a);
105 var t = {}.toString.call(r).slice(8, -1);
106 return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$1(r, a) : void 0;
107 }
108 }
109 __name(_unsupportedIterableToArray$1, "_unsupportedIterableToArray");
110
111 //#endregion
112 //#region node_modules/@babel/runtime/helpers/esm/nonIterableRest.js
113 function _nonIterableRest() {
114 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
115 }
116
117 //#endregion
118 //#region node_modules/@babel/runtime/helpers/esm/slicedToArray.js
119 function _slicedToArray(r, e) {
120 return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray$1(r, e) || _nonIterableRest();
121 }
122
123 //#endregion
124 //#region modules/interactions/assets/js/interactions-breakpoints.js
125 var breakpoints = {
126 list: {},
127 active: {},
128 onChange: function onChange() {}
129 };
130 function getActiveBreakpoint() {
131 return breakpoints.active;
132 }
133
134 //#endregion
135 //#region modules/interactions/assets/js/interactions-shared-utils.js
136 function ownKeys(e, r) {
137 var t = Object.keys(e);
138 if (Object.getOwnPropertySymbols) {
139 var o = Object.getOwnPropertySymbols(e);
140 r && (o = o.filter(function(r) {
141 return Object.getOwnPropertyDescriptor(e, r).enumerable;
142 })), t.push.apply(t, o);
143 }
144 return t;
145 }
146 function _objectSpread(e) {
147 for (var r = 1; r < arguments.length; r++) {
148 var t = null != arguments[r] ? arguments[r] : {};
149 r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
150 _defineProperty(e, r, t[r]);
151 }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
152 Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
153 });
154 }
155 return e;
156 }
157 function _createForOfIteratorHelper(r, e) {
158 var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
159 if (!t) {
160 if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
161 t && (r = t);
162 var _n = 0;
163 var F = function F() {};
164 return {
165 s: F,
166 n: function n() {
167 return _n >= r.length ? { done: !0 } : {
168 done: !1,
169 value: r[_n++]
170 };
171 },
172 e: function e(r) {
173 throw r;
174 },
175 f: F
176 };
177 }
178 throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
179 }
180 var o;
181 var a = !0;
182 var u = !1;
183 return {
184 s: function s() {
185 t = t.call(r);
186 },
187 n: function n() {
188 var r = t.next();
189 return a = r.done, r;
190 },
191 e: function e(r) {
192 u = !0, o = r;
193 },
194 f: function f() {
195 try {
196 a || null == t.return || t.return();
197 } finally {
198 if (u) throw o;
199 }
200 }
201 };
202 }
203 function _unsupportedIterableToArray(r, a) {
204 if (r) {
205 if ("string" == typeof r) return _arrayLikeToArray(r, a);
206 var t = {}.toString.call(r).slice(8, -1);
207 return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
208 }
209 }
210 function _arrayLikeToArray(r, a) {
211 (null == a || a > r.length) && (a = r.length);
212 for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
213 return n;
214 }
215 function config() {
216 var _window$ElementorInte;
217 var _window$ElementorInte2;
218 return (_window$ElementorInte = (_window$ElementorInte2 = window.ElementorInteractionsConfig) === null || _window$ElementorInte2 === void 0 ? void 0 : _window$ElementorInte2.constants) !== null && _window$ElementorInte !== void 0 ? _window$ElementorInte : {};
219 }
220 function skipInteraction(interaction) {
221 var _interaction$breakpoi;
222 var breakpoint = getActiveBreakpoint();
223 return interaction === null || interaction === void 0 || (_interaction$breakpoi = interaction.breakpoints) === null || _interaction$breakpoi === void 0 || (_interaction$breakpoi = _interaction$breakpoi.excluded) === null || _interaction$breakpoi === void 0 ? void 0 : _interaction$breakpoi.includes(breakpoint);
224 }
225 function extractInteractionId(interaction) {
226 if ("interaction-item" === (interaction === null || interaction === void 0 ? void 0 : interaction.$$type) && interaction !== null && interaction !== void 0 && interaction.value) {
227 var _interaction$value$in;
228 return ((_interaction$value$in = interaction.value.interaction_id) === null || _interaction$value$in === void 0 ? void 0 : _interaction$value$in.value) || null;
229 }
230 return null;
231 }
232 function motionFunc(name) {
233 var _window;
234 var _window2;
235 if ("function" !== typeof ((_window = window) === null || _window === void 0 || (_window = _window.Motion) === null || _window === void 0 ? void 0 : _window[name])) return;
236 return (_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.Motion) === null || _window2 === void 0 ? void 0 : _window2[name];
237 }
238 function getAnimateFunction() {
239 return motionFunc("animate");
240 }
241 function getInViewFunction() {
242 return motionFunc("inView");
243 }
244 function waitForAnimateFunction(callback) {
245 var maxAttempts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 10;
246 if (getAnimateFunction()) {
247 callback();
248 return;
249 }
250 if (maxAttempts > 0) setTimeout(function() {
251 return waitForAnimateFunction(callback, maxAttempts - 1);
252 }, 100);
253 }
254 function parseInteractionsData(data) {
255 if ("string" === typeof data) try {
256 return JSON.parse(data);
257 } catch (_unused) {
258 return null;
259 }
260 return data;
261 }
262 function unwrapInteractionValue(propValue) {
263 var fallback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
264 if (propValue && "object" === _typeof(propValue) && "$$type" in propValue) return propValue.value;
265 return propValue !== null && propValue !== void 0 ? propValue : fallback;
266 }
267 function timingValueToMs(timingValue, fallbackMs) {
268 if (null === timingValue || void 0 === timingValue) return fallbackMs;
269 var unwrapped = unwrapInteractionValue(timingValue);
270 if ("number" === typeof unwrapped) return unwrapped;
271 var sizeObj = unwrapInteractionValue(unwrapped);
272 var size = sizeObj === null || sizeObj === void 0 ? void 0 : sizeObj.size;
273 var unit = (sizeObj === null || sizeObj === void 0 ? void 0 : sizeObj.unit) || "ms";
274 if ("number" !== typeof size) return fallbackMs;
275 if ("s" === unit) return size * 1e3;
276 return size;
277 }
278 function resetElementStyles(element) {
279 if (!element) return;
280 element.style.transition = "";
281 element.style.transform = "";
282 element.style.opacity = "";
283 }
284 var TRANSFORM_EPSILON = .001;
285 var radiansToDegrees = function radiansToDegrees(radians) {
286 return radians * (180 / Math.PI);
287 };
288 var isNear = function isNear(value, expected) {
289 return Math.abs(value - expected) <= TRANSFORM_EPSILON;
290 };
291 var isNearZero = function isNearZero(value) {
292 return isNear(value, 0);
293 };
294 var isNearOne = function isNearOne(value) {
295 return isNear(value, 1);
296 };
297 function parseMatrixValues(transformValue) {
298 var match = transformValue.match(/^matrix(3d)?\((.+)\)$/);
299 if (!match) return null;
300 return match[2].split(",").map(function(token) {
301 return Number.parseFloat(token.trim());
302 }).filter(function(value) {
303 return Number.isFinite(value);
304 });
305 }
306 function createMatrixFromTransform(transformValue) {
307 if (!transformValue || "none" === transformValue) return null;
308 var _iterator = _createForOfIteratorHelper([window.DOMMatrixReadOnly, window.DOMMatrix].filter(function(Factory) {
309 return "function" === typeof Factory;
310 }));
311 var _step;
312 try {
313 for (_iterator.s(); !(_step = _iterator.n()).done;) {
314 var MatrixFactory = _step.value;
315 try {
316 var _ref;
317 var _matrix$a;
318 var _ref2;
319 var _matrix$b;
320 var _ref3;
321 var _matrix$c;
322 var _ref4;
323 var _matrix$d;
324 var _ref5;
325 var _matrix$e;
326 var _ref6;
327 var _matrix$f;
328 var matrix = new MatrixFactory(transformValue);
329 var compactMatrix = {
330 matrixXfromX: (_ref = (_matrix$a = matrix.a) !== null && _matrix$a !== void 0 ? _matrix$a : matrix.m11) !== null && _ref !== void 0 ? _ref : 1,
331 matrixYfromX: (_ref2 = (_matrix$b = matrix.b) !== null && _matrix$b !== void 0 ? _matrix$b : matrix.m12) !== null && _ref2 !== void 0 ? _ref2 : 0,
332 matrixXfromY: (_ref3 = (_matrix$c = matrix.c) !== null && _matrix$c !== void 0 ? _matrix$c : matrix.m21) !== null && _ref3 !== void 0 ? _ref3 : 0,
333 matrixYfromY: (_ref4 = (_matrix$d = matrix.d) !== null && _matrix$d !== void 0 ? _matrix$d : matrix.m22) !== null && _ref4 !== void 0 ? _ref4 : 1,
334 matrixTranslateX: (_ref5 = (_matrix$e = matrix.e) !== null && _matrix$e !== void 0 ? _matrix$e : matrix.m41) !== null && _ref5 !== void 0 ? _ref5 : 0,
335 matrixTranslateY: (_ref6 = (_matrix$f = matrix.f) !== null && _matrix$f !== void 0 ? _matrix$f : matrix.m42) !== null && _ref6 !== void 0 ? _ref6 : 0
336 };
337 if (Object.values(compactMatrix).every(Number.isFinite)) return compactMatrix;
338 } catch (_unused2) {}
339 }
340 } catch (err) {
341 _iterator.e(err);
342 } finally {
343 _iterator.f();
344 }
345 var parsedValues = parseMatrixValues(transformValue);
346 if (!parsedValues) return null;
347 if (6 === parsedValues.length) {
348 var _parsedValues = _slicedToArray(parsedValues, 6);
349 return {
350 matrixXfromX: _parsedValues[0],
351 matrixYfromX: _parsedValues[1],
352 matrixXfromY: _parsedValues[2],
353 matrixYfromY: _parsedValues[3],
354 matrixTranslateX: _parsedValues[4],
355 matrixTranslateY: _parsedValues[5]
356 };
357 }
358 if (16 === parsedValues.length) {
359 var _parsedValues2 = _slicedToArray(parsedValues, 14);
360 return {
361 matrixXfromX: _parsedValues2[0],
362 matrixYfromX: _parsedValues2[1],
363 matrixXfromY: _parsedValues2[4],
364 matrixYfromY: _parsedValues2[5],
365 matrixTranslateX: _parsedValues2[12],
366 matrixTranslateY: _parsedValues2[13]
367 };
368 }
369 return null;
370 }
371 function getTransformBaselineFromComputedStyle(element) {
372 if (!element) return null;
373 var computedStyle = window.getComputedStyle(element);
374 var matrix = createMatrixFromTransform((computedStyle === null || computedStyle === void 0 ? void 0 : computedStyle.transform) || "");
375 if (!matrix) return null;
376 var matrixXfromX = matrix.matrixXfromX;
377 var matrixYfromX = matrix.matrixYfromX;
378 var matrixXfromY = matrix.matrixXfromY;
379 var matrixYfromY = matrix.matrixYfromY;
380 var matrixTranslateX = matrix.matrixTranslateX;
381 var matrixTranslateY = matrix.matrixTranslateY;
382 var scaleX = Math.hypot(matrixXfromX, matrixYfromX);
383 var determinant = matrixXfromX * matrixYfromY - matrixYfromX * matrixXfromY;
384 var scaleY = scaleX ? determinant / scaleX : Math.hypot(matrixXfromY, matrixYfromY);
385 var rotate = radiansToDegrees(Math.atan2(matrixYfromX, matrixXfromX));
386 var shear = scaleX ? (matrixXfromX * matrixXfromY + matrixYfromX * matrixYfromY) / (scaleX * scaleX) : 0;
387 var skewX = radiansToDegrees(Math.atan(shear));
388 return {
389 x: matrixTranslateX,
390 y: matrixTranslateY,
391 scaleX: Number.isFinite(scaleX) ? scaleX : 1,
392 scaleY: Number.isFinite(scaleY) ? scaleY : 1,
393 rotate: Number.isFinite(rotate) ? rotate : 0,
394 skewX: Number.isFinite(skewX) ? skewX : 0
395 };
396 }
397 function preserveTransformKeyframes(keyframes, baseline) {
398 if (!baseline) return keyframes;
399 var mergedKeyframes = _objectSpread({}, keyframes);
400 var hasScaleShorthand = mergedKeyframes.scale !== void 0;
401 var canSetScaleX = mergedKeyframes.scaleX === void 0 && !isNearOne(baseline.scaleX);
402 var canSetScaleY = mergedKeyframes.scaleY === void 0 && !isNearOne(baseline.scaleY);
403 if (mergedKeyframes.x === void 0 && !isNearZero(baseline.x)) mergedKeyframes.x = [baseline.x, baseline.x];
404 if (mergedKeyframes.y === void 0 && !isNearZero(baseline.y)) mergedKeyframes.y = [baseline.y, baseline.y];
405 if (!hasScaleShorthand) if (canSetScaleX && canSetScaleY && isNear(baseline.scaleX, baseline.scaleY)) mergedKeyframes.scale = [baseline.scaleX, baseline.scaleX];
406 else {
407 if (canSetScaleX) mergedKeyframes.scaleX = [baseline.scaleX, baseline.scaleX];
408 if (canSetScaleY) mergedKeyframes.scaleY = [baseline.scaleY, baseline.scaleY];
409 }
410 if (mergedKeyframes.rotate === void 0 && mergedKeyframes.rotateZ === void 0 && !isNearZero(baseline.rotate)) mergedKeyframes.rotate = [baseline.rotate, baseline.rotate];
411 if (mergedKeyframes.skew === void 0 && mergedKeyframes.skewX === void 0 && !isNearZero(baseline.skewX)) mergedKeyframes.skewX = [baseline.skewX, baseline.skewX];
412 return mergedKeyframes;
413 }
414 window.elementorModules = window.elementorModules || {};
415 window.elementorModules.interactions = {
416 config,
417 skipInteraction,
418 extractInteractionId,
419 getAnimateFunction,
420 getInViewFunction,
421 waitForAnimateFunction,
422 parseInteractionsData,
423 unwrapInteractionValue,
424 timingValueToMs,
425 resetElementStyles,
426 getTransformBaselineFromComputedStyle,
427 preserveTransformKeyframes
428 };
429
430 //#endregion
431 })();
432 //# sourceMappingURL=interactions-shared-utils.js.map