@webalternatif/js-core 1.2.0 → 1.2.1
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/dist/cjs/dom.js +23 -2
- package/dist/esm/dom.js +23 -2
- package/package.json +1 -1
- package/types/dom.d.ts +14 -2
- package/types/index.d.ts +3 -1
package/dist/cjs/dom.js
CHANGED
|
@@ -517,11 +517,12 @@ export default {
|
|
|
517
517
|
return null;
|
|
518
518
|
},
|
|
519
519
|
/**
|
|
520
|
-
* @param {NodeList} nodeList
|
|
520
|
+
* @param {NodeList|Element|Array<Element>} nodeList
|
|
521
521
|
* @returns {Element|null}
|
|
522
522
|
*/
|
|
523
523
|
first: function first(nodeList) {
|
|
524
|
-
|
|
524
|
+
if (nodeList instanceof Element) return nodeList;
|
|
525
|
+
return nodeList.length ? Array.from(nodeList)[0] : null;
|
|
525
526
|
},
|
|
526
527
|
/**
|
|
527
528
|
* @param {NodeList|Array<Element>} nodeList
|
|
@@ -592,5 +593,25 @@ export default {
|
|
|
592
593
|
if (!(e instanceof Element)) return false;
|
|
593
594
|
return selectorIsString ? !e.matches(selector) : e !== selector;
|
|
594
595
|
});
|
|
596
|
+
},
|
|
597
|
+
/**
|
|
598
|
+
* @param {Element} el
|
|
599
|
+
* @param {Element} child
|
|
600
|
+
* @param {Element} oldChild
|
|
601
|
+
*/
|
|
602
|
+
replaceChild: function replaceChild(el, child, oldChild) {
|
|
603
|
+
return el.replaceChild(child, oldChild);
|
|
604
|
+
},
|
|
605
|
+
/**
|
|
606
|
+
* @param {Element} el
|
|
607
|
+
* @param {Element[]} children
|
|
608
|
+
* @returns {Element}
|
|
609
|
+
*/
|
|
610
|
+
replaceChildren: function replaceChildren(el) {
|
|
611
|
+
for (var _len4 = arguments.length, children = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
612
|
+
children[_key4 - 1] = arguments[_key4];
|
|
613
|
+
}
|
|
614
|
+
el.replaceChildren.apply(el, children);
|
|
615
|
+
return el;
|
|
595
616
|
}
|
|
596
617
|
};
|
package/dist/esm/dom.js
CHANGED
|
@@ -517,11 +517,12 @@ export default {
|
|
|
517
517
|
return null;
|
|
518
518
|
},
|
|
519
519
|
/**
|
|
520
|
-
* @param {NodeList} nodeList
|
|
520
|
+
* @param {NodeList|Element|Array<Element>} nodeList
|
|
521
521
|
* @returns {Element|null}
|
|
522
522
|
*/
|
|
523
523
|
first: function first(nodeList) {
|
|
524
|
-
|
|
524
|
+
if (nodeList instanceof Element) return nodeList;
|
|
525
|
+
return nodeList.length ? Array.from(nodeList)[0] : null;
|
|
525
526
|
},
|
|
526
527
|
/**
|
|
527
528
|
* @param {NodeList|Array<Element>} nodeList
|
|
@@ -592,5 +593,25 @@ export default {
|
|
|
592
593
|
if (!(e instanceof Element)) return false;
|
|
593
594
|
return selectorIsString ? !e.matches(selector) : e !== selector;
|
|
594
595
|
});
|
|
596
|
+
},
|
|
597
|
+
/**
|
|
598
|
+
* @param {Element} el
|
|
599
|
+
* @param {Element} child
|
|
600
|
+
* @param {Element} oldChild
|
|
601
|
+
*/
|
|
602
|
+
replaceChild: function replaceChild(el, child, oldChild) {
|
|
603
|
+
return el.replaceChild(child, oldChild);
|
|
604
|
+
},
|
|
605
|
+
/**
|
|
606
|
+
* @param {Element} el
|
|
607
|
+
* @param {Element[]} children
|
|
608
|
+
* @returns {Element}
|
|
609
|
+
*/
|
|
610
|
+
replaceChildren: function replaceChildren(el) {
|
|
611
|
+
for (var _len4 = arguments.length, children = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
612
|
+
children[_key4 - 1] = arguments[_key4];
|
|
613
|
+
}
|
|
614
|
+
el.replaceChildren.apply(el, children);
|
|
615
|
+
return el;
|
|
595
616
|
}
|
|
596
617
|
};
|
package/package.json
CHANGED
package/types/dom.d.ts
CHANGED
|
@@ -212,10 +212,10 @@ declare namespace _default {
|
|
|
212
212
|
*/
|
|
213
213
|
function closestFindOne(el: Element, selectorClosest: string, selectorFindOne: string): Element | null;
|
|
214
214
|
/**
|
|
215
|
-
* @param {NodeList} nodeList
|
|
215
|
+
* @param {NodeList|Element|Array<Element>} nodeList
|
|
216
216
|
* @returns {Element|null}
|
|
217
217
|
*/
|
|
218
|
-
function first(nodeList: NodeList): Element | null;
|
|
218
|
+
function first(nodeList: NodeList | Element | Array<Element>): Element | null;
|
|
219
219
|
/**
|
|
220
220
|
* @param {NodeList|Array<Element>} nodeList
|
|
221
221
|
* @returns {Element|null}
|
|
@@ -255,5 +255,17 @@ declare namespace _default {
|
|
|
255
255
|
* @return {Element[]}
|
|
256
256
|
*/
|
|
257
257
|
function not(el: Element | NodeList, selector: string | Element): Element[];
|
|
258
|
+
/**
|
|
259
|
+
* @param {Element} el
|
|
260
|
+
* @param {Element} child
|
|
261
|
+
* @param {Element} oldChild
|
|
262
|
+
*/
|
|
263
|
+
function replaceChild(el: Element, child: Element, oldChild: Element): Element;
|
|
264
|
+
/**
|
|
265
|
+
* @param {Element} el
|
|
266
|
+
* @param {Element[]} children
|
|
267
|
+
* @returns {Element}
|
|
268
|
+
*/
|
|
269
|
+
function replaceChildren(el: Element, ...children: Element[]): Element;
|
|
258
270
|
}
|
|
259
271
|
export default _default;
|
package/types/index.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ declare const webf: {
|
|
|
66
66
|
} | string, value?: string): Element;
|
|
67
67
|
closestFind(el: Element, selectorClosest: string, selectorFind: string): NodeList | null;
|
|
68
68
|
closestFindOne(el: Element, selectorClosest: string, selectorFindOne: string): Element | null;
|
|
69
|
-
first(nodeList: NodeList): Element | null;
|
|
69
|
+
first(nodeList: NodeList | Element | Array<Element>): Element | null;
|
|
70
70
|
last(nodeList: NodeList | Array<Element>): Element | null;
|
|
71
71
|
create(html: string): Element | null;
|
|
72
72
|
eq(nodeList: NodeList, index?: number): Element | null;
|
|
@@ -74,6 +74,8 @@ declare const webf: {
|
|
|
74
74
|
before(el: Element, newEl: Element): Element;
|
|
75
75
|
empty(el: Element): Element;
|
|
76
76
|
not(el: Element | NodeList, selector: string | Element): Element[];
|
|
77
|
+
replaceChild(el: Element, child: Element, oldChild: Element): Element;
|
|
78
|
+
replaceChildren(el: Element, ...children: Element[]): Element;
|
|
77
79
|
};
|
|
78
80
|
isWindow: (o: any) => boolean;
|
|
79
81
|
isDomElement: (o: any) => boolean;
|