htmlnano 3.0.0 → 3.2.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.
Files changed (115) hide show
  1. package/README.md +40 -25
  2. package/dist/_modules/collapseAttributeWhitespace.d.mts +41 -5
  3. package/dist/_modules/collapseAttributeWhitespace.d.ts +41 -5
  4. package/dist/_modules/collapseAttributeWhitespace.js +69 -16
  5. package/dist/_modules/collapseAttributeWhitespace.mjs +67 -17
  6. package/dist/_modules/collapseBooleanAttributes.d.mts +36 -3
  7. package/dist/_modules/collapseBooleanAttributes.d.ts +36 -3
  8. package/dist/_modules/collapseBooleanAttributes.js +18 -11
  9. package/dist/_modules/collapseBooleanAttributes.mjs +18 -11
  10. package/dist/_modules/collapseWhitespace.d.mts +36 -3
  11. package/dist/_modules/collapseWhitespace.d.ts +36 -3
  12. package/dist/_modules/collapseWhitespace.js +25 -2
  13. package/dist/_modules/collapseWhitespace.mjs +25 -2
  14. package/dist/_modules/custom.d.mts +36 -3
  15. package/dist/_modules/custom.d.ts +36 -3
  16. package/dist/_modules/deduplicateAttributeValues.d.mts +36 -3
  17. package/dist/_modules/deduplicateAttributeValues.d.ts +36 -3
  18. package/dist/_modules/deduplicateAttributeValues.js +20 -5
  19. package/dist/_modules/deduplicateAttributeValues.mjs +21 -6
  20. package/dist/_modules/example.d.mts +36 -3
  21. package/dist/_modules/example.d.ts +36 -3
  22. package/dist/_modules/mergeScripts.d.mts +36 -3
  23. package/dist/_modules/mergeScripts.d.ts +36 -3
  24. package/dist/_modules/mergeScripts.js +111 -24
  25. package/dist/_modules/mergeScripts.mjs +111 -24
  26. package/dist/_modules/mergeStyles.d.mts +36 -3
  27. package/dist/_modules/mergeStyles.d.ts +36 -3
  28. package/dist/_modules/mergeStyles.js +66 -4
  29. package/dist/_modules/mergeStyles.mjs +66 -4
  30. package/dist/_modules/minifyAttributes.d.mts +95 -0
  31. package/dist/_modules/minifyAttributes.d.ts +95 -0
  32. package/dist/_modules/minifyAttributes.js +159 -0
  33. package/dist/_modules/minifyAttributes.mjs +157 -0
  34. package/dist/_modules/minifyConditionalComments.d.mts +36 -3
  35. package/dist/_modules/minifyConditionalComments.d.ts +36 -3
  36. package/dist/_modules/minifyConditionalComments.js +37 -19
  37. package/dist/_modules/minifyConditionalComments.mjs +37 -19
  38. package/dist/_modules/minifyCss.d.mts +36 -3
  39. package/dist/_modules/minifyCss.d.ts +36 -3
  40. package/dist/_modules/minifyCss.js +13 -27
  41. package/dist/_modules/minifyCss.mjs +14 -28
  42. package/dist/_modules/minifyHtmlTemplate.d.mts +91 -0
  43. package/dist/_modules/minifyHtmlTemplate.d.ts +91 -0
  44. package/dist/_modules/minifyHtmlTemplate.js +231 -0
  45. package/dist/_modules/minifyHtmlTemplate.mjs +228 -0
  46. package/dist/_modules/minifyJs.d.mts +36 -3
  47. package/dist/_modules/minifyJs.d.ts +36 -3
  48. package/dist/_modules/minifyJs.js +106 -5
  49. package/dist/_modules/minifyJs.mjs +107 -6
  50. package/dist/_modules/minifyJson.d.mts +36 -3
  51. package/dist/_modules/minifyJson.d.ts +36 -3
  52. package/dist/_modules/minifyJson.js +8 -11
  53. package/dist/_modules/minifyJson.mjs +8 -11
  54. package/dist/_modules/minifySvg.d.mts +36 -3
  55. package/dist/_modules/minifySvg.d.ts +36 -3
  56. package/dist/_modules/minifySvg.js +35 -4
  57. package/dist/_modules/minifySvg.mjs +35 -4
  58. package/dist/_modules/minifyUrls.d.mts +37 -4
  59. package/dist/_modules/minifyUrls.d.ts +37 -4
  60. package/dist/_modules/minifyUrls.js +52 -27
  61. package/dist/_modules/minifyUrls.mjs +52 -27
  62. package/dist/_modules/normalizeAttributeValues.d.mts +36 -3
  63. package/dist/_modules/normalizeAttributeValues.d.ts +36 -3
  64. package/dist/_modules/normalizeAttributeValues.js +10 -8
  65. package/dist/_modules/normalizeAttributeValues.mjs +10 -8
  66. package/dist/_modules/removeAttributeQuotes.d.mts +40 -4
  67. package/dist/_modules/removeAttributeQuotes.d.ts +40 -4
  68. package/dist/_modules/removeAttributeQuotes.js +9 -4
  69. package/dist/_modules/removeAttributeQuotes.mjs +9 -4
  70. package/dist/_modules/removeComments.d.mts +37 -4
  71. package/dist/_modules/removeComments.d.ts +37 -4
  72. package/dist/_modules/removeComments.js +44 -12
  73. package/dist/_modules/removeComments.mjs +44 -12
  74. package/dist/_modules/removeEmptyAttributes.d.mts +36 -3
  75. package/dist/_modules/removeEmptyAttributes.d.ts +36 -3
  76. package/dist/_modules/removeEmptyAttributes.js +37 -16
  77. package/dist/_modules/removeEmptyAttributes.mjs +37 -16
  78. package/dist/_modules/removeEmptyElements.d.mts +95 -0
  79. package/dist/_modules/removeEmptyElements.d.ts +95 -0
  80. package/dist/_modules/removeEmptyElements.js +90 -0
  81. package/dist/_modules/removeEmptyElements.mjs +88 -0
  82. package/dist/_modules/removeOptionalTags.d.mts +36 -3
  83. package/dist/_modules/removeOptionalTags.d.ts +36 -3
  84. package/dist/_modules/removeOptionalTags.js +39 -28
  85. package/dist/_modules/removeOptionalTags.mjs +39 -28
  86. package/dist/_modules/removeRedundantAttributes.d.mts +36 -3
  87. package/dist/_modules/removeRedundantAttributes.d.ts +36 -3
  88. package/dist/_modules/removeRedundantAttributes.js +43 -28
  89. package/dist/_modules/removeRedundantAttributes.mjs +43 -28
  90. package/dist/_modules/removeUnusedCss.d.mts +37 -3
  91. package/dist/_modules/removeUnusedCss.d.ts +37 -3
  92. package/dist/_modules/removeUnusedCss.js +40 -14
  93. package/dist/_modules/removeUnusedCss.mjs +41 -15
  94. package/dist/_modules/sortAttributes.d.mts +39 -5
  95. package/dist/_modules/sortAttributes.d.ts +39 -5
  96. package/dist/_modules/sortAttributes.js +27 -8
  97. package/dist/_modules/sortAttributes.mjs +27 -8
  98. package/dist/_modules/sortAttributesWithLists.d.mts +39 -4
  99. package/dist/_modules/sortAttributesWithLists.d.ts +39 -4
  100. package/dist/_modules/sortAttributesWithLists.js +61 -52
  101. package/dist/_modules/sortAttributesWithLists.mjs +62 -53
  102. package/dist/helpers.d.ts +8 -1
  103. package/dist/helpers.js +48 -0
  104. package/dist/helpers.mjs +45 -1
  105. package/dist/index.d.ts +37 -4
  106. package/dist/index.js +13 -0
  107. package/dist/index.mjs +13 -0
  108. package/dist/presets/ampSafe.d.ts +36 -3
  109. package/dist/presets/max.d.ts +36 -3
  110. package/dist/presets/max.js +13 -5
  111. package/dist/presets/max.mjs +13 -5
  112. package/dist/presets/safe.d.ts +36 -3
  113. package/dist/presets/safe.js +6 -0
  114. package/dist/presets/safe.mjs +6 -0
  115. package/package.json +27 -15
