@napi-rs/canvas 0.1.66 → 0.1.68
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/README.md +1 -1
- package/index.d.ts +10 -13
- package/index.js +2 -4
- package/js-binding.js +360 -242
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# `skr canvas`
|
|
2
2
|
|
|
3
3
|
[](https://github.com/Brooooooklyn/canvas/actions/workflows/CI.yaml)
|
|
4
|
-

|
|
5
5
|
[](https://packagephobia.com/result?p=@napi-rs/canvas)
|
|
6
6
|
[](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true)
|
|
7
7
|
|
package/index.d.ts
CHANGED
|
@@ -107,9 +107,7 @@ export interface DOMMatrix extends DOMMatrixReadOnly {
|
|
|
107
107
|
toJSON(): { [K in OmitNeverOfMatrix]: DOMMatrix[K] }
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
type OmitMatrixMethod = {
|
|
111
|
-
[K in keyof DOMMatrix]: DOMMatrix[K] extends (...args: any[]) => any ? never : K
|
|
112
|
-
}
|
|
110
|
+
type OmitMatrixMethod = { [K in keyof DOMMatrix]: DOMMatrix[K] extends (...args: any[]) => any ? never : K }
|
|
113
111
|
|
|
114
112
|
type OmitNeverOfMatrix = OmitMatrixMethod[keyof OmitMatrixMethod]
|
|
115
113
|
|
|
@@ -278,7 +276,7 @@ export interface SKRSContext2D
|
|
|
278
276
|
dh: number,
|
|
279
277
|
): void
|
|
280
278
|
createPattern(
|
|
281
|
-
image: Image | ImageData,
|
|
279
|
+
image: Image | ImageData | Canvas | SvgCanvas,
|
|
282
280
|
repeat: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' | null,
|
|
283
281
|
): CanvasPattern
|
|
284
282
|
getContextAttributes(): { alpha: boolean; desynchronized: boolean }
|
|
@@ -392,21 +390,20 @@ export function createCanvas(width: number, height: number): Canvas
|
|
|
392
390
|
|
|
393
391
|
export function createCanvas(width: number, height: number, svgExportFlag: SvgExportFlag): SvgCanvas
|
|
394
392
|
|
|
393
|
+
export declare class FontKey {
|
|
394
|
+
// make it a unique type
|
|
395
|
+
private readonly key: symbol
|
|
396
|
+
}
|
|
397
|
+
|
|
395
398
|
interface IGlobalFonts {
|
|
396
|
-
readonly families: {
|
|
397
|
-
family: string
|
|
398
|
-
styles: {
|
|
399
|
-
weight: number
|
|
400
|
-
width: string
|
|
401
|
-
style: string
|
|
402
|
-
}[]
|
|
403
|
-
}[]
|
|
399
|
+
readonly families: { family: string; styles: { weight: number; width: string; style: string }[] }[]
|
|
404
400
|
// return true if succeeded
|
|
405
|
-
register(font: Buffer, nameAlias?: string):
|
|
401
|
+
register(font: Buffer, nameAlias?: string): FontKey | null
|
|
406
402
|
// absolute path
|
|
407
403
|
registerFromPath(path: string, nameAlias?: string): boolean
|
|
408
404
|
has(name: string): boolean
|
|
409
405
|
loadFontsFromDir(path: string): number
|
|
406
|
+
remove(key: FontKey): void
|
|
410
407
|
}
|
|
411
408
|
|
|
412
409
|
export const GlobalFonts: IGlobalFonts
|
package/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const {
|
|
|
9
9
|
Path: Path2D,
|
|
10
10
|
ImageData,
|
|
11
11
|
Image,
|
|
12
|
-
|
|
12
|
+
FontKey,
|
|
13
13
|
GlobalFonts,
|
|
14
14
|
PathOp,
|
|
15
15
|
FillType,
|
|
@@ -28,9 +28,6 @@ const SvgExportFlag = {
|
|
|
28
28
|
RelativePathEncoding: 0x04,
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// eslint-disable-next-line sonarjs/no-unused-collection
|
|
32
|
-
const Fonts = []
|
|
33
|
-
|
|
34
31
|
if (!('families' in GlobalFonts)) {
|
|
35
32
|
Object.defineProperty(GlobalFonts, 'families', {
|
|
36
33
|
get: function () {
|
|
@@ -113,4 +110,5 @@ module.exports = {
|
|
|
113
110
|
DOMMatrix,
|
|
114
111
|
DOMRect,
|
|
115
112
|
loadImage,
|
|
113
|
+
FontKey,
|
|
116
114
|
}
|
package/js-binding.js
CHANGED
|
@@ -1,269 +1,387 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
|
+
const { readFileSync } = require('fs')
|
|
6
7
|
let nativeBinding = null
|
|
7
|
-
|
|
8
|
-
let loadError = null
|
|
8
|
+
const loadErrors = []
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const isMusl = () => {
|
|
11
|
+
let musl = false
|
|
12
|
+
if (process.platform === 'linux') {
|
|
13
|
+
musl = isMuslFromFilesystem()
|
|
14
|
+
if (musl === null) {
|
|
15
|
+
musl = isMuslFromReport()
|
|
16
|
+
}
|
|
17
|
+
if (musl === null) {
|
|
18
|
+
musl = isMuslFromChildProcess()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return musl
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
25
|
+
|
|
26
|
+
const isMuslFromFilesystem = () => {
|
|
27
|
+
try {
|
|
28
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
29
|
+
} catch {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isMuslFromReport = () => {
|
|
35
|
+
const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
|
|
36
|
+
if (!report) {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
43
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
16
44
|
return true
|
|
17
45
|
}
|
|
18
|
-
} else {
|
|
19
|
-
const { glibcVersionRuntime } = process.report.getReport().header
|
|
20
|
-
return !glibcVersionRuntime
|
|
21
46
|
}
|
|
47
|
+
return false
|
|
22
48
|
}
|
|
23
49
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
50
|
+
const isMuslFromChildProcess = () => {
|
|
51
|
+
try {
|
|
52
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
53
|
+
} catch (e) {
|
|
54
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
55
|
+
return false
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function requireNative() {
|
|
60
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
61
|
+
try {
|
|
62
|
+
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
loadErrors.push(err);
|
|
65
|
+
}
|
|
66
|
+
} else if (process.platform === 'android') {
|
|
67
|
+
if (process.arch === 'arm64') {
|
|
68
|
+
try {
|
|
69
|
+
return require('./skia.android-arm64.node')
|
|
70
|
+
} catch (e) {
|
|
71
|
+
loadErrors.push(e)
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
return require('@napi-rs/canvas-android-arm64')
|
|
75
|
+
} catch (e) {
|
|
76
|
+
loadErrors.push(e)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
} else if (process.arch === 'arm') {
|
|
80
|
+
try {
|
|
81
|
+
return require('./skia.android-arm-eabi.node')
|
|
82
|
+
} catch (e) {
|
|
83
|
+
loadErrors.push(e)
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
return require('@napi-rs/canvas-android-arm-eabi')
|
|
87
|
+
} catch (e) {
|
|
88
|
+
loadErrors.push(e)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
} else {
|
|
92
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
93
|
+
}
|
|
94
|
+
} else if (process.platform === 'win32') {
|
|
95
|
+
if (process.arch === 'x64') {
|
|
96
|
+
try {
|
|
97
|
+
return require('./skia.win32-x64-msvc.node')
|
|
98
|
+
} catch (e) {
|
|
99
|
+
loadErrors.push(e)
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
return require('@napi-rs/canvas-win32-x64-msvc')
|
|
103
|
+
} catch (e) {
|
|
104
|
+
loadErrors.push(e)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
} else if (process.arch === 'ia32') {
|
|
108
|
+
try {
|
|
109
|
+
return require('./skia.win32-ia32-msvc.node')
|
|
110
|
+
} catch (e) {
|
|
111
|
+
loadErrors.push(e)
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
return require('@napi-rs/canvas-win32-ia32-msvc')
|
|
115
|
+
} catch (e) {
|
|
116
|
+
loadErrors.push(e)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
} else if (process.arch === 'arm64') {
|
|
120
|
+
try {
|
|
121
|
+
return require('./skia.win32-arm64-msvc.node')
|
|
122
|
+
} catch (e) {
|
|
123
|
+
loadErrors.push(e)
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
return require('@napi-rs/canvas-win32-arm64-msvc')
|
|
127
|
+
} catch (e) {
|
|
128
|
+
loadErrors.push(e)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
} else {
|
|
132
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
133
|
+
}
|
|
134
|
+
} else if (process.platform === 'darwin') {
|
|
135
|
+
try {
|
|
136
|
+
return require('./skia.darwin-universal.node')
|
|
137
|
+
} catch (e) {
|
|
138
|
+
loadErrors.push(e)
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
return require('@napi-rs/canvas-darwin-universal')
|
|
142
|
+
} catch (e) {
|
|
143
|
+
loadErrors.push(e)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (process.arch === 'x64') {
|
|
147
|
+
try {
|
|
148
|
+
return require('./skia.darwin-x64.node')
|
|
149
|
+
} catch (e) {
|
|
150
|
+
loadErrors.push(e)
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
return require('@napi-rs/canvas-darwin-x64')
|
|
154
|
+
} catch (e) {
|
|
155
|
+
loadErrors.push(e)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
} else if (process.arch === 'arm64') {
|
|
159
|
+
try {
|
|
160
|
+
return require('./skia.darwin-arm64.node')
|
|
161
|
+
} catch (e) {
|
|
162
|
+
loadErrors.push(e)
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
return require('@napi-rs/canvas-darwin-arm64')
|
|
166
|
+
} catch (e) {
|
|
167
|
+
loadErrors.push(e)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
} else {
|
|
171
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
172
|
+
}
|
|
173
|
+
} else if (process.platform === 'freebsd') {
|
|
174
|
+
if (process.arch === 'x64') {
|
|
175
|
+
try {
|
|
176
|
+
return require('./skia.freebsd-x64.node')
|
|
177
|
+
} catch (e) {
|
|
178
|
+
loadErrors.push(e)
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
return require('@napi-rs/canvas-freebsd-x64')
|
|
182
|
+
} catch (e) {
|
|
183
|
+
loadErrors.push(e)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
} else if (process.arch === 'arm64') {
|
|
187
|
+
try {
|
|
188
|
+
return require('./skia.freebsd-arm64.node')
|
|
189
|
+
} catch (e) {
|
|
190
|
+
loadErrors.push(e)
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
return require('@napi-rs/canvas-freebsd-arm64')
|
|
194
|
+
} catch (e) {
|
|
195
|
+
loadErrors.push(e)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
} else {
|
|
199
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
200
|
+
}
|
|
201
|
+
} else if (process.platform === 'linux') {
|
|
202
|
+
if (process.arch === 'x64') {
|
|
203
|
+
if (isMusl()) {
|
|
29
204
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
205
|
+
return require('./skia.linux-x64-musl.node')
|
|
206
|
+
} catch (e) {
|
|
207
|
+
loadErrors.push(e)
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
return require('@napi-rs/canvas-linux-x64-musl')
|
|
211
|
+
} catch (e) {
|
|
212
|
+
loadErrors.push(e)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
} else {
|
|
41
216
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
case 'win32':
|
|
56
|
-
switch (arch) {
|
|
57
|
-
case 'x64':
|
|
58
|
-
localFileExisted = existsSync(join(__dirname, 'skia.win32-x64-msvc.node'))
|
|
217
|
+
return require('./skia.linux-x64-gnu.node')
|
|
218
|
+
} catch (e) {
|
|
219
|
+
loadErrors.push(e)
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
return require('@napi-rs/canvas-linux-x64-gnu')
|
|
223
|
+
} catch (e) {
|
|
224
|
+
loadErrors.push(e)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
} else if (process.arch === 'arm64') {
|
|
229
|
+
if (isMusl()) {
|
|
59
230
|
try {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
231
|
+
return require('./skia.linux-arm64-musl.node')
|
|
232
|
+
} catch (e) {
|
|
233
|
+
loadErrors.push(e)
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
return require('@napi-rs/canvas-linux-arm64-musl')
|
|
237
|
+
} catch (e) {
|
|
238
|
+
loadErrors.push(e)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
} else {
|
|
71
242
|
try {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
243
|
+
return require('./skia.linux-arm64-gnu.node')
|
|
244
|
+
} catch (e) {
|
|
245
|
+
loadErrors.push(e)
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
return require('@napi-rs/canvas-linux-arm64-gnu')
|
|
249
|
+
} catch (e) {
|
|
250
|
+
loadErrors.push(e)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
} else if (process.arch === 'arm') {
|
|
255
|
+
if (isMusl()) {
|
|
83
256
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
break
|
|
97
|
-
case 'darwin':
|
|
98
|
-
switch (arch) {
|
|
99
|
-
case 'x64':
|
|
100
|
-
localFileExisted = existsSync(join(__dirname, 'skia.darwin-x64.node'))
|
|
257
|
+
return require('./skia.linux-arm-musleabihf.node')
|
|
258
|
+
} catch (e) {
|
|
259
|
+
loadErrors.push(e)
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
return require('@napi-rs/canvas-linux-arm-musleabihf')
|
|
263
|
+
} catch (e) {
|
|
264
|
+
loadErrors.push(e)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
} else {
|
|
101
268
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
269
|
+
return require('./skia.linux-arm-gnueabihf.node')
|
|
270
|
+
} catch (e) {
|
|
271
|
+
loadErrors.push(e)
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
return require('@napi-rs/canvas-linux-arm-gnueabihf')
|
|
275
|
+
} catch (e) {
|
|
276
|
+
loadErrors.push(e)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
}
|
|
280
|
+
} else if (process.arch === 'riscv64') {
|
|
281
|
+
if (isMusl()) {
|
|
113
282
|
try {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
283
|
+
return require('./skia.linux-riscv64-musl.node')
|
|
284
|
+
} catch (e) {
|
|
285
|
+
loadErrors.push(e)
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
return require('@napi-rs/canvas-linux-riscv64-musl')
|
|
289
|
+
} catch (e) {
|
|
290
|
+
loadErrors.push(e)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
} else {
|
|
294
|
+
try {
|
|
295
|
+
return require('./skia.linux-riscv64-gnu.node')
|
|
296
|
+
} catch (e) {
|
|
297
|
+
loadErrors.push(e)
|
|
298
|
+
}
|
|
299
|
+
try {
|
|
300
|
+
return require('@napi-rs/canvas-linux-riscv64-gnu')
|
|
301
|
+
} catch (e) {
|
|
302
|
+
loadErrors.push(e)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
}
|
|
306
|
+
} else if (process.arch === 'ppc64') {
|
|
307
|
+
try {
|
|
308
|
+
return require('./skia.linux-ppc64-gnu.node')
|
|
309
|
+
} catch (e) {
|
|
310
|
+
loadErrors.push(e)
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
return require('@napi-rs/canvas-linux-ppc64-gnu')
|
|
314
|
+
} catch (e) {
|
|
315
|
+
loadErrors.push(e)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
} else if (process.arch === 's390x') {
|
|
319
|
+
try {
|
|
320
|
+
return require('./skia.linux-s390x-gnu.node')
|
|
321
|
+
} catch (e) {
|
|
322
|
+
loadErrors.push(e)
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
return require('@napi-rs/canvas-linux-s390x-gnu')
|
|
326
|
+
} catch (e) {
|
|
327
|
+
loadErrors.push(e)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
} else {
|
|
331
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
125
332
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
333
|
+
} else {
|
|
334
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
nativeBinding = requireNative()
|
|
339
|
+
|
|
340
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
341
|
+
try {
|
|
342
|
+
nativeBinding = require('./skia.wasi.cjs')
|
|
343
|
+
} catch (err) {
|
|
344
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
345
|
+
loadErrors.push(err)
|
|
130
346
|
}
|
|
131
|
-
|
|
347
|
+
}
|
|
348
|
+
if (!nativeBinding) {
|
|
132
349
|
try {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
350
|
+
nativeBinding = require('@napi-rs/canvas-wasm32-wasi')
|
|
351
|
+
} catch (err) {
|
|
352
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
353
|
+
loadErrors.push(err)
|
|
137
354
|
}
|
|
138
|
-
} catch (e) {
|
|
139
|
-
loadError = e
|
|
140
|
-
}
|
|
141
|
-
break
|
|
142
|
-
case 'linux':
|
|
143
|
-
switch (arch) {
|
|
144
|
-
case 'x64':
|
|
145
|
-
if (isMusl()) {
|
|
146
|
-
localFileExisted = existsSync(join(__dirname, 'skia.linux-x64-musl.node'))
|
|
147
|
-
try {
|
|
148
|
-
if (localFileExisted) {
|
|
149
|
-
nativeBinding = require('./skia.linux-x64-musl.node')
|
|
150
|
-
} else {
|
|
151
|
-
nativeBinding = require('@napi-rs/canvas-linux-x64-musl')
|
|
152
|
-
}
|
|
153
|
-
} catch (e) {
|
|
154
|
-
loadError = e
|
|
155
|
-
}
|
|
156
|
-
} else {
|
|
157
|
-
localFileExisted = existsSync(join(__dirname, 'skia.linux-x64-gnu.node'))
|
|
158
|
-
try {
|
|
159
|
-
if (localFileExisted) {
|
|
160
|
-
nativeBinding = require('./skia.linux-x64-gnu.node')
|
|
161
|
-
} else {
|
|
162
|
-
nativeBinding = require('@napi-rs/canvas-linux-x64-gnu')
|
|
163
|
-
}
|
|
164
|
-
} catch (e) {
|
|
165
|
-
loadError = e
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
break
|
|
169
|
-
case 'arm64':
|
|
170
|
-
if (isMusl()) {
|
|
171
|
-
localFileExisted = existsSync(join(__dirname, 'skia.linux-arm64-musl.node'))
|
|
172
|
-
try {
|
|
173
|
-
if (localFileExisted) {
|
|
174
|
-
nativeBinding = require('./skia.linux-arm64-musl.node')
|
|
175
|
-
} else {
|
|
176
|
-
nativeBinding = require('@napi-rs/canvas-linux-arm64-musl')
|
|
177
|
-
}
|
|
178
|
-
} catch (e) {
|
|
179
|
-
loadError = e
|
|
180
|
-
}
|
|
181
|
-
} else {
|
|
182
|
-
localFileExisted = existsSync(join(__dirname, 'skia.linux-arm64-gnu.node'))
|
|
183
|
-
try {
|
|
184
|
-
if (localFileExisted) {
|
|
185
|
-
nativeBinding = require('./skia.linux-arm64-gnu.node')
|
|
186
|
-
} else {
|
|
187
|
-
nativeBinding = require('@napi-rs/canvas-linux-arm64-gnu')
|
|
188
|
-
}
|
|
189
|
-
} catch (e) {
|
|
190
|
-
loadError = e
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
break
|
|
194
|
-
case 'arm':
|
|
195
|
-
localFileExisted = existsSync(join(__dirname, 'skia.linux-arm-gnueabihf.node'))
|
|
196
|
-
try {
|
|
197
|
-
if (localFileExisted) {
|
|
198
|
-
nativeBinding = require('./skia.linux-arm-gnueabihf.node')
|
|
199
|
-
} else {
|
|
200
|
-
nativeBinding = require('@napi-rs/canvas-linux-arm-gnueabihf')
|
|
201
|
-
}
|
|
202
|
-
} catch (e) {
|
|
203
|
-
loadError = e
|
|
204
|
-
}
|
|
205
|
-
break
|
|
206
|
-
case 'riscv64':
|
|
207
|
-
localFileExisted = existsSync(join(__dirname, 'skia.linux-riscv64-gnu.node'))
|
|
208
|
-
try {
|
|
209
|
-
if (localFileExisted) {
|
|
210
|
-
nativeBinding = require('./skia.linux-riscv64-gnu.node')
|
|
211
|
-
} else {
|
|
212
|
-
nativeBinding = require('@napi-rs/canvas-linux-riscv64-gnu')
|
|
213
|
-
}
|
|
214
|
-
} catch (e) {
|
|
215
|
-
loadError = e
|
|
216
|
-
}
|
|
217
|
-
break
|
|
218
|
-
default:
|
|
219
|
-
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
|
220
355
|
}
|
|
221
|
-
|
|
222
|
-
default:
|
|
223
|
-
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
|
356
|
+
}
|
|
224
357
|
}
|
|
225
358
|
|
|
226
359
|
if (!nativeBinding) {
|
|
227
|
-
if (
|
|
228
|
-
|
|
360
|
+
if (loadErrors.length > 0) {
|
|
361
|
+
// TODO Link to documentation with potential fixes
|
|
362
|
+
// - The package owner could build/publish bindings for this arch
|
|
363
|
+
// - The user may need to bundle the correct files
|
|
364
|
+
// - The user may need to re-install node_modules to get new packages
|
|
365
|
+
throw new Error('Failed to load native binding', { cause: loadErrors })
|
|
229
366
|
}
|
|
230
367
|
throw new Error(`Failed to load native binding`)
|
|
231
368
|
}
|
|
232
369
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
} = nativeBinding
|
|
252
|
-
|
|
253
|
-
module.exports.ChromaSubsampling = ChromaSubsampling
|
|
254
|
-
module.exports.SvgExportFlag = SvgExportFlag
|
|
255
|
-
module.exports.CanvasRenderingContext2D = CanvasRenderingContext2D
|
|
256
|
-
module.exports.CanvasGradient = CanvasGradient
|
|
257
|
-
module.exports.ImageData = ImageData
|
|
258
|
-
module.exports.Image = Image
|
|
259
|
-
module.exports.PathOp = PathOp
|
|
260
|
-
module.exports.FillType = FillType
|
|
261
|
-
module.exports.StrokeCap = StrokeCap
|
|
262
|
-
module.exports.StrokeJoin = StrokeJoin
|
|
263
|
-
module.exports.Path = Path
|
|
264
|
-
module.exports.CanvasPattern = CanvasPattern
|
|
265
|
-
module.exports.convertSVGTextToPath = convertSVGTextToPath
|
|
266
|
-
module.exports.CanvasElement = CanvasElement
|
|
267
|
-
module.exports.SVGCanvas = SVGCanvas
|
|
268
|
-
module.exports.clearAllCache = clearAllCache
|
|
269
|
-
module.exports.GlobalFonts = GlobalFonts
|
|
370
|
+
module.exports.GlobalFonts = nativeBinding.GlobalFonts
|
|
371
|
+
module.exports.CanvasElement = nativeBinding.CanvasElement
|
|
372
|
+
module.exports.CanvasGradient = nativeBinding.CanvasGradient
|
|
373
|
+
module.exports.CanvasPattern = nativeBinding.CanvasPattern
|
|
374
|
+
module.exports.CanvasRenderingContext2D = nativeBinding.CanvasRenderingContext2D
|
|
375
|
+
module.exports.FontKey = nativeBinding.FontKey
|
|
376
|
+
module.exports.Image = nativeBinding.Image
|
|
377
|
+
module.exports.ImageData = nativeBinding.ImageData
|
|
378
|
+
module.exports.Path = nativeBinding.Path
|
|
379
|
+
module.exports.SVGCanvas = nativeBinding.SVGCanvas
|
|
380
|
+
module.exports.ChromaSubsampling = nativeBinding.ChromaSubsampling
|
|
381
|
+
module.exports.clearAllCache = nativeBinding.clearAllCache
|
|
382
|
+
module.exports.convertSVGTextToPath = nativeBinding.convertSVGTextToPath
|
|
383
|
+
module.exports.FillType = nativeBinding.FillType
|
|
384
|
+
module.exports.PathOp = nativeBinding.PathOp
|
|
385
|
+
module.exports.StrokeCap = nativeBinding.StrokeCap
|
|
386
|
+
module.exports.StrokeJoin = nativeBinding.StrokeJoin
|
|
387
|
+
module.exports.SvgExportFlag = nativeBinding.SvgExportFlag
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/canvas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.68",
|
|
4
4
|
"description": "Canvas for Node.js with skia backend",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -136,17 +136,17 @@
|
|
|
136
136
|
"singleQuote": true,
|
|
137
137
|
"arrowParens": "always"
|
|
138
138
|
},
|
|
139
|
-
"packageManager": "yarn@4.
|
|
139
|
+
"packageManager": "yarn@4.7.0",
|
|
140
140
|
"optionalDependencies": {
|
|
141
|
-
"@napi-rs/canvas-linux-x64-gnu": "0.1.
|
|
142
|
-
"@napi-rs/canvas-darwin-x64": "0.1.
|
|
143
|
-
"@napi-rs/canvas-win32-x64-msvc": "0.1.
|
|
144
|
-
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.
|
|
145
|
-
"@napi-rs/canvas-linux-x64-musl": "0.1.
|
|
146
|
-
"@napi-rs/canvas-linux-arm64-gnu": "0.1.
|
|
147
|
-
"@napi-rs/canvas-linux-arm64-musl": "0.1.
|
|
148
|
-
"@napi-rs/canvas-darwin-arm64": "0.1.
|
|
149
|
-
"@napi-rs/canvas-android-arm64": "0.1.
|
|
150
|
-
"@napi-rs/canvas-linux-riscv64-gnu": "0.1.
|
|
141
|
+
"@napi-rs/canvas-linux-x64-gnu": "0.1.68",
|
|
142
|
+
"@napi-rs/canvas-darwin-x64": "0.1.68",
|
|
143
|
+
"@napi-rs/canvas-win32-x64-msvc": "0.1.68",
|
|
144
|
+
"@napi-rs/canvas-linux-arm-gnueabihf": "0.1.68",
|
|
145
|
+
"@napi-rs/canvas-linux-x64-musl": "0.1.68",
|
|
146
|
+
"@napi-rs/canvas-linux-arm64-gnu": "0.1.68",
|
|
147
|
+
"@napi-rs/canvas-linux-arm64-musl": "0.1.68",
|
|
148
|
+
"@napi-rs/canvas-darwin-arm64": "0.1.68",
|
|
149
|
+
"@napi-rs/canvas-android-arm64": "0.1.68",
|
|
150
|
+
"@napi-rs/canvas-linux-riscv64-gnu": "0.1.68"
|
|
151
151
|
}
|
|
152
152
|
}
|