pseudo-dom 0.8.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.
- package/README.md +206 -1
- package/browser/pseudo-dom.js +813 -470
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/classes/PseudoHTMLDocument.d.ts +41 -41
- package/dist/classes/PseudoHTMLDocument.js +74 -74
- package/dist/factories/createDataset.d.ts +10 -0
- package/dist/factories/createDataset.js +78 -0
- package/dist/factories/createDataset.min.js +1 -0
- package/dist/factories/createStyleDeclaration.d.ts +30 -0
- package/dist/factories/createStyleDeclaration.js +64 -0
- package/dist/factories/createStyleDeclaration.min.js +1 -0
- package/dist/functions/getElementById.d.ts +13 -13
- package/dist/functions/getElementById.js +33 -33
- package/dist/interfaces/PseudoCSSStyleDeclaration.d.ts +14 -0
- package/dist/interfaces/PseudoCSSStyleDeclaration.js +5 -0
- package/dist/interfaces/PseudoCSSStyleDeclaration.min.js +1 -0
- package/dist/interfaces/PseudoDocument.d.ts +35 -35
- package/dist/interfaces/PseudoDocumentFragment.d.ts +10 -10
- package/dist/interfaces/PseudoHTMLElement.d.ts +33 -22
- package/dist/services/CSSStyleDeclarationService.d.ts +73 -0
- package/dist/services/CSSStyleDeclarationService.js +156 -0
- package/dist/services/CSSStyleDeclarationService.min.js +1 -0
- package/dist/services/DocumentFragmentService.d.ts +21 -21
- package/dist/services/DocumentFragmentService.js +42 -42
- package/dist/services/DocumentService.d.ts +46 -46
- package/dist/services/DocumentService.js +95 -95
- package/dist/services/HTMLElementService.d.ts +87 -57
- package/dist/services/HTMLElementService.js +202 -163
- package/dist/services/HTMLElementService.min.js +1 -1
- package/package.json +1 -1
|
@@ -1,163 +1,202 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
-
return mod && mod.__esModule
|
|
5
|
-
? mod
|
|
6
|
-
: {
|
|
7
|
-
default: mod
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(exports, '__esModule', {
|
|
11
|
-
value: true
|
|
12
|
-
})
|
|
13
|
-
exports.HTMLElementService = void 0
|
|
14
|
-
const ElementService_1 = require('./ElementService')
|
|
15
|
-
const createEvent_1 = __importDefault(require('../factories/createEvent'))
|
|
16
|
-
const activeElement_1 = require('../functions/activeElement')
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
22
|
-
* @
|
|
23
|
-
* @
|
|
24
|
-
* @property {
|
|
25
|
-
* @property {
|
|
26
|
-
* @property {number}
|
|
27
|
-
* @property {
|
|
28
|
-
* @property {
|
|
29
|
-
* @property {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
* @param {
|
|
38
|
-
* @
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
name: '
|
|
52
|
-
value:
|
|
53
|
-
}, {
|
|
54
|
-
name: '
|
|
55
|
-
value: 0
|
|
56
|
-
}, {
|
|
57
|
-
name: '
|
|
58
|
-
value:
|
|
59
|
-
}, {
|
|
60
|
-
name: '
|
|
61
|
-
value:
|
|
62
|
-
}, {
|
|
63
|
-
name: '
|
|
64
|
-
value: 0
|
|
65
|
-
}, {
|
|
66
|
-
name: '
|
|
67
|
-
value:
|
|
68
|
-
}, {
|
|
69
|
-
name: 'title',
|
|
70
|
-
value: ''
|
|
71
|
-
}],
|
|
72
|
-
parent,
|
|
73
|
-
children
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule
|
|
5
|
+
? mod
|
|
6
|
+
: {
|
|
7
|
+
default: mod
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(exports, '__esModule', {
|
|
11
|
+
value: true
|
|
12
|
+
})
|
|
13
|
+
exports.HTMLElementService = void 0
|
|
14
|
+
const ElementService_1 = require('./ElementService')
|
|
15
|
+
const createEvent_1 = __importDefault(require('../factories/createEvent'))
|
|
16
|
+
const activeElement_1 = require('../functions/activeElement')
|
|
17
|
+
const createStyleDeclaration_1 = __importDefault(require('../factories/createStyleDeclaration'))
|
|
18
|
+
const createDataset_1 = __importDefault(require('../factories/createDataset'))
|
|
19
|
+
/**
|
|
20
|
+
* Simulate the behaviour of the HTMLElement Class when there is no DOM available.
|
|
21
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
22
|
+
* @class
|
|
23
|
+
* @augments PseudoElement
|
|
24
|
+
* @property {boolean} hidden - State of whether element is visible
|
|
25
|
+
* @property {number} offsetHeight - The height of the element as offset by the parent element
|
|
26
|
+
* @property {number} offsetLeft - The position of the left side of the element based on the parent element
|
|
27
|
+
* @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
|
|
28
|
+
* @property {number} offsetTop - The position of the top side of the element based on the parent element
|
|
29
|
+
* @property {number} offsetWidth - The width of the element as offset by the parent element
|
|
30
|
+
* @property {CSSStyleDeclarationService} style - The element's inline styles, live and settable per property
|
|
31
|
+
* @property {Object.<string, string>} dataset - The element's data-* attributes, live, under their camelCase names
|
|
32
|
+
* @property {string} title - The title attribute which affects the text visible on hover
|
|
33
|
+
*/
|
|
34
|
+
class HTMLElementService extends ElementService_1.ElementService {
|
|
35
|
+
/**
|
|
36
|
+
* Simulate the HTMLElement object when the Dom is not available
|
|
37
|
+
* @param {Object} [elementOptions={}]
|
|
38
|
+
* @param {string} [elementOptions.tagName='']
|
|
39
|
+
* @param {PseudoNode|Object} [elementOptions.parent={}]
|
|
40
|
+
* @param {Array} [elementOptions.children=[]]
|
|
41
|
+
* @constructor
|
|
42
|
+
*/
|
|
43
|
+
constructor ({
|
|
44
|
+
tagName = '',
|
|
45
|
+
parent = null,
|
|
46
|
+
children = []
|
|
47
|
+
} = {}) {
|
|
48
|
+
super({
|
|
49
|
+
tagName,
|
|
50
|
+
attributes: [{
|
|
51
|
+
name: 'hidden',
|
|
52
|
+
value: false
|
|
53
|
+
}, {
|
|
54
|
+
name: 'offsetHeight',
|
|
55
|
+
value: 0
|
|
56
|
+
}, {
|
|
57
|
+
name: 'offsetLeft',
|
|
58
|
+
value: 0
|
|
59
|
+
}, {
|
|
60
|
+
name: 'offsetParent',
|
|
61
|
+
value: null
|
|
62
|
+
}, {
|
|
63
|
+
name: 'offsetTop',
|
|
64
|
+
value: 0
|
|
65
|
+
}, {
|
|
66
|
+
name: 'offsetWidth',
|
|
67
|
+
value: 0
|
|
68
|
+
}, {
|
|
69
|
+
name: 'title',
|
|
70
|
+
value: ''
|
|
71
|
+
}],
|
|
72
|
+
parent,
|
|
73
|
+
children
|
|
74
|
+
})
|
|
75
|
+
this.styleDeclaration = (0, createStyleDeclaration_1.default)()
|
|
76
|
+
this.datasetProxy = (0, createDataset_1.default)(this)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The element's inline styles: a live CSSStyleDeclaration-like object, so both style.setProperty('color', 'red')
|
|
81
|
+
* and style.color = 'red' work.
|
|
82
|
+
* @returns {CSSStyleDeclarationService}
|
|
83
|
+
*/
|
|
84
|
+
get style () {
|
|
85
|
+
return this.styleDeclaration
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The element's data-* attributes, live, under their camelCase names (data-foo-bar <-> dataset.fooBar). Backed
|
|
90
|
+
* directly by getAttribute / setAttribute, so it is never out of sync with the attributes themselves.
|
|
91
|
+
* @returns {Object.<string, string>}
|
|
92
|
+
*/
|
|
93
|
+
get dataset () {
|
|
94
|
+
return this.datasetProxy
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Style is not attribute-backed like most properties (see the constructor), so cloneNode needs its own copy of it.
|
|
99
|
+
* @returns {NodeService}
|
|
100
|
+
*/
|
|
101
|
+
cloneShallow () {
|
|
102
|
+
const copy = super.cloneShallow()
|
|
103
|
+
copy.style.cssText = this.style.cssText
|
|
104
|
+
return copy
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Style is not attribute-backed like most properties, so isEqualNode needs to compare it separately too.
|
|
109
|
+
* @param {NodeService} other The node to compare with
|
|
110
|
+
* @returns {boolean}
|
|
111
|
+
*/
|
|
112
|
+
equalsShallow (other) {
|
|
113
|
+
return super.equalsShallow(other) && this.style.cssText === other.style.cssText
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
|
|
118
|
+
* @returns {boolean}
|
|
119
|
+
*/
|
|
120
|
+
get canFocus () {
|
|
121
|
+
if (this.hasAttribute('disabled')) {
|
|
122
|
+
return false
|
|
123
|
+
}
|
|
124
|
+
switch (this.tagName) {
|
|
125
|
+
case 'button':
|
|
126
|
+
case 'select':
|
|
127
|
+
case 'textarea':
|
|
128
|
+
return true
|
|
129
|
+
case 'input':
|
|
130
|
+
return String(this.getAttribute('type') || '').toLowerCase() !== 'hidden'
|
|
131
|
+
case 'a':
|
|
132
|
+
return this.hasAttribute('href') || this.hasAttribute('tabindex')
|
|
133
|
+
default:
|
|
134
|
+
return this.hasAttribute('tabindex')
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
|
|
140
|
+
* script made it (so it is not trusted). A disabled element does nothing.
|
|
141
|
+
*/
|
|
142
|
+
click () {
|
|
143
|
+
if (this.hasAttribute('disabled')) {
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
this.dispatchEvent((0, createEvent_1.default)('click', {}, {
|
|
147
|
+
browser: true
|
|
148
|
+
}))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
|
|
153
|
+
* focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
|
|
154
|
+
* focus or already has it.
|
|
155
|
+
*/
|
|
156
|
+
focus () {
|
|
157
|
+
const root = this.getRootNode()
|
|
158
|
+
const previous = (0, activeElement_1.getActiveElement)(root)
|
|
159
|
+
if (!this.canFocus || previous === this) {
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
const send = (target, type, relatedTarget) => {
|
|
163
|
+
target.dispatchEvent((0, createEvent_1.default)(type, {
|
|
164
|
+
relatedTarget
|
|
165
|
+
}, {
|
|
166
|
+
browser: true,
|
|
167
|
+
trusted: true
|
|
168
|
+
}))
|
|
169
|
+
}
|
|
170
|
+
if (previous) {
|
|
171
|
+
send(previous, 'blur', this)
|
|
172
|
+
send(previous, 'focusout', this)
|
|
173
|
+
}
|
|
174
|
+
(0, activeElement_1.setActiveElement)(root, this)
|
|
175
|
+
send(this, 'focus', previous)
|
|
176
|
+
send(this, 'focusin', previous)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Take the focus away from the element, when it has it: it gets blur then focusout.
|
|
181
|
+
*/
|
|
182
|
+
blur () {
|
|
183
|
+
const root = this.getRootNode()
|
|
184
|
+
if ((0, activeElement_1.getActiveElement)(root) !== this) {
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
(0, activeElement_1.setActiveElement)(root, null)
|
|
188
|
+
this.dispatchEvent((0, createEvent_1.default)('blur', {
|
|
189
|
+
relatedTarget: null
|
|
190
|
+
}, {
|
|
191
|
+
browser: true,
|
|
192
|
+
trusted: true
|
|
193
|
+
}))
|
|
194
|
+
this.dispatchEvent((0, createEvent_1.default)('focusout', {
|
|
195
|
+
relatedTarget: null
|
|
196
|
+
}, {
|
|
197
|
+
browser: true,
|
|
198
|
+
trusted: true
|
|
199
|
+
}))
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.HTMLElementService = HTMLElementService
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.HTMLElementService=void 0;const ElementService_1=require("./ElementService"),createEvent_1=__importDefault(require("../factories/createEvent")),activeElement_1=require("../functions/activeElement");class HTMLElementService extends ElementService_1.ElementService{constructor({tagName:e="",parent:t=null,children:
|
|
1
|
+
"use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.HTMLElementService=void 0;const ElementService_1=require("./ElementService"),createEvent_1=__importDefault(require("../factories/createEvent")),activeElement_1=require("../functions/activeElement"),createStyleDeclaration_1=__importDefault(require("../factories/createStyleDeclaration")),createDataset_1=__importDefault(require("../factories/createDataset"));class HTMLElementService extends ElementService_1.ElementService{constructor({tagName:e="",parent:t=null,children:a=[]}={}){super({tagName:e,attributes:[{name:"hidden",value:!1},{name:"offsetHeight",value:0},{name:"offsetLeft",value:0},{name:"offsetParent",value:null},{name:"offsetTop",value:0},{name:"offsetWidth",value:0},{name:"title",value:""}],parent:t,children:a}),this.styleDeclaration=(0,createStyleDeclaration_1.default)(),this.datasetProxy=(0,createDataset_1.default)(this)}get style(){return this.styleDeclaration}get dataset(){return this.datasetProxy}cloneShallow(){const e=super.cloneShallow();return e.style.cssText=this.style.cssText,e}equalsShallow(e){return super.equalsShallow(e)&&this.style.cssText===e.style.cssText}get canFocus(){if(this.hasAttribute("disabled"))return!1;switch(this.tagName){case"button":case"select":case"textarea":return!0;case"input":return"hidden"!==String(this.getAttribute("type")||"").toLowerCase();case"a":return this.hasAttribute("href")||this.hasAttribute("tabindex");default:return this.hasAttribute("tabindex")}}click(){this.hasAttribute("disabled")||this.dispatchEvent((0,createEvent_1.default)("click",{},{browser:!0}))}focus(){const e=this.getRootNode(),t=(0,activeElement_1.getActiveElement)(e);if(!this.canFocus||t===this)return;const a=(e,t,a)=>{e.dispatchEvent((0,createEvent_1.default)(t,{relatedTarget:a},{browser:!0,trusted:!0}))};t&&(a(t,"blur",this),a(t,"focusout",this)),(0,activeElement_1.setActiveElement)(e,this),a(this,"focus",t),a(this,"focusin",t)}blur(){const e=this.getRootNode();(0,activeElement_1.getActiveElement)(e)===this&&((0,activeElement_1.setActiveElement)(e,null),this.dispatchEvent((0,createEvent_1.default)("blur",{relatedTarget:null},{browser:!0,trusted:!0})),this.dispatchEvent((0,createEvent_1.default)("focusout",{relatedTarget:null},{browser:!0,trusted:!0})))}}exports.HTMLElementService=HTMLElementService;
|