import n from "../Color.js";
import m from "../utils/type.js";
const { pow: _ } = Math, g = 1e-7, h = 20;
n.prototype.luminance = function(t, r = "rgb") {
  if (t !== void 0 && m(t) === "number") {
    if (t === 0)
      return new n([0, 0, 0, this._rgb[3]], "rgb");
    if (t === 1)
      return new n([255, 255, 255, this._rgb[3]], "rgb");
    let e = this.luminance(), b = h;
    const i = (c, u) => {
      const o = c.interpolate(u, 0.5, r), a = o.luminance();
      return Math.abs(t - a) < g || !b-- ? o : a > t ? i(c, o) : i(o, u);
    }, f = (e > t ? i(new n([0, 0, 0]), this) : i(this, new n([255, 255, 255]))).rgb();
    return new n([...f, this._rgb[3]]);
  }
  return p(...this._rgb.slice(0, 3));
};
const p = (t, r, e) => (t = s(t), r = s(r), e = s(e), 0.2126 * t + 0.7152 * r + 0.0722 * e), s = (t) => (t /= 255, t <= 0.03928 ? t / 12.92 : _((t + 0.055) / 1.055, 2.4));
//# sourceMappingURL=luminance.js.map
