@financial-times/custom-code-component 2.0.16 → 2.0.18
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/custom-element.d.ts +5 -3
- package/dist/custom-element.js +60 -58
- package/dist/custom-element.js.map +1 -1
- package/package.json +1 -1
- package/src/custom-code-component.ts +40 -40
- package/src/logger.ts +13 -5
package/dist/custom-element.d.ts
CHANGED
|
@@ -68,9 +68,9 @@ declare class FTCustomCodeComponent extends HTMLElement {
|
|
|
68
68
|
*/
|
|
69
69
|
component: ComponentPath;
|
|
70
70
|
/**
|
|
71
|
-
* Logger instance. Set log level using `this.
|
|
71
|
+
* Logger instance. Set log level using `this.logger.setLogLevel(string|number|null)`.
|
|
72
72
|
*/
|
|
73
|
-
|
|
73
|
+
logger: Logger;
|
|
74
74
|
/**
|
|
75
75
|
* IntersectionObserver that dispatches CCCViewportEvents
|
|
76
76
|
*/
|
|
@@ -185,8 +185,10 @@ export { FTCustomCodeComponent }
|
|
|
185
185
|
|
|
186
186
|
declare class Logger {
|
|
187
187
|
level: number;
|
|
188
|
-
|
|
188
|
+
component?: ComponentPath;
|
|
189
|
+
constructor({ level, component, }?: {
|
|
189
190
|
level: number;
|
|
191
|
+
component?: ComponentPath;
|
|
190
192
|
});
|
|
191
193
|
debug(...args: any[]): void;
|
|
192
194
|
log: (...args: any[]) => void;
|
package/dist/custom-element.js
CHANGED
|
@@ -123,22 +123,25 @@ function S(o) {
|
|
|
123
123
|
return t === "debug" ? p.DEBUG : t === "info" ? p.INFO : t === "warn" ? p.WARN : t === "error" ? p.ERROR : t === "test" ? p.TEST : p.DEFAULT;
|
|
124
124
|
}
|
|
125
125
|
class P {
|
|
126
|
-
constructor({
|
|
126
|
+
constructor({
|
|
127
|
+
level: t = p.DEFAULT,
|
|
128
|
+
component: e
|
|
129
|
+
} = {
|
|
127
130
|
level: p.DEFAULT
|
|
128
131
|
}) {
|
|
129
|
-
this.log = this.debug, this.level = localStorage.getItem("CCC_LOG_LEVEL") ? S(localStorage.getItem("CCC_LOG_LEVEL")) : t;
|
|
132
|
+
this.log = this.debug, this.level = localStorage.getItem("CCC_LOG_LEVEL") ? S(localStorage.getItem("CCC_LOG_LEVEL")) : t, this.component = e;
|
|
130
133
|
}
|
|
131
134
|
debug(...t) {
|
|
132
|
-
this.level <= p.DEBUG && console.info(b, ...t);
|
|
135
|
+
this.level <= p.DEBUG && console.info(b, ...t, this.component);
|
|
133
136
|
}
|
|
134
137
|
info(...t) {
|
|
135
|
-
this.level <= p.INFO && console.info(b, ...t);
|
|
138
|
+
this.level <= p.INFO && console.info(b, ...t, this.component);
|
|
136
139
|
}
|
|
137
140
|
warn(...t) {
|
|
138
|
-
this.level <= p.WARN && console.warn(b, ...t);
|
|
141
|
+
this.level <= p.WARN && console.warn(b, ...t, this.component);
|
|
139
142
|
}
|
|
140
143
|
error(...t) {
|
|
141
|
-
this.level <= p.ERROR && console.error(b, ...t);
|
|
144
|
+
this.level <= p.ERROR && console.error(b, ...t, this.component);
|
|
142
145
|
}
|
|
143
146
|
setLogLevel(t) {
|
|
144
147
|
localStorage.getItem("CCC_LOG_LEVEL") ? this.level = S(localStorage.getItem("CCC_LOG_LEVEL")) : typeof t == "number" ? this.level = t : this.level = S(t);
|
|
@@ -285,14 +288,14 @@ class G {
|
|
|
285
288
|
}
|
|
286
289
|
}
|
|
287
290
|
}
|
|
288
|
-
class
|
|
291
|
+
class g {
|
|
289
292
|
constructor(t) {
|
|
290
293
|
this.org = "local", this.repo = "dev";
|
|
291
|
-
const { org: e, repo: n, name: r, versionRange: s } = L(t) ? t :
|
|
294
|
+
const { org: e, repo: n, name: r, versionRange: s } = L(t) ? t : g.fromString(t);
|
|
292
295
|
e && (this.org = e), n && (this.repo = n), this.name = r, this.versionRange = s;
|
|
293
296
|
}
|
|
294
297
|
set path(t) {
|
|
295
|
-
const { org: e, repo: n, name: r, versionRange: s } = L(t) ? t :
|
|
298
|
+
const { org: e, repo: n, name: r, versionRange: s } = L(t) ? t : g.fromString(t);
|
|
296
299
|
this.org = e, this.repo = n, this.name = r, this.versionRange = s;
|
|
297
300
|
}
|
|
298
301
|
get path() {
|
|
@@ -309,36 +312,36 @@ class d {
|
|
|
309
312
|
static fromString(t, e) {
|
|
310
313
|
var a;
|
|
311
314
|
const n = t ?? "unknown/unknown/unknown", [r, s, i] = n.replace(/@[^\/]+/, "").split("/").reverse(), c = e ?? ((a = n.match(/@[^\/]+/)) == null ? void 0 : a.toString().replace("@", "")) ?? "unknown";
|
|
312
|
-
if (s && !c) throw new
|
|
313
|
-
return new
|
|
315
|
+
if (s && !c) throw new d("No version specified");
|
|
316
|
+
return new g({ org: i, repo: s, name: r, versionRange: c });
|
|
314
317
|
}
|
|
315
318
|
}
|
|
316
319
|
function L(o) {
|
|
317
320
|
return typeof o == "object" && o !== null ? "org" in o && "repo" in o && "name" in o : !1;
|
|
318
321
|
}
|
|
319
|
-
class
|
|
322
|
+
class d extends Error {
|
|
320
323
|
constructor(t, e) {
|
|
321
324
|
var n;
|
|
322
325
|
!e && t ? (super(t), this.component = null) : typeof (e == null ? void 0 : e.component) == "string" ? (super(
|
|
323
326
|
t ?? `${e.cause ?? "Unknown error"} in ${e.component} imported from ${e.source ?? "an undefined source"}.`
|
|
324
|
-
), this.component =
|
|
327
|
+
), this.component = g.fromString(e.component)) : L(e == null ? void 0 : e.component) ? (super(
|
|
325
328
|
t ?? `${e.cause ?? "Unknown error"} in ${e.component.org}/${e.component.repo}/${e.component.name}@${e.component.versionRange} imported from ${e.source ?? "an undefined source"}.`
|
|
326
|
-
), this.component = new
|
|
329
|
+
), this.component = new g(e.component)) : (super(
|
|
327
330
|
`${(e == null ? void 0 : e.cause) ?? "Unknown error"} in unknown component imported from ${(e == null ? void 0 : e.source) ?? "unknown source"}.`
|
|
328
|
-
), this.component = null), this.source = (e == null ? void 0 : e.source) ?? "unknown source", this.errors = [], e != null && e.error && ((n = this.errors) == null || n.push(e == null ? void 0 : e.error)), Error.captureStackTrace && Error.captureStackTrace(this,
|
|
331
|
+
), this.component = null), this.source = (e == null ? void 0 : e.source) ?? "unknown source", this.errors = [], e != null && e.error && ((n = this.errors) == null || n.push(e == null ? void 0 : e.error)), Error.captureStackTrace && Error.captureStackTrace(this, d), this.name = "CCCError";
|
|
329
332
|
}
|
|
330
333
|
}
|
|
331
|
-
class w extends
|
|
334
|
+
class w extends d {
|
|
332
335
|
constructor(t, e) {
|
|
333
336
|
super(t, { ...e, cause: "Import error" }), this.name = "CCCImportError";
|
|
334
337
|
}
|
|
335
338
|
}
|
|
336
|
-
class O extends
|
|
339
|
+
class O extends d {
|
|
337
340
|
constructor(t, e) {
|
|
338
341
|
super(t, { ...e, cause: "Render error" }), this.name = "CCCRenderError";
|
|
339
342
|
}
|
|
340
343
|
}
|
|
341
|
-
class J extends
|
|
344
|
+
class J extends d {
|
|
342
345
|
constructor(t) {
|
|
343
346
|
super(null, { ...t, cause: "Timeout error" }), this.name = "CCCTimeoutError";
|
|
344
347
|
}
|
|
@@ -354,22 +357,22 @@ const E = class E extends Event {
|
|
|
354
357
|
}
|
|
355
358
|
};
|
|
356
359
|
E.eventType = "ccc:event";
|
|
357
|
-
let
|
|
358
|
-
const y = class y extends
|
|
360
|
+
let f = E;
|
|
361
|
+
const y = class y extends f {
|
|
359
362
|
constructor(t, e) {
|
|
360
363
|
super(y.eventType, t, e);
|
|
361
364
|
}
|
|
362
365
|
};
|
|
363
366
|
y.eventType = "ccc:connected";
|
|
364
367
|
let T = y;
|
|
365
|
-
const v = class v extends
|
|
368
|
+
const v = class v extends f {
|
|
366
369
|
constructor(t, e) {
|
|
367
370
|
super(v.eventType, t, e);
|
|
368
371
|
}
|
|
369
372
|
};
|
|
370
373
|
v.eventType = "ccc:ready";
|
|
371
374
|
let k = v;
|
|
372
|
-
const C = class C extends
|
|
375
|
+
const C = class C extends f {
|
|
373
376
|
constructor(t, e) {
|
|
374
377
|
super(C.eventType, t, e), this.intersecting = !1, this.intersecting = t.intersecting, this.entry = t.entry;
|
|
375
378
|
}
|
|
@@ -446,8 +449,8 @@ class et extends HTMLElement {
|
|
|
446
449
|
"shadow-open",
|
|
447
450
|
"env",
|
|
448
451
|
"load-timeout"
|
|
449
|
-
]), this.component = new
|
|
450
|
-
this.
|
|
452
|
+
]), this.component = new g(), this.observer = new IntersectionObserver((e) => {
|
|
453
|
+
this.logger.debug("Intersection Observer callback", { entries: e }), e.forEach((n) => {
|
|
451
454
|
this.dispatchEvent(
|
|
452
455
|
new R({
|
|
453
456
|
component: this.component,
|
|
@@ -459,14 +462,14 @@ class et extends HTMLElement {
|
|
|
459
462
|
});
|
|
460
463
|
}), this.channel = new MessageChannel(), this.initTracking = async () => {
|
|
461
464
|
var e;
|
|
462
|
-
this.
|
|
465
|
+
this.logger.debug("initTracking", { cccId: this.id });
|
|
463
466
|
try {
|
|
464
467
|
(e = this.tracking) == null || e.init(this.id);
|
|
465
468
|
} catch (n) {
|
|
466
469
|
const r = this.getAttribute("path"), s = this.getAttribute("version");
|
|
467
|
-
this.
|
|
470
|
+
this.logger.info(
|
|
468
471
|
`Error initialising tracking on <custom-code-component> ${r}@${s}`
|
|
469
|
-
), this.
|
|
472
|
+
), this.logger.error(n);
|
|
470
473
|
}
|
|
471
474
|
}, this.injectViteScripts = () => {
|
|
472
475
|
var r, s;
|
|
@@ -481,12 +484,12 @@ class et extends HTMLElement {
|
|
|
481
484
|
`.trim(), document.head.appendChild(e);
|
|
482
485
|
const n = document.createElement("script");
|
|
483
486
|
n.type = "module", n.src = `${(s = this.testUrl) == null ? void 0 : s.origin}/@vite/client`, document.head.appendChild(n);
|
|
484
|
-
}, this.
|
|
487
|
+
}, this.logger = new P();
|
|
485
488
|
const t = HTMLElement.prototype.hasOwnProperty("attachInternals");
|
|
486
489
|
try {
|
|
487
490
|
const e = t && this.attachInternals();
|
|
488
491
|
} catch (e) {
|
|
489
|
-
this.
|
|
492
|
+
this.logger.error(e);
|
|
490
493
|
}
|
|
491
494
|
}
|
|
492
495
|
/**
|
|
@@ -496,9 +499,8 @@ class et extends HTMLElement {
|
|
|
496
499
|
*/
|
|
497
500
|
async connectedCallback() {
|
|
498
501
|
try {
|
|
499
|
-
this.log.setLogLevel(this.getAttribute("log")), this.log.debug("connectedCallback");
|
|
500
502
|
const t = this.getAttribute("path"), e = this.getAttribute("version");
|
|
501
|
-
this.component =
|
|
503
|
+
this.component = g.fromString(t, e), this.logger.component = this.component, this.logger.setLogLevel(this.getAttribute("log")), this.logger.debug("connectedCallback"), this.app = await this.load(), await this.mount(), await this.initTracking();
|
|
502
504
|
} catch (t) {
|
|
503
505
|
t instanceof Error && requestAnimationFrame(() => {
|
|
504
506
|
this.emitError(t);
|
|
@@ -511,7 +513,7 @@ class et extends HTMLElement {
|
|
|
511
513
|
* @param error
|
|
512
514
|
*/
|
|
513
515
|
emitError(t) {
|
|
514
|
-
if (this.
|
|
516
|
+
if (this.logger.debug("emitError", { error: t }), t instanceof d)
|
|
515
517
|
this.dispatchEvent(
|
|
516
518
|
new ErrorEvent("ccc:error", {
|
|
517
519
|
bubbles: !0,
|
|
@@ -522,7 +524,7 @@ class et extends HTMLElement {
|
|
|
522
524
|
})
|
|
523
525
|
);
|
|
524
526
|
else {
|
|
525
|
-
const e = new
|
|
527
|
+
const e = new d(t.message, {
|
|
526
528
|
component: this.component,
|
|
527
529
|
error: t
|
|
528
530
|
});
|
|
@@ -543,9 +545,9 @@ class et extends HTMLElement {
|
|
|
543
545
|
* Called when a <custom-code-component> element is removed from DOM.
|
|
544
546
|
*/
|
|
545
547
|
disconnectedCallback() {
|
|
546
|
-
this.
|
|
548
|
+
this.logger.debug("disconnectedCallback");
|
|
547
549
|
const t = this.getAttribute("path");
|
|
548
|
-
this.
|
|
550
|
+
this.logger.info(`<custom-code-component:${t}> disconnected`), this.observer.disconnect();
|
|
549
551
|
}
|
|
550
552
|
/**
|
|
551
553
|
* MessageChannel postMessage callback
|
|
@@ -553,7 +555,7 @@ class et extends HTMLElement {
|
|
|
553
555
|
* @param e
|
|
554
556
|
*/
|
|
555
557
|
onmessage(t) {
|
|
556
|
-
this.
|
|
558
|
+
this.logger.debug("onmessage", { event: t });
|
|
557
559
|
}
|
|
558
560
|
/**
|
|
559
561
|
* This error handler is called by the child component on e.g. unrecoverable error.
|
|
@@ -562,7 +564,7 @@ class et extends HTMLElement {
|
|
|
562
564
|
* @param e
|
|
563
565
|
*/
|
|
564
566
|
onunmount(t) {
|
|
565
|
-
if (this.
|
|
567
|
+
if (this.logger.debug("onunmount", { error: t }), t instanceof Error) {
|
|
566
568
|
const e = new O(t.message, {
|
|
567
569
|
error: t,
|
|
568
570
|
component: this.component
|
|
@@ -580,14 +582,14 @@ class et extends HTMLElement {
|
|
|
580
582
|
*/
|
|
581
583
|
async onready(t) {
|
|
582
584
|
try {
|
|
583
|
-
await t, this.
|
|
585
|
+
await t, this.logger.debug("onready", { app: t }), this.dispatchEvent(
|
|
584
586
|
new k({
|
|
585
587
|
component: this.component,
|
|
586
588
|
source: this.source
|
|
587
589
|
})
|
|
588
590
|
), this.dataset.cccReady = "true", delete this.dataset.cccError, this.observer.observe(this);
|
|
589
591
|
} catch (e) {
|
|
590
|
-
if (this.
|
|
592
|
+
if (this.logger.debug("onready caught error", { error: e }), e instanceof Error) {
|
|
591
593
|
const n = new O(e.message, {
|
|
592
594
|
error: e,
|
|
593
595
|
component: this.component
|
|
@@ -604,7 +606,7 @@ class et extends HTMLElement {
|
|
|
604
606
|
* @param event
|
|
605
607
|
*/
|
|
606
608
|
postMessage(t) {
|
|
607
|
-
this.
|
|
609
|
+
this.logger.debug("postmessage", { event: t }), this.channel.port1.postMessage(t);
|
|
608
610
|
}
|
|
609
611
|
/**
|
|
610
612
|
* Initial mounting behaviour.
|
|
@@ -617,7 +619,7 @@ class et extends HTMLElement {
|
|
|
617
619
|
*/
|
|
618
620
|
async mount(t) {
|
|
619
621
|
var e, n;
|
|
620
|
-
this.
|
|
622
|
+
this.logger.debug("mount", t);
|
|
621
623
|
try {
|
|
622
624
|
if (this.mode = this.getAttribute("shadow-open") == "false" ? "closed" : "open", this.component) {
|
|
623
625
|
if (!this.app)
|
|
@@ -628,8 +630,8 @@ class et extends HTMLElement {
|
|
|
628
630
|
component: this.component,
|
|
629
631
|
source: this.source
|
|
630
632
|
})
|
|
631
|
-
), !s.querySelector('link[href~="custom-code-component.css"]') && !s.adoptedStyleSheets.length && (window.CCC_LAYOUT_STYLESHEET || (this.
|
|
632
|
-
this.
|
|
633
|
+
), !s.querySelector('link[href~="custom-code-component.css"]') && !s.adoptedStyleSheets.length && (window.CCC_LAYOUT_STYLESHEET || (this.logger.debug("mount generating CCC_LAYOUT_STYLESHEET"), window.CCC_LAYOUT_STYLESHEET = new CSSStyleSheet(), window.CCC_LAYOUT_STYLESHEET.replaceSync(tt)), s.adoptedStyleSheets = [window.CCC_LAYOUT_STYLESHEET]), !r) {
|
|
634
|
+
this.logger.debug("mount generating fallback template");
|
|
633
635
|
const l = document.createElement("template");
|
|
634
636
|
l.innerHTML = "<div data-component-root><slot></slot></div>", this.appendChild(l), s.appendChild(l.content.cloneNode(!0));
|
|
635
637
|
}
|
|
@@ -643,12 +645,12 @@ class et extends HTMLElement {
|
|
|
643
645
|
subtype: "interactive",
|
|
644
646
|
teamName: "djd",
|
|
645
647
|
shadowRoot: this.shadowRoot,
|
|
646
|
-
logger: this.
|
|
647
|
-
}), !i && Object.keys(c).length > 0 && (this.
|
|
648
|
+
logger: this.logger
|
|
649
|
+
}), !i && Object.keys(c).length > 0 && (this.logger.warn(
|
|
648
650
|
`CCC ${this.component.toString()}: passing component settings as webcomponent attributes is %cDEPRECATED`,
|
|
649
651
|
"font-weight: bold",
|
|
650
652
|
" and will be removed in v3."
|
|
651
|
-
), this.
|
|
653
|
+
), this.logger.warn(
|
|
652
654
|
"Please use the %cdata-component-props",
|
|
653
655
|
"text-decoration: underline;",
|
|
654
656
|
" attribute instead."
|
|
@@ -657,7 +659,7 @@ class et extends HTMLElement {
|
|
|
657
659
|
s,
|
|
658
660
|
{
|
|
659
661
|
...i ?? c,
|
|
660
|
-
log: this.
|
|
662
|
+
log: this.logger,
|
|
661
663
|
data: i ?? c,
|
|
662
664
|
port: this.channel.port2,
|
|
663
665
|
tracking: this.tracking,
|
|
@@ -670,9 +672,9 @@ class et extends HTMLElement {
|
|
|
670
672
|
a && (this.onmessage = a), this.onready(h);
|
|
671
673
|
}
|
|
672
674
|
} catch (r) {
|
|
673
|
-
throw this.
|
|
675
|
+
throw this.logger.info(
|
|
674
676
|
`<custom-code-component> uncaught error during mount from ${(n = this.component) == null ? void 0 : n.toString()}`
|
|
675
|
-
), this.
|
|
677
|
+
), this.logger.error(r), r;
|
|
676
678
|
}
|
|
677
679
|
}
|
|
678
680
|
/**
|
|
@@ -684,11 +686,11 @@ class et extends HTMLElement {
|
|
|
684
686
|
*/
|
|
685
687
|
unmount(t) {
|
|
686
688
|
var n;
|
|
687
|
-
this.
|
|
689
|
+
this.logger.debug("unmount", { error: t });
|
|
688
690
|
const e = this.querySelector(
|
|
689
691
|
"template[data-component-fallback]"
|
|
690
692
|
) ?? this.querySelector("template");
|
|
691
|
-
e && (this.
|
|
693
|
+
e && (this.logger.debug("unmount replacing shadowRoot with fallback"), (n = this.shadowRoot) == null || n.replaceChildren(e.content.cloneNode(!0))), this.dataset.cccError || (this.dataset.cccError = W(t.name.replace("CCC", ""))), delete this.dataset.cccReady, this.observer.disconnect();
|
|
692
694
|
}
|
|
693
695
|
/**
|
|
694
696
|
* Asynchronously loads the CCC child component.
|
|
@@ -697,7 +699,7 @@ class et extends HTMLElement {
|
|
|
697
699
|
*/
|
|
698
700
|
async load() {
|
|
699
701
|
var c;
|
|
700
|
-
if (this.
|
|
702
|
+
if (this.logger.debug("load"), !this.component.isValid)
|
|
701
703
|
throw new Error("No path found");
|
|
702
704
|
const t = this.getAttribute("path"), e = this.getAttribute("version"), n = Number(this.getAttribute("load-timeout") || 1e4), r = this.getAttribute("test-env");
|
|
703
705
|
this.testUrl = X(r);
|
|
@@ -705,12 +707,12 @@ class et extends HTMLElement {
|
|
|
705
707
|
this.component.name,
|
|
706
708
|
this.testUrl
|
|
707
709
|
), i = this.getAttribute("id");
|
|
708
|
-
s && this.testUrl && (this.
|
|
710
|
+
s && this.testUrl && (this.logger.debug("load adding Vite scripts"), this.injectViteScripts()), this.source = s ? `${(c = this.testUrl) == null ? void 0 : c.origin}/src/${this.component.name}/index.jsx?id=${i}` : `https://www.ft.com/__component/${this.component.org}/${this.component.repo}${e ? `@${e}` : "@latest"}/${this.component.name}/${this.component.name}.js?id=${i}`;
|
|
709
711
|
try {
|
|
710
712
|
return await new Promise(
|
|
711
713
|
(a, h) => {
|
|
712
714
|
const l = setTimeout(() => {
|
|
713
|
-
this.
|
|
715
|
+
this.logger.error("CCC import timeout error"), h(
|
|
714
716
|
new J({
|
|
715
717
|
component: this.component,
|
|
716
718
|
source: this.source
|
|
@@ -734,7 +736,7 @@ class et extends HTMLElement {
|
|
|
734
736
|
}
|
|
735
737
|
);
|
|
736
738
|
}).catch((u) => {
|
|
737
|
-
clearTimeout(l), this.
|
|
739
|
+
clearTimeout(l), this.logger.error(u), u instanceof Error && !(u instanceof w) ? h(
|
|
738
740
|
new w(u.message, {
|
|
739
741
|
component: this.component,
|
|
740
742
|
source: this.source
|
|
@@ -749,7 +751,7 @@ class et extends HTMLElement {
|
|
|
749
751
|
}
|
|
750
752
|
);
|
|
751
753
|
} catch (a) {
|
|
752
|
-
throw this.
|
|
754
|
+
throw this.logger.error(
|
|
753
755
|
`<custom-code-component> error during import from ${t}@${e}`
|
|
754
756
|
), a;
|
|
755
757
|
}
|
|
@@ -763,13 +765,13 @@ class et extends HTMLElement {
|
|
|
763
765
|
* @param newValue
|
|
764
766
|
*/
|
|
765
767
|
attributeChangedCallback(t, e, n) {
|
|
766
|
-
switch (this.
|
|
768
|
+
switch (this.logger.debug("attributeChangedCallback lifecycle method", {
|
|
767
769
|
name: t,
|
|
768
770
|
oldValue: e,
|
|
769
771
|
newValue: n
|
|
770
772
|
}), t) {
|
|
771
773
|
case "log":
|
|
772
|
-
this.
|
|
774
|
+
this.logger.setLogLevel(n);
|
|
773
775
|
}
|
|
774
776
|
}
|
|
775
777
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-element.js","sources":["../node_modules/ftdomdelegate/main.js","../../node_modules/@financial-times/o-tracking/src/javascript/utils.js","../src/logger.ts","../src/get-trace.ts","../src/tracking.ts","../src/path.ts","../src/errors.ts","../src/events.ts","../src/util.ts","../src/environment.ts","../src/custom-code-component.ts"],"sourcesContent":["/**\n * DOM event delegator\n *\n * The delegator will listen\n * for events that bubble up\n * to the root node.\n *\n * @constructor\n * @param {Node|string} [root] The root node or a selector string matching the root node\n */\nfunction Delegate(root) {\n\n\t/**\n\t * Maintain a map of listener\n\t * lists, keyed by event name.\n\t *\n\t * @type Object\n\t */\n\tthis.listenerMap = [{}, {}];\n\tif (root) {\n\t\tthis.root(root);\n\t}\n\n\t/** @type function() */\n\tthis.handle = Delegate.prototype.handle.bind(this);\n\n\t// Cache of event listeners removed during an event cycle\n\tthis._removedListeners = [];\n}\n\n/**\n * Start listening for events\n * on the provided DOM element\n *\n * @param {Node|string} [root] The root node or a selector string matching the root node\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.root = function (root) {\n\tconst listenerMap = this.listenerMap;\n\tlet eventType;\n\n\t// Remove master event listeners\n\tif (this.rootElement) {\n\t\tfor (eventType in listenerMap[1]) {\n\t\t\tif (listenerMap[1].hasOwnProperty(eventType)) {\n\t\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, true);\n\t\t\t}\n\t\t}\n\t\tfor (eventType in listenerMap[0]) {\n\t\t\tif (listenerMap[0].hasOwnProperty(eventType)) {\n\t\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, false);\n\t\t\t}\n\t\t}\n\t}\n\n\t// If no root or root is not\n\t// a dom node, then remove internal\n\t// root reference and exit here\n\tif (!root || !root.addEventListener) {\n\t\tif (this.rootElement) {\n\t\t\tdelete this.rootElement;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * The root node at which\n\t * listeners are attached.\n\t *\n\t * @type Node\n\t */\n\tthis.rootElement = root;\n\n\t// Set up master event listeners\n\tfor (eventType in listenerMap[1]) {\n\t\tif (listenerMap[1].hasOwnProperty(eventType)) {\n\t\t\tthis.rootElement.addEventListener(eventType, this.handle, true);\n\t\t}\n\t}\n\tfor (eventType in listenerMap[0]) {\n\t\tif (listenerMap[0].hasOwnProperty(eventType)) {\n\t\t\tthis.rootElement.addEventListener(eventType, this.handle, false);\n\t\t}\n\t}\n\n\treturn this;\n};\n\n/**\n * @param {string} eventType\n * @returns boolean\n */\nDelegate.prototype.captureForType = function (eventType) {\n\treturn ['blur', 'error', 'focus', 'load', 'resize', 'scroll'].indexOf(eventType) !== -1;\n};\n\n/**\n * Attach a handler to one\n * event for all elements\n * that match the selector,\n * now or in the future\n *\n * The handler function receives\n * three arguments: the DOM event\n * object, the node that matched\n * the selector while the event\n * was bubbling and a reference\n * to itself. Within the handler,\n * 'this' is equal to the second\n * argument.\n *\n * The node that actually received\n * the event can be accessed via\n * 'event.target'.\n *\n * @param {string} eventType Listen for these events\n * @param {string|undefined} selector Only handle events on elements matching this selector, if undefined match root element\n * @param {function()} handler Handler function - event data passed here will be in event.data\n * @param {boolean} [useCapture] see 'useCapture' in <https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener>\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.on = function (eventType, selector, handler, useCapture) {\n\tlet root;\n\tlet listenerMap;\n\tlet matcher;\n\tlet matcherParam;\n\n\tif (!eventType) {\n\t\tthrow new TypeError('Invalid event type: ' + eventType);\n\t}\n\n\t// handler can be passed as\n\t// the second or third argument\n\tif (typeof selector === 'function') {\n\t\tuseCapture = handler;\n\t\thandler = selector;\n\t\tselector = null;\n\t}\n\n\t// Fallback to sensible defaults\n\t// if useCapture not set\n\tif (useCapture === undefined) {\n\t\tuseCapture = this.captureForType(eventType);\n\t}\n\n\tif (typeof handler !== 'function') {\n\t\tthrow new TypeError('Handler must be a type of Function');\n\t}\n\n\troot = this.rootElement;\n\tlistenerMap = this.listenerMap[useCapture ? 1 : 0];\n\n\t// Add master handler for type if not created yet\n\tif (!listenerMap[eventType]) {\n\t\tif (root) {\n\t\t\troot.addEventListener(eventType, this.handle, useCapture);\n\t\t}\n\t\tlistenerMap[eventType] = [];\n\t}\n\n\tif (!selector) {\n\t\tmatcherParam = null;\n\n\t\t// COMPLEX - matchesRoot needs to have access to\n\t\t// this.rootElement, so bind the function to this.\n\t\tmatcher = matchesRoot.bind(this);\n\n\t\t// Compile a matcher for the given selector\n\t} else if (/^[a-z]+$/i.test(selector)) {\n\t\tmatcherParam = selector;\n\t\tmatcher = matchesTag;\n\t} else if (/^#[a-z0-9\\-_]+$/i.test(selector)) {\n\t\tmatcherParam = selector.slice(1);\n\t\tmatcher = matchesId;\n\t} else {\n\t\tmatcherParam = selector;\n\t\tmatcher = Element.prototype.matches;\n\t}\n\n\t// Add to the list of listeners\n\tlistenerMap[eventType].push({\n\t\tselector: selector,\n\t\thandler: handler,\n\t\tmatcher: matcher,\n\t\tmatcherParam: matcherParam\n\t});\n\n\treturn this;\n};\n\n/**\n * Remove an event handler\n * for elements that match\n * the selector, forever\n *\n * @param {string} [eventType] Remove handlers for events matching this type, considering the other parameters\n * @param {string} [selector] If this parameter is omitted, only handlers which match the other two will be removed\n * @param {function()} [handler] If this parameter is omitted, only handlers which match the previous two will be removed\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.off = function (eventType, selector, handler, useCapture) {\n\tlet i;\n\tlet listener;\n\tlet listenerMap;\n\tlet listenerList;\n\tlet singleEventType;\n\n\t// Handler can be passed as\n\t// the second or third argument\n\tif (typeof selector === 'function') {\n\t\tuseCapture = handler;\n\t\thandler = selector;\n\t\tselector = null;\n\t}\n\n\t// If useCapture not set, remove\n\t// all event listeners\n\tif (useCapture === undefined) {\n\t\tthis.off(eventType, selector, handler, true);\n\t\tthis.off(eventType, selector, handler, false);\n\t\treturn this;\n\t}\n\n\tlistenerMap = this.listenerMap[useCapture ? 1 : 0];\n\tif (!eventType) {\n\t\tfor (singleEventType in listenerMap) {\n\t\t\tif (listenerMap.hasOwnProperty(singleEventType)) {\n\t\t\t\tthis.off(singleEventType, selector, handler);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tlistenerList = listenerMap[eventType];\n\tif (!listenerList || !listenerList.length) {\n\t\treturn this;\n\t}\n\n\t// Remove only parameter matches\n\t// if specified\n\tfor (i = listenerList.length - 1; i >= 0; i--) {\n\t\tlistener = listenerList[i];\n\n\t\tif ((!selector || selector === listener.selector) && (!handler || handler === listener.handler)) {\n\t\t\tthis._removedListeners.push(listener);\n\t\t\tlistenerList.splice(i, 1);\n\t\t}\n\t}\n\n\t// All listeners removed\n\tif (!listenerList.length) {\n\t\tdelete listenerMap[eventType];\n\n\t\t// Remove the main handler\n\t\tif (this.rootElement) {\n\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, useCapture);\n\t\t}\n\t}\n\n\treturn this;\n};\n\n\n/**\n * Handle an arbitrary event.\n *\n * @param {Event} event\n */\nDelegate.prototype.handle = function (event) {\n\tlet i;\n\tlet l;\n\tconst type = event.type;\n\tlet root;\n\tlet phase;\n\tlet listener;\n\tlet returned;\n\tlet listenerList = [];\n\tlet target;\n\tconst eventIgnore = 'ftLabsDelegateIgnore';\n\n\tif (event[eventIgnore] === true) {\n\t\treturn;\n\t}\n\n\ttarget = event.target;\n\n\t// Hardcode value of Node.TEXT_NODE\n\t// as not defined in IE8\n\tif (target.nodeType === 3) {\n\t\ttarget = target.parentNode;\n\t}\n\n\t// Handle SVG <use> elements in IE\n\tif (target.correspondingUseElement) {\n\t\ttarget = target.correspondingUseElement;\n\t}\n\n\troot = this.rootElement;\n\n\tphase = event.eventPhase || (event.target !== event.currentTarget ? 3 : 2);\n\n\t// eslint-disable-next-line default-case\n\tswitch (phase) {\n\t\tcase 1: //Event.CAPTURING_PHASE:\n\t\t\tlistenerList = this.listenerMap[1][type];\n\t\t\tbreak;\n\t\tcase 2: //Event.AT_TARGET:\n\t\t\tif (this.listenerMap[0] && this.listenerMap[0][type]) {\n\t\t\t\tlistenerList = listenerList.concat(this.listenerMap[0][type]);\n\t\t\t}\n\t\t\tif (this.listenerMap[1] && this.listenerMap[1][type]) {\n\t\t\t\tlistenerList = listenerList.concat(this.listenerMap[1][type]);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 3: //Event.BUBBLING_PHASE:\n\t\t\tlistenerList = this.listenerMap[0][type];\n\t\t\tbreak;\n\t}\n\n\tlet toFire = [];\n\n\t// Need to continuously check\n\t// that the specific list is\n\t// still populated in case one\n\t// of the callbacks actually\n\t// causes the list to be destroyed.\n\tl = listenerList.length;\n\twhile (target && l) {\n\t\tfor (i = 0; i < l; i++) {\n\t\t\tlistener = listenerList[i];\n\n\t\t\t// Bail from this loop if\n\t\t\t// the length changed and\n\t\t\t// no more listeners are\n\t\t\t// defined between i and l.\n\t\t\tif (!listener) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\ttarget.tagName &&\n\t\t\t\t[\"button\", \"input\", \"select\", \"textarea\"].indexOf(target.tagName.toLowerCase()) > -1 &&\n\t\t\t\ttarget.hasAttribute(\"disabled\")\n\t\t\t) {\n\t\t\t\t// Remove things that have previously fired\n\t\t\t\ttoFire = [];\n\t\t\t}\n\t\t\t// Check for match and fire\n\t\t\t// the event if there's one\n\t\t\t//\n\t\t\t// TODO:MCG:20120117: Need a way\n\t\t\t// to check if event#stopImmediatePropagation\n\t\t\t// was called. If so, break both loops.\n\t\t\telse if (listener.matcher.call(target, listener.matcherParam, target)) {\n\t\t\t\ttoFire.push([event, target, listener]);\n\t\t\t}\n\t\t}\n\n\t\t// TODO:MCG:20120117: Need a way to\n\t\t// check if event#stopPropagation\n\t\t// was called. If so, break looping\n\t\t// through the DOM. Stop if the\n\t\t// delegation root has been reached\n\t\tif (target === root) {\n\t\t\tbreak;\n\t\t}\n\n\t\tl = listenerList.length;\n\n\t\t// Fall back to parentNode since SVG children have no parentElement in IE\n\t\ttarget = target.parentElement || target.parentNode;\n\n\t\t// Do not traverse up to document root when using parentNode, though\n\t\tif (target instanceof HTMLDocument) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tlet ret;\n\n\tfor (i = 0; i < toFire.length; i++) {\n\t\t// Has it been removed during while the event function was fired\n\t\tif (this._removedListeners.indexOf(toFire[i][2]) > -1) {\n\t\t\tcontinue;\n\t\t}\n\t\treturned = this.fire.apply(this, toFire[i]);\n\n\t\t// Stop propagation to subsequent\n\t\t// callbacks if the callback returned\n\t\t// false\n\t\tif (returned === false) {\n\t\t\ttoFire[i][0][eventIgnore] = true;\n\t\t\ttoFire[i][0].preventDefault();\n\t\t\tret = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn ret;\n};\n\n/**\n * Fire a listener on a target.\n *\n * @param {Event} event\n * @param {Node} target\n * @param {Object} listener\n * @returns {boolean}\n */\nDelegate.prototype.fire = function (event, target, listener) {\n\treturn listener.handler.call(target, event, target);\n};\n\n/**\n * Check whether an element\n * matches a tag selector.\n *\n * Tags are NOT case-sensitive,\n * except in XML (and XML-based\n * languages such as XHTML).\n *\n * @param {string} tagName The tag name to test against\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesTag(tagName, element) {\n\treturn tagName.toLowerCase() === element.tagName.toLowerCase();\n}\n\n/**\n * Check whether an element\n * matches the root.\n *\n * @param {?String} selector In this case this is always passed through as null and not used\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesRoot(selector, element) {\n\tif (this.rootElement === window) {\n\t\treturn (\n\t\t\t// Match the outer document (dispatched from document)\n\t\t\telement === document ||\n\t\t\t// The <html> element (dispatched from document.body or document.documentElement)\n\t\t\telement === document.documentElement ||\n\t\t\t// Or the window itself (dispatched from window)\n\t\t\telement === window\n\t\t);\n\t}\n\treturn this.rootElement === element;\n}\n\n/**\n * Check whether the ID of\n * the element in 'this'\n * matches the given ID.\n *\n * IDs are case-sensitive.\n *\n * @param {string} id The ID to test against\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesId(id, element) {\n\treturn id === element.id;\n}\n\n/**\n * Short hand for off()\n * and root(), ie both\n * with no parameters\n *\n * @return void\n */\nDelegate.prototype.destroy = function () {\n\tthis.off();\n\tthis.root();\n};\n\nexport default Delegate;\n","/**\n * Shared 'internal' scope.\n */\nimport {get} from './core/settings.js';\n\n/**\n * CUID Generator\n */\nimport {api as cuid} from '../libs/browser-cuid.js';\n\n/**\n * Record of callbacks to call when a page is tracked.\n */\nconst page_callbacks = [];\n\n/**\n * Log messages to the browser console. Requires 'log' to be set on init.\n *\n * @param {*} args items to log\n * @returns {void}\n */\nfunction log(...args) {\n\tif (get('config').test && window.console) {\n\t\tfor (const arg of args) {\n\t\t\twindow.console.log(arg);\n\t\t}\n\t}\n}\n\n/**\n * Creates a logging function that logs messages to the console with a specified namespace.\n *\n * @function namedLog\n * @param {string} namespace - The namespace to be prefixed to each log message.\n * @returns {function} A function that logs messages to the console with the given namespace if the configuration allows.\n *\n * @example\n * const log = namedLog('MyNamespace');\n * log('This is a message'); \n * // Output: [MyNamespace]: This is a message\n */\nfunction namedLog(namespace) {\n\treturn function(...args) {\n\t\tif(get('config').test && window.console) {\n\t\t\twindow.console.log(`%c[${namespace}]:`, 'color: teal', ...args)\n\t\t}\n\t}\n}\n\n/**\n * Tests if variable is a certain type. Defaults to check for undefined if no type specified.\n *\n * @param {*} variable - The variable to check.\n * @param {string=} type - The type to test for. Defaults to undefined.\n *\n * @returns {boolean} - The answer for if the variable is of type.\n */\nfunction is(variable, type = 'undefined') {\n\treturn typeof variable === type;\n}\n\n/**\n * Merge objects together. Will remove undefined and null values.\n *\n * @param {object} target - The original object to merge in to.\n * @param {object} options - The object to merge into the target. If omitted, will merge target into a new empty Object.\n *\n * @returns {object} The merged object.\n */\nfunction merge(target, options) {\n\tif (!options) {\n\t\toptions = target;\n\t\ttarget = {};\n\t}\n\n\tlet name;\n\tlet src;\n\tlet copy;\n\n\t/* jshint -W089 */\n\t/* eslint guard-for-in: 0 */\n\tfor (name in options) {\n\t\tsrc = target[name];\n\t\tcopy = options[name];\n\n\t\t// Prevent never-ending loop\n\t\tif (target === copy) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Gets rid of missing values too\n\t\tif (typeof copy !== 'undefined' && copy !== null) {\n\t\t\ttarget[name] = src === Object(src) && !is(src, 'function') ? merge(src, copy) : copy;\n\t\t}\n\t}\n\t/* jshint +W089 */\n\t/* jslint forin:true */\n\n\treturn target;\n}\n\n/**\n * URL encode a string.\n *\n * @param {string} str - The string to be encoded.\n * @returns {string} The encoded string.\n */\nfunction encode(str) {\n\tif (window.encodeURIComponent) {\n\t\treturn window.encodeURIComponent(str);\n\t} else {\n\t\treturn window.escape(str);\n\t}\n}\n\n/**\n * URL decode a string.\n *\n * @param {string} str - The string to be decoded.\n * @returns {string} The decoded string.\n */\nfunction decode(str) {\n\tif (window.decodeURIComponent) {\n\t\treturn window.decodeURIComponent(str);\n\t} else {\n\t\treturn window.unescape(str);\n\t}\n}\n\n/**\n * Utility to add event listeners.\n *\n * @param {Element} element\n * @param {string} event\n * @param {EventListenerOrEventListenerObject} listener\n * @returns {void}\n */\nfunction addEvent(element, event, listener) {\n\tif (element.addEventListener) {\n\t\telement.addEventListener(event, listener, false);\n\t} else {\n\t\telement.attachEvent('on' + event, listener);\n\t}\n}\n\n/**\n * Utility for dispatching custom events from window\n *\n * @param {string} namespace\n * @param {string} eventType\n * @param {object} detail\n * @returns {void}\n */\nfunction broadcast(namespace, eventType, detail) {\n\tdetail = detail || {};\n\ttry {\n\t\twindow.dispatchEvent(new CustomEvent(namespace + '.' + eventType, {\n\t\t\tdetail: detail,\n\t\t\tbubbles: true\n\t\t}));\n\t} catch (error) {\n\t\t// empty\n\t}\n}\n\n/**\n * Listen for page tracking requests.\n *\n * @param {Function} cb - The callback to be called whenever a page is tracked.\n * @returns {void}\n */\nfunction onPage(cb) {\n\tif (is(cb, 'function') && !page_callbacks.includes(cb)) {\n\t\tpage_callbacks.push(cb);\n\t}\n}\n\n/**\n * Trigger the 'page' listeners.\n *\n * @returns {void}\n */\nfunction triggerPage() {\n\tfor (let i = 0; i < page_callbacks.length; i++) {\n\t\tpage_callbacks[i]();\n\t}\n}\n\n/**\n * Get a value from document.cookie matching the first match of the regexp you supply\n *\n * @param {RegExp} matcher - The Regex to match with\n * @returns {string} - The vale from the cookie\n */\nfunction getValueFromCookie(matcher) {\n\treturn document.cookie.match(matcher) && RegExp.$1 !== '' && RegExp.$1 !== 'null' ? RegExp.$1 : null;\n}\n\n/**\n * Filter an object to only have the properties which are listed in the `allowlist` parameter.\n *\n * @param {object} objectToFilter - An object whose props need to be filtered\n * @param {Array} allowedPropertyNames - The list of props to allow\n * @returns {object} An object containing only the allowed props\n */\nfunction filterProperties (objectToFilter, allowedPropertyNames) {\n\tconst filteredObject = {};\n\tfor (const allowedName of allowedPropertyNames) {\n\t\tif (objectToFilter[allowedName]) {\n\t\t\tfilteredObject[allowedName] = objectToFilter[allowedName];\n\t\t}\n\t}\n\treturn filteredObject;\n}\n\n/**\n * Trim strings\n *\n * @param {string} str - The string to trim.\n * @returns {string} The trimmed string.\n */\nfunction sanitise (str) {\n\treturn typeof str === 'string' ? str.trim() : str;\n}\n\n/**\n * Assign the subject value if the target properties are undefined\n *\n * @param {object} subject - assign the value\n * @param {object} target - be assigned the value\n * @returns {void}\n */\nfunction assignIfUndefined (subject, target) {\n\tfor (const prop in subject) {\n\t\tif (!target[prop]) {\n\t\t\ttarget[prop] = subject[prop];\n\t\t} else {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(`You can't set a custom property called ${prop}`);\n\t\t}\n\t}\n}\n\n\n/**\n * Identify circular references in 'object', and replace them with a string representation\n * of the reference. Returns a succesfully serialised JSON string, and a list of circular\n * references which were removed.\n * \n * Inspired by https://github.com/sindresorhus/safe-stringify and \n * https://github.com/sindresorhus/decircular\n *\n * @param {*} object The object we want to stringify, and search within for circular references\n * @returns {Object: {jsonString: string, warnings: array}} The stringified object, and a warnings for each circular reference which was removed\n */\nfunction removeCircularReferences(object) {\n\n\t// WeakMaps release memory when all references are garbage-collected\n\tconst circularReferences = new WeakMap();\n\tconst paths = new WeakMap();\n\n\tconst warnings = [];\n\n\tfunction getPathFragment(parent, key) {\n\t\tif (!key) {\n\t\t\treturn '$';\n\t\t}\n\n\t\tif (Array.isArray(parent)) {\n\t\t\treturn `[${key}]`;\n\t\t}\n\n\t\treturn `.${key}`;\n\t}\n\n\tfunction formatCircularReferencesWarning(references) {\n\t\tconst paths = references.map(path => '`' + path.join('') + '`');\n\t\treturn 'Circular reference between ' + paths.join(' AND ');\n\t}\n\n\tfunction replacer(key, value) {\n\t\t// Scalars don't need to be inspected as they can't contain circular references\n\t\tif (!(value !== null && typeof value === 'object')) {\n\t\t\treturn value\n\t\t}\n\n\t\t// Record the path from the root ($) to the current object (value)\n\t\t// in order to print helpful circular reference warnings.\n\t\tconst path = [...paths.get(this) || [], getPathFragment(this, key)];\n\t\tpaths.set(value, path);\n\n\t\t// If a reference to the current value is already in the list, we have\n\t\t// a circular reference. Add the current value to the list along with its path,\n\t\t// and return a useful error string rather than the unserialisable value.\n\t\tif (circularReferences.has(value)) {\n\t\t\tconst references = [...circularReferences.get(value), path];\n\t\t\tcircularReferences.set(value, references);\n\t\t\tconst warning = formatCircularReferencesWarning(references);\n\t\t\twarnings.push(warning);\n\t\t\treturn warning;\n\t\t}\n\n\t\t// This is the first time we've seen the current value in this branch \n\t\t// of the object. Record its path from the object root.\n\t\tcircularReferences.set(value, [path]);\n\n\t\t// Recurse into the value to proactively find circular references\n\t\t// before encountering a loop.\n\t\tconst newValue = Array.isArray(value) ? [] : {};\n\t\tfor (const [k, v] of Object.entries(value)) {\n\t\t\tnewValue[k] = replacer.call(value, k, v);\n\t\t}\n\n\t\t// All circular references to this object will have been identified,\n\t\t// so remove it from the list.\n\t\tcircularReferences.delete(value);\n\n\t\t// This branch of the object can now be safely serialised to a JSON string\n\t\treturn newValue;\n\t}\n\n\tconst jsonString = JSON.stringify(object, replacer);\n\treturn {jsonString, warnings};\n}\n\n\n/**\n * Stringify an object to JSON, removing any circular references. When circular references\n * are found, an error is thrown in a new event loop so that global error handlers can report it.\n *\n * @param {*} object The object we want to stringify, and search within for circular references\n * @returns {string} The safely stringified JSON string\n */\nfunction safelyStringifyJson(object) {\n\n\t// JSON.stringify throws on two cases:\n\t// - value contains a circular reference\n\t// - A BigInt value is encountered\n\t// Circular references are a real possibility in the way o-tracking is called (and saves a queue of \n\t// messages in a store), so we need to handle those gracefully.\n\t// \n\t// However, for performance reasons, we always attempt to do a basic JSON.stringify() first. The \n\t// recursion involved in removeCircularReferences() makes it about 20x slower to stringify a basic payload. \n\t// This performance hit will be exacerbated on slow devices (e.g. old Android phones) with lots of queued offline events.\n\ttry {\n\t\treturn JSON.stringify(object);\n\n\t// NB: error is discarded - we have more work to do in order to throw a useful message\n\t} catch (error) {\n\t\n\t\tconst {jsonString, warnings} = removeCircularReferences(object);\n\t\n\t\tif (warnings.length) {\n\t\t\t// Throw in a new event loop, as we always want to return JSON so the tracking payload is sent\n\t\t\tsetTimeout(() => {\n\t\t\t\tconst errorMessage = \"AssertionError: o-tracking does not support circular references in the analytics data.\\n\" +\n\t\t\t\t\"Please remove the circular references in the data.\\n\" +\n\t\t\t\t\"Here are the paths in the data which are circular:\\n\" +\n\t\t\t\twarnings.join('\\n');\n\t\t\t\tthrow new Error(errorMessage);\n\t\t\t});\n\t\t}\n\t\n\t\treturn jsonString;\n\t}\n\n\n};\n\n/**\n * Find out whether two objects are deeply equal to each other.\n *\n * @param {*} a\n * @param {*} b\n * @returns {boolean} - true if the two arguments are deeply equal\n */\nfunction isDeepEqual(a, b) {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\tif (\n\t\ta &&\n\t\tb &&\n\t\ttypeof a === \"object\" &&\n\t\ttypeof b === \"object\"\n\t) {\n\t\tif (a.constructor !== b.constructor) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (Array.isArray(a)) {\n\t\t\tconst length = a.length;\n\t\t\tif (length !== b.length) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\t\tif (!isDeepEqual(a[i], b[i])) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tif (a.constructor === RegExp) {\n\t\t\treturn (\n\t\t\t\ta.source === b.source && a.flags === b.flags\n\t\t\t);\n\t\t}\n\t\tif (a.valueOf !== Object.prototype.valueOf) {\n\t\t\treturn a.valueOf() === b.valueOf();\n\t\t}\n\t\tif (a.toString !== Object.prototype.toString) {\n\t\t\treturn a.toString() === b.toString();\n\t\t}\n\n\t\tconst keys = Object.keys(a);\n\t\tconst length = keys.length;\n\t\tif (length !== Object.keys(b).length) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\tif (!Object.prototype.hasOwnProperty.call(b, keys[i])) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\tconst key = keys[i];\n\n\t\t\tif (!isDeepEqual(a[key], b[key])) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n}\n\nexport {\n\tlog,\n\tnamedLog,\n\tis,\n\tis as isUndefined,\n\tmerge,\n\tencode,\n\tdecode,\n\tcuid as guid,\n\taddEvent,\n\tbroadcast,\n\tonPage,\n\ttriggerPage,\n\tgetValueFromCookie,\n\tsanitise,\n\tassignIfUndefined,\n\tfilterProperties,\n\tremoveCircularReferences,\n\tsafelyStringifyJson,\n\tisDeepEqual\n};\n","export const LogLevel = Object.freeze({\n DEBUG: 0,\n INFO: 1,\n WARN: 2,\n ERROR: 3,\n TEST: 4,\n DEFAULT: 2,\n});\n\nconst LOG_PREFIX = \"CCC:\";\n\nexport function convertStringLogLevel(value: string | null) {\n const level = value?.toLowerCase();\n\n if (level === \"debug\") {\n return LogLevel.DEBUG;\n }\n\n if (level === \"info\") {\n return LogLevel.INFO;\n }\n\n if (level === \"warn\") {\n return LogLevel.WARN;\n }\n\n if (level === \"error\") {\n return LogLevel.ERROR;\n }\n\n if (level === \"test\") {\n return LogLevel.TEST;\n }\n\n return LogLevel.DEFAULT;\n}\n\nexport class Logger {\n public level: number;\n constructor(\n { level = LogLevel.DEFAULT }: { level: number } = {\n level: LogLevel.DEFAULT,\n }\n ) {\n this.level = localStorage.getItem(\"CCC_LOG_LEVEL\")\n ? convertStringLogLevel(localStorage.getItem(\"CCC_LOG_LEVEL\"))\n : level;\n }\n\n debug(...args: any[]) {\n if (this.level <= LogLevel.DEBUG) {\n console.info(LOG_PREFIX, ...args);\n }\n }\n\n log = this.debug;\n\n info(...args: any[]) {\n if (this.level <= LogLevel.INFO) {\n console.info(LOG_PREFIX, ...args);\n }\n }\n\n warn(...args: any[]) {\n if (this.level <= LogLevel.WARN) {\n console.warn(LOG_PREFIX, ...args);\n }\n }\n\n error(...args: any[]) {\n if (this.level <= LogLevel.ERROR) {\n console.error(LOG_PREFIX, ...args);\n }\n }\n\n setLogLevel(level: string | number | null) {\n if (localStorage.getItem(\"CCC_LOG_LEVEL\")) {\n this.level = convertStringLogLevel(localStorage.getItem(\"CCC_LOG_LEVEL\"));\n } else if (typeof level === \"number\") {\n this.level = level;\n } else {\n this.level = convertStringLogLevel(level);\n }\n }\n}\n","// Trace the element and all of its parents, collecting properties as we go\nimport {\n sanitise,\n assignIfUndefined,\n} from \"@financial-times/o-tracking/src/javascript/utils\";\n\ntype PropMap = { [k: string]: any };\n// For a given container element, get the number of elements that match the\n// original element (siblings); and the index of the original element (position).\nconst getSiblingsAndPosition = (\n el: Element | null,\n originalEl: Element,\n selector: string\n) => {\n const siblings = Array.from(el?.querySelectorAll(selector) ?? []);\n const position = siblings.findIndex((item) => item === originalEl);\n if (position === -1) {\n return;\n }\n return {\n siblings: siblings.length,\n position,\n };\n};\n\nconst elementPropertiesToCollect = [\n \"nodeName\",\n \"className\",\n \"id\",\n \"href\",\n \"text\",\n \"role\",\n];\n// Get all (sanitised) properties of a given element.\nconst getAllElementProperties = (element: any) => {\n const properties: PropMap = {};\n for (const property of elementPropertiesToCollect) {\n const value =\n element[property] ||\n element.getAttribute(property) ||\n element.hasAttribute(property);\n if (value !== undefined) {\n if (typeof value === \"boolean\") {\n properties[property] = value;\n } else {\n properties[property] = sanitise(value);\n }\n }\n }\n\n return properties;\n};\n\nconst parseRawValue = (rawValue: string) => {\n try {\n const parsedValue = JSON.parse(rawValue);\n const type = Object.prototype.toString.call(parsedValue);\n const isJSON = type === \"[object Object]\" || type === \"[object Array]\";\n\n return [isJSON, parsedValue];\n } catch (error) {\n return [false, null];\n }\n};\n\nconst getAttributeValue = (rawValue: string) => {\n const [isJSON, value] = parseRawValue(rawValue);\n\n return isJSON ? value : rawValue;\n};\n\n// Get some properties of a given element.\nconst getDomPathProps = (attrs: Attr[], props: PropMap) => {\n // Collect any attribute that matches given strings.\n attrs\n .filter((attribute) =>\n attribute.name.match(/^data-trackable|^data-o-|^aria-/i)\n )\n .forEach((attribute) => {\n props[attribute.name] = attribute.value;\n });\n\n return props;\n};\n\n// Get only the custom data-trackable-context-? properties of a given element\nconst getContextProps = (\n attrs: Attr[],\n props: PropMap,\n isOriginalEl: boolean\n) => {\n const customProps: { [k: string]: any } = {};\n\n // for the original element collect properties like className, nodeName\n if (isOriginalEl) {\n elementPropertiesToCollect.forEach((name) => {\n if (typeof props[name] !== \"undefined\" && name !== \"id\") {\n customProps[name] = props[name];\n }\n });\n }\n\n // Collect any attribute that matches given strings.\n attrs\n .filter((attribute) => attribute.name.match(/^data-trackable-context-/i))\n .forEach((attribute) => {\n customProps[attribute.name.replace(\"data-trackable-context-\", \"\")] =\n getAttributeValue(attribute.value);\n });\n\n return customProps;\n};\n\nexport function getTrace(el: Element, rootEl: Element) {\n const originalEl = el;\n const selector = originalEl?.getAttribute(\"data-trackable\")\n ? `[data-trackable=\"${originalEl.getAttribute(\"data-trackable\")}\"]`\n : originalEl?.nodeName;\n const trace = [];\n const customContext = {};\n while (el && el !== rootEl) {\n const props = getAllElementProperties(el);\n const attrs = Array.from(el.attributes);\n let domPathProps = getDomPathProps(attrs, props);\n\n // If the element happens to have a data-trackable attribute, get the siblings\n // and position of the element (relative to the current element).\n if (domPathProps[\"data-trackable\"]) {\n domPathProps = Object.assign(\n domPathProps,\n getSiblingsAndPosition(el, originalEl, selector)\n );\n }\n\n trace.push(domPathProps);\n\n const contextProps = getContextProps(attrs, props, el === originalEl);\n\n assignIfUndefined(contextProps, customContext);\n\n el = el.parentNode as Element;\n }\n return { trace, customContext };\n}\n","import Delegate from \"ftdomdelegate/main\";\n\nimport {\n sanitise,\n assignIfUndefined,\n} from \"@financial-times/o-tracking/src/javascript/utils\";\nimport { Logger } from \"./logger\";\nimport { getTrace } from \"./get-trace\";\n\nconst eventPropertiesToCollect = [\"ctrlKey\", \"altKey\", \"shiftKey\", \"metaKey\"];\n\nclass Tracking {\n cccId: string;\n cccName: string;\n subtype: string;\n teamName: string;\n shadowRoot: ShadowRoot | null;\n category: string;\n elements: string | string[];\n isInitialised: boolean;\n log: Logger;\n\n constructor({\n id = \"00000000-0000-0000-0000-000000000000\",\n name = \"ccc-component\",\n subtype = \"interactive\",\n teamName = \"djd\",\n shadowRoot = null,\n category = \"cta\",\n elements = 'a, button, input, [role=\"button\"]',\n logger,\n }: {\n id?: string;\n name: string;\n subtype: string;\n teamName?: string;\n shadowRoot: ShadowRoot | null;\n category?: string;\n elements?: string | string[];\n logger: Logger;\n }) {\n this.cccId = id;\n this.cccName = name;\n this.subtype = subtype;\n this.teamName = teamName;\n this.shadowRoot = shadowRoot;\n this.category = category;\n this.elements = elements;\n this.isInitialised = false;\n this.log = logger ?? new Logger();\n }\n\n // Get properties for the event (as opposed to properties of the clicked element)\n getEventProperties(event: any) {\n const eventProperties: { [k: string]: any } = {};\n for (const property of eventPropertiesToCollect) {\n if (event[property]) {\n try {\n eventProperties[property] = sanitise(event[property]);\n } catch (e) {\n this.log.info(e);\n }\n }\n }\n return eventProperties;\n }\n\n // Controller for handling click events\n handleClickEvent(\n eventData: { action: string; category: string },\n root: Element\n ) {\n return (clickEvent: Event, clickElement: HTMLElement) => {\n const context: any = this.getEventProperties(clickEvent);\n const { trace, customContext } = getTrace(clickElement, root);\n context.custom =\n clickElement.dataset && clickElement.dataset.custom\n ? JSON.parse(clickElement.dataset.custom)\n : null;\n context.domPathTokens = trace;\n context.component = {\n id: this.cccId,\n name: this.cccName,\n type: \"custom-code-component\",\n subtype: this.subtype,\n };\n context.teamName = this.teamName;\n context.url = document.URL;\n\n assignIfUndefined(customContext, context);\n\n context.method = \"ftCustomAnalytics\";\n eventData = { ...eventData, ...context };\n\n // send spoor event\n document.body.dispatchEvent(\n new CustomEvent(\"oTracking.event\", {\n detail: eventData,\n bubbles: true,\n composed: true,\n })\n );\n };\n }\n\n sendSpoorEvent(triggerAction: any, extraDetail: any) {\n const eventData = {\n category: \"component\",\n action: \"act\",\n component: {\n id: this.cccId,\n name: this.cccName,\n type: \"custom-code-component\",\n subtype: this.subtype,\n },\n teamName: this.teamName,\n trigger_action: triggerAction,\n custom: extraDetail,\n method: \"ftCustomAnalytics\",\n };\n\n // send spoor event\n document.body.dispatchEvent(\n new CustomEvent(\"oTracking.event\", {\n detail: eventData,\n bubbles: true,\n composed: true,\n })\n );\n }\n\n init(id: string) {\n if (!this.isInitialised) {\n this.isInitialised = true;\n this.cccId = id ? id : this.cccId;\n\n const eventData = {\n action: \"click\",\n category: this.category,\n };\n\n const root = this.shadowRoot?.querySelector(\"[data-component-root]\");\n\n if (root) {\n const shadowDelegate = new Delegate(root);\n shadowDelegate.on(\n \"click\",\n this.elements,\n this.handleClickEvent(eventData, root),\n true\n );\n }\n }\n }\n}\n\nexport default Tracking;\n","import { CCCError } from \"./errors\";\n\nexport type ComponentPathType = {\n org: string;\n repo: string;\n name: string;\n versionRange: string;\n};\nexport class ComponentPath {\n org: string = \"local\";\n repo: string = \"dev\";\n name: string;\n versionRange: string;\n\n constructor(path?: ComponentPathType | string) {\n const { org, repo, name, versionRange } = isValidComponentPathObject(path)\n ? path\n : ComponentPath.fromString(path);\n if (org) this.org = org;\n if (repo) this.repo = repo;\n this.name = name;\n this.versionRange = versionRange;\n }\n\n set path(path: ComponentPathType | string) {\n const { org, repo, name, versionRange } = isValidComponentPathObject(path)\n ? path\n : ComponentPath.fromString(path);\n this.org = org;\n this.repo = repo;\n this.name = name;\n this.versionRange = versionRange;\n }\n\n get path(): string {\n return `${this.org}/${this.repo}@${this.versionRange}/${this.name}`;\n }\n\n get isValid(): boolean {\n return [this.org, this.repo, this.name].every(\n (value) => value !== \"unknown\"\n );\n }\n\n toString(): string {\n return this.path;\n }\n\n static fromString(p?: string | null, v?: string | null): ComponentPath {\n const path = p ?? \"unknown/unknown/unknown\";\n\n const [name, repo, org] = path\n .replace(/@[^\\/]+/, \"\")\n .split(\"/\")\n .reverse();\n\n const versionRange =\n v ??\n path\n .match(/@[^\\/]+/)\n ?.toString()\n .replace(\"@\", \"\") ??\n \"unknown\";\n\n if (repo && !versionRange) throw new CCCError(\"No version specified\");\n\n return new ComponentPath({ org, repo, name, versionRange });\n }\n}\n\nexport type DetailType = {\n component: ComponentPath;\n source?: string;\n cause?: string;\n error?: Error;\n};\n\nexport function isValidComponentPathObject(\n value: unknown\n): value is ComponentPathType {\n if (typeof value === \"object\" && value !== null) {\n return \"org\" in value && \"repo\" in value && \"name\" in value;\n }\n\n return false;\n}\n","/**\n * This is the base CCC component error class. These are raised when the component being loaded errors\n */\n\nimport { ComponentPath, DetailType, isValidComponentPathObject } from \"./path\";\n\nexport class CCCError extends Error {\n component: ComponentPath | null;\n source?: string;\n errors?: Error[];\n constructor(message: string | null, detail?: DetailType) {\n if (!detail && message) {\n super(message);\n this.component = null;\n } else if (typeof detail?.component === \"string\") {\n super(\n message ??\n `${detail.cause ?? \"Unknown error\"} in ${detail.component} imported from ${detail.source ?? \"an undefined source\"}.`\n );\n\n this.component = ComponentPath.fromString(detail.component);\n } else if (isValidComponentPathObject(detail?.component)) {\n super(\n message ??\n `${detail.cause ?? \"Unknown error\"} in ${detail.component.org}/${detail.component.repo}/${detail.component.name}@${detail.component.versionRange} imported from ${detail.source ?? \"an undefined source\"}.`\n );\n this.component = new ComponentPath(detail.component);\n } else {\n super(\n `${detail?.cause ?? \"Unknown error\"} in unknown component imported from ${detail?.source ?? \"unknown source\"}.`\n );\n this.component = null;\n }\n\n this.source = detail?.source ?? \"unknown source\";\n this.errors = [];\n if (detail?.error) {\n this.errors?.push(detail?.error);\n }\n if (Error.captureStackTrace) {\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n Error.captureStackTrace(this, CCCError);\n }\n\n this.name = \"CCCError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur during the import of the CCC component app\n */\nexport class CCCImportError extends CCCError {\n constructor(message: string, detail: DetailType) {\n super(message, { ...detail, cause: \"Import error\" });\n this.name = \"CCCImportError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur during the rendering of the CCC component app\n */\nexport class CCCRenderError extends CCCError {\n constructor(message: string, detail: DetailType) {\n super(message, { ...detail, cause: \"Render error\" });\n this.name = \"CCCRenderError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur as a result of the CCC component app timing out\n */\nexport class CCCTimeoutError extends CCCError {\n constructor(detail: DetailType) {\n super(null, { ...detail, cause: \"Timeout error\" });\n this.name = \"CCCTimeoutError\";\n }\n}\n","import { ComponentPath } from \"./path\";\n\nexport class CCCEvent extends Event {\n component: ComponentPath;\n source?: string;\n static eventType = \"ccc:event\";\n\n constructor(\n eventType: string = CCCEvent.eventType,\n detail: { component: ComponentPath; source?: string },\n opts?: EventInit\n ) {\n super(eventType, {\n bubbles: true,\n cancelable: false,\n composed: true,\n ...opts,\n });\n this.component = detail.component;\n this.source = detail.source;\n }\n}\n\nexport class CCCConnectedEvent extends CCCEvent {\n static eventType = \"ccc:connected\";\n\n constructor(\n detail: { component: ComponentPath; source?: string },\n opts?: EventInit\n ) {\n super(CCCConnectedEvent.eventType, detail, opts);\n }\n}\n\nexport class CCCReadyEvent extends CCCEvent {\n static eventType = \"ccc:ready\";\n\n constructor(\n detail: { component: ComponentPath; source?: string },\n opts?: EventInit\n ) {\n super(CCCReadyEvent.eventType, detail, opts);\n }\n}\n\nexport class CCCViewportEvent extends CCCEvent {\n static eventType = \"ccc:viewport\";\n intersecting = false;\n entry?: IntersectionObserverEntry;\n\n constructor(\n detail: {\n component: ComponentPath;\n source?: string;\n intersecting: boolean;\n entry?: IntersectionObserverEntry;\n },\n opts?: EventInit\n ) {\n super(CCCViewportEvent.eventType, detail, opts);\n this.intersecting = detail.intersecting;\n this.entry = detail.entry;\n }\n}\n","/**\n * Used to convert camelCase to kebab-case\n * @param str\n * @returns\n */\nexport const kebabize = (str: string) =>\n str.replace(\n /[A-Z]+(?![a-z])|[A-Z]/g,\n ($, ofs) => (ofs ? \"-\" : \"\") + $.toLowerCase()\n );\n\n/**\n * Checks if the provided host is part of the allowed test environments.\n *\n * @param host - The hostname to check.\n * @returns True if the hostname is a safe test environment, false otherwise.\n */\nexport function isSafeTestEnv(host: string | undefined) {\n return isAllowed([\n 'localhost',\n 'local.ft.com',\n /^.*\\.apps\\.in\\.ft\\.com$/,\n ], host);\n}\n\n/**\n * Checks if the current window location hostname is considered a local environment.\n *\n * @returns True if the hostname is local, false otherwise.\n */\nexport function isLocalEnv() {\n return isAllowed([\n 'localhost',\n 'local.ft.com',\n /^.*\\.in\\.ft\\.com$/,\n ], window.location.hostname);\n}\n\n/**\n * Checks if the current window location host is one of the Spark environments.\n *\n * @returns True if the host is spark.ft.com or spark-staging.ft.com, false otherwise.\n */\nexport function isSparkEnv() {\n return isAllowed([\n 'spark.ft.com',\n 'spark-staging.ft.com',\n ], window.location.host);\n}\n\n/**\n * Checks if the given hostname is in the provided allowlist.\n *\n * @param allowlist - A list of allowed hostnames or RegExp matchers.\n * @param hostname - The hostname to validate.\n * @returns True if the hostname matches any item in the allowlist, false otherwise.\n */\nexport function isAllowed(allowlist: (string|RegExp)[], hostname: string | undefined) {\n if (!hostname) return false;\n return allowlist.some(item => {\n if (typeof item === 'string') {\n return item === hostname;\n }\n return item.test(hostname);\n });\n} \n","import { isLocalEnv, isSafeTestEnv, isSparkEnv } from \"./util\";\n\n/**\n * Assigns a test URL based on the provided testEnv value.\n *\n * @param testEnv - A string indicating test environment setting\n * @returns A `URL` object if valid and safe, or `undefined` if invalid.\n */\nexport function assignTestURL(testEnv: string | null): URL | undefined {\n if (testEnv === null) {\n return;\n }\n\n let testUrl;\n const defaultTestUrl = new URL(\"http://localhost:5173\");\n\n try {\n if (typeof testEnv === \"string\") {\n if (\n (testEnv === \"\" || testEnv.toLowerCase() === \"true\") &&\n isLocalEnv()\n ) {\n testUrl = defaultTestUrl;\n } else {\n const hasProtocol =\n testEnv.startsWith(\"http://\") || testEnv.startsWith(\"https://\");\n testUrl = hasProtocol ? new URL(testEnv) : undefined;\n\n // Prevent script injection\n if (testUrl && !isSafeTestEnv(testUrl?.hostname)) {\n throw new Error(\"Unsafe testing host override\");\n }\n }\n } else if (isSparkEnv()) {\n testUrl = defaultTestUrl;\n }\n } catch (_) {\n return testUrl;\n }\n\n return testUrl;\n}\n\n/**\n * Checks whether the given test component exists on local dev server\n *\n * @param testUrl - The test environment URL to check.\n * @returns A promise that resolves to true if Vite is running, false otherwise.\n */\nexport async function useComponentTestEnv(\n componentName: string,\n testUrl?: URL\n): Promise<boolean> {\n if (!testUrl) {\n return false;\n }\n\n const localDevOnline = fetch(\n new URL(`src/${componentName}/config.yaml`, testUrl),\n {\n method: \"HEAD\",\n }\n )\n .then(() => true)\n .catch(() => false);\n\n return localDevOnline;\n}\n","/**\n * @file\n * Main component definition for custom-code-component\n */\n\nimport type { ContentTree } from \"@financial-times/content-tree\";\nimport { BaseRenderer } from \"../../ccc-sdk/src/renderers/BaseRenderer\";\nimport Tracking from \"./tracking\";\nimport { Logger } from \"./logger\";\nimport {\n CCCError,\n CCCImportError,\n CCCRenderError,\n CCCTimeoutError,\n} from \"./errors\";\nimport { CCCConnectedEvent, CCCReadyEvent, CCCViewportEvent } from \"./events\";\nimport { ComponentPath } from \"./path\";\nimport { kebabize } from \"./util\";\nimport { assignTestURL, useComponentTestEnv } from \"./environment\";\nimport styles from \"./custom-code-component.css?inline\";\n\nexport class FTCustomCodeComponent extends HTMLElement {\n /**\n * The component renderer, resolved from dynamic import\n */\n app?: typeof BaseRenderer.prototype.render;\n\n /**\n * Set whether component is \"open\" or \"closed\". Defaults to \"open\".\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow#mode\n */\n mode: \"closed\" | \"open\" = \"open\";\n\n /**\n * Reserved attributes we don't pass to the child component\n */\n RESERVED_ATTRS = new Set([\n \"iframe\",\n \"path\",\n \"version\",\n \"data-component-props\",\n \"data-asset-type\",\n \"shadow-open\",\n \"env\",\n \"load-timeout\",\n ]);\n\n /**\n * URI of component module for CCC webcomponent to load\n */\n source?: string;\n\n /**\n * OTracking config\n */\n tracking?: Tracking;\n\n /**\n * Alternative base URL, used for testing\n */\n testUrl?: URL;\n\n /**\n * ComponentPath instance with `org`, `repo`, `name` and `versionRange` attributes\n */\n component = new ComponentPath();\n\n /**\n * Logger instance. Set log level using `this.log.setLogLevel(string|number|null)`.\n */\n log: Logger;\n\n /**\n * IntersectionObserver that dispatches CCCViewportEvents\n */\n observer = new IntersectionObserver((entries) => {\n this.log.debug(\"Intersection Observer callback\", { entries });\n entries.forEach((entry) => {\n this.dispatchEvent(\n new CCCViewportEvent({\n component: this.component,\n source: this.source,\n intersecting: entry.isIntersecting,\n entry,\n })\n );\n });\n });\n\n /**\n * Custom Element constructor.\n *\n * n.b., attributes and ShadowDOM aren't available in custom element constructors.\n * Use connectedCallback() and other lifecycle methods if you want to eg. this.getAttribute()\n */\n constructor() {\n super();\n this.log = new Logger();\n\n const supportsDeclarative =\n HTMLElement.prototype.hasOwnProperty(\"attachInternals\");\n\n try {\n const internals = supportsDeclarative && this.attachInternals();\n } catch (e) {\n this.log.error(e);\n }\n }\n\n /**\n * connectedCallback() CE lifecycle callback\n *\n * Called whenever a <custom-code-component> element is mounted to the DOM.\n */\n async connectedCallback() {\n try {\n this.log.setLogLevel(this.getAttribute(\"log\"));\n this.log.debug(\"connectedCallback\");\n\n const path = this.getAttribute(\"path\");\n const versionRange = this.getAttribute(\"version\");\n this.component = ComponentPath.fromString(path, versionRange);\n\n this.app = await this.load();\n await this.mount();\n await this.initTracking();\n } catch (e) {\n if (e instanceof Error) {\n requestAnimationFrame(() => {\n this.emitError(e);\n });\n }\n\n this.unmount(e as Error);\n }\n }\n\n /**\n * Error handler. Decorates errors for easier ingestion.\n *\n * @param error\n */\n emitError(error: Error) {\n this.log.debug(\"emitError\", { error });\n if (error instanceof CCCError) {\n this.dispatchEvent(\n new ErrorEvent(\"ccc:error\", {\n bubbles: true,\n cancelable: false,\n composed: true,\n error,\n message: error.message,\n })\n );\n } else {\n // Wrap original error with generic CCC error class\n const wrappedError = new CCCError(error.message, {\n component: this.component,\n error: error,\n });\n\n this.dispatchEvent(\n new ErrorEvent(\"ccc:error\", {\n bubbles: true,\n cancelable: false,\n composed: true,\n error: wrappedError,\n message: wrappedError.message,\n })\n );\n }\n }\n\n /**\n * disconnectedCallback() CE lifecycle event.\n *\n * Called when a <custom-code-component> element is removed from DOM.\n */\n disconnectedCallback() {\n this.log.debug(\"disconnectedCallback\");\n const path = this.getAttribute(\"path\");\n this.log.info(`<custom-code-component:${path}> disconnected`);\n this.observer.disconnect();\n }\n\n /**\n * MessageChannel interface.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n */\n channel = new MessageChannel();\n\n /**\n * MessageChannel postMessage callback\n *\n * @param e\n */\n onmessage(e?: any) {\n this.log.debug(\"onmessage\", { event: e });\n }\n\n /**\n * This error handler is called by the child component on e.g. unrecoverable error.\n * It then calls unmount(), which restores the fallback.\n *\n * @param e\n */\n onunmount(e: Error) {\n this.log.debug(\"onunmount\", { error: e });\n if (e instanceof Error) {\n const renderError = new CCCRenderError(e.message, {\n error: e,\n component: this.component,\n });\n requestAnimationFrame(() => {\n this.emitError(renderError);\n this.unmount(renderError);\n });\n }\n }\n\n /**\n * onready event callback.\n * Called by mount() after kicking off initial component render.\n *\n * @param app\n */\n async onready(app: Promise<void>) {\n try {\n await app;\n this.log.debug(\"onready\", { app });\n this.dispatchEvent(\n new CCCReadyEvent({\n component: this.component,\n source: this.source,\n })\n );\n\n this.dataset.cccReady = \"true\";\n delete this.dataset.cccError;\n\n this.observer.observe(this);\n } catch (e) {\n this.log.debug(\"onready caught error\", { error: e });\n if (e instanceof Error) {\n const renderError = new CCCRenderError(e.message, {\n error: e,\n component: this.component,\n });\n requestAnimationFrame(() => {\n this.emitError(renderError);\n this.unmount(renderError);\n });\n }\n }\n }\n\n /**\n * MessageChannel postMessage handler.\n * This can be used for inter-CCC communication.\n * @param event\n */\n postMessage(event: any) {\n this.log.debug(\"postmessage\", { event });\n this.channel.port1.postMessage(event);\n }\n\n /**\n * Initial mounting behaviour.\n *\n * Attaches ShadowDOM if needed, dispatches ccc:connected event, adds component base styles,\n * generates fallback template element if one doesn't exist already, initialises tracking,\n * then kicks off component rendering. Passes component render promise to onready().\n *\n * @param prerendered\n */\n async mount(prerendered?: ShadowRoot | null) {\n this.log.debug(\"mount\", prerendered);\n try {\n this.mode =\n this.getAttribute(\"shadow-open\") == \"false\" ? \"closed\" : \"open\";\n if (this.component) {\n if (!this.app) {\n throw new Error(\"CCC mounted without App\");\n }\n\n const ssr = this.shadowRoot !== null;\n const shadow =\n this.shadowRoot ?? this.attachShadow({ mode: this.mode });\n\n this.dispatchEvent(\n new CCCConnectedEvent({\n component: this.component,\n source: this.source,\n })\n );\n // Add global CCC styles if not already present in shadow DOM.\n if (\n !shadow.querySelector('link[href~=\"custom-code-component.css\"]') &&\n !shadow.adoptedStyleSheets.length\n ) {\n if (!window.CCC_LAYOUT_STYLESHEET) {\n this.log.debug(\"mount generating CCC_LAYOUT_STYLESHEET\");\n window.CCC_LAYOUT_STYLESHEET = new CSSStyleSheet();\n window.CCC_LAYOUT_STYLESHEET.replaceSync(styles);\n }\n shadow.adoptedStyleSheets = [window.CCC_LAYOUT_STYLESHEET];\n }\n\n if (!ssr) {\n this.log.debug(\"mount generating fallback template\");\n const template = document.createElement(\"template\");\n template.innerHTML = \"<div data-component-root><slot></slot></div>\";\n this.appendChild(template);\n shadow.appendChild(template.content.cloneNode(true));\n }\n\n const data = JSON.parse(this.getAttribute(\"data-component-props\")!);\n\n const extraProps = Object.fromEntries(\n [...this.attributes]\n .filter(\n (attribute) =>\n !this.RESERVED_ATTRS.has(attribute.name) &&\n !attribute.name.startsWith(\"data-\")\n )\n .map((attribute) => [attribute.name, attribute.value])\n );\n\n // Create tracking instance\n this.tracking = new Tracking({\n name: this.component?.toString(),\n subtype: \"interactive\",\n teamName: \"djd\",\n shadowRoot: this.shadowRoot,\n logger: this.log,\n });\n\n if (!data && Object.keys(extraProps).length > 0) {\n this.log.warn(\n `CCC ${this.component.toString()}: passing component settings as webcomponent attributes is %cDEPRECATED`,\n \"font-weight: bold\",\n \" and will be removed in v3.\"\n );\n this.log.warn(\n `Please use the %cdata-component-props`,\n \"text-decoration: underline;\",\n \" attribute instead.\"\n );\n }\n\n const { onmessage, ready = Promise.resolve() } =\n this.app(\n shadow,\n {\n ...(data ?? extraProps),\n log: this.log,\n data: data ?? extraProps,\n port: this.channel.port2,\n tracking: this.tracking,\n prerendered: !!prerendered,\n children: this.children,\n },\n ssr,\n this.onunmount.bind(this)\n ) || {};\n\n if (onmessage) this.onmessage = onmessage;\n\n this.onready(ready);\n }\n } catch (err) {\n this.log.info(\n `<custom-code-component> uncaught error during mount from ${this.component?.toString()}`\n );\n this.log.error(err);\n\n throw err;\n }\n }\n\n /**\n * Called in top-level error handler or by child component on unhandled error.\n * Replace shadow root with either <slot> or template[data-component-fallback]\n * slot on failure\n *\n * @param e\n */\n unmount(e: Error) {\n this.log.debug(\"unmount\", { error: e });\n\n const template =\n this.querySelector<HTMLTemplateElement>(\n \"template[data-component-fallback]\"\n ) ?? this.querySelector<HTMLTemplateElement>(\"template\");\n\n if (template) {\n this.log.debug(\"unmount replacing shadowRoot with fallback\");\n this.shadowRoot?.replaceChildren(template.content.cloneNode(true));\n }\n\n if (!this.dataset.cccError)\n this.dataset.cccError = kebabize(e.name.replace(\"CCC\", \"\"));\n\n delete this.dataset.cccReady;\n\n this.observer.disconnect();\n }\n\n /**\n * Asynchronously loads the CCC child component.\n *\n * @returns Promise resolving to component renderer function\n */\n async load() {\n this.log.debug(\"load\");\n\n if (!this.component.isValid) {\n throw new Error(\"No path found\");\n }\n\n const path = this.getAttribute(\"path\");\n const componentVersionRange = this.getAttribute(\"version\");\n const timeout = Number(this.getAttribute(\"load-timeout\") || 10000);\n const testEnv = this.getAttribute(\"test-env\");\n this.testUrl = assignTestURL(testEnv);\n const isTestEnv = await useComponentTestEnv(\n this.component.name,\n this.testUrl\n );\n\n // id querystring necessary to multiple allow components with the same source (same name and version number) to appear on the page correctly\n const id = this.getAttribute(\"id\");\n\n if (isTestEnv && this.testUrl) {\n this.log.debug(\"load adding Vite scripts\");\n this.injectViteScripts();\n }\n\n this.source = isTestEnv\n ? `${this.testUrl?.origin}/src/${this.component.name}/index.jsx?id=${id}`\n : `https://www.ft.com/__component/${this.component.org}/${this.component.repo}${\n componentVersionRange ? `@${componentVersionRange}` : \"@latest\"\n }/${this.component.name}/${this.component.name}.js?id=${id}`;\n\n try {\n return await new Promise<typeof BaseRenderer.prototype.render>(\n (resolve, reject) => {\n const to = setTimeout(() => {\n this.log.error(\"CCC import timeout error\");\n reject(\n new CCCTimeoutError({\n component: this.component!,\n source: this.source,\n })\n );\n }, Number(timeout));\n\n if (this.source) {\n import(/* webpackIgnore: true */ this.source /* @vite-ignore */)\n .then(({ default: componentRenderFunction }) => {\n if (componentRenderFunction) {\n clearTimeout(to);\n resolve(componentRenderFunction);\n } else\n throw new CCCImportError(\n \"No component renderer default export found\",\n {\n component: this.component!,\n source: this.source,\n }\n );\n })\n .catch((e) => {\n clearTimeout(to);\n this.log.error(e);\n if (e instanceof Error && !(e instanceof CCCImportError)) {\n reject(\n new CCCImportError(e.message, {\n component: this.component!,\n source: this.source,\n })\n );\n } else {\n reject(e);\n }\n });\n } else {\n clearTimeout(to);\n throw new CCCImportError(`Unable to mount ${path}`, {\n component: this.component!,\n source: this.source,\n });\n }\n }\n );\n } catch (err) {\n this.log.error(\n `<custom-code-component> error during import from ${path}@${componentVersionRange}`\n );\n\n throw err;\n }\n }\n\n /**\n * Initialises OTracking\n */\n initTracking = async () => {\n this.log.debug(\"initTracking\", { cccId: this.id });\n try {\n this.tracking?.init(this.id);\n } catch (e) {\n const path = this.getAttribute(\"path\");\n const componentVersionRange = this.getAttribute(\"version\");\n this.log.info(\n `Error initialising tracking on <custom-code-component> ${path}@${componentVersionRange}`\n );\n this.log.error(e);\n }\n };\n\n /**\n * Injects Vite HMR scripts during dev environment usage\n */\n injectViteScripts = () => {\n if (document.querySelector('script[name=\"ccc-sdk-react-preamble\"]')) return;\n\n const preambleScript = document.createElement(\"script\");\n preambleScript.type = \"module\";\n preambleScript.setAttribute(\"name\", \"ccc-sdk-react-preamble\");\n\n preambleScript.textContent = `\n import RefreshRuntime from \"${this.testUrl?.origin}/@react-refresh\";\n RefreshRuntime.injectIntoGlobalHook(window);\n window.$RefreshReg$ = () => {};\n window.$RefreshSig$ = () => (type) => type;\n window.__vite_plugin_react_preamble_installed__ = true;\n `.trim();\n document.head.appendChild(preambleScript);\n\n const viteClientScript = document.createElement(\"script\");\n viteClientScript.type = \"module\";\n viteClientScript.src = `${this.testUrl?.origin}/@vite/client`;\n document.head.appendChild(viteClientScript);\n };\n\n /**\n * Called whenever the <custom-code-component>'s attributes are changed.\n * Currently only used to dynamically set log level.\n *\n * @param name\n * @param oldValue\n * @param newValue\n */\n attributeChangedCallback(name: string, oldValue: string, newValue: string) {\n this.log.debug(\"attributeChangedCallback lifecycle method\", {\n name,\n oldValue,\n newValue,\n });\n\n switch (name) {\n case \"log\": {\n this.log.setLogLevel(newValue);\n }\n }\n }\n}\n\nexport interface CustomCodeComponent extends ContentTree.Node {\n type: \"CustomCodeComponent\";\n path: string;\n versionRange: string;\n altText: string;\n lastModified: string;\n fallbackImage?: ContentTree.Image;\n displayFallbackText: boolean;\n layout: \"in-line\" | \"mid-grid\" | \"full-grid\" | \"full-bleed\";\n /* prettier-ignore */\n attributes: {\n [key: string]: string | boolean | undefined;\n } | { children?: CustomCodeComponent | Array<CustomCodeComponent> };\n}\n\nexport type { FTCustomCodeComponent as CCCHTMLElement };\n"],"names":["Delegate","root","listenerMap","eventType","selector","handler","useCapture","matcher","matcherParam","matchesTag","matchesId","matchesRoot","i","listener","listenerList","singleEventType","event","l","type","phase","returned","target","eventIgnore","toFire","ret","tagName","element","id","sanitise","str","assignIfUndefined","subject","prop","LogLevel","LOG_PREFIX","convertStringLogLevel","value","level","Logger","args","getSiblingsAndPosition","el","originalEl","siblings","position","item","elementPropertiesToCollect","getAllElementProperties","properties","property","parseRawValue","rawValue","parsedValue","getAttributeValue","isJSON","getDomPathProps","attrs","props","attribute","getContextProps","isOriginalEl","customProps","name","getTrace","rootEl","trace","customContext","domPathProps","contextProps","eventPropertiesToCollect","Tracking","subtype","teamName","shadowRoot","category","elements","logger","eventProperties","e","eventData","clickEvent","clickElement","context","triggerAction","extraDetail","_a","ComponentPath","path","org","repo","versionRange","isValidComponentPathObject","p","v","CCCError","message","detail","CCCImportError","CCCRenderError","CCCTimeoutError","_CCCEvent","opts","CCCEvent","_CCCConnectedEvent","CCCConnectedEvent","_CCCReadyEvent","CCCReadyEvent","_CCCViewportEvent","CCCViewportEvent","kebabize","$","ofs","isSafeTestEnv","host","isAllowed","isLocalEnv","isSparkEnv","allowlist","hostname","assignTestURL","testEnv","testUrl","defaultTestUrl","useComponentTestEnv","componentName","FTCustomCodeComponent","entries","entry","componentVersionRange","_b","preambleScript","viteClientScript","supportsDeclarative","internals","error","wrappedError","renderError","app","prerendered","ssr","shadow","styles","template","data","extraProps","onmessage","ready","err","timeout","isTestEnv","resolve","reject","to","componentRenderFunction","oldValue","newValue"],"mappings":"AAUA,SAASA,EAASC,GAAM;AAQvB,OAAK,cAAc,CAAC,CAAE,GAAE,EAAE,GACtBA,KACH,KAAK,KAAKA,CAAI,GAIf,KAAK,SAASD,EAAS,UAAU,OAAO,KAAK,IAAI,GAGjD,KAAK,oBAAoB,CAAE;AAC5B;AASAA,EAAS,UAAU,OAAO,SAAUC,GAAM;AACzC,QAAMC,IAAc,KAAK;AACzB,MAAIC;AAGJ,MAAI,KAAK,aAAa;AACrB,SAAKA,KAAaD,EAAY,CAAC;AAC9B,MAAIA,EAAY,CAAC,EAAE,eAAeC,CAAS,KAC1C,KAAK,YAAY,oBAAoBA,GAAW,KAAK,QAAQ,EAAI;AAGnE,SAAKA,KAAaD,EAAY,CAAC;AAC9B,MAAIA,EAAY,CAAC,EAAE,eAAeC,CAAS,KAC1C,KAAK,YAAY,oBAAoBA,GAAW,KAAK,QAAQ,EAAK;AAAA,EAGtE;AAKC,MAAI,CAACF,KAAQ,CAACA,EAAK;AAClB,WAAI,KAAK,eACR,OAAO,KAAK,aAEN;AASR,OAAK,cAAcA;AAGnB,OAAKE,KAAaD,EAAY,CAAC;AAC9B,IAAIA,EAAY,CAAC,EAAE,eAAeC,CAAS,KAC1C,KAAK,YAAY,iBAAiBA,GAAW,KAAK,QAAQ,EAAI;AAGhE,OAAKA,KAAaD,EAAY,CAAC;AAC9B,IAAIA,EAAY,CAAC,EAAE,eAAeC,CAAS,KAC1C,KAAK,YAAY,iBAAiBA,GAAW,KAAK,QAAQ,EAAK;AAIjE,SAAO;AACR;AAMAH,EAAS,UAAU,iBAAiB,SAAUG,GAAW;AACxD,SAAO,CAAC,QAAQ,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D,GAEO7F,GAAM;AAAA,MACZ,KAAK;AACE,aAAA,IAAI,YAAY6F,CAAQ;AAAA,IAC/B;AAAA,EACF;AAEJ;","x_google_ignoreList":[0,1]}
|
|
1
|
+
{"version":3,"file":"custom-element.js","sources":["../node_modules/ftdomdelegate/main.js","../../node_modules/@financial-times/o-tracking/src/javascript/utils.js","../src/logger.ts","../src/get-trace.ts","../src/tracking.ts","../src/path.ts","../src/errors.ts","../src/events.ts","../src/util.ts","../src/environment.ts","../src/custom-code-component.ts"],"sourcesContent":["/**\n * DOM event delegator\n *\n * The delegator will listen\n * for events that bubble up\n * to the root node.\n *\n * @constructor\n * @param {Node|string} [root] The root node or a selector string matching the root node\n */\nfunction Delegate(root) {\n\n\t/**\n\t * Maintain a map of listener\n\t * lists, keyed by event name.\n\t *\n\t * @type Object\n\t */\n\tthis.listenerMap = [{}, {}];\n\tif (root) {\n\t\tthis.root(root);\n\t}\n\n\t/** @type function() */\n\tthis.handle = Delegate.prototype.handle.bind(this);\n\n\t// Cache of event listeners removed during an event cycle\n\tthis._removedListeners = [];\n}\n\n/**\n * Start listening for events\n * on the provided DOM element\n *\n * @param {Node|string} [root] The root node or a selector string matching the root node\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.root = function (root) {\n\tconst listenerMap = this.listenerMap;\n\tlet eventType;\n\n\t// Remove master event listeners\n\tif (this.rootElement) {\n\t\tfor (eventType in listenerMap[1]) {\n\t\t\tif (listenerMap[1].hasOwnProperty(eventType)) {\n\t\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, true);\n\t\t\t}\n\t\t}\n\t\tfor (eventType in listenerMap[0]) {\n\t\t\tif (listenerMap[0].hasOwnProperty(eventType)) {\n\t\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, false);\n\t\t\t}\n\t\t}\n\t}\n\n\t// If no root or root is not\n\t// a dom node, then remove internal\n\t// root reference and exit here\n\tif (!root || !root.addEventListener) {\n\t\tif (this.rootElement) {\n\t\t\tdelete this.rootElement;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * The root node at which\n\t * listeners are attached.\n\t *\n\t * @type Node\n\t */\n\tthis.rootElement = root;\n\n\t// Set up master event listeners\n\tfor (eventType in listenerMap[1]) {\n\t\tif (listenerMap[1].hasOwnProperty(eventType)) {\n\t\t\tthis.rootElement.addEventListener(eventType, this.handle, true);\n\t\t}\n\t}\n\tfor (eventType in listenerMap[0]) {\n\t\tif (listenerMap[0].hasOwnProperty(eventType)) {\n\t\t\tthis.rootElement.addEventListener(eventType, this.handle, false);\n\t\t}\n\t}\n\n\treturn this;\n};\n\n/**\n * @param {string} eventType\n * @returns boolean\n */\nDelegate.prototype.captureForType = function (eventType) {\n\treturn ['blur', 'error', 'focus', 'load', 'resize', 'scroll'].indexOf(eventType) !== -1;\n};\n\n/**\n * Attach a handler to one\n * event for all elements\n * that match the selector,\n * now or in the future\n *\n * The handler function receives\n * three arguments: the DOM event\n * object, the node that matched\n * the selector while the event\n * was bubbling and a reference\n * to itself. Within the handler,\n * 'this' is equal to the second\n * argument.\n *\n * The node that actually received\n * the event can be accessed via\n * 'event.target'.\n *\n * @param {string} eventType Listen for these events\n * @param {string|undefined} selector Only handle events on elements matching this selector, if undefined match root element\n * @param {function()} handler Handler function - event data passed here will be in event.data\n * @param {boolean} [useCapture] see 'useCapture' in <https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener>\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.on = function (eventType, selector, handler, useCapture) {\n\tlet root;\n\tlet listenerMap;\n\tlet matcher;\n\tlet matcherParam;\n\n\tif (!eventType) {\n\t\tthrow new TypeError('Invalid event type: ' + eventType);\n\t}\n\n\t// handler can be passed as\n\t// the second or third argument\n\tif (typeof selector === 'function') {\n\t\tuseCapture = handler;\n\t\thandler = selector;\n\t\tselector = null;\n\t}\n\n\t// Fallback to sensible defaults\n\t// if useCapture not set\n\tif (useCapture === undefined) {\n\t\tuseCapture = this.captureForType(eventType);\n\t}\n\n\tif (typeof handler !== 'function') {\n\t\tthrow new TypeError('Handler must be a type of Function');\n\t}\n\n\troot = this.rootElement;\n\tlistenerMap = this.listenerMap[useCapture ? 1 : 0];\n\n\t// Add master handler for type if not created yet\n\tif (!listenerMap[eventType]) {\n\t\tif (root) {\n\t\t\troot.addEventListener(eventType, this.handle, useCapture);\n\t\t}\n\t\tlistenerMap[eventType] = [];\n\t}\n\n\tif (!selector) {\n\t\tmatcherParam = null;\n\n\t\t// COMPLEX - matchesRoot needs to have access to\n\t\t// this.rootElement, so bind the function to this.\n\t\tmatcher = matchesRoot.bind(this);\n\n\t\t// Compile a matcher for the given selector\n\t} else if (/^[a-z]+$/i.test(selector)) {\n\t\tmatcherParam = selector;\n\t\tmatcher = matchesTag;\n\t} else if (/^#[a-z0-9\\-_]+$/i.test(selector)) {\n\t\tmatcherParam = selector.slice(1);\n\t\tmatcher = matchesId;\n\t} else {\n\t\tmatcherParam = selector;\n\t\tmatcher = Element.prototype.matches;\n\t}\n\n\t// Add to the list of listeners\n\tlistenerMap[eventType].push({\n\t\tselector: selector,\n\t\thandler: handler,\n\t\tmatcher: matcher,\n\t\tmatcherParam: matcherParam\n\t});\n\n\treturn this;\n};\n\n/**\n * Remove an event handler\n * for elements that match\n * the selector, forever\n *\n * @param {string} [eventType] Remove handlers for events matching this type, considering the other parameters\n * @param {string} [selector] If this parameter is omitted, only handlers which match the other two will be removed\n * @param {function()} [handler] If this parameter is omitted, only handlers which match the previous two will be removed\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.off = function (eventType, selector, handler, useCapture) {\n\tlet i;\n\tlet listener;\n\tlet listenerMap;\n\tlet listenerList;\n\tlet singleEventType;\n\n\t// Handler can be passed as\n\t// the second or third argument\n\tif (typeof selector === 'function') {\n\t\tuseCapture = handler;\n\t\thandler = selector;\n\t\tselector = null;\n\t}\n\n\t// If useCapture not set, remove\n\t// all event listeners\n\tif (useCapture === undefined) {\n\t\tthis.off(eventType, selector, handler, true);\n\t\tthis.off(eventType, selector, handler, false);\n\t\treturn this;\n\t}\n\n\tlistenerMap = this.listenerMap[useCapture ? 1 : 0];\n\tif (!eventType) {\n\t\tfor (singleEventType in listenerMap) {\n\t\t\tif (listenerMap.hasOwnProperty(singleEventType)) {\n\t\t\t\tthis.off(singleEventType, selector, handler);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tlistenerList = listenerMap[eventType];\n\tif (!listenerList || !listenerList.length) {\n\t\treturn this;\n\t}\n\n\t// Remove only parameter matches\n\t// if specified\n\tfor (i = listenerList.length - 1; i >= 0; i--) {\n\t\tlistener = listenerList[i];\n\n\t\tif ((!selector || selector === listener.selector) && (!handler || handler === listener.handler)) {\n\t\t\tthis._removedListeners.push(listener);\n\t\t\tlistenerList.splice(i, 1);\n\t\t}\n\t}\n\n\t// All listeners removed\n\tif (!listenerList.length) {\n\t\tdelete listenerMap[eventType];\n\n\t\t// Remove the main handler\n\t\tif (this.rootElement) {\n\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, useCapture);\n\t\t}\n\t}\n\n\treturn this;\n};\n\n\n/**\n * Handle an arbitrary event.\n *\n * @param {Event} event\n */\nDelegate.prototype.handle = function (event) {\n\tlet i;\n\tlet l;\n\tconst type = event.type;\n\tlet root;\n\tlet phase;\n\tlet listener;\n\tlet returned;\n\tlet listenerList = [];\n\tlet target;\n\tconst eventIgnore = 'ftLabsDelegateIgnore';\n\n\tif (event[eventIgnore] === true) {\n\t\treturn;\n\t}\n\n\ttarget = event.target;\n\n\t// Hardcode value of Node.TEXT_NODE\n\t// as not defined in IE8\n\tif (target.nodeType === 3) {\n\t\ttarget = target.parentNode;\n\t}\n\n\t// Handle SVG <use> elements in IE\n\tif (target.correspondingUseElement) {\n\t\ttarget = target.correspondingUseElement;\n\t}\n\n\troot = this.rootElement;\n\n\tphase = event.eventPhase || (event.target !== event.currentTarget ? 3 : 2);\n\n\t// eslint-disable-next-line default-case\n\tswitch (phase) {\n\t\tcase 1: //Event.CAPTURING_PHASE:\n\t\t\tlistenerList = this.listenerMap[1][type];\n\t\t\tbreak;\n\t\tcase 2: //Event.AT_TARGET:\n\t\t\tif (this.listenerMap[0] && this.listenerMap[0][type]) {\n\t\t\t\tlistenerList = listenerList.concat(this.listenerMap[0][type]);\n\t\t\t}\n\t\t\tif (this.listenerMap[1] && this.listenerMap[1][type]) {\n\t\t\t\tlistenerList = listenerList.concat(this.listenerMap[1][type]);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 3: //Event.BUBBLING_PHASE:\n\t\t\tlistenerList = this.listenerMap[0][type];\n\t\t\tbreak;\n\t}\n\n\tlet toFire = [];\n\n\t// Need to continuously check\n\t// that the specific list is\n\t// still populated in case one\n\t// of the callbacks actually\n\t// causes the list to be destroyed.\n\tl = listenerList.length;\n\twhile (target && l) {\n\t\tfor (i = 0; i < l; i++) {\n\t\t\tlistener = listenerList[i];\n\n\t\t\t// Bail from this loop if\n\t\t\t// the length changed and\n\t\t\t// no more listeners are\n\t\t\t// defined between i and l.\n\t\t\tif (!listener) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\ttarget.tagName &&\n\t\t\t\t[\"button\", \"input\", \"select\", \"textarea\"].indexOf(target.tagName.toLowerCase()) > -1 &&\n\t\t\t\ttarget.hasAttribute(\"disabled\")\n\t\t\t) {\n\t\t\t\t// Remove things that have previously fired\n\t\t\t\ttoFire = [];\n\t\t\t}\n\t\t\t// Check for match and fire\n\t\t\t// the event if there's one\n\t\t\t//\n\t\t\t// TODO:MCG:20120117: Need a way\n\t\t\t// to check if event#stopImmediatePropagation\n\t\t\t// was called. If so, break both loops.\n\t\t\telse if (listener.matcher.call(target, listener.matcherParam, target)) {\n\t\t\t\ttoFire.push([event, target, listener]);\n\t\t\t}\n\t\t}\n\n\t\t// TODO:MCG:20120117: Need a way to\n\t\t// check if event#stopPropagation\n\t\t// was called. If so, break looping\n\t\t// through the DOM. Stop if the\n\t\t// delegation root has been reached\n\t\tif (target === root) {\n\t\t\tbreak;\n\t\t}\n\n\t\tl = listenerList.length;\n\n\t\t// Fall back to parentNode since SVG children have no parentElement in IE\n\t\ttarget = target.parentElement || target.parentNode;\n\n\t\t// Do not traverse up to document root when using parentNode, though\n\t\tif (target instanceof HTMLDocument) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tlet ret;\n\n\tfor (i = 0; i < toFire.length; i++) {\n\t\t// Has it been removed during while the event function was fired\n\t\tif (this._removedListeners.indexOf(toFire[i][2]) > -1) {\n\t\t\tcontinue;\n\t\t}\n\t\treturned = this.fire.apply(this, toFire[i]);\n\n\t\t// Stop propagation to subsequent\n\t\t// callbacks if the callback returned\n\t\t// false\n\t\tif (returned === false) {\n\t\t\ttoFire[i][0][eventIgnore] = true;\n\t\t\ttoFire[i][0].preventDefault();\n\t\t\tret = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn ret;\n};\n\n/**\n * Fire a listener on a target.\n *\n * @param {Event} event\n * @param {Node} target\n * @param {Object} listener\n * @returns {boolean}\n */\nDelegate.prototype.fire = function (event, target, listener) {\n\treturn listener.handler.call(target, event, target);\n};\n\n/**\n * Check whether an element\n * matches a tag selector.\n *\n * Tags are NOT case-sensitive,\n * except in XML (and XML-based\n * languages such as XHTML).\n *\n * @param {string} tagName The tag name to test against\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesTag(tagName, element) {\n\treturn tagName.toLowerCase() === element.tagName.toLowerCase();\n}\n\n/**\n * Check whether an element\n * matches the root.\n *\n * @param {?String} selector In this case this is always passed through as null and not used\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesRoot(selector, element) {\n\tif (this.rootElement === window) {\n\t\treturn (\n\t\t\t// Match the outer document (dispatched from document)\n\t\t\telement === document ||\n\t\t\t// The <html> element (dispatched from document.body or document.documentElement)\n\t\t\telement === document.documentElement ||\n\t\t\t// Or the window itself (dispatched from window)\n\t\t\telement === window\n\t\t);\n\t}\n\treturn this.rootElement === element;\n}\n\n/**\n * Check whether the ID of\n * the element in 'this'\n * matches the given ID.\n *\n * IDs are case-sensitive.\n *\n * @param {string} id The ID to test against\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesId(id, element) {\n\treturn id === element.id;\n}\n\n/**\n * Short hand for off()\n * and root(), ie both\n * with no parameters\n *\n * @return void\n */\nDelegate.prototype.destroy = function () {\n\tthis.off();\n\tthis.root();\n};\n\nexport default Delegate;\n","/**\n * Shared 'internal' scope.\n */\nimport {get} from './core/settings.js';\n\n/**\n * CUID Generator\n */\nimport {api as cuid} from '../libs/browser-cuid.js';\n\n/**\n * Record of callbacks to call when a page is tracked.\n */\nconst page_callbacks = [];\n\n/**\n * Log messages to the browser console. Requires 'log' to be set on init.\n *\n * @param {*} args items to log\n * @returns {void}\n */\nfunction log(...args) {\n\tif (get('config').test && window.console) {\n\t\tfor (const arg of args) {\n\t\t\twindow.console.log(arg);\n\t\t}\n\t}\n}\n\n/**\n * Creates a logging function that logs messages to the console with a specified namespace.\n *\n * @function namedLog\n * @param {string} namespace - The namespace to be prefixed to each log message.\n * @returns {function} A function that logs messages to the console with the given namespace if the configuration allows.\n *\n * @example\n * const log = namedLog('MyNamespace');\n * log('This is a message'); \n * // Output: [MyNamespace]: This is a message\n */\nfunction namedLog(namespace) {\n\treturn function(...args) {\n\t\tif(get('config').test && window.console) {\n\t\t\twindow.console.log(`%c[${namespace}]:`, 'color: teal', ...args)\n\t\t}\n\t}\n}\n\n/**\n * Tests if variable is a certain type. Defaults to check for undefined if no type specified.\n *\n * @param {*} variable - The variable to check.\n * @param {string=} type - The type to test for. Defaults to undefined.\n *\n * @returns {boolean} - The answer for if the variable is of type.\n */\nfunction is(variable, type = 'undefined') {\n\treturn typeof variable === type;\n}\n\n/**\n * Merge objects together. Will remove undefined and null values.\n *\n * @param {object} target - The original object to merge in to.\n * @param {object} options - The object to merge into the target. If omitted, will merge target into a new empty Object.\n *\n * @returns {object} The merged object.\n */\nfunction merge(target, options) {\n\tif (!options) {\n\t\toptions = target;\n\t\ttarget = {};\n\t}\n\n\tlet name;\n\tlet src;\n\tlet copy;\n\n\t/* jshint -W089 */\n\t/* eslint guard-for-in: 0 */\n\tfor (name in options) {\n\t\tsrc = target[name];\n\t\tcopy = options[name];\n\n\t\t// Prevent never-ending loop\n\t\tif (target === copy) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Gets rid of missing values too\n\t\tif (typeof copy !== 'undefined' && copy !== null) {\n\t\t\ttarget[name] = src === Object(src) && !is(src, 'function') ? merge(src, copy) : copy;\n\t\t}\n\t}\n\t/* jshint +W089 */\n\t/* jslint forin:true */\n\n\treturn target;\n}\n\n/**\n * URL encode a string.\n *\n * @param {string} str - The string to be encoded.\n * @returns {string} The encoded string.\n */\nfunction encode(str) {\n\tif (window.encodeURIComponent) {\n\t\treturn window.encodeURIComponent(str);\n\t} else {\n\t\treturn window.escape(str);\n\t}\n}\n\n/**\n * URL decode a string.\n *\n * @param {string} str - The string to be decoded.\n * @returns {string} The decoded string.\n */\nfunction decode(str) {\n\tif (window.decodeURIComponent) {\n\t\treturn window.decodeURIComponent(str);\n\t} else {\n\t\treturn window.unescape(str);\n\t}\n}\n\n/**\n * Utility to add event listeners.\n *\n * @param {Element} element\n * @param {string} event\n * @param {EventListenerOrEventListenerObject} listener\n * @returns {void}\n */\nfunction addEvent(element, event, listener) {\n\tif (element.addEventListener) {\n\t\telement.addEventListener(event, listener, false);\n\t} else {\n\t\telement.attachEvent('on' + event, listener);\n\t}\n}\n\n/**\n * Utility for dispatching custom events from window\n *\n * @param {string} namespace\n * @param {string} eventType\n * @param {object} detail\n * @returns {void}\n */\nfunction broadcast(namespace, eventType, detail) {\n\tdetail = detail || {};\n\ttry {\n\t\twindow.dispatchEvent(new CustomEvent(namespace + '.' + eventType, {\n\t\t\tdetail: detail,\n\t\t\tbubbles: true\n\t\t}));\n\t} catch (error) {\n\t\t// empty\n\t}\n}\n\n/**\n * Listen for page tracking requests.\n *\n * @param {Function} cb - The callback to be called whenever a page is tracked.\n * @returns {void}\n */\nfunction onPage(cb) {\n\tif (is(cb, 'function') && !page_callbacks.includes(cb)) {\n\t\tpage_callbacks.push(cb);\n\t}\n}\n\n/**\n * Trigger the 'page' listeners.\n *\n * @returns {void}\n */\nfunction triggerPage() {\n\tfor (let i = 0; i < page_callbacks.length; i++) {\n\t\tpage_callbacks[i]();\n\t}\n}\n\n/**\n * Get a value from document.cookie matching the first match of the regexp you supply\n *\n * @param {RegExp} matcher - The Regex to match with\n * @returns {string} - The vale from the cookie\n */\nfunction getValueFromCookie(matcher) {\n\treturn document.cookie.match(matcher) && RegExp.$1 !== '' && RegExp.$1 !== 'null' ? RegExp.$1 : null;\n}\n\n/**\n * Filter an object to only have the properties which are listed in the `allowlist` parameter.\n *\n * @param {object} objectToFilter - An object whose props need to be filtered\n * @param {Array} allowedPropertyNames - The list of props to allow\n * @returns {object} An object containing only the allowed props\n */\nfunction filterProperties (objectToFilter, allowedPropertyNames) {\n\tconst filteredObject = {};\n\tfor (const allowedName of allowedPropertyNames) {\n\t\tif (objectToFilter[allowedName]) {\n\t\t\tfilteredObject[allowedName] = objectToFilter[allowedName];\n\t\t}\n\t}\n\treturn filteredObject;\n}\n\n/**\n * Trim strings\n *\n * @param {string} str - The string to trim.\n * @returns {string} The trimmed string.\n */\nfunction sanitise (str) {\n\treturn typeof str === 'string' ? str.trim() : str;\n}\n\n/**\n * Assign the subject value if the target properties are undefined\n *\n * @param {object} subject - assign the value\n * @param {object} target - be assigned the value\n * @returns {void}\n */\nfunction assignIfUndefined (subject, target) {\n\tfor (const prop in subject) {\n\t\tif (!target[prop]) {\n\t\t\ttarget[prop] = subject[prop];\n\t\t} else {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(`You can't set a custom property called ${prop}`);\n\t\t}\n\t}\n}\n\n\n/**\n * Identify circular references in 'object', and replace them with a string representation\n * of the reference. Returns a succesfully serialised JSON string, and a list of circular\n * references which were removed.\n * \n * Inspired by https://github.com/sindresorhus/safe-stringify and \n * https://github.com/sindresorhus/decircular\n *\n * @param {*} object The object we want to stringify, and search within for circular references\n * @returns {Object: {jsonString: string, warnings: array}} The stringified object, and a warnings for each circular reference which was removed\n */\nfunction removeCircularReferences(object) {\n\n\t// WeakMaps release memory when all references are garbage-collected\n\tconst circularReferences = new WeakMap();\n\tconst paths = new WeakMap();\n\n\tconst warnings = [];\n\n\tfunction getPathFragment(parent, key) {\n\t\tif (!key) {\n\t\t\treturn '$';\n\t\t}\n\n\t\tif (Array.isArray(parent)) {\n\t\t\treturn `[${key}]`;\n\t\t}\n\n\t\treturn `.${key}`;\n\t}\n\n\tfunction formatCircularReferencesWarning(references) {\n\t\tconst paths = references.map(path => '`' + path.join('') + '`');\n\t\treturn 'Circular reference between ' + paths.join(' AND ');\n\t}\n\n\tfunction replacer(key, value) {\n\t\t// Scalars don't need to be inspected as they can't contain circular references\n\t\tif (!(value !== null && typeof value === 'object')) {\n\t\t\treturn value\n\t\t}\n\n\t\t// Record the path from the root ($) to the current object (value)\n\t\t// in order to print helpful circular reference warnings.\n\t\tconst path = [...paths.get(this) || [], getPathFragment(this, key)];\n\t\tpaths.set(value, path);\n\n\t\t// If a reference to the current value is already in the list, we have\n\t\t// a circular reference. Add the current value to the list along with its path,\n\t\t// and return a useful error string rather than the unserialisable value.\n\t\tif (circularReferences.has(value)) {\n\t\t\tconst references = [...circularReferences.get(value), path];\n\t\t\tcircularReferences.set(value, references);\n\t\t\tconst warning = formatCircularReferencesWarning(references);\n\t\t\twarnings.push(warning);\n\t\t\treturn warning;\n\t\t}\n\n\t\t// This is the first time we've seen the current value in this branch \n\t\t// of the object. Record its path from the object root.\n\t\tcircularReferences.set(value, [path]);\n\n\t\t// Recurse into the value to proactively find circular references\n\t\t// before encountering a loop.\n\t\tconst newValue = Array.isArray(value) ? [] : {};\n\t\tfor (const [k, v] of Object.entries(value)) {\n\t\t\tnewValue[k] = replacer.call(value, k, v);\n\t\t}\n\n\t\t// All circular references to this object will have been identified,\n\t\t// so remove it from the list.\n\t\tcircularReferences.delete(value);\n\n\t\t// This branch of the object can now be safely serialised to a JSON string\n\t\treturn newValue;\n\t}\n\n\tconst jsonString = JSON.stringify(object, replacer);\n\treturn {jsonString, warnings};\n}\n\n\n/**\n * Stringify an object to JSON, removing any circular references. When circular references\n * are found, an error is thrown in a new event loop so that global error handlers can report it.\n *\n * @param {*} object The object we want to stringify, and search within for circular references\n * @returns {string} The safely stringified JSON string\n */\nfunction safelyStringifyJson(object) {\n\n\t// JSON.stringify throws on two cases:\n\t// - value contains a circular reference\n\t// - A BigInt value is encountered\n\t// Circular references are a real possibility in the way o-tracking is called (and saves a queue of \n\t// messages in a store), so we need to handle those gracefully.\n\t// \n\t// However, for performance reasons, we always attempt to do a basic JSON.stringify() first. The \n\t// recursion involved in removeCircularReferences() makes it about 20x slower to stringify a basic payload. \n\t// This performance hit will be exacerbated on slow devices (e.g. old Android phones) with lots of queued offline events.\n\ttry {\n\t\treturn JSON.stringify(object);\n\n\t// NB: error is discarded - we have more work to do in order to throw a useful message\n\t} catch (error) {\n\t\n\t\tconst {jsonString, warnings} = removeCircularReferences(object);\n\t\n\t\tif (warnings.length) {\n\t\t\t// Throw in a new event loop, as we always want to return JSON so the tracking payload is sent\n\t\t\tsetTimeout(() => {\n\t\t\t\tconst errorMessage = \"AssertionError: o-tracking does not support circular references in the analytics data.\\n\" +\n\t\t\t\t\"Please remove the circular references in the data.\\n\" +\n\t\t\t\t\"Here are the paths in the data which are circular:\\n\" +\n\t\t\t\twarnings.join('\\n');\n\t\t\t\tthrow new Error(errorMessage);\n\t\t\t});\n\t\t}\n\t\n\t\treturn jsonString;\n\t}\n\n\n};\n\n/**\n * Find out whether two objects are deeply equal to each other.\n *\n * @param {*} a\n * @param {*} b\n * @returns {boolean} - true if the two arguments are deeply equal\n */\nfunction isDeepEqual(a, b) {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\tif (\n\t\ta &&\n\t\tb &&\n\t\ttypeof a === \"object\" &&\n\t\ttypeof b === \"object\"\n\t) {\n\t\tif (a.constructor !== b.constructor) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (Array.isArray(a)) {\n\t\t\tconst length = a.length;\n\t\t\tif (length !== b.length) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\t\tif (!isDeepEqual(a[i], b[i])) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tif (a.constructor === RegExp) {\n\t\t\treturn (\n\t\t\t\ta.source === b.source && a.flags === b.flags\n\t\t\t);\n\t\t}\n\t\tif (a.valueOf !== Object.prototype.valueOf) {\n\t\t\treturn a.valueOf() === b.valueOf();\n\t\t}\n\t\tif (a.toString !== Object.prototype.toString) {\n\t\t\treturn a.toString() === b.toString();\n\t\t}\n\n\t\tconst keys = Object.keys(a);\n\t\tconst length = keys.length;\n\t\tif (length !== Object.keys(b).length) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\tif (!Object.prototype.hasOwnProperty.call(b, keys[i])) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\tconst key = keys[i];\n\n\t\t\tif (!isDeepEqual(a[key], b[key])) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n}\n\nexport {\n\tlog,\n\tnamedLog,\n\tis,\n\tis as isUndefined,\n\tmerge,\n\tencode,\n\tdecode,\n\tcuid as guid,\n\taddEvent,\n\tbroadcast,\n\tonPage,\n\ttriggerPage,\n\tgetValueFromCookie,\n\tsanitise,\n\tassignIfUndefined,\n\tfilterProperties,\n\tremoveCircularReferences,\n\tsafelyStringifyJson,\n\tisDeepEqual\n};\n","import { ComponentPath } from \"./path\";\n\nexport const LogLevel = Object.freeze({\n DEBUG: 0,\n INFO: 1,\n WARN: 2,\n ERROR: 3,\n TEST: 4,\n DEFAULT: 2,\n});\n\nconst LOG_PREFIX = \"CCC:\";\n\nexport function convertStringLogLevel(value: string | null) {\n const level = value?.toLowerCase();\n\n if (level === \"debug\") {\n return LogLevel.DEBUG;\n }\n\n if (level === \"info\") {\n return LogLevel.INFO;\n }\n\n if (level === \"warn\") {\n return LogLevel.WARN;\n }\n\n if (level === \"error\") {\n return LogLevel.ERROR;\n }\n\n if (level === \"test\") {\n return LogLevel.TEST;\n }\n\n return LogLevel.DEFAULT;\n}\n\nexport class Logger {\n public level: number;\n public component?: ComponentPath;\n\n constructor(\n {\n level = LogLevel.DEFAULT,\n component,\n }: { level: number; component?: ComponentPath } = {\n level: LogLevel.DEFAULT,\n }\n ) {\n this.level = localStorage.getItem(\"CCC_LOG_LEVEL\")\n ? convertStringLogLevel(localStorage.getItem(\"CCC_LOG_LEVEL\"))\n : level;\n this.component = component;\n }\n\n debug(...args: any[]) {\n if (this.level <= LogLevel.DEBUG) {\n console.info(LOG_PREFIX, ...args, this.component);\n }\n }\n\n log = this.debug;\n\n info(...args: any[]) {\n if (this.level <= LogLevel.INFO) {\n console.info(LOG_PREFIX, ...args, this.component);\n }\n }\n\n warn(...args: any[]) {\n if (this.level <= LogLevel.WARN) {\n console.warn(LOG_PREFIX, ...args, this.component);\n }\n }\n\n error(...args: any[]) {\n if (this.level <= LogLevel.ERROR) {\n console.error(LOG_PREFIX, ...args, this.component);\n }\n }\n\n setLogLevel(level: string | number | null) {\n if (localStorage.getItem(\"CCC_LOG_LEVEL\")) {\n this.level = convertStringLogLevel(localStorage.getItem(\"CCC_LOG_LEVEL\"));\n } else if (typeof level === \"number\") {\n this.level = level;\n } else {\n this.level = convertStringLogLevel(level);\n }\n }\n}\n","// Trace the element and all of its parents, collecting properties as we go\nimport {\n sanitise,\n assignIfUndefined,\n} from \"@financial-times/o-tracking/src/javascript/utils\";\n\ntype PropMap = { [k: string]: any };\n// For a given container element, get the number of elements that match the\n// original element (siblings); and the index of the original element (position).\nconst getSiblingsAndPosition = (\n el: Element | null,\n originalEl: Element,\n selector: string\n) => {\n const siblings = Array.from(el?.querySelectorAll(selector) ?? []);\n const position = siblings.findIndex((item) => item === originalEl);\n if (position === -1) {\n return;\n }\n return {\n siblings: siblings.length,\n position,\n };\n};\n\nconst elementPropertiesToCollect = [\n \"nodeName\",\n \"className\",\n \"id\",\n \"href\",\n \"text\",\n \"role\",\n];\n// Get all (sanitised) properties of a given element.\nconst getAllElementProperties = (element: any) => {\n const properties: PropMap = {};\n for (const property of elementPropertiesToCollect) {\n const value =\n element[property] ||\n element.getAttribute(property) ||\n element.hasAttribute(property);\n if (value !== undefined) {\n if (typeof value === \"boolean\") {\n properties[property] = value;\n } else {\n properties[property] = sanitise(value);\n }\n }\n }\n\n return properties;\n};\n\nconst parseRawValue = (rawValue: string) => {\n try {\n const parsedValue = JSON.parse(rawValue);\n const type = Object.prototype.toString.call(parsedValue);\n const isJSON = type === \"[object Object]\" || type === \"[object Array]\";\n\n return [isJSON, parsedValue];\n } catch (error) {\n return [false, null];\n }\n};\n\nconst getAttributeValue = (rawValue: string) => {\n const [isJSON, value] = parseRawValue(rawValue);\n\n return isJSON ? value : rawValue;\n};\n\n// Get some properties of a given element.\nconst getDomPathProps = (attrs: Attr[], props: PropMap) => {\n // Collect any attribute that matches given strings.\n attrs\n .filter((attribute) =>\n attribute.name.match(/^data-trackable|^data-o-|^aria-/i)\n )\n .forEach((attribute) => {\n props[attribute.name] = attribute.value;\n });\n\n return props;\n};\n\n// Get only the custom data-trackable-context-? properties of a given element\nconst getContextProps = (\n attrs: Attr[],\n props: PropMap,\n isOriginalEl: boolean\n) => {\n const customProps: { [k: string]: any } = {};\n\n // for the original element collect properties like className, nodeName\n if (isOriginalEl) {\n elementPropertiesToCollect.forEach((name) => {\n if (typeof props[name] !== \"undefined\" && name !== \"id\") {\n customProps[name] = props[name];\n }\n });\n }\n\n // Collect any attribute that matches given strings.\n attrs\n .filter((attribute) => attribute.name.match(/^data-trackable-context-/i))\n .forEach((attribute) => {\n customProps[attribute.name.replace(\"data-trackable-context-\", \"\")] =\n getAttributeValue(attribute.value);\n });\n\n return customProps;\n};\n\nexport function getTrace(el: Element, rootEl: Element) {\n const originalEl = el;\n const selector = originalEl?.getAttribute(\"data-trackable\")\n ? `[data-trackable=\"${originalEl.getAttribute(\"data-trackable\")}\"]`\n : originalEl?.nodeName;\n const trace = [];\n const customContext = {};\n while (el && el !== rootEl) {\n const props = getAllElementProperties(el);\n const attrs = Array.from(el.attributes);\n let domPathProps = getDomPathProps(attrs, props);\n\n // If the element happens to have a data-trackable attribute, get the siblings\n // and position of the element (relative to the current element).\n if (domPathProps[\"data-trackable\"]) {\n domPathProps = Object.assign(\n domPathProps,\n getSiblingsAndPosition(el, originalEl, selector)\n );\n }\n\n trace.push(domPathProps);\n\n const contextProps = getContextProps(attrs, props, el === originalEl);\n\n assignIfUndefined(contextProps, customContext);\n\n el = el.parentNode as Element;\n }\n return { trace, customContext };\n}\n","import Delegate from \"ftdomdelegate/main\";\n\nimport {\n sanitise,\n assignIfUndefined,\n} from \"@financial-times/o-tracking/src/javascript/utils\";\nimport { Logger } from \"./logger\";\nimport { getTrace } from \"./get-trace\";\n\nconst eventPropertiesToCollect = [\"ctrlKey\", \"altKey\", \"shiftKey\", \"metaKey\"];\n\nclass Tracking {\n cccId: string;\n cccName: string;\n subtype: string;\n teamName: string;\n shadowRoot: ShadowRoot | null;\n category: string;\n elements: string | string[];\n isInitialised: boolean;\n log: Logger;\n\n constructor({\n id = \"00000000-0000-0000-0000-000000000000\",\n name = \"ccc-component\",\n subtype = \"interactive\",\n teamName = \"djd\",\n shadowRoot = null,\n category = \"cta\",\n elements = 'a, button, input, [role=\"button\"]',\n logger,\n }: {\n id?: string;\n name: string;\n subtype: string;\n teamName?: string;\n shadowRoot: ShadowRoot | null;\n category?: string;\n elements?: string | string[];\n logger: Logger;\n }) {\n this.cccId = id;\n this.cccName = name;\n this.subtype = subtype;\n this.teamName = teamName;\n this.shadowRoot = shadowRoot;\n this.category = category;\n this.elements = elements;\n this.isInitialised = false;\n this.log = logger ?? new Logger();\n }\n\n // Get properties for the event (as opposed to properties of the clicked element)\n getEventProperties(event: any) {\n const eventProperties: { [k: string]: any } = {};\n for (const property of eventPropertiesToCollect) {\n if (event[property]) {\n try {\n eventProperties[property] = sanitise(event[property]);\n } catch (e) {\n this.log.info(e);\n }\n }\n }\n return eventProperties;\n }\n\n // Controller for handling click events\n handleClickEvent(\n eventData: { action: string; category: string },\n root: Element\n ) {\n return (clickEvent: Event, clickElement: HTMLElement) => {\n const context: any = this.getEventProperties(clickEvent);\n const { trace, customContext } = getTrace(clickElement, root);\n context.custom =\n clickElement.dataset && clickElement.dataset.custom\n ? JSON.parse(clickElement.dataset.custom)\n : null;\n context.domPathTokens = trace;\n context.component = {\n id: this.cccId,\n name: this.cccName,\n type: \"custom-code-component\",\n subtype: this.subtype,\n };\n context.teamName = this.teamName;\n context.url = document.URL;\n\n assignIfUndefined(customContext, context);\n\n context.method = \"ftCustomAnalytics\";\n eventData = { ...eventData, ...context };\n\n // send spoor event\n document.body.dispatchEvent(\n new CustomEvent(\"oTracking.event\", {\n detail: eventData,\n bubbles: true,\n composed: true,\n })\n );\n };\n }\n\n sendSpoorEvent(triggerAction: any, extraDetail: any) {\n const eventData = {\n category: \"component\",\n action: \"act\",\n component: {\n id: this.cccId,\n name: this.cccName,\n type: \"custom-code-component\",\n subtype: this.subtype,\n },\n teamName: this.teamName,\n trigger_action: triggerAction,\n custom: extraDetail,\n method: \"ftCustomAnalytics\",\n };\n\n // send spoor event\n document.body.dispatchEvent(\n new CustomEvent(\"oTracking.event\", {\n detail: eventData,\n bubbles: true,\n composed: true,\n })\n );\n }\n\n init(id: string) {\n if (!this.isInitialised) {\n this.isInitialised = true;\n this.cccId = id ? id : this.cccId;\n\n const eventData = {\n action: \"click\",\n category: this.category,\n };\n\n const root = this.shadowRoot?.querySelector(\"[data-component-root]\");\n\n if (root) {\n const shadowDelegate = new Delegate(root);\n shadowDelegate.on(\n \"click\",\n this.elements,\n this.handleClickEvent(eventData, root),\n true\n );\n }\n }\n }\n}\n\nexport default Tracking;\n","import { CCCError } from \"./errors\";\n\nexport type ComponentPathType = {\n org: string;\n repo: string;\n name: string;\n versionRange: string;\n};\nexport class ComponentPath {\n org: string = \"local\";\n repo: string = \"dev\";\n name: string;\n versionRange: string;\n\n constructor(path?: ComponentPathType | string) {\n const { org, repo, name, versionRange } = isValidComponentPathObject(path)\n ? path\n : ComponentPath.fromString(path);\n if (org) this.org = org;\n if (repo) this.repo = repo;\n this.name = name;\n this.versionRange = versionRange;\n }\n\n set path(path: ComponentPathType | string) {\n const { org, repo, name, versionRange } = isValidComponentPathObject(path)\n ? path\n : ComponentPath.fromString(path);\n this.org = org;\n this.repo = repo;\n this.name = name;\n this.versionRange = versionRange;\n }\n\n get path(): string {\n return `${this.org}/${this.repo}@${this.versionRange}/${this.name}`;\n }\n\n get isValid(): boolean {\n return [this.org, this.repo, this.name].every(\n (value) => value !== \"unknown\"\n );\n }\n\n toString(): string {\n return this.path;\n }\n\n static fromString(p?: string | null, v?: string | null): ComponentPath {\n const path = p ?? \"unknown/unknown/unknown\";\n\n const [name, repo, org] = path\n .replace(/@[^\\/]+/, \"\")\n .split(\"/\")\n .reverse();\n\n const versionRange =\n v ??\n path\n .match(/@[^\\/]+/)\n ?.toString()\n .replace(\"@\", \"\") ??\n \"unknown\";\n\n if (repo && !versionRange) throw new CCCError(\"No version specified\");\n\n return new ComponentPath({ org, repo, name, versionRange });\n }\n}\n\nexport type DetailType = {\n component: ComponentPath;\n source?: string;\n cause?: string;\n error?: Error;\n};\n\nexport function isValidComponentPathObject(\n value: unknown\n): value is ComponentPathType {\n if (typeof value === \"object\" && value !== null) {\n return \"org\" in value && \"repo\" in value && \"name\" in value;\n }\n\n return false;\n}\n","/**\n * This is the base CCC component error class. These are raised when the component being loaded errors\n */\n\nimport { ComponentPath, DetailType, isValidComponentPathObject } from \"./path\";\n\nexport class CCCError extends Error {\n component: ComponentPath | null;\n source?: string;\n errors?: Error[];\n constructor(message: string | null, detail?: DetailType) {\n if (!detail && message) {\n super(message);\n this.component = null;\n } else if (typeof detail?.component === \"string\") {\n super(\n message ??\n `${detail.cause ?? \"Unknown error\"} in ${detail.component} imported from ${detail.source ?? \"an undefined source\"}.`\n );\n\n this.component = ComponentPath.fromString(detail.component);\n } else if (isValidComponentPathObject(detail?.component)) {\n super(\n message ??\n `${detail.cause ?? \"Unknown error\"} in ${detail.component.org}/${detail.component.repo}/${detail.component.name}@${detail.component.versionRange} imported from ${detail.source ?? \"an undefined source\"}.`\n );\n this.component = new ComponentPath(detail.component);\n } else {\n super(\n `${detail?.cause ?? \"Unknown error\"} in unknown component imported from ${detail?.source ?? \"unknown source\"}.`\n );\n this.component = null;\n }\n\n this.source = detail?.source ?? \"unknown source\";\n this.errors = [];\n if (detail?.error) {\n this.errors?.push(detail?.error);\n }\n if (Error.captureStackTrace) {\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n Error.captureStackTrace(this, CCCError);\n }\n\n this.name = \"CCCError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur during the import of the CCC component app\n */\nexport class CCCImportError extends CCCError {\n constructor(message: string, detail: DetailType) {\n super(message, { ...detail, cause: \"Import error\" });\n this.name = \"CCCImportError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur during the rendering of the CCC component app\n */\nexport class CCCRenderError extends CCCError {\n constructor(message: string, detail: DetailType) {\n super(message, { ...detail, cause: \"Render error\" });\n this.name = \"CCCRenderError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur as a result of the CCC component app timing out\n */\nexport class CCCTimeoutError extends CCCError {\n constructor(detail: DetailType) {\n super(null, { ...detail, cause: \"Timeout error\" });\n this.name = \"CCCTimeoutError\";\n }\n}\n","import { ComponentPath } from \"./path\";\n\nexport class CCCEvent extends Event {\n component: ComponentPath;\n source?: string;\n static eventType = \"ccc:event\";\n\n constructor(\n eventType: string = CCCEvent.eventType,\n detail: { component: ComponentPath; source?: string },\n opts?: EventInit\n ) {\n super(eventType, {\n bubbles: true,\n cancelable: false,\n composed: true,\n ...opts,\n });\n this.component = detail.component;\n this.source = detail.source;\n }\n}\n\nexport class CCCConnectedEvent extends CCCEvent {\n static eventType = \"ccc:connected\";\n\n constructor(\n detail: { component: ComponentPath; source?: string },\n opts?: EventInit\n ) {\n super(CCCConnectedEvent.eventType, detail, opts);\n }\n}\n\nexport class CCCReadyEvent extends CCCEvent {\n static eventType = \"ccc:ready\";\n\n constructor(\n detail: { component: ComponentPath; source?: string },\n opts?: EventInit\n ) {\n super(CCCReadyEvent.eventType, detail, opts);\n }\n}\n\nexport class CCCViewportEvent extends CCCEvent {\n static eventType = \"ccc:viewport\";\n intersecting = false;\n entry?: IntersectionObserverEntry;\n\n constructor(\n detail: {\n component: ComponentPath;\n source?: string;\n intersecting: boolean;\n entry?: IntersectionObserverEntry;\n },\n opts?: EventInit\n ) {\n super(CCCViewportEvent.eventType, detail, opts);\n this.intersecting = detail.intersecting;\n this.entry = detail.entry;\n }\n}\n","/**\n * Used to convert camelCase to kebab-case\n * @param str\n * @returns\n */\nexport const kebabize = (str: string) =>\n str.replace(\n /[A-Z]+(?![a-z])|[A-Z]/g,\n ($, ofs) => (ofs ? \"-\" : \"\") + $.toLowerCase()\n );\n\n/**\n * Checks if the provided host is part of the allowed test environments.\n *\n * @param host - The hostname to check.\n * @returns True if the hostname is a safe test environment, false otherwise.\n */\nexport function isSafeTestEnv(host: string | undefined) {\n return isAllowed([\n 'localhost',\n 'local.ft.com',\n /^.*\\.apps\\.in\\.ft\\.com$/,\n ], host);\n}\n\n/**\n * Checks if the current window location hostname is considered a local environment.\n *\n * @returns True if the hostname is local, false otherwise.\n */\nexport function isLocalEnv() {\n return isAllowed([\n 'localhost',\n 'local.ft.com',\n /^.*\\.in\\.ft\\.com$/,\n ], window.location.hostname);\n}\n\n/**\n * Checks if the current window location host is one of the Spark environments.\n *\n * @returns True if the host is spark.ft.com or spark-staging.ft.com, false otherwise.\n */\nexport function isSparkEnv() {\n return isAllowed([\n 'spark.ft.com',\n 'spark-staging.ft.com',\n ], window.location.host);\n}\n\n/**\n * Checks if the given hostname is in the provided allowlist.\n *\n * @param allowlist - A list of allowed hostnames or RegExp matchers.\n * @param hostname - The hostname to validate.\n * @returns True if the hostname matches any item in the allowlist, false otherwise.\n */\nexport function isAllowed(allowlist: (string|RegExp)[], hostname: string | undefined) {\n if (!hostname) return false;\n return allowlist.some(item => {\n if (typeof item === 'string') {\n return item === hostname;\n }\n return item.test(hostname);\n });\n} \n","import { isLocalEnv, isSafeTestEnv, isSparkEnv } from \"./util\";\n\n/**\n * Assigns a test URL based on the provided testEnv value.\n *\n * @param testEnv - A string indicating test environment setting\n * @returns A `URL` object if valid and safe, or `undefined` if invalid.\n */\nexport function assignTestURL(testEnv: string | null): URL | undefined {\n if (testEnv === null) {\n return;\n }\n\n let testUrl;\n const defaultTestUrl = new URL(\"http://localhost:5173\");\n\n try {\n if (typeof testEnv === \"string\") {\n if (\n (testEnv === \"\" || testEnv.toLowerCase() === \"true\") &&\n isLocalEnv()\n ) {\n testUrl = defaultTestUrl;\n } else {\n const hasProtocol =\n testEnv.startsWith(\"http://\") || testEnv.startsWith(\"https://\");\n testUrl = hasProtocol ? new URL(testEnv) : undefined;\n\n // Prevent script injection\n if (testUrl && !isSafeTestEnv(testUrl?.hostname)) {\n throw new Error(\"Unsafe testing host override\");\n }\n }\n } else if (isSparkEnv()) {\n testUrl = defaultTestUrl;\n }\n } catch (_) {\n return testUrl;\n }\n\n return testUrl;\n}\n\n/**\n * Checks whether the given test component exists on local dev server\n *\n * @param testUrl - The test environment URL to check.\n * @returns A promise that resolves to true if Vite is running, false otherwise.\n */\nexport async function useComponentTestEnv(\n componentName: string,\n testUrl?: URL\n): Promise<boolean> {\n if (!testUrl) {\n return false;\n }\n\n const localDevOnline = fetch(\n new URL(`src/${componentName}/config.yaml`, testUrl),\n {\n method: \"HEAD\",\n }\n )\n .then(() => true)\n .catch(() => false);\n\n return localDevOnline;\n}\n","/**\n * @file\n * Main component definition for custom-code-component\n */\n\nimport type { ContentTree } from \"@financial-times/content-tree\";\nimport { BaseRenderer } from \"../../ccc-sdk/src/renderers/BaseRenderer\";\nimport Tracking from \"./tracking\";\nimport { Logger, LogLevel } from \"./logger\";\nimport {\n CCCError,\n CCCImportError,\n CCCRenderError,\n CCCTimeoutError,\n} from \"./errors\";\nimport { CCCConnectedEvent, CCCReadyEvent, CCCViewportEvent } from \"./events\";\nimport { ComponentPath } from \"./path\";\nimport { kebabize } from \"./util\";\nimport { assignTestURL, useComponentTestEnv } from \"./environment\";\nimport styles from \"./custom-code-component.css?inline\";\n\nexport class FTCustomCodeComponent extends HTMLElement {\n /**\n * The component renderer, resolved from dynamic import\n */\n app?: typeof BaseRenderer.prototype.render;\n\n /**\n * Set whether component is \"open\" or \"closed\". Defaults to \"open\".\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow#mode\n */\n mode: \"closed\" | \"open\" = \"open\";\n\n /**\n * Reserved attributes we don't pass to the child component\n */\n RESERVED_ATTRS = new Set([\n \"iframe\",\n \"path\",\n \"version\",\n \"data-component-props\",\n \"data-asset-type\",\n \"shadow-open\",\n \"env\",\n \"load-timeout\",\n ]);\n\n /**\n * URI of component module for CCC webcomponent to load\n */\n source?: string;\n\n /**\n * OTracking config\n */\n tracking?: Tracking;\n\n /**\n * Alternative base URL, used for testing\n */\n testUrl?: URL;\n\n /**\n * ComponentPath instance with `org`, `repo`, `name` and `versionRange` attributes\n */\n component = new ComponentPath();\n\n /**\n * Logger instance. Set log level using `this.logger.setLogLevel(string|number|null)`.\n */\n logger: Logger;\n \n /**\n * IntersectionObserver that dispatches CCCViewportEvents\n */\n observer = new IntersectionObserver((entries) => {\n this.logger.debug(\"Intersection Observer callback\", { entries });\n entries.forEach((entry) => {\n this.dispatchEvent(\n new CCCViewportEvent({\n component: this.component,\n source: this.source,\n intersecting: entry.isIntersecting,\n entry,\n })\n );\n });\n });\n\n /**\n * Custom Element constructor.\n *\n * n.b., attributes and ShadowDOM aren't available in custom element constructors.\n * Use connectedCallback() and other lifecycle methods if you want to eg. this.getAttribute()\n */\n constructor() {\n super();\n this.logger = new Logger();\n \n const supportsDeclarative =\n HTMLElement.prototype.hasOwnProperty(\"attachInternals\");\n\n try {\n const internals = supportsDeclarative && this.attachInternals();\n } catch (e) {\n this.logger.error(e);\n }\n }\n\n /**\n * connectedCallback() CE lifecycle callback\n *\n * Called whenever a <custom-code-component> element is mounted to the DOM.\n */\n async connectedCallback() {\n try {\n const path = this.getAttribute(\"path\");\n const versionRange = this.getAttribute(\"version\");\n this.component = ComponentPath.fromString(path, versionRange);\n this.logger.component = this.component;\n this.logger.setLogLevel(this.getAttribute(\"log\"));\n this.logger.debug(\"connectedCallback\");\n\n this.app = await this.load();\n await this.mount();\n await this.initTracking();\n } catch (e) {\n if (e instanceof Error) {\n requestAnimationFrame(() => {\n this.emitError(e);\n });\n }\n\n this.unmount(e as Error);\n }\n }\n\n /**\n * Error handler. Decorates errors for easier ingestion.\n *\n * @param error\n */\n emitError(error: Error) {\n this.logger.debug(\"emitError\", { error });\n if (error instanceof CCCError) {\n this.dispatchEvent(\n new ErrorEvent(\"ccc:error\", {\n bubbles: true,\n cancelable: false,\n composed: true,\n error,\n message: error.message,\n })\n );\n } else {\n // Wrap original error with generic CCC error class\n const wrappedError = new CCCError(error.message, {\n component: this.component,\n error: error,\n });\n\n this.dispatchEvent(\n new ErrorEvent(\"ccc:error\", {\n bubbles: true,\n cancelable: false,\n composed: true,\n error: wrappedError,\n message: wrappedError.message,\n })\n );\n }\n }\n\n /**\n * disconnectedCallback() CE lifecycle event.\n *\n * Called when a <custom-code-component> element is removed from DOM.\n */\n disconnectedCallback() {\n this.logger.debug(\"disconnectedCallback\");\n const path = this.getAttribute(\"path\");\n this.logger.info(`<custom-code-component:${path}> disconnected`);\n this.observer.disconnect();\n }\n\n /**\n * MessageChannel interface.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n */\n channel = new MessageChannel();\n\n /**\n * MessageChannel postMessage callback\n *\n * @param e\n */\n onmessage(e?: any) {\n this.logger.debug(\"onmessage\", { event: e });\n }\n\n /**\n * This error handler is called by the child component on e.g. unrecoverable error.\n * It then calls unmount(), which restores the fallback.\n *\n * @param e\n */\n onunmount(e: Error) {\n this.logger.debug(\"onunmount\", { error: e });\n if (e instanceof Error) {\n const renderError = new CCCRenderError(e.message, {\n error: e,\n component: this.component,\n });\n requestAnimationFrame(() => {\n this.emitError(renderError);\n this.unmount(renderError);\n });\n }\n }\n\n /**\n * onready event callback.\n * Called by mount() after kicking off initial component render.\n *\n * @param app\n */\n async onready(app: Promise<void>) {\n try {\n await app;\n this.logger.debug(\"onready\", { app });\n this.dispatchEvent(\n new CCCReadyEvent({\n component: this.component,\n source: this.source,\n })\n );\n\n this.dataset.cccReady = \"true\";\n delete this.dataset.cccError;\n\n this.observer.observe(this);\n } catch (e) {\n this.logger.debug(\"onready caught error\", { error: e });\n if (e instanceof Error) {\n const renderError = new CCCRenderError(e.message, {\n error: e,\n component: this.component,\n });\n requestAnimationFrame(() => {\n this.emitError(renderError);\n this.unmount(renderError);\n });\n }\n }\n }\n\n /**\n * MessageChannel postMessage handler.\n * This can be used for inter-CCC communication.\n * @param event\n */\n postMessage(event: any) {\n this.logger.debug(\"postmessage\", { event });\n this.channel.port1.postMessage(event);\n }\n\n /**\n * Initial mounting behaviour.\n *\n * Attaches ShadowDOM if needed, dispatches ccc:connected event, adds component base styles,\n * generates fallback template element if one doesn't exist already, initialises tracking,\n * then kicks off component rendering. Passes component render promise to onready().\n *\n * @param prerendered\n */\n async mount(prerendered?: ShadowRoot | null) {\n this.logger.debug(\"mount\", prerendered);\n try {\n this.mode =\n this.getAttribute(\"shadow-open\") == \"false\" ? \"closed\" : \"open\";\n if (this.component) {\n if (!this.app) {\n throw new Error(\"CCC mounted without App\");\n }\n\n const ssr = this.shadowRoot !== null;\n const shadow =\n this.shadowRoot ?? this.attachShadow({ mode: this.mode });\n\n this.dispatchEvent(\n new CCCConnectedEvent({\n component: this.component,\n source: this.source,\n })\n );\n // Add global CCC styles if not already present in shadow DOM.\n if (\n !shadow.querySelector('link[href~=\"custom-code-component.css\"]') &&\n !shadow.adoptedStyleSheets.length\n ) {\n if (!window.CCC_LAYOUT_STYLESHEET) {\n this.logger.debug(\"mount generating CCC_LAYOUT_STYLESHEET\");\n window.CCC_LAYOUT_STYLESHEET = new CSSStyleSheet();\n window.CCC_LAYOUT_STYLESHEET.replaceSync(styles);\n }\n shadow.adoptedStyleSheets = [window.CCC_LAYOUT_STYLESHEET];\n }\n\n if (!ssr) {\n this.logger.debug(\"mount generating fallback template\");\n const template = document.createElement(\"template\");\n template.innerHTML = \"<div data-component-root><slot></slot></div>\";\n this.appendChild(template);\n shadow.appendChild(template.content.cloneNode(true));\n }\n\n const data = JSON.parse(this.getAttribute(\"data-component-props\")!);\n\n const extraProps = Object.fromEntries(\n [...this.attributes]\n .filter(\n (attribute) =>\n !this.RESERVED_ATTRS.has(attribute.name) &&\n !attribute.name.startsWith(\"data-\")\n )\n .map((attribute) => [attribute.name, attribute.value])\n );\n\n // Create tracking instance\n this.tracking = new Tracking({\n name: this.component?.toString(),\n subtype: \"interactive\",\n teamName: \"djd\",\n shadowRoot: this.shadowRoot,\n logger: this.logger,\n });\n\n if (!data && Object.keys(extraProps).length > 0) {\n this.logger.warn(\n `CCC ${this.component.toString()}: passing component settings as webcomponent attributes is %cDEPRECATED`,\n \"font-weight: bold\",\n \" and will be removed in v3.\"\n );\n this.logger.warn(\n `Please use the %cdata-component-props`,\n \"text-decoration: underline;\",\n \" attribute instead.\"\n );\n }\n\n const { onmessage, ready = Promise.resolve() } =\n this.app(\n shadow,\n {\n ...(data ?? extraProps),\n log: this.logger,\n data: data ?? extraProps,\n port: this.channel.port2,\n tracking: this.tracking,\n prerendered: !!prerendered,\n children: this.children,\n },\n ssr,\n this.onunmount.bind(this)\n ) || {};\n\n if (onmessage) this.onmessage = onmessage;\n\n this.onready(ready);\n }\n } catch (err) {\n this.logger.info(\n `<custom-code-component> uncaught error during mount from ${this.component?.toString()}`\n );\n this.logger.error(err);\n\n throw err;\n }\n }\n\n /**\n * Called in top-level error handler or by child component on unhandled error.\n * Replace shadow root with either <slot> or template[data-component-fallback]\n * slot on failure\n *\n * @param e\n */\n unmount(e: Error) {\n this.logger.debug(\"unmount\", { error: e });\n\n const template =\n this.querySelector<HTMLTemplateElement>(\n \"template[data-component-fallback]\"\n ) ?? this.querySelector<HTMLTemplateElement>(\"template\");\n\n if (template) {\n this.logger.debug(\"unmount replacing shadowRoot with fallback\");\n this.shadowRoot?.replaceChildren(template.content.cloneNode(true));\n }\n\n if (!this.dataset.cccError)\n this.dataset.cccError = kebabize(e.name.replace(\"CCC\", \"\"));\n\n delete this.dataset.cccReady;\n\n this.observer.disconnect();\n }\n\n /**\n * Asynchronously loads the CCC child component.\n *\n * @returns Promise resolving to component renderer function\n */\n async load() {\n this.logger.debug(\"load\");\n\n if (!this.component.isValid) {\n throw new Error(\"No path found\");\n }\n\n const path = this.getAttribute(\"path\");\n const componentVersionRange = this.getAttribute(\"version\");\n const timeout = Number(this.getAttribute(\"load-timeout\") || 10000);\n const testEnv = this.getAttribute(\"test-env\");\n this.testUrl = assignTestURL(testEnv);\n const isTestEnv = await useComponentTestEnv(\n this.component.name,\n this.testUrl\n );\n\n // id querystring necessary to multiple allow components with the same source (same name and version number) to appear on the page correctly\n const id = this.getAttribute(\"id\");\n\n if (isTestEnv && this.testUrl) {\n this.logger.debug(\"load adding Vite scripts\");\n this.injectViteScripts();\n }\n\n this.source = isTestEnv\n ? `${this.testUrl?.origin}/src/${this.component.name}/index.jsx?id=${id}`\n : `https://www.ft.com/__component/${this.component.org}/${this.component.repo}${\n componentVersionRange ? `@${componentVersionRange}` : \"@latest\"\n }/${this.component.name}/${this.component.name}.js?id=${id}`;\n\n try {\n return await new Promise<typeof BaseRenderer.prototype.render>(\n (resolve, reject) => {\n const to = setTimeout(() => {\n this.logger.error(\"CCC import timeout error\");\n reject(\n new CCCTimeoutError({\n component: this.component!,\n source: this.source,\n })\n );\n }, Number(timeout));\n\n if (this.source) {\n import(/* webpackIgnore: true */ this.source /* @vite-ignore */)\n .then(({ default: componentRenderFunction }) => {\n if (componentRenderFunction) {\n clearTimeout(to);\n resolve(componentRenderFunction);\n } else\n throw new CCCImportError(\n \"No component renderer default export found\",\n {\n component: this.component!,\n source: this.source,\n }\n );\n })\n .catch((e) => {\n clearTimeout(to);\n this.logger.error(e);\n if (e instanceof Error && !(e instanceof CCCImportError)) {\n reject(\n new CCCImportError(e.message, {\n component: this.component!,\n source: this.source,\n })\n );\n } else {\n reject(e);\n }\n });\n } else {\n clearTimeout(to);\n throw new CCCImportError(`Unable to mount ${path}`, {\n component: this.component!,\n source: this.source,\n });\n }\n }\n );\n } catch (err) {\n this.logger.error(\n `<custom-code-component> error during import from ${path}@${componentVersionRange}`\n );\n\n throw err;\n }\n }\n\n /**\n * Initialises OTracking\n */\n initTracking = async () => {\n this.logger.debug(\"initTracking\", { cccId: this.id });\n try {\n this.tracking?.init(this.id);\n } catch (e) {\n const path = this.getAttribute(\"path\");\n const componentVersionRange = this.getAttribute(\"version\");\n this.logger.info(\n `Error initialising tracking on <custom-code-component> ${path}@${componentVersionRange}`\n );\n this.logger.error(e);\n }\n };\n\n /**\n * Injects Vite HMR scripts during dev environment usage\n */\n injectViteScripts = () => {\n if (document.querySelector('script[name=\"ccc-sdk-react-preamble\"]')) return;\n\n const preambleScript = document.createElement(\"script\");\n preambleScript.type = \"module\";\n preambleScript.setAttribute(\"name\", \"ccc-sdk-react-preamble\");\n\n preambleScript.textContent = `\n import RefreshRuntime from \"${this.testUrl?.origin}/@react-refresh\";\n RefreshRuntime.injectIntoGlobalHook(window);\n window.$RefreshReg$ = () => {};\n window.$RefreshSig$ = () => (type) => type;\n window.__vite_plugin_react_preamble_installed__ = true;\n `.trim();\n document.head.appendChild(preambleScript);\n\n const viteClientScript = document.createElement(\"script\");\n viteClientScript.type = \"module\";\n viteClientScript.src = `${this.testUrl?.origin}/@vite/client`;\n document.head.appendChild(viteClientScript);\n };\n\n /**\n * Called whenever the <custom-code-component>'s attributes are changed.\n * Currently only used to dynamically set log level.\n *\n * @param name\n * @param oldValue\n * @param newValue\n */\n attributeChangedCallback(name: string, oldValue: string, newValue: string) {\n this.logger.debug(\"attributeChangedCallback lifecycle method\", {\n name,\n oldValue,\n newValue,\n });\n\n switch (name) {\n case \"log\": {\n this.logger.setLogLevel(newValue);\n }\n }\n }\n}\n\nexport interface CustomCodeComponent extends ContentTree.Node {\n type: \"CustomCodeComponent\";\n path: string;\n versionRange: string;\n altText: string;\n lastModified: string;\n fallbackImage?: ContentTree.Image;\n displayFallbackText: boolean;\n layout: \"in-line\" | \"mid-grid\" | \"full-grid\" | \"full-bleed\";\n /* prettier-ignore */\n attributes: {\n [key: string]: string | boolean | undefined;\n } | { children?: CustomCodeComponent | Array<CustomCodeComponent> };\n}\n\nexport type { FTCustomCodeComponent as CCCHTMLElement };\n"],"names":["Delegate","root","listenerMap","eventType","selector","handler","useCapture","matcher","matcherParam","matchesTag","matchesId","matchesRoot","i","listener","listenerList","singleEventType","event","l","type","phase","returned","target","eventIgnore","toFire","ret","tagName","element","id","sanitise","str","assignIfUndefined","subject","prop","LogLevel","LOG_PREFIX","convertStringLogLevel","value","level","Logger","component","args","getSiblingsAndPosition","el","originalEl","siblings","position","item","elementPropertiesToCollect","getAllElementProperties","properties","property","parseRawValue","rawValue","parsedValue","getAttributeValue","isJSON","getDomPathProps","attrs","props","attribute","getContextProps","isOriginalEl","customProps","name","getTrace","rootEl","trace","customContext","domPathProps","contextProps","eventPropertiesToCollect","Tracking","subtype","teamName","shadowRoot","category","elements","logger","eventProperties","e","eventData","clickEvent","clickElement","context","triggerAction","extraDetail","_a","ComponentPath","path","org","repo","versionRange","isValidComponentPathObject","p","v","CCCError","message","detail","CCCImportError","CCCRenderError","CCCTimeoutError","_CCCEvent","opts","CCCEvent","_CCCConnectedEvent","CCCConnectedEvent","_CCCReadyEvent","CCCReadyEvent","_CCCViewportEvent","CCCViewportEvent","kebabize","$","ofs","isSafeTestEnv","host","isAllowed","isLocalEnv","isSparkEnv","allowlist","hostname","assignTestURL","testEnv","testUrl","defaultTestUrl","useComponentTestEnv","componentName","FTCustomCodeComponent","entries","entry","componentVersionRange","_b","preambleScript","viteClientScript","supportsDeclarative","internals","error","wrappedError","renderError","app","prerendered","ssr","shadow","styles","template","data","extraProps","onmessage","ready","err","timeout","isTestEnv","resolve","reject","to","componentRenderFunction","oldValue","newValue"],"mappings":"AAUA,SAASA,EAASC,GAAM;AAQvB,OAAK,cAAc,CAAC,CAAE,GAAE,EAAE,GACtBA,KACH,KAAK,KAAKA,CAAI,GAIf,KAAK,SAASD,EAAS,UAAU,OAAO,KAAK,IAAI,GAGjD,KAAK,oBAAoB,CAAE;AAC5B;AASAA,EAAS,UAAU,OAAO,SAAUC,GAAM;AACzC,QAAMC,IAAc,KAAK;AACzB,MAAIC;AAGJ,MAAI,KAAK,aAAa;AACrB,SAAKA,KAAaD,EAAY,CAAC;AAC9B,MAAIA,EAAY,CAAC,EAAE,eAAeC,CAAS,KAC1C,KAAK,YAAY,oBAAoBA,GAAW,KAAK,QAAQ,EAAI;AAGnE,SAAKA,KAAaD,EAAY,CAAC;AAC9B,MAAIA,EAAY,CAAC,EAAE,eAAeC,CAAS,KAC1C,KAAK,YAAY,oBAAoBA,GAAW,KAAK,QAAQ,EAAK;AAAA,EAGtE;AAKC,MAAI,CAACF,KAAQ,CAACA,EAAK;AAClB,WAAI,KAAK,eACR,OAAO,KAAK,aAEN;AASR,OAAK,cAAcA;AAGnB,OAAKE,KAAaD,EAAY,CAAC;AAC9B,IAAIA,EAAY,CAAC,EAAE,eAAeC,CAAS,KAC1C,KAAK,YAAY,iBAAiBA,GAAW,KAAK,QAAQ,EAAI;AAGhE,OAAKA,KAAaD,EAAY,CAAC;AAC9B,IAAIA,EAAY,CAAC,EAAE,eA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AAoD5D,CAAI,IAAIyC,CAAqB;AAAA,MACnF,GAEMmB;AAAA,IAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqDF,yBAAyBrF,GAAc4F,GAAkBC,GAAkB;AAOzE,YANK,KAAA,OAAO,MAAM,6CAA6C;AAAA,MAC7D,MAAA7F;AAAA,MACA,UAAA4F;AAAA,MACA,UAAAC;AAAA,IAAA,CACD,GAEO7F,GAAM;AAAA,MACZ,KAAK;AACE,aAAA,OAAO,YAAY6F,CAAQ;AAAA,IAClC;AAAA,EACF;AAEJ;","x_google_ignoreList":[0,1]}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import type { ContentTree } from "@financial-times/content-tree";
|
|
7
7
|
import { BaseRenderer } from "../../ccc-sdk/src/renderers/BaseRenderer";
|
|
8
8
|
import Tracking from "./tracking";
|
|
9
|
-
import { Logger } from "./logger";
|
|
9
|
+
import { Logger, LogLevel } from "./logger";
|
|
10
10
|
import {
|
|
11
11
|
CCCError,
|
|
12
12
|
CCCImportError,
|
|
@@ -66,15 +66,15 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
66
66
|
component = new ComponentPath();
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
* Logger instance. Set log level using `this.
|
|
69
|
+
* Logger instance. Set log level using `this.logger.setLogLevel(string|number|null)`.
|
|
70
70
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
logger: Logger;
|
|
72
|
+
|
|
73
73
|
/**
|
|
74
74
|
* IntersectionObserver that dispatches CCCViewportEvents
|
|
75
75
|
*/
|
|
76
76
|
observer = new IntersectionObserver((entries) => {
|
|
77
|
-
this.
|
|
77
|
+
this.logger.debug("Intersection Observer callback", { entries });
|
|
78
78
|
entries.forEach((entry) => {
|
|
79
79
|
this.dispatchEvent(
|
|
80
80
|
new CCCViewportEvent({
|
|
@@ -95,15 +95,15 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
95
95
|
*/
|
|
96
96
|
constructor() {
|
|
97
97
|
super();
|
|
98
|
-
this.
|
|
99
|
-
|
|
98
|
+
this.logger = new Logger();
|
|
99
|
+
|
|
100
100
|
const supportsDeclarative =
|
|
101
101
|
HTMLElement.prototype.hasOwnProperty("attachInternals");
|
|
102
102
|
|
|
103
103
|
try {
|
|
104
104
|
const internals = supportsDeclarative && this.attachInternals();
|
|
105
105
|
} catch (e) {
|
|
106
|
-
this.
|
|
106
|
+
this.logger.error(e);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -114,12 +114,12 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
114
114
|
*/
|
|
115
115
|
async connectedCallback() {
|
|
116
116
|
try {
|
|
117
|
-
this.log.setLogLevel(this.getAttribute("log"));
|
|
118
|
-
this.log.debug("connectedCallback");
|
|
119
|
-
|
|
120
117
|
const path = this.getAttribute("path");
|
|
121
118
|
const versionRange = this.getAttribute("version");
|
|
122
119
|
this.component = ComponentPath.fromString(path, versionRange);
|
|
120
|
+
this.logger.component = this.component;
|
|
121
|
+
this.logger.setLogLevel(this.getAttribute("log"));
|
|
122
|
+
this.logger.debug("connectedCallback");
|
|
123
123
|
|
|
124
124
|
this.app = await this.load();
|
|
125
125
|
await this.mount();
|
|
@@ -141,7 +141,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
141
141
|
* @param error
|
|
142
142
|
*/
|
|
143
143
|
emitError(error: Error) {
|
|
144
|
-
this.
|
|
144
|
+
this.logger.debug("emitError", { error });
|
|
145
145
|
if (error instanceof CCCError) {
|
|
146
146
|
this.dispatchEvent(
|
|
147
147
|
new ErrorEvent("ccc:error", {
|
|
@@ -177,9 +177,9 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
177
177
|
* Called when a <custom-code-component> element is removed from DOM.
|
|
178
178
|
*/
|
|
179
179
|
disconnectedCallback() {
|
|
180
|
-
this.
|
|
180
|
+
this.logger.debug("disconnectedCallback");
|
|
181
181
|
const path = this.getAttribute("path");
|
|
182
|
-
this.
|
|
182
|
+
this.logger.info(`<custom-code-component:${path}> disconnected`);
|
|
183
183
|
this.observer.disconnect();
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -196,7 +196,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
196
196
|
* @param e
|
|
197
197
|
*/
|
|
198
198
|
onmessage(e?: any) {
|
|
199
|
-
this.
|
|
199
|
+
this.logger.debug("onmessage", { event: e });
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
@@ -206,7 +206,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
206
206
|
* @param e
|
|
207
207
|
*/
|
|
208
208
|
onunmount(e: Error) {
|
|
209
|
-
this.
|
|
209
|
+
this.logger.debug("onunmount", { error: e });
|
|
210
210
|
if (e instanceof Error) {
|
|
211
211
|
const renderError = new CCCRenderError(e.message, {
|
|
212
212
|
error: e,
|
|
@@ -228,7 +228,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
228
228
|
async onready(app: Promise<void>) {
|
|
229
229
|
try {
|
|
230
230
|
await app;
|
|
231
|
-
this.
|
|
231
|
+
this.logger.debug("onready", { app });
|
|
232
232
|
this.dispatchEvent(
|
|
233
233
|
new CCCReadyEvent({
|
|
234
234
|
component: this.component,
|
|
@@ -241,7 +241,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
241
241
|
|
|
242
242
|
this.observer.observe(this);
|
|
243
243
|
} catch (e) {
|
|
244
|
-
this.
|
|
244
|
+
this.logger.debug("onready caught error", { error: e });
|
|
245
245
|
if (e instanceof Error) {
|
|
246
246
|
const renderError = new CCCRenderError(e.message, {
|
|
247
247
|
error: e,
|
|
@@ -261,7 +261,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
261
261
|
* @param event
|
|
262
262
|
*/
|
|
263
263
|
postMessage(event: any) {
|
|
264
|
-
this.
|
|
264
|
+
this.logger.debug("postmessage", { event });
|
|
265
265
|
this.channel.port1.postMessage(event);
|
|
266
266
|
}
|
|
267
267
|
|
|
@@ -275,7 +275,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
275
275
|
* @param prerendered
|
|
276
276
|
*/
|
|
277
277
|
async mount(prerendered?: ShadowRoot | null) {
|
|
278
|
-
this.
|
|
278
|
+
this.logger.debug("mount", prerendered);
|
|
279
279
|
try {
|
|
280
280
|
this.mode =
|
|
281
281
|
this.getAttribute("shadow-open") == "false" ? "closed" : "open";
|
|
@@ -300,7 +300,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
300
300
|
!shadow.adoptedStyleSheets.length
|
|
301
301
|
) {
|
|
302
302
|
if (!window.CCC_LAYOUT_STYLESHEET) {
|
|
303
|
-
this.
|
|
303
|
+
this.logger.debug("mount generating CCC_LAYOUT_STYLESHEET");
|
|
304
304
|
window.CCC_LAYOUT_STYLESHEET = new CSSStyleSheet();
|
|
305
305
|
window.CCC_LAYOUT_STYLESHEET.replaceSync(styles);
|
|
306
306
|
}
|
|
@@ -308,7 +308,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
if (!ssr) {
|
|
311
|
-
this.
|
|
311
|
+
this.logger.debug("mount generating fallback template");
|
|
312
312
|
const template = document.createElement("template");
|
|
313
313
|
template.innerHTML = "<div data-component-root><slot></slot></div>";
|
|
314
314
|
this.appendChild(template);
|
|
@@ -333,16 +333,16 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
333
333
|
subtype: "interactive",
|
|
334
334
|
teamName: "djd",
|
|
335
335
|
shadowRoot: this.shadowRoot,
|
|
336
|
-
logger: this.
|
|
336
|
+
logger: this.logger,
|
|
337
337
|
});
|
|
338
338
|
|
|
339
339
|
if (!data && Object.keys(extraProps).length > 0) {
|
|
340
|
-
this.
|
|
340
|
+
this.logger.warn(
|
|
341
341
|
`CCC ${this.component.toString()}: passing component settings as webcomponent attributes is %cDEPRECATED`,
|
|
342
342
|
"font-weight: bold",
|
|
343
343
|
" and will be removed in v3."
|
|
344
344
|
);
|
|
345
|
-
this.
|
|
345
|
+
this.logger.warn(
|
|
346
346
|
`Please use the %cdata-component-props`,
|
|
347
347
|
"text-decoration: underline;",
|
|
348
348
|
" attribute instead."
|
|
@@ -354,7 +354,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
354
354
|
shadow,
|
|
355
355
|
{
|
|
356
356
|
...(data ?? extraProps),
|
|
357
|
-
log: this.
|
|
357
|
+
log: this.logger,
|
|
358
358
|
data: data ?? extraProps,
|
|
359
359
|
port: this.channel.port2,
|
|
360
360
|
tracking: this.tracking,
|
|
@@ -370,10 +370,10 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
370
370
|
this.onready(ready);
|
|
371
371
|
}
|
|
372
372
|
} catch (err) {
|
|
373
|
-
this.
|
|
373
|
+
this.logger.info(
|
|
374
374
|
`<custom-code-component> uncaught error during mount from ${this.component?.toString()}`
|
|
375
375
|
);
|
|
376
|
-
this.
|
|
376
|
+
this.logger.error(err);
|
|
377
377
|
|
|
378
378
|
throw err;
|
|
379
379
|
}
|
|
@@ -387,7 +387,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
387
387
|
* @param e
|
|
388
388
|
*/
|
|
389
389
|
unmount(e: Error) {
|
|
390
|
-
this.
|
|
390
|
+
this.logger.debug("unmount", { error: e });
|
|
391
391
|
|
|
392
392
|
const template =
|
|
393
393
|
this.querySelector<HTMLTemplateElement>(
|
|
@@ -395,7 +395,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
395
395
|
) ?? this.querySelector<HTMLTemplateElement>("template");
|
|
396
396
|
|
|
397
397
|
if (template) {
|
|
398
|
-
this.
|
|
398
|
+
this.logger.debug("unmount replacing shadowRoot with fallback");
|
|
399
399
|
this.shadowRoot?.replaceChildren(template.content.cloneNode(true));
|
|
400
400
|
}
|
|
401
401
|
|
|
@@ -413,7 +413,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
413
413
|
* @returns Promise resolving to component renderer function
|
|
414
414
|
*/
|
|
415
415
|
async load() {
|
|
416
|
-
this.
|
|
416
|
+
this.logger.debug("load");
|
|
417
417
|
|
|
418
418
|
if (!this.component.isValid) {
|
|
419
419
|
throw new Error("No path found");
|
|
@@ -433,7 +433,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
433
433
|
const id = this.getAttribute("id");
|
|
434
434
|
|
|
435
435
|
if (isTestEnv && this.testUrl) {
|
|
436
|
-
this.
|
|
436
|
+
this.logger.debug("load adding Vite scripts");
|
|
437
437
|
this.injectViteScripts();
|
|
438
438
|
}
|
|
439
439
|
|
|
@@ -447,7 +447,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
447
447
|
return await new Promise<typeof BaseRenderer.prototype.render>(
|
|
448
448
|
(resolve, reject) => {
|
|
449
449
|
const to = setTimeout(() => {
|
|
450
|
-
this.
|
|
450
|
+
this.logger.error("CCC import timeout error");
|
|
451
451
|
reject(
|
|
452
452
|
new CCCTimeoutError({
|
|
453
453
|
component: this.component!,
|
|
@@ -473,7 +473,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
473
473
|
})
|
|
474
474
|
.catch((e) => {
|
|
475
475
|
clearTimeout(to);
|
|
476
|
-
this.
|
|
476
|
+
this.logger.error(e);
|
|
477
477
|
if (e instanceof Error && !(e instanceof CCCImportError)) {
|
|
478
478
|
reject(
|
|
479
479
|
new CCCImportError(e.message, {
|
|
@@ -495,7 +495,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
495
495
|
}
|
|
496
496
|
);
|
|
497
497
|
} catch (err) {
|
|
498
|
-
this.
|
|
498
|
+
this.logger.error(
|
|
499
499
|
`<custom-code-component> error during import from ${path}@${componentVersionRange}`
|
|
500
500
|
);
|
|
501
501
|
|
|
@@ -507,16 +507,16 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
507
507
|
* Initialises OTracking
|
|
508
508
|
*/
|
|
509
509
|
initTracking = async () => {
|
|
510
|
-
this.
|
|
510
|
+
this.logger.debug("initTracking", { cccId: this.id });
|
|
511
511
|
try {
|
|
512
512
|
this.tracking?.init(this.id);
|
|
513
513
|
} catch (e) {
|
|
514
514
|
const path = this.getAttribute("path");
|
|
515
515
|
const componentVersionRange = this.getAttribute("version");
|
|
516
|
-
this.
|
|
516
|
+
this.logger.info(
|
|
517
517
|
`Error initialising tracking on <custom-code-component> ${path}@${componentVersionRange}`
|
|
518
518
|
);
|
|
519
|
-
this.
|
|
519
|
+
this.logger.error(e);
|
|
520
520
|
}
|
|
521
521
|
};
|
|
522
522
|
|
|
@@ -554,7 +554,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
554
554
|
* @param newValue
|
|
555
555
|
*/
|
|
556
556
|
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
557
|
-
this.
|
|
557
|
+
this.logger.debug("attributeChangedCallback lifecycle method", {
|
|
558
558
|
name,
|
|
559
559
|
oldValue,
|
|
560
560
|
newValue,
|
|
@@ -562,7 +562,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
562
562
|
|
|
563
563
|
switch (name) {
|
|
564
564
|
case "log": {
|
|
565
|
-
this.
|
|
565
|
+
this.logger.setLogLevel(newValue);
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
568
|
}
|
package/src/logger.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ComponentPath } from "./path";
|
|
2
|
+
|
|
1
3
|
export const LogLevel = Object.freeze({
|
|
2
4
|
DEBUG: 0,
|
|
3
5
|
INFO: 1,
|
|
@@ -37,19 +39,25 @@ export function convertStringLogLevel(value: string | null) {
|
|
|
37
39
|
|
|
38
40
|
export class Logger {
|
|
39
41
|
public level: number;
|
|
42
|
+
public component?: ComponentPath;
|
|
43
|
+
|
|
40
44
|
constructor(
|
|
41
|
-
{
|
|
45
|
+
{
|
|
46
|
+
level = LogLevel.DEFAULT,
|
|
47
|
+
component,
|
|
48
|
+
}: { level: number; component?: ComponentPath } = {
|
|
42
49
|
level: LogLevel.DEFAULT,
|
|
43
50
|
}
|
|
44
51
|
) {
|
|
45
52
|
this.level = localStorage.getItem("CCC_LOG_LEVEL")
|
|
46
53
|
? convertStringLogLevel(localStorage.getItem("CCC_LOG_LEVEL"))
|
|
47
54
|
: level;
|
|
55
|
+
this.component = component;
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
debug(...args: any[]) {
|
|
51
59
|
if (this.level <= LogLevel.DEBUG) {
|
|
52
|
-
console.info(LOG_PREFIX, ...args);
|
|
60
|
+
console.info(LOG_PREFIX, ...args, this.component);
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
|
|
@@ -57,19 +65,19 @@ export class Logger {
|
|
|
57
65
|
|
|
58
66
|
info(...args: any[]) {
|
|
59
67
|
if (this.level <= LogLevel.INFO) {
|
|
60
|
-
console.info(LOG_PREFIX, ...args);
|
|
68
|
+
console.info(LOG_PREFIX, ...args, this.component);
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
warn(...args: any[]) {
|
|
65
73
|
if (this.level <= LogLevel.WARN) {
|
|
66
|
-
console.warn(LOG_PREFIX, ...args);
|
|
74
|
+
console.warn(LOG_PREFIX, ...args, this.component);
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
error(...args: any[]) {
|
|
71
79
|
if (this.level <= LogLevel.ERROR) {
|
|
72
|
-
console.error(LOG_PREFIX, ...args);
|
|
80
|
+
console.error(LOG_PREFIX, ...args, this.component);
|
|
73
81
|
}
|
|
74
82
|
}
|
|
75
83
|
|