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.
- package/README.md +51 -1
- package/browser/pseudo-dom.js +85 -1
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/interfaces/PseudoElement.d.ts +789 -789
- package/dist/services/ElementService.d.ts +527 -527
- package/dist/services/ElementService.js +1149 -1149
- package/dist/services/HTMLElementService.d.ts +154 -119
- package/dist/services/HTMLElementService.js +353 -269
- package/dist/services/HTMLElementService.min.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
* @param {
|
|
34
|
-
* @param {
|
|
35
|
-
* @
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
*
|
|
70
|
-
* @param {string}
|
|
71
|
-
* @
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
get
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* @returns {undefined}
|
|
87
|
-
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* @
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
}
|