jj 0.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +35 -7
- package/lib/ComponentFiles.d.ts +35 -0
- package/lib/ComponentFiles.js +116 -0
- package/lib/ComponentFiles.js.map +1 -0
- package/lib/WC.d.ts +33 -0
- package/lib/WC.js +160 -0
- package/lib/WC.js.map +1 -0
- package/lib/WDF.d.ts +11 -0
- package/lib/WDF.js +31 -0
- package/lib/WDF.js.map +1 -0
- package/lib/WE.d.ts +42 -0
- package/lib/WE.js +132 -0
- package/lib/WE.js.map +1 -0
- package/lib/WF.d.ts +14 -0
- package/lib/WF.js +44 -0
- package/lib/WF.js.map +1 -0
- package/lib/WHE.d.ts +21 -0
- package/lib/WHE.js +75 -0
- package/lib/WHE.js.map +1 -0
- package/lib/WN-mixin.d.ts +9 -0
- package/lib/WN-mixin.js +59 -0
- package/lib/WN-mixin.js.map +1 -0
- package/lib/WN.d.ts +34 -0
- package/lib/WN.js +145 -0
- package/lib/WN.js.map +1 -0
- package/lib/WS.d.ts +11 -0
- package/lib/WS.js +32 -0
- package/lib/WS.js.map +1 -0
- package/lib/WSH.d.ts +11 -0
- package/lib/WSH.js +29 -0
- package/lib/WSH.js.map +1 -0
- package/lib/WT.d.ts +12 -0
- package/lib/WT.js +39 -0
- package/lib/WT.js.map +1 -0
- package/lib/Welem.d.ts +49 -0
- package/lib/Welem.js +173 -0
- package/lib/Welem.js.map +1 -0
- package/lib/Wfrag.d.ts +15 -0
- package/lib/Wfrag.js +56 -0
- package/lib/Wfrag.js.map +1 -0
- package/lib/Whelem.d.ts +17 -0
- package/lib/Whelem.js +69 -0
- package/lib/Whelem.js.map +1 -0
- package/lib/Wnode.d.ts +6 -0
- package/lib/Wnode.js +33 -0
- package/lib/Wnode.js.map +1 -0
- package/lib/Wshad.d.ts +9 -0
- package/lib/Wshad.js +31 -0
- package/lib/Wshad.js.map +1 -0
- package/lib/bundle.js +737 -0
- package/lib/bundle.js.map +7 -0
- package/lib/bundle.min.js +3 -0
- package/lib/case.d.ts +3 -0
- package/lib/case.js +34 -0
- package/lib/case.js.map +1 -0
- package/lib/case.test.d.ts +1 -0
- package/lib/case.test.js +79 -0
- package/lib/case.test.js.map +1 -0
- package/lib/h.d.ts +3 -0
- package/lib/h.js +9 -0
- package/lib/h.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -0
- package/lib/util.d.ts +5 -0
- package/lib/util.js +19 -0
- package/lib/util.js.map +1 -0
- package/lib/wrap-unwrap.d.ts +22 -0
- package/lib/wrap-unwrap.js +68 -0
- package/lib/wrap-unwrap.js.map +1 -0
- package/package.json +56 -26
- package/CSS.js +0 -145
- package/Router.js +0 -89
- package/Selector.js +0 -175
- package/Tag.js +0 -827
- package/control.js +0 -74
- package/events.js +0 -16
- package/index.js +0 -26
- package/observer.js +0 -27
- package/rollup.config.js +0 -25
- package/unit.js +0 -78
- package/util.js +0 -153
- package/win.js +0 -11
package/lib/bundle.js
ADDED
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
// src/util.ts
|
|
2
|
+
function nextAnimationFrame() {
|
|
3
|
+
return new Promise((resolve) => requestAnimationFrame(resolve));
|
|
4
|
+
}
|
|
5
|
+
function on(target, eventName, handler) {
|
|
6
|
+
target.addEventListener(eventName, handler);
|
|
7
|
+
}
|
|
8
|
+
function off(target, eventName, handler) {
|
|
9
|
+
target.removeEventListener(eventName, handler);
|
|
10
|
+
}
|
|
11
|
+
async function ensureComponent(name, constructor) {
|
|
12
|
+
if (!customElements.get(name)) {
|
|
13
|
+
customElements.define(name, constructor);
|
|
14
|
+
await customElements.whenDefined(name);
|
|
15
|
+
return constructor;
|
|
16
|
+
}
|
|
17
|
+
return constructor;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/case.ts
|
|
21
|
+
function pas2keb(str) {
|
|
22
|
+
if (typeof str !== "string") {
|
|
23
|
+
throw new TypeError(`Expected a string. Got ${str} (${typeof str})`);
|
|
24
|
+
}
|
|
25
|
+
if (/[^a-zA-Z0-9_]/.test(str)) {
|
|
26
|
+
throw new TypeError(`Invalid characters in string. Only alphanumeric and underscores are allowed. Got: ${str}`);
|
|
27
|
+
}
|
|
28
|
+
return str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").replace(/_/g, "-").toLowerCase();
|
|
29
|
+
}
|
|
30
|
+
function keb2pas(str) {
|
|
31
|
+
if (typeof str !== "string") {
|
|
32
|
+
throw new TypeError(`Expected a string. Got ${str} (${typeof str})`);
|
|
33
|
+
}
|
|
34
|
+
return str.split("-").filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("") || // Handle strings that were not kebab-case to begin with (e.g. 'single', 'camelCase')
|
|
35
|
+
(str.length > 0 ? str.charAt(0).toUpperCase() + str.slice(1) : "");
|
|
36
|
+
}
|
|
37
|
+
function keb2cam(str) {
|
|
38
|
+
if (typeof str !== "string") {
|
|
39
|
+
throw new TypeError(`Expected a string. Got ${str} (${typeof str})`);
|
|
40
|
+
}
|
|
41
|
+
return str.replace(/^-+|-+$/g, "").replace(/-+([a-z])/g, (g, c) => c.toUpperCase());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// node_modules/jty/lib/misc.js
|
|
45
|
+
function isDef(x) {
|
|
46
|
+
return x !== void 0;
|
|
47
|
+
}
|
|
48
|
+
function isFn(x) {
|
|
49
|
+
return typeof x === "function";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// node_modules/jty/lib/number.js
|
|
53
|
+
var { isNaN, isFinite, isInteger } = Number;
|
|
54
|
+
function isNum(x) {
|
|
55
|
+
return typeof x === "number" && !isNaN(x);
|
|
56
|
+
}
|
|
57
|
+
function inRange(x, min, max) {
|
|
58
|
+
if (!isNum(x)) {
|
|
59
|
+
throw new TypeError(`inRange(): "x" must be a number. Got ${x} (${typeof x})`);
|
|
60
|
+
}
|
|
61
|
+
if (isDef(min)) {
|
|
62
|
+
if (!isNum(min)) {
|
|
63
|
+
throw new TypeError(`inRange(): "min" must be a number. Got ${min} (${typeof min})`);
|
|
64
|
+
}
|
|
65
|
+
if (isDef(max)) {
|
|
66
|
+
if (!isNum(max)) {
|
|
67
|
+
throw new TypeError(`inRange(): "max" must be a number. Got ${max} (${typeof max})`);
|
|
68
|
+
}
|
|
69
|
+
if (min > max) {
|
|
70
|
+
return max <= x && x <= min;
|
|
71
|
+
}
|
|
72
|
+
return min <= x && x <= max;
|
|
73
|
+
}
|
|
74
|
+
return x >= min;
|
|
75
|
+
} else if (isDef(max)) {
|
|
76
|
+
if (!isNum(max)) {
|
|
77
|
+
throw new TypeError(`inRange(): "max" must be a number. Got ${max} (${typeof max})`);
|
|
78
|
+
}
|
|
79
|
+
return x <= max;
|
|
80
|
+
}
|
|
81
|
+
throw new TypeError(`inRange(): expected at least min or max to be defined. Got min=${min} and max=${max}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// node_modules/jty/lib/array.js
|
|
85
|
+
var { isArray } = Array;
|
|
86
|
+
function isArr(x, minLen = 0, maxLen) {
|
|
87
|
+
return isArray(x) && inRange(x.length, minLen, maxLen);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// node_modules/jty/lib/object.js
|
|
91
|
+
var { hasOwnProperty } = Object;
|
|
92
|
+
function isObj(x) {
|
|
93
|
+
return Boolean(x) && typeof x === "object";
|
|
94
|
+
}
|
|
95
|
+
function isA(x, classConstructor) {
|
|
96
|
+
if (!isFn(classConstructor)) {
|
|
97
|
+
throw new TypeError(`Expected a constructor function. Got ${classConstructor} (${typeof classConstructor})`);
|
|
98
|
+
}
|
|
99
|
+
return x instanceof classConstructor;
|
|
100
|
+
}
|
|
101
|
+
function hasProp(x, ...propNames) {
|
|
102
|
+
if (!isObj(x)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
for (let propName of propNames) {
|
|
106
|
+
if (!(propName in x)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// node_modules/jty/lib/string.js
|
|
114
|
+
function isStr(x) {
|
|
115
|
+
return typeof x === "string";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// node_modules/jty/lib/same.js
|
|
119
|
+
var { hasOwnProperty: hasOwnProperty2 } = Object;
|
|
120
|
+
var { isArray: isArray2 } = Array;
|
|
121
|
+
|
|
122
|
+
// src/WN.ts
|
|
123
|
+
function isElementOrDocumentFragment(x) {
|
|
124
|
+
return isA(x, Element) || isA(x, DocumentFragment);
|
|
125
|
+
}
|
|
126
|
+
var WN = class _WN {
|
|
127
|
+
static from(node) {
|
|
128
|
+
return new _WN(node);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* wraps an iteratable object (e.g. an array of wrapped or DOM elements)
|
|
132
|
+
*/
|
|
133
|
+
static wrapAll(iterable) {
|
|
134
|
+
return Array.from(iterable, _WN.wrap);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* unwraps an iteratable object (e.g. an array of HTMLCollection)
|
|
138
|
+
*/
|
|
139
|
+
static unwrapAll(iterable) {
|
|
140
|
+
return Array.from(iterable, _WN.unwrap);
|
|
141
|
+
}
|
|
142
|
+
static byId(id, throwIfNotFound = true) {
|
|
143
|
+
const el = document.getElementById(id);
|
|
144
|
+
if (el) {
|
|
145
|
+
return _WN.wrap(el);
|
|
146
|
+
}
|
|
147
|
+
if (throwIfNotFound) {
|
|
148
|
+
throw new TypeError(`Element with id ${id} not found`);
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
static byClass(className) {
|
|
153
|
+
return _WN.wrapAll(document.getElementsByClassName(className));
|
|
154
|
+
}
|
|
155
|
+
static query(selector, throwIfNotFound = true) {
|
|
156
|
+
const queryResult = document.querySelector(selector);
|
|
157
|
+
if (queryResult) {
|
|
158
|
+
return _WN.wrap(queryResult);
|
|
159
|
+
}
|
|
160
|
+
if (throwIfNotFound) {
|
|
161
|
+
throw new TypeError(`Element with selector ${selector} not found`);
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
query(selector, throwIfNotFound = true) {
|
|
166
|
+
if (!isElementOrDocumentFragment(this.ref)) {
|
|
167
|
+
throw new TypeError(`Expected an Element or DocumentFragment. Got ${this.ref} (${typeof this.ref})`);
|
|
168
|
+
}
|
|
169
|
+
const queryResult = this.ref.querySelector(selector);
|
|
170
|
+
if (queryResult) {
|
|
171
|
+
return _WN.wrap(queryResult);
|
|
172
|
+
}
|
|
173
|
+
if (throwIfNotFound) {
|
|
174
|
+
throw new TypeError(`Element with selector ${selector} not found`);
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
static queryAll(selector) {
|
|
179
|
+
return _WN.wrapAll(document.querySelectorAll(selector));
|
|
180
|
+
}
|
|
181
|
+
queryAll(selector) {
|
|
182
|
+
if (!isElementOrDocumentFragment(this.ref)) {
|
|
183
|
+
throw new TypeError(`Expected an Element or DocumentFragment. Got ${this.ref} (${typeof this.ref})`);
|
|
184
|
+
}
|
|
185
|
+
return _WN.wrapAll(this.ref.querySelectorAll(selector));
|
|
186
|
+
}
|
|
187
|
+
#ref;
|
|
188
|
+
constructor(ref) {
|
|
189
|
+
if (!isA(ref, Node)) {
|
|
190
|
+
throw new TypeError(`Expected a Node. Got ${ref} (${typeof ref})`);
|
|
191
|
+
}
|
|
192
|
+
this.#ref = ref;
|
|
193
|
+
}
|
|
194
|
+
get ref() {
|
|
195
|
+
return this.#ref;
|
|
196
|
+
}
|
|
197
|
+
clone(deep) {
|
|
198
|
+
return _WN.wrap(this.ref.cloneNode(deep));
|
|
199
|
+
}
|
|
200
|
+
append(...children) {
|
|
201
|
+
const nodes = _WN.unwrapAll(children);
|
|
202
|
+
if (isElementOrDocumentFragment(this.ref)) {
|
|
203
|
+
this.ref.append(...nodes);
|
|
204
|
+
} else {
|
|
205
|
+
for (const node of nodes) {
|
|
206
|
+
if (node) {
|
|
207
|
+
this.ref.appendChild(node);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
mapAppend(array, mapFn) {
|
|
214
|
+
return this.append(...array.map(mapFn));
|
|
215
|
+
}
|
|
216
|
+
prepend(...children) {
|
|
217
|
+
const nodes = _WN.unwrapAll(children);
|
|
218
|
+
if (isElementOrDocumentFragment(this.ref)) {
|
|
219
|
+
this.ref.prepend(...nodes);
|
|
220
|
+
} else {
|
|
221
|
+
const first = this.ref.firstChild;
|
|
222
|
+
for (const node of nodes) {
|
|
223
|
+
if (node) {
|
|
224
|
+
this.ref.insertBefore(node, first);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
mapPrepend(array, mapFn) {
|
|
231
|
+
return this.prepend(...array.map(mapFn));
|
|
232
|
+
}
|
|
233
|
+
on(eventName, handler) {
|
|
234
|
+
on(this.ref, eventName, handler);
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
off(eventName, handler) {
|
|
238
|
+
off(this.ref, eventName, handler);
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
rm() {
|
|
242
|
+
this.ref.parentNode?.removeChild(this.ref);
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// src/WT.ts
|
|
248
|
+
var WT = class _WT extends WN {
|
|
249
|
+
static from(text) {
|
|
250
|
+
if (!isA(text, Text)) {
|
|
251
|
+
throw new TypeError(`Expected a Text object. Got: ${text} (${typeof text})`);
|
|
252
|
+
}
|
|
253
|
+
return new _WT(text);
|
|
254
|
+
}
|
|
255
|
+
constructor(ref) {
|
|
256
|
+
if (isStr(ref)) {
|
|
257
|
+
super(document.createTextNode(ref));
|
|
258
|
+
} else if (isA(ref, Text)) {
|
|
259
|
+
super(ref);
|
|
260
|
+
}
|
|
261
|
+
throw new TypeError(`Expected a Text. Got: ${ref} (${typeof ref})`);
|
|
262
|
+
}
|
|
263
|
+
getText() {
|
|
264
|
+
return this.ref.textContent;
|
|
265
|
+
}
|
|
266
|
+
setText(text) {
|
|
267
|
+
if (!isStr(text)) {
|
|
268
|
+
throw new TypeError(`Expected a string. Got: ${text} (${typeof text})`);
|
|
269
|
+
}
|
|
270
|
+
this.ref.textContent = text;
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
empty() {
|
|
274
|
+
return this.setText("");
|
|
275
|
+
}
|
|
276
|
+
addLines(...lines) {
|
|
277
|
+
return this.setText(lines.join("\n"));
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// src/WDF.ts
|
|
282
|
+
var WDF = class _WDF extends WN {
|
|
283
|
+
static from(ref) {
|
|
284
|
+
return new _WDF(ref);
|
|
285
|
+
}
|
|
286
|
+
constructor(ref) {
|
|
287
|
+
if (!isA(ref, DocumentFragment)) {
|
|
288
|
+
throw new TypeError(`Expected a DocumentFragment. Got ${ref} (${typeof ref})`);
|
|
289
|
+
}
|
|
290
|
+
super(ref);
|
|
291
|
+
}
|
|
292
|
+
byId(id, throwIfNotFound = true) {
|
|
293
|
+
const el = this.ref.getElementById(id);
|
|
294
|
+
if (el) {
|
|
295
|
+
return WN.wrap(el);
|
|
296
|
+
}
|
|
297
|
+
if (throwIfNotFound) {
|
|
298
|
+
throw new TypeError(`Element with id ${id} not found`);
|
|
299
|
+
}
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
empty() {
|
|
303
|
+
this.ref.replaceChildren();
|
|
304
|
+
return this;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// src/WSH.ts
|
|
309
|
+
var WSH = class _WSH extends WDF {
|
|
310
|
+
static from(shadow) {
|
|
311
|
+
return new _WSH(shadow);
|
|
312
|
+
}
|
|
313
|
+
constructor(shadow) {
|
|
314
|
+
if (!isA(shadow, ShadowRoot)) {
|
|
315
|
+
throw new TypeError(`Expected a ShadowRoot. Got ${shadow} (${typeof shadow})`);
|
|
316
|
+
}
|
|
317
|
+
super(shadow);
|
|
318
|
+
}
|
|
319
|
+
getHtml() {
|
|
320
|
+
return this.ref.innerHTML;
|
|
321
|
+
}
|
|
322
|
+
setHtml(value, unsafe) {
|
|
323
|
+
this.ref.innerHTML = value;
|
|
324
|
+
return this;
|
|
325
|
+
}
|
|
326
|
+
addStyleSheets(...styleSheets) {
|
|
327
|
+
this.ref.adoptedStyleSheets.push(...styleSheets);
|
|
328
|
+
return this;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// src/WE.ts
|
|
333
|
+
var WE = class _WE extends WN {
|
|
334
|
+
static from(ref) {
|
|
335
|
+
return new _WE(ref);
|
|
336
|
+
}
|
|
337
|
+
constructor(ref) {
|
|
338
|
+
if (!isA(ref, Element)) {
|
|
339
|
+
throw new TypeError(`Expected a Element. Got: ${ref} (${typeof ref})`);
|
|
340
|
+
}
|
|
341
|
+
super(ref);
|
|
342
|
+
}
|
|
343
|
+
getAttr(name) {
|
|
344
|
+
return this.ref.getAttribute(name);
|
|
345
|
+
}
|
|
346
|
+
hasAttr(name) {
|
|
347
|
+
return this.ref.hasAttribute(name);
|
|
348
|
+
}
|
|
349
|
+
setAttr(name, value) {
|
|
350
|
+
this.ref.setAttribute(name, value);
|
|
351
|
+
return this;
|
|
352
|
+
}
|
|
353
|
+
setAttrs(obj) {
|
|
354
|
+
if (!isObj(obj)) {
|
|
355
|
+
throw new TypeError(`Expected an object. Got: ${obj} (${typeof obj})`);
|
|
356
|
+
}
|
|
357
|
+
for (const [name, value] of Object.entries(obj)) {
|
|
358
|
+
this.setAttr(name, value);
|
|
359
|
+
}
|
|
360
|
+
return this;
|
|
361
|
+
}
|
|
362
|
+
rmAttr(name) {
|
|
363
|
+
return this.rmAttrs(name);
|
|
364
|
+
}
|
|
365
|
+
rmAttrs(...names) {
|
|
366
|
+
for (const name of names) {
|
|
367
|
+
this.ref.removeAttribute(name);
|
|
368
|
+
}
|
|
369
|
+
return this;
|
|
370
|
+
}
|
|
371
|
+
getAria(name) {
|
|
372
|
+
return this.ref.getAttribute(`aria-${name}`);
|
|
373
|
+
}
|
|
374
|
+
hasAria(name) {
|
|
375
|
+
return this.ref.hasAttribute(`aria-${name}`);
|
|
376
|
+
}
|
|
377
|
+
setAria(name, value) {
|
|
378
|
+
this.ref.setAttribute(`aria-${name}`, value);
|
|
379
|
+
return this;
|
|
380
|
+
}
|
|
381
|
+
rmAria(name) {
|
|
382
|
+
this.ref.removeAttribute(`aria-${name}`);
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
addClass(...classNames) {
|
|
386
|
+
this.ref.classList.add(...classNames);
|
|
387
|
+
return this;
|
|
388
|
+
}
|
|
389
|
+
rmClasses(...classNames) {
|
|
390
|
+
this.ref.classList.remove(...classNames);
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
rmClass(className) {
|
|
394
|
+
return this.rmClasses(className);
|
|
395
|
+
}
|
|
396
|
+
hasClass(className) {
|
|
397
|
+
return this.ref.classList.contains(className);
|
|
398
|
+
}
|
|
399
|
+
toggleClass(className) {
|
|
400
|
+
this.ref.classList.toggle(className);
|
|
401
|
+
return this;
|
|
402
|
+
}
|
|
403
|
+
onClick(handler) {
|
|
404
|
+
return this.on("click", handler);
|
|
405
|
+
}
|
|
406
|
+
hide() {
|
|
407
|
+
return this.setAttr("hidden", "").setAttr("aria-hidden", "true");
|
|
408
|
+
}
|
|
409
|
+
show() {
|
|
410
|
+
return this.rmAttrs("hidden", "aria-hidden");
|
|
411
|
+
}
|
|
412
|
+
disable() {
|
|
413
|
+
return this.setAttr("disabled", "").setAttr("aria-disabled", "true");
|
|
414
|
+
}
|
|
415
|
+
enable() {
|
|
416
|
+
return this.rmAttrs("disabled", "aria-disabled");
|
|
417
|
+
}
|
|
418
|
+
getTitle() {
|
|
419
|
+
return this.getAttr("title");
|
|
420
|
+
}
|
|
421
|
+
setTitle(title) {
|
|
422
|
+
return this.setAttr("title", title);
|
|
423
|
+
}
|
|
424
|
+
setId(id) {
|
|
425
|
+
return this.setAttr("id", id);
|
|
426
|
+
}
|
|
427
|
+
getId() {
|
|
428
|
+
return this.getAttr("id");
|
|
429
|
+
}
|
|
430
|
+
getHtml() {
|
|
431
|
+
return this.ref.innerHTML;
|
|
432
|
+
}
|
|
433
|
+
setHtml(html) {
|
|
434
|
+
this.ref.innerHTML = html;
|
|
435
|
+
return this;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* @remarks
|
|
439
|
+
* **Note:** You can't attach a shadow root to every type of element. There are some that can't have a
|
|
440
|
+
* shadow DOM for security reasons (for example `<a>`).
|
|
441
|
+
*/
|
|
442
|
+
setShadow(mode = "open", html, ...styleSheets) {
|
|
443
|
+
const shadowRoot = this.ref.shadowRoot ?? this.ref.attachShadow({ mode });
|
|
444
|
+
if (html) {
|
|
445
|
+
shadowRoot.innerHTML = html;
|
|
446
|
+
}
|
|
447
|
+
if (styleSheets.length) {
|
|
448
|
+
shadowRoot.adoptedStyleSheets.push(...styleSheets);
|
|
449
|
+
}
|
|
450
|
+
return this;
|
|
451
|
+
}
|
|
452
|
+
getShadow() {
|
|
453
|
+
if (!this.ref.shadowRoot) throw new Error("No shadow root");
|
|
454
|
+
return new WSH(this.ref.shadowRoot);
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
// src/WHE.ts
|
|
459
|
+
var WHE = class _WHE extends WE {
|
|
460
|
+
static from(ref) {
|
|
461
|
+
return new _WHE(ref);
|
|
462
|
+
}
|
|
463
|
+
static fromTag(tagName, options) {
|
|
464
|
+
if (!isStr(tagName)) {
|
|
465
|
+
throw new TypeError(`Expected a string for tagName. Got: ${tagName} (${typeof tagName})`);
|
|
466
|
+
}
|
|
467
|
+
return new _WHE(document.createElement(tagName, options));
|
|
468
|
+
}
|
|
469
|
+
constructor(ref) {
|
|
470
|
+
if (!isA(ref, HTMLElement)) {
|
|
471
|
+
throw new TypeError(`Expected a HTMLElement. Got ${ref} (${typeof ref})`);
|
|
472
|
+
}
|
|
473
|
+
super(ref);
|
|
474
|
+
}
|
|
475
|
+
getValue() {
|
|
476
|
+
if (!hasProp(this.ref, "value")) {
|
|
477
|
+
throw new Error("Element does not have a value property");
|
|
478
|
+
}
|
|
479
|
+
return this.ref.value;
|
|
480
|
+
}
|
|
481
|
+
setValue(value) {
|
|
482
|
+
if (!hasProp(this.ref, "value")) {
|
|
483
|
+
throw new Error("Element does not have a value property");
|
|
484
|
+
}
|
|
485
|
+
this.ref.value = value;
|
|
486
|
+
return this;
|
|
487
|
+
}
|
|
488
|
+
getData(name) {
|
|
489
|
+
return this.ref.dataset[name];
|
|
490
|
+
}
|
|
491
|
+
hasData(name) {
|
|
492
|
+
return hasProp(this.ref.dataset, name);
|
|
493
|
+
}
|
|
494
|
+
setData(name, value) {
|
|
495
|
+
this.ref.dataset[name] = value;
|
|
496
|
+
return this;
|
|
497
|
+
}
|
|
498
|
+
setDataObj(obj) {
|
|
499
|
+
for (const [name, value] of Object.entries(obj)) {
|
|
500
|
+
this.setData(name, value);
|
|
501
|
+
}
|
|
502
|
+
return this;
|
|
503
|
+
}
|
|
504
|
+
rmData(name) {
|
|
505
|
+
delete this.ref.dataset[name];
|
|
506
|
+
return this;
|
|
507
|
+
}
|
|
508
|
+
focus() {
|
|
509
|
+
this.ref.focus();
|
|
510
|
+
return this;
|
|
511
|
+
}
|
|
512
|
+
click() {
|
|
513
|
+
this.ref.click();
|
|
514
|
+
return this;
|
|
515
|
+
}
|
|
516
|
+
empty() {
|
|
517
|
+
this.ref.innerText = "";
|
|
518
|
+
return this;
|
|
519
|
+
}
|
|
520
|
+
getText() {
|
|
521
|
+
return this.ref.innerText;
|
|
522
|
+
}
|
|
523
|
+
setText(text) {
|
|
524
|
+
this.ref.innerText = text;
|
|
525
|
+
return this;
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
// src/WC.ts
|
|
530
|
+
var ComponentFile = class {
|
|
531
|
+
constructor(as, href, loading = "lazy") {
|
|
532
|
+
this.as = as;
|
|
533
|
+
this.href = href;
|
|
534
|
+
if (!isStr(href)) {
|
|
535
|
+
throw new TypeError(`Expected a string href. Got ${href} (${typeof href})`);
|
|
536
|
+
}
|
|
537
|
+
switch (loading) {
|
|
538
|
+
case "eager":
|
|
539
|
+
this.promise;
|
|
540
|
+
break;
|
|
541
|
+
case "prefetch":
|
|
542
|
+
case "preload":
|
|
543
|
+
this.addLinkPre(loading);
|
|
544
|
+
break;
|
|
545
|
+
case "lazy":
|
|
546
|
+
break;
|
|
547
|
+
default:
|
|
548
|
+
throw new RangeError(`Expected a valid loading strategy. Got: ${loading} (${typeof loading})`);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
#promise;
|
|
552
|
+
/**
|
|
553
|
+
* Creates a <lik re="preload|prefetch"> element and adds it to the document <head> element.
|
|
554
|
+
* @param as the link "as" attribute. Use 'fetch' for HTML, 'style' for CSS, and 'script' for JavaScript
|
|
555
|
+
* @param rel when set to a truthy value, a 'preload' link is created. Otherwise a 'prefetch' is created
|
|
556
|
+
* The difference lies in the priority of loading the resource to the browser cache where preload has higher prio.
|
|
557
|
+
*/
|
|
558
|
+
addLinkPre(rel) {
|
|
559
|
+
const link = WHE.fromTag("link").setAttr("rel", rel).setAttr("href", this.href).setAttr("as", this.as);
|
|
560
|
+
document.head.append(link.ref);
|
|
561
|
+
return this;
|
|
562
|
+
}
|
|
563
|
+
get promise() {
|
|
564
|
+
if (this.#promise === void 0) {
|
|
565
|
+
this.#promise = this.fetch();
|
|
566
|
+
}
|
|
567
|
+
return this.#promise;
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
var TemplateFile = class extends ComponentFile {
|
|
571
|
+
constructor(href, loading) {
|
|
572
|
+
super("fetch", href, loading);
|
|
573
|
+
}
|
|
574
|
+
async fetch() {
|
|
575
|
+
const response = await fetch(this.href, { headers: { Accept: "text/html" } });
|
|
576
|
+
if (!response.ok) {
|
|
577
|
+
throw new Error(`GET ${this.href} failed: ${response.status} ${response.statusText}`);
|
|
578
|
+
}
|
|
579
|
+
return response.text();
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
var StyleFile = class extends ComponentFile {
|
|
583
|
+
constructor(href, loading) {
|
|
584
|
+
super("style", href, loading);
|
|
585
|
+
}
|
|
586
|
+
async fetch() {
|
|
587
|
+
const response = await fetch(this.href, { headers: { Accept: "text/css" } });
|
|
588
|
+
if (!response.ok) {
|
|
589
|
+
throw new Error(`GET ${this.href} failed: ${response.status} ${response.statusText}`);
|
|
590
|
+
}
|
|
591
|
+
const text = await response.text();
|
|
592
|
+
const sheet = new CSSStyleSheet();
|
|
593
|
+
return sheet.replace(`${text}
|
|
594
|
+
/*# sourceURL=${this.href} */`);
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
var TemplateStr = class {
|
|
598
|
+
constructor(content) {
|
|
599
|
+
if (!isStr(content)) {
|
|
600
|
+
throw new TypeError(`Expected a HTML string. Got ${content} (${typeof content})`);
|
|
601
|
+
}
|
|
602
|
+
this.promise = Promise.resolve(content);
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
var StyleStr = class {
|
|
606
|
+
constructor(css) {
|
|
607
|
+
if (!isStr(css)) {
|
|
608
|
+
throw new TypeError(`Expected a CSS string. Got ${css} (${typeof css})`);
|
|
609
|
+
}
|
|
610
|
+
const sheet = new CSSStyleSheet();
|
|
611
|
+
this.promise = sheet.replace(css);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
var WC = class extends HTMLElement {
|
|
615
|
+
static setTemplateFile(href, loading) {
|
|
616
|
+
this.jjTemplate = new TemplateFile(href, loading);
|
|
617
|
+
return this;
|
|
618
|
+
}
|
|
619
|
+
static setTemplateHtml(html) {
|
|
620
|
+
this.jjTemplate = new TemplateStr(html);
|
|
621
|
+
return this;
|
|
622
|
+
}
|
|
623
|
+
static addStyleFile(href, loading) {
|
|
624
|
+
if (!isArr(this.jjStyle)) {
|
|
625
|
+
this.jjStyle = [];
|
|
626
|
+
}
|
|
627
|
+
this.jjStyle.push(new StyleFile(href, loading));
|
|
628
|
+
return this;
|
|
629
|
+
}
|
|
630
|
+
static addStyleCss(css) {
|
|
631
|
+
if (!isArr(this.jjStyle)) {
|
|
632
|
+
this.jjStyle = [];
|
|
633
|
+
}
|
|
634
|
+
this.jjStyle.push(new StyleStr(css));
|
|
635
|
+
return this;
|
|
636
|
+
}
|
|
637
|
+
async connectedCallback() {
|
|
638
|
+
const { jjTemplate: template, jjStyle: style = [], closedShadow } = this.constructor;
|
|
639
|
+
const [html, ...styleSheets] = await Promise.all([template?.promise, ...style.map((style2) => style2.promise)]);
|
|
640
|
+
WHE.from(this).setShadow(closedShadow ? "closed" : "open", html, ...styleSheets);
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* The class that extends this one should define
|
|
644
|
+
* `static observedAttributes[]` containing kebab-based attribute names (all lower case)
|
|
645
|
+
* @param name kebab-case and in lower case exactly as it appears in `observedAttributes`
|
|
646
|
+
* @param oldValue
|
|
647
|
+
* @param newValue
|
|
648
|
+
* @returns true if it tried to set the attribute; otherwise false
|
|
649
|
+
*/
|
|
650
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
651
|
+
if (oldValue !== newValue) {
|
|
652
|
+
const observedAttributes = this.constructor.observedAttributes;
|
|
653
|
+
if (isArr(observedAttributes) && observedAttributes.includes(name)) {
|
|
654
|
+
const kebabName = keb2cam(name);
|
|
655
|
+
if (hasProp(this, kebabName)) {
|
|
656
|
+
this[kebabName] = newValue;
|
|
657
|
+
return true;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
return false;
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
// src/WN-mixin.ts
|
|
666
|
+
WN.wrap = (raw) => {
|
|
667
|
+
if (isStr(raw)) {
|
|
668
|
+
return WT.from(document.createTextNode(raw));
|
|
669
|
+
}
|
|
670
|
+
if (!isObj(raw)) {
|
|
671
|
+
throw new TypeError(`Expected an object to wrap. Got ${raw} (${typeof raw})`);
|
|
672
|
+
}
|
|
673
|
+
if (isA(raw, WN)) {
|
|
674
|
+
return raw;
|
|
675
|
+
}
|
|
676
|
+
if (isA(raw, HTMLElement)) {
|
|
677
|
+
return WHE.from(raw);
|
|
678
|
+
}
|
|
679
|
+
if (isA(raw, Element)) {
|
|
680
|
+
return WE.from(raw);
|
|
681
|
+
}
|
|
682
|
+
if (isA(raw, ShadowRoot)) {
|
|
683
|
+
return WSH.from(raw);
|
|
684
|
+
}
|
|
685
|
+
if (isA(raw, DocumentFragment)) {
|
|
686
|
+
return WDF.from(raw);
|
|
687
|
+
}
|
|
688
|
+
if (isA(raw, Text)) {
|
|
689
|
+
return WT.from(raw);
|
|
690
|
+
}
|
|
691
|
+
if (isA(raw, Node)) {
|
|
692
|
+
return WN.from(raw);
|
|
693
|
+
}
|
|
694
|
+
throw new TypeError(`Only Frag or DocumentFragment can be wrapped. Got ${raw} (${typeof raw})`);
|
|
695
|
+
};
|
|
696
|
+
WN.unwrap = (obj) => {
|
|
697
|
+
if (isStr(obj)) {
|
|
698
|
+
return document.createTextNode(obj);
|
|
699
|
+
}
|
|
700
|
+
if (!isObj(obj)) {
|
|
701
|
+
throw new TypeError(`Expected an object. Got ${obj} (${typeof obj})`);
|
|
702
|
+
}
|
|
703
|
+
if (isA(obj, Node)) {
|
|
704
|
+
return obj;
|
|
705
|
+
}
|
|
706
|
+
if (isA(obj, WN)) {
|
|
707
|
+
return obj.ref;
|
|
708
|
+
}
|
|
709
|
+
throw new TypeError(`Could not unwrap ${obj} (${typeof obj})`);
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
// src/h.ts
|
|
713
|
+
function h(tagName, attributes, ...children) {
|
|
714
|
+
const ret = WHE.fromTag(tagName).append(...children);
|
|
715
|
+
if (attributes) {
|
|
716
|
+
ret.setAttrs(attributes);
|
|
717
|
+
}
|
|
718
|
+
return ret;
|
|
719
|
+
}
|
|
720
|
+
export {
|
|
721
|
+
WC,
|
|
722
|
+
WDF,
|
|
723
|
+
WE,
|
|
724
|
+
WHE,
|
|
725
|
+
WN,
|
|
726
|
+
WSH,
|
|
727
|
+
WT,
|
|
728
|
+
ensureComponent,
|
|
729
|
+
h,
|
|
730
|
+
keb2cam,
|
|
731
|
+
keb2pas,
|
|
732
|
+
nextAnimationFrame,
|
|
733
|
+
off,
|
|
734
|
+
on,
|
|
735
|
+
pas2keb
|
|
736
|
+
};
|
|
737
|
+
//# sourceMappingURL=bundle.js.map
|