@optique/core 1.3.0-dev.2536 → 1.3.0-dev.2540

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/doc.cjs CHANGED
@@ -252,7 +252,7 @@ function formatDocPage(programName, page, options = {}) {
252
252
  return rendered;
253
253
  };
254
254
  const usageLabel = page.usage != null && options.showUsage !== false ? label("Usage:", "usage") + " " : "";
255
- const usageLabelWidth = require_displaywidth.getDisplayWidth(usageLabel);
255
+ const usageLabelWidth = require_displaywidth.getDisplayWidth(usageLabel.split("\n").at(-1) ?? "");
256
256
  const defaultStyle = require_terminal_internal.styleCode(options.theme?.annotationStyles?.default ?? { dim: true });
257
257
  const choicesStyle = require_terminal_internal.styleCode(options.theme?.annotationStyles?.choices ?? { dim: true });
258
258
  require_validate.validateProgramName(programName);
@@ -323,9 +323,9 @@ function formatDocPage(programName, page, options = {}) {
323
323
  }, options.theme))].map((token) => token.width)) : 0;
324
324
  const usageMin = page.usage != null && showUsage ? usageLabelWidth + Math.max(programNameWidth, Math.min(maxVisibleAtomicWidth(page.usage, options.theme), programNameWidth + usageLabelWidth)) : 1;
325
325
  let sectionMin = 1;
326
- if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, require_displaywidth.getDisplayWidth(label("Examples:", "examples")));
327
- if (hasContent(page.author)) sectionMin = Math.max(sectionMin, require_displaywidth.getDisplayWidth(label("Author:", "author")));
328
- if (hasContent(page.bugs)) sectionMin = Math.max(sectionMin, require_displaywidth.getDisplayWidth(label("Bugs:", "bugs")));
326
+ if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, ...label("Examples:", "examples").split("\n").map((line) => require_displaywidth.getDisplayWidth(line)));
327
+ if (hasContent(page.author)) sectionMin = Math.max(sectionMin, ...label("Author:", "author").split("\n").map((line) => require_displaywidth.getDisplayWidth(line)));
328
+ if (hasContent(page.bugs)) sectionMin = Math.max(sectionMin, ...label("Bugs:", "bugs").split("\n").map((line) => require_displaywidth.getDisplayWidth(line)));
329
329
  const minWidth = Math.max(entryMin, usageMin, sectionMin);
330
330
  if (options.maxWidth < minWidth) throw new RangeError(`maxWidth must be at least ${minWidth}, got ${options.maxWidth}.`);
331
331
  if (needsDescColumn && minDescWidth > 1) {
package/dist/doc.js CHANGED
@@ -252,7 +252,7 @@ function formatDocPage(programName, page, options = {}) {
252
252
  return rendered;
253
253
  };
254
254
  const usageLabel = page.usage != null && options.showUsage !== false ? label("Usage:", "usage") + " " : "";
255
- const usageLabelWidth = getDisplayWidth(usageLabel);
255
+ const usageLabelWidth = getDisplayWidth(usageLabel.split("\n").at(-1) ?? "");
256
256
  const defaultStyle = styleCode(options.theme?.annotationStyles?.default ?? { dim: true });
257
257
  const choicesStyle = styleCode(options.theme?.annotationStyles?.choices ?? { dim: true });
258
258
  validateProgramName(programName);
@@ -323,9 +323,9 @@ function formatDocPage(programName, page, options = {}) {
323
323
  }, options.theme))].map((token) => token.width)) : 0;
324
324
  const usageMin = page.usage != null && showUsage ? usageLabelWidth + Math.max(programNameWidth, Math.min(maxVisibleAtomicWidth(page.usage, options.theme), programNameWidth + usageLabelWidth)) : 1;
325
325
  let sectionMin = 1;
326
- if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, getDisplayWidth(label("Examples:", "examples")));
327
- if (hasContent(page.author)) sectionMin = Math.max(sectionMin, getDisplayWidth(label("Author:", "author")));
328
- if (hasContent(page.bugs)) sectionMin = Math.max(sectionMin, getDisplayWidth(label("Bugs:", "bugs")));
326
+ if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, ...label("Examples:", "examples").split("\n").map((line) => getDisplayWidth(line)));
327
+ if (hasContent(page.author)) sectionMin = Math.max(sectionMin, ...label("Author:", "author").split("\n").map((line) => getDisplayWidth(line)));
328
+ if (hasContent(page.bugs)) sectionMin = Math.max(sectionMin, ...label("Bugs:", "bugs").split("\n").map((line) => getDisplayWidth(line)));
329
329
  const minWidth = Math.max(entryMin, usageMin, sectionMin);
