@revizly/sharp 0.35.0-revizly40 → 0.35.0-revizly42

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/dist/colour.cjs CHANGED
@@ -146,12 +146,16 @@ function _getBackgroundColourOption (value) {
146
146
  (is.string(value) && value.length >= 3 && value.length <= 200)
147
147
  ) {
148
148
  const colour = color(value);
149
- return [
150
- colour.red(),
151
- colour.green(),
152
- colour.blue(),
153
- Math.round(colour.alpha() * 255)
154
- ];
149
+ const red = colour.red();
150
+ const green = colour.green();
151
+ const blue = colour.blue();
152
+ const alpha = Math.round(colour.alpha() * 255);
153
+ for (const [channel, component] of [['red', red], ['green', green], ['blue', blue], ['alpha', alpha]]) {
154
+ if (!is.number(component)) {
155
+ throw is.invalidParameterError(`background.${channel}`, 'number', component);
156
+ }
157
+ }
158
+ return [red, green, blue, alpha];
155
159
  } else {
156
160
  throw is.invalidParameterError('background', 'object or string', value);
157
161
  }
package/dist/colour.mjs CHANGED
@@ -146,12 +146,16 @@ function _getBackgroundColourOption (value) {
146
146
  (is.string(value) && value.length >= 3 && value.length <= 200)
147
147
  ) {
148
148
  const colour = color(value);
149
- return [
150
- colour.red(),
151
- colour.green(),
152
- colour.blue(),
153
- Math.round(colour.alpha() * 255)
154
- ];
149
+ const red = colour.red();
150
+ const green = colour.green();
151
+ const blue = colour.blue();
152
+ const alpha = Math.round(colour.alpha() * 255);
153
+ for (const [channel, component] of [['red', red], ['green', green], ['blue', blue], ['alpha', alpha]]) {
154
+ if (!is.number(component)) {
155
+ throw is.invalidParameterError(`background.${channel}`, 'number', component);
156
+ }
157
+ }
158
+ return [red, green, blue, alpha];
155
159
  } else {
156
160
  throw is.invalidParameterError('background', 'object or string', value);
157
161
  }
package/dist/index.d.cts CHANGED
@@ -658,25 +658,27 @@ declare namespace sharp {
658
658
  * @param callback Callback function called on completion with three arguments (err, buffer, info).
659
659
  * @returns A sharp instance that can be used to chain operations
660
660
  */
661
- toBuffer(callback: (err: Error, buffer: Buffer, info: OutputInfo) => void): Sharp;
661
+ toBuffer(callback: (err: Error, buffer: Buffer<ArrayBuffer>, info: OutputInfo) => void): Sharp;
662
662
 
663
663
  /**
664
664
  * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
665
665
  * By default, the format will match the input image, except SVG input which becomes PNG output.
666
+ * The underlying `ArrayBuffer` may be marked as non-transferable by some JavaScript runtimes.
666
667
  * @param options resolve options
667
668
  * @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
668
669
  * @returns A promise that resolves with the Buffer data.
669
670
  */
670
- toBuffer(options?: { resolveWithObject: false }): Promise<Buffer>;
671
+ toBuffer(options?: { resolveWithObject: false }): Promise<Buffer<ArrayBuffer>>;
671
672
 
672
673
  /**
673
674
  * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
674
675
  * By default, the format will match the input image, except SVG input which becomes PNG output.
676
+ * The underlying `ArrayBuffer` may be marked as non-transferable by some JavaScript runtimes.
675
677
  * @param options resolve options
676
678
  * @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
677
679
  * @returns A promise that resolves with an object containing the Buffer data and an info object containing the output image format, size (bytes), width, height and channels
678
680
  */
679
- toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer; info: OutputInfo }>;
681
+ toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer<ArrayBuffer>; info: OutputInfo }>;
680
682
 
681
683
  /**
682
684
  * Write output to a Uint8Array backed by a transferable ArrayBuffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
@@ -1602,13 +1604,13 @@ declare namespace sharp {
1602
1604
  }
1603
1605
 
1604
1606
  interface Region {
1605
- /** zero-indexed offset from left edge */
1607
+ /** zero-indexed offset from left edge, an integer between 0 and 100000000 */
1606
1608
  left: number;
1607
- /** zero-indexed offset from top edge */
1609
+ /** zero-indexed offset from top edge, an integer between 0 and 100000000 */
1608
1610
  top: number;
1609
- /** dimension of extracted image */
1611
+ /** dimension of extracted image, an integer between 0 and 100000000 */
1610
1612
  width: number;
