MLightCAD
    Preparing search index...

    Class to handle ACI and RGB color logic for MText.

    This class encapsulates color state for MText, supporting both AutoCAD Color Index (ACI) and RGB color. Only one color mode is active at a time: setting an RGB color disables ACI, and vice versa. RGB is stored as a single 24-bit integer (0xRRGGBB) for efficient comparison and serialization.

    Example usage:

    const color1 = new MTextColor(1); // ACI color
    const color2 = new MTextColor([255, 0, 0]); // RGB color
    const color3 = new MTextColor(); // Default (ACI=256, "by layer")
    Index

    Constructors

    • Create a new MTextColor instance.

      Parameters

      • Optionalcolor: number | RGB | null

        The initial color: number for ACI, [r,g,b] for RGB, or null/undefined for default (ACI=256).

      Returns MTextColor

    Accessors

    • get aci(): number | null

      Get the current ACI color value.

      Returns number | null

      The ACI color (0-256), or null if using RGB.

    • set aci(value: number | null): void

      Set the ACI color value. Setting this disables any RGB color.

      Parameters

      • value: number | null

        The ACI color (0-256), or null to unset.

      Returns void

      Error if value is out of range.

    • get isAci(): boolean

      Returns true if the color is set by ACI, false if by RGB.

      Returns boolean

    • get isRgb(): boolean

      Returns true if the color is set by RGB, false if by ACI.

      Returns boolean

    • get rgb(): RGB | null

      Get the current RGB color as a tuple [r, g, b], or null if not set.

      Returns RGB | null

      The RGB color tuple, or null if using ACI.

    • set rgb(value: RGB | null): void

      Set the RGB color. Setting this disables ACI color.

      Parameters

      • value: RGB | null

        The RGB color tuple [r, g, b], or null to use ACI.

      Returns void

    • get rgbValue(): number | null

      Get or set the internal RGB value as a number (0xRRGGBB), or null if not set. Setting this will switch to RGB mode and set ACI to null.

      Returns number | null

    • set rgbValue(val: number | null): void

      Parameters

      • val: number | null

      Returns void

    Methods

    • Returns a deep copy of this color.

      Returns MTextColor

      A new MTextColor instance with the same color state.

    • Equality check for color.

      Parameters

      • other: MTextColor

        The other MTextColor to compare.

      Returns boolean

      True if both ACI and RGB values are equal.

    • Convert the current color to a CSS hex color string (#rrggbb). Returns null if the color is ACI-based and has no RGB value.

      Returns string | null

    • Returns a plain object for serialization.

      Returns { aci: number | null; rgb: RGB | null; rgbValue: number | null }

      An object with aci, rgb (tuple), and rgbValue (number or null).

    • Create an MTextColor from a CSS color string. Supports #rgb, #rrggbb, rgb(...), rgba(...). Returns null if invalid or transparent.

      Parameters

      • value: string | null | undefined

      Returns MTextColor | null