jj 2.5.0 → 2.6.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.
Files changed (77) hide show
  1. package/README.md +29 -1
  2. package/SKILL.md +671 -0
  3. package/lib/bundle.cjs +2031 -0
  4. package/lib/bundle.cjs.map +1 -0
  5. package/lib/bundle.d.cts +1782 -0
  6. package/lib/bundle.d.ts +1782 -1
  7. package/lib/bundle.global.js +1953 -0
  8. package/lib/bundle.global.js.map +1 -0
  9. package/lib/bundle.js +232 -230
  10. package/lib/bundle.js.map +1 -7
  11. package/lib/bundle.min.cjs +2 -0
  12. package/lib/bundle.min.cjs.map +1 -0
  13. package/lib/bundle.min.d.cts +1782 -0
  14. package/lib/bundle.min.d.ts +1782 -1
  15. package/lib/bundle.min.global.js +2 -0
  16. package/lib/bundle.min.global.js.map +1 -0
  17. package/lib/bundle.min.js +2 -1
  18. package/lib/bundle.min.js.map +1 -0
  19. package/package.json +5 -5
  20. package/lib/JJD.d.ts +0 -87
  21. package/lib/JJD.js +0 -119
  22. package/lib/JJD.js.map +0 -1
  23. package/lib/JJDF.d.ts +0 -74
  24. package/lib/JJDF.js +0 -98
  25. package/lib/JJDF.js.map +0 -1
  26. package/lib/JJE.d.ts +0 -299
  27. package/lib/JJE.js +0 -401
  28. package/lib/JJE.js.map +0 -1
  29. package/lib/JJET.d.ts +0 -79
  30. package/lib/JJET.js +0 -114
  31. package/lib/JJET.js.map +0 -1
  32. package/lib/JJEx.d.ts +0 -63
  33. package/lib/JJEx.js +0 -83
  34. package/lib/JJEx.js.map +0 -1
  35. package/lib/JJHE.d.ts +0 -109
  36. package/lib/JJHE.js +0 -136
  37. package/lib/JJHE.js.map +0 -1
  38. package/lib/JJN-wrap.d.ts +0 -1
  39. package/lib/JJN-wrap.js +0 -46
  40. package/lib/JJN-wrap.js.map +0 -1
  41. package/lib/JJN.d.ts +0 -126
  42. package/lib/JJN.js +0 -166
  43. package/lib/JJN.js.map +0 -1
  44. package/lib/JJNx.d.ts +0 -126
  45. package/lib/JJNx.js +0 -157
  46. package/lib/JJNx.js.map +0 -1
  47. package/lib/JJSE.d.ts +0 -170
  48. package/lib/JJSE.js +0 -217
  49. package/lib/JJSE.js.map +0 -1
  50. package/lib/JJSR.d.ts +0 -71
  51. package/lib/JJSR.js +0 -90
  52. package/lib/JJSR.js.map +0 -1
  53. package/lib/JJT.d.ts +0 -92
  54. package/lib/JJT.js +0 -116
  55. package/lib/JJT.js.map +0 -1
  56. package/lib/case.d.ts +0 -60
  57. package/lib/case.js +0 -92
  58. package/lib/case.js.map +0 -1
  59. package/lib/components.d.ts +0 -147
  60. package/lib/components.js +0 -287
  61. package/lib/components.js.map +0 -1
  62. package/lib/helpers.d.ts +0 -159
  63. package/lib/helpers.js +0 -233
  64. package/lib/helpers.js.map +0 -1
  65. package/lib/index.d.ts +0 -33
  66. package/lib/index.js +0 -35
  67. package/lib/index.js.map +0 -1
  68. package/lib/internal.d.ts +0 -30
  69. package/lib/internal.js +0 -35
  70. package/lib/internal.js.map +0 -1
  71. package/lib/types.d.ts +0 -65
  72. package/lib/types.js +0 -2
  73. package/lib/types.js.map +0 -1
  74. package/lib/util.d.ts +0 -68
  75. package/lib/util.js +0 -90
  76. package/lib/util.js.map +0 -1
  77. package/llms.txt +0 -214
