@trunkjs/browser-utils 1.0.12 → 1.0.14
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/CHANGELOG.md +8 -0
- package/index.d.ts +1 -0
- package/index.js +107 -82
- package/lib/Logger.d.ts +10 -0
- package/mixins/LoggingMixin.d.ts +11 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 1.0.14 (2025-08-24)
|
|
2
|
+
|
|
3
|
+
This was a version bump only for browser-utils to align it with other projects, there were no code changes.
|
|
4
|
+
|
|
5
|
+
## 1.0.13 (2025-08-13)
|
|
6
|
+
|
|
7
|
+
This was a version bump only for browser-utils to align it with other projects, there were no code changes.
|
|
8
|
+
|
|
1
9
|
## 1.0.12 (2025-08-11)
|
|
2
10
|
|
|
3
11
|
This was a version bump only for browser-utils to align it with other projects, there were no code changes.
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,78 +1,96 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
throw TypeError(
|
|
1
|
+
var f = Object.defineProperty;
|
|
2
|
+
var h = (t) => {
|
|
3
|
+
throw TypeError(t);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
function
|
|
5
|
+
var g = (t, e, n) => e in t ? f(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
6
|
+
var a = (t, e, n) => g(t, typeof e != "symbol" ? e + "" : e, n), d = (t, e, n) => e.has(t) || h("Cannot " + n);
|
|
7
|
+
var o = (t, e, n) => (d(t, e, "read from private field"), n ? n.call(t) : e.get(t)), u = (t, e, n) => e.has(t) ? h("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), m = (t, e, n, i) => (d(t, e, "write to private field"), i ? i.call(t, n) : e.set(t, n), n);
|
|
8
|
+
function y(t, e = {}, n = []) {
|
|
9
9
|
Array.isArray(n) || (n = [n]);
|
|
10
|
-
const i = document.createElement(
|
|
11
|
-
for (const s in
|
|
12
|
-
|
|
10
|
+
const i = document.createElement(t);
|
|
11
|
+
for (const s in e)
|
|
12
|
+
e[s] !== null && e[s] !== void 0 && i.setAttribute(s, e[s] !== !0 ? e[s] : "");
|
|
13
13
|
for (const s of n)
|
|
14
14
|
i.append(typeof s == "string" ? document.createTextNode(s) : s);
|
|
15
15
|
return i;
|
|
16
16
|
}
|
|
17
|
-
class
|
|
17
|
+
class E {
|
|
18
18
|
/**
|
|
19
19
|
*
|
|
20
20
|
* @param delay Debounce delay in milliseconds
|
|
21
21
|
* @param max_delay Maximum delay in milliseconds, if false then no maximum delay is applied
|
|
22
22
|
*/
|
|
23
|
-
constructor(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.delay =
|
|
23
|
+
constructor(e, n = !1) {
|
|
24
|
+
a(this, "timeout", null);
|
|
25
|
+
a(this, "startTimeWithMs", 0);
|
|
26
|
+
this.delay = e, this.max_delay = n;
|
|
27
27
|
}
|
|
28
28
|
async wait() {
|
|
29
|
-
return this.startTimeWithMs === 0 && (this.startTimeWithMs = Date.now()), this.timeout && (this.max_delay === !1 || this.startTimeWithMs + this.max_delay > Date.now()) && clearTimeout(this.timeout), new Promise((
|
|
29
|
+
return this.startTimeWithMs === 0 && (this.startTimeWithMs = Date.now()), this.timeout && (this.max_delay === !1 || this.startTimeWithMs + this.max_delay > Date.now()) && clearTimeout(this.timeout), new Promise((e) => {
|
|
30
30
|
this.timeout = setTimeout(() => {
|
|
31
|
-
this.startTimeWithMs = 0,
|
|
31
|
+
this.startTimeWithMs = 0, e(!0);
|
|
32
32
|
}, this.delay);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
debounce(
|
|
35
|
+
debounce(e) {
|
|
36
36
|
this.timeout && clearTimeout(this.timeout), this.timeout = setTimeout(() => {
|
|
37
|
-
|
|
37
|
+
e();
|
|
38
38
|
}, this.delay);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
if (typeof
|
|
41
|
+
function I(t) {
|
|
42
|
+
if (typeof t.lineNumber == "number")
|
|
43
43
|
return {
|
|
44
|
-
file:
|
|
45
|
-
line:
|
|
46
|
-
column:
|
|
44
|
+
file: t.fileName || t.sourceURL,
|
|
45
|
+
line: t.lineNumber,
|
|
46
|
+
column: t.columnNumber ?? void 0
|
|
47
47
|
};
|
|
48
|
-
if (typeof
|
|
48
|
+
if (typeof t.line == "number")
|
|
49
49
|
return {
|
|
50
|
-
file:
|
|
51
|
-
line:
|
|
52
|
-
column:
|
|
50
|
+
file: t.sourceURL,
|
|
51
|
+
line: t.line,
|
|
52
|
+
column: t.column
|
|
53
53
|
};
|
|
54
|
-
const n = String(
|
|
54
|
+
const n = String(t.stack || t.message || "").split(`
|
|
55
55
|
`), i = /(.*?)(?:\(|@)?(.*?):(\d+):(\d+)\)?$/;
|
|
56
56
|
for (const s of n) {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
return { file:
|
|
57
|
+
const r = s.match(i);
|
|
58
|
+
if (r)
|
|
59
|
+
return { file: r[2], line: +r[3], column: +r[4] };
|
|
60
|
+
}
|
|
61
|
+
return { file: t.fileName || t.sourceURL };
|
|
62
|
+
}
|
|
63
|
+
class w {
|
|
64
|
+
constructor(e, n, i = "main") {
|
|
65
|
+
this._debug = e, this.myElementId = n, this.instanceId = i;
|
|
66
|
+
}
|
|
67
|
+
log(...e) {
|
|
68
|
+
this._debug && console.log(`[LOG][ID:${this.myElementId}:${this.instanceId}]`, ...e);
|
|
69
|
+
}
|
|
70
|
+
warn(...e) {
|
|
71
|
+
console.warn(`[WARN][ID:${this.myElementId}:${this.instanceId}]`, ...e);
|
|
72
|
+
}
|
|
73
|
+
error(...e) {
|
|
74
|
+
console.error(`[ERROR][ID:${this.myElementId}:${this.instanceId}]`, ...e);
|
|
75
|
+
}
|
|
76
|
+
throwError(...e) {
|
|
77
|
+
const n = `[ERROR][ID:${this.myElementId}:${this.instanceId}] ${e.join(" ")}`;
|
|
78
|
+
throw this.error(...e), new Error(n);
|
|
60
79
|
}
|
|
61
|
-
return { file: e.fileName || e.sourceURL };
|
|
62
80
|
}
|
|
63
|
-
class
|
|
64
|
-
constructor(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.label =
|
|
71
|
-
}
|
|
72
|
-
lap(
|
|
81
|
+
class p {
|
|
82
|
+
constructor(e, n = !0) {
|
|
83
|
+
a(this, "label");
|
|
84
|
+
a(this, "last");
|
|
85
|
+
a(this, "startTime");
|
|
86
|
+
a(this, "running", !1);
|
|
87
|
+
a(this, "enabled");
|
|
88
|
+
this.label = e, this.enabled = n, this.startTime = this.last = performance.now(), this.running = !0;
|
|
89
|
+
}
|
|
90
|
+
lap(e = "") {
|
|
73
91
|
if (!this.enabled) return;
|
|
74
92
|
const n = performance.now(), i = (n - this.last) / 1e3;
|
|
75
|
-
this.last = n, console.debug(`[${this.label}] ${
|
|
93
|
+
this.last = n, console.debug(`[${this.label}] ${e} +${i.toFixed(3)}s`);
|
|
76
94
|
}
|
|
77
95
|
elapsed() {
|
|
78
96
|
return performance.now() - this.startTime;
|
|
@@ -90,73 +108,80 @@ class L {
|
|
|
90
108
|
return this.running;
|
|
91
109
|
}
|
|
92
110
|
}
|
|
93
|
-
function T(
|
|
111
|
+
function T(t, e, n) {
|
|
94
112
|
return new Promise((i, s) => {
|
|
95
|
-
const
|
|
96
|
-
|
|
113
|
+
const r = (c) => {
|
|
114
|
+
t.removeEventListener(e, r, n), i(c);
|
|
97
115
|
};
|
|
98
|
-
|
|
116
|
+
t.addEventListener(e, r, n);
|
|
99
117
|
});
|
|
100
118
|
}
|
|
101
|
-
function
|
|
102
|
-
return document.readyState === "loading" ? new Promise((
|
|
103
|
-
document.addEventListener("DOMContentLoaded", () =>
|
|
119
|
+
function $() {
|
|
120
|
+
return document.readyState === "loading" ? new Promise((t) => {
|
|
121
|
+
document.addEventListener("DOMContentLoaded", () => t());
|
|
104
122
|
}) : Promise.resolve();
|
|
105
123
|
}
|
|
106
|
-
function
|
|
107
|
-
return document.readyState === "complete" ? Promise.resolve() : new Promise((
|
|
108
|
-
window.addEventListener("load", () =>
|
|
124
|
+
function D() {
|
|
125
|
+
return document.readyState === "complete" ? Promise.resolve() : new Promise((t) => {
|
|
126
|
+
window.addEventListener("load", () => t());
|
|
109
127
|
});
|
|
110
128
|
}
|
|
111
|
-
function
|
|
112
|
-
return new Promise((
|
|
129
|
+
function v(t) {
|
|
130
|
+
return new Promise((e) => setTimeout(e, t));
|
|
113
131
|
}
|
|
114
|
-
function
|
|
115
|
-
return new Promise((
|
|
132
|
+
function R(t) {
|
|
133
|
+
return new Promise((e) => {
|
|
116
134
|
const n = (i) => {
|
|
117
|
-
|
|
135
|
+
t.removeEventListener("animationend", n), e(i);
|
|
118
136
|
};
|
|
119
|
-
|
|
137
|
+
t.addEventListener("animationend", n);
|
|
120
138
|
});
|
|
121
139
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
140
|
+
let b = 1;
|
|
141
|
+
function x(t) {
|
|
142
|
+
var n, i, s;
|
|
143
|
+
class e extends t {
|
|
125
144
|
constructor() {
|
|
126
145
|
super(...arguments);
|
|
127
|
-
|
|
146
|
+
u(this, n, null);
|
|
147
|
+
u(this, i, b++);
|
|
148
|
+
u(this, s, null);
|
|
128
149
|
}
|
|
129
150
|
/**
|
|
130
151
|
* Clears the cached debug flag so the attribute will be checked again
|
|
131
152
|
* on the next log/warn/error call.
|
|
132
153
|
*/
|
|
133
154
|
invalidateDebugCache() {
|
|
134
|
-
|
|
155
|
+
m(this, n, null);
|
|
135
156
|
}
|
|
136
157
|
get _debug() {
|
|
137
|
-
return
|
|
158
|
+
return o(this, n) !== null ? o(this, n) : (this instanceof HTMLElement && m(this, n, this.hasAttribute("debug") && !["false", "0", "off", "no"].includes(this.getAttribute("debug") || "")), o(this, n) === !0 && console.log(`[DEBUG][ID:${o(this, i)}] LoggingMixin: Debug mode is enabled for <${this.tagName}>`, this), o(this, n) ?? !1);
|
|
159
|
+
}
|
|
160
|
+
getLogger(l = "main") {
|
|
161
|
+
return o(this, s) || m(this, s, new w(this._debug, `${o(this, i)}`, l)), o(this, s);
|
|
138
162
|
}
|
|
139
|
-
log(...
|
|
140
|
-
this.
|
|
163
|
+
log(...l) {
|
|
164
|
+
this.getLogger().log(...l);
|
|
141
165
|
}
|
|
142
|
-
warn(...
|
|
143
|
-
|
|
166
|
+
warn(...l) {
|
|
167
|
+
this.getLogger().warn(...l);
|
|
144
168
|
}
|
|
145
|
-
error(...
|
|
146
|
-
|
|
169
|
+
error(...l) {
|
|
170
|
+
this.getLogger().error(...l);
|
|
147
171
|
}
|
|
148
172
|
}
|
|
149
|
-
return n = new WeakMap(),
|
|
173
|
+
return n = new WeakMap(), i = new WeakMap(), s = new WeakMap(), e;
|
|
150
174
|
}
|
|
151
175
|
export {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
176
|
+
E as Debouncer,
|
|
177
|
+
w as Logger,
|
|
178
|
+
x as LoggingMixin,
|
|
179
|
+
p as Stopwatch,
|
|
180
|
+
y as create_element,
|
|
181
|
+
I as getErrorLocation,
|
|
182
|
+
v as sleep,
|
|
158
183
|
T as waitFor,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
184
|
+
R as waitForAnimationEnd,
|
|
185
|
+
$ as waitForDomContentLoaded,
|
|
186
|
+
D as waitForLoad
|
|
162
187
|
};
|
package/lib/Logger.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class Logger {
|
|
2
|
+
private _debug;
|
|
3
|
+
private myElementId;
|
|
4
|
+
private instanceId;
|
|
5
|
+
constructor(_debug: boolean, myElementId: string, instanceId?: string);
|
|
6
|
+
log(...args: any[]): void;
|
|
7
|
+
warn(...args: any[]): void;
|
|
8
|
+
error(...args: any[]): void;
|
|
9
|
+
throwError(...args: any[]): never;
|
|
10
|
+
}
|
package/mixins/LoggingMixin.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Logger } from '../lib/Logger';
|
|
1
2
|
type Constructor<T = object> = abstract new (...args: any[]) => T;
|
|
2
3
|
/**
|
|
3
4
|
* LoggingMixin
|
|
@@ -17,16 +18,24 @@ type Constructor<T = object> = abstract new (...args: any[]) => T;
|
|
|
17
18
|
* // or with Lit:
|
|
18
19
|
* class MyLitEl extends LoggingMixin(ReactiveElement) {}
|
|
19
20
|
*
|
|
21
|
+
*
|
|
22
|
+
* // Create a new Logger Instance
|
|
23
|
+
* const logger = this.getLogger("loader1");
|
|
24
|
+
* logger.log("This is a log message from loader1");
|
|
25
|
+
*
|
|
20
26
|
* <my-element debug></my-element> // enables debug logging
|
|
21
27
|
*/
|
|
22
28
|
export declare function LoggingMixin<TBase extends Constructor<object>>(Base: TBase): (abstract new (...args: any[]) => {
|
|
23
|
-
"__#
|
|
29
|
+
"__#1726@#debugCached": boolean | null;
|
|
30
|
+
"__#1726@#myElementId": number;
|
|
24
31
|
/**
|
|
25
32
|
* Clears the cached debug flag so the attribute will be checked again
|
|
26
33
|
* on the next log/warn/error call.
|
|
27
34
|
*/
|
|
28
35
|
invalidateDebugCache(): void;
|
|
29
|
-
|
|
36
|
+
"__#1726@#myLoggerInstance": Logger | null;
|
|
37
|
+
readonly _debug: boolean;
|
|
38
|
+
getLogger(instanceId?: string): Logger;
|
|
30
39
|
log(...args: any[]): void;
|
|
31
40
|
warn(...args: any[]): void;
|
|
32
41
|
error(...args: any[]): void;
|