@optique/core 1.1.0-dev.2057 → 1.1.0-dev.2065

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.
@@ -747,6 +747,83 @@ declare function fileSize(options?: FileSizeOptionsNumber): ValueParser<"sync",
747
747
  * @since 1.1.0
748
748
  */
749
749
  declare function fileSize(options: FileSizeOptionsBigInt): ValueParser<"sync", bigint>;
750
+ /**
751
+ * A structured CSS color value with normalized RGBA components.
752
+ * @since 1.1.0
753
+ */
754
+ interface Color {
755
+ /** Red channel, 0–255. */
756
+ readonly r: number;
757
+ /** Green channel, 0–255. */
758
+ readonly g: number;
759
+ /** Blue channel, 0–255. */
760
+ readonly b: number;
761
+ /** Alpha channel, 0–1 (1 = fully opaque). */
762
+ readonly a: number;
763
+ }
764
+ /**
765
+ * The CSS color notation a {@link color} parser accepts.
766
+ * @since 1.1.0
767
+ */
768
+ type ColorFormat = "hex" | "rgb" | "hsl" | "named";
769
+ /**
770
+ * Options for creating a {@link color} value parser.
771
+ * @since 1.1.0
772
+ */
773
+ interface ColorOptions {
774
+ /**
775
+ * The metavariable name for this parser. Used in help messages to
776
+ * indicate what kind of value this parser expects.
777
+ * @default `"COLOR"`
778
+ */
779
+ readonly metavar?: NonEmptyString;
780
+ /**
781
+ * Restricts which CSS color notations are accepted. Defaults to all
782
+ * four notations: `"hex"`, `"rgb"`, `"hsl"`, and `"named"`.
783
+ * @default all formats
784
+ */
785
+ readonly formats?: readonly ColorFormat[];
786
+ /**
787
+ * A custom placeholder value used during deferred prompt resolution.
788
+ * @default `{ r: 0, g: 0, b: 0, a: 1 }`
789
+ * @since 1.1.0
790
+ */
791
+ readonly placeholder?: Color;
792
+ /**
793
+ * Custom error messages for color parsing failures.
794
+ * @since 1.1.0
795
+ */
796
+ readonly errors?: {
797
+ /**
798
+ * Custom error message when the input is not a valid CSS color string.
799
+ * Can be a static message or a function that receives the raw input.
800
+ */
801
+ readonly invalidFormat?: Message | ((input: string) => Message);
802
+ };
803
+ }
804
+ /**
805
+ * Creates a value parser that accepts CSS color strings and returns a
806
+ * structured {@link Color} object with normalized RGBA components.
807
+ *
808
+ * Supported input notations by default:
809
+ * - Hex: `#rgb`, `#rrggbb`, `#rgba`, `#rrggbbaa`
810
+ * - RGB: `rgb(r, g, b)`, `rgba(r, g, b, a)`
811
+ * - HSL: `hsl(h, s%, l%)`, `hsla(h, s%, l%, a)`
812
+ * - Named: all 148 CSS Level 4 named colors (e.g., `red`, `rebeccapurple`)
813
+ *
814
+ * The `format()` method always outputs canonical lowercase hex
815
+ * (`#rrggbb` when fully opaque, `#rrggbbaa` otherwise).
816
+ *
817
+ * @param options Configuration options for the parser.
818
+ * @returns A sync value parser producing {@link Color} objects.
819
+ * @throws {TypeError} If {@link ColorOptions.metavar} is an empty string, or
820
+ * if {@link ColorOptions.formats} contains an invalid format name.
821
+ * @throws {RangeError} If {@link ValueParser.format} is called with a
822
+ * {@link Color} whose `r`, `g`, or `b` channel is not an integer in
823
+ * 0–255, or whose `a` channel is not a finite number in 0–1.
824
+ * @since 1.1.0
825
+ */
826
+ declare function color(options?: ColorOptions): ValueParser<"sync", Color>;
750
827
  /**
751
828
  * Options for creating a {@link url} parser.
752
829
  */
