pseudo-dom 0.6.0 → 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.
Files changed (122) hide show
  1. package/README.md +432 -13
  2. package/browser/pseudo-dom.js +3364 -603
  3. package/browser/pseudo-dom.min.js +1 -1
  4. package/dist/classes/PseudoEventListener.d.ts +96 -96
  5. package/dist/classes/PseudoEventListener.js +151 -151
  6. package/dist/classes/PseudoHTMLDocument.d.ts +67 -67
  7. package/dist/classes/PseudoHTMLDocument.js +144 -144
  8. package/dist/classes/PseudoNodeList.d.ts +34 -34
  9. package/dist/classes/PseudoNodeList.js +71 -71
  10. package/dist/classes.d.ts +20 -20
  11. package/dist/classes.js +31 -31
  12. package/dist/factories/createEvent.d.ts +28 -28
  13. package/dist/factories/createEvent.js +56 -56
  14. package/dist/factories/cssSelectAdapter.d.ts +23 -0
  15. package/dist/factories/cssSelectAdapter.js +87 -0
  16. package/dist/factories/cssSelectAdapter.min.js +1 -0
  17. package/dist/factories/eventDefaults.d.ts +31 -31
  18. package/dist/factories/eventDefaults.js +105 -105
  19. package/dist/factories/generateDocument.d.ts +11 -11
  20. package/dist/factories/generateDocument.js +65 -65
  21. package/dist/factories/generateNode.d.ts +32 -32
  22. package/dist/factories/generateNode.js +85 -85
  23. package/dist/factories/generateNodeList.d.ts +9 -9
  24. package/dist/factories/generateNodeList.js +13 -13
  25. package/dist/factories/query.d.ts +33 -0
  26. package/dist/factories/query.js +66 -0
  27. package/dist/factories/query.min.js +1 -0
  28. package/dist/factories.d.ts +11 -11
  29. package/dist/factories.js +27 -27
  30. package/dist/functions/activeElement.d.ts +14 -14
  31. package/dist/functions/activeElement.js +33 -33
  32. package/dist/functions/getParentNodes.d.ts +11 -11
  33. package/dist/functions/getParentNodes.js +22 -22
  34. package/dist/functions/getParentNodesFromAttribute.d.ts +14 -14
  35. package/dist/functions/getParentNodesFromAttribute.js +29 -29
  36. package/dist/functions/modifierState.d.ts +29 -29
  37. package/dist/functions/modifierState.js +41 -41
  38. package/dist/functions.d.ts +5 -5
  39. package/dist/functions.js +23 -23
  40. package/dist/interfaces/PseudoAnimation.d.ts +3 -3
  41. package/dist/interfaces/PseudoAnimation.js +5 -5
  42. package/dist/interfaces/PseudoAttr.d.ts +11 -11
  43. package/dist/interfaces/PseudoAttr.js +5 -5
  44. package/dist/interfaces/PseudoDOMTokenList.d.ts +16 -16
  45. package/dist/interfaces/PseudoDOMTokenList.js +5 -5
  46. package/dist/interfaces/PseudoDocument.d.ts +7 -0
  47. package/dist/interfaces/PseudoDocument.js +5 -5
  48. package/dist/interfaces/PseudoDocumentFragment.d.ts +3 -3
  49. package/dist/interfaces/PseudoDocumentFragment.js +5 -5
  50. package/dist/interfaces/PseudoElement.d.ts +20 -7
  51. package/dist/interfaces/PseudoElement.js +5 -5
  52. package/dist/interfaces/PseudoEvent.d.ts +79 -79
  53. package/dist/interfaces/PseudoEvent.js +10 -10
  54. package/dist/interfaces/PseudoEventTarget.d.ts +46 -46
  55. package/dist/interfaces/PseudoEventTarget.js +5 -5
  56. package/dist/interfaces/PseudoHTMLCollection.d.ts +23 -23
  57. package/dist/interfaces/PseudoHTMLCollection.js +5 -5
  58. package/dist/interfaces/PseudoHTMLElement.d.ts +22 -22
  59. package/dist/interfaces/PseudoHTMLElement.js +5 -5
  60. package/dist/interfaces/PseudoHTMLSlotElement.d.ts +3 -3
  61. package/dist/interfaces/PseudoHTMLSlotElement.js +5 -5
  62. package/dist/interfaces/PseudoNamedNodeMap.d.ts +11 -11
  63. package/dist/interfaces/PseudoNamedNodeMap.js +5 -5
  64. package/dist/interfaces/PseudoNode.d.ts +179 -179
  65. package/dist/interfaces/PseudoNode.js +5 -5
  66. package/dist/interfaces/PseudoShadowRoot.d.ts +3 -3
  67. package/dist/interfaces/PseudoShadowRoot.js +5 -5
  68. package/dist/main.d.ts +63 -63
  69. package/dist/main.js +155 -155
  70. package/dist/services/AnimationService.d.ts +4 -4
  71. package/dist/services/AnimationService.js +16 -16
  72. package/dist/services/AttrService.d.ts +37 -37
  73. package/dist/services/AttrService.js +81 -81
  74. package/dist/services/CommentService.d.ts +1 -1
  75. package/dist/services/CommentService.js +13 -13
  76. package/dist/services/CustomEventService.d.ts +37 -37
  77. package/dist/services/CustomEventService.js +35 -35
  78. package/dist/services/DOMTokenListService.d.ts +33 -33
  79. package/dist/services/DOMTokenListService.js +117 -117
  80. package/dist/services/DocumentFragmentService.d.ts +13 -13
  81. package/dist/services/DocumentFragmentService.js +24 -24
  82. package/dist/services/DocumentService.d.ts +7 -0
  83. package/dist/services/DocumentService.js +23 -0
  84. package/dist/services/DocumentService.min.js +1 -1
  85. package/dist/services/ElementService.d.ts +13 -0
  86. package/dist/services/ElementService.js +20 -0
  87. package/dist/services/ElementService.min.js +1 -1
  88. package/dist/services/EventService.d.ts +120 -120
  89. package/dist/services/EventService.js +250 -250
  90. package/dist/services/EventTargetService.d.ts +84 -84
  91. package/dist/services/EventTargetService.js +232 -232
  92. package/dist/services/FocusEventService.d.ts +32 -32
  93. package/dist/services/FocusEventService.js +35 -35
  94. package/dist/services/HTMLCollectionService.d.ts +11 -6
  95. package/dist/services/HTMLCollectionService.js +25 -8
  96. package/dist/services/HTMLCollectionService.min.js +1 -1
  97. package/dist/services/HTMLElementService.d.ts +57 -57
  98. package/dist/services/HTMLElementService.js +163 -163
  99. package/dist/services/HTMLSlotElementService.d.ts +4 -4
  100. package/dist/services/HTMLSlotElementService.js +9 -9
  101. package/dist/services/InputEventService.d.ts +41 -41
  102. package/dist/services/InputEventService.js +47 -47
  103. package/dist/services/KeyboardEventService.d.ts +70 -70
  104. package/dist/services/KeyboardEventService.js +86 -86
  105. package/dist/services/MouseEventService.d.ts +80 -80
  106. package/dist/services/MouseEventService.js +108 -108
  107. package/dist/services/NamedNodeMapService.d.ts +23 -23
  108. package/dist/services/NamedNodeMapService.js +77 -77
  109. package/dist/services/NodeService.d.ts +26 -0
  110. package/dist/services/NodeService.js +42 -0
  111. package/dist/services/NodeService.min.js +1 -1
  112. package/dist/services/PointerEventService.d.ts +51 -51
  113. package/dist/services/PointerEventService.js +67 -67
  114. package/dist/services/ShadowRootService.d.ts +4 -4
  115. package/dist/services/ShadowRootService.js +9 -9
  116. package/dist/services/TextService.d.ts +1 -1
  117. package/dist/services/TextService.js +13 -13
  118. package/dist/services/UIEventService.d.ts +43 -43
  119. package/dist/services/UIEventService.js +42 -42
  120. package/dist/simulate.d.ts +32 -32
  121. package/dist/simulate.js +115 -115
  122. package/package.json +3 -2
