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,191 +1,191 @@
1
- /**
2
- * @file Substitute for the DOM Element Class.
3
- * @author Joshua Heagle <joshuaheagle@gmail.com>
4
- * @version 1.0.0
5
- */
6
- import { PseudoNode } from '../interfaces/PseudoNode';
7
- import { PseudoElement } from '../interfaces/PseudoElement';
8
- import { NodeService } from './NodeService';
9
- import { PseudoNamedNodeMap } from '../interfaces/PseudoNamedNodeMap';
10
- import { PseudoDOMTokenList } from '../interfaces/PseudoDOMTokenList';
11
- import { PseudoHTMLCollection } from '../interfaces/PseudoHTMLCollection';
12
- type attribute = {
13
- name: string;
14
- value: any;
15
- };
16
- /**
17
- * Simulate the behaviour of the Element Class when there is no DOM available.
18
- * @author Joshua Heagle <joshuaheagle@gmail.com>
19
- * @class
20
- * @augments PseudoNode
21
- * @property {string} tagName
22
- * @property {string} className
23
- * @property {string} id
24
- * @property {string} innerHtml
25
- * @property {Array} attributes
26
- * @property {function} hasAttribute
27
- * @property {function} setAttribute
28
- * @property {function} getAttribute
29
- * @property {function} removeAttribute
30
- */
31
- export declare class ElementService extends NodeService implements Partial<PseudoElement> {
32
- id: string;
33
- innerHTML: string;
34
- type: string;
35
- private readonly tag;
36
- private readonly attributeList;
37
- private readonly propertyAttributes;
38
- private readonly tokenList;
39
- private defaultEventApplied;
40
- /**
41
- * @param {Object} [settings={}]
42
- * @param {string} [settings.tagName=''] The name of the tag this element represents
43
- * @param {Array<{name: string, value: *}>} [settings.attributes=[]] The attributes (also assigned as properties) to start with
44
- * @param {PseudoNode|null} [settings.parent=null] The node to add this element to as its last child
45
- * @param {Array<PseudoNode>} [settings.children=[]] The nodes to start as children
46
- * @constructor
47
- */
48
- constructor({ tagName, attributes, parent, children }?: {
49
- tagName?: string;
50
- attributes?: Array<attribute>;
51
- parent?: PseudoNode | null;
52
- children?: Array<any>;
53
- });
54
- /**
55
- * The attributes with the values they have now: the ones which are also properties (className, id, style, ...) can
56
- * have been changed through the property, which does not change the stored list.
57
- * @returns {Array<{name: string, value: *}>}
58
- */
59
- private currentAttributes;
60
- get nodeName(): string;
61
- /**
62
- * A copy of this element without its children: the same tag and attributes (the values which are objects, such as
63
- * style, are copied too rather than shared), but not its parent or listeners.
64
- * @returns {ElementService}
65
- */
66
- protected cloneShallow(): NodeService;
67
- /**
68
- * Elements are equal when they have the same tag and the same attributes (in any order), which is what isEqualNode
69
- * checks before it compares the children.
70
- * @param {NodeService} other The element to compare with
71
- * @returns {boolean}
72
- */
73
- protected equalsShallow(other: NodeService): boolean;
74
- get tagName(): string;
75
- get nodeType(): number;
76
- get attributes(): PseudoNamedNodeMap;
77
- get classList(): PseudoDOMTokenList;
78
- get className(): string;
79
- set className(className: string);
80
- /**
81
- * Some elements have default behaviour, this registers it when the element is added.
82
- * @returns {Function}
83
- */
84
- /**
85
- * A live view of this element's element children (text, comments and the like are not included).
86
- * @returns {PseudoHTMLCollection}
87
- */
88
- get children(): PseudoHTMLCollection;
89
- /**
90
- * How many element children this element has.
91
- * @returns {number}
92
- */
93
- get childElementCount(): number;
94
- /**
95
- * The first child of this element which is an element, or null when there is none.
96
- * @returns {PseudoElement|null}
97
- */
98
- get firstElementChild(): PseudoElement | null;
99
- /**
100
- * The last child of this element which is an element, or null when there is none.
101
- * @returns {PseudoElement|null}
102
- */
103
- get lastElementChild(): PseudoElement | null;
104
- /**
105
- * The sibling after this one which is an element, or null when there is none.
106
- * @returns {PseudoElement|null}
107
- */
108
- get nextElementSibling(): PseudoElement | null;
109
- /**
110
- * The sibling before this one which is an element, or null when there is none.
111
- * @returns {PseudoElement|null}
112
- */
113
- get previousElementSibling(): PseudoElement | null;
114
- /**
115
- * Put an element at a position relative to this one: beforebegin (before this element, as its previous sibling),
116
- * afterbegin (as this element's first child), beforeend (as this element's last child) or afterend (after this
117
- * element, as its next sibling).
118
- * @param {string} position beforebegin, afterbegin, beforeend or afterend
119
- * @param {ElementService} element The element to insert
120
- * @returns {ElementService|null} The inserted element, or null when the position needed a parent this element does not have
121
- * @throws {Error} When the position is not one of the four above
122
- */
123
- insertAdjacentElement(position: string, element: PseudoElement): PseudoElement | null;
124
- /**
125
- * Put text at a position relative to this element, the same as insertAdjacentElement but the text becomes a text node.
126
- * @param {string} position beforebegin, afterbegin, beforeend or afterend
127
- * @param {string} text The text to insert
128
- * @throws {Error} When the position is not one of the four above
129
- */
130
- insertAdjacentText(position: string, text: string): void;
131
- /**
132
- * Shared implementation for insertAdjacentElement / insertAdjacentText.
133
- * @param {string} position beforebegin, afterbegin, beforeend or afterend
134
- * @param {PseudoNode|string} node The node (or text) to insert
135
- * @returns {PseudoNode|null} The inserted node, or null when the position needed a parent this element does not have
136
- * @throws {Error} When the position is not one of the four above
137
- */
138
- private insertAdjacent;
139
- /**
140
- * Not implemented yet (HTML parsing is out of scope for now).
141
- * @param {string} position beforebegin, afterbegin, beforeend or afterend
142
- * @param {string} text The markup which would be parsed
143
- * @throws {Error}
144
- */
145
- insertAdjacentHTML(position: string, text: string): void;
146
- /**
147
- * Whether this element itself (not its descendants) matches the given CSS selector.
148
- * @param {string} selectors A CSS selector
149
- * @returns {boolean}
150
- */
151
- matches(selectors: string): boolean;
152
- /**
153
- * The nearest ancestor of this element (starting with this element itself) which matches the CSS selector, or
154
- * null when none of them do.
155
- * @param {string} selectors A CSS selector
156
- * @returns {PseudoElement|null}
157
- */
158
- closest(selectors: string): PseudoElement | null;
159
- applyDefaultEvent(): Function;
160
- /**
161
- * An element which is added as a child gets its default events (for example a submit button submits its form).
162
- * @param {NodeService} child The node which was inserted
163
- */
164
- protected childInserted(child: NodeService): void;
165
- /**
166
- * Check whether the element has an attribute by that name.
167
- * @param {string} attributeName
168
- * @returns {boolean}
169
- */
170
- hasAttribute(attributeName: string): boolean;
171
- /**
172
- * Set the value of an attribute, adding the attribute if it did not exist.
173
- * @param {string} attributeName
174
- * @param {string} attributeValue
175
- * @returns {undefined}
176
- */
177
- setAttribute(attributeName: string, attributeValue: string): void;
178
- /**
179
- * Retrieve the value of an attribute.
180
- * @param {string} attributeName
181
- * @returns {string|null} The value, or null when there is no such attribute
182
- */
183
- getAttribute(attributeName: string): string | null;
184
- /**
185
- * Remove an attribute from the element.
186
- * @param {string} attributeName
187
- * @returns {undefined}
188
- */
189
- removeAttribute(attributeName: string): void;
190
- }
191
- export {};
1
+ /**
2
+ * @file Substitute for the DOM Element Class.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ */
6
+ import { PseudoNode } from '../interfaces/PseudoNode';
7
+ import { PseudoElement } from '../interfaces/PseudoElement';
8
+ import { NodeService } from './NodeService';
9
+ import { PseudoNamedNodeMap } from '../interfaces/PseudoNamedNodeMap';
10
+ import { PseudoDOMTokenList } from '../interfaces/PseudoDOMTokenList';
11
+ import { PseudoHTMLCollection } from '../interfaces/PseudoHTMLCollection';
12
+ type attribute = {
13
+ name: string;
14
+ value: any;
15
+ };
16
+ /**
17
+ * Simulate the behaviour of the Element Class when there is no DOM available.
18
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
19
+ * @class
20
+ * @augments PseudoNode
21
+ * @property {string} tagName
22
+ * @property {string} className
23
+ * @property {string} id
24
+ * @property {string} innerHtml
25
+ * @property {Array} attributes
26
+ * @property {function} hasAttribute
27
+ * @property {function} setAttribute
28
+ * @property {function} getAttribute
29
+ * @property {function} removeAttribute
30
+ */
31
+ export declare class ElementService extends NodeService implements Partial<PseudoElement> {
32
+ id: string;
33
+ innerHTML: string;
34
+ type: string;
35
+ private readonly tag;
36
+ private readonly attributeList;
37
+ private readonly propertyAttributes;
38
+ private readonly tokenList;
39
+ private defaultEventApplied;
40
+ /**
41
+ * @param {Object} [settings={}]
42
+ * @param {string} [settings.tagName=''] The name of the tag this element represents
43
+ * @param {Array<{name: string, value: *}>} [settings.attributes=[]] The attributes (also assigned as properties) to start with
44
+ * @param {PseudoNode|null} [settings.parent=null] The node to add this element to as its last child
45
+ * @param {Array<PseudoNode>} [settings.children=[]] The nodes to start as children
46
+ * @constructor
47
+ */
48
+ constructor({ tagName, attributes, parent, children }?: {
49
+ tagName?: string;
50
+ attributes?: Array<attribute>;
51
+ parent?: PseudoNode | null;
52
+ children?: Array<any>;
53
+ });
54
+ /**
55
+ * The attributes with the values they have now: the ones which are also properties (className, id, style, ...) can
56
+ * have been changed through the property, which does not change the stored list.
57
+ * @returns {Array<{name: string, value: *}>}
58
+ */
59
+ private currentAttributes;
60
+ get nodeName(): string;
61
+ /**
62
+ * A copy of this element without its children: the same tag and attributes (the values which are objects, such as
63
+ * style, are copied too rather than shared), but not its parent or listeners.
64
+ * @returns {ElementService}
65
+ */
66
+ protected cloneShallow(): NodeService;
67
+ /**
68
+ * Elements are equal when they have the same tag and the same attributes (in any order), which is what isEqualNode
69
+ * checks before it compares the children.
70
+ * @param {NodeService} other The element to compare with
71
+ * @returns {boolean}
72
+ */
73
+ protected equalsShallow(other: NodeService): boolean;
74
+ get tagName(): string;
75
+ get nodeType(): number;
76
+ get attributes(): PseudoNamedNodeMap;
77
+ get classList(): PseudoDOMTokenList;
78
+ get className(): string;
79
+ set className(className: string);
80
+ /**
81
+ * Some elements have default behaviour, this registers it when the element is added.
82
+ * @returns {Function}
83
+ */
84
+ /**
85
+ * A live view of this element's element children (text, comments and the like are not included).
86
+ * @returns {PseudoHTMLCollection}
87
+ */
88
+ get children(): PseudoHTMLCollection;
89
+ /**
90
+ * How many element children this element has.
91
+ * @returns {number}
92
+ */
93
+ get childElementCount(): number;
94
+ /**
95
+ * The first child of this element which is an element, or null when there is none.
96
+ * @returns {PseudoElement|null}
97
+ */
98
+ get firstElementChild(): PseudoElement | null;
99
+ /**
100
+ * The last child of this element which is an element, or null when there is none.
101
+ * @returns {PseudoElement|null}
102
+ */
103
+ get lastElementChild(): PseudoElement | null;
104
+ /**
105
+ * The sibling after this one which is an element, or null when there is none.
106
+ * @returns {PseudoElement|null}
107
+ */
108
+ get nextElementSibling(): PseudoElement | null;
109
+ /**
110
+ * The sibling before this one which is an element, or null when there is none.
111
+ * @returns {PseudoElement|null}
112
+ */
113
+ get previousElementSibling(): PseudoElement | null;
114
+ /**
115
+ * Put an element at a position relative to this one: beforebegin (before this element, as its previous sibling),
116
+ * afterbegin (as this element's first child), beforeend (as this element's last child) or afterend (after this
117
+ * element, as its next sibling).
118
+ * @param {string} position beforebegin, afterbegin, beforeend or afterend
119
+ * @param {ElementService} element The element to insert
120
+ * @returns {ElementService|null} The inserted element, or null when the position needed a parent this element does not have
121
+ * @throws {Error} When the position is not one of the four above
122
+ */
123
+ insertAdjacentElement(position: string, element: PseudoElement): PseudoElement | null;
124
+ /**
125
+ * Put text at a position relative to this element, the same as insertAdjacentElement but the text becomes a text node.
126
+ * @param {string} position beforebegin, afterbegin, beforeend or afterend
127
+ * @param {string} text The text to insert
128
+ * @throws {Error} When the position is not one of the four above
129
+ */
130
+ insertAdjacentText(position: string, text: string): void;
131
+ /**
132
+ * Shared implementation for insertAdjacentElement / insertAdjacentText.
133
+ * @param {string} position beforebegin, afterbegin, beforeend or afterend
134
+ * @param {PseudoNode|string} node The node (or text) to insert
135
+ * @returns {PseudoNode|null} The inserted node, or null when the position needed a parent this element does not have
136
+ * @throws {Error} When the position is not one of the four above
137
+ */
138
+ private insertAdjacent;
139
+ /**
140
+ * Not implemented yet (HTML parsing is out of scope for now).
141
+ * @param {string} position beforebegin, afterbegin, beforeend or afterend
142
+ * @param {string} text The markup which would be parsed
143
+ * @throws {Error}
144
+ */
145
+ insertAdjacentHTML(position: string, text: string): void;
146
+ /**
147
+ * Whether this element itself (not its descendants) matches the given CSS selector.
148
+ * @param {string} selectors A CSS selector
149
+ * @returns {boolean}
150
+ */
151
+ matches(selectors: string): boolean;
152
+ /**
153
+ * The nearest ancestor of this element (starting with this element itself) which matches the CSS selector, or
154
+ * null when none of them do.
155
+ * @param {string} selectors A CSS selector
156
+ * @returns {PseudoElement|null}
157
+ */
158
+ closest(selectors: string): PseudoElement | null;
159
+ applyDefaultEvent(): Function;
160
+ /**
161
+ * An element which is added as a child gets its default events (for example a submit button submits its form).
162
+ * @param {NodeService} child The node which was inserted
163
+ */
164
+ protected childInserted(child: NodeService): void;
165
+ /**
166
+ * Check whether the element has an attribute by that name.
167
+ * @param {string} attributeName
168
+ * @returns {boolean}
169
+ */
170
+ hasAttribute(attributeName: string): boolean;
171
+ /**
172
+ * Set the value of an attribute, adding the attribute if it did not exist.
173
+ * @param {string} attributeName
174
+ * @param {string} attributeValue
175
+ * @returns {undefined}
176
+ */
177
+ setAttribute(attributeName: string, attributeValue: string): void;
178
+ /**
179
+ * Retrieve the value of an attribute.
180
+ * @param {string} attributeName
181
+ * @returns {string|null} The value, or null when there is no such attribute
182
+ */
183
+ getAttribute(attributeName: string): string | null;
184
+ /**
185
+ * Remove an attribute from the element.
186
+ * @param {string} attributeName
187
+ * @returns {undefined}
188
+ */
189
+ removeAttribute(attributeName: string): void;
190
+ }
191
+ export {};