@atlaspack/transformer-image 3.1.5-canary.36 → 3.1.5-canary.361

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.
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateConfig = validateConfig;
4
+ const utils_1 = require("@atlaspack/utils");
5
+ // https://sharp.pixelplumbing.com/api-output#jpeg
6
+ const JPEG_OUTPUT_SCHEMA = {
7
+ type: 'object',
8
+ properties: {
9
+ quality: {
10
+ type: 'number',
11
+ },
12
+ progressive: {
13
+ type: 'boolean',
14
+ },
15
+ chromaSubsampling: {
16
+ type: 'string',
17
+ },
18
+ optimiseCoding: {
19
+ type: 'boolean',
20
+ },
21
+ optimizeCoding: {
22
+ type: 'boolean',
23
+ },
24
+ mozjpeg: {
25
+ type: 'boolean',
26
+ },
27
+ trellisQuantisation: {
28
+ type: 'boolean',
29
+ },
30
+ overshootDeringing: {
31
+ type: 'boolean',
32
+ },
33
+ optimiseScans: {
34
+ type: 'boolean',
35
+ },
36
+ optimizeScans: {
37
+ type: 'boolean',
38
+ },
39
+ quantisationTable: {
40
+ type: 'number',
41
+ },
42
+ quantizationTable: {
43
+ type: 'number',
44
+ },
45
+ force: {
46
+ type: 'boolean',
47
+ },
48
+ },
49
+ additionalProperties: true,
50
+ };
51
+ // https://sharp.pixelplumbing.com/api-output#png
52
+ const PNG_OUTPUT_SCHEMA = {
53
+ type: 'object',
54
+ properties: {
55
+ quality: {
56
+ type: 'number',
57
+ },
58
+ progressive: {
59
+ type: 'boolean',
60
+ },
61
+ compressionLevel: {
62
+ type: 'number',
63
+ },
64
+ adaptiveFiltering: {
65
+ type: 'boolean',
66
+ },
67
+ palette: {
68
+ type: 'boolean',
69
+ },
70
+ colours: {
71
+ type: 'number',
72
+ },
73
+ colors: {
74
+ type: 'number',
75
+ },
76
+ dither: {
77
+ type: 'number',
78
+ },
79
+ force: {
80
+ type: 'boolean',
81
+ },
82
+ },
83
+ additionalProperties: true,
84
+ };
85
+ // https://sharp.pixelplumbing.com/api-output#webp
86
+ const WEBP_OUTPUT_SCHEMA = {
87
+ type: 'object',
88
+ properties: {
89
+ quality: {
90
+ type: 'number',
91
+ },
92
+ alphaQuality: {
93
+ type: 'number',
94
+ },
95
+ lossless: {
96
+ type: 'boolean',
97
+ },
98
+ nearLossless: {
99
+ type: 'boolean',
100
+ },
101
+ smartSubsample: {
102
+ type: 'boolean',
103
+ },
104
+ reductionEffort: {
105
+ type: 'number',
106
+ },
107
+ pageHeight: {
108
+ type: 'number',
109
+ },
110
+ loop: {
111
+ type: 'number',
112
+ },
113
+ delay: {
114
+ type: 'array',
115
+ items: {
116
+ type: 'number',
117
+ },
118
+ },
119
+ force: {
120
+ type: 'boolean',
121
+ },
122
+ },
123
+ additionalProperties: true,
124
+ };
125
+ // https://sharp.pixelplumbing.com/api-output#gif
126
+ const GIF_OUTPUT_SCHEMA = {
127
+ type: 'object',
128
+ properties: {
129
+ pageHeight: {
130
+ type: 'number',
131
+ },
132
+ loop: {
133
+ type: 'number',
134
+ },
135
+ delay: {
136
+ type: 'array',
137
+ items: {
138
+ type: 'number',
139
+ },
140
+ },
141
+ force: {
142
+ type: 'boolean',
143
+ },
144
+ },
145
+ additionalProperties: true,
146
+ };
147
+ // https://sharp.pixelplumbing.com/api-output#tiff
148
+ const TIFF_OUTPUT_SCHEMA = {
149
+ type: 'object',
150
+ properties: {
151
+ quality: {
152
+ type: 'number',
153
+ },
154
+ force: {
155
+ type: 'boolean',
156
+ },
157
+ compression: {
158
+ type: 'string',
159
+ },
160
+ predictor: {
161
+ type: 'string',
162
+ },
163
+ pyramid: {
164
+ type: 'boolean',
165
+ },
166
+ tile: {
167
+ type: 'boolean',
168
+ },
169
+ tileWidth: {
170
+ type: 'number',
171
+ },
172
+ tileHeight: {
173
+ type: 'number',
174
+ },
175
+ xres: {
176
+ type: 'number',
177
+ },
178
+ yres: {
179
+ type: 'number',
180
+ },
181
+ bitdepth: {
182
+ type: 'number',
183
+ },
184
+ },
185
+ additionalProperties: true,
186
+ };
187
+ // https://sharp.pixelplumbing.com/api-output#avif
188
+ const AVIF_OUTPUT_SCHEMA = {
189
+ type: 'object',
190
+ properties: {
191
+ quality: {
192
+ type: 'number',
193
+ },
194
+ lossless: {
195
+ type: 'boolean',
196
+ },
197
+ speed: {
198
+ type: 'number',
199
+ },
200
+ chromaSubsampling: {
201
+ type: 'string',
202
+ },
203
+ },
204
+ additionalProperties: true,
205
+ };
206
+ // https://sharp.pixelplumbing.com/api-output#heif
207
+ const HEIF_OUTPUT_SCHEMA = {
208
+ type: 'object',
209
+ properties: {
210
+ quality: {
211
+ type: 'number',
212
+ },
213
+ compression: {
214
+ type: 'string',
215
+ },
216
+ lossless: {
217
+ type: 'boolean',
218
+ },
219
+ speed: {
220
+ type: 'number',
221
+ },
222
+ chromaSubsampling: {
223
+ type: 'string',
224
+ },
225
+ },
226
+ additionalProperties: true,
227
+ };
228
+ const CONFIG_SCHEMA = {
229
+ type: 'object',
230
+ properties: {
231
+ // Fallback quality
232
+ quality: {
233
+ type: 'number',
234
+ },
235
+ jpeg: JPEG_OUTPUT_SCHEMA,
236
+ png: PNG_OUTPUT_SCHEMA,
237
+ webp: WEBP_OUTPUT_SCHEMA,
238
+ gif: GIF_OUTPUT_SCHEMA,
239
+ tiff: TIFF_OUTPUT_SCHEMA,
240
+ avif: AVIF_OUTPUT_SCHEMA,
241
+ heif: HEIF_OUTPUT_SCHEMA,
242
+ },
243
+ additionalProperties: false,
244
+ };
245
+ function validateConfig(data, filePath) {
246
+ utils_1.validateSchema.diagnostic(CONFIG_SCHEMA, { data, filePath }, '@atlaspack/transformer-image', 'Invalid sharp config');
247
+ }
@@ -28,6 +28,8 @@ function _workers() {
28
28
  }