@@ -0,0 +1,1782 @@
1
+ /**
2
+ * Returns the file extension
3
+ *
4
+ * @remarks
5
+ * This convenience function is primarily used to guess the 'as' attribute of
6
+ * a link preload/prefetch behind the scene.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * fileExt('file.txt') // => 'txt'
11
+ * fileExt('https://www.alexewerlof.com/path/to/file.js') // => 'js'
12
+ * ```
13
+ *
14
+ * @param path - absolute, relative, or URL path to a file
15
+ * @returns the extension name in lowercase and without any dot prefix
16
+ * @throws {TypeError} If path is not a string.
17
+ */
18
+ declare function fileExt(path: string): string;
19
+ /**
20
+ * Returns a promise that resolves before the next repaint.
21
+ *
22
+ * @remarks
23
+ * Used to give the UI a moment to update.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * await nextAnimationFrame()
28
+ * ```
29
+ *
30
+ * @returns A promise that resolves with the timestamp.
31
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame | requestAnimationFrame}
32
+ */
33
+ declare function nextAnimationFrame(): Promise<number>;
34
+ /**
35
+ * Returns a promise that resolves after the specified delay.
36
+ *
37
+ * @remarks
38
+ * Uses `setTimeout` to delay execution. When used with 0ms, it defers
39
+ * execution to the next macro-task, allowing the event loop to cycle.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * await sleep(100)
44
+ * await sleep() // equivalent to setTimeout(..., 0)
45
+ * ```
46
+ *
47
+ * @param ms - The delay in milliseconds. Defaults to 0.
48
+ * @returns A promise that resolves after the delay.
49
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/setTimeout | setTimeout}
50
+ */
51
+ declare function sleep(ms?: number): Promise<void>;
52
+ /**
53
+ * Converts a CSS string to a CSSStyleSheet.
54
+ *
55
+ * @remarks
56
+ * Suitable for attaching to ShadowRoot via `adoptedStyleSheets`.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const sheet = await cssToStyle('p { color: red; }')
61
+ * shadowRoot.adoptedStyleSheets = [sheet]
62
+ * ```
63
+ *
64
+ * @param css - The CSS string.
65
+ * @returns A promise resolving to the created CSSStyleSheet.
66
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/replace | CSSStyleSheet.replace}
67
+ */
68
+ declare function cssToStyle(css: string): Promise<CSSStyleSheet>;
69
+
70
+ /**
71
+ * Converts a PascalCase, camelCase, or snake_case string to kebab-case.
72
+ *
73
+ * @remarks
74
+ * This function is useful for converting JavaScript property names to CSS or HTML attribute names.
75
+ * It strictly validates the input to contain only alphanumeric characters and underscores.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * pas2keb('backgroundColor') // 'background-color'
80
+ * pas2keb('MyComponent') // 'my-component'
81
+ * pas2keb('user_id') // 'user-id'
82
+ * ```
83
+ *
84
+ * @param str - The string to convert.
85
+ * @returns The kebab-case string.
86
+ * @throws {TypeError} If `str` is not a string or contains invalid characters (anything other than `/[a-zA-Z0-9_]/`).
87
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace | String.prototype.replace}
88
+ */
89
+ declare function pas2keb(str: string): string;
90
+ /**
91
+ * Converts a kebab-case string to PascalCase.
92
+ *
93
+ * @remarks
94
+ * This function splits the string by hyphens and capitalizes the first letter of each segment.
95
+ * It handles multiple hyphens by ignoring empty segments.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * keb2pas('background-color') // 'BackgroundColor'
100
+ * keb2pas('my-component') // 'MyComponent'
101
+ * keb2pas('multi--dash') // 'MultiDash'
102
+ * ```
103
+ *
104
+ * @param str - The string to convert.
105
+ * @returns The PascalCase string.
106
+ * @throws {TypeError} If `str` is not a string.
107
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split | String.prototype.split}
108
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.prototype.map}
109
+ */
110
+ declare function keb2pas(str: string): string;
111
+ /**
112
+ * Converts a kebab-case string to camelCase.
113
+ *
114
+ * @remarks
115
+ * This function is primarily useful for converting attributes to JavaScript property names.
116
+ * Leading and trailing hyphens are removed before conversion.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * keb2cam('background-color') // 'backgroundColor'
121
+ * keb2cam('-webkit-transform') // 'webkitTransform'
122
+ * ```
123
+ *
124
+ * @param str - The string to convert.
125
+ * @returns The camelCase string.
126
+ * @throws {TypeError} If `str` is not a string.
127
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace | String.prototype.replace}
128
+ */
129
+ declare function keb2cam(str: string): string;
130
+
131
+ /**
132
+ * Wraps a DOM EventTarget.
133
+ *
134
+ * @remarks
135
+ * This is the base class for all JJ wrappers that wrap an EventTarget.
136
+ *
137
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget | EventTarget}
138
+ */
139
+ declare class JJET<T extends EventTarget = EventTarget> {
140
+ #private;
141
+ static from(ref: EventTarget): JJET<EventTarget>;
142
+ /**
143
+ * Creates a JJET instance.
144
+ *
145
+ * @param ref - The EventTarget to wrap.
146
+ * @throws {TypeError} If `ref` is not an EventTarget.
147
+ */
148
+ constructor(ref: T);
149
+ /**
150
+ * Gets the underlying DOM object.
151
+ */
152
+ get ref(): T;
153
+ /**
154
+ * Adds an event listener.
155
+ *
156
+ * @remarks
157
+ * The handler is automatically bound to this JJET instance, so `this` inside the handler
158
+ * refers to the JJET instance, not the DOM element. To access the DOM element, use `this.ref`.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * JJET.from(window).on('resize', function() {
163
+ * console.log(this) // JJET instance
164
+ * console.log(this.ref) // window object
165
+ * })
166
+ * ```
167
+ * @param eventName - The name of the event.
168
+ * @param handler - The event handler.
169
+ * @param options - Optional event listener options.
170
+ * @returns This instance for chaining.
171
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener | EventTarget.addEventListener}
172
+ */
173
+ on(eventName: string, handler: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions): this;
174
+ /**
175
+ * Removes an event listener.
176
+ *
177
+ * @remarks
178
+ * Pass the same handler reference that was used in `on()` to properly remove the listener.
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * const handler = function() { console.log(this) }
183
+ * JJET.from(window).on('resize', handler)
184
+ * JJET.from(window).off('resize', handler)
185
+ * ```
186
+ * @param eventName - The name of the event.
187
+ * @param handler - The event handler.
188
+ * @param options - Optional event listener options or boolean.
189
+ * @returns This instance for chaining.
190
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener | EventTarget.removeEventListener}
191
+ */
192
+ off(eventName: string, handler: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): this;
193
+ /**
194
+ * Dispatches an Event at the specified EventTarget.
195
+ *
196
+ * @param event - The Event object to dispatch.
197
+ * @returns This instance for chaining.
198
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent | EventTarget.dispatchEvent}
199
+ */
200
+ trigger(event: Event): this;
201
+ /**
202
+ * Runs a function in the context of this JJET instance.
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * node.run(function() {
207
+ * console.log(this.ref)
208
+ * })
209
+ * ```
210
+ * @remarks
211
+ * If you want to access the current JJ* instance using `this` keyword, you SHOULD use a `function` not an arrow function.
212
+ * If the function throws, `run()` doesn't swallow the exception.
213
+ * So if you're expecting an error, make sure to wrap it in a `try..catch` block and handle the exception.
214
+ * If the function returns a promise, you can `await` on the response.
215
+ *
216
+ * @param fn - The function to run. `this` inside the function will refer to this JJET instance.
217
+ * @param args - Arguments to pass to the function.
218
+ * @returns The return value of the function.
219
+ */
220
+ run<R, Args extends any[]>(fn: (this: this, ...args: Args) => R, ...args: Args): R;
221
+ }
222
+
223
+ /**
224
+ * Wraps a DOM Node.
225
+ *
226
+ * @remarks
227
+ * This is the base class for all JJ wrappers. It provides common functionality for DOM manipulation,
228
+ * traversal, and event handling.
229
+ *
230
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | Node}
231
+ */
232
+ declare class JJN<T extends Node = Node> extends JJET<T> {
233
+ /**
234
+ * Creates a JJN instance from a Node reference.
235
+ *
236
+ * @example
237
+ * ```ts
238
+ * const node = JJN.from(document.createTextNode('hello'))
239
+ * ```
240
+ *
241
+ * @param node - The Node instance.
242
+ * @returns A new JJN instance.
243
+ */
244
+ static from(node: Node): JJN;
245
+ /**
246
+ * Checks if a value can be passed to the `wrap()` or `unwrap()` function.
247
+ *
248
+ * @remarks
249
+ * This is useful for filtering the array that is passed to `append()`, `prepend()` or `setChildren()`
250
+ *
251
+ * @param x an unknown value
252
+ * @returns true if `x` is a string, Node (or its descendents), JJN (or its descendents)
253
+ */
254
+ static isWrapable(x: unknown): x is Wrappable;
255
+ /**
256
+ * Wraps a native DOM node or string into the most specific JJ wrapper available.
257
+ *
258
+ * @remarks
259
+ * This function acts as a factory, inspecting the input type and returning the appropriate
260
+ * subclass of `JJN` (e.g., `JJHE` for `HTMLElement`, `JJT` for `Text`).
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * const bodyWrapper = JJN.wrap(document.body) // Returns JJHE
265
+ * const textWrapper = JJN.wrap('Hello') // Returns JJT wrapping a new Text node
266
+ * ```
267
+ *
268
+ * @param raw - The object to wrap. If it's already Wrapped, it'll be returned without any change. We don't double-wrap or clone it.
269
+ * @returns The most granular Wrapped subclass instance. If the input is already wrapped, it'll be returned as is without cloning.
270
+ * @throws {TypeError} If the input is not a Node, string, or JJ wrapper.
271
+ */
272
+ static wrap(raw: Wrappable): Wrapped;
273
+ /**
274
+ * Extracts the underlying native DOM node from a wrapper.
275
+ *
276
+ * @remarks
277
+ * If the input is already a native Node, it is returned as is.
278
+ * If the input is a string, a new Text node is created and returned.
279
+ *
280
+ * @example
281
+ * ```ts
282
+ * const rawElement = JJN.unwrap(myJJHE) // Returns HTMLElement
283
+ * ```
284
+ *
285
+ * @param obj - The object to unwrap.
286
+ * @returns The underlying DOM node.
287
+ * @throws {TypeError} If the input cannot be unwrapped.
288
+ */
289
+ static unwrap(obj: Wrappable): Unwrapped;
290
+ /**
291
+ * Wraps an iterable object (e.g. an array of wrapped or DOM elements).
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * const wrappedList = JJN.wrapAll(document.querySelectorAll('div'))
296
+ * ```
297
+ *
298
+ * @param iterable - The iterable to wrap.
299
+ * @returns An array of wrapped instances.
300
+ */
301
+ static wrapAll(iterable: Iterable<Wrappable>): Wrapped[];
302
+ /**
303
+ * Unwraps an iterable object (e.g. an array or HTMLCollection).
304
+ *
305
+ * @example
306
+ * ```ts
307
+ * const nodes = JJN.unwrapAll(wrappedList)
308
+ * ```
309
+ *
310
+ * @param iterable - The iterable to unwrap.
311
+ * @returns An array of native DOM nodes.
312
+ */
313
+ static unwrapAll(iterable: Iterable<Wrappable>): Unwrapped[];
314
+ /**
315
+ * Creates an instance of JJN.
316
+ *
317
+ * @param ref - The Node to wrap.
318
+ * @throws {TypeError} If `ref` is not a Node.
319
+ */
320
+ constructor(ref: T);
321
+ /**
322
+ * Clones the Node.
323
+ *
324
+ * @param deep - If true, clones the subtree.
325
+ * @returns A new wrapped instance of the clone.
326
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode | Node.cloneNode}
327
+ */
328
+ clone(deep?: boolean): Wrapped;
329
+ /**
330
+ * Creates a Text node from a string and appends it to this Node.
331
+ *
332
+ * @remarks
333
+ * This method is overridden in JJT to append to the existing text content instead.
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * el.addText('Hello ')
338
+ * el.addText('World')
339
+ * ```
340
+ *
341
+ * @param text - The text to add. If null or undefined, nothing is added.
342
+ * @returns This instance for chaining.
343
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/createTextNode | document.createTextNode}
344
+ */
345
+ addText(text?: string | null): this;
346
+ }
347
+
348
+ declare abstract class JJNx<T extends Element | Document | DocumentFragment> extends JJN<T> {
349
+ /**
350
+ * Finds the first element matching a selector within this Element.
351
+ *
352
+ * @example
353
+ * ```ts
354
+ * const span = el.find('span') // Returns null if not found
355
+ * const span = el.find('span', true) // Throws if not found
356
+ * ```
357
+ *
358
+ * @param selector - The CSS selector.
359
+ * @param required - Whether to throw an error if not found. Defaults to false.
360
+ * @returns The wrapped element, or null if not found and required is false.
361
+ * @throws {TypeError} If selector is not a string or element not found and required is true.
362
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector | Element.querySelector}
363
+ */
364
+ find(selector: string, required?: boolean): Wrapped | null;
365
+ /**
366
+ * Finds all elements matching a selector within this Element.
367
+ *
368
+ * @example
369
+ * ```ts
370
+ * const items = el.findAll('li')
371
+ * ```
372
+ *
373
+ * @param selector - The CSS selector.
374
+ * @returns An array of wrapped elements.
375
+ * @throws {TypeError} If selector is not a string.
376
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll | Element.querySelectorAll}
377
+ */
378
+ findAll(selector: string): Wrapped[];
379
+ /**
380
+ * Appends children to this Element.
381
+ *
382
+ * @example
383
+ * ```ts
384
+ * el.addChild(h('span', null, 'hello'))
385
+ * ```
386
+ *
387
+ * @remarks
388
+ * To make template codes easier, this function ignores any child that is not possible to `wrap()` (e.g. undefined, null, false).
389
+ *
390
+ * @param children - The children to append.
391
+ * @returns This instance for chaining.
392
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/append | Element.append}
393
+ */
394
+ addChild(...children: Wrappable[]): this;
395
+ /**
396
+ * Prepends children to this Element.
397
+ *
398
+ * @example
399
+ * ```ts
400
+ * el.preChild(h('span', null, 'first'))
401
+ * ```
402
+ *
403
+ * @remarks
404
+ * To make template codes easier, this function ignores any child that is not possible to `wrap()` (e.g. undefined, null, false).
405
+ *
406
+ * @param children - The children to prepend.
407
+ * @returns This instance for chaining.
408
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend | Element.prepend}
409
+ */
410
+ preChild(...children: Wrappable[]): this;
411
+ /**
412
+ * Maps an array to children and appends them.
413
+ *
414
+ * @example
415
+ * ```ts
416
+ * node.addChildMap(['a', 'b'], item => h('li', null, item))
417
+ * ```
418
+ *
419
+ * @remarks
420
+ * To make template codes easier, this function ignores any child that is not possible to `wrap()` (e.g. undefined, null, false).
421
+ *
422
+ * @param array - The source array.
423
+ * @param mapFn - The mapping function returning a Wrappable.
424
+ * @returns This instance for chaining.
425
+ */
426
+ addChildMap(array: Wrappable[], mapFn: (item: Wrappable) => Wrappable): this;
427
+ /**
428
+ * Maps an array to children and prepends them.
429
+ *
430
+ * @example
431
+ * ```ts
432
+ * node.preChildMap(['a', 'b'], item => JJHE.create('li').setText(item))
433
+ * ```
434
+ *
435
+ * @remarks
436
+ * To make template codes easier, this function ignores any child that is not possible to `wrap()` (e.g. undefined, null, false).
437
+ *
438
+ * @param array - The source array.
439
+ * @param mapFn - The mapping function.
440
+ * @returns This instance for chaining.
441
+ */
442
+ preChildMap(array: Wrappable[], mapFn: (item: Wrappable) => Wrappable): this;
443
+ /**
444
+ * Replaces the existing children of an Element with a specified new set of children.
445
+ *
446
+ * @remarks
447
+ * If no children are provided, it empties the Element.
448
+ * To make template codes easier, this function ignores any child that is not possible to `wrap()` (e.g. undefined, null, false).
449
+ *
450
+ * @example
451
+ * ```ts
452
+ * el.setChildren(h('p', null, 'New Content'))
453
+ * ```
454
+ * @param children - The children to replace with.
455
+ * @returns This instance for chaining.
456
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren | Element.replaceChildren}
457
+ */
458
+ setChildren(...children: Wrappable[]): this;
459
+ /**
460
+ * Removes all children from this Element.
461
+ *
462
+ * @example
463
+ * ```ts
464
+ * el.empty()
465
+ * ```
466
+ *
467
+ * @returns This instance for chaining.
468
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren | Element.setChildren}
469
+ */
470
+ empty(): this;
471
+ }
472
+
473
+ /**
474
+ * Wraps a DocumentFragment (which is a descendant of Node).
475
+ *
476
+ * @remarks
477
+ * DocumentFragments are lightweight versions of Document that store a segment of a document structure
478
+ * comprised of nodes just like a standard document. The key difference is that because the document fragment
479
+ * isn't part of the active document tree structure, changes made to the fragment don't affect the document,
480
+ * cause reflow, or incur any performance impact that can occur when changes are made.
481
+ *
482
+ * @example
483
+ * ```ts
484
+ * const frag = JJDF.create()
485
+ * frag.addChild(
486
+ * h('div', null, 'Item 1'),
487
+ * h('div', null, 'Item 2'),
488
+ * )
489
+ * doc.body.addChild(frag)
490
+ * ```
491
+ *
492
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment | DocumentFragment}
493
+ */
494
+ declare class JJDF<T extends DocumentFragment = DocumentFragment> extends JJNx<T> {
495
+ /**
496
+ * Creates a JJDF instance from a DocumentFragment reference.
497
+ *
498
+ * @example
499
+ * ```ts
500
+ * const frag = JJDF.from(myFrag)
501
+ * ```
502
+ *
503
+ *
504
+ * @param ref - The DocumentFragment instance.
505
+ * @returns A new JJDF instance.
506
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment | DocumentFragment}
507
+ */
508
+ static from(ref: DocumentFragment): JJDF;
509
+ /**
510
+ * Creates a new empty JJDF instance (wraps a new DocumentFragment).
511
+ *
512
+ * @example
513
+ * ```ts
514
+ * const frag = JJDF.create()
515
+ * ```
516
+ *
517
+ * @returns A new JJDF instance.
518
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/createDocumentFragment | document.createDocumentFragment}
519
+ */
520
+ static create(): JJDF<DocumentFragment>;
521
+ /**
522
+ * Creates an instance of JJDF.
523
+ *
524
+ * @param ref - The DocumentFragment instance to wrap.
525
+ * @throws {TypeError} If `ref` is not a DocumentFragment.
526
+ */
527
+ constructor(ref: T);
528
+ }
529
+
530
+ /**
531
+ * Wraps a DOM ShadowRoot (which is a descendant of DocumentFragment).
532
+ *
533
+ * @remarks
534
+ * The ShadowRoot interface of the Shadow DOM API is the root node of a DOM subtree
535
+ * that is rendered separately from a document's main DOM tree.
536
+ *
537
+ * ShadowRoot inherits DocumentFragment and therefore has access to all its methods
538
+ * most importantly `find`, and `findAll` which come handy to access and
539
+ * update its children.
540
+ *
541
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot | ShadowRoot}
542
+ */
543
+ declare class JJSR<T extends ShadowRoot = ShadowRoot> extends JJDF<T> {
544
+ /**
545
+ * Creates a JJSR instance from a ShadowRoot reference.
546
+ *
547
+ * @example
548
+ * ```ts
549
+ * const shadow = JJSR.from(element.shadowRoot)
550
+ * ```
551
+ *
552
+ * @param shadowRoot - The ShadowRoot instance.
553
+ * @returns A new JJSR instance.
554
+ */
555
+ static from(shadowRoot: ShadowRoot): JJSR<ShadowRoot>;
556
+ /**
557
+ * Creates an instance of JJSR.
558
+ *
559
+ * @param shadowRoot - The ShadowRoot to wrap.
560
+ * @throws {TypeError} If `shadowRoot` is not a ShadowRoot.
561
+ */
562
+ constructor(shadowRoot: T);
563
+ /**
564
+ * Gets the inner HTML of the ShadowRoot.
565
+ *
566
+ * @returns The inner HTML string.
567
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
568
+ */
569
+ getHTML(): string;
570
+ /**
571
+ * Sets the inner HTML of the ShadowRoot.
572
+ *
573
+ * @example
574
+ * ```ts
575
+ * shadow.setHTML('<p>Hello</p>', true)
576
+ * ```
577
+ *
578
+ * @param html - The HTML string to set, or null/undefined to clear.
579
+ * @param unsafe - explicit opt-in to set innerHTML. must be true if html is provided.
580
+ * @returns This instance for chaining.
581
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
582
+ */
583
+ setHTML(html: string | null | undefined, unsafe?: boolean): this;
584
+ /**
585
+ * Adds constructed stylesheets to the ShadowRoot.
586
+ *
587
+ * @example
588
+ * ```ts
589
+ * const sheet = new CSSStyleSheet()
590
+ * sheet.replaceSync('p { color: red; }')
591
+ * shadow.addStyleSheets(sheet)
592
+ * ```
593
+ *
594
+ * @param styleSheets - The stylesheets to add.
595
+ * @returns This instance for chaining.
596
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/adoptedStyleSheets | ShadowRoot.adoptedStyleSheets}
597
+ */
598
+ addStyleSheets(...styleSheets: CSSStyleSheet[]): this;
599
+ }
600
+
601
+ /**
602
+ * Wraps a DOM Element (which is a descendant of Node).
603
+ *
604
+ * @remarks
605
+ * This class provides a wrapper around the native `Element` interface, adding fluent API methods
606
+ * for attribute manipulation, class handling, and event binding.
607
+ *
608
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element | Element}
609
+ */
610
+ declare class JJE<T extends Element = Element> extends JJNx<T> {
611
+ /**
612
+ * Creates a JJE instance from an Element reference.
613
+ *
614
+ * @example
615
+ * ```ts
616
+ * const el = JJE.from(document.querySelector('.my-class'))
617
+ * ```
618
+ *
619
+ * @param ref - The Element instance.
620
+ * @returns A new JJE instance.
621
+ */
622
+ static from(ref: Element): JJE;
623
+ /**
624
+ * Creates an instance of JJE.
625
+ *
626
+ * @param ref - The Element to wrap.
627
+ * @throws {TypeError} If `ref` is not an Element.
628
+ */
629
+ constructor(ref: T);
630
+ /**
631
+ * Gets the value of an attribute.
632
+ *
633
+ * @param name - The name of the attribute.
634
+ * @returns The attribute value, or null if not present.
635
+ * @throws {TypeError} If `name` is not a string.
636
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute | Element.getAttribute}
637
+ */
638
+ getAttr(name: string): string | null;
639
+ /**
640
+ * Checks if an attribute exists.
641
+ *
642
+ * @param name - The name of the attribute.
643
+ * @returns `true` if the attribute exists, otherwise `false`.
644
+ * @throws {TypeError} If `name` is not a string.
645
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute | Element.hasAttribute}
646
+ */
647
+ hasAttr(name: string): boolean;
648
+ /**
649
+ * Sets one or more attributes on the Element.
650
+ *
651
+ * @example
652
+ * ```ts
653
+ * el.setAttr('id', 'my-id') // Single attribute
654
+ * el.setAttr({ id: 'my-id', class: 'my-class' }) // Multiple attributes
655
+ * el.setAttr('x', 50) // Numbers are automatically converted
656
+ * ```
657
+ *
658
+ * @throws {TypeError} If arguments are invalid types.
659
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute | Element.setAttribute}
660
+ */
661
+ setAttr(name: string, value: any): this;
662
+ setAttr(obj: Record<string, any>): this;
663
+ /**
664
+ * Removes one or more attributes from the Element.
665
+ *
666
+ * @example
667
+ * ```ts
668
+ * el.rmAttr('disabled') // Remove single
669
+ * el.rmAttr('hidden', 'aria-hidden') // Remove multiple
670
+ * ```
671
+ *
672
+ * @param names - The name(s) of the attribute(s) to remove.
673
+ * @returns This instance for chaining.
674
+ * @throws {TypeError} If any name is not a string.
675
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute | Element.removeAttribute}
676
+ */
677
+ rmAttr(...names: string[]): this;
678
+ /**
679
+ * Gets the value of an ARIA attribute.
680
+ *
681
+ * @remarks
682
+ * Automatically prepends `aria-` to the name.
683
+ *
684
+ * @example
685
+ * ```ts
686
+ * el.getAria('label') // gets 'aria-label'
687
+ * ```
688
+ *
689
+ * @param name - The ARIA attribute suffix (e.g., 'label' for 'aria-label').
690
+ * @returns The attribute value, or null if not present.
691
+ * @throws {TypeError} If `name` is not a string.
692
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes | ARIA Attributes}
693
+ */
694
+ getAria(name: string): string | null;
695
+ /**
696
+ * Checks if an ARIA attribute exists.
697
+ *
698
+ * @param name - The ARIA attribute suffix.
699
+ * @returns `true` if the attribute exists.
700
+ * @throws {TypeError} If `name` is not a string.
701
+ */
702
+ hasAria(name: string): boolean;
703
+ /**
704
+ * Sets one or more ARIA attributes on the Element.
705
+ *
706
+ * @example
707
+ * ```ts
708
+ * el.setAria('hidden', 'true') // Single: sets aria-hidden="true"
709
+ * el.setAria({ label: 'Close', hidden: 'false' }) // Multiple
710
+ * el.setAria('level', 2) // Numbers are automatically converted
711
+ * ```
712
+ *
713
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes | ARIA Attributes}
714
+ */
715
+ setAria(name: string, value: any): this;
716
+ setAria(obj: Record<string, any>): this;
717
+ /**
718
+ * Removes one or more ARIA attributes from the Element.
719
+ *
720
+ * @example
721
+ * ```ts
722
+ * el.rmAria('hidden') // Remove single
723
+ * el.rmAria('label', 'hidden') // Remove multiple
724
+ * ```
725
+ *
726
+ * @param names - The ARIA attribute suffix(es) to remove.
727
+ * @returns This instance for chaining.
728
+ * @throws {TypeError} If any name is not a string.
729
+ */
730
+ rmAria(...names: string[]): this;
731
+ /**
732
+ * Gets the class attribute.
733
+ *
734
+ * @returns The class attribute value, or null if not present.
735
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/className | Element.className}
736
+ */
737
+ getClass(): string | null;
738
+ /**
739
+ * Sets the class attribute or conditionally adds/removes classes.
740
+ *
741
+ * @remarks
742
+ * - Pass a string to replace the entire class attribute
743
+ * - Pass an object with class names as keys and boolean values to conditionally add/remove classes
744
+ * - To remove all classes, pass an empty string: `setClass('')`
745
+ *
746
+ * @example
747
+ * ```ts
748
+ * el.setClass('btn btn-primary') // Set classes as string
749
+ * el.setClass({ // Conditional classes (Vue.js style)
750
+ * 'active': true, // adds 'active'
751
+ * 'disabled': false, // removes 'disabled'
752
+ * 'highlight': isHighlighted // adds/removes based on condition
753
+ * })
754
+ * ```
755
+ *
756
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/className | Element.className}
757
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
758
+ */
759
+ setClass(className: string): this;
760
+ setClass(classMap: Record<string, boolean | unknown>): this;
761
+ /**
762
+ * Adds one or more classes to the Element.
763
+ *
764
+ * @example
765
+ * ```ts
766
+ * el.addClass('btn', 'btn-primary')
767
+ * ```
768
+ *
769
+ * @param classNames - The classes to add.
770
+ * @returns This instance for chaining.
771
+ * @throws {TypeError} If any class name is not a string.
772
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
773
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/add | DOMTokenList.add}
774
+ */
775
+ addClass(...classNames: string[]): this;
776
+ /**
777
+ * Removes one or more classes from the Element.
778
+ *
779
+ * @example
780
+ * ```ts
781
+ * el.rmClass('active') // Remove single
782
+ * el.rmClass('btn', 'btn-primary') // Remove multiple
783
+ * ```
784
+ *
785
+ * @param classNames - The classes to remove.
786
+ * @returns This instance for chaining.
787
+ * @throws {TypeError} If any class name is not a string.
788
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
789
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove | DOMTokenList.remove}
790
+ */
791
+ rmClass(...classNames: string[]): this;
792
+ /**
793
+ * Checks if the Element has a specific class.
794
+ *
795
+ * @param className - The class to check for.
796
+ * @returns `true` if the element has the class.
797
+ * @throws {TypeError} If `className` is not a string.
798
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
799
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/contains | DOMTokenList.contains}
800
+ */
801
+ hasClass(className: string): boolean;
802
+ /**
803
+ * Toggles a class on the Element.
804
+ *
805
+ * @param className - The class to toggle.
806
+ * @returns This instance for chaining.
807
+ * @throws {TypeError} If `className` is not a string.
808
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
809
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/toggle | DOMTokenList.toggle}
810
+ */
811
+ toggleClass(className: string): this;
812
+ /**
813
+ * Replaces a class with another one
814
+ *
815
+ * @remarks
816
+ * If the `oldClassName` doesn't exist, the `newClassName` isn't added
817
+ *
818
+ * @param oldClassName - The class name to remove
819
+ * @param newClassName - The class name to add
820
+ * @throws {TypeError} If either className is not a string.
821
+ */
822
+ replaceClass(oldClassName: string, newClassName: string): this;
823
+ /**
824
+ * Finds the closest ancestor (or self) that matches a CSS selector.
825
+ *
826
+ * @remarks
827
+ * Returns `null` when no matching ancestor is found.
828
+ *
829
+ * @example
830
+ * ```ts
831
+ * const button = JJE.from(document.querySelector('button'))
832
+ * const card = button.closest('.card')
833
+ * if (card) {
834
+ * card.addClass('has-action')
835
+ * }
836
+ * ```
837
+ *
838
+ * @param selector - The CSS selector to search for.
839
+ * @returns A JJE wrapping the closest match, or null when none exists.
840
+ * @throws {TypeError} If `selector` is not a string.
841
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/closest | Element.closest}
842
+ */
843
+ closest(selector: string): Wrapped | null;
844
+ /**
845
+
846
+ * Hides the Element by setting the `hidden` attribute and `aria-hidden="true"`.
847
+ *
848
+ * @returns This instance for chaining.
849
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden | hidden attribute}
850
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-hidden | aria-hidden}
851
+ */
852
+ hide(): this;
853
+ /**
854
+ * Shows the Element by removing the `hidden` and `aria-hidden` attributes.
855
+ *
856
+ * @returns This instance for chaining.
857
+ */
858
+ show(): this;
859
+ /**
860
+ * Disables the Element by setting the `disabled` attribute and `aria-disabled="true"`.
861
+ *
862
+ * @returns This instance for chaining.
863
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled | disabled attribute}
864
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled | aria-disabled}
865
+ */
866
+ disable(): this;
867
+ /**
868
+ * Enables the Element by removing the `disabled` and `aria-disabled` attributes.
869
+ *
870
+ * @returns This instance for chaining.
871
+ */
872
+ enable(): this;
873
+ /**
874
+ * Gets the inner HTML of the Element.
875
+ *
876
+ * @remarks
877
+ * This method operates on `innerHTML`. The method name is kept short for convenience.
878
+ *
879
+ * @returns The inner HTML string.
880
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
881
+ */
882
+ getHTML(): string;
883
+ /**
884
+ * Sets the inner HTML of the Element.
885
+ *
886
+ * @remarks
887
+ * This method operates on `innerHTML`. The method name is kept short for convenience.
888
+ * Pass an empty string, `null`, or `undefined` to clear the content.
889
+ *
890
+ * @param html - The HTML string to set, or null/undefined to clear.
891
+ * @param unsafe - explicit opt-in to set innerHTML. must be true if html is provided.
892
+ * @returns This instance for chaining.
893
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
894
+ */
895
+ setHTML(html: string | null | undefined, unsafe?: boolean): this;
896
+ /**
897
+ * Attaches a Shadow DOM to the Element and optionally sets its content and styles.
898
+ *
899
+ * @remarks
900
+ * We prevent FOUC by assigning the template and CSS in one go.
901
+ * **Note:** You can't attach a shadow root to every type of element. There are some that can't have a
902
+ * shadow DOM for security reasons (for example `<a>`).
903
+ *
904
+ * @param mode - The encapsulation mode ('open' or 'closed'). Defaults to 'open'.
905
+ * @param config - Optional configuration object containing `template` (HTML string) and `styles` (array of CSSStyleSheet).
906
+ * @returns This instance for chaining.
907
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow | Element.attachShadow}
908
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/adoptedStyleSheets | ShadowRoot.adoptedStyleSheets}
909
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/adoptedStyleSheets | Document.adoptedStyleSheets}
910
+ */
911
+ initShadow(mode?: ShadowRootMode, config?: ShadowConfig): this;
912
+ /**
913
+ * Gets a wrapper around the Element's Shadow Root, if it exists.
914
+ *
915
+ * @returns A JJSR instance wrapping the shadow root, or null if no shadow root exists.
916
+ */
917
+ get shadow(): JJSR<ShadowRoot> | null;
918
+ }
919
+
920
+ declare abstract class JJEx<T extends HTMLElement | SVGElement> extends JJE<T> {
921
+ /**
922
+ * Gets a data attribute from the HTMLElement.
923
+ *
924
+ * @example
925
+ * ```ts
926
+ * const value = el.getData('my-key')
927
+ * ```
928
+ *
929
+ * @param name - The data attribute name (in camelCase).
930
+ * @returns The value of the attribute, or undefined if not set.
931
+ * @throws {TypeError} If `name` is not a string.
932
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset | HTMLElement.dataset}
933
+ */
934
+ getData(name: string): string | undefined;
935
+ /**
936
+ * Checks if a data attribute exists on the HTMLElement.
937
+ *
938
+ * @example
939
+ * ```ts
940
+ * if (el.hasData('my-key')) {
941
+ * // ...
942
+ * }
943
+ * ```
944
+ *
945
+ * @param name - The data attribute name (in camelCase).
946
+ * @returns True if the attribute exists, false otherwise.
947
+ * @throws {TypeError} If `name` is not a string.
948
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset | HTMLElement.dataset}
949
+ */
950
+ hasData(name: string): boolean;
951
+ /**
952
+ * Sets one or more data attributes on the HTMLElement.
953
+ *
954
+ * @example
955
+ * ```ts
956
+ * el.setData('myKey', 'myValue') // Single
957
+ * el.setData({ myKey: 'myValue', otherKey: 'otherValue' }) // Multiple
958
+ * el.setData('count', 42) // Numbers are automatically converted
959
+ * ```
960
+ *
961
+ * @throws {TypeError} If arguments are invalid types.
962
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset | HTMLElement.dataset}
963
+ */
964
+ setData(name: string, value: any): this;
965
+ setData(obj: Record<string, any>): this;
966
+ /**
967
+ * Removes one or more data attributes from the HTMLElement.
968
+ *
969
+ * @example
970
+ * ```ts
971
+ * el.rmData('myKey') // Remove single
972
+ * el.rmData('myKey', 'otherKey') // Remove multiple
973
+ * ```
974
+ *
975
+ * @param names - The data attribute name(s) (in camelCase).
976
+ * @returns This instance for chaining.
977
+ * @throws {TypeError} If any name is not a string.
978
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset | HTMLElement.dataset}
979
+ */
980
+ rmData(...names: string[]): this;
981
+ }
982
+
983
+ /**
984
+ * Wraps a DOM HTMLElement (which is a descendant of Element).
985
+ *
986
+ * @remarks
987
+ * This class extends `JJE` to provide specific functionality for HTML elements,
988
+ * such as access to `dataset`, `innerText`, and form values.
989
+ *
990
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement | HTMLElement}
991
+ */
992
+ declare class JJHE<T extends HTMLElement = HTMLElement> extends JJEx<T> {
993
+ /**
994
+ * Creates a JJHE instance from an HTMLElement reference.
995
+ *
996
+ * @example
997
+ * ```ts
998
+ * const el = JJHE.from(document.getElementById('my-id')) // from an existing HTMLElement
999
+ * const el = JJHE.from(new document.createElement('div')) // from a new HTMLElement
1000
+ * ```
1001
+ *
1002
+ * @param ref - The HTMLElement.
1003
+ * @returns A new JJHE instance.
1004
+ */
1005
+ static from<T extends HTMLElement>(ref: T): JJHE<T>;
1006
+ /**
1007
+ * Creates a JJHE instance from a tag name.
1008
+ *
1009
+ * @example
1010
+ * ```ts
1011
+ * const div = JJHE.create('div')
1012
+ * const input = JJHE.create('input', { is: 'custom-input' })
1013
+ * ```
1014
+ *
1015
+ * @param tagName - The tag name.
1016
+ * @param options - Element creation options.
1017
+ * @returns A new JJHE instance.
1018
+ * @throws {TypeError} If `tagName` is not a string.
1019
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement | document.createElement}
1020
+ */
1021
+ static create<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): JJHE<HTMLElementTagNameMap[K]>;
1022
+ static create(tagName: string, options?: ElementCreationOptions): JJHE;
1023
+ /**
1024
+ * Creates an instance of JJHE.
1025
+ *
1026
+ * @param ref - The HTMLElement to wrap.
1027
+ * @throws {TypeError} If `ref` is not an HTMLElement.
1028
+ */
1029
+ constructor(ref: T);
1030
+ /**
1031
+ * Gets the value property of the HTMLElement (e.g. for inputs).
1032
+ *
1033
+ * @returns The value.
1034
+ * @throws {Error} If the HTMLElement does not have a value property.
1035
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/value | HTMLInputElement.value}
1036
+ */
1037
+ getValue(): unknown;
1038
+ /**
1039
+ * Sets the value property of the HTMLElement.
1040
+ *
1041
+ * @example
1042
+ * ```ts
1043
+ * input.setValue('new value')
1044
+ * input.setValue(42) // Numbers are automatically converted
1045
+ * ```
1046
+ *
1047
+ * @param value - The value to set.
1048
+ * @returns This instance for chaining.
1049
+ * @throws {Error} If the HTMLElement does not have a value property.
1050
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/value | HTMLInputElement.value}
1051
+ */
1052
+ setValue(value: any): this;
1053
+ /**
1054
+ * Focuses the HTMLElement.
1055
+ *
1056
+ * @returns This instance for chaining.
1057
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus | HTMLElement.focus}
1058
+ */
1059
+ focus(): this;
1060
+ /**
1061
+ * Clicks the HTMLElement.
1062
+ *
1063
+ * @returns This instance for chaining.
1064
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click | HTMLElement.click}
1065
+ */
1066
+ click(): this;
1067
+ /**
1068
+ * Gets the inner text of the HTMLElement.
1069
+ *
1070
+ * @remarks
1071
+ * This method operates on `innerText`. The method name is kept short for convenience.
1072
+ *
1073
+ * @returns The inner text.
1074
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText | HTMLElement.innerText}
1075
+ */
1076
+ getText(): string;
1077
+ /**
1078
+ * Sets the inner text of the HTMLElement.
1079
+ *
1080
+ * @remarks
1081
+ * This method operates on `innerText`. The method name is kept short for convenience.
1082
+ * Pass an empty string, `null`, or `undefined` to clear the content.
1083
+ * Numbers and booleans are automatically converted to strings.
1084
+ *
1085
+ * @param text - The text to set, or null/undefined to clear.
1086
+ * @returns This instance for chaining.
1087
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText | HTMLElement.innerText}
1088
+ */
1089
+ setText(text?: any): this;
1090
+ }
1091
+
1092
+ /**
1093
+ * Wraps a Document (which is a descendant of Node).
1094
+ *
1095
+ * @remarks
1096
+ * This class provides a wrapper around the native `Document` interface, inheriting
1097
+ * the fluent API capabilities of `JJN`.
1098
+ * It also supports querying (`find`) and manipulation (`addChild`, `preChild`) methods.
1099
+ *
1100
+ * To find elements by class name, use: `doc.find('.my-class')`
1101
+ *
1102
+ * To set the document title, use: `doc.ref.title = 'New Title'`
1103
+ *
1104
+ * @example
1105
+ * ```ts
1106
+ * const doc = JJD.from(document)
1107
+ * doc.on('DOMContentLoaded', () => console.log('Ready'))
1108
+ * doc.ref.title = 'My Page Title' // Set document title
1109
+ * ```
1110
+ *
1111
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document | Document}
1112
+ */
1113
+ declare class JJD<T extends Document = Document> extends JJNx<T> {
1114
+ /**
1115
+ * Creates a JJD instance from a Document reference.
1116
+ *
1117
+ * @example
1118
+ * ```ts
1119
+ * const doc = JJD.from(document)
1120
+ * ```
1121
+ *
1122
+ * @param ref - The Document instance.
1123
+ * @returns A new JJD instance.
1124
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document | Document}
1125
+ */
1126
+ static from(ref: Document): JJD;
1127
+ /**
1128
+ * Creates an instance of JJD.
1129
+ *
1130
+ * @param ref - The Document instance to wrap.
1131
+ * @throws {TypeError} If `ref` is not a Document.
1132
+ */
1133
+ constructor(ref: T);
1134
+ /**
1135
+ * Gets the `<head>` element of the document wrapped in a `JJHE` instance.
1136
+ *
1137
+ * @returns The wrapped head element.
1138
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/head | Document.head}
1139
+ */
1140
+ get head(): JJHE<HTMLHeadElement>;
1141
+ /**
1142
+ * Gets the `<body>` element of the document wrapped in a `JJHE` instance.
1143
+ *
1144
+ * @returns The wrapped body element.
1145
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/body | Document.body}
1146
+ */
1147
+ get body(): JJHE<HTMLElement>;
1148
+ }
1149
+
1150
+ /**
1151
+ * Wraps a DOM SVGElement.
1152
+ *
1153
+ * @remarks
1154
+ * This class extends `JJE` to provide specific functionality for SVG elements,
1155
+ * including namespace-aware creation and helper methods for common SVG attributes.
1156
+ *
1157
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/SVGElement | SVGElement}
1158
+ */
1159
+ declare class JJSE<T extends SVGElement = SVGElement> extends JJEx<T> {
1160
+ /**
1161
+ * Creates a JJSE instance from an SVGElement reference.
1162
+ *
1163
+ * @example
1164
+ * ```ts
1165
+ * const svg = JJSE.from(myCircle)
1166
+ * ```
1167
+ *
1168
+ * @param ref - The SVGElement.
1169
+ * @returns A new JJSE instance.
1170
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/SVGElement | SVGElement}
1171
+ */
1172
+ static from(ref: SVGElement): JJSE;
1173
+ /**
1174
+ * Creates a JJSE instance from a tag name (in the SVG namespace).
1175
+ *
1176
+ * @remarks
1177
+ * Automatically uses the correct SVG namespace URI: `http://www.w3.org/2000/svg`.
1178
+ *
1179
+ * @example
1180
+ * ```ts
1181
+ * const circle = JJSE.create('circle')
1182
+ * ```
1183
+ *
1184
+ * @param tagName - The tag name.
1185
+ * @param options - Element creation options.
1186
+ * @returns A new JJSE instance.
1187
+ * @throws {TypeError} If `tagName` is not a string.
1188
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS | document.createElementNS}
1189
+ */
1190
+ static create(tagName: string, options?: ElementCreationOptions): JJSE;
1191
+ /**
1192
+ * Creates an instance of JJSE.
1193
+ *
1194
+ * @param ref - The SVGElement to wrap.
1195
+ * @throws {TypeError} If `ref` is not an SVGElement.
1196
+ */
1197
+ constructor(ref: T);
1198
+ /**
1199
+ * Gets the text content of the SVGElement.
1200
+ *
1201
+ * @remarks
1202
+ * This method operates on `textContent`. The method name is kept short for convenience.
1203
+ *
1204
+ * @example
1205
+ * ```ts
1206
+ * const text = svg.getText()
1207
+ * ```
1208
+ *
1209
+ * @returns The text content.
1210
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
1211
+ */
1212
+ getText(): string;
1213
+ /**
1214
+ * Sets the text content of the SVGElement.
1215
+ *
1216
+ * @remarks
1217
+ * This method operates on `textContent`. The method name is kept short for convenience.
1218
+ * Pass an empty string, `null`, or `undefined` to clear the content.
1219
+ * Numbers and booleans are automatically converted to strings.
1220
+ *
1221
+ * @example
1222
+ * ```ts
1223
+ * svg.setText('Hello SVG')
1224
+ * svg.setText(null) // Clear content
1225
+ * svg.setText(42) // Numbers are converted
1226
+ * ```
1227
+ *
1228
+ * @param text - The text to set, or null/undefined to clear.
1229
+ * @returns This instance for chaining.
1230
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
1231
+ */
1232
+ setText(text?: any): this;
1233
+ /**
1234
+ * Sets the fill attribute.
1235
+ *
1236
+ * @param value - The fill color/value.
1237
+ * @returns This instance for chaining.
1238
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill | fill}
1239
+ */
1240
+ setFill(value: string): this;
1241
+ /**
1242
+ * Sets the stroke attribute.
1243
+ *
1244
+ * @param value - The stroke color/value.
1245
+ * @returns This instance for chaining.
1246
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke | stroke}
1247
+ */
1248
+ setStroke(value: string): this;
1249
+ /**
1250
+ * Sets the stroke-width attribute.
1251
+ *
1252
+ * @param value - The width.
1253
+ * @returns This instance for chaining.
1254
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-width | stroke-width}
1255
+ */
1256
+ setStrokeWidth(value: string | number): this;
1257
+ /**
1258
+ * Sets the viewBox attribute.
1259
+ *
1260
+ * @example
1261
+ * ```ts
1262
+ * svg.setViewBox(0, 0, 100, 100)
1263
+ * svg.setViewBox('0 0 100 100')
1264
+ * ```
1265
+ *
1266
+ * @param p1 - Min-x or string/array value.
1267
+ * @param p2 - Min-y.
1268
+ * @param p3 - Width.
1269
+ * @param p4 - Height.
1270
+ * @returns This instance for chaining.
1271
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox | viewBox}
1272
+ */
1273
+ setViewBox(p1: string | (string | number)[] | number, p2?: number, p3?: number, p4?: number): this;
1274
+ /**
1275
+ * Sets the width attribute.
1276
+ *
1277
+ * @param value - The width.
1278
+ * @returns This instance for chaining.
1279
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/width | width}
1280
+ */
1281
+ setWidth(value: string | number): this;
1282
+ /**
1283
+ * Sets the height attribute.
1284
+ *
1285
+ * @param value - The height.
1286
+ * @returns This instance for chaining.
1287
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/height | height}
1288
+ */
1289
+ setHeight(value: string | number): this;
1290
+ /**
1291
+ * Sets the d attribute (path data).
1292
+ *
1293
+ * @param value - The path data string or array of segments.
1294
+ * @returns This instance for chaining.
1295
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d | d}
1296
+ */
1297
+ setD(value: string | (string | number)[]): this;
1298
+ /**
1299
+ * Sets the transform attribute.
1300
+ *
1301
+ * @param value - The transform string.
1302
+ * @returns This instance for chaining.
1303
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform | transform}
1304
+ */
1305
+ setTransform(value: string): this;
1306
+ }
1307
+
1308
+ /**
1309
+ * Wraps a DOM Text Node.
1310
+ *
1311
+ * @remarks
1312
+ * The Text interface represents the textual content of Element or Attr.
1313
+ * If an element has no markup within its content, it has a single child implementing Text
1314
+ * that contains the element's text.
1315
+ *
1316
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Text | Text}
1317
+ */
1318
+ declare class JJT<T extends Text = Text> extends JJN<Text> {
1319
+ /**
1320
+ * Creates a JJT instance from a Text node.
1321
+ *
1322
+ * @example
1323
+ * ```ts
1324
+ * const textNode = document.createTextNode('foo')
1325
+ * const text = JJT.from(textNode)
1326
+ * ```
1327
+ *
1328
+ * @param text - The Text node.
1329
+ * @returns A new JJT instance.
1330
+ * @throws {TypeError} If `text` is not a Text node.
1331
+ */
1332
+ static from(text: Text): JJT;
1333
+ static fromStr(text: string): JJT;
1334
+ /**
1335
+ * Creates an instance of JJT.
1336
+ *
1337
+ * @example
1338
+ * ```ts
1339
+ * const text = new JJT('Hello World')
1340
+ * ```
1341
+ *
1342
+ * @param ref - The Text node or a string to create a Text node from.
1343
+ * @throws {TypeError} If `ref` is not a Text node or string.
1344
+ */
1345
+ constructor(ref: T);
1346
+ /**
1347
+ * Gets the text content of the Text node.
1348
+ *
1349
+ * @example
1350
+ * ```ts
1351
+ * const content = text.getText()
1352
+ * ```
1353
+ *
1354
+ * @returns The text content.
1355
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
1356
+ */
1357
+ getText(): string;
1358
+ /**
1359
+ * Sets the text content of the Text node.
1360
+ *
1361
+ * @example
1362
+ * ```ts
1363
+ * text.setText('New content')
1364
+ * ```
1365
+ *
1366
+ * @param text - The text to set. Set it to null or undefined to remove all text
1367
+ * @returns This instance for chaining.
1368
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
1369
+ */
1370
+ setText(text?: any): this;
1371
+ /**
1372
+ * Appends text to the existing content.
1373
+ *
1374
+ * @example
1375
+ * ```ts
1376
+ * text.setText('hello')
1377
+ * text.addText(' world')
1378
+ * console.log(text.getText()) // 'hello world'
1379
+ * ```
1380
+ *
1381
+ * @param text - The string to add to the existing contents. If null or undefined, nothing is added.
1382
+ * @returns This instance for chaining.
1383
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
1384
+ */
1385
+ addText(text?: any): this;
1386
+ /**
1387
+ * Clears the text content of the Text node.
1388
+ *
1389
+ * @example
1390
+ * ```ts
1391
+ * text.empty()
1392
+ * ```
1393
+ *
1394
+ * @returns This instance for chaining.
1395
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
1396
+ */
1397
+ empty(): this;
1398
+ }
1399
+
1400
+ /**
1401
+ * Represents any value that can be wrapped by the library.
1402
+ * Can be a native Node, a string (which becomes a Text node), or an existing JJ wrapper.
1403
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | Node}
1404
+ */
1405
+ type Wrappable = string | Node | JJN;
1406
+ /**
1407
+ * Union type of all possible JJ wrapper classes.
1408
+ */
1409
+ type Wrapped = JJN | JJT | JJE | JJHE | JJSE | JJD | JJDF | JJSR;
1410
+ /**
1411
+ * Union type of all native DOM nodes that correspond to JJ wrappers.
1412
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | Node}
1413
+ */
1414
+ type Unwrapped = Node | Text | Element | HTMLElement | SVGElement | Document | DocumentFragment | ShadowRoot;
1415
+ /**
1416
+ * Configuration for the component's template.
1417
+ * Can be an HTML string, a JJHE instance, a raw HTMLElement, or a
1418
+ * Promise / factory that yields one of those.
1419
+ *
1420
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
1421
+ * @example
1422
+ * ```ts
1423
+ * const t1: tmplConf = '<div>Hello</div>'
1424
+ * const t2: tmplConf = fetchHtml('./template.html') // Lazy loading
1425
+ * const t3: tmplConf = () => fetchHtml('./template.html') // Lazy loading
1426
+ * const t4: tmplConf = new JJHE(document.createElement('div')) // JJHE instance
1427
+ * const t5: tmplConf = document.createElement('div') // Raw HTMLElement
1428
+ * const t6: tmplConf = await fetchHtml('./template.html') // Eager loading
1429
+ * ```
1430
+ */
1431
+ type JJTemplateConfig = string | JJHE | JJDF | HTMLElement | DocumentFragment | Promise<string | JJHE | JJDF | HTMLElement | DocumentFragment> | (() => string | JJHE | JJDF | HTMLElement | DocumentFragment | Promise<string | JJHE | JJDF | HTMLElement | DocumentFragment>);
1432
+ /**
1433
+ * Configuration for the component's styles.
1434
+ * Can be a CSS string, a CSSStyleSheet, or a Promise / factory that yields one of those.
1435
+ *
1436
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet | CSSStyleSheet}
1437
+ * @example
1438
+ * ```ts
1439
+ * const s1: JJStyleConfig = 'p { color: red; }' // simple string
1440
+ * const s2: JJStyleConfig = cssToSheet('p { color: red; }') // Parse string to CSSStyleSheet
1441
+ * const s3: JJStyleConfig = await fetchCss('./style.css') // Eager loading
1442
+ * const s4: JJStyleConfig = fetchCss('./style.css') // Lazy loading
1443
+ * const s5: JJStyleConfig = () => fetchCss('./style.css') // Lazy loading
1444
+ * ```
1445
+ */
1446
+ type JJStyleConfig = string | CSSStyleSheet | Promise<string | CSSStyleSheet> | (() => string | CSSStyleSheet | Promise<string | CSSStyleSheet>);
1447
+ /**
1448
+ * Configuration for initializing a shadowRoot
1449
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/adoptedStyleSheets | ShadowRoot.adoptedStyleSheets}
1450
+ */
1451
+ interface ShadowConfig {
1452
+ /** Optional HTML content to set in the shadow root */
1453
+ template?: string | DocumentFragment;
1454
+ /** Optional CSSStyleSheets to adopt in the shadow root */
1455
+ styles?: CSSStyleSheet[];
1456
+ }
1457
+
1458
+ /**
1459
+ * Hyperscript helper to create JJHE instances.
1460
+ * The `h` function provides a concise way to create DOM wrappers with attributes and children,
1461
+ * similar to hyperscript helpers found in other libraries.
1462
+ *
1463
+ *
1464
+ * @remarks
1465
+ * It returns a `JJHE` instance which wraps the native HTMLElement.
1466
+ *
1467
+ * You may recognize it from other libraries:
1468
+ * - [React](https://react.dev/reference/react/createElement)
1469
+ * - [Vue](https://vuejs.org/guide/extras/render-function)
1470
+ * - [Hyperscript](https://github.com/hyperhype/hyperscript)
1471
+ * - [Angular](https://angular.dev/guide/components/programmatic-rendering)
1472
+ * - [Lit](https://lit.dev/docs/components/rendering/)
1473
+ *
1474
+ * This is not exactly a replacement, but it roughly follows the same idea.
1475
+ *
1476
+ * @example
1477
+ * ```ts
1478
+ * // Create a simple div
1479
+ * h('div', { id: 'app' }, 'Hello World')
1480
+ *
1481
+ * // Create a nested structure
1482
+ * h('ul', { class: 'list' },
1483
+ * h('li', null, 'Item 1'),
1484
+ * h('li', null, 'Item 2')
1485
+ * )
1486
+ * ```
1487
+ *
1488
+ * @param tagName - The HTML tag name.
1489
+ * @param attributes - Attributes to set on the element. Can be null or undefined.
1490
+ * @param children - Children to append (strings, nodes, or other JJHE instances).
1491
+ * @returns The created JJHE instance.
1492
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement | document.createElement}
1493
+ */
1494
+ declare function h(tagName: string, attributes?: Record<string, string> | null, ...children: Wrappable[]): JJHE;
1495
+ /**
1496
+ * Creates a `<link>` element for prefetching or preloading resources.
1497
+ *
1498
+ * @remarks
1499
+ * This function validates the input arguments and returns a wrapped `JJHE` instance.
1500
+ * It does not append the element to the document.
1501
+ *
1502
+ * @param href - The URL of the resource.
1503
+ * @param rel - The relationship of the linked resource ('prefetch' or 'preload').
1504
+ * @param as - The type of content being loaded ('fetch' for HTML, 'style' for CSS, or 'script' for JavaScript files).
1505
+ * If it's not provided or set to a falsy value, it runs heuristics to find the best match from the href parameter.
1506
+ *
1507
+ * @returns The JJHE instance representing the link element. The `<link>` is accessible via `.ref`
1508
+ * @throws {TypeError} If `href` is not a string or URL.
1509
+ * @throws {RangeError} If `rel` or `as` are not valid values.
1510
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload | Link types: preload}
1511
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/prefetch | Link types: prefetch}
1512
+ */
1513
+ declare function createLinkPre(href: string | URL, rel: 'prefetch' | 'preload', as?: 'fetch' | 'style' | 'script'): JJHE;
1514
+ /**
1515
+ * Adds a `<link>` tag to the document head for prefetching or preloading resources.
1516
+ *
1517
+ * @remarks
1518
+ * This function helps in optimizing performance by telling the browser to fetch resources
1519
+ * that might be needed later (prefetch) or are needed immediately (preload).
1520
+ *
1521
+ * Please refer to {@link createLinkPre} for more details.
1522
+ *
1523
+ * @example
1524
+ * ```ts
1525
+ * // Preload a script
1526
+ * addLinkPre('https://example.com/script.js', 'preload', 'script')
1527
+ *
1528
+ * // Prefetch a future page's CSS
1529
+ * addLinkPre('/next-page.css', 'prefetch', 'style')
1530
+ * ```
1531
+ *
1532
+ * @param args - The arguments to be passed to {@link createLinkPre}.
1533
+ * @returns The JJHE instance representing the link element.
1534
+ * @throws {TypeError} If `href` is not a string or URL.
1535
+ * @throws {RangeError} If `rel` or `as` are not valid values.
1536
+ * @see {@link createLinkPre}
1537
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload | Link types: preload}
1538
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/prefetch | Link types: prefetch}
1539
+ */
1540
+ declare function addLinkPre(...args: Parameters<typeof createLinkPre>): JJHE<HTMLElement>;
1541
+ /**
1542
+ * Fetches a file and returns its contents as string.
1543
+ *
1544
+ * @remarks
1545
+ * This is a wrapper around the native `fetch` API that handles the response status check
1546
+ * and text extraction. It sets the `Accept` header based on the provided mime type.
1547
+ *
1548
+ * @example
1549
+ * ```ts
1550
+ * const text = await fetchText('https://example.com/data.txt')
1551
+ * ```
1552
+ *
1553
+ * @param url - The file location.
1554
+ * @param mime - The HTTP Request Accept header. Defaults to 'text/*'.
1555
+ * @returns The file contents as a string.
1556
+ * @throws {TypeError} If `mime` is not a string.
1557
+ * @throws {Error} If the fetch fails or the response status is not OK (200-299).
1558
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API | Fetch API}
1559
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/text | Response.text()}
1560
+ */
1561
+ declare function fetchText(url: URL | string, mime?: string): Promise<string>;
1562
+ /**
1563
+ * Fetches the contents of a HTML file as string.
1564
+ *
1565
+ * @remarks
1566
+ * Useful for loading HTML templates dynamically.
1567
+ * You can use `import.meta.resolve('./relative-path-to.html')` to resolve paths relative to the current module.
1568
+ *
1569
+ * @example
1570
+ * ```ts
1571
+ * const template = await fetchHtml('./template.html')
1572
+ * ```
1573
+ *
1574
+ * @param url - The HTML file location.
1575
+ * @returns The file content as a string.
1576
+ * @throws {Error} If the response is not ok.
1577
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types | MIME types}
1578
+ */
1579
+ declare function fetchHtml(url: URL | string): Promise<string>;
1580
+ /**
1581
+ * Fetches the contents of a CSS file as string.
1582
+ *
1583
+ * @remarks
1584
+ * You can use `import.meta.resolve('./relative-path-to.css')` inside components to resolve relative paths.
1585
+ *
1586
+ * @example
1587
+ * ```ts
1588
+ * const css = await fetchCss('./style.css')
1589
+ * ```
1590
+ *
1591
+ * @param url - The CSS file location.
1592
+ * @returns The file content as a string.
1593
+ * @throws {Error} If the response is not ok.
1594
+ */
1595
+ declare function fetchCss(url: URL | string): Promise<string>;
1596
+ /**
1597
+ * Fetches a CSS file and constructs a CSSStyleSheet.
1598
+ *
1599
+ * @remarks
1600
+ * This is particularly useful for Constructable Stylesheets, which can be shared across Shadow DOM boundaries.
1601
+ *
1602
+ * @example
1603
+ * ```ts
1604
+ * const sheet = await fetchStyle('./component.css')
1605
+ * shadowRoot.adoptedStyleSheets = [sheet]
1606
+ * ```
1607
+ *
1608
+ * @param url - The CSS file location.
1609
+ * @returns The CSSStyleSheet object constructed from the CSS contents.
1610
+ * @throws {Error} If the fetch fails.
1611
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet | CSSStyleSheet}
1612
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/adoptedStyleSheets | adoptedStyleSheets}
1613
+ */
1614
+ declare function fetchStyle(url: URL | string): Promise<CSSStyleSheet>;
1615
+
1616
+ /**
1617
+ * A helper to bridge the attribute world (kebab-case) to the property world (camelCase).
1618
+ * It works in tandem with browser's `observedAttributes` feature which triggers
1619
+ * `attributeChangedCallback`.
1620
+ *
1621
+ * @remarks
1622
+ * Your custom component class MUST define `static observedAttributes[]` otherwise `attributeChangedCallback` won't trigger.
1623
+ * `observedAttributes` should contain kebab-based attribute names.
1624
+ *
1625
+ * @example
1626
+ * ```ts
1627
+ * class MyComponent extends HTMLElement {
1628
+ * static observedAttributes = ['user-name', 'counter']
1629
+ * userName = '' // Property MUST exist on the instance (or prototype setter)
1630
+ * #counter = 0 // You can also use private properties together with getter/setters
1631
+ *
1632
+ * attributeChangedCallback(name, oldValue, newValue) {
1633
+ * attr2prop(this, name, oldValue, newValue)
1634
+ * }
1635
+
1636
+ * get counter() {
1637
+ * return this.#counter
1638
+ * }
1639
+ *
1640
+ * set counter(value) {
1641
+ * this.#counter = value
1642
+ * this.#render() // You can call your render function to update the DOM
1643
+ * }
1644
+ *
1645
+ * #render() {
1646
+ * const shadow = JJHE.from(this).shadow
1647
+ * if (shadow) {
1648
+ * shadow.find('#user').setText(this.userName)
1649
+ shadow.find('#counter').setText(this.counter)
1650
+ * }
1651
+ * }
1652
+ * }
1653
+ * ```
1654
+ *
1655
+ * @param instance - A reference to the common component instance
1656
+ * @param name - kebab-case and in lower case exactly as it appears in `observedAttributes`.
1657
+ * @param oldValue - The previous value of the attribute.
1658
+ * @param newValue - The new value of the attribute.
1659
+ * @returns `true` if it tried to set the attribute; otherwise `false`.
1660
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes | Responding to attribute changes}
1661
+ */
1662
+ declare function attr2prop(instance: HTMLElement, name: string, oldValue: any, newValue: any): boolean;
1663
+ /**
1664
+ * Registers the custom element with the browser and waits till it is defined.
1665
+ *
1666
+ * @example
1667
+ * ```ts
1668
+ * class MyComponent extends HTMLElement {}
1669
+ * await registerComponent('my-component', MyComponent)
1670
+ * ```
1671
+ * Another convention is to have a `static async register()` function in the Custom Component.
1672
+ * ```ts
1673
+ * export class MyComponent extends HTMLElement {
1674
+ * static async register() {
1675
+ * return registerComponent('my-component', MyComponent)
1676
+ * }
1677
+ * }
1678
+ * ```
1679
+ * That way, you can import multiple components and do a `Promise.all()` on all their `.register()`s.
1680
+ * ```ts
1681
+ * import { MyComponent, YourComponent, TheirComponent } ...
1682
+ * await Promise.all([
1683
+ * MyComponent.register(),
1684
+ * YourComponent.register(),
1685
+ * TheirComponent.register(),
1686
+ * ])
1687
+ *
1688
+ * @throws {TypeError} If name is not a string or constructor is not a function
1689
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define | customElements.define}
1690
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/whenDefined | customElements.whenDefined}
1691
+ */
1692
+ declare function registerComponent(name: string, constructor: CustomElementConstructor, options?: ElementDefinitionOptions): Promise<void>;
1693
+
1694
+ /**
1695
+ * Manages the resolution of Shadow DOM configuration (template and styles).
1696
+ *
1697
+ * Allows building up the configuration and resolving it lazily.
1698
+ *
1699
+ * @example
1700
+ * ```ts
1701
+ * const sm = ShadowMaster.create()
1702
+ * .setTemplate('<div>Hello World</div>')
1703
+ * .addStyles('div { color: red; }')
1704
+ *
1705
+ * class MyComponent extends HTMLElement {
1706
+ * async connectedCallback() {
1707
+ * // Resolves the config once and caches it
1708
+ * const shadowConfig = await sm.getResolved()
1709
+ * // ... init shadow root with shadowConfig
1710
+ * }
1711
+ * }
1712
+ * ```
1713
+ */
1714
+ declare class ShadowMaster {
1715
+ #private;
1716
+ /**
1717
+ * Creates a new instance of ShadowMaster.
1718
+ *
1719
+ * @returns A new ShadowMaster instance.
1720
+ */
1721
+ static create(): ShadowMaster;
1722
+ constructor();
1723
+ /**
1724
+ * Sets the template configuration.
1725
+ *
1726
+ * @param templateConfig - The template configuration.
1727
+ * @returns The instance for chaining.
1728
+ *
1729
+ * @example
1730
+ * ```ts
1731
+ * // Accepts string, promise, or fetchHtml result
1732
+ * sm.setTemplate(fetchHtml('./template.html'))
1733
+ * ```
1734
+ */
1735
+ setTemplate(templateConfig?: JJTemplateConfig): this;
1736
+ /**
1737
+ * Adds one or more style configurations.
1738
+ *
1739
+ * @param stylesConfig - Variable number of style configurations.
1740
+ * @returns The instance for chaining.
1741
+ *
1742
+ * @example
1743
+ * ```ts
1744
+ * sm.addStyles(
1745
+ * 'p { color: red; }',
1746
+ * fetchCss('./styles.css'),
1747
+ * () => fetchCss('../lazy-loaded-styles.css'),
1748
+ * )
1749
+ * ```
1750
+ */
1751
+ addStyles(...stylesConfig: JJStyleConfig[]): this;
1752
+ /**
1753
+ * Resolves the configuration to something that can be fed to `JJHE.initShadow()` function
1754
+ *
1755
+ * The result is cached, so subsequent calls return the same promise.
1756
+ * Note: Any changes made to the ShadowMaster instance (via setTemplate/addStyles)
1757
+ * after the first call to getResolved() will be ignored.
1758
+ *
1759
+ * @returns A promise resolving to the ShadowConfig.
1760
+ */
1761
+ getResolved(): Promise<ShadowConfig>;
1762
+ }
1763
+
1764
+ /**
1765
+ * A wrapped document for convenience.
1766
+ * It can be used instead of document
1767
+ *
1768
+ * @example
1769
+ * ```ts
1770
+ * import { doc } from 'jj'
1771
+ * const el = doc.find('#my-element') // A JJHE instance
1772
+ * const body = doc.body // A JJHE instance
1773
+ * doc.addChild(JJHE.create('script').setAttr('src', 'my-code.js'))
1774
+ * doc.head.addChild(JJHE.create('link').setAttr({
1775
+ * rel: 'stylesheet',
1776
+ * href: 'code.css'
1777
+ * }))
1778
+ * ```
1779
+ */
1780
+ declare const doc: JJD<Document>;
1781
+
1782
+ export { JJD, JJDF, JJE, JJET, JJHE, JJN, JJSE, JJSR, type JJStyleConfig, JJT, type JJTemplateConfig, type ShadowConfig, ShadowMaster, type Unwrapped, type Wrappable, type Wrapped, addLinkPre, attr2prop, createLinkPre, cssToStyle, doc, fetchCss, fetchHtml, fetchStyle, fetchText, fileExt, h, keb2cam, keb2pas, nextAnimationFrame, pas2keb, registerComponent, sleep };