@depup/sharp 0.34.5-depup.0 → 0.35.4-depup.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.
Files changed (47) hide show
  1. package/README.md +16 -109
  2. package/changes.json +5 -0
  3. package/{lib/channel.js → dist/channel.cjs} +1 -1
  4. package/dist/channel.mjs +177 -0
  5. package/{lib/colour.js → dist/colour.cjs} +11 -7
  6. package/dist/colour.mjs +199 -0
  7. package/{lib/composite.js → dist/composite.cjs} +8 -7
  8. package/dist/composite.mjs +213 -0
  9. package/{lib/constructor.js → dist/constructor.cjs} +42 -30
  10. package/dist/constructor.mjs +511 -0
  11. package/dist/index.cjs +25 -0
  12. package/dist/index.d.cts +1999 -0
  13. package/dist/index.d.mts +2046 -0
  14. package/dist/index.mjs +25 -0
  15. package/{lib/input.js → dist/input.cjs} +47 -37
  16. package/dist/input.mjs +819 -0
  17. package/{lib/is.js → dist/is.cjs} +1 -1
  18. package/dist/is.mjs +143 -0
  19. package/{lib/libvips.js → dist/libvips.cjs} +35 -30
  20. package/dist/libvips.mjs +212 -0
  21. package/{lib/operation.js → dist/operation.cjs} +37 -51
  22. package/dist/operation.mjs +1002 -0
  23. package/{lib/output.js → dist/output.cjs} +166 -47
  24. package/dist/output.mjs +1785 -0
  25. package/{lib/resize.js → dist/resize.cjs} +54 -32
  26. package/dist/resize.mjs +617 -0
  27. package/dist/sharp.cjs +174 -0
  28. package/dist/sharp.mjs +174 -0
  29. package/{lib/utility.js → dist/utility.cjs} +18 -8
  30. package/dist/utility.mjs +301 -0
  31. package/install/build.js +3 -3
  32. package/lib/index.d.ts +111 -83
  33. package/package.json +95 -54
  34. package/src/binding.gyp +19 -14
  35. package/src/common.cc +77 -21
  36. package/src/common.h +23 -4
  37. package/src/metadata.cc +66 -8
  38. package/src/metadata.h +6 -1
  39. package/src/operations.cc +25 -8
  40. package/src/operations.h +1 -1
  41. package/src/pipeline.cc +203 -69
  42. package/src/pipeline.h +15 -1
  43. package/src/stats.cc +6 -6
  44. package/src/utilities.cc +7 -6
  45. package/install/check.js +0 -14
  46. package/lib/index.js +0 -16
  47. package/lib/sharp.js +0 -121
package/dist/index.mjs ADDED
@@ -0,0 +1,25 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import Sharp from './constructor.mjs';
7
+ import input from './input.mjs';
8
+ import resize from './resize.mjs';
9
+ import composite from './composite.mjs';
10
+ import operation from './operation.mjs';
11
+ import colour from './colour.mjs';
12
+ import channel from './channel.mjs';
13
+ import output from './output.mjs';
14
+ import utility from './utility.mjs';
15
+
16
+ input(Sharp);
17
+ resize(Sharp);
18
+ composite(Sharp);
19
+ operation(Sharp);
20
+ colour(Sharp);
21
+ channel(Sharp);
22
+ output(Sharp);
23
+ utility(Sharp);
24
+
25
+ export default Sharp;
@@ -3,8 +3,8 @@
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
6
- const is = require('./is');
7
- const sharp = require('./sharp');
6
+ const is = require('./is.cjs');
7
+ const sharp = require('./sharp.cjs');
8
8
 
