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)

198 lines 6.64 kB
import { AcCmColorMethod } from './AcCmColorMethod'; /** * Represents an AutoCAD-like entity color object. * * This class mimics ObjectARX `AcCmEntityColor`. It stores: * - A color method (`AcCmColorMethod`) * - A single numeric `value` that represents: * - RGB (packed R/G/B) * - ACI index * - Layer index * * It uses lazy decoding/encoding to expose convenient getters/setters. */ var AcCmEntityColor = /** @class */ (function () { /** * Constructs a new `AcCmEntityColor`. * * @param method Initial color method (defaults to `ByColor`) * @param value Internal packed value (defaults to `0`) */ function AcCmEntityColor(method, value) { if (method === void 0) { method = AcCmColorMethod.ByColor; } if (value === void 0) { value = 0; } this._colorMethod = method; this._value = value; } Object.defineProperty(AcCmEntityColor.prototype, "colorMethd", { /** * Gets the method used to determine the final color. */ get: function () { return this._colorMethod; }, enumerable: false, configurable: true }); Object.defineProperty(AcCmEntityColor.prototype, "red", { // --------------------------------------------------------------------- // RGB accessors // --------------------------------------------------------------------- /** * Gets the red component (0–255). Only valid when colorMethod = ByColor. */ get: function () { return (this._value >> 16) & 0xff; }, /** * Sets the red component and updates the packed RGB value. */ set: function (v) { this._colorMethod = AcCmColorMethod.ByColor; this._value = (this._value & 0x00ffff) | ((v & 0xff) << 16); }, enumerable: false, configurable: true }); Object.defineProperty(AcCmEntityColor.prototype, "green", { /** * Gets the green component (0–255). Only valid when colorMethod = ByColor. */ get: function () { return (this._value >> 8) & 0xff; }, /** * Sets the green component and updates the packed RGB value. */ set: function (v) { this._colorMethod = AcCmColorMethod.ByColor; this._value = (this._value & 0xff00ff) | ((v & 0xff) << 8); }, enumerable: false, configurable: true }); Object.defineProperty(AcCmEntityColor.prototype, "blue", { /** * Gets the blue component (0–255). Only valid when colorMethod = ByColor. */ get: function () { return this._value & 0xff; }, /** * Sets the blue component and updates the packed RGB value. */ set: function (v) { this._colorMethod = AcCmColorMethod.ByColor; this._value = (this._value & 0xffff00) | (v & 0xff); }, enumerable: false, configurable: true }); /** * Sets all RGB components. * * @param r Red (0–255) * @param g Green (0–255) * @param b Blue (0–255) */ AcCmEntityColor.prototype.setRGB = function (r, g, b) { this._colorMethod = AcCmColorMethod.ByColor; this._value = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); }; Object.defineProperty(AcCmEntityColor.prototype, "colorIndex", { // --------------------------------------------------------------------- // ACI accessors // --------------------------------------------------------------------- /** * Gets the AutoCAD Color Index (ACI). Only valid when colorMethod = ByACI. */ get: function () { return this._value; }, /** * Sets the AutoCAD Color Index (ACI). */ set: function (index) { this._colorMethod = AcCmColorMethod.ByACI; this._value = index; }, enumerable: false, configurable: true }); Object.defineProperty(AcCmEntityColor.prototype, "layerIndex", { // --------------------------------------------------------------------- // Layer index accessors // --------------------------------------------------------------------- /** * Gets the referenced layer index. Only valid when colorMethod = ByLayer. */ get: function () { return this._value; }, /** * Sets the layer index for ByLayer color mode. */ set: function (index) { this._colorMethod = AcCmColorMethod.ByLayer; this._value = index; }, enumerable: false, configurable: true }); // --------------------------------------------------------------------- // Utility methods // --------------------------------------------------------------------- /** * Returns true if the color method is ByColor (explicit RGB). */ AcCmEntityColor.prototype.isByColor = function () { return this._colorMethod === AcCmColorMethod.ByColor; }; /** * Returns true if the color method is ByLayer. */ AcCmEntityColor.prototype.isByLayer = function () { return this._colorMethod === AcCmColorMethod.ByLayer; }; /** * Returns true if the color method is ByBlock. */ AcCmEntityColor.prototype.isByBlock = function () { return this._colorMethod === AcCmColorMethod.ByBlock; }; /** * Returns true if the color method is ByACI. */ AcCmEntityColor.prototype.isByACI = function () { return this._colorMethod === AcCmColorMethod.ByACI; }; /** * Returns true if color is uninitialized or invalid. */ AcCmEntityColor.prototype.isNone = function () { return this._colorMethod === AcCmColorMethod.None; }; Object.defineProperty(AcCmEntityColor.prototype, "rawValue", { /** * Gets the packed internal value. * * - RGB → packed 24-bit integer * - ACI → index * - Layer → index */ get: function () { return this._value; }, /** * Sets a raw internal value. The meaning depends on `colorMethod`. */ set: function (v) { this._value = v; }, enumerable: false, configurable: true }); return AcCmEntityColor; }()); export { AcCmEntityColor }; //# sourceMappingURL=AcCmEntityColor.js.map