@napi-rs/image 1.9.2 → 1.11.0
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 +20 -21
- package/index.js +287 -272
- package/package.json +28 -19
package/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* auto-generated by NAPI-RS */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
constructor(input: Buffer)
|
|
3
|
+
export declare class Transformer {
|
|
4
|
+
constructor(input: Uint8Array)
|
|
6
5
|
/** Support CSS3 color, e.g. rgba(255, 255, 255, .8) */
|
|
7
|
-
static fromSvg(input: string |
|
|
6
|
+
static fromSvg(input: string | Uint8Array, background?: string | undefined | null): Transformer
|
|
8
7
|
static fromRgbaPixels(input: Uint8Array | Uint8ClampedArray, width: number, height: number): Transformer
|
|
9
8
|
metadata(withExif?: boolean | undefined | null, signal?: AbortSignal | undefined | null): Promise<Metadata>
|
|
9
|
+
metadataSync(withExif?: boolean | undefined | null): Metadata
|
|
10
10
|
/**
|
|
11
11
|
* Rotate with exif orientation
|
|
12
12
|
* If the orientation param is not null,
|
|
@@ -73,7 +73,7 @@ export class Transformer {
|
|
|
73
73
|
/** Crop a cut-out of this image delimited by the bounding rectangle. */
|
|
74
74
|
crop(x: number, y: number, width: number, height: number): this
|
|
75
75
|
/** Overlay an image at a given coordinate (x, y) */
|
|
76
|
-
overlay(onTop:
|
|
76
|
+
overlay(onTop: Uint8Array, x: number, y: number): this
|
|
77
77
|
/** Return this image's pixels as a native endian byte slice. */
|
|
78
78
|
rawPixels(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
79
79
|
/** Return this image's pixels as a native endian byte slice. */
|
|
@@ -131,7 +131,7 @@ export interface AvifConfig {
|
|
|
131
131
|
* https://en.wikipedia.org/wiki/Chroma_subsampling#Types_of_sampling_and_subsampling
|
|
132
132
|
* https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_concepts
|
|
133
133
|
*/
|
|
134
|
-
export enum ChromaSubsampling {
|
|
134
|
+
export declare enum ChromaSubsampling {
|
|
135
135
|
/**
|
|
136
136
|
* Each of the three Y'CbCr components has the same sample rate, thus there is no chroma subsampling. This scheme is sometimes used in high-end film scanners and cinematic post-production.
|
|
137
137
|
* Note that "4:4:4" may instead be wrongly referring to R'G'B' color space, which implicitly also does not have any chroma subsampling (except in JPEG R'G'B' can be subsampled).
|
|
@@ -170,7 +170,7 @@ export enum ChromaSubsampling {
|
|
|
170
170
|
Yuv400 = 3
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
export enum CompressionType {
|
|
173
|
+
export declare enum CompressionType {
|
|
174
174
|
/** Default compression level */
|
|
175
175
|
Default = 0,
|
|
176
176
|
/** Fast, minimal compression */
|
|
@@ -179,11 +179,11 @@ export enum CompressionType {
|
|
|
179
179
|
Best = 2
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
export function compressJpeg(input:
|
|
182
|
+
export declare function compressJpeg(input: Uint8Array, options?: JpegCompressOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
183
183
|
|
|
184
|
-
export function compressJpegSync(input:
|
|
184
|
+
export declare function compressJpegSync(input: Uint8Array, options?: JpegCompressOptions | undefined | null): Buffer
|
|
185
185
|
|
|
186
|
-
export enum FastResizeFilter {
|
|
186
|
+
export declare enum FastResizeFilter {
|
|
187
187
|
/**
|
|
188
188
|
* Each pixel of source image contributes to one pixel of the
|
|
189
189
|
* destination image with identical weights. For upscaling is equivalent
|
|
@@ -230,7 +230,7 @@ export interface FastResizeOptions {
|
|
|
230
230
|
fit?: ResizeFit
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
export enum FilterType {
|
|
233
|
+
export declare enum FilterType {
|
|
234
234
|
/**
|
|
235
235
|
* No processing done, best used for low bit depth greyscale or data with a
|
|
236
236
|
* low color count
|
|
@@ -261,7 +261,7 @@ export interface JpegCompressOptions {
|
|
|
261
261
|
optimizeScans?: boolean
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
export enum JsColorType {
|
|
264
|
+
export declare enum JsColorType {
|
|
265
265
|
/** Pixel is 8-bit luminance */
|
|
266
266
|
L8 = 0,
|
|
267
267
|
/** Pixel is 8-bit luminance with an alpha channel */
|
|
@@ -284,9 +284,9 @@ export enum JsColorType {
|
|
|
284
284
|
Rgba32F = 9
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
export function losslessCompressPng(input:
|
|
287
|
+
export declare function losslessCompressPng(input: Uint8Array, options?: PNGLosslessOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
288
288
|
|
|
289
|
-
export function losslessCompressPngSync(input: Buffer, options?: PNGLosslessOptions | undefined | null): Buffer
|
|
289
|
+
export declare function losslessCompressPngSync(input: Buffer, options?: PNGLosslessOptions | undefined | null): Buffer
|
|
290
290
|
|
|
291
291
|
export interface Metadata {
|
|
292
292
|
width: number
|
|
@@ -297,7 +297,7 @@ export interface Metadata {
|
|
|
297
297
|
colorType: JsColorType
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
export enum Orientation {
|
|
300
|
+
export declare enum Orientation {
|
|
301
301
|
/** Normal */
|
|
302
302
|
Horizontal = 1,
|
|
303
303
|
MirrorHorizontal = 2,
|
|
@@ -359,9 +359,9 @@ export interface PNGLosslessOptions {
|
|
|
359
359
|
strip?: boolean
|
|
360
360
|
}
|
|
361
361
|
|
|
362
|
-
export function pngQuantize(input:
|
|
362
|
+
export declare function pngQuantize(input: Uint8Array, options?: PngQuantOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
363
363
|
|
|
364
|
-
export function pngQuantizeSync(input:
|
|
364
|
+
export declare function pngQuantizeSync(input: Uint8Array, options?: PngQuantOptions | undefined | null): Buffer
|
|
365
365
|
|
|
366
366
|
export interface PngQuantOptions {
|
|
367
367
|
/** default is 70 */
|
|
@@ -381,7 +381,7 @@ export interface PngQuantOptions {
|
|
|
381
381
|
posterization?: number
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
export enum PngRowFilter {
|
|
384
|
+
export declare enum PngRowFilter {
|
|
385
385
|
None = 0,
|
|
386
386
|
Sub = 1,
|
|
387
387
|
Up = 2,
|
|
@@ -462,7 +462,7 @@ export enum PngRowFilter {
|
|
|
462
462
|
* </tr>
|
|
463
463
|
* </table>
|
|
464
464
|
*/
|
|
465
|
-
export enum ResizeFilterType {
|
|
465
|
+
export declare enum ResizeFilterType {
|
|
466
466
|
/** Nearest Neighbor */
|
|
467
467
|
Nearest = 0,
|
|
468
468
|
/** Linear Filter */
|
|
@@ -475,7 +475,7 @@ export enum ResizeFilterType {
|
|
|
475
475
|
Lanczos3 = 4
|
|
476
476
|
}
|
|
477
477
|
|
|
478
|
-
export enum ResizeFit {
|
|
478
|
+
export declare enum ResizeFit {
|
|
479
479
|
/**
|
|
480
480
|
* (default) Preserving aspect ratio
|
|
481
481
|
* ensure the image covers both provided dimensions by cropping/clipping to fit.
|
|
@@ -496,4 +496,3 @@ export interface ResizeOptions {
|
|
|
496
496
|
filter?: ResizeFilterType
|
|
497
497
|
fit?: ResizeFit
|
|
498
498
|
}
|
|
499
|
-
|
package/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
// prettier-ignore
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
3
4
|
/* auto-generated by NAPI-RS */
|
|
4
5
|
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const { platform, arch } = process
|
|
6
|
+
const { createRequire } = require('node:module')
|
|
7
|
+
require = createRequire(__filename)
|
|
9
8
|
|
|
9
|
+
const { readFileSync } = require('node:fs')
|
|
10
10
|
let nativeBinding = null
|
|
11
|
-
|
|
12
|
-
let loadError = null
|
|
11
|
+
const loadErrors = []
|
|
13
12
|
|
|
14
13
|
const isMusl = () => {
|
|
15
14
|
let musl = false
|
|
@@ -36,7 +35,11 @@ const isMuslFromFilesystem = () => {
|
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
const isMuslFromReport = () => {
|
|
39
|
-
|
|
38
|
+
let report = null
|
|
39
|
+
if (typeof process.report?.getReport === 'function') {
|
|
40
|
+
process.report.excludeNetwork = true
|
|
41
|
+
report = process.report.getReport()
|
|
42
|
+
}
|
|
40
43
|
if (!report) {
|
|
41
44
|
return null
|
|
42
45
|
}
|
|
@@ -60,287 +63,293 @@ const isMuslFromChildProcess = () => {
|
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (localFileExisted) {
|
|
70
|
-
nativeBinding = require('./image.android-arm64.node')
|
|
71
|
-
} else {
|
|
72
|
-
nativeBinding = require('@napi-rs/image-android-arm64')
|
|
73
|
-
}
|
|
74
|
-
} catch (e) {
|
|
75
|
-
loadError = e
|
|
76
|
-
}
|
|
77
|
-
break
|
|
78
|
-
case 'arm':
|
|
79
|
-
localFileExisted = existsSync(join(__dirname, 'image.android-arm-eabi.node'))
|
|
80
|
-
try {
|
|
81
|
-
if (localFileExisted) {
|
|
82
|
-
nativeBinding = require('./image.android-arm-eabi.node')
|
|
83
|
-
} else {
|
|
84
|
-
nativeBinding = require('@napi-rs/image-android-arm-eabi')
|
|
85
|
-
}
|
|
86
|
-
} catch (e) {
|
|
87
|
-
loadError = e
|
|
88
|
-
}
|
|
89
|
-
break
|
|
90
|
-
default:
|
|
91
|
-
loadError = new Error(`Unsupported architecture on Android ${arch}`)
|
|
66
|
+
function requireNative() {
|
|
67
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
68
|
+
try {
|
|
69
|
+
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
loadErrors.push(err)
|
|
92
72
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
73
|
+
} else if (process.platform === 'android') {
|
|
74
|
+
if (process.arch === 'arm64') {
|
|
75
|
+
try {
|
|
76
|
+
return require('./image.android-arm64.node')
|
|
77
|
+
} catch (e) {
|
|
78
|
+
loadErrors.push(e)
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return require('@napi-rs/image-android-arm64')
|
|
82
|
+
} catch (e) {
|
|
83
|
+
loadErrors.push(e)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
} else if (process.arch === 'arm') {
|
|
87
|
+
try {
|
|
88
|
+
return require('./image.android-arm-eabi.node')
|
|
89
|
+
} catch (e) {
|
|
90
|
+
loadErrors.push(e)
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
return require('@napi-rs/image-android-arm-eabi')
|
|
94
|
+
} catch (e) {
|
|
95
|
+
loadErrors.push(e)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
} else {
|
|
99
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
100
|
+
}
|
|
101
|
+
} else if (process.platform === 'win32') {
|
|
102
|
+
if (process.arch === 'x64') {
|
|
103
|
+
try {
|
|
104
|
+
return require('./image.win32-x64-msvc.node')
|
|
105
|
+
} catch (e) {
|
|
106
|
+
loadErrors.push(e)
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
return require('@napi-rs/image-win32-x64-msvc')
|
|
110
|
+
} catch (e) {
|
|
111
|
+
loadErrors.push(e)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
} else if (process.arch === 'ia32') {
|
|
115
|
+
try {
|
|
116
|
+
return require('./image.win32-ia32-msvc.node')
|
|
117
|
+
} catch (e) {
|
|
118
|
+
loadErrors.push(e)
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
return require('@napi-rs/image-win32-ia32-msvc')
|
|
122
|
+
} catch (e) {
|
|
123
|
+
loadErrors.push(e)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
} else if (process.arch === 'arm64') {
|
|
127
|
+
try {
|
|
128
|
+
return require('./image.win32-arm64-msvc.node')
|
|
129
|
+
} catch (e) {
|
|
130
|
+
loadErrors.push(e)
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
return require('@napi-rs/image-win32-arm64-msvc')
|
|
134
|
+
} catch (e) {
|
|
135
|
+
loadErrors.push(e)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
} else {
|
|
139
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
140
140
|
}
|
|
141
|
-
|
|
142
|
-
case 'darwin':
|
|
143
|
-
localFileExisted = existsSync(join(__dirname, 'image.darwin-universal.node'))
|
|
141
|
+
} else if (process.platform === 'darwin') {
|
|
144
142
|
try {
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
return require('./image.darwin-universal.node')
|
|
144
|
+
} catch (e) {
|
|
145
|
+
loadErrors.push(e)
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
return require('@napi-rs/image-darwin-universal')
|
|
149
|
+
} catch (e) {
|
|
150
|
+
loadErrors.push(e)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (process.arch === 'x64') {
|
|
154
|
+
try {
|
|
155
|
+
return require('./image.darwin-x64.node')
|
|
156
|
+
} catch (e) {
|
|
157
|
+
loadErrors.push(e)
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
return require('@napi-rs/image-darwin-x64')
|
|
161
|
+
} catch (e) {
|
|
162
|
+
loadErrors.push(e)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
} else if (process.arch === 'arm64') {
|
|
166
|
+
try {
|
|
167
|
+
return require('./image.darwin-arm64.node')
|
|
168
|
+
} catch (e) {
|
|
169
|
+
loadErrors.push(e)
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
return require('@napi-rs/image-darwin-arm64')
|
|
173
|
+
} catch (e) {
|
|
174
|
+
loadErrors.push(e)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
} else {
|
|
178
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
179
|
+
}
|
|
180
|
+
} else if (process.platform === 'freebsd') {
|
|
181
|
+
if (process.arch === 'x64') {
|
|
182
|
+
try {
|
|
183
|
+
return require('./image.freebsd-x64.node')
|
|
184
|
+
} catch (e) {
|
|
185
|
+
loadErrors.push(e)
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
return require('@napi-rs/image-freebsd-x64')
|
|
189
|
+
} catch (e) {
|
|
190
|
+
loadErrors.push(e)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
} else if (process.arch === 'arm64') {
|
|
194
|
+
try {
|
|
195
|
+
return require('./image.freebsd-arm64.node')
|
|
196
|
+
} catch (e) {
|
|
197
|
+
loadErrors.push(e)
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
return require('@napi-rs/image-freebsd-arm64')
|
|
201
|
+
} catch (e) {
|
|
202
|
+
loadErrors.push(e)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
} else {
|
|
206
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
207
|
+
}
|
|
208
|
+
} else if (process.platform === 'linux') {
|
|
209
|
+
if (process.arch === 'x64') {
|
|
210
|
+
if (isMusl()) {
|
|
211
|
+
try {
|
|
212
|
+
return require('./image.linux-x64-musl.node')
|
|
213
|
+
} catch (e) {
|
|
214
|
+
loadErrors.push(e)
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
return require('@napi-rs/image-linux-x64-musl')
|
|
218
|
+
} catch (e) {
|
|
219
|
+
loadErrors.push(e)
|
|
220
|
+
}
|
|
221
|
+
|
|
147
222
|
} else {
|
|
148
|
-
|
|
223
|
+
try {
|
|
224
|
+
return require('./image.linux-x64-gnu.node')
|
|
225
|
+
} catch (e) {
|
|
226
|
+
loadErrors.push(e)
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
return require('@napi-rs/image-linux-x64-gnu')
|
|
230
|
+
} catch (e) {
|
|
231
|
+
loadErrors.push(e)
|
|
149
232
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
localFileExisted = existsSync(join(__dirname, 'image.darwin-x64.node'))
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
} else if (process.arch === 'arm64') {
|
|
236
|
+
if (isMusl()) {
|
|
155
237
|
try {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
join(__dirname, 'image.darwin-arm64.node')
|
|
168
|
-
)
|
|
238
|
+
return require('./image.linux-arm64-musl.node')
|
|
239
|
+
} catch (e) {
|
|
240
|
+
loadErrors.push(e)
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
return require('@napi-rs/image-linux-arm64-musl')
|
|
244
|
+
} catch (e) {
|
|
245
|
+
loadErrors.push(e)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
} else {
|
|
169
249
|
try {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
case 'freebsd':
|
|
184
|
-
switch (arch) {
|
|
185
|
-
case 'x64':
|
|
186
|
-
localFileExisted = existsSync(join(__dirname, 'image.freebsd-x64.node'))
|
|
250
|
+
return require('./image.linux-arm64-gnu.node')
|
|
251
|
+
} catch (e) {
|
|
252
|
+
loadErrors.push(e)
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
return require('@napi-rs/image-linux-arm64-gnu')
|
|
256
|
+
} catch (e) {
|
|
257
|
+
loadErrors.push(e)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
}
|
|
261
|
+
} else if (process.arch === 'arm') {
|
|
262
|
+
if (isMusl()) {
|
|
187
263
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
264
|
+
return require('./image.linux-arm-musleabihf.node')
|
|
265
|
+
} catch (e) {
|
|
266
|
+
loadErrors.push(e)
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
return require('@napi-rs/image-linux-arm-musleabihf')
|
|
270
|
+
} catch (e) {
|
|
271
|
+
loadErrors.push(e)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
} else {
|
|
199
275
|
try {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
case 'linux':
|
|
214
|
-
switch (arch) {
|
|
215
|
-
case 'x64':
|
|
216
|
-
if (isMusl()) {
|
|
217
|
-
localFileExisted = existsSync(
|
|
218
|
-
join(__dirname, 'image.linux-x64-musl.node')
|
|
219
|
-
)
|
|
220
|
-
try {
|
|
221
|
-
if (localFileExisted) {
|
|
222
|
-
nativeBinding = require('./image.linux-x64-musl.node')
|
|
223
|
-
} else {
|
|
224
|
-
nativeBinding = require('@napi-rs/image-linux-x64-musl')
|
|
225
|
-
}
|
|
226
|
-
} catch (e) {
|
|
227
|
-
loadError = e
|
|
228
|
-
}
|
|
229
|
-
} else {
|
|
230
|
-
localFileExisted = existsSync(
|
|
231
|
-
join(__dirname, 'image.linux-x64-gnu.node')
|
|
232
|
-
)
|
|
233
|
-
try {
|
|
234
|
-
if (localFileExisted) {
|
|
235
|
-
nativeBinding = require('./image.linux-x64-gnu.node')
|
|
236
|
-
} else {
|
|
237
|
-
nativeBinding = require('@napi-rs/image-linux-x64-gnu')
|
|
238
|
-
}
|
|
239
|
-
} catch (e) {
|
|
240
|
-
loadError = e
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
break
|
|
244
|
-
case 'arm64':
|
|
245
|
-
if (isMusl()) {
|
|
246
|
-
localFileExisted = existsSync(
|
|
247
|
-
join(__dirname, 'image.linux-arm64-musl.node')
|
|
248
|
-
)
|
|
249
|
-
try {
|
|
250
|
-
if (localFileExisted) {
|
|
251
|
-
nativeBinding = require('./image.linux-arm64-musl.node')
|
|
252
|
-
} else {
|
|
253
|
-
nativeBinding = require('@napi-rs/image-linux-arm64-musl')
|
|
254
|
-
}
|
|
255
|
-
} catch (e) {
|
|
256
|
-
loadError = e
|
|
257
|
-
}
|
|
258
|
-
} else {
|
|
259
|
-
localFileExisted = existsSync(
|
|
260
|
-
join(__dirname, 'image.linux-arm64-gnu.node')
|
|
261
|
-
)
|
|
262
|
-
try {
|
|
263
|
-
if (localFileExisted) {
|
|
264
|
-
nativeBinding = require('./image.linux-arm64-gnu.node')
|
|
265
|
-
} else {
|
|
266
|
-
nativeBinding = require('@napi-rs/image-linux-arm64-gnu')
|
|
267
|
-
}
|
|
268
|
-
} catch (e) {
|
|
269
|
-
loadError = e
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
break
|
|
273
|
-
case 'arm':
|
|
274
|
-
localFileExisted = existsSync(
|
|
275
|
-
join(__dirname, 'image.linux-arm-gnueabihf.node')
|
|
276
|
-
)
|
|
276
|
+
return require('./image.linux-arm-gnueabihf.node')
|
|
277
|
+
} catch (e) {
|
|
278
|
+
loadErrors.push(e)
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
return require('@napi-rs/image-linux-arm-gnueabihf')
|
|
282
|
+
} catch (e) {
|
|
283
|
+
loadErrors.push(e)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
}
|
|
287
|
+
} else if (process.arch === 'riscv64') {
|
|
288
|
+
if (isMusl()) {
|
|
277
289
|
try {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
localFileExisted = existsSync(
|
|
290
|
-
join(__dirname, 'image.linux-riscv64-musl.node')
|
|
291
|
-
)
|
|
292
|
-
try {
|
|
293
|
-
if (localFileExisted) {
|
|
294
|
-
nativeBinding = require('./image.linux-riscv64-musl.node')
|
|
295
|
-
} else {
|
|
296
|
-
nativeBinding = require('@napi-rs/image-linux-riscv64-musl')
|
|
297
|
-
}
|
|
298
|
-
} catch (e) {
|
|
299
|
-
loadError = e
|
|
300
|
-
}
|
|
301
|
-
} else {
|
|
302
|
-
localFileExisted = existsSync(
|
|
303
|
-
join(__dirname, 'image.linux-riscv64-gnu.node')
|
|
304
|
-
)
|
|
305
|
-
try {
|
|
306
|
-
if (localFileExisted) {
|
|
307
|
-
nativeBinding = require('./image.linux-riscv64-gnu.node')
|
|
308
|
-
} else {
|
|
309
|
-
nativeBinding = require('@napi-rs/image-linux-riscv64-gnu')
|
|
310
|
-
}
|
|
311
|
-
} catch (e) {
|
|
312
|
-
loadError = e
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
break
|
|
316
|
-
case 's390x':
|
|
317
|
-
localFileExisted = existsSync(
|
|
318
|
-
join(__dirname, 'image.linux-s390x-gnu.node')
|
|
319
|
-
)
|
|
290
|
+
return require('./image.linux-riscv64-musl.node')
|
|
291
|
+
} catch (e) {
|
|
292
|
+
loadErrors.push(e)
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
return require('@napi-rs/image-linux-riscv64-musl')
|
|
296
|
+
} catch (e) {
|
|
297
|
+
loadErrors.push(e)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
} else {
|
|
320
301
|
try {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
302
|
+
return require('./image.linux-riscv64-gnu.node')
|
|
303
|
+
} catch (e) {
|
|
304
|
+
loadErrors.push(e)
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
return require('@napi-rs/image-linux-riscv64-gnu')
|
|
308
|
+
} catch (e) {
|
|
309
|
+
loadErrors.push(e)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
} else if (process.arch === 'ppc64') {
|
|
314
|
+
try {
|
|
315
|
+
return require('./image.linux-ppc64-gnu.node')
|
|
316
|
+
} catch (e) {
|
|
317
|
+
loadErrors.push(e)
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
return require('@napi-rs/image-linux-ppc64-gnu')
|
|
321
|
+
} catch (e) {
|
|
322
|
+
loadErrors.push(e)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
} else if (process.arch === 's390x') {
|
|
326
|
+
try {
|
|
327
|
+
return require('./image.linux-s390x-gnu.node')
|
|
328
|
+
} catch (e) {
|
|
329
|
+
loadErrors.push(e)
|
|
330
|
+
}
|
|
331
|
+
try {
|
|
332
|
+
return require('@napi-rs/image-linux-s390x-gnu')
|
|
333
|
+
} catch (e) {
|
|
334
|
+
loadErrors.push(e)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
} else {
|
|
338
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
332
339
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
340
|
+
} else {
|
|
341
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
342
|
+
}
|
|
336
343
|
}
|
|
337
344
|
|
|
345
|
+
nativeBinding = requireNative()
|
|
346
|
+
|
|
338
347
|
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
339
348
|
try {
|
|
340
349
|
nativeBinding = require('./image.wasi.cjs')
|
|
341
350
|
} catch (err) {
|
|
342
351
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
343
|
-
|
|
352
|
+
loadErrors.push(err)
|
|
344
353
|
}
|
|
345
354
|
}
|
|
346
355
|
if (!nativeBinding) {
|
|
@@ -348,19 +357,25 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
|
348
357
|
nativeBinding = require('@napi-rs/image-wasm32-wasi')
|
|
349
358
|
} catch (err) {
|
|
350
359
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
351
|
-
|
|
360
|
+
loadErrors.push(err)
|
|
352
361
|
}
|
|
353
362
|
}
|
|
354
363
|
}
|
|
355
364
|
}
|
|
356
365
|
|
|
357
366
|
if (!nativeBinding) {
|
|
358
|
-
if (
|
|
359
|
-
throw
|
|
367
|
+
if (loadErrors.length > 0) {
|
|
368
|
+
throw new Error(
|
|
369
|
+
`Cannot find native binding. ` +
|
|
370
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
371
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
372
|
+
{ cause: loadErrors }
|
|
373
|
+
)
|
|
360
374
|
}
|
|
361
375
|
throw new Error(`Failed to load native binding`)
|
|
362
376
|
}
|
|
363
377
|
|
|
378
|
+
module.exports = nativeBinding
|
|
364
379
|
module.exports.Transformer = nativeBinding.Transformer
|
|
365
380
|
module.exports.ChromaSubsampling = nativeBinding.ChromaSubsampling
|
|
366
381
|
module.exports.CompressionType = nativeBinding.CompressionType
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/image",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"browser": "browser.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
],
|
|
22
22
|
"files": [
|
|
23
23
|
"index.js",
|
|
24
|
-
"index.d.ts"
|
|
24
|
+
"index.d.ts",
|
|
25
|
+
"browser.js"
|
|
25
26
|
],
|
|
26
27
|
"publishConfig": {
|
|
27
28
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
"targets": [
|
|
33
34
|
"x86_64-apple-darwin",
|
|
34
35
|
"x86_64-pc-windows-msvc",
|
|
36
|
+
"aarch64-pc-windows-msvc",
|
|
35
37
|
"x86_64-unknown-linux-gnu",
|
|
36
38
|
"aarch64-apple-darwin",
|
|
37
39
|
"aarch64-linux-android",
|
|
@@ -42,7 +44,13 @@
|
|
|
42
44
|
"x86_64-unknown-freebsd",
|
|
43
45
|
"i686-pc-windows-msvc",
|
|
44
46
|
"wasm32-wasi-preview1-threads"
|
|
45
|
-
]
|
|
47
|
+
],
|
|
48
|
+
"wasm": {
|
|
49
|
+
"browser": {
|
|
50
|
+
"asyncInit": true,
|
|
51
|
+
"fs": false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
46
54
|
},
|
|
47
55
|
"license": "MIT",
|
|
48
56
|
"engines": {
|
|
@@ -60,26 +68,27 @@
|
|
|
60
68
|
"format:prettier": "prettier --config ./package.json -w .",
|
|
61
69
|
"format:rs": "cargo fmt --all",
|
|
62
70
|
"prepublishOnly": "napi prepublish",
|
|
63
|
-
"version": "napi version
|
|
71
|
+
"version": "napi version"
|
|
64
72
|
},
|
|
65
73
|
"repository": "git@github.com:Brooooooklyn/Image.git",
|
|
66
74
|
"devDependencies": {
|
|
67
|
-
"@napi-rs/cli": "^3.0.0-alpha.
|
|
68
|
-
"@napi-rs/wasm-runtime": "^0.2.
|
|
75
|
+
"@napi-rs/cli": "^3.0.0-alpha.92",
|
|
76
|
+
"@napi-rs/wasm-runtime": "^0.2.11"
|
|
69
77
|
},
|
|
70
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "b59adf7830adafecc7ca8559faec7a8df20bedb4",
|
|
71
79
|
"optionalDependencies": {
|
|
72
|
-
"@napi-rs/image-darwin-x64": "1.
|
|
73
|
-
"@napi-rs/image-win32-x64-msvc": "1.
|
|
74
|
-
"@napi-rs/image-
|
|
75
|
-
"@napi-rs/image-
|
|
76
|
-
"@napi-rs/image-
|
|
77
|
-
"@napi-rs/image-
|
|
78
|
-
"@napi-rs/image-linux-arm64-
|
|
79
|
-
"@napi-rs/image-linux-
|
|
80
|
-
"@napi-rs/image-linux-
|
|
81
|
-
"@napi-rs/image-
|
|
82
|
-
"@napi-rs/image-
|
|
83
|
-
"@napi-rs/image-
|
|
80
|
+
"@napi-rs/image-darwin-x64": "1.11.0",
|
|
81
|
+
"@napi-rs/image-win32-x64-msvc": "1.11.0",
|
|
82
|
+
"@napi-rs/image-win32-arm64-msvc": "1.11.0",
|
|
83
|
+
"@napi-rs/image-linux-x64-gnu": "1.11.0",
|
|
84
|
+
"@napi-rs/image-darwin-arm64": "1.11.0",
|
|
85
|
+
"@napi-rs/image-android-arm64": "1.11.0",
|
|
86
|
+
"@napi-rs/image-linux-arm64-gnu": "1.11.0",
|
|
87
|
+
"@napi-rs/image-linux-arm64-musl": "1.11.0",
|
|
88
|
+
"@napi-rs/image-linux-arm-gnueabihf": "1.11.0",
|
|
89
|
+
"@napi-rs/image-linux-x64-musl": "1.11.0",
|
|
90
|
+
"@napi-rs/image-freebsd-x64": "1.11.0",
|
|
91
|
+
"@napi-rs/image-win32-ia32-msvc": "1.11.0",
|
|
92
|
+
"@napi-rs/image-wasm32-wasi": "1.11.0"
|
|
84
93
|
}
|
|
85
94
|
}
|