@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/lib/observer.js
CHANGED
|
@@ -1,47 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.LayoutObserver = void 0
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.LayoutObserver = void 0
|
|
4
4
|
class LayoutObserver {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
this.connected = true;
|
|
22
|
-
};
|
|
23
|
-
this.disconnect = () => {
|
|
24
|
-
if (this.connected) {
|
|
25
|
-
this.resizeObserver?.disconnect();
|
|
26
|
-
this.performanceObserver?.disconnect();
|
|
27
|
-
this.mutationObserver?.disconnect();
|
|
28
|
-
}
|
|
29
|
-
this.connected = false;
|
|
30
|
-
};
|
|
31
|
-
if (typeof ResizeObserver !== 'undefined') {
|
|
32
|
-
this.resizeObserver = new ResizeObserver(() => observer());
|
|
33
|
-
}
|
|
34
|
-
if (typeof PerformanceObserver !== 'undefined') {
|
|
35
|
-
try {
|
|
36
|
-
this.performanceObserver = new PerformanceObserver(() => {
|
|
37
|
-
observer();
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
catch (e) { }
|
|
41
|
-
}
|
|
42
|
-
if (typeof MutationObserver !== 'undefined') {
|
|
43
|
-
this.mutationObserver = new MutationObserver(() => observer());
|
|
44
|
-
}
|
|
5
|
+
constructor(observer = () => {}) {
|
|
6
|
+
this.connected = false
|
|
7
|
+
this.observe = (target) => {
|
|
8
|
+
if (!target) return
|
|
9
|
+
this.resizeObserver?.observe(target)
|
|
10
|
+
try {
|
|
11
|
+
this.performanceObserver?.observe({
|
|
12
|
+
entryTypes: ['paint', 'element', 'layout-shift', 'event'],
|
|
13
|
+
})
|
|
14
|
+
} catch (e) {}
|
|
15
|
+
this.mutationObserver?.observe(target, {
|
|
16
|
+
attributeFilter: ['style'],
|
|
17
|
+
attributes: true,
|
|
18
|
+
})
|
|
19
|
+
this.connected = true
|
|
45
20
|
}
|
|
21
|
+
this.disconnect = () => {
|
|
22
|
+
if (this.connected) {
|
|
23
|
+
this.resizeObserver?.disconnect()
|
|
24
|
+
this.performanceObserver?.disconnect()
|
|
25
|
+
this.mutationObserver?.disconnect()
|
|
26
|
+
}
|
|
27
|
+
this.connected = false
|
|
28
|
+
}
|
|
29
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
30
|
+
this.resizeObserver = new ResizeObserver(() => observer())
|
|
31
|
+
}
|
|
32
|
+
if (typeof PerformanceObserver !== 'undefined') {
|
|
33
|
+
try {
|
|
34
|
+
this.performanceObserver = new PerformanceObserver(() => {
|
|
35
|
+
observer()
|
|
36
|
+
})
|
|
37
|
+
} catch (e) {}
|
|
38
|
+
}
|
|
39
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
40
|
+
this.mutationObserver = new MutationObserver(() => observer())
|
|
41
|
+
}
|
|
42
|
+
}
|
|
46
43
|
}
|
|
47
|
-
exports.LayoutObserver = LayoutObserver
|
|
44
|
+
exports.LayoutObserver = LayoutObserver
|
package/lib/request-idle.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import 'requestidlecallback'
|
|
1
|
+
import 'requestidlecallback'
|
|
2
2
|
export interface IIdleDeadline {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
didTimeout: boolean
|
|
4
|
+
timeRemaining: () => DOMHighResTimeStamp
|
|
5
5
|
}
|
|
6
6
|
export interface IdleCallbackOptions {
|
|
7
|
-
|
|
7
|
+
timeout?: number
|
|
8
8
|
}
|
|
9
|
-
export declare const requestIdle: (
|
|
10
|
-
|
|
9
|
+
export declare const requestIdle: (
|
|
10
|
+
callback: (params: IIdleDeadline) => void,
|
|
11
|
+
options?: IdleCallbackOptions
|
|
12
|
+
) => number
|
|
13
|
+
export declare const cancelIdle: (id: number) => void
|
package/lib/request-idle.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.cancelIdle = exports.requestIdle = void 0
|
|
4
|
-
require(
|
|
5
|
-
const globalThisPolyfill_1 = require(
|
|
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
6
|
const requestIdle = (callback, options) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
return globalThisPolyfill_1.globalThisPolyfill['requestIdleCallback'](
|
|
8
|
+
callback,
|
|
9
|
+
options
|
|
10
|
+
)
|
|
11
|
+
}
|
|
12
|
+
exports.requestIdle = requestIdle
|
|
10
13
|
const cancelIdle = (id) => {
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
exports.cancelIdle = cancelIdle
|
|
14
|
+
globalThisPolyfill_1.globalThisPolyfill['cancelIdleCallback'](id)
|
|
15
|
+
}
|
|
16
|
+
exports.cancelIdle = cancelIdle
|
package/lib/scroller.d.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import { IPoint } from './coordinate'
|
|
2
|
-
export type ScrollDirection = 'begin' | 'end'
|
|
1
|
+
import { IPoint } from './coordinate'
|
|
2
|
+
export type ScrollDirection = 'begin' | 'end'
|
|
3
3
|
export interface IAutoScrollBasicInfo {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
direction: ScrollDirection
|
|
5
|
+
speedFactor: number
|
|
6
|
+
speed: number
|
|
7
7
|
}
|
|
8
|
-
export declare const calcAutoScrollBasicInfo: (
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export declare const calcAutoScrollBasicInfo: (
|
|
9
|
+
point: IPoint,
|
|
10
|
+
axis: 'x' | 'y',
|
|
11
|
+
viewport: DOMRect,
|
|
12
|
+
maxSpeed?: number
|
|
13
|
+
) => IAutoScrollBasicInfo | null
|
|
14
|
+
export declare const updateScrollValue: (
|
|
15
|
+
element: HTMLElement | Window,
|
|
16
|
+
axis: 'x' | 'y',
|
|
17
|
+
value: number,
|
|
18
|
+
callback?: (scrollValue: number) => void
|
|
19
|
+
) => void
|
|
20
|
+
export declare const scrollAnimate: (
|
|
21
|
+
element: HTMLElement | Window,
|
|
22
|
+
axis: 'x' | 'y',
|
|
23
|
+
direction: 'begin' | 'end',
|
|
24
|
+
speed: number,
|
|
25
|
+
callback?: (scrollValue: number) => void
|
|
26
|
+
) => () => void
|
package/lib/scroller.js
CHANGED
|
@@ -1,88 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.scrollAnimate =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.scrollAnimate =
|
|
4
|
+
exports.updateScrollValue =
|
|
5
|
+
exports.calcAutoScrollBasicInfo =
|
|
6
|
+
void 0
|
|
7
|
+
const animation_1 = require('./animation')
|
|
8
|
+
const types_1 = require('./types')
|
|
9
|
+
const MAX_SPEED = 80 // px/s
|
|
10
|
+
const calcAutoScrollBasicInfo = (
|
|
11
|
+
point,
|
|
12
|
+
axis,
|
|
13
|
+
viewport,
|
|
14
|
+
maxSpeed = MAX_SPEED
|
|
15
|
+
) => {
|
|
16
|
+
const { left, right, top, bottom } = viewport
|
|
17
|
+
const { x, y } = point
|
|
18
|
+
let begin
|
|
19
|
+
let end
|
|
20
|
+
let pos
|
|
21
|
+
let speedFactor
|
|
22
|
+
if (axis === 'x') {
|
|
23
|
+
begin = left
|
|
24
|
+
end = right
|
|
25
|
+
pos = x
|
|
26
|
+
} else {
|
|
27
|
+
begin = top
|
|
28
|
+
end = bottom
|
|
29
|
+
pos = y
|
|
30
|
+
}
|
|
31
|
+
const scrollerSize = end - begin
|
|
32
|
+
const moveDistance = scrollerSize > 400 ? 100 : scrollerSize / 3
|
|
33
|
+
if (end - pos < moveDistance) {
|
|
34
|
+
return {
|
|
35
|
+
direction: 'end',
|
|
36
|
+
speedFactor,
|
|
37
|
+
speed:
|
|
38
|
+
maxSpeed * (0, animation_1.calcSpeedFactor)(end - pos, moveDistance),
|
|
18
39
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
} else if (pos - begin < moveDistance) {
|
|
41
|
+
return {
|
|
42
|
+
direction: 'begin',
|
|
43
|
+
speedFactor,
|
|
44
|
+
speed:
|
|
45
|
+
maxSpeed * (0, animation_1.calcSpeedFactor)(pos - begin, moveDistance),
|
|
23
46
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
|
47
|
+
}
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
exports.calcAutoScrollBasicInfo = calcAutoScrollBasicInfo
|
|
43
51
|
const updateScrollValue = (element, axis, value, callback) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
}
|
|
52
|
+
if (element) {
|
|
53
|
+
if (!(0, types_1.isWindow)(element)) {
|
|
54
|
+
if (axis === 'x') {
|
|
55
|
+
if (element.scrollLeft + value > element.scrollWidth) return
|
|
56
|
+
element.scrollLeft += value
|
|
57
|
+
if ((0, types_1.isFn)(callback)) {
|
|
58
|
+
callback(element.scrollLeft)
|
|
62
59
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
}
|
|
60
|
+
} else {
|
|
61
|
+
if (element.scrollTop + value > element.scrollHeight) return
|
|
62
|
+
element.scrollTop += value
|
|
63
|
+
if ((0, types_1.isFn)(callback)) {
|
|
64
|
+
callback(element.scrollTop)
|
|
79
65
|
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
if (axis === 'x') {
|
|
69
|
+
element.scrollBy({
|
|
70
|
+
left: value,
|
|
71
|
+
behavior: 'smooth',
|
|
72
|
+
})
|
|
73
|
+
} else {
|
|
74
|
+
element.scrollBy({
|
|
75
|
+
top: value,
|
|
76
|
+
behavior: 'smooth',
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
if ((0, types_1.isFn)(callback)) {
|
|
80
|
+
callback(value)
|
|
81
|
+
}
|
|
80
82
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.updateScrollValue = updateScrollValue
|
|
83
86
|
const scrollAnimate = (element, axis, direction, speed, callback) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
return (0, animation_1.createUniformSpeedAnimation)(speed, (delta) => {
|
|
88
|
+
;(0, exports.updateScrollValue)(
|
|
89
|
+
element,
|
|
90
|
+
axis,
|
|
91
|
+
direction === 'begin' ? 0 - delta : delta,
|
|
92
|
+
callback
|
|
93
|
+
)
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
exports.scrollAnimate = scrollAnimate
|
package/lib/subscribable.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
declare const UNSUBSCRIBE_ID_SYMBOL: unique symbol
|
|
1
|
+
declare const UNSUBSCRIBE_ID_SYMBOL: unique symbol
|
|
2
2
|
export interface ISubscriber<Payload = any> {
|
|
3
|
-
|
|
3
|
+
(payload: Payload): void | boolean
|
|
4
4
|
}
|
|
5
5
|
export declare class Subscribable<ExtendsType = any> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
private subscribers
|
|
7
|
+
dispatch<T extends ExtendsType = any>(event: T, context?: any): boolean
|
|
8
|
+
subscribe(subscriber: ISubscriber): {
|
|
9
|
+
(): void
|
|
10
|
+
[UNSUBSCRIBE_ID_SYMBOL]: number
|
|
11
|
+
}
|
|
12
|
+
unsubscribe: (id?: number | string | (() => void)) => void
|
|
13
13
|
}
|
|
14
|
-
export {}
|
|
14
|
+
export {}
|
package/lib/subscribable.js
CHANGED
|
@@ -1,52 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.Subscribable = void 0
|
|
4
|
-
const types_1 = require(
|
|
5
|
-
const UNSUBSCRIBE_ID_SYMBOL = Symbol('UNSUBSCRIBE_ID_SYMBOL')
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.Subscribable = void 0
|
|
4
|
+
const types_1 = require('./types')
|
|
5
|
+
const UNSUBSCRIBE_ID_SYMBOL = Symbol('UNSUBSCRIBE_ID_SYMBOL')
|
|
6
6
|
class Subscribable {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
this.unsubscribe = (id) => {
|
|
12
|
-
if (id === undefined || id === null) {
|
|
13
|
-
for (const key in this.subscribers) {
|
|
14
|
-
this.unsubscribe(key);
|
|
15
|
-
}
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (!(0, types_1.isFn)(id)) {
|
|
19
|
-
delete this.subscribers[id];
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
delete this.subscribers[id[UNSUBSCRIBE_ID_SYMBOL]];
|
|
23
|
-
}
|
|
24
|
-
};
|
|
7
|
+
constructor() {
|
|
8
|
+
this.subscribers = {
|
|
9
|
+
index: 0,
|
|
25
10
|
}
|
|
26
|
-
|
|
27
|
-
|
|
11
|
+
this.unsubscribe = (id) => {
|
|
12
|
+
if (id === undefined || id === null) {
|
|
28
13
|
for (const key in this.subscribers) {
|
|
29
|
-
|
|
30
|
-
event['context'] = context;
|
|
31
|
-
if (this.subscribers[key](event) === false) {
|
|
32
|
-
interrupted = true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
14
|
+
this.unsubscribe(key)
|
|
35
15
|
}
|
|
36
|
-
return
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
if (!(0, types_1.isFn)(id)) {
|
|
19
|
+
delete this.subscribers[id]
|
|
20
|
+
} else {
|
|
21
|
+
delete this.subscribers[id[UNSUBSCRIBE_ID_SYMBOL]]
|
|
22
|
+
}
|
|
37
23
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
24
|
+
}
|
|
25
|
+
dispatch(event, context) {
|
|
26
|
+
let interrupted = false
|
|
27
|
+
for (const key in this.subscribers) {
|
|
28
|
+
if ((0, types_1.isFn)(this.subscribers[key])) {
|
|
29
|
+
event['context'] = context
|
|
30
|
+
if (this.subscribers[key](event) === false) {
|
|
31
|
+
interrupted = true
|
|
44
32
|
}
|
|
45
|
-
|
|
46
|
-
this.unsubscribe(id);
|
|
47
|
-
};
|
|
48
|
-
unsubscribe[UNSUBSCRIBE_ID_SYMBOL] = id;
|
|
49
|
-
return unsubscribe;
|
|
33
|
+
}
|
|
50
34
|
}
|
|
35
|
+
return interrupted ? false : true
|
|
36
|
+
}
|
|
37
|
+
subscribe(subscriber) {
|
|
38
|
+
let id
|
|
39
|
+
if ((0, types_1.isFn)(subscriber)) {
|
|
40
|
+
id = this.subscribers.index + 1
|
|
41
|
+
this.subscribers[id] = subscriber
|
|
42
|
+
this.subscribers.index++
|
|
43
|
+
}
|
|
44
|
+
const unsubscribe = () => {
|
|
45
|
+
this.unsubscribe(id)
|
|
46
|
+
}
|
|
47
|
+
unsubscribe[UNSUBSCRIBE_ID_SYMBOL] = id
|
|
48
|
+
return unsubscribe
|
|
49
|
+
}
|
|
51
50
|
}
|
|
52
|
-
exports.Subscribable = Subscribable
|
|
51
|
+
exports.Subscribable = Subscribable
|
package/lib/types.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export declare const getType: (obj: any) => any
|
|
2
|
-
export declare const isFn: (obj: unknown) => obj is (...args: any[]) => any
|
|
3
|
-
export declare const isWindow: (obj: unknown) => obj is Window
|
|
4
|
-
export declare const isHTMLElement: (obj: any) => obj is HTMLElement
|
|
5
|
-
export declare const isArr: (arg: any) => arg is any[]
|
|
6
|
-
export declare const isPlainObj: (obj: unknown) => obj is object
|
|
7
|
-
export declare const isStr: (obj: unknown) => obj is string
|
|
8
|
-
export declare const isBool: (obj: unknown) => obj is boolean
|
|
9
|
-
export declare const isNum: (obj: unknown) => obj is number
|
|
10
|
-
export declare const isObj: (val: unknown) => val is object
|
|
11
|
-
export declare const isRegExp: (obj: unknown) => obj is RegExp
|
|
12
|
-
export declare const isValid: (val: any) => boolean
|
|
13
|
-
export declare const isValidNumber: (val: any) => val is number
|
|
1
|
+
export declare const getType: (obj: any) => any
|
|
2
|
+
export declare const isFn: (obj: unknown) => obj is (...args: any[]) => any
|
|
3
|
+
export declare const isWindow: (obj: unknown) => obj is Window
|
|
4
|
+
export declare const isHTMLElement: (obj: any) => obj is HTMLElement
|
|
5
|
+
export declare const isArr: (arg: any) => arg is any[]
|
|
6
|
+
export declare const isPlainObj: (obj: unknown) => obj is object
|
|
7
|
+
export declare const isStr: (obj: unknown) => obj is string
|
|
8
|
+
export declare const isBool: (obj: unknown) => obj is boolean
|
|
9
|
+
export declare const isNum: (obj: unknown) => obj is number
|
|
10
|
+
export declare const isObj: (val: unknown) => val is object
|
|
11
|
+
export declare const isRegExp: (obj: unknown) => obj is RegExp
|
|
12
|
+
export declare const isValid: (val: any) => boolean
|
|
13
|
+
export declare const isValidNumber: (val: any) => val is number
|
package/lib/types.js
CHANGED
|
@@ -1,29 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.isValidNumber =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.isWindow =
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.isValidNumber =
|
|
4
|
+
exports.isValid =
|
|
5
|
+
exports.isRegExp =
|
|
6
|
+
exports.isObj =
|
|
7
|
+
exports.isNum =
|
|
8
|
+
exports.isBool =
|
|
9
|
+
exports.isStr =
|
|
10
|
+
exports.isPlainObj =
|
|
11
|
+
exports.isArr =
|
|
12
|
+
exports.isHTMLElement =
|
|
13
|
+
exports.isWindow =
|
|
14
|
+
exports.isFn =
|
|
15
|
+
exports.getType =
|
|
16
|
+
void 0
|
|
17
|
+
const isType = (type) => (obj) =>
|
|
18
|
+
obj != null &&
|
|
19
|
+
(Array.isArray(type) ? type : [type]).some(
|
|
20
|
+
(t) => (0, exports.getType)(obj) === `[object ${t}]`
|
|
21
|
+
)
|
|
22
|
+
const getType = (obj) => Object.prototype.toString.call(obj)
|
|
23
|
+
exports.getType = getType
|
|
24
|
+
exports.isFn = isType(['Function', 'AsyncFunction', 'GeneratorFunction'])
|
|
25
|
+
exports.isWindow = isType('Window')
|
|
14
26
|
const isHTMLElement = (obj) => {
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
exports.isHTMLElement = isHTMLElement
|
|
18
|
-
exports.isArr = Array.isArray
|
|
19
|
-
exports.isPlainObj = isType('Object')
|
|
20
|
-
exports.isStr = isType('String')
|
|
21
|
-
exports.isBool = isType('Boolean')
|
|
22
|
-
exports.isNum = isType('Number')
|
|
23
|
-
const isObj = (val) => typeof val === 'object'
|
|
24
|
-
exports.isObj = isObj
|
|
25
|
-
exports.isRegExp = isType('RegExp')
|
|
26
|
-
const isValid = (val) => val !== null && val !== undefined
|
|
27
|
-
exports.isValid = isValid
|
|
28
|
-
const isValidNumber = (val) => !isNaN(val) && (0, exports.isNum)(val)
|
|
29
|
-
exports.isValidNumber = isValidNumber
|
|
27
|
+
return obj?.['nodeName'] || obj?.['tagName']
|
|
28
|
+
}
|
|
29
|
+
exports.isHTMLElement = isHTMLElement
|
|
30
|
+
exports.isArr = Array.isArray
|
|
31
|
+
exports.isPlainObj = isType('Object')
|
|
32
|
+
exports.isStr = isType('String')
|
|
33
|
+
exports.isBool = isType('Boolean')
|
|
34
|
+
exports.isNum = isType('Number')
|
|
35
|
+
const isObj = (val) => typeof val === 'object'
|
|
36
|
+
exports.isObj = isObj
|
|
37
|
+
exports.isRegExp = isType('RegExp')
|
|
38
|
+
const isValid = (val) => val !== null && val !== undefined
|
|
39
|
+
exports.isValid = isValid
|
|
40
|
+
const isValidNumber = (val) => !isNaN(val) && (0, exports.isNum)(val)
|
|
41
|
+
exports.isValidNumber = isValidNumber
|
package/lib/uid.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function uid(len?: number): string
|
|
1
|
+
export declare function uid(len?: number): string
|
package/lib/uid.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.uid = void 0
|
|
4
|
-
let IDX = 36,
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.uid = void 0
|
|
4
|
+
let IDX = 36,
|
|
5
|
+
HEX = ''
|
|
6
|
+
while (IDX--) HEX += IDX.toString(36)
|
|
7
7
|
function uid(len) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
let str = '',
|
|
9
|
+
num = len || 11
|
|
10
|
+
while (num--) str += HEX[(Math.random() * 36) | 0]
|
|
11
|
+
return str
|
|
12
12
|
}
|
|
13
|
-
exports.uid = uid
|
|
13
|
+
exports.uid = uid
|