@bquery/bquery 1.3.0 → 1.5.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 +546 -501
- package/dist/component/component.d.ts.map +1 -1
- package/dist/component/index.d.ts +2 -0
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/library.d.ts +34 -0
- package/dist/component/library.d.ts.map +1 -0
- package/dist/component/types.d.ts +10 -6
- package/dist/component/types.d.ts.map +1 -1
- package/dist/component-CY5MVoYN.js +531 -0
- package/dist/component-CY5MVoYN.js.map +1 -0
- package/dist/component.es.mjs +6 -184
- package/dist/config-DRmZZno3.js +40 -0
- package/dist/config-DRmZZno3.js.map +1 -0
- package/dist/core/collection.d.ts +19 -3
- package/dist/core/collection.d.ts.map +1 -1
- package/dist/core/element.d.ts +23 -4
- 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/function.d.ts +21 -4
- package/dist/core/utils/function.d.ts.map +1 -1
- package/dist/core-CK2Mfpf4.js +648 -0
- package/dist/core-CK2Mfpf4.js.map +1 -0
- package/dist/core-DPdbItcq.js +112 -0
- package/dist/core-DPdbItcq.js.map +1 -0
- package/dist/core.es.mjs +45 -1218
- package/dist/full.d.ts +6 -6
- package/dist/full.d.ts.map +1 -1
- package/dist/full.es.mjs +98 -92
- package/dist/full.iife.js +173 -3
- package/dist/full.iife.js.map +1 -1
- package/dist/full.umd.js +173 -3
- package/dist/full.umd.js.map +1 -1
- package/dist/index.es.mjs +143 -139
- package/dist/motion/transition.d.ts +1 -1
- package/dist/motion/transition.d.ts.map +1 -1
- package/dist/motion/types.d.ts +11 -1
- package/dist/motion/types.d.ts.map +1 -1
- package/dist/motion-C5DRdPnO.js +415 -0
- package/dist/motion-C5DRdPnO.js.map +1 -0
- package/dist/motion.es.mjs +25 -361
- package/dist/object-qGpWr6-J.js +38 -0
- package/dist/object-qGpWr6-J.js.map +1 -0
- package/dist/platform/announcer.d.ts +59 -0
- package/dist/platform/announcer.d.ts.map +1 -0
- package/dist/platform/config.d.ts +92 -0
- package/dist/platform/config.d.ts.map +1 -0
- package/dist/platform/cookies.d.ts +45 -0
- package/dist/platform/cookies.d.ts.map +1 -0
- package/dist/platform/index.d.ts +8 -0
- package/dist/platform/index.d.ts.map +1 -1
- package/dist/platform/meta.d.ts +62 -0
- package/dist/platform/meta.d.ts.map +1 -0
- package/dist/platform/storage.d.ts.map +1 -1
- package/dist/platform-B7JhGBc7.js +361 -0
- package/dist/platform-B7JhGBc7.js.map +1 -0
- package/dist/platform.es.mjs +11 -243
- package/dist/reactive/async-data.d.ts +114 -0
- package/dist/reactive/async-data.d.ts.map +1 -0
- package/dist/reactive/core.d.ts +12 -0
- package/dist/reactive/core.d.ts.map +1 -1
- package/dist/reactive/effect.d.ts.map +1 -1
- package/dist/reactive/index.d.ts +2 -2
- package/dist/reactive/index.d.ts.map +1 -1
- package/dist/reactive/internals.d.ts +6 -0
- package/dist/reactive/internals.d.ts.map +1 -1
- package/dist/reactive/signal.d.ts +2 -0
- package/dist/reactive/signal.d.ts.map +1 -1
- package/dist/reactive-BDya-ia8.js +253 -0
- package/dist/reactive-BDya-ia8.js.map +1 -0
- package/dist/reactive.es.mjs +18 -34
- package/dist/router-CijiICxt.js +188 -0
- package/dist/router-CijiICxt.js.map +1 -0
- package/dist/router.es.mjs +11 -200
- package/dist/sanitize-jyJ2ryE2.js +302 -0
- package/dist/sanitize-jyJ2ryE2.js.map +1 -0
- package/dist/security/constants.d.ts.map +1 -1
- package/dist/security/sanitize-core.d.ts.map +1 -1
- package/dist/security.es.mjs +10 -56
- package/dist/store-CPK9E62U.js +262 -0
- package/dist/store-CPK9E62U.js.map +1 -0
- package/dist/store.es.mjs +12 -25
- package/dist/view/evaluate.d.ts.map +1 -1
- package/dist/view-Cdi0g-qo.js +396 -0
- package/dist/view-Cdi0g-qo.js.map +1 -0
- package/dist/view.es.mjs +10 -424
- package/package.json +136 -132
- package/src/component/component.ts +319 -289
- package/src/component/index.ts +42 -40
- package/src/component/library.ts +504 -0
- package/src/component/types.ts +91 -85
- package/src/core/collection.ts +44 -4
- package/src/core/element.ts +33 -5
- package/src/core/index.ts +1 -0
- package/src/core/utils/function.ts +56 -15
- package/src/full.ts +223 -187
- package/src/motion/transition.ts +97 -51
- package/src/motion/types.ts +208 -198
- package/src/platform/announcer.ts +208 -0
- package/src/platform/config.ts +163 -0
- package/src/platform/cookies.ts +165 -0
- package/src/platform/index.ts +39 -18
- package/src/platform/meta.ts +168 -0
- package/src/platform/storage.ts +8 -1
- package/src/reactive/async-data.ts +486 -0
- package/src/reactive/core.ts +21 -0
- package/src/reactive/effect.ts +18 -7
- package/src/reactive/index.ts +37 -23
- package/src/reactive/internals.ts +18 -1
- package/src/reactive/signal.ts +29 -20
- package/src/security/constants.ts +211 -209
- package/src/security/sanitize-core.ts +22 -1
- package/src/view/evaluate.ts +29 -13
- package/dist/batch-4LAvfLE7.js +0 -13
- package/dist/batch-4LAvfLE7.js.map +0 -1
- package/dist/component.es.mjs.map +0 -1
- package/dist/core-COenAZjD.js +0 -145
- package/dist/core-COenAZjD.js.map +0 -1
- package/dist/core.es.mjs.map +0 -1
- package/dist/full.es.mjs.map +0 -1
- package/dist/index.es.mjs.map +0 -1
- package/dist/motion.es.mjs.map +0 -1
- package/dist/persisted-Dz_ryNuC.js +0 -278
- package/dist/persisted-Dz_ryNuC.js.map +0 -1
- package/dist/platform.es.mjs.map +0 -1
- package/dist/reactive.es.mjs.map +0 -1
- package/dist/router.es.mjs.map +0 -1
- package/dist/sanitize-1FBEPAFH.js +0 -272
- package/dist/sanitize-1FBEPAFH.js.map +0 -1
- package/dist/security.es.mjs.map +0 -1
- package/dist/store.es.mjs.map +0 -1
- package/dist/type-guards-DRma3-Kc.js +0 -16
- package/dist/type-guards-DRma3-Kc.js.map +0 -1
- package/dist/untrack-BuEQKH7_.js +0 -6
- package/dist/untrack-BuEQKH7_.js.map +0 -1
- package/dist/view.es.mjs.map +0 -1
- package/dist/watch-CXyaBC_9.js +0 -58
- package/dist/watch-CXyaBC_9.js.map +0 -1
package/dist/core.es.mjs
CHANGED
|
@@ -1,1221 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
for (const t of n)
|
|
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
|
-
});
|
|
19
|
-
};
|
|
20
|
-
class h {
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new BQueryElement wrapper.
|
|
23
|
-
* @param element - The DOM element to wrap
|
|
24
|
-
*/
|
|
25
|
-
constructor(e) {
|
|
26
|
-
this.element = e, this.delegatedHandlers = /* @__PURE__ */ new Map();
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Exposes the raw DOM element when direct access is needed.
|
|
30
|
-
* Use sparingly; prefer the wrapper methods for consistency.
|
|
31
|
-
*/
|
|
32
|
-
get raw() {
|
|
33
|
-
return this.element;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Exposes the underlying DOM element.
|
|
37
|
-
* Provided for spec compatibility and read-only access.
|
|
38
|
-
*/
|
|
39
|
-
get node() {
|
|
40
|
-
return this.element;
|
|
41
|
-
}
|
|
42
|
-
/** Add one or more classes. */
|
|
43
|
-
addClass(...e) {
|
|
44
|
-
return this.element.classList.add(...e), this;
|
|
45
|
-
}
|
|
46
|
-
/** Remove one or more classes. */
|
|
47
|
-
removeClass(...e) {
|
|
48
|
-
return this.element.classList.remove(...e), this;
|
|
49
|
-
}
|
|
50
|
-
/** Toggle a class by name. */
|
|
51
|
-
toggleClass(e, t) {
|
|
52
|
-
return this.element.classList.toggle(e, t), this;
|
|
53
|
-
}
|
|
54
|
-
/** Get or set an attribute. */
|
|
55
|
-
attr(e, t) {
|
|
56
|
-
return t === void 0 ? this.element.getAttribute(e) ?? "" : (this.element.setAttribute(e, t), this);
|
|
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
|
-
}
|
|
67
|
-
/** Get or set a property. */
|
|
68
|
-
prop(e, t) {
|
|
69
|
-
return t === void 0 ? this.element[e] : (this.element[e] = t, this);
|
|
70
|
-
}
|
|
71
|
-
/** Read or write data attributes in camelCase. */
|
|
72
|
-
data(e, t) {
|
|
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);
|
|
75
|
-
}
|
|
76
|
-
/** Get or set text content. */
|
|
77
|
-
text(e) {
|
|
78
|
-
return e === void 0 ? this.element.textContent ?? "" : (this.element.textContent = e, this);
|
|
79
|
-
}
|
|
80
|
-
/** Set HTML content using a sanitized string. */
|
|
81
|
-
/**
|
|
82
|
-
* Sets sanitized HTML content on the element.
|
|
83
|
-
* Uses the security module to sanitize input and prevent XSS attacks.
|
|
84
|
-
*
|
|
85
|
-
* @param value - The HTML string to set (will be sanitized)
|
|
86
|
-
* @returns The instance for method chaining
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```ts
|
|
90
|
-
* $('#content').html('<strong>Hello</strong>');
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
html(e) {
|
|
94
|
-
return w(this.element, e), this;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Sets HTML content without sanitization.
|
|
98
|
-
* Use only when you trust the HTML source completely.
|
|
99
|
-
*
|
|
100
|
-
* @param value - The raw HTML string to set
|
|
101
|
-
* @returns The instance for method chaining
|
|
102
|
-
*
|
|
103
|
-
* @warning This method bypasses XSS protection. Use with caution.
|
|
104
|
-
*/
|
|
105
|
-
htmlUnsafe(e) {
|
|
106
|
-
return this.element.innerHTML = e, this;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Gets or sets CSS styles on the element.
|
|
110
|
-
*
|
|
111
|
-
* @param property - A CSS property name or an object of property-value pairs
|
|
112
|
-
* @param value - The value when setting a single property
|
|
113
|
-
* @returns The instance for method chaining
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* // Single property
|
|
118
|
-
* $('#box').css('color', 'red');
|
|
119
|
-
*
|
|
120
|
-
* // Multiple properties
|
|
121
|
-
* $('#box').css({ color: 'red', 'font-size': '16px' });
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
css(e, t) {
|
|
125
|
-
if (typeof e == "string")
|
|
126
|
-
return t !== void 0 && this.element.style.setProperty(e, t), this;
|
|
127
|
-
for (const [r, s] of Object.entries(e))
|
|
128
|
-
this.element.style.setProperty(r, s);
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Appends HTML or elements to the end of the element.
|
|
133
|
-
*
|
|
134
|
-
* @param content - HTML string or element(s) to append
|
|
135
|
-
* @returns The instance for method chaining
|
|
136
|
-
*/
|
|
137
|
-
append(e) {
|
|
138
|
-
return this.insertContent(e, "beforeend"), this;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Prepends HTML or elements to the beginning of the element.
|
|
142
|
-
*
|
|
143
|
-
* @param content - HTML string or element(s) to prepend
|
|
144
|
-
* @returns The instance for method chaining
|
|
145
|
-
*/
|
|
146
|
-
prepend(e) {
|
|
147
|
-
return this.insertContent(e, "afterbegin"), this;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Inserts content before this element.
|
|
151
|
-
*
|
|
152
|
-
* @param content - HTML string or element(s) to insert
|
|
153
|
-
* @returns The instance for method chaining
|
|
154
|
-
*/
|
|
155
|
-
before(e) {
|
|
156
|
-
return this.insertContent(e, "beforebegin"), this;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Inserts content after this element.
|
|
160
|
-
*
|
|
161
|
-
* @param content - HTML string or element(s) to insert
|
|
162
|
-
* @returns The instance for method chaining
|
|
163
|
-
*/
|
|
164
|
-
after(e) {
|
|
165
|
-
return this.insertContent(e, "afterend"), this;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Wraps the element with the specified wrapper element or tag.
|
|
169
|
-
*
|
|
170
|
-
* @param wrapper - Tag name string or Element to wrap with
|
|
171
|
-
* @returns The instance for method chaining
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```ts
|
|
175
|
-
* $('#content').wrap('div'); // Wraps with <div>
|
|
176
|
-
* $('#content').wrap(document.createElement('section'));
|
|
177
|
-
* ```
|
|
178
|
-
*/
|
|
179
|
-
wrap(e) {
|
|
180
|
-
const t = typeof e == "string" ? document.createElement(e) : e;
|
|
181
|
-
return this.element.parentNode?.insertBefore(t, this.element), t.appendChild(this.element), this;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Removes the parent element, keeping this element in its place.
|
|
185
|
-
* Essentially the opposite of wrap().
|
|
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
|
-
*
|
|
191
|
-
* @returns The instance for method chaining
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* ```ts
|
|
195
|
-
* // Before: <div><span id="text">Hello</span></div>
|
|
196
|
-
* $('#text').unwrap();
|
|
197
|
-
* // After: <span id="text">Hello</span>
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
200
|
-
unwrap() {
|
|
201
|
-
const e = this.element.parentElement;
|
|
202
|
-
return e && e.parentNode && (e.parentNode.insertBefore(this.element, e), e.remove()), this;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Replaces this element with new content.
|
|
206
|
-
*
|
|
207
|
-
* @param content - HTML string (sanitized) or Element to replace with
|
|
208
|
-
* @returns A new BQueryElement wrapping the replacement element
|
|
209
|
-
*
|
|
210
|
-
* @example
|
|
211
|
-
* ```ts
|
|
212
|
-
* const newEl = $('#old').replaceWith('<div id="new">Replaced</div>');
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
replaceWith(e) {
|
|
216
|
-
const t = typeof e == "string" ? y(e) : e;
|
|
217
|
-
return this.element.replaceWith(t), new h(t);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Scrolls the element into view with configurable behavior.
|
|
221
|
-
*
|
|
222
|
-
* @param options - ScrollIntoView options or boolean for legacy behavior
|
|
223
|
-
* @returns The instance for method chaining
|
|
224
|
-
*
|
|
225
|
-
* @example
|
|
226
|
-
* ```ts
|
|
227
|
-
* $('#section').scrollTo(); // Smooth scroll
|
|
228
|
-
* $('#section').scrollTo({ behavior: 'instant', block: 'start' });
|
|
229
|
-
* ```
|
|
230
|
-
*/
|
|
231
|
-
scrollTo(e = { behavior: "smooth" }) {
|
|
232
|
-
return this.element.scrollIntoView(e), this;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Removes the element from the DOM.
|
|
236
|
-
*
|
|
237
|
-
* @returns The instance for method chaining (though element is now detached)
|
|
238
|
-
*/
|
|
239
|
-
remove() {
|
|
240
|
-
return this.element.remove(), this;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Clears all child nodes from the element.
|
|
244
|
-
*
|
|
245
|
-
* @returns The instance for method chaining
|
|
246
|
-
*/
|
|
247
|
-
empty() {
|
|
248
|
-
return this.element.innerHTML = "", this;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Clones the element, optionally with all descendants.
|
|
252
|
-
*
|
|
253
|
-
* @param deep - If true, clone all descendants (default: true)
|
|
254
|
-
* @returns A new BQueryElement wrapping the cloned element
|
|
255
|
-
*/
|
|
256
|
-
clone(e = !0) {
|
|
257
|
-
return new h(this.element.cloneNode(e));
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Finds all descendant elements matching the selector.
|
|
261
|
-
*
|
|
262
|
-
* @param selector - CSS selector to match
|
|
263
|
-
* @returns Array of matching elements
|
|
264
|
-
*/
|
|
265
|
-
find(e) {
|
|
266
|
-
return Array.from(this.element.querySelectorAll(e));
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Finds the first descendant element matching the selector.
|
|
270
|
-
*
|
|
271
|
-
* @param selector - CSS selector to match
|
|
272
|
-
* @returns The first matching element or null
|
|
273
|
-
*/
|
|
274
|
-
findOne(e) {
|
|
275
|
-
return this.element.querySelector(e);
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Finds the closest ancestor matching the selector.
|
|
279
|
-
*
|
|
280
|
-
* @param selector - CSS selector to match
|
|
281
|
-
* @returns The matching ancestor or null
|
|
282
|
-
*/
|
|
283
|
-
closest(e) {
|
|
284
|
-
return this.element.closest(e);
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Gets the parent element.
|
|
288
|
-
*
|
|
289
|
-
* @returns The parent element or null
|
|
290
|
-
*/
|
|
291
|
-
parent() {
|
|
292
|
-
return this.element.parentElement;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Gets all child elements.
|
|
296
|
-
*
|
|
297
|
-
* @returns Array of child elements
|
|
298
|
-
*/
|
|
299
|
-
children() {
|
|
300
|
-
return Array.from(this.element.children);
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Gets all sibling elements.
|
|
304
|
-
*
|
|
305
|
-
* @returns Array of sibling elements (excluding this element)
|
|
306
|
-
*/
|
|
307
|
-
siblings() {
|
|
308
|
-
const e = this.element.parentElement;
|
|
309
|
-
return e ? Array.from(e.children).filter((t) => t !== this.element) : [];
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Gets the next sibling element.
|
|
313
|
-
*
|
|
314
|
-
* @returns The next sibling element or null
|
|
315
|
-
*/
|
|
316
|
-
next() {
|
|
317
|
-
return this.element.nextElementSibling;
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Gets the previous sibling element.
|
|
321
|
-
*
|
|
322
|
-
* @returns The previous sibling element or null
|
|
323
|
-
*/
|
|
324
|
-
prev() {
|
|
325
|
-
return this.element.previousElementSibling;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Adds an event listener.
|
|
329
|
-
*
|
|
330
|
-
* @param event - Event type to listen for
|
|
331
|
-
* @param handler - Event handler function
|
|
332
|
-
* @returns The instance for method chaining
|
|
333
|
-
*/
|
|
334
|
-
on(e, t) {
|
|
335
|
-
return this.element.addEventListener(e, t), this;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Adds a one-time event listener that removes itself after firing.
|
|
339
|
-
*
|
|
340
|
-
* @param event - Event type to listen for
|
|
341
|
-
* @param handler - Event handler function
|
|
342
|
-
* @returns The instance for method chaining
|
|
343
|
-
*/
|
|
344
|
-
once(e, t) {
|
|
345
|
-
return this.element.addEventListener(e, t, { once: !0 }), this;
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Removes an event listener.
|
|
349
|
-
*
|
|
350
|
-
* @param event - Event type
|
|
351
|
-
* @param handler - The handler to remove
|
|
352
|
-
* @returns The instance for method chaining
|
|
353
|
-
*/
|
|
354
|
-
off(e, t) {
|
|
355
|
-
return this.element.removeEventListener(e, t), this;
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Triggers a custom event on the element.
|
|
359
|
-
*
|
|
360
|
-
* @param event - Event type to trigger
|
|
361
|
-
* @param detail - Optional detail data to include with the event
|
|
362
|
-
* @returns The instance for method chaining
|
|
363
|
-
*/
|
|
364
|
-
trigger(e, t) {
|
|
365
|
-
return this.element.dispatchEvent(new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 })), this;
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Adds a delegated event listener that only triggers for matching descendants.
|
|
369
|
-
* More efficient than adding listeners to many elements individually.
|
|
370
|
-
*
|
|
371
|
-
* Use `undelegate()` to remove the listener later.
|
|
372
|
-
*
|
|
373
|
-
* @param event - Event type to listen for
|
|
374
|
-
* @param selector - CSS selector to match against event targets
|
|
375
|
-
* @param handler - Event handler function, receives the matched element as context
|
|
376
|
-
* @returns The instance for method chaining
|
|
377
|
-
*
|
|
378
|
-
* @example
|
|
379
|
-
* ```ts
|
|
380
|
-
* // Instead of adding listeners to each button:
|
|
381
|
-
* const handler = (e, target) => console.log('Clicked:', target.textContent);
|
|
382
|
-
* $('#list').delegate('click', '.item', handler);
|
|
383
|
-
*
|
|
384
|
-
* // Later, remove the delegated listener:
|
|
385
|
-
* $('#list').undelegate('click', '.item', handler);
|
|
386
|
-
* ```
|
|
387
|
-
*/
|
|
388
|
-
delegate(e, t, r) {
|
|
389
|
-
const s = `${e}:${t}`, i = (l) => {
|
|
390
|
-
const u = l.target.closest(t);
|
|
391
|
-
u && this.element.contains(u) && r(l, u);
|
|
392
|
-
};
|
|
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;
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Removes a delegated event listener previously added with `delegate()`.
|
|
397
|
-
*
|
|
398
|
-
* @param event - Event type that was registered
|
|
399
|
-
* @param selector - CSS selector that was used
|
|
400
|
-
* @param handler - The original handler function passed to delegate()
|
|
401
|
-
* @returns The instance for method chaining
|
|
402
|
-
*
|
|
403
|
-
* @example
|
|
404
|
-
* ```ts
|
|
405
|
-
* const handler = (e, target) => console.log('Clicked:', target.textContent);
|
|
406
|
-
* $('#list').delegate('click', '.item', handler);
|
|
407
|
-
*
|
|
408
|
-
* // Remove the delegated listener:
|
|
409
|
-
* $('#list').undelegate('click', '.item', handler);
|
|
410
|
-
* ```
|
|
411
|
-
*/
|
|
412
|
-
undelegate(e, t, r) {
|
|
413
|
-
const s = `${e}:${t}`, i = this.delegatedHandlers.get(s);
|
|
414
|
-
if (i) {
|
|
415
|
-
const l = i.get(r);
|
|
416
|
-
l && (this.element.removeEventListener(e, l), i.delete(r), i.size === 0 && this.delegatedHandlers.delete(s));
|
|
417
|
-
}
|
|
418
|
-
return this;
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Checks if the element matches a CSS selector.
|
|
422
|
-
*
|
|
423
|
-
* @param selector - CSS selector to match against
|
|
424
|
-
* @returns True if the element matches the selector
|
|
425
|
-
*/
|
|
426
|
-
matches(e) {
|
|
427
|
-
return this.element.matches(e);
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Checks if the element has a specific class.
|
|
431
|
-
*
|
|
432
|
-
* @param className - Class name to check
|
|
433
|
-
* @returns True if the element has the class
|
|
434
|
-
*/
|
|
435
|
-
hasClass(e) {
|
|
436
|
-
return this.element.classList.contains(e);
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Shows the element by removing the hidden attribute and setting display.
|
|
440
|
-
*
|
|
441
|
-
* @param display - Optional display value (default: '')
|
|
442
|
-
* @returns The instance for method chaining
|
|
443
|
-
*/
|
|
444
|
-
show(e = "") {
|
|
445
|
-
return this.element.removeAttribute("hidden"), this.element.style.display = e, this;
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Hides the element by setting display to 'none'.
|
|
449
|
-
*
|
|
450
|
-
* @returns The instance for method chaining
|
|
451
|
-
*/
|
|
452
|
-
hide() {
|
|
453
|
-
return this.element.style.display = "none", this;
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Toggles the visibility of the element.
|
|
457
|
-
*
|
|
458
|
-
* @param force - Optional force show (true) or hide (false)
|
|
459
|
-
* @returns The instance for method chaining
|
|
460
|
-
*/
|
|
461
|
-
toggle(e) {
|
|
462
|
-
const t = this.element.style.display === "none";
|
|
463
|
-
return e ?? t ? this.show() : this.hide();
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Focuses the element.
|
|
467
|
-
*
|
|
468
|
-
* @returns The instance for method chaining
|
|
469
|
-
*/
|
|
470
|
-
focus() {
|
|
471
|
-
return this.element.focus(), this;
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* Blurs (unfocuses) the element.
|
|
475
|
-
*
|
|
476
|
-
* @returns The instance for method chaining
|
|
477
|
-
*/
|
|
478
|
-
blur() {
|
|
479
|
-
return this.element.blur(), this;
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Gets or sets the value of form elements.
|
|
483
|
-
*
|
|
484
|
-
* @param newValue - Optional value to set
|
|
485
|
-
* @returns The current value when getting, or the instance when setting
|
|
486
|
-
*/
|
|
487
|
-
val(e) {
|
|
488
|
-
const t = this.element;
|
|
489
|
-
return e === void 0 ? t.value ?? "" : (t.value = e, this);
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Serializes form data to a plain object.
|
|
493
|
-
* Only works on form elements; returns empty object for non-forms.
|
|
494
|
-
*
|
|
495
|
-
* @returns Object with form field names as keys and values
|
|
496
|
-
*
|
|
497
|
-
* @example
|
|
498
|
-
* ```ts
|
|
499
|
-
* // For a form with <input name="email" value="test@example.com">
|
|
500
|
-
* const data = $('#myForm').serialize();
|
|
501
|
-
* // { email: 'test@example.com' }
|
|
502
|
-
* ```
|
|
503
|
-
*/
|
|
504
|
-
serialize() {
|
|
505
|
-
const e = this.element;
|
|
506
|
-
if (e.tagName.toLowerCase() !== "form")
|
|
507
|
-
return {};
|
|
508
|
-
const t = {}, r = new FormData(e);
|
|
509
|
-
for (const [s, i] of r.entries())
|
|
510
|
-
if (typeof i == "string")
|
|
511
|
-
if (s in t) {
|
|
512
|
-
const l = t[s];
|
|
513
|
-
Array.isArray(l) ? l.push(i) : t[s] = [l, i];
|
|
514
|
-
} else
|
|
515
|
-
t[s] = i;
|
|
516
|
-
return t;
|
|
517
|
-
}
|
|
518
|
-
/**
|
|
519
|
-
* Serializes form data to a URL-encoded query string.
|
|
520
|
-
*
|
|
521
|
-
* @returns URL-encoded string suitable for form submission
|
|
522
|
-
*
|
|
523
|
-
* @example
|
|
524
|
-
* ```ts
|
|
525
|
-
* const queryString = $('#myForm').serializeString();
|
|
526
|
-
* // 'email=test%40example.com&name=John'
|
|
527
|
-
* ```
|
|
528
|
-
*/
|
|
529
|
-
serializeString() {
|
|
530
|
-
const e = this.element;
|
|
531
|
-
if (e.tagName.toLowerCase() !== "form")
|
|
532
|
-
return "";
|
|
533
|
-
const t = new FormData(e), r = new URLSearchParams();
|
|
534
|
-
for (const [s, i] of t.entries())
|
|
535
|
-
typeof i == "string" && r.append(s, i);
|
|
536
|
-
return r.toString();
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* Gets the bounding client rectangle of the element.
|
|
540
|
-
*
|
|
541
|
-
* @returns The element's bounding rectangle
|
|
542
|
-
*/
|
|
543
|
-
rect() {
|
|
544
|
-
return this.element.getBoundingClientRect();
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Gets the offset dimensions (width, height, top, left).
|
|
548
|
-
*
|
|
549
|
-
* @returns Object with offset dimensions
|
|
550
|
-
*/
|
|
551
|
-
offset() {
|
|
552
|
-
const e = this.element;
|
|
553
|
-
return {
|
|
554
|
-
width: e.offsetWidth,
|
|
555
|
-
height: e.offsetHeight,
|
|
556
|
-
top: e.offsetTop,
|
|
557
|
-
left: e.offsetLeft
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
/**
|
|
561
|
-
* Internal method to insert content at a specified position.
|
|
562
|
-
* @internal
|
|
563
|
-
*/
|
|
564
|
-
insertContent(e, t) {
|
|
565
|
-
b(this.element, e, t);
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
class c {
|
|
569
|
-
/**
|
|
570
|
-
* Creates a new collection wrapper.
|
|
571
|
-
* @param elements - Array of DOM elements to wrap
|
|
572
|
-
*/
|
|
573
|
-
constructor(e) {
|
|
574
|
-
this.elements = e, this.delegatedHandlers = /* @__PURE__ */ new WeakMap();
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Gets the number of elements in the collection.
|
|
578
|
-
*/
|
|
579
|
-
get length() {
|
|
580
|
-
return this.elements.length;
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Gets the first element in the collection, if any.
|
|
584
|
-
* @internal
|
|
585
|
-
*/
|
|
586
|
-
first() {
|
|
587
|
-
return this.elements[0];
|
|
588
|
-
}
|
|
589
|
-
/**
|
|
590
|
-
* Gets a single element as a BQueryElement wrapper.
|
|
591
|
-
*
|
|
592
|
-
* @param index - Zero-based index of the element
|
|
593
|
-
* @returns BQueryElement wrapper or undefined if out of range
|
|
594
|
-
*/
|
|
595
|
-
eq(e) {
|
|
596
|
-
const t = this.elements[e];
|
|
597
|
-
return t ? new h(t) : void 0;
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* Gets the first element as a BQueryElement wrapper.
|
|
601
|
-
*
|
|
602
|
-
* @returns BQueryElement wrapper or undefined if empty
|
|
603
|
-
*/
|
|
604
|
-
firstEl() {
|
|
605
|
-
return this.eq(0);
|
|
606
|
-
}
|
|
607
|
-
/**
|
|
608
|
-
* Gets the last element as a BQueryElement wrapper.
|
|
609
|
-
*
|
|
610
|
-
* @returns BQueryElement wrapper or undefined if empty
|
|
611
|
-
*/
|
|
612
|
-
lastEl() {
|
|
613
|
-
return this.eq(this.elements.length - 1);
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* Iterates over each element in the collection.
|
|
617
|
-
*
|
|
618
|
-
* @param callback - Function to call for each wrapped element
|
|
619
|
-
* @returns The instance for method chaining
|
|
620
|
-
*/
|
|
621
|
-
each(e) {
|
|
622
|
-
return this.elements.forEach((t, r) => {
|
|
623
|
-
e(new h(t), r);
|
|
624
|
-
}), this;
|
|
625
|
-
}
|
|
626
|
-
/**
|
|
627
|
-
* Maps each element to a new value.
|
|
628
|
-
*
|
|
629
|
-
* @param callback - Function to transform each element
|
|
630
|
-
* @returns Array of transformed values
|
|
631
|
-
*/
|
|
632
|
-
map(e) {
|
|
633
|
-
return this.elements.map(e);
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* Filters elements based on a predicate.
|
|
637
|
-
*
|
|
638
|
-
* @param predicate - Function to test each element
|
|
639
|
-
* @returns New BQueryCollection with matching elements
|
|
640
|
-
*/
|
|
641
|
-
filter(e) {
|
|
642
|
-
return new c(this.elements.filter(e));
|
|
643
|
-
}
|
|
644
|
-
/**
|
|
645
|
-
* Reduces the collection to a single value.
|
|
646
|
-
*
|
|
647
|
-
* @param callback - Reducer function
|
|
648
|
-
* @param initialValue - Initial accumulator value
|
|
649
|
-
* @returns Accumulated result
|
|
650
|
-
*/
|
|
651
|
-
reduce(e, t) {
|
|
652
|
-
return this.elements.reduce(e, t);
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* Converts the collection to an array of BQueryElement wrappers.
|
|
656
|
-
*
|
|
657
|
-
* @returns Array of BQueryElement instances
|
|
658
|
-
*/
|
|
659
|
-
toArray() {
|
|
660
|
-
return this.elements.map((e) => new h(e));
|
|
661
|
-
}
|
|
662
|
-
/** Add one or more classes to all elements. */
|
|
663
|
-
addClass(...e) {
|
|
664
|
-
return o(this.elements, (t) => t.classList.add(...e)), this;
|
|
665
|
-
}
|
|
666
|
-
/** Remove one or more classes from all elements. */
|
|
667
|
-
removeClass(...e) {
|
|
668
|
-
return o(this.elements, (t) => t.classList.remove(...e)), this;
|
|
669
|
-
}
|
|
670
|
-
/** Toggle a class on all elements. */
|
|
671
|
-
toggleClass(e, t) {
|
|
672
|
-
return o(this.elements, (r) => r.classList.toggle(e, t)), this;
|
|
673
|
-
}
|
|
674
|
-
/**
|
|
675
|
-
* Sets an attribute on all elements or gets from first.
|
|
676
|
-
*
|
|
677
|
-
* @param name - Attribute name
|
|
678
|
-
* @param value - Value to set (optional)
|
|
679
|
-
* @returns Attribute value when getting, instance when setting
|
|
680
|
-
*/
|
|
681
|
-
attr(e, t) {
|
|
682
|
-
return t === void 0 ? this.first()?.getAttribute(e) ?? "" : (o(this.elements, (r) => r.setAttribute(e, t)), this);
|
|
683
|
-
}
|
|
684
|
-
/**
|
|
685
|
-
* Removes an attribute from all elements.
|
|
686
|
-
*
|
|
687
|
-
* @param name - Attribute name to remove
|
|
688
|
-
* @returns The instance for method chaining
|
|
689
|
-
*/
|
|
690
|
-
removeAttr(e) {
|
|
691
|
-
return o(this.elements, (t) => t.removeAttribute(e)), this;
|
|
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
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* Sets text content on all elements or gets from first.
|
|
702
|
-
*
|
|
703
|
-
* @param value - Text to set (optional)
|
|
704
|
-
* @returns Text content when getting, instance when setting
|
|
705
|
-
*/
|
|
706
|
-
text(e) {
|
|
707
|
-
return e === void 0 ? this.first()?.textContent ?? "" : (o(this.elements, (t) => {
|
|
708
|
-
t.textContent = e;
|
|
709
|
-
}), this);
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* Sets sanitized HTML on all elements or gets from first.
|
|
713
|
-
*
|
|
714
|
-
* @param value - HTML to set (optional, will be sanitized)
|
|
715
|
-
* @returns HTML content when getting, instance when setting
|
|
716
|
-
*/
|
|
717
|
-
html(e) {
|
|
718
|
-
if (e === void 0)
|
|
719
|
-
return this.first()?.innerHTML ?? "";
|
|
720
|
-
const t = p(e);
|
|
721
|
-
return o(this.elements, (r) => {
|
|
722
|
-
r.innerHTML = t;
|
|
723
|
-
}), this;
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* Sets HTML on all elements without sanitization.
|
|
727
|
-
*
|
|
728
|
-
* @param value - Raw HTML to set
|
|
729
|
-
* @returns The instance for method chaining
|
|
730
|
-
* @warning Bypasses XSS protection
|
|
731
|
-
*/
|
|
732
|
-
htmlUnsafe(e) {
|
|
733
|
-
return o(this.elements, (t) => {
|
|
734
|
-
t.innerHTML = e;
|
|
735
|
-
}), this;
|
|
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
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* Applies CSS styles to all elements.
|
|
755
|
-
*
|
|
756
|
-
* @param property - Property name or object of properties
|
|
757
|
-
* @param value - Value when setting single property
|
|
758
|
-
* @returns The instance for method chaining
|
|
759
|
-
*/
|
|
760
|
-
css(e, t) {
|
|
761
|
-
return typeof e == "string" ? (t !== void 0 && o(this.elements, (r) => {
|
|
762
|
-
r.style.setProperty(e, t);
|
|
763
|
-
}), this) : (o(this.elements, (r) => {
|
|
764
|
-
for (const [s, i] of Object.entries(e))
|
|
765
|
-
r.style.setProperty(s, i);
|
|
766
|
-
}), this);
|
|
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
|
-
}
|
|
814
|
-
/**
|
|
815
|
-
* Shows all elements.
|
|
816
|
-
*
|
|
817
|
-
* @param display - Optional display value (default: '')
|
|
818
|
-
* @returns The instance for method chaining
|
|
819
|
-
*/
|
|
820
|
-
show(e = "") {
|
|
821
|
-
return o(this.elements, (t) => {
|
|
822
|
-
t.removeAttribute("hidden"), t.style.display = e;
|
|
823
|
-
}), this;
|
|
824
|
-
}
|
|
825
|
-
/**
|
|
826
|
-
* Hides all elements.
|
|
827
|
-
*
|
|
828
|
-
* @returns The instance for method chaining
|
|
829
|
-
*/
|
|
830
|
-
hide() {
|
|
831
|
-
return o(this.elements, (e) => {
|
|
832
|
-
e.style.display = "none";
|
|
833
|
-
}), this;
|
|
834
|
-
}
|
|
835
|
-
/**
|
|
836
|
-
* Adds an event listener to all elements.
|
|
837
|
-
*
|
|
838
|
-
* @param event - Event type
|
|
839
|
-
* @param handler - Event handler
|
|
840
|
-
* @returns The instance for method chaining
|
|
841
|
-
*/
|
|
842
|
-
on(e, t) {
|
|
843
|
-
return o(this.elements, (r) => r.addEventListener(e, t)), this;
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Adds a one-time event listener to all elements.
|
|
847
|
-
*
|
|
848
|
-
* @param event - Event type
|
|
849
|
-
* @param handler - Event handler
|
|
850
|
-
* @returns The instance for method chaining
|
|
851
|
-
*/
|
|
852
|
-
once(e, t) {
|
|
853
|
-
return o(this.elements, (r) => r.addEventListener(e, t, { once: !0 })), this;
|
|
854
|
-
}
|
|
855
|
-
/**
|
|
856
|
-
* Removes an event listener from all elements.
|
|
857
|
-
*
|
|
858
|
-
* @param event - Event type
|
|
859
|
-
* @param handler - The handler to remove
|
|
860
|
-
* @returns The instance for method chaining
|
|
861
|
-
*/
|
|
862
|
-
off(e, t) {
|
|
863
|
-
return o(this.elements, (r) => r.removeEventListener(e, t)), this;
|
|
864
|
-
}
|
|
865
|
-
/**
|
|
866
|
-
* Triggers a custom event on all elements.
|
|
867
|
-
*
|
|
868
|
-
* @param event - Event type
|
|
869
|
-
* @param detail - Optional event detail
|
|
870
|
-
* @returns The instance for method chaining
|
|
871
|
-
*/
|
|
872
|
-
trigger(e, t) {
|
|
873
|
-
return o(this.elements, (r) => {
|
|
874
|
-
r.dispatchEvent(new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 }));
|
|
875
|
-
}), this;
|
|
876
|
-
}
|
|
877
|
-
/**
|
|
878
|
-
* Adds a delegated event listener to all elements.
|
|
879
|
-
* Events are delegated to matching descendants.
|
|
880
|
-
*
|
|
881
|
-
* Use `undelegate()` to remove the listener later.
|
|
882
|
-
*
|
|
883
|
-
* @param event - Event type to listen for
|
|
884
|
-
* @param selector - CSS selector to match against event targets
|
|
885
|
-
* @param handler - Event handler function
|
|
886
|
-
* @returns The instance for method chaining
|
|
887
|
-
*
|
|
888
|
-
* @example
|
|
889
|
-
* ```ts
|
|
890
|
-
* const handler = (e, target) => console.log('Clicked:', target.textContent);
|
|
891
|
-
* $$('.container').delegate('click', '.item', handler);
|
|
892
|
-
*
|
|
893
|
-
* // Later, remove the delegated listener:
|
|
894
|
-
* $$('.container').undelegate('click', '.item', handler);
|
|
895
|
-
* ```
|
|
896
|
-
*/
|
|
897
|
-
delegate(e, t, r) {
|
|
898
|
-
const s = `${e}:${t}`;
|
|
899
|
-
return o(this.elements, (i) => {
|
|
900
|
-
const l = (a) => {
|
|
901
|
-
const m = a.target.closest(t);
|
|
902
|
-
m && i.contains(m) && r(a, m);
|
|
903
|
-
};
|
|
904
|
-
this.delegatedHandlers.has(i) || this.delegatedHandlers.set(i, /* @__PURE__ */ new Map());
|
|
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);
|
|
907
|
-
}), this;
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* Removes a delegated event listener previously added with `delegate()`.
|
|
911
|
-
*
|
|
912
|
-
* @param event - Event type that was registered
|
|
913
|
-
* @param selector - CSS selector that was used
|
|
914
|
-
* @param handler - The original handler function passed to delegate()
|
|
915
|
-
* @returns The instance for method chaining
|
|
916
|
-
*
|
|
917
|
-
* @example
|
|
918
|
-
* ```ts
|
|
919
|
-
* const handler = (e, target) => console.log('Clicked:', target.textContent);
|
|
920
|
-
* $$('.container').delegate('click', '.item', handler);
|
|
921
|
-
*
|
|
922
|
-
* // Remove the delegated listener:
|
|
923
|
-
* $$('.container').undelegate('click', '.item', handler);
|
|
924
|
-
* ```
|
|
925
|
-
*/
|
|
926
|
-
undelegate(e, t, r) {
|
|
927
|
-
const s = `${e}:${t}`;
|
|
928
|
-
return o(this.elements, (i) => {
|
|
929
|
-
const l = this.delegatedHandlers.get(i);
|
|
930
|
-
if (!l) return;
|
|
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));
|
|
935
|
-
}), this;
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
* Removes all elements from the DOM.
|
|
939
|
-
*
|
|
940
|
-
* @returns The instance for method chaining
|
|
941
|
-
*/
|
|
942
|
-
remove() {
|
|
943
|
-
return o(this.elements, (e) => e.remove()), this;
|
|
944
|
-
}
|
|
945
|
-
/**
|
|
946
|
-
* Clears all child nodes from all elements.
|
|
947
|
-
*
|
|
948
|
-
* @returns The instance for method chaining
|
|
949
|
-
*/
|
|
950
|
-
empty() {
|
|
951
|
-
return o(this.elements, (e) => {
|
|
952
|
-
e.innerHTML = "";
|
|
953
|
-
}), this;
|
|
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
|
-
}
|
|
970
|
-
}
|
|
971
|
-
const oe = (n) => {
|
|
972
|
-
if (typeof n != "string")
|
|
973
|
-
return new h(n);
|
|
974
|
-
const e = document.querySelector(n);
|
|
975
|
-
if (!e)
|
|
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 {
|
|
1030
|
-
return e;
|
|
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
|
|
1174
|
-
};
|
|
1
|
+
import { A as a, C as e, D as i, E as t, F as o, I as n, L as r, M as l, N as c, O as m, P as u, R as p, S as b, T as y, _ as g, a as C, b as f, c as E, d, f as h, g as O, h as j, i as k, j as x, k as A, l as B, m as N, n as P, o as R, p as $, r as w, s as D, t as F, u as I, v as Q, w as S, x as q, y as v } from "./core-CK2Mfpf4.js";
|
|
2
|
+
import { a as J, i as K, n as L, o as M, r as T, t as _ } from "./object-qGpWr6-J.js";
|
|
1175
3
|
export {
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
4
|
+
o as $,
|
|
5
|
+
n as $$,
|
|
6
|
+
r as BQueryCollection,
|
|
7
|
+
p as BQueryElement,
|
|
8
|
+
h as capitalize,
|
|
9
|
+
a as chunk,
|
|
10
|
+
Q as clamp,
|
|
11
|
+
_ as clone,
|
|
12
|
+
x as compact,
|
|
13
|
+
t as debounce,
|
|
14
|
+
l as ensureArray,
|
|
15
|
+
$ as escapeRegExp,
|
|
16
|
+
c as flatten,
|
|
17
|
+
L as hasOwn,
|
|
18
|
+
v as inRange,
|
|
19
|
+
P as isArray,
|
|
20
|
+
w as isBoolean,
|
|
21
|
+
k as isCollection,
|
|
22
|
+
C as isDate,
|
|
23
|
+
R as isElement,
|
|
24
|
+
b as isEmpty,
|
|
25
|
+
D as isFunction,
|
|
26
|
+
E as isNumber,
|
|
27
|
+
B as isObject,
|
|
28
|
+
T as isPlainObject,
|
|
29
|
+
I as isPromise,
|
|
30
|
+
d as isString,
|
|
31
|
+
K as merge,
|
|
32
|
+
i as noop,
|
|
33
|
+
J as omit,
|
|
34
|
+
m as once,
|
|
35
|
+
e as parseJson,
|
|
36
|
+
M as pick,
|
|
37
|
+
f as randomInt,
|
|
38
|
+
S as sleep,
|
|
39
|
+
N as slugify,
|
|
40
|
+
A as throttle,
|
|
41
|
+
j as toCamelCase,
|
|
42
|
+
O as toKebabCase,
|
|
1215
43
|
q as toNumber,
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
44
|
+
g as truncate,
|
|
45
|
+
y as uid,
|
|
46
|
+
u as unique,
|
|
47
|
+
F as utils
|
|
1220
48
|
};
|
|
1221
|
-
//# sourceMappingURL=core.es.mjs.map
|