@thienvu18/designable-shared 2.0.0 → 2.0.2

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.
Files changed (73) hide show
  1. package/esm/animation.d.ts +8 -2
  2. package/esm/animation.js +29 -30
  3. package/esm/array.d.ts +163 -37
  4. package/esm/array.js +104 -87
  5. package/esm/clone.d.ts +4 -4
  6. package/esm/clone.js +79 -86
  7. package/esm/compose.d.ts +3 -1
  8. package/esm/compose.js +6 -6
  9. package/esm/coordinate.d.ts +120 -76
  10. package/esm/coordinate.js +480 -411
  11. package/esm/element.d.ts +11 -6
  12. package/esm/element.js +123 -125
  13. package/esm/event.d.ts +162 -75
  14. package/esm/event.js +197 -197
  15. package/esm/globalThisPolyfill.d.ts +1 -1
  16. package/esm/globalThisPolyfill.js +14 -17
  17. package/esm/index.d.ts +17 -17
  18. package/esm/index.js +17 -17
  19. package/esm/instanceof.d.ts +1 -1
  20. package/esm/instanceof.js +9 -10
  21. package/esm/keycode.d.ts +145 -145
  22. package/esm/keycode.js +149 -149
  23. package/esm/lru.d.ts +50 -47
  24. package/esm/lru.js +236 -245
  25. package/esm/observer.d.ts +7 -7
  26. package/esm/observer.js +37 -40
  27. package/esm/request-idle.d.ts +9 -6
  28. package/esm/request-idle.js +6 -6
  29. package/esm/scroller.d.ts +24 -8
  30. package/esm/scroller.js +78 -75
  31. package/esm/subscribable.d.ts +10 -10
  32. package/esm/subscribable.js +39 -40
  33. package/esm/types.d.ts +13 -13
  34. package/esm/types.js +19 -20
  35. package/esm/uid.d.ts +1 -1
  36. package/esm/uid.js +7 -7
  37. package/lib/animation.d.ts +8 -2
  38. package/lib/animation.js +34 -35
  39. package/lib/array.d.ts +163 -37
  40. package/lib/array.js +129 -101
  41. package/lib/clone.d.ts +4 -4
  42. package/lib/clone.js +84 -91
  43. package/lib/compose.d.ts +3 -1
  44. package/lib/compose.js +10 -10
  45. package/lib/coordinate.d.ts +120 -76
  46. package/lib/coordinate.js +538 -440
  47. package/lib/element.d.ts +11 -6
  48. package/lib/element.js +139 -133
  49. package/lib/event.d.ts +162 -75
  50. package/lib/event.js +206 -202
  51. package/lib/globalThisPolyfill.d.ts +1 -1
  52. package/lib/globalThisPolyfill.js +17 -20
  53. package/lib/index.d.ts +17 -17
  54. package/lib/index.js +49 -33
  55. package/lib/instanceof.d.ts +1 -1
  56. package/lib/instanceof.js +13 -14
  57. package/lib/keycode.d.ts +145 -145
  58. package/lib/keycode.js +153 -153
  59. package/lib/lru.d.ts +50 -47
  60. package/lib/lru.js +240 -249
  61. package/lib/observer.d.ts +7 -7
  62. package/lib/observer.js +41 -44
  63. package/lib/request-idle.d.ts +9 -6
  64. package/lib/request-idle.js +14 -11
  65. package/lib/scroller.d.ts +24 -8
  66. package/lib/scroller.js +89 -81
  67. package/lib/subscribable.d.ts +10 -10
  68. package/lib/subscribable.js +43 -44
  69. package/lib/types.d.ts +13 -13
  70. package/lib/types.js +40 -28
  71. package/lib/uid.d.ts +1 -1
  72. package/lib/uid.js +11 -11
  73. package/package.json +15 -15
package/lib/lru.d.ts CHANGED
@@ -17,57 +17,60 @@
17
17
  * removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added
