1
- /* 说明 V 0.2.4
1
+ /* 说明 V 0.3.0
2
2
* 该组件提供了 canvas 的图片绘制与文本绘制功能,使用同步的语法完成异步绘制,简化原生 canvas 绘制语法。
3
3
* API:https://github.com/NalvyBoo/create-picture
4
4
* npm:https://www.npmjs.com/package/create-picture
5
5
* */
6
6
7
7
let saidHello = false ;
8
- const VERSION = '0.2.4 ' ;
8
+ const VERSION = '0.3.0 ' ;
9
9
const defaultProp = {
10
10
width : 750 ,
11
11
height : 1448 ,
@@ -28,18 +28,23 @@ const defaultFontStyle = {
28
28
} ;
29
29
export default class CreatePicture {
30
30
constructor ( { ...prop } = { } ) {
31
- prop = Object . assign ( prop , defaultProp ) ;
31
+ prop = Object . assign ( defaultProp , prop ) ;
32
32
this . canvas = document . createElement ( 'canvas' ) ;
33
33
this . ctx = this . canvas . getContext ( '2d' ) ;
34
34
[ this . canvas . width , this . canvas . height ] = [ Reflect . get ( prop , 'width' ) , Reflect . get ( prop , 'height' ) ] ;
35
35
this . map = new Map ( ) ;
36
36
this . pictureMap = new Map ( ) ;
37
37
this . sayHello ( ) ;
38
38
}
39
+ // V 0.2.4 即将废弃
39
40
drawPicture ( ...prop ) {
40
41
this . map . set ( prop , 'picture' ) ;
41
42
this . pictureMap . set ( prop , prop [ 0 ] ) ;
42
43
}
44
+ drawImage ( ...prop ) {
45
+ this . map . set ( prop , 'picture' ) ;
46
+ this . pictureMap . set ( prop , prop [ 0 ] ) ;
47
+ }
43
48
drawCirclePicture ( ...prop ) {
44
49
this . map . set ( prop , 'circlePicture' ) ;
45
50
this . pictureMap . set ( prop , prop [ 0 ] ) ;
@@ -108,13 +113,18 @@ export default class CreatePicture{
108
113
const promiseArr = [ ] ;
109
114
assetsArr . forEach ( ( item , index ) => {
110
115
promiseArr . push ( new Promise ( ( resolve ) => {
111
- const image = new Image ( ) ;
112
- imageArr . push ( image ) ;
113
- image . onload = ( ) => {
114
- resolve ( imageArr )
115
- } ;
116
- image . crossOrigin = 'anonymous' ;
117
- image . src = assetsArr [ index ] + '?corp' ;
116
+ if ( item instanceof HTMLCanvasElement ) {
117
+ imageArr . push ( item ) ;
118
+ resolve ( imageArr ) ;
119
+ } else {
120
+ const image = new Image ( ) ;
121
+ imageArr . push ( image ) ;
122
+ image . onload = ( ) => {
123
+ resolve ( imageArr )
124
+ } ;
125
+ image . crossOrigin = 'anonymous' ;
126
+ image . src = assetsArr [ index ] + '?corp' ;
127
+ }
118
128
} ) ) ;
119
129
} ) ;
120
130
return Promise . all ( promiseArr ) ;
0 commit comments