jj 2.2.0 → 2.4.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 (93) hide show
  1. package/lib/JJD.d.ts +76 -0
  2. package/lib/JJD.js +91 -0
  3. package/lib/JJD.js.map +1 -0
  4. package/lib/JJDF.d.ts +60 -0
  5. package/lib/JJDF.js +68 -0
  6. package/lib/JJDF.js.map +1 -0
  7. package/lib/JJE.d.ts +313 -0
  8. package/lib/JJE.js +412 -0
  9. package/lib/JJE.js.map +1 -0
  10. package/lib/JJHE.d.ts +120 -0
  11. package/lib/JJHE.js +164 -0
  12. package/lib/JJHE.js.map +1 -0
  13. package/lib/JJN.d.ts +234 -0
  14. package/lib/JJN.js +323 -0
  15. package/lib/JJN.js.map +1 -0
  16. package/lib/JJSE.d.ts +148 -0
  17. package/lib/JJSE.js +190 -0
  18. package/lib/JJSE.js.map +1 -0
  19. package/lib/JJSR.d.ts +67 -0
  20. package/lib/JJSR.js +85 -0
  21. package/lib/JJSR.js.map +1 -0
  22. package/lib/JJT.d.ts +79 -0
  23. package/lib/JJT.js +108 -0
  24. package/lib/JJT.js.map +1 -0
  25. package/lib/bundle.d.ts +1 -0
  26. package/lib/bundle.js +1533 -442
  27. package/lib/bundle.js.map +3 -3
  28. package/lib/bundle.min.d.ts +1 -0
  29. package/lib/bundle.min.js +2 -2
  30. package/lib/case.d.ts +57 -0
  31. package/lib/case.js +61 -3
  32. package/lib/case.js.map +1 -1
  33. package/lib/components.d.ts +147 -0
  34. package/lib/components.js +286 -0
  35. package/lib/components.js.map +1 -0
  36. package/lib/helpers.d.ts +158 -0
  37. package/lib/helpers.js +231 -0
  38. package/lib/helpers.js.map +1 -0
  39. package/lib/index.d.ts +13 -12
  40. package/lib/index.js +13 -12
  41. package/lib/index.js.map +1 -1
  42. package/lib/mixin-types.d.ts +143 -0
  43. package/lib/mixin-types.js +2 -0
  44. package/lib/mixin-types.js.map +1 -0
  45. package/lib/mixins.d.ts +77 -0
  46. package/lib/mixins.js +336 -0
  47. package/lib/mixins.js.map +1 -0
  48. package/lib/types.d.ts +77 -0
  49. package/lib/types.js +2 -0
  50. package/lib/types.js.map +1 -0
  51. package/lib/util.d.ts +90 -2
  52. package/lib/util.js +106 -2
  53. package/lib/util.js.map +1 -1
  54. package/lib/util.test.d.ts +1 -0
  55. package/lib/util.test.js +46 -0
  56. package/lib/util.test.js.map +1 -0
  57. package/package.json +16 -7
  58. package/lib/WC.d.ts +0 -41
  59. package/lib/WC.js +0 -117
  60. package/lib/WC.js.map +0 -1
  61. package/lib/WD.d.ts +0 -8
  62. package/lib/WD.js +0 -17
  63. package/lib/WD.js.map +0 -1
  64. package/lib/WDF.d.ts +0 -9
  65. package/lib/WDF.js +0 -20
  66. package/lib/WDF.js.map +0 -1
  67. package/lib/WE.d.ts +0 -43
  68. package/lib/WE.js +0 -131
  69. package/lib/WE.js.map +0 -1
  70. package/lib/WHE.d.ts +0 -21
  71. package/lib/WHE.js +0 -75
  72. package/lib/WHE.js.map +0 -1
  73. package/lib/WN-mixin.d.ts +0 -9
  74. package/lib/WN-mixin.js +0 -59
  75. package/lib/WN-mixin.js.map +0 -1
  76. package/lib/WN.d.ts +0 -47
  77. package/lib/WN.js +0 -194
  78. package/lib/WN.js.map +0 -1
  79. package/lib/WSE.d.ts +0 -25
  80. package/lib/WSE.js +0 -84
  81. package/lib/WSE.js.map +0 -1
  82. package/lib/WSH.d.ts +0 -11
  83. package/lib/WSH.js +0 -29
  84. package/lib/WSH.js.map +0 -1
  85. package/lib/WT.d.ts +0 -12
  86. package/lib/WT.js +0 -39
  87. package/lib/WT.js.map +0 -1
  88. package/lib/fetch.d.ts +0 -31
  89. package/lib/fetch.js +0 -69
  90. package/lib/fetch.js.map +0 -1
  91. package/lib/h.d.ts +0 -3
  92. package/lib/h.js +0 -9
  93. package/lib/h.js.map +0 -1
