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.
Files changed (57) hide show
  1. package/README.md +468 -237
  2. package/browser/pseudo-dom.js +986 -563
  3. package/browser/pseudo-dom.min.js +1 -1
  4. package/dist/classes/PseudoHTMLDocument.d.ts +17 -43
  5. package/dist/classes/PseudoHTMLDocument.js +24 -94
  6. package/dist/classes/PseudoHTMLDocument.min.js +1 -1
  7. package/dist/factories/createDataset.d.ts +10 -0
  8. package/dist/factories/createDataset.js +78 -0
  9. package/dist/factories/createDataset.min.js +1 -0
  10. package/dist/factories/createStyleDeclaration.d.ts +30 -0
  11. package/dist/factories/createStyleDeclaration.js +64 -0
  12. package/dist/factories/createStyleDeclaration.min.js +1 -0
  13. package/dist/factories/cssSelectAdapter.d.ts +23 -23
  14. package/dist/factories/cssSelectAdapter.js +87 -87
  15. package/dist/factories/query.d.ts +33 -33
  16. package/dist/factories/query.js +66 -66
  17. package/dist/functions/getElementById.d.ts +13 -0
  18. package/dist/functions/getElementById.js +33 -0
  19. package/dist/functions/getElementById.min.js +1 -0
  20. package/dist/interfaces/PseudoCSSStyleDeclaration.d.ts +14 -0
  21. package/dist/interfaces/PseudoCSSStyleDeclaration.js +5 -0
  22. package/dist/interfaces/PseudoCSSStyleDeclaration.min.js +1 -0
  23. package/dist/interfaces/PseudoDocument.d.ts +35 -10
  24. package/dist/interfaces/PseudoDocumentFragment.d.ts +7 -0
  25. package/dist/interfaces/PseudoElement.d.ts +702 -702
  26. package/dist/interfaces/PseudoHTMLElement.d.ts +33 -22
  27. package/dist/services/CSSStyleDeclarationService.d.ts +73 -0
  28. package/dist/services/CSSStyleDeclarationService.js +156 -0
  29. package/dist/services/CSSStyleDeclarationService.min.js +1 -0
  30. package/dist/services/DocumentFragmentService.d.ts +8 -0
  31. package/dist/services/DocumentFragmentService.js +18 -0
  32. package/dist/services/DocumentFragmentService.min.js +1 -1
  33. package/dist/services/DocumentService.d.ts +46 -19
  34. package/dist/services/DocumentService.js +95 -46
  35. package/dist/services/DocumentService.min.js +1 -1
  36. package/dist/services/ElementService.d.ts +191 -191
  37. package/dist/services/ElementService.js +426 -426
  38. package/dist/services/HTMLCollectionService.d.ts +54 -54
  39. package/dist/services/HTMLCollectionService.js +92 -92
  40. package/dist/services/HTMLElementService.d.ts +87 -57
  41. package/dist/services/HTMLElementService.js +202 -163
  42. package/dist/services/HTMLElementService.min.js +1 -1
  43. package/dist/services/NodeService.d.ts +297 -297
  44. package/dist/services/NodeService.js +721 -721
  45. package/package.json +2 -2
  46. package/dist/classes.d.ts +0 -20
  47. package/dist/classes.js +0 -31
  48. package/dist/classes.min.js +0 -1
  49. package/dist/factories/generateNode.d.ts +0 -32
  50. package/dist/factories/generateNode.js +0 -85
  51. package/dist/factories/generateNode.min.js +0 -1
  52. package/dist/factories.d.ts +0 -11
  53. package/dist/factories.js +0 -27
  54. package/dist/factories.min.js +0 -1
  55. package/dist/functions.d.ts +0 -5
  56. package/dist/functions.js +0 -23
  57. 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
