/
ParentNode.iface.ts
83 lines (78 loc) · 3.23 KB
/
ParentNode.iface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { Content } from '../ambient.d'
import xjs_Element from '../class/Element.class'
/**
* Wrapper for a ParentNode.
* @see https://www.w3.org/TR/dom/#interface-parentnode
*/
export default interface xjs_ParentNode {
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/prepend|ParentNode#prepend},
* but return this object when done.
*
* This method exists simply for chaining.
*
* ```js
* let strong = document.createElement('strong')
* strong.textContent = 'hello'
* let em = document.createElement('em')
* let mark = document.createElement('mark')
*
* this.prepend(...[
* strong, // DOM Node
* ` to the `, // string
* new Comment(`great`), // DOM Node
* `<small>big</small> `, // string with HTML
* new xjs.Element(em).addContent(`world`).node, // DOM Node (unwrapped)
* null, // null
* new xjs.Element(mark).addContent(`!`), // wrapped DOM Node
* ]).node.querySelector('body').innerHTML
* // `<strong>hello</strong> to the <!--great--><small>big</small> <em>world</em><mark>!</mark>`
* ```
* @see https://dom.spec.whatwg.org/#dom-parentnode-prepend
* @param contents the contents to prepend
* @returns `this`
*/
prepend(...contents: Content[]): this;
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append|ParentNode#append},
* but return this object when done.
*
* This method exists simply for chaining.
*
* ```js
* let strong = document.createElement('strong')
* strong.textContent = 'hello'
* let em = document.createElement('em')
* let mark = document.createElement('mark')
*
* this.append(...[
* strong, // DOM Node
* ` to the `, // string
* new Comment(`great`), // DOM Node
* `<small>big</small> `, // string with HTML
* new xjs.Element(em).addContent(`world`).node, // DOM Node (unwrapped)
* null, // null
* new xjs.Element(mark).addContent(`!`), // wrapped DOM Node
* ]).node.querySelector('body').innerHTML
* // `<strong>hello</strong> to the <!--great--><small>big</small> <em>world</em><mark>!</mark>`
* ```
* @see https://dom.spec.whatwg.org/#dom-parentnode-append
* @param contents the contents to append
* @returns `this`
*/
append(...contents: Content[]): this;
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/querySelector|ParentNode#querySelector},
* but return the wrapped element.
* @param selector the selector of the element to match
* @returns the first matched element, wrapped, or `null` if there is no match
*/
querySelector(selector: string): xjs_Element|null;
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/querySelectorAll|ParentNode#querySelectorAll},
* but return an array of wrapped elements.
* @param selector the selector of the element(s) to match
* @returns a (possibly empty) array of matched elements, wrapped
*/
querySelectorAll(selector: string): xjs_Element[];
}