@trunkjs/browser-utils 1.0.41 → 1.0.43
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.js +67 -63
- package/lib/breakpoints.d.ts +1 -0
- package/mixins/EventBindingsMixin.d.ts +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 1.0.43 (2026-04-23)
|
|
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.42 (2026-04-14)
|
|
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.41 (2026-04-14)
|
|
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.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var N = Object.defineProperty;
|
|
2
|
-
var
|
|
2
|
+
var L = (e) => {
|
|
3
3
|
throw TypeError(e);
|
|
4
4
|
};
|
|
5
5
|
var B = (e, t, n) => t in e ? N(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
6
|
-
var l = (e, t, n) => B(e, typeof t != "symbol" ? t + "" : t, n),
|
|
7
|
-
var u = (e, t, n) => (
|
|
6
|
+
var l = (e, t, n) => B(e, typeof t != "symbol" ? t + "" : t, n), v = (e, t, n) => t.has(e) || L("Cannot " + n);
|
|
7
|
+
var u = (e, t, n) => (v(e, t, "read from private field"), n ? n.call(e) : t.get(e)), h = (e, t, n) => t.has(e) ? L("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), w = (e, t, n, i) => (v(e, t, "write to private field"), i ? i.call(e, n) : t.set(e, n), n), y = (e, t, n) => (v(e, t, "access private method"), n);
|
|
8
8
|
const T = [
|
|
9
9
|
{ name: "xs", minWidth: 0 },
|
|
10
10
|
{ name: "sm", minWidth: 576 },
|
|
@@ -12,23 +12,26 @@ const T = [
|
|
|
12
12
|
{ name: "lg", minWidth: 992 },
|
|
13
13
|
{ name: "xl", minWidth: 1200 },
|
|
14
14
|
{ name: "xxl", minWidth: 1400 }
|
|
15
|
-
],
|
|
15
|
+
], p = T.reduce(
|
|
16
16
|
(e, t) => (e[t.name] = t.minWidth, e),
|
|
17
17
|
{}
|
|
18
18
|
);
|
|
19
19
|
function E(e) {
|
|
20
|
-
if (!(e in
|
|
20
|
+
if (!(e in p))
|
|
21
21
|
throw new Error(`Unknown breakpoint: ${e}`);
|
|
22
|
-
return
|
|
22
|
+
return p[e];
|
|
23
23
|
}
|
|
24
|
-
function D(
|
|
25
|
-
|
|
24
|
+
function D() {
|
|
25
|
+
return window.visualViewport ? window.visualViewport.width : window.innerWidth;
|
|
26
|
+
}
|
|
27
|
+
function R(e) {
|
|
28
|
+
e === void 0 && (e = D());
|
|
26
29
|
for (let t = T.length - 1; t >= 0; t--)
|
|
27
30
|
if (e >= T[t].minWidth)
|
|
28
31
|
return T[t].name;
|
|
29
32
|
return "xs";
|
|
30
33
|
}
|
|
31
|
-
function
|
|
34
|
+
function G(e, t = {}, n = []) {
|
|
32
35
|
Array.isArray(n) || (n = [n]);
|
|
33
36
|
const i = document.createElement(e);
|
|
34
37
|
for (const r in t)
|
|
@@ -68,7 +71,7 @@ class M {
|
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
|
-
function
|
|
74
|
+
function J(e, t = !1) {
|
|
72
75
|
const n = /* @__PURE__ */ new WeakMap();
|
|
73
76
|
return function(i, r) {
|
|
74
77
|
if (r.kind !== "method") return i;
|
|
@@ -81,7 +84,7 @@ function G(e, t = !1) {
|
|
|
81
84
|
};
|
|
82
85
|
};
|
|
83
86
|
}
|
|
84
|
-
function
|
|
87
|
+
function q(e) {
|
|
85
88
|
if (typeof e.lineNumber == "number")
|
|
86
89
|
return {
|
|
87
90
|
file: e.fileName || e.sourceURL,
|
|
@@ -103,7 +106,7 @@ function J(e) {
|
|
|
103
106
|
}
|
|
104
107
|
return { file: e.fileName || e.sourceURL };
|
|
105
108
|
}
|
|
106
|
-
class
|
|
109
|
+
class O {
|
|
107
110
|
constructor(t, n, i, r = "main") {
|
|
108
111
|
this._debug = t, this.myTag = n, this.myElementId = i, this.instanceId = r;
|
|
109
112
|
}
|
|
@@ -124,7 +127,7 @@ class R {
|
|
|
124
127
|
throw this.error(...t), new Error(n);
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
|
-
class
|
|
130
|
+
class X {
|
|
128
131
|
constructor(t, n = !0) {
|
|
129
132
|
l(this, "label");
|
|
130
133
|
l(this, "last");
|
|
@@ -154,10 +157,10 @@ class q {
|
|
|
154
157
|
return this.running;
|
|
155
158
|
}
|
|
156
159
|
}
|
|
157
|
-
function
|
|
160
|
+
function U(e) {
|
|
158
161
|
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
159
162
|
}
|
|
160
|
-
function
|
|
163
|
+
function V(e) {
|
|
161
164
|
if (e != null)
|
|
162
165
|
try {
|
|
163
166
|
return JSON.parse(e);
|
|
@@ -165,13 +168,13 @@ function U(e) {
|
|
|
165
168
|
return;
|
|
166
169
|
}
|
|
167
170
|
}
|
|
168
|
-
function
|
|
171
|
+
function x(e) {
|
|
169
172
|
const t = JSON.stringify(e);
|
|
170
173
|
return t === void 0 ? "null" : t;
|
|
171
174
|
}
|
|
172
175
|
function K(e, t) {
|
|
173
176
|
const n = { ...t };
|
|
174
|
-
if (
|
|
177
|
+
if (U(e))
|
|
175
178
|
for (const i of Object.keys(t))
|
|
176
179
|
i in e && (n[i] = e[i]);
|
|
177
180
|
return n;
|
|
@@ -183,10 +186,10 @@ class P {
|
|
|
183
186
|
}
|
|
184
187
|
read() {
|
|
185
188
|
if (this.cache) return this.cache;
|
|
186
|
-
const t = this.backend ?
|
|
189
|
+
const t = this.backend ? V(this.backend.getItem(this.storageKey)) : void 0, n = K(t, this.initialValue);
|
|
187
190
|
if (this.backend && this.backend.getItem(this.storageKey) == null)
|
|
188
191
|
try {
|
|
189
|
-
this.backend.setItem(this.storageKey,
|
|
192
|
+
this.backend.setItem(this.storageKey, x(n));
|
|
190
193
|
} catch {
|
|
191
194
|
}
|
|
192
195
|
return this.cache = n, n;
|
|
@@ -194,7 +197,7 @@ class P {
|
|
|
194
197
|
write(t) {
|
|
195
198
|
if (this.cache = t, !!this.backend)
|
|
196
199
|
try {
|
|
197
|
-
this.backend.setItem(this.storageKey,
|
|
200
|
+
this.backend.setItem(this.storageKey, x(t));
|
|
198
201
|
} catch {
|
|
199
202
|
}
|
|
200
203
|
}
|
|
@@ -246,13 +249,13 @@ function A(e) {
|
|
|
246
249
|
const t = globalThis.window;
|
|
247
250
|
return (e === "session" ? t == null ? void 0 : t.sessionStorage : t == null ? void 0 : t.localStorage) ?? void 0;
|
|
248
251
|
}
|
|
249
|
-
function
|
|
252
|
+
function Q(e, t) {
|
|
250
253
|
return new P(A("session"), e, t).asProxy();
|
|
251
254
|
}
|
|
252
|
-
function
|
|
255
|
+
function Y(e, t) {
|
|
253
256
|
return new P(A("local"), e, t).asProxy();
|
|
254
257
|
}
|
|
255
|
-
function
|
|
258
|
+
function Z(e, t, n) {
|
|
256
259
|
return new Promise((i, r) => {
|
|
257
260
|
const a = (c) => {
|
|
258
261
|
e.removeEventListener(t, a, n), i(c);
|
|
@@ -265,15 +268,15 @@ function z() {
|
|
|
265
268
|
document.addEventListener("DOMContentLoaded", () => e());
|
|
266
269
|
}) : Promise.resolve();
|
|
267
270
|
}
|
|
268
|
-
function
|
|
271
|
+
function tt(e = window) {
|
|
269
272
|
return e || (e = window), e === window ? document.readyState === "complete" ? Promise.resolve() : new Promise((t) => window.addEventListener("load", () => t(), { once: !0 })) : e instanceof HTMLImageElement ? e.complete && e.naturalWidth !== 0 ? Promise.resolve() : new Promise((t, n) => {
|
|
270
273
|
e.addEventListener("load", () => t(), { once: !0 }), e.addEventListener("error", () => n(new Error("image error")), { once: !0 });
|
|
271
274
|
}) : e instanceof HTMLMediaElement ? e.readyState >= HTMLMediaElement.HAVE_FUTURE_DATA ? Promise.resolve() : new Promise((t) => e.addEventListener("loadeddata", () => t(), { once: !0 })) : new Promise((t) => e.addEventListener("load", () => t(), { once: !0 }));
|
|
272
275
|
}
|
|
273
|
-
function
|
|
276
|
+
function et(e) {
|
|
274
277
|
return new Promise((t) => setTimeout(t, e));
|
|
275
278
|
}
|
|
276
|
-
function
|
|
279
|
+
function nt(e) {
|
|
277
280
|
return new Promise((t) => {
|
|
278
281
|
const n = (i) => {
|
|
279
282
|
e.removeEventListener("animationend", n), t(i);
|
|
@@ -281,7 +284,7 @@ function et(e) {
|
|
|
281
284
|
e.addEventListener("animationend", n);
|
|
282
285
|
});
|
|
283
286
|
}
|
|
284
|
-
function
|
|
287
|
+
function it(e) {
|
|
285
288
|
var n, i;
|
|
286
289
|
class t extends e {
|
|
287
290
|
constructor() {
|
|
@@ -296,7 +299,7 @@ function nt(e) {
|
|
|
296
299
|
if (!o || o === "")
|
|
297
300
|
return;
|
|
298
301
|
o = o.trim().replace(/^['"]|['"]$/g, "");
|
|
299
|
-
const d = o.split(","), m = d[0].trim(), f = ((b = d[1]) == null ? void 0 : b.trim()) ?? m, g =
|
|
302
|
+
const d = o.split(","), m = d[0].trim(), f = ((b = d[1]) == null ? void 0 : b.trim()) ?? m, g = R(s);
|
|
300
303
|
this.currentBreakPoint !== g && (E(f) <= E(g) ? c.setAttribute("mode", "desktop") : E(m) > E(g) ? c.setAttribute("mode", "mobile") : c.setAttribute("mode", "tablet"));
|
|
301
304
|
});
|
|
302
305
|
}
|
|
@@ -314,8 +317,8 @@ function nt(e) {
|
|
|
314
317
|
}
|
|
315
318
|
return n = new WeakMap(), i = new WeakMap(), t;
|
|
316
319
|
}
|
|
317
|
-
const k = Symbol("listenerDefs"),
|
|
318
|
-
function
|
|
320
|
+
const k = Symbol("listenerDefs"), W = Symbol("withEventBindings");
|
|
321
|
+
function rt(e, t) {
|
|
319
322
|
const n = Array.isArray(e) ? e : [e];
|
|
320
323
|
return function(i, r) {
|
|
321
324
|
if (r.kind !== "method") throw new Error("@Listen nur für Methoden");
|
|
@@ -327,7 +330,7 @@ function it(e, t) {
|
|
|
327
330
|
opts: t
|
|
328
331
|
});
|
|
329
332
|
}), function(...a) {
|
|
330
|
-
if (!this[
|
|
333
|
+
if (!this[W])
|
|
331
334
|
throw new Error("[EventBindings] @Listen - decorator requires EventBindingMixin.");
|
|
332
335
|
return i.apply(this, a);
|
|
333
336
|
};
|
|
@@ -337,25 +340,25 @@ function F(e, t) {
|
|
|
337
340
|
var n;
|
|
338
341
|
return !t || t === "host" ? e : t === "document" ? e.ownerDocument ?? document : t === "window" ? ((n = e.ownerDocument) == null ? void 0 : n.defaultView) ?? window : t === "shadowRoot" ? e.shadowRoot ?? e : typeof t == "function" ? t(e) : t;
|
|
339
342
|
}
|
|
340
|
-
function
|
|
341
|
-
var n, i,
|
|
343
|
+
function st(e) {
|
|
344
|
+
var n, i, $;
|
|
342
345
|
class t extends e {
|
|
343
346
|
constructor(...s) {
|
|
344
347
|
super(...s);
|
|
345
348
|
h(this, i);
|
|
346
349
|
h(this, n);
|
|
347
|
-
this[
|
|
350
|
+
this[W] = !0;
|
|
348
351
|
}
|
|
349
352
|
connectedCallback() {
|
|
350
353
|
var s;
|
|
351
|
-
(s = super.connectedCallback) == null || s.call(this), y(this, i,
|
|
354
|
+
(s = super.connectedCallback) == null || s.call(this), y(this, i, $).call(this);
|
|
352
355
|
}
|
|
353
356
|
disconnectedCallback() {
|
|
354
357
|
var s, o;
|
|
355
358
|
(s = u(this, n)) == null || s.abort(), (o = super.disconnectedCallback) == null || o.call(this);
|
|
356
359
|
}
|
|
357
360
|
}
|
|
358
|
-
return n = new WeakMap(), i = new WeakSet(),
|
|
361
|
+
return n = new WeakMap(), i = new WeakSet(), $ = function() {
|
|
359
362
|
var o, d, m;
|
|
360
363
|
(o = u(this, n)) == null || o.abort(), w(this, n, new AbortController());
|
|
361
364
|
const s = this[k] || [];
|
|
@@ -366,14 +369,14 @@ function rt(e) {
|
|
|
366
369
|
}
|
|
367
370
|
}, t;
|
|
368
371
|
}
|
|
369
|
-
let
|
|
370
|
-
function
|
|
372
|
+
let j = 1;
|
|
373
|
+
function ot(e) {
|
|
371
374
|
var n, i, r;
|
|
372
375
|
class t extends e {
|
|
373
376
|
constructor() {
|
|
374
377
|
super(...arguments);
|
|
375
378
|
h(this, n, null);
|
|
376
|
-
h(this, i,
|
|
379
|
+
h(this, i, j++);
|
|
377
380
|
h(this, r, null);
|
|
378
381
|
}
|
|
379
382
|
/**
|
|
@@ -392,7 +395,7 @@ function st(e) {
|
|
|
392
395
|
}
|
|
393
396
|
getLogger(s = "main") {
|
|
394
397
|
const o = "<" + (this.tagName || this.constructor.name || "UnknownElement") + ">";
|
|
395
|
-
return u(this, r) || w(this, r, new
|
|
398
|
+
return u(this, r) || w(this, r, new O(this._debug, o, `${u(this, i)}`, s)), u(this, r);
|
|
396
399
|
}
|
|
397
400
|
debug(...s) {
|
|
398
401
|
this.getLogger().debug(...s);
|
|
@@ -412,23 +415,23 @@ function st(e) {
|
|
|
412
415
|
}
|
|
413
416
|
return n = new WeakMap(), i = new WeakMap(), r = new WeakMap(), t;
|
|
414
417
|
}
|
|
415
|
-
function
|
|
416
|
-
var n,
|
|
418
|
+
function at(e) {
|
|
419
|
+
var n, I, r, S;
|
|
417
420
|
class t extends e {
|
|
418
421
|
constructor() {
|
|
419
422
|
super(...arguments);
|
|
420
423
|
h(this, n);
|
|
421
424
|
h(this, r, (o) => {
|
|
422
425
|
const d = o.target;
|
|
423
|
-
d.assignedNodes({ flatten: !0 }).filter((g) => y(this, n, S).call(this, g)).length > 0 && d.classList.remove("slot-empty");
|
|
426
|
+
d.assignedNodes({ flatten: !0 }).filter((g) => y(this, n, S).call(this, g)).length > 0 && d.childNodes.length > 0 && d.classList.remove("slot-empty");
|
|
424
427
|
});
|
|
425
428
|
}
|
|
426
429
|
firstUpdated(o) {
|
|
427
430
|
var d;
|
|
428
|
-
(d = super.firstUpdated) == null || d.call(this, o), y(this, n,
|
|
431
|
+
(d = super.firstUpdated) == null || d.call(this, o), y(this, n, I).call(this);
|
|
429
432
|
}
|
|
430
433
|
}
|
|
431
|
-
return n = new WeakSet(),
|
|
434
|
+
return n = new WeakSet(), I = function() {
|
|
432
435
|
var d;
|
|
433
436
|
const o = (d = this.shadowRoot) == null ? void 0 : d.querySelectorAll("slot");
|
|
434
437
|
o == null || o.forEach((m) => {
|
|
@@ -439,26 +442,27 @@ function ot(e) {
|
|
|
439
442
|
}, t;
|
|
440
443
|
}
|
|
441
444
|
export {
|
|
442
|
-
|
|
445
|
+
it as BreakPointMixin,
|
|
443
446
|
M as Debouncer,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
447
|
+
st as EventBindingsMixin,
|
|
448
|
+
rt as Listen,
|
|
449
|
+
O as Logger,
|
|
450
|
+
ot as LoggingMixin,
|
|
451
|
+
at as SlotVisibilityMixin,
|
|
452
|
+
X as Stopwatch,
|
|
453
|
+
p as breakpointMap,
|
|
451
454
|
T as breakpoints,
|
|
452
|
-
|
|
453
|
-
|
|
455
|
+
G as create_element,
|
|
456
|
+
J as debounce,
|
|
454
457
|
E as getBreakpointMinWidth,
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
458
|
+
R as getCurrentBreakpoint,
|
|
459
|
+
q as getErrorLocation,
|
|
460
|
+
D as getViewportWidth,
|
|
461
|
+
Y as local_storage,
|
|
462
|
+
Q as session_storage,
|
|
463
|
+
et as sleep,
|
|
464
|
+
Z as waitFor,
|
|
465
|
+
nt as waitForAnimationEnd,
|
|
462
466
|
z as waitForDomContentLoaded,
|
|
463
|
-
|
|
467
|
+
tt as waitForLoad
|
|
464
468
|
};
|
package/lib/breakpoints.d.ts
CHANGED
|
@@ -21,4 +21,5 @@ export declare const breakpointMap: {
|
|
|
21
21
|
[key: string]: number;
|
|
22
22
|
};
|
|
23
23
|
export declare function getBreakpointMinWidth(breakpoint: string): number;
|
|
24
|
+
export declare function getViewportWidth(): number;
|
|
24
25
|
export declare function getCurrentBreakpoint(width?: number): string;
|
|
@@ -6,7 +6,7 @@ type ListenOpts = {
|
|
|
6
6
|
};
|
|
7
7
|
type EventName = keyof DocumentEventMap;
|
|
8
8
|
type OneOrMany<N extends EventName> = N | readonly N[];
|
|
9
|
-
type EventFromInput<I extends OneOrMany<EventName
|
|
10
|
-
export declare function Listen<I extends OneOrMany<EventName
|
|
9
|
+
type EventFromInput<I extends OneOrMany<EventName> | string> = I extends readonly (infer K)[] ? K extends EventName ? DocumentEventMap[K] : never : I extends EventName ? DocumentEventMap[I] : never;
|
|
10
|
+
export declare function Listen<I extends OneOrMany<EventName> | string>(type: I, opts?: ListenOpts): <This, Fn extends (this: This, ev: EventFromInput<I>, ...args: any[]) => any>(value: Fn, context: ClassMethodDecoratorContext<This, Fn>) => Fn;
|
|
11
11
|
export declare function EventBindingsMixin<TBase extends Ctor<object>>(Base: TBase): TBase;
|
|
12
12
|
export {};
|