@financial-times/custom-code-component 1.9.7 → 1.9.9

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.
@@ -1,1146 +1,217 @@
1
- function w(t) {
2
- this.listenerMap = [{}, {}], t && this.root(t), this.handle = w.prototype.handle.bind(this), this._removedListeners = [];
1
+ function u(o) {
2
+ this.listenerMap = [{}, {}], o && this.root(o), this.handle = u.prototype.handle.bind(this), this._removedListeners = [];
3
3
  }
4
- w.prototype.root = function(t) {
5
- const e = this.listenerMap;
6
- let n;
7
- if (this.rootElement) {
8
- for (n in e[1])
9
- e[1].hasOwnProperty(n) && this.rootElement.removeEventListener(n, this.handle, !0);
10
- for (n in e[0])
11
- e[0].hasOwnProperty(n) && this.rootElement.removeEventListener(n, this.handle, !1);
12
- }
13
- if (!t || !t.addEventListener)
14
- return this.rootElement && delete this.rootElement, this;
15
- this.rootElement = t;
16
- for (n in e[1])
17
- e[1].hasOwnProperty(n) && this.rootElement.addEventListener(n, this.handle, !0);
18
- for (n in e[0])
19
- e[0].hasOwnProperty(n) && this.rootElement.addEventListener(n, this.handle, !1);
20
- return this;
21
- };
22
- w.prototype.captureForType = function(t) {
23
- return ["blur", "error", "focus", "load", "resize", "scroll"].indexOf(t) !== -1;
24
- };
25
- w.prototype.on = function(t, e, n, o) {
26
- let r, i, a, c;
27
- if (!t)
28
- throw new TypeError("Invalid event type: " + t);
29
- if (typeof e == "function" && (o = n, n = e, e = null), o === void 0 && (o = this.captureForType(t)), typeof n != "function")
30
- throw new TypeError("Handler must be a type of Function");
31
- return r = this.rootElement, i = this.listenerMap[o ? 1 : 0], i[t] || (r && r.addEventListener(t, this.handle, o), i[t] = []), e ? /^[a-z]+$/i.test(e) ? (c = e, a = Et) : /^#[a-z0-9\-_]+$/i.test(e) ? (c = e.slice(1), a = xt) : (c = e, a = Element.prototype.matches) : (c = null, a = vt.bind(this)), i[t].push({
32
- selector: e,
33
- handler: n,
34
- matcher: a,
35
- matcherParam: c
36
- }), this;
37
- };
38
- w.prototype.off = function(t, e, n, o) {
39
- let r, i, a, c, s;
40
- if (typeof e == "function" && (o = n, n = e, e = null), o === void 0)
41
- return this.off(t, e, n, !0), this.off(t, e, n, !1), this;
42
- if (a = this.listenerMap[o ? 1 : 0], !t) {
43
- for (s in a)
44
- a.hasOwnProperty(s) && this.off(s, e, n);
45
- return this;
46
- }
47
- if (c = a[t], !c || !c.length)
48
- return this;
49
- for (r = c.length - 1; r >= 0; r--)
50
- i = c[r], (!e || e === i.selector) && (!n || n === i.handler) && (this._removedListeners.push(i), c.splice(r, 1));
51
- return c.length || (delete a[t], this.rootElement && this.rootElement.removeEventListener(t, this.handle, o)), this;
52
- };
53
- w.prototype.handle = function(t) {
54
- let e, n;
55
- const o = t.type;
56
- let r, i, a, c, s = [], u;
57
- const l = "ftLabsDelegateIgnore";
58
- if (t[l] === !0)
59
- return;
60
- switch (u = t.target, u.nodeType === 3 && (u = u.parentNode), u.correspondingUseElement && (u = u.correspondingUseElement), r = this.rootElement, i = t.eventPhase || (t.target !== t.currentTarget ? 3 : 2), i) {
61
- case 1:
62
- s = this.listenerMap[1][o];
63
- break;
64
- case 2:
65
- this.listenerMap[0] && this.listenerMap[0][o] && (s = s.concat(this.listenerMap[0][o])), this.listenerMap[1] && this.listenerMap[1][o] && (s = s.concat(this.listenerMap[1][o]));
66
- break;
67
- case 3:
68
- s = this.listenerMap[0][o];
69
- break;
70
- }
71
- let f = [];
72
- for (n = s.length; u && n; ) {
73
- for (e = 0; e < n && (a = s[e], !!a); e++)
74
- u.tagName && ["button", "input", "select", "textarea"].indexOf(u.tagName.toLowerCase()) > -1 && u.hasAttribute("disabled") ? f = [] : a.matcher.call(u, a.matcherParam, u) && f.push([t, u, a]);
75
- if (u === r || (n = s.length, u = u.parentElement || u.parentNode, u instanceof HTMLDocument))
76
- break;
77
- }
78
- let d;
79
- for (e = 0; e < f.length; e++)
80
- if (!(this._removedListeners.indexOf(f[e][2]) > -1) && (c = this.fire.apply(this, f[e]), c === !1)) {
81
- f[e][0][l] = !0, f[e][0].preventDefault(), d = !1;
82
- break;
83
- }
84
- return d;
85
- };
86
- w.prototype.fire = function(t, e, n) {
87
- return n.handler.call(e, t, e);
88
- };
89
- function Et(t, e) {
90
- return t.toLowerCase() === e.tagName.toLowerCase();
91
- }
92
- function vt(t, e) {
93
- return this.rootElement === window ? (
94
- // Match the outer document (dispatched from document)
95
- e === document || // The <html> element (dispatched from document.body or document.documentElement)
96
- e === document.documentElement || // Or the window itself (dispatched from window)
97
- e === window
98
- ) : this.rootElement === e;
99
- }
100
- function xt(t, e) {
101
- return t === e.id;
102
- }
103
- w.prototype.destroy = function() {
104
- this.off(), this.root();
105
- };
106
- const K = { config: {} };
107
- function tt(t) {
108
- if (t === void 0)
109
- return t;
110
- switch (Object.prototype.toString.call(t)) {
111
- case "[object Object]":
112
- return JSON.parse(JSON.stringify(t));
113
- case "[object Array]":
114
- return [].slice.call(t);
115
- default:
116
- return t;
117
- }
118
- }
119
- function kt(t, e) {
120
- K[t] = tt(e);
121
- }
122
- function Ot(t) {
123
- return tt(K[t]);
124
- }
125
- function Q(t) {
126
- delete K[t];
127
- }
128
- const C = kt, h = Ot;
129
- let A = 0;
130
- const H = 4, N = 36, et = Math.pow(N, H), F = function(e, n) {
131
- const o = "000000000" + e;
132
- return o.substr(o.length - n);
133
- }, U = function() {
134
- return F((Math.random() * et << 0).toString(N), H);
135
- }, nt = () => (A = A < et ? A : 0, A++, A - 1), p = function() {
136
- const e = "c", n = (/* @__PURE__ */ new Date()).getTime().toString(N), o = p.fingerprint(), r = U() + U(), i = F(nt().toString(N), H);
137
- return e + n + i + o + r;
138
- };
139
- p.slug = function() {
140
- const e = (/* @__PURE__ */ new Date()).getTime().toString(36), n = p.fingerprint().slice(0, 1) + p.fingerprint().slice(-1), o = U().slice(-2), r = nt().toString(36).slice(-4);
141
- return e.slice(-2) + r + n + o;
142
- };
143
- p.globalCount = function() {
144
- const e = function() {
145
- let o = 0;
146
- for (const r in window)
147
- o++;
148
- return o;
149
- }();
150
- return p.globalCount = () => e, e;
151
- };
152
- p.fingerprint = function() {
153
- return F((navigator.mimeTypes.length + navigator.userAgent.length).toString(36) + p.globalCount().toString(36), 4);
154
- };
155
- const X = [];
156
- function P(...t) {
157
- if (h("config").test && window.console)
158
- for (const e of t)
159
- window.console.log(e);
160
- }
161
- function y(t, e = "undefined") {
162
- return typeof t === e;
163
- }
164
- function m(t, e) {
165
- e || (e = t, t = {});
166
- let n, o, r;
167
- for (n in e)
168
- o = t[n], r = e[n], t !== r && typeof r < "u" && r !== null && (t[n] = o === Object(o) && !y(o, "function") ? m(o, r) : r);
169
- return t;
170
- }
171
- function V(t) {
172
- return window.encodeURIComponent ? window.encodeURIComponent(t) : window.escape(t);
173
- }
174
- function Ct(t) {
175
- return window.decodeURIComponent ? window.decodeURIComponent(t) : window.unescape(t);
176
- }
177
- function z(t, e, n) {
178
- t.addEventListener ? t.addEventListener(e, n, !1) : t.attachEvent("on" + e, n);
179
- }
180
- function v(t, e, n) {
181
- n = n || {};
182
- try {
183
- window.dispatchEvent(new CustomEvent(t + "." + e, {
184
- detail: n,
185
- bubbles: !0
186
- }));
187
- } catch {
188
- }
189
- }
190
- function St() {
191
- for (let t = 0; t < X.length; t++)
192
- X[t]();
193
- }
194
- function Y(t) {
195
- return document.cookie.match(t) && RegExp.$1 !== "" && RegExp.$1 !== "null" ? RegExp.$1 : null;
196
- }
197
- function At(t, e) {
198
- const n = {};
199
- for (const o of e)
200
- t[o] && (n[o] = t[o]);
201
- return n;
202
- }
203
- function R(t) {
204
- return typeof t == "string" ? t.trim() : t;
205
- }
206
- function _(t, e) {
207
- for (const n in t)
208
- e[n] ? console.warn(`You can't set a custom property called ${n}`) : e[n] = t[n];
209
- }
210
- function ot(t) {
211
- const e = /* @__PURE__ */ new WeakSet(), n = [];
212
- function o(r, i) {
213
- if (e.has(r)) {
214
- n.push(i);
215
- return;
216
- }
217
- if (r instanceof Object) {
218
- e.add(r);
219
- for (const [a, c] of Object.entries(r))
220
- c instanceof Object && (Array.isArray(r) ? o(c, `${i}[${a}]`) : o(c, `${i}.${a}`));
221
- }
222
- }
223
- return o(t, ""), n;
224
- }
225
- function rt(t) {
226
- const e = /* @__PURE__ */ new WeakSet();
227
- function n(o) {
228
- if (e.has(o))
229
- return !0;
230
- if (o instanceof Object) {
231
- e.add(o);
232
- for (const r of Object.values(o))
233
- if (r instanceof Object && n(r))
234
- return !0;
235
- }
236
- }
237
- return !!n(
238
- t
239
- );
240
- }
241
- function q(t, e) {
242
- if (t === e)
243
- return !0;
244
- if (t && e && typeof t == "object" && typeof e == "object") {
245
- if (t.constructor !== e.constructor)
246
- return !1;
247
- if (Array.isArray(t)) {
248
- const r = t.length;
249
- if (r !== e.length)
250
- return !1;
251
- for (let i = r; i-- !== 0; )
252
- if (!q(t[i], e[i]))
253
- return !1;
254
- return !0;
255
- }
256
- if (t.constructor === RegExp)
257
- return t.source === e.source && t.flags === e.flags;
258
- if (t.valueOf !== Object.prototype.valueOf)
259
- return t.valueOf() === e.valueOf();
260
- if (t.toString !== Object.prototype.toString)
261
- return t.toString() === e.toString();
262
- const n = Object.keys(t), o = n.length;
263
- if (o !== Object.keys(e).length)
264
- return !1;
265
- for (let r = o; r-- !== 0; )
266
- if (!Object.prototype.hasOwnProperty.call(e, n[r]))
267
- return !1;
268
- for (let r = o; r-- !== 0; ) {
269
- const i = n[r];
270
- if (!q(t[i], e[i]))
271
- return !1;
272
- }
273
- return !0;
274
- }
275
- }
276
- const S = function(t, e = {}) {
277
- const n = "o-tracking";
278
- if (typeof t != "string" || t === "") {
279
- const s = new Error("You must specify a name for the store.");
280
- throw v("oErrors", "log", {
281
- error: s.message,
282
- info: { module: "o-tracking" }
283
- }), s;
284
- }
285
- this.config = Object.assign({}, e), this.data = null, this.storageKey = this.config.nameOverride ? this.config.nameOverride : [n, t].join("_"), this.storage = {
286
- _type: "localStorage",
287
- load: function(s) {
288
- return window.localStorage.getItem(s);
289
- },
290
- save: function(s, u) {
291
- return window.localStorage.setItem(s, u);
292
- },
293
- remove: function(s) {
294
- return i(s), window.localStorage.removeItem(s);
295
- }
296
- };
297
- function o(s) {
298
- s = s + "=";
299
- const u = window.document.cookie.split(";");
300
- let l, f;
301
- for (l = 0; l < u.length; l = l + 1)
302
- if (f = u[l].replace(/^\s+|\s+$/g, ""), f.indexOf(s) === 0)
303
- return Ct(f.substring(s.length, f.length));
304
- return null;
305
- }
306
- function r(s, u, l) {
307
- let f, d = "";
308
- y(l, "number") && (f = /* @__PURE__ */ new Date(), f.setTime(f.getTime() + l), d = "expires=" + f.toUTCString() + ";");
309
- const bt = V(s) + "=" + V(u) + ";" + d + "path=/;" + (e.domain ? "domain=." + e.domain + ";" : "");
310
- window.document.cookie = bt;
311
- }
312
- function i(s) {
313
- r(s, "", -1);
314
- }
315
- const a = this.storage.load(this.storageKey);
316
- if (a)
317
- try {
318
- this.data = JSON.parse(a);
319
- } catch (s) {
320
- v("oErrors", "log", {
321
- error: s.message,
322
- module: "o-tracking"
323
- }), this.data = a;
324
- }
325
- const c = o(this.storageKey);
326
- if (c)
327
- try {
328
- if (this.storageKey === "spoor-id")
329
- this.data = c;
330
- else {
331
- const s = JSON.parse(c);
332
- this.data ? Object.assign(this.data, s) : this.data = s;
333
- for (const u of Object.keys(s))
334
- u !== "spoor-id" && i(u);
335
- }
336
- } catch (s) {
337
- v("oErrors", "log", {
338
- error: s.message,
339
- module: "o-tracking"
340
- }), this.data = a;
341
- }
342
- return this;
343
- };
344
- S.prototype.read = function() {
345
- return this.data;
346
- };
347
- S.prototype.write = function(t) {
348
- this.data = t;
4
+ u.prototype.root = function(o) {
5
+ const t = this.listenerMap;
349
6
  let e;
350
- if (typeof this.data == "string")
351
- e = this.data;
352
- else {
353
- if (rt(this.data)) {
354
- const n = `o-tracking does not support circular references in the analytics data.
355
- Please remove the circular references in the data.
356
- Here are the paths in the data which are circular:
357
- ` + JSON.stringify(ot(this.data), void 0, 4);
358
- throw new Error(n);
359
- }
360
- e = JSON.stringify(this.data);
361
- }
362
- return this.storage.save(this.storageKey, e), this;
363
- };
364
- S.prototype.destroy = function() {
365
- return this.data = null, this.storage.remove(this.storageKey), this;
366
- };
367
- let O, B;
368
- function Pt(t, e) {
369
- const n = {
370
- storage: "cookie",
371
- name: "spoor-id",
372
- nameOverride: "spoor-id",
373
- value: null,
374
- // Set the store cookie domain to .ft.com for ft.com and all its subdomains
375
- domain: location.hostname.match(/^(?:.+\.)?ft\.com$/) ? "ft.com" : null
376
- };
377
- e && (n.domain = e), B = new S(n.name, n);
378
- let o = B.read();
379
- return o || (o = t), it(o);
380
- }
381
- function it(t) {
382
- return O = t, O || (O = p()), B.write(O), O;
383
- }
384
- function _t() {
385
- return O;
386
- }
387
- let $;
388
- const Nt = {
389
- storage: "best",
390
- name: "session",
391
- expires: 30 * 60 * 1e3
392
- // 30 minutes
393
- };
394
- function $t(t) {
395
- const e = /* @__PURE__ */ new Date();
396
- e.setTime(e.getTime() + $.config.expires), $.write({
397
- value: t,
398
- expiry: e.valueOf()
399
- });
400
- }
401
- function st() {
402
- const t = $.read();
403
- let e, n = !1;
404
- if (t) {
405
- const o = (/* @__PURE__ */ new Date()).valueOf();
406
- parseInt(t.expiry, 10) >= o ? e = t.value : (e = p(), n = !0);
407
- }
408
- return e || (e = p(), n = !0), $t(e), {
409
- id: e,
410
- isNew: n
411
- };
412
- }
413
- function It(t) {
414
- y(t, "string") && (t = { name: t }), y(t) && (t = {});
415
- const e = m(Nt, t);
416
- return e.storage === "cookie" && t.name && (e.nameOverride = e.name), $ = new S(e.name, e), st();
417
- }
418
- function b(t) {
419
- if (y(t)) {
420
- const e = new Error("You must specify a name for the queue.");
421
- throw v("oErrors", "log", {
422
- error: e.message,
423
- info: { module: "o-tracking" }
424
- }), e;
425
- }
426
- return this.queue = [], this.storage = new S(t), this.storage.read() && (this.queue = this.storage.read()), this;
427
- }
428
- b.prototype.all = function() {
429
- if (this.queue.length === 0)
430
- return [];
431
- const t = [];
432
- for (let e = 0; e < this.queue.length; e = e + 1)
433
- t.push(this.queue[e].item);
434
- return t;
435
- };
436
- b.prototype.first = function() {
437
- return this.queue.length === 0 ? null : this.queue[0].item;
438
- };
439
- b.prototype.last = function() {
440
- return this.queue.length === 0 ? null : this.queue.slice(-1)[0].item;
441
- };
442
- b.prototype.add = function(t) {
443
- const e = this;
444
- let n;
445
- function o(r) {
446
- e.queue.push({
447
- created_at: (/* @__PURE__ */ new Date()).valueOf(),
448
- item: r
449
- });
450
- }
451
- if (y(t, "object") && t.constructor.toString().match(/array/i))
452
- for (n = 0; n < t.length; n = n + 1)
453
- o(t[n]);
454
- else
455
- o(t);
456
- return e;
457
- };
458
- b.prototype.replace = function(t) {
459
- if (Array.isArray(t))
460
- return this.queue = [], this.add(t).save(), this;
461
- const e = new Error("Argument invalid, must be an array.");
462
- throw v("oErrors", "log", {
463
- error: e.message,
464
- info: { module: "o-tracking" }
465
- }), e;
466
- };
467
- b.prototype.shift = function() {
468
- if (this.queue.length === 0)
469
- return null;
470
- const t = this.queue.shift().item;
471
- return this.save(), t;
472
- };
473
- b.prototype.save = function() {
474
- return this.storage.write(this.queue), this;
475
- };
476
- function Lt() {
477
- const t = new window.XMLHttpRequest();
478
- return {
479
- name: "xhr",
480
- send: function(e, n) {
481
- t.open("POST", e, !0), t.withCredentials = !0, t.setRequestHeader("Content-type", "application/json"), t.send(n);
482
- },
483
- complete: function(e) {
484
- t.onerror = function() {
485
- e(this);
486
- }, t.onload = function() {
487
- t.status >= 200 && t.status < 300 ? e() : e("Incorrect response: " + t.status);
488
- };
489
- }
490
- };
491
- }
492
- function Dt() {
493
- let t, e;
494
- const n = new Promise((o, r) => {
495
- t = o, e = r;
496
- });
497
- return {
498
- name: "sendBeacon",
499
- send: function(o, r) {
500
- navigator.sendBeacon(o, r) ? t() : e(new Error("Failed to send beacon event: " + r.toString()));
501
- },
502
- complete: function(o) {
503
- o && n.then(o, o);
504
- }
505
- };
506
- }
507
- function Rt() {
508
- const t = new Image(1, 1);
509
- return {
510
- name: "image",
511
- send: function(e, n) {
512
- e = e.replace("https://spoor-api.ft.com/ingest", "https://spoor-api.ft.com/px.gif"), t.src = e + (e.indexOf("?") > -1 ? "&" : "?") + "data=" + V(n);
513
- },
514
- complete: function(e) {
515
- t.addEventListener ? (t.addEventListener("error", e), t.addEventListener("load", () => e())) : (t.attachEvent("onerror", e), t.attachEvent("onload", () => e()));
516
- }
517
- };
518
- }
519
- const G = {};
520
- function j(t) {
521
- if (G.transport)
522
- return G.transport;
523
- switch (t) {
524
- case "xhr":
525
- return Lt;
526
- case "sendBeacon":
527
- return Dt;
528
- case "image":
529
- return Rt;
530
- default:
531
- return;
532
- }
533
- }
534
- let g;
535
- function at() {
536
- return (h("config") || {}).queue === !0 ? !1 : !!navigator.sendBeacon;
537
- }
538
- function ct(t, e) {
539
- const n = t.queueTime, o = (/* @__PURE__ */ new Date()).getTime() - n, r = at() ? j("sendBeacon")() : window.XMLHttpRequest && "withCredentials" in new window.XMLHttpRequest() ? j("xhr")() : j("image")(), i = t.callback, a = h("config") && h("config").system || {}, c = m(a, {
540
- version: h("version"),
541
- // Version of the tracking client e.g. '1.2'
542
- source: h("source"),
543
- // Source of the tracking client e.g. 'o-tracking'
544
- transport: r.name
545
- // The transport method used.
546
- });
547
- if (h("config").test || h("config").test_data ? c.is_live = !1 : c.is_live = !0, t = m({ system: c }, t), o > 1e3 && o < 12 * 30 * 24 * 60 * 60 * 1e3 && (t.time = t.time || {}, t.time.offset = o), delete t.callback, delete t.type, delete t.queueTime, P("user_callback", i), P("PreSend", t), rt(t)) {
548
- const l = `o-tracking does not support circular references in the analytics data.
549
- Please remove the circular references in the data.
550
- Here are the paths in the data which are circular:
551
- ` + JSON.stringify(ot(t), void 0, 4);
552
- throw new Error(l);
553
- }
554
- const s = JSON.stringify(t);
555
- r.complete(function(l) {
556
- y(i, "function") && (i.call(t), P("calling user_callback")), l ? (t.queueTime = n, g.add(t).save(), v("oErrors", "log", {
557
- error: l.message,
558
- info: { module: "o-tracking" }
559
- })) : e && e();
560
- });
561
- let u = "https://spoor-api.ft.com/ingest";
562
- t && t.category && t.action && (u += `?type=${t.category}:${t.action}`), r.send(u, s);
563
- }
564
- function Mt(t) {
565
- t.queueTime = (/* @__PURE__ */ new Date()).getTime(), at() ? ct(t) : g.add(t).save(), P("AddedToQueue", g);
566
- }
567
- function I(t = function() {
568
- }) {
569
- const e = g.all();
570
- if (e.length > 200) {
571
- const r = {};
572
- e.forEach(function(i) {
573
- const a = [i.category, i.action].join(":");
574
- Object.prototype.hasOwnProperty.call(r, a) || (r[a] = 0), r[a] += 1;
575
- }), g.replace([]), g.add({
576
- category: "o-tracking",
577
- action: "queue-bug",
578
- context: {
579
- url: document.URL,
580
- queue_length: e.length,
581
- counts: r,
582
- storage: g.storage.storage._type
583
- }
584
- });
585
- }
586
- const n = function() {
587
- I(), t();
588
- }, o = g.shift();
589
- return o ? ct(o, n) : t();
590
- }
591
- function Tt(t) {
592
- Mt(t), I();
593
- }
594
- function jt() {
595
- return g = new b("requests"), z(window, "online", function() {
596
- I();
597
- }), I(), g;
598
- }
599
- let L;
600
- function ut() {
601
- return L = p(), L;
602
- }
603
- function ft() {
604
- return L || ut(), L;
605
- }
606
- function Jt(t, e = function() {
607
- }) {
608
- const n = st(), o = {
609
- callback: e,
610
- context: {
611
- id: t.id || p(),
612
- // Use a supplied id or generate one for this request
613
- root_id: ft()
614
- },
615
- user: {
616
- ft_session: Y(/FTSession=([^;]+)/),
617
- ft_session_s: Y(/FTSession_s=([^;]+)/)
618
- },
619
- device: {
620
- spoor_session: n.id,
621
- spoor_session_is_new: n.isNew,
622
- spoor_id: _t()
623
- }
624
- }, r = h("config") || {};
625
- return r.context && m(o.context, r.context), r.user && m(o.user, r.user), r.device && m(o.device, r.device), m(o, t), P("Core.Track", o), Tt(o), o;
626
- }
627
- const x = {
628
- setRootID: ut,
629
- getRootID: ft,
630
- track: Jt
631
- }, Ut = function() {
632
- return {
633
- category: "event",
634
- action: "generic",
635
- context: {}
636
- };
637
- };
638
- function M(t, e) {
639
- if (y(t.detail.category) || y(t.detail.action)) {
640
- const r = "Missing category or action values";
641
- throw v("oErrors", "log", {
642
- error: r,
643
- info: { module: "o-tracking" }
644
- }), r;
645
- }
646
- const n = m(Ut(), {
647
- category: t.detail.category,
648
- action: t.detail.action,
649
- context: t.detail
650
- });
651
- delete n.context.category, delete n.context.action;
652
- const o = Vt(t);
653
- o && (n.context.component_name = o.getAttribute("data-o-component"), n.context.component_id = n.context.component_id || qt(o)), x.track(n, e);
654
- }
655
- function Vt(t) {
656
- const e = t.target || t.srcElement;
657
- if (e && e.getAttribute("data-o-component"))
658
- return e;
659
- }
660
- function qt(t) {
661
- const e = Bt(t);
662
- if (typeof e > "u")
663
- return;
664
- const n = e[0], o = function(a) {
665
- const c = a.parentElement;
666
- if (c) {
667
- for (let s = 0; s < c.childNodes.length; s++)
668
- if (c.childNodes[s] === n)
669
- return s;
670
- return -1;
671
- } else
672
- return 0;
673
- }(n), r = e.reduceRight(function(i, a) {
674
- if (!a.nodeName)
675
- return i + " - " + a.constructor.name + `
676
- `;
677
- const c = a.nodeName.toLowerCase();
678
- return c.indexOf("#") === 0 ? i + "<" + c + ">" : i + "<" + c + ' id="' + (a.id || "") + '">';
679
- }, "");
680
- return Kt(r + "_siblingIndex=" + o);
681
- }
682
- function Bt(t) {
683
- const e = [];
684
- for (; t; )
685
- e.push(t), t = t.parentElement;
686
- return e;
687
- }
688
- function Kt(t) {
689
- let e = t.length, n = 1 ^ e, o = 0, r;
690
- for (; e >= 4; )
691
- r = t.charCodeAt(o) & 255 | (t.charCodeAt(++o) & 255) << 8 | (t.charCodeAt(++o) & 255) << 16 | (t.charCodeAt(++o) & 255) << 24, r = (r & 65535) * 1540483477 + (((r >>> 16) * 1540483477 & 65535) << 16), r ^= r >>> 24, r = (r & 65535) * 1540483477 + (((r >>> 16) * 1540483477 & 65535) << 16), n = (n & 65535) * 1540483477 + (((n >>> 16) * 1540483477 & 65535) << 16) ^ r, e -= 4, ++o;
692
- switch (e) {
693
- case 3:
694
- n ^= (t.charCodeAt(o + 2) & 255) << 16;
695
- break;
696
- case 2:
697
- n ^= (t.charCodeAt(o + 1) & 255) << 8;
698
- break;
699
- case 1:
700
- n ^= t.charCodeAt(o) & 255, n = (n & 65535) * 1540483477 + (((n >>> 16) * 1540483477 & 65535) << 16);
701
- break;
702
- }
703
- return n ^= n >>> 13, n = (n & 65535) * 1540483477 + (((n >>> 16) * 1540483477 & 65535) << 16), n ^= n >>> 15, n >>> 0;
704
- }
705
- const Ht = function() {
706
- z(window, "oTracking.event", M);
707
- };
708
- M.init = Ht;
709
- C("page_has_already_been_viewed", !1);
710
- const Ft = function() {
711
- return {
712
- category: "page",
713
- action: "view",
714
- context: {
715
- url: document.URL,
716
- referrer: document.referrer
717
- }
718
- };
719
- };
720
- function T(t, e) {
721
- t = m(Ft(), {
722
- context: t
723
- }), h("page_has_already_been_viewed") && x.setRootID(), C("page_has_already_been_viewed", !0), zt(t) ? h("config").test && console.warn("A page event has already been sent for this page, refusing to send a duplicate page event.") : (x.track(t, e), St());
724
- }
725
- let Z = {};
726
- function zt(t) {
727
- const e = JSON.parse(JSON.stringify(t));
728
- return delete e.context.id, delete e.context.root_id, q(Z, e) ? !0 : (Z = e, !1);
729
- }
730
- function Wt(t) {
731
- T(t.detail);
732
- }
733
- const Qt = function() {
734
- z(window, "oTracking.page", Wt);
735
- };
736
- T.init = Qt;
737
- function E(t) {
738
- this.listenerMap = [{}, {}], t && this.root(t), this.handle = E.prototype.handle.bind(this), this._removedListeners = [];
739
- }
740
- E.prototype.root = function(t) {
741
- const e = this.listenerMap;
742
- let n;
743
7
  if (this.rootElement) {
744
- for (n in e[1])
745
- e[1].hasOwnProperty(n) && this.rootElement.removeEventListener(n, this.handle, !0);
746
- for (n in e[0])
747
- e[0].hasOwnProperty(n) && this.rootElement.removeEventListener(n, this.handle, !1);
8
+ for (e in t[1])
9
+ t[1].hasOwnProperty(e) && this.rootElement.removeEventListener(e, this.handle, !0);
10
+ for (e in t[0])
11
+ t[0].hasOwnProperty(e) && this.rootElement.removeEventListener(e, this.handle, !1);
748
12
  }
749
- if (!t || !t.addEventListener)
13
+ if (!o || !o.addEventListener)
750
14
  return this.rootElement && delete this.rootElement, this;
751
- this.rootElement = t;
752
- for (n in e[1])
753
- e[1].hasOwnProperty(n) && this.rootElement.addEventListener(n, this.handle, !0);
754
- for (n in e[0])
755
- e[0].hasOwnProperty(n) && this.rootElement.addEventListener(n, this.handle, !1);
15
+ this.rootElement = o;
16
+ for (e in t[1])
17
+ t[1].hasOwnProperty(e) && this.rootElement.addEventListener(e, this.handle, !0);
18
+ for (e in t[0])
19
+ t[0].hasOwnProperty(e) && this.rootElement.addEventListener(e, this.handle, !1);
756
20
  return this;
757
21
  };
758
- E.prototype.captureForType = function(t) {
759
- return ["blur", "error", "focus", "load", "resize", "scroll"].indexOf(t) !== -1;
22
+ u.prototype.captureForType = function(o) {
23
+ return ["blur", "error", "focus", "load", "resize", "scroll"].indexOf(o) !== -1;
760
24
  };
761
- E.prototype.on = function(t, e, n, o) {
762
- let r, i, a, c;
763
- if (!t)
764
- throw new TypeError("Invalid event type: " + t);
765
- if (typeof e == "function" && (o = n, n = e, e = null), o === void 0 && (o = this.captureForType(t)), typeof n != "function")
25
+ u.prototype.on = function(o, t, e, n) {
26
+ let s, r, c, i;
27
+ if (!o)
28
+ throw new TypeError("Invalid event type: " + o);
29
+ if (typeof t == "function" && (n = e, e = t, t = null), n === void 0 && (n = this.captureForType(o)), typeof e != "function")
766
30
  throw new TypeError("Handler must be a type of Function");
767
- return r = this.rootElement, i = this.listenerMap[o ? 1 : 0], i[t] || (r && r.addEventListener(t, this.handle, o), i[t] = []), e ? /^[a-z]+$/i.test(e) ? (c = e, a = Xt) : /^#[a-z0-9\-_]+$/i.test(e) ? (c = e.slice(1), a = Gt) : (c = e, a = Element.prototype.matches) : (c = null, a = Yt.bind(this)), i[t].push({
768
- selector: e,
769
- handler: n,
770
- matcher: a,
771
- matcherParam: c
31
+ return s = this.rootElement, r = this.listenerMap[n ? 1 : 0], r[o] || (s && s.addEventListener(o, this.handle, n), r[o] = []), t ? /^[a-z]+$/i.test(t) ? (i = t, c = E) : /^#[a-z0-9\-_]+$/i.test(t) ? (i = t.slice(1), c = w) : (i = t, c = Element.prototype.matches) : (i = null, c = y.bind(this)), r[o].push({
32
+ selector: t,
33
+ handler: e,
34
+ matcher: c,
35
+ matcherParam: i
772
36
  }), this;
773
37
  };
774
- E.prototype.off = function(t, e, n, o) {
775
- let r, i, a, c, s;
776
- if (typeof e == "function" && (o = n, n = e, e = null), o === void 0)
777
- return this.off(t, e, n, !0), this.off(t, e, n, !1), this;
778
- if (a = this.listenerMap[o ? 1 : 0], !t) {
779
- for (s in a)
780
- a.hasOwnProperty(s) && this.off(s, e, n);
38
+ u.prototype.off = function(o, t, e, n) {
39
+ let s, r, c, i, h;
40
+ if (typeof t == "function" && (n = e, e = t, t = null), n === void 0)
41
+ return this.off(o, t, e, !0), this.off(o, t, e, !1), this;
42
+ if (c = this.listenerMap[n ? 1 : 0], !o) {
43
+ for (h in c)
44
+ c.hasOwnProperty(h) && this.off(h, t, e);
781
45
  return this;
782
46
  }
783
- if (c = a[t], !c || !c.length)
47
+ if (i = c[o], !i || !i.length)
784
48
  return this;
785
- for (r = c.length - 1; r >= 0; r--)
786
- i = c[r], (!e || e === i.selector) && (!n || n === i.handler) && (this._removedListeners.push(i), c.splice(r, 1));
787
- return c.length || (delete a[t], this.rootElement && this.rootElement.removeEventListener(t, this.handle, o)), this;
49
+ for (s = i.length - 1; s >= 0; s--)
50
+ r = i[s], (!t || t === r.selector) && (!e || e === r.handler) && (this._removedListeners.push(r), i.splice(s, 1));
51
+ return i.length || (delete c[o], this.rootElement && this.rootElement.removeEventListener(o, this.handle, n)), this;
788
52
  };
789
- E.prototype.handle = function(t) {
790
- let e, n;
791
- const o = t.type;
792
- let r, i, a, c, s = [], u;
793
- const l = "ftLabsDelegateIgnore";
794
- if (t[l] === !0)
53
+ u.prototype.handle = function(o) {
54
+ let t, e;
55
+ const n = o.type;
56
+ let s, r, c, i, h = [], a;
57
+ const m = "ftLabsDelegateIgnore";
58
+ if (o[m] === !0)
795
59
  return;
796
- switch (u = t.target, u.nodeType === 3 && (u = u.parentNode), u.correspondingUseElement && (u = u.correspondingUseElement), r = this.rootElement, i = t.eventPhase || (t.target !== t.currentTarget ? 3 : 2), i) {
60
+ switch (a = o.target, a.nodeType === 3 && (a = a.parentNode), a.correspondingUseElement && (a = a.correspondingUseElement), s = this.rootElement, r = o.eventPhase || (o.target !== o.currentTarget ? 3 : 2), r) {
797
61
  case 1:
798
- s = this.listenerMap[1][o];
62
+ h = this.listenerMap[1][n];
799
63
  break;
800
64
  case 2:
801
- this.listenerMap[0] && this.listenerMap[0][o] && (s = s.concat(this.listenerMap[0][o])), this.listenerMap[1] && this.listenerMap[1][o] && (s = s.concat(this.listenerMap[1][o]));
65
+ this.listenerMap[0] && this.listenerMap[0][n] && (h = h.concat(this.listenerMap[0][n])), this.listenerMap[1] && this.listenerMap[1][n] && (h = h.concat(this.listenerMap[1][n]));
802
66
  break;
803
67
  case 3:
804
- s = this.listenerMap[0][o];
68
+ h = this.listenerMap[0][n];
805
69
  break;
806
70
  }
807
- let f = [];
808
- for (n = s.length; u && n; ) {
809
- for (e = 0; e < n && (a = s[e], !!a); e++)
810
- u.tagName && ["button", "input", "select", "textarea"].indexOf(u.tagName.toLowerCase()) > -1 && u.hasAttribute("disabled") ? f = [] : a.matcher.call(u, a.matcherParam, u) && f.push([t, u, a]);
811
- if (u === r || (n = s.length, u = u.parentElement || u.parentNode, u instanceof HTMLDocument))
71
+ let l = [];
72
+ for (e = h.length; a && e; ) {
73
+ for (t = 0; t < e && (c = h[t], !!c); t++)
74
+ a.tagName && ["button", "input", "select", "textarea"].indexOf(a.tagName.toLowerCase()) > -1 && a.hasAttribute("disabled") ? l = [] : c.matcher.call(a, c.matcherParam, a) && l.push([o, a, c]);
75
+ if (a === s || (e = h.length, a = a.parentElement || a.parentNode, a instanceof HTMLDocument))
812
76
  break;
813
77
  }
814
78
  let d;
815
- for (e = 0; e < f.length; e++)
816
- if (!(this._removedListeners.indexOf(f[e][2]) > -1) && (c = this.fire.apply(this, f[e]), c === !1)) {
817
- f[e][0][l] = !0, f[e][0].preventDefault(), d = !1;
79
+ for (t = 0; t < l.length; t++)
80
+ if (!(this._removedListeners.indexOf(l[t][2]) > -1) && (i = this.fire.apply(this, l[t]), i === !1)) {
81
+ l[t][0][m] = !0, l[t][0].preventDefault(), d = !1;
818
82
  break;
819
83
  }
820
84
  return d;
821
85
  };
822
- E.prototype.fire = function(t, e, n) {
823
- return n.handler.call(e, t, e);
86
+ u.prototype.fire = function(o, t, e) {
87
+ return e.handler.call(t, o, t);
824
88
  };
825
- function Xt(t, e) {
826
- return t.toLowerCase() === e.tagName.toLowerCase();
89
+ function E(o, t) {
90
+ return o.toLowerCase() === t.tagName.toLowerCase();
827
91
  }
828
- function Yt(t, e) {
92
+ function y(o, t) {
829
93
  return this.rootElement === window ? (
830
94
  // Match the outer document (dispatched from document)
831
- e === document || // The <html> element (dispatched from document.body or document.documentElement)
832
- e === document.documentElement || // Or the window itself (dispatched from window)
833
- e === window
834
- ) : this.rootElement === e;
95
+ t === document || // The <html> element (dispatched from document.body or document.documentElement)
96
+ t === document.documentElement || // Or the window itself (dispatched from window)
97
+ t === window
98
+ ) : this.rootElement === t;
835
99
  }
836
- function Gt(t, e) {
837
- return t === e.id;
100
+ function w(o, t) {
101
+ return o === t.id;
838
102
  }
839
- E.prototype.destroy = function() {
103
+ u.prototype.destroy = function() {
840
104
  this.off(), this.root();
841
105
  };
842
- const Zt = (t, e, n) => {
843
- const o = Array.from(t.querySelectorAll(n)), r = o.findIndex((i) => i === e);
844
- if (r !== -1)
845
- return {
846
- siblings: o.length,
847
- position: r
848
- };
849
- }, lt = [
850
- "nodeName",
851
- "className",
852
- "id",
853
- "href",
854
- "text",
855
- "role"
856
- ], te = (t) => {
857
- const e = {};
858
- for (const n of lt) {
859
- const o = t[n] || t.getAttribute(n) || t.hasAttribute(n);
860
- o !== void 0 && (typeof o == "boolean" ? e[n] = o : e[n] = R(o));
861
- }
862
- return e;
863
- }, ee = (t) => {
864
- try {
865
- const e = JSON.parse(t), n = Object.prototype.toString.call(e);
866
- return [n === "[object Object]" || n === "[object Array]", e];
867
- } catch {
868
- return [!1, null];
869
- }
870
- }, ne = (t) => {
871
- const [e, n] = ee(t);
872
- return e ? n : t;
873
- }, oe = (t, e) => (t.filter((n) => n.name.match(/^data-trackable|^data-o-|^aria-/i)).forEach((n) => {
874
- e[n.name] = n.value;
875
- }), e), re = (t, e, n) => {
876
- const o = {};
877
- return n && lt.forEach((r) => {
878
- typeof e[r] < "u" && r !== "id" && (o[r] = e[r]);
879
- }), t.filter((r) => r.name.match(/^data-trackable-context-/i)).forEach((r) => {
880
- o[r.name.replace("data-trackable-context-", "")] = ne(r.value);
881
- }), o;
882
- };
883
- function dt(t) {
884
- const e = document, n = t, o = n.getAttribute("data-trackable") ? `[data-trackable="${n.getAttribute("data-trackable")}"]` : n.nodeName, r = [], i = {};
885
- for (; t && t !== e; ) {
886
- const a = te(t), c = Array.from(t.attributes);
887
- let s = oe(c, a);
888
- s["data-trackable"] && (s = Object.assign(
889
- s,
890
- Zt(t, n, o)
891
- )), r.push(s);
892
- const u = re(c, a, t === n);
893
- _(u, i), t = t.parentNode;
894
- }
895
- return { trace: r, customContext: i };
106
+ function f(o) {
107
+ return typeof o == "string" ? o.trim() : o;
896
108
  }
897
- let J;
898
- const ie = [
899
- "ctrlKey",
900
- "altKey",
901
- "shiftKey",
902
- "metaKey"
903
- ], se = (t) => {
904
- const e = {};
905
- for (const n of ie)
906
- if (t[n])
907
- try {
908
- e[n] = R(t[n]);
909
- } catch (o) {
910
- console.log(o);
911
- }
912
- return e;
913
- }, ae = (t) => (e, n) => {
914
- if (n.getAttribute("data-o-tracking-do-not-track") === "true")
915
- return;
916
- const o = se(e), { trace: r, customContext: i } = dt(n);
917
- o.domPathTokens = r, o.url = window.document.location.href || null, o.source_id = x.getRootID(), _(i, o), t.context = o;
918
- const a = m(h("config"), t);
919
- x.track(a);
920
- }, ce = (t, e) => {
921
- e = e || 'a, button, input, [role="button"]';
922
- const n = {
923
- action: "click",
924
- category: t || "o-tracking"
925
- };
926
- J = J || new E(document.body), J.on("click", e, ae(n), !0);
927
- const o = new b("clicks");
928
- ht(o);
929
- };
930
- function ht(t) {
931
- const e = t.shift();
932
- e && x.track(e, () => ht(t));
933
- }
934
- const ue = {
935
- init: ce
936
- }, fe = [
937
- "componentContentId",
938
- "type",
939
- "subtype",
940
- "component"
941
- ], le = (t, e, n) => {
942
- const { trace: o, customContext: r } = dt(e);
943
- let i;
944
- if (n.getContextData) {
945
- if (typeof n.getContextData != "function")
946
- throw new Error("opts.getContextData is not a function");
947
- const a = n.getContextData(e);
948
- if (typeof a != "object")
949
- throw new Error("opts.getContextData function should return {object}");
950
- i = At(a, fe);
951
- } else
952
- i = {};
953
- i.domPathTokens = o, i.url = window.document.location.href || null, _(r, i), t.context = i;
954
- }, de = (t = {}) => {
955
- if (!window.IntersectionObserver) {
956
- console.warn('o-tracking: Unable to track component view events as "window.IntersectionObserver" is not supported.');
957
- return;
958
- }
959
- const e = t.selector || "[data-o-tracking-view]", n = [...document.querySelectorAll(e)];
960
- if (!n.length)
961
- return;
962
- function o(i) {
963
- i.forEach((a) => {
964
- if (a.isIntersecting || a.intersectionRatio > 0) {
965
- const c = {
966
- action: t.action || "view",
967
- category: t.category || "component"
968
- }, s = a.target;
969
- le(c, s, t), x.track(c), r.unobserve(s);
970
- }
971
- });
972
- }
973
- const r = new IntersectionObserver(o, { threshold: [1] });
974
- n.forEach((i) => r.observe(i));
975
- }, he = {
976
- init: de
977
- }, pe = M.init, me = T.init, W = "4.5.4", pt = "o-tracking";
978
- function mt(t) {
979
- let e = h("config") || {};
980
- e = m(e, t), C("config", e), e.user && e.user.user_id && it(e.user.user_id);
981
- }
982
- function ge() {
983
- k.initialised = !1, Q("config"), Q("page_sent");
984
- }
985
- function ye() {
986
- return "oTracking version " + W;
987
- }
988
- function we(t = {}) {
989
- if (k.initialised)
990
- return k;
991
- if (!!gt() && (t = be(t)), Object.keys(t).length === 0 && t.constructor === Object)
992
- return null;
993
- C("version", W), C("source", pt), C("page_sent", !1);
994
- const n = t ? t.cookieDomain : "";
995
- return Pt("", n), mt(t), It(t.session), jt(), pe(), me(), k.initialised = !0, k;
996
- }
997
- function gt() {
998
- return document.querySelector("script[data-o-tracking-config]");
109
+ function g(o, t) {
110
+ for (const e in o)
111
+ t[e] ? console.warn(`You can't set a custom property called ${e}`) : t[e] = o[e];
999
112
  }
1000
- function be(t) {
1001
- const e = gt();
1002
- let n;
1003
- if (e)
1004
- n = e.textContent || e.innerText || e.innerHTML;
1005
- else
1006
- return !1;
1007
- try {
1008
- const o = JSON.parse(n);
1009
- Object.assign(t, o);
1010
- } catch (o) {
1011
- const r = new Error('Invalid JSON configuration syntax, check validity for o-tracking configuration: "' + o.message + '"');
1012
- throw v("oErrors", "log", {
1013
- error: r.message,
1014
- info: { module: "o-tracking" }
1015
- }), r;
1016
- }
1017
- return t;
1018
- }
1019
- const k = {
1020
- /**
1021
- * The initialised state of the object.
1022
- *
1023
- * @type {boolean}
1024
- */
1025
- initialised: !1,
1026
- version: W,
1027
- updateConfig: mt,
1028
- source: pt,
1029
- destroy: ge,
1030
- toString: ye,
1031
- init: we,
1032
- click: ue,
1033
- event: M,
1034
- page: T,
1035
- view: he,
1036
- getRootID: x.getRootID
1037
- };
1038
- function yt() {
1039
- k.init(), document.removeEventListener("o.DOMContentLoaded", yt);
1040
- }
1041
- typeof document < "u" && document.addEventListener("o.DOMContentLoaded", yt);
1042
- const Ee = (t, e, n) => {
1043
- const o = Array.from(t.querySelectorAll(n)), r = o.findIndex((i) => i === e);
1044
- if (r !== -1)
113
+ const v = (o, t, e) => {
114
+ const n = Array.from(o.querySelectorAll(e)), s = n.findIndex((r) => r === t);
115
+ if (s !== -1)
1045
116
  return {
1046
- siblings: o.length,
1047
- position: r
117
+ siblings: n.length,
118
+ position: s
1048
119
  };
1049
- }, wt = [
120
+ }, b = [
1050
121
  "nodeName",
1051
122
  "className",
1052
123
  "id",
1053
124
  "href",
1054
125
  "text",
1055
126
  "role"
1056
- ], ve = (t) => {
1057
- const e = {};
1058
- for (const n of wt) {
1059
- const o = t[n] || t.getAttribute(n) || t.hasAttribute(n);
1060
- o !== void 0 && (typeof o == "boolean" ? e[n] = o : e[n] = R(o));
127
+ ], k = (o) => {
128
+ const t = {};
129
+ for (const e of b) {
130
+ const n = o[e] || o.getAttribute(e) || o.hasAttribute(e);
131
+ n !== void 0 && (typeof n == "boolean" ? t[e] = n : t[e] = f(n));
1061
132
  }
1062
- return e;
1063
- }, xe = (t) => {
133
+ return t;
134
+ }, A = (o) => {
1064
135
  try {
1065
- const e = JSON.parse(t), n = Object.prototype.toString.call(e);
1066
- return [n === "[object Object]" || n === "[object Array]", e];
136
+ const t = JSON.parse(o), e = Object.prototype.toString.call(t);
137
+ return [e === "[object Object]" || e === "[object Array]", t];
1067
138
  } catch {
1068
139
  return [!1, null];
1069
140
  }
1070
- }, ke = (t) => {
1071
- const [e, n] = xe(t);
1072
- return e ? n : t;
1073
- }, Oe = (t, e) => (t.filter(
1074
- (n) => n.name.match(/^data-trackable|^data-o-|^aria-/i)
1075
- ).forEach((n) => {
1076
- e[n.name] = n.value;
1077
- }), e), Ce = (t, e, n) => {
1078
- const o = {};
1079
- return n && wt.forEach((r) => {
1080
- typeof e[r] < "u" && r !== "id" && (o[r] = e[r]);
1081
- }), t.filter((r) => r.name.match(/^data-trackable-context-/i)).forEach((r) => {
1082
- o[r.name.replace("data-trackable-context-", "")] = ke(r.value);
1083
- }), o;
1084
- };
1085
- function Se(t, e) {
1086
- const n = t, o = n.getAttribute("data-trackable") ? `[data-trackable="${n.getAttribute("data-trackable")}"]` : n.nodeName, r = [], i = {};
1087
- for (; t && t !== e; ) {
1088
- const a = ve(t), c = Array.from(t.attributes);
1089
- let s = Oe(c, a);
1090
- s["data-trackable"] && (s = Object.assign(
1091
- s,
1092
- Ee(t, n, o)
1093
- )), r.push(s);
1094
- const u = Ce(c, a, t === n);
1095
- _(u, i), t = t.parentNode;
1096
- }
1097
- return { trace: r, customContext: i };
1098
- }
1099
- const Ae = ["ctrlKey", "altKey", "shiftKey", "metaKey"];
1100
- class Pe {
141
+ }, N = (o) => {
142
+ const [t, e] = A(o);
143
+ return t ? e : o;
144
+ }, P = (o, t) => (o.filter(
145
+ (e) => e.name.match(/^data-trackable|^data-o-|^aria-/i)
146
+ ).forEach((e) => {
147
+ t[e.name] = e.value;
148
+ }), t), $ = (o, t, e) => {
149
+ const n = {};
150
+ return e && b.forEach((s) => {
151
+ typeof t[s] < "u" && s !== "id" && (n[s] = t[s]);
152
+ }), o.filter((s) => s.name.match(/^data-trackable-context-/i)).forEach((s) => {
153
+ n[s.name.replace("data-trackable-context-", "")] = N(s.value);
154
+ }), n;
155
+ };
156
+ function x(o, t) {
157
+ const e = o, n = e.getAttribute("data-trackable") ? `[data-trackable="${e.getAttribute("data-trackable")}"]` : e.nodeName, s = [], r = {};
158
+ for (; o && o !== t; ) {
159
+ const c = k(o), i = Array.from(o.attributes);
160
+ let h = P(i, c);
161
+ h["data-trackable"] && (h = Object.assign(
162
+ h,
163
+ v(o, e, n)
164
+ )), s.push(h);
165
+ const a = $(i, c, o === e);
166
+ g(a, r), o = o.parentNode;
167
+ }
168
+ return { trace: s, customContext: r };
169
+ }
170
+ const C = ["ctrlKey", "altKey", "shiftKey", "metaKey"];
171
+ class L {
1101
172
  constructor({
1102
- id: e = "00000000-0000-0000-0000-000000000000",
1103
- name: n = "ccc-component",
1104
- subtype: o = "interactive",
1105
- teamName: r = "djd",
1106
- shadowRoot: i = null,
1107
- category: a = "cta",
1108
- elements: c = 'a, button, input, [role="button"]'
1109
- } = {}) {
1110
- this.cccId = e, this.cccName = n, this.subtype = o, this.teamName = r, this.shadowRoot = i, this.category = a, this.elements = c, this.isInitialised = !1;
173
+ id: t = "00000000-0000-0000-0000-000000000000",
174
+ name: e = "ccc-component",
175
+ subtype: n = "interactive",
176
+ teamName: s = "djd",
177
+ shadowRoot: r = null,
178
+ category: c = "cta",
179
+ elements: i = 'a, button, input, [role="button"]'
180
+ }) {
181
+ this.cccId = t, this.cccName = e, this.subtype = n, this.teamName = s, this.shadowRoot = r, this.category = c, this.elements = i, this.isInitialised = !1;
1111
182
  }
1112
183
  // Get properties for the event (as opposed to properties of the clicked element)
1113
- getEventProperties(e) {
1114
- const n = {};
1115
- for (const o of Ae)
1116
- if (e[o])
184
+ getEventProperties(t) {
185
+ const e = {};
186
+ for (const n of C)
187
+ if (t[n])
1117
188
  try {
1118
- n[o] = R(e[o]);
1119
- } catch (r) {
1120
- console.log(r);
189
+ e[n] = f(t[n]);
190
+ } catch (s) {
191
+ console.log(s);
1121
192
  }
1122
- return n;
193
+ return e;
1123
194
  }
1124
195
  // Controller for handling click events
1125
- handleClickEvent(e, n) {
1126
- return (o, r) => {
1127
- const i = this.getEventProperties(o), { trace: a, customContext: c } = Se(r, n);
1128
- i.custom = r.dataset && r.dataset.custom ? JSON.parse(r.dataset.custom) : null, i.domPathTokens = a, i.component = {
196
+ handleClickEvent(t, e) {
197
+ return (n, s) => {
198
+ const r = this.getEventProperties(n), { trace: c, customContext: i } = x(s, e);
199
+ r.custom = s.dataset && s.dataset.custom ? JSON.parse(s.dataset.custom) : null, r.domPathTokens = c, r.component = {
1129
200
  id: this.cccId,
1130
201
  name: this.cccName,
1131
202
  type: "custom-code-component",
1132
203
  subtype: this.subtype
1133
- }, i.teamName = this.teamName, _(c, i), e.context = i, e.method = "ftCustomAnalytics", document.body.dispatchEvent(
204
+ }, r.teamName = this.teamName, g(i, r), t.context = r, t.method = "ftCustomAnalytics", document.body.dispatchEvent(
1134
205
  new CustomEvent("oTracking.event", {
1135
- detail: e,
206
+ detail: t,
1136
207
  bubbles: !0,
1137
208
  composed: !0
1138
209
  })
1139
210
  );
1140
211
  };
1141
212
  }
1142
- sendSpoorEvent(e, n) {
1143
- const o = {
213
+ sendSpoorEvent(t, e) {
214
+ const n = {
1144
215
  category: "component",
1145
216
  action: "act",
1146
217
  context: {
@@ -1151,37 +222,37 @@ class Pe {
1151
222
  subtype: this.subtype
1152
223
  },
1153
224
  teamName: this.teamName,
1154
- trigger_action: e,
1155
- custom: n
225
+ trigger_action: t,
226
+ custom: e
1156
227
  },
1157
228
  method: "ftCustomAnalytics"
1158
229
  };
1159
230
  document.body.dispatchEvent(
1160
231
  new CustomEvent("oTracking.event", {
1161
- detail: o,
232
+ detail: n,
1162
233
  bubbles: !0,
1163
234
  composed: !0
1164
235
  })
1165
236
  );
1166
237
  }
1167
- init(e) {
1168
- var n;
238
+ init(t) {
239
+ var e;
1169
240
  if (!this.isInitialised) {
1170
- this.isInitialised = !0, this.cccId = e || this.cccId, k.init({ queue: !0 });
1171
- const o = {
241
+ this.isInitialised = !0, this.cccId = t || this.cccId;
242
+ const n = {
1172
243
  action: "click",
1173
244
  category: this.category
1174
- }, r = (n = this.shadowRoot) == null ? void 0 : n.querySelector("#component-root");
1175
- this.shadowRoot && new w(r).on(
245
+ }, s = (e = this.shadowRoot) == null ? void 0 : e.querySelector("[data-component-root]");
246
+ this.shadowRoot && new u(s).on(
1176
247
  "click",
1177
248
  this.elements,
1178
- this.handleClickEvent(o, r),
249
+ this.handleClickEvent(n, s),
1179
250
  !0
1180
251
  );
1181
252
  }
1182
253
  }
1183
254
  }
1184
- class _e extends HTMLElement {
255
+ class M extends HTMLElement {
1185
256
  constructor() {
1186
257
  super(...arguments), this.RESERVED_ATTRS = /* @__PURE__ */ new Set([
1187
258
  "iframe",
@@ -1192,75 +263,74 @@ class _e extends HTMLElement {
1192
263
  "shadow-open",
1193
264
  "env",
1194
265
  "load-timeout"
1195
- ]), this.unmount = (e) => {
266
+ ]), this.unmount = (t) => {
1196
267
  }, this.channel = new MessageChannel();
1197
268
  }
1198
269
  async mount() {
1199
- var c;
1200
270
  if (!this.app)
1201
271
  throw new Error("CCC mounted without App");
1202
- const e = this.shadowRoot ?? this.attachShadow({ mode: this.mode }), n = this.app, o = JSON.parse(this.getAttribute("data-component-props")), r = Object.fromEntries(
1203
- [...this.attributes].filter((s) => !this.RESERVED_ATTRS.has(s.name)).map((s) => [s.name, s.value])
272
+ const t = this.shadowRoot ?? this.attachShadow({ mode: this.mode }), e = this.app, n = JSON.parse(this.getAttribute("data-component-props")), s = Object.fromEntries(
273
+ [...this.attributes].filter((i) => !this.RESERVED_ATTRS.has(i.name)).map((i) => [i.name, i.value])
1204
274
  );
1205
- (c = this.shadowRoot) == null || c.replaceChildren(), this.tracking = new Pe({
275
+ this.tracking = new L({
1206
276
  name: `${this.getAttribute("path")}@${this.getAttribute("version")}`,
1207
277
  subtype: "interactive",
1208
278
  teamName: "djd",
1209
279
  shadowRoot: this.shadowRoot
1210
280
  });
1211
- const { unmount: i, onmessage: a } = n(
1212
- e,
281
+ const { unmount: r, onmessage: c } = e(
282
+ t,
1213
283
  {
1214
- ...r,
1215
- data: o,
284
+ ...s,
285
+ data: n,
1216
286
  port: this.channel.port2,
1217
287
  tracking: this.tracking
1218
288
  },
1219
289
  ...this.children
1220
290
  ) || {};
1221
- i && (this.unmount = i), a && (this.onmessage = a);
291
+ r && (this.unmount = r), c && (this.onmessage = c);
1222
292
  }
1223
293
  async connectedCallback() {
1224
- var s;
1225
- const e = this.getAttribute("path"), n = this.getAttribute("version"), o = this.getAttribute("load-timeout") ?? 2e3, r = (s = this.getAttribute("env")) == null ? void 0 : s.toLowerCase().startsWith("d");
1226
- if (!e)
294
+ var h;
295
+ const t = this.getAttribute("path"), e = this.getAttribute("version"), n = this.getAttribute("load-timeout") ?? 2e3, s = (h = this.getAttribute("env")) == null ? void 0 : h.toLowerCase().startsWith("d");
296
+ if (!t)
1227
297
  throw new Error(
1228
298
  "path attribute not specified in <custom-code-component>"
1229
299
  );
1230
- const [i, a, c] = e.split("/").reverse();
1231
- if (!(!i || !a || !c)) {
1232
- this.source = r ? `http://localhost:5173/src/${i}/index.jsx` : `https://www.ft.com/__component/${c}/${a}${n ? `@${n}` : "@latest"}/${i}/${i}.js`;
300
+ const [r, c, i] = t.split("/").reverse();
301
+ if (!(!r || !c || !i)) {
302
+ this.source = s ? `http://localhost:5173/src/${r}/index.jsx` : `https://www.ft.com/__component/${i}/${c}${e ? `@${e}` : "@latest"}/${r}/${r}.js`;
1233
303
  try {
1234
- this.app = await new Promise((u, l) => {
1235
- const f = setTimeout(() => {
304
+ this.app = await new Promise((a, m) => {
305
+ const l = setTimeout(() => {
1236
306
  this.dispatchEvent(
1237
307
  new CustomEvent("ccc-timeout", {
1238
308
  bubbles: !0,
1239
309
  cancelable: !0,
1240
310
  detail: {
1241
- component: `${e}@${n}`,
311
+ component: `${t}@${e}`,
1242
312
  source: this.source
1243
313
  }
1244
314
  })
1245
315
  ), this.dataset.cccError = "import-timeout", delete this.dataset.cccReady;
1246
- }, Number(o));
316
+ }, Number(n));
1247
317
  import(
1248
318
  /* webpackIgnore: true */
1249
319
  this.source
1250
320
  /* @vite-ignore */
1251
321
  ).then(({ default: d }) => {
1252
322
  if (d)
1253
- clearTimeout(f), u(d);
323
+ clearTimeout(l), a(d);
1254
324
  else
1255
- throw new D(
325
+ throw new p(
1256
326
  "No component renderer default export found"
1257
327
  );
1258
- }).catch((d) => l(new D(d)));
328
+ }).catch((d) => m(new p(d)));
1259
329
  });
1260
- } catch (u) {
330
+ } catch (a) {
1261
331
  console.error(
1262
- `<custom-code-component> error during import from ${e}@${n}`
1263
- ), delete this.dataset.cccReady, this.dataset.cccError = "import-failure", this.dispatchEvent(new ErrorEvent("error", u)), console.error(u);
332
+ `<custom-code-component> error during import from ${t}@${e}`
333
+ ), delete this.dataset.cccReady, this.dataset.cccError = "import-failure", this.dispatchEvent(new ErrorEvent("error", a)), console.error(a);
1264
334
  return;
1265
335
  }
1266
336
  try {
@@ -1269,43 +339,43 @@ class _e extends HTMLElement {
1269
339
  bubbles: !0,
1270
340
  cancelable: !0,
1271
341
  detail: {
1272
- component: `${e}@${n}`,
342
+ component: `${t}@${e}`,
1273
343
  source: this.source
1274
344
  }
1275
345
  })
1276
346
  ), this.dataset.cccReady = "true", delete this.dataset.cccError;
1277
- } catch (u) {
347
+ } catch (a) {
1278
348
  console.info(
1279
- `<custom-code-component> uncaught error during mount from ${e}@${n}`
1280
- ), console.error(u), this.dispatchEvent(new ErrorEvent("error", u)), this.dataset.cccError = "mount-error", delete this.dataset.cccReady;
349
+ `<custom-code-component> uncaught error during mount from ${t}@${e}`
350
+ ), console.error(a), this.dispatchEvent(new ErrorEvent("error", a)), this.dataset.cccError = "mount-error", delete this.dataset.cccReady;
1281
351
  }
1282
352
  try {
1283
353
  this.tracking.init(this.id);
1284
- } catch (u) {
354
+ } catch (a) {
1285
355
  console.info(
1286
- `Error initialising tracking on <custom-code-component> ${e}@${n}`
1287
- ), console.error(u);
356
+ `Error initialising tracking on <custom-code-component> ${t}@${e}`
357
+ ), console.error(a);
1288
358
  }
1289
359
  }
1290
360
  }
1291
361
  disconnectedCallback() {
1292
- const e = this.getAttribute("path");
1293
- console.info(`<custom-code-component:${e}> disconnected`), typeof this.unmount == "function" && this.unmount();
362
+ const t = this.getAttribute("path");
363
+ console.info(`<custom-code-component:${t}> disconnected`), typeof this.unmount == "function" && this.unmount();
1294
364
  }
1295
365
  onmessage() {
1296
366
  }
1297
367
  // I'm honestly not sure what to do with this
1298
- postMessage(e) {
1299
- this.channel.port1.postMessage(e);
368
+ postMessage(t) {
369
+ this.channel.port1.postMessage(t);
1300
370
  }
1301
371
  }
1302
- const Ne = () => customElements.define("custom-code-component", _e);
1303
- customElements && !customElements.get("custom-code-component") && Ne();
1304
- class D extends Error {
1305
- constructor(...e) {
1306
- super(...e), Error.captureStackTrace && Error.captureStackTrace(this, D), this.name = "CCCImportError";
372
+ const O = () => customElements.define("custom-code-component", M);
373
+ customElements && !customElements.get("custom-code-component") && O();
374
+ class p extends Error {
375
+ constructor(...t) {
376
+ super(...t), Error.captureStackTrace && Error.captureStackTrace(this, p), this.name = "CCCImportError";
1307
377
  }
1308
378
  }
1309
379
  export {
1310
- Ne as init
380
+ O as init
1311
381
  };