@@ -1,57 +1,87 @@
1
- /**
2
- * @file Substitute for the DOM HTMLElement Class.
3
- * @author Joshua Heagle <joshuaheagle@gmail.com>
4
- * @version 1.0.0
5
- */
6
- import { PseudoHTMLElement } from '../interfaces/PseudoHTMLElement';
7
- import { PseudoNode } from '../interfaces/PseudoNode';
8
- import { ElementService } from './ElementService';
9
- /**
10
- * Simulate the behaviour of the HTMLElement Class when there is no DOM available.
11
- * @author Joshua Heagle <joshuaheagle@gmail.com>
12
- * @class
13
- * @augments PseudoElement
14
- * @property {boolean} hidden - State of whether element is visible
15
- * @property {number} offsetHeight - The height of the element as offset by the parent element
16
- * @property {number} offsetLeft - The position of the left side of the element based on the parent element
17
- * @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
18
- * @property {number} offsetTop - The position of the top side of the element based on the parent element
19
- * @property {number} offsetWidth - The width of the element as offset by the parent element
20
- * @property {Object} style - A container to define all applied inline-styles
21
- * @property {string} title - The title attribute which affects the text visible on hover
22
- */
23
- export declare class HTMLElementService extends ElementService implements Partial<PseudoHTMLElement> {
24
- /**
25
- * Simulate the HTMLElement object when the Dom is not available
26
- * @param {Object} [elementOptions={}]
27
- * @param {string} [elementOptions.tagName='']
28
- * @param {PseudoNode|Object} [elementOptions.parent={}]
29
- * @param {Array} [elementOptions.children=[]]
30
- * @constructor
31
- */
32
- constructor({ tagName, parent, children }?: {
33
- tagName?: string;
34
- parent?: PseudoNode | null;
35
- children?: Array<any>;
36
- });
37
- /**
38
- * Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
39
- * @returns {boolean}
40
- */
41
- get canFocus(): boolean;
42
- /**
43
- * Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
44
- * script made it (so it is not trusted). A disabled element does nothing.
45
- */
46
- click(): void;
47
- /**
48
- * Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
49
- * focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
50
- * focus or already has it.
51
- */
52
- focus(): void;
53
- /**
54
- * Take the focus away from the element, when it has it: it gets blur then focusout.
55
- */
56
- blur(): void;
57
- }
1
+ /**
2
+ * @file Substitute for the DOM HTMLElement Class.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ */
6
+ import { PseudoHTMLElement } from '../interfaces/PseudoHTMLElement';
7
+ import { PseudoNode } from '../interfaces/PseudoNode';
8
+ import { NodeService } from './NodeService';
9
+ import { ElementService } from './ElementService';
10
+ import { CSSStyleDeclarationService } from './CSSStyleDeclarationService';
11
+ /**
12
+ * Simulate the behaviour of the HTMLElement Class when there is no DOM available.
13
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
14
+ * @class
15
+ * @augments PseudoElement
16
+ * @property {boolean} hidden - State of whether element is visible
17
+ * @property {number} offsetHeight - The height of the element as offset by the parent element
18
+ * @property {number} offsetLeft - The position of the left side of the element based on the parent element
19
+ * @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
20
+ * @property {number} offsetTop - The position of the top side of the element based on the parent element
21
+ * @property {number} offsetWidth - The width of the element as offset by the parent element
22
+ * @property {CSSStyleDeclarationService} style - The element's inline styles, live and settable per property
23
+ * @property {Object.<string, string>} dataset - The element's data-* attributes, live, under their camelCase names
24
+ * @property {string} title - The title attribute which affects the text visible on hover
25
+ */
26
+ export declare class HTMLElementService extends ElementService implements Partial<PseudoHTMLElement> {
27
+ private readonly styleDeclaration;
28
+ private readonly datasetProxy;
29
+ /**
30
+ * Simulate the HTMLElement object when the Dom is not available
31
+ * @param {Object} [elementOptions={}]
32
+ * @param {string} [elementOptions.tagName='']
33
+ * @param {PseudoNode|Object} [elementOptions.parent={}]
34
+ * @param {Array} [elementOptions.children=[]]
35
+ * @constructor
36
+ */
37
+ constructor({ tagName, parent, children }?: {
38
+ tagName?: string;
39
+ parent?: PseudoNode | null;
40
+ children?: Array<any>;
41
+ });
42
+ /**
43
+ * The element's inline styles: a live CSSStyleDeclaration-like object, so both style.setProperty('color', 'red')
44
+ * and style.color = 'red' work.
45
+ * @returns {CSSStyleDeclarationService}
46
+ */
47
+ get style(): CSSStyleDeclarationService;
48
+ /**
49
+ * The element's data-* attributes, live, under their camelCase names (data-foo-bar <-> dataset.fooBar). Backed
50
+ * directly by getAttribute / setAttribute, so it is never out of sync with the attributes themselves.
51
+ * @returns {Object.<string, string>}
52
+ */
53
+ get dataset(): {
54
+ [key: string]: string;
55
+ };
56
+ /**
57
+ * Style is not attribute-backed like most properties (see the constructor), so cloneNode needs its own copy of it.
58
+ * @returns {NodeService}
59
+ */
60
+ protected cloneShallow(): NodeService;
61
+ /**
62
+ * Style is not attribute-backed like most properties, so isEqualNode needs to compare it separately too.
63
+ * @param {NodeService} other The node to compare with
64
+ * @returns {boolean}
65
+ */
66
+ protected equalsShallow(other: NodeService): boolean;
67
+ /**
68
+ * Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
69
+ * @returns {boolean}
70
+ */
71
+ get canFocus(): boolean;
72
+ /**
73
+ * Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
74
+ * script made it (so it is not trusted). A disabled element does nothing.
75
+ */
76
+ click(): void;
77
+ /**
78
+ * Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
79
+ * focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
80
+ * focus or already has it.
81
+ */
82
+ focus(): void;
83
+ /**
84
+ * Take the focus away from the element, when it has it: it gets blur then focusout.
85
+ */
86
+ blur(): void;
87
+ }