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aAAa,EAC3B,CACE,GAAI,KAAK,KAAM,CACb,MAAM,IAAS,EAAO,KAAK,SAAS,QAAQ,IAAM,KAAK,KAC5C,IAAX,EAAI,GAAW,EAAI,GAAK,KAAK,IAAI,EAAG,EAAI,GAAK,EAAM,GAAK,EAAI,GAAK,KAAK,IAAI,EAAI,GAAK,EAAM,EAC3F,MACE,EAAI,GAAK,KAAK,SAAW,EAAI,GAG/B,OADA,EAAQ,KAAK,SAAS,GACf,KAAK,aAAa,EAE7B,CACF,CAKA,MAAA,CAAO,GAGL,GAFA,KAAK,KAAO,EACZ,KAAK,kBAAkB,KAAK,MAAO,KAAK,UACpC,KAAK,UAAY,KAAK,QAA1B,CAIA,GAAK,EAEE,CACL,IAAK,IAAI,EAAI,EAAG,EAAI,EAAI,OAAQ,IAC9B,KAAK,KAAO,EAAI,WAAW,KAAO,KAAK,MAAQ,GAAK,KAAK,MACzD,KAAK,KAAO,KAAK,KAAO,KAAK,KAE/B,KAAK,SAAW,CAAC,EAAG,EAAG,GACvB,KAAK,SAAW,KAAK,SAAS,KAAI,CAAC,EAAG,IAAgB,KAAK,MAAiB,EAAR,EAAc,KACpF,MARE,KAAK,SAAW,CAAC,EAAG,EAAG,GAAG,KAAI,GAAK,KAAK,MAAsB,IAAhB,KAAK,YAUrD,OADA,KAAK,SAAW,KAAK,aAAa,KAAK,UAChC,OAAS,KAAK,SAAW,GAZhC,CAFE,KAAK,SAAW,KAAK,QAAU,CAAC,IAAK,IAAK,KAAO,CAAC,EAAG,EAAG,EAe5D,iBAGa","file":"/npm/safecolor@1.0.1/safecolor.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/safecolor@1.0.1/safecolor.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * @author jessuni\n */\n\n\nconst _CONFIG = {\n  color: [0, 0, 0],\n  contrast: 4.5,\n  step: 0.05,\n}\n\nclass SafeColor {\n  /**\n   * Create a SafeColor instance with options\n   * @param {Array} color 8bit RGB value of a given color in the form of [R, G, B]\n   * @param {Number} contrast contrast ratio of foreground color and background color https://www.w3.org/TR/WCAG20/#contrast-ratiodef\n   */\n  constructor(options = {}) {\n    this.color = options.color || _CONFIG.color\n    this.contrast = options.contrast || _CONFIG.contrast\n    this.step = _CONFIG.step\n    this.hash = 0\n  }\n\n  _rgb2hsl([r, g, b]) {\n    r /= 255\n    g /= 255\n    b /= 255\n    const cmax = Math.max(r, g, b)\n    const cmin = Math.min(r, g, b)\n    const chroma = cmax - cmin\n    let l = (cmax + cmin) / 2\n    let h, s\n    if (!chroma) {\n      h = s = 0\n    } else {\n      s = chroma / (1 - Math.abs(2 * l - 1))\n      if (cmax === r) {\n        h = ((g - b) / chroma) % 6\n      } else if (cmax === g) {\n        h = (b - r) / chroma + 2\n      } else {\n        h = (r - g) / chroma + 4\n      }\n      h = Math.round(h * 60)\n      h = h < 0 ? h + 360 : h\n    }\n    return [h, s, l]\n  }\n\n  _hsl2rgb([h, s, l]) {\n    let c = (1 - Math.abs(2 * l - 1)) * s\n    let x = c * (1 - Math.abs((h / 60) % 2 - 1))\n    let m = l - c / 2\n    let r = 0\n    let g = 0\n    let b = 0\n    if (h >= 0 && h < 60) {\n      r = c\n      g = x\n      b = 0\n    } else if (h >= 60 && h < 120) {\n      r = x\n      g = c\n      b = 0\n    } else if (h >= 120 && h < 180) {\n      r = 0\n      g = c\n      b = x\n    } else if (h >= 180 && h < 240) {\n      r = 0\n      g = x\n      b = c\n    } else if (h >= 240 && h < 300) {\n      r = x\n      g = 0\n      b = c\n    } else if (h >= 300 && h < 360) {\n      r = c\n      g = 0\n      b = x\n    }\n    r = Math.round((r + m) * 255)\n    g = Math.round((g + m) * 255)\n    b = Math.round((b + m) * 255)\n    return [r, g, b]\n  }\n\n  /**\n   * Calculate the luma of a given sRGB array\n   * @param {Array} sRGB\n   * @return luma of the color\n   */\n  calLuma(sRGB) {\n    const [linearR, linearG, linearB] = sRGB.map(v => {\n      const decimal = v / 255\n      return decimal <= 0.04045 ? decimal / 12.92 : Math.pow((decimal + 0.055) / 1.055, 2.4)\n    })\n    return linearR * 0.2126 + linearG * 0.7152 + linearB * 0.0722\n  }\n\n  /**\n   * Calculate the valid luma range with the provided color and the contrast ratio\n   * @param {Array} fgColor\n   * @param {Number} contrastRatio\n   */\n  calValidLumaRange(fgColor, contrastRatio) {\n    const fgLuma = this.calLuma(fgColor)\n    const edgeLuma = (fgLuma + 0.05) / contrastRatio - 0.05\n    if (edgeLuma < 1 && edgeLuma > 0) {\n      this.minLuma = 0\n      this.maxLuma = edgeLuma\n    } else if (edgeLuma === 1 || edgeLuma === 0) {\n      this.minLuma = this.maxLuma = edgeLuma\n    } else {\n      this.minLuma = (fgLuma + 0.05) * contrastRatio\n      this.maxLuma = 1\n    }\n  }\n\n  /**\n   * Check if generated color's luma is within the valid luma range. If not, launder the color until it is\n   * @param {Array} color\n   */\n  launderColor(color) {\n    const luma = this.calLuma(color)\n    if (luma >= this.minLuma && luma <= this.maxLuma) {\n      return color\n    } else {\n      const hsl = this._rgb2hsl(color)\n      if (luma < this.minLuma) {\n        if (this.hash) {\n          const step = +(this.minLuma - luma).toFixed(2) || this.step\n          hsl[2] === 1 ? hsl[1] = Math.min(hsl[1] + step, 1) : hsl[2] = Math.min(hsl[2] + step, 1)\n        } else {\n          hsl[2] = (1 - hsl[2]) * Math.random() + hsl[2]\n        }\n        color = this._hsl2rgb(hsl)\n        return this.launderColor(color)\n      } else {\n        if (this.hash) {\n          const step = +(luma - this.maxLuma).toFixed(2) || this.step\n          hsl[2] === 0 ? hsl[1] = Math.max(0, hsl[1] - step, 0) : hsl[2] = Math.max(hsl[2] - step, 0)\n        } else {\n          hsl[2] = Math.random() % hsl[2]\n        }\n        color = this._hsl2rgb(hsl)\n        return this.launderColor(color)\n      }\n    }\n  }\n  /**\n   * Generates a random color that meets (>=) the contrast ratio. If a string is passed in, generate a consistent contrast-safe color for that string.\n   * @param {String} str\n   */\n  random(str) {\n    this.hash = 0\n    this.calValidLumaRange(this.color, this.contrast)\n    if (this.minLuma === this.maxLuma) {\n      this.genColor = this.minLuma ? [255, 255, 255] : [0, 0, 0]\n      return\n    }\n    if (!str) {\n      this.genColor = [0, 0, 0].map(v => Math.round(Math.random() * 255))\n    } else {\n      for (let i = 0; i < str.length; i++) {\n        this.hash = str.charCodeAt(i) + ((this.hash << 5) - this.hash)\n        this.hash = this.hash & this.hash\n      }\n      this.genColor = [0, 0, 0]\n      this.genColor = this.genColor.map((v, index) => (v = (this.hash >> (index * 8)) & 255))\n    }\n    this.genColor = this.launderColor(this.genColor)\n    return 'rgb(' + this.genColor + ')'\n  }\n}\n\nexport default SafeColor\n"]}