@napi-rs/canvas 0.1.74 → 0.1.76
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/index.d.ts +8 -0
- package/index.js +27 -1
- package/package.json +12 -12
package/index.d.ts
CHANGED
|
@@ -626,6 +626,11 @@ export enum ChromaSubsampling {
|
|
|
626
626
|
Yuv400 = 3,
|
|
627
627
|
}
|
|
628
628
|
|
|
629
|
+
export interface ConvertToBlobOptions {
|
|
630
|
+
mime?: string
|
|
631
|
+
quality?: number
|
|
632
|
+
}
|
|
633
|
+
|
|
629
634
|
export class Canvas {
|
|
630
635
|
constructor(width: number, height: number, flag?: SvgExportFlag)
|
|
631
636
|
|
|
@@ -654,6 +659,9 @@ export class Canvas {
|
|
|
654
659
|
toDataURLAsync(mime: 'image/jpeg' | 'image/webp', quality?: number): Promise<string>
|
|
655
660
|
toDataURLAsync(mime?: 'image/jpeg' | 'image/webp' | 'image/png', quality?: number): Promise<string>
|
|
656
661
|
toDataURLAsync(mime?: 'image/avif', cfg?: AvifConfig): Promise<string>
|
|
662
|
+
|
|
663
|
+
toBlob(callback: (blob: Blob | null) => void, mime?: string, quality?: number): void
|
|
664
|
+
convertToBlob(options?: ConvertToBlobOptions): Promise<Blob>
|
|
657
665
|
}
|
|
658
666
|
|
|
659
667
|
export function createCanvas(width: number, height: number): Canvas
|
package/index.js
CHANGED
|
@@ -47,6 +47,32 @@ if (!('has' in GlobalFonts)) {
|
|
|
47
47
|
})
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
const _toBlob = CanvasElement.prototype.toBlob
|
|
51
|
+
const _convertToBlob = CanvasElement.prototype.convertToBlob
|
|
52
|
+
if ('Blob' in globalThis) {
|
|
53
|
+
CanvasElement.prototype.toBlob = function toBlob(callback, mimeType, quality) {
|
|
54
|
+
_toBlob.call(this, function(/** @type {Uint8Array} */ imageBuffer) {
|
|
55
|
+
const blob = new Blob([imageBuffer.buffer], { type: mimeType })
|
|
56
|
+
callback(blob)
|
|
57
|
+
}, mimeType, quality)
|
|
58
|
+
}
|
|
59
|
+
CanvasElement.prototype.convertToBlob = function convertToBlob(options) {
|
|
60
|
+
return _convertToBlob.call(this, options).then((/** @type {Uint8Array} */ imageBuffer) => {
|
|
61
|
+
const blob = new Blob([imageBuffer.buffer], { type: options?.mime || 'image/png' })
|
|
62
|
+
return blob
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
// oxlint-disable-next-line no-unused-vars
|
|
67
|
+
CanvasElement.prototype.toBlob = function toBlob(callback, mimeType, quality) {
|
|
68
|
+
callback(null)
|
|
69
|
+
}
|
|
70
|
+
// oxlint-disable-next-line no-unused-vars
|
|
71
|
+
CanvasElement.prototype.convertToBlob = function convertToBlob(options) {
|
|
72
|
+
return Promise.reject(new Error('Blob is not supported in this environment'))
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
50
76
|
const _getTransform = CanvasRenderingContext2D.prototype.getTransform
|
|
51
77
|
|
|
52
78
|
CanvasRenderingContext2D.prototype.getTransform = function getTransform() {
|
|
@@ -85,7 +111,7 @@ CanvasRenderingContext2D.prototype.drawImage = function drawImage(image, ...args
|
|
|
85
111
|
}
|
|
86
112
|
}
|
|
87
113
|
}
|
|
88
|
-
|
|
114
|
+
|
|
89
115
|
// Call the original drawImage with the potentially corrected image
|
|
90
116
|
return _drawImage.apply(this, [image, ...args])
|
|
91
117
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/canvas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.76",
|
|
4
4
|
"description": "Canvas for Node.js with skia backend",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@jimp/custom": "^0.22.12",
|
|
76
76
|
"@jimp/jpeg": "^0.22.12",
|
|
77
77
|
"@jimp/png": "^0.22.12",
|
|
78
|
-
"@napi-rs/cli": "^3.0.0
|
|
78
|
+
"@napi-rs/cli": "^3.0.0",
|
|
79
79
|
"@octokit/rest": "^22.0.0",
|
|
80
80
|
"@swc-node/register": "^1.10.10",
|
|
81
81
|
"@swc/core": "^1.11.31",
|
|
@@ -143,15 +143,15 @@
|
|
|
143
143
|
},
|
|
144
144
|
"packageManager": "yarn@4.9.2",
|
|
145
145
|
"optionalDependencies": {
|
|
146
|
-
"@napi-rs/canvas-linux-x64-gnu": "0.1.
|
|
147
|
-
"@napi-rs/canvas-darwin-x64": "0.1.
|
|
148
|
-
"@napi-rs/canvas-win32-x64-msvc": "0.1.
|
|
149
|
-
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.
|
|
150
|
-
"@napi-rs/canvas-linux-x64-musl": "0.1.
|
|
151
|
-
"@napi-rs/canvas-linux-arm64-gnu": "0.1.
|
|
152
|
-
"@napi-rs/canvas-linux-arm64-musl": "0.1.
|
|
153
|
-
"@napi-rs/canvas-darwin-arm64": "0.1.
|
|
154
|
-
"@napi-rs/canvas-android-arm64": "0.1.
|
|
155
|
-
"@napi-rs/canvas-linux-riscv64-gnu": "0.1.
|
|
146
|
+
"@napi-rs/canvas-linux-x64-gnu": "0.1.76",
|
|
147
|
+
"@napi-rs/canvas-darwin-x64": "0.1.76",
|
|
148
|
+
"@napi-rs/canvas-win32-x64-msvc": "0.1.76",
|
|
149
|
+
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.76",
|
|
150
|
+
"@napi-rs/canvas-linux-x64-musl": "0.1.76",
|
|
151
|
+
"@napi-rs/canvas-linux-arm64-gnu": "0.1.76",
|
|
152
|
+
"@napi-rs/canvas-linux-arm64-musl": "0.1.76",
|
|
153
|
+
"@napi-rs/canvas-darwin-arm64": "0.1.76",
|
|
154
|
+
"@napi-rs/canvas-android-arm64": "0.1.76",
|
|
155
|
+
"@napi-rs/canvas-linux-riscv64-gnu": "0.1.76"
|
|
156
156
|
}
|
|
157
157
|
}
|