@divriots/jampack 0.25.0 → 0.27.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.
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/dist/config-types.d.ts +1 -1
- package/dist/index.js +0 -0
- package/dist/optimize.js +31 -22
- package/package.json +10 -9
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/dist/config-types.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type Options = {
|
|
|
27
27
|
src_include: RegExp;
|
|
28
28
|
src_exclude: RegExp | null;
|
|
29
29
|
external: {
|
|
30
|
-
process: 'off' | 'download';
|
|
30
|
+
process: 'off' | 'download' | ((attrib_src: string) => Promise<string>);
|
|
31
31
|
src_include: RegExp;
|
|
32
32
|
src_exclude: RegExp | null;
|
|
33
33
|
};
|
package/dist/index.js
CHANGED
|
File without changes
|
package/dist/optimize.js
CHANGED
|
@@ -219,6 +219,10 @@ async function processImage(state, htmlfile, img, isAboveTheFold) {
|
|
|
219
219
|
});
|
|
220
220
|
return;
|
|
221
221
|
}
|
|
222
|
+
const fullSizeRaw = img.attr('data-fullsize');
|
|
223
|
+
if (typeof fullSizeRaw !== undefined)
|
|
224
|
+
img.removeAttr('data-fullsize');
|
|
225
|
+
const fullSize = !!fullSizeRaw && parseInt(fullSizeRaw) > 0;
|
|
222
226
|
const config = state.options;
|
|
223
227
|
if (!isIncluded(attrib_src, config.image.src_include, config.image.src_exclude)) {
|
|
224
228
|
// Setup to ignore
|
|
@@ -274,6 +278,30 @@ async function processImage(state, htmlfile, img, isAboveTheFold) {
|
|
|
274
278
|
/*
|
|
275
279
|
* Check for external images
|
|
276
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
|
+
}
|
|
277
305
|
switch (config.image.cdn.process) {
|
|
278
306
|
case 'off':
|
|
279
307
|
break;
|
|
@@ -292,6 +320,8 @@ async function processImage(state, htmlfile, img, isAboveTheFold) {
|
|
|
292
320
|
break;
|
|
293
321
|
if (!isIncluded(attrib_src, config.image.cdn.src_include || /.*/, config.image.cdn.src_exclude))
|
|
294
322
|
break;
|
|
323
|
+
if (fullSize)
|
|
324
|
+
return;
|
|
295
325
|
let attrib_width = getIntAttr(img, 'width');
|
|
296
326
|
if (!attrib_width) {
|
|
297
327
|
state.reportIssue(htmlfile, {
|
|
@@ -318,27 +348,6 @@ async function processImage(state, htmlfile, img, isAboveTheFold) {
|
|
|
318
348
|
}
|
|
319
349
|
return;
|
|
320
350
|
}
|
|
321
|
-
if (!isLocal(attrib_src)) {
|
|
322
|
-
switch (config.image.external.process) {
|
|
323
|
-
case 'off': // Don't process external images
|
|
324
|
-
return;
|
|
325
|
-
case 'download': // Download external image for local processing
|
|
326
|
-
if (!isIncluded(attrib_src, config.image.external.src_include, config.image.external.src_exclude))
|
|
327
|
-
break;
|
|
328
|
-
try {
|
|
329
|
-
attrib_src = await downloadExternalImage(state, htmlfile, attrib_src);
|
|
330
|
-
img.attr('src', attrib_src);
|
|
331
|
-
}
|
|
332
|
-
catch (e) {
|
|
333
|
-
state.reportIssue(htmlfile, {
|
|
334
|
-
type: 'warn',
|
|
335
|
-
msg: `Failed to download image: ${attrib_src} - ${e.message}`,
|
|
336
|
-
});
|
|
337
|
-
return; // No more processing
|
|
338
|
-
}
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
351
|
/*
|
|
343
352
|
* Loading image
|
|
344
353
|
*/
|
|
@@ -478,7 +487,7 @@ async function processImage(state, htmlfile, img, isAboveTheFold) {
|
|
|
478
487
|
// The compress pass will compress the images
|
|
479
488
|
// of the srcset
|
|
480
489
|
}
|
|
481
|
-
else {
|
|
490
|
+
else if (!fullSize) {
|
|
482
491
|
const new_srcset = await generateSrcSet(state, htmlfile, originalImage, img.attr('src'), imageLengthToBeatInSrcSet, { toFormat: srcToFormat });
|
|
483
492
|
if (new_srcset !== null) {
|
|
484
493
|
img.attr('srcset', new_srcset);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@divriots/jampack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
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
|
+
}
|