@@ -10,19 +10,27 @@ var safePreset__default = /*#__PURE__*/_interopDefault(safePreset);
10
10
  * Maximal minification (might break some pages)
11
11
  */ var max = {
12
12
  ...safePreset__default.default,
13
+ removeRedundantAttributes: true,
14
+ sortAttributes: true,
13
15
  collapseWhitespace: 'all',
14
16
  removeComments: 'all',
17
+ removeEmptyElements: true,
18
+ minifyConditionalComments: true,
19
+ removeOptionalTags: true,
15
20
  removeAttributeQuotes: true,
16
- removeRedundantAttributes: true,
21
+ minifyAttributes: {
22
+ metaContent: true,
23
+ redundantWhitespaces: 'agressive'
24
+ },
17
25
  mergeScripts: true,
18
26
  mergeStyles: true,
19
- removeUnusedCss: {},
27
+ removeUnusedCss: {
28
+ tool: 'purgeCSS'
29
+ },
20
30
  minifyCss: {
21
31
  preset: 'default'
22
32
  },
23
- minifySvg: {},
24
- minifyConditionalComments: true,
25
- removeOptionalTags: true
33
+ minifySvg: {}
26
34
  };
27
35
 
28
36
  exports.default = max;
@@ -4,19 +4,27 @@ import safePreset from './safe.mjs';
4
4
  * Maximal minification (might break some pages)
