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.
Files changed (41) hide show
  1. package/README.md +262 -236
  2. package/browser/pseudo-dom.js +628 -548
  3. package/browser/pseudo-dom.min.js +1 -1
  4. package/dist/classes/PseudoHTMLDocument.d.ts +41 -67
  5. package/dist/classes/PseudoHTMLDocument.js +74 -144
  6. package/dist/classes/PseudoHTMLDocument.min.js +1 -1
  7. package/dist/factories/cssSelectAdapter.d.ts +23 -23
  8. package/dist/factories/cssSelectAdapter.js +87 -87
  9. package/dist/factories/query.d.ts +33 -33
  10. package/dist/factories/query.js +66 -66
  11. package/dist/functions/getElementById.d.ts +13 -0
  12. package/dist/functions/getElementById.js +33 -0
  13. package/dist/functions/getElementById.min.js +1 -0
  14. package/dist/interfaces/PseudoDocument.d.ts +25 -0
  15. package/dist/interfaces/PseudoDocumentFragment.d.ts +10 -3
  16. package/dist/interfaces/PseudoElement.d.ts +702 -702
  17. package/dist/services/DocumentFragmentService.d.ts +21 -13
  18. package/dist/services/DocumentFragmentService.js +42 -24
  19. package/dist/services/DocumentFragmentService.min.js +1 -1
  20. package/dist/services/DocumentService.d.ts +28 -1
  21. package/dist/services/DocumentService.js +64 -15
  22. package/dist/services/DocumentService.min.js +1 -1
  23. package/dist/services/ElementService.d.ts +191 -191
  24. package/dist/services/ElementService.js +426 -426
  25. package/dist/services/HTMLCollectionService.d.ts +54 -54
  26. package/dist/services/HTMLCollectionService.js +92 -92
  27. package/dist/services/NodeService.d.ts +297 -297
  28. package/dist/services/NodeService.js +721 -721
  29. package/package.json +2 -2
  30. package/dist/classes.d.ts +0 -20
  31. package/dist/classes.js +0 -31
  32. package/dist/classes.min.js +0 -1
  33. package/dist/factories/generateNode.d.ts +0 -32
  34. package/dist/factories/generateNode.js +0 -85
  35. package/dist/factories/generateNode.min.js +0 -1
  36. package/dist/factories.d.ts +0 -11
  37. package/dist/factories.js +0 -27
  38. package/dist/factories.min.js +0 -1
  39. package/dist/functions.d.ts +0 -5
  40. package/dist/functions.js +0 -23
  41. package/dist/functions.min.js +0 -1