18
18
  */
19
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;
20
+ size: number
21
+ limit: number
22
+ oldest: any
23
+ newest: any
24
+ _keymap: Map<
25
+ K,
26
+ {
27
+ key: K
28
+ value: V
29
+ }
30
+ >
31
+ constructor(limit: number, entries?: any)
32
+ private _markEntryAsUsed
33
+ assign(entries: any): void
34
+ get(key: K): V
35
+ set(key: K, value: V): this
36
+ shift(): any[]
37
+ find(key: K): V
38
+ has(key: K): boolean
39
+ delete(key: any): V
40
+ clear(): void
41
+ keys(): KeyIterator
42
+ values(): ValueIterator
43
+ entries(): void
44
+ forEach(fun: (value: any, key: any, ctx: object) => void, thisObj: any): void
45
+ toJSON(): any[]
46
+ toString(): string
47
+ [Symbol.iterator](): EntryIterator
45
48
  }
46
49
  declare class EntryIterator {
47
- entry: any;
48
- constructor(oldestEntry: any);
49
- [Symbol.iterator](): this;
50
- next(): {
51
- done: boolean;
52
- value: any[];
53
- };
50
+ entry: any
51
+ constructor(oldestEntry: any)
52
+ [Symbol.iterator](): this
53
+ next(): {
54
+ done: boolean
55
+ value: any[]
56
+ }
54
57
  }
55
58
  declare class KeyIterator {
56
- entry: any;
57
- constructor(oldestEntry: any);
58
- [Symbol.iterator](): this;
59
- next(): {
60
- done: boolean;
61
- value: any;
62
- };
59
+ entry: any
60
+ constructor(oldestEntry: any)
61
+ [Symbol.iterator](): this
62
+ next(): {
63
+ done: boolean
64
+ value: any
65
+ }
63
66
  }
64
67
  declare class ValueIterator {
65
- entry: any;
66
- constructor(oldestEntry: any);
67
- [Symbol.iterator](): this;
68
- next(): {
69
- done: boolean;
70
- value: any;
71
- };
68
+ entry: any
69
+ constructor(oldestEntry: any)
70
+ [Symbol.iterator](): this
71
+ next(): {
72
+ done: boolean
73
+ value: any
74
+ }
72
75
  }
73
- export {};
76
+ export {}
package/lib/lru.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ 'use strict'
2
2
  /**
3
3
  * A doubly linked list-based Least Recently Used (LRU) cache. Will keep most
4
4
  * recently used items while discarding least recently used items when its limit
@@ -18,280 +18,271 @@
18
18
  * removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added
19
19
  */
20
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');
21
+ Object.defineProperty(exports, '__esModule', { value: true })
22
+ exports.LRUMap = void 0
23
+ const NEWER = Symbol('newer')
24
+ const OLDER = Symbol('older')
25
25
  function Entry(key, value) {
26
- this.key = key;
27
- this.value = value;
28
- this[NEWER] = undefined;
29
- this[OLDER] = undefined;
26
+ this.key = key
27
+ this.value = value
28
+ this[NEWER] = undefined
29
+ this[OLDER] = undefined
30
30
  }
31
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
- }
32
+ constructor(limit, entries) {
33
+ if (typeof limit !== 'number') {
34
+ // called as (entries)
35
+ entries = limit
36
+ limit = 0
48
37
  }
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;
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
+ }
73
47
  }
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;
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
96
53
  }
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;
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.
106
63
  }
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;
64
+ if (entry[OLDER]) {
65
+ entry[OLDER][NEWER] = entry[NEWER] // C. --> E
134
66
  }
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
- }
67
+ entry[NEWER] = undefined // D --x
68
+ entry[OLDER] = this.newest // D. --> E
69
+ if (this.newest) {
70
+ this.newest[NEWER] = entry // E. <-- D
156
71
  }