5
5
  */ var max = {
6
6
  ...safePreset,
7
+ removeRedundantAttributes: true,
8
+ sortAttributes: true,
7
9
  collapseWhitespace: 'all',
8
10
  removeComments: 'all',
11
+ removeEmptyElements: true,
12
+ minifyConditionalComments: true,
13
+ removeOptionalTags: true,
9
14
  removeAttributeQuotes: true,
10
- removeRedundantAttributes: true,
15
+ minifyAttributes: {
16
+ metaContent: true,
17
+ redundantWhitespaces: 'agressive'
18
+ },
11
19
  mergeScripts: true,
12
20
  mergeStyles: true,
13
- removeUnusedCss: {},
21
+ removeUnusedCss: {
22
+ tool: 'purgeCSS'
23
+ },
14
24
  minifyCss: {
15
25
  preset: 'default'
16
26
  },
17
- minifySvg: {},
18
- minifyConditionalComments: true,
19
- removeOptionalTags: true
27
+ minifySvg: {}
20
28
  };
21
29
 
22
30
  export { max as default };
@@ -2,15 +2,23 @@ import PostHTML from 'posthtml';
2
2
  import { MinifyOptions } from 'terser';
3
3
  import { Options } from 'cssnano';
4
4
  import { Config } from 'svgo';
5
+ import { UserDefinedOptions } from 'purgecss';
5
6
 
6
7
  type PostHTMLTreeLike = [PostHTML.Node] & PostHTML.NodeAPI & {
7
8
  options?: {
8
9
  quoteAllAttributes?: boolean | undefined;
10
+ quoteStyle?: 0 | 1 | 2 | undefined;
11
+ replaceQuote?: boolean | undefined;
9
12
  } | undefined;
10
13
  render(): string;
11
14
  render(node: PostHTML.Node | PostHTMLTreeLike, renderOptions?: any): string;
12
15
  };
13
16
  type MaybeArray<T> = T | Array<T>;
