pseudo-dom 0.7.0 → 0.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/README.md +468 -237
- package/browser/pseudo-dom.js +986 -563
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/classes/PseudoHTMLDocument.d.ts +17 -43
- package/dist/classes/PseudoHTMLDocument.js +24 -94
- package/dist/classes/PseudoHTMLDocument.min.js +1 -1
- package/dist/factories/createDataset.d.ts +10 -0
- package/dist/factories/createDataset.js +78 -0
- package/dist/factories/createDataset.min.js +1 -0
- package/dist/factories/createStyleDeclaration.d.ts +30 -0
- package/dist/factories/createStyleDeclaration.js +64 -0
- package/dist/factories/createStyleDeclaration.min.js +1 -0
- package/dist/factories/cssSelectAdapter.d.ts +23 -23
- package/dist/factories/cssSelectAdapter.js +87 -87
- package/dist/factories/query.d.ts +33 -33
- package/dist/factories/query.js +66 -66
- package/dist/functions/getElementById.d.ts +13 -0
- package/dist/functions/getElementById.js +33 -0
- package/dist/functions/getElementById.min.js +1 -0
- package/dist/interfaces/PseudoCSSStyleDeclaration.d.ts +14 -0
- package/dist/interfaces/PseudoCSSStyleDeclaration.js +5 -0
- package/dist/interfaces/PseudoCSSStyleDeclaration.min.js +1 -0
- package/dist/interfaces/PseudoDocument.d.ts +35 -10
- package/dist/interfaces/PseudoDocumentFragment.d.ts +7 -0
- package/dist/interfaces/PseudoElement.d.ts +702 -702
- package/dist/interfaces/PseudoHTMLElement.d.ts +33 -22
- package/dist/services/CSSStyleDeclarationService.d.ts +73 -0
- package/dist/services/CSSStyleDeclarationService.js +156 -0
- package/dist/services/CSSStyleDeclarationService.min.js +1 -0
- package/dist/services/DocumentFragmentService.d.ts +8 -0
- package/dist/services/DocumentFragmentService.js +18 -0
- package/dist/services/DocumentFragmentService.min.js +1 -1
- package/dist/services/DocumentService.d.ts +46 -19
- package/dist/services/DocumentService.js +95 -46
- package/dist/services/DocumentService.min.js +1 -1
- package/dist/services/ElementService.d.ts +191 -191
- package/dist/services/ElementService.js +426 -426
- package/dist/services/HTMLCollectionService.d.ts +54 -54
- package/dist/services/HTMLCollectionService.js +92 -92
- package/dist/services/HTMLElementService.d.ts +87 -57
- package/dist/services/HTMLElementService.js +202 -163
- package/dist/services/HTMLElementService.min.js +1 -1
- package/dist/services/NodeService.d.ts +297 -297
- package/dist/services/NodeService.js +721 -721
- package/package.json +2 -2
- package/dist/classes.d.ts +0 -20
- package/dist/classes.js +0 -31
- package/dist/classes.min.js +0 -1
- package/dist/factories/generateNode.d.ts +0 -32
- package/dist/factories/generateNode.js +0 -85
- package/dist/factories/generateNode.min.js +0 -1
- package/dist/factories.d.ts +0 -11
- package/dist/factories.js +0 -27
- package/dist/factories.min.js +0 -1
- package/dist/functions.d.ts +0 -5
- package/dist/functions.js +0 -23
- package/dist/functions.min.js +0 -1
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
require('core-js/modules/esnext.iterator.constructor.js')
|
|
4
|
-
require('core-js/modules/esnext.iterator.filter.js')
|
|
5
|
-
require('core-js/modules/esnext.iterator.for-each.js')
|
|
6
|
-
require('core-js/modules/esnext.iterator.some.js')
|
|
7
|
-
Object.defineProperty(exports, '__esModule', {
|
|
8
|
-
value: true
|
|
9
|
-
})
|
|
10
|
-
exports.cssSelectAdapter = void 0
|
|
11
|
-
/**
|
|
12
|
-
* @file The css-select Adapter which lets it query pseudo-dom's own tree, instead of the domutils-based tree it
|
|
13
|
-
* defaults to.
|
|
14
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
15
|
-
* @version 1.0.0
|
|
16
|
-
*/
|
|
17
|
-
const NodeService_1 = require('../services/NodeService')
|
|
18
|
-
/**
|
|
19
|
-
* Walk up from a node (not including it) to find the nearest element, in the given direction.
|
|
20
|
-
* @param {*} node The node to start from
|
|
21
|
-
* @param {'nextSibling'|'previousSibling'} direction Which sibling reference to follow
|
|
22
|
-
* @returns {*|null}
|
|
23
|
-
*/
|
|
24
|
-
const nearestElementSibling = (node, direction) => {
|
|
25
|
-
let current = node ? node[direction] : null
|
|
26
|
-
while (current && current.nodeType !== NodeService_1.NodeService.ELEMENT_NODE) {
|
|
27
|
-
current = current[direction]
|
|
28
|
-
}
|
|
29
|
-
return current || null
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Maps pseudo-dom's own Node / Element API onto the Adapter interface css-select needs to query a tree which is not
|
|
33
|
-
* domutils' own (css-select's own Adapter<Node, ElementNode> type). Every method here is one pseudo-dom already has
|
|
34
|
-
* under a different name; nothing here reimplements DOM behaviour.
|
|
35
|
-
* @memberOf module:factories
|
|
36
|
-
* @type {Object}
|
|
37
|
-
*/
|
|
38
|
-
exports.cssSelectAdapter = {
|
|
39
|
-
isTag: node => !!node && node.nodeType === NodeService_1.NodeService.ELEMENT_NODE,
|
|
40
|
-
existsOne: (test, elems) => elems.some(elem => exports.cssSelectAdapter.isTag(elem) && (test(elem) || exports.cssSelectAdapter.existsOne(test, exports.cssSelectAdapter.getChildren(elem)))),
|
|
41
|
-
// pseudo-dom's className / classList are kept in sync with each other, but not with a literal 'class' attribute
|
|
42
|
-
// (there is no such special-cased attribute here, unlike a real DOM) - so the 'class' css-select needs for class
|
|
43
|
-
// selectors is read from className instead.
|
|
44
|
-
getAttributeValue: (elem, name) => {
|
|
45
|
-
const value = name === 'class' ? elem.className : elem.getAttribute(name)
|
|
46
|
-
return value === null || value === undefined ? undefined : value
|
|
47
|
-
},
|
|
48
|
-
getChildren: node => Array.from(node.childNodes),
|
|
49
|
-
getName: elem => elem.tagName,
|
|
50
|
-
getParent: node => node.parentNode,
|
|
51
|
-
// Unlike jQuery's siblings(), this is expected to include the node itself
|
|
52
|
-
getSiblings: node => node.parentNode ? Array.from(node.parentNode.childNodes) : [node],
|
|
53
|
-
prevElementSibling: node => nearestElementSibling(node, 'previousSibling'),
|
|
54
|
-
getText: node => node.textContent || '',
|
|
55
|
-
hasAttrib: (elem, name) => elem.hasAttribute(name),
|
|
56
|
-
removeSubsets: nodes => nodes.filter((node, index) => !nodes.some((other, otherIndex) => otherIndex !== index && typeof other.contains === 'function' && other !== node && other.contains(node))),
|
|
57
|
-
findAll: (test, nodes) => {
|
|
58
|
-
const found = []
|
|
59
|
-
const visit = list => list.forEach(node => {
|
|
60
|
-
if (!exports.cssSelectAdapter.isTag(node)) {
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
if (test(node)) {
|
|
64
|
-
found.push(node)
|
|
65
|
-
}
|
|
66
|
-
visit(exports.cssSelectAdapter.getChildren(node))
|
|
67
|
-
})
|
|
68
|
-
visit(nodes)
|
|
69
|
-
return found
|
|
70
|
-
},
|
|
71
|
-
findOne: (test, nodes) => {
|
|
72
|
-
for (const node of nodes) {
|
|
73
|
-
if (!exports.cssSelectAdapter.isTag(node)) {
|
|
74
|
-
continue
|
|
75
|
-
}
|
|
76
|
-
if (test(node)) {
|
|
77
|
-
return node
|
|
78
|
-
}
|
|
79
|
-
const inChildren = exports.cssSelectAdapter.findOne(test, exports.cssSelectAdapter.getChildren(node))
|
|
80
|
-
if (inChildren) {
|
|
81
|
-
return inChildren
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return null
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.default = exports.cssSelectAdapter
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
4
|
+
require('core-js/modules/esnext.iterator.filter.js')
|
|
5
|
+
require('core-js/modules/esnext.iterator.for-each.js')
|
|
6
|
+
require('core-js/modules/esnext.iterator.some.js')
|
|
7
|
+
Object.defineProperty(exports, '__esModule', {
|
|
8
|
+
value: true
|
|
9
|
+
})
|
|
10
|
+
exports.cssSelectAdapter = void 0
|
|
11
|
+
/**
|
|
12
|
+
* @file The css-select Adapter which lets it query pseudo-dom's own tree, instead of the domutils-based tree it
|
|
13
|
+
* defaults to.
|
|
14
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
15
|
+
* @version 1.0.0
|
|
16
|
+
*/
|
|
17
|
+
const NodeService_1 = require('../services/NodeService')
|
|
18
|
+
/**
|
|
19
|
+
* Walk up from a node (not including it) to find the nearest element, in the given direction.
|
|
20
|
+
* @param {*} node The node to start from
|
|
21
|
+
* @param {'nextSibling'|'previousSibling'} direction Which sibling reference to follow
|
|
22
|
+
* @returns {*|null}
|
|
23
|
+
*/
|
|
24
|
+
const nearestElementSibling = (node, direction) => {
|
|
25
|
+
let current = node ? node[direction] : null
|
|
26
|
+
while (current && current.nodeType !== NodeService_1.NodeService.ELEMENT_NODE) {
|
|
27
|
+
current = current[direction]
|
|
28
|
+
}
|
|
29
|
+
return current || null
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Maps pseudo-dom's own Node / Element API onto the Adapter interface css-select needs to query a tree which is not
|
|
33
|
+
* domutils' own (css-select's own Adapter<Node, ElementNode> type). Every method here is one pseudo-dom already has
|
|
34
|
+
* under a different name; nothing here reimplements DOM behaviour.
|
|
35
|
+
* @memberOf module:factories
|
|
36
|
+
* @type {Object}
|
|
37
|
+
*/
|
|
38
|
+
exports.cssSelectAdapter = {
|
|
39
|
+
isTag: node => !!node && node.nodeType === NodeService_1.NodeService.ELEMENT_NODE,
|
|
40
|
+
existsOne: (test, elems) => elems.some(elem => exports.cssSelectAdapter.isTag(elem) && (test(elem) || exports.cssSelectAdapter.existsOne(test, exports.cssSelectAdapter.getChildren(elem)))),
|
|
41
|
+
// pseudo-dom's className / classList are kept in sync with each other, but not with a literal 'class' attribute
|
|
42
|
+
// (there is no such special-cased attribute here, unlike a real DOM) - so the 'class' css-select needs for class
|
|
43
|
+
// selectors is read from className instead.
|
|
44
|
+
getAttributeValue: (elem, name) => {
|
|
45
|
+
const value = name === 'class' ? elem.className : elem.getAttribute(name)
|
|
46
|
+
return value === null || value === undefined ? undefined : value
|
|
47
|
+
},
|
|
48
|
+
getChildren: node => Array.from(node.childNodes),
|
|
49
|
+
getName: elem => elem.tagName,
|
|
50
|
+
getParent: node => node.parentNode,
|
|
51
|
+
// Unlike jQuery's siblings(), this is expected to include the node itself
|
|
52
|
+
getSiblings: node => node.parentNode ? Array.from(node.parentNode.childNodes) : [node],
|
|
53
|
+
prevElementSibling: node => nearestElementSibling(node, 'previousSibling'),
|
|
54
|
+
getText: node => node.textContent || '',
|
|
55
|
+
hasAttrib: (elem, name) => elem.hasAttribute(name),
|
|
56
|
+
removeSubsets: nodes => nodes.filter((node, index) => !nodes.some((other, otherIndex) => otherIndex !== index && typeof other.contains === 'function' && other !== node && other.contains(node))),
|
|
57
|
+
findAll: (test, nodes) => {
|
|
58
|
+
const found = []
|
|
59
|
+
const visit = list => list.forEach(node => {
|
|
60
|
+
if (!exports.cssSelectAdapter.isTag(node)) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
if (test(node)) {
|
|
64
|
+
found.push(node)
|
|
65
|
+
}
|
|
66
|
+
visit(exports.cssSelectAdapter.getChildren(node))
|
|
67
|
+
})
|
|
68
|
+
visit(nodes)
|
|
69
|
+
return found
|
|
70
|
+
},
|
|
71
|
+
findOne: (test, nodes) => {
|
|
72
|
+
for (const node of nodes) {
|
|
73
|
+
if (!exports.cssSelectAdapter.isTag(node)) {
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
76
|
+
if (test(node)) {
|
|
77
|
+
return node
|
|
78
|
+
}
|
|
79
|
+
const inChildren = exports.cssSelectAdapter.findOne(test, exports.cssSelectAdapter.getChildren(node))
|
|
80
|
+
if (inChildren) {
|
|
81
|
+
return inChildren
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.default = exports.cssSelectAdapter
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* All of the elements below (not including) scope which match the selector, in tree order.
|
|
3
|
-
* @memberOf module:factories
|
|
4
|
-
* @param {string} selector A CSS selector
|
|
5
|
-
* @param {*} scope The node to search below
|
|
6
|
-
* @returns {Array<*>}
|
|
7
|
-
*/
|
|
8
|
-
export declare const querySelectorAll: (selector: string, scope: any) => Array<any>;
|
|
9
|
-
/**
|
|
10
|
-
* The first element below (not including) scope which matches the selector, in tree order, or null when there is none.
|
|
11
|
-
* @memberOf module:factories
|
|
12
|
-
* @param {string} selector A CSS selector
|
|
13
|
-
* @param {*} scope The node to search below
|
|
14
|
-
* @returns {*|null}
|
|
15
|
-
*/
|
|
16
|
-
export declare const querySelector: (selector: string, scope: any) => any | null;
|
|
17
|
-
/**
|
|
18
|
-
* Whether an element itself (not its descendants) matches the selector.
|
|
19
|
-
* @memberOf module:factories
|
|
20
|
-
* @param {*} element The element to test
|
|
21
|
-
* @param {string} selector A CSS selector
|
|
22
|
-
* @returns {boolean}
|
|
23
|
-
*/
|
|
24
|
-
export declare const matches: (element: any, selector: string) => boolean;
|
|
25
|
-
/**
|
|
26
|
-
* The nearest ancestor of an element (starting with the element itself) which matches the selector, or null when
|
|
27
|
-
* none of them do.
|
|
28
|
-
* @memberOf module:factories
|
|
29
|
-
* @param {*} element The element to start from
|
|
30
|
-
* @param {string} selector A CSS selector
|
|
31
|
-
* @returns {*|null}
|
|
32
|
-
*/
|
|
33
|
-
export declare const closest: (element: any, selector: string) => any | null;
|
|
1
|
+
/**
|
|
2
|
+
* All of the elements below (not including) scope which match the selector, in tree order.
|
|
3
|
+
* @memberOf module:factories
|
|
4
|
+
* @param {string} selector A CSS selector
|
|
5
|
+
* @param {*} scope The node to search below
|
|
6
|
+
* @returns {Array<*>}
|
|
7
|
+
*/
|
|
8
|
+
export declare const querySelectorAll: (selector: string, scope: any) => Array<any>;
|
|
9
|
+
/**
|
|
10
|
+
* The first element below (not including) scope which matches the selector, in tree order, or null when there is none.
|
|
11
|
+
* @memberOf module:factories
|
|
12
|
+
* @param {string} selector A CSS selector
|
|
13
|
+
* @param {*} scope The node to search below
|
|
14
|
+
* @returns {*|null}
|
|
15
|
+
*/
|
|
16
|
+
export declare const querySelector: (selector: string, scope: any) => any | null;
|
|
17
|
+
/**
|
|
18
|
+
* Whether an element itself (not its descendants) matches the selector.
|
|
19
|
+
* @memberOf module:factories
|
|
20
|
+
* @param {*} element The element to test
|
|
21
|
+
* @param {string} selector A CSS selector
|
|
22
|
+
* @returns {boolean}
|
|
23
|
+
*/
|
|
24
|
+
export declare const matches: (element: any, selector: string) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The nearest ancestor of an element (starting with the element itself) which matches the selector, or null when
|
|
27
|
+
* none of them do.
|
|
28
|
+
* @memberOf module:factories
|
|
29
|
+
* @param {*} element The element to start from
|
|
30
|
+
* @param {string} selector A CSS selector
|
|
31
|
+
* @returns {*|null}
|
|
32
|
+
*/
|
|
33
|
+
export declare const closest: (element: any, selector: string) => any | null;
|
package/dist/factories/query.js
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.closest = exports.matches = exports.querySelector = exports.querySelectorAll = void 0
|
|
7
|
-
/**
|
|
8
|
-
* @file Selector queries (querySelector, querySelectorAll, matches, closest), built on css-select and the
|
|
9
|
-
* cssSelectAdapter which lets it query pseudo-dom's own tree.
|
|
10
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
11
|
-
* @version 1.0.0
|
|
12
|
-
*/
|
|
13
|
-
const css_select_1 = require('css-select')
|
|
14
|
-
const cssSelectAdapter_1 = require('./cssSelectAdapter')
|
|
15
|
-
/**
|
|
16
|
-
* All of the elements below (not including) scope which match the selector, in tree order.
|
|
17
|
-
* @memberOf module:factories
|
|
18
|
-
* @param {string} selector A CSS selector
|
|
19
|
-
* @param {*} scope The node to search below
|
|
20
|
-
* @returns {Array<*>}
|
|
21
|
-
*/
|
|
22
|
-
const querySelectorAll = (selector, scope) => (0, css_select_1.selectAll)(selector, scope, {
|
|
23
|
-
adapter: cssSelectAdapter_1.cssSelectAdapter
|
|
24
|
-
})
|
|
25
|
-
exports.querySelectorAll = querySelectorAll
|
|
26
|
-
/**
|
|
27
|
-
* The first element below (not including) scope which matches the selector, in tree order, or null when there is none.
|
|
28
|
-
* @memberOf module:factories
|
|
29
|
-
* @param {string} selector A CSS selector
|
|
30
|
-
* @param {*} scope The node to search below
|
|
31
|
-
* @returns {*|null}
|
|
32
|
-
*/
|
|
33
|
-
const querySelector = (selector, scope) => (0, css_select_1.selectOne)(selector, scope, {
|
|
34
|
-
adapter: cssSelectAdapter_1.cssSelectAdapter
|
|
35
|
-
})
|
|
36
|
-
exports.querySelector = querySelector
|
|
37
|
-
/**
|
|
38
|
-
* Whether an element itself (not its descendants) matches the selector.
|
|
39
|
-
* @memberOf module:factories
|
|
40
|
-
* @param {*} element The element to test
|
|
41
|
-
* @param {string} selector A CSS selector
|
|
42
|
-
* @returns {boolean}
|
|
43
|
-
*/
|
|
44
|
-
const matches = (element, selector) => (0, css_select_1.is)(element, selector, {
|
|
45
|
-
adapter: cssSelectAdapter_1.cssSelectAdapter
|
|
46
|
-
})
|
|
47
|
-
exports.matches = matches
|
|
48
|
-
/**
|
|
49
|
-
* The nearest ancestor of an element (starting with the element itself) which matches the selector, or null when
|
|
50
|
-
* none of them do.
|
|
51
|
-
* @memberOf module:factories
|
|
52
|
-
* @param {*} element The element to start from
|
|
53
|
-
* @param {string} selector A CSS selector
|
|
54
|
-
* @returns {*|null}
|
|
55
|
-
*/
|
|
56
|
-
const closest = (element, selector) => {
|
|
57
|
-
let current = element
|
|
58
|
-
while (current && cssSelectAdapter_1.cssSelectAdapter.isTag(current)) {
|
|
59
|
-
if ((0, exports.matches)(current, selector)) {
|
|
60
|
-
return current
|
|
61
|
-
}
|
|
62
|
-
current = current.parentNode
|
|
63
|
-
}
|
|
64
|
-
return null
|
|
65
|
-
}
|
|
66
|
-
exports.closest = closest
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.closest = exports.matches = exports.querySelector = exports.querySelectorAll = void 0
|
|
7
|
+
/**
|
|
8
|
+
* @file Selector queries (querySelector, querySelectorAll, matches, closest), built on css-select and the
|
|
9
|
+
* cssSelectAdapter which lets it query pseudo-dom's own tree.
|
|
10
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
11
|
+
* @version 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
const css_select_1 = require('css-select')
|
|
14
|
+
const cssSelectAdapter_1 = require('./cssSelectAdapter')
|
|
15
|
+
/**
|
|
16
|
+
* All of the elements below (not including) scope which match the selector, in tree order.
|
|
17
|
+
* @memberOf module:factories
|
|
18
|
+
* @param {string} selector A CSS selector
|
|
19
|
+
* @param {*} scope The node to search below
|
|
20
|
+
* @returns {Array<*>}
|
|
21
|
+
*/
|
|
22
|
+
const querySelectorAll = (selector, scope) => (0, css_select_1.selectAll)(selector, scope, {
|
|
23
|
+
adapter: cssSelectAdapter_1.cssSelectAdapter
|
|
24
|
+
})
|
|
25
|
+
exports.querySelectorAll = querySelectorAll
|
|
26
|
+
/**
|
|
27
|
+
* The first element below (not including) scope which matches the selector, in tree order, or null when there is none.
|
|
28
|
+
* @memberOf module:factories
|
|
29
|
+
* @param {string} selector A CSS selector
|
|
30
|
+
* @param {*} scope The node to search below
|
|
31
|
+
* @returns {*|null}
|
|
32
|
+
*/
|
|
33
|
+
const querySelector = (selector, scope) => (0, css_select_1.selectOne)(selector, scope, {
|
|
34
|
+
adapter: cssSelectAdapter_1.cssSelectAdapter
|
|
35
|
+
})
|
|
36
|
+
exports.querySelector = querySelector
|
|
37
|
+
/**
|
|
38
|
+
* Whether an element itself (not its descendants) matches the selector.
|
|
39
|
+
* @memberOf module:factories
|
|
40
|
+
* @param {*} element The element to test
|
|
41
|
+
* @param {string} selector A CSS selector
|
|
42
|
+
* @returns {boolean}
|
|
43
|
+
*/
|
|
44
|
+
const matches = (element, selector) => (0, css_select_1.is)(element, selector, {
|
|
45
|
+
adapter: cssSelectAdapter_1.cssSelectAdapter
|
|
46
|
+
})
|
|
47
|
+
exports.matches = matches
|
|
48
|
+
/**
|
|
49
|
+
* The nearest ancestor of an element (starting with the element itself) which matches the selector, or null when
|
|
50
|
+
* none of them do.
|
|
51
|
+
* @memberOf module:factories
|
|
52
|
+
* @param {*} element The element to start from
|
|
53
|
+
* @param {string} selector A CSS selector
|
|
54
|
+
* @returns {*|null}
|
|
55
|
+
*/
|
|
56
|
+
const closest = (element, selector) => {
|
|
57
|
+
let current = element
|
|
58
|
+
while (current && cssSelectAdapter_1.cssSelectAdapter.isTag(current)) {
|
|
59
|
+
if ((0, exports.matches)(current, selector)) {
|
|
60
|
+
return current
|
|
61
|
+
}
|
|
62
|
+
current = current.parentNode
|
|
63
|
+
}
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
exports.closest = closest
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NodeService } from '../services/NodeService';
|
|
2
|
+
import { PseudoElement } from '../interfaces/PseudoElement';
|
|
3
|
+
/**
|
|
4
|
+
* The first element, in tree order, below (not including) the given node whose id matches the given value, or null
|
|
5
|
+
* when there is none. Shared by Document and DocumentFragment, which both implement the DOM's NonElementParentNode
|
|
6
|
+
* mixin (so ShadowRoot, a DocumentFragment, gets it too).
|
|
7
|
+
* @memberOf module:functions
|
|
8
|
+
* @param {NodeService} root The node to search below
|
|
9
|
+
* @param {string} id
|
|
10
|
+
* @returns {PseudoElement|null}
|
|
11
|
+
*/
|
|
12
|
+
declare const getElementById: (root: NodeService, id: string) => PseudoElement | null;
|
|
13
|
+
export default getElementById;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
const NodeService_1 = require('../services/NodeService')
|
|
7
|
+
/**
|
|
8
|
+
* The first element, in tree order, below (not including) the given node whose id matches the given value, or null
|
|
9
|
+
* when there is none. Shared by Document and DocumentFragment, which both implement the DOM's NonElementParentNode
|
|
10
|
+
* mixin (so ShadowRoot, a DocumentFragment, gets it too).
|
|
11
|
+
* @memberOf module:functions
|
|
12
|
+
* @param {NodeService} root The node to search below
|
|
13
|
+
* @param {string} id
|
|
14
|
+
* @returns {PseudoElement|null}
|
|
15
|
+
*/
|
|
16
|
+
const getElementById = (root, id) => {
|
|
17
|
+
const search = node => {
|
|
18
|
+
for (const child of Array.from(node.childNodes)) {
|
|
19
|
+
if (child.nodeType === NodeService_1.NodeService.ELEMENT_NODE) {
|
|
20
|
+
if (child.id === id) {
|
|
21
|
+
return child
|
|
22
|
+
}
|
|
23
|
+
const found = search(child)
|
|
24
|
+
if (found) {
|
|
25
|
+
return found
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
return search(root)
|
|
32
|
+
}
|
|
33
|
+
exports.default = getElementById
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const NodeService_1=require("../services/NodeService"),getElementById=(e,r)=>{const t=e=>{for(const o of Array.from(e.childNodes))if(o.nodeType===NodeService_1.NodeService.ELEMENT_NODE){if(o.id===r)return o;const e=t(o);if(e)return e}return null};return t(e)};exports.default=getElementById;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Substitute for the DOM CSSStyleDeclaration Class. Real instances (from createStyleDeclaration) also accept
|
|
3
|
+
* arbitrary camelCase CSS property names (declaration.backgroundColor), which cannot be expressed in an interface.
|
|
4
|
+
*/
|
|
5
|
+
export interface PseudoCSSStyleDeclaration {
|
|
6
|
+
get length(): number;
|
|
7
|
+
get cssText(): string;
|
|
8
|
+
set cssText(cssText: string);
|
|
9
|
+
item(index: number): string;
|
|
10
|
+
getPropertyValue(property: string): string;
|
|
11
|
+
getPropertyPriority(property: string): string;
|
|
12
|
+
setProperty(property: string, value: string, priority: string): void;
|
|
13
|
+
removeProperty(property: string): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -1,10 +1,35 @@
|
|
|
1
|
-
import { PseudoNode } from './PseudoNode';
|
|
2
|
-
import { PseudoElement } from './PseudoElement';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { PseudoNode } from './PseudoNode';
|
|
2
|
+
import { PseudoElement } from './PseudoElement';
|
|
3
|
+
import { PseudoDocumentFragment } from './PseudoDocumentFragment';
|
|
4
|
+
export interface PseudoDocument extends PseudoNode {
|
|
5
|
+
/**
|
|
6
|
+
* The first element, in tree order, whose id matches the given value, or null when there is none.
|
|
7
|
+
* @param {string} id
|
|
8
|
+
* @returns {PseudoElement|null}
|
|
9
|
+
*/
|
|
10
|
+
getElementById(id: string): PseudoElement | null;
|
|
11
|
+
/**
|
|
12
|
+
* Make an element of the given type which belongs to this document but is not added anywhere until it is appended.
|
|
13
|
+
* @param {string} [tagName='div'] The type of element to create
|
|
14
|
+
* @returns {PseudoElement}
|
|
15
|
+
*/
|
|
16
|
+
createElement(tagName: string): PseudoElement;
|
|
17
|
+
/**
|
|
18
|
+
* Make a text node which belongs to this document.
|
|
19
|
+
* @param {string} [data=''] The text
|
|
20
|
+
* @returns {PseudoNode}
|
|
21
|
+
*/
|
|
22
|
+
createTextNode(data: string): PseudoNode;
|
|
23
|
+
/**
|
|
24
|
+
* Make a comment which belongs to this document.
|
|
25
|
+
* @param {string} [data=''] The comment
|
|
26
|
+
* @returns {PseudoNode}
|
|
27
|
+
*/
|
|
28
|
+
createComment(data: string): PseudoNode;
|
|
29
|
+
/**
|
|
30
|
+
* Make an empty document fragment which belongs to this document, a container for nodes which can be built up and
|
|
31
|
+
* then inserted in one go.
|
|
32
|
+
* @returns {PseudoDocumentFragment}
|
|
33
|
+
*/
|
|
34
|
+
createDocumentFragment(): PseudoDocumentFragment;
|
|
35
|
+
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { PseudoNode } from './PseudoNode';
|
|
2
|
+
import { PseudoElement } from './PseudoElement';
|
|
2
3
|
export interface PseudoDocumentFragment extends PseudoNode {
|
|
4
|
+
/**
|
|
5
|
+
* The first element, in tree order, whose id matches the given value, or null when there is none.
|
|
6
|
+
* @param {string} id
|
|
7
|
+
* @returns {PseudoElement|null}
|
|
8
|
+
*/
|
|
9
|
+
getElementById(id: string): PseudoElement | null;
|
|
3
10
|
}
|