htmlnano 2.1.2 → 2.1.4

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 (191) hide show
  1. package/README.md +54 -12
  2. package/dist/_modules/collapseAttributeWhitespace.d.mts +57 -0
  3. package/dist/_modules/collapseAttributeWhitespace.d.ts +57 -0
  4. package/dist/_modules/collapseAttributeWhitespace.js +296 -0
  5. package/dist/_modules/collapseAttributeWhitespace.mjs +293 -0
  6. package/dist/_modules/collapseBooleanAttributes.d.mts +60 -0
  7. package/dist/_modules/collapseBooleanAttributes.d.ts +60 -0
  8. package/dist/_modules/collapseBooleanAttributes.js +159 -0
  9. package/{lib/modules → dist/_modules}/collapseBooleanAttributes.mjs +39 -57
  10. package/dist/_modules/collapseWhitespace.d.mts +57 -0
  11. package/dist/_modules/collapseWhitespace.d.ts +57 -0
  12. package/dist/_modules/collapseWhitespace.js +172 -0
  13. package/dist/_modules/collapseWhitespace.mjs +170 -0
  14. package/dist/_modules/custom.d.mts +57 -0
  15. package/dist/_modules/custom.d.ts +57 -0
  16. package/dist/_modules/custom.js +22 -0
  17. package/dist/_modules/custom.mjs +20 -0
  18. package/dist/_modules/deduplicateAttributeValues.d.mts +56 -0
  19. package/dist/_modules/deduplicateAttributeValues.d.ts +56 -0
  20. package/dist/_modules/deduplicateAttributeValues.js +38 -0
  21. package/dist/_modules/deduplicateAttributeValues.mjs +36 -0
  22. package/dist/_modules/example.d.mts +59 -0
  23. package/dist/_modules/example.d.ts +59 -0
  24. package/dist/_modules/example.js +67 -0
  25. package/dist/_modules/example.mjs +65 -0
  26. package/dist/_modules/mergeScripts.d.mts +56 -0
  27. package/dist/_modules/mergeScripts.d.ts +56 -0
  28. package/dist/_modules/mergeScripts.js +53 -0
  29. package/dist/_modules/mergeScripts.mjs +51 -0
  30. package/dist/_modules/mergeStyles.d.mts +56 -0
  31. package/dist/_modules/mergeStyles.d.ts +56 -0
  32. package/dist/_modules/mergeStyles.js +42 -0
  33. package/dist/_modules/mergeStyles.mjs +40 -0
  34. package/dist/_modules/minifyConditionalComments.d.mts +56 -0
  35. package/dist/_modules/minifyConditionalComments.d.ts +56 -0
  36. package/dist/_modules/minifyConditionalComments.js +54 -0
  37. package/{lib/modules → dist/_modules}/minifyConditionalComments.mjs +21 -22
  38. package/dist/_modules/minifyCss.d.mts +56 -0
  39. package/dist/_modules/minifyCss.d.ts +56 -0
  40. package/dist/_modules/minifyCss.js +84 -0
  41. package/dist/_modules/minifyCss.mjs +82 -0
  42. package/dist/_modules/minifyJs.d.mts +56 -0
  43. package/dist/_modules/minifyJs.d.ts +56 -0
  44. package/dist/_modules/minifyJs.js +108 -0
  45. package/dist/_modules/minifyJs.mjs +106 -0
  46. package/dist/_modules/minifyJson.d.mts +56 -0
  47. package/dist/_modules/minifyJson.d.ts +56 -0
  48. package/dist/_modules/minifyJson.js +35 -0
  49. package/dist/_modules/minifyJson.mjs +33 -0
  50. package/dist/_modules/minifySvg.d.mts +56 -0
  51. package/dist/_modules/minifySvg.d.ts +56 -0
  52. package/dist/_modules/minifySvg.js +40 -0
  53. package/dist/_modules/minifySvg.mjs +38 -0
  54. package/dist/_modules/minifyUrls.d.mts +56 -0
  55. package/dist/_modules/minifyUrls.d.ts +56 -0
  56. package/dist/_modules/minifyUrls.js +180 -0
  57. package/dist/_modules/minifyUrls.mjs +178 -0
  58. package/dist/_modules/normalizeAttributeValues.d.mts +56 -0
  59. package/dist/_modules/normalizeAttributeValues.d.ts +56 -0
  60. package/dist/_modules/normalizeAttributeValues.js +234 -0
  61. package/dist/_modules/normalizeAttributeValues.mjs +232 -0
  62. package/dist/_modules/removeAttributeQuotes.d.mts +56 -0
  63. package/dist/_modules/removeAttributeQuotes.d.ts +56 -0
  64. package/dist/_modules/removeAttributeQuotes.js +15 -0
  65. package/dist/_modules/removeAttributeQuotes.mjs +13 -0
  66. package/dist/_modules/removeComments.d.mts +58 -0
  67. package/dist/_modules/removeComments.d.ts +58 -0
  68. package/dist/_modules/removeComments.js +83 -0
  69. package/{lib/modules → dist/_modules}/removeComments.mjs +24 -35
  70. package/dist/_modules/removeEmptyAttributes.d.mts +56 -0
  71. package/dist/_modules/removeEmptyAttributes.d.ts +56 -0
  72. package/dist/_modules/removeEmptyAttributes.js +197 -0
  73. package/dist/_modules/removeEmptyAttributes.mjs +195 -0
  74. package/dist/_modules/removeOptionalTags.d.mts +56 -0
  75. package/dist/_modules/removeOptionalTags.d.ts +56 -0
  76. package/dist/_modules/removeOptionalTags.js +190 -0
  77. package/{lib/modules → dist/_modules}/removeOptionalTags.mjs +54 -91
  78. package/dist/_modules/removeRedundantAttributes.d.mts +57 -0
  79. package/dist/_modules/removeRedundantAttributes.d.ts +57 -0
  80. package/dist/_modules/removeRedundantAttributes.js +128 -0
  81. package/{lib/modules → dist/_modules}/removeRedundantAttributes.mjs +43 -59
  82. package/dist/_modules/removeUnusedCss.d.mts +60 -0
  83. package/dist/_modules/removeUnusedCss.d.ts +60 -0
  84. package/dist/_modules/removeUnusedCss.js +134 -0
  85. package/dist/_modules/removeUnusedCss.mjs +132 -0
  86. package/dist/_modules/sortAttributes.d.mts +57 -0
  87. package/dist/_modules/sortAttributes.d.ts +57 -0
  88. package/dist/_modules/sortAttributes.js +102 -0
  89. package/{lib/modules → dist/_modules}/sortAttributes.mjs +39 -58
  90. package/dist/_modules/sortAttributesWithLists.d.mts +56 -0
  91. package/dist/_modules/sortAttributesWithLists.d.ts +56 -0
  92. package/dist/_modules/sortAttributesWithLists.js +118 -0
  93. package/{lib/modules → dist/_modules}/sortAttributesWithLists.mjs +41 -59
  94. package/dist/helpers.d.ts +16 -0
  95. package/dist/helpers.js +72 -0
  96. package/dist/helpers.mjs +63 -0
  97. package/dist/index.d.ts +79 -0
  98. package/dist/index.js +223 -0
  99. package/dist/index.mjs +209 -0
  100. package/dist/presets/ampSafe.d.ts +47 -0
  101. package/dist/presets/ampSafe.js +19 -0
  102. package/{lib → dist}/presets/ampSafe.mjs +6 -4
  103. package/dist/presets/max.d.ts +47 -0
  104. package/dist/presets/max.js +28 -0
  105. package/{lib → dist}/presets/max.mjs +6 -4
  106. package/dist/presets/safe.d.ts +47 -0
  107. package/dist/presets/safe.js +60 -0
  108. package/{lib → dist}/presets/safe.mjs +13 -20
  109. package/package.json +53 -56
  110. package/.eslintignore +0 -3
  111. package/CHANGELOG.md +0 -409
  112. package/docs/README.md +0 -33
  113. package/docs/babel.config.js +0 -3
  114. package/docs/docs/010-introduction.md +0 -22
  115. package/docs/docs/020-usage.md +0 -117
  116. package/docs/docs/030-config.md +0 -21
  117. package/docs/docs/040-presets.md +0 -75
  118. package/docs/docs/050-modules.md +0 -855
  119. package/docs/docs/060-contribute.md +0 -16
  120. package/docs/docusaurus.config.js +0 -65
  121. package/docs/netlify.toml +0 -4
  122. package/docs/package-lock.json +0 -21630
  123. package/docs/package.json +0 -40
  124. package/docs/sidebars.js +0 -26
  125. package/docs/versioned_docs/version-1.1.1/010-introduction.md +0 -22
  126. package/docs/versioned_docs/version-1.1.1/020-usage.md +0 -77
  127. package/docs/versioned_docs/version-1.1.1/030-config.md +0 -21
  128. package/docs/versioned_docs/version-1.1.1/040-presets.md +0 -75
  129. package/docs/versioned_docs/version-1.1.1/050-modules.md +0 -785
  130. package/docs/versioned_docs/version-1.1.1/060-contribute.md +0 -16
  131. package/docs/versioned_docs/version-2.0.0/010-introduction.md +0 -22
  132. package/docs/versioned_docs/version-2.0.0/020-usage.md +0 -77
  133. package/docs/versioned_docs/version-2.0.0/030-config.md +0 -21
  134. package/docs/versioned_docs/version-2.0.0/040-presets.md +0 -75
  135. package/docs/versioned_docs/version-2.0.0/050-modules.md +0 -838
  136. package/docs/versioned_docs/version-2.0.0/060-contribute.md +0 -16
  137. package/docs/versioned_sidebars/version-1.1.1-sidebars.json +0 -8
  138. package/docs/versioned_sidebars/version-2.0.0-sidebars.json +0 -8
  139. package/docs/versions.json +0 -4
  140. package/index.cjs +0 -11
  141. package/index.d.cts +0 -3
  142. package/index.d.mts +0 -3
  143. package/index.d.ts +0 -94
  144. package/index.mjs +0 -2
  145. package/lib/helpers.cjs +0 -79
  146. package/lib/helpers.mjs +0 -53
  147. package/lib/htmlnano.cjs +0 -202
  148. package/lib/htmlnano.mjs +0 -198
  149. package/lib/modules/collapseAttributeWhitespace.cjs +0 -86
  150. package/lib/modules/collapseAttributeWhitespace.mjs +0 -104
  151. package/lib/modules/collapseBooleanAttributes.cjs +0 -62
  152. package/lib/modules/collapseWhitespace.cjs +0 -100
  153. package/lib/modules/collapseWhitespace.mjs +0 -132
  154. package/lib/modules/custom.cjs +0 -19
  155. package/lib/modules/custom.mjs +0 -16
  156. package/lib/modules/deduplicateAttributeValues.cjs +0 -38
  157. package/lib/modules/deduplicateAttributeValues.mjs +0 -40
  158. package/lib/modules/example.cjs +0 -85
  159. package/lib/modules/example.mjs +0 -75
  160. package/lib/modules/mergeScripts.cjs +0 -54
  161. package/lib/modules/mergeScripts.mjs +0 -56
  162. package/lib/modules/mergeStyles.cjs +0 -38
  163. package/lib/modules/mergeStyles.mjs +0 -36
  164. package/lib/modules/minifyConditionalComments.cjs +0 -47
  165. package/lib/modules/minifyCss.cjs +0 -73
  166. package/lib/modules/minifyCss.mjs +0 -88
  167. package/lib/modules/minifyJs.cjs +0 -103
  168. package/lib/modules/minifyJs.mjs +0 -121
  169. package/lib/modules/minifyJson.cjs +0 -24
  170. package/lib/modules/minifyJson.mjs +0 -21
  171. package/lib/modules/minifySvg.cjs +0 -37
  172. package/lib/modules/minifySvg.mjs +0 -30
  173. package/lib/modules/minifyUrls.cjs +0 -141
  174. package/lib/modules/minifyUrls.mjs +0 -229
  175. package/lib/modules/normalizeAttributeValues.cjs +0 -120
  176. package/lib/modules/normalizeAttributeValues.mjs +0 -140
  177. package/lib/modules/removeAttributeQuotes.cjs +0 -17
  178. package/lib/modules/removeAttributeQuotes.mjs +0 -12
  179. package/lib/modules/removeComments.cjs +0 -86
  180. package/lib/modules/removeEmptyAttributes.cjs +0 -72
  181. package/lib/modules/removeEmptyAttributes.mjs +0 -121
  182. package/lib/modules/removeOptionalTags.cjs +0 -183
  183. package/lib/modules/removeRedundantAttributes.cjs +0 -112
  184. package/lib/modules/removeUnusedCss.cjs +0 -113
  185. package/lib/modules/removeUnusedCss.mjs +0 -122
  186. package/lib/modules/sortAttributes.cjs +0 -98
  187. package/lib/modules/sortAttributesWithLists.cjs +0 -114
  188. package/lib/presets/ampSafe.cjs +0 -18
  189. package/lib/presets/max.cjs +0 -27
  190. package/lib/presets/safe.cjs +0 -65
  191. package/test.js +0 -23
