forked from Automattic/node-canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test-d.ts
53 lines (39 loc) · 1.54 KB
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { expectAssignable, expectType } from 'tsd'
import * as path from 'path'
import { Readable } from 'stream'
import * as Canvas from './index'
Canvas.registerFont(path.join(__dirname, '../pfennigFont/Pfennig.ttf'), {family: 'pfennigFont'})
Canvas.createCanvas(5, 10)
Canvas.createCanvas(200, 200, 'pdf')
Canvas.createCanvas(150, 150, 'svg')
const canv = Canvas.createCanvas(10, 10)
const ctx = canv.getContext('2d')
canv.getContext('2d', {alpha: false})
// LHS is ImageData, not Canvas.ImageData
const id = ctx.getImageData(0, 0, 10, 10)
expectType<number>(id.height)
expectType<number>(id.width)
ctx.currentTransform = ctx.getTransform()
ctx.quality = 'best'
ctx.textDrawingMode = 'glyph'
const grad = ctx.createLinearGradient(0, 1, 2, 3)
expectType<Canvas.CanvasGradient>(grad)
grad.addColorStop(0.1, 'red')
const dm = new Canvas.DOMMatrix([1, 2, 3, 4, 5, 6])
expectType<number>(dm.a)
expectType<Buffer>(canv.toBuffer())
expectType<Buffer>(canv.toBuffer('application/pdf'))
canv.toBuffer((err, data) => {}, 'image/png', {filters: Canvas.Canvas.PNG_ALL_FILTERS})
expectAssignable<Readable>(canv.createJPEGStream({ quality: 0.5 }))
expectAssignable<Readable>(canv.createPDFStream({ author: 'octocat' }))
canv.toDataURL()
const img = new Canvas.Image()
img.src = Buffer.alloc(0)
img.dataMode = Canvas.Image.MODE_IMAGE | Canvas.Image.MODE_MIME
img.onload = () => {}
img.onload = null
const id2 = Canvas.createImageData(new Uint16Array(4), 1)
expectType<Canvas.ImageData>(id2)
ctx.putImageData(id2, 0, 0)
ctx.drawImage(canv, 0, 0)
Canvas.deregisterAllFonts()