157
- find(key) {
158
- const e = this._keymap.get(key);
159
- return e ? e.value : undefined;
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
+ } else {
85
+ entry[NEWER] = e
86
+ e[OLDER] = entry
87
+ }
88
+ entry = e
89
+ if (limit-- === 0) {
90
+ throw new Error('overflow')
91
+ }
160
92
  }
161
- has(key) {
162
- return this._keymap.has(key);
93
+ this.newest = entry
94
+ this.size = this._keymap.size
95
+ }
96
+ get(key) {
97
+ // First, find our cache entry
98
+ const entry = this._keymap.get(key)
99
+ if (!entry) {
100
+ return
101
+ } // Not cached. Sorry.
102
+ // As <key> was found in the cache, register it as being requested recently
103
+ this._markEntryAsUsed(entry)
104
+ return entry.value
105
+ }
106
+ set(key, value) {
107
+ let entry = this._keymap.get(key)
108
+ if (entry) {
109
+ // update existing
110
+ entry.value = value
111
+ this._markEntryAsUsed(entry)
112
+ return this
163
113
  }
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;
114
+ // new entry
115
+ this._keymap.set(key, (entry = new Entry(key, value)))
116
+ if (this.newest) {
117
+ // link previous tail to the new tail (entry)
118
+ this.newest[NEWER] = entry
119
+ entry[OLDER] = this.newest
120
+ } else {
121
+ // we're first in -- yay
122
+ this.oldest = entry
193
123
  }
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();
124
+ // add new entry to the end of the linked list -- it's now the freshest entry.
125
+ this.newest = entry
126
+ ++this.size
127
+ if (this.size > this.limit) {
128
+ // we hit the limit -- remove the head
129
+ this.shift()
199
130
  }
200
- keys() {
201
- return new KeyIterator(this.oldest);
131
+ return this
132
+ }
133
+ shift() {
134
+ // todo: handle special case when limit == 1
135
+ const entry = this.oldest
136
+ if (entry) {
137
+ if (this.oldest[NEWER]) {
138
+ // advance the list
139
+ this.oldest = this.oldest[NEWER]
140
+ this.oldest[OLDER] = undefined
141
+ } else {
142
+ // the cache is exhausted
143
+ this.oldest = undefined
144
+ this.newest = undefined
145
+ }
146
+ // Remove last strong reference to <entry> and remove links from the purged
147
+ // entry being returned:
148
+ entry[NEWER] = entry[OLDER] = undefined
149
+ this._keymap.delete(entry.key)
150
+ --this.size
151
+ return [entry.key, entry.value]
202
152
  }
203
- values() {
204
- return new ValueIterator(this.oldest);
153
+ }
154
+ find(key) {
155
+ const e = this._keymap.get(key)
156
+ return e ? e.value : undefined
157
+ }
158
+ has(key) {
159
+ return this._keymap.has(key)
160
+ }
161
+ delete(key) {
162
+ const entry = this._keymap.get(key)
163
+ if (!entry) {
164
+ return
205
165
  }
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
- }
166
+ this._keymap.delete(entry.key)
167
+ if (entry[NEWER] && entry[OLDER]) {
168
+ // relink the older entry with the newer entry
169
+ entry[OLDER][NEWER] = entry[NEWER]
170
+ entry[NEWER][OLDER] = entry[OLDER]
171
+ } else if (entry[NEWER]) {
172
+ // remove the link to us
173
+ entry[NEWER][OLDER] = undefined
174
+ // link the newer entry to head
175
+ this.oldest = entry[NEWER]
176
+ } else if (entry[OLDER]) {
177
+ // remove the link to us
178
+ entry[OLDER][NEWER] = undefined
179
+ // link the newer entry to head
180
+ this.newest = entry[OLDER]
181
+ } else {
182
+ // if(entry[OLDER] === undefined && entry.newer === undefined) {
183
+ this.oldest = this.newest = undefined
216
184
  }
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;
185
+ this.size--
186
+ return entry.value
187
+ }
188
+ clear() {
189
+ // Not clearing links should be safe, as we don't expose live links to user
190
+ this.oldest = this.newest = undefined
191
+ this.size = 0
192
+ this._keymap.clear()
193
+ }
194
+ keys() {
195
+ return new KeyIterator(this.oldest)
196
+ }
197
+ values() {
198
+ return new ValueIterator(this.oldest)
199
+ }
200
+ entries() {}
201
+ forEach(fun, thisObj) {
202
+ if (typeof thisObj !== 'object') {
203
+ thisObj = this
226
204
  }
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;
205
+ let entry = this.oldest
206
+ while (entry) {
207
+ fun.call(thisObj, entry.value, entry.key, this)
208
+ entry = entry[NEWER]
238
209
  }
239
- [Symbol.iterator]() {
240
- return new EntryIterator(this.oldest);
210
+ }
211
+ toJSON() {
212
+ const s = new Array(this.size)
213
+ let i = 0
214
+ let entry = this.oldest
215
+ while (entry) {
216
+ s[i++] = { key: entry.key, value: entry.value }
217
+ entry = entry[NEWER]
241
218
  }
219
+ return s
220
+ }
221
+ toString() {
222
+ let s = ''
223
+ let entry = this.oldest
224
+ while (entry) {
225
+ s += String(entry.key) + ':' + entry.value
226
+ entry = entry[NEWER]
227
+ if (entry) {
228
+ s += ' < '
229
+ }
230
+ }
231
+ return s
232
+ }
233
+ [Symbol.iterator]() {
234
+ return new EntryIterator(this.oldest)
235
+ }
242
236
  }
243
- exports.LRUMap = LRUMap;
237
+ exports.LRUMap = LRUMap
244
238
  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
- }
239
+ constructor(oldestEntry) {
240
+ this.entry = oldestEntry
241
+ }
242
+ [Symbol.iterator]() {
243
+ return this
244
+ }
245
+ next() {
246
+ const ent = this.entry
247
+ if (ent) {
248
+ this.entry = ent[NEWER]
249
+ return { done: false, value: [ent.key, ent.value] }
250
+ } else {
251
+ return { done: true, value: undefined }
260
252
  }
253
+ }
261
254
  }
