jj 2.7.2 → 2.8.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/bundle.cjs +24 -17
- package/lib/bundle.cjs.map +1 -1
- package/lib/bundle.d.cts +19 -18
- package/lib/bundle.d.ts +19 -18
- package/lib/bundle.global.js +24 -17
- package/lib/bundle.global.js.map +1 -1
- package/lib/bundle.js +24 -17
- package/lib/bundle.js.map +1 -1
- package/lib/bundle.min.cjs +1 -1
- package/lib/bundle.min.cjs.map +1 -1
- package/lib/bundle.min.d.cts +19 -18
- package/lib/bundle.min.d.ts +19 -18
- package/lib/bundle.min.global.js +1 -1
- package/lib/bundle.min.global.js.map +1 -1
- package/lib/bundle.min.js +1 -1
- package/lib/bundle.min.js.map +1 -1
- package/package.json +12 -6
package/lib/bundle.js
CHANGED
|
@@ -303,9 +303,9 @@ var JJN = class _JJN extends JJET {
|
|
|
303
303
|
* This is useful for filtering the array that is passed to `append()`, `prepend()` or `setChildren()`
|
|
304
304
|
*
|
|
305
305
|
* @param x an unknown value
|
|
306
|
-
* @returns true if `x` is a string, Node (or its
|
|
306
|
+
* @returns true if `x` is a string, Node (or its descendent), JJN (or its descendent)
|
|
307
307
|
*/
|
|
308
|
-
static
|
|
308
|
+
static isWrappable(x) {
|
|
309
309
|
return isStr(x) || isA(x, Node) || isA(x, _JJN);
|
|
310
310
|
}
|
|
311
311
|
/**
|
|
@@ -314,6 +314,7 @@ var JJN = class _JJN extends JJET {
|
|
|
314
314
|
* @remarks
|
|
315
315
|
* This function acts as a factory, inspecting the input type and returning the appropriate
|
|
316
316
|
* subclass of `JJN` (e.g., `JJHE` for `HTMLElement`, `JJT` for `Text`).
|
|
317
|
+
* JJN.ts overrides this method to a richer version that handles all subclasses of JJN.
|
|
317
318
|
*
|
|
318
319
|
* @example
|
|
319
320
|
* ```ts
|
|
@@ -326,7 +327,15 @@ var JJN = class _JJN extends JJET {
|
|
|
326
327
|
* @throws {TypeError} If the input is not a Node, string, or JJ wrapper.
|
|
327
328
|
*/
|
|
328
329
|
static wrap(raw) {
|
|
329
|
-
|
|
330
|
+
if (isObj(raw)) {
|
|
331
|
+
if (isA(raw, _JJN)) {
|
|
332
|
+
return raw;
|
|
333
|
+
}
|
|
334
|
+
if (isA(raw, Node)) {
|
|
335
|
+
return new _JJN(raw);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
throw typeErr("raw", "a Node", raw);
|
|
330
339
|
}
|
|
331
340
|
/**
|
|
332
341
|
* Extracts the underlying native DOM node from a wrapper.
|
|
@@ -429,9 +438,9 @@ var JJN = class _JJN extends JJET {
|
|
|
429
438
|
* @returns This instance for chaining.
|
|
430
439
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/createTextNode | document.createTextNode}
|
|
431
440
|
*/
|
|
432
|
-
addText(
|
|
433
|
-
if (
|
|
434
|
-
this.ref.appendChild(document.createTextNode(
|
|
441
|
+
addText(...textArr) {
|
|
442
|
+
if (textArr) {
|
|
443
|
+
this.ref.appendChild(document.createTextNode(textArr.join("")));
|
|
435
444
|
}
|
|
436
445
|
return this;
|
|
437
446
|
}
|
|
@@ -496,7 +505,7 @@ var JJNx = class extends JJN {
|
|
|
496
505
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/append | Element.append}
|
|
497
506
|
*/
|
|
498
507
|
addChild(...children) {
|
|
499
|
-
const nodes = JJN.unwrapAll(children.filter(JJN.
|
|
508
|
+
const nodes = JJN.unwrapAll(children.filter(JJN.isWrappable));
|
|
500
509
|
this.ref.append(...nodes);
|
|
501
510
|
return this;
|
|
502
511
|
}
|
|
@@ -516,7 +525,7 @@ var JJNx = class extends JJN {
|
|
|
516
525
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend | Element.prepend}
|
|
517
526
|
*/
|
|
518
527
|
preChild(...children) {
|
|
519
|
-
const nodes = JJN.unwrapAll(children.filter(JJN.
|
|
528
|
+
const nodes = JJN.unwrapAll(children.filter(JJN.isWrappable));
|
|
520
529
|
this.ref.prepend(...nodes);
|
|
521
530
|
return this;
|
|
522
531
|
}
|
|
@@ -572,7 +581,7 @@ var JJNx = class extends JJN {
|
|
|
572
581
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren | Element.replaceChildren}
|
|
573
582
|
*/
|
|
574
583
|
setChildren(...children) {
|
|
575
|
-
const nodes = JJN.unwrapAll(children.filter(JJN.
|
|
584
|
+
const nodes = JJN.unwrapAll(children.filter(JJN.isWrappable));
|
|
576
585
|
this.ref.replaceChildren(...nodes);
|
|
577
586
|
return this;
|
|
578
587
|
}
|
|
@@ -1334,7 +1343,7 @@ var JJHE = class _JJHE extends JJEx {
|
|
|
1334
1343
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText | HTMLElement.innerText}
|
|
1335
1344
|
*/
|
|
1336
1345
|
setText(text) {
|
|
1337
|
-
this.ref.innerText = text
|
|
1346
|
+
this.ref.innerText = text;
|
|
1338
1347
|
return this;
|
|
1339
1348
|
}
|
|
1340
1349
|
};
|
|
@@ -1406,7 +1415,7 @@ var JJT = class _JJT extends JJN {
|
|
|
1406
1415
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
|
|
1407
1416
|
*/
|
|
1408
1417
|
setText(text) {
|
|
1409
|
-
this.ref.textContent = text
|
|
1418
|
+
this.ref.textContent = text;
|
|
1410
1419
|
return this;
|
|
1411
1420
|
}
|
|
1412
1421
|
/**
|
|
@@ -1419,14 +1428,12 @@ var JJT = class _JJT extends JJN {
|
|
|
1419
1428
|
* console.log(text.getText()) // 'hello world'
|
|
1420
1429
|
* ```
|
|
1421
1430
|
*
|
|
1422
|
-
* @param
|
|
1431
|
+
* @param textArr - The string to add to the existing contents. If null or undefined, nothing is added.
|
|
1423
1432
|
* @returns This instance for chaining.
|
|
1424
1433
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
|
|
1425
1434
|
*/
|
|
1426
|
-
addText(
|
|
1427
|
-
|
|
1428
|
-
this.ref.textContent += text;
|
|
1429
|
-
}
|
|
1435
|
+
addText(...textArr) {
|
|
1436
|
+
this.setText(this.getText() + textArr.join(""));
|
|
1430
1437
|
return this;
|
|
1431
1438
|
}
|
|
1432
1439
|
/**
|
|
@@ -1585,7 +1592,7 @@ var JJSE = class _JJSE extends JJEx {
|
|
|
1585
1592
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
|
|
1586
1593
|
*/
|
|
1587
1594
|
setText(text) {
|
|
1588
|
-
this.ref.textContent = text
|
|
1595
|
+
this.ref.textContent = text;
|
|
1589
1596
|
return this;
|
|
1590
1597
|
}
|
|
1591
1598
|
/**
|