@@ -1,250 +1,250 @@
1
- 'use strict'
2
-
3
- /**
4
- * @file Substitute for the DOM Event Class.
5
- * @author Joshua Heagle <joshuaheagle@gmail.com>
6
- * @version 1.0.0
7
- */
8
- Object.defineProperty(exports, '__esModule', {
9
- value: true
10
- })
11
- exports.EventService = void 0
12
- /**
13
- * Simulate the behaviour of the Event Class when there is no DOM available.
14
- * @author Joshua Heagle <joshuaheagle@gmail.com>
15
- * @class
16
- * @property {number} NONE
17
- * @property {number} CAPTURING_PHASE
18
- * @property {number} AT_TARGET
19
- * @property {number} BUBBLING_PHASE
20
- * @property {boolean} bubbles - A Boolean indicating whether the event bubbles up through the Dom or not.
21
- * @property {boolean} cancelable - A Boolean indicating whether the event is cancelable.
22
- * @property {boolean} composed - A Boolean value indicating whether the event can bubble across the boundary
23
- * between the shadow Dom and the regular Dom.
24
- * @property {function|PseudoEventTarget} currentTarget - A reference to the currently registered target for the event. This
25
- * is the object to which the event is currently slated to be sent; it's possible this has been changed along the way
26
- * through re-targeting.
27
- * @property {boolean} defaultPrevented - Indicates whether event.preventDefault() has been called on the event.
28
- * @property {boolean} immediatePropagationStopped - Flag that no further propagation should occur, including on current
29
- * target.
30
- * @property {boolean} propagationStopped - Flag that no further propagation should occur.
31
- * @property {int} eventPhase - Indicates which phase of the event flow is being processed. Uses EventService constants.
32
- * @property {EventTarget|PseudoEventTarget} target - A reference to the target to which the event was originally
33
- * dispatched.
34
- * @property {int} timeStamp - The time at which the event was created (in milliseconds). By specification, this
35
- * value is time since epoch, but in reality browsers' definitions vary; in addition, work is underway to change this
36
- * to be a DomHighResTimeStamp instead.
37
- * @property {string} type - The name of the event (case-insensitive).
38
- * @property {boolean} isTrusted - Indicates whether the event was initiated by the browser (after a user
39
- * click for instance) or by a script (using an event creation method, like event.initEvent)
40
- */
41
- class EventService {
42
- /**
43
- *
44
- * @param {string} typeArg
45
- * @param {Object} [eventOptions={}]
46
- * @param {boolean} [eventOptions.bubbles=false]
47
- * @param {boolean} [eventOptions.cancelable=false]
48
- * @param {boolean} [eventOptions.composed=false]
49
- * @constructor
50
- */
51
- constructor (typeArg = '', {
52
- bubbles = false,
53
- cancelable = false,
54
- composed = false
55
- } = {}) {
56
- this.properties = {
57
- bubbles: false,
58
- cancelable: false,
59
- composed: false,
60
- currentTarget: null,
61
- defaultPrevented: false,
62
- immediatePropagationStopped: false,
63
- propagationStopped: false,
64
- eventPhase: 0,
65
- target: null,
66
- timeStamp: Math.floor(Date.now() / 1000),
67
- type: '',
68
- isTrusted: false,
69
- dispatching: false,
70
- inPassiveListener: false,
71
- path: []
72
- }
73
- this.setReadOnlyProperties({
74
- type: typeArg,
75
- bubbles,
76
- cancelable,
77
- composed
78
- })
79
- }
80
-
81
- get bubbles () {
82
- return this.properties.bubbles
83
- }
84
-
85
- get cancelable () {
86
- return this.properties.cancelable
87
- }
88
-
89
- get composed () {
90
- return this.properties.composed
91
- }
92
-
93
- get currentTarget () {
94
- return this.properties.currentTarget
95
- }
96
-
97
- get defaultPrevented () {
98
- return this.properties.defaultPrevented
99
- }
100
-
101
- get eventPhase () {
102
- return this.properties.eventPhase
103
- }
104
-
105
- get isTrusted () {
106
- return this.properties.isTrusted
107
- }
108
-
109
- get target () {
110
- return this.properties.target
111
- }
112
-
113
- get timeStamp () {
114
- return this.properties.timeStamp
115
- }
116
-
117
- get type () {
118
- return this.properties.type
119
- }
120
-
121
- /**
122
- * Scope several accessors inside the inner object. These are only intended for usage by other DOM classes.
123
- * @returns {EventInner}
124
- */
125
- get inner () {
126
- const self = this
127
- return {
128
- get currentTarget () {
129
- return self.properties.currentTarget
130
- },
131
- set currentTarget (target) {
132
- self.properties.currentTarget = target
133
- },
134
- get eventPhase () {
135
- return self.properties.eventPhase
136
- },
137
- set eventPhase (phase) {
138
- self.properties.eventPhase = phase
139
- },
140
- get target () {
141
- return self.properties.target
142
- },
143
- set target (target) {
144
- self.properties.target = target
145
- },
146
- get immediatePropagationStopped () {
147
- return self.properties.immediatePropagationStopped
148
- },
149
- get propagationStopped () {
150
- return self.properties.propagationStopped
151
- },
152
- get trusted () {
153
- return self.properties.isTrusted
154
- },
155
- set trusted (trusted) {
156
- self.properties.isTrusted = trusted
157
- },
158
- get dispatching () {
159
- return self.properties.dispatching
160
- },
161
- set dispatching (dispatching) {
162
- self.properties.dispatching = dispatching
163
- },
164
- get inPassiveListener () {
165
- return self.properties.inPassiveListener
166
- },
167
- set inPassiveListener (passive) {
168
- self.properties.inPassiveListener = passive
169
- },
170
- get path () {
171
- return self.properties.path
172
- },
173
- set path (path) {
174
- self.properties.path = path
175
- },
176
- finishDispatch () {
177
- self.setReadOnlyProperties({
178
- currentTarget: null,
179
- eventPhase: EventService.NONE,
180
- path: [],
181
- dispatching: false,
182
- inPassiveListener: false,
183
- propagationStopped: false,
184
- immediatePropagationStopped: false
185
- })
186
- }
187
- }
188
- }
189
-
190
- /**
191
- * Return an array of targets that will have the event executed open them. The order is based on the eventPhase
192
- * @method
193
- * @returns {Array.<PseudoEventTarget>}
194
- */
195
- composedPath () {
196
- // While the event is being dispatched this is every target it travels through, the target first and the root last
197
- return this.properties.dispatching ? this.properties.path.slice() : []
198
- }
199
-
200
- /**
201
- * Cancels the event (if it is cancelable).
202
- * @method
203
- * @returns {null}
204
- */
205
- preventDefault () {
206
- // Only an event which can be cancelled can be prevented, and a passive listener cannot prevent the default
207
- if (this.cancelable && !this.properties.inPassiveListener) {
208
- this.setReadOnlyProperties({
209
- defaultPrevented: true
210
- })
211
- }
212
- return null
213
- }
214
-
215
- /**
216
- * For this particular event, no other listener will be called.
217
- * Neither those attached on the same element, nor those attached on elements which will be traversed later (in
218
- * capture phase, for instance)
219
- * @method
220
- * @returns {null}
221
- */
222
- stopImmediatePropagation () {
223
- this.setReadOnlyProperties({
224
- immediatePropagationStopped: true
225
- })
226
- return null
227
- }
228
-
229
- /**
230
- * Stops the propagation of events further along in the Dom.
231
- * @method
232
- * @returns {null}
233
- */
234
- stopPropagation () {
235
- this.setReadOnlyProperties({
236
- propagationStopped: true
237
- })
238
- return null
239
- }
240
-
241
- setReadOnlyProperties (updateProps = {}) {
242
- this.properties = Object.assign({}, this.properties, updateProps)
243
- return this
244
- }
245
- }
246
- exports.EventService = EventService
247
- EventService.NONE = 0
248
- EventService.CAPTURING_PHASE = 1
249
- EventService.AT_TARGET = 2
250
- EventService.BUBBLING_PHASE = 3
1
+ 'use strict'
2
+
3
+ /**
4
+ * @file Substitute for the DOM Event Class.
5
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
6
+ * @version 1.0.0
7
+ */
8
+ Object.defineProperty(exports, '__esModule', {
9
+ value: true
10
+ })
11
+ exports.EventService = void 0
12
+ /**
13
+ * Simulate the behaviour of the Event Class when there is no DOM available.
14
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
15
+ * @class
16
+ * @property {number} NONE
17
+ * @property {number} CAPTURING_PHASE
18
+ * @property {number} AT_TARGET
19
+ * @property {number} BUBBLING_PHASE
20
+ * @property {boolean} bubbles - A Boolean indicating whether the event bubbles up through the Dom or not.
21
+ * @property {boolean} cancelable - A Boolean indicating whether the event is cancelable.
22
+ * @property {boolean} composed - A Boolean value indicating whether the event can bubble across the boundary
23
+ * between the shadow Dom and the regular Dom.
24
+ * @property {function|PseudoEventTarget} currentTarget - A reference to the currently registered target for the event. This
25
+ * is the object to which the event is currently slated to be sent; it's possible this has been changed along the way
26
+ * through re-targeting.
27
+ * @property {boolean} defaultPrevented - Indicates whether event.preventDefault() has been called on the event.
28
+ * @property {boolean} immediatePropagationStopped - Flag that no further propagation should occur, including on current
29
+ * target.
30
+ * @property {boolean} propagationStopped - Flag that no further propagation should occur.
31
+ * @property {int} eventPhase - Indicates which phase of the event flow is being processed. Uses EventService constants.
32
+ * @property {EventTarget|PseudoEventTarget} target - A reference to the target to which the event was originally
33
+ * dispatched.
34
+ * @property {int} timeStamp - The time at which the event was created (in milliseconds). By specification, this
35
+ * value is time since epoch, but in reality browsers' definitions vary; in addition, work is underway to change this
36
+ * to be a DomHighResTimeStamp instead.
37
+ * @property {string} type - The name of the event (case-insensitive).
38
+ * @property {boolean} isTrusted - Indicates whether the event was initiated by the browser (after a user
39
+ * click for instance) or by a script (using an event creation method, like event.initEvent)
40
+ */
41
+ class EventService {
42
+ /**
43
+ *
44
+ * @param {string} typeArg
45
+ * @param {Object} [eventOptions={}]
46
+ * @param {boolean} [eventOptions.bubbles=false]
47
+ * @param {boolean} [eventOptions.cancelable=false]
48
+ * @param {boolean} [eventOptions.composed=false]
49
+ * @constructor
50
+ */
51
+ constructor (typeArg = '', {
52
+ bubbles = false,
53
+ cancelable = false,
54
+ composed = false
55
+ } = {}) {
56
+ this.properties = {
57
+ bubbles: false,
58
+ cancelable: false,
59
+ composed: false,
60
+ currentTarget: null,
61
+ defaultPrevented: false,
62
+ immediatePropagationStopped: false,
63
+ propagationStopped: false,
64
+ eventPhase: 0,
65
+ target: null,
66
+ timeStamp: Math.floor(Date.now() / 1000),
67
+ type: '',
68
+ isTrusted: false,
69
+ dispatching: false,
70
+ inPassiveListener: false,
71
+ path: []
72
+ }
73
+ this.setReadOnlyProperties({
74
+ type: typeArg,
75
+ bubbles,
76
+ cancelable,
77
+ composed
78
+ })
79
+ }
80
+
81
+ get bubbles () {
82
+ return this.properties.bubbles
83
+ }
84
+
85
+ get cancelable () {
86
+ return this.properties.cancelable
87
+ }
88
+
89
+ get composed () {
90
+ return this.properties.composed
91
+ }
92
+
93
+ get currentTarget () {
94
+ return this.properties.currentTarget
95
+ }
96
+
97
+ get defaultPrevented () {
98
+ return this.properties.defaultPrevented
99
+ }
100
+
101
+ get eventPhase () {
102
+ return this.properties.eventPhase
103
+ }
104
+
105
+ get isTrusted () {
106
+ return this.properties.isTrusted
107
+ }
108
+
109
+ get target () {
110
+ return this.properties.target
111
+ }
112
+
113
+ get timeStamp () {
114
+ return this.properties.timeStamp
115
+ }
116
+
117
+ get type () {
118
+ return this.properties.type
119
+ }
120
+
121
+ /**
122
+ * Scope several accessors inside the inner object. These are only intended for usage by other DOM classes.
123
+ * @returns {EventInner}
124
+ */
125
+ get inner () {
126
+ const self = this
127
+ return {
128
+ get currentTarget () {
129
+ return self.properties.currentTarget
130
+ },
131
+ set currentTarget (target) {
132
+ self.properties.currentTarget = target
133
+ },
134
+ get eventPhase () {
135
+ return self.properties.eventPhase
136
+ },
137
+ set eventPhase (phase) {
138
+ self.properties.eventPhase = phase
139
+ },
140
+ get target () {
141
+ return self.properties.target
142
+ },
143
+ set target (target) {
144
+ self.properties.target = target
145
+ },
146
+ get immediatePropagationStopped () {
147
+ return self.properties.immediatePropagationStopped
148
+ },
149
+ get propagationStopped () {
150
+ return self.properties.propagationStopped
151
+ },
152
+ get trusted () {
153
+ return self.properties.isTrusted
154
+ },
155
+ set trusted (trusted) {
156
+ self.properties.isTrusted = trusted
157
+ },
158
+ get dispatching () {
159
+ return self.properties.dispatching
160
+ },
161
+ set dispatching (dispatching) {
162
+ self.properties.dispatching = dispatching
163
+ },
164
+ get inPassiveListener () {
165
+ return self.properties.inPassiveListener
166
+ },
167
+ set inPassiveListener (passive) {
168
+ self.properties.inPassiveListener = passive
169
+ },
170
+ get path () {
171
+ return self.properties.path
172
+ },
173
+ set path (path) {
174
+ self.properties.path = path
175
+ },
176
+ finishDispatch () {
177
+ self.setReadOnlyProperties({
178
+ currentTarget: null,
179
+ eventPhase: EventService.NONE,
180
+ path: [],
181
+ dispatching: false,
182
+ inPassiveListener: false,
183
+ propagationStopped: false,
184
+ immediatePropagationStopped: false
185
+ })
186
+ }
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Return an array of targets that will have the event executed open them. The order is based on the eventPhase
192
+ * @method
193
+ * @returns {Array.<PseudoEventTarget>}
194
+ */
195
+ composedPath () {
196
+ // While the event is being dispatched this is every target it travels through, the target first and the root last
197
+ return this.properties.dispatching ? this.properties.path.slice() : []
198
+ }
199
+
200
+ /**
201
+ * Cancels the event (if it is cancelable).
202
+ * @method
203
+ * @returns {null}
204
+ */
205
+ preventDefault () {
206
+ // Only an event which can be cancelled can be prevented, and a passive listener cannot prevent the default
207
+ if (this.cancelable && !this.properties.inPassiveListener) {
208
+ this.setReadOnlyProperties({
209
+ defaultPrevented: true
210
+ })
211
+ }
212
+ return null
213
+ }
214
+
215
+ /**
216
+ * For this particular event, no other listener will be called.
217
+ * Neither those attached on the same element, nor those attached on elements which will be traversed later (in
218
+ * capture phase, for instance)
219
+ * @method
220
+ * @returns {null}
221
+ */
222
+ stopImmediatePropagation () {
223
+ this.setReadOnlyProperties({
224
+ immediatePropagationStopped: true
225
+ })
226
+ return null
227
+ }
228
+
229
+ /**
230
+ * Stops the propagation of events further along in the Dom.
231
+ * @method
232
+ * @returns {null}
233
+ */
234
+ stopPropagation () {
235
+ this.setReadOnlyProperties({
236
+ propagationStopped: true
237
+ })
238
+ return null
239
+ }
240
+
241
+ setReadOnlyProperties (updateProps = {}) {
242
+ this.properties = Object.assign({}, this.properties, updateProps)
243
+ return this
244
+ }
245
+ }
246
+ exports.EventService = EventService
247
+ EventService.NONE = 0
248
+ EventService.CAPTURING_PHASE = 1
249
+ EventService.AT_TARGET = 2
250
+ EventService.BUBBLING_PHASE = 3
@@ -1,84 +1,84 @@
1
- /**
2
- * @file Substitute for the DOM EventTarget Class.
3
- * @author Joshua Heagle <joshuaheagle@gmail.com>
4
- * @version 1.0.0
5
- */
6
- import { EventService } from './EventService';
7
- import { listenerOptions, PseudoEventTarget } from '../interfaces/PseudoEventTarget';
8
- /**
9
- * Simulate the behaviour of the EventTarget Class when there is no DOM available.
10
- * Dispatching an event sends it through the tree the way the DOM does: down from the root to the target (capture
11
- * listeners), to the target itself, then back up to the root (the listeners which are not capture listeners, when the
12
- * event bubbles).
13
- * @author Joshua Heagle <joshuaheagle@gmail.com>
14
- * @class
15
- * @property {Object.<string, Array.<PseudoEventListener>>} listeners
16
- * @property {function} addEventListener
17
- * @property {function} removeEventListener
18
- * @property {function} dispatchEvent
19
- */
20
- declare class EventTargetService implements PseudoEventTarget {
21
- private readonly listeners;
22
- private readonly defaultEvent;
23
- /**
24
- * @constructor
25
- */
26
- constructor();
27
- /**
28
- * The listeners registered for a type of event, creating the (empty) list of them when there are none yet.
29
- * @param {string} type
30
- * @returns {LinkedList}
31
- */
32
- private listenersFor;
33
- /**
34
- * Run the listeners registered on this target for the type of the event which apply to the phase the event is in
35
- * (at the target, the capture listeners run before the others). Listeners which are added while this runs do not run
36
- * for this event, and listeners which are removed while it runs no longer do. Running stops as soon as immediate
37
- * propagation is stopped. A listener which throws does not stop the others.
38
- * @param {EventService} event The event, which is at a phase and has a current target
39
- * @returns {Array<*>} The errors which the listeners threw
40
- */
41
- private runEvents;
42
- /**
43
- * Take a listener out of the registered listeners, so that it does not run again.
44
- * @param {string} type
45
- * @param {PseudoEventListener} listener
46
- */
47
- private removeListener;
48
- /**
49
- * Register the function to run when nothing else has prevented the default for this type of event.
50
- * @param {string} type
51
- * @param {Function} callback
52
- */
53
- protected setDefaultEvent(type: string, callback: Function): void;
54
- /**
55
- * Registers an event handler of a specific event type. Adding the same handler again for the same type and phase does
56
- * nothing, like the DOM.
57
- * @param {string} type The type of event to listen for
58
- * @param {Function|Object} callback The function to call (or an object with a handleEvent function)
59
- * @param {Object|boolean} [useCapture=false] Listen while the event travels down to the target (true), or an object with capture, once and passive
60
- */
61
- addEventListener(type: string, callback: Function | {
62
- handleEvent: Function;
63
- } | any, useCapture?: listenerOptions | boolean): void;
64
- /**
65
- * Removes an event listener, the one which was added with the same type, handler and phase.
66
- * @param {string} type The type of event
67
- * @param {Function|Object} callback The handler which was added
68
- * @param {Object|boolean} [options=false] Whether the listener was a capture listener (true), or an object with capture
69
- */
70
- removeEventListener(type: string, callback: Function, options?: listenerOptions | boolean): void;
71
- /**
72
- * Dispatches an event to this target and through the tree: capture listeners of the ancestors from the root down,
73
- * then the listeners of this target, then (when the event bubbles) the other listeners of the ancestors from the
74
- * parent up to the root. stopPropagation() stops it reaching further targets, stopImmediatePropagation() also stops
75
- * the remaining listeners of the current target. Afterwards, unless the default was prevented, the default action
76
- * of this target (see setDefaultEvent) runs. The event can be dispatched again afterwards.
77
- * @param {EventService} event The event to dispatch
78
- * @returns {boolean} False when the event was cancelable and a listener prevented the default, otherwise true
79
- * @throws {Error} When the event is already being dispatched, or (after the whole dispatch has finished) the error
80
- * which a listener threw (an error with all of them in its errors property when several did)
81
- */
82
- dispatchEvent(event: EventService): boolean;
83
- }
84
- export default EventTargetService;
1
+ /**
2
+ * @file Substitute for the DOM EventTarget Class.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ */
6
+ import { EventService } from './EventService';
7
+ import { listenerOptions, PseudoEventTarget } from '../interfaces/PseudoEventTarget';
8
+ /**
9
+ * Simulate the behaviour of the EventTarget Class when there is no DOM available.
10
+ * Dispatching an event sends it through the tree the way the DOM does: down from the root to the target (capture
11
+ * listeners), to the target itself, then back up to the root (the listeners which are not capture listeners, when the
12
+ * event bubbles).
13
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
14
+ * @class
15
+ * @property {Object.<string, Array.<PseudoEventListener>>} listeners
16
+ * @property {function} addEventListener
17
+ * @property {function} removeEventListener
18
+ * @property {function} dispatchEvent
19
+ */
20
+ declare class EventTargetService implements PseudoEventTarget {
21
+ private readonly listeners;
22
+ private readonly defaultEvent;
23
+ /**
24
+ * @constructor
25
+ */
26
+ constructor();
27
+ /**
28
+ * The listeners registered for a type of event, creating the (empty) list of them when there are none yet.
29
+ * @param {string} type
30
+ * @returns {LinkedList}
31
+ */
32
+ private listenersFor;
33
+ /**
34
+ * Run the listeners registered on this target for the type of the event which apply to the phase the event is in
35
+ * (at the target, the capture listeners run before the others). Listeners which are added while this runs do not run
36
+ * for this event, and listeners which are removed while it runs no longer do. Running stops as soon as immediate
37
+ * propagation is stopped. A listener which throws does not stop the others.
38
+ * @param {EventService} event The event, which is at a phase and has a current target
39
+ * @returns {Array<*>} The errors which the listeners threw
40
+ */
41
+ private runEvents;
42
+ /**
43
+ * Take a listener out of the registered listeners, so that it does not run again.
44
+ * @param {string} type
45
+ * @param {PseudoEventListener} listener
46
+ */
47
+ private removeListener;
48
+ /**
49
+ * Register the function to run when nothing else has prevented the default for this type of event.
50
+ * @param {string} type
51
+ * @param {Function} callback
52
+ */
53
+ protected setDefaultEvent(type: string, callback: Function): void;
54
+ /**
55
+ * Registers an event handler of a specific event type. Adding the same handler again for the same type and phase does
56
+ * nothing, like the DOM.
57
+ * @param {string} type The type of event to listen for
58
+ * @param {Function|Object} callback The function to call (or an object with a handleEvent function)
59
+ * @param {Object|boolean} [useCapture=false] Listen while the event travels down to the target (true), or an object with capture, once and passive
60
+ */
61
+ addEventListener(type: string, callback: Function | {
62
+ handleEvent: Function;
63
+ } | any, useCapture?: listenerOptions | boolean): void;
64
+ /**
65
+ * Removes an event listener, the one which was added with the same type, handler and phase.
66
+ * @param {string} type The type of event
67
+ * @param {Function|Object} callback The handler which was added
68
+ * @param {Object|boolean} [options=false] Whether the listener was a capture listener (true), or an object with capture
69
+ */
70
+ removeEventListener(type: string, callback: Function, options?: listenerOptions | boolean): void;
71
+ /**
72
+ * Dispatches an event to this target and through the tree: capture listeners of the ancestors from the root down,
73
+ * then the listeners of this target, then (when the event bubbles) the other listeners of the ancestors from the
74
+ * parent up to the root. stopPropagation() stops it reaching further targets, stopImmediatePropagation() also stops
75
+ * the remaining listeners of the current target. Afterwards, unless the default was prevented, the default action
76
+ * of this target (see setDefaultEvent) runs. The event can be dispatched again afterwards.
77
+ * @param {EventService} event The event to dispatch
78
+ * @returns {boolean} False when the event was cancelable and a listener prevented the default, otherwise true
79
+ * @throws {Error} When the event is already being dispatched, or (after the whole dispatch has finished) the error
80
+ * which a listener threw (an error with all of them in its errors property when several did)
81
+ */
82
+ dispatchEvent(event: EventService): boolean;
83
+ }
84
+ export default EventTargetService;