9
9
  /**
10
10
  * Justification alignment
@@ -24,13 +24,13 @@ const align = {
24
24
 
25
25
  const inputStreamParameters = [
26
26
  // Limits and error handling
27
- 'failOn', 'limitInputPixels', 'unlimited',
27
+ 'failOn', 'limitInputPixels', 'limitInputChannels', 'unlimited',
28
28
  // Format-generic
29
29
  'animated', 'autoOrient', 'density', 'ignoreIcc', 'page', 'pages', 'sequentialRead',
30
30
  // Format-specific
31
31
  'jp2', 'openSlide', 'pdf', 'raw', 'svg', 'tiff',
32
32
  // Deprecated
33
- 'failOnError', 'openSlideLevel', 'pdfBackground', 'tiffSubifd'
33
+ 'openSlideLevel', 'pdfBackground', 'tiffSubifd'
34
34
  ];
35
35
 
36
36
  /**
@@ -55,6 +55,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
55
55
  autoOrient: false,
56
56
  failOn: 'warning',
57
57
  limitInputPixels: 0x3FFF ** 2,
58
+ limitInputChannels: 5,
58
59
  ignoreIcc: false,
59
60
  unlimited: false,
60
61
  sequentialRead: true
@@ -106,14 +107,6 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
106
107
  }`);
107
108
  }
108
109
  if (is.object(inputOptions)) {
109
- // Deprecated: failOnError
110
- if (is.defined(inputOptions.failOnError)) {
111
- if (is.bool(inputOptions.failOnError)) {
112
- inputDescriptor.failOn = inputOptions.failOnError ? 'warning' : 'none';
113
- } else {
114
- throw is.invalidParameterError('failOnError', 'boolean', inputOptions.failOnError);
115
- }
116
- }
117
110
  // failOn
118
111
  if (is.defined(inputOptions.failOn)) {
119
112
  if (is.string(inputOptions.failOn) && is.inArray(inputOptions.failOn, ['none', 'truncated', 'error', 'warning'])) {
@@ -132,7 +125,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
132
125
  }
133
126
  // Density
134
127
  if (is.defined(inputOptions.density)) {
135
- if (is.inRange(inputOptions.density, 1, 100000)) {
128
+ if (is.number(inputOptions.density) && is.inRange(inputOptions.density, 1, 100000)) {
136
129
  inputDescriptor.density = inputOptions.density;
137
130
  } else {
138
131
  throw is.invalidParameterError('density', 'number between 1 and 100000', inputOptions.density);
@@ -158,6 +151,16 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
158
151
  throw is.invalidParameterError('limitInputPixels', 'positive integer', inputOptions.limitInputPixels);
159
152
  }
160
153
  }
154
+ // limitInputChannels
155
+ if (is.defined(inputOptions.limitInputChannels)) {
156
+ if (is.bool(inputOptions.limitInputChannels)) {
157
+ inputDescriptor.limitInputChannels = inputOptions.limitInputChannels ? 5 : 0;
158
+ } else if (is.integer(inputOptions.limitInputChannels) && is.inRange(inputOptions.limitInputChannels, 0, Number.MAX_SAFE_INTEGER)) {
159
+ inputDescriptor.limitInputChannels = inputOptions.limitInputChannels;
160
+ } else {
161
+ throw is.invalidParameterError('limitInputChannels', 'positive integer', inputOptions.limitInputChannels);
162
+ }
163
+ }
161
164
  // unlimited
162
165
  if (is.defined(inputOptions.unlimited)) {
163
166
  if (is.bool(inputOptions.unlimited)) {
@@ -178,8 +181,8 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
178
181
  if (is.defined(inputOptions.raw)) {
179
182
  if (
180
183
  is.object(inputOptions.raw) &&
181
- is.integer(inputOptions.raw.width) && inputOptions.raw.width > 0 &&
182
- 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) &&
183
186
  is.integer(inputOptions.raw.channels) && is.inRange(inputOptions.raw.channels, 1, 4)
184
187
  ) {
185
188
  inputDescriptor.rawWidth = inputOptions.raw.width;
@@ -326,8 +329,8 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
326
329
  if (is.defined(inputOptions.create)) {
327
330
  if (
328
331
  is.object(inputOptions.create) &&
329
- is.integer(inputOptions.create.width) && inputOptions.create.width > 0 &&
330
- 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) &&
331
334
  is.integer(inputOptions.create.channels)
332
335
  ) {
333
336
  inputDescriptor.createWidth = inputOptions.create.width;
@@ -407,17 +410,17 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
407
410
  }
408
411
  }
409
412
  if (is.defined(inputOptions.text.width)) {
410
- if (is.integer(inputOptions.text.width) && inputOptions.text.width > 0) {
413
+ if (is.integer(inputOptions.text.width) && is.inRange(inputOptions.text.width, 1, 1000000)) {
411
414
  inputDescriptor.textWidth = inputOptions.text.width;
412
415
  } else {
413
- throw is.invalidParameterError('text.width', 'positive integer', inputOptions.text.width);
416
+ throw is.invalidParameterError('text.width', 'integer between 1 and 1000000', inputOptions.text.width);
414
417
  }
415
418
  }
416
419
  if (is.defined(inputOptions.text.height)) {
417
- if (is.integer(inputOptions.text.height) && inputOptions.text.height > 0) {
420
+ if (is.integer(inputOptions.text.height) && is.inRange(inputOptions.text.height, 1, 1000000)) {
418
421
  inputDescriptor.textHeight = inputOptions.text.height;
419
422
  } else {
420
- throw is.invalidParameterError('text.height', 'positive integer', inputOptions.text.height);
423
+ throw is.invalidParameterError('text.height', 'integer between 1 and 1000000', inputOptions.text.height);
421
424
  }
422
425
  }
423
426
  if (is.defined(inputOptions.text.align)) {
@@ -528,11 +531,6 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
528
531
  function _write (chunk, _encoding, callback) {
529
532
  if (Array.isArray(this.options.input.buffer)) {
530
533
  if (is.buffer(chunk)) {
531
- if (this.options.input.buffer.length === 0) {
532
- this.on('finish', () => {
533
- this.streamInFinished = true;
534
- });
535
- }
536
534
  this.options.input.buffer.push(chunk);
537
535
  callback();
538
536
  } else {
@@ -562,6 +560,20 @@ function _isStreamInput () {
562
560
  return Array.isArray(this.options.input.buffer);
563
561
  }
564
562
 
563
+ /**
564
+ * Call fn when the Writable side of Stream-based input has finished,
565
+ * or immediately when it already has, as 'finish' is emitted only once.
566
+ * @private
567
+ * @param {Function} fn
568
+ */
569
+ function _whenStreamInFinished (fn) {
570
+ if (this.writableFinished) {
571
+ fn();
572
+ } else {
573
+ this.once('finish', fn);
574
+ }
575
+ }
576
+
565
577
  /**
566
578
  * Fast access to (uncached) image metadata without decoding any compressed pixel data.
567
579
  *
@@ -574,7 +586,8 @@ function _isStreamInput () {
574
586
  *
575
587
  * A `Promise` is returned when `callback` is not provided.
576
588
  *
577
- * - `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
589
+ * - `format`: Name of decoder used to parse image e.g. `jpeg`, `png`, `webp`, `gif`, `svg`, `heif`, `tiff`
590
+ * - `mediaType`: Media Type (MIME Type) e.g. `image/jpeg`, `image/png`, `image/svg+xml`, `image/avif`
578
591
  * - `size`: Total size of image in bytes, for Stream and Buffer input only
579
592
  * - `width`: Number of pixels wide (EXIF orientation is not taken into consideration, see example below)
580
593
  * - `height`: Number of pixels high (EXIF orientation is not taken into consideration, see example below)
@@ -607,6 +620,7 @@ function _isStreamInput () {
607
620
  * - `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
608
621
  * - `formatMagick`: String containing format for images loaded via *magick
609
622
  * - `comments`: Array of keyword/text pairs representing PNG text blocks, if present.
623
+ * - `gainMap.image`: HDR gain map, if present, as compressed JPEG image.
610
624
  *
611
625
  * @example
612
626
  * const metadata = await sharp(input).metadata();
@@ -637,7 +651,7 @@ function metadata (callback) {
637
651
  const stack = Error();
638
652
  if (is.fn(callback)) {
639
653
  if (this._isStreamInput()) {
640
- this.on('finish', () => {
654
+ this._whenStreamInFinished(() => {
641
655
  this._flattenBufferIn();
642
656
  sharp.metadata(this.options, (err, metadata) => {
643
657
  if (err) {
@@ -660,7 +674,7 @@ function metadata (callback) {
660
674
  } else {
661
675
  if (this._isStreamInput()) {
662
676
  return new Promise((resolve, reject) => {
663
- const finished = () => {
677
+ this._whenStreamInFinished(() => {
664
678
  this._flattenBufferIn();
665
679
  sharp.metadata(this.options, (err, metadata) => {
666
680
  if (err) {
@@ -669,12 +683,7 @@ function metadata (callback) {
669
683
  resolve(metadata);
670
684
  }
671
685
  });
672
- };
673
- if (this.writableFinished) {
674
- finished();
675
- } else {
676
- this.once('finish', finished);
677
- }
686
+ });
678
687
  });
679
688
  } else {
680
689
  return new Promise((resolve, reject) => {
@@ -739,7 +748,7 @@ function stats (callback) {
739
748
  const stack = Error();
740
749
  if (is.fn(callback)) {
741
750
  if (this._isStreamInput()) {
742
- this.on('finish', () => {
751
+ this._whenStreamInFinished(() => {
743
752
  this._flattenBufferIn();
744
753
  sharp.stats(this.options, (err, stats) => {
745
754
  if (err) {
@@ -762,7 +771,7 @@ function stats (callback) {
762
771
  } else {
763
772
  if (this._isStreamInput()) {
764
773
  return new Promise((resolve, reject) => {
765
- this.on('finish', function () {
774
+ this._whenStreamInFinished(() => {
766
775
  this._flattenBufferIn();
767
776
  sharp.stats(this.options, (err, stats) => {
768
777
  if (err) {
@@ -800,6 +809,7 @@ module.exports = (Sharp) => {
800
809
  _write,
801
810
  _flattenBufferIn,
802
811
  _isStreamInput,
812
+ _whenStreamInFinished,
803
813
  // Public
804
814
  metadata,
805
815
  stats