29
29
  var _loadSharp = _interopRequireDefault(require("./loadSharp"));
30
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+ // @ts-expect-error TS1192
32
+
31
33
  // from https://github.com/lovell/sharp/blob/df7b8ba73808fc494be413e88cfb621b6279218c/lib/output.js#L6-L17
32
34
  const FORMATS = new Map([['jpeg', 'jpeg'], ['jpg', 'jpeg'], ['png', 'png'], ['webp', 'webp'], ['gif', 'gif'], ['tiff', 'tiff'], ['avif', 'avif'], ['heic', 'heif'], ['heif', 'heif']]);
33
35
  let isSharpLoadedOnMainThread = false;
@@ -58,9 +60,15 @@ var _default = exports.default = new (_plugin().Transformer)({
58
60
  if (!originalFormat) {
59
61
  throw new Error(`The image transformer does not support ${asset.type} images.`);
60
62
  }
61
- const width = asset.query.has('width') ? parseInt(asset.query.get('width'), 10) : null;
62
- const height = asset.query.has('height') ? parseInt(asset.query.get('height'), 10) : null;
63
- const quality = asset.query.has('quality') ? parseInt(asset.query.get('quality'), 10) : config.quality;
63
+ const width = asset.query.has('width') ?
64
+ // @ts-expect-error TS2345
65
+ parseInt(asset.query.get('width'), 10) : null;
66
+ const height = asset.query.has('height') ?
67
+ // @ts-expect-error TS2345
68
+ parseInt(asset.query.get('height'), 10) : null;
69
+ const quality = asset.query.has('quality') ?
70
+ // @ts-expect-error TS2345
71
+ parseInt(asset.query.get('quality'), 10) : config.quality;
64
72
  let targetFormat = (_asset$query$get = asset.query.get('as')) === null || _asset$query$get === void 0 ? void 0 : _asset$query$get.toLowerCase().trim();
65
73
  if (targetFormat && !FORMATS.has(targetFormat)) {
66
74
  throw new Error(`The image transformer does not support ${targetFormat} images.`);
@@ -0,0 +1,3 @@
1
+ import { Transformer } from '@atlaspack/plugin';
2
+ declare const _default: Transformer<unknown>;
3
+ export default _default;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare function validateConfig(data: any, filePath: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/transformer-image",
3
- "version": "3.1.5-canary.36+2d10c6656",
3
+ "version": "3.1.5-canary.361+405bbaf61",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,23 +9,27 @@
9
9
  "type": "git",
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
- "main": "lib/ImageTransformer.js",
13
- "source": "src/ImageTransformer.js",
12
+ "main": "./lib/ImageTransformer.js",
13
+ "source": "./src/ImageTransformer.ts",
14
+ "types": "./lib/types/ImageTransformer.d.ts",
14
15
  "engines": {
15
16
  "node": ">= 16.0.0"
16
17
  },
17
18
  "dependencies": {
18
- "@atlaspack/plugin": "2.14.5-canary.36+2d10c6656",
19
- "@atlaspack/utils": "2.14.5-canary.36+2d10c6656",
20
- "@atlaspack/workers": "2.14.5-canary.36+2d10c6656",
19
+ "@atlaspack/plugin": "2.14.5-canary.361+405bbaf61",
20
+ "@atlaspack/utils": "2.14.5-canary.361+405bbaf61",
21
+ "@atlaspack/workers": "2.14.5-canary.361+405bbaf61",
21
22
  "nullthrows": "^1.1.1"
22
23
  },
23
24
  "devDependencies": {
24
25
  "sharp": "^0.31.1"
25
26
  },
26
27
  "peerDependencies": {
27
- "@atlaspack/core": "^2.13.1"
28
+ "@atlaspack/core": "2.31.3"
28
29
  },
29
30
  "type": "commonjs",
30
- "gitHead": "2d10c6656fc58743c5dbed1d2b6c5666887f9fe4"
31
- }
31
+ "scripts": {
32
+ "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
33
+ },
34
+ "gitHead": "405bbaf619f634cf9e58cc618d9a911f7db2998d"
35
+ }
@@ -1,8 +1,8 @@
1
- // @flow
2
1
  import {validateConfig} from './validateConfig';
3
2
  import {Transformer} from '@atlaspack/plugin';
4
3
  import nullthrows from 'nullthrows';
5
4
  import WorkerFarm from '@atlaspack/workers';
5
+ // @ts-expect-error TS1192
6
6
  import loadSharp from './loadSharp';
7
7
 
8
8
  // from https://github.com/lovell/sharp/blob/df7b8ba73808fc494be413e88cfb621b6279218c/lib/output.js#L6-L17
@@ -20,7 +20,7 @@ const FORMATS = new Map([
20
20
 
21
21
  let isSharpLoadedOnMainThread = false;
22
22
 
23
- export default (new Transformer({
23
+ export default new Transformer({
24
24
  async loadConfig({config}) {
25
25
  let configFile: any = await config.getConfig(
26
26
  ['sharp.config.json'], // '.sharprc', '.sharprc.json'
@@ -46,13 +46,16 @@ export default (new Transformer({
46
46
  }
47
47
 
48
48
  const width = asset.query.has('width')
49
- ? parseInt(asset.query.get('width'), 10)
49
+ ? // @ts-expect-error TS2345
50
+ parseInt(asset.query.get('width'), 10)
50
51
  : null;
51
52
  const height = asset.query.has('height')
52
- ? parseInt(asset.query.get('height'), 10)
53
+ ? // @ts-expect-error TS2345
54
+ parseInt(asset.query.get('height'), 10)
53
55
  : null;
54
56
  const quality = asset.query.has('quality')
55
- ? parseInt(asset.query.get('quality'), 10)
57
+ ? // @ts-expect-error TS2345
58
+ parseInt(asset.query.get('quality'), 10)
56
59
  : config.quality;
57
60
  let targetFormat = asset.query.get('as')?.toLowerCase().trim();
58
61
  if (targetFormat && !FORMATS.has(targetFormat)) {
@@ -117,4 +120,4 @@ export default (new Transformer({
117
120
 
118
121
  return [asset];
119
122
  },
120
- }): Transformer);
123
+ }) as Transformer<unknown>;
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {PackageManager} from '@atlaspack/package-manager';
3
2
  import type {FilePath} from '@atlaspack/types';
4
3
 
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {SchemaEntity} from '@atlaspack/utils';
3
2
  import {validateSchema} from '@atlaspack/utils';
4
3
 
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["src"],
4
+ "compilerOptions": {
5
+ "composite": true
6
+ },
7
+ "references": [
8
+ {
9
+ "path": "../../core/plugin/tsconfig.json"
10
+ },
11
+ {
12
+ "path": "../../core/utils/tsconfig.json"
13
+ },
14
+ {
15
+ "path": "../../core/workers/tsconfig.json"
16
+ }
17
+ ]
18
+ }