@formily-design/shared 1.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 +20 -0
- package/README.md +1 -0
- package/dist/designable.shared.umd.production.js +1 -0
- package/dist/designable.shared.umd.production.min.js +2051 -0
- package/esm/animation.d.ts +2 -0
- package/esm/animation.js +33 -0
- package/esm/array.d.ts +37 -0
- package/esm/array.js +111 -0
- package/esm/clone.d.ts +4 -0
- package/esm/clone.js +97 -0
- package/esm/compose.d.ts +1 -0
- package/esm/compose.js +7 -0
- package/esm/coordinate.d.ts +106 -0
- package/esm/coordinate.js +475 -0
- package/esm/element.d.ts +6 -0
- package/esm/element.js +137 -0
- package/esm/event.d.ts +96 -0
- package/esm/event.js +213 -0
- package/esm/globalThisPolyfill.d.ts +1 -0
- package/esm/globalThisPolyfill.js +22 -0
- package/esm/index.d.ts +17 -0
- package/esm/index.js +17 -0
- package/esm/instanceof.d.ts +1 -0
- package/esm/instanceof.js +11 -0
- package/esm/keycode.d.ts +147 -0
- package/esm/keycode.js +150 -0
- package/esm/lru.d.ts +73 -0
- package/esm/lru.js +293 -0
- package/esm/observer.d.ts +9 -0
- package/esm/observer.js +29 -0
- package/esm/request-idle.d.ts +10 -0
- package/esm/request-idle.js +8 -0
- package/esm/scroller.d.ts +10 -0
- package/esm/scroller.js +82 -0
- package/esm/subscribable.d.ts +14 -0
- package/esm/subscribable.js +48 -0
- package/esm/types.d.ts +13 -0
- package/esm/types.js +21 -0
- package/esm/uid.d.ts +1 -0
- package/esm/uid.js +9 -0
- package/lib/animation.d.ts +2 -0
- package/lib/animation.js +38 -0
- package/lib/array.d.ts +37 -0
- package/lib/array.js +125 -0
- package/lib/clone.d.ts +4 -0
- package/lib/clone.js +102 -0
- package/lib/compose.d.ts +1 -0
- package/lib/compose.js +11 -0
- package/lib/coordinate.d.ts +106 -0
- package/lib/coordinate.js +504 -0
- package/lib/element.d.ts +6 -0
- package/lib/element.js +145 -0
- package/lib/event.d.ts +96 -0
- package/lib/event.js +218 -0
- package/lib/globalThisPolyfill.d.ts +1 -0
- package/lib/globalThisPolyfill.js +25 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +33 -0
- package/lib/instanceof.d.ts +1 -0
- package/lib/instanceof.js +15 -0
- package/lib/keycode.d.ts +147 -0
- package/lib/keycode.js +154 -0
- package/lib/lru.d.ts +73 -0
- package/lib/lru.js +297 -0
- package/lib/observer.d.ts +9 -0
- package/lib/observer.js +33 -0
- package/lib/request-idle.d.ts +10 -0
- package/lib/request-idle.js +13 -0
- package/lib/scroller.d.ts +10 -0
- package/lib/scroller.js +88 -0
- package/lib/subscribable.d.ts +14 -0
- package/lib/subscribable.js +52 -0
- package/lib/types.d.ts +13 -0
- package/lib/types.js +29 -0
- package/lib/uid.d.ts +1 -0
- package/lib/uid.js +12 -0
- package/package.json +32 -0
- package/rollup.config.js +3 -0
- package/src/animation.ts +38 -0
- package/src/array.ts +301 -0
- package/src/clone.ts +96 -0
- package/src/compose.ts +7 -0
- package/src/coordinate.ts +633 -0
- package/src/element.ts +144 -0
- package/src/event.ts +379 -0
- package/src/globalThisPolyfill.ts +19 -0
- package/src/index.ts +17 -0
- package/src/instanceof.ts +10 -0
- package/src/keycode.ts +150 -0
- package/src/lru.ts +322 -0
- package/src/observer.ts +38 -0
- package/src/request-idle.ts +22 -0
- package/src/scroller.ts +113 -0
- package/src/subscribable.ts +60 -0
- package/src/types.ts +27 -0
- package/src/uid.ts +10 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +5 -0
package/esm/event.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Subscribable, ISubscriber } from './subscribable';
|
|
2
|
+
export type EventOptions = boolean | (AddEventListenerOptions & EventListenerOptions & {
|
|
3
|
+
mode?: 'onlyOne' | 'onlyParent' | 'onlyChild';
|
|
4
|
+
});
|
|
5
|
+
export type EventContainer = Window | HTMLElement | HTMLDocument;
|
|
6
|
+
export type EventDriverContainer = HTMLElement | HTMLDocument;
|
|
7
|
+
export interface IEventEffect<T> {
|
|
8
|
+
(engine: T): void;
|
|
9
|
+
}
|
|
10
|
+
export interface IEventDriver {
|
|
11
|
+
container: EventDriverContainer;
|
|
12
|
+
contentWindow: Window;
|
|
13
|
+
attach(container: EventDriverContainer): void;
|
|
14
|
+
detach(container: EventDriverContainer): void;
|
|
15
|
+
dispatch<T extends ICustomEvent<any> = any>(event: T): void | boolean;
|
|
16
|
+
subscribe<T extends ICustomEvent<any> = any>(subscriber: ISubscriber<T>): void;
|
|
17
|
+
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventOptions): void;
|
|
18
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventOptions): void;
|
|
19
|
+
addEventListener(type: any, listener: any, options: any): void;
|
|
20
|
+
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventOptions): void;
|
|
21
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventOptions): void;
|
|
22
|
+
removeEventListener(type: any, listener: any, options?: any): void;
|
|
23
|
+
batchAddEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventOptions): void;
|
|
24
|
+
batchAddEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventOptions): void;
|
|
25
|
+
batchAddEventListener(type: any, listener: any, options?: any): void;
|
|
26
|
+
batchRemoveEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventOptions): void;
|
|
27
|
+
batchRemoveEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventOptions): void;
|
|
28
|
+
batchRemoveEventListener(type: any, listener: any, options: any): void;
|
|
29
|
+
}
|
|
30
|
+
export interface IEventDriverClass<T> {
|
|
31
|
+
new (engine: T, context?: any): IEventDriver;
|
|
32
|
+
}
|
|
33
|
+
export interface ICustomEvent<EventData = any, EventContext = any> {
|
|
34
|
+
type: string;
|
|
35
|
+
data?: EventData;
|
|
36
|
+
context?: EventContext;
|
|
37
|
+
}
|
|
38
|
+
export interface CustomEventClass {
|
|
39
|
+
new (...args: any[]): any;
|
|
40
|
+
}
|
|
41
|
+
export interface IEventProps<T = Event> {
|
|
42
|
+
drivers?: IEventDriverClass<T>[];
|
|
43
|
+
effects?: IEventEffect<T>[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 事件驱动器基类
|
|
47
|
+
*/
|
|
48
|
+
export declare class EventDriver<Engine extends Event = Event, Context = any> implements IEventDriver {
|
|
49
|
+
engine: Engine;
|
|
50
|
+
container: EventDriverContainer;
|
|
51
|
+
contentWindow: Window;
|
|
52
|
+
context: Context;
|
|
53
|
+
constructor(engine: Engine, context?: Context);
|
|
54
|
+
dispatch<T extends ICustomEvent<any> = any>(event: T): boolean;
|
|
55
|
+
subscribe<T extends ICustomEvent<any> = any>(subscriber: ISubscriber<T>): {
|
|
56
|
+
(): void;
|
|
57
|
+
[UNSUBSCRIBE_ID_SYMBOL]: number;
|
|
58
|
+
};
|
|
59
|
+
subscribeTo<T extends CustomEventClass>(type: T, subscriber: ISubscriber<InstanceType<T>>): {
|
|
60
|
+
(): void;
|
|
61
|
+
[UNSUBSCRIBE_ID_SYMBOL]: number;
|
|
62
|
+
};
|
|
63
|
+
subscribeWith<T extends ICustomEvent = ICustomEvent>(type: string | string[], subscriber: ISubscriber<T>): {
|
|
64
|
+
(): void;
|
|
65
|
+
[UNSUBSCRIBE_ID_SYMBOL]: number;
|
|
66
|
+
};
|
|
67
|
+
attach(container: EventDriverContainer): void;
|
|
68
|
+
detach(container: EventDriverContainer): void;
|
|
69
|
+
eventTarget(type: string): Window | EventDriverContainer;
|
|
70
|
+
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventOptions): void;
|
|
71
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventOptions): void;
|
|
72
|
+
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventOptions): void;
|
|
73
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventOptions): void;
|
|
74
|
+
batchAddEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventOptions): void;
|
|
75
|
+
batchAddEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventOptions): void;
|
|
76
|
+
batchRemoveEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventOptions): void;
|
|
77
|
+
batchRemoveEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventOptions): void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 事件引擎
|
|
81
|
+
*/
|
|
82
|
+
export declare class Event extends Subscribable<ICustomEvent<any>> {
|
|
83
|
+
private drivers;
|
|
84
|
+
private containers;
|
|
85
|
+
constructor(props?: IEventProps);
|
|
86
|
+
subscribeTo<T extends CustomEventClass>(type: T, subscriber: ISubscriber<InstanceType<T>>): {
|
|
87
|
+
(): void;
|
|
88
|
+
[UNSUBSCRIBE_ID_SYMBOL]: number;
|
|
89
|
+
};
|
|
90
|
+
subscribeWith<T extends ICustomEvent = ICustomEvent>(type: string | string[], subscriber: ISubscriber<T>): {
|
|
91
|
+
(): void;
|
|
92
|
+
[UNSUBSCRIBE_ID_SYMBOL]: number;
|
|
93
|
+
};
|
|
94
|
+
attachEvents(container: EventContainer, contentWindow?: Window, context?: any): any;
|
|
95
|
+
detachEvents(container?: EventContainer): any;
|
|
96
|
+
}
|
package/esm/event.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { isArr, isWindow } from './types';
|
|
2
|
+
import { Subscribable } from './subscribable';
|
|
3
|
+
import { globalThisPolyfill } from './globalThisPolyfill';
|
|
4
|
+
const ATTACHED_SYMBOL = Symbol('ATTACHED_SYMBOL');
|
|
5
|
+
const EVENTS_SYMBOL = Symbol('__EVENTS_SYMBOL__');
|
|
6
|
+
const EVENTS_ONCE_SYMBOL = Symbol('EVENTS_ONCE_SYMBOL');
|
|
7
|
+
const EVENTS_BATCH_SYMBOL = Symbol('EVENTS_BATCH_SYMBOL');
|
|
8
|
+
const DRIVER_INSTANCES_SYMBOL = Symbol('DRIVER_INSTANCES_SYMBOL');
|
|
9
|
+
const isOnlyMode = (mode) => mode === 'onlyOne' || mode === 'onlyChild' || mode === 'onlyParent';
|
|
10
|
+
/**
|
|
11
|
+
* 事件驱动器基类
|
|
12
|
+
*/
|
|
13
|
+
export class EventDriver {
|
|
14
|
+
constructor(engine, context) {
|
|
15
|
+
this.container = document;
|
|
16
|
+
this.contentWindow = globalThisPolyfill;
|
|
17
|
+
this.engine = engine;
|
|
18
|
+
this.context = context;
|
|
19
|
+
}
|
|
20
|
+
dispatch(event) {
|
|
21
|
+
return this.engine.dispatch(event, this.context);
|
|
22
|
+
}
|
|
23
|
+
subscribe(subscriber) {
|
|
24
|
+
return this.engine.subscribe(subscriber);
|
|
25
|
+
}
|
|
26
|
+
subscribeTo(type, subscriber) {
|
|
27
|
+
return this.engine.subscribeTo(type, subscriber);
|
|
28
|
+
}
|
|
29
|
+
subscribeWith(type, subscriber) {
|
|
30
|
+
return this.engine.subscribeWith(type, subscriber);
|
|
31
|
+
}
|
|
32
|
+
attach(container) {
|
|
33
|
+
console.error('attach must implement.');
|
|
34
|
+
}
|
|
35
|
+
detach(container) {
|
|
36
|
+
console.error('attach must implement.');
|
|
37
|
+
}
|
|
38
|
+
eventTarget(type) {
|
|
39
|
+
var _a;
|
|
40
|
+
if (type === 'resize' || type === 'scroll') {
|
|
41
|
+
if (this.container === ((_a = this.contentWindow) === null || _a === void 0 ? void 0 : _a.document)) {
|
|
42
|
+
return this.contentWindow;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return this.container;
|
|
46
|
+
}
|
|
47
|
+
addEventListener(type, listener, options) {
|
|
48
|
+
var _a, _b, _c, _d;
|
|
49
|
+
const target = this.eventTarget(type);
|
|
50
|
+
if (isOnlyMode(options === null || options === void 0 ? void 0 : options.mode)) {
|
|
51
|
+
target[EVENTS_ONCE_SYMBOL] = target[EVENTS_ONCE_SYMBOL] || {};
|
|
52
|
+
const constructor = this['constructor'];
|
|
53
|
+
constructor[EVENTS_ONCE_SYMBOL] = constructor[EVENTS_ONCE_SYMBOL] || {};
|
|
54
|
+
const handler = target[EVENTS_ONCE_SYMBOL][type];
|
|
55
|
+
const container = constructor[EVENTS_ONCE_SYMBOL][type];
|
|
56
|
+
if (!handler) {
|
|
57
|
+
if (container) {
|
|
58
|
+
if (options.mode === 'onlyChild') {
|
|
59
|
+
if (container.contains(target)) {
|
|
60
|
+
container.removeEventListener(type, container[EVENTS_ONCE_SYMBOL][type], options);
|
|
61
|
+
delete container[EVENTS_ONCE_SYMBOL][type];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (options.mode === 'onlyParent') {
|
|
65
|
+
if (container.contains(target))
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
target.addEventListener(type, listener, options);
|
|
70
|
+
target[EVENTS_ONCE_SYMBOL][type] = listener;
|
|
71
|
+
constructor[EVENTS_ONCE_SYMBOL][type] = target;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
target[EVENTS_SYMBOL] = target[EVENTS_SYMBOL] || {};
|
|
76
|
+
target[EVENTS_SYMBOL][type] = target[EVENTS_SYMBOL][type] || new Map();
|
|
77
|
+
if (!((_b = (_a = target[EVENTS_SYMBOL][type]) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a, listener))) {
|
|
78
|
+
target.addEventListener(type, listener, options);
|
|
79
|
+
(_d = (_c = target[EVENTS_SYMBOL][type]) === null || _c === void 0 ? void 0 : _c.set) === null || _d === void 0 ? void 0 : _d.call(_c, listener, true);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
removeEventListener(type, listener, options) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
const target = this.eventTarget(type);
|
|
86
|
+
if (isOnlyMode(options === null || options === void 0 ? void 0 : options.mode)) {
|
|
87
|
+
const constructor = this['constructor'];
|
|
88
|
+
constructor[EVENTS_ONCE_SYMBOL] = constructor[EVENTS_ONCE_SYMBOL] || {};
|
|
89
|
+
target[EVENTS_ONCE_SYMBOL] = target[EVENTS_ONCE_SYMBOL] || {};
|
|
90
|
+
delete constructor[EVENTS_ONCE_SYMBOL][type];
|
|
91
|
+
delete target[EVENTS_ONCE_SYMBOL][type];
|
|
92
|
+
target.removeEventListener(type, listener, options);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
target[EVENTS_SYMBOL] = target[EVENTS_SYMBOL] || {};
|
|
96
|
+
target[EVENTS_SYMBOL][type] = target[EVENTS_SYMBOL][type] || new Map();
|
|
97
|
+
(_b = (_a = target[EVENTS_SYMBOL][type]) === null || _a === void 0 ? void 0 : _a.delete) === null || _b === void 0 ? void 0 : _b.call(_a, listener);
|
|
98
|
+
target.removeEventListener(type, listener, options);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
batchAddEventListener(type, listener, options) {
|
|
102
|
+
this.engine[DRIVER_INSTANCES_SYMBOL] =
|
|
103
|
+
this.engine[DRIVER_INSTANCES_SYMBOL] || [];
|
|
104
|
+
if (!this.engine[DRIVER_INSTANCES_SYMBOL].includes(this)) {
|
|
105
|
+
this.engine[DRIVER_INSTANCES_SYMBOL].push(this);
|
|
106
|
+
}
|
|
107
|
+
this.engine[DRIVER_INSTANCES_SYMBOL].forEach((driver) => {
|
|
108
|
+
const target = driver.eventTarget(type);
|
|
109
|
+
target[EVENTS_BATCH_SYMBOL] = target[EVENTS_BATCH_SYMBOL] || {};
|
|
110
|
+
if (!target[EVENTS_BATCH_SYMBOL][type]) {
|
|
111
|
+
target.addEventListener(type, listener, options);
|
|
112
|
+
target[EVENTS_BATCH_SYMBOL][type] = listener;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
batchRemoveEventListener(type, listener, options) {
|
|
117
|
+
this.engine[DRIVER_INSTANCES_SYMBOL] =
|
|
118
|
+
this.engine[DRIVER_INSTANCES_SYMBOL] || [];
|
|
119
|
+
this.engine[DRIVER_INSTANCES_SYMBOL].forEach((driver) => {
|
|
120
|
+
const target = driver.eventTarget(type);
|
|
121
|
+
target[EVENTS_BATCH_SYMBOL] = target[EVENTS_BATCH_SYMBOL] || {};
|
|
122
|
+
target.removeEventListener(type, listener, options);
|
|
123
|
+
delete target[EVENTS_BATCH_SYMBOL][type];
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 事件引擎
|
|
129
|
+
*/
|
|
130
|
+
export class Event extends Subscribable {
|
|
131
|
+
constructor(props) {
|
|
132
|
+
super();
|
|
133
|
+
this.drivers = [];
|
|
134
|
+
this.containers = [];
|
|
135
|
+
if (isArr(props === null || props === void 0 ? void 0 : props.effects)) {
|
|
136
|
+
props.effects.forEach((plugin) => {
|
|
137
|
+
plugin(this);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (isArr(props === null || props === void 0 ? void 0 : props.drivers)) {
|
|
141
|
+
this.drivers = props.drivers;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
subscribeTo(type, subscriber) {
|
|
145
|
+
return this.subscribe((event) => {
|
|
146
|
+
if (type && event instanceof type) {
|
|
147
|
+
return subscriber(event);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
subscribeWith(type, subscriber) {
|
|
152
|
+
return this.subscribe((event) => {
|
|
153
|
+
if (isArr(type)) {
|
|
154
|
+
if (type.includes(event === null || event === void 0 ? void 0 : event.type)) {
|
|
155
|
+
return subscriber(event);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (type && (event === null || event === void 0 ? void 0 : event.type) === type) {
|
|
160
|
+
return subscriber(event);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
attachEvents(container, contentWindow = globalThisPolyfill, context) {
|
|
166
|
+
if (!container)
|
|
167
|
+
return;
|
|
168
|
+
if (isWindow(container)) {
|
|
169
|
+
return this.attachEvents(container.document, container, context);
|
|
170
|
+
}
|
|
171
|
+
if (container[ATTACHED_SYMBOL])
|
|
172
|
+
return;
|
|
173
|
+
container[ATTACHED_SYMBOL] = this.drivers.map((EventDriver) => {
|
|
174
|
+
const driver = new EventDriver(this, context);
|
|
175
|
+
driver.contentWindow = contentWindow;
|
|
176
|
+
driver.container = container;
|
|
177
|
+
driver.attach(container);
|
|
178
|
+
return driver;
|
|
179
|
+
});
|
|
180
|
+
if (!this.containers.includes(container)) {
|
|
181
|
+
this.containers.push(container);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
detachEvents(container) {
|
|
185
|
+
if (!container) {
|
|
186
|
+
this.containers.forEach((container) => {
|
|
187
|
+
this.detachEvents(container);
|
|
188
|
+
});
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (isWindow(container)) {
|
|
192
|
+
return this.detachEvents(container.document);
|
|
193
|
+
}
|
|
194
|
+
if (!container[ATTACHED_SYMBOL])
|
|
195
|
+
return;
|
|
196
|
+
container[ATTACHED_SYMBOL].forEach((driver) => {
|
|
197
|
+
driver.detach(container);
|
|
198
|
+
});
|
|
199
|
+
this[DRIVER_INSTANCES_SYMBOL] = this[DRIVER_INSTANCES_SYMBOL] || [];
|
|
200
|
+
this[DRIVER_INSTANCES_SYMBOL] = this[DRIVER_INSTANCES_SYMBOL].reduce((drivers, driver) => {
|
|
201
|
+
if (driver.container === container) {
|
|
202
|
+
driver.detach(container);
|
|
203
|
+
return drivers;
|
|
204
|
+
}
|
|
205
|
+
return drivers.concat(driver);
|
|
206
|
+
}, []);
|
|
207
|
+
this.containers = this.containers.filter((item) => item !== container);
|
|
208
|
+
delete container[ATTACHED_SYMBOL];
|
|
209
|
+
delete container[EVENTS_SYMBOL];
|
|
210
|
+
delete container[EVENTS_ONCE_SYMBOL];
|
|
211
|
+
delete container[EVENTS_BATCH_SYMBOL];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const globalThisPolyfill: Window;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function getGlobalThis() {
|
|
2
|
+
try {
|
|
3
|
+
if (typeof self !== 'undefined') {
|
|
4
|
+
return self;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
catch (e) { }
|
|
8
|
+
try {
|
|
9
|
+
if (typeof globalThisPolyfill !== 'undefined') {
|
|
10
|
+
return globalThisPolyfill;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
catch (e) { }
|
|
14
|
+
try {
|
|
15
|
+
if (typeof global !== 'undefined') {
|
|
16
|
+
return global;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (e) { }
|
|
20
|
+
return Function('return this')();
|
|
21
|
+
}
|
|
22
|
+
export const globalThisPolyfill = getGlobalThis();
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './event';
|
|
2
|
+
export * from './scroller';
|
|
3
|
+
export * from './subscribable';
|
|
4
|
+
export * from './coordinate';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export * from './uid';
|
|
7
|
+
export * from './clone';
|
|
8
|
+
export * from './instanceof';
|
|
9
|
+
export * from './lru';
|
|
10
|
+
export * from './compose';
|
|
11
|
+
export * from './array';
|
|
12
|
+
export * from './keycode';
|
|
13
|
+
export * from './animation';
|
|
14
|
+
export * from './request-idle';
|
|
15
|
+
export * from './element';
|
|
16
|
+
export * from './globalThisPolyfill';
|
|
17
|
+
export * from './observer';
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './event';
|
|
2
|
+
export * from './scroller';
|
|
3
|
+
export * from './subscribable';
|
|
4
|
+
export * from './coordinate';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export * from './uid';
|
|
7
|
+
export * from './clone';
|
|
8
|
+
export * from './instanceof';
|
|
9
|
+
export * from './lru';
|
|
10
|
+
export * from './compose';
|
|
11
|
+
export * from './array';
|
|
12
|
+
export * from './keycode';
|
|
13
|
+
export * from './animation';
|
|
14
|
+
export * from './request-idle';
|
|
15
|
+
export * from './element';
|
|
16
|
+
export * from './globalThisPolyfill';
|
|
17
|
+
export * from './observer';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const instOf: (value: any, cls: any) => boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isStr, isFn } from './types';
|
|
2
|
+
import { globalThisPolyfill } from './globalThisPolyfill';
|
|
3
|
+
export const instOf = (value, cls) => {
|
|
4
|
+
if (isFn(cls))
|
|
5
|
+
return value instanceof cls;
|
|
6
|
+
if (isStr(cls))
|
|
7
|
+
return globalThisPolyfill[cls]
|
|
8
|
+
? value instanceof globalThisPolyfill[cls]
|
|
9
|
+
: false;
|
|
10
|
+
return false;
|
|
11
|
+
};
|
package/esm/keycode.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export declare enum KeyCode {
|
|
2
|
+
Backspace = "Backspace",
|
|
3
|
+
Tab = "Tab",
|
|
4
|
+
Enter = "Enter",
|
|
5
|
+
Shift = "Shift",
|
|
6
|
+
Control = "Control",
|
|
7
|
+
Alt = "Alt",
|
|
8
|
+
CapsLock = "CapsLock",
|
|
9
|
+
Escape = "Escape",
|
|
10
|
+
Space = " ",
|
|
11
|
+
PageUp = "PageUp",
|
|
12
|
+
PageDown = "PageDown",
|
|
13
|
+
End = "End",
|
|
14
|
+
Home = "Home",
|
|
15
|
+
ArrowLeft = "ArrowLeft",
|
|
16
|
+
ArrowUp = "ArrowUp",
|
|
17
|
+
ArrowRight = "ArrowRight",
|
|
18
|
+
ArrowDown = "ArrowDown",
|
|
19
|
+
Left = "Left",
|
|
20
|
+
Up = "Up",
|
|
21
|
+
Right = "Right",
|
|
22
|
+
Down = "Down",
|
|
23
|
+
Insert = "Insert",
|
|
24
|
+
Delete = "Delete",
|
|
25
|
+
Zero = "0",
|
|
26
|
+
ClosedParen = ")",
|
|
27
|
+
One = "1",
|
|
28
|
+
ExclamationMark = "!",
|
|
29
|
+
Two = "2",
|
|
30
|
+
AtSign = "@",
|
|
31
|
+
Three = "3",
|
|
32
|
+
PoundSign = "\u00A3",
|
|
33
|
+
Hash = "#",
|
|
34
|
+
Four = "4",
|
|
35
|
+
DollarSign = "$",
|
|
36
|
+
Five = "5",
|
|
37
|
+
PercentSign = "%",
|
|
38
|
+
Six = "6",
|
|
39
|
+
Caret = "^",
|
|
40
|
+
Hat = "^",
|
|
41
|
+
Seven = "7",
|
|
42
|
+
Ampersand = "&",
|
|
43
|
+
Eight = "8",
|
|
44
|
+
Star = "*",
|
|
45
|
+
Asterisk = "*",
|
|
46
|
+
Nine = "9",
|
|
47
|
+
OpenParen = "(",
|
|
48
|
+
a = "a",
|
|
49
|
+
b = "b",
|
|
50
|
+
c = "c",
|
|
51
|
+
d = "d",
|
|
52
|
+
e = "e",
|
|
53
|
+
f = "f",
|
|
54
|
+
g = "g",
|
|
55
|
+
h = "h",
|
|
56
|
+
i = "i",
|
|
57
|
+
j = "j",
|
|
58
|
+
k = "k",
|
|
59
|
+
l = "l",
|
|
60
|
+
m = "m",
|
|
61
|
+
n = "n",
|
|
62
|
+
o = "o",
|
|
63
|
+
p = "p",
|
|
64
|
+
q = "q",
|
|
65
|
+
r = "r",
|
|
66
|
+
s = "s",
|
|
67
|
+
t = "t",
|
|
68
|
+
u = "u",
|
|
69
|
+
v = "v",
|
|
70
|
+
w = "w",
|
|
71
|
+
x = "x",
|
|
72
|
+
y = "y",
|
|
73
|
+
z = "z",
|
|
74
|
+
A = "A",
|
|
75
|
+
B = "B",
|
|
76
|
+
C = "C",
|
|
77
|
+
D = "D",
|
|
78
|
+
E = "E",
|
|
79
|
+
F = "F",
|
|
80
|
+
G = "G",
|
|
81
|
+
H = "H",
|
|
82
|
+
I = "I",
|
|
83
|
+
J = "J",
|
|
84
|
+
K = "K",
|
|
85
|
+
L = "L",
|
|
86
|
+
M = "M",
|
|
87
|
+
N = "N",
|
|
88
|
+
O = "O",
|
|
89
|
+
P = "P",
|
|
90
|
+
Q = "Q",
|
|
91
|
+
R = "R",
|
|
92
|
+
S = "S",
|
|
93
|
+
T = "T",
|
|
94
|
+
U = "U",
|
|
95
|
+
V = "V",
|
|
96
|
+
W = "W",
|
|
97
|
+
X = "X",
|
|
98
|
+
Y = "Y",
|
|
99
|
+
Z = "Z",
|
|
100
|
+
Meta = "Meta",
|
|
101
|
+
LeftWindowKey = "Meta",
|
|
102
|
+
RightWindowKey = "Meta",
|
|
103
|
+
Numpad0 = "0",
|
|
104
|
+
Numpad1 = "1",
|
|
105
|
+
Numpad2 = "2",
|
|
106
|
+
Numpad3 = "3",
|
|
107
|
+
Numpad4 = "4",
|
|
108
|
+
Numpad5 = "5",
|
|
109
|
+
Numpad6 = "6",
|
|
110
|
+
Numpad7 = "7",
|
|
111
|
+
Numpad8 = "8",
|
|
112
|
+
Numpad9 = "9",
|
|
113
|
+
Multiply = "*",
|
|
114
|
+
Add = "+",
|
|
115
|
+
Subtract = "-",
|
|
116
|
+
DecimalPoint = ".",
|
|
117
|
+
MSDecimalPoint = "Decimal",
|
|
118
|
+
Divide = "/",
|
|
119
|
+
F1 = "F1",
|
|
120
|
+
F2 = "F2",
|
|
121
|
+
F3 = "F3",
|
|
122
|
+
F4 = "F4",
|
|
123
|
+
F5 = "F5",
|
|
124
|
+
F6 = "F6",
|
|
125
|
+
F7 = "F7",
|
|
126
|
+
F8 = "F8",
|
|
127
|
+
F9 = "F9",
|
|
128
|
+
F10 = "F10",
|
|
129
|
+
F11 = "F11",
|
|
130
|
+
F12 = "F12",
|
|
131
|
+
NumLock = "NumLock",
|
|
132
|
+
ScrollLock = "ScrollLock",
|
|
133
|
+
SemiColon = ";",
|
|
134
|
+
Equals = "=",
|
|
135
|
+
Comma = ",",
|
|
136
|
+
Dash = "-",
|
|
137
|
+
Period = ".",
|
|
138
|
+
UnderScore = "_",
|
|
139
|
+
PlusSign = "+",
|
|
140
|
+
ForwardSlash = "/",
|
|
141
|
+
Tilde = "~",
|
|
142
|
+
GraveAccent = "`",
|
|
143
|
+
OpenBracket = "[",
|
|
144
|
+
ClosedBracket = "]",
|
|
145
|
+
Quote = "'"
|
|
146
|
+
}
|
|
147
|
+
export declare const getKeyCodeFromEvent: (event: KeyboardEvent) => KeyCode;
|
package/esm/keycode.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
export var KeyCode;
|
|
2
|
+
(function (KeyCode) {
|
|
3
|
+
KeyCode["Backspace"] = "Backspace";
|
|
4
|
+
KeyCode["Tab"] = "Tab";
|
|
5
|
+
KeyCode["Enter"] = "Enter";
|
|
6
|
+
KeyCode["Shift"] = "Shift";
|
|
7
|
+
KeyCode["Control"] = "Control";
|
|
8
|
+
KeyCode["Alt"] = "Alt";
|
|
9
|
+
KeyCode["CapsLock"] = "CapsLock";
|
|
10
|
+
KeyCode["Escape"] = "Escape";
|
|
11
|
+
KeyCode["Space"] = " ";
|
|
12
|
+
KeyCode["PageUp"] = "PageUp";
|
|
13
|
+
KeyCode["PageDown"] = "PageDown";
|
|
14
|
+
KeyCode["End"] = "End";
|
|
15
|
+
KeyCode["Home"] = "Home";
|
|
16
|
+
KeyCode["ArrowLeft"] = "ArrowLeft";
|
|
17
|
+
KeyCode["ArrowUp"] = "ArrowUp";
|
|
18
|
+
KeyCode["ArrowRight"] = "ArrowRight";
|
|
19
|
+
KeyCode["ArrowDown"] = "ArrowDown";
|
|
20
|
+
KeyCode["Left"] = "Left";
|
|
21
|
+
KeyCode["Up"] = "Up";
|
|
22
|
+
KeyCode["Right"] = "Right";
|
|
23
|
+
KeyCode["Down"] = "Down";
|
|
24
|
+
KeyCode["Insert"] = "Insert";
|
|
25
|
+
KeyCode["Delete"] = "Delete";
|
|
26
|
+
KeyCode["Zero"] = "0";
|
|
27
|
+
KeyCode["ClosedParen"] = ")";
|
|
28
|
+
KeyCode["One"] = "1";
|
|
29
|
+
KeyCode["ExclamationMark"] = "!";
|
|
30
|
+
KeyCode["Two"] = "2";
|
|
31
|
+
KeyCode["AtSign"] = "@";
|
|
32
|
+
KeyCode["Three"] = "3";
|
|
33
|
+
KeyCode["PoundSign"] = "\u00A3";
|
|
34
|
+
KeyCode["Hash"] = "#";
|
|
35
|
+
KeyCode["Four"] = "4";
|
|
36
|
+
KeyCode["DollarSign"] = "$";
|
|
37
|
+
KeyCode["Five"] = "5";
|
|
38
|
+
KeyCode["PercentSign"] = "%";
|
|
39
|
+
KeyCode["Six"] = "6";
|
|
40
|
+
KeyCode["Caret"] = "^";
|
|
41
|
+
KeyCode["Hat"] = "^";
|
|
42
|
+
KeyCode["Seven"] = "7";
|
|
43
|
+
KeyCode["Ampersand"] = "&";
|
|
44
|
+
KeyCode["Eight"] = "8";
|
|
45
|
+
KeyCode["Star"] = "*";
|
|
46
|
+
KeyCode["Asterisk"] = "*";
|
|
47
|
+
KeyCode["Nine"] = "9";
|
|
48
|
+
KeyCode["OpenParen"] = "(";
|
|
49
|
+
KeyCode["a"] = "a";
|
|
50
|
+
KeyCode["b"] = "b";
|
|
51
|
+
KeyCode["c"] = "c";
|
|
52
|
+
KeyCode["d"] = "d";
|
|
53
|
+
KeyCode["e"] = "e";
|
|
54
|
+
KeyCode["f"] = "f";
|
|
55
|
+
KeyCode["g"] = "g";
|
|
56
|
+
KeyCode["h"] = "h";
|
|
57
|
+
KeyCode["i"] = "i";
|
|
58
|
+
KeyCode["j"] = "j";
|
|
59
|
+
KeyCode["k"] = "k";
|
|
60
|
+
KeyCode["l"] = "l";
|
|
61
|
+
KeyCode["m"] = "m";
|
|
62
|
+
KeyCode["n"] = "n";
|
|
63
|
+
KeyCode["o"] = "o";
|
|
64
|
+
KeyCode["p"] = "p";
|
|
65
|
+
KeyCode["q"] = "q";
|
|
66
|
+
KeyCode["r"] = "r";
|
|
67
|
+
KeyCode["s"] = "s";
|
|
68
|
+
KeyCode["t"] = "t";
|
|
69
|
+
KeyCode["u"] = "u";
|
|
70
|
+
KeyCode["v"] = "v";
|
|
71
|
+
KeyCode["w"] = "w";
|
|
72
|
+
KeyCode["x"] = "x";
|
|
73
|
+
KeyCode["y"] = "y";
|
|
74
|
+
KeyCode["z"] = "z";
|
|
75
|
+
KeyCode["A"] = "A";
|
|
76
|
+
KeyCode["B"] = "B";
|
|
77
|
+
KeyCode["C"] = "C";
|
|
78
|
+
KeyCode["D"] = "D";
|
|
79
|
+
KeyCode["E"] = "E";
|
|
80
|
+
KeyCode["F"] = "F";
|
|
81
|
+
KeyCode["G"] = "G";
|
|
82
|
+
KeyCode["H"] = "H";
|
|
83
|
+
KeyCode["I"] = "I";
|
|
84
|
+
KeyCode["J"] = "J";
|
|
85
|
+
KeyCode["K"] = "K";
|
|
86
|
+
KeyCode["L"] = "L";
|
|
87
|
+
KeyCode["M"] = "M";
|
|
88
|
+
KeyCode["N"] = "N";
|
|
89
|
+
KeyCode["O"] = "O";
|
|
90
|
+
KeyCode["P"] = "P";
|
|
91
|
+
KeyCode["Q"] = "Q";
|
|
92
|
+
KeyCode["R"] = "R";
|
|
93
|
+
KeyCode["S"] = "S";
|
|
94
|
+
KeyCode["T"] = "T";
|
|
95
|
+
KeyCode["U"] = "U";
|
|
96
|
+
KeyCode["V"] = "V";
|
|
97
|
+
KeyCode["W"] = "W";
|
|
98
|
+
KeyCode["X"] = "X";
|
|
99
|
+
KeyCode["Y"] = "Y";
|
|
100
|
+
KeyCode["Z"] = "Z";
|
|
101
|
+
KeyCode["Meta"] = "Meta";
|
|
102
|
+
KeyCode["LeftWindowKey"] = "Meta";
|
|
103
|
+
KeyCode["RightWindowKey"] = "Meta";
|
|
104
|
+
KeyCode["Numpad0"] = "0";
|
|
105
|
+
KeyCode["Numpad1"] = "1";
|
|
106
|
+
KeyCode["Numpad2"] = "2";
|
|
107
|
+
KeyCode["Numpad3"] = "3";
|
|
108
|
+
KeyCode["Numpad4"] = "4";
|
|
109
|
+
KeyCode["Numpad5"] = "5";
|
|
110
|
+
KeyCode["Numpad6"] = "6";
|
|
111
|
+
KeyCode["Numpad7"] = "7";
|
|
112
|
+
KeyCode["Numpad8"] = "8";
|
|
113
|
+
KeyCode["Numpad9"] = "9";
|
|
114
|
+
KeyCode["Multiply"] = "*";
|
|
115
|
+
KeyCode["Add"] = "+";
|
|
116
|
+
KeyCode["Subtract"] = "-";
|
|
117
|
+
KeyCode["DecimalPoint"] = ".";
|
|
118
|
+
KeyCode["MSDecimalPoint"] = "Decimal";
|
|
119
|
+
KeyCode["Divide"] = "/";
|
|
120
|
+
KeyCode["F1"] = "F1";
|
|
121
|
+
KeyCode["F2"] = "F2";
|
|
122
|
+
KeyCode["F3"] = "F3";
|
|
123
|
+
KeyCode["F4"] = "F4";
|
|
124
|
+
KeyCode["F5"] = "F5";
|
|
125
|
+
KeyCode["F6"] = "F6";
|
|
126
|
+
KeyCode["F7"] = "F7";
|
|
127
|
+
KeyCode["F8"] = "F8";
|
|
128
|
+
KeyCode["F9"] = "F9";
|
|
129
|
+
KeyCode["F10"] = "F10";
|
|
130
|
+
KeyCode["F11"] = "F11";
|
|
131
|
+
KeyCode["F12"] = "F12";
|
|
132
|
+
KeyCode["NumLock"] = "NumLock";
|
|
133
|
+
KeyCode["ScrollLock"] = "ScrollLock";
|
|
134
|
+
KeyCode["SemiColon"] = ";";
|
|
135
|
+
KeyCode["Equals"] = "=";
|
|
136
|
+
KeyCode["Comma"] = ",";
|
|
137
|
+
KeyCode["Dash"] = "-";
|
|
138
|
+
KeyCode["Period"] = ".";
|
|
139
|
+
KeyCode["UnderScore"] = "_";
|
|
140
|
+
KeyCode["PlusSign"] = "+";
|
|
141
|
+
KeyCode["ForwardSlash"] = "/";
|
|
142
|
+
KeyCode["Tilde"] = "~";
|
|
143
|
+
KeyCode["GraveAccent"] = "`";
|
|
144
|
+
KeyCode["OpenBracket"] = "[";
|
|
145
|
+
KeyCode["ClosedBracket"] = "]";
|
|
146
|
+
KeyCode["Quote"] = "'";
|
|
147
|
+
})(KeyCode || (KeyCode = {}));
|
|
148
|
+
export const getKeyCodeFromEvent = (event) => {
|
|
149
|
+
return event.key;
|
|
150
|
+
};
|