@ohos-ports/sharp 0.34.5-beta.8 → 0.35.5-beta.1

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 (46) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +112 -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} +12 -8
  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/{lib/index.d.ts → dist/index.d.cts} +113 -85
  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} +9 -3
  18. package/dist/is.mjs +149 -0
  19. package/{lib/libvips.js → dist/libvips.cjs} +35 -30
  20. package/dist/libvips.mjs +213 -0
  21. package/{lib/operation.js → dist/operation.cjs} +39 -53
  22. package/dist/operation.mjs +1002 -0
  23. package/{lib/output.js → dist/output.cjs} +167 -47
  24. package/dist/output.mjs +1786 -0
  25. package/{lib/resize.js → dist/resize.cjs} +54 -32
  26. package/dist/resize.mjs +617 -0
  27. package/dist/sharp.cjs +177 -0
  28. package/dist/sharp.mjs +177 -0
  29. package/{lib/utility.js → dist/utility.cjs} +23 -25
  30. package/dist/utility.mjs +301 -0
  31. package/install/build.js +3 -3
  32. package/package.json +56 -56
  33. package/src/binding.gyp +21 -269
  34. package/src/common.cc +81 -25
  35. package/src/common.h +23 -4
  36. package/src/metadata.cc +66 -8
  37. package/src/metadata.h +6 -1
  38. package/src/operations.cc +25 -8
  39. package/src/operations.h +1 -1
  40. package/src/pipeline.cc +231 -72
  41. package/src/pipeline.h +15 -1
  42. package/src/stats.cc +6 -6
  43. package/src/utilities.cc +8 -7
  44. package/install/check.js +0 -73
  45. package/lib/index.js +0 -16
  46. package/lib/sharp.js +0 -154