17
+ type HtmlnanoTemplateRule = {
18
+ tag: string;
19
+ attrs?: Record<string, string | boolean | void>;
20
+ };
21
+ type MinifyHtmlTemplateOptions = boolean | HtmlnanoTemplateRule[];
14
22
  interface HtmlnanoOptions {
15
23
  skipConfigLoading?: boolean;
16
24
  configPath?: string;
@@ -26,17 +34,42 @@ interface HtmlnanoOptions {
26
34
  mergeStyles?: boolean;
27
35
  mergeScripts?: boolean;
28
36
  minifyCss?: Options | boolean;
37
+ minifyHtmlTemplate?: MinifyHtmlTemplateOptions;
29
38
  minifyConditionalComments?: boolean;
30
39
  minifyJs?: MinifyOptions | boolean;
31
40
  minifyJson?: boolean;
41
+ minifyAttributes?: boolean | {
42
+ metaContent?: boolean;
43
+ redundantWhitespaces?: 'safe' | 'agressive' | false;
44
+ };
32
45
  minifySvg?: Config | boolean;
33
46
  normalizeAttributeValues?: boolean;
34
- removeAttributeQuotes?: boolean;
35
- removeComments?: boolean | 'safe' | 'all' | RegExp | ((comment: string) => boolean);
47
+ removeAttributeQuotes?: boolean | {
48
+ force?: boolean;
49
+ };
50
+ removeComments?: boolean | RegExp | ((comment: string) => boolean) | string;
36
51
  removeEmptyAttributes?: boolean;
52
+ removeEmptyElements?: boolean | {
53
+ removeWithAttributes?: boolean;
54
+ };
37
55
  removeRedundantAttributes?: boolean;
38
56
  removeOptionalTags?: boolean;
39
- removeUnusedCss?: boolean;
57
+ removeUnusedCss?: boolean | ({
58
+ tool: 'purgeCSS';
59
+ } & Omit<UserDefinedOptions, 'content' | 'css' | 'extractors'>) | {
60
+ banner?: boolean;
61
+ csspath?: string;
62
+ htmlroot?: string;
63
+ ignore?: (string | RegExp)[];
64
+ inject?: string;
65
+ jsdom?: object;
66
+ media?: string[];
67
+ report?: boolean;
68
+ strictSSL?: boolean;
69
+ timeout?: number;
70
+ uncssrc?: string;
71
+ userAgent?: string;
72
+ };
40
73
  sortAttributes?: boolean | 'alphabetical' | 'frequency';
41
74
  sortAttributesWithLists?: boolean | 'alphabetical' | 'frequency';
42
75
  }
@@ -19,6 +19,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
19
19
  amphtml: false
20
20
  },
21
21
  deduplicateAttributeValues: true,
22
+ minifyAttributes: {
23
+ metaContent: true,
24
+ redundantWhitespaces: 'safe'
25
+ },
22
26
  minifyUrls: false,
23
27
  sortAttributes: false,
24
28
  sortAttributesWithLists: 'alphabetical',
@@ -26,6 +30,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
26
30
  * Minify HTML content
27
31
  * ---------------------------------------- */ collapseWhitespace: 'conservative',
28
32
  removeComments: 'safe',
33
+ removeEmptyElements: false,
29
34
  minifyConditionalComments: false,
30
35
  removeOptionalTags: false,
31
36
  removeAttributeQuotes: false,
@@ -36,6 +41,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
36
41
  minifyCss: {
37
42
  preset: 'default'
38
43
  },
44
+ minifyHtmlTemplate: true,
39
45
  minifyJs: {},
40
46
  minifyJson: {},
41
47
  minifySvg: {
@@ -17,6 +17,10 @@
17
17
  amphtml: false
18
18
  },
19
19
  deduplicateAttributeValues: true,
20
+ minifyAttributes: {
21
+ metaContent: true,
22
+ redundantWhitespaces: 'safe'
23
+ },
20
24
  minifyUrls: false,
21
25
  sortAttributes: false,
22
26
  sortAttributesWithLists: 'alphabetical',
@@ -24,6 +28,7 @@
24
28
  * Minify HTML content
25
29
  * ---------------------------------------- */ collapseWhitespace: 'conservative',
26
30
  removeComments: 'safe',
31
+ removeEmptyElements: false,
27
32
  minifyConditionalComments: false,
28
33
  removeOptionalTags: false,
29
34
  removeAttributeQuotes: false,
@@ -34,6 +39,7 @@
34
39
  minifyCss: {
35
40
  preset: 'default'
36
41
  },
42
+ minifyHtmlTemplate: true,
37
43
  minifyJs: {},
38
44
  minifyJson: {},