262
255
  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
- }
256
+ constructor(oldestEntry) {
257
+ this.entry = oldestEntry
258
+ }
259
+ [Symbol.iterator]() {
260
+ return this
261
+ }
262
+ next() {
263
+ const ent = this.entry
264
+ if (ent) {
265
+ this.entry = ent[NEWER]
266
+ return { done: false, value: ent.key }
267
+ } else {
268
+ return { done: true, value: undefined }
278
269
  }
270
+ }
279
271
  }
280
272
  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
- }
273
+ constructor(oldestEntry) {
274
+ this.entry = oldestEntry
275
+ }
276
+ [Symbol.iterator]() {
277
+ return this
278
+ }
279
+ next() {
280
+ const ent = this.entry
281
+ if (ent) {
282
+ this.entry = ent[NEWER]
283
+ return { done: false, value: ent.value }
284
+ } else {
285
+ return { done: true, value: undefined }
296
286
  }
287
+ }
297
288
  }
package/lib/observer.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export declare class LayoutObserver {
2
- private resizeObserver?;
3
- private performanceObserver?;
4
- private mutationObserver?;
5
- private connected;
6
- constructor(observer?: () => void);
7
- observe: (target: HTMLElement | Element) => void;
8
- disconnect: () => void;
2
+ private resizeObserver?
3
+ private performanceObserver?
4
+ private mutationObserver?
5
+ private connected
6
+ constructor(observer?: () => void)
7
+ observe: (target: HTMLElement | Element) => void
8
+ disconnect: () => void
9
9
  }