pseudo-dom 0.16.0 → 0.17.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.
@@ -1,119 +1,154 @@
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
- * Parses html with this class building each new element (matches HTML: parsed elements behave like plain
69
- * HTMLElements, not whatever specialized class happens to be setting innerHTML / outerHTML).
70
- * @param {string} html
71
- * @returns {Array<*>}
72
- */
73
- private parse;
74
- /**
75
- * Replace this element's children by parsing html. innerHTML's setter is here rather than on ElementService (which
76
- * only has the getter) because building the new elements needs a concrete element class - see parse().
77
- * @param {string} html
78
- * @returns {undefined}
79
- */
80
- set innerHTML(html: string);
81
- get innerHTML(): string;
82
- /**
83
- * Replace this element itself, in its parent, by parsing html. Does nothing when it has no parent, like
84
- * replaceWith. outerHTML's setter is here rather than on ElementService for the same reason as innerHTML's.
85
- * @param {string} html
86
- * @returns {undefined}
87
- */
88
- set outerHTML(html: string);
89
- get outerHTML(): string;
90
- /**
91
- * Parse html and insert the resulting nodes at the given position, like insertAdjacentElement /
92
- * insertAdjacentText.
93
- * @param {string} position beforebegin, afterbegin, beforeend or afterend
94
- * @param {string} html The markup to parse
95
- * @returns {undefined}
96
- * @throws {Error} When the position is not one of the four above
97
- */
98
- insertAdjacentHTML(position: string, html: string): void;
99
- /**
100
- * Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
101
- * @returns {boolean}
102
- */
103
- get canFocus(): boolean;
104
- /**
105
- * Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
106
- * script made it (so it is not trusted). A disabled element does nothing.
107
- */
108
- click(): void;
109
- /**
110
- * Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
111
- * focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
112
- * focus or already has it.
113
- */
114
- focus(): void;
115
- /**
116
- * Take the focus away from the element, when it has it: it gets blur then focusout.
117
- */
118
- blur(): void;
119
- }
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
+ private dirtyValue;
30
+ private dirtyChecked;
31
+ /**
32
+ * Simulate the HTMLElement object when the Dom is not available
33
+ * @param {Object} [elementOptions={}]
34
+ * @param {string} [elementOptions.tagName='']
35
+ * @param {PseudoNode|Object} [elementOptions.parent={}]
36
+ * @param {Array} [elementOptions.children=[]]
37
+ * @constructor
38
+ */
39
+ constructor({ tagName, parent, children }?: {
40
+ tagName?: string;
41
+ parent?: PseudoNode | null;
42
+ children?: Array<any>;
43
+ });
44
+ /**
45
+ * The element's inline styles: a live CSSStyleDeclaration-like object, so both style.setProperty('color', 'red')
46
+ * and style.color = 'red' work.
47
+ * @returns {CSSStyleDeclarationService}
48
+ */
49
+ get style(): CSSStyleDeclarationService;
50
+ /**
51
+ * The element's data-* attributes, live, under their camelCase names (data-foo-bar <-> dataset.fooBar). Backed
52
+ * directly by getAttribute / setAttribute, so it is never out of sync with the attributes themselves.
53
+ * @returns {Object.<string, string>}
54
+ */
55
+ get dataset(): {
56
+ [key: string]: string;
57
+ };
58
+ /**
59
+ * Whether this tag has a `value` (the form controls which do).
60
+ * @returns {boolean}
61
+ */
62
+ private hasValueProperty;
63
+ /**
64
+ * Whether this tag has a `checked` (only input does).
65
+ * @returns {boolean}
66
+ */
67
+ private hasCheckedProperty;
68
+ /**
69
+ * Put a plain own property on the element, as assigning a property this element does not have does in the DOM.
70
+ * @param {string} name
71
+ * @param {*} value
72
+ * @returns {undefined}
73
+ */
74
+ private setExpando;
75
+ /**
76
+ * The current value of a form control. Until it is set (or edited), it is the value attribute (the default value),
77
+ * or '' when there is none ('on' for a checkbox or radio); setting it never changes the attribute, like the DOM's.
78
+ * Only form controls (input, textarea, select, button, option, output) have one.
79
+ * @returns {string|undefined}
80
+ */
81
+ get value(): string | undefined;
82
+ set value(value: string | undefined);
83
+ /**
84
+ * Whether a checkbox or radio input is checked. Until it is set, it follows the checked attribute (which sets the
85
+ * default); setting it never changes the attribute, like the DOM's. Only input has one.
86
+ * @returns {boolean|undefined}
87
+ */
88
+ get checked(): boolean | undefined;
89
+ set checked(checked: boolean | undefined);
90
+ /**
91
+ * Style is not attribute-backed like most properties (see the constructor), so cloneNode needs its own copy of it,
92
+ * and a form control keeps its current value and checkedness (as the DOM's cloneNode does).
93
+ * @returns {NodeService}
94
+ */
95
+ protected cloneShallow(): NodeService;
96
+ /**
97
+ * Style is not attribute-backed like most properties, so isEqualNode needs to compare it separately too.
98
+ * @param {NodeService} other The node to compare with
99
+ * @returns {boolean}
100
+ */
101
+ protected equalsShallow(other: NodeService): boolean;
102
+ /**
103
+ * Parses html with this class building each new element (matches HTML: parsed elements behave like plain
104
+ * HTMLElements, not whatever specialized class happens to be setting innerHTML / outerHTML).
105
+ * @param {string} html
106
+ * @returns {Array<*>}
107
+ */
108
+ private parse;
109
+ /**
110
+ * Replace this element's children by parsing html. innerHTML's setter is here rather than on ElementService (which
111
+ * only has the getter) because building the new elements needs a concrete element class - see parse().
112
+ * @param {string} html
113
+ * @returns {undefined}
114
+ */
115
+ set innerHTML(html: string);
116
+ get innerHTML(): string;
117
+ /**
118
+ * Replace this element itself, in its parent, by parsing html. Does nothing when it has no parent, like
119
+ * replaceWith. outerHTML's setter is here rather than on ElementService for the same reason as innerHTML's.
120
+ * @param {string} html
121
+ * @returns {undefined}
122
+ */
123
+ set outerHTML(html: string);
124
+ get outerHTML(): string;
125
+ /**
126
+ * Parse html and insert the resulting nodes at the given position, like insertAdjacentElement /
127
+ * insertAdjacentText.
128
+ * @param {string} position beforebegin, afterbegin, beforeend or afterend
129
+ * @param {string} html The markup to parse
130
+ * @returns {undefined}
131
+ * @throws {Error} When the position is not one of the four above
132
+ */
133
+ insertAdjacentHTML(position: string, html: string): void;
134
+ /**
135
+ * Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
136
+ * @returns {boolean}
137
+ */
138
+ get canFocus(): boolean;
139
+ /**
140
+ * Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
141
+ * script made it (so it is not trusted). A disabled element does nothing.
142
+ */
143
+ click(): void;
144
+ /**
145
+ * Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
146
+ * focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
147
+ * focus or already has it.
148
+ */
149
+ focus(): void;
150
+ /**
151
+ * Take the focus away from the element, when it has it: it gets blur then focusout.
152
+ */
153
+ blur(): void;
154
+ }