39
45
  minifySvg: {
package/package.json CHANGED
@@ -1,18 +1,22 @@
1
1
  {
2
2
  "name": "htmlnano",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "Modular HTML minifier, built on top of the PostHTML",
5
5
  "author": "Kirill Maltsev <maltsevkirill@gmail.com>",
6
6
  "license": "MIT",
7
7
  "scripts": {
8
- "clean": "rimraf dist",
8
+ "clean": "rimraf dist coverage",
9
9
  "build": "npm run clean && bunchee",
10
10
  "postbuild": "chmod +x dist/bin.js",
11
11
  "compile": "npm run build",
12
- "lint": "eslint --fix .",
12
+ "lint:eslint": "eslint --fix .",
13
+ "lint:duplicates": "jscpd",
14
+ "lint:knip": "knip",
15
+ "lint": "npm run lint:eslint && npm run lint:duplicates && npm run lint:knip",
16
+ "test:mocha": "mocha --timeout 5000 --require @swc-node/register --recursive --check-leaks --globals addresses 'test/**/*.ts'",
13
17
  "pretest": "npm run lint && npm run compile",
14
- "test": ":",
15
- "posttest": "mocha --timeout 5000 --require @swc-node/register --recursive --check-leaks --globals addresses 'test/**/*.ts'",
18
+ "test": "c8 -r text -r html npm run test:mocha",
19
+ "posttest": "c8 check-coverage --lines 87 --per-file",
16
20
  "prepare": "npm run compile"
17
21
  },
18
22
  "files": [
@@ -68,17 +72,19 @@
68
72
  "@types/mocha": "^10.0.10",
69
73
  "@types/node": "^25.0.0",
70
74
  "bunchee": "^6.5.1",
75
+ "c8": "^11.0.0",
71
76
  "cssnano": "^7.0.0",
72
77
  "eslint": "^9.25.1",
73
78
  "eslint-config-flat-gitignore": "^2.1.0",
74
- "eslint-plugin-import": "^2.28.1",
75
79
  "eslint-plugin-import-x": "^4.11.0",
76
80
  "eslint-plugin-unused-imports": "^4.1.4",
77
81
  "expect": "^30.1.1",
78
- "globals": "^16.0.0",
82
+ "globals": "^17.0.0",
83
+ "jscpd": "^4.0.8",
84
+ "knip": "^5.83.1",
79
85
  "mocha": "^11.0.1",
80
86
  "postcss": "^8.3.11",
81
- "purgecss": "^7.0.2",
87
+ "purgecss": "^8.0.0",
82
88
  "relateurl": "^0.2.7",
83
89
  "rimraf": "^6.0.0",
84
90
  "srcset": "^5.0.1",
@@ -91,11 +97,11 @@
91
97
  "peerDependencies": {
92
98
  "cssnano": "^7.0.0",
93
99
  "postcss": "^8.3.11",
94
- "purgecss": "^7.0.2",
100
+ "purgecss": "^8.0.0",
95
101
  "relateurl": "^0.2.7",
96
- "srcset": "5.0.1",
97
- "svgo": "^3.0.2",
98
- "terser": "^5.10.0",
102
+ "srcset": "^5.0.1",
103
+ "svgo": "^4.0.0",
104
+ "terser": "^5.21.0",
99
105
  "uncss": "^0.17.3"
100
106
  },
101
107
  "peerDependenciesMeta": {
@@ -124,12 +130,18 @@
124
130
  "optional": true
125
131
  }
126
132
  },
133
+ "c8": {
134
+ "exclude": [
135
+ "dist/**/*.js",
136
+ "dist/**/*.cjs"
137
+ ]
138
+ },
127
139
  "repository": {
128
140
  "type": "git",
129
- "url": "git://github.com/posthtml/htmlnano.git"
141
+ "url": "git://github.com/maltsev/htmlnano.git"
130
142
  },
131
143
  "bugs": {
132
- "url": "https://github.com/posthtml/htmlnano/issues"
144
+ "url": "https://github.com/maltsev/htmlnano/issues"
133
145
  },
134
- "homepage": "https://github.com/posthtml/htmlnano"
146
+ "homepage": "https://github.com/maltsev/htmlnano"
135
147
  }