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.
- package/README.md +432 -13
- package/browser/pseudo-dom.js +3364 -603
- 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 +20 -7
- 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 -23
- 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 +13 -0
- package/dist/services/ElementService.js +20 -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 +11 -6
- package/dist/services/HTMLCollectionService.js +25 -8
- 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 +26 -0
- package/dist/services/NodeService.js +42 -0
- 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,96 +1,96 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Substitute for the DOM EventEventListener Class.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.0.0
|
|
5
|
-
*/
|
|
6
|
-
import { EventService } from '../services/EventService';
|
|
7
|
-
/**
|
|
8
|
-
* Handle events as they are stored and implemented.
|
|
9
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
10
|
-
* @class
|
|
11
|
-
* @property {string} eventType
|
|
12
|
-
* @property {Object} eventOptions
|
|
13
|
-
* @property {boolean} isDefault
|
|
14
|
-
*/
|
|
15
|
-
declare class PseudoEventListener {
|
|
16
|
-
private eventOptions;
|
|
17
|
-
private eventType;
|
|
18
|
-
private handler;
|
|
19
|
-
private readonly originalCallback;
|
|
20
|
-
private readonly defaultListener;
|
|
21
|
-
private isRemoved;
|
|
22
|
-
/**
|
|
23
|
-
* @param {string} eventType The type of event this listens for
|
|
24
|
-
* @param {Object} [options] The capture, once and passive options
|
|
25
|
-
* @param {Function} handleEvent The function which is called with the event, already bound to what it should run as
|
|
26
|
-
* @param {Function} [originalCallback=handleEvent] The function (or object) which was given when registering, used to find this listener again
|
|
27
|
-
* @constructor
|
|
28
|
-
*/
|
|
29
|
-
constructor(eventType: string, { capture, once, passive }: {
|
|
30
|
-
capture?: boolean;
|
|
31
|
-
once?: boolean;
|
|
32
|
-
passive?: boolean;
|
|
33
|
-
}, handleEvent: Function, originalCallback?: Function);
|
|
34
|
-
/**
|
|
35
|
-
* The function (or object with handleEvent) which was originally given when registering, used to find this listener again for removal.
|
|
36
|
-
*/
|
|
37
|
-
get callback(): Function;
|
|
38
|
-
/** Whether this listener listens in the capture phase (and at the target) rather than in the bubble phase. */
|
|
39
|
-
get capture(): boolean;
|
|
40
|
-
get isDefault(): boolean;
|
|
41
|
-
get once(): boolean;
|
|
42
|
-
/** Whether the listener promises not to prevent the default (preventDefault does nothing while it runs). */
|
|
43
|
-
get passive(): boolean;
|
|
44
|
-
/** Whether this listener has been removed, a removed listener does not run even if the event already started. */
|
|
45
|
-
get removed(): boolean;
|
|
46
|
-
set removed(removed: boolean);
|
|
47
|
-
/**
|
|
48
|
-
* @method
|
|
49
|
-
* @name PseudoEventListener#handleEvent
|
|
50
|
-
* @param {PseudoEvent} event
|
|
51
|
-
* @returns {*}
|
|
52
|
-
*/
|
|
53
|
-
handleEvent(event: EventService): any;
|
|
54
|
-
/**
|
|
55
|
-
* A capture listener runs while the event travels down to the target.
|
|
56
|
-
* @method
|
|
57
|
-
* @name PseudoEventListener#doCapturePhase
|
|
58
|
-
* @param {PseudoEvent} event
|
|
59
|
-
* @returns {boolean}
|
|
60
|
-
*/
|
|
61
|
-
doCapturePhase(event: EventService): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Every listener of the target itself runs, capture listeners first.
|
|
64
|
-
* @method
|
|
65
|
-
* @name PseudoEventListener#doTargetPhase
|
|
66
|
-
* @param {PseudoEvent} event
|
|
67
|
-
* @returns {boolean}
|
|
68
|
-
*/
|
|
69
|
-
doTargetPhase(event: EventService): boolean;
|
|
70
|
-
/**
|
|
71
|
-
* A listener which is not a capture listener runs while the event travels back up (when it bubbles).
|
|
72
|
-
* @method
|
|
73
|
-
* @name PseudoEventListener#doBubblePhase
|
|
74
|
-
* @param {PseudoEvent} event
|
|
75
|
-
* @returns {boolean}
|
|
76
|
-
*/
|
|
77
|
-
doBubblePhase(event: EventService): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* @method
|
|
80
|
-
* @name PseudoEventListener#skipPhase
|
|
81
|
-
* @param {PseudoEvent} event
|
|
82
|
-
* @returns {boolean}
|
|
83
|
-
*/
|
|
84
|
-
skipPhase(event: EventService): boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Whether this listener should not run for the event as it is now (it was removed, or it is for another phase).
|
|
87
|
-
* Stopping propagation is handled by the dispatching, since it stops other targets and not the listeners of the
|
|
88
|
-
* current one.
|
|
89
|
-
* @method
|
|
90
|
-
* @name PseudoEventListener#rejectEvent
|
|
91
|
-
* @param {PseudoEvent} event
|
|
92
|
-
* @returns {boolean}
|
|
93
|
-
*/
|
|
94
|
-
rejectEvent(event: EventService): boolean;
|
|
95
|
-
}
|
|
96
|
-
export default PseudoEventListener;
|
|
1
|
+
/**
|
|
2
|
+
* @file Substitute for the DOM EventEventListener Class.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { EventService } from '../services/EventService';
|
|
7
|
+
/**
|
|
8
|
+
* Handle events as they are stored and implemented.
|
|
9
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
10
|
+
* @class
|
|
11
|
+
* @property {string} eventType
|
|
12
|
+
* @property {Object} eventOptions
|
|
13
|
+
* @property {boolean} isDefault
|
|
14
|
+
*/
|
|
15
|
+
declare class PseudoEventListener {
|
|
16
|
+
private eventOptions;
|
|
17
|
+
private eventType;
|
|
18
|
+
private handler;
|
|
19
|
+
private readonly originalCallback;
|
|
20
|
+
private readonly defaultListener;
|
|
21
|
+
private isRemoved;
|
|
22
|
+
/**
|
|
23
|
+
* @param {string} eventType The type of event this listens for
|
|
24
|
+
* @param {Object} [options] The capture, once and passive options
|
|
25
|
+
* @param {Function} handleEvent The function which is called with the event, already bound to what it should run as
|
|
26
|
+
* @param {Function} [originalCallback=handleEvent] The function (or object) which was given when registering, used to find this listener again
|
|
27
|
+
* @constructor
|
|
28
|
+
*/
|
|
29
|
+
constructor(eventType: string, { capture, once, passive }: {
|
|
30
|
+
capture?: boolean;
|
|
31
|
+
once?: boolean;
|
|
32
|
+
passive?: boolean;
|
|
33
|
+
}, handleEvent: Function, originalCallback?: Function);
|
|
34
|
+
/**
|
|
35
|
+
* The function (or object with handleEvent) which was originally given when registering, used to find this listener again for removal.
|
|
36
|
+
*/
|
|
37
|
+
get callback(): Function;
|
|
38
|
+
/** Whether this listener listens in the capture phase (and at the target) rather than in the bubble phase. */
|
|
39
|
+
get capture(): boolean;
|
|
40
|
+
get isDefault(): boolean;
|
|
41
|
+
get once(): boolean;
|
|
42
|
+
/** Whether the listener promises not to prevent the default (preventDefault does nothing while it runs). */
|
|
43
|
+
get passive(): boolean;
|
|
44
|
+
/** Whether this listener has been removed, a removed listener does not run even if the event already started. */
|
|
45
|
+
get removed(): boolean;
|
|
46
|
+
set removed(removed: boolean);
|
|
47
|
+
/**
|
|
48
|
+
* @method
|
|
49
|
+
* @name PseudoEventListener#handleEvent
|
|
50
|
+
* @param {PseudoEvent} event
|
|
51
|
+
* @returns {*}
|
|
52
|
+
*/
|
|
53
|
+
handleEvent(event: EventService): any;
|
|
54
|
+
/**
|
|
55
|
+
* A capture listener runs while the event travels down to the target.
|
|
56
|
+
* @method
|
|
57
|
+
* @name PseudoEventListener#doCapturePhase
|
|
58
|
+
* @param {PseudoEvent} event
|
|
59
|
+
* @returns {boolean}
|
|
60
|
+
*/
|
|
61
|
+
doCapturePhase(event: EventService): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Every listener of the target itself runs, capture listeners first.
|
|
64
|
+
* @method
|
|
65
|
+
* @name PseudoEventListener#doTargetPhase
|
|
66
|
+
* @param {PseudoEvent} event
|
|
67
|
+
* @returns {boolean}
|
|
68
|
+
*/
|
|
69
|
+
doTargetPhase(event: EventService): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* A listener which is not a capture listener runs while the event travels back up (when it bubbles).
|
|
72
|
+
* @method
|
|
73
|
+
* @name PseudoEventListener#doBubblePhase
|
|
74
|
+
* @param {PseudoEvent} event
|
|
75
|
+
* @returns {boolean}
|
|
76
|
+
*/
|
|
77
|
+
doBubblePhase(event: EventService): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* @method
|
|
80
|
+
* @name PseudoEventListener#skipPhase
|
|
81
|
+
* @param {PseudoEvent} event
|
|
82
|
+
* @returns {boolean}
|
|
83
|
+
*/
|
|
84
|
+
skipPhase(event: EventService): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Whether this listener should not run for the event as it is now (it was removed, or it is for another phase).
|
|
87
|
+
* Stopping propagation is handled by the dispatching, since it stops other targets and not the listeners of the
|
|
88
|
+
* current one.
|
|
89
|
+
* @method
|
|
90
|
+
* @name PseudoEventListener#rejectEvent
|
|
91
|
+
* @param {PseudoEvent} event
|
|
92
|
+
* @returns {boolean}
|
|
93
|
+
*/
|
|
94
|
+
rejectEvent(event: EventService): boolean;
|
|
95
|
+
}
|
|
96
|
+
export default PseudoEventListener;
|
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
/**
|
|
7
|
-
* @file Substitute for the DOM EventEventListener Class.
|
|
8
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
9
|
-
* @version 1.0.0
|
|
10
|
-
*/
|
|
11
|
-
const EventService_1 = require('../services/EventService')
|
|
12
|
-
/**
|
|
13
|
-
* Handle events as they are stored and implemented.
|
|
14
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
15
|
-
* @class
|
|
16
|
-
* @property {string} eventType
|
|
17
|
-
* @property {Object} eventOptions
|
|
18
|
-
* @property {boolean} isDefault
|
|
19
|
-
*/
|
|
20
|
-
class PseudoEventListener {
|
|
21
|
-
/**
|
|
22
|
-
* @param {string} eventType The type of event this listens for
|
|
23
|
-
* @param {Object} [options] The capture, once and passive options
|
|
24
|
-
* @param {Function} handleEvent The function which is called with the event, already bound to what it should run as
|
|
25
|
-
* @param {Function} [originalCallback=handleEvent] The function (or object) which was given when registering, used to find this listener again
|
|
26
|
-
* @constructor
|
|
27
|
-
*/
|
|
28
|
-
constructor (eventType, {
|
|
29
|
-
capture = false,
|
|
30
|
-
once = false,
|
|
31
|
-
passive = false
|
|
32
|
-
} = {}, handleEvent, originalCallback = handleEvent) {
|
|
33
|
-
this.eventOptions = {
|
|
34
|
-
capture: false,
|
|
35
|
-
once: false,
|
|
36
|
-
passive: false
|
|
37
|
-
}
|
|
38
|
-
this.eventType = ''
|
|
39
|
-
this.defaultListener = false
|
|
40
|
-
this.isRemoved = false
|
|
41
|
-
this.eventOptions = {
|
|
42
|
-
capture,
|
|
43
|
-
once,
|
|
44
|
-
passive
|
|
45
|
-
}
|
|
46
|
-
this.eventType = eventType
|
|
47
|
-
this.handler = handleEvent
|
|
48
|
-
this.originalCallback = originalCallback
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* The function (or object with handleEvent) which was originally given when registering, used to find this listener again for removal.
|
|
53
|
-
*/
|
|
54
|
-
get callback () {
|
|
55
|
-
return this.originalCallback
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Whether this listener listens in the capture phase (and at the target) rather than in the bubble phase. */
|
|
59
|
-
get capture () {
|
|
60
|
-
return this.eventOptions.capture
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get isDefault () {
|
|
64
|
-
return this.defaultListener
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get once () {
|
|
68
|
-
return this.eventOptions.once
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Whether the listener promises not to prevent the default (preventDefault does nothing while it runs). */
|
|
72
|
-
get passive () {
|
|
73
|
-
return this.eventOptions.passive
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Whether this listener has been removed, a removed listener does not run even if the event already started. */
|
|
77
|
-
get removed () {
|
|
78
|
-
return this.isRemoved
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
set removed (removed) {
|
|
82
|
-
this.isRemoved = removed
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @method
|
|
87
|
-
* @name PseudoEventListener#handleEvent
|
|
88
|
-
* @param {PseudoEvent} event
|
|
89
|
-
* @returns {*}
|
|
90
|
-
*/
|
|
91
|
-
handleEvent (event) {
|
|
92
|
-
return this.handler(event)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* A capture listener runs while the event travels down to the target.
|
|
97
|
-
* @method
|
|
98
|
-
* @name PseudoEventListener#doCapturePhase
|
|
99
|
-
* @param {PseudoEvent} event
|
|
100
|
-
* @returns {boolean}
|
|
101
|
-
*/
|
|
102
|
-
doCapturePhase (event) {
|
|
103
|
-
return event.eventPhase === EventService_1.EventService.CAPTURING_PHASE && this.eventOptions.capture
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Every listener of the target itself runs, capture listeners first.
|
|
108
|
-
* @method
|
|
109
|
-
* @name PseudoEventListener#doTargetPhase
|
|
110
|
-
* @param {PseudoEvent} event
|
|
111
|
-
* @returns {boolean}
|
|
112
|
-
*/
|
|
113
|
-
doTargetPhase (event) {
|
|
114
|
-
return event.eventPhase === EventService_1.EventService.AT_TARGET
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* A listener which is not a capture listener runs while the event travels back up (when it bubbles).
|
|
119
|
-
* @method
|
|
120
|
-
* @name PseudoEventListener#doBubblePhase
|
|
121
|
-
* @param {PseudoEvent} event
|
|
122
|
-
* @returns {boolean}
|
|
123
|
-
*/
|
|
124
|
-
doBubblePhase (event) {
|
|
125
|
-
return event.eventPhase === EventService_1.EventService.BUBBLING_PHASE && !this.eventOptions.capture
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @method
|
|
130
|
-
* @name PseudoEventListener#skipPhase
|
|
131
|
-
* @param {PseudoEvent} event
|
|
132
|
-
* @returns {boolean}
|
|
133
|
-
*/
|
|
134
|
-
skipPhase (event) {
|
|
135
|
-
return !this.doCapturePhase(event) && !this.doTargetPhase(event) && !this.doBubblePhase(event)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Whether this listener should not run for the event as it is now (it was removed, or it is for another phase).
|
|
140
|
-
* Stopping propagation is handled by the dispatching, since it stops other targets and not the listeners of the
|
|
141
|
-
* current one.
|
|
142
|
-
* @method
|
|
143
|
-
* @name PseudoEventListener#rejectEvent
|
|
144
|
-
* @param {PseudoEvent} event
|
|
145
|
-
* @returns {boolean}
|
|
146
|
-
*/
|
|
147
|
-
rejectEvent (event) {
|
|
148
|
-
return this.isRemoved || this.skipPhase(event)
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
exports.default = PseudoEventListener
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
/**
|
|
7
|
+
* @file Substitute for the DOM EventEventListener Class.
|
|
8
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
const EventService_1 = require('../services/EventService')
|
|
12
|
+
/**
|
|
13
|
+
* Handle events as they are stored and implemented.
|
|
14
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
15
|
+
* @class
|
|
16
|
+
* @property {string} eventType
|
|
17
|
+
* @property {Object} eventOptions
|
|
18
|
+
* @property {boolean} isDefault
|
|
19
|
+
*/
|
|
20
|
+
class PseudoEventListener {
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} eventType The type of event this listens for
|
|
23
|
+
* @param {Object} [options] The capture, once and passive options
|
|
24
|
+
* @param {Function} handleEvent The function which is called with the event, already bound to what it should run as
|
|
25
|
+
* @param {Function} [originalCallback=handleEvent] The function (or object) which was given when registering, used to find this listener again
|
|
26
|
+
* @constructor
|
|
27
|
+
*/
|
|
28
|
+
constructor (eventType, {
|
|
29
|
+
capture = false,
|
|
30
|
+
once = false,
|
|
31
|
+
passive = false
|
|
32
|
+
} = {}, handleEvent, originalCallback = handleEvent) {
|
|
33
|
+
this.eventOptions = {
|
|
34
|
+
capture: false,
|
|
35
|
+
once: false,
|
|
36
|
+
passive: false
|
|
37
|
+
}
|
|
38
|
+
this.eventType = ''
|
|
39
|
+
this.defaultListener = false
|
|
40
|
+
this.isRemoved = false
|
|
41
|
+
this.eventOptions = {
|
|
42
|
+
capture,
|
|
43
|
+
once,
|
|
44
|
+
passive
|
|
45
|
+
}
|
|
46
|
+
this.eventType = eventType
|
|
47
|
+
this.handler = handleEvent
|
|
48
|
+
this.originalCallback = originalCallback
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The function (or object with handleEvent) which was originally given when registering, used to find this listener again for removal.
|
|
53
|
+
*/
|
|
54
|
+
get callback () {
|
|
55
|
+
return this.originalCallback
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Whether this listener listens in the capture phase (and at the target) rather than in the bubble phase. */
|
|
59
|
+
get capture () {
|
|
60
|
+
return this.eventOptions.capture
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get isDefault () {
|
|
64
|
+
return this.defaultListener
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get once () {
|
|
68
|
+
return this.eventOptions.once
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Whether the listener promises not to prevent the default (preventDefault does nothing while it runs). */
|
|
72
|
+
get passive () {
|
|
73
|
+
return this.eventOptions.passive
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Whether this listener has been removed, a removed listener does not run even if the event already started. */
|
|
77
|
+
get removed () {
|
|
78
|
+
return this.isRemoved
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
set removed (removed) {
|
|
82
|
+
this.isRemoved = removed
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @method
|
|
87
|
+
* @name PseudoEventListener#handleEvent
|
|
88
|
+
* @param {PseudoEvent} event
|
|
89
|
+
* @returns {*}
|
|
90
|
+
*/
|
|
91
|
+
handleEvent (event) {
|
|
92
|
+
return this.handler(event)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A capture listener runs while the event travels down to the target.
|
|
97
|
+
* @method
|
|
98
|
+
* @name PseudoEventListener#doCapturePhase
|
|
99
|
+
* @param {PseudoEvent} event
|
|
100
|
+
* @returns {boolean}
|
|
101
|
+
*/
|
|
102
|
+
doCapturePhase (event) {
|
|
103
|
+
return event.eventPhase === EventService_1.EventService.CAPTURING_PHASE && this.eventOptions.capture
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Every listener of the target itself runs, capture listeners first.
|
|
108
|
+
* @method
|
|
109
|
+
* @name PseudoEventListener#doTargetPhase
|
|
110
|
+
* @param {PseudoEvent} event
|
|
111
|
+
* @returns {boolean}
|
|
112
|
+
*/
|
|
113
|
+
doTargetPhase (event) {
|
|
114
|
+
return event.eventPhase === EventService_1.EventService.AT_TARGET
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A listener which is not a capture listener runs while the event travels back up (when it bubbles).
|
|
119
|
+
* @method
|
|
120
|
+
* @name PseudoEventListener#doBubblePhase
|
|
121
|
+
* @param {PseudoEvent} event
|
|
122
|
+
* @returns {boolean}
|
|
123
|
+
*/
|
|
124
|
+
doBubblePhase (event) {
|
|
125
|
+
return event.eventPhase === EventService_1.EventService.BUBBLING_PHASE && !this.eventOptions.capture
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @method
|
|
130
|
+
* @name PseudoEventListener#skipPhase
|
|
131
|
+
* @param {PseudoEvent} event
|
|
132
|
+
* @returns {boolean}
|
|
133
|
+
*/
|
|
134
|
+
skipPhase (event) {
|
|
135
|
+
return !this.doCapturePhase(event) && !this.doTargetPhase(event) && !this.doBubblePhase(event)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Whether this listener should not run for the event as it is now (it was removed, or it is for another phase).
|
|
140
|
+
* Stopping propagation is handled by the dispatching, since it stops other targets and not the listeners of the
|
|
141
|
+
* current one.
|
|
142
|
+
* @method
|
|
143
|
+
* @name PseudoEventListener#rejectEvent
|
|
144
|
+
* @param {PseudoEvent} event
|
|
145
|
+
* @returns {boolean}
|
|
146
|
+
*/
|
|
147
|
+
rejectEvent (event) {
|
|
148
|
+
return this.isRemoved || this.skipPhase(event)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.default = PseudoEventListener
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Substitute for the DOM HTMLDocument Class.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.0.0
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @type {PseudoHTMLElement}
|
|
9
|
-
*/
|
|
10
|
-
import { HTMLElementService as PseudoHTMLElement } from '../services/HTMLElementService';
|
|
11
|
-
import { TextService, CommentService } from '../services/NodeService';
|
|
12
|
-
import { DocumentFragmentService } from '../services/DocumentFragmentService';
|
|
13
|
-
import { PseudoNode } from '../interfaces/PseudoNode';
|
|
14
|
-
/**
|
|
15
|
-
* Simulate the behaviour of the HTMLDocument Class when there is no DOM available.
|
|
16
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
17
|
-
* @class
|
|
18
|
-
* @augments PseudoHTMLElement
|
|
19
|
-
* @property {PseudoHTMLElement} head - A reference to the Head child element
|
|
20
|
-
* @property {PseudoHTMLElement} body - A reference to the Body child element
|
|
21
|
-
* @property {function} createElement - Generate a new PseudoHTMLElement (which is not in the document until it is appended)
|
|
22
|
-
*/
|
|
23
|
-
declare class PseudoHTMLDocument extends PseudoHTMLElement {
|
|
24
|
-
private head;
|
|
25
|
-
private body;
|
|
26
|
-
/**
|
|
27
|
-
* The root HTML element is acts as the parent to all HTML elements in the document.
|
|
28
|
-
* @constructor
|
|
29
|
-
*/
|
|
30
|
-
constructor();
|
|
31
|
-
get nodeName(): string;
|
|
32
|
-
get nodeType(): number;
|
|
33
|
-
get textContent(): string | null;
|
|
34
|
-
set textContent(text: string | null);
|
|
35
|
-
/**
|
|
36
|
-
* Make an element of the given type which belongs to this document but is not added anywhere until it is appended.
|
|
37
|
-
* @param {string} tagName - Tag Name is a string representing the type of Dom element this represents
|
|
38
|
-
* @returns {PseudoHTMLElement}
|
|
39
|
-
*/
|
|
40
|
-
createElement(tagName?: string): PseudoHTMLElement;
|
|
41
|
-
/**
|
|
42
|
-
* Make a text node which belongs to this document.
|
|
43
|
-
* @param {string} [data=''] The text
|
|
44
|
-
* @returns {TextService}
|
|
45
|
-
*/
|
|
46
|
-
createTextNode(data?: string): TextService;
|
|
47
|
-
/**
|
|
48
|
-
* Make a comment which belongs to this document.
|
|
49
|
-
* @param {string} [data=''] The comment
|
|
50
|
-
* @returns {CommentService}
|
|
51
|
-
*/
|
|
52
|
-
createComment(data?: string): CommentService;
|
|
53
|
-
/**
|
|
54
|
-
* Make an empty document fragment which belongs to this document, a container for nodes which can be built up and
|
|
55
|
-
* then inserted in one go.
|
|
56
|
-
* @returns {DocumentFragmentService}
|
|
57
|
-
*/
|
|
58
|
-
createDocumentFragment(): DocumentFragmentService;
|
|
59
|
-
/**
|
|
60
|
-
* Make a copy of this document. The copy has no parent or listeners, and a deep copy has copies of everything in the
|
|
61
|
-
* document (a shallow one is an empty document).
|
|
62
|
-
* @param {boolean} [deep=false] Copy everything in the document as well
|
|
63
|
-
* @returns {PseudoNode}
|
|
64
|
-
*/
|
|
65
|
-
cloneNode(deep?: boolean): PseudoNode;
|
|
66
|
-
}
|
|
67
|
-
export default PseudoHTMLDocument;
|
|
1
|
+
/**
|
|
2
|
+
* @file Substitute for the DOM HTMLDocument Class.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @type {PseudoHTMLElement}
|
|
9
|
+
*/
|
|
10
|
+
import { HTMLElementService as PseudoHTMLElement } from '../services/HTMLElementService';
|
|
11
|
+
import { TextService, CommentService } from '../services/NodeService';
|
|
12
|
+
import { DocumentFragmentService } from '../services/DocumentFragmentService';
|
|
13
|
+
import { PseudoNode } from '../interfaces/PseudoNode';
|
|
14
|
+
/**
|
|
15
|
+
* Simulate the behaviour of the HTMLDocument Class when there is no DOM available.
|
|
16
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
17
|
+
* @class
|
|
18
|
+
* @augments PseudoHTMLElement
|
|
19
|
+
* @property {PseudoHTMLElement} head - A reference to the Head child element
|
|
20
|
+
* @property {PseudoHTMLElement} body - A reference to the Body child element
|
|
21
|
+
* @property {function} createElement - Generate a new PseudoHTMLElement (which is not in the document until it is appended)
|
|
22
|
+
*/
|
|
23
|
+
declare class PseudoHTMLDocument extends PseudoHTMLElement {
|
|
24
|
+
private head;
|
|
25
|
+
private body;
|
|
26
|
+
/**
|
|
27
|
+
* The root HTML element is acts as the parent to all HTML elements in the document.
|
|
28
|
+
* @constructor
|
|
29
|
+
*/
|
|
30
|
+
constructor();
|
|
31
|
+
get nodeName(): string;
|
|
32
|
+
get nodeType(): number;
|
|
33
|
+
get textContent(): string | null;
|
|
34
|
+
set textContent(text: string | null);
|
|
35
|
+
/**
|
|
36
|
+
* Make an element of the given type which belongs to this document but is not added anywhere until it is appended.
|
|
37
|
+
* @param {string} tagName - Tag Name is a string representing the type of Dom element this represents
|
|
38
|
+
* @returns {PseudoHTMLElement}
|
|
39
|
+
*/
|
|
40
|
+
createElement(tagName?: string): PseudoHTMLElement;
|
|
41
|
+
/**
|
|
42
|
+
* Make a text node which belongs to this document.
|
|
43
|
+
* @param {string} [data=''] The text
|
|
44
|
+
* @returns {TextService}
|
|
45
|
+
*/
|
|
46
|
+
createTextNode(data?: string): TextService;
|
|
47
|
+
/**
|
|
48
|
+
* Make a comment which belongs to this document.
|
|
49
|
+
* @param {string} [data=''] The comment
|
|
50
|
+
* @returns {CommentService}
|
|
51
|
+
*/
|
|
52
|
+
createComment(data?: string): CommentService;
|
|
53
|
+
/**
|
|
54
|
+
* Make an empty document fragment which belongs to this document, a container for nodes which can be built up and
|
|
55
|
+
* then inserted in one go.
|
|
56
|
+
* @returns {DocumentFragmentService}
|
|
57
|
+
*/
|
|
58
|
+
createDocumentFragment(): DocumentFragmentService;
|
|
59
|
+
/**
|
|
60
|
+
* Make a copy of this document. The copy has no parent or listeners, and a deep copy has copies of everything in the
|
|
61
|
+
* document (a shallow one is an empty document).
|
|
62
|
+
* @param {boolean} [deep=false] Copy everything in the document as well
|
|
63
|
+
* @returns {PseudoNode}
|
|
64
|
+
*/
|
|
65
|
+
cloneNode(deep?: boolean): PseudoNode;
|
|
66
|
+
}
|
|
67
|
+
export default PseudoHTMLDocument;
|