pseudo-dom 0.5.1 → 0.7.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 +1495 -119
- package/browser/pseudo-dom.js +3539 -482
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/classes/PseudoEventListener.d.ts +96 -96
- package/dist/classes/PseudoEventListener.js +151 -151
- package/dist/classes/PseudoHTMLDocument.d.ts +67 -67
- package/dist/classes/PseudoHTMLDocument.js +144 -144
- package/dist/classes/PseudoNodeList.d.ts +34 -34
- package/dist/classes/PseudoNodeList.js +71 -71
- package/dist/classes.d.ts +20 -20
- package/dist/classes.js +31 -31
- package/dist/factories/createEvent.d.ts +28 -28
- package/dist/factories/createEvent.js +56 -56
- package/dist/factories/cssSelectAdapter.d.ts +23 -0
- package/dist/factories/cssSelectAdapter.js +87 -0
- package/dist/factories/cssSelectAdapter.min.js +1 -0
- package/dist/factories/eventDefaults.d.ts +31 -31
- package/dist/factories/eventDefaults.js +105 -105
- package/dist/factories/generateDocument.d.ts +11 -11
- package/dist/factories/generateDocument.js +65 -65
- package/dist/factories/generateNode.d.ts +32 -32
- package/dist/factories/generateNode.js +85 -85
- package/dist/factories/generateNodeList.d.ts +9 -9
- package/dist/factories/generateNodeList.js +13 -13
- package/dist/factories/query.d.ts +33 -0
- package/dist/factories/query.js +66 -0
- package/dist/factories/query.min.js +1 -0
- package/dist/factories.d.ts +11 -11
- package/dist/factories.js +27 -27
- package/dist/functions/activeElement.d.ts +14 -14
- package/dist/functions/activeElement.js +33 -33
- package/dist/functions/getParentNodes.d.ts +11 -11
- package/dist/functions/getParentNodes.js +22 -22
- package/dist/functions/getParentNodesFromAttribute.d.ts +14 -14
- package/dist/functions/getParentNodesFromAttribute.js +29 -29
- package/dist/functions/modifierState.d.ts +29 -29
- package/dist/functions/modifierState.js +41 -41
- package/dist/functions.d.ts +5 -5
- package/dist/functions.js +23 -23
- package/dist/interfaces/PseudoAnimation.d.ts +3 -3
- package/dist/interfaces/PseudoAnimation.js +5 -5
- package/dist/interfaces/PseudoAttr.d.ts +11 -11
- package/dist/interfaces/PseudoAttr.js +5 -5
- package/dist/interfaces/PseudoDOMTokenList.d.ts +16 -16
- package/dist/interfaces/PseudoDOMTokenList.js +5 -5
- package/dist/interfaces/PseudoDocument.d.ts +7 -0
- package/dist/interfaces/PseudoDocument.js +5 -5
- package/dist/interfaces/PseudoDocumentFragment.d.ts +3 -3
- package/dist/interfaces/PseudoDocumentFragment.js +5 -5
- package/dist/interfaces/PseudoElement.d.ts +48 -24
- package/dist/interfaces/PseudoElement.js +5 -5
- package/dist/interfaces/PseudoEvent.d.ts +79 -79
- package/dist/interfaces/PseudoEvent.js +10 -10
- package/dist/interfaces/PseudoEventTarget.d.ts +46 -46
- package/dist/interfaces/PseudoEventTarget.js +5 -5
- package/dist/interfaces/PseudoHTMLCollection.d.ts +23 -2
- package/dist/interfaces/PseudoHTMLCollection.js +5 -5
- package/dist/interfaces/PseudoHTMLElement.d.ts +22 -22
- package/dist/interfaces/PseudoHTMLElement.js +5 -5
- package/dist/interfaces/PseudoHTMLSlotElement.d.ts +3 -3
- package/dist/interfaces/PseudoHTMLSlotElement.js +5 -5
- package/dist/interfaces/PseudoNamedNodeMap.d.ts +11 -11
- package/dist/interfaces/PseudoNamedNodeMap.js +5 -5
- package/dist/interfaces/PseudoNode.d.ts +179 -179
- package/dist/interfaces/PseudoNode.js +5 -5
- package/dist/interfaces/PseudoShadowRoot.d.ts +3 -3
- package/dist/interfaces/PseudoShadowRoot.js +5 -5
- package/dist/main.d.ts +63 -63
- package/dist/main.js +155 -155
- package/dist/services/AnimationService.d.ts +4 -4
- package/dist/services/AnimationService.js +16 -16
- package/dist/services/AttrService.d.ts +37 -37
- package/dist/services/AttrService.js +81 -81
- package/dist/services/CommentService.d.ts +1 -1
- package/dist/services/CommentService.js +13 -13
- package/dist/services/CustomEventService.d.ts +37 -37
- package/dist/services/CustomEventService.js +35 -35
- package/dist/services/DOMTokenListService.d.ts +33 -33
- package/dist/services/DOMTokenListService.js +117 -117
- package/dist/services/DocumentFragmentService.d.ts +13 -13
- package/dist/services/DocumentFragmentService.js +24 -24
- package/dist/services/DocumentService.d.ts +7 -0
- package/dist/services/DocumentService.js +23 -0
- package/dist/services/DocumentService.min.js +1 -1
- package/dist/services/ElementService.d.ts +77 -1
- package/dist/services/ElementService.js +143 -0
- package/dist/services/ElementService.min.js +1 -1
- package/dist/services/EventService.d.ts +120 -120
- package/dist/services/EventService.js +250 -250
- package/dist/services/EventTargetService.d.ts +84 -84
- package/dist/services/EventTargetService.js +232 -232
- package/dist/services/FocusEventService.d.ts +32 -32
- package/dist/services/FocusEventService.js +35 -35
- package/dist/services/HTMLCollectionService.d.ts +51 -0
- package/dist/services/HTMLCollectionService.js +85 -1
- package/dist/services/HTMLCollectionService.min.js +1 -1
- package/dist/services/HTMLElementService.d.ts +57 -57
- package/dist/services/HTMLElementService.js +163 -163
- package/dist/services/HTMLSlotElementService.d.ts +4 -4
- package/dist/services/HTMLSlotElementService.js +9 -9
- package/dist/services/InputEventService.d.ts +41 -41
- package/dist/services/InputEventService.js +47 -47
- package/dist/services/KeyboardEventService.d.ts +70 -70
- package/dist/services/KeyboardEventService.js +86 -86
- package/dist/services/MouseEventService.d.ts +80 -80
- package/dist/services/MouseEventService.js +108 -108
- package/dist/services/NamedNodeMapService.d.ts +23 -23
- package/dist/services/NamedNodeMapService.js +77 -77
- package/dist/services/NodeService.d.ts +75 -1
- package/dist/services/NodeService.js +145 -7
- package/dist/services/NodeService.min.js +1 -1
- package/dist/services/PointerEventService.d.ts +51 -51
- package/dist/services/PointerEventService.js +67 -67
- package/dist/services/ShadowRootService.d.ts +4 -4
- package/dist/services/ShadowRootService.js +9 -9
- package/dist/services/TextService.d.ts +1 -1
- package/dist/services/TextService.js +13 -13
- package/dist/services/UIEventService.d.ts +43 -43
- package/dist/services/UIEventService.js +42 -42
- package/dist/simulate.d.ts +32 -32
- package/dist/simulate.js +115 -115
- package/package.json +3 -2
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.MouseEventService = void 0
|
|
7
|
-
/**
|
|
8
|
-
* @file Substitute for the DOM MouseEvent Class.
|
|
9
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
10
|
-
* @version 1.0.0
|
|
11
|
-
*/
|
|
12
|
-
const UIEventService_1 = require('./UIEventService')
|
|
13
|
-
const modifierState_1 = require('../functions/modifierState')
|
|
14
|
-
/**
|
|
15
|
-
* Simulate the behaviour of the MouseEvent Class when there is no DOM available.
|
|
16
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
17
|
-
* @class
|
|
18
|
-
* @augments UIEventService
|
|
19
|
-
* @property {number} screenX
|
|
20
|
-
* @property {number} screenY
|
|
21
|
-
* @property {number} clientX
|
|
22
|
-
* @property {number} clientY
|
|
23
|
-
* @property {number} button
|
|
24
|
-
* @property {number} buttons
|
|
25
|
-
* @property {PseudoEventTarget|null} relatedTarget
|
|
26
|
-
*/
|
|
27
|
-
class MouseEventService extends UIEventService_1.UIEventService {
|
|
28
|
-
/**
|
|
29
|
-
* @param {string} [typeArg=''] The type of the event
|
|
30
|
-
* @param {MouseEventInit} [init={}] The options for the event
|
|
31
|
-
* @constructor
|
|
32
|
-
*/
|
|
33
|
-
constructor (typeArg = '', init = {}) {
|
|
34
|
-
super(typeArg, init)
|
|
35
|
-
this.position = {
|
|
36
|
-
screenX: init.screenX || 0,
|
|
37
|
-
screenY: init.screenY || 0,
|
|
38
|
-
clientX: init.clientX || 0,
|
|
39
|
-
clientY: init.clientY || 0
|
|
40
|
-
}
|
|
41
|
-
this.modifiers = (0, modifierState_1.modifierKeys)(init)
|
|
42
|
-
this.buttonPressed = init.button || 0
|
|
43
|
-
this.buttonsDown = init.buttons || 0
|
|
44
|
-
this.related = init.relatedTarget || null
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get screenX () {
|
|
48
|
-
return this.position.screenX
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get screenY () {
|
|
52
|
-
return this.position.screenY
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get clientX () {
|
|
56
|
-
return this.position.clientX
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get clientY () {
|
|
60
|
-
return this.position.clientY
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get x () {
|
|
64
|
-
return this.position.clientX
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get y () {
|
|
68
|
-
return this.position.clientY
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
get ctrlKey () {
|
|
72
|
-
return this.modifiers.ctrlKey
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
get shiftKey () {
|
|
76
|
-
return this.modifiers.shiftKey
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
get altKey () {
|
|
80
|
-
return this.modifiers.altKey
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
get metaKey () {
|
|
84
|
-
return this.modifiers.metaKey
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
get button () {
|
|
88
|
-
return this.buttonPressed
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
get buttons () {
|
|
92
|
-
return this.buttonsDown
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
get relatedTarget () {
|
|
96
|
-
return this.related
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Whether a modifier key was held down when the event happened.
|
|
101
|
-
* @param {string} key Control, Shift, Alt or Meta
|
|
102
|
-
* @returns {boolean}
|
|
103
|
-
*/
|
|
104
|
-
getModifierState (key) {
|
|
105
|
-
return (0, modifierState_1.modifierState)(this.modifiers, key)
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.MouseEventService = MouseEventService
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.MouseEventService = void 0
|
|
7
|
+
/**
|
|
8
|
+
* @file Substitute for the DOM MouseEvent Class.
|
|
9
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
10
|
+
* @version 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
const UIEventService_1 = require('./UIEventService')
|
|
13
|
+
const modifierState_1 = require('../functions/modifierState')
|
|
14
|
+
/**
|
|
15
|
+
* Simulate the behaviour of the MouseEvent Class when there is no DOM available.
|
|
16
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
17
|
+
* @class
|
|
18
|
+
* @augments UIEventService
|
|
19
|
+
* @property {number} screenX
|
|
20
|
+
* @property {number} screenY
|
|
21
|
+
* @property {number} clientX
|
|
22
|
+
* @property {number} clientY
|
|
23
|
+
* @property {number} button
|
|
24
|
+
* @property {number} buttons
|
|
25
|
+
* @property {PseudoEventTarget|null} relatedTarget
|
|
26
|
+
*/
|
|
27
|
+
class MouseEventService extends UIEventService_1.UIEventService {
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} [typeArg=''] The type of the event
|
|
30
|
+
* @param {MouseEventInit} [init={}] The options for the event
|
|
31
|
+
* @constructor
|
|
32
|
+
*/
|
|
33
|
+
constructor (typeArg = '', init = {}) {
|
|
34
|
+
super(typeArg, init)
|
|
35
|
+
this.position = {
|
|
36
|
+
screenX: init.screenX || 0,
|
|
37
|
+
screenY: init.screenY || 0,
|
|
38
|
+
clientX: init.clientX || 0,
|
|
39
|
+
clientY: init.clientY || 0
|
|
40
|
+
}
|
|
41
|
+
this.modifiers = (0, modifierState_1.modifierKeys)(init)
|
|
42
|
+
this.buttonPressed = init.button || 0
|
|
43
|
+
this.buttonsDown = init.buttons || 0
|
|
44
|
+
this.related = init.relatedTarget || null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get screenX () {
|
|
48
|
+
return this.position.screenX
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get screenY () {
|
|
52
|
+
return this.position.screenY
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get clientX () {
|
|
56
|
+
return this.position.clientX
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get clientY () {
|
|
60
|
+
return this.position.clientY
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get x () {
|
|
64
|
+
return this.position.clientX
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get y () {
|
|
68
|
+
return this.position.clientY
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get ctrlKey () {
|
|
72
|
+
return this.modifiers.ctrlKey
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get shiftKey () {
|
|
76
|
+
return this.modifiers.shiftKey
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get altKey () {
|
|
80
|
+
return this.modifiers.altKey
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get metaKey () {
|
|
84
|
+
return this.modifiers.metaKey
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get button () {
|
|
88
|
+
return this.buttonPressed
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get buttons () {
|
|
92
|
+
return this.buttonsDown
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get relatedTarget () {
|
|
96
|
+
return this.related
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Whether a modifier key was held down when the event happened.
|
|
101
|
+
* @param {string} key Control, Shift, Alt or Meta
|
|
102
|
+
* @returns {boolean}
|
|
103
|
+
*/
|
|
104
|
+
getModifierState (key) {
|
|
105
|
+
return (0, modifierState_1.modifierState)(this.modifiers, key)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.MouseEventService = MouseEventService
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { PseudoNamedNodeMap } from '../interfaces/PseudoNamedNodeMap';
|
|
2
|
-
import { PseudoAttr } from '../interfaces/PseudoAttr';
|
|
3
|
-
/**
|
|
4
|
-
* Simulate the behaviour of the NamedNodeMap Class when there is no DOM available.
|
|
5
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
6
|
-
* @class
|
|
7
|
-
*/
|
|
8
|
-
export declare class NamedNodeMapService implements PseudoNamedNodeMap {
|
|
9
|
-
private attributes;
|
|
10
|
-
/**
|
|
11
|
-
* @param {Array<PseudoAttr>} [attributes=[]] The attributes to start with
|
|
12
|
-
* @constructor
|
|
13
|
-
*/
|
|
14
|
-
constructor(attributes?: Array<PseudoAttr>);
|
|
15
|
-
get length(): number;
|
|
16
|
-
getNamedItem(name: string): PseudoAttr | null;
|
|
17
|
-
setNamedItem(attr: PseudoAttr): PseudoAttr | null;
|
|
18
|
-
removeNamedItem(attrName: string): PseudoAttr;
|
|
19
|
-
item(index: number): PseudoAttr | null;
|
|
20
|
-
getNamedItemNS(namespace: string, localName: string): PseudoAttr | null;
|
|
21
|
-
setNamedItemNS(attr: PseudoAttr): PseudoAttr | null;
|
|
22
|
-
removeNamedItemNS(namespace: string, localName: string): PseudoAttr;
|
|
23
|
-
}
|
|
1
|
+
import { PseudoNamedNodeMap } from '../interfaces/PseudoNamedNodeMap';
|
|
2
|
+
import { PseudoAttr } from '../interfaces/PseudoAttr';
|
|
3
|
+
/**
|
|
4
|
+
* Simulate the behaviour of the NamedNodeMap Class when there is no DOM available.
|
|
5
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
6
|
+
* @class
|
|
7
|
+
*/
|
|
8
|
+
export declare class NamedNodeMapService implements PseudoNamedNodeMap {
|
|
9
|
+
private attributes;
|
|
10
|
+
/**
|
|
11
|
+
* @param {Array<PseudoAttr>} [attributes=[]] The attributes to start with
|
|
12
|
+
* @constructor
|
|
13
|
+
*/
|
|
14
|
+
constructor(attributes?: Array<PseudoAttr>);
|
|
15
|
+
get length(): number;
|
|
16
|
+
getNamedItem(name: string): PseudoAttr | null;
|
|
17
|
+
setNamedItem(attr: PseudoAttr): PseudoAttr | null;
|
|
18
|
+
removeNamedItem(attrName: string): PseudoAttr;
|
|
19
|
+
item(index: number): PseudoAttr | null;
|
|
20
|
+
getNamedItemNS(namespace: string, localName: string): PseudoAttr | null;
|
|
21
|
+
setNamedItemNS(attr: PseudoAttr): PseudoAttr | null;
|
|
22
|
+
removeNamedItemNS(namespace: string, localName: string): PseudoAttr;
|
|
23
|
+
}
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
require('core-js/modules/esnext.iterator.constructor.js')
|
|
4
|
-
require('core-js/modules/esnext.iterator.find.js')
|
|
5
|
-
Object.defineProperty(exports, '__esModule', {
|
|
6
|
-
value: true
|
|
7
|
-
})
|
|
8
|
-
exports.NamedNodeMapService = void 0
|
|
9
|
-
/**
|
|
10
|
-
* Simulate the behaviour of the NamedNodeMap Class when there is no DOM available.
|
|
11
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
12
|
-
* @class
|
|
13
|
-
*/
|
|
14
|
-
class NamedNodeMapService {
|
|
15
|
-
/**
|
|
16
|
-
* @param {Array<PseudoAttr>} [attributes=[]] The attributes to start with
|
|
17
|
-
* @constructor
|
|
18
|
-
*/
|
|
19
|
-
constructor (attributes = []) {
|
|
20
|
-
this.attributes = attributes.slice()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get length () {
|
|
24
|
-
return this.attributes.length
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getNamedItem (name) {
|
|
28
|
-
return this.attributes.find(attr => attr.name === name) || null
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
setNamedItem (attr) {
|
|
32
|
-
const index = this.attributes.findIndex(existing => existing.name === attr.name)
|
|
33
|
-
if (index < 0) {
|
|
34
|
-
this.attributes.push(attr)
|
|
35
|
-
return null
|
|
36
|
-
}
|
|
37
|
-
const replaced = this.attributes[index]
|
|
38
|
-
this.attributes[index] = attr
|
|
39
|
-
return replaced
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
removeNamedItem (attrName) {
|
|
43
|
-
const index = this.attributes.findIndex(attr => attr.name === attrName)
|
|
44
|
-
if (index < 0) {
|
|
45
|
-
throw new Error(`The attribute "${attrName}" was not found.`)
|
|
46
|
-
}
|
|
47
|
-
return this.attributes.splice(index, 1)[0]
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
item (index) {
|
|
51
|
-
return this.attributes[index] || null
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
getNamedItemNS (namespace, localName) {
|
|
55
|
-
return this.attributes.find(attr => attr.namespaceURI === namespace && attr.localName === localName) || null
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
setNamedItemNS (attr) {
|
|
59
|
-
const index = this.attributes.findIndex(existing => existing.namespaceURI === attr.namespaceURI && existing.localName === attr.localName)
|
|
60
|
-
if (index < 0) {
|
|
61
|
-
this.attributes.push(attr)
|
|
62
|
-
return null
|
|
63
|
-
}
|
|
64
|
-
const replaced = this.attributes[index]
|
|
65
|
-
this.attributes[index] = attr
|
|
66
|
-
return replaced
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
removeNamedItemNS (namespace, localName) {
|
|
70
|
-
const index = this.attributes.findIndex(attr => attr.namespaceURI === namespace && attr.localName === localName)
|
|
71
|
-
if (index < 0) {
|
|
72
|
-
throw new Error(`The attribute "${localName}" in the namespace "${namespace}" was not found.`)
|
|
73
|
-
}
|
|
74
|
-
return this.attributes.splice(index, 1)[0]
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.NamedNodeMapService = NamedNodeMapService
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
4
|
+
require('core-js/modules/esnext.iterator.find.js')
|
|
5
|
+
Object.defineProperty(exports, '__esModule', {
|
|
6
|
+
value: true
|
|
7
|
+
})
|
|
8
|
+
exports.NamedNodeMapService = void 0
|
|
9
|
+
/**
|
|
10
|
+
* Simulate the behaviour of the NamedNodeMap Class when there is no DOM available.
|
|
11
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
12
|
+
* @class
|
|
13
|
+
*/
|
|
14
|
+
class NamedNodeMapService {
|
|
15
|
+
/**
|
|
16
|
+
* @param {Array<PseudoAttr>} [attributes=[]] The attributes to start with
|
|
17
|
+
* @constructor
|
|
18
|
+
*/
|
|
19
|
+
constructor (attributes = []) {
|
|
20
|
+
this.attributes = attributes.slice()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get length () {
|
|
24
|
+
return this.attributes.length
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getNamedItem (name) {
|
|
28
|
+
return this.attributes.find(attr => attr.name === name) || null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setNamedItem (attr) {
|
|
32
|
+
const index = this.attributes.findIndex(existing => existing.name === attr.name)
|
|
33
|
+
if (index < 0) {
|
|
34
|
+
this.attributes.push(attr)
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
const replaced = this.attributes[index]
|
|
38
|
+
this.attributes[index] = attr
|
|
39
|
+
return replaced
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
removeNamedItem (attrName) {
|
|
43
|
+
const index = this.attributes.findIndex(attr => attr.name === attrName)
|
|
44
|
+
if (index < 0) {
|
|
45
|
+
throw new Error(`The attribute "${attrName}" was not found.`)
|
|
46
|
+
}
|
|
47
|
+
return this.attributes.splice(index, 1)[0]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
item (index) {
|
|
51
|
+
return this.attributes[index] || null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getNamedItemNS (namespace, localName) {
|
|
55
|
+
return this.attributes.find(attr => attr.namespaceURI === namespace && attr.localName === localName) || null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
setNamedItemNS (attr) {
|
|
59
|
+
const index = this.attributes.findIndex(existing => existing.namespaceURI === attr.namespaceURI && existing.localName === attr.localName)
|
|
60
|
+
if (index < 0) {
|
|
61
|
+
this.attributes.push(attr)
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
const replaced = this.attributes[index]
|
|
65
|
+
this.attributes[index] = attr
|
|
66
|
+
return replaced
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
removeNamedItemNS (namespace, localName) {
|
|
70
|
+
const index = this.attributes.findIndex(attr => attr.namespaceURI === namespace && attr.localName === localName)
|
|
71
|
+
if (index < 0) {
|
|
72
|
+
throw new Error(`The attribute "${localName}" in the namespace "${namespace}" was not found.`)
|
|
73
|
+
}
|
|
74
|
+
return this.attributes.splice(index, 1)[0]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.NamedNodeMapService = NamedNodeMapService
|
|
@@ -6,6 +6,7 @@ import EventTargetService from './EventTargetService';
|
|
|
6
6
|
import { PseudoElement } from '../interfaces/PseudoElement';
|
|
7
7
|
import { PseudoDocument } from '../interfaces/PseudoDocument';
|
|
8
8
|
import { PseudoDocumentFragment } from '../interfaces/PseudoDocumentFragment';
|
|
9
|
+
import { HTMLCollectionService } from './HTMLCollectionService';
|
|
9
10
|
/**
|
|
10
11
|
* Simulate the behaviour of the Node Class when there is no DOM available.
|
|
11
12
|
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
@@ -36,7 +37,8 @@ export declare class NodeService extends EventTargetService implements PseudoNod
|
|
|
36
37
|
static readonly DOCUMENT_POSITION_CONTAINED_BY = 16;
|
|
37
38
|
static readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32;
|
|
38
39
|
private static nextNodeId;
|
|
39
|
-
children
|
|
40
|
+
/** The raw list of every child node (all types), used to implement childNodes/firstChild/lastChild/insertBefore/removeChild. Not the same thing as Element.children (an HTMLCollection of just the element children). */
|
|
41
|
+
protected childList: PseudoNodeList | LinkedTreeList;
|
|
40
42
|
parent: PseudoNode | null;
|
|
41
43
|
protected nodeNameValue: string;
|
|
42
44
|
private nodeValueStore;
|
|
@@ -91,6 +93,78 @@ export declare class NodeService extends EventTargetService implements PseudoNod
|
|
|
91
93
|
* @returns {boolean}
|
|
92
94
|
*/
|
|
93
95
|
protected equalsShallow(other: NodeService): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Add nodes (strings become text nodes) as the last children of this node, in the order given.
|
|
98
|
+
* @param {...(PseudoNode|string)} nodes The nodes (or text) to add
|
|
99
|
+
* @throws {Error} When this kind of node cannot have children
|
|
100
|
+
*/
|
|
101
|
+
append(...nodes: Array<PseudoNode | string>): void;
|
|
102
|
+
/**
|
|
103
|
+
* Add nodes (strings become text nodes) as the first children of this node, in the order given.
|
|
104
|
+
* @param {...(PseudoNode|string)} nodes The nodes (or text) to add
|
|
105
|
+
* @throws {Error} When this kind of node cannot have children
|
|
106
|
+
*/
|
|
107
|
+
prepend(...nodes: Array<PseudoNode | string>): void;
|
|
108
|
+
/**
|
|
109
|
+
* Remove every child of this node and put the given nodes (strings become text nodes) in their place, in order.
|
|
110
|
+
* @param {...(PseudoNode|string)} nodes The nodes (or text) to add
|
|
111
|
+
* @throws {Error} When this kind of node cannot have children
|
|
112
|
+
*/
|
|
113
|
+
replaceChildren(...nodes: Array<PseudoNode | string>): void;
|
|
114
|
+
/**
|
|
115
|
+
* Add nodes (strings become text nodes) as this node's previous siblings, in order. Does nothing when this node has
|
|
116
|
+
* no parent.
|
|
117
|
+
* @param {...(PseudoNode|string)} nodes The nodes (or text) to add
|
|
118
|
+
*/
|
|
119
|
+
before(...nodes: Array<PseudoNode | string>): void;
|
|
120
|
+
/**
|
|
121
|
+
* Add nodes (strings become text nodes) as this node's next siblings, in order. Does nothing when this node has no
|
|
122
|
+
* parent.
|
|
123
|
+
* @param {...(PseudoNode|string)} nodes The nodes (or text) to add
|
|
124
|
+
*/
|
|
125
|
+
after(...nodes: Array<PseudoNode | string>): void;
|
|
126
|
+
/**
|
|
127
|
+
* Put the given nodes (strings become text nodes) where this node is, in order, then remove this node. Does nothing
|
|
128
|
+
* when this node has no parent.
|
|
129
|
+
* @param {...(PseudoNode|string)} nodes The nodes (or text) to put in this node's place
|
|
130
|
+
*/
|
|
131
|
+
replaceWith(...nodes: Array<PseudoNode | string>): void;
|
|
132
|
+
/**
|
|
133
|
+
* Remove this node from its parent. Does nothing when it has no parent.
|
|
134
|
+
*/
|
|
135
|
+
remove(): void;
|
|
136
|
+
/**
|
|
137
|
+
* Turn a value given to append / prepend / before / after / replaceWith / replaceChildren into a node: a string
|
|
138
|
+
* becomes a text node belonging to this node's document, anything else is returned as it is.
|
|
139
|
+
* @param {PseudoNode|string} value The value to add
|
|
140
|
+
* @returns {PseudoNode}
|
|
141
|
+
*/
|
|
142
|
+
private toChildNode;
|
|
143
|
+
/**
|
|
144
|
+
* Every element below this node with the given tag name (or every element when tagName is *), live.
|
|
145
|
+
* @param {string} tagName
|
|
146
|
+
* @returns {PseudoHTMLCollection}
|
|
147
|
+
*/
|
|
148
|
+
getElementsByTagName(tagName: string): HTMLCollectionService;
|
|
149
|
+
/**
|
|
150
|
+
* Every element below this node which has all of the given (space separated) classes, live.
|
|
151
|
+
* @param {string} className
|
|
152
|
+
* @returns {PseudoHTMLCollection}
|
|
153
|
+
*/
|
|
154
|
+
getElementsByClassName(className: string): HTMLCollectionService;
|
|
155
|
+
/**
|
|
156
|
+
* The first element below this node which matches the CSS selector, in tree order, or null when there is none.
|
|
157
|
+
* @param {string} selectors A CSS selector
|
|
158
|
+
* @returns {PseudoElement|null}
|
|
159
|
+
*/
|
|
160
|
+
querySelector(selectors: string): PseudoElement | null;
|
|
161
|
+
/**
|
|
162
|
+
* Every element below this node which matches the CSS selector, in tree order. A plain array (not a live
|
|
163
|
+
* collection): like the DOM's querySelectorAll, it is a snapshot taken when it is called.
|
|
164
|
+
* @param {string} selectors A CSS selector
|
|
165
|
+
* @returns {Array<PseudoElement>}
|
|
166
|
+
*/
|
|
167
|
+
querySelectorAll(selectors: string): Array<PseudoElement>;
|
|
94
168
|
/**
|
|
95
169
|
* Called each time a node has been inserted as a child of this node, so that nodes which need to react to children
|
|
96
170
|
* (for example elements applying default events) can do so.
|