@@ -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?
@@ -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 ADDED
@@ -0,0 +1,149 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Is this value defined and not null?
8
+ * @private
9
+ */
10
+ const defined = (val) => typeof val !== 'undefined' && val !== null;
11
+
12
+ /**
13
+ * Is this value an object?
14
+ * @private
15
+ */
16
+ const object = (val) => typeof val === 'object';
17
+
18
+ /**
19
+ * Is this value a plain object?
20
+ * @private
21
+ */
22
+ const plainObject = (val) => Object.prototype.toString.call(val) === '[object Object]';
23
+
24
+ /**
25
+ * Is this value a function?
26
+ * @private
27
+ */
28
+ const fn = (val) => typeof val === 'function';
29
+
30
+ /**
31
+ * Is this value a boolean?
32
+ * @private
33
+ */
34
+ const bool = (val) => typeof val === 'boolean';
35
+
36
+ /**
37
+ * Is this value a Buffer object?
38
+ * @private
39
+ */
40
+ const buffer = (val) => val instanceof Buffer;
41
+
42
+ /**
43
+ * Is this value a typed array object?. E.g. Uint8Array or Uint8ClampedArray?
44
+ * @private
45
+ */
46
+ const typedArray = (val) => {
47
+ if (defined(val)) {
48
+ switch (val.constructor) {
49
+ case Uint8Array:
50
+ case Uint8ClampedArray:
51
+ case Int8Array:
52
+ case Uint16Array:
53
+ case Int16Array:
54
+ case Uint32Array:
55
+ case Int32Array:
56
+ case Float32Array:
57
+ case Float64Array:
58
+ return true;
59
+ }
60
+ }
61
+
62
+ return false;
63
+ };
64
+
65
+ /**
66
+ * Is this value an ArrayBuffer object?
67
+ * @private
68
+ */
69
+ const arrayBuffer = (val) => val instanceof ArrayBuffer;
70
+
71
+ /**
72
+ * Is this value a non-empty string?
73
+ * @private
74
+ */
75
+ const string = (val) => typeof val === 'string' && val.length > 0;
76
+
77
+ /**
78
+ * Is this value a real number?
79
+ * @private
80
+ */
81
+ const number = (val) => typeof val === 'number' && Number.isFinite(val);
82
+
83
+ /**
84
+ * Is this value an integer?
85
+ * @private
86
+ */
87
+ const integer = (val) => Number.isInteger(val);
88
+
89
+ /**
90
+ * Is this value within an inclusive given range?
91
+ * @private
92
+ */
93
+ const inRange = (val, min, max) => val >= min && val <= max;
94
+
95
+ /**
96
+ * Is this value within the elements of an array?
97
+ * @private
98
+ */
99
+ const inArray = (val, list) => list.includes(val);
100
+
101
+ /**
102
+ * Create an Error with a message relating to an invalid parameter.
103
+ *
104
+ * @param {string} name - parameter name.
105
+ * @param {string} expected - description of the type/value/range expected.
106
+ * @param {*} actual - the value received.
107
+ * @returns {Error} Containing the formatted message.
108
+ * @private
109
+ */
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}`
117
+ );
118
+ };
119
+
120
+ /**
121
+ * Ensures an Error from C++ contains a JS stack.
122
+ *
123
+ * @param {Error} native - Error with message from C++.
124
+ * @param {Error} context - Error with stack from JS.
125
+ * @returns {Error} Error with message and stack.
126
+ * @private
127
+ */
128
+ const nativeError = (native, context) => {
129
+ context.message = native.message;
130
+ return context;
131
+ };
132
+
133
+ export default {
134
+ defined,
135
+ object,
136
+ plainObject,
137
+ fn,
138
+ bool,
139
+ buffer,
140
+ typedArray,
141
+ arrayBuffer,
142
+ string,
143
+ number,
144
+ integer,
145
+ inRange,
146
+ inArray,
147
+ invalidParameterError,
148
+ nativeError
149
+ };
@@ -5,20 +5,18 @@
5
5
 
6
6
  const { spawnSync } = require('node:child_process');
7
7
  const { createHash } = require('node:crypto');
8
- const semverCoerce = require('semver/functions/coerce');
9
- const semverGreaterThanOrEqualTo = require('semver/functions/gte');
10
- const semverSatisfies = require('semver/functions/satisfies');
8
+ const semver = require('semver');
11
9
  const detectLibc = require('detect-libc');
12
-
13
- const { config, engines, optionalDependencies } = require('../package.json');
10
+ const pkg = require('../package.json');
14
11
 
15
12
  /* node:coverage ignore next */
16
- const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || (config && config.libvips) || '>=8.17.3';
17
- const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).version;
13
+ const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || pkg.config.libvips;
14
+ const minimumLibvipsVersion = semver.coerce(minimumLibvipsVersionLabelled).version;
18
15
 
19
16
  const prebuiltPlatforms = [
20
17
  'darwin-arm64', 'darwin-x64',
21
- 'linux-arm', 'linux-arm64', 'linux-ppc64', 'linux-riscv64', 'linux-s390x', 'linux-x64',
18
+ 'freebsd-arm64', 'freebsd-x64',
19
+ 'linux-arm', 'linux-arm64', 'linux-ppc64', 'linux-riscv64', 'linux-s390x', 'linux-wasm32', 'linux-x64',
22
20
  'linuxmusl-arm64', 'linuxmusl-x64',
23
21
  'win32-arm64', 'win32-ia32', 'win32-x64',
24
22
  'openharmony-arm64'
@@ -37,13 +35,13 @@ const log = (item) => {
37
35
  }
38
36
  };
39
37
 
40
- /* node:coverage ignore next */
38
+ /* node:coverage disable */
39
+
41
40
  const runtimeLibc = () => detectLibc.isNonGlibcLinuxSync() ? detectLibc.familySync() : '';
42
41
 
43
42
  const runtimePlatformArch = () => `${process.platform}${runtimeLibc()}-${process.arch}`;
44
43
 
45
44
  const buildPlatformArch = () => {
46
- /* node:coverage ignore next 3 */
47
45
  if (isEmscripten()) {
48
46
  return 'wasm32';
49
47
  }
@@ -56,7 +54,6 @@ const buildSharpLibvipsIncludeDir = () => {
56
54
  try {
57
55
  return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/include`);