1611
- /** dimension of extracted image */
1613
+ /** dimension of extracted image, an integer between 0 and 100000000 */
1612
1614
  height: number;
1613
1615
  }
1614
1616
 
@@ -1787,6 +1789,8 @@ declare namespace sharp {
1787
1789
  channels: Channels;
1788
1790
  /** indicating if premultiplication was used */
1789
1791
  premultiplied: boolean;
1792
+ /** Indicates if the output image has an alpha channel */
1793
+ hasAlpha: boolean;
1790
1794
  /** Only defined when using a crop strategy */
1791
1795
  cropOffsetLeft?: number | undefined;
1792
1796
  /** Only defined when using a crop strategy */
package/dist/index.d.mts CHANGED
@@ -652,25 +652,27 @@ export interface Sharp extends Duplex {
652
652
  * @param callback Callback function called on completion with three arguments (err, buffer, info).
653
653
  * @returns A sharp instance that can be used to chain operations
654
654
  */
655
- toBuffer(callback: (err: Error, buffer: Buffer, info: OutputInfo) => void): Sharp;
655
+ toBuffer(callback: (err: Error, buffer: Buffer<ArrayBuffer>, info: OutputInfo) => void): Sharp;
656
656
 
657
657
  /**
658
658
  * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
659
659
  * By default, the format will match the input image, except SVG input which becomes PNG output.
660
+ * The underlying `ArrayBuffer` may be marked as non-transferable by some JavaScript runtimes.
660
661
  * @param options resolve options
661
662
  * @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
662
663
  * @returns A promise that resolves with the Buffer data.
663
664
  */
664
- toBuffer(options?: { resolveWithObject: false }): Promise<Buffer>;
665
+ toBuffer(options?: { resolveWithObject: false }): Promise<Buffer<ArrayBuffer>>;
665
666
 
666
667
  /**
667
668
  * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
668
669
  * By default, the format will match the input image, except SVG input which becomes PNG output.
670
+ * The underlying `ArrayBuffer` may be marked as non-transferable by some JavaScript runtimes.
669
671
  * @param options resolve options
670
672
  * @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
671
673
  * @returns A promise that resolves with an object containing the Buffer data and an info object containing the output image format, size (bytes), width, height and channels
672
674
  */
673
- toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer; info: OutputInfo }>;
675
+ toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer<ArrayBuffer>; info: OutputInfo }>;
674
676
 
675
677
  /**
676
678
  * Write output to a Uint8Array backed by a transferable ArrayBuffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
@@ -1596,13 +1598,13 @@ export interface ResizeOptions {
1596
1598
  }
1597
1599
 
1598
1600
  export interface Region {
1599
- /** zero-indexed offset from left edge */
1601
+ /** zero-indexed offset from left edge, an integer between 0 and 100000000 */
1600
1602
  left: number;
1601
- /** zero-indexed offset from top edge */
1603
+ /** zero-indexed offset from top edge, an integer between 0 and 100000000 */
1602
1604
  top: number;
1603
- /** dimension of extracted image */
1605
+ /** dimension of extracted image, an integer between 0 and 100000000 */
1604
1606
  width: number;
1605
- /** dimension of extracted image */
1607
+ /** dimension of extracted image, an integer between 0 and 100000000 */
1606
1608
  height: number;
1607
1609
  }
1608
1610
 
