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