jj 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +18 -57
  2. package/lib/JJD.d.ts +36 -25
  3. package/lib/JJD.js +56 -28
  4. package/lib/JJD.js.map +1 -1
  5. package/lib/JJDF.d.ts +19 -5
  6. package/lib/JJDF.js +32 -2
  7. package/lib/JJDF.js.map +1 -1
  8. package/lib/JJE.d.ts +96 -110
  9. package/lib/JJE.js +143 -154
  10. package/lib/JJE.js.map +1 -1
  11. package/lib/JJET.d.ts +79 -0
  12. package/lib/JJET.js +114 -0
  13. package/lib/JJET.js.map +1 -0
  14. package/lib/JJEx.d.ts +63 -0
  15. package/lib/JJEx.js +83 -0
  16. package/lib/JJEx.js.map +1 -0
  17. package/lib/JJHE.d.ts +26 -37
  18. package/lib/JJHE.js +34 -62
  19. package/lib/JJHE.js.map +1 -1
  20. package/lib/JJN-wrap.js +46 -0
  21. package/lib/JJN-wrap.js.map +1 -0
  22. package/lib/JJN.d.ts +10 -118
  23. package/lib/JJN.js +19 -176
  24. package/lib/JJN.js.map +1 -1
  25. package/lib/JJNx.d.ts +126 -0
  26. package/lib/JJNx.js +157 -0
  27. package/lib/JJNx.js.map +1 -0
  28. package/lib/JJSE.d.ts +32 -10
  29. package/lib/JJSE.js +36 -9
  30. package/lib/JJSE.js.map +1 -1
  31. package/lib/JJSR.d.ts +8 -4
  32. package/lib/JJSR.js +10 -5
  33. package/lib/JJSR.js.map +1 -1
  34. package/lib/JJT.d.ts +26 -13
  35. package/lib/JJT.js +38 -30
  36. package/lib/JJT.js.map +1 -1
  37. package/lib/bundle.js +755 -741
  38. package/lib/bundle.js.map +3 -3
  39. package/lib/bundle.min.js +1 -2
  40. package/lib/components.js +5 -4
  41. package/lib/components.js.map +1 -1
  42. package/lib/helpers.d.ts +3 -2
  43. package/lib/helpers.js +11 -9
  44. package/lib/helpers.js.map +1 -1
  45. package/lib/index.d.ts +20 -2
  46. package/lib/index.js +21 -2
  47. package/lib/index.js.map +1 -1
  48. package/lib/internal.d.ts +30 -0
  49. package/lib/internal.js +35 -0
  50. package/lib/internal.js.map +1 -0
  51. package/lib/types.d.ts +18 -30
  52. package/lib/util.d.ts +0 -28
  53. package/lib/util.js +0 -32
  54. package/lib/util.js.map +1 -1
  55. package/llms.txt +214 -0
  56. package/package.json +11 -3
  57. package/lib/case.test.js +0 -79
  58. package/lib/case.test.js.map +0 -1
  59. package/lib/mixin-types.d.ts +0 -143
  60. package/lib/mixin-types.js +0 -2
  61. package/lib/mixin-types.js.map +0 -1
  62. package/lib/mixins.d.ts +0 -77
  63. package/lib/mixins.js +0 -336
  64. package/lib/mixins.js.map +0 -1
  65. package/lib/util.test.d.ts +0 -1
  66. package/lib/util.test.js +0 -46
  67. package/lib/util.test.js.map +0 -1
  68. /package/lib/{case.test.d.ts → JJN-wrap.d.ts} +0 -0
package/lib/JJE.d.ts CHANGED
@@ -1,9 +1,6 @@
1
- import { JJN } from './JJN.js';
2
1
  import { JJSR } from './JJSR.js';
3
- import { IAppendPrepend, IById, IQuery } from './mixin-types.js';
4
- import { ShadowConfig, Wrapped } from './types.js';
5
- export interface JJE<T extends Element> extends IQuery, IAppendPrepend {
6
- }
2
+ import { ShadowConfig } from './types.js';
3
+ import { JJNx } from './JJNx.js';
7
4
  /**
8
5
  * Wraps a DOM Element (which is a descendant of Node).
9
6
  *
@@ -13,7 +10,7 @@ export interface JJE<T extends Element> extends IQuery, IAppendPrepend {
13
10
  *
14
11
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element | Element}
15
12
  */