@@ -1781,6 +1783,8 @@ export interface OutputInfo {
1781
1783
  channels: Channels;
1782
1784
  /** indicating if premultiplication was used */
1783
1785
  premultiplied: boolean;
1786
+ /** Indicates if the output image has an alpha channel */
1787
+ hasAlpha: boolean;
1784
1788
  /** Only defined when using a crop strategy */
1785
1789
  cropOffsetLeft?: number | undefined;
1786
1790
  /** Only defined when using a crop strategy */
package/dist/input.cjs CHANGED
@@ -181,8 +181,8 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
181
181
  if (is.defined(inputOptions.raw)) {
182
182
  if (
183
183
  is.object(inputOptions.raw) &&
184
- is.integer(inputOptions.raw.width) && inputOptions.raw.width > 0 &&
185
- is.integer(inputOptions.raw.height) && inputOptions.raw.height > 0 &&
184
+ is.integer(inputOptions.raw.width) && is.inRange(inputOptions.raw.width, 1, 100000000) &&
185
+ is.integer(inputOptions.raw.height) && is.inRange(inputOptions.raw.height, 1, 100000000) &&
186
186
  is.integer(inputOptions.raw.channels) && is.inRange(inputOptions.raw.channels, 1, 4)
187
187
  ) {
188
188
  inputDescriptor.rawWidth = inputOptions.raw.width;
@@ -329,8 +329,8 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
329
329
  if (is.defined(inputOptions.create)) {
330
330
  if (
331
331
  is.object(inputOptions.create) &&
332
- is.integer(inputOptions.create.width) && inputOptions.create.width > 0 &&
333
- is.integer(inputOptions.create.height) && inputOptions.create.height > 0 &&
332
+ is.integer(inputOptions.create.width) && is.inRange(inputOptions.create.width, 1, 100000000) &&
333
+ is.integer(inputOptions.create.height) && is.inRange(inputOptions.create.height, 1, 100000000) &&
334
334
  is.integer(inputOptions.create.channels)
335
335
  ) {
336
336
  inputDescriptor.createWidth = inputOptions.create.width;
package/dist/input.mjs CHANGED
@@ -181,8 +181,8 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
181
181
  if (is.defined(inputOptions.raw)) {
182
182
  if (
183
183
  is.object(inputOptions.raw) &&
184
- is.integer(inputOptions.raw.width) && inputOptions.raw.width > 0 &&
185
- is.integer(inputOptions.raw.height) && inputOptions.raw.height > 0 &&
184
+ is.integer(inputOptions.raw.width) && is.inRange(inputOptions.raw.width, 1, 100000000) &&
185
+ is.integer(inputOptions.raw.height) && is.inRange(inputOptions.raw.height, 1, 100000000) &&
186
186
  is.integer(inputOptions.raw.channels) && is.inRange(inputOptions.raw.channels, 1, 4)
187
187
  ) {
188
188
  inputDescriptor.rawWidth = inputOptions.raw.width;
@@ -329,8 +329,8 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
329
329
  if (is.defined(inputOptions.create)) {
330
330
  if (
331
331
  is.object(inputOptions.create) &&
332
- is.integer(inputOptions.create.width) && inputOptions.create.width > 0 &&
333
- is.integer(inputOptions.create.height) && inputOptions.create.height > 0 &&
332
+ is.integer(inputOptions.create.width) && is.inRange(inputOptions.create.width, 1, 100000000) &&
333
+ is.integer(inputOptions.create.height) && is.inRange(inputOptions.create.height, 1, 100000000) &&
334
334
  is.integer(inputOptions.create.channels)
335
335
  ) {
336
336
  inputDescriptor.createWidth = inputOptions.create.width;
@@ -178,7 +178,13 @@ function flop (flop) {
178
178
  * @throws {Error} Invalid parameters
179
179
  */
180
180
  function affine (matrix, options) {
181
- const flatMatrix = Array.isArray(matrix) ? [].concat(...matrix) : [];
181
+ const isValidShape = Array.isArray(matrix) && (
182
+ // 1x4 array of numbers
183
+ (matrix.length === 4 && matrix.every(is.number)) ||
184
+ // 2x2 array of arrays of numbers
185
+ (matrix.length === 2 && matrix.every((row) => Array.isArray(row) && row.length === 2))
186
+ );
187
+ const flatMatrix = isValidShape ? matrix.flat() : [];
182
188
  if (flatMatrix.length === 4 && flatMatrix.every(is.number)) {
183
189
  this.options.affineMatrix = flatMatrix;
184
190
  } else {
@@ -860,13 +866,14 @@ function recomb (inputMatrix) {
860
866
  if (!Array.isArray(inputMatrix)) {
861
867
  throw is.invalidParameterError('inputMatrix', 'array', inputMatrix);
862
868
  }
863
- if (inputMatrix.length !== 3 && inputMatrix.length !== 4) {
864
- throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', inputMatrix.length);
869
+ const dimensions = inputMatrix.length;
870
+ if (dimensions !== 3 && dimensions !== 4) {
871
+ throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', dimensions);
865
872
  }
866
- const recombMatrix = inputMatrix.flat();
867
- if (recombMatrix.length !== 9 && recombMatrix.length !== 16) {
868
- throw is.invalidParameterError('inputMatrix', 'cardinality of 9 or 16', recombMatrix.length);
873
+ if (!inputMatrix.every((row) => Array.isArray(row) && row.length === dimensions)) {
874
+ throw is.invalidParameterError('inputMatrix', `array of ${dimensions} arrays of length ${dimensions}`, inputMatrix);
869
875
  }
876
+ const recombMatrix = inputMatrix.flat();
870
877
  if (!recombMatrix.every(is.number)) {
871
878
  throw is.invalidParameterError('inputMatrix', 'array of numbers', recombMatrix);
872
879
  }
@@ -178,7 +178,13 @@ function flop (flop) {
178
178
  * @throws {Error} Invalid parameters
179
179
  */
180
180
  function affine (matrix, options) {
181
- const flatMatrix = Array.isArray(matrix) ? [].concat(...matrix) : [];
181
+ const isValidShape = Array.isArray(matrix) && (
182
+ // 1x4 array of numbers
183
+ (matrix.length === 4 && matrix.every(is.number)) ||
184
+ // 2x2 array of arrays of numbers
185
+ (matrix.length === 2 && matrix.every((row) => Array.isArray(row) && row.length === 2))
186
+ );
187
+ const flatMatrix = isValidShape ? matrix.flat() : [];
182
188
  if (flatMatrix.length === 4 && flatMatrix.every(is.number)) {
183
189
  this.options.affineMatrix = flatMatrix;
184
190
  } else {
@@ -860,13 +866,14 @@ function recomb (inputMatrix) {
860
866
  if (!Array.isArray(inputMatrix)) {
861
867
  throw is.invalidParameterError('inputMatrix', 'array', inputMatrix);
862
868
  }
863
- if (inputMatrix.length !== 3 && inputMatrix.length !== 4) {
864
- throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', inputMatrix.length);
869
+ const dimensions = inputMatrix.length;
870
+ if (dimensions !== 3 && dimensions !== 4) {
871
+ throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', dimensions);
865
872
  }
866
- const recombMatrix = inputMatrix.flat();
867
- if (recombMatrix.length !== 9 && recombMatrix.length !== 16) {
868
- throw is.invalidParameterError('inputMatrix', 'cardinality of 9 or 16', recombMatrix.length);
873
+ if (!inputMatrix.every((row) => Array.isArray(row) && row.length === dimensions)) {
874
+ throw is.invalidParameterError('inputMatrix', `array of ${dimensions} arrays of length ${dimensions}`, inputMatrix);
869
875
  }
876
+ const recombMatrix = inputMatrix.flat();
870
877
  if (!recombMatrix.every(is.number)) {
871
878
  throw is.invalidParameterError('inputMatrix', 'array of numbers', recombMatrix);
872
879
  }
package/dist/output.cjs CHANGED
@@ -113,24 +113,20 @@ function toFile (fileOut, callback) {
113
113
  * Animated output will also contain `pageHeight` and `pages`.
114
114
  * May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
115
115
  *
116
- * A `Promise` is returned when `callback` is not provided.
116
+ * The underlying `ArrayBuffer` may be marked as non-transferable by some JavaScript runtimes.
117
+ * Use {@link #touint8array toUint8Array} for a guaranteed transferable `ArrayBuffer`.
117
118
  *
118
- * @example
119
- * sharp(input)
120
- * .toBuffer((err, data, info) => { ... });
119
+ * A `Promise` is returned when `callback` is not provided.
121
120
  *
122
121
  * @example
123
- * sharp(input)
124
- * .toBuffer()
125
- * .then(data => { ... })
126
- * .catch(err => { ... });
122
+ * const data = await sharp(input)
123
+ * .png()
124
+ * .toBuffer();
127
125
  *
128
126
  * @example
129
- * sharp(input)
127
+ * const { data, info } = await sharp(input)
130
128
  * .png()
131
- * .toBuffer({ resolveWithObject: true })
132
- * .then(({ data, info }) => { ... })
133
- * .catch(err => { ... });
129
+ * .toBuffer({ resolveWithObject: true });
134
130
  *
135
131
  * @example
136
132
  * const { data, info } = await sharp('my-image.jpg')
package/dist/output.mjs CHANGED
@@ -113,24 +113,20 @@ function toFile (fileOut, callback) {
113
113
  * Animated output will also contain `pageHeight` and `pages`.
114
114
  * May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
115
115
  *
116
- * A `Promise` is returned when `callback` is not provided.
116
+ * The underlying `ArrayBuffer` may be marked as non-transferable by some JavaScript runtimes.
117
+ * Use {@link #touint8array toUint8Array} for a guaranteed transferable `ArrayBuffer`.
117
118
  *
118
- * @example
119
- * sharp(input)
120
- * .toBuffer((err, data, info) => { ... });
119
+ * A `Promise` is returned when `callback` is not provided.
121
120
  *
122
121
  * @example
123
- * sharp(input)
124
- * .toBuffer()
125
- * .then(data => { ... })
126
- * .catch(err => { ... });
122
+ * const data = await sharp(input)
123
+ * .png()
124
+ * .toBuffer();
127
125
  *
128
126
  * @example
129
- * sharp(input)
127
+ * const { data, info } = await sharp(input)
130
128
  * .png()
131
- * .toBuffer({ resolveWithObject: true })
132
- * .then(({ data, info }) => { ... })
133
- * .catch(err => { ... });
129
+ * .toBuffer({ resolveWithObject: true });
134
130
  *
135
131
  * @example
136
132
  * const { data, info } = await sharp('my-image.jpg')
package/dist/resize.cjs CHANGED
@@ -471,10 +471,10 @@ function extend (extend) {
471
471
  * });
472
472
  *
473
473
  * @param {Object} options - describes the region to extract using integral pixel values
474
- * @param {number} options.left - zero-indexed offset from left edge
475
- * @param {number} options.top - zero-indexed offset from top edge
476
- * @param {number} options.width - width of region to extract
477
- * @param {number} options.height - height of region to extract
474
+ * @param {number} options.left - zero-indexed offset from left edge, an integer between 0 and 100000000
475
+ * @param {number} options.top - zero-indexed offset from top edge, an integer between 0 and 100000000
476
+ * @param {number} options.width - width of region to extract, an integer between 0 and 100000000
477
+ * @param {number} options.height - height of region to extract, an integer between 0 and 100000000
478
478
  * @returns {Sharp}
479
479
  * @throws {Error} Invalid parameters
480
480
  */
@@ -485,10 +485,10 @@ function extract (options) {
485
485
  }
486
486
  ['left', 'top', 'width', 'height'].forEach(function (name) {
487
487
  const value = options[name];
488
- if (is.integer(value) && value >= 0) {
488
+ if (is.integer(value) && is.inRange(value, 0, 100000000)) {
489
489
  this.options[name + (name === 'left' || name === 'top' ? 'Offset' : '') + suffix] = value;
490
490
  } else {
491
- throw is.invalidParameterError(name, 'integer', value);
491
+ throw is.invalidParameterError(name, 'integer between 0 and 100000000', value);
492
492
  }
493
493
  }, this);
494
494
  // Ensure existing rotation occurs before pre-resize extraction
package/dist/resize.mjs CHANGED
@@ -471,10 +471,10 @@ function extend (extend) {
471
471
  * });
472
472
  *
473
473
  * @param {Object} options - describes the region to extract using integral pixel values
474
- * @param {number} options.left - zero-indexed offset from left edge
475
- * @param {number} options.top - zero-indexed offset from top edge
476
- * @param {number} options.width - width of region to extract
477
- * @param {number} options.height - height of region to extract
474
+ * @param {number} options.left - zero-indexed offset from left edge, an integer between 0 and 100000000
475
+ * @param {number} options.top - zero-indexed offset from top edge, an integer between 0 and 100000000
476
+ * @param {number} options.width - width of region to extract, an integer between 0 and 100000000
477
+ * @param {number} options.height - height of region to extract, an integer between 0 and 100000000
478
478
  * @returns {Sharp}
479
479
  * @throws {Error} Invalid parameters
480
480
  */
@@ -485,10 +485,10 @@ function extract (options) {
485
485
  }
486
486
  ['left', 'top', 'width', 'height'].forEach(function (name) {
487
487
  const value = options[name];
488
- if (is.integer(value) && value >= 0) {
488
+ if (is.integer(value) && is.inRange(value, 0, 100000000)) {
489
489
  this.options[name + (name === 'left' || name === 'top' ? 'Offset' : '') + suffix] = value;
490
490
  } else {
491
- throw is.invalidParameterError(name, 'integer', value);
491
+ throw is.invalidParameterError(name, 'integer between 0 and 100000000', value);
492
492
  }
493
493
  }, this);
494
494
  // Ensure existing rotation occurs before pre-resize extraction
package/dist/sharp.cjs CHANGED
@@ -49,6 +49,12 @@ if (!sharp) {
49
49
  errors.push(err);
50
50
  sharp = null;
51
51
  }
52
+ if (sharp && process.versions.electron && runtimePlatform.startsWith("linux")) {
53
+ process.emitWarning(
54
+ "Binaries provided by Electron for use on Linux may be incompatible with sharp - see https://sharp.pixelplumbing.com/install#electron-and-linux",
55
+ { code: "SharpElectronLinux" }
56
+ );
57
+ }
52
58
  } catch (err) {
53
59
  errors.push(err);
54
60
  }
package/dist/sharp.mjs CHANGED
@@ -49,6 +49,12 @@ if (!sharp) {
49
49
  errors.push(err);
50
50
  sharp = null;
51
51
  }
52
+ if (sharp && process.versions.electron && runtimePlatform.startsWith("linux")) {
53
+ process.emitWarning(
54
+ "Binaries provided by Electron for use on Linux may be incompatible with sharp - see https://sharp.pixelplumbing.com/install#electron-and-linux",
55
+ { code: "SharpElectronLinux" }
56
+ );
57
+ }
52
58
  } catch (err) {
53
59
  errors.push(err);
54
60
  }
package/dist/utility.cjs CHANGED
@@ -114,6 +114,12 @@ function cache (options) {
114
114
  return sharp.cache(0, 0, 0);
115
115
  }
116
116
  } else if (is.object(options)) {
117
+ for (const property of ['memory', 'files', 'items']) {
118
+ const value = options[property];
119
+ if (is.defined(value) && !(is.integer(value) && value >= 0)) {
120
+ throw is.invalidParameterError(property, 'a positive integer', value);
121
+ }
122
+ }
117
123
  return sharp.cache(options.memory, options.files, options.items);
118
124
  } else {
119
125
  return sharp.cache();
@@ -155,7 +161,7 @@ function concurrency (concurrency) {
155
161
  return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
156
162
  }
157
163
  /* node:coverage ignore next 7 */
158
- if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
164
+ if (!process.env.MALLOC_ARENA_MAX && detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
159
165
  // Reduce default concurrency to 1 when using glibc memory allocator
160
166
  sharp.concurrency(1);
161
167
  } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
package/dist/utility.mjs CHANGED
@@ -114,6 +114,12 @@ function cache (options) {
114
114
  return sharp.cache(0, 0, 0);
115
115
  }
116
116
  } else if (is.object(options)) {
117
+ for (const property of ['memory', 'files', 'items']) {
118
+ const value = options[property];
119
+ if (is.defined(value) && !(is.integer(value) && value >= 0)) {
120
+ throw is.invalidParameterError(property, 'a positive integer', value);
121
+ }
122
+ }
117
123
  return sharp.cache(options.memory, options.files, options.items);
118
124
  } else {
119
125
  return sharp.cache();
@@ -155,7 +161,7 @@ function concurrency (concurrency) {
155
161
  return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
156
162
  }
157
163
  /* node:coverage ignore next 7 */
158
- if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
164
+ if (!process.env.MALLOC_ARENA_MAX && detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
159
165
  // Reduce default concurrency to 1 when using glibc memory allocator
160
166
  sharp.concurrency(1);
161
167
  } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
package/lib/index.d.ts CHANGED
@@ -658,25 +658,27 @@ declare namespace sharp {
658
658
  * @param callback Callback function called on completion with three arguments (err, buffer, info).
659
659
  * @returns A sharp instance that can be used to chain operations
660
660
  */
661
- toBuffer(callback: (err: Error, buffer: Buffer, info: OutputInfo) => void): Sharp;
661
+ toBuffer(callback: (err: Error, buffer: Buffer<ArrayBuffer>, info: OutputInfo) => void): Sharp;
662
662
 
663
663
  /**
664
664
  * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
665
665
  * By default, the format will match the input image, except SVG input which becomes PNG output.
666
+ * The underlying `ArrayBuffer` may be marked as non-transferable by some JavaScript runtimes.
666
667
  * @param options resolve options
667
668
  * @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
668
669
  * @returns A promise that resolves with the Buffer data.
669
670
  */
670
- toBuffer(options?: { resolveWithObject: false }): Promise<Buffer>;
671
+ toBuffer(options?: { resolveWithObject: false }): Promise<Buffer<ArrayBuffer>>;
671
672
 
672
673
  /**
673
674
  * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
674
675
  * By default, the format will match the input image, except SVG input which becomes PNG output.
676
+ * The underlying `ArrayBuffer` may be marked as non-transferable by some JavaScript runtimes.
675
677
  * @param options resolve options
676
678
  * @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
677
679
  * @returns A promise that resolves with an object containing the Buffer data and an info object containing the output image format, size (bytes), width, height and channels
678
680
  */
679
- toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer; info: OutputInfo }>;
681
+ toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer<ArrayBuffer>; info: OutputInfo }>;
680
682
 
681
683
  /**
682
684
  * Write output to a Uint8Array backed by a transferable ArrayBuffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
@@ -1602,13 +1604,13 @@ declare namespace sharp {
1602
1604
  }
1603
1605
 
1604
1606
  interface Region {
1605
- /** zero-indexed offset from left edge */
1607
+ /** zero-indexed offset from left edge, an integer between 0 and 100000000 */
1606
1608
  left: number;
1607
- /** zero-indexed offset from top edge */
1609
+ /** zero-indexed offset from top edge, an integer between 0 and 100000000 */
1608
1610
  top: number;
1609
- /** dimension of extracted image */
1611
+ /** dimension of extracted image, an integer between 0 and 100000000 */
1610
1612
  width: number;
1611
- /** dimension of extracted image */
1613
+ /** dimension of extracted image, an integer between 0 and 100000000 */
1612
1614
  height: number;
1613
1615
  }
1614
1616
 
@@ -1787,6 +1789,8 @@ declare namespace sharp {
1787
1789
  channels: Channels;
1788
1790
  /** indicating if premultiplication was used */
1789
1791
  premultiplied: boolean;
1792
+ /** Indicates if the output image has an alpha channel */
1793
+ hasAlpha: boolean;
1790
1794
  /** Only defined when using a crop strategy */
1791
1795
  cropOffsetLeft?: number | undefined;
1792
1796
  /** Only defined when using a crop strategy */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@revizly/sharp",
3
3
  "description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
4
- "version": "0.35.0-revizly40",
4
+ "version": "0.35.0-revizly42",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
@@ -163,25 +163,30 @@
163
163
  "semver": "^7.8.5"
164
164
  },
165
165
  "optionalDependencies": {
166
- "@revizly/sharp-libvips-linux-arm64": "1.0.41",
167
- "@revizly/sharp-libvips-linux-x64": "1.0.41",
168
- "@revizly/sharp-linux-arm64": "0.35.0-revizly40",
169
- "@revizly/sharp-linux-x64": "0.35.0-revizly40"
166
+ "@revizly/sharp-libvips-linux-arm64": "1.0.43",
167
+ "@revizly/sharp-libvips-linux-x64": "1.0.43",
168
+ "@revizly/sharp-linux-arm64": "0.35.0-revizly42",
169
+ "@revizly/sharp-linux-x64": "0.35.0-revizly42"
170
+ },
171
+ "peerDependenciesMeta": {
172
+ "@types/node": {
173
+ "optional": true
174
+ }
170
175
  },
171
176
  "devDependencies": {
172
177
  "@biomejs/biome": "^2.5.1",
173
178
  "@cpplint/cli": "^0.1.0",
174
179
  "@emnapi/runtime": "^1.11.1",
175
- "@revizly/sharp-libvips-dev": "1.0.41",
180
+ "@revizly/sharp-libvips-dev": "1.0.43",
176
181
  "@types/node": "*",
177
182
  "emnapi": "^1.11.1",
178
183
  "exif-reader": "^2.0.3",
179
184
  "extract-zip": "^2.0.1",
180
185
  "icc": "^4.0.0",
181
- "node-addon-api": "^8.8.0",
186
+ "node-addon-api": "^8.9.0",
182
187
  "node-gyp": "^12.4.0",
183
188
  "publint": "^0.3.21",
184
- "tar-fs": "^3.1.2",
189
+ "tar-fs": "^3.1.3",
185
190
  "tsd": "^0.33.0"
186
191
  },
187
192
  "license": "Apache-2.0",
package/src/pipeline.cc CHANGED
@@ -944,6 +944,7 @@ class PipelineWorker : public Napi::AsyncWorker {
944
944
  baton->pageHeightOut = image.get_int(VIPS_META_PAGE_HEIGHT);
945
945
  baton->pagesOut = image.get_int(VIPS_META_N_PAGES);
946
946
  }
947
+ baton->hasAlphaOut = image.has_alpha();
947
948
 
948
949
  // Output
949
950
  sharp::SetTimeout(image, baton->timeoutSeconds);
@@ -983,6 +984,7 @@ class PipelineWorker : public Napi::AsyncWorker {
983
984
  } else {
984
985
  baton->channels = std::min(baton->channels, 3);
985
986
  }
987
+ baton->hasAlphaOut = false;
986
988
  } else if (baton->formatOut == "jp2" || (baton->formatOut == "input"
987
989
  && inputImageType == sharp::ImageType::JP2)) {
988
990
  // Write JP2 to Buffer
@@ -1065,6 +1067,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1065
1067
  if (baton->tiffCompression == VIPS_FOREIGN_TIFF_COMPRESSION_JPEG) {
1066
1068
  sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
1067
1069
  baton->channels = std::min(baton->channels, 3);
1070
+ baton->hasAlphaOut = false;
1068
1071
  }
1069
1072
  // Cast pixel values to float, if required
1070
1073
  if (baton->tiffPredictor == VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT) {
@@ -1125,6 +1128,9 @@ class PipelineWorker : public Napi::AsyncWorker {
1125
1128
  area->free_fn = nullptr;
1126
1129
  vips_area_unref(area);
1127
1130
  baton->formatOut = "dz";
1131
+ if (baton->tileFormat == "jpeg") {
1132
+ baton->hasAlphaOut = false;
1133
+ }
1128
1134
  } else if (baton->formatOut == "jxl" ||
1129
1135
  (baton->formatOut == "input" && inputImageType == sharp::ImageType::JXL)) {
1130
1136
  // Write JXL to buffer
@@ -1212,6 +1218,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1212
1218
  }
1213
1219
  baton->formatOut = "jpeg";
1214
1220
  baton->channels = std::min(baton->channels, 3);
1221
+ baton->hasAlphaOut = false;
1215
1222
  } else if (baton->formatOut == "jp2" || (mightMatchInput && isJp2) ||
1216
1223
  (willMatchInput && (inputImageType == sharp::ImageType::JP2))) {
1217
1224
  // Write JP2 to file
@@ -1278,6 +1285,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1278
1285
  if (baton->tiffCompression == VIPS_FOREIGN_TIFF_COMPRESSION_JPEG) {
1279
1286
  sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
1280
1287
  baton->channels = std::min(baton->channels, 3);
1288
+ baton->hasAlphaOut = false;
1281
1289
  }
1282
1290
  // Cast pixel values to float, if required
1283
1291
  if (baton->tiffPredictor == VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT) {
@@ -1339,6 +1347,9 @@ class PipelineWorker : public Napi::AsyncWorker {
1339
1347
  vips::VOption *options = BuildOptionsDZ(baton);
1340
1348
  image.dzsave(const_cast<char*>(baton->fileOut.data()), options);
1341
1349
  baton->formatOut = "dz";
1350
+ if (baton->tileFormat == "jpeg") {
1351
+ baton->hasAlphaOut = false;
1352
+ }
1342
1353
  } else if (baton->formatOut == "v" || (mightMatchInput && isV) ||
1343
1354
  (willMatchInput && inputImageType == sharp::ImageType::VIPS)) {
1344
1355
  // Write V to file
@@ -1423,6 +1434,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1423
1434
  info.Set("pageHeight", static_cast<int32_t>(baton->pageHeightOut));
1424
1435
  info.Set("pages", static_cast<int32_t>(baton->pagesOut));
1425
1436
  }
1437
+ info.Set("hasAlpha", baton->hasAlphaOut);
1426
1438
 
1427
1439
  if (baton->bufferOutLength > 0) {
1428
1440
  info.Set("size", static_cast<uint32_t>(baton->bufferOutLength));
package/src/pipeline.h CHANGED
@@ -49,6 +49,7 @@ struct PipelineBaton {
49
49
  int pageHeightOut;
50
50
  int pagesOut;
51
51
  bool typedArrayOut;
52
+ bool hasAlphaOut;
52
53
  std::vector<Composite *> composite;
53
54
  std::vector<sharp::InputDescriptor *> joinChannelIn;
54
55
  int topOffsetPre;
@@ -250,6 +251,7 @@ struct PipelineBaton {
250
251
  pageHeightOut(0),
251
252
  pagesOut(0),
252
253
  typedArrayOut(false),
254
+ hasAlphaOut(false),
253
255
  topOffsetPre(-1),
254
256
  topOffsetPost(-1),
255
257
  channels(0),
package/src/utilities.cc CHANGED
@@ -23,15 +23,15 @@ Napi::Value cache(const Napi::CallbackInfo& info) {
23
23
 
24
24
  // Set memory limit
25
25
  if (info[size_t(0)].IsNumber()) {
26
- vips_cache_set_max_mem(info[size_t(0)].As<Napi::Number>().Int32Value() * 1048576);
26
+ vips_cache_set_max_mem(static_cast<size_t>(info[size_t(0)].As<Napi::Number>().Uint32Value()) * 1048576);
27
27
  }
28
28
  // Set file limit
29
29
  if (info[size_t(1)].IsNumber()) {
30
- vips_cache_set_max_files(info[size_t(1)].As<Napi::Number>().Int32Value());
30
+ vips_cache_set_max_files(info[size_t(1)].As<Napi::Number>().Uint32Value());
31
31
  }
32
32
  // Set items limit
33
33
  if (info[size_t(2)].IsNumber()) {
34
- vips_cache_set_max(info[size_t(2)].As<Napi::Number>().Int32Value());
34
+ vips_cache_set_max(info[size_t(2)].As<Napi::Number>().Uint32Value());
35
35
  }
36
36
 
37
37
  // Get memory stats