@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
@@ -0,0 +1,301 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import events from 'node:events';
7
+ import { createRequire } from "node:module";
8
+ import { availableParallelism } from "node:os";
9
+ import detectLibc from 'detect-libc';
10
+
11
+ import is from './is.mjs';
12
+ import libvips from './libvips.mjs';
13
+ import sharp from './sharp.mjs';
14
+ import pkg from "../package.json" with { type: "json" };
15
+
16
+ const require = createRequire(import.meta.url);
17
+ const runtimePlatform = libvips.runtimePlatformArch();
18
+ const libvipsVersion = sharp.libvipsVersion();
19
+
20
+ /**
21
+ * An Object containing nested boolean values representing the available input and output formats/methods.
22
+ * @member
23
+ * @example
24
+ * console.log(sharp.format);
25
+ * @returns {Object}
26
+ */
27
+ const format = sharp.format();
28
+ format.heif.output.alias = ['avif', 'heic'];
29
+ format.jpeg.output.alias = ['jpe', 'jpg'];
30
+ format.tiff.output.alias = ['tif'];
31
+ format.jp2.output.alias = ['j2c', 'j2k', 'jp2', 'jpx'];
32
+
33
+ /**
34
+ * An Object containing the available interpolators and their proper values
35
+ * @readonly
36
+ * @enum {string}
37
+ */
38
+ const interpolators = {
39
+ /** [Nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation). Suitable for image enlargement only. */
40
+ nearest: 'nearest',
41
+ /** [Bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation). Faster than bicubic but with less smooth results. */
42
+ bilinear: 'bilinear',
43
+ /** [Bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default). */
44
+ bicubic: 'bicubic',
45
+ /** [LBB interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/lbb.cpp#L100). Prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2. */
46
+ locallyBoundedBicubic: 'lbb',
47
+ /** [Nohalo interpolation](http://eprints.soton.ac.uk/268086/). Prevents acutance but typically reduces performance by a factor of 3. */
48
+ nohalo: 'nohalo',
49
+ /** [VSQBS interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/vsqbs.cpp#L48). Prevents "staircasing" when enlarging. */
50
+ vertexSplitQuadraticBasisSpline: 'vsqbs'
51
+ };
52
+
53
+ /**
54
+ * An Object containing the version numbers of sharp, libvips
55
+ * and (when using prebuilt binaries) its dependencies.
56
+ *
57
+ * @member
58
+ * @example
59
+ * console.log(sharp.versions);
60
+ */
61
+ let versions = {
62
+ vips: libvipsVersion.semver
63
+ };
64
+ /* node:coverage ignore next 15 */
65
+ if (!libvipsVersion.isGlobal) {
66
+ if (!libvipsVersion.isWasm) {
67
+ try {
68
+ versions = require(`@img/sharp-${runtimePlatform}/versions`);
69
+ } catch (_) {
70
+ try {
71
+ versions = require(`@img/sharp-libvips-${runtimePlatform}/versions`);
72
+ } catch (_) {}
73
+ }
74
+ } else {
75
+ try {
76
+ versions = require('@img/sharp-wasm32/versions');
77
+ } catch (_) {}
78
+ }
79
+ }
80
+ versions.sharp = pkg.version;
81
+
82
+ /* node:coverage ignore next 5 */
83
+ if (versions.heif && format.heif) {
84
+ // Prebuilt binaries provide AV1
85
+ format.heif.input.fileSuffix = ['.avif'];
86
+ format.heif.output.alias = ['avif'];
87
+ }
88
+
89
+ /**
90
+ * Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
91
+ * Existing entries in the cache will be trimmed after any change in limits.
92
+ * This method always returns cache statistics,
93
+ * useful for determining how much working memory is required for a particular task.
94
+ *
95
+ * @example
96
+ * const stats = sharp.cache();
97
+ * @example
98
+ * sharp.cache( { items: 200 } );
99
+ * sharp.cache( { files: 0 } );
100
+ * sharp.cache(false);
101
+ *
102
+ * @param {Object|boolean} [options=true] - Object with the following attributes, or boolean where true uses default cache settings and false removes all caching
103
+ * @param {number} [options.memory=50] - is the maximum memory in MB to use for this cache
104
+ * @param {number} [options.files=20] - is the maximum number of files to hold open
105
+ * @param {number} [options.items=100] - is the maximum number of operations to cache
106
+ * @returns {Object}
107
+ */
108
+ function cache (options) {
109
+ if (is.bool(options)) {
110
+ if (options) {
111
+ // Default cache settings of 50MB, 20 files, 100 items
112
+ return sharp.cache(50, 20, 100);
113
+ } else {
114
+ return sharp.cache(0, 0, 0);
115
+ }
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
+ }
123
+ return sharp.cache(options.memory, options.files, options.items);
124
+ } else {
125
+ return sharp.cache();
126
+ }
127
+ }
128
+ cache(true);
129
+
130
+ /**
131
+ * Gets or, when a concurrency is provided, sets
132
+ * the maximum number of threads _libvips_ should use to process _each image_.
133
+ * These are from a thread pool managed by glib,
134
+ * which helps avoid the overhead of creating new threads.
135
+ *
136
+ * This method always returns the current concurrency.
137
+ *
138
+ * The default value is the number of CPU cores,
139
+ * except when using glibc-based Linux without jemalloc,
140
+ * where the default is `1` to help reduce memory fragmentation.
141
+ *
142
+ * A value of `0` will reset this to the number of CPU cores.
143
+ *
144
+ * Some image format libraries spawn additional threads,
145
+ * e.g. libaom manages its own 4 threads when encoding AVIF images,
146
+ * and these are independent of the value set here.
147
+ *
148
+ * :::note
149
+ * Further {@link /performance/ control over performance} is available.
150
+ * :::
151
+ *
152
+ * @example
153
+ * const threads = sharp.concurrency(); // 4
154
+ * sharp.concurrency(2); // 2
155
+ * sharp.concurrency(0); // 4
156
+ *
157
+ * @param {number} [concurrency]
158
+ * @returns {number} concurrency
159
+ */
160
+ function concurrency (concurrency) {
161
+ return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
162
+ }
163
+ /* node:coverage ignore next 7 */
164
+ if (!process.env.MALLOC_ARENA_MAX && detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
165
+ // Reduce default concurrency to 1 when using glibc memory allocator
166
+ sharp.concurrency(1);
167
+ } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
168
+ // Reduce default concurrency when musl thread over-subscription detected
169
+ sharp.concurrency(availableParallelism());
170
+ }
171
+
172
+ /**
173
+ * An EventEmitter that emits a `change` event when a task is either:
174
+ * - queued, waiting for _libuv_ to provide a worker thread
175
+ * - complete
176
+ * @member
177
+ * @example
178
+ * sharp.queue.on('change', function(queueLength) {
179
+ * console.log('Queue contains ' + queueLength + ' task(s)');
180
+ * });
181
+ */
182
+ const queue = new events.EventEmitter();
183
+
184
+ /**
185
+ * Provides access to internal task counters.
186
+ * - queue is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool.
187
+ * - process is the number of resize tasks currently being processed.
188
+ *
189
+ * @example
190
+ * const counters = sharp.counters(); // { queue: 2, process: 4 }
191
+ *
192
+ * @returns {Object}
193
+ */
194
+ function counters () {
195
+ return sharp.counters();
196
+ }
197
+
198
+ /**
199
+ * Get and set use of SIMD vector unit instructions.
200
+ * Requires libvips to have been compiled with highway support.
201
+ *
202
+ * Improves the performance of `resize`, `blur` and `sharpen` operations
203
+ * by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
204
+ *
205
+ * @example
206
+ * const simd = sharp.simd();
207
+ * // simd is `true` if the runtime use of highway is currently enabled
208
+ * @example
209
+ * const simd = sharp.simd(false);
210
+ * // prevent libvips from using highway at runtime
211
+ *
212
+ * @param {boolean} [simd=true]
213
+ * @returns {boolean}
214
+ */
215
+ function simd (simd) {
216
+ return sharp.simd(is.bool(simd) ? simd : null);
217
+ }
218
+
219
+ /**
220
+ * Block libvips operations at runtime.
221
+ *
222
+ * This is in addition to the `VIPS_BLOCK_UNTRUSTED` environment variable,
223
+ * which when set will block all "untrusted" operations.
224
+ *
225
+ * @since 0.32.4
226
+ *
227
+ * @example <caption>Block all TIFF input.</caption>
228
+ * sharp.block({
229
+ * operation: ['VipsForeignLoadTiff']
230
+ * });
231
+ *
232
+ * @param {Object} options
233
+ * @param {Array<string>} options.operation - List of libvips low-level operation names to block.
234
+ */
235
+ function block (options) {
236
+ if (is.object(options)) {
237
+ if (Array.isArray(options.operation) && options.operation.every(is.string)) {
238
+ sharp.block(options.operation, true);
239
+ } else {
240
+ throw is.invalidParameterError('operation', 'Array<string>', options.operation);
241
+ }
242
+ } else {
243
+ throw is.invalidParameterError('options', 'object', options);
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Unblock libvips operations at runtime.
249
+ *
250
+ * This is useful for defining a list of allowed operations.
251
+ *
252
+ * @since 0.32.4
253
+ *
254
+ * @example <caption>Block all input except WebP from the filesystem.</caption>
255
+ * sharp.block({
256
+ * operation: ['VipsForeignLoad']
257
+ * });
258
+ * sharp.unblock({
259
+ * operation: ['VipsForeignLoadWebpFile']
260
+ * });
261
+ *
262
+ * @example <caption>Block all input except JPEG and PNG from a Buffer or Stream.</caption>
263
+ * sharp.block({
264
+ * operation: ['VipsForeignLoad']
265
+ * });
266
+ * sharp.unblock({
267
+ * operation: ['VipsForeignLoadJpegBuffer', 'VipsForeignLoadPngBuffer']
268
+ * });
269
+ *
270
+ * @param {Object} options
271
+ * @param {Array<string>} options.operation - List of libvips low-level operation names to unblock.
272
+ */
273
+ function unblock (options) {
274
+ if (is.object(options)) {
275
+ if (Array.isArray(options.operation) && options.operation.every(is.string)) {
276
+ sharp.block(options.operation, false);
277
+ } else {
278
+ throw is.invalidParameterError('operation', 'Array<string>', options.operation);
279
+ }
280
+ } else {
281
+ throw is.invalidParameterError('options', 'object', options);
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Decorate the Sharp class with utility-related functions.
287
+ * @module Sharp
288
+ * @private
289
+ */
290
+ export default (Sharp) => {
291
+ Sharp.cache = cache;
292
+ Sharp.concurrency = concurrency;
293
+ Sharp.counters = counters;
294
+ Sharp.simd = simd;
295
+ Sharp.format = format;
296
+ Sharp.interpolators = interpolators;
297
+ Sharp.versions = versions;
298
+ Sharp.queue = queue;
299
+ Sharp.block = block;
300
+ Sharp.unblock = unblock;
301
+ };
package/install/build.js CHANGED
@@ -8,9 +8,9 @@ const {
8
8
  globalLibvipsVersion,
9
9
  log,
10
10
  spawnRebuild,
11
- } = require('../lib/libvips');
11
+ } = require('../dist/libvips.cjs');
12
12
 
13
- log('Attempting to build from source via node-gyp');
13
+ log('Building from source');
14
14
  log('See https://sharp.pixelplumbing.com/install#building-from-source');
15
15
 
16
16
  try {
@@ -29,7 +29,7 @@ try {
29
29
  }
30
30
 
31
31
  if (useGlobalLibvips(log)) {
32
- log(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
32
+ log(`Found globally-installed libvips v${globalLibvipsVersion()}`);
33
33
  }
34
34
 
35
35
  const status = spawnRebuild();