@vnpn/lucky-canvas-core 1.7.26
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/LICENSE +201 -0
- package/README.md +42 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +1 -0
- package/dist/index.umd.js.map +1 -0
- package/index.js +1 -0
- package/package.json +71 -0
- package/types/index.d.ts +751 -0
- package/types/src/index.d.ts +4 -0
- package/types/src/lib/grid.d.ts +130 -0
- package/types/src/lib/lucky.d.ts +128 -0
- package/types/src/lib/slot.d.ts +109 -0
- package/types/src/lib/wheel.d.ts +109 -0
- package/types/src/observer/array.d.ts +2 -0
- package/types/src/observer/dep.d.ts +18 -0
- package/types/src/observer/index.d.ts +23 -0
- package/types/src/observer/utils.d.ts +4 -0
- package/types/src/observer/watcher.d.ts +30 -0
- package/types/src/types/grid.d.ts +85 -0
- package/types/src/types/index.d.ts +59 -0
- package/types/src/types/slot.d.ts +69 -0
- package/types/src/types/wheel.d.ts +59 -0
- package/types/src/utils/image.d.ts +29 -0
- package/types/src/utils/index.d.ts +53 -0
- package/types/src/utils/math.d.ts +26 -0
- package/types/src/utils/polyfill.d.ts +0 -0
- package/types/src/utils/tween.d.ts +21 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export type FontItemType = {
|
|
2
|
+
text: string;
|
|
3
|
+
top?: string | number;
|
|
4
|
+
left?: string | number;
|
|
5
|
+
fontColor?: string;
|
|
6
|
+
fontSize?: string;
|
|
7
|
+
fontStyle?: string;
|
|
8
|
+
fontWeight?: string;
|
|
9
|
+
lineHeight?: string;
|
|
10
|
+
};
|
|
11
|
+
export type FontExtendType = {
|
|
12
|
+
wordWrap?: boolean;
|
|
13
|
+
lengthLimit?: string | number;
|
|
14
|
+
lineClamp?: number;
|
|
15
|
+
};
|
|
16
|
+
export type ImgType = HTMLImageElement | HTMLCanvasElement;
|
|
17
|
+
export type ImgItemType = {
|
|
18
|
+
src: string;
|
|
19
|
+
top?: string | number;
|
|
20
|
+
left?: string | number;
|
|
21
|
+
width?: string;
|
|
22
|
+
height?: string;
|
|
23
|
+
formatter?: (img: ImgType) => ImgType;
|
|
24
|
+
$resolve?: Function;
|
|
25
|
+
$reject?: Function;
|
|
26
|
+
};
|
|
27
|
+
export type BorderRadiusType = string | number;
|
|
28
|
+
export type BackgroundType = string;
|
|
29
|
+
export type ShadowType = string;
|
|
30
|
+
export type ConfigType = {
|
|
31
|
+
nodeType?: number;
|
|
32
|
+
flag: 'WEB' | 'MP-WX' | 'UNI-H5' | 'UNI-MP' | 'TARO-H5' | 'TARO-MP';
|
|
33
|
+
el?: string;
|
|
34
|
+
divElement?: HTMLDivElement;
|
|
35
|
+
canvasElement?: HTMLCanvasElement;
|
|
36
|
+
ctx: CanvasRenderingContext2D;
|
|
37
|
+
dpr: number;
|
|
38
|
+
handleCssUnit?: (num: number, unit: string) => number;
|
|
39
|
+
rAF?: Function;
|
|
40
|
+
setTimeout: Function;
|
|
41
|
+
setInterval: Function;
|
|
42
|
+
clearTimeout: Function;
|
|
43
|
+
clearInterval: Function;
|
|
44
|
+
beforeCreate?: Function;
|
|
45
|
+
beforeResize?: Function;
|
|
46
|
+
afterResize?: Function;
|
|
47
|
+
beforeInit?: Function;
|
|
48
|
+
afterInit?: Function;
|
|
49
|
+
beforeDraw?: Function;
|
|
50
|
+
afterDraw?: Function;
|
|
51
|
+
afterStart?: Function;
|
|
52
|
+
};
|
|
53
|
+
export type UserConfigType = Partial<ConfigType>;
|
|
54
|
+
export type UniImageType = {
|
|
55
|
+
path: string;
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
};
|
|
59
|
+
export type Tuple<T, Len extends number, Res extends T[] = []> = Res['length'] extends Len ? Res : Tuple<T, Len, [...Res, T]>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { FontItemType, ImgItemType, BorderRadiusType, BackgroundType, FontExtendType } from './index';
|
|
2
|
+
export type PrizeFontType = FontItemType & FontExtendType;
|
|
3
|
+
export type BlockImgType = ImgItemType & {};
|
|
4
|
+
export type PrizeImgType = ImgItemType;
|
|
5
|
+
export type BlockType = {
|
|
6
|
+
borderRadius?: BorderRadiusType;
|
|
7
|
+
background?: BackgroundType;
|
|
8
|
+
padding?: string;
|
|
9
|
+
paddingTop?: string | number;
|
|
10
|
+
paddingRight?: string | number;
|
|
11
|
+
paddingBottom?: string | number;
|
|
12
|
+
paddingLeft?: string | number;
|
|
13
|
+
imgs?: Array<BlockImgType>;
|
|
14
|
+
};
|
|
15
|
+
export type PrizeType = {
|
|
16
|
+
borderRadius?: BorderRadiusType;
|
|
17
|
+
background?: BackgroundType;
|
|
18
|
+
fonts?: Array<PrizeFontType>;
|
|
19
|
+
imgs?: Array<PrizeImgType>;
|
|
20
|
+
};
|
|
21
|
+
export type SlotType = {
|
|
22
|
+
order?: number[];
|
|
23
|
+
speed?: number;
|
|
24
|
+
direction?: 1 | -1;
|
|
25
|
+
};
|
|
26
|
+
export type DefaultConfigType = {
|
|
27
|
+
/**
|
|
28
|
+
* vertical 为纵向旋转
|
|
29
|
+
* horizontal 为横向旋转
|
|
30
|
+
*/
|
|
31
|
+
mode?: 'vertical' | 'horizontal';
|
|
32
|
+
/**
|
|
33
|
+
* 当排列方向 = `vertical`时
|
|
34
|
+
* 1 bottom to top
|
|
35
|
+
* -1 top to bottom
|
|
36
|
+
* 当排列方向 = `horizontal`时
|
|
37
|
+
* 1 right to left
|
|
38
|
+
* -1 left to right
|
|
39
|
+
*/
|
|
40
|
+
direction?: 1 | -1;
|
|
41
|
+
rowSpacing?: number;
|
|
42
|
+
colSpacing?: number;
|
|
43
|
+
speed?: number;
|
|
44
|
+
accelerationTime?: number;
|
|
45
|
+
decelerationTime?: number;
|
|
46
|
+
};
|
|
47
|
+
export type DefaultStyleType = {
|
|
48
|
+
borderRadius?: BorderRadiusType;
|
|
49
|
+
background?: BackgroundType;
|
|
50
|
+
fontColor?: PrizeFontType['fontColor'];
|
|
51
|
+
fontSize?: PrizeFontType['fontSize'];
|
|
52
|
+
fontStyle?: PrizeFontType['fontStyle'];
|
|
53
|
+
fontWeight?: PrizeFontType['fontWeight'];
|
|
54
|
+
lineHeight?: PrizeFontType['lineHeight'];
|
|
55
|
+
wordWrap?: PrizeFontType['wordWrap'];
|
|
56
|
+
lengthLimit?: PrizeFontType['lengthLimit'];
|
|
57
|
+
lineClamp?: PrizeFontType['lineClamp'];
|
|
58
|
+
};
|
|
59
|
+
export type EndCallbackType = (prize: PrizeType | undefined) => void;
|
|
60
|
+
export default interface SlotMachineConfig {
|
|
61
|
+
width: string | number;
|
|
62
|
+
height: string | number;
|
|
63
|
+
blocks?: Array<BlockType>;
|
|
64
|
+
prizes?: Array<PrizeType>;
|
|
65
|
+
slots?: Array<SlotType>;
|
|
66
|
+
defaultConfig?: DefaultConfigType;
|
|
67
|
+
defaultStyle?: DefaultStyleType;
|
|
68
|
+
end?: EndCallbackType;
|
|
69
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { FontItemType, ImgItemType, BackgroundType, FontExtendType } from './index';
|
|
2
|
+
export type PrizeFontType = FontItemType & FontExtendType;
|
|
3
|
+
export type ButtonFontType = FontItemType & {};
|
|
4
|
+
export type BlockImgType = ImgItemType & {
|
|
5
|
+
rotate?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type PrizeImgType = ImgItemType & {};
|
|
8
|
+
export type ButtonImgType = ImgItemType & {};
|
|
9
|
+
export type BlockType = {
|
|
10
|
+
padding?: string;
|
|
11
|
+
background?: BackgroundType;
|
|
12
|
+
imgs?: Array<BlockImgType>;
|
|
13
|
+
};
|
|
14
|
+
export type PrizeType = {
|
|
15
|
+
range?: number;
|
|
16
|
+
background?: BackgroundType;
|
|
17
|
+
fonts?: Array<PrizeFontType>;
|
|
18
|
+
imgs?: Array<PrizeImgType>;
|
|
19
|
+
};
|
|
20
|
+
export type ButtonType = {
|
|
21
|
+
radius?: string;
|
|
22
|
+
pointer?: boolean;
|
|
23
|
+
background?: BackgroundType;
|
|
24
|
+
fonts?: Array<ButtonFontType>;
|
|
25
|
+
imgs?: Array<ButtonImgType>;
|
|
26
|
+
};
|
|
27
|
+
export type DefaultConfigType = {
|
|
28
|
+
gutter?: string | number;
|
|
29
|
+
offsetDegree?: number;
|
|
30
|
+
speed?: number;
|
|
31
|
+
speedFunction?: string;
|
|
32
|
+
accelerationTime?: number;
|
|
33
|
+
decelerationTime?: number;
|
|
34
|
+
stopRange?: number;
|
|
35
|
+
};
|
|
36
|
+
export type DefaultStyleType = {
|
|
37
|
+
background?: BackgroundType;
|
|
38
|
+
fontColor?: PrizeFontType['fontColor'];
|
|
39
|
+
fontSize?: PrizeFontType['fontSize'];
|
|
40
|
+
fontStyle?: PrizeFontType['fontStyle'];
|
|
41
|
+
fontWeight?: PrizeFontType['fontWeight'];
|
|
42
|
+
lineHeight?: PrizeFontType['lineHeight'];
|
|
43
|
+
wordWrap?: PrizeFontType['wordWrap'];
|
|
44
|
+
lengthLimit?: PrizeFontType['lengthLimit'];
|
|
45
|
+
lineClamp?: PrizeFontType['lineClamp'];
|
|
46
|
+
};
|
|
47
|
+
export type StartCallbackType = (e: MouseEvent) => void;
|
|
48
|
+
export type EndCallbackType = (prize: object) => void;
|
|
49
|
+
export default interface LuckyWheelConfig {
|
|
50
|
+
width: string | number;
|
|
51
|
+
height: string | number;
|
|
52
|
+
blocks?: Array<BlockType>;
|
|
53
|
+
prizes?: Array<PrizeType>;
|
|
54
|
+
buttons?: Array<ButtonType>;
|
|
55
|
+
defaultConfig?: DefaultConfigType;
|
|
56
|
+
defaultStyle?: DefaultStyleType;
|
|
57
|
+
start?: StartCallbackType;
|
|
58
|
+
end?: EndCallbackType;
|
|
59
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ImgType } from '../types/index';
|
|
2
|
+
/**
|
|
3
|
+
* 根据路径获取图片对象
|
|
4
|
+
* @param { string } src 图片路径
|
|
5
|
+
* @returns { Promise<HTMLImageElement> } 图片标签
|
|
6
|
+
*/
|
|
7
|
+
export declare const getImage: (src: string) => Promise<ImgType>;
|
|
8
|
+
/**
|
|
9
|
+
* 切割圆角
|
|
10
|
+
* @param img 将要裁剪的图片对象
|
|
11
|
+
* @param radius 裁剪的圆角半径
|
|
12
|
+
* @returns 返回一个离屏 canvas 用于渲染
|
|
13
|
+
*/
|
|
14
|
+
export declare const cutRound: (img: ImgType, radius: number) => ImgType;
|
|
15
|
+
/**
|
|
16
|
+
* 透明度
|
|
17
|
+
* @param img 将要处理的图片对象
|
|
18
|
+
* @param opacity 透明度
|
|
19
|
+
* @returns 返回一个离屏 canvas 用于渲染
|
|
20
|
+
*/
|
|
21
|
+
export declare const opacity: (img: ImgType, opacity: number) => ImgType;
|
|
22
|
+
/**
|
|
23
|
+
* 高斯模糊
|
|
24
|
+
* @param img 将要处理的图片对象
|
|
25
|
+
* @param radius 模糊半径
|
|
26
|
+
* @returns 返回一个离屏 canvas 用于渲染
|
|
27
|
+
*/
|
|
28
|
+
export declare const blur: (img: ImgType, radius: number) => ImgType;
|
|
29
|
+
export declare const getBase64Image: () => void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断是否是期望的类型
|
|
3
|
+
* @param { unknown } param 将要判断的变量
|
|
4
|
+
* @param { ...string } types 期望的类型
|
|
5
|
+
* @return { boolean } 返回期望是否正确
|
|
6
|
+
*/
|
|
7
|
+
export declare const isExpectType: (param: unknown, ...types: string[]) => boolean;
|
|
8
|
+
export declare const get: (data: object, strKeys: string) => any;
|
|
9
|
+
export declare const has: (data: object, key: string | number) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 移除\n
|
|
12
|
+
* @param { string } str 将要处理的字符串
|
|
13
|
+
* @return { string } 返回新的字符串
|
|
14
|
+
*/
|
|
15
|
+
export declare const removeEnter: (str: string) => string;
|
|
16
|
+
/**
|
|
17
|
+
* 把任何数据类型转成数字
|
|
18
|
+
* @param num
|
|
19
|
+
*/
|
|
20
|
+
export declare const getNumber: (num: unknown) => number;
|
|
21
|
+
/**
|
|
22
|
+
* 判断颜色是否有效 (透明色 === 无效)
|
|
23
|
+
* @param color 颜色
|
|
24
|
+
*/
|
|
25
|
+
export declare const hasBackground: (color: string | undefined | null) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* 通过padding计算
|
|
28
|
+
* @return { object } block 边框信息
|
|
29
|
+
*/
|
|
30
|
+
export declare const computePadding: (block: {
|
|
31
|
+
padding?: string | undefined;
|
|
32
|
+
}, getLength: Function) => [number, number, number, number];
|
|
33
|
+
/**
|
|
34
|
+
* 节流函数
|
|
35
|
+
* @param fn 将要处理的函数
|
|
36
|
+
* @param wait 时间, 单位为毫秒
|
|
37
|
+
* @returns 包装好的节流函数
|
|
38
|
+
*/
|
|
39
|
+
export declare const throttle: (fn: Function, wait?: number) => (this: any, ...args: any[]) => void;
|
|
40
|
+
/**
|
|
41
|
+
* 通过概率计算出一个奖品索引
|
|
42
|
+
* @param { Array<number | undefined> } rangeArr 概率
|
|
43
|
+
* @returns { number } 中奖索引
|
|
44
|
+
*/
|
|
45
|
+
export declare const computeRange: (rangeArr: Array<number | undefined>) => number;
|
|
46
|
+
/**
|
|
47
|
+
* 根据宽度分割字符串, 来达到换行的效果
|
|
48
|
+
* @param text
|
|
49
|
+
* @param maxWidth
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
export declare const splitText: (ctx: CanvasRenderingContext2D, text: string, getWidth: (lines: string[]) => number, lineClamp?: number) => string[];
|
|
53
|
+
export declare const getSortedArrayByIndex: <T>(arr: T[], order: number[]) => T[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 转换为运算角度
|
|
3
|
+
* @param { number } deg 数学角度
|
|
4
|
+
* @return { number } 运算角度
|
|
5
|
+
*/
|
|
6
|
+
export declare const getAngle: (deg: number) => number;
|
|
7
|
+
/**
|
|
8
|
+
* 根据角度计算圆上的点
|
|
9
|
+
* @param { number } deg 运算角度
|
|
10
|
+
* @param { number } r 半径
|
|
11
|
+
* @return { Array<number> } 坐标[x, y]
|
|
12
|
+
*/
|
|
13
|
+
export declare const getArcPointerByDeg: (deg: number, r: number) => [number, number];
|
|
14
|
+
/**
|
|
15
|
+
* 根据点计算切线方程
|
|
16
|
+
* @param { number } x 横坐标
|
|
17
|
+
* @param { number } y 纵坐标
|
|
18
|
+
* @return { Array<number> } [斜率, 常数]
|
|
19
|
+
*/
|
|
20
|
+
export declare const getTangentByPointer: (x: number, y: number) => Array<number>;
|
|
21
|
+
export declare const fanShapedByArc: (ctx: CanvasRenderingContext2D, minRadius: number, maxRadius: number, start: number, end: number, gutter: number) => void;
|
|
22
|
+
export declare const roundRectByArc: (ctx: CanvasRenderingContext2D, ...[x, y, w, h, r]: number[]) => void;
|
|
23
|
+
/**
|
|
24
|
+
* 创建线性渐变色
|
|
25
|
+
*/
|
|
26
|
+
export declare const getLinearGradient: (ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, background: string) => any;
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 缓动函数
|
|
3
|
+
* t: current time(当前时间)
|
|
4
|
+
* b: beginning value(初始值)
|
|
5
|
+
* c: change in value(变化量)
|
|
6
|
+
* d: duration(持续时间)
|
|
7
|
+
*
|
|
8
|
+
* 感谢张鑫旭大佬 https://github.com/zhangxinxu/Tween
|
|
9
|
+
*/
|
|
10
|
+
interface SpeedType {
|
|
11
|
+
easeIn: (...arr: number[]) => number;
|
|
12
|
+
easeOut: (...arr: number[]) => number;
|
|
13
|
+
}
|
|
14
|
+
export declare const quad: SpeedType;
|
|
15
|
+
export declare const cubic: SpeedType;
|
|
16
|
+
export declare const quart: SpeedType;
|
|
17
|
+
export declare const quint: SpeedType;
|
|
18
|
+
export declare const sine: SpeedType;
|
|
19
|
+
export declare const expo: SpeedType;
|
|
20
|
+
export declare const circ: SpeedType;
|
|
21
|
+
export {};
|