html-minifier-next 4.4.0 → 4.5.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/README.md CHANGED
@@ -33,6 +33,7 @@ Use `html-minifier-next --help` to check all available options:
33
33
  | `--file-ext <extensions>` | Specify file extension(s) to process (overrides config file setting) | `--file-ext=html`, `--file-ext=html,htm,php`, `--file-ext="html, htm, php"` |
34
34
  | `-o <file>`, `--output <file>` | Specify output file (reads from file arguments or STDIN) | File to file: `html-minifier-next input.html -o output.html`<br>Pipe to file: `cat input.html \| html-minifier-next -o output.html`<br>File to STDOUT: `html-minifier-next input.html` |
35
35
  | `-c <file>`, `--config-file <file>` | Use a configuration file | `--config-file=html-minifier.json` |
36
+ | `--preset <name>` | Use a preset configuration (conservative, comprehensive) | `--preset=conservative` |
36
37
  | `-v`, `--verbose` | Show detailed processing information (active options, file statistics) | `html-minifier-next --input-dir=src --output-dir=dist --verbose --collapse-whitespace` |
37
38
  | `-d`, `--dry` | Dry run: Process and report statistics without writing output | `html-minifier-next input.html --dry --collapse-whitespace` |
38
39
  | `-V`, `--version` | Output the version number | `html-minifier-next --version` |
