@micromag/core 0.3.767 → 0.3.779

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