pseudo-dom 0.3.0 → 0.4.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 +774 -0
- package/browser/pseudo-dom.js +1266 -260
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/factories/createEvent.d.ts +28 -0
- package/dist/factories/createEvent.js +56 -0
- package/dist/factories/createEvent.min.js +1 -0
- package/dist/factories/eventDefaults.d.ts +31 -0
- package/dist/factories/eventDefaults.js +105 -0
- package/dist/factories/eventDefaults.min.js +1 -0
- package/dist/factories.d.ts +6 -0
- package/dist/factories.js +5 -1
- package/dist/factories.min.js +1 -1
- package/dist/functions/activeElement.d.ts +14 -0
- package/dist/functions/activeElement.js +33 -0
- package/dist/functions/activeElement.min.js +1 -0
- package/dist/functions/modifierState.d.ts +29 -0
- package/dist/functions/modifierState.js +41 -0
- package/dist/functions/modifierState.min.js +1 -0
- package/dist/main.d.ts +32 -1
- package/dist/main.js +66 -1
- package/dist/main.min.js +1 -1
- package/dist/services/CustomEventService.d.ts +37 -0
- package/dist/services/CustomEventService.js +35 -0
- package/dist/services/CustomEventService.min.js +1 -0
- package/dist/services/ElementService.js +13 -13
- package/dist/services/ElementService.min.js +1 -1
- package/dist/services/EventService.d.ts +2 -0
- package/dist/services/EventService.js +7 -1
- package/dist/services/EventService.min.js +1 -1
- package/dist/services/FocusEventService.d.ts +32 -0
- package/dist/services/FocusEventService.js +35 -0
- package/dist/services/FocusEventService.min.js +1 -0
- package/dist/services/HTMLElementService.d.ts +20 -0
- package/dist/services/HTMLElementService.js +95 -0
- package/dist/services/HTMLElementService.min.js +1 -1
- package/dist/services/InputEventService.d.ts +41 -0
- package/dist/services/InputEventService.js +47 -0
- package/dist/services/InputEventService.min.js +1 -0
- package/dist/services/KeyboardEventService.d.ts +70 -0
- package/dist/services/KeyboardEventService.js +86 -0
- package/dist/services/KeyboardEventService.min.js +1 -0
- package/dist/services/MouseEventService.d.ts +80 -0
- package/dist/services/MouseEventService.js +108 -0
- package/dist/services/MouseEventService.min.js +1 -0
- package/dist/services/PointerEventService.d.ts +51 -0
- package/dist/services/PointerEventService.js +67 -0
- package/dist/services/PointerEventService.min.js +1 -0
- package/dist/services/UIEventService.d.ts +43 -0
- package/dist/services/UIEventService.js +42 -0
- package/dist/services/UIEventService.min.js +1 -0
- package/dist/simulate.d.ts +32 -0
- package/dist/simulate.js +115 -0
- package/dist/simulate.min.js +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventService=void 0;class EventService{constructor(e="",{bubbles:t=!1,cancelable:r=!1,composed:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventService=void 0;class EventService{constructor(e="",{bubbles:t=!1,cancelable:r=!1,composed:s=!1}={}){this.properties={bubbles:!1,cancelable:!1,composed:!1,currentTarget:null,defaultPrevented:!1,immediatePropagationStopped:!1,propagationStopped:!1,eventPhase:0,target:null,timeStamp:Math.floor(Date.now()/1e3),type:"",isTrusted:!1,dispatching:!1,inPassiveListener:!1,path:[]},this.setReadOnlyProperties({type:e,bubbles:t,cancelable:r,composed:s})}get bubbles(){return this.properties.bubbles}get cancelable(){return this.properties.cancelable}get composed(){return this.properties.composed}get currentTarget(){return this.properties.currentTarget}get defaultPrevented(){return this.properties.defaultPrevented}get eventPhase(){return this.properties.eventPhase}get isTrusted(){return this.properties.isTrusted}get target(){return this.properties.target}get timeStamp(){return this.properties.timeStamp}get type(){return this.properties.type}get inner(){const e=this;return{get currentTarget(){return e.properties.currentTarget},set currentTarget(t){e.properties.currentTarget=t},get eventPhase(){return e.properties.eventPhase},set eventPhase(t){e.properties.eventPhase=t},get target(){return e.properties.target},set target(t){e.properties.target=t},get immediatePropagationStopped(){return e.properties.immediatePropagationStopped},get propagationStopped(){return e.properties.propagationStopped},get trusted(){return e.properties.isTrusted},set trusted(t){e.properties.isTrusted=t},get dispatching(){return e.properties.dispatching},set dispatching(t){e.properties.dispatching=t},get inPassiveListener(){return e.properties.inPassiveListener},set inPassiveListener(t){e.properties.inPassiveListener=t},get path(){return e.properties.path},set path(t){e.properties.path=t},finishDispatch(){e.setReadOnlyProperties({currentTarget:null,eventPhase:EventService.NONE,path:[],dispatching:!1,inPassiveListener:!1,propagationStopped:!1,immediatePropagationStopped:!1})}}}composedPath(){return this.properties.dispatching?this.properties.path.slice():[]}preventDefault(){return this.cancelable&&!this.properties.inPassiveListener&&this.setReadOnlyProperties({defaultPrevented:!0}),null}stopImmediatePropagation(){return this.setReadOnlyProperties({immediatePropagationStopped:!0}),null}stopPropagation(){return this.setReadOnlyProperties({propagationStopped:!0}),null}setReadOnlyProperties(e={}){return this.properties=Object.assign({},this.properties,e),this}}exports.EventService=EventService,EventService.NONE=0,EventService.CAPTURING_PHASE=1,EventService.AT_TARGET=2,EventService.BUBBLING_PHASE=3;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Substitute for the DOM FocusEvent Class.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { UIEventInit, UIEventService } from './UIEventService';
|
|
7
|
+
import { PseudoEventTarget } from '../interfaces/PseudoEventTarget';
|
|
8
|
+
/**
|
|
9
|
+
* The options for creating a focus event, on top of the ones every UI event has.
|
|
10
|
+
* @typedef {Object} FocusEventInit
|
|
11
|
+
* @property {PseudoEventTarget|null} [relatedTarget=null] The other target involved (the one losing or gaining the focus)
|
|
12
|
+
*/
|
|
13
|
+
export type FocusEventInit = UIEventInit & {
|
|
14
|
+
relatedTarget?: PseudoEventTarget | null;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Simulate the behaviour of the FocusEvent Class when there is no DOM available.
|
|
18
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
19
|
+
* @class
|
|
20
|
+
* @augments UIEventService
|
|
21
|
+
* @property {PseudoEventTarget|null} relatedTarget
|
|
22
|
+
*/
|
|
23
|
+
export declare class FocusEventService extends UIEventService {
|
|
24
|
+
private readonly related;
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} [typeArg=''] The type of the event
|
|
27
|
+
* @param {FocusEventInit} [init={}] The options for the event
|
|
28
|
+
* @constructor
|
|
29
|
+
*/
|
|
30
|
+
constructor(typeArg?: string, init?: FocusEventInit);
|
|
31
|
+
get relatedTarget(): PseudoEventTarget | null;
|
|
32
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.FocusEventService = void 0
|
|
7
|
+
/**
|
|
8
|
+
* @file Substitute for the DOM FocusEvent Class.
|
|
9
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
10
|
+
* @version 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
const UIEventService_1 = require('./UIEventService')
|
|
13
|
+
/**
|
|
14
|
+
* Simulate the behaviour of the FocusEvent Class when there is no DOM available.
|
|
15
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
16
|
+
* @class
|
|
17
|
+
* @augments UIEventService
|
|
18
|
+
* @property {PseudoEventTarget|null} relatedTarget
|
|
19
|
+
*/
|
|
20
|
+
class FocusEventService extends UIEventService_1.UIEventService {
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} [typeArg=''] The type of the event
|
|
23
|
+
* @param {FocusEventInit} [init={}] The options for the event
|
|
24
|
+
* @constructor
|
|
25
|
+
*/
|
|
26
|
+
constructor (typeArg = '', init = {}) {
|
|
27
|
+
super(typeArg, init)
|
|
28
|
+
this.related = init.relatedTarget || null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get relatedTarget () {
|
|
32
|
+
return this.related
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.FocusEventService = FocusEventService
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FocusEventService=void 0;const UIEventService_1=require("./UIEventService");class FocusEventService extends UIEventService_1.UIEventService{constructor(e="",t={}){super(e,t),this.related=t.relatedTarget||null}get relatedTarget(){return this.related}}exports.FocusEventService=FocusEventService;
|
|
@@ -34,4 +34,24 @@ export declare class HTMLElementService extends ElementService implements Partia
|
|
|
34
34
|
parent?: PseudoNode | null;
|
|
35
35
|
children?: Array<any>;
|
|
36
36
|
});
|
|
37
|
+
/**
|
|
38
|
+
* Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
|
|
39
|
+
* @returns {boolean}
|
|
40
|
+
*/
|
|
41
|
+
get canFocus(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
|
|
44
|
+
* script made it (so it is not trusted). A disabled element does nothing.
|
|
45
|
+
*/
|
|
46
|
+
click(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
|
|
49
|
+
* focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
|
|
50
|
+
* focus or already has it.
|
|
51
|
+
*/
|
|
52
|
+
focus(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Take the focus away from the element, when it has it: it gets blur then focusout.
|
|
55
|
+
*/
|
|
56
|
+
blur(): void;
|
|
37
57
|
}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule
|
|
5
|
+
? mod
|
|
6
|
+
: {
|
|
7
|
+
default: mod
|
|
8
|
+
}
|
|
9
|
+
}
|
|
3
10
|
Object.defineProperty(exports, '__esModule', {
|
|
4
11
|
value: true
|
|
5
12
|
})
|
|
6
13
|
exports.HTMLElementService = void 0
|
|
7
14
|
const ElementService_1 = require('./ElementService')
|
|
15
|
+
const createEvent_1 = __importDefault(require('../factories/createEvent'))
|
|
16
|
+
const activeElement_1 = require('../functions/activeElement')
|
|
8
17
|
/**
|
|
9
18
|
* Simulate the behaviour of the HTMLElement Class when there is no DOM available.
|
|
10
19
|
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
@@ -64,5 +73,91 @@ class HTMLElementService extends ElementService_1.ElementService {
|
|
|
64
73
|
children
|
|
65
74
|
})
|
|
66
75
|
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
|
|
79
|
+
* @returns {boolean}
|
|
80
|
+
*/
|
|
81
|
+
get canFocus () {
|
|
82
|
+
if (this.hasAttribute('disabled')) {
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
switch (this.tagName) {
|
|
86
|
+
case 'button':
|
|
87
|
+
case 'select':
|
|
88
|
+
case 'textarea':
|
|
89
|
+
return true
|
|
90
|
+
case 'input':
|
|
91
|
+
return String(this.getAttribute('type') || '').toLowerCase() !== 'hidden'
|
|
92
|
+
case 'a':
|
|
93
|
+
return this.hasAttribute('href') || this.hasAttribute('tabindex')
|
|
94
|
+
default:
|
|
95
|
+
return this.hasAttribute('tabindex')
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
|
|
101
|
+
* script made it (so it is not trusted). A disabled element does nothing.
|
|
102
|
+
*/
|
|
103
|
+
click () {
|
|
104
|
+
if (this.hasAttribute('disabled')) {
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
this.dispatchEvent((0, createEvent_1.default)('click', {}, {
|
|
108
|
+
browser: true
|
|
109
|
+
}))
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
|
|
114
|
+
* focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
|
|
115
|
+
* focus or already has it.
|
|
116
|
+
*/
|
|
117
|
+
focus () {
|
|
118
|
+
const root = this.getRootNode()
|
|
119
|
+
const previous = (0, activeElement_1.getActiveElement)(root)
|
|
120
|
+
if (!this.canFocus || previous === this) {
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
const send = (target, type, relatedTarget) => {
|
|
124
|
+
target.dispatchEvent((0, createEvent_1.default)(type, {
|
|
125
|
+
relatedTarget
|
|
126
|
+
}, {
|
|
127
|
+
browser: true,
|
|
128
|
+
trusted: true
|
|
129
|
+
}))
|
|
130
|
+
}
|
|
131
|
+
if (previous) {
|
|
132
|
+
send(previous, 'blur', this)
|
|
133
|
+
send(previous, 'focusout', this)
|
|
134
|
+
}
|
|
135
|
+
(0, activeElement_1.setActiveElement)(root, this)
|
|
136
|
+
send(this, 'focus', previous)
|
|
137
|
+
send(this, 'focusin', previous)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Take the focus away from the element, when it has it: it gets blur then focusout.
|
|
142
|
+
*/
|
|
143
|
+
blur () {
|
|
144
|
+
const root = this.getRootNode()
|
|
145
|
+
if ((0, activeElement_1.getActiveElement)(root) !== this) {
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
(0, activeElement_1.setActiveElement)(root, null)
|
|
149
|
+
this.dispatchEvent((0, createEvent_1.default)('blur', {
|
|
150
|
+
relatedTarget: null
|
|
151
|
+
}, {
|
|
152
|
+
browser: true,
|
|
153
|
+
trusted: true
|
|
154
|
+
}))
|
|
155
|
+
this.dispatchEvent((0, createEvent_1.default)('focusout', {
|
|
156
|
+
relatedTarget: null
|
|
157
|
+
}, {
|
|
158
|
+
browser: true,
|
|
159
|
+
trusted: true
|
|
160
|
+
}))
|
|
161
|
+
}
|
|
67
162
|
}
|
|
68
163
|
exports.HTMLElementService = HTMLElementService
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.HTMLElementService=void 0;const ElementService_1=require("./ElementService");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");class HTMLElementService extends ElementService_1.ElementService{constructor({tagName:e="",parent:t=null,children:r=[]}={}){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:"style",value:{}},{name:"title",value:""}],parent:t,children:r})}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 r=(e,t,r)=>{e.dispatchEvent((0,createEvent_1.default)(t,{relatedTarget:r},{browser:!0,trusted:!0}))};t&&(r(t,"blur",this),r(t,"focusout",this)),(0,activeElement_1.setActiveElement)(e,this),r(this,"focus",t),r(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;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Substitute for the DOM InputEvent Class.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { UIEventInit, UIEventService } from './UIEventService';
|
|
7
|
+
/**
|
|
8
|
+
* The options for creating an input event, on top of the ones every UI event has.
|
|
9
|
+
* @typedef {Object} InputEventInit
|
|
10
|
+
* @property {string|null} [data=null] The characters which were entered
|
|
11
|
+
* @property {string} [inputType=''] What kind of change it was, such as insertText
|
|
12
|
+
* @property {boolean} [isComposing=false]
|
|
13
|
+
*/
|
|
14
|
+
export type InputEventInit = UIEventInit & {
|
|
15
|
+
data?: string | null;
|
|
16
|
+
inputType?: string;
|
|
17
|
+
isComposing?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Simulate the behaviour of the InputEvent Class when there is no DOM available.
|
|
21
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
22
|
+
* @class
|
|
23
|
+
* @augments UIEventService
|
|
24
|
+
* @property {string|null} data
|
|
25
|
+
* @property {string} inputType
|
|
26
|
+
* @property {boolean} isComposing
|
|
27
|
+
*/
|
|
28
|
+
export declare class InputEventService extends UIEventService {
|
|
29
|
+
private readonly inputData;
|
|
30
|
+
private readonly kind;
|
|
31
|
+
private readonly composing;
|
|
32
|
+
/**
|
|
33
|
+
* @param {string} [typeArg=''] The type of the event
|
|
34
|
+
* @param {InputEventInit} [init={}] The options for the event
|
|
35
|
+
* @constructor
|
|
36
|
+
*/
|
|
37
|
+
constructor(typeArg?: string, init?: InputEventInit);
|
|
38
|
+
get data(): string | null;
|
|
39
|
+
get inputType(): string;
|
|
40
|
+
get isComposing(): boolean;
|
|
41
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.InputEventService = void 0
|
|
7
|
+
/**
|
|
8
|
+
* @file Substitute for the DOM InputEvent Class.
|
|
9
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
10
|
+
* @version 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
const UIEventService_1 = require('./UIEventService')
|
|
13
|
+
/**
|
|
14
|
+
* Simulate the behaviour of the InputEvent Class when there is no DOM available.
|
|
15
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
16
|
+
* @class
|
|
17
|
+
* @augments UIEventService
|
|
18
|
+
* @property {string|null} data
|
|
19
|
+
* @property {string} inputType
|
|
20
|
+
* @property {boolean} isComposing
|
|
21
|
+
*/
|
|
22
|
+
class InputEventService extends UIEventService_1.UIEventService {
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} [typeArg=''] The type of the event
|
|
25
|
+
* @param {InputEventInit} [init={}] The options for the event
|
|
26
|
+
* @constructor
|
|
27
|
+
*/
|
|
28
|
+
constructor (typeArg = '', init = {}) {
|
|
29
|
+
super(typeArg, init)
|
|
30
|
+
this.inputData = typeof init.data === 'string' ? init.data : null
|
|
31
|
+
this.kind = init.inputType || ''
|
|
32
|
+
this.composing = !!init.isComposing
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get data () {
|
|
36
|
+
return this.inputData
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get inputType () {
|
|
40
|
+
return this.kind
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get isComposing () {
|
|
44
|
+
return this.composing
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.InputEventService = InputEventService
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InputEventService=void 0;const UIEventService_1=require("./UIEventService");class InputEventService extends UIEventService_1.UIEventService{constructor(e="",t={}){super(e,t),this.inputData="string"==typeof t.data?t.data:null,this.kind=t.inputType||"",this.composing=!!t.isComposing}get data(){return this.inputData}get inputType(){return this.kind}get isComposing(){return this.composing}}exports.InputEventService=InputEventService;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Substitute for the DOM KeyboardEvent Class.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { UIEventInit, UIEventService } from './UIEventService';
|
|
7
|
+
/**
|
|
8
|
+
* The options for creating a keyboard event, on top of the ones every UI event has.
|
|
9
|
+
* @typedef {Object} KeyboardEventInit
|
|
10
|
+
* @property {string} [key=''] The value of the key, such as a or Enter
|
|
11
|
+
* @property {string} [code=''] The physical key, such as KeyA or Enter
|
|
12
|
+
* @property {number} [location=0] Where on the keyboard the key is (0 standard, 1 left, 2 right, 3 numeric pad)
|
|
13
|
+
* @property {boolean} [repeat=false] The key is being held down
|
|
14
|
+
* @property {boolean} [isComposing=false]
|
|
15
|
+
* @property {boolean} [ctrlKey=false]
|
|
16
|
+
* @property {boolean} [shiftKey=false]
|
|
17
|
+
* @property {boolean} [altKey=false]
|
|
18
|
+
* @property {boolean} [metaKey=false]
|
|
19
|
+
*/
|
|
20
|
+
export type KeyboardEventInit = UIEventInit & {
|
|
21
|
+
key?: string;
|
|
22
|
+
code?: string;
|
|
23
|
+
location?: number;
|
|
24
|
+
repeat?: boolean;
|
|
25
|
+
isComposing?: boolean;
|
|
26
|
+
ctrlKey?: boolean;
|
|
27
|
+
shiftKey?: boolean;
|
|
28
|
+
altKey?: boolean;
|
|
29
|
+
metaKey?: boolean;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Simulate the behaviour of the KeyboardEvent Class when there is no DOM available.
|
|
33
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
34
|
+
* @class
|
|
35
|
+
* @augments UIEventService
|
|
36
|
+
* @property {string} key
|
|
37
|
+
* @property {string} code
|
|
38
|
+
* @property {number} location
|
|
39
|
+
* @property {boolean} repeat
|
|
40
|
+
* @property {boolean} isComposing
|
|
41
|
+
*/
|
|
42
|
+
export declare class KeyboardEventService extends UIEventService {
|
|
43
|
+
private readonly keyValue;
|
|
44
|
+
private readonly keyCode;
|
|
45
|
+
private readonly keyLocation;
|
|
46
|
+
private readonly held;
|
|
47
|
+
private readonly composing;
|
|
48
|
+
private readonly modifiers;
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} [typeArg=''] The type of the event
|
|
51
|
+
* @param {KeyboardEventInit} [init={}] The options for the event
|
|
52
|
+
* @constructor
|
|
53
|
+
*/
|
|
54
|
+
constructor(typeArg?: string, init?: KeyboardEventInit);
|
|
55
|
+
get key(): string;
|
|
56
|
+
get code(): string;
|
|
57
|
+
get location(): number;
|
|
58
|
+
get repeat(): boolean;
|
|
59
|
+
get isComposing(): boolean;
|
|
60
|
+
get ctrlKey(): boolean;
|
|
61
|
+
get shiftKey(): boolean;
|
|
62
|
+
get altKey(): boolean;
|
|
63
|
+
get metaKey(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Whether a modifier key was held down when the event happened.
|
|
66
|
+
* @param {string} key Control, Shift, Alt or Meta
|
|
67
|
+
* @returns {boolean}
|
|
68
|
+
*/
|
|
69
|
+
getModifierState(key: string): boolean;
|
|
70
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.KeyboardEventService = void 0
|
|
7
|
+
/**
|
|
8
|
+
* @file Substitute for the DOM KeyboardEvent 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 KeyboardEvent Class when there is no DOM available.
|
|
16
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
17
|
+
* @class
|
|
18
|
+
* @augments UIEventService
|
|
19
|
+
* @property {string} key
|
|
20
|
+
* @property {string} code
|
|
21
|
+
* @property {number} location
|
|
22
|
+
* @property {boolean} repeat
|
|
23
|
+
* @property {boolean} isComposing
|
|
24
|
+
*/
|
|
25
|
+
class KeyboardEventService extends UIEventService_1.UIEventService {
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} [typeArg=''] The type of the event
|
|
28
|
+
* @param {KeyboardEventInit} [init={}] The options for the event
|
|
29
|
+
* @constructor
|
|
30
|
+
*/
|
|
31
|
+
constructor (typeArg = '', init = {}) {
|
|
32
|
+
super(typeArg, init)
|
|
33
|
+
this.keyValue = init.key || ''
|
|
34
|
+
this.keyCode = init.code || ''
|
|
35
|
+
this.keyLocation = init.location || 0
|
|
36
|
+
this.held = !!init.repeat
|
|
37
|
+
this.composing = !!init.isComposing
|
|
38
|
+
this.modifiers = (0, modifierState_1.modifierKeys)(init)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get key () {
|
|
42
|
+
return this.keyValue
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get code () {
|
|
46
|
+
return this.keyCode
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get location () {
|
|
50
|
+
return this.keyLocation
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get repeat () {
|
|
54
|
+
return this.held
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get isComposing () {
|
|
58
|
+
return this.composing
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get ctrlKey () {
|
|
62
|
+
return this.modifiers.ctrlKey
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get shiftKey () {
|
|
66
|
+
return this.modifiers.shiftKey
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get altKey () {
|
|
70
|
+
return this.modifiers.altKey
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get metaKey () {
|
|
74
|
+
return this.modifiers.metaKey
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Whether a modifier key was held down when the event happened.
|
|
79
|
+
* @param {string} key Control, Shift, Alt or Meta
|
|
80
|
+
* @returns {boolean}
|
|
81
|
+
*/
|
|
82
|
+
getModifierState (key) {
|
|
83
|
+
return (0, modifierState_1.modifierState)(this.modifiers, key)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.KeyboardEventService = KeyboardEventService
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KeyboardEventService=void 0;const UIEventService_1=require("./UIEventService"),modifierState_1=require("../functions/modifierState");class KeyboardEventService extends UIEventService_1.UIEventService{constructor(e="",t={}){super(e,t),this.keyValue=t.key||"",this.keyCode=t.code||"",this.keyLocation=t.location||0,this.held=!!t.repeat,this.composing=!!t.isComposing,this.modifiers=(0,modifierState_1.modifierKeys)(t)}get key(){return this.keyValue}get code(){return this.keyCode}get location(){return this.keyLocation}get repeat(){return this.held}get isComposing(){return this.composing}get ctrlKey(){return this.modifiers.ctrlKey}get shiftKey(){return this.modifiers.shiftKey}get altKey(){return this.modifiers.altKey}get metaKey(){return this.modifiers.metaKey}getModifierState(e){return(0,modifierState_1.modifierState)(this.modifiers,e)}}exports.KeyboardEventService=KeyboardEventService;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Substitute for the DOM MouseEvent Class.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { UIEventInit, UIEventService } from './UIEventService';
|
|
7
|
+
import { PseudoEventTarget } from '../interfaces/PseudoEventTarget';
|
|
8
|
+
/**
|
|
9
|
+
* The options for creating a mouse event, on top of the ones every UI event has.
|
|
10
|
+
* @typedef {Object} MouseEventInit
|
|
11
|
+
* @property {number} [screenX=0]
|
|
12
|
+
* @property {number} [screenY=0]
|
|
13
|
+
* @property {number} [clientX=0]
|
|
14
|
+
* @property {number} [clientY=0]
|
|
15
|
+
* @property {boolean} [ctrlKey=false]
|
|
16
|
+
* @property {boolean} [shiftKey=false]
|
|
17
|
+
* @property {boolean} [altKey=false]
|
|
18
|
+
* @property {boolean} [metaKey=false]
|
|
19
|
+
* @property {number} [button=0] The button which changed (0 is the main button)
|
|
20
|
+
* @property {number} [buttons=0] The buttons which are down
|
|
21
|
+
* @property {PseudoEventTarget|null} [relatedTarget=null] The other target involved (the one the mouse came from or went to)
|
|
22
|
+
*/
|
|
23
|
+
export type MouseEventInit = UIEventInit & {
|
|
24
|
+
screenX?: number;
|
|
25
|
+
screenY?: number;
|
|
26
|
+
clientX?: number;
|
|
27
|
+
clientY?: number;
|
|
28
|
+
ctrlKey?: boolean;
|
|
29
|
+
shiftKey?: boolean;
|
|
30
|
+
altKey?: boolean;
|
|
31
|
+
metaKey?: boolean;
|
|
32
|
+
button?: number;
|
|
33
|
+
buttons?: number;
|
|
34
|
+
relatedTarget?: PseudoEventTarget | null;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Simulate the behaviour of the MouseEvent Class when there is no DOM available.
|
|
38
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
39
|
+
* @class
|
|
40
|
+
* @augments UIEventService
|
|
41
|
+
* @property {number} screenX
|
|
42
|
+
* @property {number} screenY
|
|
43
|
+
* @property {number} clientX
|
|
44
|
+
* @property {number} clientY
|
|
45
|
+
* @property {number} button
|
|
46
|
+
* @property {number} buttons
|
|
47
|
+
* @property {PseudoEventTarget|null} relatedTarget
|
|
48
|
+
*/
|
|
49
|
+
export declare class MouseEventService extends UIEventService {
|
|
50
|
+
private readonly position;
|
|
51
|
+
private readonly modifiers;
|
|
52
|
+
private readonly buttonPressed;
|
|
53
|
+
private readonly buttonsDown;
|
|
54
|
+
private readonly related;
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} [typeArg=''] The type of the event
|
|
57
|
+
* @param {MouseEventInit} [init={}] The options for the event
|
|
58
|
+
* @constructor
|
|
59
|
+
*/
|
|
60
|
+
constructor(typeArg?: string, init?: MouseEventInit);
|
|
61
|
+
get screenX(): number;
|
|
62
|
+
get screenY(): number;
|
|
63
|
+
get clientX(): number;
|
|
64
|
+
get clientY(): number;
|
|
65
|
+
get x(): number;
|
|
66
|
+
get y(): number;
|
|
67
|
+
get ctrlKey(): boolean;
|
|
68
|
+
get shiftKey(): boolean;
|
|
69
|
+
get altKey(): boolean;
|
|
70
|
+
get metaKey(): boolean;
|
|
71
|
+
get button(): number;
|
|
72
|
+
get buttons(): number;
|
|
73
|
+
get relatedTarget(): PseudoEventTarget | null;
|
|
74
|
+
/**
|
|
75
|
+
* Whether a modifier key was held down when the event happened.
|
|
76
|
+
* @param {string} key Control, Shift, Alt or Meta
|
|
77
|
+
* @returns {boolean}
|
|
78
|
+
*/
|
|
79
|
+
getModifierState(key: string): boolean;
|
|
80
|
+
}
|
|
@@ -0,0 +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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MouseEventService=void 0;const UIEventService_1=require("./UIEventService"),modifierState_1=require("../functions/modifierState");class MouseEventService extends UIEventService_1.UIEventService{constructor(e="",t={}){super(e,t),this.position={screenX:t.screenX||0,screenY:t.screenY||0,clientX:t.clientX||0,clientY:t.clientY||0},this.modifiers=(0,modifierState_1.modifierKeys)(t),this.buttonPressed=t.button||0,this.buttonsDown=t.buttons||0,this.related=t.relatedTarget||null}get screenX(){return this.position.screenX}get screenY(){return this.position.screenY}get clientX(){return this.position.clientX}get clientY(){return this.position.clientY}get x(){return this.position.clientX}get y(){return this.position.clientY}get ctrlKey(){return this.modifiers.ctrlKey}get shiftKey(){return this.modifiers.shiftKey}get altKey(){return this.modifiers.altKey}get metaKey(){return this.modifiers.metaKey}get button(){return this.buttonPressed}get buttons(){return this.buttonsDown}get relatedTarget(){return this.related}getModifierState(e){return(0,modifierState_1.modifierState)(this.modifiers,e)}}exports.MouseEventService=MouseEventService;
|