330
330
  if (options.maxWidth < minWidth) throw new RangeError(`maxWidth must be at least ${minWidth}, got ${options.maxWidth}.`);
331
331
  if (needsDescColumn && minDescWidth > 1) {
package/dist/facade.cjs CHANGED
@@ -896,7 +896,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
896
896
  label: "Usage:",
897
897
  kind: "usageSummary"
898
898
  }, theme, colors) + " ";
899
- const usageLabelWidth = () => require_displaywidth.getDisplayWidth(usageLabel());
899
+ const usageLabelWidth = () => require_displaywidth.getDisplayWidth(usageLabel().split("\n").at(-1) ?? "");
900
900
  const norm = (c) => c === true ? {} : c;
901
901
  const helpCommandConfig = norm(options.help?.command);
902
902
  const helpOptionConfig = norm(options.help?.option);
@@ -1238,6 +1238,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
1238
1238
  * @param programName The name of the program for help messages.
1239
1239
  * @param args The command-line arguments to parse.
1240
1240
  * @param options Configuration options for customizing behavior.
1241
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
1242
+ * color, even when colors are disabled.
1241
1243
  * @returns The parsed result if successful.
1242
1244
  * @throws {TypeError} If an async parser is passed at runtime. Use
1243
1245
  * {@link runParser} or {@link runParserAsync} for async parsers.
