@revizly/sharp 0.35.0-revizly39 → 0.35.0-revizly40

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/index.d.cts CHANGED
@@ -1512,11 +1512,11 @@ declare namespace sharp {
1512
1512
  tile?: boolean | undefined;
1513
1513
  /** Horizontal tile size (optional, default 256) */
1514
1514
  tileWidth?: number | undefined;
1515
- /** Vertical tile size (optional, default 256) */
1515
+ /** Vertical tile size, valid values are integers in the range 1-32768 (optional, default 256) */
1516
1516
  tileHeight?: number | undefined;
1517
- /** Horizontal resolution in pixels/mm (optional, default 1.0) */
1517
+ /** Horizontal resolution in pixels/mm, valid values are numbers in the range 0.001-1000000 (optional, default 1.0) */
1518
1518
  xres?: number | undefined;
1519
- /** Vertical resolution in pixels/mm (optional, default 1.0) */
1519
+ /** Vertical resolution in pixels/mm, valid values are numbers in the range 0.001-1000000 (optional, default 1.0) */
1520
1520
  yres?: number | undefined;
1521
1521
  /** Reduce bitdepth to 1, 2 or 4 bit (optional) */
1522
1522
  bitdepth?: 1 | 2 | 4 | undefined;
@@ -1624,13 +1624,13 @@ declare namespace sharp {
1624
1624
  type ExtendWith = 'background' | 'copy' | 'repeat' | 'mirror';
1625
1625
 
1626
1626
  interface ExtendOptions {
1627
- /** single pixel count to top edge (optional, default 0) */
1627
+ /** single pixel count to top edge, valid values are integers in the range 0-10000 (optional, default 0) */
1628
1628
  top?: number | undefined;
1629
- /** single pixel count to left edge (optional, default 0) */
1629
+ /** single pixel count to left edge, valid values are integers in the range 0-10000 (optional, default 0) */
1630
1630
  left?: number | undefined;
1631
- /** single pixel count to bottom edge (optional, default 0) */
1631
+ /** single pixel count to bottom edge, valid values are integers in the range 0-10000 (optional, default 0) */
1632
1632
  bottom?: number | undefined;
1633
- /** single pixel count to right edge (optional, default 0) */
1633
+ /** single pixel count to right edge, valid values are integers in the range 0-10000 (optional, default 0) */
1634
1634
  right?: number | undefined;
1635
1635
  /** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
1636
1636
  background?: ColorLike | undefined;
@@ -1645,7 +1645,7 @@ declare namespace sharp {
1645
1645
  threshold?: number | undefined;
1646
1646
  /** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
1647
1647
  lineArt?: boolean | undefined;
1648
- /** Leave a margin around trimmed content, value is in pixels. (optional, default 0) */
1648
+ /** Leave a margin around trimmed content, integral number of pixels between 0 and 10000000. (optional, default 0) */
1649
1649
  margin?: number | undefined;
1650
1650
  }
1651
1651
 
@@ -1673,11 +1673,11 @@ declare namespace sharp {
1673
1673
  }
1674
1674
 
1675
1675
  interface ClaheOptions {
1676
- /** width of the region */
1676
+ /** width of the region. Valid values are integers in the range 1-65536. */
1677
1677
  width: number;
1678
- /** height of the region */
1678
+ /** height of the region. Valid values are integers in the range 1-65536. */
1679
1679
  height: number;
1680
- /** max slope of the cumulative contrast. A value of 0 disables contrast limiting. Valid values are integers in the range 0-100 (inclusive) (optional, default 3) */
1680
+ /** max slope of the cumulative contrast. A value of 0 disables contrast limiting. Valid values are integers in the range 0-100. (optional, default 3) */
1681
1681
  maxSlope?: number | undefined;
1682
1682
  }
1683
1683
 
package/dist/index.d.mts CHANGED
@@ -1506,11 +1506,11 @@ export interface TiffOptions extends OutputOptions {
1506
1506
  tile?: boolean | undefined;
1507
1507
  /** Horizontal tile size (optional, default 256) */
1508
1508
  tileWidth?: number | undefined;
1509
- /** Vertical tile size (optional, default 256) */
1509
+ /** Vertical tile size, valid values are integers in the range 1-32768 (optional, default 256) */
1510
1510
  tileHeight?: number | undefined;
1511
- /** Horizontal resolution in pixels/mm (optional, default 1.0) */
1511
+ /** Horizontal resolution in pixels/mm, valid values are numbers in the range 0.001-1000000 (optional, default 1.0) */
1512
1512
  xres?: number | undefined;
1513
- /** Vertical resolution in pixels/mm (optional, default 1.0) */
1513
+ /** Vertical resolution in pixels/mm, valid values are numbers in the range 0.001-1000000 (optional, default 1.0) */
1514
1514
  yres?: number | undefined;
1515
1515
  /** Reduce bitdepth to 1, 2 or 4 bit (optional) */
1516
1516
  bitdepth?: 1 | 2 | 4 | undefined;
@@ -1618,13 +1618,13 @@ export interface Noise {
1618
1618
  export type ExtendWith = 'background' | 'copy' | 'repeat' | 'mirror';
1619
1619
 
1620
1620
  export interface ExtendOptions {
1621
- /** single pixel count to top edge (optional, default 0) */
1621
+ /** single pixel count to top edge, valid values are integers in the range 0-10000 (optional, default 0) */
1622
1622
  top?: number | undefined;
1623
- /** single pixel count to left edge (optional, default 0) */
1623
+ /** single pixel count to left edge, valid values are integers in the range 0-10000 (optional, default 0) */
1624
1624
  left?: number | undefined;
1625
- /** single pixel count to bottom edge (optional, default 0) */
1625
+ /** single pixel count to bottom edge, valid values are integers in the range 0-10000 (optional, default 0) */
1626
1626
  bottom?: number | undefined;
1627
- /** single pixel count to right edge (optional, default 0) */
1627
+ /** single pixel count to right edge, valid values are integers in the range 0-10000 (optional, default 0) */
1628
1628
  right?: number | undefined;
1629
1629
  /** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
1630
1630
  background?: ColorLike | undefined;
@@ -1639,7 +1639,7 @@ export interface TrimOptions {
1639
1639
  threshold?: number | undefined;
1640
1640
  /** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
1641
1641
  lineArt?: boolean | undefined;
1642
- /** Leave a margin around trimmed content, value is in pixels. (optional, default 0) */
1642
+ /** Leave a margin around trimmed content, integral number of pixels between 0 and 10000000. (optional, default 0) */
1643
1643
  margin?: number | undefined;
1644
1644
  }
1645
1645
 
@@ -1667,11 +1667,11 @@ export interface Kernel {
1667
1667
  }
1668
1668
 
1669
1669
  export interface ClaheOptions {
1670
- /** width of the region */
1670
+ /** width of the region. Valid values are integers in the range 1-65536. */
1671
1671
  width: number;
1672
- /** height of the region */
1672
+ /** height of the region. Valid values are integers in the range 1-65536. */
1673
1673
  height: number;
1674
- /** max slope of the cumulative contrast. A value of 0 disables contrast limiting. Valid values are integers in the range 0-100 (inclusive) (optional, default 3) */
1674
+ /** max slope of the cumulative contrast. A value of 0 disables contrast limiting. Valid values are integers in the range 0-100. (optional, default 3) */
1675
1675
  maxSlope?: number | undefined;
1676
1676
  }
1677
1677
 
package/dist/input.cjs CHANGED
@@ -410,17 +410,17 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
410
410
  }
411
411
  }
412
412
  if (is.defined(inputOptions.text.width)) {
413
- if (is.integer(inputOptions.text.width) && inputOptions.text.width > 0) {
413
+ if (is.integer(inputOptions.text.width) && is.inRange(inputOptions.text.width, 1, 1000000)) {
414
414
  inputDescriptor.textWidth = inputOptions.text.width;
415
415
  } else {
416
- throw is.invalidParameterError('text.width', 'positive integer', inputOptions.text.width);
416
+ throw is.invalidParameterError('text.width', 'integer between 1 and 1000000', inputOptions.text.width);
417
417
  }
418
418
  }
419
419
  if (is.defined(inputOptions.text.height)) {
420
- if (is.integer(inputOptions.text.height) && inputOptions.text.height > 0) {
420
+ if (is.integer(inputOptions.text.height) && is.inRange(inputOptions.text.height, 1, 1000000)) {
421
421
  inputDescriptor.textHeight = inputOptions.text.height;
422
422
  } else {
423
- throw is.invalidParameterError('text.height', 'positive integer', inputOptions.text.height);
423
+ throw is.invalidParameterError('text.height', 'integer between 1 and 1000000', inputOptions.text.height);
424
424
  }
425
425
  }
426
426
  if (is.defined(inputOptions.text.align)) {
package/dist/input.mjs CHANGED
@@ -410,17 +410,17 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
410
410
  }
411
411
  }
412
412
  if (is.defined(inputOptions.text.width)) {
413
- if (is.integer(inputOptions.text.width) && inputOptions.text.width > 0) {
413
+ if (is.integer(inputOptions.text.width) && is.inRange(inputOptions.text.width, 1, 1000000)) {
414
414
  inputDescriptor.textWidth = inputOptions.text.width;
415
415
  } else {
416
- throw is.invalidParameterError('text.width', 'positive integer', inputOptions.text.width);
416
+ throw is.invalidParameterError('text.width', 'integer between 1 and 1000000', inputOptions.text.width);
417
417
  }
418
418
  }
419
419
  if (is.defined(inputOptions.text.height)) {
420
- if (is.integer(inputOptions.text.height) && inputOptions.text.height > 0) {
420
+ if (is.integer(inputOptions.text.height) && is.inRange(inputOptions.text.height, 1, 1000000)) {
421
421
  inputDescriptor.textHeight = inputOptions.text.height;
422
422
  } else {
423
- throw is.invalidParameterError('text.height', 'positive integer', inputOptions.text.height);
423
+ throw is.invalidParameterError('text.height', 'integer between 1 and 1000000', inputOptions.text.height);
424
424
  }
425
425
  }
426
426
  if (is.defined(inputOptions.text.align)) {
package/dist/is.cjs CHANGED
@@ -78,7 +78,7 @@ const string = (val) => typeof val === 'string' && val.length > 0;
78
78
  * Is this value a real number?
79
79
  * @private
80
80
  */
81
- const number = (val) => typeof val === 'number' && !Number.isNaN(val);
81
+ const number = (val) => typeof val === 'number' && Number.isFinite(val);
82
82
 
83
83
  /**
84
84
  * Is this value an integer?
package/dist/is.mjs CHANGED
@@ -78,7 +78,7 @@ const string = (val) => typeof val === 'string' && val.length > 0;
78
78
  * Is this value a real number?
79
79
  * @private
80
80
  */
81
- const number = (val) => typeof val === 'number' && !Number.isNaN(val);
81
+ const number = (val) => typeof val === 'number' && Number.isFinite(val);
82
82
 
83
83
  /**
84
84
  * Is this value an integer?
@@ -646,23 +646,23 @@ function normalize (options) {
646
646
  * .toBuffer();
647
647
  *
648
648
  * @param {Object} options
649
- * @param {number} options.width - Integral width of the search window, in pixels.
650
- * @param {number} options.height - Integral height of the search window, in pixels.
649
+ * @param {number} options.width - Integral width of the search window, in pixels, between 1 and 65536.
650
+ * @param {number} options.height - Integral height of the search window, in pixels, between 1 and 65536.
651
651
  * @param {number} [options.maxSlope=3] - Integral level of brightening, between 0 and 100, where 0 disables contrast limiting.
652
652
  * @returns {Sharp}
653
653
  * @throws {Error} Invalid parameters
654
654
  */
655
655
  function clahe (options) {
656
656
  if (is.plainObject(options)) {
657
- if (is.integer(options.width) && options.width > 0) {
657
+ if (is.integer(options.width) && is.inRange(options.width, 1, 65536)) {
658
658
  this.options.claheWidth = options.width;
659
659
  } else {
660
- throw is.invalidParameterError('width', 'integer greater than zero', options.width);
660
+ throw is.invalidParameterError('width', 'integer between 1 and 65536', options.width);
661
661
  }
662
- if (is.integer(options.height) && options.height > 0) {
662
+ if (is.integer(options.height) && is.inRange(options.height, 1, 65536)) {
663
663
  this.options.claheHeight = options.height;
664
664
  } else {
665
- throw is.invalidParameterError('height', 'integer greater than zero', options.height);
665
+ throw is.invalidParameterError('height', 'integer between 1 and 65536', options.height);
666
666
  }
667
667
  if (is.defined(options.maxSlope)) {
668
668
  if (is.integer(options.maxSlope) && is.inRange(options.maxSlope, 0, 100)) {
@@ -706,7 +706,8 @@ function convolve (kernel) {
706
706
  if (!is.object(kernel) || !Array.isArray(kernel.kernel) ||
707
707
  !is.integer(kernel.width) || !is.integer(kernel.height) ||
708
708
  !is.inRange(kernel.width, 3, 1001) || !is.inRange(kernel.height, 3, 1001) ||
709
- kernel.height * kernel.width !== kernel.kernel.length
709
+ kernel.height * kernel.width !== kernel.kernel.length ||
710
+ !kernel.kernel.every(is.number)
710
711
  ) {
711
712
  // must pass in a kernel
712
713
  throw new Error('Invalid convolution kernel');
@@ -646,23 +646,23 @@ function normalize (options) {
646
646
  * .toBuffer();
647
647
  *
648
648
  * @param {Object} options
649
- * @param {number} options.width - Integral width of the search window, in pixels.
650
- * @param {number} options.height - Integral height of the search window, in pixels.
649
+ * @param {number} options.width - Integral width of the search window, in pixels, between 1 and 65536.
650
+ * @param {number} options.height - Integral height of the search window, in pixels, between 1 and 65536.
651
651
  * @param {number} [options.maxSlope=3] - Integral level of brightening, between 0 and 100, where 0 disables contrast limiting.
652
652
  * @returns {Sharp}
653
653
  * @throws {Error} Invalid parameters
654
654
  */
655
655
  function clahe (options) {
656
656
  if (is.plainObject(options)) {
657
- if (is.integer(options.width) && options.width > 0) {
657
+ if (is.integer(options.width) && is.inRange(options.width, 1, 65536)) {
658
658
  this.options.claheWidth = options.width;
659
659
  } else {
660
- throw is.invalidParameterError('width', 'integer greater than zero', options.width);
660
+ throw is.invalidParameterError('width', 'integer between 1 and 65536', options.width);
661
661
  }
662
- if (is.integer(options.height) && options.height > 0) {
662
+ if (is.integer(options.height) && is.inRange(options.height, 1, 65536)) {
663
663
  this.options.claheHeight = options.height;
664
664
  } else {
665
- throw is.invalidParameterError('height', 'integer greater than zero', options.height);
665
+ throw is.invalidParameterError('height', 'integer between 1 and 65536', options.height);
666
666
  }
667
667
  if (is.defined(options.maxSlope)) {
668
668
  if (is.integer(options.maxSlope) && is.inRange(options.maxSlope, 0, 100)) {
@@ -706,7 +706,8 @@ function convolve (kernel) {
706
706
  if (!is.object(kernel) || !Array.isArray(kernel.kernel) ||
707
707
  !is.integer(kernel.width) || !is.integer(kernel.height) ||
708
708
  !is.inRange(kernel.width, 3, 1001) || !is.inRange(kernel.height, 3, 1001) ||
709
- kernel.height * kernel.width !== kernel.kernel.length
709
+ kernel.height * kernel.width !== kernel.kernel.length ||
710
+ !kernel.kernel.every(is.number)
710
711
  ) {
711
712
  // must pass in a kernel
712
713
  throw new Error('Invalid convolution kernel');
package/dist/output.cjs CHANGED
@@ -1103,10 +1103,10 @@ function trySetAnimationOptions (source, target) {
1103
1103
  * @param {string} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
1104
1104
  * @param {boolean} [options.pyramid=false] - write an image pyramid
1105
1105
  * @param {boolean} [options.tile=false] - write a tiled tiff
1106
- * @param {number} [options.tileWidth=256] - horizontal tile size
1107
- * @param {number} [options.tileHeight=256] - vertical tile size
1108
- * @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm
1109
- * @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
1106
+ * @param {number} [options.tileWidth=256] - horizontal tile size, valid values are integers in the range 1-32768
1107
+ * @param {number} [options.tileHeight=256] - vertical tile size, valid values are integers in the range 1-32768
1108
+ * @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm, valid values are numbers in the range 0.001-1000000
1109
+ * @param {number} [options.yres=1.0] - vertical resolution in pixels/mm, valid values are numbers in the range 0.001-1000000
1110
1110
  * @param {string} [options.resolutionUnit='inch'] - resolution unit options: inch, cm
1111
1111
  * @param {number} [options.bitdepth=0] - reduce bitdepth to 1, 2 or 4 bit
1112
1112
  * @param {boolean} [options.miniswhite=false] - write 1-bit images as miniswhite
@@ -1134,17 +1134,17 @@ function tiff (options) {
1134
1134
  this._setBooleanOption('tiffTile', options.tile);
1135
1135
  }
1136
1136
  if (is.defined(options.tileWidth)) {
1137
- if (is.integer(options.tileWidth) && options.tileWidth > 0) {
1137
+ if (is.integer(options.tileWidth) && is.inRange(options.tileWidth, 1, 32768)) {
1138
1138
  this.options.tiffTileWidth = options.tileWidth;
1139
1139
  } else {
1140
- throw is.invalidParameterError('tileWidth', 'integer greater than zero', options.tileWidth);
1140
+ throw is.invalidParameterError('tileWidth', 'integer between 1 and 32768', options.tileWidth);
1141
1141
  }
1142
1142
  }
1143
1143
  if (is.defined(options.tileHeight)) {
1144
- if (is.integer(options.tileHeight) && options.tileHeight > 0) {
1144
+ if (is.integer(options.tileHeight) && is.inRange(options.tileHeight, 1, 32768)) {
1145
1145
  this.options.tiffTileHeight = options.tileHeight;
1146
1146
  } else {
1147
- throw is.invalidParameterError('tileHeight', 'integer greater than zero', options.tileHeight);
1147
+ throw is.invalidParameterError('tileHeight', 'integer between 1 and 32768', options.tileHeight);
1148
1148
  }
1149
1149
  }
1150
1150
  // miniswhite
@@ -1157,17 +1157,17 @@ function tiff (options) {
1157
1157
  }
1158
1158
  // resolution
1159
1159
  if (is.defined(options.xres)) {
1160
- if (is.number(options.xres) && options.xres > 0) {
1160
+ if (is.number(options.xres) && is.inRange(options.xres, 0.001, 1000000)) {
1161
1161
  this.options.tiffXres = options.xres;
1162
1162
  } else {
1163
- throw is.invalidParameterError('xres', 'number greater than zero', options.xres);
1163
+ throw is.invalidParameterError('xres', 'number between 0.001 and 1000000', options.xres);
1164
1164
  }
1165
1165
  }
1166
1166
  if (is.defined(options.yres)) {
1167
- if (is.number(options.yres) && options.yres > 0) {
1167
+ if (is.number(options.yres) && is.inRange(options.yres, 0.001, 1000000)) {
1168
1168
  this.options.tiffYres = options.yres;
1169
1169
  } else {
1170
- throw is.invalidParameterError('yres', 'number greater than zero', options.yres);
1170
+ throw is.invalidParameterError('yres', 'number between 0.001 and 1000000', options.yres);
1171
1171
  }
1172
1172
  }
1173
1173
  // compression
package/dist/output.mjs CHANGED
@@ -1103,10 +1103,10 @@ function trySetAnimationOptions (source, target) {
1103
1103
  * @param {string} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
1104
1104
  * @param {boolean} [options.pyramid=false] - write an image pyramid
1105
1105
  * @param {boolean} [options.tile=false] - write a tiled tiff
1106
- * @param {number} [options.tileWidth=256] - horizontal tile size
1107
- * @param {number} [options.tileHeight=256] - vertical tile size
1108
- * @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm
1109
- * @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
1106
+ * @param {number} [options.tileWidth=256] - horizontal tile size, valid values are integers in the range 1-32768
1107
+ * @param {number} [options.tileHeight=256] - vertical tile size, valid values are integers in the range 1-32768
1108
+ * @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm, valid values are numbers in the range 0.001-1000000
1109
+ * @param {number} [options.yres=1.0] - vertical resolution in pixels/mm, valid values are numbers in the range 0.001-1000000
1110
1110
  * @param {string} [options.resolutionUnit='inch'] - resolution unit options: inch, cm
1111
1111
  * @param {number} [options.bitdepth=0] - reduce bitdepth to 1, 2 or 4 bit
1112
1112
  * @param {boolean} [options.miniswhite=false] - write 1-bit images as miniswhite
@@ -1134,17 +1134,17 @@ function tiff (options) {
1134
1134
  this._setBooleanOption('tiffTile', options.tile);
1135
1135
  }
1136
1136
  if (is.defined(options.tileWidth)) {
1137
- if (is.integer(options.tileWidth) && options.tileWidth > 0) {
1137
+ if (is.integer(options.tileWidth) && is.inRange(options.tileWidth, 1, 32768)) {
1138
1138
  this.options.tiffTileWidth = options.tileWidth;
1139
1139
  } else {
1140
- throw is.invalidParameterError('tileWidth', 'integer greater than zero', options.tileWidth);
1140
+ throw is.invalidParameterError('tileWidth', 'integer between 1 and 32768', options.tileWidth);
1141
1141
  }
1142
1142
  }
1143
1143
  if (is.defined(options.tileHeight)) {
1144
- if (is.integer(options.tileHeight) && options.tileHeight > 0) {
1144
+ if (is.integer(options.tileHeight) && is.inRange(options.tileHeight, 1, 32768)) {
1145
1145
  this.options.tiffTileHeight = options.tileHeight;
1146
1146
  } else {
1147
- throw is.invalidParameterError('tileHeight', 'integer greater than zero', options.tileHeight);
1147
+ throw is.invalidParameterError('tileHeight', 'integer between 1 and 32768', options.tileHeight);
1148
1148
  }
1149
1149
  }
1150
1150
  // miniswhite
@@ -1157,17 +1157,17 @@ function tiff (options) {
1157
1157
  }
1158
1158
  // resolution
1159
1159
  if (is.defined(options.xres)) {
1160
- if (is.number(options.xres) && options.xres > 0) {
1160
+ if (is.number(options.xres) && is.inRange(options.xres, 0.001, 1000000)) {
1161
1161
  this.options.tiffXres = options.xres;
1162
1162
  } else {
1163
- throw is.invalidParameterError('xres', 'number greater than zero', options.xres);
1163
+ throw is.invalidParameterError('xres', 'number between 0.001 and 1000000', options.xres);
1164
1164
  }
1165
1165
  }
1166
1166
  if (is.defined(options.yres)) {
1167
- if (is.number(options.yres) && options.yres > 0) {
1167
+ if (is.number(options.yres) && is.inRange(options.yres, 0.001, 1000000)) {
1168
1168
  this.options.tiffYres = options.yres;
1169
1169
  } else {
1170
- throw is.invalidParameterError('yres', 'number greater than zero', options.yres);
1170
+ throw is.invalidParameterError('yres', 'number between 0.001 and 1000000', options.yres);
1171
1171
  }
1172
1172
  }
1173
1173
  // compression
package/dist/resize.cjs CHANGED
@@ -386,48 +386,52 @@ function resize (widthOrOptions, height, options) {
386
386
  * ...
387
387
  *
388
388
  * @param {(number|Object)} extend - single pixel count to add to all edges or an Object with per-edge counts
389
- * @param {number} [extend.top=0]
390
- * @param {number} [extend.left=0]
391
- * @param {number} [extend.bottom=0]
392
- * @param {number} [extend.right=0]
389
+ * @param {number} [extend.top=0] - number of pixels to add to the top edge, valid values are integers in the range 0-10000
390
+ * @param {number} [extend.left=0] - number of pixels to add to the left edge, valid values are integers in the range 0-10000
391
+ * @param {number} [extend.bottom=0] - number of pixels to add to the bottom edge, valid values are integers in the range 0-10000
392
+ * @param {number} [extend.right=0] - number of pixels to add to the right edge, valid values are integers in the range 0-10000
393
393
  * @param {String} [extend.extendWith='background'] - populate new pixels using this method, one of: background, copy, repeat, mirror.
394
394
  * @param {String|Object} [extend.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
395
395
  * @returns {Sharp}
396
396
  * @throws {Error} Invalid parameters
397
397
  */
398
398
  function extend (extend) {
399
- if (is.integer(extend) && extend > 0) {
400
- this.options.extendTop = extend;
401
- this.options.extendBottom = extend;
402
- this.options.extendLeft = extend;
403
- this.options.extendRight = extend;
399
+ if (is.integer(extend)) {
400
+ if (is.inRange(extend, 1, 10000)) {
401
+ this.options.extendTop = extend;
402
+ this.options.extendBottom = extend;
403
+ this.options.extendLeft = extend;
404
+ this.options.extendRight = extend;
405
+ } else {
406
+ throw is.invalidParameterError('extend', 'integer between 1 and 10000', extend);
407
+ }
404
408
  } else if (is.object(extend)) {
405
409
  if (is.defined(extend.top)) {
406
- if (is.integer(extend.top) && extend.top >= 0) {
410
+ if (is.integer(extend.top) && is.inRange(extend.top, 0, 10000)) {
407
411
  this.options.extendTop = extend.top;
408
412
  } else {
409
- throw is.invalidParameterError('top', 'positive integer', extend.top);
413
+ throw is.invalidParameterError('top', 'integer between 0 and 10000', extend.top);
410
414
  }
411
415
  }
412
416
  if (is.defined(extend.bottom)) {
413
- if (is.integer(extend.bottom) && extend.bottom >= 0) {
417
+ if (is.integer(extend.bottom) && is.inRange(extend.bottom, 0, 10000)) {
414
418
  this.options.extendBottom = extend.bottom;
415
419
  } else {
416
- throw is.invalidParameterError('bottom', 'positive integer', extend.bottom);
420
+ throw is.invalidParameterError('bottom', 'integer between 0 and 10000', extend.bottom);
417
421
  }
418
422
  }
419
423
  if (is.defined(extend.left)) {
420
- if (is.integer(extend.left) && extend.left >= 0) {
424
+ if (is.integer(extend.left) && is.inRange(extend.left, 0, 10000)) {
421
425
  this.options.extendLeft = extend.left;
422
426
  } else {
423
- throw is.invalidParameterError('left', 'positive integer', extend.left);
427
+ throw is.invalidParameterError('left', 'integer between 0 and 10000', extend.left);
424
428
  }
425
429
  }
426
430
  if (is.defined(extend.right)) {
427
- if (is.integer(extend.right) && extend.right >= 0) {
431
+ if (is.integer(extend.right) && is.inRange(extend.right, 0, 10000)) {
428
432
  this.options.extendRight = extend.right;
429
433
  } else {
430
- throw is.invalidParameterError('right', 'positive integer', extend.right);
434
+ throw is.invalidParameterError('right', 'integer between 0 and 10000', extend.right);
431
435
  }
432
436
  }
433
437
  this._setBackgroundColourOption('extendBackground', extend.background);
@@ -554,7 +558,7 @@ function extract (options) {
554
558
  * @param {string|Object} [options.background='top-left pixel'] - Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel.
555
559
  * @param {number} [options.threshold=10] - Allowed difference from the above colour, a positive number.
556
560
  * @param {boolean} [options.lineArt=false] - Does the input more closely resemble line art (e.g. vector) rather than being photographic?
557
- * @param {number} [options.margin=0] - Leave a margin around trimmed content, value is in pixels.
561
+ * @param {number} [options.margin=0] - Leave a margin around trimmed content, integral number of pixels between 0 and 10000000.
558
562
  * @returns {Sharp}
559
563
  * @throws {Error} Invalid parameters
560
564
  */
@@ -576,10 +580,10 @@ function trim (options) {
576
580
  this._setBooleanOption('trimLineArt', options.lineArt);
577
581
  }
578
582
  if (is.defined(options.margin)) {
579
- if (is.integer(options.margin) && options.margin >= 0) {
583
+ if (is.integer(options.margin) && is.inRange(options.margin, 0, 10000000)) {
580
584
  this.options.trimMargin = options.margin;
581
585
  } else {
582
- throw is.invalidParameterError('margin', 'positive integer', options.margin);
586
+ throw is.invalidParameterError('margin', 'integer between 0 and 10000000', options.margin);
583
587
  }
584
588
  }
585
589
  } else {
package/dist/resize.mjs CHANGED
@@ -386,48 +386,52 @@ function resize (widthOrOptions, height, options) {
386
386
  * ...
387
387
  *
388
388
  * @param {(number|Object)} extend - single pixel count to add to all edges or an Object with per-edge counts
389
- * @param {number} [extend.top=0]
390
- * @param {number} [extend.left=0]
391
- * @param {number} [extend.bottom=0]
392
- * @param {number} [extend.right=0]
389
+ * @param {number} [extend.top=0] - number of pixels to add to the top edge, valid values are integers in the range 0-10000
390
+ * @param {number} [extend.left=0] - number of pixels to add to the left edge, valid values are integers in the range 0-10000
391
+ * @param {number} [extend.bottom=0] - number of pixels to add to the bottom edge, valid values are integers in the range 0-10000
392
+ * @param {number} [extend.right=0] - number of pixels to add to the right edge, valid values are integers in the range 0-10000
393
393
  * @param {String} [extend.extendWith='background'] - populate new pixels using this method, one of: background, copy, repeat, mirror.
394
394
  * @param {String|Object} [extend.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
395
395
  * @returns {Sharp}
396
396
  * @throws {Error} Invalid parameters
397
397
  */
398
398
  function extend (extend) {
399
- if (is.integer(extend) && extend > 0) {
400
- this.options.extendTop = extend;
401
- this.options.extendBottom = extend;
402
- this.options.extendLeft = extend;
403
- this.options.extendRight = extend;
399
+ if (is.integer(extend)) {
400
+ if (is.inRange(extend, 1, 10000)) {
401
+ this.options.extendTop = extend;
402
+ this.options.extendBottom = extend;
403
+ this.options.extendLeft = extend;
404
+ this.options.extendRight = extend;
405
+ } else {
406
+ throw is.invalidParameterError('extend', 'integer between 1 and 10000', extend);
407
+ }
404
408
  } else if (is.object(extend)) {
405
409
  if (is.defined(extend.top)) {
406
- if (is.integer(extend.top) && extend.top >= 0) {
410
+ if (is.integer(extend.top) && is.inRange(extend.top, 0, 10000)) {
407
411
  this.options.extendTop = extend.top;
408
412
  } else {
409
- throw is.invalidParameterError('top', 'positive integer', extend.top);
413
+ throw is.invalidParameterError('top', 'integer between 0 and 10000', extend.top);
410
414
  }
411
415
  }
412
416
  if (is.defined(extend.bottom)) {
413
- if (is.integer(extend.bottom) && extend.bottom >= 0) {
417
+ if (is.integer(extend.bottom) && is.inRange(extend.bottom, 0, 10000)) {
414
418
  this.options.extendBottom = extend.bottom;
415
419
  } else {
416
- throw is.invalidParameterError('bottom', 'positive integer', extend.bottom);
420
+ throw is.invalidParameterError('bottom', 'integer between 0 and 10000', extend.bottom);
417
421
  }
418
422
  }
419
423
  if (is.defined(extend.left)) {
420
- if (is.integer(extend.left) && extend.left >= 0) {
424
+ if (is.integer(extend.left) && is.inRange(extend.left, 0, 10000)) {
421
425
  this.options.extendLeft = extend.left;
422
426
  } else {
423
- throw is.invalidParameterError('left', 'positive integer', extend.left);
427
+ throw is.invalidParameterError('left', 'integer between 0 and 10000', extend.left);
424
428
  }
425
429
  }
426
430
  if (is.defined(extend.right)) {
427
- if (is.integer(extend.right) && extend.right >= 0) {
431
+ if (is.integer(extend.right) && is.inRange(extend.right, 0, 10000)) {
428
432
  this.options.extendRight = extend.right;
429
433
  } else {
430
- throw is.invalidParameterError('right', 'positive integer', extend.right);
434
+ throw is.invalidParameterError('right', 'integer between 0 and 10000', extend.right);
431
435
  }
432
436
  }
433
437
  this._setBackgroundColourOption('extendBackground', extend.background);
@@ -554,7 +558,7 @@ function extract (options) {
554
558
  * @param {string|Object} [options.background='top-left pixel'] - Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel.
555
559
  * @param {number} [options.threshold=10] - Allowed difference from the above colour, a positive number.
556
560
  * @param {boolean} [options.lineArt=false] - Does the input more closely resemble line art (e.g. vector) rather than being photographic?
557
- * @param {number} [options.margin=0] - Leave a margin around trimmed content, value is in pixels.
561
+ * @param {number} [options.margin=0] - Leave a margin around trimmed content, integral number of pixels between 0 and 10000000.
558
562
  * @returns {Sharp}
559
563
  * @throws {Error} Invalid parameters
560
564
  */
@@ -576,10 +580,10 @@ function trim (options) {
576
580
  this._setBooleanOption('trimLineArt', options.lineArt);
577
581
  }
578
582
  if (is.defined(options.margin)) {
579
- if (is.integer(options.margin) && options.margin >= 0) {
583
+ if (is.integer(options.margin) && is.inRange(options.margin, 0, 10000000)) {
580
584
  this.options.trimMargin = options.margin;
581
585
  } else {
582
- throw is.invalidParameterError('margin', 'positive integer', options.margin);
586
+ throw is.invalidParameterError('margin', 'integer between 0 and 10000000', options.margin);
583
587
  }
584
588
  }
585
589
  } else {
package/lib/index.d.ts CHANGED
@@ -1512,11 +1512,11 @@ declare namespace sharp {
1512
1512
  tile?: boolean | undefined;
1513
1513
  /** Horizontal tile size (optional, default 256) */
1514
1514
  tileWidth?: number | undefined;
1515
- /** Vertical tile size (optional, default 256) */
1515
+ /** Vertical tile size, valid values are integers in the range 1-32768 (optional, default 256) */
1516
1516
  tileHeight?: number | undefined;
1517
- /** Horizontal resolution in pixels/mm (optional, default 1.0) */
1517
+ /** Horizontal resolution in pixels/mm, valid values are numbers in the range 0.001-1000000 (optional, default 1.0) */
1518
1518
  xres?: number | undefined;
1519
- /** Vertical resolution in pixels/mm (optional, default 1.0) */
1519
+ /** Vertical resolution in pixels/mm, valid values are numbers in the range 0.001-1000000 (optional, default 1.0) */
1520
1520
  yres?: number | undefined;
1521
1521
  /** Reduce bitdepth to 1, 2 or 4 bit (optional) */
1522
1522
  bitdepth?: 1 | 2 | 4 | undefined;
@@ -1624,13 +1624,13 @@ declare namespace sharp {
1624
1624
  type ExtendWith = 'background' | 'copy' | 'repeat' | 'mirror';
1625
1625
 
1626
1626
  interface ExtendOptions {
1627
- /** single pixel count to top edge (optional, default 0) */
1627
+ /** single pixel count to top edge, valid values are integers in the range 0-10000 (optional, default 0) */
1628
1628
  top?: number | undefined;
1629
- /** single pixel count to left edge (optional, default 0) */
1629
+ /** single pixel count to left edge, valid values are integers in the range 0-10000 (optional, default 0) */
1630
1630
  left?: number | undefined;
1631
- /** single pixel count to bottom edge (optional, default 0) */
1631
+ /** single pixel count to bottom edge, valid values are integers in the range 0-10000 (optional, default 0) */
1632
1632
  bottom?: number | undefined;
1633
- /** single pixel count to right edge (optional, default 0) */
1633
+ /** single pixel count to right edge, valid values are integers in the range 0-10000 (optional, default 0) */
1634
1634
  right?: number | undefined;
1635
1635
  /** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
1636
1636
  background?: ColorLike | undefined;
@@ -1645,7 +1645,7 @@ declare namespace sharp {
1645
1645
  threshold?: number | undefined;
1646
1646
  /** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
1647
1647
  lineArt?: boolean | undefined;
1648
- /** Leave a margin around trimmed content, value is in pixels. (optional, default 0) */
1648
+ /** Leave a margin around trimmed content, integral number of pixels between 0 and 10000000. (optional, default 0) */
1649
1649
  margin?: number | undefined;
1650
1650
  }
1651
1651
 
@@ -1673,11 +1673,11 @@ declare namespace sharp {
1673
1673
  }
1674
1674
 
1675
1675
  interface ClaheOptions {
1676
- /** width of the region */
1676
+ /** width of the region. Valid values are integers in the range 1-65536. */
1677
1677
  width: number;
1678
- /** height of the region */
1678
+ /** height of the region. Valid values are integers in the range 1-65536. */
1679
1679
  height: number;
1680
- /** max slope of the cumulative contrast. A value of 0 disables contrast limiting. Valid values are integers in the range 0-100 (inclusive) (optional, default 3) */
1680
+ /** max slope of the cumulative contrast. A value of 0 disables contrast limiting. Valid values are integers in the range 0-100. (optional, default 3) */
1681
1681
  maxSlope?: number | undefined;
1682
1682
  }
1683
1683
 
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-revizly39",
4
+ "version": "0.35.0-revizly40",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
@@ -160,21 +160,21 @@
160
160
  "dependencies": {
161
161
  "@img/colour": "^1.1.0",
162
162
  "detect-libc": "^2.1.2",
163
- "semver": "^7.8.4"
163
+ "semver": "^7.8.5"
164
164
  },
165
165
  "optionalDependencies": {
166
- "@revizly/sharp-libvips-linux-arm64": "1.0.40",
167
- "@revizly/sharp-libvips-linux-x64": "1.0.40",
168
- "@revizly/sharp-linux-arm64": "0.35.0-revizly39",
169
- "@revizly/sharp-linux-x64": "0.35.0-revizly39"
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"
170
170
  },
171
171
  "devDependencies": {
172
- "@biomejs/biome": "^2.5.0",
172
+ "@biomejs/biome": "^2.5.1",
173
173
  "@cpplint/cli": "^0.1.0",
174
- "@emnapi/runtime": "^1.11.0",
175
- "@revizly/sharp-libvips-dev": "1.0.40",
174
+ "@emnapi/runtime": "^1.11.1",
175
+ "@revizly/sharp-libvips-dev": "1.0.41",
176
176
  "@types/node": "*",
177
- "emnapi": "^1.11.0",
177
+ "emnapi": "^1.11.1",
178
178
  "exif-reader": "^2.0.3",
179
179
  "extract-zip": "^2.0.1",
180
180
  "icc": "^4.0.0",
package/src/pipeline.cc CHANGED
@@ -608,38 +608,25 @@ class PipelineWorker : public Napi::AsyncWorker {
608
608
  baton->width = image.width() + baton->extendLeft + baton->extendRight;
609
609
  baton->height = (nPages > 1 ? targetPageHeight : image.height()) + baton->extendTop + baton->extendBottom;
610
610
 
611
+ std::vector<double> background;
611
612
  if (baton->extendWith == VIPS_EXTEND_BACKGROUND) {
612
- std::vector<double> background;
613
613
  std::tie(image, background) = sharp::ApplyAlpha(image, baton->extendBackground, shouldPremultiplyAlpha);
614
-
615
- image = sharp::StaySequential(image, nPages > 1);
616
- image = nPages > 1
617
- ? sharp::EmbedMultiPage(image,
618
- baton->extendLeft, baton->extendTop, baton->width, baton->height,
619
- baton->extendWith, background, nPages, &targetPageHeight)
620
- : image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height,
621
- VImage::option()->set("extend", baton->extendWith)->set("background", background));
622
- if (baton->keepGainMap) {
623
- gainMap = gainMap.embed(baton->extendLeft / gainMapScaleFactor, baton->extendTop / gainMapScaleFactor,
624
- baton->width / gainMapScaleFactor, baton->height / gainMapScaleFactor, VImage::option()
625
- ->set("extend", baton->extendWith)
626
- ->set("background", 0));
627
- }
628
- } else {
629
- std::vector<double> ignoredBackground(1);
630
- image = sharp::StaySequential(image);
631
- image = nPages > 1
632
- ? sharp::EmbedMultiPage(image,
633
- baton->extendLeft, baton->extendTop, baton->width, baton->height,
634
- baton->extendWith, ignoredBackground, nPages, &targetPageHeight)
635
- : image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height,
636
- VImage::option()->set("extend", baton->extendWith));
637
- if (baton->keepGainMap) {
638
- gainMap = gainMap.embed(baton->extendLeft / gainMapScaleFactor, baton->extendTop / gainMapScaleFactor,
639
- baton->width / gainMapScaleFactor, baton->height / gainMapScaleFactor, VImage::option()
640
- ->set("extend", baton->extendWith)
641
- ->set("background", 0));
642
- }
614
+ }
615
+ image = sharp::StaySequential(image, nPages > 1 || baton->extendWith != VIPS_EXTEND_BACKGROUND);
616
+ auto options = VImage::option()->set("extend", baton->extendWith);
617
+ if (baton->extendWith == VIPS_EXTEND_BACKGROUND) {
618
+ options->set("background", background);
619
+ }
620
+ image = nPages > 1
621
+ ? sharp::EmbedMultiPage(image,
622
+ baton->extendLeft, baton->extendTop, baton->width, baton->height,
623
+ baton->extendWith, background, nPages, &targetPageHeight)
624
+ : image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height, options);
625
+ if (baton->keepGainMap) {
626
+ gainMap = gainMap.embed(baton->extendLeft / gainMapScaleFactor, baton->extendTop / gainMapScaleFactor,
627
+ baton->width / gainMapScaleFactor, baton->height / gainMapScaleFactor, VImage::option()
628
+ ->set("extend", baton->extendWith)
629
+ ->set("background", 0));
643
630
  }
644
631
  }
645
632
  // Median - must happen before blurring, due to the utility of blurring after thresholding