@divriots/jampack 0.26.0 → 0.27.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.
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/dist/config-default.js +1 -0
- package/dist/config-types.d.ts +2 -1
- package/dist/index.js +0 -0
- package/dist/optimize.js +25 -22
- package/package.json +10 -9
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/dist/config-default.js
CHANGED
|
@@ -16,6 +16,7 @@ const default_options = {
|
|
|
16
16
|
embed_size: 1500,
|
|
17
17
|
srcset_min_width: 390 * 2, // HiDPI phone
|
|
18
18
|
srcset_max_width: 1920 * 2, // 4K
|
|
19
|
+
srcset_step: 300,
|
|
19
20
|
max_width: 99999,
|
|
20
21
|
src_include: /^.*$/,
|
|
21
22
|
src_exclude: /^\/vercel\/image\?/, // Ignore /vervel/image? URLs because not local and most likely already optimized,
|
package/dist/config-types.d.ts
CHANGED
|
@@ -23,11 +23,12 @@ export type Options = {
|
|
|
23
23
|
embed_size: number;
|
|
24
24
|
srcset_min_width: number;
|
|
25
25
|
srcset_max_width: number;
|
|
26
|
+
srcset_step: number;
|
|
26
27
|
max_width: number;
|
|
27
28
|
src_include: RegExp;
|
|
28
29
|
src_exclude: RegExp | null;
|
|
29
30
|
external: {
|
|
30
|
-
process: 'off' | 'download';
|
|
31
|
+
process: 'off' | 'download' | ((attrib_src: string) => Promise<string>);
|
|
31
32
|
src_include: RegExp;
|
|
32
33
|
src_exclude: RegExp | null;
|
|
33
34
|
};
|
package/dist/index.js
CHANGED
|
File without changes
|
package/dist/optimize.js
CHANGED
|
@@ -278,6 +278,30 @@ async function processImage(state, htmlfile, img, isAboveTheFold) {
|
|
|
278
278
|
/*
|
|
279
279
|
* Check for external images
|
|
280
280
|
*/
|
|
281
|
+
if (!isLocal(attrib_src) &&
|
|
282
|
+
isIncluded(attrib_src, config.image.external.src_include, config.image.external.src_exclude)) {
|
|
283
|
+
// Don't process external images
|
|
284
|
+
if (config.image.external.process === 'off')
|
|
285
|
+
return;
|
|
286
|
+
try {
|
|
287
|
+
if (config.image.external.process === 'download') {
|
|
288
|
+
// Download external image for local processing
|
|
289
|
+
attrib_src = await downloadExternalImage(state, htmlfile, attrib_src);
|
|
290
|
+
}
|
|
291
|
+
else if (typeof config.image.external.process === 'function') {
|
|
292
|
+
// Custom processing for external image
|
|
293
|
+
attrib_src = await config.image.external.process(attrib_src);
|
|
294
|
+
}
|
|
295
|
+
img.attr('src', attrib_src);
|
|
296
|
+
}
|
|
297
|
+
catch (e) {
|
|
298
|
+
state.reportIssue(htmlfile, {
|
|
299
|
+
type: 'warn',
|
|
300
|
+
msg: `Failed to process external image: ${attrib_src} - ${e.message}`,
|
|
301
|
+
});
|
|
302
|
+
return; // No more processing
|
|
303
|
+
}
|
|
304
|
+
}
|
|
281
305
|
switch (config.image.cdn.process) {
|
|
282
306
|
case 'off':
|
|
283
307
|
break;
|
|
@@ -324,27 +348,6 @@ async function processImage(state, htmlfile, img, isAboveTheFold) {
|
|
|
324
348
|
}
|
|
325
349
|
return;
|
|
326
350
|
}
|
|
327
|
-
if (!isLocal(attrib_src)) {
|
|
328
|
-
switch (config.image.external.process) {
|
|
329
|
-
case 'off': // Don't process external images
|
|
330
|
-
return;
|
|
331
|
-
case 'download': // Download external image for local processing
|
|
332
|
-
if (!isIncluded(attrib_src, config.image.external.src_include, config.image.external.src_exclude))
|
|
333
|
-
break;
|
|
334
|
-
try {
|
|
335
|
-
attrib_src = await downloadExternalImage(state, htmlfile, attrib_src);
|
|
336
|
-
img.attr('src', attrib_src);
|
|
337
|
-
}
|
|
338
|
-
catch (e) {
|
|
339
|
-
state.reportIssue(htmlfile, {
|
|
340
|
-
type: 'warn',
|
|
341
|
-
msg: `Failed to download image: ${attrib_src} - ${e.message}`,
|
|
342
|
-
});
|
|
343
|
-
return; // No more processing
|
|
344
|
-
}
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
351
|
/*
|
|
349
352
|
* Loading image
|
|
350
353
|
*/
|
|
@@ -561,7 +564,7 @@ async function _generateSrcSet({ options }, startSrc, imageWidth, imageHeight, t
|
|
|
561
564
|
return null;
|
|
562
565
|
}
|
|
563
566
|
// Start reduction
|
|
564
|
-
const step =
|
|
567
|
+
const step = options.image.srcset_step; //px
|
|
565
568
|
let valueW = !startSrc ? imageWidth : imageWidth - step;
|
|
566
569
|
valueW = Math.min(valueW, options.image.srcset_max_width);
|
|
567
570
|
while (valueW >= options.image.srcset_min_width) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@divriots/jampack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.1",
|
|
4
4
|
"cache-version": {
|
|
5
5
|
"img": "v1",
|
|
6
6
|
"img-ext": "v1"
|
|
@@ -59,17 +59,18 @@
|
|
|
59
59
|
"tslib": "^2.6.2",
|
|
60
60
|
"typescript": "^5.4.5"
|
|
61
61
|
},
|
|
62
|
-
"engines": {
|
|
63
|
-
"node": ">=14.0.0"
|
|
64
|
-
},
|
|
65
|
-
"bugs": "https://github.com/divriots/jampack/issues",
|
|
66
|
-
"keywords": [],
|
|
67
|
-
"types": "dist/index.d.ts",
|
|
68
62
|
"scripts": {
|
|
69
63
|
"watch": "pnpm build --watch",
|
|
70
64
|
"try": "shx rm -fr demo && cp -R demo_drc demo && node ./dist/index.js ./demo --nocache",
|
|
71
65
|
"build": "shx rm -rf dist && tsc -b",
|
|
72
66
|
"lint": "eslint . --ext .ts --config .eslintrc",
|
|
67
|
+
"prepublishOnly": "pnpm build",
|
|
73
68
|
"cleanAllDotJampack": "find -s . | grep '.jampack$' | xargs rm -fr"
|
|
74
|
-
}
|
|
75
|
-
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=14.0.0"
|
|
72
|
+
},
|
|
73
|
+
"bugs": "https://github.com/divriots/jampack/issues",
|
|
74
|
+
"keywords": [],
|
|
75
|
+
"types": "dist/index.d.ts"
|
|
76
|
+
}
|