jj 2.7.2 → 2.9.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/SKILL.md +20 -2
- package/lib/bundle.cjs +85 -17
- package/lib/bundle.cjs.map +1 -1
- package/lib/bundle.d.cts +69 -18
- package/lib/bundle.d.ts +69 -18
- package/lib/bundle.global.js +85 -17
- package/lib/bundle.global.js.map +1 -1
- package/lib/bundle.js +85 -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 +69 -18
- package/lib/bundle.min.d.ts +69 -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.
|
|
@@ -403,6 +412,44 @@ var JJN = class _JJN extends JJET {
|
|
|
403
412
|
}
|
|
404
413
|
super(ref);
|
|
405
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* Gets the parent node wrapped in the most specific JJ wrapper available.
|
|
417
|
+
*
|
|
418
|
+
* @remarks
|
|
419
|
+
* Returns `null` when this node is detached and therefore has no parent.
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ```ts
|
|
423
|
+
* const text = JJT.fromStr('hello')
|
|
424
|
+
* JJHE.create('div').addChild(text)
|
|
425
|
+
* const parent = text.parent // JJHE
|
|
426
|
+
* ```
|
|
427
|
+
*
|
|
428
|
+
* @returns The wrapped parent node, or `null` if this node has no parent.
|
|
429
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/parentNode | Node.parentNode}
|
|
430
|
+
*/
|
|
431
|
+
get parent() {
|
|
432
|
+
const { parentNode } = this.ref;
|
|
433
|
+
return parentNode ? _JJN.wrap(parentNode) : null;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Gets the child nodes wrapped in the most specific JJ wrappers available.
|
|
437
|
+
*
|
|
438
|
+
* @remarks
|
|
439
|
+
* Returns an empty array when this node has no children.
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```ts
|
|
443
|
+
* const el = JJHE.create('div').addChild('hello', JJHE.create('span'))
|
|
444
|
+
* const children = el.children // [JJT, JJHE]
|
|
445
|
+
* ```
|
|
446
|
+
*
|
|
447
|
+
* @returns The wrapped child nodes.
|
|
448
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes | Node.childNodes}
|
|
449
|
+
*/
|
|
450
|
+
get children() {
|
|
451
|
+
return _JJN.wrapAll(this.ref.childNodes);
|
|
452
|
+
}
|
|
406
453
|
/**
|
|
407
454
|
* Clones the Node.
|
|
408
455
|
*
|
|
@@ -413,6 +460,29 @@ var JJN = class _JJN extends JJET {
|
|
|
413
460
|
clone(deep) {
|
|
414
461
|
return _JJN.wrap(this.ref.cloneNode(deep));
|
|
415
462
|
}
|
|
463
|
+
/**
|
|
464
|
+
* Removes this node from its parent.
|
|
465
|
+
*
|
|
466
|
+
* @remarks
|
|
467
|
+
* If the node has no parent, this method does nothing.
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```ts
|
|
471
|
+
* const el = JJHE.create('div')
|
|
472
|
+
* doc.body.addChild(el)
|
|
473
|
+
* el.rm()
|
|
474
|
+
* ```
|
|
475
|
+
*
|
|
476
|
+
* @returns This instance for chaining.
|
|
477
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild | Node.removeChild}
|
|
478
|
+
*/
|
|
479
|
+
rm() {
|
|
480
|
+
const { parentNode } = this.ref;
|
|
481
|
+
if (parentNode) {
|
|
482
|
+
parentNode.removeChild(this.ref);
|
|
483
|
+
}
|
|
484
|
+
return this;
|
|
485
|
+
}
|
|
416
486
|
/**
|
|
417
487
|
* Creates a Text node from a string and appends it to this Node.
|
|
418
488
|
*
|
|
@@ -429,9 +499,9 @@ var JJN = class _JJN extends JJET {
|
|
|
429
499
|
* @returns This instance for chaining.
|
|
430
500
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/createTextNode | document.createTextNode}
|
|
431
501
|
*/
|
|
432
|
-
addText(
|
|
433
|
-
if (
|
|
434
|
-
this.ref.appendChild(document.createTextNode(
|
|
502
|
+
addText(...textArr) {
|
|
503
|
+
if (textArr) {
|
|
504
|
+
this.ref.appendChild(document.createTextNode(textArr.join("")));
|
|
435
505
|
}
|
|
436
506
|
return this;
|
|
437
507
|
}
|
|
@@ -496,7 +566,7 @@ var JJNx = class extends JJN {
|
|
|
496
566
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/append | Element.append}
|
|
497
567
|
*/
|
|
498
568
|
addChild(...children) {
|
|
499
|
-
const nodes = JJN.unwrapAll(children.filter(JJN.
|
|
569
|
+
const nodes = JJN.unwrapAll(children.filter(JJN.isWrappable));
|
|
500
570
|
this.ref.append(...nodes);
|
|
501
571
|
return this;
|
|
502
572
|
}
|
|
@@ -516,7 +586,7 @@ var JJNx = class extends JJN {
|
|
|
516
586
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend | Element.prepend}
|
|
517
587
|
*/
|
|
518
588
|
preChild(...children) {
|
|
519
|
-
const nodes = JJN.unwrapAll(children.filter(JJN.
|
|
589
|
+
const nodes = JJN.unwrapAll(children.filter(JJN.isWrappable));
|
|
520
590
|
this.ref.prepend(...nodes);
|
|
521
591
|
return this;
|
|
522
592
|
}
|
|
@@ -572,7 +642,7 @@ var JJNx = class extends JJN {
|
|
|
572
642
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren | Element.replaceChildren}
|
|
573
643
|
*/
|
|
574
644
|
setChildren(...children) {
|
|
575
|
-
const nodes = JJN.unwrapAll(children.filter(JJN.
|
|
645
|
+
const nodes = JJN.unwrapAll(children.filter(JJN.isWrappable));
|
|
576
646
|
this.ref.replaceChildren(...nodes);
|
|
577
647
|
return this;
|
|
578
648
|
}
|
|
@@ -1334,7 +1404,7 @@ var JJHE = class _JJHE extends JJEx {
|
|
|
1334
1404
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText | HTMLElement.innerText}
|
|
1335
1405
|
*/
|
|
1336
1406
|
setText(text) {
|
|
1337
|
-
this.ref.innerText = text
|
|
1407
|
+
this.ref.innerText = text;
|
|
1338
1408
|
return this;
|
|
1339
1409
|
}
|
|
1340
1410
|
};
|
|
@@ -1406,7 +1476,7 @@ var JJT = class _JJT extends JJN {
|
|
|
1406
1476
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
|
|
1407
1477
|
*/
|
|
1408
1478
|
setText(text) {
|
|
1409
|
-
this.ref.textContent = text
|
|
1479
|
+
this.ref.textContent = text;
|
|
1410
1480
|
return this;
|
|
1411
1481
|
}
|
|
1412
1482
|
/**
|
|
@@ -1419,14 +1489,12 @@ var JJT = class _JJT extends JJN {
|
|
|
1419
1489
|
* console.log(text.getText()) // 'hello world'
|
|
1420
1490
|
* ```
|
|
1421
1491
|
*
|
|
1422
|
-
* @param
|
|
1492
|
+
* @param textArr - The string to add to the existing contents. If null or undefined, nothing is added.
|
|
1423
1493
|
* @returns This instance for chaining.
|
|
1424
1494
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
|
|
1425
1495
|
*/
|
|
1426
|
-
addText(
|
|
1427
|
-
|
|
1428
|
-
this.ref.textContent += text;
|
|
1429
|
-
}
|
|
1496
|
+
addText(...textArr) {
|
|
1497
|
+
this.setText(this.getText() + textArr.join(""));
|
|
1430
1498
|
return this;
|
|
1431
1499
|
}
|
|
1432
1500
|
/**
|
|
@@ -1585,7 +1653,7 @@ var JJSE = class _JJSE extends JJEx {
|
|
|
1585
1653
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
|
|
1586
1654
|
*/
|
|
1587
1655
|
setText(text) {
|
|
1588
|
-
this.ref.textContent = text
|
|
1656
|
+
this.ref.textContent = text;
|
|
1589
1657
|
return this;
|
|
1590
1658
|
}
|
|
1591
1659
|
/**
|