PageSourceSearch

https://enterprisersproject.com/libraries/chapeaux--cpx-reporter/cpx-reporter.js?v=0.12.0

js enterprisersproject.com collected 2026-10-01 08:49:58 UTC 4,211 bytes, 141 lines download raw bytes

1import { ReporterEvent } from "./reporter.js";
2export class CPXReporter extends HTMLElement {
3    constructor() {
4        super();
5        this._debug = null;
6        this._scope = 'global';
7        this._data = {};
8        this.tasks = new Set(['beat', 'event', 'data']);
9        this._ready = false;
10        this._emit = 'cpx-report';
11        this.report = this.report.bind(this);
12    }
13    static get tag() { return 'cpx-reporter'; }
14    get debug() {
15        return this._debug;
16    }
17    set debug(val) {
18        if (this._debug === val)
19            return;
20        this._debug = val;
21    }
22    get beat() { return this._beat; }
23    set beat(val) {
24        if (this._beat === val)
25            return;
26        this._beat = val;
27        if (this.scope === 'global') {
28            top.addEventListener(this.beat, this.report);
29        }
30        else {
31            this.addEventListener(this.beat, this.report);
32        }
33        this.setAttribute('beat', this._beat);
34    }
35    get scope() { return this._scope; }
36    set scope(val) {
37        if (this._scope === val)
38            return;
39        this._scope = val;
40        this.setAttribute('scope', this._scope);
41    }
42    get event() { return this._event; }
43    set event(val) {
44        if (this._event === val)
45            return;
46        this._event = val;
47        this.setAttribute('event', this._event);
48        this.evt = 'eddl-' + this._event.toLowerCase().split(' ').join('-');
49    }
50    get evt() { return this._evt; }
51    set evt(val) {
52        if (this._evt === val)
53            return;
54        this._evt = val;
55        this.setAttribute('evt', this._evt);
56    }
57    get option() { return this._option; }
58    set option(val) {
59        if (this._option === val)
60            return;
61        this._option = val;
62        this.setAttribute('option', this._option);
63    }
64    get data() { return this._data; }
65    set data(val) {
66        if (this._data === val)
67            return;
68        this._data = val;
69    }
70    get ready() { return this._ready; }
71    set ready(val) {
72        if (this._ready === !!val)
73            return;
74        this._ready = !!val;
75        if (this._ready) {
76            this.report({});
77        }
78    }
79    get emit() { return this._emit; }
80    set emit(val) {
81        if (this._emit === val)
82            return;
83        this._emit = val;
84    }
85    connectedCallback() {
86        const dataEle = this.querySelector(':scope > script[type="data"]');
87        if (dataEle) {
88            this.data = JSON.parse(dataEle.textContent);
89        }
90        const attrs = new Set();
91        for (let i = 0; i < this.attributes.length; i++) {
92            attrs.add(this.attributes[i]);
93        }
94        this.tasks.forEach(r => {
95            if (!attrs.has(r)) {
96                this.tasks.delete(r);
97            }
98        });
99    }
100    static get observedAttributes() {
101        return [
102            "scope",
103            "data",
104            "emit",
105            "event",
106            "beat",
107            "debug",
108            "option"
109        ];
110    }
111    attributeChangedCallback(name, oldVal, newVal) {
112        this[name] = newVal;
113        if (this.tasks.has(name)) {
114            this.tasks.delete(name);
115        }
116        if (this.getAttribute('auto') === '' && this.tasks.size === 0) {
117            this.ready = true;
118        }
119    }
120    report(e) {
121        var _a, _b, _c;
122        if (this.debug !== null) {
123            if (this.debug !== 'verbose') {
124                console.log('DEBUG ON');
125            }
126            else {
127                console.log('VERBOSE DEBUG ON');
128            }
129        }
130        const detail = e['detail'];
131        if (this.option) {
132            this.data = Object.assign((_a = this.data) !== null && _a !== void 0 ? _a : {}, (_b = detail[this.option]) !== null && _b !== void 0 ? _b : {});
133        }
134        else {
135            this.data = Object.assign((_c = this.data) !== null && _c !== void 0 ? _c : {}, detail !== null && detail !== void 0 ? detail : {});
136        }
137        this.dispatchEvent(new ReporterEvent(this.event, this.data, this.emit));
138        this.dispatchEvent(new CustomEvent(this.evt, { bubbles: true, composed: true }));
139    }
140}
141window.customElements.define(CPXReporter.tag, CPXReporter);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.