@telia-ace/widget-utilities 1.0.3 → 1.0.5-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,114 +1,89 @@
1
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2
- var __hasOwnProp = Object.prototype.hasOwnProperty;
3
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
4
- var __objRest = (source, exclude) => {
5
- var target = {};
6
- for (var prop in source)
7
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
8
- target[prop] = source[prop];
9
- if (source != null && __getOwnPropSymbols)
10
- for (var prop of __getOwnPropSymbols(source)) {
11
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
12
- target[prop] = source[prop];
13
- }
14
- return target;
1
+ var z = Object.defineProperty;
2
+ var T = Object.getOwnPropertySymbols;
3
+ var W = Object.prototype.hasOwnProperty, I = Object.prototype.propertyIsEnumerable;
4
+ var M = (o, t, e) => t in o ? z(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
5
+ var E = (o, t) => {
6
+ var e = {};
7
+ for (var r in o)
8
+ W.call(o, r) && t.indexOf(r) < 0 && (e[r] = o[r]);
9
+ if (o != null && T)
10
+ for (var r of T(o))
11
+ t.indexOf(r) < 0 && I.call(o, r) && (e[r] = o[r]);
12
+ return e;
15
13
  };
16
- function uniqueClassArray(classNames) {
17
- const classArray = [];
18
- classNames.forEach((c) => {
19
- if (classArray.indexOf(c) === -1) {
20
- classArray.push(c);
21
- }
22
- });
23
- return classArray;
14
+ var a = (o, t, e) => (M(o, typeof t != "symbol" ? t + "" : t, e), e);
15
+ function V(o) {
16
+ const t = [];
17
+ return o.forEach((e) => {
18
+ t.indexOf(e) === -1 && t.push(e);
19
+ }), t;
24
20
  }
25
- function append(className1 = "", className2 = "") {
26
- const classNames = className1.split(" ").concat(className2.split(" "));
27
- return uniqueClassArray(classNames).join(" ").trim();
21
+ function w(o = "", t = "") {
22
+ const e = o.split(" ").concat(t.split(" "));
23
+ return V(e).join(" ").trim();
28
24
  }
29
- function handleFunctionArgument(expression, classes) {
30
- if (Boolean(expression)) {
31
- if (typeof classes === "string") {
32
- return classes;
33
- }
34
- if (Array.isArray(classes)) {
35
- let className = "";
36
- classes.forEach((c) => className = append(className, c));
37
- return className;
25
+ function Y(o, t) {
26
+ if (Boolean(o)) {
27
+ if (typeof t == "string")
28
+ return t;
29
+ if (Array.isArray(t)) {
30
+ let e = "";
31
+ return t.forEach((r) => e = w(e, r)), e;
38
32
  }
39
33
  }
40
34
  }
41
- function appendClassNames(...args) {
42
- let className = "";
43
- if (args.length) {
44
- args.forEach((argument) => {
45
- if (typeof argument === "string") {
46
- className = append(className, argument);
47
- } else if (Array.isArray(argument)) {
48
- className = append(className, handleFunctionArgument(...argument));
49
- } else
50
- ;
51
- });
52
- }
53
- return className;
35
+ function Q(...o) {
36
+ let t = "";
37
+ return o.length && o.forEach((e) => {
38
+ typeof e == "string" ? t = w(t, e) : Array.isArray(e) ? t = w(t, Y(...e)) : typeof e != "undefined" && e !== null && process.env.NODE_ENV !== "production" && p.warn(
39
+ "appendClassNames: arguments either haveto be a string or [boolean, ...string[]]. Passed args:",
40
+ ...o
41
+ );
42
+ }), t;
54
43
  }
55
- const createBatch = (delay, createFallback) => {
56
- let timeout;
57
- let queue = [];
58
- return (fn) => {
59
- clearTimeout(timeout);
60
- return new Promise((resolve, reject) => {
61
- queue.push([fn, resolve, reject]);
62
- timeout = setTimeout(() => {
63
- let acc = createFallback();
64
- queue.forEach(([fn2, resolve2, reject2]) => {
65
- acc = fn2(acc);
66
- });
67
- queue = [];
68
- resolve(acc);
69
- }, delay);
70
- });
71
- };
44
+ const H = (o, t) => {
45
+ let e, r = [];
46
+ return (i) => (clearTimeout(e), new Promise((n, c) => {
47
+ r.push([i, n, c]), e = setTimeout(() => {
48
+ let f = t();
49
+ r.forEach(([u, g, d]) => {
50
+ f = u(f);
51
+ }), r = [], n(f);
52
+ }, o);
53
+ }));
72
54
  };
73
- function camilize(obj) {
74
- const camilizedObject = {};
75
- if (typeof obj === "number" || typeof obj === "string") {
76
- return obj;
77
- }
78
- for (const prop in obj) {
79
- if (obj.hasOwnProperty(prop)) {
80
- const p = obj[prop];
81
- const camilizedProp = prop.substring(0, 1).toLowerCase() + prop.substring(1);
82
- if (Object.prototype.toString.call(p) === "[object Array]") {
83
- camilizedObject[camilizedProp] = [];
84
- for (let i = 0, c = p.length; i < c; i++) {
85
- camilizedObject[camilizedProp].push(camilize(p[i]));
86
- }
87
- } else if (p !== null && typeof p === "object") {
88
- camilizedObject[camilizedProp] = camilize(p);
89
- } else {
90
- camilizedObject[camilizedProp] = p;
91
- }
55
+ function j(o) {
56
+ const t = {};
57
+ if (typeof o == "number" || typeof o == "string")
58
+ return o;
59
+ for (const e in o)
60
+ if (o.hasOwnProperty(e)) {
61
+ const r = o[e], i = e.substring(0, 1).toLowerCase() + e.substring(1);
62
+ if (Object.prototype.toString.call(r) === "[object Array]") {
63
+ t[i] = [];
64
+ for (let n = 0, c = r.length; n < c; n++)
65
+ t[i].push(j(r[n]));
66
+ } else
67
+ r !== null && typeof r == "object" ? t[i] = j(r) : t[i] = r;
92
68
  }
93
- }
94
- return camilizedObject;
69
+ return t;
95
70
  }
96
- function createParams(args = {}) {
97
- const _a = args, {
98
- phrase = "",
99
- category,
100
- guideCategory,
101
- contactCategory,
102
- take,
103
- connectionKey,
104
- accordion,
105
- id,
106
- uriName,
107
- sorting,
108
- tag,
109
- tagId,
110
- tagTitle
111
- } = _a, other = __objRest(_a, [
71
+ function N(o = {}) {
72
+ const x = o, {
73
+ phrase: t = "",
74
+ category: e,
75
+ guideCategory: r,
76
+ contactCategory: i,
77
+ take: n,
78
+ connectionKey: c,
79
+ accordion: f,
80
+ id: u,
81
+ uriName: g,
82
+ sorting: d,
83
+ tag: m,
84
+ tagId: l,
85
+ tagTitle: y
86
+ } = x, D = E(x, [
112
87
  "phrase",
113
88
  "category",
114
89
  "guideCategory",
@@ -122,122 +97,28 @@ function createParams(args = {}) {
122
97
  "tag",
123
98
  "tagId",
124
99
  "tagTitle"
125
- ]);
126
- const params = {};
127
- Object.keys(other).forEach((k) => {
128
- if (typeof args[k] === "string") {
129
- params[k] = args[k];
130
- }
131
- });
132
- if (typeof phrase === "string" && phrase.length) {
133
- params.phrase = phrase;
134
- }
135
- if (phrase === null) {
136
- params.phrase = phrase;
137
- }
138
- if (typeof guideCategory === "string" && guideCategory !== "0") {
139
- params.guideCategory = guideCategory;
140
- }
141
- if (typeof guideCategory === "number" && guideCategory !== 0) {
142
- params.guideCategory = guideCategory;
143
- }
144
- if (typeof guideCategory === "object" && guideCategory !== null) {
145
- if (typeof guideCategory.id === "string" && guideCategory.id !== "0") {
146
- params.guideCategory = guideCategory.id;
147
- }
148
- if (typeof guideCategory.id === "number" && guideCategory.id !== 0) {
149
- params.guideCategory = guideCategory.id;
150
- }
151
- }
152
- if (typeof contactCategory === "string" && contactCategory !== "0") {
153
- params.contactCategory = contactCategory;
154
- }
155
- if (typeof contactCategory === "number" && contactCategory !== 0) {
156
- params.contactCategory = contactCategory;
157
- }
158
- if (typeof contactCategory === "object" && contactCategory !== null) {
159
- if (typeof contactCategory.id === "string" && contactCategory.id !== "0") {
160
- params.contactCategory = contactCategory.id;
161
- }
162
- if (typeof contactCategory.id === "number" && contactCategory.id !== 0) {
163
- params.contactCategory = contactCategory.id;
164
- }
165
- }
166
- if (typeof category === "string" && category !== "0") {
167
- params.category = category;
168
- }
169
- if (typeof category === "number" && category !== 0) {
170
- params.category = category;
171
- }
172
- if (typeof category === "object" && category !== null) {
173
- if (typeof category.id === "string" && category.id !== "0") {
174
- params.category = category.id;
175
- }
176
- if (typeof category.id === "number" && category.id !== 0) {
177
- params.category = category.id;
178
- }
179
- }
180
- if (id) {
181
- params.id = id;
182
- }
183
- if (uriName && (!!+params.category || !!+params.guideCategory || !!+params.guide || !!+params.contactCategory || !!+params.contactMethod)) {
184
- params.uriName = uriName;
185
- }
186
- if (connectionKey) {
187
- params.connectionKey = connectionKey;
188
- }
189
- if (take) {
190
- params.take = take;
191
- }
192
- if (sorting) {
193
- params.sorting = sorting;
194
- }
195
- if (typeof accordion === "string" && accordion.length > 0) {
196
- params.accordion = accordion;
197
- }
198
- if (typeof tag === "string" && tag !== "0") {
199
- params.tag = tag;
200
- }
201
- if (typeof tag === "number" && tag !== 0) {
202
- params.tag = tag;
203
- }
204
- if (typeof tagId === "string" || typeof tagId === "number") {
205
- params.tagId = tagId;
206
- }
207
- if (typeof tagTitle === "string") {
208
- params.tagTitle = tagTitle;
209
- }
210
- return params;
100
+ ]), s = {};
101
+ return Object.keys(D).forEach((k) => {
102
+ typeof o[k] == "string" && (s[k] = o[k]);
103
+ }), typeof t == "string" && t.length && (s.phrase = t), t === null && (s.phrase = t), typeof r == "string" && r !== "0" && (s.guideCategory = r), typeof r == "number" && r !== 0 && (s.guideCategory = r), typeof r == "object" && r !== null && (typeof r.id == "string" && r.id !== "0" && (s.guideCategory = r.id), typeof r.id == "number" && r.id !== 0 && (s.guideCategory = r.id)), typeof i == "string" && i !== "0" && (s.contactCategory = i), typeof i == "number" && i !== 0 && (s.contactCategory = i), typeof i == "object" && i !== null && (typeof i.id == "string" && i.id !== "0" && (s.contactCategory = i.id), typeof i.id == "number" && i.id !== 0 && (s.contactCategory = i.id)), typeof e == "string" && e !== "0" && (s.category = e), typeof e == "number" && e !== 0 && (s.category = e), typeof e == "object" && e !== null && (typeof e.id == "string" && e.id !== "0" && (s.category = e.id), typeof e.id == "number" && e.id !== 0 && (s.category = e.id)), u && (s.id = u), g && (!!+s.category || !!+s.guideCategory || !!+s.guide || !!+s.contactCategory || !!+s.contactMethod) && (s.uriName = g), c && (s.connectionKey = c), n && (s.take = n), d && (s.sorting = d), typeof f == "string" && f.length > 0 && (s.accordion = f), typeof m == "string" && m !== "0" && (s.tag = m), typeof m == "number" && m !== 0 && (s.tag = m), (typeof l == "string" || typeof l == "number") && (s.tagId = l), typeof y == "string" && (s.tagTitle = y), s;
211
104
  }
212
- function* processData(data) {
213
- if (!data) {
214
- return;
215
- }
216
- for (let i = 0; i < data.length; i++) {
217
- const val = data[i];
218
- yield val;
219
- if (val.items) {
220
- yield* processData(val.items);
105
+ function* S(o) {
106
+ if (!!o)
107
+ for (let t = 0; t < o.length; t++) {
108
+ const e = o[t];
109
+ yield e, e.items && (yield* S(e.items));
221
110
  }
222
- }
223
111
  }
224
- const findCategoryById = (id, categories) => {
225
- const it = processData(categories);
226
- let res = it.next();
227
- let found = null;
228
- while (!res.done) {
229
- if (res.value.id === id) {
230
- found = res.value;
231
- }
232
- res = it.next();
233
- }
234
- return found;
235
- };
236
- const formatUrl = (url) => {
237
- if (!url) {
112
+ const B = (o, t) => {
113
+ const e = S(t);
114
+ let r = e.next(), i = null;
115
+ for (; !r.done; )
116
+ r.value.id === o && (i = r.value), r = e.next();
117
+ return i;
118
+ }, q = (o) => {
119
+ if (!o)
238
120
  return "";
239
- }
240
- const replacements = [
121
+ const t = [
241
122
  { from: /[äæǽ]+/gi, to: "ae" },
242
123
  { from: /[öœ]+/gi, to: "oe" },
243
124
  { from: /[ü]+/gi, to: "ue" },
@@ -327,476 +208,320 @@ const formatUrl = (url) => {
327
208
  { from: /[ю]+/gi, to: "yu" },
328
209
  { from: /[Я]+/gi, to: "Ya" },
329
210
  { from: /[я]+/gi, to: "ya" }
330
- ];
331
- const alphanumericExpression = /[^a-zA-Z0-9]+/g;
332
- const trailingDashExpression = /[-]$/;
333
- let parsed = url;
334
- for (const i in replacements) {
335
- if (replacements.hasOwnProperty(i) && replacements[i].from.test(url)) {
336
- parsed = parsed.replace(replacements[i].from, replacements[i].to);
337
- }
338
- }
339
- parsed = parsed.replace(alphanumericExpression, "-");
340
- parsed = parsed.replace(trailingDashExpression, "");
341
- parsed = parsed.toLowerCase();
342
- return parsed || "humany";
211
+ ], e = /[^a-zA-Z0-9]+/g, r = /[-]$/;
212
+ let i = o;
213
+ for (const n in t)
214
+ t.hasOwnProperty(n) && t[n].from.test(o) && (i = i.replace(t[n].from, t[n].to));
215
+ return i = i.replace(e, "-"), i = i.replace(r, ""), i = i.toLowerCase(), i || "humany";
343
216
  };
344
- function childParentStructure(items, structure = {}, parent) {
345
- items.forEach((item) => {
346
- if (parent) {
347
- structure[+item.id] = parent;
348
- }
349
- if (item.items) {
350
- childParentStructure(item.items, structure, item.id);
351
- }
352
- });
353
- return structure;
217
+ function P(o, t = {}, e) {
218
+ return o.forEach((r) => {
219
+ e && (t[+r.id] = e), r.items && P(r.items, t, r.id);
220
+ }), t;
354
221
  }
355
- function categoryTrail(id, items, ids = [id], structure = childParentStructure(items)) {
356
- const addAncestors = (id2) => {
357
- const parentId2 = structure[+id2];
358
- if (parentId2) {
359
- ids.unshift(parentId2);
360
- addAncestors(parentId2);
361
- }
362
- };
363
- const parentId = structure[+id];
364
- if (parentId) {
365
- ids.unshift(parentId);
366
- addAncestors(parentId);
367
- }
368
- return ids;
222
+ function F(o, t, e = [o], r = P(t)) {
223
+ const i = (c) => {
224
+ const f = r[+c];
225
+ f && (e.unshift(f), i(f));
226
+ }, n = r[+o];
227
+ return n && (e.unshift(n), i(n)), e;
369
228
  }
370
- const getCategoryTrailAsObjects = (trail, categories) => {
371
- if (typeof trail === "undefined" || typeof categories === "undefined") {
372
- return /* @__PURE__ */ new Map();
373
- }
374
- return new Map(trail.map((categoryId) => {
375
- const category = findCategoryById(categoryId, categories);
376
- return [categoryId, category];
377
- }));
378
- };
379
- const buildCategoryTrail = (routeName, categoryIds, container, dataType = "guide-categories") => {
380
- return container.getAsync("dataClient").then((dataClient) => {
381
- return dataClient.fetch(dataType, { expandCategories: "descendants" }).then(({ categories }) => {
382
- const buildTrail = (id) => {
383
- const trail = categoryTrail(id, categories);
384
- const objectTrail = getCategoryTrailAsObjects(trail, categories);
385
- const result = [];
386
- trail.forEach((categoryId) => {
387
- const category = objectTrail.get(categoryId);
388
- if (category) {
389
- result.push({
390
- routeName,
391
- title: category.title,
392
- symbol: category.symbol,
393
- id: category.id,
394
- routeParams: dataType === "contact-method-categories" ? createParams({
395
- contactCategory: category.id,
396
- uriName: formatUrl(category.title)
397
- }) : createParams({
398
- guideCategory: category.id,
399
- uriName: formatUrl(category.title)
400
- })
401
- });
402
- }
403
- });
404
- return result;
405
- };
406
- if (Array.isArray(categoryIds)) {
407
- return categoryIds.reduce((acc, id) => {
408
- const result = buildTrail(id);
409
- if (result.length > 0) {
410
- acc.push(result);
411
- }
412
- return acc;
413
- }, []);
414
- }
415
- return buildTrail(categoryIds);
416
- });
417
- });
418
- };
419
- const dataURItoBlob = (dataURI) => {
420
- let byteString;
421
- let mimestring;
422
- if (dataURI.split(",")[0].indexOf("base64") !== -1) {
423
- byteString = atob(dataURI.split(",")[1]);
424
- } else {
425
- byteString = decodeURI(dataURI.split(",")[1]);
426
- }
427
- mimestring = dataURI.split(",")[0].split(":")[1].split(";")[0];
428
- const content = [];
429
- for (let i = 0; i < byteString.length; i++) {
430
- content[i] = byteString.charCodeAt(i);
431
- }
432
- return new Blob([new Uint8Array(content)], { type: mimestring });
229
+ const K = (o, t) => typeof o == "undefined" || typeof t == "undefined" ? /* @__PURE__ */ new Map() : new Map(
230
+ o.map((e) => {
231
+ const r = B(e, t);
232
+ return [e, r];
233
+ })
234
+ ), G = (o, t, e, r = "guide-categories") => e.getAsync("dataClient").then((i) => i.fetch(r, { expandCategories: "descendants" }).then(({ categories: n }) => {
235
+ const c = (f) => {
236
+ const u = F(f, n), g = K(u, n), d = [];
237
+ return u.forEach((m) => {
238
+ const l = g.get(m);
239
+ l && d.push({
240
+ routeName: o,
241
+ title: l.title,
242
+ symbol: l.symbol,
243
+ id: l.id,
244
+ routeParams: N(r === "contact-method-categories" ? {
245
+ contactCategory: l.id,
246
+ uriName: q(l.title)
247
+ } : {
248
+ guideCategory: l.id,
249
+ uriName: q(l.title)
250
+ })
251
+ });
252
+ }), d;
253
+ };
254
+ return Array.isArray(t) ? t.reduce((f, u) => {
255
+ const g = c(u);
256
+ return g.length > 0 && f.push(g), f;
257
+ }, []) : c(t);
258
+ })), R = (o) => {
259
+ let t, e;
260
+ o.split(",")[0].indexOf("base64") !== -1 ? t = atob(o.split(",")[1]) : t = decodeURI(o.split(",")[1]), e = o.split(",")[0].split(":")[1].split(";")[0];
261
+ const r = [];
262
+ for (let i = 0; i < t.length; i++)
263
+ r[i] = t.charCodeAt(i);
264
+ return new Blob([new Uint8Array(r)], { type: e });
433
265
  };
434
- function debugLog(...args) {
435
- return false;
266
+ function _(...o) {
267
+ return process.env.NODE_ENV !== "production" && console && console.warn(...o);
436
268
  }
437
- const print = (print2, msgOrObj, ...args) => {
438
- if (typeof msgOrObj === "string") {
439
- return print2(`[humany] ${msgOrObj}`, ...args);
440
- }
441
- return print2(msgOrObj, ...args);
442
- };
443
- const _Logger = class {
269
+ const C = (o, t, ...e) => typeof t == "string" ? o(`[humany] ${t}`, ...e) : o(t, ...e), b = class {
444
270
  constructor() {
445
- this.keys = [];
446
- this.log = (key, ...args) => this.lookup(key, () => _Logger.log(...args));
447
- this.warn = (key, ...args) => this.lookup(key, () => _Logger.warn(...args));
448
- this.error = (key, ...args) => this.lookup(key, () => _Logger.error(...args));
449
- this.info = (key, ...args) => this.lookup(key, () => _Logger.info(...args));
271
+ a(this, "keys", []);
272
+ a(this, "log", (t, ...e) => this.lookup(t, () => b.log(...e)));
273
+ a(this, "warn", (t, ...e) => this.lookup(t, () => b.warn(...e)));
274
+ a(this, "error", (t, ...e) => this.lookup(t, () => b.error(...e)));
275
+ a(this, "info", (t, ...e) => this.lookup(t, () => b.info(...e)));
450
276
  }
451
- lookup(key, fn) {
452
- if (this.keys.indexOf(key) === -1) {
453
- this.keys.push(key);
454
- fn();
455
- }
456
- }
457
- };
458
- let Logger = _Logger;
459
- Logger.log = (...args) => print(console.log, ...args);
460
- Logger.warn = (...args) => print(console.warn, ...args);
461
- Logger.error = (...args) => print(console.error, ...args);
462
- Logger.info = (...args) => print(console.info, ...args);
463
- const deepClone = (data) => {
464
- let out = {};
465
- let value;
466
- let key;
467
- if (typeof data !== "object" || data === null) {
468
- return data;
469
- }
470
- out = Array.isArray(data) ? [] : {};
471
- for (key in data) {
472
- value = data[key];
473
- out[key] = typeof value === "object" && value !== null ? deepClone(value) : value;
277
+ lookup(t, e) {
278
+ this.keys.indexOf(t) === -1 && (this.keys.push(t), e());
474
279
  }
475
- return out;
476
280
  };
477
- var findAndActivateStoredWidgets = (implementation) => {
478
- if (!implementation) {
281
+ let p = b;
282
+ a(p, "log", (...t) => C(console.log, ...t)), a(p, "warn", (...t) => C(console.warn, ...t)), a(p, "error", (...t) => C(console.error, ...t)), a(p, "info", (...t) => C(console.info, ...t));
283
+ const O = (o) => {
284
+ let t = {}, e, r;
285
+ if (typeof o != "object" || o === null)
286
+ return o;
287
+ t = Array.isArray(o) ? [] : {};
288
+ for (r in o)
289
+ e = o[r], t[r] = typeof e == "object" && e !== null ? O(e) : e;
290
+ return t;
291
+ }, X = (o) => {
292
+ if (!o)
479
293
  return null;
480
- }
481
- const implementationStorage = localStorage.getItem(`humany_${hash(implementation.tenant + implementation.name)}`);
482
- if (implementationStorage) {
483
- const { activeStickyWidget } = JSON.parse(implementationStorage);
484
- if (activeStickyWidget && activeStickyWidget.value) {
485
- const widget = implementation.widgets.get(activeStickyWidget.value);
486
- if (widget) {
487
- const el = document.createElement("a");
488
- el.setAttribute("href", `//${implementation.bindings[0]}/${activeStickyWidget.value}`);
489
- document.body.appendChild(el);
490
- }
294
+ const t = localStorage.getItem(
295
+ `humany_${L(o.tenant + o.name)}`
296
+ );
297
+ if (t) {
298
+ const { activeStickyWidget: e } = JSON.parse(t);
299
+ if (e && e.value && o.widgets.get(e.value)) {
300
+ const i = document.createElement("a");
301
+ i.setAttribute(
302
+ "href",
303
+ `//${o.bindings[0]}/${e.value}`
304
+ ), document.body.appendChild(i);
491
305
  }
492
306
  }
493
- };
494
- var formatDate = (date, includeTime = false) => {
495
- const d = new Date(date);
496
- let month = `${d.getMonth() + 1}`;
497
- let day = `${d.getDate()}`;
498
- const year = d.getFullYear();
499
- if (month.length < 2)
500
- month = `0${month}`;
501
- if (day.length < 2)
502
- day = `0${day}`;
503
- if (includeTime) {
504
- let hours = `${d.getHours()}`;
505
- let minutes = `${d.getMinutes()}`;
506
- if (hours.length < 2)
507
- hours = `0${hours}`;
508
- if (minutes.length < 2)
509
- minutes = `0${minutes}`;
510
- return `${[year, month, day].join("-")} ${[hours, minutes].join(":")}`;
307
+ }, tt = (o, t = !1) => {
308
+ const e = new Date(o);
309
+ let r = `${e.getMonth() + 1}`, i = `${e.getDate()}`;
310
+ const n = e.getFullYear();
311
+ if (r.length < 2 && (r = `0${r}`), i.length < 2 && (i = `0${i}`), t) {
312
+ let c = `${e.getHours()}`, f = `${e.getMinutes()}`;
313
+ return c.length < 2 && (c = `0${c}`), f.length < 2 && (f = `0${f}`), `${[n, r, i].join("-")} ${[c, f].join(":")}`;
511
314
  }
512
- return [year, month, day].join("-");
315
+ return [n, r, i].join("-");
513
316
  };
514
- function getCookie(cookieName) {
515
- const documentCookie = document.cookie;
516
- if (documentCookie.length > 0) {
517
- let start = documentCookie.indexOf(`${cookieName}=`);
518
- if (start !== -1) {
519
- start = start + cookieName.length + 1;
520
- let end = documentCookie.indexOf(";", start);
521
- if (end === -1) {
522
- end = documentCookie.length;
523
- }
524
- return unescape(documentCookie.substring(start, end));
317
+ function et(o) {
318
+ const t = document.cookie;
319
+ if (t.length > 0) {
320
+ let e = t.indexOf(`${o}=`);
321
+ if (e !== -1) {
322
+ e = e + o.length + 1;
323
+ let r = t.indexOf(";", e);
324
+ return r === -1 && (r = t.length), unescape(t.substring(e, r));
525
325
  }
526
326
  }
527
327
  return null;
528
328
  }
529
- function hash(s) {
530
- let hash2 = 0;
531
- if (s.length === 0) {
532
- return hash2.toString();
533
- }
534
- for (let i = 0; i < s.length; i++) {
535
- const char = s.charCodeAt(i);
536
- hash2 = (hash2 << 5) - hash2 + char;
537
- hash2 = hash2 & hash2;
538
- }
539
- return hash2.toString();
329
+ function L(o) {
330
+ let t = 0;
331
+ if (o.length === 0)
332
+ return t.toString();
333
+ for (let e = 0; e < o.length; e++) {
334
+ const r = o.charCodeAt(e);
335
+ t = (t << 5) - t + r, t = t & t;
336
+ }
337
+ return t.toString();
540
338
  }
541
- var htmlParentContains = (parent, child) => {
542
- if (!parent || !child) {
543
- return true;
544
- }
545
- let node = child.parentNode;
546
- let hasChild = false;
547
- while (node !== null) {
548
- if (node === parent) {
549
- hasChild = true;
550
- }
551
- node = node.parentNode;
552
- }
553
- return hasChild;
339
+ const ot = (o, t) => {
340
+ if (!o || !t)
341
+ return !0;
342
+ let e = t.parentNode, r = !1;
343
+ for (; e !== null; )
344
+ e === o && (r = !0), e = e.parentNode;
345
+ return r;
554
346
  };
555
- function kebabCase(string) {
556
- return string.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/\s+/g, "-").toLowerCase();
347
+ function rt(o) {
348
+ return o.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/\s+/g, "-").toLowerCase();
557
349
  }
558
- class Queue {
559
- constructor(lockWarningTime, lockErrorTime) {
560
- this.lockWarningTime = lockWarningTime;
561
- this.lockErrorTime = lockErrorTime;
562
- this.tasks = [];
563
- this.current = Promise.resolve();
564
- this.next = this.next.bind(this);
350
+ class U {
351
+ constructor(t, e) {
352
+ a(this, "tasks", []);
353
+ a(this, "current", Promise.resolve());
354
+ this.lockWarningTime = t, this.lockErrorTime = e, this.next = this.next.bind(this);
565
355
  }
566
- add(task, resolve, reject, done) {
567
- this.tasks.push({ task, resolve, reject, done });
568
- this.next();
356
+ add(t, e, r, i) {
357
+ this.tasks.push({ task: t, resolve: e, reject: r, done: i }), this.next();
569
358
  }
570
359
  next() {
571
360
  this.current = this.current.then(() => {
572
- const next = this.tasks.shift();
573
- if (next) {
574
- let errorTimeout;
575
- const warningTimeout = setTimeout(() => {
576
- errorTimeout = setTimeout(() => {
577
- next.reject("lock timeout exceeded");
361
+ const t = this.tasks.shift();
362
+ if (t) {
363
+ let e;
364
+ const r = setTimeout(() => {
365
+ process.env.NODE_ENV !== "production" && p.warn(
366
+ `A lock has exceeded ${this.lockWarningTime} ms. Waiting additional ${this.lockErrorTime} ms before rejecting the task.`,
367
+ t
368
+ ), e = setTimeout(() => {
369
+ t.reject("lock timeout exceeded");
578
370
  }, this.lockErrorTime);
579
- }, this.lockWarningTime);
580
- const taskPromise = Promise.resolve(next.task()).then((result) => {
581
- clearTimeout(warningTimeout);
582
- clearTimeout(errorTimeout);
583
- return result;
584
- });
585
- return Promise.resolve(taskPromise).then(this.next).then(() => taskPromise.then((data) => {
586
- next.done();
587
- next.resolve(data);
588
- })).catch((reason) => {
589
- next.done();
590
- next.reject(reason);
591
- return this.next();
592
- });
371
+ }, this.lockWarningTime), i = Promise.resolve(t.task()).then((n) => (clearTimeout(r), clearTimeout(e), n));
372
+ return Promise.resolve(i).then(this.next).then(
373
+ () => i.then((n) => {
374
+ t.done(), t.resolve(n);
375
+ })
376
+ ).catch((n) => (t.done(), t.reject(n), this.next()));
593
377
  }
594
378
  return Promise.resolve();
595
379
  });
596
380
  }
597
381
  }
598
- const locks = /* @__PURE__ */ new WeakMap();
599
- function lock(key, lockWarningTime = 5e3, lockErrorTime = 1e3) {
600
- if (!locks.has(key)) {
601
- locks.set(key, new Queue(lockWarningTime, lockErrorTime));
602
- }
603
- return (task) => {
604
- return new Promise((resolve, reject) => {
605
- const queue = locks.get(key);
606
- queue.add(task, resolve, reject, () => {
607
- if (!queue.tasks.length) {
608
- locks.delete(key);
609
- }
610
- });
382
+ const A = /* @__PURE__ */ new WeakMap();
383
+ function it(o, t = 5e3, e = 1e3) {
384
+ return A.has(o) || A.set(o, new U(t, e)), (r) => new Promise((i, n) => {
385
+ const c = A.get(o);
386
+ c.add(r, i, n, () => {
387
+ c.tasks.length || A.delete(o);
611
388
  });
612
- };
389
+ });
613
390
  }
614
- const isObject = (item) => {
615
- return !!item && typeof item === "object" && !Array.isArray(item);
616
- };
617
- const mergeDeep = (target, ...sources) => {
618
- const clonedTarget = deepClone(target);
619
- const clonedSources = deepClone(sources);
620
- return mergeDeepRecursive(clonedTarget, ...clonedSources);
621
- };
622
- const mergeDeepRecursive = (target, ...sources) => {
623
- if (!sources.length)
624
- return target;
625
- const source = sources.shift();
626
- if (isObject(target) && isObject(source)) {
627
- for (const key in source) {
628
- if (isObject(source[key])) {
629
- if (!target[key])
630
- Object.assign(target, { [key]: {} });
631
- mergeDeepRecursive(target[key], source[key]);
632
- } else {
633
- Object.assign(target, { [key]: source[key] });
634
- }
635
- }
636
- }
637
- return mergeDeepRecursive(target, ...sources);
638
- };
639
- const watchForLoadingComplete = (container, widgetDOMElement) => {
640
- const isLoading = () => widgetDOMElement.querySelectorAll("[data-loading=true]").length > 0;
641
- const complete = () => {
642
- let dispatched = false;
391
+ const v = (o) => !!o && typeof o == "object" && !Array.isArray(o), nt = (o, ...t) => {
392
+ const e = O(o), r = O(t);
393
+ return $(e, ...r);
394
+ }, $ = (o, ...t) => {
395
+ if (!t.length)
396
+ return o;
397
+ const e = t.shift();
398
+ if (v(o) && v(e))
399
+ for (const r in e)
400
+ v(e[r]) ? (o[r] || Object.assign(o, { [r]: {} }), $(o[r], e[r])) : Object.assign(o, { [r]: e[r] });
401
+ return $(o, ...t);
402
+ }, Z = (o, t) => {
403
+ const e = () => t.querySelectorAll("[data-loading=true]").length > 0, i = (() => {
404
+ let c = !1;
643
405
  return () => {
644
- if (dispatched) {
406
+ if (c)
645
407
  return;
646
- }
647
- const widget = container.get("$widget");
648
- widget.events.dispatch("widget:data-loaded", {
649
- element: widgetDOMElement
650
- });
651
- dispatched = true;
408
+ o.get("$widget").events.dispatch("widget:data-loaded", {
409
+ element: t
410
+ }), c = !0;
652
411
  };
653
- };
654
- const handleComplete = complete();
655
- if (!isLoading()) {
656
- return handleComplete();
657
- }
658
- const observer = new MutationObserver((mutations, observer2) => {
659
- const check = mutations.find((mutation) => mutation.type === "attributes" && mutation.attributeName === "data-loading");
660
- if (check && !isLoading()) {
661
- observer2.disconnect();
662
- handleComplete();
663
- }
412
+ })();
413
+ if (!e())
414
+ return i();
415
+ new MutationObserver((c, f) => {
416
+ c.find(
417
+ (g) => g.type === "attributes" && g.attributeName === "data-loading"
418
+ ) && !e() && (f.disconnect(), i());
419
+ }).observe(t, {
420
+ attributes: !0,
421
+ childList: !0,
422
+ subtree: !0
664
423
  });
665
- observer.observe(widgetDOMElement, {
666
- attributes: true,
667
- childList: true,
668
- subtree: true
669
- });
670
- };
671
- const notifyDataLoaded = (viewOutletContainer, widgetDOMElement) => {
672
- const widget = viewOutletContainer.get("$widget");
673
- widget.container.getAsync("components").then((components) => {
674
- components.events.subscribeOnce("components:component-model-initialized", () => {
675
- let waitingFor = components.nodes.visible.reduce((acc, node) => {
676
- if (!node.name || !node.type || node.type === "view" || node.type === "root" || node.attributes.layout.size === "none" || widgetDOMElement.querySelector(`[data-name="${node.name}"]`)) {
677
- return acc;
678
- }
679
- acc.push(node.name);
680
- return acc;
681
- }, []);
682
- let complete = false;
683
- const observer = new MutationObserver((mutations, observer2) => {
684
- mutations.forEach((mutation) => {
685
- if (mutation.addedNodes) {
686
- const componentElements = Array.from(mutation.addedNodes).reduce((acc, element) => {
687
- const dataName = element.getAttribute && element.getAttribute("data-name");
688
- if (dataName && waitingFor.indexOf(dataName) > -1) {
689
- acc.push(dataName);
690
- }
691
- return acc;
424
+ }, st = (o, t) => {
425
+ o.get("$widget").container.getAsync("components").then((r) => {
426
+ r.events.subscribeOnce("components:component-model-initialized", () => {
427
+ let i = r.nodes.visible.reduce(
428
+ (f, u) => (!u.name || !u.type || u.type === "view" || u.type === "root" || u.attributes.layout.size === "none" || t.querySelector(`[data-name="${u.name}"]`) || f.push(u.name), f),
429
+ []
430
+ ), n = !1;
431
+ new MutationObserver((f, u) => {
432
+ f.forEach((g) => {
433
+ if (g.addedNodes) {
434
+ const d = Array.from(
435
+ g.addedNodes
436
+ ).reduce((m, l) => {
437
+ const y = l.getAttribute && l.getAttribute("data-name");
438
+ return y && i.indexOf(y) > -1 && m.push(y), m;
692
439
  }, []);
693
- waitingFor = waitingFor.filter((name) => {
694
- return componentElements.indexOf(name) === -1;
695
- });
696
- if (!complete && waitingFor.length === 0) {
697
- complete = true;
698
- watchForLoadingComplete(viewOutletContainer, widgetDOMElement);
699
- observer2.disconnect();
700
- }
440
+ i = i.filter((m) => d.indexOf(m) === -1), !n && i.length === 0 && (n = !0, Z(o, t), u.disconnect());
701
441
  }
702
442
  });
703
- });
704
- observer.observe(widgetDOMElement, {
705
- attributes: false,
706
- characterData: false,
707
- childList: true,
708
- subtree: true,
709
- attributeOldValue: false,
710
- characterDataOldValue: false
443
+ }).observe(t, {
444
+ attributes: !1,
445
+ characterData: !1,
446
+ childList: !0,
447
+ subtree: !0,
448
+ attributeOldValue: !1,
449
+ characterDataOldValue: !1
711
450
  });
712
451
  });
713
452
  });
714
- };
715
- const removeNullAndUndefinedValues = (object = {}) => {
716
- Object.keys(object).forEach((key) => {
717
- if (object[key] === null || typeof object[key] === "undefined") {
718
- delete object[key];
719
- }
720
- });
721
- return object;
722
- };
723
- function setCookie(cookieName, value, days) {
724
- let expires = "";
725
- if (days) {
726
- const date = new Date();
727
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
728
- expires = `; expires=${date.toUTCString()}`;
729
- }
730
- document.cookie = `${cookieName}=${value}${expires}; path=/`;
453
+ }, ft = (o = {}) => (Object.keys(o).forEach((t) => {
454
+ (o[t] === null || typeof o[t] == "undefined") && delete o[t];
455
+ }), o);
456
+ function ct(o, t, e) {
457
+ let r = "";
458
+ if (e) {
459
+ const i = new Date();
460
+ i.setTime(i.getTime() + e * 24 * 60 * 60 * 1e3), r = `; expires=${i.toUTCString()}`;
461
+ }
462
+ document.cookie = `${o}=${t}${r}; path=/`;
731
463
  }
732
- var shallowCompare = (a, b) => {
733
- let equal = true;
734
- if (Object.keys(a).length !== Object.keys(b).length) {
735
- return false;
736
- }
737
- const missingKey = Object.keys(a).some((key) => {
738
- const found = Object.keys(b).some((bKey) => {
739
- return key === bKey;
740
- });
741
- return !found;
742
- });
743
- if (missingKey) {
744
- return false;
745
- }
746
- Object.keys(a).forEach((key) => {
747
- if (equal) {
748
- const c = typeof a[key] === "undefined" ? "" : a[key];
749
- const d = typeof b[key] === "undefined" ? "" : b[key];
750
- equal = c.toString() === d.toString();
464
+ const ut = (o, t) => {
465
+ let e = !0;
466
+ return Object.keys(o).length !== Object.keys(t).length || Object.keys(o).some((i) => !Object.keys(t).some((c) => i === c)) ? !1 : (Object.keys(o).forEach((i) => {
467
+ if (e) {
468
+ const n = typeof o[i] == "undefined" ? "" : o[i], c = typeof t[i] == "undefined" ? "" : t[i];
469
+ e = n.toString() === c.toString();
751
470
  }
752
- });
753
- return equal;
754
- };
755
- const s4 = () => {
756
- return Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
757
- };
758
- function uuid() {
759
- return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
471
+ }), e);
472
+ }, h = () => Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
473
+ function at() {
474
+ return h() + h() + "-" + h() + "-" + h() + "-" + h() + "-" + h() + h() + h();
760
475
  }
761
- class WaitFor {
762
- constructor(options) {
763
- this.queue = [];
764
- this.queueAttemptCalls = 0;
765
- this.callCount = 5;
766
- this.add = (action) => {
767
- this.queue.push(action);
768
- this.queueAttempt = setInterval(this.processQueue, 1e3);
769
- };
770
- this.processQueue = () => {
476
+ class lt {
477
+ constructor(t) {
478
+ a(this, "queue", []);
479
+ a(this, "queueAttempt");
480
+ a(this, "queueAttemptCalls", 0);
481
+ a(this, "callCount", 5);
482
+ a(this, "add", (t) => {
483
+ this.queue.push(t), this.queueAttempt = setInterval(this.processQueue, 1e3);
484
+ });
485
+ a(this, "processQueue", () => {
771
486
  if (this.queue.length > 0) {
772
- const indexOfActionsEmitted = [];
773
- this.queue.forEach((queuedAction, index) => {
774
- const evaluate = queuedAction();
775
- if (typeof evaluate === "function") {
776
- evaluate();
777
- indexOfActionsEmitted.push(index);
778
- }
779
- });
780
- this.queue = this.queue.filter((_, index) => {
781
- if (indexOfActionsEmitted.indexOf(index) > -1) {
782
- return false;
783
- }
784
- return true;
785
- });
786
- if (this.queueAttempt) {
787
- clearInterval(this.queueAttempt);
788
- }
789
- }
790
- if (this.queueAttemptCalls > this.callCount) {
791
- clearInterval(this.queueAttempt);
792
- this.queueAttemptCalls = 0;
487
+ const t = [];
488
+ this.queue.forEach((e, r) => {
489
+ const i = e();
490
+ typeof i == "function" && (i(), t.push(r));
491
+ }), this.queue = this.queue.filter((e, r) => !(t.indexOf(r) > -1)), this.queueAttempt && clearInterval(this.queueAttempt);
793
492
  }
794
- this.queueAttemptCalls = this.queueAttemptCalls + 1;
795
- };
796
- if (options && options.callCount) {
797
- this.callCount = options.callCount;
798
- }
493
+ this.queueAttemptCalls > this.callCount && (clearInterval(this.queueAttempt), this.queueAttemptCalls = 0), this.queueAttemptCalls = this.queueAttemptCalls + 1;
494
+ });
495
+ t && t.callCount && (this.callCount = t.callCount);
799
496
  }
800
497
  }
801
- export { Logger, WaitFor, appendClassNames, buildCategoryTrail, camilize, categoryTrail, createBatch, createParams, dataURItoBlob, debugLog, deepClone, findAndActivateStoredWidgets, findCategoryById, formatDate, formatUrl, getCategoryTrailAsObjects, getCookie, hash, htmlParentContains, kebabCase, lock, mergeDeep, notifyDataLoaded, removeNullAndUndefinedValues, setCookie, shallowCompare, uuid };
498
+ export {
499
+ p as Logger,
500
+ lt as WaitFor,
501
+ Q as appendClassNames,
502
+ G as buildCategoryTrail,
503
+ j as camilize,
504
+ F as categoryTrail,
505
+ H as createBatch,
506
+ N as createParams,
507
+ R as dataURItoBlob,
508
+ _ as debugLog,
509
+ O as deepClone,
510
+ X as findAndActivateStoredWidgets,
511
+ B as findCategoryById,
512
+ tt as formatDate,
513
+ q as formatUrl,
514
+ K as getCategoryTrailAsObjects,
515
+ et as getCookie,
516
+ L as hash,
517
+ ot as htmlParentContains,
518
+ rt as kebabCase,
519
+ it as lock,
520
+ nt as mergeDeep,
521
+ st as notifyDataLoaded,
522
+ ft as removeNullAndUndefinedValues,
523
+ ct as setCookie,
524
+ ut as shallowCompare,
525
+ at as uuid
526
+ };
802
527
  //# sourceMappingURL=index.js.map