Skip to content

Commit

Permalink
Merge pull request #29 from Jasery/feat-ts-support
Browse files Browse the repository at this point in the history
feat: 添加TypeScript 类型支持
  • Loading branch information
kiccer committed Jun 8, 2024
2 parents a0c68d1 + ea97def commit 48e8186
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ const buildConfig = [
babel: true,
uglify: true,
watch: true
},
{
name: 'types',
from: buildFrom + 'index.d.ts',
to: buildTo,
babel: false,
uglify: false,
watch: true
}
]

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "微信小程序 canvas-2d 绘图工具,支持按需引用,支持内容配置,支持功能扩展,适配各种机型,超轻量,超易用,无需学习,直接上手。",
"main": "miniprogram_dist",
"miniprogram": "miniprogram_dist",
"types": "miniprogram_dist/index.d.ts",
"files": [
"miniprogram_dist",
"postinstall.js"
Expand Down
81 changes: 81 additions & 0 deletions plugin/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
export class WxCanvas2d {
create(opts: {
query: string;
rootWidth?: number;
bgColor?: string;
component?: any;
radius?: number;
}) : Promise<void>;

draw(opts: { series: ISerie[] }) : Promise<void>;
clear(): void;

save(opts: {
x?: number;
y?: number;
width?: number;
height?: number;
destWidth?: number;
destHeight?: number;
modalOption?: {
title?: string;
content?: string;
success?: (res: { confirm: boolean, cancel: boolean }) => void;
};
}) : Promise<{ tempFilePath: string }>;

static use(plugin: IPlugin): void;
}

export interface ISerieType {
name: string;
handler: (config: Exclude<ISerie, 'type'>) => Promise<void>;
}

export interface IPlugin {
name: string;
handler: (opt: any) => void;
}

export interface ISerie {
type: ISerieType;
x?: number;
y?: number;
width?: number;
height?: number;
bgColor?: string;
radius?: number;
lineStyle?: {
color?: string;
width?: number;
dash?: number[];
};
zIndex?: number;
reverse?: boolean;
r?: number;
blur?: number;
url?: string;
mode?: string;
text?: string;
fontSize?: number;
lineHeight?: number;
ellipsis?: number;
color?: string;
align?: string;
baseline?: string;
fontWeight?: string;
line?: { point: [number, number] }[];
'line.point'?: [number, number];
size?: number;
}

export const Arc: ISerieType;
export const Blur: ISerieType;
export const Image: ISerieType;
export const Line: ISerieType;
export const Qrcode: ISerieType;
export const Rect: ISerieType;
export const Text: ISerieType;

export const Debugger: IPlugin;
export const SaveToAlbum: IPlugin;

0 comments on commit 48e8186

Please sign in to comment.