@loickit/shared 0.0.4 → 0.0.6
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/README.md +22 -0
- package/dist/index.d.mts +26 -5
- package/dist/index.d.ts +26 -5
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,3 +8,25 @@ loickit shared lib
|
|
|
8
8
|
|
|
9
9
|
点赞小工具
|
|
10
10
|
|
|
11
|
+
### IntervalFn
|
|
12
|
+
|
|
13
|
+
间隔执行函数, 可以随时修改 delay, 即时生效
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const intervalFn = new IntervalFn(
|
|
17
|
+
(...args: string[]) => {
|
|
18
|
+
console.log('intervalFn', args);
|
|
19
|
+
},
|
|
20
|
+
1000,
|
|
21
|
+
'arg1',
|
|
22
|
+
'arg2'
|
|
23
|
+
);
|
|
24
|
+
intervalFn.run('otherArg1', 'otherArg2');
|
|
25
|
+
intervalFn.pause();
|
|
26
|
+
intervalFn.reset();
|
|
27
|
+
intervalFn.restart('otherArg1', 'otherArg2');
|
|
28
|
+
|
|
29
|
+
console.log(intervalFn.record);
|
|
30
|
+
|
|
31
|
+
intervalFn.maxRecord = 2;
|
|
32
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -11,16 +11,37 @@ declare class Like {
|
|
|
11
11
|
|
|
12
12
|
declare class IntervalFn {
|
|
13
13
|
timer: ReturnType<typeof setTimeout> | undefined;
|
|
14
|
-
fn: (p: any[]) => any;
|
|
14
|
+
fn: (...p: any[]) => any;
|
|
15
15
|
delay: number;
|
|
16
16
|
args: any[];
|
|
17
17
|
record: number;
|
|
18
18
|
maxRecord: number;
|
|
19
|
-
constructor(fn: (p: any[]) => any, delay: number, ...args: any[]);
|
|
20
|
-
run(): void;
|
|
19
|
+
constructor(fn: (...p: any[]) => any, delay: number, ...args: any[]);
|
|
20
|
+
run(...otherArgs: any[]): void;
|
|
21
21
|
pause(): void;
|
|
22
22
|
reset(): void;
|
|
23
|
-
restart(): void;
|
|
23
|
+
restart(...otherArgs: any[]): void;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
type DeviceDetectType = 'weixin' | 'mobile' | 'ios' | 'android' | 'iphone' | 'ipad' | null;
|
|
27
|
+
|
|
28
|
+
declare function is(deviceType?: DeviceDetectType): boolean;
|
|
29
|
+
declare function isWeixin(): boolean;
|
|
30
|
+
declare function isMobile(): boolean;
|
|
31
|
+
declare function isIos(): boolean;
|
|
32
|
+
declare function isAndroid(): boolean;
|
|
33
|
+
declare function isIphone(): boolean;
|
|
34
|
+
declare function isIpad(): boolean;
|
|
35
|
+
declare const deviceDetect: {
|
|
36
|
+
is: typeof is;
|
|
37
|
+
isWeixin: typeof isWeixin;
|
|
38
|
+
isMobile: typeof isMobile;
|
|
39
|
+
isIos: typeof isIos;
|
|
40
|
+
isAndroid: typeof isAndroid;
|
|
41
|
+
isIphone: typeof isIphone;
|
|
42
|
+
isIpad: typeof isIpad;
|
|
43
|
+
isWechatMP: () => boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { IntervalFn, Like, deviceDetect };
|
|
47
|
+
export type { DeviceDetectType };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,16 +11,37 @@ declare class Like {
|
|
|
11
11
|
|
|
12
12
|
declare class IntervalFn {
|
|
13
13
|
timer: ReturnType<typeof setTimeout> | undefined;
|
|
14
|
-
fn: (p: any[]) => any;
|
|
14
|
+
fn: (...p: any[]) => any;
|
|
15
15
|
delay: number;
|
|
16
16
|
args: any[];
|
|
17
17
|
record: number;
|
|
18
18
|
maxRecord: number;
|
|
19
|
-
constructor(fn: (p: any[]) => any, delay: number, ...args: any[]);
|
|
20
|
-
run(): void;
|
|
19
|
+
constructor(fn: (...p: any[]) => any, delay: number, ...args: any[]);
|
|
20
|
+
run(...otherArgs: any[]): void;
|
|
21
21
|
pause(): void;
|
|
22
22
|
reset(): void;
|
|
23
|
-
restart(): void;
|
|
23
|
+
restart(...otherArgs: any[]): void;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
type DeviceDetectType = 'weixin' | 'mobile' | 'ios' | 'android' | 'iphone' | 'ipad' | null;
|
|
27
|
+
|
|
28
|
+
declare function is(deviceType?: DeviceDetectType): boolean;
|
|
29
|
+
declare function isWeixin(): boolean;
|
|
30
|
+
declare function isMobile(): boolean;
|
|
31
|
+
declare function isIos(): boolean;
|
|
32
|
+
declare function isAndroid(): boolean;
|
|
33
|
+
declare function isIphone(): boolean;
|
|
34
|
+
declare function isIpad(): boolean;
|
|
35
|
+
declare const deviceDetect: {
|
|
36
|
+
is: typeof is;
|
|
37
|
+
isWeixin: typeof isWeixin;
|
|
38
|
+
isMobile: typeof isMobile;
|
|
39
|
+
isIos: typeof isIos;
|
|
40
|
+
isAndroid: typeof isAndroid;
|
|
41
|
+
isIphone: typeof isIphone;
|
|
42
|
+
isIpad: typeof isIpad;
|
|
43
|
+
isWechatMP: () => boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { IntervalFn, Like, deviceDetect };
|
|
47
|
+
export type { DeviceDetectType };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class t{createElement;width;height;constructor(t,{width:
|
|
1
|
+
class t{createElement;width;height;constructor(t,{width:i,height:e}){this.width=i,this.height=e,this.createElement=t}play(t,i){const e=this.createElement();e.style.position="fixed",e.style.width=this.width+"px",e.style.height=this.height+"px",e.style.left=t-parseInt(e.style.width)/2+"px",e.style.top=i-parseInt(e.style.height)-10+"px";const s=new KeyframeEffect(e,[{transform:"scale(1)",opacity:.5},{transform:`scale(1.5) translateY(-${this.height/2}px)`,opacity:.9},{transform:`scale(1.5) translateY(-${this.height/2+10}px)`,opacity:0}],{duration:600,iterations:1,easing:"linear"});document.body.appendChild(e);const n=new Animation(s,document.timeline);n.onfinish=()=>{e.remove()},n.play()}}class i{timer;fn;delay;args;record;maxRecord;constructor(t,i,...e){this.fn=t,this.delay=i,this.args=e,this.timer=void 0,this.record=0,this.maxRecord=1/0}run(...t){this.fn.apply(this,this.args.concat(t)),this.record++,this.record>=this.maxRecord&&this.pause.call(this),this.timer=setTimeout(this.run.bind(this),this.delay)}pause(){clearTimeout(this.timer),this.timer=void 0}reset(){this.pause.call(this),this.record=0}restart(...t){this.reset.call(this),this.run.apply(this,t)}}const e={weixin:/micromessenger/i,mobile:/AppleWebKit.*Mobile.*/,ios:/\(i[^;]+;( U;)? CPU.+Mac OS X/,android:/Android|Adr/,iphone:/iPhone/,ipad:/iPad/},s=new Map;function n(t=null){if(s.has(t))return s.get(t);if(null===t)return!0;const{userAgent:i}=window.navigator;if(!e[t])return console.warn("deviceType is not support"),!1;const n=e[t].test(i);return s.set(t,n),n}const r={is:n,isWeixin:function(){return n("weixin")},isMobile:function(){return n("mobile")},isIos:function(){return n("ios")},isAndroid:function(){return n("android")},isIphone:function(){return n("iphone")},isIpad:function(){return n("ipad")},isWechatMP:()=>!(!navigator.userAgent.match(/micromessenger/i)||!navigator.userAgent.match(/miniprogram/i))||"miniprogram"===window.__wxjs_environment};export{i as IntervalFn,t as Like,r as deviceDetect};
|