package/lib/JJE.js ADDED
@@ -0,0 +1,412 @@
1
+ import { isA, isArr, isObj, isStr } from 'jty';
2
+ import { JJN } from './JJN.js';
3
+ import { JJSR } from './JJSR.js';
4
+ /**
5
+ * Wraps a DOM Element (which is a descendant of Node).
6
+ *
7
+ * @remarks
8
+ * This class provides a wrapper around the native `Element` interface, adding fluent API methods
9
+ * for attribute manipulation, class handling, and event binding.
10
+ *
11
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element | Element}
12
+ */
13
+ export class JJE extends JJN {
14
+ /**
15
+ * Creates a JJE instance from an Element reference.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const el = JJE.from(document.querySelector('.my-class'))
20
+ * ```
21
+ *
22
+ * @param ref - The Element instance.
23
+ * @returns A new JJE instance.
24
+ */
25
+ static from(ref) {
26
+ return new JJE(ref);
27
+ }
28
+ /**
29
+ * Creates an instance of JJE.
30
+ *
31
+ * @param ref - The Element to wrap.
32
+ * @throws {TypeError} If `ref` is not an Element.
33
+ */
34
+ constructor(ref) {
35
+ if (!isA(ref, Element)) {
36
+ throw new TypeError(`Expected an Element. Got: ${ref} (${typeof ref})`);
37
+ }
38
+ super(ref);
39
+ }
40
+ /**
41
+ * Finds an element by ID within this element's context
42
+ *
43
+ * @remarks
44
+ * This method uses `Element.querySelector()` under the hood.
45
+ *
46
+ * @param id - The ID to search for.
47
+ * @param throwIfNotFound - Whether to throw an error if not found. Defaults to true.
48
+ * @returns The wrapped element, or null if not found and throwIfNotFound is false.
49
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector | Element.querySelector}
50
+ */
51
+ byId(id, throwIfNotFound = true) {
52
+ if (!isStr(id)) {
53
+ throw new TypeError(`Expected a string id. Got ${id} (${typeof id})`);
54
+ }
55
+ return this.query(`#${id}`, throwIfNotFound);
56
+ }
57
+ /**
58
+ * Gets the value of an attribute.
59
+ *
60
+ * @param name - The name of the attribute.
61
+ * @returns The attribute value, or null if not present.
62
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute | Element.getAttribute}
63
+ */
64
+ getAttr(name) {
65
+ return this.ref.getAttribute(name);
66
+ }
67
+ /**
68
+ * Checks if an attribute exists.
69
+ *
70
+ * @param name - The name of the attribute.
71
+ * @returns `true` if the attribute exists, otherwise `false`.
72
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute | Element.hasAttribute}
73
+ */
74
+ hasAttr(name) {
75
+ return this.ref.hasAttribute(name);
76
+ }
77
+ /**
78
+ * Sets the value of an attribute.
79
+ *
80
+ * @param name - The name of the attribute.
81
+ * @param value - The value to set.
82
+ * @returns This instance for chaining.
83
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute | Element.setAttribute}
84
+ */
85
+ setAttr(name, value) {
86
+ this.ref.setAttribute(name, value);
87
+ return this;
88
+ }
89
+ /**
90
+ * Sets multiple attributes at once.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * el.setAttrs({ id: 'my-id', class: 'my-class' })
95
+ * ```
96
+ *
97
+ * @param obj - An object where keys are attribute names and values are attribute values.
98
+ * @returns This instance for chaining.
99
+ * @throws {TypeError} If `obj` is not an object.
100
+ */
101
+ setAttrs(obj) {
102
+ if (!isObj(obj)) {
103
+ throw new TypeError(`Expected an object. Got: ${obj} (${typeof obj})`);
104
+ }
105
+ for (const [name, value] of Object.entries(obj)) {
106
+ this.setAttr(name, value);
107
+ }
108
+ return this;
109
+ }
110
+ /**
111
+ * Removes an attribute.
112
+ *
113
+ * @param name - The name of the attribute to remove.
114
+ * @returns This instance for chaining.
115
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute | Element.removeAttribute}
116
+ */
117
+ rmAttr(name) {
118
+ return this.rmAttrs(name);
119
+ }
120
+ /**
121
+ * Removes multiple attributes.
122
+ *
123
+ * @param names - The names of the attributes to remove.
124
+ * @returns This instance for chaining.
125
+ */
126
+ rmAttrs(...names) {
127
+ for (const name of names) {
128
+ this.ref.removeAttribute(name);
129
+ }
130
+ return this;
131
+ }
132
+ /**
133
+ * Gets the value of an ARIA attribute.
134
+ *
135
+ * @remarks
136
+ * Automatically prepends `aria-` to the name.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * el.getAria('label') // gets 'aria-label'
141
+ * ```
142
+ *
143
+ * @param name - The ARIA attribute suffix (e.g., 'label' for 'aria-label').
144
+ * @returns The attribute value, or null if not present.
145
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes | ARIA Attributes}
146
+ */
147
+ getAria(name) {
148
+ return this.ref.getAttribute(`aria-${name}`);
149
+ }
150
+ /**
151
+ * Checks if an ARIA attribute exists.
152
+ *
153
+ * @param name - The ARIA attribute suffix.
154
+ * @returns `true` if the attribute exists.
155
+ */
156
+ hasAria(name) {
157
+ return this.ref.hasAttribute(`aria-${name}`);
158
+ }
159
+ /**
160
+ * Sets an ARIA attribute.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * el.setAria('hidden', 'true') // sets aria-hidden="true"
165
+ * ```
166
+ *
167
+ * @param name - The ARIA attribute suffix.
168
+ * @param value - The value to set.
169
+ * @returns This instance for chaining.
170
+ */
171
+ setAria(name, value) {
172
+ this.ref.setAttribute(`aria-${name}`, value);
173
+ return this;
174
+ }
175
+ /**
176
+ * Removes an ARIA attribute.
177
+ *
178
+ * @param name - The ARIA attribute suffix.
179
+ * @returns This instance for chaining.
180
+ */
181
+ rmAria(name) {
182
+ this.ref.removeAttribute(`aria-${name}`);
183
+ return this;
184
+ }
185
+ /**
186
+ * Gets the class attribute.
187
+ *
188
+ * @returns The class attribute value, or null if not present.
189
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/className | Element.className}
190
+ */
191
+ getClass() {
192
+ return this.getAttr('class');
193
+ }
194
+ /**
195
+ * Sets the class attribute.
196
+ *
197
+ * @param className - The class string to set.
198
+ * @returns This instance for chaining.
199
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/className | Element.className}
200
+ */
201
+ setClass(className) {
202
+ return this.setAttr('class', className);
203
+ }
204
+ /**
205
+ * Removes the `class` attribute of the element.
206
+ *
207
+ * @remarks
208
+ * If you want to remove a few specific class instead of all, use `rmClasses`
209
+ *
210
+ * @returns This instance for chaining.
211
+ */
212
+ rmClass() {
213
+ return this.rmAttr('class');
214
+ }
215
+ /**
216
+ * Adds one or more classes to the element.
217
+ *
218
+ * @param classNames - The classes to add.
219
+ * @returns This instance for chaining.
220
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
221
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/add | DOMTokenList.add}
222
+ */
223
+ addClass(...classNames) {
224
+ this.ref.classList.add(...classNames);
225
+ return this;
226
+ }
227
+ /**
228
+ * Removes one or more classes from the element.
229
+ *
230
+ * @param classNames - The classes to remove.
231
+ * @returns This instance for chaining.
232
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
233
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove | DOMTokenList.remove}
234
+ */
235
+ rmClasses(...classNames) {
236
+ this.ref.classList.remove(...classNames);
237
+ return this;
238
+ }
239
+ /**
240
+ * Checks if the element has a specific class.
241
+ *
242
+ * @param className - The class to check for.
243
+ * @returns `true` if the element has the class.
244
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
245
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/contains | DOMTokenList.contains}
246
+ */
247
+ hasClass(className) {
248
+ return this.ref.classList.contains(className);
249
+ }
250
+ /**
251
+ * Toggles a class on the element.
252
+ *
253
+ * @param className - The class to toggle.
254
+ * @returns This instance for chaining.
255
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
256
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/toggle | DOMTokenList.toggle}
257
+ */
258
+ toggleClass(className) {
259
+ this.ref.classList.toggle(className);
260
+ return this;
261
+ }
262
+ /**
263
+ * Replaces a class with another one
264
+ *
265
+ * @remarks
266
+ * If the `oldClassName` doesn't exist, the `newClassName` isn't added
267
+ *
268
+ * @param oldClassName - The class name to remove
269
+ * @param newClassName - The class name to add
270
+ */
271
+ replaceClass(oldClassName, newClassName) {
272
+ this.ref.classList.replace(oldClassName, newClassName);
273
+ return this;
274
+ }
275
+ /**
276
+ * Adds a click event listener.
277
+ *
278
+ * @param handler - The event handler.
279
+ * @returns This instance for chaining.
280
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener | EventTarget.addEventListener}
281
+ */
282
+ onClick(handler) {
283
+ return this.on('click', handler);
284
+ }
285
+ /**
286
+ * Hides the element by setting the `hidden` attribute and `aria-hidden="true"`.
287
+ *
288
+ * @returns This instance for chaining.
289
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden | hidden attribute}
290
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-hidden | aria-hidden}
291
+ */
292
+ hide() {
293
+ return this.setAttr('hidden', '').setAttr('aria-hidden', 'true');
294
+ }
295
+ /**
296
+ * Shows the element by removing the `hidden` and `aria-hidden` attributes.
297
+ *
298
+ * @returns This instance for chaining.
299
+ */
300
+ show() {
301
+ return this.rmAttrs('hidden', 'aria-hidden');
302
+ }
303
+ /**
304
+ * Disables the element by setting the `disabled` attribute and `aria-disabled="true"`.
305
+ *
306
+ * @returns This instance for chaining.
307
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled | disabled attribute}
308
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled | aria-disabled}
309
+ */
310
+ disable() {
311
+ return this.setAttr('disabled', '').setAttr('aria-disabled', 'true');
312
+ }
313
+ /**
314
+ * Enables the element by removing the `disabled` and `aria-disabled` attributes.
315
+ *
316
+ * @returns This instance for chaining.
317
+ */
318
+ enable() {
319
+ return this.rmAttrs('disabled', 'aria-disabled');
320
+ }
321
+ /**
322
+ * Gets the title attribute.
323
+ *
324
+ * @returns The title, or null if not set.
325
+ */
326
+ getTitle() {
327
+ return this.getAttr('title');
328
+ }
329
+ /**
330
+ * Sets the title attribute.
331
+ *
332
+ * @param title - The title to set.
333
+ * @returns This instance for chaining.
334
+ */
335
+ setTitle(title) {
336
+ return this.setAttr('title', title);
337
+ }
338
+ /**
339
+ * Sets the id attribute.
340
+ *
341
+ * @param id - The id to set.
342
+ * @returns This instance for chaining.
343
+ */
344
+ setId(id) {
345
+ return this.setAttr('id', id);
346
+ }
347
+ /**
348
+ * Gets the id attribute.
349
+ *
350
+ * @returns The id, or null if not set.
351
+ */
352
+ getId() {
353
+ return this.getAttr('id');
354
+ }
355
+ /**
356
+ * Gets the inner HTML of the element.
357
+ *
358
+ * @returns The inner HTML string.
359
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
360
+ */
361
+ getHTML() {
362
+ return this.ref.innerHTML;
363
+ }
364
+ /**
365
+ * Sets the inner HTML of the element.
366
+ *
367
+ * @param html - The HTML string to set.
368
+ * @returns This instance for chaining.
369
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
370
+ */
371
+ setHTML(html) {
372
+ this.ref.innerHTML = html;
373
+ return this;
374
+ }
375
+ /**
376
+ * Attaches a Shadow DOM to the element and optionally sets its content and styles.
377
+ *
378
+ * @remarks
379
+ * We prevent FOUC by assigning the template and CSS in one go.
380
+ * **Note:** You can't attach a shadow root to every type of element. There are some that can't have a
381
+ * shadow DOM for security reasons (for example `<a>`).
382
+ *
383
+ * @param mode - The encapsulation mode ('open' or 'closed'). Defaults to 'open'.
384
+ * @param config - Optional configuration object containing `template` (HTML string) and `styles` (array of CSSStyleSheet).
385
+ * @returns This instance for chaining.
386
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow | Element.attachShadow}
387
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/adoptedStyleSheets | ShadowRoot.adoptedStyleSheets}
388
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/adoptedStyleSheets | Document.adoptedStyleSheets}
389
+ */
390
+ initShadow(mode = 'open', config) {
391
+ const shadowRoot = this.ref.shadowRoot ?? this.ref.attachShadow({ mode });
392
+ if (isObj(config)) {
393
+ const { template, styles } = config;
394
+ if (template) {
395
+ shadowRoot.innerHTML = template;
396
+ }
397
+ if (isArr(styles) && styles.length) {
398
+ shadowRoot.adoptedStyleSheets.push(...styles);
399
+ }
400
+ }
401
+ return this;
402
+ }
403
+ /**
404
+ * Gets a wrapper around the element's Shadow Root, if it exists.
405
+ *
406
+ * @returns A JJSR instance wrapping the shadow root, or null if no shadow root exists.
407
+ */
408
+ get shadow() {
409
+ return this.ref.shadowRoot ? new JJSR(this.ref.shadowRoot) : null;
410
+ }
411
+ }
412
+ //# sourceMappingURL=JJE.js.map
package/lib/JJE.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JJE.js","sourceRoot":"","sources":["../src/JJE.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAMhC;;;;;;;;GAQG;AACH,MAAM,OAAO,GAAiC,SAAQ,GAAM;IACxD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,CAAC,GAAY;QACpB,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;IACvB,CAAC;IAED;;;;;OAKG;IACH,YAAY,GAAM;QACd,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,SAAS,CAAC,6BAA6B,GAAG,KAAK,OAAO,GAAG,G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AC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAA;YACjD,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAA;IACf,CAAC;IAED;;;;OAIG;IACH,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACrE,CAAC;CACJ"}
package/lib/JJHE.d.ts ADDED
@@ -0,0 +1,120 @@
1
+ import { JJE } from './JJE.js';
2
+ import { IElementData, IQuery } from './mixin-types.js';
3
+ import { Wrapped } from './types.js';
4
+ /**
5
+ * Wraps a DOM HTMLElement (which is a descendant of Element).
6
+ *
7
+ * @remarks
8
+ * This class extends `JJE` to provide specific functionality for HTML elements,
9
+ * such as access to `dataset`, `innerText`, and form values.
10
+ *
11
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement | HTMLElement}
12
+ */
13
+ export declare class JJHE<T extends HTMLElement = HTMLElement> extends JJE<T> {
14
+ /**
15
+ * Creates a JJHE instance from an HTMLElement reference.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const el = JJHE.from(document.getElementById('my-id'))
20
+ * ```
21
+ *
22
+ * @param ref - The HTMLElement.
23
+ * @returns A new JJHE instance.
24
+ */
25
+ static from(ref: HTMLElement): JJHE;
26
+ /**
27
+ * Creates a JJHE instance from a tag name.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const div = JJHE.fromTag('div')
32
+ * const input = JJHE.fromTag('input', { is: 'custom-input' })
33
+ * ```
34
+ *
35
+ * @param tagName - The tag name.
36
+ * @param options - Element creation options.
37
+ * @returns A new JJHE instance.
38
+ * @throws {TypeError} If `tagName` is not a string.
39
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement | document.createElement}
40
+ */
41
+ static fromTag(tagName: string, options?: ElementCreationOptions): JJHE;
42
+ /**
43
+ * Creates an instance of JJHE.
44
+ *
45
+ * @param ref - The HTMLElement to wrap.
46
+ * @throws {TypeError} If `ref` is not an HTMLElement.
47
+ */
48
+ constructor(ref: T);
49
+ /**
50
+ * Gets the value property of the element (e.g. for inputs).
51
+ *
52
+ * @returns The value.
53
+ * @throws {Error} If the element does not have a value property.
54
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/value | HTMLInputElement.value}
55
+ */
56
+ getValue(): unknown;
57
+ /**
58
+ * Sets the value property of the element.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * input.setValue('new value')
63
+ * ```
64
+ *
65
+ * @param value - The value to set.
66
+ * @returns This instance for chaining.
67
+ * @throws {Error} If the element does not have a value property.
68
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/value | HTMLInputElement.value}
69
+ */
70
+ setValue(value: string): this;
71
+ /**
72
+ * Focuses the element.
73
+ *
74
+ * @returns This instance for chaining.
75
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus | HTMLElement.focus}
76
+ */
77
+ focus(): this;
78
+ /**
79
+ * Clicks the element.
80
+ *
81
+ * @returns This instance for chaining.
82
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click | HTMLElement.click}
83
+ */
84
+ click(): this;
85
+ /**
86
+ * Gets the inner text of the element.
87
+ *
88
+ * @returns The inner text.
89
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText | HTMLElement.innerText}
90
+ */
91
+ getText(): string;
92
+ /**
93
+ * Sets the inner text of the element.
94
+ *
95
+ * @param text - The text to set.
96
+ * @returns This instance for chaining.
97
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText | HTMLElement.innerText}
98
+ */
99
+ setText(text: string): this;
100
+ /**
101
+ * Finds the first element matching a selector within this element's context.
102
+ *
103
+ * @param selector - The CSS selector.
104
+ * @param throwIfNotFound - Whether to throw an error if not found. Defaults to true.
105
+ * @returns The wrapped element, or null.
106
+ * @throws {TypeError} If the element is not found and `throwIfNotFound` is true.
107
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector | Element.querySelector}
108
+ */
109
+ query(selector: string, throwIfNotFound?: boolean): Wrapped | null;
110
+ /**
111
+ * Finds all elements matching a selector within this element's context.
112
+ *
113
+ * @param selector - The CSS selector.
114
+ * @returns An array of wrapped elements.
115
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll | Element.querySelectorAll}
116
+ */
117
+ queryAll(selector: string): Wrapped[];
118
+ }
119
+ export declare interface JJHE<T extends HTMLElement> extends IQuery, IElementData {
120
+ }