@micromag/core 0.4.71 → 0.4.74

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.
package/lib/utils.js DELETED
@@ -1,1300 +0,0 @@
1
- 'use strict';
2
-
3
- var isString = require('lodash/isString');
4
- var isNumber = require('lodash/isNumber');
5
- var changeCase = require('change-case');
6
- var _regenerator = require('@babel/runtime/helpers/regenerator');
7
- var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
8
- var isObject = require('lodash/isObject');
9
- var react = require('react');
10
- var tinycolor = require('tinycolor2');
11
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
12
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
13
- var isArray = require('lodash/isArray');
14
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
15
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
16
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
17
- var slugify = require('slugify');
18
-
19
- function addNonBreakingSpaces(text) {
20
- return isString(text) ? text.replace(/«\s/g, '« ').replace(/\s»/g, ' »').replace(/\s:\s/g, ' : ') : text;
21
- }
22
-
23
- var convertStyleToString = function convertStyleToString(style) {
24
- return style !== null ? Object.keys(style).map(function (key) {
25
- return "".concat(changeCase.kebabCase(key), ":").concat(isNumber(style[key]) ? "".concat(style[key], "px") : style[key], ";");
26
- }).join('\n') : '';
27
- };
28
-
29
- /*! clipboard-copy. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
30
-
31
- // @note vendoring this: https://github.com/feross/clipboard-copy/blob/master/index.js
32
- // we might want to add that to the npm deps and just use it
33
-
34
- function makeError() {
35
- return new DOMException('The request is not allowed', 'NotAllowedError');
36
- }
37
- function copyClipboardApi(_x) {
38
- return _copyClipboardApi.apply(this, arguments);
39
- }
40
- function _copyClipboardApi() {
41
- _copyClipboardApi = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(text) {
42
- return _regenerator().w(function (_context) {
43
- while (1) switch (_context.n) {
44
- case 0:
45
- if (navigator.clipboard) {
46
- _context.n = 1;
47
- break;
48
- }
49
- throw makeError();
50
- case 1:
51
- return _context.a(2, navigator.clipboard.writeText(text));
52
- }
53
- }, _callee);
54
- }));
55
- return _copyClipboardApi.apply(this, arguments);
56
- }
57
- function copyExecCommand(_x2) {
58
- return _copyExecCommand.apply(this, arguments);
59
- }
60
- function _copyExecCommand() {
61
- _copyExecCommand = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(text) {
62
- var span, selection, range, success;
63
- return _regenerator().w(function (_context2) {
64
- while (1) switch (_context2.n) {
65
- case 0:
66
- // Put the text to copy into a <span>
67
- span = document.createElement('span');
68
- span.textContent = text;
69
-
70
- // Preserve consecutive spaces and newlines
71
- span.style.whiteSpace = 'pre';
72
- span.style.webkitUserSelect = 'auto';
73
- span.style.userSelect = 'all';
74
-
75
- // Add the <span> to the page
76
- document.body.appendChild(span);
77
-
78
- // Make a selection object representing the range of text selected by the user
79
- selection = window.getSelection();
80
- range = window.document.createRange();
81
- selection.removeAllRanges();
82
- range.selectNode(span);
83
- selection.addRange(range);
84
-
85
- // Copy text to the clipboard
86
- success = false;
87
- try {
88
- success = window.document.execCommand('copy');
89
- } finally {
90
- // Cleanup
91
- selection.removeAllRanges();
92
- window.document.body.removeChild(span);
93
- }
94
- if (success) {
95
- _context2.n = 1;
96
- break;
97
- }
98
- throw makeError();
99
- case 1:
100
- return _context2.a(2);
101
- }
102
- }, _callee2);
103
- }));
104
- return _copyExecCommand.apply(this, arguments);
105
- }
106
- function copyToClipboard(_x3) {
107
- return _copyToClipboard.apply(this, arguments);
108
- }
109
- function _copyToClipboard() {
110
- _copyToClipboard = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(text) {
111
- var _t, _t2;
112
- return _regenerator().w(function (_context3) {
113
- while (1) switch (_context3.p = _context3.n) {
114
- case 0:
115
- _context3.p = 0;
116
- _context3.n = 1;
117
- return copyClipboardApi(text);
118
- case 1:
119
- _context3.n = 6;
120
- break;
121
- case 2:
122
- _context3.p = 2;
123
- _t = _context3.v;
124
- _context3.p = 3;
125
- _context3.n = 4;
126
- return copyExecCommand(text);
127
- case 4:
128
- _context3.n = 6;
129
- break;
130
- case 5:
131
- _context3.p = 5;
132
- _t2 = _context3.v;
133
- throw _t2 || _t || makeError();
134
- case 6:
135
- return _context3.a(2);
136
- }
137
- }, _callee3, null, [[3, 5], [0, 2]]);
138
- }));
139
- return _copyToClipboard.apply(this, arguments);
140
- }
141
-
142
- var createNullableOnChange = function createNullableOnChange() {
143
- var onChange = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
144
- return function (newValue) {
145
- var nullableValue = newValue;
146
- if (isObject(newValue)) {
147
- var allNull = Object.keys(newValue).reduce(function (acc, key) {
148
- return acc && newValue[key] === null;
149
- }, true);
150
- if (allNull) {
151
- nullableValue = null;
152
- }
153
- }
154
- if (onChange !== null) {
155
- onChange(nullableValue);
156
- }
157
- };
158
- };
159
-
160
- var createUseEvent = function createUseEvent(eventsManager) {
161
- return function (event, callback) {
162
- var enabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
163
- react.useEffect(function () {
164
- if (enabled && eventsManager !== null) {
165
- eventsManager.subscribe(event, callback);
166
- }
167
- return function () {
168
- if (enabled && eventsManager !== null) {
169
- eventsManager.unsubscribe(event, callback);
170
- }
171
- };
172
- }, [eventsManager, event, callback, enabled]);
173
- };
174
- };
175
-
176
- function cssEscape(value) {
177
- return typeof CSS !== 'undefined' && typeof CSS.escape === 'function' ? CSS.escape(value) : value.replace(/([^\x00-\x7F]|[!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g, '\\$1');
178
- }
179
-
180
- /* eslint-disable */
181
- var easings = {
182
- linear: function linear(x) {
183
- return x;
184
- },
185
- easeInQuad: function easeInQuad(x) {
186
- return x * x;
187
- },
188
- easeOutQuad: function easeOutQuad(x) {
189
- return 1 - (1 - x) * (1 - x);
190
- },
191
- easeInOutQuad: function easeInOutQuad(x) {
192
- return x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2;
193
- },
194
- easeInCubic: function easeInCubic(x) {
195
- return x * x * x;
196
- },
197
- easeOutCubic: function easeOutCubic(x) {
198
- return 1 - Math.pow(1 - x, 3);
199
- },
200
- easeInOutCubic: function easeInOutCubic(x) {
201
- return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
202
- },
203
- easeInQuart: function easeInQuart(x) {
204
- return x * x * x * x;
205
- },
206
- easeOutQuart: function easeOutQuart(x) {
207
- return 1 - Math.pow(1 - x, 4);
208
- },
209
- easeInOutQuart: function easeInOutQuart(x) {
210
- return x < 0.5 ? 8 * x * x * x * x : 1 - Math.pow(-2 * x + 2, 4) / 2;
211
- },
212
- easeInQuint: function easeInQuint(x) {
213
- return x * x * x * x * x;
214
- },
215
- easeOutQuint: function easeOutQuint(x) {
216
- return 1 - Math.pow(1 - x, 5);
217
- },
218
- easeInOutQuint: function easeInOutQuint(x) {
219
- return x < 0.5 ? 16 * x * x * x * x * x : 1 - Math.pow(-2 * x + 2, 5) / 2;
220
- },
221
- easeInSine: function easeInSine(x) {
222
- return 1 - Math.cos(x * Math.PI / 2);
223
- },
224
- easeOutSine: function easeOutSine(x) {
225
- return Math.sin(x * Math.PI / 2);
226
- },
227
- easeInOutSine: function easeInOutSine(x) {
228
- return -(Math.cos(Math.PI * x) - 1) / 2;
229
- },
230
- easeInExpo: function easeInExpo(x) {
231
- return x === 0 ? 0 : Math.pow(2, 10 * x - 10);
232
- },
233
- easeOutExpo: function easeOutExpo(x) {
234
- return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
235
- },
236
- easeInOutExpo: function easeInOutExpo(x) {
237
- return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? Math.pow(2, 20 * x - 10) / 2 : (2 - Math.pow(2, -20 * x + 10)) / 2;
238
- },
239
- easeInCirc: function easeInCirc(x) {
240
- return 1 - Math.sqrt(1 - Math.pow(x, 2));
241
- },
242
- easeOutCirc: function easeOutCirc(x) {
243
- return Math.sqrt(1 - Math.pow(x - 1, 2));
244
- },
245
- easeInOutCirc: function easeInOutCirc(x) {
246
- return x < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2;
247
- },
248
- easeInBack: function easeInBack(x) {
249
- return c3 * x * x * x - c1 * x * x;
250
- },
251
- easeOutBack: function easeOutBack(x) {
252
- return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
253
- },
254
- easeInOutBack: function easeInOutBack(x) {
255
- return x < 0.5 ? Math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2) / 2 : (Math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2;
256
- },
257
- easeInElastic: function easeInElastic(x) {
258
- return x === 0 ? 0 : x === 1 ? 1 : -Math.pow(2, 10 * x - 10) * Math.sin((x * 10 - 10.75) * c4);
259
- },
260
- easeOutElastic: function easeOutElastic(x) {
261
- return x === 0 ? 0 : x === 1 ? 1 : Math.pow(2, -10 * x) * Math.sin((x * 10 - 0.75) * c4) + 1;
262
- },
263
- easeInOutElastic: function easeInOutElastic(x) {
264
- return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? -(Math.pow(2, 20 * x - 10) * Math.sin((20 * x - 11.125) * c5)) / 2 : Math.pow(2, -20 * x + 10) * Math.sin((20 * x - 11.125) * c5) / 2 + 1;
265
- }
266
- };
267
-
268
- var getColorAsString = function getColorAsString() {
269
- var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
270
- var overideAlpha = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
271
- if (value === null) {
272
- return null;
273
- }
274
- var _ref = isString(value) ? {
275
- color: value
276
- } : value,
277
- _ref$color = _ref.color,
278
- color = _ref$color === void 0 ? null : _ref$color,
279
- _ref$alpha = _ref.alpha,
280
- alpha = _ref$alpha === void 0 ? null : _ref$alpha;
281
- return alpha !== null || overideAlpha !== null ? tinycolor(color).setAlpha(overideAlpha !== null ? overideAlpha : alpha).toRgbString() : color;
282
- };
283
-
284
- var getComponentFromName = function getComponentFromName() {
285
- var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
286
- var components = arguments.length > 1 ? arguments[1] : undefined;
287
- var defaultComponent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
288
- if (components === null || name === null) {
289
- return defaultComponent;
290
- }
291
- var pascalName = changeCase.pascalCase(name);
292
- return components[pascalName] || components[name] || defaultComponent;
293
- };
294
-
295
- var deviceScreens = [{
296
- name: 'mobile'
297
- }, {
298
- name: 'small',
299
- mediaQuery: 'only screen and (min-width: 500px)'
300
- }, {
301
- name: 'medium',
302
- mediaQuery: 'only screen and (min-width: 790px)'
303
- }, {
304
- name: 'large',
305
- mediaQuery: 'only screen and (min-width: 1000px)'
306
- }, {
307
- name: 'very-large',
308
- mediaQuery: 'only screen and (min-width: 1600px)'
309
- }];
310
-
311
- // eslint-disable-next-line import/prefer-default-export
312
- var getDeviceScreens = function getDeviceScreens() {
313
- return deviceScreens;
314
- };
315
-
316
- var getDisplayName = function getDisplayName(_ref) {
317
- var _ref$displayName = _ref.displayName,
318
- displayName = _ref$displayName === void 0 ? null : _ref$displayName,
319
- _ref$name = _ref.name,
320
- name = _ref$name === void 0 ? null : _ref$name;
321
- return displayName || name || 'Component';
322
- };
323
-
324
- var _getFieldByName = function getFieldByName(fields, name) {
325
- return fields.reduce(function (foundField, it) {
326
- if (foundField !== null) {
327
- return foundField;
328
- }
329
- var _it$name = it.name,
330
- fieldName = _it$name === void 0 ? null : _it$name,
331
- _it$fields = it.fields,
332
- subFields = _it$fields === void 0 ? [] : _it$fields;
333
- if (name !== null && fieldName === name) {
334
- return it;
335
- }
336
- return _getFieldByName(subFields, name);
337
- }, null);
338
- };
339
-
340
- var getFieldFromPath = function getFieldFromPath(path, fields, fieldManager) {
341
- return (isArray(path) ? path : [path]).reduce(function (foundField, key) {
342
- if (foundField === null) {
343
- return null;
344
- }
345
- var _foundField$type = foundField.type,
346
- type = _foundField$type === void 0 ? null : _foundField$type,
347
- _foundField$fields = foundField.fields,
348
- fieldFields = _foundField$fields === void 0 ? null : _foundField$fields,
349
- _foundField$field = foundField.field,
350
- field = _foundField$field === void 0 ? null : _foundField$field,
351
- _foundField$itemsFiel = foundField.itemsField,
352
- itemsField = _foundField$itemsFiel === void 0 ? null : _foundField$itemsFiel;
353
- var finalType = field !== null ? field.type || type : type;
354
- var definition = fieldManager.getDefinition(finalType);
355
- var _ref = finalType !== null ? definition : foundField,
356
- _ref$fields = _ref.fields,
357
- subFields = _ref$fields === void 0 ? null : _ref$fields,
358
- _ref$settings = _ref.settings,
359
- settings = _ref$settings === void 0 ? null : _ref$settings,
360
- _ref$itemsField = _ref.itemsField,
361
- defItemsField = _ref$itemsField === void 0 ? null : _ref$itemsField;
362
- var finalItemsField = itemsField || defItemsField;
363
- if (finalItemsField !== null && key.match(/^[0-9]+$/)) {
364
- return _objectSpread(_objectSpread({}, finalItemsField), {}, {
365
- name: path.join('/'),
366
- listItems: true
367
- });
368
- }
369
- return _getFieldByName([].concat(_toConsumableArray(fieldFields || []), _toConsumableArray(subFields || []), _toConsumableArray(settings || [])), key);
370
- }, {
371
- fields: fields
372
- });
373
- };
374
-
375
- var getFileName = function getFileName() {
376
- var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
377
- if (url === null || typeof url.match === 'undefined') {
378
- return null;
379
- }
380
- return url.match(/([^/]+)(\?.*)?$/)[1] || url;
381
- };
382
-
383
- var getFontFamily = function getFontFamily(value) {
384
- if (value == null) {
385
- return null;
386
- }
387
- var _ref = isObject(value) ? value : {
388
- name: value
389
- },
390
- name = _ref.name,
391
- _ref$fallback = _ref.fallback,
392
- fallback = _ref$fallback === void 0 ? null : _ref$fallback;
393
- return [name, fallback].filter(function (it) {
394
- return it !== null;
395
- }).map(function (it) {
396
- return "\"".concat(it, "\"");
397
- }).join(', ');
398
- };
399
-
400
- var _excluded$1 = ["isPreview", "isView", "current", "openWebView", "enableInteraction", "disableInteraction"];
401
- var getFooterProps = function getFooterProps() {
402
- var footer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
403
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
404
- _ref$isPreview = _ref.isPreview,
405
- isPreview = _ref$isPreview === void 0 ? false : _ref$isPreview,
406
- _ref$isView = _ref.isView,
407
- isView = _ref$isView === void 0 ? false : _ref$isView,
408
- _ref$current = _ref.current,
409
- current = _ref$current === void 0 ? false : _ref$current,
410
- _ref$openWebView = _ref.openWebView,
411
- openWebView = _ref$openWebView === void 0 ? false : _ref$openWebView,
412
- _ref$enableInteractio = _ref.enableInteraction,
413
- enableInteraction = _ref$enableInteractio === void 0 ? true : _ref$enableInteractio,
414
- _ref$disableInteracti = _ref.disableInteraction,
415
- disableInteraction = _ref$disableInteracti === void 0 ? false : _ref$disableInteracti,
416
- otherProps = _objectWithoutProperties(_ref, _excluded$1);
417
- var _ref2 = footer || {},
418
- _ref2$callToAction = _ref2.callToAction,
419
- callToAction = _ref2$callToAction === void 0 ? null : _ref2$callToAction;
420
- var footerProps = react.useMemo(function () {
421
- return {
422
- callToAction: _objectSpread(_objectSpread({}, callToAction), {}, {
423
- animationDisabled: isPreview,
424
- focusable: current && isView,
425
- openWebView: openWebView,
426
- enableInteraction: enableInteraction,
427
- disableInteraction: disableInteraction
428
- }, otherProps)
429
- };
430
- }, [callToAction, isPreview, isView, current, enableInteraction, disableInteraction, otherProps]);
431
- return footerProps;
432
- };
433
-
434
- var getGridLayoutName = function getGridLayoutName(layout) {
435
- return layout.map(function (it) {
436
- return "".concat(it.rows, "_").concat(it.columns.join('_'));
437
- }).join('|');
438
- };
439
-
440
- var getRemainder = function getRemainder(number) {
441
- var remainder = number - Math.floor(number);
442
- return remainder.toFixed(4);
443
- };
444
- var largestRemainderRound = function largestRemainderRound(numbers, desiredTotal) {
445
- if (!isArray(numbers) || numbers.length < 1) return numbers;
446
- var result = numbers.map(function (number, index) {
447
- return {
448
- floor: Math.floor(number) || 0,
449
- remainder: getRemainder(number),
450
- index: index
451
- };
452
- }).sort(function (a, b) {
453
- return b.remainder - a.remainder;
454
- });
455
- var lowerSum = result.reduce(function (sum, current) {
456
- return sum + current.floor;
457
- }, 0);
458
- var delta = desiredTotal - lowerSum;
459
- for (var i = 0; i < delta; i += 1) {
460
- if (result[i]) {
461
- result[i].floor += 1;
462
- }
463
- }
464
- return result.sort(function (a, b) {
465
- return a.index - b.index;
466
- }).map(function (res) {
467
- return res.floor;
468
- });
469
- };
470
-
471
- var _excluded = ["image", "video", "media", "color"];
472
- var getLayersFromBackground = function getLayersFromBackground() {
473
- var background = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
474
- if (background === null) {
475
- return [];
476
- }
477
- return (isArray(background) ? background : [background]).reduce(function (layers, _ref) {
478
- var _ref$image = _ref.image,
479
- image = _ref$image === void 0 ? null : _ref$image,
480
- _ref$video = _ref.video,
481
- video = _ref$video === void 0 ? null : _ref$video,
482
- _ref$media = _ref.media,
483
- media = _ref$media === void 0 ? null : _ref$media,
484
- _ref$color = _ref.color,
485
- color = _ref$color === void 0 ? null : _ref$color,
486
- data = _objectWithoutProperties(_ref, _excluded);
487
- if (image === null && video === null && color === null) {
488
- return layers;
489
- }
490
- if (image !== null && video !== null) {
491
- return [].concat(_toConsumableArray(layers), [_objectSpread({
492
- media: image
493
- }, data), _objectSpread({
494
- media: video,
495
- color: color
496
- }, data)]);
497
- }
498
- return [].concat(_toConsumableArray(layers), [_objectSpread({
499
- media: media || image || video,
500
- color: color
501
- }, data)]);
502
- }, []);
503
- };
504
-
505
- var getMediaFilesAsArray = function getMediaFilesAsArray(files) {
506
- return files !== null && isArray(files) ? files : Object.keys(files || {}).reduce(function (newFiles, key) {
507
- return [].concat(_toConsumableArray(newFiles), [_objectSpread({
508
- handle: key
509
- }, files[key])]);
510
- }, []);
511
- };
512
-
513
- // eslint-disable-next-line import/prefer-default-export
514
- var getOptimalImageUrl = function getOptimalImageUrl() {
515
- var media = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
516
- var containerWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
517
- var containerHeight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
518
- var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
519
- _ref$resolution = _ref.resolution,
520
- resolution = _ref$resolution === void 0 ? 1 : _ref$resolution,
521
- _ref$maxDiff = _ref.maxDiff,
522
- maxDiff = _ref$maxDiff === void 0 ? 800 : _ref$maxDiff,
523
- _ref$supportsWebp = _ref.supportsWebp,
524
- supportsWebp = _ref$supportsWebp === void 0 ? false : _ref$supportsWebp;
525
- var _ref2 = media || {},
526
- _ref2$sizes = _ref2.sizes,
527
- sizes = _ref2$sizes === void 0 ? null : _ref2$sizes,
528
- _ref2$url = _ref2.url,
529
- defaultUrl = _ref2$url === void 0 ? null : _ref2$url,
530
- _ref2$webp_url = _ref2.webp_url,
531
- defaultWebpUrl = _ref2$webp_url === void 0 ? null : _ref2$webp_url,
532
- _ref2$metadata = _ref2.metadata,
533
- _ref2$metadata2 = _ref2$metadata === void 0 ? {} : _ref2$metadata,
534
- imgWidth = _ref2$metadata2.width,
535
- imgHeight = _ref2$metadata2.height;
536
- var finalDefaultUrl = supportsWebp && defaultWebpUrl !== null ? defaultWebpUrl : defaultUrl;
537
- if (sizes === null || containerWidth === null && containerHeight === null) {
538
- return finalDefaultUrl;
539
- }
540
- var finalSizes = _objectSpread({
541
- original: {
542
- url: finalDefaultUrl,
543
- width: imgWidth,
544
- height: imgHeight
545
- }
546
- }, sizes);
547
- var finalContainerWidth = containerWidth !== null && resolution !== null ? containerWidth * resolution : containerWidth;
548
- var finalContainerHeight = containerHeight !== null && resolution !== null ? containerHeight * resolution : containerHeight;
549
- var _Object$keys$reduce = Object.keys(finalSizes).reduce(function (acc, key) {
550
- var currentDiff = acc.diff,
551
- currentIsLarger = acc.isLarger,
552
- currentSize = acc.size;
553
- var _finalSizes$key = finalSizes[key],
554
- url = _finalSizes$key.url,
555
- _finalSizes$key$webp_ = _finalSizes$key.webp_url,
556
- webpUrl = _finalSizes$key$webp_ === void 0 ? null : _finalSizes$key$webp_,
557
- _finalSizes$key$width = _finalSizes$key.width,
558
- width = _finalSizes$key$width === void 0 ? null : _finalSizes$key$width,
559
- _finalSizes$key$heigh = _finalSizes$key.height,
560
- height = _finalSizes$key$heigh === void 0 ? null : _finalSizes$key$heigh;
561
- var sizeUrl = supportsWebp && webpUrl !== null ? webpUrl : url;
562
- var diffWidth = width !== null && finalContainerWidth !== null ? width - finalContainerWidth : null;
563
- var diffHeight = height !== null && finalContainerHeight !== null ? height - finalContainerHeight : null;
564
- var isLarger = (diffWidth === null || diffWidth >= 0) && (diffHeight === null || diffHeight >= 0);
565
- var diff = [diffWidth, diffHeight].reduce(function (total, value) {
566
- return value !== null ? (total || 0) + Math.abs(value) : total;
567
- }, null);
568
- if (diff === null) {
569
- diff = Infinity;
570
- }
571
- var size = (width || 0) + (height || 0);
572
- var sizeIsLarger = size > currentSize;
573
- if (
574
- // Difference is lower and image is larger
575
- diff < currentDiff && isLarger ||
576
- // Difference is lower and current is not larger or diff is greater than max
577
- diff < currentDiff && (!currentIsLarger && sizeIsLarger || currentDiff > maxDiff) ||
578
- // Image is larger and diff is smaller than max
579
- diff <= maxDiff && !currentIsLarger && isLarger ||
580
- // Image is larger than previous
581
- diff <= maxDiff && !currentIsLarger && !isLarger && sizeIsLarger) {
582
- return {
583
- key: key,
584
- url: sizeUrl,
585
- diff: diff,
586
- isLarger: isLarger
587
- };
588
- }
589
- return acc;
590
- }, {
591
- key: null,
592
- url: finalDefaultUrl,
593
- diff: Infinity,
594
- isLarger: false,
595
- size: 0
596
- }),
597
- finalUrl = _Object$keys$reduce.url;
598
- return finalUrl;
599
- };
600
-
601
- var getSecondsFromTime = function getSecondsFromTime(time) {
602
- var t = time.split(':');
603
- try {
604
- var s = t[2].split(',');
605
- if (s.length === 1) {
606
- s = t[2].split('.');
607
- }
608
- return parseFloat(t[0], 10) * 3600 + parseFloat(t[1], 10) * 60 + parseFloat(s[0], 10) + parseFloat(s[1], 10) / 1000;
609
- } catch (e) {
610
- return 0;
611
- }
612
- };
613
-
614
- var getScreenExtraField = function getScreenExtraField(intl) {
615
- return {
616
- name: 'parameters',
617
- type: 'parameters',
618
- label: intl.formatMessage({
619
- id: "8A8cuq",
620
- defaultMessage: [{
621
- "type": 0,
622
- "value": "Parameters"
623
- }]
624
- })
625
- };
626
- };
627
-
628
- function getScreenFieldsWithStates(definition) {
629
- var _ref = definition || {},
630
- _ref$fields = _ref.fields,
631
- screenFields = _ref$fields === void 0 ? null : _ref$fields,
632
- _ref$states = _ref.states,
633
- states = _ref$states === void 0 ? null : _ref$states;
634
- if (states === null) {
635
- return screenFields;
636
- }
637
- var extraFields = states.reduce(function (statesFields, current) {
638
- var _ref2 = current || {},
639
- id = _ref2.id,
640
- _ref2$fields = _ref2.fields,
641
- fields = _ref2$fields === void 0 ? [] : _ref2$fields,
642
- _ref2$repeatable = _ref2.repeatable,
643
- repeatable = _ref2$repeatable === void 0 ? false : _ref2$repeatable,
644
- _ref2$fieldName = _ref2.fieldName,
645
- fieldName = _ref2$fieldName === void 0 ? null : _ref2$fieldName,
646
- label = _ref2.label,
647
- _ref2$defaultValue = _ref2.defaultValue,
648
- defaultValue = _ref2$defaultValue === void 0 ? null : _ref2$defaultValue;
649
- return [].concat(_toConsumableArray(statesFields), _toConsumableArray(repeatable ? [{
650
- type: 'items',
651
- name: fieldName || id,
652
- label: label,
653
- defaultValue: defaultValue,
654
- stateId: id,
655
- itemsField: {
656
- label: label,
657
- type: 'fields',
658
- fields: fields
659
- }
660
- }] : []), _toConsumableArray(!repeatable && fieldName !== null ? [{
661
- type: 'fields',
662
- name: fieldName,
663
- stateId: id,
664
- fields: fields
665
- }] : []), _toConsumableArray(!repeatable && fieldName === null ? fields.map(function (it) {
666
- return _objectSpread(_objectSpread({}, it), {}, {
667
- stateId: id
668
- });
669
- }) : []));
670
- }, []);
671
- return [].concat(_toConsumableArray(extraFields), _toConsumableArray(screenFields));
672
- }
673
-
674
- function getShadowCoords(angle, distance) {
675
- var x = (Math.cos(angle) * distance).toFixed(3);
676
- var y = (Math.sin(angle) * distance).toFixed(3);
677
- return {
678
- x: x,
679
- y: y
680
- };
681
- }
682
-
683
- function getJustifyContent(horizontal) {
684
- if (horizontal === 'left') return 'flex-start';
685
- if (horizontal === 'middle') return 'center';
686
- if (horizontal === 'right') return 'flex-end';
687
- return null;
688
- }
689
- function getAlignItems(vertical) {
690
- if (vertical === 'top') return 'flex-start';
691
- if (vertical === 'middle') return 'center';
692
- if (vertical === 'bottom') return 'flex-end';
693
- return null;
694
- }
695
- var getStyleFromAlignment = function getStyleFromAlignment(value) {
696
- var invertAxis = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
697
- var defaultAlignment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
698
- if (value === null) {
699
- return null;
700
- }
701
- var _value$horizontal = value.horizontal,
702
- horizontal = _value$horizontal === void 0 ? null : _value$horizontal,
703
- _value$vertical = value.vertical,
704
- vertical = _value$vertical === void 0 ? null : _value$vertical;
705
- var justifyContent = getJustifyContent(horizontal);
706
- var alignItems = getAlignItems(vertical);
707
- if (invertAxis) {
708
- return {
709
- justifyContent: alignItems || defaultAlignment,
710
- alignItems: justifyContent || defaultAlignment
711
- };
712
- }
713
- return {
714
- justifyContent: justifyContent || defaultAlignment,
715
- alignItems: alignItems || alignItems
716
- };
717
- };
718
-
719
- var getStyleFromColor = function getStyleFromColor() {
720
- var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
721
- var property = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'backgroundColor';
722
- var overideAlpha = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
723
- var color = getColorAsString(value, overideAlpha);
724
- return color !== null ? _defineProperty({}, property, color) : null;
725
- };
726
-
727
- var getStyleFromBorder = function getStyleFromBorder(value) {
728
- if (value == null) {
729
- return null;
730
- }
731
- var _value$width = value.width,
732
- width = _value$width === void 0 ? null : _value$width,
733
- _value$style = value.style,
734
- borderStyle = _value$style === void 0 ? null : _value$style,
735
- _value$color = value.color,
736
- color = _value$color === void 0 ? null : _value$color;
737
- return _objectSpread(_objectSpread(_objectSpread({}, width !== null ? {
738
- borderWidth: width
739
- } : null), borderStyle !== null ? {
740
- borderStyle: borderStyle
741
- } : null), getStyleFromColor(color, 'borderColor'));
742
- };
743
-
744
- var getStyleFromShadow = function getStyleFromShadow(value) {
745
- if (value == null) {
746
- return null;
747
- }
748
- var _ref = value || {},
749
- _ref$shadowAngle = _ref.shadowAngle,
750
- shadowAngle = _ref$shadowAngle === void 0 ? null : _ref$shadowAngle,
751
- _ref$shadowDistance = _ref.shadowDistance,
752
- shadowDistance = _ref$shadowDistance === void 0 ? null : _ref$shadowDistance,
753
- _ref$shadowBlur = _ref.shadowBlur,
754
- shadowBlur = _ref$shadowBlur === void 0 ? null : _ref$shadowBlur,
755
- _ref$shadowColor = _ref.shadowColor,
756
- shadowColor = _ref$shadowColor === void 0 ? null : _ref$shadowColor;
757
- if (!shadowAngle) return null;
758
- var blur = shadowBlur || '0';
759
- var color = getColorAsString(shadowColor) || '#000000';
760
- var _getShadowCoords = getShadowCoords(shadowAngle, shadowDistance),
761
- x = _getShadowCoords.x,
762
- y = _getShadowCoords.y;
763
- var boxShadow = "".concat(x, "px ").concat(y, "px ").concat(blur, "px 0 ").concat(color);
764
- return {
765
- boxShadow: boxShadow
766
- };
767
- };
768
-
769
- // @todo hmm, gotta find a better way to handle this
770
- var getStyleFromBox = function getStyleFromBox(value) {
771
- if (value === null) {
772
- return null;
773
- }
774
- var _value$backgroundColo = value.backgroundColor,
775
- backgroundColor = _value$backgroundColo === void 0 ? null : _value$backgroundColo,
776
- _value$borderRadius = value.borderRadius,
777
- borderRadius = _value$borderRadius === void 0 ? null : _value$borderRadius,
778
- _value$padding = value.padding,
779
- padding = _value$padding === void 0 ? null : _value$padding,
780
- _value$paddingTop = value.paddingTop,
781
- paddingTop = _value$paddingTop === void 0 ? null : _value$paddingTop,
782
- _value$paddingRight = value.paddingRight,
783
- paddingRight = _value$paddingRight === void 0 ? null : _value$paddingRight,
784
- _value$paddingBottom = value.paddingBottom,
785
- paddingBottom = _value$paddingBottom === void 0 ? null : _value$paddingBottom,
786
- _value$paddingLeft = value.paddingLeft,
787
- paddingLeft = _value$paddingLeft === void 0 ? null : _value$paddingLeft,
788
- _value$borderWidth = value.borderWidth,
789
- borderWidth = _value$borderWidth === void 0 ? null : _value$borderWidth,
790
- _value$borderStyle = value.borderStyle,
791
- borderStyle = _value$borderStyle === void 0 ? null : _value$borderStyle,
792
- _value$borderColor = value.borderColor,
793
- borderColor = _value$borderColor === void 0 ? null : _value$borderColor,
794
- _value$shadowAngle = value.shadowAngle,
795
- shadowAngle = _value$shadowAngle === void 0 ? null : _value$shadowAngle,
796
- _value$shadowDistance = value.shadowDistance,
797
- shadowDistance = _value$shadowDistance === void 0 ? null : _value$shadowDistance,
798
- _value$shadowBlur = value.shadowBlur,
799
- shadowBlur = _value$shadowBlur === void 0 ? null : _value$shadowBlur,
800
- _value$shadowColor = value.shadowColor,
801
- shadowColor = _value$shadowColor === void 0 ? null : _value$shadowColor;
802
- var border = {
803
- width: borderWidth,
804
- style: borderStyle,
805
- color: borderColor
806
- };
807
- var shadow = {
808
- shadowAngle: shadowAngle,
809
- shadowDistance: shadowDistance,
810
- shadowBlur: shadowBlur,
811
- shadowColor: shadowColor
812
- };
813
- var _ref = isObject(padding) ? padding : {
814
- padding: padding
815
- },
816
- _ref$top = _ref.top,
817
- paddingValueTop = _ref$top === void 0 ? null : _ref$top,
818
- _ref$right = _ref.right,
819
- paddingValueRight = _ref$right === void 0 ? null : _ref$right,
820
- _ref$bottom = _ref.bottom,
821
- paddingValueBottom = _ref$bottom === void 0 ? null : _ref$bottom,
822
- _ref$left = _ref.left,
823
- paddingValueLeft = _ref$left === void 0 ? null : _ref$left,
824
- _ref$padding = _ref.padding,
825
- paddingValue = _ref$padding === void 0 ? null : _ref$padding;
826
- var basePadding = padding || paddingValue;
827
- var hasBasePadding = basePadding !== null;
828
- var topVal = paddingTop || paddingValueTop;
829
- var rightVal = paddingRight || paddingValueRight;
830
- var bottomVal = paddingBottom || paddingValueBottom;
831
- var leftVal = paddingLeft || paddingValueLeft;
832
- var hasAnyIndividual = topVal !== null || rightVal !== null || bottomVal !== null || leftVal !== null;
833
-
834
- // Avoid mixing shorthand `padding` with longhand `paddingTop`/etc — React warns about this
835
- var paddingStyles = hasBasePadding && hasAnyIndividual ? {
836
- paddingTop: topVal !== null && topVal !== void 0 ? topVal : basePadding,
837
- paddingRight: rightVal !== null && rightVal !== void 0 ? rightVal : basePadding,
838
- paddingBottom: bottomVal !== null && bottomVal !== void 0 ? bottomVal : basePadding,
839
- paddingLeft: leftVal !== null && leftVal !== void 0 ? leftVal : basePadding
840
- } : _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, hasBasePadding ? {
841
- padding: basePadding
842
- } : null), topVal !== null ? {
843
- paddingTop: topVal
844
- } : null), rightVal !== null ? {
845
- paddingRight: rightVal
846
- } : null), bottomVal !== null ? {
847
- paddingBottom: bottomVal
848
- } : null), leftVal !== null ? {
849
- paddingLeft: leftVal
850
- } : null);
851
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, getStyleFromColor(backgroundColor, 'backgroundColor')), borderRadius !== null ? {
852
- borderRadius: borderRadius
853
- } : null), getStyleFromBorder(border)), getStyleFromShadow(shadow)), paddingStyles);
854
- };
855
-
856
- var getStyleFromContainer = function getStyleFromContainer(value) {
857
- if (value == null) {
858
- return null;
859
- }
860
- var _value$size = value.size,
861
- size = _value$size === void 0 ? {} : _value$size,
862
- _value$backgroundColo = value.backgroundColor,
863
- backgroundColor = _value$backgroundColo === void 0 ? null : _value$backgroundColo;
864
- var _size$width = size.width,
865
- width = _size$width === void 0 ? null : _size$width,
866
- _size$height = size.height,
867
- height = _size$height === void 0 ? null : _size$height;
868
- return _objectSpread(_objectSpread(_objectSpread({}, width ? {
869
- width: "".concat(width, "%")
870
- } : null), height ? {
871
- height: "".concat(height, "%")
872
- } : null), getStyleFromColor(backgroundColor, 'backgroundColor'));
873
- };
874
-
875
- var getStyleFromHighlight = function getStyleFromHighlight(value) {
876
- if (value == null) {
877
- return null;
878
- }
879
- var _value$textColor = value.textColor,
880
- textColor = _value$textColor === void 0 ? null : _value$textColor,
881
- _value$color = value.color,
882
- color = _value$color === void 0 ? null : _value$color;
883
- var colorString = color !== null ? getColorAsString(color) : null;
884
- var boxShadow = colorString !== null ? "0.05em 0px 0px ".concat(colorString, ", -0.05em 0px 0px ").concat(colorString) : null;
885
- return color !== null || textColor !== null ? _objectSpread(_objectSpread(_objectSpread({}, color !== null ? getStyleFromColor(color, 'backgroundColor') : null), textColor !== null ? getStyleFromColor(textColor, 'color') : null), color !== null ? {
886
- boxShadow: boxShadow,
887
- mozBoxShadow: boxShadow,
888
- msBoxShadow: boxShadow,
889
- webkitBoxShadow: boxShadow
890
- } : null) : null;
891
- };
892
-
893
- var getStyleFromImage = function getStyleFromImage(value) {
894
- if (value == null) {
895
- return null;
896
- }
897
- var _value$fit = value.fit,
898
- fit = _value$fit === void 0 ? {} : _value$fit,
899
- _value$backgroundColo = value.backgroundColor,
900
- backgroundColor = _value$backgroundColo === void 0 ? null : _value$backgroundColo;
901
- var _fit$size = fit.size,
902
- size = _fit$size === void 0 ? null : _fit$size,
903
- _fit$position = fit.position,
904
- position = _fit$position === void 0 ? {} : _fit$position;
905
- var _position$axisAlign = position.axisAlign,
906
- axisAlign = _position$axisAlign === void 0 ? null : _position$axisAlign,
907
- _position$crossAlign = position.crossAlign,
908
- crossAlign = _position$crossAlign === void 0 ? null : _position$crossAlign;
909
- return _objectSpread(_objectSpread(_objectSpread({}, size !== null ? {
910
- objectFit: size
911
- } : null), axisAlign !== null && crossAlign !== null ? {
912
- objectPosition: "".concat(axisAlign, " ").concat(crossAlign)
913
- } : null), getStyleFromColor(backgroundColor, 'backgroundColor'));
914
- };
915
-
916
- var getStyleFromLink = function getStyleFromLink(value) {
917
- if (value == null) {
918
- return null;
919
- }
920
- var _value$color = value.color,
921
- color = _value$color === void 0 ? null : _value$color,
922
- fontStyle = value.fontStyle;
923
- var _ref = fontStyle || {},
924
- _ref$italic = _ref.italic,
925
- italic = _ref$italic === void 0 ? false : _ref$italic,
926
- _ref$bold = _ref.bold,
927
- bold = _ref$bold === void 0 ? false : _ref$bold,
928
- _ref$underline = _ref.underline,
929
- underline = _ref$underline === void 0 ? false : _ref$underline;
930
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, color !== null ? getStyleFromColor(color, 'color') : null), italic ? {
931
- fontStyle: 'italic'
932
- } : null), bold ? {
933
- fontWeight: 'bold'
934
- } : null), underline ? {
935
- textDecoration: 'underline'
936
- } : null);
937
- };
938
-
939
- var getStyleFromText = function getStyleFromText(value) {
940
- if (value == null) {
941
- return null;
942
- }
943
- var _value$fontFamily = value.fontFamily,
944
- fontFamily = _value$fontFamily === void 0 ? null : _value$fontFamily,
945
- _value$fontSize = value.fontSize,
946
- fontSize = _value$fontSize === void 0 ? null : _value$fontSize,
947
- _value$fontStyle = value.fontStyle,
948
- fontStyle = _value$fontStyle === void 0 ? null : _value$fontStyle,
949
- _value$fontWeight = value.fontWeight,
950
- fontWeight = _value$fontWeight === void 0 ? null : _value$fontWeight,
951
- _value$lineHeight = value.lineHeight,
952
- lineHeight = _value$lineHeight === void 0 ? null : _value$lineHeight,
953
- _value$letterSpacing = value.letterSpacing,
954
- letterSpacing = _value$letterSpacing === void 0 ? null : _value$letterSpacing,
955
- _value$align = value.align,
956
- textAlign = _value$align === void 0 ? null : _value$align,
957
- _value$color = value.color,
958
- color = _value$color === void 0 ? null : _value$color;
959
- var _ref = fontStyle || {},
960
- _ref$italic = _ref.italic,
961
- italic = _ref$italic === void 0 ? false : _ref$italic,
962
- _ref$bold = _ref.bold,
963
- bold = _ref$bold === void 0 ? false : _ref$bold,
964
- _ref$underline = _ref.underline,
965
- underline = _ref$underline === void 0 ? false : _ref$underline,
966
- _ref$transform = _ref.transform,
967
- textTransform = _ref$transform === void 0 ? null : _ref$transform,
968
- _ref$outline = _ref.outline,
969
- outline = _ref$outline === void 0 ? false : _ref$outline;
970
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
971
- fontFamily: getFontFamily(fontFamily)
972
- }, fontSize !== null ? {
973
- fontSize: fontSize
974
- } : null), italic ? {
975
- fontStyle: 'italic'
976
- } : null), bold ? {
977
- fontWeight: 'bold'
978
- } : null), fontWeight !== null ? {
979
- fontWeight: fontWeight
980
- } : null), underline ? {
981
- textDecoration: 'underline'
982
- } : null), textTransform !== null ? {
983
- textTransform: textTransform
984
- } : null), textAlign !== null ? {
985
- textAlign: textAlign
986
- } : null), lineHeight !== null ? {
987
- lineHeight: lineHeight
988
- } : null), letterSpacing !== null ? {
989
- letterSpacing: letterSpacing
990
- } : null), getStyleFromColor(color, 'color')), outline ? {
991
- WebkitTextStroke: "2px ".concat(getColorAsString(color, 'color')),
992
- color: 'transparent'
993
- } : null);
994
- };
995
-
996
- var getStyleFromMargin = function getStyleFromMargin(value) {
997
- if (value == null) {
998
- return null;
999
- }
1000
- var _value$top = value.top,
1001
- marginTop = _value$top === void 0 ? null : _value$top,
1002
- _value$bottom = value.bottom,
1003
- marginBottom = _value$bottom === void 0 ? null : _value$bottom;
1004
- return _objectSpread(_objectSpread({}, marginTop !== null ? {
1005
- marginTop: marginTop
1006
- } : null), marginBottom !== null ? {
1007
- marginBottom: marginBottom
1008
- } : null);
1009
- };
1010
-
1011
- // const possibleMimes = ['video/webm', 'video/mp4', 'video/ogg', 'application/vnd.apple.mpegurl'];
1012
- var possibleMimes = ['video/mp4'];
1013
- var supportedMimes = null;
1014
- function getVideoSupportedMimes() {
1015
- var mimes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : possibleMimes;
1016
- if (supportedMimes === null) {
1017
- var video = document.createElement('video');
1018
- supportedMimes = (mimes || possibleMimes).filter(function (mime) {
1019
- return video.canPlayType(mime) !== '';
1020
- });
1021
- }
1022
- return supportedMimes;
1023
- }
1024
-
1025
- var getLayoutParts = function getLayoutParts() {
1026
- var layout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1027
- var _ref = layout !== null && layout.indexOf('-') !== false ? layout.split('-') : [layout, null, null],
1028
- _ref2 = _slicedToArray(_ref, 3),
1029
- horizontal = _ref2[0],
1030
- vertical = _ref2[1],
1031
- suffix = _ref2[2];
1032
- return {
1033
- horizontal: horizontal,
1034
- vertical: vertical,
1035
- suffix: suffix
1036
- };
1037
- };
1038
-
1039
- var isHeaderFilled = function isHeaderFilled() {
1040
- var header = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1041
- if (header === null || typeof header === 'undefined') {
1042
- return false;
1043
- }
1044
- var _ref = header || {},
1045
- _ref$badge = _ref.badge,
1046
- badge = _ref$badge === void 0 ? null : _ref$badge;
1047
- var _ref2 = badge || {},
1048
- _ref2$active = _ref2.active,
1049
- badgeActive = _ref2$active === void 0 ? false : _ref2$active,
1050
- _ref2$label = _ref2.label,
1051
- label = _ref2$label === void 0 ? null : _ref2$label;
1052
- var _ref3 = label || {},
1053
- _ref3$body = _ref3.body,
1054
- body = _ref3$body === void 0 ? null : _ref3$body;
1055
- return badgeActive && body !== null;
1056
- };
1057
-
1058
- var isFooterFilled = function isFooterFilled() {
1059
- var footer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1060
- if (footer === null || typeof footer === 'undefined') {
1061
- return false;
1062
- }
1063
- var _ref = footer || {},
1064
- _ref$callToAction = _ref.callToAction,
1065
- callToAction = _ref$callToAction === void 0 ? null : _ref$callToAction;
1066
- var _ref2 = callToAction || {},
1067
- _ref2$active = _ref2.active,
1068
- callToActionActive = _ref2$active === void 0 ? false : _ref2$active,
1069
- _ref2$label = _ref2.label,
1070
- label = _ref2$label === void 0 ? null : _ref2$label;
1071
- var _ref3 = label || {},
1072
- _ref3$body = _ref3.body,
1073
- body = _ref3$body === void 0 ? null : _ref3$body;
1074
- return callToActionActive && body !== null;
1075
- };
1076
-
1077
- var isMessage = function isMessage(message) {
1078
- return isObject(message) && typeof message.defaultMessage !== 'undefined';
1079
- };
1080
-
1081
- var isIos = function isIos() {
1082
- return ['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator.platform) ||
1083
- // iPad on iOS 13 detection
1084
- navigator.userAgent.includes('Mac') && 'ontouchend' in document;
1085
- };
1086
-
1087
- var isImageFilled = function isImageFilled(image) {
1088
- if (image === null || typeof image === 'undefined') {
1089
- return false;
1090
- }
1091
- var _ref = image || {},
1092
- _ref$media = _ref.media,
1093
- media = _ref$media === void 0 ? null : _ref$media,
1094
- _ref$url = _ref.url,
1095
- url = _ref$url === void 0 ? null : _ref$url;
1096
- return media !== null || url !== null;
1097
- };
1098
-
1099
- var isTextFilled$1 = function isTextFilled(text) {
1100
- if (text === null || typeof text === 'undefined') {
1101
- return false;
1102
- }
1103
- var _ref = text || {},
1104
- _ref$label = _ref.label,
1105
- label = _ref$label === void 0 ? null : _ref$label;
1106
- var _ref2 = label || {},
1107
- _ref2$length = _ref2.length,
1108
- length = _ref2$length === void 0 ? 0 : _ref2$length;
1109
- return typeof length === 'number' && length > 0;
1110
- };
1111
-
1112
- var isTextFilled = function isTextFilled(text) {
1113
- if (text === null || typeof text === 'undefined') {
1114
- return false;
1115
- }
1116
- var _ref = text || {},
1117
- _ref$body = _ref.body,
1118
- body = _ref$body === void 0 ? null : _ref$body;
1119
- var _ref2 = body || {},
1120
- _ref2$length = _ref2.length,
1121
- length = _ref2$length === void 0 ? 0 : _ref2$length;
1122
- return typeof length === 'number' && length > 0;
1123
- };
1124
-
1125
- var isValidUrl = function isValidUrl(string) {
1126
- if (string === null || typeof string === 'undefined') {
1127
- return false;
1128
- }
1129
- var url;
1130
- try {
1131
- url = new URL(string);
1132
- } catch (_) {
1133
- return false;
1134
- }
1135
- return url.protocol === 'http:' || url.protocol === 'https:';
1136
- };
1137
-
1138
- function mergeRefs() {
1139
- for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
1140
- refs[_key] = arguments[_key];
1141
- }
1142
- return function (value) {
1143
- refs.forEach(function (ref) {
1144
- if (typeof ref === 'function') {
1145
- ref(value);
1146
- } else if (ref != null) {
1147
- ref.current = value;
1148
- }
1149
- });
1150
- };
1151
- }
1152
-
1153
- var createSchemaId = function createSchemaId(id) {
1154
- return "https://schemas.micromag.ca/0.1/".concat(id, ".json");
1155
- };
1156
-
1157
- var schemaId = function schemaId(str) {
1158
- return createSchemaId(str.join('/'));
1159
- };
1160
-
1161
- var _setValue = function setValue(value, keyParts, fieldValue) {
1162
- var key = keyParts.shift();
1163
- var isArray = key.match(/^[0-9]+$/) !== null;
1164
- if (value !== null || fieldValue !== null) {
1165
- if (isArray) {
1166
- var index = parseInt(key, 10);
1167
- // TODO: fix this with an explicit delete
1168
- // instead on splicing out the element on null fieldValue
1169
- // const newArrayValue =
1170
- // fieldValue !== null
1171
- // ? [
1172
- // ...value.slice(0, index),
1173
- // keyParts.length > 0
1174
- // ? setValue(
1175
- // value !== null ? value[index] || null : null,
1176
- // keyParts,
1177
- // fieldValue,
1178
- // )
1179
- // : fieldValue,
1180
- // ...value.slice(index + 1),
1181
- // ]
1182
- // : [...value.slice(0, index), ...value.slice(index + 1)];
1183
-
1184
- var newArrayValue = [].concat(_toConsumableArray(value.slice(0, index)), [keyParts.length > 0 ? _setValue(value !== null ? value[index] || null : null, keyParts, fieldValue) : fieldValue], _toConsumableArray(value.slice(index + 1)));
1185
- return newArrayValue.length > 0 ? newArrayValue : null;
1186
- }
1187
- return _objectSpread(_objectSpread({}, value), {}, _defineProperty({}, key, keyParts.length > 0 ? _setValue(value !== null ? value[key] || null : null, keyParts, fieldValue) : fieldValue));
1188
- }
1189
- return null;
1190
- };
1191
-
1192
- var slug = function slug(str) {
1193
- var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1194
- var toSlug;
1195
- if (separator === '-') {
1196
- toSlug = changeCase.kebabCase(str);
1197
- } else {
1198
- toSlug = changeCase.snakeCase(str);
1199
- }
1200
- return slugify(toSlug, {
1201
- lower: true
1202
- });
1203
- };
1204
-
1205
- var unique = function unique(arrArg) {
1206
- return arrArg !== null ? arrArg.filter(function (elem, pos, arr) {
1207
- return arr.indexOf(elem) === pos;
1208
- }) : [];
1209
- };
1210
-
1211
- var _validateFields = function validateFields(fields, value) {
1212
- return fields.reduce(function (acc, field) {
1213
- if (acc === true) {
1214
- if (field.type === 'fields' && field.fields) {
1215
- return _validateFields(field.fields, value);
1216
- }
1217
- var val = value && value[field.name] ? value[field.name] : false;
1218
- return !(field.required && !val);
1219
- }
1220
- return acc;
1221
- }, true);
1222
- };
1223
-
1224
- var getContrastingColor = function getContrastingColor(backgroundColor) {
1225
- var _ref = backgroundColor || {},
1226
- _ref$color = _ref.color,
1227
- color = _ref$color === void 0 ? 'white' : _ref$color;
1228
- if (tinycolor.equals(color, tinycolor('white'))) {
1229
- return '#A13DFF';
1230
- }
1231
- if (tinycolor.equals(color, tinycolor('black'))) {
1232
- return 'white';
1233
- }
1234
- return tinycolor(color).spin(30).toString();
1235
- };
1236
-
1237
- Object.defineProperty(exports, "camelCase", {
1238
- enumerable: true,
1239
- get: function () { return changeCase.camelCase; }
1240
- });
1241
- Object.defineProperty(exports, "pascalCase", {
1242
- enumerable: true,
1243
- get: function () { return changeCase.pascalCase; }
1244
- });
1245
- Object.defineProperty(exports, "snakeCase", {
1246
- enumerable: true,
1247
- get: function () { return changeCase.snakeCase; }
1248
- });
1249
- exports.addNonBreakingSpaces = addNonBreakingSpaces;
1250
- exports.convertStyleToString = convertStyleToString;
1251
- exports.copyToClipboard = copyToClipboard;
1252
- exports.createNullableOnChange = createNullableOnChange;
1253
- exports.createUseEvent = createUseEvent;
1254
- exports.cssEscape = cssEscape;
1255
- exports.easings = easings;
1256
- exports.getColorAsString = getColorAsString;
1257
- exports.getComponentFromName = getComponentFromName;
1258
- exports.getContrastingColor = getContrastingColor;
1259
- exports.getDeviceScreens = getDeviceScreens;
1260
- exports.getDisplayName = getDisplayName;
1261
- exports.getFieldByName = _getFieldByName;
1262
- exports.getFieldFromPath = getFieldFromPath;
1263
- exports.getFileName = getFileName;
1264
- exports.getFontFamilyFromFont = getFontFamily;
1265
- exports.getFooterProps = getFooterProps;
1266
- exports.getGridLayoutName = getGridLayoutName;
1267
- exports.getLargestRemainderRound = largestRemainderRound;
1268
- exports.getLayersFromBackground = getLayersFromBackground;
1269
- exports.getLayoutParts = getLayoutParts;
1270
- exports.getMediaFilesAsArray = getMediaFilesAsArray;
1271
- exports.getOptimalImageUrl = getOptimalImageUrl;
1272
- exports.getScreenExtraField = getScreenExtraField;
1273
- exports.getScreenFieldsWithStates = getScreenFieldsWithStates;
1274
- exports.getSecondsFromTime = getSecondsFromTime;
1275
- exports.getShadowCoords = getShadowCoords;
1276
- exports.getStyleFromAlignment = getStyleFromAlignment;
1277
- exports.getStyleFromBorder = getStyleFromBorder;
1278
- exports.getStyleFromBox = getStyleFromBox;
1279
- exports.getStyleFromColor = getStyleFromColor;
1280
- exports.getStyleFromContainer = getStyleFromContainer;
1281
- exports.getStyleFromHighlight = getStyleFromHighlight;
1282
- exports.getStyleFromImage = getStyleFromImage;
1283
- exports.getStyleFromLink = getStyleFromLink;
1284
- exports.getStyleFromMargin = getStyleFromMargin;
1285
- exports.getStyleFromText = getStyleFromText;
1286
- exports.getVideoSupportedMimes = getVideoSupportedMimes;
1287
- exports.isFooterFilled = isFooterFilled;
1288
- exports.isHeaderFilled = isHeaderFilled;
1289
- exports.isImageFilled = isImageFilled;
1290
- exports.isIos = isIos;
1291
- exports.isLabelFilled = isTextFilled$1;
1292
- exports.isMessage = isMessage;
1293
- exports.isTextFilled = isTextFilled;
1294
- exports.isValidUrl = isValidUrl;
1295
- exports.mergeRefs = mergeRefs;
1296
- exports.schemaId = schemaId;
1297
- exports.setFieldValue = _setValue;
1298
- exports.slug = slug;
1299
- exports.unique = unique;
1300
- exports.validateFields = _validateFields;