{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Lookup table for hex digits\r\nconst hexDigits = \"0123456789abcdef\";\r\n\r\nexport interface RGB {\r\n  r: number;\r\n  g: number;\r\n  b: number;\r\n}\r\n\r\nexport default class FastColorGenerator {\r\n  private state: number;\r\n\r\n  /**\r\n   * Creates an instance of FastColorGenerator.\r\n   * @param seed - The seed value for the generator. Defaults to the current timestamp.\r\n   */\r\n  constructor(seed: number = Date.now()) {\r\n    this.state = seed >>> 0; // Ensure the seed is a 32-bit unsigned integer\r\n  }\r\n\r\n  /**\r\n   * Generates the next pseudo-random color state.\r\n   */\r\n  next(): void {\r\n    const multiplier = 1664525;\r\n    const increment = 1013904223;\r\n\r\n    // Linear Congruential Generator (LCG) for pseudo-random numbers\r\n    this.state = (this.state * multiplier + increment) >>> 0;\r\n  }\r\n\r\n  /**\r\n   * Gets the current color as a hex string (e.g., #rrggbb).\r\n   */\r\n  get hex(): string {\r\n    const { r, g, b } = this.rgb;\r\n    return `#${hexDigits[r >> 4]}${hexDigits[r & 0xf]}${hexDigits[g >> 4]}${\r\n      hexDigits[g & 0xf]\r\n    }${hexDigits[b >> 4]}${hexDigits[b & 0xf]}`;\r\n  }\r\n\r\n  /**\r\n   * Sets the color using a hex string (e.g., #rrggbb).\r\n   * @param value - The hex color string to set.\r\n   * @throws {Error} - If invalid hex color format was passed.\r\n   */\r\n  set hex(value: string) {\r\n    if (!/^#[0-9a-fA-F]{6}$/.test(value)) {\r\n      throw new Error(\"Invalid hex color format. Expected format: #rrggbb.\");\r\n    }\r\n\r\n    const r = parseInt(value.slice(1, 3), 16);\r\n    const g = parseInt(value.slice(3, 5), 16);\r\n    const b = parseInt(value.slice(5, 7), 16);\r\n\r\n    this.rgb = { r, g, b };\r\n  }\r\n\r\n  /**\r\n   * Gets the current color as an RGB object.\r\n   */\r\n  get rgb(): RGB {\r\n    return {\r\n      r: (this.state >> 16) & 0xff,\r\n      g: (this.state >> 8) & 0xff,\r\n      b: this.state & 0xff,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Sets the color using an RGB object.\r\n   * @param value - The RGB object to set.\r\n   */\r\n  set rgb(value: RGB) {\r\n    const { r, g, b } = value;\r\n    if (\r\n      !this.isValidChannel(r) ||\r\n      !this.isValidChannel(g) ||\r\n      !this.isValidChannel(b)\r\n    ) {\r\n      throw new Error(\"RGB values must be integers between 0 and 255.\");\r\n    }\r\n\r\n    this.state = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);\r\n  }\r\n\r\n  /**\r\n   * Validates if a color channel value is between 0 and 255.\r\n   * @param value - The channel value to validate.\r\n   * @returns True if the value is valid, false otherwise.\r\n   */\r\n  private isValidChannel(value: number): boolean {\r\n    return Number.isInteger(value) && value >= 0 && value <= 255;\r\n  }\r\n}\r\n"],"mappings":"4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GACA,IAAMI,EAAY,mBAQGF,EAArB,KAAwC,CAC9B,MAMR,YAAYG,EAAe,KAAK,IAAI,EAAG,CACrC,KAAK,MAAQA,IAAS,CACxB,CAKA,MAAa,CAKX,KAAK,MAAS,KAAK,MAAQ,QAAa,aAAe,CACzD,CAKA,IAAI,KAAc,CAChB,GAAM,CAAE,EAAAC,EAAG,EAAAC,EAAG,EAAAC,CAAE,EAAI,KAAK,IACzB,MAAO,IAAIJ,EAAUE,GAAK,CAAC,CAAC,GAAGF,EAAUE,EAAI,EAAG,CAAC,GAAGF,EAAUG,GAAK,CAAC,CAAC,GACnEH,EAAUG,EAAI,EAAG,CACnB,GAAGH,EAAUI,GAAK,CAAC,CAAC,GAAGJ,EAAUI,EAAI,EAAG,CAAC,EAC3C,CAOA,IAAI,IAAIC,EAAe,CACrB,GAAI,CAAC,oBAAoB,KAAKA,CAAK,EACjC,MAAM,IAAI,MAAM,qDAAqD,EAGvE,IAAMH,EAAI,SAASG,EAAM,MAAM,EAAG,CAAC,EAAG,EAAE,EAClCF,EAAI,SAASE,E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