@divriots/jampack 0.6.1 → 0.7.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/dist/config.d.ts +1 -1
- package/dist/config.js +3 -3
- package/dist/optimize.js +17 -2
- package/package.json +1 -1
- package/dist/compressors/js copy.d.ts +0 -1
- package/dist/compressors/js copy.js +0 -8
- package/dist/types.d.ts +0 -6
- package/dist/types.js +0 -1
package/dist/config.d.ts
CHANGED
package/dist/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const default_options = {
|
|
2
2
|
image: {
|
|
3
3
|
embed_size: 400,
|
|
4
|
-
srcset_min_width:
|
|
4
|
+
srcset_min_width: 640,
|
|
5
5
|
compress: true,
|
|
6
6
|
jpeg: {
|
|
7
7
|
options: {
|
|
@@ -18,12 +18,12 @@ const default_options = {
|
|
|
18
18
|
options_lossless: {
|
|
19
19
|
effort: 4,
|
|
20
20
|
quality: 80,
|
|
21
|
-
mode:
|
|
21
|
+
mode: 'lossless',
|
|
22
22
|
},
|
|
23
23
|
options_lossly: {
|
|
24
24
|
effort: 4,
|
|
25
25
|
quality: 80,
|
|
26
|
-
mode:
|
|
26
|
+
mode: 'lossly',
|
|
27
27
|
},
|
|
28
28
|
},
|
|
29
29
|
},
|
package/dist/optimize.js
CHANGED
|
@@ -11,6 +11,7 @@ import kleur from 'kleur';
|
|
|
11
11
|
import ora from 'ora';
|
|
12
12
|
import { isLocal, Resource, translateSrc } from './utils/resource.js';
|
|
13
13
|
async function analyse(file) {
|
|
14
|
+
var _a;
|
|
14
15
|
console.log('▶ ' + file);
|
|
15
16
|
const html = (await fs.readFile(path.join($state.dir, file))).toString();
|
|
16
17
|
const $ = cheerio.load(html, {
|
|
@@ -46,6 +47,15 @@ async function analyse(file) {
|
|
|
46
47
|
if (theFold) {
|
|
47
48
|
$('the-fold').remove();
|
|
48
49
|
}
|
|
50
|
+
// Add CSS to head
|
|
51
|
+
const CSS = `<style>:where(img){height:auto;}</style>`;
|
|
52
|
+
const heads = $('head');
|
|
53
|
+
if (heads.length > 0) {
|
|
54
|
+
heads.prepend(CSS);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
(_a = $('html')) === null || _a === void 0 ? void 0 : _a.prepend(`<head>${CSS}</head>`);
|
|
58
|
+
}
|
|
49
59
|
if (!$state.args.nowrite) {
|
|
50
60
|
await fs.writeFile(path.join($state.dir, file), $.html());
|
|
51
61
|
}
|
|
@@ -233,10 +243,14 @@ async function processImage(htmlfile, $, imgElement, isAboveTheFold) {
|
|
|
233
243
|
* Attribute 'srcset'
|
|
234
244
|
*/
|
|
235
245
|
const attr_srcset = img.attr('srcset');
|
|
236
|
-
|
|
237
|
-
|
|
246
|
+
const attr_sizes = img.attr('sizes');
|
|
247
|
+
if (attr_srcset || attr_sizes) {
|
|
248
|
+
// If srcset or sizes are set, don't touch it.
|
|
238
249
|
// The compress pass will compress the images
|
|
239
250
|
// of the srcset
|
|
251
|
+
//
|
|
252
|
+
// TODO
|
|
253
|
+
// support if sizes alone is set (no srcset) and generate the appropriate srcset
|
|
240
254
|
}
|
|
241
255
|
else {
|
|
242
256
|
// Generate image set
|
|
@@ -286,6 +300,7 @@ async function processImage(htmlfile, $, imgElement, isAboveTheFold) {
|
|
|
286
300
|
}
|
|
287
301
|
if (new_srcset) {
|
|
288
302
|
img.attr('srcset', `${img.attr('src')} ${w}w` + new_srcset);
|
|
303
|
+
img.attr('sizes', '100vw');
|
|
289
304
|
}
|
|
290
305
|
}
|
|
291
306
|
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function compressJS(originalCode: string): Promise<string>;
|
package/dist/types.d.ts
DELETED
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|