@revizly/sharp 0.35.0-revizly50 → 0.35.0-revizly51

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/is.cjs CHANGED
@@ -107,9 +107,15 @@ const inArray = (val, list) => list.includes(val);
107
107
  * @returns {Error} Containing the formatted message.
108
108
  * @private
109
109
  */
110
- const invalidParameterError = (name, expected, actual) => new Error(
111
- `Expected ${expected} for ${name} but received ${actual} of type ${typeof actual}`
110
+ const invalidParameterError = (name, expected, actual) => {
111
+ let actualString;
112
+ try {
113
+ actualString = String(actual).slice(0, 100);
114
+ } catch {}
115
+ return new Error(
116
+ `Expected ${expected} for ${name} but received ${actualString} of type ${typeof actual}`
112
117
  );
118
+ };
113
119
 
114
120
  /**
115
121
  * Ensures an Error from C++ contains a JS stack.
package/dist/is.mjs CHANGED
@@ -107,9 +107,15 @@ const inArray = (val, list) => list.includes(val);
107
107
  * @returns {Error} Containing the formatted message.
108
108
  * @private
109
109
  */
110
- const invalidParameterError = (name, expected, actual) => new Error(
111
- `Expected ${expected} for ${name} but received ${actual} of type ${typeof actual}`
110
+ const invalidParameterError = (name, expected, actual) => {
111
+ let actualString;
112
+ try {
113
+ actualString = String(actual).slice(0, 100);
114
+ } catch {}
115
+ return new Error(
116
+ `Expected ${expected} for ${name} but received ${actualString} of type ${typeof actual}`
112
117
  );
118
+ };
113
119
 
114
120
  /**
115
121
  * Ensures an Error from C++ contains a JS stack.
@@ -824,7 +824,7 @@ function linear (a, b) {
824
824
  this.options.linearA = [];
825
825
  } else if (is.number(a)) {
826
826
  this.options.linearA = [a];
827
- } else if (Array.isArray(a) && a.length && a.every(is.number)) {
827
+ } else if (Array.isArray(a) && is.inRange(a.length, 1, 1000000) && a.every(is.number)) {
828
828
  this.options.linearA = a;
829
829
  } else {
830
830
  throw is.invalidParameterError('a', 'number or array of numbers', a);
@@ -833,7 +833,7 @@ function linear (a, b) {
833
833
  this.options.linearB = [];
834
834
  } else if (is.number(b)) {
835
835
  this.options.linearB = [b];
836
- } else if (Array.isArray(b) && b.length && b.every(is.number)) {
836
+ } else if (Array.isArray(b) && is.inRange(b.length, 1, 1000000) && b.every(is.number)) {
837
837
  this.options.linearB = b;
838
838
  } else {
839
839
  throw is.invalidParameterError('b', 'number or array of numbers', b);
@@ -824,7 +824,7 @@ function linear (a, b) {
824
824
  this.options.linearA = [];
825
825
  } else if (is.number(a)) {
826
826
  this.options.linearA = [a];
827
- } else if (Array.isArray(a) && a.length && a.every(is.number)) {
827
+ } else if (Array.isArray(a) && is.inRange(a.length, 1, 1000000) && a.every(is.number)) {
828
828
  this.options.linearA = a;
829
829
  } else {
830
830
  throw is.invalidParameterError('a', 'number or array of numbers', a);
@@ -833,7 +833,7 @@ function linear (a, b) {
833
833
  this.options.linearB = [];
834
834
  } else if (is.number(b)) {
835
835
  this.options.linearB = [b];
836
- } else if (Array.isArray(b) && b.length && b.every(is.number)) {
836
+ } else if (Array.isArray(b) && is.inRange(b.length, 1, 1000000) && b.every(is.number)) {
837
837
  this.options.linearB = b;
838
838
  } else {
839
839
  throw is.invalidParameterError('b', 'number or array of numbers', b);
package/dist/output.cjs CHANGED
@@ -1066,6 +1066,7 @@ function trySetAnimationOptions (source, target) {
1066
1066
  target.delay = [source.delay];
1067
1067
  } else if (
1068
1068
  Array.isArray(source.delay) &&
1069
+ is.inRange(source.delay.length, 1, 1000000) &&
1069
1070
  source.delay.every(is.integer) &&
1070
1071
  source.delay.every(v => is.inRange(v, 0, 65535))) {
1071
1072
  target.delay = source.delay;
package/dist/output.mjs CHANGED
@@ -1066,6 +1066,7 @@ function trySetAnimationOptions (source, target) {
1066
1066
  target.delay = [source.delay];
1067
1067
  } else if (
1068
1068
  Array.isArray(source.delay) &&
1069
+ is.inRange(source.delay.length, 1, 1000000) &&
1069
1070
  source.delay.every(is.integer) &&
1070
1071
  source.delay.every(v => is.inRange(v, 0, 65535))) {
1071
1072
  target.delay = source.delay;
package/dist/sharp.cjs CHANGED
@@ -75,7 +75,7 @@ if (!sharp) {
75
75
  if (isUnsupportedNodeRuntime()) {
76
76
  const { found, expected } = isUnsupportedNodeRuntime();
77
77
  help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
78
- } else if (prebuiltPlatforms.includes(runtimePlatform)) {
78
+ } else if (prebuiltPlatforms.includes(runtimePlatform) && !/libstdc\+\+\.so/.test(messages)) {
79
79
  const [os, cpu] = runtimePlatform.split("-");
80
80
  const libc = os.endsWith("musl") ? " --libc=musl" : "";
81
81
  help.push(
package/dist/sharp.mjs CHANGED
@@ -75,7 +75,7 @@ if (!sharp) {
75
75
  if (isUnsupportedNodeRuntime()) {
76
76
  const { found, expected } = isUnsupportedNodeRuntime();
77
77
  help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
78
- } else if (prebuiltPlatforms.includes(runtimePlatform)) {
78
+ } else if (prebuiltPlatforms.includes(runtimePlatform) && !/libstdc\+\+\.so/.test(messages)) {
79
79
  const [os, cpu] = runtimePlatform.split("-");
80
80
  const libc = os.endsWith("musl") ? " --libc=musl" : "";
81
81
  help.push(
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-revizly50",
4
+ "version": "0.35.0-revizly51",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
@@ -163,10 +163,10 @@
163
163
  "semver": "^7.8.5"
164
164
  },
165
165
  "optionalDependencies": {
166
- "@revizly/sharp-libvips-linux-arm64": "1.0.51",
167
- "@revizly/sharp-libvips-linux-x64": "1.0.51",
168
- "@revizly/sharp-linux-arm64": "0.35.0-revizly50",
169
- "@revizly/sharp-linux-x64": "0.35.0-revizly50"
166
+ "@revizly/sharp-libvips-linux-arm64": "1.0.52",
167
+ "@revizly/sharp-libvips-linux-x64": "1.0.52",
168
+ "@revizly/sharp-linux-arm64": "0.35.0-revizly51",
169
+ "@revizly/sharp-linux-x64": "0.35.0-revizly51"
170
170
  },
171
171
  "peerDependenciesMeta": {
172
172
  "@types/node": {
@@ -174,27 +174,27 @@
174
174
  }
175
175
  },
176
176
  "devDependencies": {
177
- "@biomejs/biome": "^2.5.10",
177
+ "@biomejs/biome": "^2.5.14",
178
178
  "@cpplint/cli": "^0.1.0",
179
179
  "@emnapi/runtime": "^1.11.3",
180
- "@revizly/sharp-libvips-dev": "1.0.51",
180
+ "@revizly/sharp-libvips-dev": "1.0.52",
181
181
  "@types/node": "*",
182
182
  "emnapi": "^1.11.3",
183
183
  "exif-reader": "^2.0.3",
184
- "yauzl": "^3.4.0",
185
184
  "icc": "^4.0.0",
186
185
  "node-addon-api": "^8.9.2",
187
186
  "node-gyp": "^12.4.0",
188
187
  "publint": "^0.3.24",
189
188
  "tar-fs": "^3.1.3",
190
- "tsd": "^0.33.0"
189
+ "tsd": "^0.33.0",
190
+ "yauzl": "^3.4.0"
191
191
  },
192
192
  "license": "Apache-2.0",
193
193
  "engines": {
194
194
  "node": ">=20.9.0"
195
195
  },
196
196
  "config": {
197
- "libvips": ">=8.18.6"
197
+ "libvips": ">=8.18.7"
198
198
  },
199
199
  "funding": {
200
200
  "url": "https://opencollective.com/libvips"
package/src/binding.gyp CHANGED
@@ -1,7 +1,7 @@
1
1
  # Copyright 2013 Lovell Fuller and others.
2
2
  # SPDX-License-Identifier: Apache-2.0
3
3
 
4
- {
4
+ { # noqa: B018
5
5
  'variables': {
6
6
  'vips_version': '<!(node -p "require(\'../dist/libvips.cjs\').minimumLibvipsVersion")',
7
7
  'platform_and_arch': '<!(node -p "require(\'../dist/libvips.cjs\').buildPlatformArch()")',
package/src/common.h CHANGED
@@ -19,8 +19,8 @@
19
19
 
20
20
  #if (VIPS_MAJOR_VERSION < 8) || \
21
21
  (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 18) || \
22
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 18 && VIPS_MICRO_VERSION < 6)
23
- #error "libvips version 8.18.6+ is required - please see https://sharp.pixelplumbing.com/install"
22
+ (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 18 && VIPS_MICRO_VERSION < 7)
23
+ #error "libvips version 8.18.7+ is required - please see https://sharp.pixelplumbing.com/install"
24
24
  #endif
25
25
 
26
26
  #if defined(__has_include)
package/src/pipeline.cc CHANGED
@@ -56,9 +56,9 @@ class PipelineWorker : public Napi::AsyncWorker {
56
56
  hasAlpha |= image.has_alpha();
57
57
  }
58
58
  if (hasAlpha) {
59
- for (auto &image : images) {
60
- if (!image.has_alpha()) {
61
- image = sharp::EnsureAlpha(image, 1);
59
+ for (size_t i = 0; i < images.size(); i++) {
60
+ if (!images[i].has_alpha()) {
61
+ images[i] = sharp::EnsureAlpha(images[i], 1);
62
62
  }
63
63
  }
64
64
  } else {
@@ -94,7 +94,10 @@ class PipelineWorker : public Napi::AsyncWorker {
94
94
  // Calculate angle of rotation
95
95
  VipsAngle rotation = VIPS_ANGLE_D0;
96
96
  VipsAngle autoRotation = VIPS_ANGLE_D0;
97
+ VipsAngle gainMapRotation = VIPS_ANGLE_D0;
97
98
  bool autoFlop = false;
99
+ bool gainMapFlip = false;
100
+ bool gainMapFlop = false;
98
101
 
99
102
  if (baton->input->autoOrient) {
100
103
  // Rotate and flip image according to Exif orientation
@@ -115,11 +118,13 @@ class PipelineWorker : public Napi::AsyncWorker {
115
118
  MultiPageUnsupported(nPages, "Rotate");
116
119
  }
117
120
  image = image.rot(autoRotation);
121
+ gainMapRotation = autoRotation;
118
122
  autoRotation = VIPS_ANGLE_D0;
119
123
  }
120
124
  if (autoFlop) {
121
125
  image = image.flip(VIPS_DIRECTION_HORIZONTAL);
122
126
  autoFlop = false;
127
+ gainMapFlop = true;
123
128
  }
124
129
  }
125
130
 
@@ -128,20 +133,24 @@ class PipelineWorker : public Napi::AsyncWorker {
128
133
  if (baton->flip) {
129
134
  image = image.flip(VIPS_DIRECTION_VERTICAL);
130
135
  baton->flip = false;
136
+ gainMapFlip = true;
131
137
  }
132
138
  if (baton->flop) {
133
139
  image = image.flip(VIPS_DIRECTION_HORIZONTAL);
134
140
  baton->flop = false;
141
+ gainMapFlop = true;
135
142
  }
136
143
  if (rotation != VIPS_ANGLE_D0) {
137
144
  if (rotation != VIPS_ANGLE_D180) {
138
145
  MultiPageUnsupported(nPages, "Rotate");
139
146
  }
140
147
  image = image.rot(rotation);
148
+ gainMapRotation = rotation;
141
149
  rotation = VIPS_ANGLE_D0;
142
150
  }
143
151
  if (baton->rotationAngle != 0.0) {
144
152
  MultiPageUnsupported(nPages, "Rotate");
153
+ KeepGainMapUnsupported(baton->keepGainMap, "Rotate");
145
154
  std::vector<double> background;
146
155
  std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground, false);
147
156
  image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background)).copy_memory();
@@ -152,6 +161,7 @@ class PipelineWorker : public Napi::AsyncWorker {
152
161
  // Trim
153
162
  if (baton->trimThreshold >= 0.0) {
154
163
  MultiPageUnsupported(nPages, "Trim");
164
+ KeepGainMapUnsupported(baton->keepGainMap, "Trim");
155
165
  image = sharp::StaySequential(image);
156
166
  image = sharp::Trim(image, baton->trimBackground, baton->trimThreshold, baton->trimLineArt, baton->trimMargin);
157
167
  baton->trimOffsetLeft = image.xoffset();
@@ -306,6 +316,20 @@ class PipelineWorker : public Napi::AsyncWorker {
306
316
  if (image.get_typeof("gainmap-scale-factor") == G_TYPE_INT) {
307
317
  gainMapScaleFactor = image.get_int("gainmap-scale-factor");
308
318
  }
319
+ if (gainMapFlip) {
320
+ gainMap = gainMap.flip(VIPS_DIRECTION_VERTICAL);
321
+ }
322
+ if (gainMapFlop) {
323
+ gainMap = gainMap.flip(VIPS_DIRECTION_HORIZONTAL);
324
+ }
325
+ if (gainMapRotation != VIPS_ANGLE_D0) {
326
+ gainMap = gainMap.rot(gainMapRotation);
327
+ }
328
+ if (baton->topOffsetPre != -1) {
329
+ gainMap = gainMap.extract_area(
330
+ baton->leftOffsetPre / gainMapScaleFactor, baton->topOffsetPre / gainMapScaleFactor,
331
+ baton->widthPre / gainMapScaleFactor, baton->heightPre / gainMapScaleFactor);
332
+ }
309
333
  } else if (baton->withGainMap) {
310
334
  image = image.uhdr2scRGB();
311
335
  }
@@ -429,14 +453,14 @@ class PipelineWorker : public Napi::AsyncWorker {
429
453
  }
430
454
  image = image.rot(autoRotation);
431
455
  if (baton->keepGainMap) {
432
- gainMap = gainMap.rot(autoRotation);
456
+ gainMap = sharp::StaySequential(gainMap).rot(autoRotation);
433
457
  }
434
458
  }
435
459
  // Mirror vertically (up-down) about the x-axis
436
460
  if (baton->flip) {
437
461
  image = image.flip(VIPS_DIRECTION_VERTICAL);
438
462
  if (baton->keepGainMap) {
439
- gainMap = gainMap.flip(VIPS_DIRECTION_VERTICAL);
463
+ gainMap = sharp::StaySequential(gainMap).flip(VIPS_DIRECTION_VERTICAL);
440
464
  }
441
465
  }
442
466
  // Mirror horizontally (left-right) about the y-axis
@@ -453,7 +477,7 @@ class PipelineWorker : public Napi::AsyncWorker {
453
477
  }
454
478
  image = image.rot(rotation);
455
479
  if (baton->keepGainMap) {
456
- gainMap = gainMap.rot(rotation);
480
+ gainMap = sharp::StaySequential(gainMap).rot(rotation);
457
481
  }
458
482
  }
459
483
 
@@ -557,6 +581,7 @@ class PipelineWorker : public Napi::AsyncWorker {
557
581
  // Rotate post-extract non-90 angle
558
582
  if (!baton->rotateBefore && baton->rotationAngle != 0.0) {
559
583
  MultiPageUnsupported(nPages, "Rotate");
584
+ KeepGainMapUnsupported(baton->keepGainMap, "Rotate");
560
585
  image = sharp::StaySequential(image);
561
586
  std::vector<double> background;
562
587
  std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground, shouldPremultiplyAlpha);
package/src/utilities.cc CHANGED
@@ -133,7 +133,7 @@ Napi::Value format(const Napi::CallbackInfo& info) {
133
133
  input.Set("file", hasInputFile);
134
134
  input.Set("buffer", hasInputBuffer);
135
135
  input.Set("stream", hasInputBuffer);
136
- if (hasInputFile) {
136
+ if (oc) {
137
137
  const VipsForeignClass *fc = VIPS_FOREIGN_CLASS(oc);
138
138
  if (fc->suffs) {
139
139
  Napi::Array fileSuffix = Napi::Array::New(env);