@bquery/bquery 1.0.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/LICENSE.md +21 -0
- package/README.md +266 -0
- package/dist/component/index.d.ts +155 -0
- package/dist/component/index.d.ts.map +1 -0
- package/dist/component.es.mjs +128 -0
- package/dist/component.es.mjs.map +1 -0
- package/dist/core/collection.d.ts +198 -0
- package/dist/core/collection.d.ts.map +1 -0
- package/dist/core/element.d.ts +301 -0
- package/dist/core/element.d.ts.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/selector.d.ts +11 -0
- package/dist/core/selector.d.ts.map +1 -0
- package/dist/core/shared.d.ts +7 -0
- package/dist/core/shared.d.ts.map +1 -0
- package/dist/core/utils.d.ts +300 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/core.es.mjs +1015 -0
- package/dist/core.es.mjs.map +1 -0
- package/dist/full.d.ts +48 -0
- package/dist/full.d.ts.map +1 -0
- package/dist/full.es.mjs +43 -0
- package/dist/full.es.mjs.map +1 -0
- package/dist/full.iife.js +2 -0
- package/dist/full.iife.js.map +1 -0
- package/dist/full.umd.js +2 -0
- package/dist/full.umd.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.mjs +43 -0
- package/dist/index.es.mjs.map +1 -0
- package/dist/motion/index.d.ts +145 -0
- package/dist/motion/index.d.ts.map +1 -0
- package/dist/motion.es.mjs +104 -0
- package/dist/motion.es.mjs.map +1 -0
- package/dist/platform/buckets.d.ts +44 -0
- package/dist/platform/buckets.d.ts.map +1 -0
- package/dist/platform/cache.d.ts +71 -0
- package/dist/platform/cache.d.ts.map +1 -0
- package/dist/platform/index.d.ts +15 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/notifications.d.ts +52 -0
- package/dist/platform/notifications.d.ts.map +1 -0
- package/dist/platform/storage.d.ts +69 -0
- package/dist/platform/storage.d.ts.map +1 -0
- package/dist/platform.es.mjs +245 -0
- package/dist/platform.es.mjs.map +1 -0
- package/dist/reactive/index.d.ts +8 -0
- package/dist/reactive/index.d.ts.map +1 -0
- package/dist/reactive/signal.d.ts +204 -0
- package/dist/reactive/signal.d.ts.map +1 -0
- package/dist/reactive.es.mjs +123 -0
- package/dist/reactive.es.mjs.map +1 -0
- package/dist/security/index.d.ts +8 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/sanitize.d.ts +99 -0
- package/dist/security/sanitize.d.ts.map +1 -0
- package/dist/security.es.mjs +194 -0
- package/dist/security.es.mjs.map +1 -0
- package/package.json +120 -0
- package/src/component/index.ts +360 -0
- package/src/core/collection.ts +339 -0
- package/src/core/element.ts +493 -0
- package/src/core/index.ts +4 -0
- package/src/core/selector.ts +29 -0
- package/src/core/shared.ts +13 -0
- package/src/core/utils.ts +425 -0
- package/src/full.ts +101 -0
- package/src/index.ts +27 -0
- package/src/motion/index.ts +365 -0
- package/src/platform/buckets.ts +115 -0
- package/src/platform/cache.ts +130 -0
- package/src/platform/index.ts +18 -0
- package/src/platform/notifications.ts +87 -0
- package/src/platform/storage.ts +208 -0
- package/src/reactive/index.ts +9 -0
- package/src/reactive/signal.ts +347 -0
- package/src/security/index.ts +18 -0
- package/src/security/sanitize.ts +446 -0
package/dist/core.es.mjs
ADDED
|
@@ -0,0 +1,1015 @@
|
|
|
1
|
+
import { sanitize as u } from "./security.es.mjs";
|
|
2
|
+
const a = (r) => Array.isArray(r) ? r : [r], s = (r, e) => {
|
|
3
|
+
for (const t of r)
|
|
4
|
+
e(t);
|
|
5
|
+
};
|
|
6
|
+
class o {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new BQueryElement wrapper.
|
|
9
|
+
* @param element - The DOM element to wrap
|
|
10
|
+
*/
|
|
11
|
+
constructor(e) {
|
|
12
|
+
this.element = e;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Exposes the raw DOM element when direct access is needed.
|
|
16
|
+
* Use sparingly; prefer the wrapper methods for consistency.
|
|
17
|
+
*/
|
|
18
|
+
get raw() {
|
|
19
|
+
return this.element;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Exposes the underlying DOM element.
|
|
23
|
+
* Provided for spec compatibility and read-only access.
|
|
24
|
+
*/
|
|
25
|
+
get node() {
|
|
26
|
+
return this.element;
|
|
27
|
+
}
|
|
28
|
+
/** Add one or more classes. */
|
|
29
|
+
addClass(...e) {
|
|
30
|
+
return this.element.classList.add(...e), this;
|
|
31
|
+
}
|
|
32
|
+
/** Remove one or more classes. */
|
|
33
|
+
removeClass(...e) {
|
|
34
|
+
return this.element.classList.remove(...e), this;
|
|
35
|
+
}
|
|
36
|
+
/** Toggle a class by name. */
|
|
37
|
+
toggleClass(e, t) {
|
|
38
|
+
return this.element.classList.toggle(e, t), this;
|
|
39
|
+
}
|
|
40
|
+
/** Get or set an attribute. */
|
|
41
|
+
attr(e, t) {
|
|
42
|
+
return t === void 0 ? this.element.getAttribute(e) ?? "" : (this.element.setAttribute(e, t), this);
|
|
43
|
+
}
|
|
44
|
+
/** Get or set a property. */
|
|
45
|
+
prop(e, t) {
|
|
46
|
+
return t === void 0 ? this.element[e] : (this.element[e] = t, this);
|
|
47
|
+
}
|
|
48
|
+
/** Read or write data attributes in camelCase. */
|
|
49
|
+
data(e, t) {
|
|
50
|
+
const n = e.replace(/[A-Z]/g, (i) => `-${i.toLowerCase()}`);
|
|
51
|
+
return t === void 0 ? this.element.getAttribute(`data-${n}`) ?? "" : (this.element.setAttribute(`data-${n}`, t), this);
|
|
52
|
+
}
|
|
53
|
+
/** Get or set text content. */
|
|
54
|
+
text(e) {
|
|
55
|
+
return e === void 0 ? this.element.textContent ?? "" : (this.element.textContent = e, this);
|
|
56
|
+
}
|
|
57
|
+
/** Set HTML content using a sanitized string. */
|
|
58
|
+
/**
|
|
59
|
+
* Sets sanitized HTML content on the element.
|
|
60
|
+
* Uses the security module to sanitize input and prevent XSS attacks.
|
|
61
|
+
*
|
|
62
|
+
* @param value - The HTML string to set (will be sanitized)
|
|
63
|
+
* @returns The instance for method chaining
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* $('#content').html('<strong>Hello</strong>');
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
html(e) {
|
|
71
|
+
return this.element.innerHTML = u(e), this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Sets HTML content without sanitization.
|
|
75
|
+
* Use only when you trust the HTML source completely.
|
|
76
|
+
*
|
|
77
|
+
* @param value - The raw HTML string to set
|
|
78
|
+
* @returns The instance for method chaining
|
|
79
|
+
*
|
|
80
|
+
* @warning This method bypasses XSS protection. Use with caution.
|
|
81
|
+
*/
|
|
82
|
+
htmlUnsafe(e) {
|
|
83
|
+
return this.element.innerHTML = e, this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets or sets CSS styles on the element.
|
|
87
|
+
*
|
|
88
|
+
* @param property - A CSS property name or an object of property-value pairs
|
|
89
|
+
* @param value - The value when setting a single property
|
|
90
|
+
* @returns The instance for method chaining
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* // Single property
|
|
95
|
+
* $('#box').css('color', 'red');
|
|
96
|
+
*
|
|
97
|
+
* // Multiple properties
|
|
98
|
+
* $('#box').css({ color: 'red', 'font-size': '16px' });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
css(e, t) {
|
|
102
|
+
if (typeof e == "string")
|
|
103
|
+
return t !== void 0 && this.element.style.setProperty(e, t), this;
|
|
104
|
+
for (const [n, i] of Object.entries(e))
|
|
105
|
+
this.element.style.setProperty(n, i);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Appends HTML or elements to the end of the element.
|
|
110
|
+
*
|
|
111
|
+
* @param content - HTML string or element(s) to append
|
|
112
|
+
* @returns The instance for method chaining
|
|
113
|
+
*/
|
|
114
|
+
append(e) {
|
|
115
|
+
return this.insertContent(e, "beforeend"), this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Prepends HTML or elements to the beginning of the element.
|
|
119
|
+
*
|
|
120
|
+
* @param content - HTML string or element(s) to prepend
|
|
121
|
+
* @returns The instance for method chaining
|
|
122
|
+
*/
|
|
123
|
+
prepend(e) {
|
|
124
|
+
return this.insertContent(e, "afterbegin"), this;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Inserts content before this element.
|
|
128
|
+
*
|
|
129
|
+
* @param content - HTML string or element(s) to insert
|
|
130
|
+
* @returns The instance for method chaining
|
|
131
|
+
*/
|
|
132
|
+
before(e) {
|
|
133
|
+
return this.insertContent(e, "beforebegin"), this;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Inserts content after this element.
|
|
137
|
+
*
|
|
138
|
+
* @param content - HTML string or element(s) to insert
|
|
139
|
+
* @returns The instance for method chaining
|
|
140
|
+
*/
|
|
141
|
+
after(e) {
|
|
142
|
+
return this.insertContent(e, "afterend"), this;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Removes the element from the DOM.
|
|
146
|
+
*
|
|
147
|
+
* @returns The instance for method chaining (though element is now detached)
|
|
148
|
+
*/
|
|
149
|
+
remove() {
|
|
150
|
+
return this.element.remove(), this;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Clears all child nodes from the element.
|
|
154
|
+
*
|
|
155
|
+
* @returns The instance for method chaining
|
|
156
|
+
*/
|
|
157
|
+
empty() {
|
|
158
|
+
return this.element.innerHTML = "", this;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Clones the element, optionally with all descendants.
|
|
162
|
+
*
|
|
163
|
+
* @param deep - If true, clone all descendants (default: true)
|
|
164
|
+
* @returns A new BQueryElement wrapping the cloned element
|
|
165
|
+
*/
|
|
166
|
+
clone(e = !0) {
|
|
167
|
+
return new o(this.element.cloneNode(e));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Finds all descendant elements matching the selector.
|
|
171
|
+
*
|
|
172
|
+
* @param selector - CSS selector to match
|
|
173
|
+
* @returns Array of matching elements
|
|
174
|
+
*/
|
|
175
|
+
find(e) {
|
|
176
|
+
return Array.from(this.element.querySelectorAll(e));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Finds the first descendant element matching the selector.
|
|
180
|
+
*
|
|
181
|
+
* @param selector - CSS selector to match
|
|
182
|
+
* @returns The first matching element or null
|
|
183
|
+
*/
|
|
184
|
+
findOne(e) {
|
|
185
|
+
return this.element.querySelector(e);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Finds the closest ancestor matching the selector.
|
|
189
|
+
*
|
|
190
|
+
* @param selector - CSS selector to match
|
|
191
|
+
* @returns The matching ancestor or null
|
|
192
|
+
*/
|
|
193
|
+
closest(e) {
|
|
194
|
+
return this.element.closest(e);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Gets the parent element.
|
|
198
|
+
*
|
|
199
|
+
* @returns The parent element or null
|
|
200
|
+
*/
|
|
201
|
+
parent() {
|
|
202
|
+
return this.element.parentElement;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Gets all child elements.
|
|
206
|
+
*
|
|
207
|
+
* @returns Array of child elements
|
|
208
|
+
*/
|
|
209
|
+
children() {
|
|
210
|
+
return Array.from(this.element.children);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Gets all sibling elements.
|
|
214
|
+
*
|
|
215
|
+
* @returns Array of sibling elements (excluding this element)
|
|
216
|
+
*/
|
|
217
|
+
siblings() {
|
|
218
|
+
const e = this.element.parentElement;
|
|
219
|
+
return e ? Array.from(e.children).filter((t) => t !== this.element) : [];
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Gets the next sibling element.
|
|
223
|
+
*
|
|
224
|
+
* @returns The next sibling element or null
|
|
225
|
+
*/
|
|
226
|
+
next() {
|
|
227
|
+
return this.element.nextElementSibling;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Gets the previous sibling element.
|
|
231
|
+
*
|
|
232
|
+
* @returns The previous sibling element or null
|
|
233
|
+
*/
|
|
234
|
+
prev() {
|
|
235
|
+
return this.element.previousElementSibling;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Adds an event listener.
|
|
239
|
+
*
|
|
240
|
+
* @param event - Event type to listen for
|
|
241
|
+
* @param handler - Event handler function
|
|
242
|
+
* @returns The instance for method chaining
|
|
243
|
+
*/
|
|
244
|
+
on(e, t) {
|
|
245
|
+
return this.element.addEventListener(e, t), this;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Adds a one-time event listener that removes itself after firing.
|
|
249
|
+
*
|
|
250
|
+
* @param event - Event type to listen for
|
|
251
|
+
* @param handler - Event handler function
|
|
252
|
+
* @returns The instance for method chaining
|
|
253
|
+
*/
|
|
254
|
+
once(e, t) {
|
|
255
|
+
return this.element.addEventListener(e, t, { once: !0 }), this;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Removes an event listener.
|
|
259
|
+
*
|
|
260
|
+
* @param event - Event type
|
|
261
|
+
* @param handler - The handler to remove
|
|
262
|
+
* @returns The instance for method chaining
|
|
263
|
+
*/
|
|
264
|
+
off(e, t) {
|
|
265
|
+
return this.element.removeEventListener(e, t), this;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Triggers a custom event on the element.
|
|
269
|
+
*
|
|
270
|
+
* @param event - Event type to trigger
|
|
271
|
+
* @param detail - Optional detail data to include with the event
|
|
272
|
+
* @returns The instance for method chaining
|
|
273
|
+
*/
|
|
274
|
+
trigger(e, t) {
|
|
275
|
+
return this.element.dispatchEvent(new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 })), this;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Checks if the element matches a CSS selector.
|
|
279
|
+
*
|
|
280
|
+
* @param selector - CSS selector to match against
|
|
281
|
+
* @returns True if the element matches the selector
|
|
282
|
+
*/
|
|
283
|
+
matches(e) {
|
|
284
|
+
return this.element.matches(e);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Checks if the element has a specific class.
|
|
288
|
+
*
|
|
289
|
+
* @param className - Class name to check
|
|
290
|
+
* @returns True if the element has the class
|
|
291
|
+
*/
|
|
292
|
+
hasClass(e) {
|
|
293
|
+
return this.element.classList.contains(e);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Shows the element by removing the hidden attribute and setting display.
|
|
297
|
+
*
|
|
298
|
+
* @param display - Optional display value (default: '')
|
|
299
|
+
* @returns The instance for method chaining
|
|
300
|
+
*/
|
|
301
|
+
show(e = "") {
|
|
302
|
+
return this.element.removeAttribute("hidden"), this.element.style.display = e, this;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Hides the element by setting display to 'none'.
|
|
306
|
+
*
|
|
307
|
+
* @returns The instance for method chaining
|
|
308
|
+
*/
|
|
309
|
+
hide() {
|
|
310
|
+
return this.element.style.display = "none", this;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Toggles the visibility of the element.
|
|
314
|
+
*
|
|
315
|
+
* @param force - Optional force show (true) or hide (false)
|
|
316
|
+
* @returns The instance for method chaining
|
|
317
|
+
*/
|
|
318
|
+
toggle(e) {
|
|
319
|
+
const t = this.element.style.display === "none";
|
|
320
|
+
return e ?? t ? this.show() : this.hide();
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Focuses the element.
|
|
324
|
+
*
|
|
325
|
+
* @returns The instance for method chaining
|
|
326
|
+
*/
|
|
327
|
+
focus() {
|
|
328
|
+
return this.element.focus(), this;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Blurs (unfocuses) the element.
|
|
332
|
+
*
|
|
333
|
+
* @returns The instance for method chaining
|
|
334
|
+
*/
|
|
335
|
+
blur() {
|
|
336
|
+
return this.element.blur(), this;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Gets or sets the value of form elements.
|
|
340
|
+
*
|
|
341
|
+
* @param newValue - Optional value to set
|
|
342
|
+
* @returns The current value when getting, or the instance when setting
|
|
343
|
+
*/
|
|
344
|
+
val(e) {
|
|
345
|
+
const t = this.element;
|
|
346
|
+
return e === void 0 ? t.value ?? "" : (t.value = e, this);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Gets the bounding client rectangle of the element.
|
|
350
|
+
*
|
|
351
|
+
* @returns The element's bounding rectangle
|
|
352
|
+
*/
|
|
353
|
+
rect() {
|
|
354
|
+
return this.element.getBoundingClientRect();
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Gets the offset dimensions (width, height, top, left).
|
|
358
|
+
*
|
|
359
|
+
* @returns Object with offset dimensions
|
|
360
|
+
*/
|
|
361
|
+
offset() {
|
|
362
|
+
const e = this.element;
|
|
363
|
+
return {
|
|
364
|
+
width: e.offsetWidth,
|
|
365
|
+
height: e.offsetHeight,
|
|
366
|
+
top: e.offsetTop,
|
|
367
|
+
left: e.offsetLeft
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Internal method to insert content at a specified position.
|
|
372
|
+
* @internal
|
|
373
|
+
*/
|
|
374
|
+
insertContent(e, t) {
|
|
375
|
+
if (typeof e == "string") {
|
|
376
|
+
this.element.insertAdjacentHTML(t, u(e));
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const n = a(e);
|
|
380
|
+
s(n, (i) => {
|
|
381
|
+
this.element.insertAdjacentElement(t, i);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
class l {
|
|
386
|
+
/**
|
|
387
|
+
* Creates a new collection wrapper.
|
|
388
|
+
* @param elements - Array of DOM elements to wrap
|
|
389
|
+
*/
|
|
390
|
+
constructor(e) {
|
|
391
|
+
this.elements = e;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Gets the number of elements in the collection.
|
|
395
|
+
*/
|
|
396
|
+
get length() {
|
|
397
|
+
return this.elements.length;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Gets the first element in the collection, if any.
|
|
401
|
+
* @internal
|
|
402
|
+
*/
|
|
403
|
+
first() {
|
|
404
|
+
return this.elements[0];
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Gets a single element as a BQueryElement wrapper.
|
|
408
|
+
*
|
|
409
|
+
* @param index - Zero-based index of the element
|
|
410
|
+
* @returns BQueryElement wrapper or undefined if out of range
|
|
411
|
+
*/
|
|
412
|
+
eq(e) {
|
|
413
|
+
const t = this.elements[e];
|
|
414
|
+
return t ? new o(t) : void 0;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Gets the first element as a BQueryElement wrapper.
|
|
418
|
+
*
|
|
419
|
+
* @returns BQueryElement wrapper or undefined if empty
|
|
420
|
+
*/
|
|
421
|
+
firstEl() {
|
|
422
|
+
return this.eq(0);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Gets the last element as a BQueryElement wrapper.
|
|
426
|
+
*
|
|
427
|
+
* @returns BQueryElement wrapper or undefined if empty
|
|
428
|
+
*/
|
|
429
|
+
lastEl() {
|
|
430
|
+
return this.eq(this.elements.length - 1);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Iterates over each element in the collection.
|
|
434
|
+
*
|
|
435
|
+
* @param callback - Function to call for each wrapped element
|
|
436
|
+
* @returns The instance for method chaining
|
|
437
|
+
*/
|
|
438
|
+
each(e) {
|
|
439
|
+
return this.elements.forEach((t, n) => {
|
|
440
|
+
e(new o(t), n);
|
|
441
|
+
}), this;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Maps each element to a new value.
|
|
445
|
+
*
|
|
446
|
+
* @param callback - Function to transform each element
|
|
447
|
+
* @returns Array of transformed values
|
|
448
|
+
*/
|
|
449
|
+
map(e) {
|
|
450
|
+
return this.elements.map(e);
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Filters elements based on a predicate.
|
|
454
|
+
*
|
|
455
|
+
* @param predicate - Function to test each element
|
|
456
|
+
* @returns New BQueryCollection with matching elements
|
|
457
|
+
*/
|
|
458
|
+
filter(e) {
|
|
459
|
+
return new l(this.elements.filter(e));
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Reduces the collection to a single value.
|
|
463
|
+
*
|
|
464
|
+
* @param callback - Reducer function
|
|
465
|
+
* @param initialValue - Initial accumulator value
|
|
466
|
+
* @returns Accumulated result
|
|
467
|
+
*/
|
|
468
|
+
reduce(e, t) {
|
|
469
|
+
return this.elements.reduce(e, t);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Converts the collection to an array of BQueryElement wrappers.
|
|
473
|
+
*
|
|
474
|
+
* @returns Array of BQueryElement instances
|
|
475
|
+
*/
|
|
476
|
+
toArray() {
|
|
477
|
+
return this.elements.map((e) => new o(e));
|
|
478
|
+
}
|
|
479
|
+
/** Add one or more classes to all elements. */
|
|
480
|
+
addClass(...e) {
|
|
481
|
+
return s(this.elements, (t) => t.classList.add(...e)), this;
|
|
482
|
+
}
|
|
483
|
+
/** Remove one or more classes from all elements. */
|
|
484
|
+
removeClass(...e) {
|
|
485
|
+
return s(this.elements, (t) => t.classList.remove(...e)), this;
|
|
486
|
+
}
|
|
487
|
+
/** Toggle a class on all elements. */
|
|
488
|
+
toggleClass(e, t) {
|
|
489
|
+
return s(this.elements, (n) => n.classList.toggle(e, t)), this;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Sets an attribute on all elements or gets from first.
|
|
493
|
+
*
|
|
494
|
+
* @param name - Attribute name
|
|
495
|
+
* @param value - Value to set (optional)
|
|
496
|
+
* @returns Attribute value when getting, instance when setting
|
|
497
|
+
*/
|
|
498
|
+
attr(e, t) {
|
|
499
|
+
return t === void 0 ? this.first()?.getAttribute(e) ?? "" : (s(this.elements, (n) => n.setAttribute(e, t)), this);
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Removes an attribute from all elements.
|
|
503
|
+
*
|
|
504
|
+
* @param name - Attribute name to remove
|
|
505
|
+
* @returns The instance for method chaining
|
|
506
|
+
*/
|
|
507
|
+
removeAttr(e) {
|
|
508
|
+
return s(this.elements, (t) => t.removeAttribute(e)), this;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Sets text content on all elements or gets from first.
|
|
512
|
+
*
|
|
513
|
+
* @param value - Text to set (optional)
|
|
514
|
+
* @returns Text content when getting, instance when setting
|
|
515
|
+
*/
|
|
516
|
+
text(e) {
|
|
517
|
+
return e === void 0 ? this.first()?.textContent ?? "" : (s(this.elements, (t) => {
|
|
518
|
+
t.textContent = e;
|
|
519
|
+
}), this);
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Sets sanitized HTML on all elements or gets from first.
|
|
523
|
+
*
|
|
524
|
+
* @param value - HTML to set (optional, will be sanitized)
|
|
525
|
+
* @returns HTML content when getting, instance when setting
|
|
526
|
+
*/
|
|
527
|
+
html(e) {
|
|
528
|
+
if (e === void 0)
|
|
529
|
+
return this.first()?.innerHTML ?? "";
|
|
530
|
+
const t = u(e);
|
|
531
|
+
return s(this.elements, (n) => {
|
|
532
|
+
n.innerHTML = t;
|
|
533
|
+
}), this;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Sets HTML on all elements without sanitization.
|
|
537
|
+
*
|
|
538
|
+
* @param value - Raw HTML to set
|
|
539
|
+
* @returns The instance for method chaining
|
|
540
|
+
* @warning Bypasses XSS protection
|
|
541
|
+
*/
|
|
542
|
+
htmlUnsafe(e) {
|
|
543
|
+
return s(this.elements, (t) => {
|
|
544
|
+
t.innerHTML = e;
|
|
545
|
+
}), this;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Applies CSS styles to all elements.
|
|
549
|
+
*
|
|
550
|
+
* @param property - Property name or object of properties
|
|
551
|
+
* @param value - Value when setting single property
|
|
552
|
+
* @returns The instance for method chaining
|
|
553
|
+
*/
|
|
554
|
+
css(e, t) {
|
|
555
|
+
return typeof e == "string" ? (t !== void 0 && s(this.elements, (n) => {
|
|
556
|
+
n.style.setProperty(e, t);
|
|
557
|
+
}), this) : (s(this.elements, (n) => {
|
|
558
|
+
for (const [i, m] of Object.entries(e))
|
|
559
|
+
n.style.setProperty(i, m);
|
|
560
|
+
}), this);
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Shows all elements.
|
|
564
|
+
*
|
|
565
|
+
* @param display - Optional display value (default: '')
|
|
566
|
+
* @returns The instance for method chaining
|
|
567
|
+
*/
|
|
568
|
+
show(e = "") {
|
|
569
|
+
return s(this.elements, (t) => {
|
|
570
|
+
t.removeAttribute("hidden"), t.style.display = e;
|
|
571
|
+
}), this;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Hides all elements.
|
|
575
|
+
*
|
|
576
|
+
* @returns The instance for method chaining
|
|
577
|
+
*/
|
|
578
|
+
hide() {
|
|
579
|
+
return s(this.elements, (e) => {
|
|
580
|
+
e.style.display = "none";
|
|
581
|
+
}), this;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Adds an event listener to all elements.
|
|
585
|
+
*
|
|
586
|
+
* @param event - Event type
|
|
587
|
+
* @param handler - Event handler
|
|
588
|
+
* @returns The instance for method chaining
|
|
589
|
+
*/
|
|
590
|
+
on(e, t) {
|
|
591
|
+
return s(this.elements, (n) => n.addEventListener(e, t)), this;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Adds a one-time event listener to all elements.
|
|
595
|
+
*
|
|
596
|
+
* @param event - Event type
|
|
597
|
+
* @param handler - Event handler
|
|
598
|
+
* @returns The instance for method chaining
|
|
599
|
+
*/
|
|
600
|
+
once(e, t) {
|
|
601
|
+
return s(this.elements, (n) => n.addEventListener(e, t, { once: !0 })), this;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Removes an event listener from all elements.
|
|
605
|
+
*
|
|
606
|
+
* @param event - Event type
|
|
607
|
+
* @param handler - The handler to remove
|
|
608
|
+
* @returns The instance for method chaining
|
|
609
|
+
*/
|
|
610
|
+
off(e, t) {
|
|
611
|
+
return s(this.elements, (n) => n.removeEventListener(e, t)), this;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Triggers a custom event on all elements.
|
|
615
|
+
*
|
|
616
|
+
* @param event - Event type
|
|
617
|
+
* @param detail - Optional event detail
|
|
618
|
+
* @returns The instance for method chaining
|
|
619
|
+
*/
|
|
620
|
+
trigger(e, t) {
|
|
621
|
+
return s(this.elements, (n) => {
|
|
622
|
+
n.dispatchEvent(new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 }));
|
|
623
|
+
}), this;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Removes all elements from the DOM.
|
|
627
|
+
*
|
|
628
|
+
* @returns The instance for method chaining
|
|
629
|
+
*/
|
|
630
|
+
remove() {
|
|
631
|
+
return s(this.elements, (e) => e.remove()), this;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Clears all child nodes from all elements.
|
|
635
|
+
*
|
|
636
|
+
* @returns The instance for method chaining
|
|
637
|
+
*/
|
|
638
|
+
empty() {
|
|
639
|
+
return s(this.elements, (e) => {
|
|
640
|
+
e.innerHTML = "";
|
|
641
|
+
}), this;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
const f = (r) => {
|
|
645
|
+
if (typeof r != "string")
|
|
646
|
+
return new o(r);
|
|
647
|
+
const e = document.querySelector(r);
|
|
648
|
+
if (!e)
|
|
649
|
+
throw new Error(`bQuery: element not found for selector "${r}"`);
|
|
650
|
+
return new o(e);
|
|
651
|
+
}, d = (r) => Array.isArray(r) ? new l(r) : r instanceof NodeList ? new l(Array.from(r)) : new l(Array.from(document.querySelectorAll(r))), h = {
|
|
652
|
+
/**
|
|
653
|
+
* Creates a deep clone using structuredClone if available, otherwise fallback to JSON.
|
|
654
|
+
*
|
|
655
|
+
* @template T - The type of value being cloned
|
|
656
|
+
* @param value - The value to clone
|
|
657
|
+
* @returns A deep copy of the value
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* ```ts
|
|
661
|
+
* const original = { nested: { value: 1 } };
|
|
662
|
+
* const copy = utils.clone(original);
|
|
663
|
+
* copy.nested.value = 2;
|
|
664
|
+
* console.log(original.nested.value); // 1
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
clone(r) {
|
|
668
|
+
return typeof structuredClone == "function" ? structuredClone(r) : JSON.parse(JSON.stringify(r));
|
|
669
|
+
},
|
|
670
|
+
/**
|
|
671
|
+
* Deep-merges plain objects into a new object.
|
|
672
|
+
* Later sources override earlier ones for primitive values.
|
|
673
|
+
* Objects are recursively merged.
|
|
674
|
+
*
|
|
675
|
+
* @template T - The type of the merged object
|
|
676
|
+
* @param sources - Objects to merge
|
|
677
|
+
* @returns A new object with all sources merged
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
* ```ts
|
|
681
|
+
* const result = utils.merge(
|
|
682
|
+
* { a: 1, nested: { x: 1 } },
|
|
683
|
+
* { b: 2, nested: { y: 2 } }
|
|
684
|
+
* );
|
|
685
|
+
* // Result: { a: 1, b: 2, nested: { x: 1, y: 2 } }
|
|
686
|
+
* ```
|
|
687
|
+
*/
|
|
688
|
+
merge(...r) {
|
|
689
|
+
const e = {};
|
|
690
|
+
for (const t of r)
|
|
691
|
+
for (const [n, i] of Object.entries(t))
|
|
692
|
+
h.isPlainObject(i) && h.isPlainObject(e[n]) ? e[n] = h.merge(
|
|
693
|
+
e[n],
|
|
694
|
+
i
|
|
695
|
+
) : e[n] = i;
|
|
696
|
+
return e;
|
|
697
|
+
},
|
|
698
|
+
/**
|
|
699
|
+
* Creates a debounced function that delays execution until after
|
|
700
|
+
* the specified delay has elapsed since the last call.
|
|
701
|
+
*
|
|
702
|
+
* @template TArgs - The argument types of the function
|
|
703
|
+
* @param fn - The function to debounce
|
|
704
|
+
* @param delayMs - Delay in milliseconds
|
|
705
|
+
* @returns A debounced version of the function
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
708
|
+
* ```ts
|
|
709
|
+
* const search = utils.debounce((query: string) => {
|
|
710
|
+
* console.log('Searching:', query);
|
|
711
|
+
* }, 300);
|
|
712
|
+
*
|
|
713
|
+
* search('h');
|
|
714
|
+
* search('he');
|
|
715
|
+
* search('hello'); // Only this call executes after 300ms
|
|
716
|
+
* ```
|
|
717
|
+
*/
|
|
718
|
+
debounce(r, e) {
|
|
719
|
+
let t;
|
|
720
|
+
return (...n) => {
|
|
721
|
+
t && clearTimeout(t), t = setTimeout(() => r(...n), e);
|
|
722
|
+
};
|
|
723
|
+
},
|
|
724
|
+
/**
|
|
725
|
+
* Creates a throttled function that runs at most once per interval.
|
|
726
|
+
*
|
|
727
|
+
* @template TArgs - The argument types of the function
|
|
728
|
+
* @param fn - The function to throttle
|
|
729
|
+
* @param intervalMs - Minimum interval between calls in milliseconds
|
|
730
|
+
* @returns A throttled version of the function
|
|
731
|
+
*
|
|
732
|
+
* @example
|
|
733
|
+
* ```ts
|
|
734
|
+
* const handleScroll = utils.throttle(() => {
|
|
735
|
+
* console.log('Scroll position:', window.scrollY);
|
|
736
|
+
* }, 100);
|
|
737
|
+
*
|
|
738
|
+
* window.addEventListener('scroll', handleScroll);
|
|
739
|
+
* ```
|
|
740
|
+
*/
|
|
741
|
+
throttle(r, e) {
|
|
742
|
+
let t = 0;
|
|
743
|
+
return (...n) => {
|
|
744
|
+
const i = Date.now();
|
|
745
|
+
i - t >= e && (t = i, r(...n));
|
|
746
|
+
};
|
|
747
|
+
},
|
|
748
|
+
/**
|
|
749
|
+
* Creates a stable unique ID for DOM usage.
|
|
750
|
+
*
|
|
751
|
+
* @param prefix - Optional prefix for the ID (default: 'bQuery')
|
|
752
|
+
* @returns A unique identifier string
|
|
753
|
+
*
|
|
754
|
+
* @example
|
|
755
|
+
* ```ts
|
|
756
|
+
* const id = utils.uid('modal'); // 'modal_x7k2m9p'
|
|
757
|
+
* ```
|
|
758
|
+
*/
|
|
759
|
+
uid(r = "bQuery") {
|
|
760
|
+
return `${r}_${Math.random().toString(36).slice(2, 9)}`;
|
|
761
|
+
},
|
|
762
|
+
/**
|
|
763
|
+
* Checks if a value is a DOM Element.
|
|
764
|
+
*
|
|
765
|
+
* @param value - The value to check
|
|
766
|
+
* @returns True if the value is an Element
|
|
767
|
+
*/
|
|
768
|
+
isElement(r) {
|
|
769
|
+
return r instanceof Element;
|
|
770
|
+
},
|
|
771
|
+
/**
|
|
772
|
+
* Checks if a value is a BQueryCollection-like object.
|
|
773
|
+
*
|
|
774
|
+
* @param value - The value to check
|
|
775
|
+
* @returns True if the value has an elements array property
|
|
776
|
+
*/
|
|
777
|
+
isCollection(r) {
|
|
778
|
+
return !!(r && typeof r == "object" && "elements" in r);
|
|
779
|
+
},
|
|
780
|
+
/**
|
|
781
|
+
* Checks for emptiness across common value types.
|
|
782
|
+
*
|
|
783
|
+
* @param value - The value to check
|
|
784
|
+
* @returns True if the value is empty (null, undefined, empty string, empty array, or empty object)
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
* ```ts
|
|
788
|
+
* utils.isEmpty(''); // true
|
|
789
|
+
* utils.isEmpty([]); // true
|
|
790
|
+
* utils.isEmpty({}); // true
|
|
791
|
+
* utils.isEmpty(null); // true
|
|
792
|
+
* utils.isEmpty('hello'); // false
|
|
793
|
+
* utils.isEmpty([1, 2]); // false
|
|
794
|
+
* ```
|
|
795
|
+
*/
|
|
796
|
+
isEmpty(r) {
|
|
797
|
+
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;
|
|
798
|
+
},
|
|
799
|
+
/**
|
|
800
|
+
* Checks if a value is a plain object (not null, array, or class instance).
|
|
801
|
+
*
|
|
802
|
+
* @param value - The value to check
|
|
803
|
+
* @returns True if the value is a plain object
|
|
804
|
+
*/
|
|
805
|
+
isPlainObject(r) {
|
|
806
|
+
return Object.prototype.toString.call(r) === "[object Object]";
|
|
807
|
+
},
|
|
808
|
+
/**
|
|
809
|
+
* Checks if a value is a function.
|
|
810
|
+
*
|
|
811
|
+
* @param value - The value to check
|
|
812
|
+
* @returns True if the value is a function
|
|
813
|
+
*/
|
|
814
|
+
isFunction(r) {
|
|
815
|
+
return typeof r == "function";
|
|
816
|
+
},
|
|
817
|
+
/**
|
|
818
|
+
* Checks if a value is a string.
|
|
819
|
+
*
|
|
820
|
+
* @param value - The value to check
|
|
821
|
+
* @returns True if the value is a string
|
|
822
|
+
*/
|
|
823
|
+
isString(r) {
|
|
824
|
+
return typeof r == "string";
|
|
825
|
+
},
|
|
826
|
+
/**
|
|
827
|
+
* Checks if a value is a number (excluding NaN).
|
|
828
|
+
*
|
|
829
|
+
* @param value - The value to check
|
|
830
|
+
* @returns True if the value is a valid number
|
|
831
|
+
*/
|
|
832
|
+
isNumber(r) {
|
|
833
|
+
return typeof r == "number" && !Number.isNaN(r);
|
|
834
|
+
},
|
|
835
|
+
/**
|
|
836
|
+
* Checks if a value is a boolean.
|
|
837
|
+
*
|
|
838
|
+
* @param value - The value to check
|
|
839
|
+
* @returns True if the value is a boolean
|
|
840
|
+
*/
|
|
841
|
+
isBoolean(r) {
|
|
842
|
+
return typeof r == "boolean";
|
|
843
|
+
},
|
|
844
|
+
/**
|
|
845
|
+
* Checks if a value is an array.
|
|
846
|
+
*
|
|
847
|
+
* @template T - The type of array elements
|
|
848
|
+
* @param value - The value to check
|
|
849
|
+
* @returns True if the value is an array
|
|
850
|
+
*/
|
|
851
|
+
isArray(r) {
|
|
852
|
+
return Array.isArray(r);
|
|
853
|
+
},
|
|
854
|
+
/**
|
|
855
|
+
* Safely parses a JSON string, returning a default value on error.
|
|
856
|
+
*
|
|
857
|
+
* @template T - The expected type of the parsed value
|
|
858
|
+
* @param json - The JSON string to parse
|
|
859
|
+
* @param fallback - The default value if parsing fails
|
|
860
|
+
* @returns The parsed value or the fallback
|
|
861
|
+
*
|
|
862
|
+
* @example
|
|
863
|
+
* ```ts
|
|
864
|
+
* utils.parseJson('{"name":"bQuery"}', {}); // { name: 'bQuery' }
|
|
865
|
+
* utils.parseJson('invalid', {}); // {}
|
|
866
|
+
* ```
|
|
867
|
+
*/
|
|
868
|
+
parseJson(r, e) {
|
|
869
|
+
try {
|
|
870
|
+
return JSON.parse(r);
|
|
871
|
+
} catch {
|
|
872
|
+
return e;
|
|
873
|
+
}
|
|
874
|
+
},
|
|
875
|
+
/**
|
|
876
|
+
* Picks specified keys from an object.
|
|
877
|
+
*
|
|
878
|
+
* @template T - The object type
|
|
879
|
+
* @template K - The key type
|
|
880
|
+
* @param obj - The source object
|
|
881
|
+
* @param keys - Keys to pick
|
|
882
|
+
* @returns A new object with only the specified keys
|
|
883
|
+
*
|
|
884
|
+
* @example
|
|
885
|
+
* ```ts
|
|
886
|
+
* const user = { name: 'John', age: 30, email: 'john@example.com' };
|
|
887
|
+
* utils.pick(user, ['name', 'email']); // { name: 'John', email: 'john@example.com' }
|
|
888
|
+
* ```
|
|
889
|
+
*/
|
|
890
|
+
pick(r, e) {
|
|
891
|
+
const t = {};
|
|
892
|
+
for (const n of e)
|
|
893
|
+
n in r && (t[n] = r[n]);
|
|
894
|
+
return t;
|
|
895
|
+
},
|
|
896
|
+
/**
|
|
897
|
+
* Omits specified keys from an object.
|
|
898
|
+
*
|
|
899
|
+
* @template T - The object type
|
|
900
|
+
* @template K - The key type
|
|
901
|
+
* @param obj - The source object
|
|
902
|
+
* @param keys - Keys to omit
|
|
903
|
+
* @returns A new object without the specified keys
|
|
904
|
+
*
|
|
905
|
+
* @example
|
|
906
|
+
* ```ts
|
|
907
|
+
* const user = { name: 'John', age: 30, password: 'secret' };
|
|
908
|
+
* utils.omit(user, ['password']); // { name: 'John', age: 30 }
|
|
909
|
+
* ```
|
|
910
|
+
*/
|
|
911
|
+
omit(r, e) {
|
|
912
|
+
const t = { ...r };
|
|
913
|
+
for (const n of e)
|
|
914
|
+
delete t[n];
|
|
915
|
+
return t;
|
|
916
|
+
},
|
|
917
|
+
/**
|
|
918
|
+
* Delays execution for a specified number of milliseconds.
|
|
919
|
+
*
|
|
920
|
+
* @param ms - Milliseconds to delay
|
|
921
|
+
* @returns A promise that resolves after the delay
|
|
922
|
+
*
|
|
923
|
+
* @example
|
|
924
|
+
* ```ts
|
|
925
|
+
* await utils.sleep(1000); // Wait 1 second
|
|
926
|
+
* console.log('Done!');
|
|
927
|
+
* ```
|
|
928
|
+
*/
|
|
929
|
+
sleep(r) {
|
|
930
|
+
return new Promise((e) => setTimeout(e, r));
|
|
931
|
+
},
|
|
932
|
+
/**
|
|
933
|
+
* Generates a random integer between min and max (inclusive).
|
|
934
|
+
*
|
|
935
|
+
* @param min - Minimum value
|
|
936
|
+
* @param max - Maximum value
|
|
937
|
+
* @returns A random integer in the range [min, max]
|
|
938
|
+
*
|
|
939
|
+
* @example
|
|
940
|
+
* ```ts
|
|
941
|
+
* const roll = utils.randomInt(1, 6); // Random dice roll
|
|
942
|
+
* ```
|
|
943
|
+
*/
|
|
944
|
+
randomInt(r, e) {
|
|
945
|
+
return Math.floor(Math.random() * (e - r + 1)) + r;
|
|
946
|
+
},
|
|
947
|
+
/**
|
|
948
|
+
* Clamps a number between a minimum and maximum value.
|
|
949
|
+
*
|
|
950
|
+
* @param value - The value to clamp
|
|
951
|
+
* @param min - Minimum value
|
|
952
|
+
* @param max - Maximum value
|
|
953
|
+
* @returns The clamped value
|
|
954
|
+
*
|
|
955
|
+
* @example
|
|
956
|
+
* ```ts
|
|
957
|
+
* utils.clamp(150, 0, 100); // 100
|
|
958
|
+
* utils.clamp(-10, 0, 100); // 0
|
|
959
|
+
* utils.clamp(50, 0, 100); // 50
|
|
960
|
+
* ```
|
|
961
|
+
*/
|
|
962
|
+
clamp(r, e, t) {
|
|
963
|
+
return Math.min(Math.max(r, e), t);
|
|
964
|
+
},
|
|
965
|
+
/**
|
|
966
|
+
* Capitalizes the first letter of a string.
|
|
967
|
+
*
|
|
968
|
+
* @param str - The string to capitalize
|
|
969
|
+
* @returns The capitalized string
|
|
970
|
+
*
|
|
971
|
+
* @example
|
|
972
|
+
* ```ts
|
|
973
|
+
* utils.capitalize('hello'); // 'Hello'
|
|
974
|
+
* ```
|
|
975
|
+
*/
|
|
976
|
+
capitalize(r) {
|
|
977
|
+
return r && r.charAt(0).toUpperCase() + r.slice(1);
|
|
978
|
+
},
|
|
979
|
+
/**
|
|
980
|
+
* Converts a string to kebab-case.
|
|
981
|
+
*
|
|
982
|
+
* @param str - The string to convert
|
|
983
|
+
* @returns The kebab-cased string
|
|
984
|
+
*
|
|
985
|
+
* @example
|
|
986
|
+
* ```ts
|
|
987
|
+
* utils.toKebabCase('myVariableName'); // 'my-variable-name'
|
|
988
|
+
* ```
|
|
989
|
+
*/
|
|
990
|
+
toKebabCase(r) {
|
|
991
|
+
return r.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
992
|
+
},
|
|
993
|
+
/**
|
|
994
|
+
* Converts a string to camelCase.
|
|
995
|
+
*
|
|
996
|
+
* @param str - The string to convert
|
|
997
|
+
* @returns The camelCased string
|
|
998
|
+
*
|
|
999
|
+
* @example
|
|
1000
|
+
* ```ts
|
|
1001
|
+
* utils.toCamelCase('my-variable-name'); // 'myVariableName'
|
|
1002
|
+
* ```
|
|
1003
|
+
*/
|
|
1004
|
+
toCamelCase(r) {
|
|
1005
|
+
return r.replace(/[-_\s]+(.)?/g, (e, t) => t ? t.toUpperCase() : "").replace(/^[A-Z]/, (e) => e.toLowerCase());
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
export {
|
|
1009
|
+
f as $,
|
|
1010
|
+
d as $$,
|
|
1011
|
+
l as BQueryCollection,
|
|
1012
|
+
o as BQueryElement,
|
|
1013
|
+
h as utils
|
|
1014
|
+
};
|
|
1015
|
+
//# sourceMappingURL=core.es.mjs.map
|