@@ -61,19 +61,19 @@ export class Canvas {
61
61
[ _gpu ] = false ;
62
62
[ _ctx ] : CanvasRenderingContext2D ;
63
63
64
- get _unsafePointer ( ) {
64
+ get _unsafePointer ( ) : Deno . PointerValue {
65
65
return this [ _ptr ] ;
66
66
}
67
67
68
- get width ( ) {
68
+ get width ( ) : number {
69
69
return this [ _width ] ;
70
70
}
71
71
72
72
set width ( width : number ) {
73
73
this . resize ( width , this [ _height ] ) ;
74
74
}
75
75
76
- get height ( ) {
76
+ get height ( ) : number {
77
77
return this [ _height ] ;
78
78
}
79
79
@@ -82,7 +82,7 @@ export class Canvas {
82
82
}
83
83
84
84
/** Whether Canvas is GPU backed */
85
- get gpu ( ) {
85
+ get gpu ( ) : boolean {
86
86
return this [ _gpu ] ;
87
87
}
88
88
@@ -123,7 +123,7 @@ export class Canvas {
123
123
* Encode the canvas image into a buffer in specified format
124
124
* and quality.
125
125
*/
126
- encode ( format : ImageFormat = "png" , quality = 100 ) {
126
+ encode ( format : ImageFormat = "png" , quality = 100 ) : Uint8Array {
127
127
const bufptr = sk_canvas_encode_image (
128
128
this [ _ptr ] ,
129
129
CFormat [ format ] ,
@@ -146,7 +146,7 @@ export class Canvas {
146
146
/**
147
147
* Creates a data url from the canvas data
148
148
*/
149
- toDataURL ( format : ImageFormat = "png" , quality = 100 ) {
149
+ toDataURL ( format : ImageFormat = "png" , quality = 100 ) : string {
150
150
const buffer = this . encode ( format , quality ) ;
151
151
return `data:image/${ format } ;base64,${ encodeBase64 ( buffer ) } ` ;
152
152
}
@@ -161,7 +161,7 @@ export class Canvas {
161
161
height ?: number ,
162
162
into ?: Uint8Array ,
163
163
colorSpace : ColorSpace = "srgb" ,
164
- ) {
164
+ ) : Uint8Array {
165
165
width = width ?? this [ _width ] ;
166
166
height = height ?? this [ _height ] ;
167
167
const pixels = into ?? new Uint8Array ( width * height * 4 ) ;
@@ -194,7 +194,7 @@ export class Canvas {
194
194
/**
195
195
* Resizes the Canvas to the specified dimensions
196
196
*/
197
- resize ( width : number , height : number ) {
197
+ resize ( width : number , height : number ) : void {
198
198
if ( this [ _width ] === width && this [ _height ] === height ) return ;
199
199
sk_canvas_set_size ( this [ _ptr ] , width , height ) ;
200
200
this [ _width ] = width ;
@@ -210,7 +210,7 @@ export class Canvas {
210
210
if ( this [ _gpu ] ) sk_canvas_flush ( this [ _ptr ] ) ;
211
211
}
212
212
213
- [ Symbol . for ( "Jupyter.display" ) ] ( ) {
213
+ [ Symbol . for ( "Jupyter.display" ) ] ( ) : Record < string , string > {
214
214
return {
215
215
"image/png" : encodeBase64 ( this . encode ( "png" ) ) ,
216
216
} ;
@@ -223,6 +223,6 @@ export class Canvas {
223
223
* Only pass `gpu: true` if you have an OpenGL context initialized
224
224
* and made current already.
225
225
*/
226
- export function createCanvas ( width : number , height : number , gpu ?: boolean ) {
226
+ export function createCanvas ( width : number , height : number , gpu ?: boolean ) : Canvas {
227
227
return new Canvas ( width , height , gpu ) ;
228
228
}
0 commit comments