16
- export declare class JJE<T extends Element = Element> extends JJN<T> implements IById {
13
+ export declare class JJE<T extends Element = Element> extends JJNx<T> {
17
14
  /**
18
15
  * Creates a JJE instance from an Element reference.
19
16
  *
@@ -33,23 +30,12 @@ export declare class JJE<T extends Element = Element> extends JJN<T> implements
33
30
  * @throws {TypeError} If `ref` is not an Element.
34
31
  */
35
32
  constructor(ref: T);
36
- /**
37
- * Finds an element by ID within this element's context
38
- *
39
- * @remarks
40
- * This method uses `Element.querySelector()` under the hood.
41
- *
42
- * @param id - The ID to search for.
43
- * @param throwIfNotFound - Whether to throw an error if not found. Defaults to true.
44
- * @returns The wrapped element, or null if not found and throwIfNotFound is false.
45
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector | Element.querySelector}
46
- */
47
- byId(id: string, throwIfNotFound?: boolean): Wrapped | null;
48
33
  /**
49
34
  * Gets the value of an attribute.
50
35
  *
51
36
  * @param name - The name of the attribute.
52
37
  * @returns The attribute value, or null if not present.
38
+ * @throws {TypeError} If `name` is not a string.
53
39
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute | Element.getAttribute}
54
40
  */
55
41
  getAttr(name: string): string | null;
@@ -58,46 +44,40 @@ export declare class JJE<T extends Element = Element> extends JJN<T> implements
58
44
  *
59
45
  * @param name - The name of the attribute.
60
46
  * @returns `true` if the attribute exists, otherwise `false`.
47
+ * @throws {TypeError} If `name` is not a string.
61
48
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute | Element.hasAttribute}
62
49
  */
63
50
  hasAttr(name: string): boolean;
64
51
  /**
65
- * Sets the value of an attribute.
52
+ * Sets one or more attributes on the Element.
66
53
  *
67
- * @param name - The name of the attribute.
68
- * @param value - The value to set.
69
- * @returns This instance for chaining.
54
+ * @example
55
+ * ```ts
56
+ * el.setAttr('id', 'my-id') // Single attribute
57
+ * el.setAttr({ id: 'my-id', class: 'my-class' }) // Multiple attributes
58
+ * el.setAttr('x', 50) // Numbers are automatically converted
59
+ * ```
60
+ *
61
+ * @throws {TypeError} If arguments are invalid types.
70
62
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute | Element.setAttribute}
71
63
  */
72
- setAttr(name: string, value: string): this;
64
+ setAttr(name: string, value: any): this;
65
+ setAttr(obj: Record<string, any>): this;
73
66
  /**
74
- * Sets multiple attributes at once.
67
+ * Removes one or more attributes from the Element.
75
68
  *
76
69
  * @example
77
70
  * ```ts
78
- * el.setAttrs({ id: 'my-id', class: 'my-class' })
71
+ * el.rmAttr('disabled') // Remove single
72
+ * el.rmAttr('hidden', 'aria-hidden') // Remove multiple
79
73
  * ```
80
74
  *
81
- * @param obj - An object where keys are attribute names and values are attribute values.
82
- * @returns This instance for chaining.
83
- * @throws {TypeError} If `obj` is not an object.
84
- */
85
- setAttrs(obj: Record<string, string>): this;
86
- /**
87
- * Removes an attribute.
88
- *
89
- * @param name - The name of the attribute to remove.
75
+ * @param names - The name(s) of the attribute(s) to remove.
90
76
  * @returns This instance for chaining.
77
+ * @throws {TypeError} If any name is not a string.
91
78
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute | Element.removeAttribute}
92
79
  */
93
- rmAttr(name: string): this;
94
- /**
95
- * Removes multiple attributes.
96
- *
97
- * @param names - The names of the attributes to remove.
98
- * @returns This instance for chaining.
99
- */
100
- rmAttrs(...names: string[]): this;
80
+ rmAttr(...names: string[]): this;
101
81
  /**
102
82
  * Gets the value of an ARIA attribute.
103
83
  *
@@ -111,6 +91,7 @@ export declare class JJE<T extends Element = Element> extends JJN<T> implements
111
91
  *
112
92
  * @param name - The ARIA attribute suffix (e.g., 'label' for 'aria-label').
113
93
  * @returns The attribute value, or null if not present.
94
+ * @throws {TypeError} If `name` is not a string.
114
95
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes | ARIA Attributes}
115
96
  */
116
97
  getAria(name: string): string | null;
@@ -119,28 +100,37 @@ export declare class JJE<T extends Element = Element> extends JJN<T> implements
119
100
  *
120
101
  * @param name - The ARIA attribute suffix.
121
102
  * @returns `true` if the attribute exists.
103
+ * @throws {TypeError} If `name` is not a string.
122
104
  */
123
105
  hasAria(name: string): boolean;
124
106
  /**
125
- * Sets an ARIA attribute.
107
+ * Sets one or more ARIA attributes on the Element.
126
108
  *
127
109
  * @example
128
110
  * ```ts
129
- * el.setAria('hidden', 'true') // sets aria-hidden="true"
111
+ * el.setAria('hidden', 'true') // Single: sets aria-hidden="true"
112
+ * el.setAria({ label: 'Close', hidden: 'false' }) // Multiple
113
+ * el.setAria('level', 2) // Numbers are automatically converted
130
114
  * ```
131
115
  *
132
- * @param name - The ARIA attribute suffix.
133
- * @param value - The value to set.
134
- * @returns This instance for chaining.
116
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes | ARIA Attributes}
135
117
  */
136
- setAria(name: string, value: string): this;
118
+ setAria(name: string, value: any): this;
119
+ setAria(obj: Record<string, any>): this;
137
120
  /**
138
- * Removes an ARIA attribute.
121
+ * Removes one or more ARIA attributes from the Element.
139
122
  *
140
- * @param name - The ARIA attribute suffix.
123
+ * @example
124
+ * ```ts
125
+ * el.rmAria('hidden') // Remove single
126
+ * el.rmAria('label', 'hidden') // Remove multiple
127
+ * ```
128
+ *
129
+ * @param names - The ARIA attribute suffix(es) to remove.
141
130
  * @returns This instance for chaining.
131
+ * @throws {TypeError} If any name is not a string.
142
132
  */
143
- rmAria(name: string): this;
133
+ rmAria(...names: string[]): this;
144
134
  /**
145
135
  * Gets the class attribute.
146
136
  *
@@ -149,54 +139,75 @@ export declare class JJE<T extends Element = Element> extends JJN<T> implements
149
139
  */
150
140
  getClass(): string | null;
151
141
  /**
152
- * Sets the class attribute.
142
+ * Sets the class attribute or conditionally adds/removes classes.
143
+ *
144
+ * @remarks
145
+ * - Pass a string to replace the entire class attribute
146
+ * - Pass an object with class names as keys and boolean values to conditionally add/remove classes
147
+ * - To remove all classes, pass an empty string: `setClass('')`
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * el.setClass('btn btn-primary') // Set classes as string
152
+ * el.setClass({ // Conditional classes (Vue.js style)
153
+ * 'active': true, // adds 'active'
154
+ * 'disabled': false, // removes 'disabled'
155
+ * 'highlight': isHighlighted // adds/removes based on condition
156
+ * })
157
+ * ```
153
158
  *
154
- * @param className - The class string to set.
155
- * @returns This instance for chaining.
156
159
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/className | Element.className}
160
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
157
161
  */
158
162
  setClass(className: string): this;
163
+ setClass(classMap: Record<string, boolean | unknown>): this;
159
164
  /**
160
- * Removes the `class` attribute of the element.
165
+ * Adds one or more classes to the Element.
161
166
  *
162
- * @remarks
163
- * If you want to remove a few specific class instead of all, use `rmClasses`
164
- *
165
- * @returns This instance for chaining.
166
- */
167
- rmClass(): this;
168
- /**
169
- * Adds one or more classes to the element.
167
+ * @example
168
+ * ```ts
169
+ * el.addClass('btn', 'btn-primary')
170
+ * ```
170
171
  *
171
172
  * @param classNames - The classes to add.
172
173
  * @returns This instance for chaining.
174
+ * @throws {TypeError} If any class name is not a string.
173
175
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
174
176
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/add | DOMTokenList.add}
175
177
  */
176
178
  addClass(...classNames: string[]): this;
177
179
  /**
178
- * Removes one or more classes from the element.
180
+ * Removes one or more classes from the Element.
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * el.rmClass('active') // Remove single
185
+ * el.rmClass('btn', 'btn-primary') // Remove multiple
186
+ * ```
179
187
  *
180
188
  * @param classNames - The classes to remove.
181
189
  * @returns This instance for chaining.
190
+ * @throws {TypeError} If any class name is not a string.
182
191
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
183
192
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove | DOMTokenList.remove}
184
193
  */
185
- rmClasses(...classNames: string[]): this;
194
+ rmClass(...classNames: string[]): this;
186
195
  /**
187
- * Checks if the element has a specific class.
196
+ * Checks if the Element has a specific class.
188
197
  *
189
198
  * @param className - The class to check for.
190
199
  * @returns `true` if the element has the class.
200
+ * @throws {TypeError} If `className` is not a string.
191
201
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
192
202
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/contains | DOMTokenList.contains}
193
203
  */
194
204
  hasClass(className: string): boolean;
195
205
  /**
196
- * Toggles a class on the element.
206
+ * Toggles a class on the Element.
197
207
  *
198
208
  * @param className - The class to toggle.
199
209
  * @returns This instance for chaining.
210
+ * @throws {TypeError} If `className` is not a string.
200
211
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/classList | Element.classList}
201
212
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/toggle | DOMTokenList.toggle}
202
213
  */
@@ -209,18 +220,12 @@ export declare class JJE<T extends Element = Element> extends JJN<T> implements
209
220
  *
210
221
  * @param oldClassName - The class name to remove
211
222
  * @param newClassName - The class name to add
223
+ * @throws {TypeError} If either className is not a string.
212
224
  */
213
225
  replaceClass(oldClassName: string, newClassName: string): this;
214
226
  /**
215
- * Adds a click event listener.
216
- *
217
- * @param handler - The event handler.
218
- * @returns This instance for chaining.
219
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener | EventTarget.addEventListener}
220
- */
221
- onClick(handler: EventListenerOrEventListenerObject): this;
222
- /**
223
- * Hides the element by setting the `hidden` attribute and `aria-hidden="true"`.
227
+
228
+ * Hides the Element by setting the `hidden` attribute and `aria-hidden="true"`.
224
229
  *
225
230
  * @returns This instance for chaining.
226
231
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden | hidden attribute}
@@ -228,13 +233,13 @@ export declare class JJE<T extends Element = Element> extends JJN<T> implements
228
233
  */
229
234
  hide(): this;
230
235
  /**
231
- * Shows the element by removing the `hidden` and `aria-hidden` attributes.
236
+ * Shows the Element by removing the `hidden` and `aria-hidden` attributes.
232
237
  *
233
238
  * @returns This instance for chaining.
234
239
  */
235
240
  show(): this;
236
241
  /**
237
- * Disables the element by setting the `disabled` attribute and `aria-disabled="true"`.
242
+ * Disables the Element by setting the `disabled` attribute and `aria-disabled="true"`.
238
243
  *
239
244
  * @returns This instance for chaining.
240
245
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled | disabled attribute}
@@ -242,54 +247,35 @@ export declare class JJE<T extends Element = Element> extends JJN<T> implements
242
247
  */
243
248
  disable(): this;
244
249
  /**
245
- * Enables the element by removing the `disabled` and `aria-disabled` attributes.
250
+ * Enables the Element by removing the `disabled` and `aria-disabled` attributes.
246
251
  *
247
252
  * @returns This instance for chaining.
248
253
  */
249
254
  enable(): this;
250
255
  /**
251
- * Gets the title attribute.
256
+ * Gets the inner HTML of the Element.
252
257
  *
253
- * @returns The title, or null if not set.
254
- */
255
- getTitle(): string | null;
256
- /**
257
- * Sets the title attribute.
258
- *
259
- * @param title - The title to set.
260
- * @returns This instance for chaining.
261
- */
262
- setTitle(title: string): this;
263
- /**
264
- * Sets the id attribute.
265
- *
266
- * @param id - The id to set.
267
- * @returns This instance for chaining.
268
- */
269
- setId(id: string): this;
270
- /**
271
- * Gets the id attribute.
272
- *
273
- * @returns The id, or null if not set.
274
- */
275
- getId(): string | null;
276
- /**
277
- * Gets the inner HTML of the element.
258
+ * @remarks
259
+ * This method operates on `innerHTML`. The method name is kept short for convenience.
278
260
  *
279
261
  * @returns The inner HTML string.
280
262
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
281
263
  */
282
264
  getHTML(): string;
283
265
  /**
284
- * Sets the inner HTML of the element.
266
+ * Sets the inner HTML of the Element.
267
+ *
268
+ * @remarks
269
+ * This method operates on `innerHTML`. The method name is kept short for convenience.
270
+ * Pass an empty string, `null`, or `undefined` to clear the content.
285
271
  *
286
- * @param html - The HTML string to set.
272
+ * @param html - The HTML string to set, or null/undefined to clear.
287
273
  * @returns This instance for chaining.
288
274
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
289
275
  */
290
- setHTML(html: string): this;
276
+ setHTML(html?: string | null): this;
291
277
  /**
292
- * Attaches a Shadow DOM to the element and optionally sets its content and styles.
278
+ * Attaches a Shadow DOM to the Element and optionally sets its content and styles.
293
279
  *
294
280
  * @remarks
295
281
  * We prevent FOUC by assigning the template and CSS in one go.
@@ -305,7 +291,7 @@ export declare class JJE<T extends Element = Element> extends JJN<T> implements
305
291
  */
306
292
  initShadow(mode?: ShadowRootMode, config?: ShadowConfig): this;
307
293
  /**
308
- * Gets a wrapper around the element's Shadow Root, if it exists.
294
+ * Gets a wrapper around the Element's Shadow Root, if it exists.
309
295
  *
310
296
  * @returns A JJSR instance wrapping the shadow root, or null if no shadow root exists.
311
297
  */