58
56
  } catch {
59
- /* node:coverage ignore next 5 */
60
57
  try {
61
58
  return require('@img/sharp-libvips-dev/include');
62
59
  } catch {}
@@ -65,7 +62,6 @@ const buildSharpLibvipsIncludeDir = () => {
65
62
  };
66
63
 
67
64
  const buildSharpLibvipsCPlusPlusDir = () => {
68
- /* node:coverage ignore next 4 */
69
65
  try {
70
66
  return require('@img/sharp-libvips-dev/cplusplus');
71
67
  } catch {}
@@ -76,7 +72,6 @@ const buildSharpLibvipsLibDir = () => {
76
72
  try {
77
73
  return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/lib`);
78
74
  } catch {
79
- /* node:coverage ignore next 5 */
80
75
  try {
81
76
  return require(`@img/sharp-libvips-${buildPlatformArch()}/lib`);
82
77
  } catch {}
@@ -84,12 +79,10 @@ const buildSharpLibvipsLibDir = () => {
84
79
  return '';
85
80
  };
86
81
 
87
- /* node:coverage disable */
88
-
89
82
  const isUnsupportedNodeRuntime = () => {
90
83
  if (process.release?.name === 'node' && process.versions) {
91
- if (!semverSatisfies(process.versions.node, engines.node)) {
92
- return { found: process.versions.node, expected: engines.node };
84
+ if (!semver.satisfies(process.versions.node, pkg.engines.node)) {
85
+ return { found: process.versions.node, expected: pkg.engines.node };
93
86
  }
94
87
  }
95
88
  };
@@ -114,7 +107,7 @@ const sha512 = (s) => createHash('sha512').update(s).digest('hex');
114
107
  const yarnLocator = () => {
115
108
  try {
116
109
  const identHash = sha512(`imgsharp-libvips-${buildPlatformArch()}`);
117
- const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`], {
110
+ const npmVersion = semver.coerce(pkg.optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`], {
118
111
  includePrerelease: true
119
112
  }).version;
120
113
  return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10);
@@ -145,22 +138,34 @@ const globalLibvipsVersion = () => {
145
138
  }
146
139
  };
147
140
 
141
+ const getBrewPkgConfigPath = () => {
142
+ try {
143
+ const brewPrefix = (spawnSync('brew', ['--prefix'], { encoding: 'utf8' }).stdout || '').trim();
144
+ if (brewPrefix) {
145
+ return `${brewPrefix}/lib/pkgconfig`;
146
+ }
147
+ } catch (_err) {}
148
+ return undefined;
149
+ };
150
+
151
+ const getPkgConfigPath = () => {
152
+ try {
153
+ const pkgConfigPath = (spawnSync('pkg-config', ['--variable', 'pc_path', 'pkg-config'], { encoding: 'utf8' }).stdout || '').trim();
154
+ if (pkgConfigPath) {
155
+ return pkgConfigPath;
156
+ }
157
+ } catch (_err) {}
158
+ return undefined;
159
+ };
160
+
148
161
  /* node:coverage enable */
149
162
 
150
163
  const pkgConfigPath = () => {
151
164
  if (process.platform !== 'win32') {
152
- /* node:coverage ignore next 4 */
153
- const brewPkgConfigPath = spawnSync(
154
- 'which brew >/dev/null 2>&1 && brew environment --plain | grep PKG_CONFIG_LIBDIR | cut -d" " -f2',
155
- spawnSyncOptions
156
- ).stdout || '';
157
165
  return [
158
- brewPkgConfigPath.trim(),
159
- process.env.PKG_CONFIG_PATH,
160
- '/usr/local/lib/pkgconfig',
161
- '/usr/lib/pkgconfig',
162
- '/usr/local/libdata/pkgconfig',
163
- '/usr/libdata/pkgconfig'
166
+ getBrewPkgConfigPath(),
167
+ getPkgConfigPath(),
168
+ process.env.PKG_CONFIG_PATH
164
169
  ].filter(Boolean).join(':');
165
170
  } else {
166
171
  return '';
@@ -187,7 +192,7 @@ const useGlobalLibvips = (logger) => {
187
192
  }
188
193
  const globalVipsVersion = globalLibvipsVersion();
189
194
  /* node:coverage ignore next */
190
- return !!globalVipsVersion && semverGreaterThanOrEqualTo(globalVipsVersion, minimumLibvipsVersion);
195
+ return !!globalVipsVersion && semver.gte(globalVipsVersion, minimumLibvipsVersion);
191
196
  };
192
197
 
193
198
  module.exports = {
@@ -0,0 +1,213 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import { spawnSync } from 'node:child_process';
7
+ import { createHash } from 'node:crypto';
8
+ import semver from 'semver';
9
+ import detectLibc from 'detect-libc';
10
+ import pkg from '../package.json' with { type: 'json' };
11
+
12
+ /* node:coverage ignore next */
13
+ const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || pkg.config.libvips;
14
+ const minimumLibvipsVersion = semver.coerce(minimumLibvipsVersionLabelled).version;
15
+
16
+ const prebuiltPlatforms = [
17
+ 'darwin-arm64', 'darwin-x64',
18
+ 'freebsd-arm64', 'freebsd-x64',
19
+ 'linux-arm', 'linux-arm64', 'linux-ppc64', 'linux-riscv64', 'linux-s390x', 'linux-wasm32', 'linux-x64',
20
+ 'linuxmusl-arm64', 'linuxmusl-x64',
21
+ 'win32-arm64', 'win32-ia32', 'win32-x64',
22
+ 'openharmony-arm64'
23
+ ];
24
+
25
+ const spawnSyncOptions = {
26
+ encoding: 'utf8',
27
+ shell: true
28
+ };
29
+
30
+ const log = (item) => {
31
+ if (item instanceof Error) {
32
+ console.error(`sharp: Installation error: ${item.message}`);
33
+ } else {
34
+ console.log(`sharp: ${item}`);
35
+ }
36
+ };
37
+
38
+ /* node:coverage disable */
39
+
40
+ const runtimeLibc = () => detectLibc.isNonGlibcLinuxSync() ? detectLibc.familySync() : '';
41
+
42
+ const runtimePlatformArch = () => `${process.platform}${runtimeLibc()}-${process.arch}`;
43
+
44
+ const buildPlatformArch = () => {
45
+ if (isEmscripten()) {
46
+ return 'wasm32';
47
+ }
48
+ const { npm_config_arch, npm_config_platform, npm_config_libc } = process.env;
49
+ const libc = typeof npm_config_libc === 'string' ? npm_config_libc : runtimeLibc();
50
+ return `${npm_config_platform || process.platform}${libc}-${npm_config_arch || process.arch}`;
51
+ };
52
+
53
+ const buildSharpLibvipsIncludeDir = () => {
54
+ try {
55
+ return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/include`);
56
+ } catch {
57
+ try {
58
+ return require('@img/sharp-libvips-dev/include');
59
+ } catch {}
60
+ }
61
+ return '';
62
+ };
63
+
64
+ const buildSharpLibvipsCPlusPlusDir = () => {
65
+ try {
66
+ return require('@img/sharp-libvips-dev/cplusplus');
67
+ } catch {}
68
+ return '';
69
+ };
70
+
71
+ const buildSharpLibvipsLibDir = () => {
72
+ try {
73
+ return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/lib`);
74
+ } catch {
75
+ try {
76
+ return require(`@img/sharp-libvips-${buildPlatformArch()}/lib`);
77
+ } catch {}
78
+ }
79
+ return '';
80
+ };
81
+
82
+ const isUnsupportedNodeRuntime = () => {
83
+ if (process.release?.name === 'node' && process.versions) {
84
+ if (!semver.satisfies(process.versions.node, pkg.engines.node)) {
85
+ return { found: process.versions.node, expected: pkg.engines.node };
86
+ }
87
+ }
88
+ };
89
+
90
+ const isEmscripten = () => {
91
+ const { CC } = process.env;
92
+ return Boolean(CC?.endsWith('/emcc'));
93
+ };
94
+
95
+ const isRosetta = () => {
96
+ if (process.platform === 'darwin' && process.arch === 'x64') {
97
+ const translated = spawnSync('sysctl sysctl.proc_translated', spawnSyncOptions).stdout;
98
+ return (translated || '').trim() === 'sysctl.proc_translated: 1';
99
+ }
100
+ return false;
101
+ };
102
+
103
+ /* node:coverage enable */
104
+
105
+ const sha512 = (s) => createHash('sha512').update(s).digest('hex');
106
+
107
+ const yarnLocator = () => {
108
+ try {
109
+ const identHash = sha512(`imgsharp-libvips-${buildPlatformArch()}`);
110
+ const npmVersion = semver.coerce(pkg.optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`], {
111
+ includePrerelease: true
112
+ }).version;
113
+ return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10);
114
+ } catch {}
115
+ return '';
116
+ };
117
+
118
+ /* node:coverage disable */
119
+
120
+ const spawnRebuild = () =>
121
+ spawnSync(`node-gyp rebuild --directory=src ${isEmscripten() ? '--nodedir=emscripten' : ''}`, {
122
+ ...spawnSyncOptions,
123
+ stdio: 'inherit'
124
+ }).status;
125
+
126
+ const globalLibvipsVersion = () => {
127
+ if (process.platform !== 'win32') {
128
+ const globalLibvipsVersion = spawnSync('pkg-config --modversion vips-cpp', {
129
+ ...spawnSyncOptions,
130
+ env: {
131
+ ...process.env,
132
+ PKG_CONFIG_PATH: pkgConfigPath()
133
+ }
134
+ }).stdout;
135
+ return (globalLibvipsVersion || '').trim();
136
+ } else {
137
+ return '';
138
+ }
139
+ };
140
+
141
+ const getBrewPkgConfigPath = () => {
142
+ try {
143
+ const brewPrefix = (spawnSync('brew', ['--prefix'], { encoding: 'utf8' }).stdout || '').trim();
144
+ if (brewPrefix) {
145
+ return `${brewPrefix}/lib/pkgconfig`;
146
+ }
147
+ } catch (_err) {}
148
+ return undefined;
149
+ };
150
+
151
+ const getPkgConfigPath = () => {
152
+ try {
153
+ const pkgConfigPath = (spawnSync('pkg-config', ['--variable', 'pc_path', 'pkg-config'], { encoding: 'utf8' }).stdout || '').trim();
154
+ if (pkgConfigPath) {
155
+ return pkgConfigPath;
156
+ }
157
+ } catch (_err) {}
158
+ return undefined;
159
+ };
160
+
161
+ /* node:coverage enable */
162
+
163
+ const pkgConfigPath = () => {
164
+ if (process.platform !== 'win32') {
165
+ return [
166
+ getBrewPkgConfigPath(),
167
+ getPkgConfigPath(),
168
+ process.env.PKG_CONFIG_PATH
169
+ ].filter(Boolean).join(':');
170
+ } else {
171
+ return '';
172
+ }
173
+ };
174
+
175
+ const skipSearch = (status, reason, logger) => {
176
+ if (logger) {
177
+ logger(`Detected ${reason}, skipping search for globally-installed libvips`);
178
+ }
179
+ return status;
180
+ };
181
+
182
+ const useGlobalLibvips = (logger) => {
183
+ if (Boolean(process.env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
184
+ return skipSearch(false, 'SHARP_IGNORE_GLOBAL_LIBVIPS', logger);
185
+ }
186
+ if (Boolean(process.env.SHARP_FORCE_GLOBAL_LIBVIPS) === true) {
187
+ return skipSearch(true, 'SHARP_FORCE_GLOBAL_LIBVIPS', logger);
188
+ }
189
+ /* node:coverage ignore next 3 */
190
+ if (isRosetta()) {
191
+ return skipSearch(false, 'Rosetta', logger);
192
+ }
193
+ const globalVipsVersion = globalLibvipsVersion();
194
+ /* node:coverage ignore next */
195
+ return !!globalVipsVersion && semver.gte(globalVipsVersion, minimumLibvipsVersion);
196
+ };
197
+
198
+ export default {
199
+ minimumLibvipsVersion,
200
+ prebuiltPlatforms,
201
+ buildPlatformArch,
202
+ buildSharpLibvipsIncludeDir,
203
+ buildSharpLibvipsCPlusPlusDir,
204
+ buildSharpLibvipsLibDir,
205
+ isUnsupportedNodeRuntime,
206
+ runtimePlatformArch,
207
+ log,
208
+ yarnLocator,
209
+ spawnRebuild,
210
+ globalLibvipsVersion,
211
+ pkgConfigPath,
212
+ useGlobalLibvips
213
+ };