package/README.md CHANGED
@@ -2,21 +2,63 @@
2
2
  [![npm version](https://badge.fury.io/js/htmlnano.svg)](http://badge.fury.io/js/htmlnano)
3
3
  ![CI](https://github.com/posthtml/htmlnano/actions/workflows/ci.yml/badge.svg)
4
4
 
5
- Modular HTML minifier, built on top of the [PostHTML](https://github.com/posthtml/posthtml). Inspired by [cssnano](http://cssnano.co/).
5
+ Modular HTML minifier, built on top of the [PostHTML](https://github.com/posthtml/posthtml). Inspired by [cssnano](https://github.com/cssnano/cssnano).
6
6
 
7
- ## [Benchmark](https://github.com/maltsev/html-minifiers-benchmark/blob/master/README.md)
8
- [html-minifier-terser@6.0.2]: https://www.npmjs.com/package/html-minifier-terser
9
- [htmlnano@2.0.0]: https://www.npmjs.com/package/htmlnano
7
+ ## Benchmarks
10
8
 
11
- | Website | Source (KB) | [html-minifier-terser@6.0.2] | [htmlnano@2.0.0] |
12
- |---------|------------:|----------------:|-----------:|
13
- | [stackoverflow.blog](https://stackoverflow.blog/) | 90 | 82 | 76 |
14
- | [github.com](https://github.com/) | 232 | 203 | 173 |
15
- | [en.wikipedia.org](https://en.wikipedia.org/wiki/Main_Page) | 81 | 76 | 75 |
16
- | [npmjs.com](https://www.npmjs.com/features) | 43 | 40 | 38 |
17
- | [tc39.es](https://tc39.es/ecma262/) | 6001 | 5465 | 5459 |
18
- | **Avg. minify rate** | 0% | **9%** | **13%** |
9
+ [html-minifier-terser]: https://www.npmjs.com/package/html-minifier-terser/v/7.2.0
10
+ [html-minifier-next]: https://www.npmjs.com/package/html-minifier-next/v/1.4.0
11
+ [htmlnano]: https://www.npmjs.com/package/htmlnano/v/2.1.3
12
+ [minify]: https://www.npmjs.com/package/@tdewolff/minify/v/2.24.2
13
+ [minify-html]: https://www.npmjs.com/package/@minify-html/node/v/0.16.4
19
14
 
15
+ | Website | Source (KB) | [html-minifier-terser] | [html-minifier-next] | [htmlnano] | [minify] | [minify-html] |
16
+ | ----------------------------------------------------------- | ----------: | ---------------------: | -------------------: | ---------: | -------: | ------------: |
17
+ | [stackoverflow.blog](https://stackoverflow.blog/) | 166 | 3.3% | 3.3% | 8.3% | 4.6% | 4.0% |
18
+ | [github.com](https://github.com/) | 541 | 3.7% | 3.7% | 18.1% | 7.9% | 6.2% |
19
+ | [en.wikipedia.org](https://en.wikipedia.org/wiki/Main_Page) | 220 | 4.6% | 4.6% | 4.9% | 6.2% | 2.9% |
20
+ | [npmjs.com](https://www.npmjs.com/package/eslint) | 460 | 0.5% | 0.5% | 0.9% | 3.6% | 0.7% |
21
+ | [tc39.es](https://tc39.es/ecma262/) | 7198 | 8.5% | 8.5% | 8.7% | 9.5% | 9.1% |
22
+ | [apple.com](https://www.apple.com/) | 190 | 7.6% | 7.6% | 12.1% | 10.5% | 8.1% |
23
+ | [w3.org](https://www.w3.org/) | 49 | 18.9% | 18.9% | 23.0% | 24.1% | 19.9% |
24
+ | [weather.com](https://weather.com) | 1770 | 0.2% | 0.2% | 12.1% | 11.9% | 0.6% |
25
+ | **Avg. minify rate** | | **5.9%** | **5.9%** | **11.0%** | **9.8%** | **6.4%** |
26
+
27
+ Latest benchmarks: https://github.com/maltsev/html-minifiers-benchmark (updated daily).
20
28
 
21
29
  ## Documentation
22
30
  https://htmlnano.netlify.app
31
+
32
+
33
+ ## Usage
34
+
35
+ ```bash
36
+ npm install htmlnano
37
+ ```
38
+
39
+ ```js
40
+ const htmlnano = require('htmlnano');
41
+ const options = {
42
+ removeEmptyAttributes: false, // Disable the module "removeEmptyAttributes"
43
+ collapseWhitespace: 'conservative' // Pass options to the module "collapseWhitespace"
44
+ };
45
+ // posthtml, posthtml-render, and posthtml-parse options
46
+ const postHtmlOptions = {
47
+ sync: true, // https://github.com/posthtml/posthtml#usage
48
+ lowerCaseTags: true, // https://github.com/posthtml/posthtml-parser#options
49
+ quoteAllAttributes: false, // https://github.com/posthtml/posthtml-render#options
50
+ };
51
+
52
+ htmlnano
53
+ // "preset" arg might be skipped (see "Presets" section below for more info)
54
+ // "postHtmlOptions" arg might be skipped
55
+ .process(html, options, preset, postHtmlOptions)
56
+ .then(function (result) {
57
+ // result.html is minified
58
+ })
59
+ .catch(function (err) {
60
+ console.error(err);
61
+ });
62
+ ```
63
+
64
+ More usage examples (PostHTML, Gulp, Webpack): https://htmlnano.netlify.app/next/usage
@@ -0,0 +1,57 @@
1
+ import PostHTML from 'posthtml';
2
+ import { MinifyOptions } from 'terser';
3
+ import { Options } from 'cssnano';
4
+ import { Config } from 'svgo';
5
+
6
+ type PostHTMLTreeLike = [PostHTML.Node] & PostHTML.NodeAPI & {
7
+ options?: {
8
+ quoteAllAttributes?: boolean | undefined;
9
+ } | undefined;
10
+ render(): string;
11
+ render(node: PostHTML.Node | PostHTMLTreeLike, renderOptions?: any): string;
12
+ };
13
+ type MaybeArray<T> = T | Array<T>;
14
+ type PostHTMLNodeLike = PostHTML.Node | string;
15
+ interface HtmlnanoOptions {
16
+ skipConfigLoading?: boolean;
17
+ skipInternalWarnings?: boolean;
18
+ collapseAttributeWhitespace?: boolean;
19
+ collapseBooleanAttributes?: {
20
+ amphtml?: boolean;
21
+ };
22
+ collapseWhitespace?: 'conservative' | 'all' | 'aggressive';
23
+ custom?: MaybeArray<(tree: PostHTMLTreeLike, options?: any) => (PostHTML.Node | PostHTMLTreeLike)>;
24
+ deduplicateAttributeValues?: boolean;
25
+ minifyUrls?: URL | string | false;
26
+ mergeStyles?: boolean;
27
+ mergeScripts?: boolean;
28
+ minifyCss?: Options | boolean;
29
+ minifyConditionalComments?: boolean;
30
+ minifyJs?: MinifyOptions | boolean;
31
+ minifyJson?: boolean;
32
+ minifySvg?: Config | boolean;
33
+ normalizeAttributeValues?: boolean;
34
+ removeAttributeQuotes?: boolean;
35
+ removeComments?: boolean | 'safe' | 'all' | RegExp | ((comment: string) => boolean);
36
+ removeEmptyAttributes?: boolean;
37
+ removeRedundantAttributes?: boolean;
38
+ removeOptionalTags?: boolean;
39
+ removeUnusedCss?: boolean;
40
+ sortAttributes?: boolean | 'alphabetical' | 'frequency';
41
+ sortAttributesWithLists?: boolean | 'alphabetical' | 'frequency';
42
+ }
43
+ type HtmlnanoModuleAttrsHandler = (attrs: Record<string, string | boolean | void>, node: PostHTML.Node) => Record<string, string | boolean | void>;
44
+ type HtmlnanoModuleContentHandler = (content: Array<PostHTMLNodeLike>, node: PostHTML.Node) => MaybeArray<PostHTMLNodeLike>;
45
+ type HtmlnanoModuleNodeHandler = (node: PostHTMLNodeLike) => PostHTML.Node | string;
46
+ type OptionalOptions<T> = T extends boolean | string | Function | number | null | undefined ? T : T extends object ? Partial<T> : T;
47
+ type HtmlnanoModule<Options = any> = {
48
+ onAttrs?: (options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => HtmlnanoModuleAttrsHandler;
49
+ onContent?: (options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => HtmlnanoModuleContentHandler;
50
+ onNode?: (options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => HtmlnanoModuleNodeHandler;
51
+ default?: (tree: PostHTMLTreeLike, options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => PostHTMLTreeLike | Promise<PostHTMLTreeLike>;
52
+ };
53
+
54
+ declare const attributesWithLists: Set<string>;
55
+ declare const mod: HtmlnanoModule;
56
+
57
+ export { attributesWithLists, mod as default };
@@ -0,0 +1,57 @@
1
+ import PostHTML from 'posthtml';
2
+ import { MinifyOptions } from 'terser';
3
+ import { Options } from 'cssnano';
4
+ import { Config } from 'svgo';
5
+
6
+ type PostHTMLTreeLike = [PostHTML.Node] & PostHTML.NodeAPI & {
7
+ options?: {
8
+ quoteAllAttributes?: boolean | undefined;
9
+ } | undefined;
10
+ render(): string;
11
+ render(node: PostHTML.Node | PostHTMLTreeLike, renderOptions?: any): string;
12
+ };
13
+ type MaybeArray<T> = T | Array<T>;
14
+ type PostHTMLNodeLike = PostHTML.Node | string;
15
+ interface HtmlnanoOptions {
16
+ skipConfigLoading?: boolean;
17
+ skipInternalWarnings?: boolean;
18
+ collapseAttributeWhitespace?: boolean;
19
+ collapseBooleanAttributes?: {
20
+ amphtml?: boolean;
21
+ };
22
+ collapseWhitespace?: 'conservative' | 'all' | 'aggressive';
23
+ custom?: MaybeArray<(tree: PostHTMLTreeLike, options?: any) => (PostHTML.Node | PostHTMLTreeLike)>;
24
+ deduplicateAttributeValues?: boolean;
25
+ minifyUrls?: URL | string | false;
26
+ mergeStyles?: boolean;
27
+ mergeScripts?: boolean;
28
+ minifyCss?: Options | boolean;
29
+ minifyConditionalComments?: boolean;
30
+ minifyJs?: MinifyOptions | boolean;
31
+ minifyJson?: boolean;
32
+ minifySvg?: Config | boolean;
33
+ normalizeAttributeValues?: boolean;
34
+ removeAttributeQuotes?: boolean;
35
+ removeComments?: boolean | 'safe' | 'all' | RegExp | ((comment: string) => boolean);
36
+ removeEmptyAttributes?: boolean;
37
+ removeRedundantAttributes?: boolean;
38
+ removeOptionalTags?: boolean;
39
+ removeUnusedCss?: boolean;
40
+ sortAttributes?: boolean | 'alphabetical' | 'frequency';
41
+ sortAttributesWithLists?: boolean | 'alphabetical' | 'frequency';
42
+ }
43
+ type HtmlnanoModuleAttrsHandler = (attrs: Record<string, string | boolean | void>, node: PostHTML.Node) => Record<string, string | boolean | void>;
44
+ type HtmlnanoModuleContentHandler = (content: Array<PostHTMLNodeLike>, node: PostHTML.Node) => MaybeArray<PostHTMLNodeLike>;
45
+ type HtmlnanoModuleNodeHandler = (node: PostHTMLNodeLike) => PostHTML.Node | string;
46
+ type OptionalOptions<T> = T extends boolean | string | Function | number | null | undefined ? T : T extends object ? Partial<T> : T;
47
+ type HtmlnanoModule<Options = any> = {
48
+ onAttrs?: (options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => HtmlnanoModuleAttrsHandler;
49
+ onContent?: (options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => HtmlnanoModuleContentHandler;
50
+ onNode?: (options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => HtmlnanoModuleNodeHandler;
51
+ default?: (tree: PostHTMLTreeLike, options: Partial<HtmlnanoOptions>, moduleOptions: OptionalOptions<Options>) => PostHTMLTreeLike | Promise<PostHTMLTreeLike>;
52
+ };
53
+
54
+ declare const attributesWithLists: Set<string>;
55
+ declare const mod: HtmlnanoModule;
56
+
57
+ export { attributesWithLists, mod as default };
@@ -0,0 +1,296 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ var helpers_js = require('../helpers.js');
4
+
5
+ const attributesWithLists = new Set([
6
+ 'class',
7
+ 'dropzone',
8
+ 'rel',
9
+ 'ping',
10
+ 'sandbox',
11
+ /**
12
+ * https://github.com/posthtml/htmlnano/issues/180
13
+ * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-sizes
14
+ *
15
+ * "sizes" of <img> should not be modified, while "sizes" of <link> will only have one entry in most cases.
16
+ */ // 'sizes', // link
17
+ 'headers' // td, th
18
+ ]);
19
+ /** empty set means the attribute is alwasy trimmable */ const attributesWithSingleValue = new Map([
20
+ [
21
+ 'accept',
22
+ new Set([
23
+ 'input'
24
+ ])
25
+ ],
26
+ [
27
+ 'action',
28
+ new Set([
29
+ 'form'
30
+ ])
31
+ ],
32
+ [
33
+ 'accesskey',
34
+ new Set()
35
+ ],
36
+ [
37
+ 'accept-charset',
38
+ new Set([
39
+ 'form'
40
+ ])
41
+ ],
42
+ [
43
+ 'cite',
44
+ new Set([
45
+ 'blockquote',
46
+ 'del',
47
+ 'ins',
48
+ 'q'
49
+ ])
50
+ ],
51
+ [
52
+ 'cols',
53
+ new Set([
54
+ 'textarea'
55
+ ])
56
+ ],
57
+ [
58
+ 'colspan',
59
+ new Set([
60
+ 'td',
61
+ 'th'
62
+ ])
63
+ ],
64
+ [
65
+ 'data',
66
+ new Set([
67
+ 'object'
68
+ ])
69
+ ],
70
+ [
71
+ 'dropzone',
72
+ new Set()
73
+ ],
74
+ [
75
+ 'formaction',
76
+ new Set([
77
+ 'button',
78
+ 'input'
79
+ ])
80
+ ],
81
+ [
82
+ 'height',
83
+ new Set([
84
+ 'canvas',
85
+ 'embed',
86
+ 'iframe',
87
+ 'img',
88
+ 'input',
89
+ 'object',
90
+ 'video'
91
+ ])
92
+ ],
93
+ [
94
+ 'high',
95
+ new Set([
96
+ 'meter'
97
+ ])
98
+ ],
99
+ [
100
+ 'href',
101
+ new Set([
102
+ 'a',
103
+ 'area',
104
+ 'base',
105
+ 'link'
106
+ ])
107
+ ],
108
+ [
109
+ 'itemid',
110
+ new Set()
111
+ ],
112
+ [
113
+ 'low',
114
+ new Set([
115
+ 'meter'
116
+ ])
117
+ ],
118
+ [
119
+ 'manifest',
120
+ new Set([
121
+ 'html'
122
+ ])
123
+ ],
124
+ [
125
+ 'max',
126
+ new Set([
127
+ 'meter',
128
+ 'progress'
129
+ ])
130
+ ],
131
+ [
132
+ 'maxlength',
133
+ new Set([
134
+ 'input',
135
+ 'textarea'
136
+ ])
137
+ ],
138
+ [
139
+ 'media',
140
+ new Set([
141
+ 'source'
142
+ ])
143
+ ],
144
+ [
145
+ 'min',
146
+ new Set([
147
+ 'meter'
148
+ ])
149
+ ],
150
+ [
151
+ 'minlength',
152
+ new Set([
153
+ 'input',
154
+ 'textarea'
155
+ ])
156
+ ],
157
+ [
158
+ 'optimum',
159
+ new Set([
160
+ 'meter'
161
+ ])
162
+ ],
163
+ [
164
+ 'ping',
165
+ new Set([
166
+ 'a',
167
+ 'area'
168
+ ])
169
+ ],
170
+ [
171
+ 'poster',
172
+ new Set([
173
+ 'video'
174
+ ])
175
+ ],
176
+ [
177
+ 'profile',
178
+ new Set([
179
+ 'head'
180
+ ])
181
+ ],
182
+ [
183
+ 'rows',
184
+ new Set([
185
+ 'textarea'
186
+ ])
187
+ ],
188
+ [
189
+ 'rowspan',
190
+ new Set([
191
+ 'td',
192
+ 'th'
193
+ ])
194
+ ],
195
+ [
196
+ 'size',
197
+ new Set([
198
+ 'input',
199
+ 'select'
200
+ ])
201
+ ],
202
+ [
203
+ 'span',
204
+ new Set([
205
+ 'col',
206
+ 'colgroup'
207
+ ])
208
+ ],
209
+ [
210
+ 'src',
211
+ new Set([
212
+ 'audio',
213
+ 'embed',
214
+ 'iframe',
215
+ 'img',
216
+ 'input',
217
+ 'script',
218
+ 'source',
219
+ 'track',
220
+ 'video'
221
+ ])
222
+ ],
223
+ [
224
+ 'start',
225
+ new Set([
226
+ 'ol'
227
+ ])
228
+ ],
229
+ [
230
+ 'step',
231
+ new Set([
232
+ 'input'
233
+ ])
234
+ ],
235
+ [
236
+ 'style',
237
+ new Set()
238
+ ],
239
+ [
240
+ 'tabindex',
241
+ new Set()
242
+ ],
243
+ [
244
+ 'usemap',
245
+ new Set([
246
+ 'img',
247
+ 'object'
248
+ ])
249
+ ],
250
+ [
251
+ 'value',
252
+ new Set([
253
+ 'li',
254
+ 'meter',
255
+ 'progress'
256
+ ])
257
+ ],
258
+ [
259
+ 'width',
260
+ new Set([
261
+ 'canvas',
262
+ 'embed',
263
+ 'iframe',
264
+ 'img',
265
+ 'input',
266
+ 'object',
267
+ 'video'
268
+ ])
269
+ ]
270
+ ]);
271
+ /** Collapse whitespaces inside list-like attributes (e.g. class, rel) */ const mod = {
272
+ onAttrs () {
273
+ return (attrs, node)=>{
274
+ const newAttrs = attrs;
275
+ Object.entries(attrs).forEach(([attrName, attrValue])=>{
276
+ if (typeof attrValue !== 'string') return;
277
+ if (attributesWithLists.has(attrName)) {
278
+ newAttrs[attrName] = attrValue.replace(/\s+/g, ' ').trim();
279
+ return;
280
+ }
281
+ if (helpers_js.isEventHandler(attrName)) {
282
+ newAttrs[attrName] = attrValue.trim();
283
+ } else if (node.tag && attributesWithSingleValue.has(attrName)) {
284
+ const tagSet = attributesWithSingleValue.get(attrName);
285
+ if (tagSet.size === 0 || tagSet.has(node.tag)) {
286
+ newAttrs[attrName] = attrValue.trim();
287
+ }
288
+ }
289
+ });
290
+ return newAttrs;
291
+ };
292
+ }
293
+ };
294
+
295
+ exports.attributesWithLists = attributesWithLists;
296
+ exports.default = mod;