@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/keycode.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getKeyCodeFromEvent = exports.KeyCode = void 0;
|
|
4
|
+
var KeyCode;
|
|
5
|
+
(function (KeyCode) {
|
|
6
|
+
KeyCode["Backspace"] = "Backspace";
|
|
7
|
+
KeyCode["Tab"] = "Tab";
|
|
8
|
+
KeyCode["Enter"] = "Enter";
|
|
9
|
+
KeyCode["Shift"] = "Shift";
|
|
10
|
+
KeyCode["Control"] = "Control";
|
|
11
|
+
KeyCode["Alt"] = "Alt";
|
|
12
|
+
KeyCode["CapsLock"] = "CapsLock";
|
|
13
|
+
KeyCode["Escape"] = "Escape";
|
|
14
|
+
KeyCode["Space"] = " ";
|
|
15
|
+
KeyCode["PageUp"] = "PageUp";
|
|
16
|
+
KeyCode["PageDown"] = "PageDown";
|
|
17
|
+
KeyCode["End"] = "End";
|
|
18
|
+
KeyCode["Home"] = "Home";
|
|
19
|
+
KeyCode["ArrowLeft"] = "ArrowLeft";
|
|
20
|
+
KeyCode["ArrowUp"] = "ArrowUp";
|
|
21
|
+
KeyCode["ArrowRight"] = "ArrowRight";
|
|
22
|
+
KeyCode["ArrowDown"] = "ArrowDown";
|
|
23
|
+
KeyCode["Left"] = "Left";
|
|
24
|
+
KeyCode["Up"] = "Up";
|
|
25
|
+
KeyCode["Right"] = "Right";
|
|
26
|
+
KeyCode["Down"] = "Down";
|
|
27
|
+
KeyCode["Insert"] = "Insert";
|
|
28
|
+
KeyCode["Delete"] = "Delete";
|
|
29
|
+
KeyCode["Zero"] = "0";
|
|
30
|
+
KeyCode["ClosedParen"] = ")";
|
|
31
|
+
KeyCode["One"] = "1";
|
|
32
|
+
KeyCode["ExclamationMark"] = "!";
|
|
33
|
+
KeyCode["Two"] = "2";
|
|
34
|
+
KeyCode["AtSign"] = "@";
|
|
35
|
+
KeyCode["Three"] = "3";
|
|
36
|
+
KeyCode["PoundSign"] = "\u00A3";
|
|
37
|
+
KeyCode["Hash"] = "#";
|
|
38
|
+
KeyCode["Four"] = "4";
|
|
39
|
+
KeyCode["DollarSign"] = "$";
|
|
40
|
+
KeyCode["Five"] = "5";
|
|
41
|
+
KeyCode["PercentSign"] = "%";
|
|
42
|
+
KeyCode["Six"] = "6";
|
|
43
|
+
KeyCode["Caret"] = "^";
|
|
44
|
+
KeyCode["Hat"] = "^";
|
|
45
|
+
KeyCode["Seven"] = "7";
|
|
46
|
+
KeyCode["Ampersand"] = "&";
|
|
47
|
+
KeyCode["Eight"] = "8";
|
|
48
|
+
KeyCode["Star"] = "*";
|
|
49
|
+
KeyCode["Asterisk"] = "*";
|
|
50
|
+
KeyCode["Nine"] = "9";
|
|
51
|
+
KeyCode["OpenParen"] = "(";
|
|
52
|
+
KeyCode["a"] = "a";
|
|
53
|
+
KeyCode["b"] = "b";
|
|
54
|
+
KeyCode["c"] = "c";
|
|
55
|
+
KeyCode["d"] = "d";
|
|
56
|
+
KeyCode["e"] = "e";
|
|
57
|
+
KeyCode["f"] = "f";
|
|
58
|
+
KeyCode["g"] = "g";
|
|
59
|
+
KeyCode["h"] = "h";
|
|
60
|
+
KeyCode["i"] = "i";
|
|
61
|
+
KeyCode["j"] = "j";
|
|
62
|
+
KeyCode["k"] = "k";
|
|
63
|
+
KeyCode["l"] = "l";
|
|
64
|
+
KeyCode["m"] = "m";
|
|
65
|
+
KeyCode["n"] = "n";
|
|
66
|
+
KeyCode["o"] = "o";
|
|
67
|
+
KeyCode["p"] = "p";
|
|
68
|
+
KeyCode["q"] = "q";
|
|
69
|
+
KeyCode["r"] = "r";
|
|
70
|
+
KeyCode["s"] = "s";
|
|
71
|
+
KeyCode["t"] = "t";
|
|
72
|
+
KeyCode["u"] = "u";
|
|
73
|
+
KeyCode["v"] = "v";
|
|
74
|
+
KeyCode["w"] = "w";
|
|
75
|
+
KeyCode["x"] = "x";
|
|
76
|
+
KeyCode["y"] = "y";
|
|
77
|
+
KeyCode["z"] = "z";
|
|
78
|
+
KeyCode["A"] = "A";
|
|
79
|
+
KeyCode["B"] = "B";
|
|
80
|
+
KeyCode["C"] = "C";
|
|
81
|
+
KeyCode["D"] = "D";
|
|
82
|
+
KeyCode["E"] = "E";
|
|
83
|
+
KeyCode["F"] = "F";
|
|
84
|
+
KeyCode["G"] = "G";
|
|
85
|
+
KeyCode["H"] = "H";
|
|
86
|
+
KeyCode["I"] = "I";
|
|
87
|
+
KeyCode["J"] = "J";
|
|
88
|
+
KeyCode["K"] = "K";
|
|
89
|
+
KeyCode["L"] = "L";
|
|
90
|
+
KeyCode["M"] = "M";
|
|
91
|
+
KeyCode["N"] = "N";
|
|
92
|
+
KeyCode["O"] = "O";
|
|
93
|
+
KeyCode["P"] = "P";
|
|
94
|
+
KeyCode["Q"] = "Q";
|
|
95
|
+
KeyCode["R"] = "R";
|
|
96
|
+
KeyCode["S"] = "S";
|
|
97
|
+
KeyCode["T"] = "T";
|
|
98
|
+
KeyCode["U"] = "U";
|
|
99
|
+
KeyCode["V"] = "V";
|
|
100
|
+
KeyCode["W"] = "W";
|
|
101
|
+
KeyCode["X"] = "X";
|
|
102
|
+
KeyCode["Y"] = "Y";
|
|
103
|
+
KeyCode["Z"] = "Z";
|
|
104
|
+
KeyCode["Meta"] = "Meta";
|
|
105
|
+
KeyCode["LeftWindowKey"] = "Meta";
|
|
106
|
+
KeyCode["RightWindowKey"] = "Meta";
|
|
107
|
+
KeyCode["Numpad0"] = "0";
|
|
108
|
+
KeyCode["Numpad1"] = "1";
|
|
109
|
+
KeyCode["Numpad2"] = "2";
|
|
110
|
+
KeyCode["Numpad3"] = "3";
|
|
111
|
+
KeyCode["Numpad4"] = "4";
|
|
112
|
+
KeyCode["Numpad5"] = "5";
|
|
113
|
+
KeyCode["Numpad6"] = "6";
|
|
114
|
+
KeyCode["Numpad7"] = "7";
|
|
115
|
+
KeyCode["Numpad8"] = "8";
|
|
116
|
+
KeyCode["Numpad9"] = "9";
|
|
117
|
+
KeyCode["Multiply"] = "*";
|
|
118
|
+
KeyCode["Add"] = "+";
|
|
119
|
+
KeyCode["Subtract"] = "-";
|
|
120
|
+
KeyCode["DecimalPoint"] = ".";
|
|
121
|
+
KeyCode["MSDecimalPoint"] = "Decimal";
|
|
122
|
+
KeyCode["Divide"] = "/";
|
|
123
|
+
KeyCode["F1"] = "F1";
|
|
124
|
+
KeyCode["F2"] = "F2";
|
|
125
|
+
KeyCode["F3"] = "F3";
|
|
126
|
+
KeyCode["F4"] = "F4";
|
|
127
|
+
KeyCode["F5"] = "F5";
|
|
128
|
+
KeyCode["F6"] = "F6";
|
|
129
|
+
KeyCode["F7"] = "F7";
|
|
130
|
+
KeyCode["F8"] = "F8";
|
|
131
|
+
KeyCode["F9"] = "F9";
|
|
132
|
+
KeyCode["F10"] = "F10";
|
|
133
|
+
KeyCode["F11"] = "F11";
|
|
134
|
+
KeyCode["F12"] = "F12";
|
|
135
|
+
KeyCode["NumLock"] = "NumLock";
|
|
136
|
+
KeyCode["ScrollLock"] = "ScrollLock";
|
|
137
|
+
KeyCode["SemiColon"] = ";";
|
|
138
|
+
KeyCode["Equals"] = "=";
|
|
139
|
+
KeyCode["Comma"] = ",";
|
|
140
|
+
KeyCode["Dash"] = "-";
|
|
141
|
+
KeyCode["Period"] = ".";
|
|
142
|
+
KeyCode["UnderScore"] = "_";
|
|
143
|
+
KeyCode["PlusSign"] = "+";
|
|
144
|
+
KeyCode["ForwardSlash"] = "/";
|
|
145
|
+
KeyCode["Tilde"] = "~";
|
|
146
|
+
KeyCode["GraveAccent"] = "`";
|
|
147
|
+
KeyCode["OpenBracket"] = "[";
|
|
148
|
+
KeyCode["ClosedBracket"] = "]";
|
|
149
|
+
KeyCode["Quote"] = "'";
|
|
150
|
+
})(KeyCode || (exports.KeyCode = KeyCode = {}));
|
|
151
|
+
const getKeyCodeFromEvent = (event) => {
|
|
152
|
+
return event.key;
|
|
153
|
+
};
|
|
154
|
+
exports.getKeyCodeFromEvent = getKeyCodeFromEvent;
|
package/lib/lru.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A doubly linked list-based Least Recently Used (LRU) cache. Will keep most
|
|
3
|
+
* recently used items while discarding least recently used items when its limit
|
|
4
|
+
* is reached.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under MIT. Copyright (c) 2010 Rasmus Andersson <http://hunch.se/>
|
|
7
|
+
* See README.md for details.
|
|
8
|
+
*
|
|
9
|
+
* Illustration of the design:
|
|
10
|
+
*
|
|
11
|
+
* entry entry entry entry
|
|
12
|
+
* ______ ______ ______ ______
|
|
13
|
+
* | head |.newer => | |.newer => | |.newer => | tail |
|
|
14
|
+
* | A | | B | | C | | D |
|
|
15
|
+
* |______| <= older.|______| <= older.|______| <= older.|______|
|
|
16
|
+
*
|
|
17
|
+
* removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added
|
|
18
|
+
*/
|
|
19
|
+
export declare class LRUMap<K, V> {
|
|
20
|
+
size: number;
|
|
21
|
+
limit: number;
|
|
22
|
+
oldest: any;
|
|
23
|
+
newest: any;
|
|
24
|
+
_keymap: Map<K, {
|
|
25
|
+
key: K;
|
|
26
|
+
value: V;
|
|
27
|
+
}>;
|
|
28
|
+
constructor(limit: number, entries?: any);
|
|
29
|
+
private _markEntryAsUsed;
|
|
30
|
+
assign(entries: any): void;
|
|
31
|
+
get(key: K): V;
|
|
32
|
+
set(key: K, value: V): this;
|
|
33
|
+
shift(): any[];
|
|
34
|
+
find(key: K): V;
|
|
35
|
+
has(key: K): boolean;
|
|
36
|
+
delete(key: any): V;
|
|
37
|
+
clear(): void;
|
|
38
|
+
keys(): KeyIterator;
|
|
39
|
+
values(): ValueIterator;
|
|
40
|
+
entries(): void;
|
|
41
|
+
forEach(fun: (value: any, key: any, ctx: object) => void, thisObj: any): void;
|
|
42
|
+
toJSON(): any[];
|
|
43
|
+
toString(): string;
|
|
44
|
+
[Symbol.iterator](): EntryIterator;
|
|
45
|
+
}
|
|
46
|
+
declare class EntryIterator {
|
|
47
|
+
entry: any;
|
|
48
|
+
constructor(oldestEntry: any);
|
|
49
|
+
[Symbol.iterator](): this;
|
|
50
|
+
next(): {
|
|
51
|
+
done: boolean;
|
|
52
|
+
value: any[];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
declare class KeyIterator {
|
|
56
|
+
entry: any;
|
|
57
|
+
constructor(oldestEntry: any);
|
|
58
|
+
[Symbol.iterator](): this;
|
|
59
|
+
next(): {
|
|
60
|
+
done: boolean;
|
|
61
|
+
value: any;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
declare class ValueIterator {
|
|
65
|
+
entry: any;
|
|
66
|
+
constructor(oldestEntry: any);
|
|
67
|
+
[Symbol.iterator](): this;
|
|
68
|
+
next(): {
|
|
69
|
+
done: boolean;
|
|
70
|
+
value: any;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export {};
|
package/lib/lru.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* A doubly linked list-based Least Recently Used (LRU) cache. Will keep most
|
|
4
|
+
* recently used items while discarding least recently used items when its limit
|
|
5
|
+
* is reached.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under MIT. Copyright (c) 2010 Rasmus Andersson <http://hunch.se/>
|
|
8
|
+
* See README.md for details.
|
|
9
|
+
*
|
|
10
|
+
* Illustration of the design:
|
|
11
|
+
*
|
|
12
|
+
* entry entry entry entry
|
|
13
|
+
* ______ ______ ______ ______
|
|
14
|
+
* | head |.newer => | |.newer => | |.newer => | tail |
|
|
15
|
+
* | A | | B | | C | | D |
|
|
16
|
+
* |______| <= older.|______| <= older.|______| <= older.|______|
|
|
17
|
+
*
|
|
18
|
+
* removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added
|
|
19
|
+
*/
|
|
20
|
+
/* eslint-disable */
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.LRUMap = void 0;
|
|
23
|
+
const NEWER = Symbol('newer');
|
|
24
|
+
const OLDER = Symbol('older');
|
|
25
|
+
function Entry(key, value) {
|
|
26
|
+
this.key = key;
|
|
27
|
+
this.value = value;
|
|
28
|
+
this[NEWER] = undefined;
|
|
29
|
+
this[OLDER] = undefined;
|
|
30
|
+
}
|
|
31
|
+
class LRUMap {
|
|
32
|
+
constructor(limit, entries) {
|
|
33
|
+
if (typeof limit !== 'number') {
|
|
34
|
+
// called as (entries)
|
|
35
|
+
entries = limit;
|
|
36
|
+
limit = 0;
|
|
37
|
+
}
|
|
38
|
+
this.size = 0;
|
|
39
|
+
this.limit = limit;
|
|
40
|
+
this.oldest = this.newest = undefined;
|
|
41
|
+
this._keymap = new Map();
|
|
42
|
+
if (entries) {
|
|
43
|
+
this.assign(entries);
|
|
44
|
+
if (limit < 1) {
|
|
45
|
+
this.limit = this.size;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
_markEntryAsUsed(entry) {
|
|
50
|
+
if (entry === this.newest) {
|
|
51
|
+
// Already the most recenlty used entry, so no need to update the list
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// HEAD--------------TAIL
|
|
55
|
+
// <.older .newer>
|
|
56
|
+
// <--- add direction --
|
|
57
|
+
// A B C <D> E
|
|
58
|
+
if (entry[NEWER]) {
|
|
59
|
+
if (entry === this.oldest) {
|
|
60
|
+
this.oldest = entry[NEWER];
|
|
61
|
+
}
|
|
62
|
+
entry[NEWER][OLDER] = entry[OLDER]; // C <-- E.
|
|
63
|
+
}
|
|
64
|
+
if (entry[OLDER]) {
|
|
65
|
+
entry[OLDER][NEWER] = entry[NEWER]; // C. --> E
|
|
66
|
+
}
|
|
67
|
+
entry[NEWER] = undefined; // D --x
|
|
68
|
+
entry[OLDER] = this.newest; // D. --> E
|
|
69
|
+
if (this.newest) {
|
|
70
|
+
this.newest[NEWER] = entry; // E. <-- D
|
|
71
|
+
}
|
|
72
|
+
this.newest = entry;
|
|
73
|
+
}
|
|
74
|
+
assign(entries) {
|
|
75
|
+
let entry;
|
|
76
|
+
let limit = this.limit || Number.MAX_VALUE;
|
|
77
|
+
this._keymap.clear();
|
|
78
|
+
const it = entries[Symbol.iterator]();
|
|
79
|
+
for (let itv = it.next(); !itv.done; itv = it.next()) {
|
|
80
|
+
const e = new Entry(itv.value[0], itv.value[1]);
|
|
81
|
+
this._keymap.set(e.key, e);
|
|
82
|
+
if (!entry) {
|
|
83
|
+
this.oldest = e;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
entry[NEWER] = e;
|
|
87
|
+
e[OLDER] = entry;
|
|
88
|
+
}
|
|
89
|
+
entry = e;
|
|
90
|
+
if (limit-- === 0) {
|
|
91
|
+
throw new Error('overflow');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
this.newest = entry;
|
|
95
|
+
this.size = this._keymap.size;
|
|
96
|
+
}
|
|
97
|
+
get(key) {
|
|
98
|
+
// First, find our cache entry
|
|
99
|
+
const entry = this._keymap.get(key);
|
|
100
|
+
if (!entry) {
|
|
101
|
+
return;
|
|
102
|
+
} // Not cached. Sorry.
|
|
103
|
+
// As <key> was found in the cache, register it as being requested recently
|
|
104
|
+
this._markEntryAsUsed(entry);
|
|
105
|
+
return entry.value;
|
|
106
|
+
}
|
|
107
|
+
set(key, value) {
|
|
108
|
+
let entry = this._keymap.get(key);
|
|
109
|
+
if (entry) {
|
|
110
|
+
// update existing
|
|
111
|
+
entry.value = value;
|
|
112
|
+
this._markEntryAsUsed(entry);
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
// new entry
|
|
116
|
+
this._keymap.set(key, (entry = new Entry(key, value)));
|
|
117
|
+
if (this.newest) {
|
|
118
|
+
// link previous tail to the new tail (entry)
|
|
119
|
+
this.newest[NEWER] = entry;
|
|
120
|
+
entry[OLDER] = this.newest;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// we're first in -- yay
|
|
124
|
+
this.oldest = entry;
|
|
125
|
+
}
|
|
126
|
+
// add new entry to the end of the linked list -- it's now the freshest entry.
|
|
127
|
+
this.newest = entry;
|
|
128
|
+
++this.size;
|
|
129
|
+
if (this.size > this.limit) {
|
|
130
|
+
// we hit the limit -- remove the head
|
|
131
|
+
this.shift();
|
|
132
|
+
}
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
shift() {
|
|
136
|
+
// todo: handle special case when limit == 1
|
|
137
|
+
const entry = this.oldest;
|
|
138
|
+
if (entry) {
|
|
139
|
+
if (this.oldest[NEWER]) {
|
|
140
|
+
// advance the list
|
|
141
|
+
this.oldest = this.oldest[NEWER];
|
|
142
|
+
this.oldest[OLDER] = undefined;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
// the cache is exhausted
|
|
146
|
+
this.oldest = undefined;
|
|
147
|
+
this.newest = undefined;
|
|
148
|
+
}
|
|
149
|
+
// Remove last strong reference to <entry> and remove links from the purged
|
|
150
|
+
// entry being returned:
|
|
151
|
+
entry[NEWER] = entry[OLDER] = undefined;
|
|
152
|
+
this._keymap.delete(entry.key);
|
|
153
|
+
--this.size;
|
|
154
|
+
return [entry.key, entry.value];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
find(key) {
|
|
158
|
+
const e = this._keymap.get(key);
|
|
159
|
+
return e ? e.value : undefined;
|
|
160
|
+
}
|
|
161
|
+
has(key) {
|
|
162
|
+
return this._keymap.has(key);
|
|
163
|
+
}
|
|
164
|
+
delete(key) {
|
|
165
|
+
const entry = this._keymap.get(key);
|
|
166
|
+
if (!entry) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this._keymap.delete(entry.key);
|
|
170
|
+
if (entry[NEWER] && entry[OLDER]) {
|
|
171
|
+
// relink the older entry with the newer entry
|
|
172
|
+
entry[OLDER][NEWER] = entry[NEWER];
|
|
173
|
+
entry[NEWER][OLDER] = entry[OLDER];
|
|
174
|
+
}
|
|
175
|
+
else if (entry[NEWER]) {
|
|
176
|
+
// remove the link to us
|
|
177
|
+
entry[NEWER][OLDER] = undefined;
|
|
178
|
+
// link the newer entry to head
|
|
179
|
+
this.oldest = entry[NEWER];
|
|
180
|
+
}
|
|
181
|
+
else if (entry[OLDER]) {
|
|
182
|
+
// remove the link to us
|
|
183
|
+
entry[OLDER][NEWER] = undefined;
|
|
184
|
+
// link the newer entry to head
|
|
185
|
+
this.newest = entry[OLDER];
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
// if(entry[OLDER] === undefined && entry.newer === undefined) {
|
|
189
|
+
this.oldest = this.newest = undefined;
|
|
190
|
+
}
|
|
191
|
+
this.size--;
|
|
192
|
+
return entry.value;
|
|
193
|
+
}
|
|
194
|
+
clear() {
|
|
195
|
+
// Not clearing links should be safe, as we don't expose live links to user
|
|
196
|
+
this.oldest = this.newest = undefined;
|
|
197
|
+
this.size = 0;
|
|
198
|
+
this._keymap.clear();
|
|
199
|
+
}
|
|
200
|
+
keys() {
|
|
201
|
+
return new KeyIterator(this.oldest);
|
|
202
|
+
}
|
|
203
|
+
values() {
|
|
204
|
+
return new ValueIterator(this.oldest);
|
|
205
|
+
}
|
|
206
|
+
entries() { }
|
|
207
|
+
forEach(fun, thisObj) {
|
|
208
|
+
if (typeof thisObj !== 'object') {
|
|
209
|
+
thisObj = this;
|
|
210
|
+
}
|
|
211
|
+
let entry = this.oldest;
|
|
212
|
+
while (entry) {
|
|
213
|
+
fun.call(thisObj, entry.value, entry.key, this);
|
|
214
|
+
entry = entry[NEWER];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
toJSON() {
|
|
218
|
+
const s = new Array(this.size);
|
|
219
|
+
let i = 0;
|
|
220
|
+
let entry = this.oldest;
|
|
221
|
+
while (entry) {
|
|
222
|
+
s[i++] = { key: entry.key, value: entry.value };
|
|
223
|
+
entry = entry[NEWER];
|
|
224
|
+
}
|
|
225
|
+
return s;
|
|
226
|
+
}
|
|
227
|
+
toString() {
|
|
228
|
+
let s = '';
|
|
229
|
+
let entry = this.oldest;
|
|
230
|
+
while (entry) {
|
|
231
|
+
s += String(entry.key) + ':' + entry.value;
|
|
232
|
+
entry = entry[NEWER];
|
|
233
|
+
if (entry) {
|
|
234
|
+
s += ' < ';
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return s;
|
|
238
|
+
}
|
|
239
|
+
[Symbol.iterator]() {
|
|
240
|
+
return new EntryIterator(this.oldest);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.LRUMap = LRUMap;
|
|
244
|
+
class EntryIterator {
|
|
245
|
+
constructor(oldestEntry) {
|
|
246
|
+
this.entry = oldestEntry;
|
|
247
|
+
}
|
|
248
|
+
[Symbol.iterator]() {
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
next() {
|
|
252
|
+
const ent = this.entry;
|
|
253
|
+
if (ent) {
|
|
254
|
+
this.entry = ent[NEWER];
|
|
255
|
+
return { done: false, value: [ent.key, ent.value] };
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
return { done: true, value: undefined };
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
class KeyIterator {
|
|
263
|
+
constructor(oldestEntry) {
|
|
264
|
+
this.entry = oldestEntry;
|
|
265
|
+
}
|
|
266
|
+
[Symbol.iterator]() {
|
|
267
|
+
return this;
|
|
268
|
+
}
|
|
269
|
+
next() {
|
|
270
|
+
const ent = this.entry;
|
|
271
|
+
if (ent) {
|
|
272
|
+
this.entry = ent[NEWER];
|
|
273
|
+
return { done: false, value: ent.key };
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
return { done: true, value: undefined };
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
class ValueIterator {
|
|
281
|
+
constructor(oldestEntry) {
|
|
282
|
+
this.entry = oldestEntry;
|
|
283
|
+
}
|
|
284
|
+
[Symbol.iterator]() {
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
287
|
+
next() {
|
|
288
|
+
const ent = this.entry;
|
|
289
|
+
if (ent) {
|
|
290
|
+
this.entry = ent[NEWER];
|
|
291
|
+
return { done: false, value: ent.value };
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
return { done: true, value: undefined };
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
package/lib/observer.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LayoutObserver = void 0;
|
|
4
|
+
class LayoutObserver {
|
|
5
|
+
constructor(observer = () => { }) {
|
|
6
|
+
this.connected = false;
|
|
7
|
+
this.observe = (target) => {
|
|
8
|
+
this.resizeObserver.observe(target);
|
|
9
|
+
this.performanceObserver.observe({
|
|
10
|
+
entryTypes: ['paint', 'element', 'layout-shift', 'event'],
|
|
11
|
+
});
|
|
12
|
+
this.mutationObserver.observe(target, {
|
|
13
|
+
attributeFilter: ['style'],
|
|
14
|
+
attributes: true,
|
|
15
|
+
});
|
|
16
|
+
this.connected = true;
|
|
17
|
+
};
|
|
18
|
+
this.disconnect = () => {
|
|
19
|
+
if (this.connected) {
|
|
20
|
+
this.resizeObserver.disconnect();
|
|
21
|
+
this.performanceObserver.disconnect();
|
|
22
|
+
this.mutationObserver.disconnect();
|
|
23
|
+
}
|
|
24
|
+
this.connected = false;
|
|
25
|
+
};
|
|
26
|
+
this.resizeObserver = new ResizeObserver(() => observer());
|
|
27
|
+
this.performanceObserver = new PerformanceObserver(() => {
|
|
28
|
+
observer();
|
|
29
|
+
});
|
|
30
|
+
this.mutationObserver = new MutationObserver(() => observer());
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.LayoutObserver = LayoutObserver;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import 'requestidlecallback';
|
|
2
|
+
export interface IIdleDeadline {
|
|
3
|
+
didTimeout: boolean;
|
|
4
|
+
timeRemaining: () => DOMHighResTimeStamp;
|
|
5
|
+
}
|
|
6
|
+
export interface IdleCallbackOptions {
|
|
7
|
+
timeout?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const requestIdle: (callback: (params: IIdleDeadline) => void, options?: IdleCallbackOptions) => number;
|
|
10
|
+
export declare const cancelIdle: (id: number) => void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cancelIdle = exports.requestIdle = void 0;
|
|
4
|
+
require("requestidlecallback");
|
|
5
|
+
const globalThisPolyfill_1 = require("./globalThisPolyfill");
|
|
6
|
+
const requestIdle = (callback, options) => {
|
|
7
|
+
return globalThisPolyfill_1.globalThisPolyfill['requestIdleCallback'](callback, options);
|
|
8
|
+
};
|
|
9
|
+
exports.requestIdle = requestIdle;
|
|
10
|
+
const cancelIdle = (id) => {
|
|
11
|
+
globalThisPolyfill_1.globalThisPolyfill['cancelIdleCallback'](id);
|
|
12
|
+
};
|
|
13
|
+
exports.cancelIdle = cancelIdle;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IPoint } from './coordinate';
|
|
2
|
+
export type ScrollDirection = 'begin' | 'end';
|
|
3
|
+
export interface IAutoScrollBasicInfo {
|
|
4
|
+
direction: ScrollDirection;
|
|
5
|
+
speedFactor: number;
|
|
6
|
+
speed: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const calcAutoScrollBasicInfo: (point: IPoint, axis: "x" | "y", viewport: DOMRect, maxSpeed?: number) => IAutoScrollBasicInfo | null;
|
|
9
|
+
export declare const updateScrollValue: (element: HTMLElement | Window, axis: "x" | "y", value: number, callback?: (scrollValue: number) => void) => void;
|
|
10
|
+
export declare const scrollAnimate: (element: HTMLElement | Window, axis: "x" | "y", direction: "begin" | "end", speed: number, callback?: (scrollValue: number) => void) => () => void;
|
package/lib/scroller.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scrollAnimate = exports.updateScrollValue = exports.calcAutoScrollBasicInfo = void 0;
|
|
4
|
+
const animation_1 = require("./animation");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const MAX_SPEED = 80; // px/s
|
|
7
|
+
const calcAutoScrollBasicInfo = (point, axis, viewport, maxSpeed = MAX_SPEED) => {
|
|
8
|
+
const { left, right, top, bottom } = viewport;
|
|
9
|
+
const { x, y } = point;
|
|
10
|
+
let begin;
|
|
11
|
+
let end;
|
|
12
|
+
let pos;
|
|
13
|
+
let speedFactor;
|
|
14
|
+
if (axis === 'x') {
|
|
15
|
+
begin = left;
|
|
16
|
+
end = right;
|
|
17
|
+
pos = x;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
begin = top;
|
|
21
|
+
end = bottom;
|
|
22
|
+
pos = y;
|
|
23
|
+
}
|
|
24
|
+
const scrollerSize = end - begin;
|
|
25
|
+
const moveDistance = scrollerSize > 400 ? 100 : scrollerSize / 3;
|
|
26
|
+
if (end - pos < moveDistance) {
|
|
27
|
+
return {
|
|
28
|
+
direction: 'end',
|
|
29
|
+
speedFactor,
|
|
30
|
+
speed: maxSpeed * (0, animation_1.calcSpeedFactor)(end - pos, moveDistance),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else if (pos - begin < moveDistance) {
|
|
34
|
+
return {
|
|
35
|
+
direction: 'begin',
|
|
36
|
+
speedFactor,
|
|
37
|
+
speed: maxSpeed * (0, animation_1.calcSpeedFactor)(pos - begin, moveDistance),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
exports.calcAutoScrollBasicInfo = calcAutoScrollBasicInfo;
|
|
43
|
+
const updateScrollValue = (element, axis, value, callback) => {
|
|
44
|
+
if (element) {
|
|
45
|
+
if (!(0, types_1.isWindow)(element)) {
|
|
46
|
+
if (axis === 'x') {
|
|
47
|
+
if (element.scrollLeft + value > element.scrollWidth)
|
|
48
|
+
return;
|
|
49
|
+
element.scrollLeft += value;
|
|
50
|
+
if ((0, types_1.isFn)(callback)) {
|
|
51
|
+
callback(element.scrollLeft);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
if (element.scrollTop + value > element.scrollHeight)
|
|
56
|
+
return;
|
|
57
|
+
element.scrollTop += value;
|
|
58
|
+
if ((0, types_1.isFn)(callback)) {
|
|
59
|
+
callback(element.scrollTop);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if (axis === 'x') {
|
|
65
|
+
element.scrollBy({
|
|
66
|
+
left: value,
|
|
67
|
+
behavior: 'smooth',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
element.scrollBy({
|
|
72
|
+
top: value,
|
|
73
|
+
behavior: 'smooth',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if ((0, types_1.isFn)(callback)) {
|
|
77
|
+
callback(value);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.updateScrollValue = updateScrollValue;
|
|
83
|
+
const scrollAnimate = (element, axis, direction, speed, callback) => {
|
|
84
|
+
return (0, animation_1.createUniformSpeedAnimation)(speed, (delta) => {
|
|
85
|
+
(0, exports.updateScrollValue)(element, axis, direction === 'begin' ? 0 - delta : delta, callback);
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
exports.scrollAnimate = scrollAnimate;
|