pseudo-dom 0.7.0 → 0.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/README.md +262 -236
- package/browser/pseudo-dom.js +628 -548
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/classes/PseudoHTMLDocument.d.ts +41 -67
- package/dist/classes/PseudoHTMLDocument.js +74 -144
- package/dist/classes/PseudoHTMLDocument.min.js +1 -1
- 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/PseudoDocument.d.ts +25 -0
- package/dist/interfaces/PseudoDocumentFragment.d.ts +10 -3
- package/dist/interfaces/PseudoElement.d.ts +702 -702
- package/dist/services/DocumentFragmentService.d.ts +21 -13
- package/dist/services/DocumentFragmentService.js +42 -24
- package/dist/services/DocumentFragmentService.min.js +1 -1
- package/dist/services/DocumentService.d.ts +28 -1
- package/dist/services/DocumentService.js +64 -15
- 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/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
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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PseudoNode } from './PseudoNode';
|
|
2
2
|
import { PseudoElement } from './PseudoElement';
|
|
3
|
+
import { PseudoDocumentFragment } from './PseudoDocumentFragment';
|
|
3
4
|
export interface PseudoDocument extends PseudoNode {
|
|
4
5
|
/**
|
|
5
6
|
* The first element, in tree order, whose id matches the given value, or null when there is none.
|
|
@@ -7,4 +8,28 @@ export interface PseudoDocument extends PseudoNode {
|
|
|
7
8
|
* @returns {PseudoElement|null}
|
|
8
9
|
*/
|
|
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;
|
|
10
35
|
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import { PseudoNode } from './PseudoNode';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { PseudoNode } from './PseudoNode';
|
|
2
|
+
import { PseudoElement } from './PseudoElement';
|
|
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;
|
|
10
|
+
}
|