@@ -1261,6 +1263,8 @@ function runParserSync(parser, programName, args, options) {
1261
1263
  * @param programName The name of the program for help messages.
1262
1264
  * @param args The command-line arguments to parse.
1263
1265
  * @param options Configuration options for customizing behavior.
1266
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
1267
+ * color, even when colors are disabled.
1264
1268
  * @returns A Promise of the parsed result if successful.
1265
1269
  * @since 0.9.0
1266
1270
  */
@@ -1610,6 +1614,8 @@ async function runWithBody(parser, programName, contexts, args, options) {
1610
1614
  * @param programName Name of the program for help/error output.
1611
1615
  * @param contexts Source contexts to use (priority: earlier overrides later).
1612
1616
  * @param options Run options including args, help, version, etc.
1617
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
1618
+ * color, even when colors are disabled.
1613
1619
  * @returns Promise that resolves to the parsed result.
1614
1620
  * @throws {TypeError} If two or more contexts share the same
1615
1621
  * {@link SourceContext.id}.
@@ -1708,6 +1714,8 @@ function runWithSyncBody(parser, programName, contexts, args, options) {
1708
1714
  * @param programName Name of the program for help/error output.
1709
1715
  * @param contexts Source contexts to use (priority: earlier overrides later).
1710
1716
  * @param options Run options including args, help, version, etc.
1717
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
1718
+ * color, even when colors are disabled.
1711
1719
  * @returns The parsed result.
1712
1720
  * @throws {TypeError} If an async parser is passed at runtime. Use
1713
1721
  * {@link runWith} or {@link runWithAsync} for async parsers.
@@ -1757,6 +1765,8 @@ function runWithSync(parser, programName, contexts, options) {
1757
1765
  * @param programName Name of the program for help/error output.
1758
1766
  * @param contexts Source contexts to use (priority: earlier overrides later).
1759
1767
  * @param options Run options including args, help, version, etc.
1768
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
1769
+ * color, even when colors are disabled.
1760
1770
  * @returns Promise that resolves to the parsed result.
1761
1771
  * @throws {TypeError} If two or more contexts share the same
1762
1772
  * {@link SourceContext.id}.
package/dist/facade.d.cts CHANGED
@@ -353,6 +353,8 @@ interface RunOptions<THelp, TError> {
353
353
  * @param args Command-line arguments to parse (typically from
354
354
  * `process.argv.slice(2)` on Node.js or `Deno.args` on Deno).
355
355
  * @param options Configuration options for output formatting and callbacks.
356
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
357
+ * color, even when colors are disabled.
356
358
  * @returns The parsed result value, or the return value of `onHelp`/`onError`
357
359
  * callbacks.
358
360
  * @throws {TypeError} If `programName` (or `program.metadata.name`) is not
@@ -385,6 +387,8 @@ declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp
385
387
  * @param programName The name of the program for help messages.
386
388
  * @param args The command-line arguments to parse.
387
389
  * @param options Configuration options for customizing behavior.
390
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
391
+ * color, even when colors are disabled.
388
392
  * @returns The parsed result if successful.
389
393
  * @throws {TypeError} If an async parser is passed at runtime. Use
390
394
  * {@link runParser} or {@link runParserAsync} for async parsers.
@@ -405,6 +409,8 @@ declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>,
405
409
  * @param programName The name of the program for help messages.
406
410
  * @param args The command-line arguments to parse.
407
411
  * @param options Configuration options for customizing behavior.
412
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
413
+ * color, even when colors are disabled.
408
414
  * @returns A Promise of the parsed result if successful.
409
415
  * @since 0.9.0
410
416
  */
@@ -519,6 +525,8 @@ type ContextOptionsParam<TContexts extends readonly SourceContext<unknown>[], TV
519
525
  * @param programName Name of the program for help/error output.
520
526
  * @param contexts Source contexts to use (priority: earlier overrides later).
521
527
  * @param options Run options including args, help, version, etc.
528
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
529
+ * color, even when colors are disabled.
522
530
  * @returns Promise that resolves to the parsed result.
523
531
  * @throws {TypeError} If two or more contexts share the same
524
532
  * {@link SourceContext.id}.
@@ -568,6 +576,8 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
568
576
  * @param programName Name of the program for help/error output.
569
577
  * @param contexts Source contexts to use (priority: earlier overrides later).
570
578
  * @param options Run options including args, help, version, etc.
579
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
580
+ * color, even when colors are disabled.
571
581
  * @returns The parsed result.
572
582
  * @throws {TypeError} If an async parser is passed at runtime. Use
573
583
  * {@link runWith} or {@link runWithAsync} for async parsers.
@@ -596,6 +606,8 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
596
606
  * @param programName Name of the program for help/error output.
597
607
  * @param contexts Source contexts to use (priority: earlier overrides later).
598
608
  * @param options Run options including args, help, version, etc.
609
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
610
+ * color, even when colors are disabled.
599
611
  * @returns Promise that resolves to the parsed result.
600
612
  * @throws {TypeError} If two or more contexts share the same
601
613
  * {@link SourceContext.id}.
package/dist/facade.d.ts CHANGED
@@ -353,6 +353,8 @@ interface RunOptions<THelp, TError> {
353
353
  * @param args Command-line arguments to parse (typically from
354
354
  * `process.argv.slice(2)` on Node.js or `Deno.args` on Deno).
355
355
  * @param options Configuration options for output formatting and callbacks.
356
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
357
+ * color, even when colors are disabled.
356
358
  * @returns The parsed result value, or the return value of `onHelp`/`onError`
357
359
  * callbacks.
358
360
  * @throws {TypeError} If `programName` (or `program.metadata.name`) is not
@@ -385,6 +387,8 @@ declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp
385
387
  * @param programName The name of the program for help messages.
386
388
  * @param args The command-line arguments to parse.
387
389
  * @param options Configuration options for customizing behavior.
390
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
391
+ * color, even when colors are disabled.
388
392
  * @returns The parsed result if successful.
389
393
  * @throws {TypeError} If an async parser is passed at runtime. Use
390
394
  * {@link runParser} or {@link runParserAsync} for async parsers.
@@ -405,6 +409,8 @@ declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>,
405
409
  * @param programName The name of the program for help messages.
406
410
  * @param args The command-line arguments to parse.
407
411
  * @param options Configuration options for customizing behavior.
412
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
413
+ * color, even when colors are disabled.
408
414
  * @returns A Promise of the parsed result if successful.
409
415
  * @since 0.9.0
410
416
  */
@@ -519,6 +525,8 @@ type ContextOptionsParam<TContexts extends readonly SourceContext<unknown>[], TV
519
525
  * @param programName Name of the program for help/error output.
520
526
  * @param contexts Source contexts to use (priority: earlier overrides later).
521
527
  * @param options Run options including args, help, version, etc.
528
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
529
+ * color, even when colors are disabled.
522
530
  * @returns Promise that resolves to the parsed result.
523
531
  * @throws {TypeError} If two or more contexts share the same
524
532
  * {@link SourceContext.id}.
@@ -568,6 +576,8 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
568
576
  * @param programName Name of the program for help/error output.
569
577
  * @param contexts Source contexts to use (priority: earlier overrides later).
570
578
  * @param options Run options including args, help, version, etc.
579
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
580
+ * color, even when colors are disabled.
571
581
  * @returns The parsed result.
572
582
  * @throws {TypeError} If an async parser is passed at runtime. Use
573
583
  * {@link runWith} or {@link runWithAsync} for async parsers.
@@ -596,6 +606,8 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
596
606
  * @param programName Name of the program for help/error output.
597
607
  * @param contexts Source contexts to use (priority: earlier overrides later).
598
608
  * @param options Run options including args, help, version, etc.
609
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
610
+ * color, even when colors are disabled.
599
611
  * @returns Promise that resolves to the parsed result.
600
612
  * @throws {TypeError} If two or more contexts share the same
601
613
  * {@link SourceContext.id}.
package/dist/facade.js CHANGED
@@ -896,7 +896,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
896
896
  label: "Usage:",
897
897
  kind: "usageSummary"
898
898
  }, theme, colors) + " ";
899
- const usageLabelWidth = () => getDisplayWidth(usageLabel());
899
+ const usageLabelWidth = () => getDisplayWidth(usageLabel().split("\n").at(-1) ?? "");
900
900
  const norm = (c) => c === true ? {} : c;
901
901
  const helpCommandConfig = norm(options.help?.command);
902
902
  const helpOptionConfig = norm(options.help?.option);
@@ -1238,6 +1238,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
1238
1238
  * @param programName The name of the program for help messages.
1239
1239
  * @param args The command-line arguments to parse.
1240
1240
  * @param options Configuration options for customizing behavior.
1241
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
1242
+ * color, even when colors are disabled.
1241
1243
  * @returns The parsed result if successful.
1242
1244
  * @throws {TypeError} If an async parser is passed at runtime. Use
1243
1245
  * {@link runParser} or {@link runParserAsync} for async parsers.
@@ -1261,6 +1263,8 @@ function runParserSync(parser, programName, args, options) {
1261
1263
  * @param programName The name of the program for help messages.
1262
1264
  * @param args The command-line arguments to parse.
1263
1265
  * @param options Configuration options for customizing behavior.
1266
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
1267
+ * color, even when colors are disabled.
1264
1268
  * @returns A Promise of the parsed result if successful.
1265
1269
  * @since 0.9.0
1266
1270
  */
@@ -1610,6 +1614,8 @@ async function runWithBody(parser, programName, contexts, args, options) {
1610
1614
  * @param programName Name of the program for help/error output.
1611
1615
  * @param contexts Source contexts to use (priority: earlier overrides later).
1612
1616
  * @param options Run options including args, help, version, etc.
1617
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
1618
+ * color, even when colors are disabled.
1613
1619
  * @returns Promise that resolves to the parsed result.
1614
1620
  * @throws {TypeError} If two or more contexts share the same
1615
1621
  * {@link SourceContext.id}.
@@ -1708,6 +1714,8 @@ function runWithSyncBody(parser, programName, contexts, args, options) {
1708
1714
  * @param programName Name of the program for help/error output.
1709
1715
  * @param contexts Source contexts to use (priority: earlier overrides later).
1710
1716
  * @param options Run options including args, help, version, etc.
1717
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
1718
+ * color, even when colors are disabled.
1711
1719
  * @returns The parsed result.
1712
1720
  * @throws {TypeError} If an async parser is passed at runtime. Use
1713
1721
  * {@link runWith} or {@link runWithAsync} for async parsers.
@@ -1757,6 +1765,8 @@ function runWithSync(parser, programName, contexts, options) {
1757
1765
  * @param programName Name of the program for help/error output.
1758
1766
  * @param contexts Source contexts to use (priority: earlier overrides later).
1759
1767
  * @param options Run options including args, help, version, etc.
1768
+ * @throws {RangeError} If rendering help or errors encounters an invalid theme
1769
+ * color, even when colors are disabled.
1760
1770
  * @returns Promise that resolves to the parsed result.
1761
1771
  * @throws {TypeError} If two or more contexts share the same
1762
1772
  * {@link SourceContext.id}.
package/dist/message.cjs CHANGED
@@ -301,9 +301,9 @@ function formatMessage(msg, options = {}) {
301
301
  /**
302
302
  * Creates a message formatter using a snapshot of the supplied theme.
303
303
  * @param theme Semantic leaf formatters and annotation styles.
304
- * @returns A reusable message formatter.
305
- * @throws {TypeError} If initialWidth is not a finite integer.
306
- * @throws {RangeError} If initialWidth is negative or a color is invalid.
304
+ * @returns A reusable message formatter. Invoking it throws `TypeError` if
305
+ * `initialWidth` is not a finite integer, or `RangeError` if `initialWidth`
306
+ * is negative or a theme color is invalid (even with colors disabled).
307
307
  * @since 1.3.0
308
308
  */
309
309
  function createMessageFormatter(theme) {
@@ -443,9 +443,9 @@ type MessageFormatter = (message: Message, options?: MessageFormatterOptions) =>
443
443
  /**
444
444
  * Creates a message formatter using a snapshot of the supplied theme.
445
445
  * @param theme Semantic leaf formatters and annotation styles.
446
- * @returns A reusable message formatter.
447
- * @throws {TypeError} If initialWidth is not a finite integer.
448
- * @throws {RangeError} If initialWidth is negative or a color is invalid.
446
+ * @returns A reusable message formatter. Invoking it throws `TypeError` if
447
+ * `initialWidth` is not a finite integer, or `RangeError` if `initialWidth`
448
+ * is negative or a theme color is invalid (even with colors disabled).
449
449
  * @since 1.3.0
450
450
  */
451
451
  declare function createMessageFormatter(theme: TerminalTheme): MessageFormatter;
package/dist/message.d.ts CHANGED
@@ -443,9 +443,9 @@ type MessageFormatter = (message: Message, options?: MessageFormatterOptions) =>
443
443
  /**
444
444
  * Creates a message formatter using a snapshot of the supplied theme.
445
445
  * @param theme Semantic leaf formatters and annotation styles.
446
- * @returns A reusable message formatter.
447
- * @throws {TypeError} If initialWidth is not a finite integer.
448
- * @throws {RangeError} If initialWidth is negative or a color is invalid.
446
+ * @returns A reusable message formatter. Invoking it throws `TypeError` if
447
+ * `initialWidth` is not a finite integer, or `RangeError` if `initialWidth`
448
+ * is negative or a theme color is invalid (even with colors disabled).
449
449
  * @since 1.3.0
450
450
  */
451
451
  declare function createMessageFormatter(theme: TerminalTheme): MessageFormatter;
package/dist/message.js CHANGED
@@ -301,9 +301,9 @@ function formatMessage(msg, options = {}) {
301
301
  /**
302
302
  * Creates a message formatter using a snapshot of the supplied theme.
303
303
  * @param theme Semantic leaf formatters and annotation styles.
304
- * @returns A reusable message formatter.
305
- * @throws {TypeError} If initialWidth is not a finite integer.
306
- * @throws {RangeError} If initialWidth is negative or a color is invalid.
304
+ * @returns A reusable message formatter. Invoking it throws `TypeError` if
305
+ * `initialWidth` is not a finite integer, or `RangeError` if `initialWidth`
306
+ * is negative or a theme color is invalid (even with colors disabled).
307
307
  * @since 1.3.0
308
308
  */
309
309
  function createMessageFormatter(theme) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.3.0-dev.2536",
3
+ "version": "1.3.0-dev.2540",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -237,7 +237,7 @@
237
237
  },
238
238
  "sideEffects": false,
239
239
  "devDependencies": {
240
- "@optique/env": "1.3.0-dev.2536+22f9c880",
240
+ "@optique/env": "1.3.0-dev.2540+a24fec00",
241
241
  "@types/node": "^24.0.0",
242
242
  "fast-check": "^4.7.0",
243
243
  "tsdown": "^0.13.0",