@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/observer.js CHANGED
@@ -1,47 +1,44 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- constructor(observer = () => { }) {
6
- this.connected = false;
7
- this.observe = (target) => {
8
- if (!target)
9
- return;
10
- this.resizeObserver?.observe(target);
11
- try {
12
- this.performanceObserver?.observe({
13
- entryTypes: ['paint', 'element', 'layout-shift', 'event'],
14
- });
15
- }
16
- catch (e) { }
17
- this.mutationObserver?.observe(target, {
18
- attributeFilter: ['style'],
19
- attributes: true,
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
@@ -1,10 +1,13 @@
1
- import 'requestidlecallback';
1
+ import 'requestidlecallback'
2
2
  export interface IIdleDeadline {
3
- didTimeout: boolean;
4
- timeRemaining: () => DOMHighResTimeStamp;
3
+ didTimeout: boolean
4
+ timeRemaining: () => DOMHighResTimeStamp
5
5
  }
6
6
  export interface IdleCallbackOptions {
7
- timeout?: number;
7
+ timeout?: number
8
8
  }
9
- export declare const requestIdle: (callback: (params: IIdleDeadline) => void, options?: IdleCallbackOptions) => number;
10
- export declare const cancelIdle: (id: number) => void;
9
+ export declare const requestIdle: (
10
+ callback: (params: IIdleDeadline) => void,
11
+ options?: IdleCallbackOptions
12
+ ) => number
13
+ export declare const cancelIdle: (id: number) => void
@@ -1,13 +1,16 @@
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");
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
- return globalThisPolyfill_1.globalThisPolyfill['requestIdleCallback'](callback, options);
8
- };
9
- exports.requestIdle = requestIdle;
7
+ return globalThisPolyfill_1.globalThisPolyfill['requestIdleCallback'](
8
+ callback,
9
+ options
10
+ )
11
+ }
12
+ exports.requestIdle = requestIdle
10
13
  const cancelIdle = (id) => {
11
- globalThisPolyfill_1.globalThisPolyfill['cancelIdleCallback'](id);
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
- direction: ScrollDirection;
5
- speedFactor: number;
6
- speed: number;
4
+ direction: ScrollDirection
5
+ speedFactor: number
6
+ speed: number
7
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;
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
- "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;
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
- else {
20
- begin = top;
21
- end = bottom;
22
- pos = y;
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
- 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;
47
+ }
48
+ return null
49
+ }
50
+ exports.calcAutoScrollBasicInfo = calcAutoScrollBasicInfo
43
51
  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
- }
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
- 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
- }
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
- exports.updateScrollValue = updateScrollValue;
83
+ }
84
+ }
85
+ exports.updateScrollValue = updateScrollValue
83
86
  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;
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
@@ -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
- (payload: Payload): void | boolean;
3
+ (payload: Payload): void | boolean
4
4
  }
5
5
  export declare class Subscribable<ExtendsType = any> {
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;
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 {}
@@ -1,52 +1,51 @@
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');
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
- constructor() {
8
- this.subscribers = {
9
- index: 0,
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
- dispatch(event, context) {
27
- let interrupted = false;
11
+ this.unsubscribe = (id) => {
12
+ if (id === undefined || id === null) {
28
13
  for (const key in this.subscribers) {
29
- if ((0, types_1.isFn)(this.subscribers[key])) {
30
- event['context'] = context;
31
- if (this.subscribers[key](event) === false) {
32
- interrupted = true;
33
- }
34
- }
14
+ this.unsubscribe(key)
35
15
  }
36
- return interrupted ? false : true;
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
- subscribe(subscriber) {
39
- let id;
40
- if ((0, types_1.isFn)(subscriber)) {
41
- id = this.subscribers.index + 1;
42
- this.subscribers[id] = subscriber;
43
- this.subscribers.index++;
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
- const unsubscribe = () => {
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidNumber = exports.isValid = exports.isRegExp = exports.isObj = exports.isNum = exports.isBool = exports.isStr = exports.isPlainObj = exports.isArr = exports.isHTMLElement = exports.isWindow = exports.isFn = exports.getType = void 0;
4
- const isType = (type) => (obj) => obj != null &&
5
- (Array.isArray(type) ? type : [type]).some((t) => (0, exports.getType)(obj) === `[object ${t}]`);
6
- const getType = (obj) => Object.prototype.toString.call(obj);
7
- exports.getType = getType;
8
- exports.isFn = isType([
9
- 'Function',
10
- 'AsyncFunction',
11
- 'GeneratorFunction',
12
- ]);
13
- exports.isWindow = isType('Window');
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
- return obj?.['nodeName'] || obj?.['tagName'];
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uid = void 0;
4
- let IDX = 36, HEX = '';
5
- while (IDX--)
6
- HEX += IDX.toString(36);
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
- let str = '', num = len || 11;
9
- while (num--)
10
- str += HEX[(Math.random() * 36) | 0];
11
- return str;
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
package/package.json CHANGED
@@ -1,6 +1,14 @@
1
1
  {
2
2
  "name": "@thienvu18/designable-shared",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
+ "homepage": "https://github.com/thienvu18/designable#readme",
5
+ "bugs": {
6
+ "url": "https://github.com/thienvu18/designable/issues"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/thienvu18/designable.git"
11
+ },
4
12
  "license": "MIT",
5
13
  "main": "lib/index.js",
6
14
  "module": "esm/index.js",
@@ -11,26 +19,18 @@
11
19
  "README.md",
12
20
  "LICENSE.md"
13
21
  ],
14
- "engines": {
15
- "node": ">=20 <25"
16
- },
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/thienvu18/designable.git"
20
- },
21
- "bugs": {
22
- "url": "https://github.com/thienvu18/designable/issues"
23
- },
24
- "homepage": "https://github.com/thienvu18/designable#readme",
25
22
  "scripts": {
26
23
  "build": "rimraf -rf lib esm && npm run build:cjs && npm run build:esm",
27
24
  "build:cjs": "tsc --project tsconfig.build.json --outDir lib",
28
25
  "build:esm": "tsc --project tsconfig.build.json --module es2020 --outDir esm"
29
26
  },
30
- "publishConfig": {
31
- "access": "public"
32
- },
33
27
  "dependencies": {
34
28
  "requestidlecallback": "^0.3.0"
29
+ },
30
+ "engines": {
31
+ "node": ">=20 <25"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
35
  }
36
36
  }