@@ -1,54 +1,54 @@
1
- /**
2
- * @file Substitute for the DOM HTMLCollection Class.
3
- * @author Joshua Heagle <joshuaheagle@gmail.com>
4
- * @version 1.0.0
5
- */
6
- import { NodeService } from './NodeService';
7
- import { PseudoHTMLCollection } from '../interfaces/PseudoHTMLCollection';
8
- /**
9
- * Simulate the behaviour of the HTMLCollection Class when there is no DOM available: a live view of some of a node's
10
- * element descendants, recomputed each time it is used rather than kept in sync as they change.
11
- * @author Joshua Heagle <joshuaheagle@gmail.com>
12
- * @class
13
- */
14
- export declare class HTMLCollectionService implements PseudoHTMLCollection {
15
- private readonly owner;
16
- private readonly predicate;
17
- private readonly deep;
18
- /**
19
- * @param {NodeService} owner The node this is a live view of a part of
20
- * @param {function(*): boolean} [predicate] Only elements which pass this are included (every element by default)
21
- * @param {boolean} [deep=false] Include every matching descendant (true, like getElementsByTagName), not just the
22
- * direct element children (false, like Element.children)
23
- * @constructor
24
- */
25
- constructor(owner: NodeService, predicate?: (element: any) => boolean, deep?: boolean);
26
- /**
27
- * The current elements the collection holds, in tree order.
28
- * @returns {Array<PseudoNode>}
29
- */
30
- private elements;
31
- /**
32
- * How many elements are in the collection right now.
33
- * @returns {number}
34
- */
35
- get length(): number;
36
- /**
37
- * The element at the given index, or null when there is none.
38
- * @param {number} index
39
- * @returns {*}
40
- */
41
- item(index: number): any | null;
42
- /**
43
- * The element whose id, or (failing that) whose name attribute, is the given value, or null when there is none.
44
- * @param {string} name
45
- * @returns {*}
46
- */
47
- namedItem(name: string): any | null;
48
- /**
49
- * Iterate over the current elements.
50
- * @returns {Iterator}
51
- */
52
- [Symbol.iterator](): Iterator<any>;
53
- }
54
- export default HTMLCollectionService;
1
+ /**
2
+ * @file Substitute for the DOM HTMLCollection Class.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ */
6
+ import { NodeService } from './NodeService';
7
+ import { PseudoHTMLCollection } from '../interfaces/PseudoHTMLCollection';
8
+ /**
9
+ * Simulate the behaviour of the HTMLCollection Class when there is no DOM available: a live view of some of a node's
10
+ * element descendants, recomputed each time it is used rather than kept in sync as they change.
11
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
12
+ * @class
13
+ */
14
+ export declare class HTMLCollectionService implements PseudoHTMLCollection {
15
+ private readonly owner;
16
+ private readonly predicate;
17
+ private readonly deep;
18
+ /**
19
+ * @param {NodeService} owner The node this is a live view of a part of
20
+ * @param {function(*): boolean} [predicate] Only elements which pass this are included (every element by default)
21
+ * @param {boolean} [deep=false] Include every matching descendant (true, like getElementsByTagName), not just the
22
+ * direct element children (false, like Element.children)
23
+ * @constructor
24
+ */
25
+ constructor(owner: NodeService, predicate?: (element: any) => boolean, deep?: boolean);
26
+ /**
27
+ * The current elements the collection holds, in tree order.
28
+ * @returns {Array<PseudoNode>}
29
+ */
30
+ private elements;
31
+ /**
32
+ * How many elements are in the collection right now.
33
+ * @returns {number}
34
+ */
35
+ get length(): number;
36
+ /**
37
+ * The element at the given index, or null when there is none.
38
+ * @param {number} index
39
+ * @returns {*}
40
+ */
41
+ item(index: number): any | null;
42
+ /**
43
+ * The element whose id, or (failing that) whose name attribute, is the given value, or null when there is none.
44
+ * @param {string} name
45
+ * @returns {*}
46
+ */
47
+ namedItem(name: string): any | null;
48
+ /**
49
+ * Iterate over the current elements.
50
+ * @returns {Iterator}
51
+ */
52
+ [Symbol.iterator](): Iterator<any>;
53
+ }
54
+ export default HTMLCollectionService;
@@ -1,92 +1,92 @@
1
- 'use strict'
2
-
3
- require('core-js/modules/esnext.iterator.constructor.js')
4
- require('core-js/modules/esnext.iterator.find.js')
5
- require('core-js/modules/esnext.iterator.for-each.js')
6
- Object.defineProperty(exports, '__esModule', {
7
- value: true
8
- })
9
- exports.HTMLCollectionService = void 0
10
- /**
11
- * @file Substitute for the DOM HTMLCollection Class.
12
- * @author Joshua Heagle <joshuaheagle@gmail.com>
13
- * @version 1.0.0
14
- */
15
- const NodeService_1 = require('./NodeService')
16
- /**
17
- * Simulate the behaviour of the HTMLCollection Class when there is no DOM available: a live view of some of a node's
18
- * element descendants, recomputed each time it is used rather than kept in sync as they change.
19
- * @author Joshua Heagle <joshuaheagle@gmail.com>
20
- * @class
21
- */
22
- class HTMLCollectionService {
23
- /**
24
- * @param {NodeService} owner The node this is a live view of a part of
25
- * @param {function(*): boolean} [predicate] Only elements which pass this are included (every element by default)
26
- * @param {boolean} [deep=false] Include every matching descendant (true, like getElementsByTagName), not just the
27
- * direct element children (false, like Element.children)
28
- * @constructor
29
- */
30
- constructor (owner, predicate = () => true, deep = false) {
31
- this.owner = owner
32
- this.predicate = predicate
33
- this.deep = deep
34
- }
35
-
36
- /**
37
- * The current elements the collection holds, in tree order.
38
- * @returns {Array<PseudoNode>}
39
- */
40
- elements () {
41
- const results = []
42
- const visit = node => {
43
- Array.from(node.childNodes).forEach(child => {
44
- if (child.nodeType === NodeService_1.NodeService.ELEMENT_NODE && this.predicate(child)) {
45
- results.push(child)
46
- }
47
- if (this.deep && child.nodeType === NodeService_1.NodeService.ELEMENT_NODE) {
48
- visit(child)
49
- }
50
- })
51
- }
52
- visit(this.owner)
53
- return results
54
- }
55
-
56
- /**
57
- * How many elements are in the collection right now.
58
- * @returns {number}
59
- */
60
- get length () {
61
- return this.elements().length
62
- }
63
-
64
- /**
65
- * The element at the given index, or null when there is none.
66
- * @param {number} index
67
- * @returns {*}
68
- */
69
- item (index) {
70
- return this.elements()[index] || null
71
- }
72
-
73
- /**
74
- * The element whose id, or (failing that) whose name attribute, is the given value, or null when there is none.
75
- * @param {string} name
76
- * @returns {*}
77
- */
78
- namedItem (name) {
79
- const elements = this.elements()
80
- return elements.find(element => element.id === name) || elements.find(element => element.getAttribute('name') === name) || null
81
- }
82
-
83
- /**
84
- * Iterate over the current elements.
85
- * @returns {Iterator}
86
- */
87
- [Symbol.iterator] () {
88
- return this.elements()[Symbol.iterator]()
89
- }
90
- }
91
- exports.HTMLCollectionService = HTMLCollectionService
92
- exports.default = HTMLCollectionService
1
+ 'use strict'
2
+
3
+ require('core-js/modules/esnext.iterator.constructor.js')
4
+ require('core-js/modules/esnext.iterator.find.js')
5
+ require('core-js/modules/esnext.iterator.for-each.js')
6
+ Object.defineProperty(exports, '__esModule', {
7
+ value: true
8
+ })
9
+ exports.HTMLCollectionService = void 0
10
+ /**
11
+ * @file Substitute for the DOM HTMLCollection Class.
12
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
13
+ * @version 1.0.0
14
+ */
15
+ const NodeService_1 = require('./NodeService')
16
+ /**
17
+ * Simulate the behaviour of the HTMLCollection Class when there is no DOM available: a live view of some of a node's
18
+ * element descendants, recomputed each time it is used rather than kept in sync as they change.
19
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
20
+ * @class
21
+ */
22
+ class HTMLCollectionService {
23
+ /**
24
+ * @param {NodeService} owner The node this is a live view of a part of
25
+ * @param {function(*): boolean} [predicate] Only elements which pass this are included (every element by default)
26
+ * @param {boolean} [deep=false] Include every matching descendant (true, like getElementsByTagName), not just the
27
+ * direct element children (false, like Element.children)
28
+ * @constructor
29
+ */
30
+ constructor (owner, predicate = () => true, deep = false) {
31
+ this.owner = owner
32
+ this.predicate = predicate
33
+ this.deep = deep
34
+ }
35
+
36
+ /**
37
+ * The current elements the collection holds, in tree order.
38
+ * @returns {Array<PseudoNode>}
39
+ */
40
+ elements () {
41
+ const results = []
42
+ const visit = node => {
43
+ Array.from(node.childNodes).forEach(child => {
44
+ if (child.nodeType === NodeService_1.NodeService.ELEMENT_NODE && this.predicate(child)) {
45
+ results.push(child)
46
+ }
47
+ if (this.deep && child.nodeType === NodeService_1.NodeService.ELEMENT_NODE) {
48
+ visit(child)
49
+ }
50
+ })
51
+ }
52
+ visit(this.owner)
53
+ return results
54
+ }
55
+
56
+ /**
57
+ * How many elements are in the collection right now.
58
+ * @returns {number}
59
+ */
60
+ get length () {
61
+ return this.elements().length
62
+ }
63
+
64
+ /**
65
+ * The element at the given index, or null when there is none.
66
+ * @param {number} index
67
+ * @returns {*}
68
+ */
69
+ item (index) {
70
+ return this.elements()[index] || null
71
+ }
72
+
73
+ /**
74
+ * The element whose id, or (failing that) whose name attribute, is the given value, or null when there is none.
75
+ * @param {string} name
76
+ * @returns {*}
77
+ */
78
+ namedItem (name) {
79
+ const elements = this.elements()
80
+ return elements.find(element => element.id === name) || elements.find(element => element.getAttribute('name') === name) || null
81
+ }
82
+
83
+ /**
84
+ * Iterate over the current elements.
85
+ * @returns {Iterator}
86
+ */
87
+ [Symbol.iterator] () {
88
+ return this.elements()[Symbol.iterator]()
89
+ }
90
+ }
91
+ exports.HTMLCollectionService = HTMLCollectionService
92
+ exports.default = HTMLCollectionService