synthetic-event 1.1.1 → 2.0.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/LICENSE.md +19 -19
- package/README.md +81 -89
- package/dist/index.js +131 -0
- package/dist/types/Event.d.ts +13 -0
- package/dist/types/EventListener.d.ts +5 -0
- package/dist/types/EventListenerObject.d.ts +12 -0
- package/dist/types/EventTarget.d.ts +55 -0
- package/dist/types/index.d.ts +4 -0
- package/package.json +77 -83
- package/build/synthetic-event.esm.js +0 -59
- package/build/synthetic-event.js +0 -121
- package/build/synthetic-event.min.js +0 -21
- package/build/types/Event.d.ts +0 -6
- package/build/types/EventListener.d.ts +0 -4
- package/build/types/EventListenerObject.d.ts +0 -4
- package/build/types/EventTarget.d.ts +0 -11
- package/build/types/index.d.ts +0 -4
package/LICENSE.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
Copyright © 2017 Raoul van Rüschen
|
|
2
|
-
|
|
3
|
-
This software is provided 'as-is', without any express or implied warranty. In
|
|
4
|
-
no event will the authors be held liable for any damages arising from the use of
|
|
5
|
-
this software.
|
|
6
|
-
|
|
7
|
-
Permission is granted to anyone to use this software for any purpose, including
|
|
8
|
-
commercial applications, and to alter it and redistribute it freely, subject to
|
|
9
|
-
the following restrictions:
|
|
10
|
-
|
|
11
|
-
1. The origin of this software must not be misrepresented; you must not claim
|
|
12
|
-
that you wrote the original software. If you use this software in a product,
|
|
13
|
-
an acknowledgment in the product documentation would be appreciated but is
|
|
14
|
-
not required.
|
|
15
|
-
|
|
16
|
-
2. Altered source versions must be plainly marked as such, and must not be
|
|
17
|
-
misrepresented as being the original software.
|
|
18
|
-
|
|
19
|
-
3. This notice may not be removed or altered from any source distribution.
|
|
1
|
+
Copyright © 2017 Raoul van Rüschen
|
|
2
|
+
|
|
3
|
+
This software is provided 'as-is', without any express or implied warranty. In
|
|
4
|
+
no event will the authors be held liable for any damages arising from the use of
|
|
5
|
+
this software.
|
|
6
|
+
|
|
7
|
+
Permission is granted to anyone to use this software for any purpose, including
|
|
8
|
+
commercial applications, and to alter it and redistribute it freely, subject to
|
|
9
|
+
the following restrictions:
|
|
10
|
+
|
|
11
|
+
1. The origin of this software must not be misrepresented; you must not claim
|
|
12
|
+
that you wrote the original software. If you use this software in a product,
|
|
13
|
+
an acknowledgment in the product documentation would be appreciated but is
|
|
14
|
+
not required.
|
|
15
|
+
|
|
16
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
|
17
|
+
misrepresented as being the original software.
|
|
18
|
+
|
|
19
|
+
3. This notice may not be removed or altered from any source distribution.
|
package/README.md
CHANGED
|
@@ -1,89 +1,81 @@
|
|
|
1
|
-
# Synthetic Event
|
|
2
|
-
|
|
3
|
-
[](https://github.com/vanruesc/synthetic-event/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/synthetic-event)
|
|
5
|
+
|
|
6
|
+
This library provides a simplified implementation of the [EventTarget](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) interface. The included classes and interfaces can be used to create [synthetic events](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Events#creating_and_dispatching_events) and custom event targets in any environment.
|
|
7
|
+
|
|
8
|
+
If your focus lies on DOM events, please refer to the native [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) class. An alternative way to create custom event targets in a browser environment is to use a [DocumentFragment](https://developer.mozilla.org/en/docs/Web/API/Document/createDocumentFragment) as a dummy target.
|
|
9
|
+
|
|
10
|
+
*[Documentation](https://vanruesc.github.io/synthetic-event)*
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install synthetic-event
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
##### Basics
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { Event, EventTarget } from "synthetic-event";
|
|
24
|
+
|
|
25
|
+
export interface MyEventMap {
|
|
26
|
+
|
|
27
|
+
test: Event<"test">;
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const eventTarget = new EventTarget<MyEventMap>();
|
|
32
|
+
|
|
33
|
+
eventTarget.addEventListener("test", (event) => {
|
|
34
|
+
|
|
35
|
+
console.log("listener function", event.target);
|
|
36
|
+
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
eventTarget.addEventListener("test", {
|
|
40
|
+
|
|
41
|
+
handleEvent(event) {
|
|
42
|
+
|
|
43
|
+
console.log("listener object", event.target);
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
eventTarget.dispatchEvent({ type: "test" });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
##### Custom EventTarget
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { Event, EventTarget } from "synthetic-event";
|
|
56
|
+
|
|
57
|
+
export interface MyEventMap {
|
|
58
|
+
|
|
59
|
+
tick: Event<"tick">;
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class MyEventTarget extends EventTarget<MyEventMap> {
|
|
64
|
+
|
|
65
|
+
private readonly myEvent: Event<"tick">;
|
|
66
|
+
|
|
67
|
+
constructor() {
|
|
68
|
+
|
|
69
|
+
super();
|
|
70
|
+
|
|
71
|
+
this.myEvent = { type: "tick" };
|
|
72
|
+
setInterval(() => this.dispatchEvent(this.myEvent), 1000);
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
|
|
81
|
+
Maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* synthetic-event v2.0.0 build Sat Jan 10 2026
|
|
3
|
+
* https://github.com/vanruesc/synthetic-event
|
|
4
|
+
* Copyright 2026 Raoul van Rüschen
|
|
5
|
+
* @license Zlib
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// src/EventTarget.ts
|
|
9
|
+
var EventTarget = class {
|
|
10
|
+
/**
|
|
11
|
+
* A collection of event listener functions.
|
|
12
|
+
*/
|
|
13
|
+
listenerFunctions;
|
|
14
|
+
/**
|
|
15
|
+
* A collection of event listener objects.
|
|
16
|
+
*/
|
|
17
|
+
listenerObjects;
|
|
18
|
+
/**
|
|
19
|
+
* Constructs a new event target.
|
|
20
|
+
*/
|
|
21
|
+
constructor() {
|
|
22
|
+
this.listenerFunctions = /* @__PURE__ */ new Map();
|
|
23
|
+
this.listenerObjects = /* @__PURE__ */ new Map();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Registers an event handler of a specific event type on the event target.
|
|
27
|
+
*
|
|
28
|
+
* @param type - The event type to listen for.
|
|
29
|
+
* @param listener - An event listener or callback.
|
|
30
|
+
*/
|
|
31
|
+
addEventListener(type, listener) {
|
|
32
|
+
if (typeof listener === "function") {
|
|
33
|
+
if (this.listenerFunctions.has(type)) {
|
|
34
|
+
const listeners = this.listenerFunctions.get(type);
|
|
35
|
+
listeners.add(listener);
|
|
36
|
+
} else {
|
|
37
|
+
const listeners = /* @__PURE__ */ new Set([listener]);
|
|
38
|
+
this.listenerFunctions.set(type, listeners);
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (this.listenerObjects.has(type)) {
|
|
43
|
+
const listeners = this.listenerObjects.get(type);
|
|
44
|
+
listeners.add(listener);
|
|
45
|
+
} else {
|
|
46
|
+
const listeners = /* @__PURE__ */ new Set([listener]);
|
|
47
|
+
this.listenerObjects.set(type, listeners);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Removes an event handler of a specific event type from the event target.
|
|
52
|
+
*
|
|
53
|
+
* @param type - The event type to remove.
|
|
54
|
+
* @param listener - The event listener to remove.
|
|
55
|
+
*/
|
|
56
|
+
hasEventListener(type, listener) {
|
|
57
|
+
if (typeof listener === "function") {
|
|
58
|
+
if (!this.listenerFunctions.has(type)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const listeners2 = this.listenerFunctions.get(type);
|
|
62
|
+
return listeners2.has(listener);
|
|
63
|
+
}
|
|
64
|
+
if (!this.listenerObjects.has(type)) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const listeners = this.listenerObjects.get(type);
|
|
68
|
+
return listeners.has(listener);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Removes an event handler of a specific event type from the event target.
|
|
72
|
+
*
|
|
73
|
+
* @param type - The event type to remove.
|
|
74
|
+
* @param listener - The event listener to remove.
|
|
75
|
+
*/
|
|
76
|
+
removeEventListener(type, listener) {
|
|
77
|
+
if (typeof listener === "function") {
|
|
78
|
+
if (!this.listenerFunctions.has(type)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const listeners2 = this.listenerFunctions.get(type);
|
|
82
|
+
if (listeners2.delete(listener) && listeners2.size === 0) {
|
|
83
|
+
this.listenerFunctions.delete(type);
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!this.listenerObjects.has(type)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const listeners = this.listenerObjects.get(type);
|
|
91
|
+
if (listeners.delete(listener) && listeners.size === 0) {
|
|
92
|
+
this.listenerObjects.delete(type);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Dispatches an event at the specified event target, invoking the affected event listeners in the appropriate order.
|
|
97
|
+
*
|
|
98
|
+
* Event listeners can safely be added and removed while an event is being dispatched.
|
|
99
|
+
*
|
|
100
|
+
* @see https://262.ecma-international.org/#sec-map.prototype.foreach for more information on the iteration behavior.
|
|
101
|
+
* @param event - The event to dispatch.
|
|
102
|
+
* @param target - An event target.
|
|
103
|
+
*/
|
|
104
|
+
dispatchEvent(event, target = this) {
|
|
105
|
+
const listenerFunctions = target.listenerFunctions;
|
|
106
|
+
const listenerObjects = target.listenerObjects;
|
|
107
|
+
event.target = target;
|
|
108
|
+
if (listenerFunctions.has(event.type)) {
|
|
109
|
+
const listeners = listenerFunctions.get(event.type);
|
|
110
|
+
for (const listener of listeners) {
|
|
111
|
+
listener.call(target, event);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (listenerObjects.has(event.type)) {
|
|
115
|
+
const listeners = listenerObjects.get(event.type);
|
|
116
|
+
for (const listener of listeners) {
|
|
117
|
+
listener.handleEvent(event);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Removes all listeners.
|
|
123
|
+
*/
|
|
124
|
+
clearEventListeners() {
|
|
125
|
+
this.listenerFunctions.clear();
|
|
126
|
+
this.listenerObjects.clear();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
export {
|
|
130
|
+
EventTarget
|
|
131
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An event.
|
|
3
|
+
*/
|
|
4
|
+
export interface Event<TEventType extends string = string, TTarget = unknown> {
|
|
5
|
+
/**
|
|
6
|
+
* The type of the event.
|
|
7
|
+
*/
|
|
8
|
+
type: TEventType;
|
|
9
|
+
/**
|
|
10
|
+
* A reference to the target to which the event was originally dispatched.
|
|
11
|
+
*/
|
|
12
|
+
target?: TTarget;
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Event } from "./Event.js";
|
|
2
|
+
/**
|
|
3
|
+
* An event listener object.
|
|
4
|
+
*/
|
|
5
|
+
export interface EventListenerObject<TEventData, TEventType extends string, TTarget = unknown> {
|
|
6
|
+
/**
|
|
7
|
+
* Handles a given event.
|
|
8
|
+
*
|
|
9
|
+
* @param event - The event.
|
|
10
|
+
*/
|
|
11
|
+
handleEvent(event: TEventData & Event<TEventType, TTarget>): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Event } from "./Event.js";
|
|
2
|
+
import { EventListener } from "./EventListener.js";
|
|
3
|
+
import { EventListenerObject } from "./EventListenerObject.js";
|
|
4
|
+
/**
|
|
5
|
+
* An event target that can dispatch events to registered listeners.
|
|
6
|
+
*/
|
|
7
|
+
export declare class EventTarget<TEventMap extends object = object> {
|
|
8
|
+
/**
|
|
9
|
+
* A collection of event listener functions.
|
|
10
|
+
*/
|
|
11
|
+
protected readonly listenerFunctions: Map<string, Set<EventListener<TEventMap[keyof TEventMap], string, this>>>;
|
|
12
|
+
/**
|
|
13
|
+
* A collection of event listener objects.
|
|
14
|
+
*/
|
|
15
|
+
protected readonly listenerObjects: Map<string, Set<EventListenerObject<TEventMap[keyof TEventMap], string, this>>>;
|
|
16
|
+
/**
|
|
17
|
+
* Constructs a new event target.
|
|
18
|
+
*/
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Registers an event handler of a specific event type on the event target.
|
|
22
|
+
*
|
|
23
|
+
* @param type - The event type to listen for.
|
|
24
|
+
* @param listener - An event listener or callback.
|
|
25
|
+
*/
|
|
26
|
+
addEventListener<T extends Extract<keyof TEventMap, string>>(type: T, listener: EventListener<TEventMap[T], T, this> | EventListenerObject<TEventMap[T], T, this>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Removes an event handler of a specific event type from the event target.
|
|
29
|
+
*
|
|
30
|
+
* @param type - The event type to remove.
|
|
31
|
+
* @param listener - The event listener to remove.
|
|
32
|
+
*/
|
|
33
|
+
hasEventListener<T extends Extract<keyof TEventMap, string>>(type: T, listener: EventListener<TEventMap[T], T, this> | EventListenerObject<TEventMap[T], T, this>): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Removes an event handler of a specific event type from the event target.
|
|
36
|
+
*
|
|
37
|
+
* @param type - The event type to remove.
|
|
38
|
+
* @param listener - The event listener to remove.
|
|
39
|
+
*/
|
|
40
|
+
removeEventListener<T extends Extract<keyof TEventMap, string>>(type: T, listener: EventListener<TEventMap[T], T, this> | EventListenerObject<TEventMap[T], T, this>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Dispatches an event at the specified event target, invoking the affected event listeners in the appropriate order.
|
|
43
|
+
*
|
|
44
|
+
* Event listeners can safely be added and removed while an event is being dispatched.
|
|
45
|
+
*
|
|
46
|
+
* @see https://262.ecma-international.org/#sec-map.prototype.foreach for more information on the iteration behavior.
|
|
47
|
+
* @param event - The event to dispatch.
|
|
48
|
+
* @param target - An event target.
|
|
49
|
+
*/
|
|
50
|
+
dispatchEvent<T extends Extract<keyof TEventMap, string>>(event: Event<T> & TEventMap[T], target?: EventTarget<TEventMap>): void;
|
|
51
|
+
/**
|
|
52
|
+
* Removes all listeners.
|
|
53
|
+
*/
|
|
54
|
+
clearEventListeners(): void;
|
|
55
|
+
}
|
package/package.json
CHANGED
|
@@ -1,83 +1,77 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "synthetic-event",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A collection of base classes for custom events and event targets.",
|
|
5
|
-
"homepage": "https://github.com/vanruesc/synthetic-event",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"url": "https://github.com/vanruesc/synthetic-event
|
|
34
|
-
},
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"rollup-plugin-terser": "7.x.x",
|
|
79
|
-
"tslib": "2.x.x",
|
|
80
|
-
"typedoc": "0.x.x",
|
|
81
|
-
"typescript": "3.x.x"
|
|
82
|
-
}
|
|
83
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "synthetic-event",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "A collection of base classes for custom events and event targets.",
|
|
5
|
+
"homepage": "https://github.com/vanruesc/synthetic-event",
|
|
6
|
+
"license": "Zlib",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/types/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"event",
|
|
20
|
+
"target",
|
|
21
|
+
"emitter",
|
|
22
|
+
"listener",
|
|
23
|
+
"dispatcher",
|
|
24
|
+
"synthetic",
|
|
25
|
+
"custom"
|
|
26
|
+
],
|
|
27
|
+
"author": {
|
|
28
|
+
"name": "Raoul van Rüschen",
|
|
29
|
+
"email": "vanruesc@outlook.de"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/vanruesc/synthetic-event.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/vanruesc/synthetic-event/issues"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">= 21"
|
|
43
|
+
},
|
|
44
|
+
"pnpm": {
|
|
45
|
+
"onlyBuiltDependencies": [
|
|
46
|
+
"esbuild"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "run-p build:js:min build:dts",
|
|
51
|
+
"build:js": "node esbuild",
|
|
52
|
+
"build:js:min": "node esbuild -m",
|
|
53
|
+
"build:dts": "tsc -p tsconfig.d.json",
|
|
54
|
+
"clean": "del-cli dist public",
|
|
55
|
+
"doc": "typedoc --plugin typedoc-plugin-mdn-links",
|
|
56
|
+
"lint": "run-p lint:*",
|
|
57
|
+
"lint:js": "eslint --fix src test",
|
|
58
|
+
"lint:tsc": "tsc --noEmit",
|
|
59
|
+
"prepublishOnly": "npm test",
|
|
60
|
+
"pretest": "run-s clean lint build",
|
|
61
|
+
"test": "node --import tsx --test",
|
|
62
|
+
"posttest": "npm run doc"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@types/node": "25.x.x",
|
|
66
|
+
"del-cli": "7.x.x",
|
|
67
|
+
"esbuild": "0.27.x",
|
|
68
|
+
"eslint": "9.x.x",
|
|
69
|
+
"eslint-config-aether": "2.x.x",
|
|
70
|
+
"npm-run-all": "4.x.x",
|
|
71
|
+
"tslib": "2.x.x",
|
|
72
|
+
"tsx": "4.x.x",
|
|
73
|
+
"typedoc": "0.x.x",
|
|
74
|
+
"typedoc-plugin-mdn-links": "5.x.x",
|
|
75
|
+
"typescript": "5.9.x"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* synthetic-event v1.1.1 build Mon Aug 10 2020
|
|
3
|
-
* https://github.com/vanruesc/synthetic-event
|
|
4
|
-
* Copyright 2020 Raoul van Rüschen
|
|
5
|
-
* @license Zlib
|
|
6
|
-
*/
|
|
7
|
-
class Event {
|
|
8
|
-
constructor(type) {
|
|
9
|
-
this.type = type;
|
|
10
|
-
this.target = null;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
class EventTarget {
|
|
15
|
-
constructor() {
|
|
16
|
-
this.listenerFunctions = new Map();
|
|
17
|
-
this.listenerObjects = new Map();
|
|
18
|
-
}
|
|
19
|
-
addEventListener(type, listener) {
|
|
20
|
-
const m = (typeof listener === "function") ?
|
|
21
|
-
this.listenerFunctions : this.listenerObjects;
|
|
22
|
-
if (m.has(type)) {
|
|
23
|
-
m.get(type).add(listener);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
m.set(type, new Set([listener]));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
removeEventListener(type, listener) {
|
|
30
|
-
const m = (typeof listener === "function") ?
|
|
31
|
-
this.listenerFunctions : this.listenerObjects;
|
|
32
|
-
if (m.has(type)) {
|
|
33
|
-
const listeners = m.get(type);
|
|
34
|
-
listeners.delete(listener);
|
|
35
|
-
if (listeners.size === 0) {
|
|
36
|
-
m.delete(type);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
dispatchEvent(event, target = this) {
|
|
41
|
-
const listenerFunctions = target.listenerFunctions;
|
|
42
|
-
const listenerObjects = target.listenerObjects;
|
|
43
|
-
event.target = target;
|
|
44
|
-
if (listenerFunctions.has(event.type)) {
|
|
45
|
-
const listeners = listenerFunctions.get(event.type);
|
|
46
|
-
for (const listener of listeners) {
|
|
47
|
-
listener.call(target, event);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (listenerObjects.has(event.type)) {
|
|
51
|
-
const listeners = listenerObjects.get(event.type);
|
|
52
|
-
for (const listener of listeners) {
|
|
53
|
-
listener.handleEvent(event);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { Event, EventTarget };
|
package/build/synthetic-event.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* synthetic-event v1.1.1 build Mon Aug 10 2020
|
|
3
|
-
* https://github.com/vanruesc/synthetic-event
|
|
4
|
-
* Copyright 2020 Raoul van Rüschen
|
|
5
|
-
* @license Zlib
|
|
6
|
-
*/
|
|
7
|
-
(function (global, factory) {
|
|
8
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
9
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
10
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SYNTHETICEVENT = {}));
|
|
11
|
-
}(this, (function (exports) { 'use strict';
|
|
12
|
-
|
|
13
|
-
var Event = (function () {
|
|
14
|
-
function Event(type) {
|
|
15
|
-
this.type = type;
|
|
16
|
-
this.target = null;
|
|
17
|
-
}
|
|
18
|
-
return Event;
|
|
19
|
-
}());
|
|
20
|
-
|
|
21
|
-
/*! *****************************************************************************
|
|
22
|
-
Copyright (c) Microsoft Corporation.
|
|
23
|
-
|
|
24
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
25
|
-
purpose with or without fee is hereby granted.
|
|
26
|
-
|
|
27
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
28
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
29
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
30
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
31
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
32
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
33
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
34
|
-
***************************************************************************** */
|
|
35
|
-
|
|
36
|
-
function __values(o) {
|
|
37
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
38
|
-
if (m) return m.call(o);
|
|
39
|
-
if (o && typeof o.length === "number") return {
|
|
40
|
-
next: function () {
|
|
41
|
-
if (o && i >= o.length) o = void 0;
|
|
42
|
-
return { value: o && o[i++], done: !o };
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
var EventTarget = (function () {
|
|
49
|
-
function EventTarget() {
|
|
50
|
-
this.listenerFunctions = new Map();
|
|
51
|
-
this.listenerObjects = new Map();
|
|
52
|
-
}
|
|
53
|
-
EventTarget.prototype.addEventListener = function (type, listener) {
|
|
54
|
-
var m = (typeof listener === "function") ?
|
|
55
|
-
this.listenerFunctions : this.listenerObjects;
|
|
56
|
-
if (m.has(type)) {
|
|
57
|
-
m.get(type).add(listener);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
m.set(type, new Set([listener]));
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
EventTarget.prototype.removeEventListener = function (type, listener) {
|
|
64
|
-
var m = (typeof listener === "function") ?
|
|
65
|
-
this.listenerFunctions : this.listenerObjects;
|
|
66
|
-
if (m.has(type)) {
|
|
67
|
-
var listeners = m.get(type);
|
|
68
|
-
listeners.delete(listener);
|
|
69
|
-
if (listeners.size === 0) {
|
|
70
|
-
m.delete(type);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
EventTarget.prototype.dispatchEvent = function (event, target) {
|
|
75
|
-
var e_1, _a, e_2, _b;
|
|
76
|
-
if (target === void 0) { target = this; }
|
|
77
|
-
var listenerFunctions = target.listenerFunctions;
|
|
78
|
-
var listenerObjects = target.listenerObjects;
|
|
79
|
-
event.target = target;
|
|
80
|
-
if (listenerFunctions.has(event.type)) {
|
|
81
|
-
var listeners = listenerFunctions.get(event.type);
|
|
82
|
-
try {
|
|
83
|
-
for (var listeners_1 = __values(listeners), listeners_1_1 = listeners_1.next(); !listeners_1_1.done; listeners_1_1 = listeners_1.next()) {
|
|
84
|
-
var listener = listeners_1_1.value;
|
|
85
|
-
listener.call(target, event);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
89
|
-
finally {
|
|
90
|
-
try {
|
|
91
|
-
if (listeners_1_1 && !listeners_1_1.done && (_a = listeners_1.return)) _a.call(listeners_1);
|
|
92
|
-
}
|
|
93
|
-
finally { if (e_1) throw e_1.error; }
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (listenerObjects.has(event.type)) {
|
|
97
|
-
var listeners = listenerObjects.get(event.type);
|
|
98
|
-
try {
|
|
99
|
-
for (var listeners_2 = __values(listeners), listeners_2_1 = listeners_2.next(); !listeners_2_1.done; listeners_2_1 = listeners_2.next()) {
|
|
100
|
-
var listener = listeners_2_1.value;
|
|
101
|
-
listener.handleEvent(event);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
105
|
-
finally {
|
|
106
|
-
try {
|
|
107
|
-
if (listeners_2_1 && !listeners_2_1.done && (_b = listeners_2.return)) _b.call(listeners_2);
|
|
108
|
-
}
|
|
109
|
-
finally { if (e_2) throw e_2.error; }
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
return EventTarget;
|
|
114
|
-
}());
|
|
115
|
-
|
|
116
|
-
exports.Event = Event;
|
|
117
|
-
exports.EventTarget = EventTarget;
|
|
118
|
-
|
|
119
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
120
|
-
|
|
121
|
-
})));
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* synthetic-event v1.1.1 build Mon Aug 10 2020
|
|
3
|
-
* https://github.com/vanruesc/synthetic-event
|
|
4
|
-
* Copyright 2020 Raoul van Rüschen
|
|
5
|
-
* @license Zlib
|
|
6
|
-
*/
|
|
7
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SYNTHETICEVENT={})}(this,(function(e){"use strict";var t=function(e){this.type=e,this.target=null};
|
|
8
|
-
/*! *****************************************************************************
|
|
9
|
-
Copyright (c) Microsoft Corporation.
|
|
10
|
-
|
|
11
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
12
|
-
purpose with or without fee is hereby granted.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
15
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
16
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
17
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
18
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
19
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
20
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
21
|
-
***************************************************************************** */function n(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}var r=function(){function e(){this.listenerFunctions=new Map,this.listenerObjects=new Map}return e.prototype.addEventListener=function(e,t){var n="function"==typeof t?this.listenerFunctions:this.listenerObjects;n.has(e)?n.get(e).add(t):n.set(e,new Set([t]))},e.prototype.removeEventListener=function(e,t){var n="function"==typeof t?this.listenerFunctions:this.listenerObjects;if(n.has(e)){var r=n.get(e);r.delete(t),0===r.size&&n.delete(e)}},e.prototype.dispatchEvent=function(e,t){var r,i,o,l;void 0===t&&(t=this);var s=t.listenerFunctions,a=t.listenerObjects;if(e.target=t,s.has(e.type)){var f=s.get(e.type);try{for(var c=n(f),u=c.next();!u.done;u=c.next()){u.value.call(t,e)}}catch(e){r={error:e}}finally{try{u&&!u.done&&(i=c.return)&&i.call(c)}finally{if(r)throw r.error}}}if(a.has(e.type)){f=a.get(e.type);try{for(var y=n(f),d=y.next();!d.done;d=y.next()){d.value.handleEvent(e)}}catch(e){o={error:e}}finally{try{d&&!d.done&&(l=y.return)&&l.call(y)}finally{if(o)throw o.error}}}},e}();e.Event=t,e.EventTarget=r,Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/build/types/Event.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Event } from "./Event";
|
|
2
|
-
import { EventListener } from "./EventListener";
|
|
3
|
-
import { EventListenerObject } from "./EventListenerObject";
|
|
4
|
-
export declare class EventTarget {
|
|
5
|
-
protected listenerFunctions: Map<string, Set<EventListener>>;
|
|
6
|
-
protected listenerObjects: Map<string, Set<EventListenerObject>>;
|
|
7
|
-
constructor();
|
|
8
|
-
addEventListener(type: string, listener: EventListener | EventListenerObject): void;
|
|
9
|
-
removeEventListener(type: string, listener: EventListener | EventListenerObject): void;
|
|
10
|
-
dispatchEvent(event: Event, target?: EventTarget): void;
|
|
11
|
-
}
|
package/build/types/index.d.ts
DELETED