@@ -2329,4 +2406,4 @@ interface CidrOptions {
2329
2406
  */
2330
2407
  declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
2331
2408
  //#endregion
2332
- export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
2409
+ export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
@@ -747,6 +747,83 @@ declare function fileSize(options?: FileSizeOptionsNumber): ValueParser<"sync",
747
747
  * @since 1.1.0
748
748
  */
749
749
  declare function fileSize(options: FileSizeOptionsBigInt): ValueParser<"sync", bigint>;
750
+ /**
751
+ * A structured CSS color value with normalized RGBA components.
752
+ * @since 1.1.0
753
+ */
754
+ interface Color {
755
+ /** Red channel, 0–255. */
756
+ readonly r: number;
757
+ /** Green channel, 0–255. */
758
+ readonly g: number;
759
+ /** Blue channel, 0–255. */
760
+ readonly b: number;
761
+ /** Alpha channel, 0–1 (1 = fully opaque). */
762
+ readonly a: number;
763
+ }
764
+ /**
765
+ * The CSS color notation a {@link color} parser accepts.
766
+ * @since 1.1.0
767
+ */
768
+ type ColorFormat = "hex" | "rgb" | "hsl" | "named";
769
+ /**
770
+ * Options for creating a {@link color} value parser.
771
+ * @since 1.1.0
772
+ */
773
+ interface ColorOptions {
774
+ /**
775
+ * The metavariable name for this parser. Used in help messages to
776
+ * indicate what kind of value this parser expects.
777
+ * @default `"COLOR"`
778
+ */
779
+ readonly metavar?: NonEmptyString;
780
+ /**
781
+ * Restricts which CSS color notations are accepted. Defaults to all
782
+ * four notations: `"hex"`, `"rgb"`, `"hsl"`, and `"named"`.
783
+ * @default all formats
784
+ */
785
+ readonly formats?: readonly ColorFormat[];
786
+ /**
787
+ * A custom placeholder value used during deferred prompt resolution.
788
+ * @default `{ r: 0, g: 0, b: 0, a: 1 }`
789
+ * @since 1.1.0
790
+ */
791
+ readonly placeholder?: Color;
792
+ /**
793
+ * Custom error messages for color parsing failures.
794
+ * @since 1.1.0
795
+ */
796
+ readonly errors?: {
797
+ /**
798
+ * Custom error message when the input is not a valid CSS color string.
799
+ * Can be a static message or a function that receives the raw input.
800
+ */
801
+ readonly invalidFormat?: Message | ((input: string) => Message);
802
+ };
803
+ }
804
+ /**
805
+ * Creates a value parser that accepts CSS color strings and returns a
806
+ * structured {@link Color} object with normalized RGBA components.
807
+ *
808
+ * Supported input notations by default:
809
+ * - Hex: `#rgb`, `#rrggbb`, `#rgba`, `#rrggbbaa`
810
+ * - RGB: `rgb(r, g, b)`, `rgba(r, g, b, a)`
811
+ * - HSL: `hsl(h, s%, l%)`, `hsla(h, s%, l%, a)`
812
+ * - Named: all 148 CSS Level 4 named colors (e.g., `red`, `rebeccapurple`)
813
+ *
814
+ * The `format()` method always outputs canonical lowercase hex
815
+ * (`#rrggbb` when fully opaque, `#rrggbbaa` otherwise).
816
+ *
817
+ * @param options Configuration options for the parser.
818
+ * @returns A sync value parser producing {@link Color} objects.
819
+ * @throws {TypeError} If {@link ColorOptions.metavar} is an empty string, or
820
+ * if {@link ColorOptions.formats} contains an invalid format name.
821
+ * @throws {RangeError} If {@link ValueParser.format} is called with a
822
+ * {@link Color} whose `r`, `g`, or `b` channel is not an integer in
823
+ * 0–255, or whose `a` channel is not a finite number in 0–1.
824
+ * @since 1.1.0
825
+ */
826
+ declare function color(options?: ColorOptions): ValueParser<"sync", Color>;
750
827
  /**
751
828
  * Options for creating a {@link url} parser.
752
829
  */
@@ -2329,4 +2406,4 @@ interface CidrOptions {
2329
2406
  */
2330
2407
  declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
2331
2408
  //#endregion
2332
- export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
2409
+ export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };