@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/lib/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/lib/event.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Event = exports.EventDriver = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const subscribable_1 = require("./subscribable");
|
|
6
|
+
const globalThisPolyfill_1 = require("./globalThisPolyfill");
|
|
7
|
+
const ATTACHED_SYMBOL = Symbol('ATTACHED_SYMBOL');
|
|
8
|
+
const EVENTS_SYMBOL = Symbol('__EVENTS_SYMBOL__');
|
|
9
|
+
const EVENTS_ONCE_SYMBOL = Symbol('EVENTS_ONCE_SYMBOL');
|
|
10
|
+
const EVENTS_BATCH_SYMBOL = Symbol('EVENTS_BATCH_SYMBOL');
|
|
11
|
+
const DRIVER_INSTANCES_SYMBOL = Symbol('DRIVER_INSTANCES_SYMBOL');
|
|
12
|
+
const isOnlyMode = (mode) => mode === 'onlyOne' || mode === 'onlyChild' || mode === 'onlyParent';
|
|
13
|
+
/**
|
|
14
|
+
* 事件驱动器基类
|
|
15
|
+
*/
|
|
16
|
+
class EventDriver {
|
|
17
|
+
constructor(engine, context) {
|
|
18
|
+
this.container = document;
|
|
19
|
+
this.contentWindow = globalThisPolyfill_1.globalThisPolyfill;
|
|
20
|
+
this.engine = engine;
|
|
21
|
+
this.context = context;
|
|
22
|
+
}
|
|
23
|
+
dispatch(event) {
|
|
24
|
+
return this.engine.dispatch(event, this.context);
|
|
25
|
+
}
|
|
26
|
+
subscribe(subscriber) {
|
|
27
|
+
return this.engine.subscribe(subscriber);
|
|
28
|
+
}
|
|
29
|
+
subscribeTo(type, subscriber) {
|
|
30
|
+
return this.engine.subscribeTo(type, subscriber);
|
|
31
|
+
}
|
|
32
|
+
subscribeWith(type, subscriber) {
|
|
33
|
+
return this.engine.subscribeWith(type, subscriber);
|
|
34
|
+
}
|
|
35
|
+
attach(container) {
|
|
36
|
+
console.error('attach must implement.');
|
|
37
|
+
}
|
|
38
|
+
detach(container) {
|
|
39
|
+
console.error('attach must implement.');
|
|
40
|
+
}
|
|
41
|
+
eventTarget(type) {
|
|
42
|
+
var _a;
|
|
43
|
+
if (type === 'resize' || type === 'scroll') {
|
|
44
|
+
if (this.container === ((_a = this.contentWindow) === null || _a === void 0 ? void 0 : _a.document)) {
|
|
45
|
+
return this.contentWindow;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return this.container;
|
|
49
|
+
}
|
|
50
|
+
addEventListener(type, listener, options) {
|
|
51
|
+
var _a, _b, _c, _d;
|
|
52
|
+
const target = this.eventTarget(type);
|
|
53
|
+
if (isOnlyMode(options === null || options === void 0 ? void 0 : options.mode)) {
|
|
54
|
+
target[EVENTS_ONCE_SYMBOL] = target[EVENTS_ONCE_SYMBOL] || {};
|
|
55
|
+
const constructor = this['constructor'];
|
|
56
|
+
constructor[EVENTS_ONCE_SYMBOL] = constructor[EVENTS_ONCE_SYMBOL] || {};
|
|
57
|
+
const handler = target[EVENTS_ONCE_SYMBOL][type];
|
|
58
|
+
const container = constructor[EVENTS_ONCE_SYMBOL][type];
|
|
59
|
+
if (!handler) {
|
|
60
|
+
if (container) {
|
|
61
|
+
if (options.mode === 'onlyChild') {
|
|
62
|
+
if (container.contains(target)) {
|
|
63
|
+
container.removeEventListener(type, container[EVENTS_ONCE_SYMBOL][type], options);
|
|
64
|
+
delete container[EVENTS_ONCE_SYMBOL][type];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (options.mode === 'onlyParent') {
|
|
68
|
+
if (container.contains(target))
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
target.addEventListener(type, listener, options);
|
|
73
|
+
target[EVENTS_ONCE_SYMBOL][type] = listener;
|
|
74
|
+
constructor[EVENTS_ONCE_SYMBOL][type] = target;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
target[EVENTS_SYMBOL] = target[EVENTS_SYMBOL] || {};
|
|
79
|
+
target[EVENTS_SYMBOL][type] = target[EVENTS_SYMBOL][type] || new Map();
|
|
80
|
+
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))) {
|
|
81
|
+
target.addEventListener(type, listener, options);
|
|
82
|
+
(_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);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
removeEventListener(type, listener, options) {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
const target = this.eventTarget(type);
|
|
89
|
+
if (isOnlyMode(options === null || options === void 0 ? void 0 : options.mode)) {
|
|
90
|
+
const constructor = this['constructor'];
|
|
91
|
+
constructor[EVENTS_ONCE_SYMBOL] = constructor[EVENTS_ONCE_SYMBOL] || {};
|
|
92
|
+
target[EVENTS_ONCE_SYMBOL] = target[EVENTS_ONCE_SYMBOL] || {};
|
|
93
|
+
delete constructor[EVENTS_ONCE_SYMBOL][type];
|
|
94
|
+
delete target[EVENTS_ONCE_SYMBOL][type];
|
|
95
|
+
target.removeEventListener(type, listener, options);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
target[EVENTS_SYMBOL] = target[EVENTS_SYMBOL] || {};
|
|
99
|
+
target[EVENTS_SYMBOL][type] = target[EVENTS_SYMBOL][type] || new Map();
|
|
100
|
+
(_b = (_a = target[EVENTS_SYMBOL][type]) === null || _a === void 0 ? void 0 : _a.delete) === null || _b === void 0 ? void 0 : _b.call(_a, listener);
|
|
101
|
+
target.removeEventListener(type, listener, options);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
batchAddEventListener(type, listener, options) {
|
|
105
|
+
this.engine[DRIVER_INSTANCES_SYMBOL] =
|
|
106
|
+
this.engine[DRIVER_INSTANCES_SYMBOL] || [];
|
|
107
|
+
if (!this.engine[DRIVER_INSTANCES_SYMBOL].includes(this)) {
|
|
108
|
+
this.engine[DRIVER_INSTANCES_SYMBOL].push(this);
|
|
109
|
+
}
|
|
110
|
+
this.engine[DRIVER_INSTANCES_SYMBOL].forEach((driver) => {
|
|
111
|
+
const target = driver.eventTarget(type);
|
|
112
|
+
target[EVENTS_BATCH_SYMBOL] = target[EVENTS_BATCH_SYMBOL] || {};
|
|
113
|
+
if (!target[EVENTS_BATCH_SYMBOL][type]) {
|
|
114
|
+
target.addEventListener(type, listener, options);
|
|
115
|
+
target[EVENTS_BATCH_SYMBOL][type] = listener;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
batchRemoveEventListener(type, listener, options) {
|
|
120
|
+
this.engine[DRIVER_INSTANCES_SYMBOL] =
|
|
121
|
+
this.engine[DRIVER_INSTANCES_SYMBOL] || [];
|
|
122
|
+
this.engine[DRIVER_INSTANCES_SYMBOL].forEach((driver) => {
|
|
123
|
+
const target = driver.eventTarget(type);
|
|
124
|
+
target[EVENTS_BATCH_SYMBOL] = target[EVENTS_BATCH_SYMBOL] || {};
|
|
125
|
+
target.removeEventListener(type, listener, options);
|
|
126
|
+
delete target[EVENTS_BATCH_SYMBOL][type];
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.EventDriver = EventDriver;
|
|
131
|
+
/**
|
|
132
|
+
* 事件引擎
|
|
133
|
+
*/
|
|
134
|
+
class Event extends subscribable_1.Subscribable {
|
|
135
|
+
constructor(props) {
|
|
136
|
+
super();
|
|
137
|
+
this.drivers = [];
|
|
138
|
+
this.containers = [];
|
|
139
|
+
if ((0, types_1.isArr)(props === null || props === void 0 ? void 0 : props.effects)) {
|
|
140
|
+
props.effects.forEach((plugin) => {
|
|
141
|
+
plugin(this);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if ((0, types_1.isArr)(props === null || props === void 0 ? void 0 : props.drivers)) {
|
|
145
|
+
this.drivers = props.drivers;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
subscribeTo(type, subscriber) {
|
|
149
|
+
return this.subscribe((event) => {
|
|
150
|
+
if (type && event instanceof type) {
|
|
151
|
+
return subscriber(event);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
subscribeWith(type, subscriber) {
|
|
156
|
+
return this.subscribe((event) => {
|
|
157
|
+
if ((0, types_1.isArr)(type)) {
|
|
158
|
+
if (type.includes(event === null || event === void 0 ? void 0 : event.type)) {
|
|
159
|
+
return subscriber(event);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
if (type && (event === null || event === void 0 ? void 0 : event.type) === type) {
|
|
164
|
+
return subscriber(event);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
attachEvents(container, contentWindow = globalThisPolyfill_1.globalThisPolyfill, context) {
|
|
170
|
+
if (!container)
|
|
171
|
+
return;
|
|
172
|
+
if ((0, types_1.isWindow)(container)) {
|
|
173
|
+
return this.attachEvents(container.document, container, context);
|
|
174
|
+
}
|
|
175
|
+
if (container[ATTACHED_SYMBOL])
|
|
176
|
+
return;
|
|
177
|
+
container[ATTACHED_SYMBOL] = this.drivers.map((EventDriver) => {
|
|
178
|
+
const driver = new EventDriver(this, context);
|
|
179
|
+
driver.contentWindow = contentWindow;
|
|
180
|
+
driver.container = container;
|
|
181
|
+
driver.attach(container);
|
|
182
|
+
return driver;
|
|
183
|
+
});
|
|
184
|
+
if (!this.containers.includes(container)) {
|
|
185
|
+
this.containers.push(container);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
detachEvents(container) {
|
|
189
|
+
if (!container) {
|
|
190
|
+
this.containers.forEach((container) => {
|
|
191
|
+
this.detachEvents(container);
|
|
192
|
+
});
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if ((0, types_1.isWindow)(container)) {
|
|
196
|
+
return this.detachEvents(container.document);
|
|
197
|
+
}
|
|
198
|
+
if (!container[ATTACHED_SYMBOL])
|
|
199
|
+
return;
|
|
200
|
+
container[ATTACHED_SYMBOL].forEach((driver) => {
|
|
201
|
+
driver.detach(container);
|
|
202
|
+
});
|
|
203
|
+
this[DRIVER_INSTANCES_SYMBOL] = this[DRIVER_INSTANCES_SYMBOL] || [];
|
|
204
|
+
this[DRIVER_INSTANCES_SYMBOL] = this[DRIVER_INSTANCES_SYMBOL].reduce((drivers, driver) => {
|
|
205
|
+
if (driver.container === container) {
|
|
206
|
+
driver.detach(container);
|
|
207
|
+
return drivers;
|
|
208
|
+
}
|
|
209
|
+
return drivers.concat(driver);
|
|
210
|
+
}, []);
|
|
211
|
+
this.containers = this.containers.filter((item) => item !== container);
|
|
212
|
+
delete container[ATTACHED_SYMBOL];
|
|
213
|
+
delete container[EVENTS_SYMBOL];
|
|
214
|
+
delete container[EVENTS_ONCE_SYMBOL];
|
|
215
|
+
delete container[EVENTS_BATCH_SYMBOL];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.Event = Event;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const globalThisPolyfill: Window;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalThisPolyfill = void 0;
|
|
4
|
+
function getGlobalThis() {
|
|
5
|
+
try {
|
|
6
|
+
if (typeof self !== 'undefined') {
|
|
7
|
+
return self;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
catch (e) { }
|
|
11
|
+
try {
|
|
12
|
+
if (typeof exports.globalThisPolyfill !== 'undefined') {
|
|
13
|
+
return exports.globalThisPolyfill;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch (e) { }
|
|
17
|
+
try {
|
|
18
|
+
if (typeof global !== 'undefined') {
|
|
19
|
+
return global;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (e) { }
|
|
23
|
+
return Function('return this')();
|
|
24
|
+
}
|
|
25
|
+
exports.globalThisPolyfill = getGlobalThis();
|
package/lib/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/lib/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./event"), exports);
|
|
18
|
+
__exportStar(require("./scroller"), exports);
|
|
19
|
+
__exportStar(require("./subscribable"), exports);
|
|
20
|
+
__exportStar(require("./coordinate"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
__exportStar(require("./uid"), exports);
|
|
23
|
+
__exportStar(require("./clone"), exports);
|
|
24
|
+
__exportStar(require("./instanceof"), exports);
|
|
25
|
+
__exportStar(require("./lru"), exports);
|
|
26
|
+
__exportStar(require("./compose"), exports);
|
|
27
|
+
__exportStar(require("./array"), exports);
|
|
28
|
+
__exportStar(require("./keycode"), exports);
|
|
29
|
+
__exportStar(require("./animation"), exports);
|
|
30
|
+
__exportStar(require("./request-idle"), exports);
|
|
31
|
+
__exportStar(require("./element"), exports);
|
|
32
|
+
__exportStar(require("./globalThisPolyfill"), exports);
|
|
33
|
+
__exportStar(require("./observer"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const instOf: (value: any, cls: any) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.instOf = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const globalThisPolyfill_1 = require("./globalThisPolyfill");
|
|
6
|
+
const instOf = (value, cls) => {
|
|
7
|
+
if ((0, types_1.isFn)(cls))
|
|
8
|
+
return value instanceof cls;
|
|
9
|
+
if ((0, types_1.isStr)(cls))
|
|
10
|
+
return globalThisPolyfill_1.globalThisPolyfill[cls]
|
|
11
|
+
? value instanceof globalThisPolyfill_1.globalThisPolyfill[cls]
|
|
12
|
+
: false;
|
|
13
|
+
return false;
|
|
14
|
+
};
|
|
15
|
+
exports.instOf = instOf;
|
package/lib/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;
|