jj 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/JJD.d.ts +76 -0
- package/lib/JJD.js +91 -0
- package/lib/JJD.js.map +1 -0
- package/lib/JJDF.d.ts +60 -0
- package/lib/JJDF.js +68 -0
- package/lib/JJDF.js.map +1 -0
- package/lib/JJE.d.ts +313 -0
- package/lib/JJE.js +412 -0
- package/lib/JJE.js.map +1 -0
- package/lib/JJHE.d.ts +120 -0
- package/lib/JJHE.js +164 -0
- package/lib/JJHE.js.map +1 -0
- package/lib/JJN.d.ts +211 -0
- package/lib/JJN.js +286 -0
- package/lib/JJN.js.map +1 -0
- package/lib/JJSE.d.ts +148 -0
- package/lib/JJSE.js +190 -0
- package/lib/JJSE.js.map +1 -0
- package/lib/JJSR.d.ts +67 -0
- package/lib/JJSR.js +85 -0
- package/lib/JJSR.js.map +1 -0
- package/lib/JJT.d.ts +79 -0
- package/lib/JJT.js +108 -0
- package/lib/JJT.js.map +1 -0
- package/lib/bundle.d.ts +1 -0
- package/lib/bundle.js +1505 -445
- package/lib/bundle.js.map +3 -3
- package/lib/bundle.min.d.ts +1 -0
- package/lib/bundle.min.js +2 -2
- package/lib/case.d.ts +57 -0
- package/lib/case.js +61 -3
- package/lib/case.js.map +1 -1
- package/lib/components.d.ts +147 -0
- package/lib/components.js +286 -0
- package/lib/components.js.map +1 -0
- package/lib/helpers.d.ts +158 -0
- package/lib/helpers.js +231 -0
- package/lib/helpers.js.map +1 -0
- package/lib/index.d.ts +13 -12
- package/lib/index.js +13 -12
- package/lib/index.js.map +1 -1
- package/lib/mixin-types.d.ts +143 -0
- package/lib/mixin-types.js +2 -0
- package/lib/mixin-types.js.map +1 -0
- package/lib/mixins.d.ts +94 -0
- package/lib/mixins.js +359 -0
- package/lib/mixins.js.map +1 -0
- package/lib/types.d.ts +77 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/util.d.ts +90 -2
- package/lib/util.js +106 -2
- package/lib/util.js.map +1 -1
- package/lib/util.test.d.ts +1 -0
- package/lib/util.test.js +46 -0
- package/lib/util.test.js.map +1 -0
- package/package.json +16 -7
- package/lib/WC.d.ts +0 -41
- package/lib/WC.js +0 -117
- package/lib/WC.js.map +0 -1
- package/lib/WD.d.ts +0 -8
- package/lib/WD.js +0 -17
- package/lib/WD.js.map +0 -1
- package/lib/WDF.d.ts +0 -9
- package/lib/WDF.js +0 -20
- package/lib/WDF.js.map +0 -1
- package/lib/WE.d.ts +0 -43
- package/lib/WE.js +0 -131
- package/lib/WE.js.map +0 -1
- package/lib/WHE.d.ts +0 -21
- package/lib/WHE.js +0 -75
- package/lib/WHE.js.map +0 -1
- package/lib/WN-mixin.d.ts +0 -9
- package/lib/WN-mixin.js +0 -59
- package/lib/WN-mixin.js.map +0 -1
- package/lib/WN.d.ts +0 -47
- package/lib/WN.js +0 -194
- package/lib/WN.js.map +0 -1
- package/lib/WSE.d.ts +0 -25
- package/lib/WSE.js +0 -84
- package/lib/WSE.js.map +0 -1
- package/lib/WSH.d.ts +0 -11
- package/lib/WSH.js +0 -29
- package/lib/WSH.js.map +0 -1
- package/lib/WT.d.ts +0 -12
- package/lib/WT.js +0 -39
- package/lib/WT.js.map +0 -1
- package/lib/fetch.d.ts +0 -31
- package/lib/fetch.js +0 -69
- package/lib/fetch.js.map +0 -1
- package/lib/h.d.ts +0 -3
- package/lib/h.js +0 -9
- package/lib/h.js.map +0 -1
package/lib/mixins.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { JJN } from './JJN.js';
|
|
2
|
+
import { Unwrapped, Wrappable, Wrapped } from './types.js';
|
|
3
|
+
export declare const wrapAll: typeof JJN.wrapAll, unwrapAll: typeof JJN.unwrapAll;
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a native DOM node or string into the most specific JJ wrapper available.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* This function acts as a factory, inspecting the input type and returning the appropriate
|
|
9
|
+
* subclass of `JJN` (e.g., `JJHE` for `HTMLElement`, `JJT` for `Text`).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const bodyWrapper = JJN.wrap(document.body) // Returns JJHE
|
|
14
|
+
* const textWrapper = JJN.wrap('Hello') // Returns JJT wrapping a new Text node
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @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.
|
|
18
|
+
* @returns The most granular Wrapped subclass instance. If the input is already wrapped, it'll be returned as is without cloning.
|
|
19
|
+
* @throws {TypeError} If the input is not a Node, string, or JJ wrapper.
|
|
20
|
+
*/
|
|
21
|
+
export declare function wrap(raw: Wrappable): Wrapped;
|
|
22
|
+
/**
|
|
23
|
+
* Extracts the underlying native DOM node from a wrapper.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* If the input is already a native Node, it is returned as is.
|
|
27
|
+
* If the input is a string, a new Text node is created and returned.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const rawElement = JJN.unwrap(myJJHE) // Returns HTMLElement
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param obj - The object to unwrap.
|
|
35
|
+
* @returns The underlying DOM node.
|
|
36
|
+
* @throws {TypeError} If the input cannot be unwrapped.
|
|
37
|
+
*/
|
|
38
|
+
export declare function unwrap(obj: Wrappable): Unwrapped;
|
|
39
|
+
/**
|
|
40
|
+
* Finds an element by ID in the document.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const el = byId('my-id')
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @param id - The ID to search for.
|
|
48
|
+
* @param throwIfNotFound - Whether to throw an error if not found. Defaults to true.
|
|
49
|
+
* @returns The wrapped element, or null if not found and throwIfNotFound is false.
|
|
50
|
+
* @throws {TypeError} If the element is not found and throwIfNotFound is true.
|
|
51
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById | Document.getElementById}
|
|
52
|
+
*/
|
|
53
|
+
export declare function byId(id: string, throwIfNotFound?: boolean): Wrapped | null;
|
|
54
|
+
/**
|
|
55
|
+
* Finds elements by class name in the document.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const items = byClass('list-item')
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @param className - The class name to search for.
|
|
63
|
+
* @returns An array of wrapped elements.
|
|
64
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName | Document.getElementsByClassName}
|
|
65
|
+
*/
|
|
66
|
+
export declare function byClass(className: string): Wrapped[];
|
|
67
|
+
/**
|
|
68
|
+
* Finds the first element matching a selector in the document.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const btn = query('.submit-btn')
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @param selector - The CSS selector.
|
|
76
|
+
* @param throwIfNotFound - Whether to throw an error if not found. Defaults to true.
|
|
77
|
+
* @returns The wrapped element, or null.
|
|
78
|
+
* @throws {TypeError} If not found and throwIfNotFound is true.
|
|
79
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector | Document.querySelector}
|
|
80
|
+
*/
|
|
81
|
+
export declare function query(selector: string, throwIfNotFound?: boolean): Wrapped | null;
|
|
82
|
+
/**
|
|
83
|
+
* Finds all elements matching a selector in the document.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const inputs = queryAll('input[type="text"]')
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @param selector - The CSS selector.
|
|
91
|
+
* @returns An array of wrapped elements.
|
|
92
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll | Document.querySelectorAll}
|
|
93
|
+
*/
|
|
94
|
+
export declare function queryAll(selector: string): Wrapped[];
|
package/lib/mixins.js
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { hasProp, isA, isObj, isStr } from 'jty';
|
|
2
|
+
import { JJHE } from './JJHE.js';
|
|
3
|
+
import { JJE } from './JJE.js';
|
|
4
|
+
import { JJDF } from './JJDF.js';
|
|
5
|
+
import { JJSR } from './JJSR.js';
|
|
6
|
+
import { JJT } from './JJT.js';
|
|
7
|
+
import { JJN } from './JJN.js';
|
|
8
|
+
import { JJD } from './JJD.js';
|
|
9
|
+
import { JJSE } from './JJSE.js';
|
|
10
|
+
export const { wrapAll, unwrapAll } = JJN;
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a native DOM node or string into the most specific JJ wrapper available.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* This function acts as a factory, inspecting the input type and returning the appropriate
|
|
16
|
+
* subclass of `JJN` (e.g., `JJHE` for `HTMLElement`, `JJT` for `Text`).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const bodyWrapper = JJN.wrap(document.body) // Returns JJHE
|
|
21
|
+
* const textWrapper = JJN.wrap('Hello') // Returns JJT wrapping a new Text node
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @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.
|
|
25
|
+
* @returns The most granular Wrapped subclass instance. If the input is already wrapped, it'll be returned as is without cloning.
|
|
26
|
+
* @throws {TypeError} If the input is not a Node, string, or JJ wrapper.
|
|
27
|
+
*/
|
|
28
|
+
export function wrap(raw) {
|
|
29
|
+
if (isStr(raw)) {
|
|
30
|
+
return JJT.from(document.createTextNode(raw));
|
|
31
|
+
}
|
|
32
|
+
if (!isObj(raw)) {
|
|
33
|
+
throw new TypeError(`Expected an object to wrap. Got ${raw} (${typeof raw})`);
|
|
34
|
+
}
|
|
35
|
+
if (isA(raw, JJN)) {
|
|
36
|
+
return raw;
|
|
37
|
+
}
|
|
38
|
+
if (isA(raw, HTMLElement)) {
|
|
39
|
+
return JJHE.from(raw);
|
|
40
|
+
}
|
|
41
|
+
if (isA(raw, SVGElement)) {
|
|
42
|
+
return JJSE.from(raw);
|
|
43
|
+
}
|
|
44
|
+
if (isA(raw, Element)) {
|
|
45
|
+
return JJE.from(raw);
|
|
46
|
+
}
|
|
47
|
+
if (isA(raw, ShadowRoot)) {
|
|
48
|
+
return JJSR.from(raw);
|
|
49
|
+
}
|
|
50
|
+
if (isA(raw, DocumentFragment)) {
|
|
51
|
+
return JJDF.from(raw);
|
|
52
|
+
}
|
|
53
|
+
if (isA(raw, Document)) {
|
|
54
|
+
return JJD.from(raw);
|
|
55
|
+
}
|
|
56
|
+
if (isA(raw, Text)) {
|
|
57
|
+
return JJT.from(raw);
|
|
58
|
+
}
|
|
59
|
+
if (isA(raw, Node)) {
|
|
60
|
+
return JJN.from(raw);
|
|
61
|
+
}
|
|
62
|
+
throw new TypeError(`Expected a Node to wrap. Got ${raw} (${typeof raw})`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Extracts the underlying native DOM node from a wrapper.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* If the input is already a native Node, it is returned as is.
|
|
69
|
+
* If the input is a string, a new Text node is created and returned.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const rawElement = JJN.unwrap(myJJHE) // Returns HTMLElement
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @param obj - The object to unwrap.
|
|
77
|
+
* @returns The underlying DOM node.
|
|
78
|
+
* @throws {TypeError} If the input cannot be unwrapped.
|
|
79
|
+
*/
|
|
80
|
+
export function unwrap(obj) {
|
|
81
|
+
if (isStr(obj)) {
|
|
82
|
+
return document.createTextNode(obj);
|
|
83
|
+
}
|
|
84
|
+
if (!isObj(obj)) {
|
|
85
|
+
throw new TypeError(`Expected an object. Got ${obj} (${typeof obj})`);
|
|
86
|
+
}
|
|
87
|
+
if (isA(obj, Node)) {
|
|
88
|
+
return obj;
|
|
89
|
+
}
|
|
90
|
+
if (isA(obj, JJN)) {
|
|
91
|
+
return obj.ref;
|
|
92
|
+
}
|
|
93
|
+
throw new TypeError(`Could not unwrap ${obj} (${typeof obj})`);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Finds an element by ID in the document.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const el = byId('my-id')
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @param id - The ID to search for.
|
|
104
|
+
* @param throwIfNotFound - Whether to throw an error if not found. Defaults to true.
|
|
105
|
+
* @returns The wrapped element, or null if not found and throwIfNotFound is false.
|
|
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/Document/getElementById | Document.getElementById}
|
|
108
|
+
*/
|
|
109
|
+
export function byId(id, throwIfNotFound = true) {
|
|
110
|
+
const el = document.getElementById(id);
|
|
111
|
+
if (el) {
|
|
112
|
+
return wrap(el);
|
|
113
|
+
}
|
|
114
|
+
if (throwIfNotFound) {
|
|
115
|
+
throw new TypeError(`Found no element with id ${id} in the document.`);
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Finds elements by class name in the document.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const items = byClass('list-item')
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @param className - The class name to search for.
|
|
128
|
+
* @returns An array of wrapped elements.
|
|
129
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName | Document.getElementsByClassName}
|
|
130
|
+
*/
|
|
131
|
+
export function byClass(className) {
|
|
132
|
+
return wrapAll(document.getElementsByClassName(className));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Finds the first element matching a selector in the document.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* const btn = query('.submit-btn')
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @param selector - The CSS selector.
|
|
143
|
+
* @param throwIfNotFound - Whether to throw an error if not found. Defaults to true.
|
|
144
|
+
* @returns The wrapped element, or null.
|
|
145
|
+
* @throws {TypeError} If not found and throwIfNotFound is true.
|
|
146
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector | Document.querySelector}
|
|
147
|
+
*/
|
|
148
|
+
export function query(selector, throwIfNotFound = true) {
|
|
149
|
+
const queryResult = document.querySelector(selector);
|
|
150
|
+
if (queryResult) {
|
|
151
|
+
return wrap(queryResult);
|
|
152
|
+
}
|
|
153
|
+
if (throwIfNotFound) {
|
|
154
|
+
throw new TypeError(`Element with selector ${selector} not found`);
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Finds all elements matching a selector in the document.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* const inputs = queryAll('input[type="text"]')
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @param selector - The CSS selector.
|
|
167
|
+
* @returns An array of wrapped elements.
|
|
168
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll | Document.querySelectorAll}
|
|
169
|
+
*/
|
|
170
|
+
export function queryAll(selector) {
|
|
171
|
+
return wrapAll(document.querySelectorAll(selector));
|
|
172
|
+
}
|
|
173
|
+
const DDF = {
|
|
174
|
+
/**
|
|
175
|
+
* Finds an element by ID within this Document or DocumentFragment.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const el = doc.byId('header')
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @param this - The JJD or JJDF instance.
|
|
183
|
+
* @param id - The ID to search for.
|
|
184
|
+
* @param throwIfNotFound - Whether to throw an error if not found. Defaults to true.
|
|
185
|
+
* @returns The wrapped element, or null if not found and throwIfNotFound is false.
|
|
186
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById | Document.getElementById}
|
|
187
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/getElementById | DocumentFragment.getElementById}
|
|
188
|
+
*/
|
|
189
|
+
byId(id, throwIfNotFound = true) {
|
|
190
|
+
const el = this.ref.getElementById(id);
|
|
191
|
+
if (el) {
|
|
192
|
+
return wrap(el);
|
|
193
|
+
}
|
|
194
|
+
if (throwIfNotFound) {
|
|
195
|
+
throw new TypeError(`Element with id ${id} not found`);
|
|
196
|
+
}
|
|
197
|
+
return null;
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
const EDDF = {
|
|
201
|
+
/**
|
|
202
|
+
* Finds the first element matching a selector within this element's context.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* const span = div.query('span')
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @param this - The JJE, JJD or JJDF instance.
|
|
210
|
+
* @param selector - The CSS selector.
|
|
211
|
+
* @param throwIfNotFound - Whether to throw an error if not found. Defaults to true.
|
|
212
|
+
* @returns The wrapped element, or null.
|
|
213
|
+
* @throws {TypeError} If context is invalid or element not found (when requested).
|
|
214
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector | Element.querySelector}
|
|
215
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector | Document.querySelector}
|
|
216
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/querySelector | DocumentFragment.querySelector}
|
|
217
|
+
*/
|
|
218
|
+
query(selector, throwIfNotFound = true) {
|
|
219
|
+
const queryResult = this.ref.querySelector(selector);
|
|
220
|
+
if (queryResult) {
|
|
221
|
+
return wrap(queryResult);
|
|
222
|
+
}
|
|
223
|
+
if (throwIfNotFound) {
|
|
224
|
+
throw new TypeError(`Element with selector ${selector} not found`);
|
|
225
|
+
}
|
|
226
|
+
return null;
|
|
227
|
+
},
|
|
228
|
+
/**
|
|
229
|
+
* Finds all elements matching a selector within this element's context.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* const items = list.queryAll('li')
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @param this - The JJE, JJD or JJDF instance.
|
|
237
|
+
* @param selector - The CSS selector.
|
|
238
|
+
* @returns An array of wrapped elements.
|
|
239
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll | Element.querySelectorAll}
|
|
240
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll | Document.querySelectorAll}
|
|
241
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/querySelectorAll | DocumentFragment.querySelectorAll}
|
|
242
|
+
*/
|
|
243
|
+
queryAll(selector) {
|
|
244
|
+
return wrapAll(this.ref.querySelectorAll(selector));
|
|
245
|
+
},
|
|
246
|
+
/**
|
|
247
|
+
* Appends children to this node using native append.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* myDiv.append(h('span', null, 'hello'))
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @param this - The JJE, JJD or JJDF instance.
|
|
255
|
+
* @param children - The children to append.
|
|
256
|
+
* @returns This instance for chaining.
|
|
257
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/append | Element.append}
|
|
258
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/append | Document.append}
|
|
259
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/append | DocumentFragment.append}
|
|
260
|
+
*/
|
|
261
|
+
append(...children) {
|
|
262
|
+
const nodes = unwrapAll(children);
|
|
263
|
+
this.ref.append(...nodes);
|
|
264
|
+
return this;
|
|
265
|
+
},
|
|
266
|
+
/**
|
|
267
|
+
* Prepends children to this node using native prepend.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* div.prepend(h('span', null, 'first'))
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* @param this - The JJE, JJD or JJDF instance.
|
|
275
|
+
* @param children - The children to prepend.
|
|
276
|
+
* @returns This instance for chaining.
|
|
277
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend | Element.prepend}
|
|
278
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/prepend | Document.prepend}
|
|
279
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/prepend | DocumentFragment.prepend}
|
|
280
|
+
*/
|
|
281
|
+
prepend(...children) {
|
|
282
|
+
const nodes = unwrapAll(children);
|
|
283
|
+
this.ref.prepend(...nodes);
|
|
284
|
+
return this;
|
|
285
|
+
},
|
|
286
|
+
/**
|
|
287
|
+
* Replaces the existing children of a node with a specified new set of children.
|
|
288
|
+
*
|
|
289
|
+
* @remarks
|
|
290
|
+
* If no children are provided, it empties the node.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts
|
|
294
|
+
* div.replaceChildren(h('p', null, 'New Content'))
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* @param this - The JJE, JJD or JJDF instance.
|
|
298
|
+
* @param children - The children to replace with.
|
|
299
|
+
* @returns This instance for chaining.
|
|
300
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren | Element.replaceChildren}
|
|
301
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/replaceChildren | Document.replaceChildren}
|
|
302
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/replaceChildren | DocumentFragment.replaceChildren}
|
|
303
|
+
*/
|
|
304
|
+
replaceChildren(...children) {
|
|
305
|
+
const nodes = unwrapAll(children);
|
|
306
|
+
this.ref.replaceChildren(...nodes);
|
|
307
|
+
return this;
|
|
308
|
+
},
|
|
309
|
+
/**
|
|
310
|
+
* Removes all children from this node.
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```ts
|
|
314
|
+
* div.empty()
|
|
315
|
+
* ```
|
|
316
|
+
*
|
|
317
|
+
* @returns This instance for chaining.
|
|
318
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren | Element.replaceChildren}
|
|
319
|
+
*/
|
|
320
|
+
empty() {
|
|
321
|
+
this.replaceChildren();
|
|
322
|
+
return this;
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
const HESE = {
|
|
326
|
+
getData(name) {
|
|
327
|
+
return this.ref.dataset[name];
|
|
328
|
+
},
|
|
329
|
+
hasData(name) {
|
|
330
|
+
return hasProp(this.ref.dataset, name);
|
|
331
|
+
},
|
|
332
|
+
setData(name, value) {
|
|
333
|
+
this.ref.dataset[name] = value;
|
|
334
|
+
return this;
|
|
335
|
+
},
|
|
336
|
+
setDataObj(obj) {
|
|
337
|
+
for (const [name, value] of Object.entries(obj)) {
|
|
338
|
+
this.setData(name, value);
|
|
339
|
+
}
|
|
340
|
+
return this;
|
|
341
|
+
},
|
|
342
|
+
rmData(name) {
|
|
343
|
+
delete this.ref.dataset[name];
|
|
344
|
+
return this;
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
function assignPrototype(Class, ...mixins) {
|
|
348
|
+
for (const mixin of mixins) {
|
|
349
|
+
Object.assign(Class.prototype, mixin);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
JJN.wrap = wrap;
|
|
353
|
+
JJN.unwrap = unwrap;
|
|
354
|
+
assignPrototype(JJE, EDDF);
|
|
355
|
+
assignPrototype(JJD, DDF, EDDF);
|
|
356
|
+
assignPrototype(JJDF, DDF, EDDF);
|
|
357
|
+
assignPrototype(JJHE, HESE);
|
|
358
|
+
assignPrototype(JJSE, HESE);
|
|
359
|
+
//# sourceMappingURL=mixins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixins.js","sourceRoot":"","sources":["../src/mixins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAIhC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,GAAG,CAAA;AAEzC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,IAAI,CAAC,GAAc;IAC/B,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAA;IACjD,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACd,MAAM,IAAI,SAAS,CAAC,mCAAmC,GAAG,KAAK,OAAO,GAAG,G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,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;QAC9B,OAAO,IAAI,CAAA;IACf,CAAC;IAED,UAAU,CAAiC,GAA2B;QAClE,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAC7B,CAAC;QACD,OAAO,IAAI,CAAA;IACf,CAAC;IAED,MAAM,CAAiC,IAAY;QAC/C,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC7B,OAAO,IAAI,CAAA;IACf,CAAC;CACJ,CAAA;AAED,SAAS,eAAe,CAAC,KAAU,EAAE,GAAG,MAAa;IACjD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;IACzC,CAAC;AACL,CAAC;AAED,GAAG,CAAC,IAAI,GAAG,IAAI,CAAA;AACf,GAAG,CAAC,MAAM,GAAG,MAAM,CAAA;AAEnB,eAAe,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AAC1B,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;AAC/B,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;AAChC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AAC3B,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { JJD } from './JJD.js';
|
|
2
|
+
import type { JJDF } from './JJDF.js';
|
|
3
|
+
import type { JJE } from './JJE.js';
|
|
4
|
+
import type { JJHE } from './JJHE.js';
|
|
5
|
+
import type { JJN } from './JJN.js';
|
|
6
|
+
import type { JJSE } from './JJSE.js';
|
|
7
|
+
import type { JJSR } from './JJSR.js';
|
|
8
|
+
import type { JJT } from './JJT.js';
|
|
9
|
+
/**
|
|
10
|
+
* Represents any value that can be wrapped by the library.
|
|
11
|
+
* Can be a native Node, a string (which becomes a Text node), or an existing JJ wrapper.
|
|
12
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | Node}
|
|
13
|
+
*/
|
|
14
|
+
export type Wrappable = string | Node | JJN;
|
|
15
|
+
/**
|
|
16
|
+
* Union type of all possible JJ wrapper classes.
|
|
17
|
+
*/
|
|
18
|
+
export type Wrapped = JJN | JJT | JJE | JJHE | JJSE | JJD | JJDF | JJSR;
|
|
19
|
+
/**
|
|
20
|
+
* Union type of all native DOM nodes that correspond to JJ wrappers.
|
|
21
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | Node}
|
|
22
|
+
*/
|
|
23
|
+
export type Unwrapped = Node | Text | Element | HTMLElement | SVGElement | Document | DocumentFragment | ShadowRoot;
|
|
24
|
+
/**
|
|
25
|
+
* Represents a resource that can be a direct value, a Promise, or a function returning either.
|
|
26
|
+
* Used for lazy loading or dynamic generation.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* type MyConfig = JJResource<string>
|
|
31
|
+
* const c1: MyConfig = 'value'
|
|
32
|
+
* const c2: MyConfig = Promise.resolve('value')
|
|
33
|
+
* const c3: MyConfig = () => 'value'
|
|
34
|
+
* const c4: MyConfig = async () => 'value'
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export type JJResource<T> = T | Promise<T> | (() => T | Promise<T>);
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for the component's template.
|
|
40
|
+
* Can be an HTML string, a JJHE instance, or a raw HTMLElement.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const t1: JJTemplateConfig = '<div>Hello</div>'
|
|
45
|
+
* const t2: JJTemplateConfig = fetchHtml('./template.html')
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
|
|
49
|
+
*/
|
|
50
|
+
export type JJTemplateConfig = JJResource<string | JJHE | HTMLElement>;
|
|
51
|
+
/**
|
|
52
|
+
* Configuration for the component's styles.
|
|
53
|
+
* Can be a CSS string or a CSSStyleSheet.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const s1: JJStyleConfig = 'p { color: red; }'
|
|
58
|
+
* const s2: JJStyleConfig = fetchCss('./style.css')
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet | CSSStyleSheet}
|
|
62
|
+
*/
|
|
63
|
+
export type JJStyleConfig = JJResource<string | CSSStyleSheet>;
|
|
64
|
+
/**
|
|
65
|
+
* Configuration for one or more style resources.
|
|
66
|
+
*/
|
|
67
|
+
export type JJStylesConfig = JJStyleConfig | JJStyleConfig[];
|
|
68
|
+
/**
|
|
69
|
+
* Configuration for initializing a shadowRoot
|
|
70
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/adoptedStyleSheets | ShadowRoot.adoptedStyleSheets}
|
|
71
|
+
*/
|
|
72
|
+
export interface ShadowConfig {
|
|
73
|
+
/** Optional HTML content to set in the shadow root */
|
|
74
|
+
template?: string;
|
|
75
|
+
/** Optional CSSStyleSheets to adopt in the shadow root */
|
|
76
|
+
styles?: CSSStyleSheet[];
|
|
77
|
+
}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/lib/util.d.ts
CHANGED
|
@@ -1,8 +1,96 @@
|
|
|
1
|
-
/**
|
|
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
|
+
export 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
|
+
*/
|
|
2
33
|
export 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
|
+
export declare function sleep(ms?: number): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Adds an event listener to a target.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* on(window, 'resize', () => console.log('resized'))
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param target - The event target.
|
|
61
|
+
* @param eventName - The name of the event.
|
|
62
|
+
* @param handler - The event handler.
|
|
63
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener | EventTarget.addEventListener}
|
|
64
|
+
*/
|
|
3
65
|
export declare function on(target: EventTarget, eventName: string, handler: EventListenerOrEventListenerObject): void;
|
|
66
|
+
/**
|
|
67
|
+
* Removes an event listener from a target.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* off(window, 'resize', handler)
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @param target - The event target.
|
|
75
|
+
* @param eventName - The name of the event.
|
|
76
|
+
* @param handler - The event handler.
|
|
77
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener | EventTarget.removeEventListener}
|
|
78
|
+
*/
|
|
4
79
|
export declare function off(target: EventTarget, eventName: string, handler: EventListenerOrEventListenerObject): void;
|
|
5
80
|
/**
|
|
6
|
-
* Converts a CSS string to a CSSStyleSheet
|
|
81
|
+
* Converts a CSS string to a CSSStyleSheet.
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* Suitable for attaching to ShadowRoot via `adoptedStyleSheets`.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const sheet = await cssToStyle('p { color: red; }')
|
|
89
|
+
* shadowRoot.adoptedStyleSheets = [sheet]
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @param css - The CSS string.
|
|
93
|
+
* @returns A promise resolving to the created CSSStyleSheet.
|
|
94
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/replace | CSSStyleSheet.replace}
|
|
7
95
|
*/
|
|
8
96
|
export declare function cssToStyle(css: string): Promise<CSSStyleSheet>;
|