@@ -101,6 +102,29 @@ See [the original blog post](https://perfectionkills.com/experimenting-with-html
101
102
 
102
103
  For lint-like capabilities, take a look at [HTMLLint](https://github.com/kangax/html-lint).
103
104
 
105
+ ## Presets
106
+
107
+ HTML Minifier Next provides presets for common use cases. Presets are pre-configured option sets that can be used as a starting point:
108
+
109
+ * `conservative`: Safe minification suitable for most projects. Includes whitespace collapsing, comment removal, and doctype normalization.
110
+ * `comprehensive`: Aggressive minification for maximum file size reduction. Includes all conservative options plus attribute quote removal, optional tag removal, and more.
111
+
112
+ **Using presets:**
113
+
114
+ ```bash
115
+ # Via CLI flag
116
+ html-minifier-next --preset conservative input.html
117
+
118
+ # Via config file
119
+ html-minifier-next --config-file=html-minifier.json input.html
120
+ # where html-minifier.json contains: { "preset": "conservative" }
121
+
122
+ # Override preset options
123
+ html-minifier-next --preset conservative --remove-empty-attributes input.html
124
+ ```
125
+
126
+ **Priority order:** Presets are applied first, then config file options, then CLI flags. This allows you to start with a preset and customize as needed.
127
+
104
128
  ## Options quick reference
105
129
 
106
130
  Most of the options are disabled by default. Experiment and find what works best for you and your project.
@@ -139,7 +163,7 @@ Options can be used in config files (camelCase) or via CLI flags (kebab-case wit
139
163
  | `preventAttributesEscaping`<br>`--prevent-attributes-escaping` | Prevents the escaping of the values of attributes | `false` |
140
164
  | `processConditionalComments`<br>`--process-conditional-comments` | Process contents of conditional comments through minifier | `false` |
141
165
  | `processScripts`<br>`--process-scripts` | Array of strings corresponding to types of `script` elements to process through minifier (e.g., `text/ng-template`, `text/x-handlebars-template`, etc.) | `[]` |
142
- | `quoteCharacter`<br>`--quote-character` | Type of quote to use for attribute values (`'` or `"`) | |
166
+ | `quoteCharacter`<br>`--quote-character` | Type of quote to use for attribute values (`'` or `"`) | Auto-detected (uses the quote requiring less escaping; defaults to `"` when equal) |
143
167
  | `removeAttributeQuotes`<br>`--remove-attribute-quotes` | [Remove quotes around attributes when possible](https://perfectionkills.com/experimenting-with-html-minifier#remove_attribute_quotes) | `false` |
144
168
  | `removeComments`<br>`--remove-comments` | [Strip HTML comments](https://perfectionkills.com/experimenting-with-html-minifier#remove_comments) | `false` |
145
169
  | `removeEmptyAttributes`<br>`--remove-empty-attributes` | [Remove all attributes with whitespace-only values](https://perfectionkills.com/experimenting-with-html-minifier#remove_empty_or_blank_attributes) | `false` (could be `true`, `Function(attrName, tag)`) |
@@ -156,7 +180,7 @@ Options can be used in config files (camelCase) or via CLI flags (kebab-case wit
156
180
 
157
181
  ### Sorting attributes and style classes
158
182
 
159
- Minifier options like `sortAttributes` and `sortClassName` won't impact the plain‑text size of the output. However, using these options for more consistent ordering improves the compression ratio for gzip and Brotli used over HTTP.
183
+ Minifier options like `sortAttributes` and `sortClassName` wont impact the plain‑text size of the output. However, using these options for more consistent ordering improves the compression ratio for gzip and Brotli used over HTTP.
160
184
 
161
185
  ### CSS minification with Lightning CSS
162
186
 
package/cli.js CHANGED
@@ -32,6 +32,7 @@ import { createRequire } from 'module';
32
32
  import { camelCase, paramCase } from 'change-case';
33
33
  import { Command } from 'commander';
34
34
  import { minify } from './src/htmlminifier.js';
35
+ import { getPreset, getPresetNames } from './src/presets.js';
35
36
 
36
37
  const require = createRequire(import.meta.url);
37
38
  const pkg = require('./package.json');
@@ -250,9 +251,10 @@ function normalizeConfig(config) {
250
251
 
251
252
  let config = {};
252
253
  program.option('-c --config-file <file>', 'Use config file');
254
+ program.option('--preset <name>', `Use a preset configuration (${getPresetNames().join(', ')})`);
253
255
  program.option('--input-dir <dir>', 'Specify an input directory');
254
256
  program.option('--output-dir <dir>', 'Specify an output directory');
255
- program.option('--file-ext <extensions>', 'Specify file extension(s) to process (comma-separated), e.g., html or html,htm,php');
257
+ program.option('--file-ext <extensions>', 'Specify file extension(s) to process (comma-separated), e.g., "html" or "html,htm,php"');
256
258
 
257
259
  (async () => {
258
260
  let content;
@@ -271,19 +273,40 @@ program.option('--file-ext <extensions>', 'Specify file extension(s) to process
271
273
  function createOptions() {
272
274
  const options = {};
273
275
 
276
+ // Priority order: preset < config < CLI
277
+ // 1. Apply preset if specified (CLI `--preset` takes priority over config.preset)
278
+ const presetName = programOptions.preset || config.preset;
279
+ if (presetName) {
280
+ const preset = getPreset(presetName);
281
+ if (!preset) {
282
+ fatal(`Unknown preset "${presetName}". Available presets: ${getPresetNames().join(', ')}`);
283
+ }
284
+ Object.assign(options, preset);
285
+ }
286
+
287
+ // 2. Apply config file options (overrides preset)
274
288
  mainOptionKeys.forEach(function (key) {
275
- const param = programOptions[key === 'minifyURLs' ? 'minifyUrls' : camelCase(key)];
289
+ if (key in config) {
290
+ options[key] = config[key];
291
+ }
292
+ });
276
293
 
294
+ // 3. Apply CLI options (overrides config and preset)
295
+ mainOptionKeys.forEach(function (key) {
296
+ const param = programOptions[key === 'minifyURLs' ? 'minifyUrls' : camelCase(key)];
277
297
  if (typeof param !== 'undefined') {
278
298
  options[key] = param;
279
- } else if (key in config) {
280
- options[key] = config[key];
281
299
  }
282
300
  });
301
+
283
302
  return options;
284
303
  }
285
304
 
286
305
  function getActiveOptionsDisplay(minifierOptions) {
306
+ const presetName = programOptions.preset || config.preset;
307
+ if (presetName) {
308
+ console.error(`Using preset: ${presetName}`);
309
+ }
287
310
  const activeOptions = Object.entries(minifierOptions)
288
311
  .filter(([k]) => program.getOptionValueSource(k === 'minifyURLs' ? 'minifyUrls' : camelCase(k)) === 'cli')
289
312
  .map(([k, v]) => (typeof v === 'boolean' ? (v ? k : `no-${k}`) : k));
@@ -541,6 +541,73 @@ class TokenChain {
541
541
  }
542
542
  }
543
543
 
544
+ /**
545
+ * Preset configurations for HTML Minifier Next
546
+ *
547
+ * Presets provide curated option sets for common use cases:
548
+ * - conservative: Safe minification suitable for most projects
549
+ * - comprehensive: Aggressive minification for maximum file size reduction
550
+ */
551
+
552
+ const presets = {
553
+ conservative: {
554
+ collapseBooleanAttributes: true,
555
+ collapseWhitespace: true,
556
+ conservativeCollapse: true,
557
+ continueOnParseError: true,
558
+ decodeEntities: true,
559
+ minifyURLs: true,
560
+ noNewlinesBeforeTagClose: true,
561
+ preserveLineBreaks: true,
562
+ removeComments: true,
563
+ removeScriptTypeAttributes: true,
564
+ removeStyleLinkTypeAttributes: true,
565
+ useShortDoctype: true
566
+ },
567
+ comprehensive: {
568
+ caseSensitive: true,
569
+ collapseBooleanAttributes: true,
570
+ collapseInlineTagWhitespace: true,
571
+ collapseWhitespace: true,
572
+ continueOnParseError: true,
573
+ decodeEntities: true,
574
+ minifyCSS: true,
575
+ minifyJS: true,
576
+ minifyURLs: true,
577
+ noNewlinesBeforeTagClose: true,
578
+ processConditionalComments: true,
579
+ removeAttributeQuotes: true,
580
+ removeComments: true,
581
+ removeEmptyAttributes: true,
582
+ removeOptionalTags: true,
583
+ removeRedundantAttributes: true,
584
+ removeScriptTypeAttributes: true,
585
+ removeStyleLinkTypeAttributes: true,
586
+ sortAttributes: true,
587
+ sortClassName: true,
588
+ useShortDoctype: true
589
+ }
590
+ };
591
+
592
+ /**
593
+ * Get preset configuration by name
594
+ * @param {string} name - Preset name ('conservative' or 'comprehensive')
595
+ * @returns {object|null} Preset options object or null if not found
596
+ */
597
+ function getPreset(name) {
598
+ if (!name) return null;
599
+ const normalizedName = name.toLowerCase();
600
+ return presets[normalizedName] || null;
601
+ }
602
+
603
+ /**
604
+ * Get list of available preset names
605
+ * @returns {string[]} Array of preset names
606
+ */
607
+ function getPresetNames() {
608
+ return Object.keys(presets);
609
+ }
610
+
544
611
  const trimWhitespace = str => str && str.replace(/^[ \n\r\t\f]+/, '').replace(/[ \n\r\t\f]+$/, '');
545
612
 
546
613
  function collapseWhitespaceAll(str) {
@@ -2019,7 +2086,7 @@ const minify = async function (value, options) {
2019
2086
  return result;
2020
2087
  };
2021
2088
 
2022
- var htmlminifier = { minify };
2089
+ var htmlminifier = { minify, presets, getPreset, getPresetNames };
2023
2090
 
2024
2091
  /**
2025
2092
  * @typedef {Object} HTMLAttribute
@@ -2369,4 +2436,7 @@ var htmlminifier = { minify };
2369
2436
  */
2370
2437
 
2371
2438
  exports.default = htmlminifier;
2439
+ exports.getPreset = getPreset;
2440
+ exports.getPresetNames = getPresetNames;
2372
2441
  exports.minify = minify;
2442
+ exports.presets = presets;
@@ -39594,6 +39594,73 @@ class TokenChain {
39594
39594
  }
39595
39595
  }
39596
39596
 
39597
+ /**
39598
+ * Preset configurations for HTML Minifier Next
39599
+ *
39600
+ * Presets provide curated option sets for common use cases:
39601
+ * - conservative: Safe minification suitable for most projects
39602
+ * - comprehensive: Aggressive minification for maximum file size reduction
39603
+ */
39604
+
39605
+ const presets = {
39606
+ conservative: {
39607
+ collapseBooleanAttributes: true,
39608
+ collapseWhitespace: true,
39609
+ conservativeCollapse: true,
39610
+ continueOnParseError: true,
39611
+ decodeEntities: true,
39612
+ minifyURLs: true,
39613
+ noNewlinesBeforeTagClose: true,
39614
+ preserveLineBreaks: true,
39615
+ removeComments: true,
39616
+ removeScriptTypeAttributes: true,
39617
+ removeStyleLinkTypeAttributes: true,
39618
+ useShortDoctype: true
39619
+ },
39620
+ comprehensive: {
39621
+ caseSensitive: true,
39622
+ collapseBooleanAttributes: true,
39623
+ collapseInlineTagWhitespace: true,
39624
+ collapseWhitespace: true,
39625
+ continueOnParseError: true,
39626
+ decodeEntities: true,
39627
+ minifyCSS: true,
39628
+ minifyJS: true,
39629
+ minifyURLs: true,
39630
+ noNewlinesBeforeTagClose: true,
39631
+ processConditionalComments: true,
39632
+ removeAttributeQuotes: true,
39633
+ removeComments: true,
39634
+ removeEmptyAttributes: true,
39635
+ removeOptionalTags: true,
39636
+ removeRedundantAttributes: true,
39637
+ removeScriptTypeAttributes: true,
39638
+ removeStyleLinkTypeAttributes: true,
39639
+ sortAttributes: true,
39640
+ sortClassName: true,
39641
+ useShortDoctype: true
39642
+ }
39643
+ };
39644
+
39645
+ /**
39646
+ * Get preset configuration by name
39647
+ * @param {string} name - Preset name ('conservative' or 'comprehensive')
39648
+ * @returns {object|null} Preset options object or null if not found
39649
+ */
39650
+ function getPreset(name) {
39651
+ if (!name) return null;
39652
+ const normalizedName = name.toLowerCase();
39653
+ return presets[normalizedName] || null;
39654
+ }
39655
+
39656
+ /**
39657
+ * Get list of available preset names
39658
+ * @returns {string[]} Array of preset names
39659
+ */
39660
+ function getPresetNames() {
39661
+ return Object.keys(presets);
39662
+ }
39663
+
39597
39664
  const trimWhitespace = str => str && str.replace(/^[ \n\r\t\f]+/, '').replace(/[ \n\r\t\f]+$/, '');
39598
39665
 
39599
39666
  function collapseWhitespaceAll(str) {
@@ -41072,7 +41139,7 @@ const minify = async function (value, options) {
41072
41139
  return result;
41073
41140
  };
41074
41141
 
41075
- var htmlminifier = { minify };
41142
+ var htmlminifier = { minify, presets, getPreset, getPresetNames };
41076
41143
 
41077
41144
  /**
41078
41145
  * @typedef {Object} HTMLAttribute
@@ -41421,4 +41488,4 @@ var htmlminifier = { minify };
41421
41488
  * Default: `false`
41422
41489
  */
41423
41490
 
41424
- export { htmlminifier as default, minify };
41491
+ export { htmlminifier as default, getPreset, getPresetNames, minify, presets };
@@ -1,6 +1,9 @@
1
1
  export function minify(value: string, options?: MinifierOptions): Promise<string>;
2
2
  declare namespace _default {
3
3
  export { minify };
4
+ export { presets };
5
+ export { getPreset };
6
+ export { getPresetNames };
4
7
  }
5
8
  export default _default;
6
9
  /**
@@ -397,4 +400,8 @@ export type MinifierOptions = {
397
400
  */
398
401
  useShortDoctype?: boolean;
399
402
  };
403
+ import { presets } from './presets.js';
404
+ import { getPreset } from './presets.js';
405
+ import { getPresetNames } from './presets.js';
406
+ export { presets, getPreset, getPresetNames };
400
407
  //# sourceMappingURL=htmlminifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"htmlminifier.d.ts","sourceRoot":"","sources":["../../src/htmlminifier.js"],"names":[],"mappings":"AAs8CO,8BAJI,MAAM,YACN,eAAe,GACb,OAAO,CAAC,MAAM,CAAC,CAQ3B;;;;;;;;;UAQS,MAAM;YACN,MAAM;YACN,MAAM;mBACN,MAAM;iBACN,MAAM;kBACN,MAAM;;;;;;;;;;;;;4BAQN,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,qBAAqB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,KAAK,OAAO;;;;;;;wBAMjG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,SAAS,EAAE,iBAAiB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,KAAK,OAAO;;;;;;;;oBAMhH,OAAO;;;;;;;;gCAOP,OAAO;;;;;;;;kCAOP,OAAO;;;;;;;;yBAOP,OAAO;;;;;;;;2BAOP,OAAO;;;;;;;;4BAOP,OAAO;;;;;;;2BAOP,OAAO;;;;;;;;uBAMP,MAAM,EAAE;;;;;;yBAOR,MAAM;;;;;;yB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AOP,OAAO;;;;;;;iCAOP,OAAO;;;;;;;oCAMP,OAAO;;;;;;;;;;0BAMP,OAAO;;;;;;;;;qBASP,OAAO,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,IAAI,CAAC;;;;;;;;;oBAQzD,OAAO,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;;;;;;;;0BAQrC,OAAO;;;;;;;sBAOP,OAAO;;wBAhyDkC,cAAc;0BAAd,cAAc;+BAAd,cAAc"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Get preset configuration by name
3
+ * @param {string} name - Preset name ('conservative' or 'comprehensive')
4
+ * @returns {object|null} Preset options object or null if not found
5
+ */
6
+ export function getPreset(name: string): object | null;
7
+ /**
8
+ * Get list of available preset names
9
+ * @returns {string[]} Array of preset names
10
+ */
11
+ export function getPresetNames(): string[];
12
+ export namespace presets {
13
+ namespace conservative {
14
+ let collapseBooleanAttributes: boolean;
15
+ let collapseWhitespace: boolean;
16
+ let conservativeCollapse: boolean;
17
+ let continueOnParseError: boolean;
18
+ let decodeEntities: boolean;
19
+ let minifyURLs: boolean;
20
+ let noNewlinesBeforeTagClose: boolean;
21
+ let preserveLineBreaks: boolean;
22
+ let removeComments: boolean;
23
+ let removeScriptTypeAttributes: boolean;
24
+ let removeStyleLinkTypeAttributes: boolean;
25
+ let useShortDoctype: boolean;
26
+ }
27
+ namespace comprehensive {
28
+ export let caseSensitive: boolean;
29
+ let collapseBooleanAttributes_1: boolean;
30
+ export { collapseBooleanAttributes_1 as collapseBooleanAttributes };
31
+ export let collapseInlineTagWhitespace: boolean;
32
+ let collapseWhitespace_1: boolean;
33
+ export { collapseWhitespace_1 as collapseWhitespace };
34
+ let continueOnParseError_1: boolean;
35
+ export { continueOnParseError_1 as continueOnParseError };
36
+ let decodeEntities_1: boolean;
37
+ export { decodeEntities_1 as decodeEntities };
38
+ export let minifyCSS: boolean;
39
+ export let minifyJS: boolean;
40
+ let minifyURLs_1: boolean;
41
+ export { minifyURLs_1 as minifyURLs };
42
+ let noNewlinesBeforeTagClose_1: boolean;
43
+ export { noNewlinesBeforeTagClose_1 as noNewlinesBeforeTagClose };
44
+ export let processConditionalComments: boolean;
45
+ export let removeAttributeQuotes: boolean;
46
+ let removeComments_1: boolean;
47
+ export { removeComments_1 as removeComments };
48
+ export let removeEmptyAttributes: boolean;
49
+ export let removeOptionalTags: boolean;
50
+ export let removeRedundantAttributes: boolean;
51
+ let removeScriptTypeAttributes_1: boolean;
52
+ export { removeScriptTypeAttributes_1 as removeScriptTypeAttributes };
53
+ let removeStyleLinkTypeAttributes_1: boolean;
54
+ export { removeStyleLinkTypeAttributes_1 as removeStyleLinkTypeAttributes };
55
+ export let sortAttributes: boolean;
56
+ export let sortClassName: boolean;
57
+ let useShortDoctype_1: boolean;
58
+ export { useShortDoctype_1 as useShortDoctype };
59
+ }
60
+ }
61
+ //# sourceMappingURL=presets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../src/presets.js"],"names":[],"mappings":"AAgDA;;;;GAIG;AACH,gCAHW,MAAM,GACJ,MAAM,GAAC,IAAI,CAMvB;AAED;;;GAGG;AACH,kCAFa,MAAM,EAAE,CAIpB"}
package/package.json CHANGED
@@ -84,5 +84,5 @@
84
84
  "test:watch": "node --test --watch tests/*.spec.js"
85
85
  },
86
86
  "type": "module",
87
- "version": "4.4.0"
87
+ "version": "4.5.1"
88
88
  }
@@ -5,6 +5,7 @@ import { minify as terser } from 'terser';
5
5
  import { HTMLParser, endTag } from './htmlparser.js';
6
6
  import TokenChain from './tokenchain.js';
7
7
  import { replaceAsync } from './utils.js';
8
+ import { presets, getPreset, getPresetNames } from './presets.js';
8
9
 
9
10
  const trimWhitespace = str => str && str.replace(/^[ \n\r\t\f]+/, '').replace(/[ \n\r\t\f]+$/, '');
10
11
 
@@ -1484,7 +1485,9 @@ export const minify = async function (value, options) {
1484
1485
  return result;
1485
1486
  };
1486
1487
 
1487
- export default { minify };
1488
+ export { presets, getPreset, getPresetNames };
1489
+
1490
+ export default { minify, presets, getPreset, getPresetNames };
1488
1491
 
1489
1492
  /**
1490
1493
  * @typedef {Object} HTMLAttribute
package/src/presets.js ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Preset configurations for HTML Minifier Next
3
+ *
4
+ * Presets provide curated option sets for common use cases:
5
+ * - conservative: Safe minification suitable for most projects
6
+ * - comprehensive: Aggressive minification for maximum file size reduction
7
+ */
8
+
9
+ export const presets = {
10
+ conservative: {
11
+ collapseBooleanAttributes: true,
12
+ collapseWhitespace: true,
13
+ conservativeCollapse: true,
14
+ continueOnParseError: true,
15
+ decodeEntities: true,
16
+ minifyURLs: true,
17
+ noNewlinesBeforeTagClose: true,
18
+ preserveLineBreaks: true,
19
+ removeComments: true,
20
+ removeScriptTypeAttributes: true,
21
+ removeStyleLinkTypeAttributes: true,
22
+ useShortDoctype: true
23
+ },
24
+ comprehensive: {
25
+ caseSensitive: true,
26
+ collapseBooleanAttributes: true,
27
+ collapseInlineTagWhitespace: true,
28
+ collapseWhitespace: true,
29
+ continueOnParseError: true,
30
+ decodeEntities: true,
31
+ minifyCSS: true,
32
+ minifyJS: true,
33
+ minifyURLs: true,
34
+ noNewlinesBeforeTagClose: true,
35
+ processConditionalComments: true,
36
+ removeAttributeQuotes: true,
37
+ removeComments: true,
38
+ removeEmptyAttributes: true,
39
+ removeOptionalTags: true,
40
+ removeRedundantAttributes: true,
41
+ removeScriptTypeAttributes: true,
42
+ removeStyleLinkTypeAttributes: true,
43
+ sortAttributes: true,
44
+ sortClassName: true,
45
+ useShortDoctype: true
46
+ }
47
+ };
48
+
49
+ /**
50
+ * Get preset configuration by name
51
+ * @param {string} name - Preset name ('conservative' or 'comprehensive')
52
+ * @returns {object|null} Preset options object or null if not found
53
+ */
54
+ export function getPreset(name) {
55
+ if (!name) return null;
56
+ const normalizedName = name.toLowerCase();
57
+ return presets[normalizedName] || null;
58
+ }
59
+
60
+ /**
61
+ * Get list of available preset names
62
+ * @returns {string[]} Array of preset names
63
+ */
64
+ export function getPresetNames() {
65
+ return Object.keys(presets);
66
+ }