UNPKG

@mlightcad/common

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://img.shields.io/npm/v/@mlightcad/common.svg)](https://www.npmjs.com/package/@mlightcad/common)

196 lines 6.25 kB
import { AcCmColorMethod } from './AcCmColorMethod'; /** * Represents an AutoCAD color. This class supports color methods: * - ByColor: explicit RGB * - ByACI: AutoCAD Color Index (0-256) * - ByLayer: color inherited from layer * - ByBlock: color inherited from block */ export declare class AcCmColor { /** The method used to determine the entity's color */ private _colorMethod; /** * Internal value representing the color. * - RGB: packed 0xRRGGBB for `ByColor` * - ACI: 0–256 for `ByACI` * - Layer index: 256 for `ByLayer` * - Block indicator: 0 for `ByBlock` */ private _value?; /** * Constructs a new AcCmColor. * @param method Initial color method (defaults to `ByColor`) * @param value Internal packed value */ constructor(method?: AcCmColorMethod, value?: number); /** Gets the current color method. */ get colorMethod(): AcCmColorMethod; /** * Sets the color method. * * Note: Changing the method does not modify `_value`. */ set colorMethod(method: AcCmColorMethod); /** Gets the red component (0–255). */ get red(): number | undefined; /** Gets the green component (0–255). */ get green(): number | undefined; /** Gets the blue component (0–255). */ get blue(): number | undefined; /** * Gets the packed RGB value (0xRRGGBB). * * - For `ByColor`, returns `_value` directly * - For `ByACI`, converts index to RGB via `AcCmColorUtil` * - For `ByLayer` or `ByBlock`, returns `_value` directly */ get RGB(): number | undefined; /** * Sets the RGB color. * * @param r Red component (0–255) * @param g Green component (0–255) * @param b Blue component (0–255) * @returns The current instance for chaining */ setRGB(r: number, g: number, b: number): this; /** * Sets the RGB color by a single packed number (0xRRGGBB). * * @param value Packed RGB number */ setRGBValue(value: number | undefined | null): this; /** * Sets the RGB color from a CSS color string. * * Examples: * - "#FF00FF" * - "#F0F" * - "rgb(255,0,255)" * - "rgba(255,0,255,0.5)" * - "red" (named colors) * * @param cssString CSS color string * @returns The current instance for chaining */ setRGBFromCss(cssString: string): this; /** * Sets the color as a scalar grayscale value. * * @param scalar Scalar value (0–255) * @returns The current instance for chaining */ setScalar(scalar: number): this; /** * Gets the hexadecimal representation of the color (e.g., "0xFF00FF"). */ get hexColor(): string | undefined; /** * Gets the CSS RGB color string (e.g., "rgb(255,0,255)"). */ get cssColor(): string | undefined; /** * Returns a CSS rgba() color string with the specified alpha value. * @param alpha - Opacity value between 0 (transparent) and 1 (opaque) */ cssColorAlpha(alpha: number): string | undefined; /** Gets the AutoCAD Color Index (ACI), or undefined if not ByACI, ByBlock, or ByLayer. */ get colorIndex(): number | undefined; /** * Sets the AutoCAD Color Index (0–256). * * - 0 sets the color method to `ByBlock` * - 256 sets the color method to `ByLayer` * - 1–255 sets the color method to `ByACI` * * @param index ACI index */ set colorIndex(index: number | undefined); /** * Returns true if the color method is ByColor (explicit RGB). */ get isByColor(): boolean; /** * Returns true if the color method is ByACI. */ get isByACI(): boolean; /** * Returns true if the color method is ByACI and ACI value is 7 * * Notes: * In AutoCAD, ACI Color 7 (Color Index 7) is officially named "Black" or "White" depending on * the context, but it is functionally defined as the "Contrasting Color" or "Auto-Contrast Color." * Here is the technical explanation of its behavior: * - If the background is dark: Color 7 displays as White. * - If the background is light: Color 7 displays as Black. */ get isForeground(): boolean; /** * Sets the color to ACI value 7. */ setForeground(): this; /** Returns true if the color method is ByLayer. */ get isByLayer(): boolean; /** * Sets the color to ByLayer. * @param value - Option layer color value */ setByLayer(value?: number): this; /** Returns true if the color method is ByBlock. */ get isByBlock(): boolean; /** * Sets the color to ByBlock. * @param value - Option layer color value */ setByBlock(value?: number): this; /** * Gets the color name. * * For `ByColor` or `ByACI`, resolves the name via `AcCmColorUtil`. * For `ByLayer` or `ByBlock`, returns the corresponding string. */ get colorName(): string | undefined; /** * Sets the color by name. * * Resolves the name to an RGB value via `AcCmColorUtil`. * * @param name Color name */ set colorName(name: string | undefined); /** * Creates a clone of this color instance. * * @returns A new AcCmColor instance with the same method and value */ clone(): AcCmColor; /** * Copies color values from another AcCmColor instance. * * @param other The source color * @returns The current instance */ copy(other: AcCmColor): this; /** * Checks equality with another color. * * @param other The color to compare * @returns True if color method and value are identical */ equals(other: AcCmColor): boolean; /** * Returns a string representation of the color. * * - "None" for None colors * - "ByLayer" for ByLayer colors * - "ByBlock" for ByBlock colors * - One number for color index * - RGB format "RGB:R,G,B" for RGB colors */ toString(): string; /** * Creates one AcCmColor from one string */ static fromString(name: string): AcCmColor | undefined; } //# sourceMappingURL=AcCmColor.d.ts.map