@bquery/bquery 1.2.0 → 1.3.0
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/README.md +501 -427
- package/dist/batch-4LAvfLE7.js +13 -0
- package/dist/batch-4LAvfLE7.js.map +1 -0
- package/dist/component/component.d.ts +69 -0
- package/dist/component/component.d.ts.map +1 -0
- package/dist/component/html.d.ts +35 -0
- package/dist/component/html.d.ts.map +1 -0
- package/dist/component/index.d.ts +3 -126
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/props.d.ts +18 -0
- package/dist/component/props.d.ts.map +1 -0
- package/dist/component/types.d.ts +77 -0
- package/dist/component/types.d.ts.map +1 -0
- package/dist/component.es.mjs +90 -59
- package/dist/component.es.mjs.map +1 -1
- package/dist/core/collection.d.ts +36 -0
- package/dist/core/collection.d.ts.map +1 -1
- package/dist/core/dom.d.ts +6 -0
- package/dist/core/dom.d.ts.map +1 -0
- package/dist/core/element.d.ts +8 -0
- package/dist/core/element.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/utils/array.d.ts +74 -0
- package/dist/core/utils/array.d.ts.map +1 -0
- package/dist/core/utils/function.d.ts +70 -0
- package/dist/core/utils/function.d.ts.map +1 -0
- package/dist/core/utils/index.d.ts +70 -0
- package/dist/core/utils/index.d.ts.map +1 -0
- package/dist/core/utils/misc.d.ts +63 -0
- package/dist/core/utils/misc.d.ts.map +1 -0
- package/dist/core/utils/number.d.ts +65 -0
- package/dist/core/utils/number.d.ts.map +1 -0
- package/dist/core/utils/object.d.ts +133 -0
- package/dist/core/utils/object.d.ts.map +1 -0
- package/dist/core/utils/string.d.ts +80 -0
- package/dist/core/utils/string.d.ts.map +1 -0
- package/dist/core/utils/type-guards.d.ts +79 -0
- package/dist/core/utils/type-guards.d.ts.map +1 -0
- package/dist/core-COenAZjD.js +145 -0
- package/dist/core-COenAZjD.js.map +1 -0
- package/dist/core.es.mjs +411 -448
- package/dist/core.es.mjs.map +1 -1
- package/dist/full.d.ts +2 -2
- package/dist/full.d.ts.map +1 -1
- package/dist/full.es.mjs +87 -64
- package/dist/full.es.mjs.map +1 -1
- package/dist/full.iife.js +2 -2
- package/dist/full.iife.js.map +1 -1
- package/dist/full.umd.js +2 -2
- package/dist/full.umd.js.map +1 -1
- package/dist/index.es.mjs +138 -68
- package/dist/index.es.mjs.map +1 -1
- package/dist/motion/animate.d.ts +25 -0
- package/dist/motion/animate.d.ts.map +1 -0
- package/dist/motion/easing.d.ts +30 -0
- package/dist/motion/easing.d.ts.map +1 -0
- package/dist/motion/flip.d.ts +55 -0
- package/dist/motion/flip.d.ts.map +1 -0
- package/dist/motion/index.d.ts +11 -138
- package/dist/motion/index.d.ts.map +1 -1
- package/dist/motion/keyframes.d.ts +21 -0
- package/dist/motion/keyframes.d.ts.map +1 -0
- package/dist/motion/reduced-motion.d.ts +12 -0
- package/dist/motion/reduced-motion.d.ts.map +1 -0
- package/dist/motion/scroll.d.ts +15 -0
- package/dist/motion/scroll.d.ts.map +1 -0
- package/dist/motion/spring.d.ts +42 -0
- package/dist/motion/spring.d.ts.map +1 -0
- package/dist/motion/stagger.d.ts +22 -0
- package/dist/motion/stagger.d.ts.map +1 -0
- package/dist/motion/timeline.d.ts +21 -0
- package/dist/motion/timeline.d.ts.map +1 -0
- package/dist/motion/transition.d.ts +22 -0
- package/dist/motion/transition.d.ts.map +1 -0
- package/dist/motion/types.d.ts +182 -0
- package/dist/motion/types.d.ts.map +1 -0
- package/dist/motion.es.mjs +320 -61
- package/dist/motion.es.mjs.map +1 -1
- package/dist/persisted-Dz_ryNuC.js +278 -0
- package/dist/persisted-Dz_ryNuC.js.map +1 -0
- package/dist/reactive/batch.d.ts +13 -0
- package/dist/reactive/batch.d.ts.map +1 -0
- package/dist/reactive/computed.d.ts +50 -0
- package/dist/reactive/computed.d.ts.map +1 -0
- package/dist/reactive/core.d.ts +60 -0
- package/dist/reactive/core.d.ts.map +1 -0
- package/dist/reactive/effect.d.ts +15 -0
- package/dist/reactive/effect.d.ts.map +1 -0
- package/dist/reactive/index.d.ts +2 -2
- package/dist/reactive/index.d.ts.map +1 -1
- package/dist/reactive/internals.d.ts +36 -0
- package/dist/reactive/internals.d.ts.map +1 -0
- package/dist/reactive/linked.d.ts +36 -0
- package/dist/reactive/linked.d.ts.map +1 -0
- package/dist/reactive/persisted.d.ts +14 -0
- package/dist/reactive/persisted.d.ts.map +1 -0
- package/dist/reactive/readonly.d.ts +26 -0
- package/dist/reactive/readonly.d.ts.map +1 -0
- package/dist/reactive/signal.d.ts +13 -312
- package/dist/reactive/signal.d.ts.map +1 -1
- package/dist/reactive/type-guards.d.ts +20 -0
- package/dist/reactive/type-guards.d.ts.map +1 -0
- package/dist/reactive/untrack.d.ts +29 -0
- package/dist/reactive/untrack.d.ts.map +1 -0
- package/dist/reactive/watch.d.ts +42 -0
- package/dist/reactive/watch.d.ts.map +1 -0
- package/dist/reactive.es.mjs +30 -163
- package/dist/reactive.es.mjs.map +1 -1
- package/dist/router/index.d.ts +6 -252
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/links.d.ts +44 -0
- package/dist/router/links.d.ts.map +1 -0
- package/dist/router/match.d.ts +20 -0
- package/dist/router/match.d.ts.map +1 -0
- package/dist/router/navigation.d.ts +45 -0
- package/dist/router/navigation.d.ts.map +1 -0
- package/dist/router/query.d.ts +16 -0
- package/dist/router/query.d.ts.map +1 -0
- package/dist/router/router.d.ts +34 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/state.d.ts +27 -0
- package/dist/router/state.d.ts.map +1 -0
- package/dist/router/types.d.ts +88 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/utils.d.ts +65 -0
- package/dist/router/utils.d.ts.map +1 -0
- package/dist/router.es.mjs +168 -132
- package/dist/router.es.mjs.map +1 -1
- package/dist/sanitize-1FBEPAFH.js +272 -0
- package/dist/sanitize-1FBEPAFH.js.map +1 -0
- package/dist/security/constants.d.ts +42 -0
- package/dist/security/constants.d.ts.map +1 -0
- package/dist/security/csp.d.ts +24 -0
- package/dist/security/csp.d.ts.map +1 -0
- package/dist/security/index.d.ts +4 -2
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/sanitize-core.d.ts +13 -0
- package/dist/security/sanitize-core.d.ts.map +1 -0
- package/dist/security/sanitize.d.ts +5 -57
- package/dist/security/sanitize.d.ts.map +1 -1
- package/dist/security/trusted-types.d.ts +25 -0
- package/dist/security/trusted-types.d.ts.map +1 -0
- package/dist/security/types.d.ts +36 -0
- package/dist/security/types.d.ts.map +1 -0
- package/dist/security.es.mjs +50 -277
- package/dist/security.es.mjs.map +1 -1
- package/dist/store/create-store.d.ts +15 -0
- package/dist/store/create-store.d.ts.map +1 -0
- package/dist/store/define-store.d.ts +28 -0
- package/dist/store/define-store.d.ts.map +1 -0
- package/dist/store/devtools.d.ts +22 -0
- package/dist/store/devtools.d.ts.map +1 -0
- package/dist/store/index.d.ts +10 -286
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/mapping.d.ts +28 -0
- package/dist/store/mapping.d.ts.map +1 -0
- package/dist/store/persisted.d.ts +13 -0
- package/dist/store/persisted.d.ts.map +1 -0
- package/dist/store/plugins.d.ts +13 -0
- package/dist/store/plugins.d.ts.map +1 -0
- package/dist/store/registry.d.ts +28 -0
- package/dist/store/registry.d.ts.map +1 -0
- package/dist/store/types.d.ts +71 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/utils.d.ts +28 -0
- package/dist/store/utils.d.ts.map +1 -0
- package/dist/store/watch.d.ts +23 -0
- package/dist/store/watch.d.ts.map +1 -0
- package/dist/store.es.mjs +22 -224
- package/dist/store.es.mjs.map +1 -1
- package/dist/type-guards-DRma3-Kc.js +16 -0
- package/dist/type-guards-DRma3-Kc.js.map +1 -0
- package/dist/untrack-BuEQKH7_.js +6 -0
- package/dist/untrack-BuEQKH7_.js.map +1 -0
- package/dist/view/directives/bind.d.ts +7 -0
- package/dist/view/directives/bind.d.ts.map +1 -0
- package/dist/view/directives/class.d.ts +8 -0
- package/dist/view/directives/class.d.ts.map +1 -0
- package/dist/view/directives/for.d.ts +23 -0
- package/dist/view/directives/for.d.ts.map +1 -0
- package/dist/view/directives/html.d.ts +7 -0
- package/dist/view/directives/html.d.ts.map +1 -0
- package/dist/view/directives/if.d.ts +7 -0
- package/dist/view/directives/if.d.ts.map +1 -0
- package/dist/view/directives/index.d.ts +12 -0
- package/dist/view/directives/index.d.ts.map +1 -0
- package/dist/view/directives/model.d.ts +7 -0
- package/dist/view/directives/model.d.ts.map +1 -0
- package/dist/view/directives/on.d.ts +7 -0
- package/dist/view/directives/on.d.ts.map +1 -0
- package/dist/view/directives/ref.d.ts +7 -0
- package/dist/view/directives/ref.d.ts.map +1 -0
- package/dist/view/directives/show.d.ts +7 -0
- package/dist/view/directives/show.d.ts.map +1 -0
- package/dist/view/directives/style.d.ts +7 -0
- package/dist/view/directives/style.d.ts.map +1 -0
- package/dist/view/directives/text.d.ts +7 -0
- package/dist/view/directives/text.d.ts.map +1 -0
- package/dist/view/evaluate.d.ts +43 -0
- package/dist/view/evaluate.d.ts.map +1 -0
- package/dist/view/index.d.ts +3 -93
- package/dist/view/index.d.ts.map +1 -1
- package/dist/view/mount.d.ts +69 -0
- package/dist/view/mount.d.ts.map +1 -0
- package/dist/view/process.d.ts +26 -0
- package/dist/view/process.d.ts.map +1 -0
- package/dist/view/types.d.ts +36 -0
- package/dist/view/types.d.ts.map +1 -0
- package/dist/view.es.mjs +368 -267
- package/dist/view.es.mjs.map +1 -1
- package/dist/watch-CXyaBC_9.js +58 -0
- package/dist/watch-CXyaBC_9.js.map +1 -0
- package/package.json +132 -132
- package/src/component/component.ts +289 -0
- package/src/component/html.ts +53 -0
- package/src/component/index.ts +40 -414
- package/src/component/props.ts +116 -0
- package/src/component/types.ts +85 -0
- package/src/core/collection.ts +588 -454
- package/src/core/dom.ts +38 -0
- package/src/core/element.ts +746 -740
- package/src/core/index.ts +43 -0
- package/src/core/utils/array.ts +102 -0
- package/src/core/utils/function.ts +110 -0
- package/src/core/utils/index.ts +83 -0
- package/src/core/utils/misc.ts +82 -0
- package/src/core/utils/number.ts +78 -0
- package/src/core/utils/object.ts +206 -0
- package/src/core/utils/string.ts +112 -0
- package/src/core/utils/type-guards.ts +112 -0
- package/src/full.ts +187 -150
- package/src/index.ts +36 -36
- package/src/motion/animate.ts +113 -0
- package/src/motion/easing.ts +40 -0
- package/src/motion/flip.ts +176 -0
- package/src/motion/index.ts +41 -358
- package/src/motion/keyframes.ts +46 -0
- package/src/motion/reduced-motion.ts +17 -0
- package/src/motion/scroll.ts +57 -0
- package/src/motion/spring.ts +150 -0
- package/src/motion/stagger.ts +43 -0
- package/src/motion/timeline.ts +246 -0
- package/src/motion/transition.ts +51 -0
- package/src/motion/types.ts +198 -0
- package/src/reactive/batch.ts +22 -0
- package/src/reactive/computed.ts +92 -0
- package/src/reactive/core.ts +93 -0
- package/src/reactive/effect.ts +43 -0
- package/src/reactive/index.ts +23 -22
- package/src/reactive/internals.ts +105 -0
- package/src/reactive/linked.ts +56 -0
- package/src/reactive/persisted.ts +74 -0
- package/src/reactive/readonly.ts +35 -0
- package/src/reactive/signal.ts +20 -520
- package/src/reactive/type-guards.ts +22 -0
- package/src/reactive/untrack.ts +31 -0
- package/src/reactive/watch.ts +73 -0
- package/src/router/index.ts +41 -718
- package/src/router/links.ts +130 -0
- package/src/router/match.ts +106 -0
- package/src/router/navigation.ts +71 -0
- package/src/router/query.ts +35 -0
- package/src/router/router.ts +211 -0
- package/src/router/state.ts +46 -0
- package/src/router/types.ts +93 -0
- package/src/router/utils.ts +116 -0
- package/src/security/constants.ts +209 -0
- package/src/security/csp.ts +77 -0
- package/src/security/index.ts +4 -12
- package/src/security/sanitize-core.ts +343 -0
- package/src/security/sanitize.ts +66 -625
- package/src/security/trusted-types.ts +69 -0
- package/src/security/types.ts +40 -0
- package/src/store/create-store.ts +329 -0
- package/src/store/define-store.ts +48 -0
- package/src/store/devtools.ts +45 -0
- package/src/store/index.ts +22 -848
- package/src/store/mapping.ts +73 -0
- package/src/store/persisted.ts +61 -0
- package/src/store/plugins.ts +32 -0
- package/src/store/registry.ts +51 -0
- package/src/store/types.ts +94 -0
- package/src/store/utils.ts +141 -0
- package/src/store/watch.ts +52 -0
- package/src/view/directives/bind.ts +23 -0
- package/src/view/directives/class.ts +70 -0
- package/src/view/directives/for.ts +275 -0
- package/src/view/directives/html.ts +19 -0
- package/src/view/directives/if.ts +30 -0
- package/src/view/directives/index.ts +11 -0
- package/src/view/directives/model.ts +56 -0
- package/src/view/directives/on.ts +41 -0
- package/src/view/directives/ref.ts +41 -0
- package/src/view/directives/show.ts +26 -0
- package/src/view/directives/style.ts +47 -0
- package/src/view/directives/text.ts +15 -0
- package/src/view/evaluate.ts +274 -0
- package/src/view/index.ts +112 -1041
- package/src/view/mount.ts +200 -0
- package/src/view/process.ts +92 -0
- package/src/view/types.ts +44 -0
- package/dist/core/utils.d.ts +0 -313
- package/dist/core/utils.d.ts.map +0 -1
- package/src/core/utils.ts +0 -444
package/dist/core.es.mjs
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
3
|
-
for (const t of
|
|
1
|
+
import { s as f } from "./sanitize-1FBEPAFH.js";
|
|
2
|
+
const g = (n) => Array.isArray(n) ? n : [n], o = (n, e) => {
|
|
3
|
+
for (const t of n)
|
|
4
4
|
e(t);
|
|
5
|
+
}, p = (n) => f(n), w = (n, e) => {
|
|
6
|
+
n.innerHTML = f(e);
|
|
7
|
+
}, y = (n) => {
|
|
8
|
+
const e = document.createElement("template");
|
|
9
|
+
return e.innerHTML = f(n), e.content.firstElementChild ?? document.createElement("div");
|
|
10
|
+
}, b = (n, e, t) => {
|
|
11
|
+
if (typeof e == "string") {
|
|
12
|
+
n.insertAdjacentHTML(t, f(e));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const r = g(e), i = t === "afterbegin" || t === "afterend" ? r.slice().reverse() : r;
|
|
16
|
+
o(i, (l) => {
|
|
17
|
+
n.insertAdjacentElement(t, l);
|
|
18
|
+
});
|
|
5
19
|
};
|
|
6
|
-
class
|
|
20
|
+
class h {
|
|
7
21
|
/**
|
|
8
22
|
* Creates a new BQueryElement wrapper.
|
|
9
23
|
* @param element - The DOM element to wrap
|
|
@@ -41,14 +55,23 @@ class a {
|
|
|
41
55
|
attr(e, t) {
|
|
42
56
|
return t === void 0 ? this.element.getAttribute(e) ?? "" : (this.element.setAttribute(e, t), this);
|
|
43
57
|
}
|
|
58
|
+
/** Remove an attribute. */
|
|
59
|
+
removeAttr(e) {
|
|
60
|
+
return this.element.removeAttribute(e), this;
|
|
61
|
+
}
|
|
62
|
+
/** Toggle an attribute on/off. */
|
|
63
|
+
toggleAttr(e, t) {
|
|
64
|
+
const r = this.element.hasAttribute(e);
|
|
65
|
+
return t ?? !r ? this.element.setAttribute(e, "") : this.element.removeAttribute(e), this;
|
|
66
|
+
}
|
|
44
67
|
/** Get or set a property. */
|
|
45
68
|
prop(e, t) {
|
|
46
69
|
return t === void 0 ? this.element[e] : (this.element[e] = t, this);
|
|
47
70
|
}
|
|
48
71
|
/** Read or write data attributes in camelCase. */
|
|
49
72
|
data(e, t) {
|
|
50
|
-
const
|
|
51
|
-
return t === void 0 ? this.element.getAttribute(`data-${
|
|
73
|
+
const r = e.replace(/[A-Z]/g, (s) => `-${s.toLowerCase()}`);
|
|
74
|
+
return t === void 0 ? this.element.getAttribute(`data-${r}`) ?? "" : (this.element.setAttribute(`data-${r}`, t), this);
|
|
52
75
|
}
|
|
53
76
|
/** Get or set text content. */
|
|
54
77
|
text(e) {
|
|
@@ -68,7 +91,7 @@ class a {
|
|
|
68
91
|
* ```
|
|
69
92
|
*/
|
|
70
93
|
html(e) {
|
|
71
|
-
return this.element
|
|
94
|
+
return w(this.element, e), this;
|
|
72
95
|
}
|
|
73
96
|
/**
|
|
74
97
|
* Sets HTML content without sanitization.
|
|
@@ -101,8 +124,8 @@ class a {
|
|
|
101
124
|
css(e, t) {
|
|
102
125
|
if (typeof e == "string")
|
|
103
126
|
return t !== void 0 && this.element.style.setProperty(e, t), this;
|
|
104
|
-
for (const [
|
|
105
|
-
this.element.style.setProperty(
|
|
127
|
+
for (const [r, s] of Object.entries(e))
|
|
128
|
+
this.element.style.setProperty(r, s);
|
|
106
129
|
return this;
|
|
107
130
|
}
|
|
108
131
|
/**
|
|
@@ -161,6 +184,10 @@ class a {
|
|
|
161
184
|
* Removes the parent element, keeping this element in its place.
|
|
162
185
|
* Essentially the opposite of wrap().
|
|
163
186
|
*
|
|
187
|
+
* **Important**: This method only moves the current element out of its parent
|
|
188
|
+
* before removing the parent. Any sibling elements will be removed along with
|
|
189
|
+
* the parent. For unwrapping multiple siblings, use a collection: `$$(siblings).unwrap()`.
|
|
190
|
+
*
|
|
164
191
|
* @returns The instance for method chaining
|
|
165
192
|
*
|
|
166
193
|
* @example
|
|
@@ -186,13 +213,8 @@ class a {
|
|
|
186
213
|
* ```
|
|
187
214
|
*/
|
|
188
215
|
replaceWith(e) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const n = document.createElement("template");
|
|
192
|
-
n.innerHTML = f(e), t = n.content.firstElementChild ?? document.createElement("div");
|
|
193
|
-
} else
|
|
194
|
-
t = e;
|
|
195
|
-
return this.element.replaceWith(t), new a(t);
|
|
216
|
+
const t = typeof e == "string" ? y(e) : e;
|
|
217
|
+
return this.element.replaceWith(t), new h(t);
|
|
196
218
|
}
|
|
197
219
|
/**
|
|
198
220
|
* Scrolls the element into view with configurable behavior.
|
|
@@ -232,7 +254,7 @@ class a {
|
|
|
232
254
|
* @returns A new BQueryElement wrapping the cloned element
|
|
233
255
|
*/
|
|
234
256
|
clone(e = !0) {
|
|
235
|
-
return new
|
|
257
|
+
return new h(this.element.cloneNode(e));
|
|
236
258
|
}
|
|
237
259
|
/**
|
|
238
260
|
* Finds all descendant elements matching the selector.
|
|
@@ -363,12 +385,12 @@ class a {
|
|
|
363
385
|
* $('#list').undelegate('click', '.item', handler);
|
|
364
386
|
* ```
|
|
365
387
|
*/
|
|
366
|
-
delegate(e, t,
|
|
388
|
+
delegate(e, t, r) {
|
|
367
389
|
const s = `${e}:${t}`, i = (l) => {
|
|
368
|
-
const
|
|
369
|
-
|
|
390
|
+
const u = l.target.closest(t);
|
|
391
|
+
u && this.element.contains(u) && r(l, u);
|
|
370
392
|
};
|
|
371
|
-
return this.delegatedHandlers.has(s) || this.delegatedHandlers.set(s, /* @__PURE__ */ new Map()), this.delegatedHandlers.get(s).set(
|
|
393
|
+
return this.delegatedHandlers.has(s) || this.delegatedHandlers.set(s, /* @__PURE__ */ new Map()), this.delegatedHandlers.get(s).set(r, i), this.element.addEventListener(e, i), this;
|
|
372
394
|
}
|
|
373
395
|
/**
|
|
374
396
|
* Removes a delegated event listener previously added with `delegate()`.
|
|
@@ -387,11 +409,11 @@ class a {
|
|
|
387
409
|
* $('#list').undelegate('click', '.item', handler);
|
|
388
410
|
* ```
|
|
389
411
|
*/
|
|
390
|
-
undelegate(e, t,
|
|
412
|
+
undelegate(e, t, r) {
|
|
391
413
|
const s = `${e}:${t}`, i = this.delegatedHandlers.get(s);
|
|
392
414
|
if (i) {
|
|
393
|
-
const l = i.get(
|
|
394
|
-
l && (this.element.removeEventListener(e, l), i.delete(
|
|
415
|
+
const l = i.get(r);
|
|
416
|
+
l && (this.element.removeEventListener(e, l), i.delete(r), i.size === 0 && this.delegatedHandlers.delete(s));
|
|
395
417
|
}
|
|
396
418
|
return this;
|
|
397
419
|
}
|
|
@@ -483,8 +505,8 @@ class a {
|
|
|
483
505
|
const e = this.element;
|
|
484
506
|
if (e.tagName.toLowerCase() !== "form")
|
|
485
507
|
return {};
|
|
486
|
-
const t = {},
|
|
487
|
-
for (const [s, i] of
|
|
508
|
+
const t = {}, r = new FormData(e);
|
|
509
|
+
for (const [s, i] of r.entries())
|
|
488
510
|
if (typeof i == "string")
|
|
489
511
|
if (s in t) {
|
|
490
512
|
const l = t[s];
|
|
@@ -508,10 +530,10 @@ class a {
|
|
|
508
530
|
const e = this.element;
|
|
509
531
|
if (e.tagName.toLowerCase() !== "form")
|
|
510
532
|
return "";
|
|
511
|
-
const t = new FormData(e),
|
|
533
|
+
const t = new FormData(e), r = new URLSearchParams();
|
|
512
534
|
for (const [s, i] of t.entries())
|
|
513
|
-
typeof i == "string" &&
|
|
514
|
-
return
|
|
535
|
+
typeof i == "string" && r.append(s, i);
|
|
536
|
+
return r.toString();
|
|
515
537
|
}
|
|
516
538
|
/**
|
|
517
539
|
* Gets the bounding client rectangle of the element.
|
|
@@ -540,17 +562,10 @@ class a {
|
|
|
540
562
|
* @internal
|
|
541
563
|
*/
|
|
542
564
|
insertContent(e, t) {
|
|
543
|
-
|
|
544
|
-
this.element.insertAdjacentHTML(t, f(e));
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
const n = p(e);
|
|
548
|
-
o(n, (s) => {
|
|
549
|
-
this.element.insertAdjacentElement(t, s);
|
|
550
|
-
});
|
|
565
|
+
b(this.element, e, t);
|
|
551
566
|
}
|
|
552
567
|
}
|
|
553
|
-
class
|
|
568
|
+
class c {
|
|
554
569
|
/**
|
|
555
570
|
* Creates a new collection wrapper.
|
|
556
571
|
* @param elements - Array of DOM elements to wrap
|
|
@@ -579,7 +594,7 @@ class m {
|
|
|
579
594
|
*/
|
|
580
595
|
eq(e) {
|
|
581
596
|
const t = this.elements[e];
|
|
582
|
-
return t ? new
|
|
597
|
+
return t ? new h(t) : void 0;
|
|
583
598
|
}
|
|
584
599
|
/**
|
|
585
600
|
* Gets the first element as a BQueryElement wrapper.
|
|
@@ -604,8 +619,8 @@ class m {
|
|
|
604
619
|
* @returns The instance for method chaining
|
|
605
620
|
*/
|
|
606
621
|
each(e) {
|
|
607
|
-
return this.elements.forEach((t,
|
|
608
|
-
e(new
|
|
622
|
+
return this.elements.forEach((t, r) => {
|
|
623
|
+
e(new h(t), r);
|
|
609
624
|
}), this;
|
|
610
625
|
}
|
|
611
626
|
/**
|
|
@@ -624,7 +639,7 @@ class m {
|
|
|
624
639
|
* @returns New BQueryCollection with matching elements
|
|
625
640
|
*/
|
|
626
641
|
filter(e) {
|
|
627
|
-
return new
|
|
642
|
+
return new c(this.elements.filter(e));
|
|
628
643
|
}
|
|
629
644
|
/**
|
|
630
645
|
* Reduces the collection to a single value.
|
|
@@ -642,7 +657,7 @@ class m {
|
|
|
642
657
|
* @returns Array of BQueryElement instances
|
|
643
658
|
*/
|
|
644
659
|
toArray() {
|
|
645
|
-
return this.elements.map((e) => new
|
|
660
|
+
return this.elements.map((e) => new h(e));
|
|
646
661
|
}
|
|
647
662
|
/** Add one or more classes to all elements. */
|
|
648
663
|
addClass(...e) {
|
|
@@ -654,7 +669,7 @@ class m {
|
|
|
654
669
|
}
|
|
655
670
|
/** Toggle a class on all elements. */
|
|
656
671
|
toggleClass(e, t) {
|
|
657
|
-
return o(this.elements, (
|
|
672
|
+
return o(this.elements, (r) => r.classList.toggle(e, t)), this;
|
|
658
673
|
}
|
|
659
674
|
/**
|
|
660
675
|
* Sets an attribute on all elements or gets from first.
|
|
@@ -664,7 +679,7 @@ class m {
|
|
|
664
679
|
* @returns Attribute value when getting, instance when setting
|
|
665
680
|
*/
|
|
666
681
|
attr(e, t) {
|
|
667
|
-
return t === void 0 ? this.first()?.getAttribute(e) ?? "" : (o(this.elements, (
|
|
682
|
+
return t === void 0 ? this.first()?.getAttribute(e) ?? "" : (o(this.elements, (r) => r.setAttribute(e, t)), this);
|
|
668
683
|
}
|
|
669
684
|
/**
|
|
670
685
|
* Removes an attribute from all elements.
|
|
@@ -675,6 +690,13 @@ class m {
|
|
|
675
690
|
removeAttr(e) {
|
|
676
691
|
return o(this.elements, (t) => t.removeAttribute(e)), this;
|
|
677
692
|
}
|
|
693
|
+
/** Toggle an attribute on all elements. */
|
|
694
|
+
toggleAttr(e, t) {
|
|
695
|
+
return o(this.elements, (r) => {
|
|
696
|
+
const s = r.hasAttribute(e);
|
|
697
|
+
t ?? !s ? r.setAttribute(e, "") : r.removeAttribute(e);
|
|
698
|
+
}), this;
|
|
699
|
+
}
|
|
678
700
|
/**
|
|
679
701
|
* Sets text content on all elements or gets from first.
|
|
680
702
|
*
|
|
@@ -695,9 +717,9 @@ class m {
|
|
|
695
717
|
html(e) {
|
|
696
718
|
if (e === void 0)
|
|
697
719
|
return this.first()?.innerHTML ?? "";
|
|
698
|
-
const t =
|
|
699
|
-
return o(this.elements, (
|
|
700
|
-
|
|
720
|
+
const t = p(e);
|
|
721
|
+
return o(this.elements, (r) => {
|
|
722
|
+
r.innerHTML = t;
|
|
701
723
|
}), this;
|
|
702
724
|
}
|
|
703
725
|
/**
|
|
@@ -712,6 +734,22 @@ class m {
|
|
|
712
734
|
t.innerHTML = e;
|
|
713
735
|
}), this;
|
|
714
736
|
}
|
|
737
|
+
/** Append content to all elements. */
|
|
738
|
+
append(e) {
|
|
739
|
+
return this.insertAll(e, "beforeend"), this;
|
|
740
|
+
}
|
|
741
|
+
/** Prepend content to all elements. */
|
|
742
|
+
prepend(e) {
|
|
743
|
+
return this.insertAll(e, "afterbegin"), this;
|
|
744
|
+
}
|
|
745
|
+
/** Insert content before all elements. */
|
|
746
|
+
before(e) {
|
|
747
|
+
return this.insertAll(e, "beforebegin"), this;
|
|
748
|
+
}
|
|
749
|
+
/** Insert content after all elements. */
|
|
750
|
+
after(e) {
|
|
751
|
+
return this.insertAll(e, "afterend"), this;
|
|
752
|
+
}
|
|
715
753
|
/**
|
|
716
754
|
* Applies CSS styles to all elements.
|
|
717
755
|
*
|
|
@@ -720,13 +758,59 @@ class m {
|
|
|
720
758
|
* @returns The instance for method chaining
|
|
721
759
|
*/
|
|
722
760
|
css(e, t) {
|
|
723
|
-
return typeof e == "string" ? (t !== void 0 && o(this.elements, (
|
|
724
|
-
|
|
725
|
-
}), this) : (o(this.elements, (
|
|
761
|
+
return typeof e == "string" ? (t !== void 0 && o(this.elements, (r) => {
|
|
762
|
+
r.style.setProperty(e, t);
|
|
763
|
+
}), this) : (o(this.elements, (r) => {
|
|
726
764
|
for (const [s, i] of Object.entries(e))
|
|
727
|
-
|
|
765
|
+
r.style.setProperty(s, i);
|
|
728
766
|
}), this);
|
|
729
767
|
}
|
|
768
|
+
/** Wrap each element with a wrapper element or tag. */
|
|
769
|
+
wrap(e) {
|
|
770
|
+
return this.elements.forEach((t, r) => {
|
|
771
|
+
const s = typeof e == "string" ? document.createElement(e) : r === 0 ? e : e.cloneNode(!0);
|
|
772
|
+
t.parentNode?.insertBefore(s, t), s.appendChild(t);
|
|
773
|
+
}), this;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Remove the parent element of each element, keeping the elements in place.
|
|
777
|
+
*
|
|
778
|
+
* **Important**: This method unwraps ALL children of each parent element,
|
|
779
|
+
* not just the elements in the collection. If you call `unwrap()` on a
|
|
780
|
+
* collection containing only some children of a parent, all siblings will
|
|
781
|
+
* also be unwrapped. This behavior is consistent with jQuery's `.unwrap()`.
|
|
782
|
+
*
|
|
783
|
+
* @returns The collection for chaining
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* ```ts
|
|
787
|
+
* // HTML: <div><section><span>A</span><span>B</span></section></div>
|
|
788
|
+
* const spans = $$('span');
|
|
789
|
+
* spans.unwrap(); // Removes <section>, both spans move to <div>
|
|
790
|
+
* // Result: <div><span>A</span><span>B</span></div>
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
793
|
+
unwrap() {
|
|
794
|
+
const e = /* @__PURE__ */ new Set();
|
|
795
|
+
for (const t of this.elements)
|
|
796
|
+
t.parentElement && e.add(t.parentElement);
|
|
797
|
+
return e.forEach((t) => {
|
|
798
|
+
const r = t.parentNode;
|
|
799
|
+
if (r) {
|
|
800
|
+
for (; t.firstChild; )
|
|
801
|
+
r.insertBefore(t.firstChild, t);
|
|
802
|
+
t.remove();
|
|
803
|
+
}
|
|
804
|
+
}), this;
|
|
805
|
+
}
|
|
806
|
+
/** Replace each element with provided content. */
|
|
807
|
+
replaceWith(e) {
|
|
808
|
+
const t = [];
|
|
809
|
+
return this.elements.forEach((r, s) => {
|
|
810
|
+
const i = typeof e == "string" ? y(e) : s === 0 ? e : e.cloneNode(!0);
|
|
811
|
+
r.replaceWith(i), t.push(i);
|
|
812
|
+
}), new c(t);
|
|
813
|
+
}
|
|
730
814
|
/**
|
|
731
815
|
* Shows all elements.
|
|
732
816
|
*
|
|
@@ -756,7 +840,7 @@ class m {
|
|
|
756
840
|
* @returns The instance for method chaining
|
|
757
841
|
*/
|
|
758
842
|
on(e, t) {
|
|
759
|
-
return o(this.elements, (
|
|
843
|
+
return o(this.elements, (r) => r.addEventListener(e, t)), this;
|
|
760
844
|
}
|
|
761
845
|
/**
|
|
762
846
|
* Adds a one-time event listener to all elements.
|
|
@@ -766,7 +850,7 @@ class m {
|
|
|
766
850
|
* @returns The instance for method chaining
|
|
767
851
|
*/
|
|
768
852
|
once(e, t) {
|
|
769
|
-
return o(this.elements, (
|
|
853
|
+
return o(this.elements, (r) => r.addEventListener(e, t, { once: !0 })), this;
|
|
770
854
|
}
|
|
771
855
|
/**
|
|
772
856
|
* Removes an event listener from all elements.
|
|
@@ -776,7 +860,7 @@ class m {
|
|
|
776
860
|
* @returns The instance for method chaining
|
|
777
861
|
*/
|
|
778
862
|
off(e, t) {
|
|
779
|
-
return o(this.elements, (
|
|
863
|
+
return o(this.elements, (r) => r.removeEventListener(e, t)), this;
|
|
780
864
|
}
|
|
781
865
|
/**
|
|
782
866
|
* Triggers a custom event on all elements.
|
|
@@ -786,8 +870,8 @@ class m {
|
|
|
786
870
|
* @returns The instance for method chaining
|
|
787
871
|
*/
|
|
788
872
|
trigger(e, t) {
|
|
789
|
-
return o(this.elements, (
|
|
790
|
-
|
|
873
|
+
return o(this.elements, (r) => {
|
|
874
|
+
r.dispatchEvent(new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 }));
|
|
791
875
|
}), this;
|
|
792
876
|
}
|
|
793
877
|
/**
|
|
@@ -810,16 +894,16 @@ class m {
|
|
|
810
894
|
* $$('.container').undelegate('click', '.item', handler);
|
|
811
895
|
* ```
|
|
812
896
|
*/
|
|
813
|
-
delegate(e, t,
|
|
897
|
+
delegate(e, t, r) {
|
|
814
898
|
const s = `${e}:${t}`;
|
|
815
899
|
return o(this.elements, (i) => {
|
|
816
|
-
const l = (
|
|
817
|
-
const
|
|
818
|
-
|
|
900
|
+
const l = (a) => {
|
|
901
|
+
const m = a.target.closest(t);
|
|
902
|
+
m && i.contains(m) && r(a, m);
|
|
819
903
|
};
|
|
820
904
|
this.delegatedHandlers.has(i) || this.delegatedHandlers.set(i, /* @__PURE__ */ new Map());
|
|
821
|
-
const
|
|
822
|
-
|
|
905
|
+
const u = this.delegatedHandlers.get(i);
|
|
906
|
+
u.has(s) || u.set(s, /* @__PURE__ */ new Map()), u.get(s).set(r, l), i.addEventListener(e, l);
|
|
823
907
|
}), this;
|
|
824
908
|
}
|
|
825
909
|
/**
|
|
@@ -839,15 +923,15 @@ class m {
|
|
|
839
923
|
* $$('.container').undelegate('click', '.item', handler);
|
|
840
924
|
* ```
|
|
841
925
|
*/
|
|
842
|
-
undelegate(e, t,
|
|
926
|
+
undelegate(e, t, r) {
|
|
843
927
|
const s = `${e}:${t}`;
|
|
844
928
|
return o(this.elements, (i) => {
|
|
845
929
|
const l = this.delegatedHandlers.get(i);
|
|
846
930
|
if (!l) return;
|
|
847
|
-
const
|
|
848
|
-
if (!
|
|
849
|
-
const
|
|
850
|
-
|
|
931
|
+
const u = l.get(s);
|
|
932
|
+
if (!u) return;
|
|
933
|
+
const a = u.get(r);
|
|
934
|
+
a && (i.removeEventListener(e, a), u.delete(r), u.size === 0 && l.delete(s), l.size === 0 && this.delegatedHandlers.delete(i));
|
|
851
935
|
}), this;
|
|
852
936
|
}
|
|
853
937
|
/**
|
|
@@ -868,391 +952,270 @@ class m {
|
|
|
868
952
|
e.innerHTML = "";
|
|
869
953
|
}), this;
|
|
870
954
|
}
|
|
955
|
+
/** @internal */
|
|
956
|
+
insertAll(e, t) {
|
|
957
|
+
if (typeof e == "string") {
|
|
958
|
+
const s = p(e);
|
|
959
|
+
o(this.elements, (i) => {
|
|
960
|
+
i.insertAdjacentHTML(t, s);
|
|
961
|
+
});
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
const r = g(e);
|
|
965
|
+
this.elements.forEach((s, i) => {
|
|
966
|
+
const l = i === 0 ? r : r.map((u) => u.cloneNode(!0));
|
|
967
|
+
b(s, l, t);
|
|
968
|
+
});
|
|
969
|
+
}
|
|
871
970
|
}
|
|
872
|
-
const
|
|
873
|
-
if (typeof
|
|
874
|
-
return new
|
|
875
|
-
const e = document.querySelector(
|
|
971
|
+
const oe = (n) => {
|
|
972
|
+
if (typeof n != "string")
|
|
973
|
+
return new h(n);
|
|
974
|
+
const e = document.querySelector(n);
|
|
876
975
|
if (!e)
|
|
877
|
-
throw new Error(`bQuery: element not found for selector "${
|
|
878
|
-
return new
|
|
879
|
-
},
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
976
|
+
throw new Error(`bQuery: element not found for selector "${n}"`);
|
|
977
|
+
return new h(e);
|
|
978
|
+
}, le = (n) => Array.isArray(n) ? new c(n) : n instanceof NodeList ? new c(Array.from(n)) : new c(Array.from(document.querySelectorAll(n)));
|
|
979
|
+
function E(n) {
|
|
980
|
+
return n == null ? [] : Array.isArray(n) ? n : [n];
|
|
981
|
+
}
|
|
982
|
+
function C(n) {
|
|
983
|
+
return Array.from(new Set(n));
|
|
984
|
+
}
|
|
985
|
+
function L(n, e) {
|
|
986
|
+
if (e <= 0) return [];
|
|
987
|
+
const t = [];
|
|
988
|
+
for (let r = 0; r < n.length; r += e)
|
|
989
|
+
t.push(n.slice(r, r + e));
|
|
990
|
+
return t;
|
|
991
|
+
}
|
|
992
|
+
function H(n) {
|
|
993
|
+
return n.filter(Boolean);
|
|
994
|
+
}
|
|
995
|
+
function v(n) {
|
|
996
|
+
const e = [];
|
|
997
|
+
for (const t of n)
|
|
998
|
+
Array.isArray(t) ? e.push(...t) : e.push(t);
|
|
999
|
+
return e;
|
|
1000
|
+
}
|
|
1001
|
+
function N(n, e) {
|
|
1002
|
+
let t;
|
|
1003
|
+
return (...r) => {
|
|
1004
|
+
t && clearTimeout(t), t = setTimeout(() => n(...r), e);
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
function $(n, e) {
|
|
1008
|
+
let t = 0;
|
|
1009
|
+
return (...r) => {
|
|
1010
|
+
const s = Date.now();
|
|
1011
|
+
s - t >= e && (t = s, n(...r));
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
function M(n) {
|
|
1015
|
+
let e = !1, t;
|
|
1016
|
+
return (...r) => (e || (t = n(...r), e = !0), t);
|
|
1017
|
+
}
|
|
1018
|
+
function S() {
|
|
1019
|
+
}
|
|
1020
|
+
function j(n = "bQuery") {
|
|
1021
|
+
return `${n}_${Math.random().toString(36).slice(2, 9)}`;
|
|
1022
|
+
}
|
|
1023
|
+
function O(n) {
|
|
1024
|
+
return new Promise((e) => setTimeout(e, n));
|
|
1025
|
+
}
|
|
1026
|
+
function T(n, e) {
|
|
1027
|
+
try {
|
|
1028
|
+
return JSON.parse(n);
|
|
1029
|
+
} catch {
|
|
927
1030
|
return e;
|
|
928
|
-
},
|
|
929
|
-
/**
|
|
930
|
-
* Checks if a key could cause prototype pollution.
|
|
931
|
-
* These keys are dangerous when used in object merging operations.
|
|
932
|
-
*
|
|
933
|
-
* @param key - The key to check
|
|
934
|
-
* @returns True if the key is a prototype pollution vector
|
|
935
|
-
*
|
|
936
|
-
* @internal
|
|
937
|
-
*/
|
|
938
|
-
isPrototypePollutionKey(r) {
|
|
939
|
-
return r === "__proto__" || r === "constructor" || r === "prototype";
|
|
940
|
-
},
|
|
941
|
-
/**
|
|
942
|
-
* Creates a debounced function that delays execution until after
|
|
943
|
-
* the specified delay has elapsed since the last call.
|
|
944
|
-
*
|
|
945
|
-
* @template TArgs - The argument types of the function
|
|
946
|
-
* @param fn - The function to debounce
|
|
947
|
-
* @param delayMs - Delay in milliseconds
|
|
948
|
-
* @returns A debounced version of the function
|
|
949
|
-
*
|
|
950
|
-
* @example
|
|
951
|
-
* ```ts
|
|
952
|
-
* const search = utils.debounce((query: string) => {
|
|
953
|
-
* console.log('Searching:', query);
|
|
954
|
-
* }, 300);
|
|
955
|
-
*
|
|
956
|
-
* search('h');
|
|
957
|
-
* search('he');
|
|
958
|
-
* search('hello'); // Only this call executes after 300ms
|
|
959
|
-
* ```
|
|
960
|
-
*/
|
|
961
|
-
debounce(r, e) {
|
|
962
|
-
let t;
|
|
963
|
-
return (...n) => {
|
|
964
|
-
t && clearTimeout(t), t = setTimeout(() => r(...n), e);
|
|
965
|
-
};
|
|
966
|
-
},
|
|
967
|
-
/**
|
|
968
|
-
* Creates a throttled function that runs at most once per interval.
|
|
969
|
-
*
|
|
970
|
-
* @template TArgs - The argument types of the function
|
|
971
|
-
* @param fn - The function to throttle
|
|
972
|
-
* @param intervalMs - Minimum interval between calls in milliseconds
|
|
973
|
-
* @returns A throttled version of the function
|
|
974
|
-
*
|
|
975
|
-
* @example
|
|
976
|
-
* ```ts
|
|
977
|
-
* const handleScroll = utils.throttle(() => {
|
|
978
|
-
* console.log('Scroll position:', window.scrollY);
|
|
979
|
-
* }, 100);
|
|
980
|
-
*
|
|
981
|
-
* window.addEventListener('scroll', handleScroll);
|
|
982
|
-
* ```
|
|
983
|
-
*/
|
|
984
|
-
throttle(r, e) {
|
|
985
|
-
let t = 0;
|
|
986
|
-
return (...n) => {
|
|
987
|
-
const s = Date.now();
|
|
988
|
-
s - t >= e && (t = s, r(...n));
|
|
989
|
-
};
|
|
990
|
-
},
|
|
991
|
-
/**
|
|
992
|
-
* Creates a stable unique ID for DOM usage.
|
|
993
|
-
*
|
|
994
|
-
* @param prefix - Optional prefix for the ID (default: 'bQuery')
|
|
995
|
-
* @returns A unique identifier string
|
|
996
|
-
*
|
|
997
|
-
* @example
|
|
998
|
-
* ```ts
|
|
999
|
-
* const id = utils.uid('modal'); // 'modal_x7k2m9p'
|
|
1000
|
-
* ```
|
|
1001
|
-
*/
|
|
1002
|
-
uid(r = "bQuery") {
|
|
1003
|
-
return `${r}_${Math.random().toString(36).slice(2, 9)}`;
|
|
1004
|
-
},
|
|
1005
|
-
/**
|
|
1006
|
-
* Checks if a value is a DOM Element.
|
|
1007
|
-
*
|
|
1008
|
-
* @param value - The value to check
|
|
1009
|
-
* @returns True if the value is an Element
|
|
1010
|
-
*/
|
|
1011
|
-
isElement(r) {
|
|
1012
|
-
return r instanceof Element;
|
|
1013
|
-
},
|
|
1014
|
-
/**
|
|
1015
|
-
* Checks if a value is a BQueryCollection-like object.
|
|
1016
|
-
*
|
|
1017
|
-
* @param value - The value to check
|
|
1018
|
-
* @returns True if the value has an elements array property
|
|
1019
|
-
*/
|
|
1020
|
-
isCollection(r) {
|
|
1021
|
-
return !!(r && typeof r == "object" && "elements" in r);
|
|
1022
|
-
},
|
|
1023
|
-
/**
|
|
1024
|
-
* Checks for emptiness across common value types.
|
|
1025
|
-
*
|
|
1026
|
-
* @param value - The value to check
|
|
1027
|
-
* @returns True if the value is empty (null, undefined, empty string, empty array, or empty object)
|
|
1028
|
-
*
|
|
1029
|
-
* @example
|
|
1030
|
-
* ```ts
|
|
1031
|
-
* utils.isEmpty(''); // true
|
|
1032
|
-
* utils.isEmpty([]); // true
|
|
1033
|
-
* utils.isEmpty({}); // true
|
|
1034
|
-
* utils.isEmpty(null); // true
|
|
1035
|
-
* utils.isEmpty('hello'); // false
|
|
1036
|
-
* utils.isEmpty([1, 2]); // false
|
|
1037
|
-
* ```
|
|
1038
|
-
*/
|
|
1039
|
-
isEmpty(r) {
|
|
1040
|
-
return r == null ? !0 : typeof r == "string" ? r.trim().length === 0 : Array.isArray(r) ? r.length === 0 : typeof r == "object" ? Object.keys(r).length === 0 : !1;
|
|
1041
|
-
},
|
|
1042
|
-
/**
|
|
1043
|
-
* Checks if a value is a plain object (not null, array, or class instance).
|
|
1044
|
-
*
|
|
1045
|
-
* @param value - The value to check
|
|
1046
|
-
* @returns True if the value is a plain object
|
|
1047
|
-
*/
|
|
1048
|
-
isPlainObject(r) {
|
|
1049
|
-
return Object.prototype.toString.call(r) === "[object Object]";
|
|
1050
|
-
},
|
|
1051
|
-
/**
|
|
1052
|
-
* Checks if a value is a function.
|
|
1053
|
-
*
|
|
1054
|
-
* @param value - The value to check
|
|
1055
|
-
* @returns True if the value is a function
|
|
1056
|
-
*/
|
|
1057
|
-
isFunction(r) {
|
|
1058
|
-
return typeof r == "function";
|
|
1059
|
-
},
|
|
1060
|
-
/**
|
|
1061
|
-
* Checks if a value is a string.
|
|
1062
|
-
*
|
|
1063
|
-
* @param value - The value to check
|
|
1064
|
-
* @returns True if the value is a string
|
|
1065
|
-
*/
|
|
1066
|
-
isString(r) {
|
|
1067
|
-
return typeof r == "string";
|
|
1068
|
-
},
|
|
1069
|
-
/**
|
|
1070
|
-
* Checks if a value is a number (excluding NaN).
|
|
1071
|
-
*
|
|
1072
|
-
* @param value - The value to check
|
|
1073
|
-
* @returns True if the value is a valid number
|
|
1074
|
-
*/
|
|
1075
|
-
isNumber(r) {
|
|
1076
|
-
return typeof r == "number" && !Number.isNaN(r);
|
|
1077
|
-
},
|
|
1078
|
-
/**
|
|
1079
|
-
* Checks if a value is a boolean.
|
|
1080
|
-
*
|
|
1081
|
-
* @param value - The value to check
|
|
1082
|
-
* @returns True if the value is a boolean
|
|
1083
|
-
*/
|
|
1084
|
-
isBoolean(r) {
|
|
1085
|
-
return typeof r == "boolean";
|
|
1086
|
-
},
|
|
1087
|
-
/**
|
|
1088
|
-
* Checks if a value is an array.
|
|
1089
|
-
*
|
|
1090
|
-
* @template T - The type of array elements
|
|
1091
|
-
* @param value - The value to check
|
|
1092
|
-
* @returns True if the value is an array
|
|
1093
|
-
*/
|
|
1094
|
-
isArray(r) {
|
|
1095
|
-
return Array.isArray(r);
|
|
1096
|
-
},
|
|
1097
|
-
/**
|
|
1098
|
-
* Safely parses a JSON string, returning a default value on error.
|
|
1099
|
-
*
|
|
1100
|
-
* @template T - The expected type of the parsed value
|
|
1101
|
-
* @param json - The JSON string to parse
|
|
1102
|
-
* @param fallback - The default value if parsing fails
|
|
1103
|
-
* @returns The parsed value or the fallback
|
|
1104
|
-
*
|
|
1105
|
-
* @example
|
|
1106
|
-
* ```ts
|
|
1107
|
-
* utils.parseJson('{"name":"bQuery"}', {}); // { name: 'bQuery' }
|
|
1108
|
-
* utils.parseJson('invalid', {}); // {}
|
|
1109
|
-
* ```
|
|
1110
|
-
*/
|
|
1111
|
-
parseJson(r, e) {
|
|
1112
|
-
try {
|
|
1113
|
-
return JSON.parse(r);
|
|
1114
|
-
} catch {
|
|
1115
|
-
return e;
|
|
1116
|
-
}
|
|
1117
|
-
},
|
|
1118
|
-
/**
|
|
1119
|
-
* Picks specified keys from an object.
|
|
1120
|
-
*
|
|
1121
|
-
* @template T - The object type
|
|
1122
|
-
* @template K - The key type
|
|
1123
|
-
* @param obj - The source object
|
|
1124
|
-
* @param keys - Keys to pick
|
|
1125
|
-
* @returns A new object with only the specified keys
|
|
1126
|
-
*
|
|
1127
|
-
* @example
|
|
1128
|
-
* ```ts
|
|
1129
|
-
* const user = { name: 'John', age: 30, email: 'john@example.com' };
|
|
1130
|
-
* utils.pick(user, ['name', 'email']); // { name: 'John', email: 'john@example.com' }
|
|
1131
|
-
* ```
|
|
1132
|
-
*/
|
|
1133
|
-
pick(r, e) {
|
|
1134
|
-
const t = {};
|
|
1135
|
-
for (const n of e)
|
|
1136
|
-
n in r && (t[n] = r[n]);
|
|
1137
|
-
return t;
|
|
1138
|
-
},
|
|
1139
|
-
/**
|
|
1140
|
-
* Omits specified keys from an object.
|
|
1141
|
-
*
|
|
1142
|
-
* @template T - The object type
|
|
1143
|
-
* @template K - The key type
|
|
1144
|
-
* @param obj - The source object
|
|
1145
|
-
* @param keys - Keys to omit
|
|
1146
|
-
* @returns A new object without the specified keys
|
|
1147
|
-
*
|
|
1148
|
-
* @example
|
|
1149
|
-
* ```ts
|
|
1150
|
-
* const user = { name: 'John', age: 30, password: 'secret' };
|
|
1151
|
-
* utils.omit(user, ['password']); // { name: 'John', age: 30 }
|
|
1152
|
-
* ```
|
|
1153
|
-
*/
|
|
1154
|
-
omit(r, e) {
|
|
1155
|
-
const t = { ...r };
|
|
1156
|
-
for (const n of e)
|
|
1157
|
-
delete t[n];
|
|
1158
|
-
return t;
|
|
1159
|
-
},
|
|
1160
|
-
/**
|
|
1161
|
-
* Delays execution for a specified number of milliseconds.
|
|
1162
|
-
*
|
|
1163
|
-
* @param ms - Milliseconds to delay
|
|
1164
|
-
* @returns A promise that resolves after the delay
|
|
1165
|
-
*
|
|
1166
|
-
* @example
|
|
1167
|
-
* ```ts
|
|
1168
|
-
* await utils.sleep(1000); // Wait 1 second
|
|
1169
|
-
* console.log('Done!');
|
|
1170
|
-
* ```
|
|
1171
|
-
*/
|
|
1172
|
-
sleep(r) {
|
|
1173
|
-
return new Promise((e) => setTimeout(e, r));
|
|
1174
|
-
},
|
|
1175
|
-
/**
|
|
1176
|
-
* Generates a random integer between min and max (inclusive).
|
|
1177
|
-
*
|
|
1178
|
-
* @param min - Minimum value
|
|
1179
|
-
* @param max - Maximum value
|
|
1180
|
-
* @returns A random integer in the range [min, max]
|
|
1181
|
-
*
|
|
1182
|
-
* @example
|
|
1183
|
-
* ```ts
|
|
1184
|
-
* const roll = utils.randomInt(1, 6); // Random dice roll
|
|
1185
|
-
* ```
|
|
1186
|
-
*/
|
|
1187
|
-
randomInt(r, e) {
|
|
1188
|
-
return Math.floor(Math.random() * (e - r + 1)) + r;
|
|
1189
|
-
},
|
|
1190
|
-
/**
|
|
1191
|
-
* Clamps a number between a minimum and maximum value.
|
|
1192
|
-
*
|
|
1193
|
-
* @param value - The value to clamp
|
|
1194
|
-
* @param min - Minimum value
|
|
1195
|
-
* @param max - Maximum value
|
|
1196
|
-
* @returns The clamped value
|
|
1197
|
-
*
|
|
1198
|
-
* @example
|
|
1199
|
-
* ```ts
|
|
1200
|
-
* utils.clamp(150, 0, 100); // 100
|
|
1201
|
-
* utils.clamp(-10, 0, 100); // 0
|
|
1202
|
-
* utils.clamp(50, 0, 100); // 50
|
|
1203
|
-
* ```
|
|
1204
|
-
*/
|
|
1205
|
-
clamp(r, e, t) {
|
|
1206
|
-
return Math.min(Math.max(r, e), t);
|
|
1207
|
-
},
|
|
1208
|
-
/**
|
|
1209
|
-
* Capitalizes the first letter of a string.
|
|
1210
|
-
*
|
|
1211
|
-
* @param str - The string to capitalize
|
|
1212
|
-
* @returns The capitalized string
|
|
1213
|
-
*
|
|
1214
|
-
* @example
|
|
1215
|
-
* ```ts
|
|
1216
|
-
* utils.capitalize('hello'); // 'Hello'
|
|
1217
|
-
* ```
|
|
1218
|
-
*/
|
|
1219
|
-
capitalize(r) {
|
|
1220
|
-
return r && r.charAt(0).toUpperCase() + r.slice(1);
|
|
1221
|
-
},
|
|
1222
|
-
/**
|
|
1223
|
-
* Converts a string to kebab-case.
|
|
1224
|
-
*
|
|
1225
|
-
* @param str - The string to convert
|
|
1226
|
-
* @returns The kebab-cased string
|
|
1227
|
-
*
|
|
1228
|
-
* @example
|
|
1229
|
-
* ```ts
|
|
1230
|
-
* utils.toKebabCase('myVariableName'); // 'my-variable-name'
|
|
1231
|
-
* ```
|
|
1232
|
-
*/
|
|
1233
|
-
toKebabCase(r) {
|
|
1234
|
-
return r.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
1235
|
-
},
|
|
1236
|
-
/**
|
|
1237
|
-
* Converts a string to camelCase.
|
|
1238
|
-
*
|
|
1239
|
-
* @param str - The string to convert
|
|
1240
|
-
* @returns The camelCased string
|
|
1241
|
-
*
|
|
1242
|
-
* @example
|
|
1243
|
-
* ```ts
|
|
1244
|
-
* utils.toCamelCase('my-variable-name'); // 'myVariableName'
|
|
1245
|
-
* ```
|
|
1246
|
-
*/
|
|
1247
|
-
toCamelCase(r) {
|
|
1248
|
-
return r.replace(/[-_\s]+(.)?/g, (e, t) => t ? t.toUpperCase() : "").replace(/^[A-Z]/, (e) => e.toLowerCase());
|
|
1249
1031
|
}
|
|
1032
|
+
}
|
|
1033
|
+
function k(n) {
|
|
1034
|
+
return n == null ? !0 : typeof n == "string" ? n.trim().length === 0 : Array.isArray(n) ? n.length === 0 : typeof n == "object" ? Object.keys(n).length === 0 : !1;
|
|
1035
|
+
}
|
|
1036
|
+
function P(n, e) {
|
|
1037
|
+
return Math.floor(Math.random() * (e - n + 1)) + n;
|
|
1038
|
+
}
|
|
1039
|
+
function z(n, e, t) {
|
|
1040
|
+
return Math.min(Math.max(n, e), t);
|
|
1041
|
+
}
|
|
1042
|
+
function x(n, e, t, r = !0) {
|
|
1043
|
+
return r ? n >= e && n <= t : n > e && n < t;
|
|
1044
|
+
}
|
|
1045
|
+
function q(n, e = 0) {
|
|
1046
|
+
const t = typeof n == "number" ? n : Number(n);
|
|
1047
|
+
return Number.isNaN(t) ? e : t;
|
|
1048
|
+
}
|
|
1049
|
+
function d(n) {
|
|
1050
|
+
return Object.prototype.toString.call(n) === "[object Object]";
|
|
1051
|
+
}
|
|
1052
|
+
function D(n) {
|
|
1053
|
+
return n === "__proto__" || n === "constructor" || n === "prototype";
|
|
1054
|
+
}
|
|
1055
|
+
function R(n) {
|
|
1056
|
+
return typeof structuredClone == "function" ? structuredClone(n) : JSON.parse(JSON.stringify(n));
|
|
1057
|
+
}
|
|
1058
|
+
function A(...n) {
|
|
1059
|
+
const e = {};
|
|
1060
|
+
for (const t of n)
|
|
1061
|
+
for (const [r, s] of Object.entries(t))
|
|
1062
|
+
D(r) || (d(s) && d(e[r]) ? e[r] = A(
|
|
1063
|
+
e[r],
|
|
1064
|
+
s
|
|
1065
|
+
) : e[r] = s);
|
|
1066
|
+
return e;
|
|
1067
|
+
}
|
|
1068
|
+
function B(n, e) {
|
|
1069
|
+
const t = {};
|
|
1070
|
+
for (const r of e)
|
|
1071
|
+
r in n && (t[r] = n[r]);
|
|
1072
|
+
return t;
|
|
1073
|
+
}
|
|
1074
|
+
function W(n, e) {
|
|
1075
|
+
const t = { ...n };
|
|
1076
|
+
for (const r of e)
|
|
1077
|
+
delete t[r];
|
|
1078
|
+
return t;
|
|
1079
|
+
}
|
|
1080
|
+
function F(n, e) {
|
|
1081
|
+
return Object.prototype.hasOwnProperty.call(n, e);
|
|
1082
|
+
}
|
|
1083
|
+
function U(n) {
|
|
1084
|
+
return n && n.charAt(0).toUpperCase() + n.slice(1);
|
|
1085
|
+
}
|
|
1086
|
+
function _(n) {
|
|
1087
|
+
return n.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
1088
|
+
}
|
|
1089
|
+
function J(n) {
|
|
1090
|
+
return n.replace(/[-_\s]+(.)?/g, (e, t) => t ? t.toUpperCase() : "").replace(/^[A-Z]/, (e) => e.toLowerCase());
|
|
1091
|
+
}
|
|
1092
|
+
function I(n, e, t = "…") {
|
|
1093
|
+
if (e <= 0) return "";
|
|
1094
|
+
if (n.length <= e) return n;
|
|
1095
|
+
const r = Math.max(0, e - t.length);
|
|
1096
|
+
return `${n.slice(0, r)}${t}`;
|
|
1097
|
+
}
|
|
1098
|
+
function Z(n) {
|
|
1099
|
+
return n.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^\w\s-]/g, "").trim().replace(/[\s_-]+/g, "-").toLowerCase();
|
|
1100
|
+
}
|
|
1101
|
+
function K(n) {
|
|
1102
|
+
return n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1103
|
+
}
|
|
1104
|
+
function G(n) {
|
|
1105
|
+
return typeof Element < "u" && n instanceof Element;
|
|
1106
|
+
}
|
|
1107
|
+
function Q(n) {
|
|
1108
|
+
return !!(n && typeof n == "object" && "elements" in n);
|
|
1109
|
+
}
|
|
1110
|
+
function V(n) {
|
|
1111
|
+
return typeof n == "function";
|
|
1112
|
+
}
|
|
1113
|
+
function X(n) {
|
|
1114
|
+
return typeof n == "string";
|
|
1115
|
+
}
|
|
1116
|
+
function Y(n) {
|
|
1117
|
+
return typeof n == "number" && !Number.isNaN(n);
|
|
1118
|
+
}
|
|
1119
|
+
function ee(n) {
|
|
1120
|
+
return typeof n == "boolean";
|
|
1121
|
+
}
|
|
1122
|
+
function te(n) {
|
|
1123
|
+
return Array.isArray(n);
|
|
1124
|
+
}
|
|
1125
|
+
function ne(n) {
|
|
1126
|
+
return n instanceof Date;
|
|
1127
|
+
}
|
|
1128
|
+
function re(n) {
|
|
1129
|
+
return !!(n && (n instanceof Promise || typeof n == "object" && "then" in n && typeof n.then == "function"));
|
|
1130
|
+
}
|
|
1131
|
+
function se(n) {
|
|
1132
|
+
return typeof n == "object" && n !== null;
|
|
1133
|
+
}
|
|
1134
|
+
const ue = {
|
|
1135
|
+
clone: R,
|
|
1136
|
+
merge: A,
|
|
1137
|
+
pick: B,
|
|
1138
|
+
omit: W,
|
|
1139
|
+
hasOwn: F,
|
|
1140
|
+
debounce: N,
|
|
1141
|
+
throttle: $,
|
|
1142
|
+
once: M,
|
|
1143
|
+
noop: S,
|
|
1144
|
+
uid: j,
|
|
1145
|
+
isElement: G,
|
|
1146
|
+
isCollection: Q,
|
|
1147
|
+
isEmpty: k,
|
|
1148
|
+
isPlainObject: d,
|
|
1149
|
+
isFunction: V,
|
|
1150
|
+
isString: X,
|
|
1151
|
+
isNumber: Y,
|
|
1152
|
+
isBoolean: ee,
|
|
1153
|
+
isArray: te,
|
|
1154
|
+
isDate: ne,
|
|
1155
|
+
isPromise: re,
|
|
1156
|
+
isObject: se,
|
|
1157
|
+
parseJson: T,
|
|
1158
|
+
sleep: O,
|
|
1159
|
+
randomInt: P,
|
|
1160
|
+
clamp: z,
|
|
1161
|
+
inRange: x,
|
|
1162
|
+
toNumber: q,
|
|
1163
|
+
capitalize: U,
|
|
1164
|
+
toKebabCase: _,
|
|
1165
|
+
toCamelCase: J,
|
|
1166
|
+
truncate: I,
|
|
1167
|
+
slugify: Z,
|
|
1168
|
+
escapeRegExp: K,
|
|
1169
|
+
ensureArray: E,
|
|
1170
|
+
unique: C,
|
|
1171
|
+
chunk: L,
|
|
1172
|
+
compact: H,
|
|
1173
|
+
flatten: v
|
|
1250
1174
|
};
|
|
1251
1175
|
export {
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1176
|
+
oe as $,
|
|
1177
|
+
le as $$,
|
|
1178
|
+
c as BQueryCollection,
|
|
1179
|
+
h as BQueryElement,
|
|
1180
|
+
U as capitalize,
|
|
1181
|
+
L as chunk,
|
|
1182
|
+
z as clamp,
|
|
1183
|
+
R as clone,
|
|
1184
|
+
H as compact,
|
|
1185
|
+
N as debounce,
|
|
1186
|
+
E as ensureArray,
|
|
1187
|
+
K as escapeRegExp,
|
|
1188
|
+
v as flatten,
|
|
1189
|
+
F as hasOwn,
|
|
1190
|
+
x as inRange,
|
|
1191
|
+
te as isArray,
|
|
1192
|
+
ee as isBoolean,
|
|
1193
|
+
Q as isCollection,
|
|
1194
|
+
ne as isDate,
|
|
1195
|
+
G as isElement,
|
|
1196
|
+
k as isEmpty,
|
|
1197
|
+
V as isFunction,
|
|
1198
|
+
Y as isNumber,
|
|
1199
|
+
se as isObject,
|
|
1200
|
+
d as isPlainObject,
|
|
1201
|
+
re as isPromise,
|
|
1202
|
+
X as isString,
|
|
1203
|
+
A as merge,
|
|
1204
|
+
S as noop,
|
|
1205
|
+
W as omit,
|
|
1206
|
+
M as once,
|
|
1207
|
+
T as parseJson,
|
|
1208
|
+
B as pick,
|
|
1209
|
+
P as randomInt,
|
|
1210
|
+
O as sleep,
|
|
1211
|
+
Z as slugify,
|
|
1212
|
+
$ as throttle,
|
|
1213
|
+
J as toCamelCase,
|
|
1214
|
+
_ as toKebabCase,
|
|
1215
|
+
q as toNumber,
|
|
1216
|
+
I as truncate,
|
|
1217
|
+
j as uid,
|
|
1218
|
+
C as unique,
|
|
1219
|
+
ue as utils
|
|
1257
1220
|
};
|
|
1258
1221
|
//# sourceMappingURL=core.es.mjs.map
|