@thienvu18/designable-shared 2.0.1 → 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.
- package/esm/animation.d.ts +8 -2
- package/esm/animation.js +29 -30
- package/esm/array.d.ts +163 -37
- package/esm/array.js +104 -87
- package/esm/clone.d.ts +4 -4
- package/esm/clone.js +79 -86
- package/esm/compose.d.ts +3 -1
- package/esm/compose.js +6 -6
- package/esm/coordinate.d.ts +120 -76
- package/esm/coordinate.js +480 -411
- package/esm/element.d.ts +11 -6
- package/esm/element.js +123 -125
- package/esm/event.d.ts +162 -75
- package/esm/event.js +197 -197
- package/esm/globalThisPolyfill.d.ts +1 -1
- package/esm/globalThisPolyfill.js +14 -17
- package/esm/index.d.ts +17 -17
- package/esm/index.js +17 -17
- package/esm/instanceof.d.ts +1 -1
- package/esm/instanceof.js +9 -10
- package/esm/keycode.d.ts +145 -145
- package/esm/keycode.js +149 -149
- package/esm/lru.d.ts +50 -47
- package/esm/lru.js +236 -245
- package/esm/observer.d.ts +7 -7
- package/esm/observer.js +37 -40
- package/esm/request-idle.d.ts +9 -6
- package/esm/request-idle.js +6 -6
- package/esm/scroller.d.ts +24 -8
- package/esm/scroller.js +78 -75
- package/esm/subscribable.d.ts +10 -10
- package/esm/subscribable.js +39 -40
- package/esm/types.d.ts +13 -13
- package/esm/types.js +19 -20
- package/esm/uid.d.ts +1 -1
- package/esm/uid.js +7 -7
- package/lib/animation.d.ts +8 -2
- package/lib/animation.js +34 -35
- package/lib/array.d.ts +163 -37
- package/lib/array.js +129 -101
- package/lib/clone.d.ts +4 -4
- package/lib/clone.js +84 -91
- package/lib/compose.d.ts +3 -1
- package/lib/compose.js +10 -10
- package/lib/coordinate.d.ts +120 -76
- package/lib/coordinate.js +538 -440
- package/lib/element.d.ts +11 -6
- package/lib/element.js +139 -133
- package/lib/event.d.ts +162 -75
- package/lib/event.js +206 -202
- package/lib/globalThisPolyfill.d.ts +1 -1
- package/lib/globalThisPolyfill.js +17 -20
- package/lib/index.d.ts +17 -17
- package/lib/index.js +49 -33
- package/lib/instanceof.d.ts +1 -1
- package/lib/instanceof.js +13 -14
- package/lib/keycode.d.ts +145 -145
- package/lib/keycode.js +153 -153
- package/lib/lru.d.ts +50 -47
- package/lib/lru.js +240 -249
- package/lib/observer.d.ts +7 -7
- package/lib/observer.js +41 -44
- package/lib/request-idle.d.ts +9 -6
- package/lib/request-idle.js +14 -11
- package/lib/scroller.d.ts +24 -8
- package/lib/scroller.js +89 -81
- package/lib/subscribable.d.ts +10 -10
- package/lib/subscribable.js +43 -44
- package/lib/types.d.ts +13 -13
- package/lib/types.js +40 -28
- package/lib/uid.d.ts +1 -1
- package/lib/uid.js +11 -11
- package/package.json +1 -1
package/esm/animation.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
export declare const createUniformSpeedAnimation: (
|
|
2
|
-
|
|
1
|
+
export declare const createUniformSpeedAnimation: (
|
|
2
|
+
speed: number,
|
|
3
|
+
callback: (delta: number) => void
|
|
4
|
+
) => () => void
|
|
5
|
+
export declare const calcSpeedFactor: (
|
|
6
|
+
delta?: number,
|
|
7
|
+
threshold?: number
|
|
8
|
+
) => number
|
package/esm/animation.js
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
export const createUniformSpeedAnimation = (speed = 10, callback) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
2
|
+
let request = null
|
|
3
|
+
let startTime = null
|
|
4
|
+
const start = () => {
|
|
5
|
+
if (request) return
|
|
6
|
+
request = requestAnimationFrame((timestamp) => {
|
|
7
|
+
if (startTime === null) {
|
|
8
|
+
startTime = timestamp
|
|
9
|
+
}
|
|
10
|
+
const deltaTime = timestamp - startTime
|
|
11
|
+
const delta = (deltaTime / 1000) * speed
|
|
12
|
+
callback(delta)
|
|
13
|
+
request = null
|
|
14
|
+
start()
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
start()
|
|
18
|
+
return () => {
|
|
19
|
+
if (request) {
|
|
20
|
+
cancelAnimationFrame(request)
|
|
21
|
+
request = null
|
|
22
|
+
}
|
|
23
|
+
startTime = null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
27
26
|
//越接近阈值,速度越小,越远离阈值,速度越大
|
|
28
27
|
export const calcSpeedFactor = (delta = 0, threshold = Infinity) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
28
|
+
if (threshold >= delta) {
|
|
29
|
+
return (threshold - delta) / threshold
|
|
30
|
+
}
|
|
31
|
+
return 0
|
|
32
|
+
}
|
package/esm/array.d.ts
CHANGED
|
@@ -1,37 +1,163 @@
|
|
|
1
|
-
type EachArrayIterator<T> = (currentValue: T, key: number) => void | boolean
|
|
2
|
-
type EachStringIterator = (currentValue: string, key: number) => void | boolean
|
|
3
|
-
type EachObjectIterator<T = any> = (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export declare
|
|
32
|
-
export declare function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export
|
|
1
|
+
type EachArrayIterator<T> = (currentValue: T, key: number) => void | boolean
|
|
2
|
+
type EachStringIterator = (currentValue: string, key: number) => void | boolean
|
|
3
|
+
type EachObjectIterator<T = any> = (
|
|
4
|
+
currentValue: T,
|
|
5
|
+
key: string
|
|
6
|
+
) => void | boolean
|
|
7
|
+
type MapArrayIterator<TItem, TResult> = (
|
|
8
|
+
currentValue: TItem,
|
|
9
|
+
key: number
|
|
10
|
+
) => TResult
|
|
11
|
+
type MapStringIterator<TResult> = (currentValue: string, key: number) => TResult
|
|
12
|
+
type MapObjectIterator<TItem, TResult> = (
|
|
13
|
+
currentValue: TItem,
|
|
14
|
+
key: string
|
|
15
|
+
) => TResult
|
|
16
|
+
type MemoArrayIterator<T, U> = (
|
|
17
|
+
previousValue: U,
|
|
18
|
+
currentValue: T,
|
|
19
|
+
key: number
|
|
20
|
+
) => U
|
|
21
|
+
type MemoStringIterator<T> = (
|
|
22
|
+
previousValue: T,
|
|
23
|
+
currentValue: string,
|
|
24
|
+
key: number
|
|
25
|
+
) => T
|
|
26
|
+
type MemoObjectIterator<TValue, TResult> = (
|
|
27
|
+
previousValue: TResult,
|
|
28
|
+
currentValue: TValue,
|
|
29
|
+
key: string
|
|
30
|
+
) => TResult
|
|
31
|
+
export declare const toArr: (val: any) => any[]
|
|
32
|
+
export declare function each(
|
|
33
|
+
val: string,
|
|
34
|
+
iterator: EachStringIterator,
|
|
35
|
+
revert?: boolean
|
|
36
|
+
): void
|
|
37
|
+
export declare function each<T>(
|
|
38
|
+
val: T[],
|
|
39
|
+
iterator: EachArrayIterator<T>,
|
|
40
|
+
revert?: boolean
|
|
41
|
+
): void
|
|
42
|
+
export declare function each<T extends {}, TValue = T[keyof T]>(
|
|
43
|
+
val: T,
|
|
44
|
+
iterator: EachObjectIterator<TValue>,
|
|
45
|
+
revert?: boolean
|
|
46
|
+
): void
|
|
47
|
+
export declare function map<T>(
|
|
48
|
+
val: string,
|
|
49
|
+
iterator: MapStringIterator<T>,
|
|
50
|
+
revert?: boolean
|
|
51
|
+
): any
|
|
52
|
+
export declare function map<TItem, TResult>(
|
|
53
|
+
val: TItem[],
|
|
54
|
+
iterator: MapArrayIterator<TItem, TResult>,
|
|
55
|
+
revert?: boolean
|
|
56
|
+
): any
|
|
57
|
+
export declare function map<T extends {}, TResult>(
|
|
58
|
+
val: T,
|
|
59
|
+
iterator: MapObjectIterator<T[keyof T], TResult>,
|
|
60
|
+
revert?: boolean
|
|
61
|
+
): any
|
|
62
|
+
export declare function reduce<T, U>(
|
|
63
|
+
val: T[],
|
|
64
|
+
iterator: MemoArrayIterator<T, U>,
|
|
65
|
+
accumulator?: U,
|
|
66
|
+
revert?: boolean
|
|
67
|
+
): U
|
|
68
|
+
export declare function reduce<T>(
|
|
69
|
+
val: string,
|
|
70
|
+
iterator: MemoStringIterator<T>,
|
|
71
|
+
accumulator?: T,
|
|
72
|
+
revert?: boolean
|
|
73
|
+
): T
|
|
74
|
+
export declare function reduce<
|
|
75
|
+
T extends {},
|
|
76
|
+
TValue = T[keyof T],
|
|
77
|
+
TResult = any
|
|
78
|
+
>(
|
|
79
|
+
val: T,
|
|
80
|
+
iterator: MemoObjectIterator<TValue, TResult>,
|
|
81
|
+
accumulator?: TResult,
|
|
82
|
+
revert?: boolean
|
|
83
|
+
): TResult
|
|
84
|
+
export declare function every<T extends string>(
|
|
85
|
+
val: T,
|
|
86
|
+
iterator: EachStringIterator,
|
|
87
|
+
revert?: boolean
|
|
88
|
+
): boolean
|
|
89
|
+
export declare function every<T>(
|
|
90
|
+
val: T[],
|
|
91
|
+
iterator: EachArrayIterator<T>,
|
|
92
|
+
revert?: boolean
|
|
93
|
+
): boolean
|
|
94
|
+
export declare function every<T extends {}>(
|
|
95
|
+
val: T,
|
|
96
|
+
iterator: EachObjectIterator,
|
|
97
|
+
revert?: boolean
|
|
98
|
+
): boolean
|
|
99
|
+
export declare function some<T extends string>(
|
|
100
|
+
val: T,
|
|
101
|
+
iterator: EachStringIterator,
|
|
102
|
+
revert?: boolean
|
|
103
|
+
): boolean
|
|
104
|
+
export declare function some<T>(
|
|
105
|
+
val: T[],
|
|
106
|
+
iterator: EachArrayIterator<T>,
|
|
107
|
+
revert?: boolean
|
|
108
|
+
): boolean
|
|
109
|
+
export declare function some<T extends {}>(
|
|
110
|
+
val: T,
|
|
111
|
+
iterator: EachObjectIterator,
|
|
112
|
+
revert?: boolean
|
|
113
|
+
): boolean
|
|
114
|
+
export declare function findIndex<T extends string>(
|
|
115
|
+
val: T,
|
|
116
|
+
iterator: EachStringIterator,
|
|
117
|
+
revert?: boolean
|
|
118
|
+
): number
|
|
119
|
+
export declare function findIndex<T>(
|
|
120
|
+
val: T[],
|
|
121
|
+
iterator: EachArrayIterator<T>,
|
|
122
|
+
revert?: boolean
|
|
123
|
+
): number
|
|
124
|
+
export declare function findIndex<T extends {}>(
|
|
125
|
+
val: T,
|
|
126
|
+
iterator: EachObjectIterator,
|
|
127
|
+
revert?: boolean
|
|
128
|
+
): keyof T
|
|
129
|
+
export declare function find<T extends string>(
|
|
130
|
+
val: T,
|
|
131
|
+
iterator: EachStringIterator,
|
|
132
|
+
revert?: boolean
|
|
133
|
+
): any
|
|
134
|
+
export declare function find<T>(
|
|
135
|
+
val: T[],
|
|
136
|
+
iterator: EachArrayIterator<T>,
|
|
137
|
+
revert?: boolean
|
|
138
|
+
): T
|
|
139
|
+
export declare function find<T extends {}>(
|
|
140
|
+
val: T,
|
|
141
|
+
iterator: EachObjectIterator,
|
|
142
|
+
revert?: boolean
|
|
143
|
+
): T[keyof T]
|
|
144
|
+
export declare function includes<T extends string>(
|
|
145
|
+
val: T,
|
|
146
|
+
searchElement: string,
|
|
147
|
+
revert?: boolean
|
|
148
|
+
): boolean
|
|
149
|
+
export declare function includes<T>(
|
|
150
|
+
val: T[],
|
|
151
|
+
searchElement: T,
|
|
152
|
+
revert?: boolean
|
|
153
|
+
): boolean
|
|
154
|
+
export declare function includesWith<T extends string>(
|
|
155
|
+
val: T,
|
|
156
|
+
search: (item: string) => boolean
|
|
157
|
+
): boolean
|
|
158
|
+
export declare function includesWith<T>(
|
|
159
|
+
val: T[],
|
|
160
|
+
search: (item: T) => boolean
|
|
161
|
+
): boolean
|
|
162
|
+
export declare const flat: <T>(array: (T | T[])[]) => T[]
|
|
163
|
+
export {}
|
package/esm/array.js
CHANGED
|
@@ -1,111 +1,128 @@
|
|
|
1
|
-
import { isArr, isObj, isStr } from './types'
|
|
2
|
-
export const toArr = (val) => (isArr(val) ? val : val ? [val] : [])
|
|
1
|
+
import { isArr, isObj, isStr } from './types'
|
|
2
|
+
export const toArr = (val) => (isArr(val) ? val : val ? [val] : [])
|
|
3
3
|
export function each(val, iterator, revert) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
}
|
|
4
|
+
if (isArr(val) || isStr(val)) {
|
|
5
|
+
if (revert) {
|
|
6
|
+
for (let i = val.length - 1; i >= 0; i--) {
|
|
7
|
+
if (iterator(val[i], i) === false) {
|
|
8
|
+
return
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
10
|
+
}
|
|
11
|
+
} else {
|
|
12
|
+
for (let i = 0; i < val.length; i++) {
|
|
13
|
+
if (iterator(val[i], i) === false) {
|
|
14
|
+
return
|
|
18
15
|
}
|
|
16
|
+
}
|
|
19
17
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
}
|
|
18
|
+
} else if (isObj(val)) {
|
|
19
|
+
let key
|
|
20
|
+
for (key in val) {
|
|
21
|
+
if (Object.hasOwnProperty.call(val, key)) {
|
|
22
|
+
if (iterator(val[key], key) === false) {
|
|
23
|
+
return
|
|
28
24
|
}
|
|
25
|
+
}
|
|
29
26
|
}
|
|
27
|
+
}
|
|
30
28
|
}
|
|
31
29
|
export function map(val, iterator, revert) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
|
|
30
|
+
const res = isArr(val) || isStr(val) ? [] : {}
|
|
31
|
+
each(
|
|
32
|
+
val,
|
|
33
|
+
(item, key) => {
|
|
34
|
+
const value = iterator(item, key)
|
|
35
|
+
if (isArr(res)) {
|
|
36
|
+
res.push(value)
|
|
37
|
+
} else {
|
|
38
|
+
res[key] = value
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
revert
|
|
42
|
+
)
|
|
43
|
+
return res
|
|
44
44
|
}
|
|
45
45
|
export function reduce(val, iterator, accumulator, revert) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
let result = accumulator
|
|
47
|
+
each(
|
|
48
|
+
val,
|
|
49
|
+
(item, key) => {
|
|
50
|
+
result = iterator(result, item, key)
|
|
51
|
+
},
|
|
52
|
+
revert
|
|
53
|
+
)
|
|
54
|
+
return result
|
|
51
55
|
}
|
|
52
56
|
export function every(val, iterator, revert) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
let res = true
|
|
58
|
+
each(
|
|
59
|
+
val,
|
|
60
|
+
(item, key) => {
|
|
61
|
+
if (!iterator(item, key)) {
|
|
62
|
+
res = false
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
revert
|
|
67
|
+
)
|
|
68
|
+
return res
|
|
61
69
|
}
|
|
62
70
|
export function some(val, iterator, revert) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
let res = false
|
|
72
|
+
each(
|
|
73
|
+
val,
|
|
74
|
+
(item, key) => {
|
|
75
|
+
if (iterator(item, key)) {
|
|
76
|
+
res = true
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
revert
|
|
81
|
+
)
|
|
82
|
+
return res
|
|
71
83
|
}
|
|
72
84
|
export function findIndex(val, iterator, revert) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
let res = -1
|
|
86
|
+
each(
|
|
87
|
+
val,
|
|
88
|
+
(item, key) => {
|
|
89
|
+
if (iterator(item, key)) {
|
|
90
|
+
res = key
|
|
91
|
+
return false
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
revert
|
|
95
|
+
)
|
|
96
|
+
return res
|
|
81
97
|
}
|
|
82
98
|
export function find(val, iterator, revert) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
99
|
+
let res
|
|
100
|
+
each(
|
|
101
|
+
val,
|
|
102
|
+
(item, key) => {
|
|
103
|
+
if (iterator(item, key)) {
|
|
104
|
+
res = item
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
revert
|
|
109
|
+
)
|
|
110
|
+
return res
|
|
91
111
|
}
|
|
92
112
|
export function includes(val, searchElement, revert) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return some(val, (item) => item === searchElement, revert);
|
|
113
|
+
if (isStr(val)) return val.includes(searchElement)
|
|
114
|
+
return some(val, (item) => item === searchElement, revert)
|
|
96
115
|
}
|
|
97
116
|
export function includesWith(val, search) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
117
|
+
if (isArr(val)) {
|
|
118
|
+
return val.some((item) => search(item))
|
|
119
|
+
} else {
|
|
120
|
+
return false
|
|
121
|
+
}
|
|
104
122
|
}
|
|
105
123
|
export const flat = (array) => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
124
|
+
return toArr(array).reduce((buf, item) => {
|
|
125
|
+
if (isArr(item)) return buf.concat(flat(item))
|
|
126
|
+
return buf.concat(item)
|
|
127
|
+
}, [])
|
|
128
|
+
}
|
package/esm/clone.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Filter = (value: any, key: string) => boolean
|
|
2
|
-
export declare const shallowClone: (values: any) => any
|
|
3
|
-
export declare const clone: (values: any, filter?: Filter) => any
|
|
4
|
-
export {}
|
|
1
|
+
type Filter = (value: any, key: string) => boolean
|
|
2
|
+
export declare const shallowClone: (values: any) => any
|
|
3
|
+
export declare const clone: (values: any, filter?: Filter) => any
|
|
4
|
+
export {}
|