import f from "../Color.js";
import "../io/lab/index.js";
import h from "./scale.js";
const s = function(a) {
  let l = [1, 1];
  for (let t = 1; t < a; t++) {
    let o = [1];
    for (let b = 1; b <= l.length; b++)
      o[b] = (l[b] || 0) + l[b - 1];
    l = o;
  }
  return l;
}, z = function(a) {
  let l, t, o, b;
  if (a = a.map((e) => new f(e)), a.length === 2)
    [t, o] = a.map((e) => e.lab()), l = function(e) {
      const n = [0, 1, 2].map((r) => t[r] + e * (o[r] - t[r]));
      return new f(n, "lab");
    };
  else if (a.length === 3)
    [t, o, b] = a.map((e) => e.lab()), l = function(e) {
      const n = [0, 1, 2].map(
        (r) => (1 - e) * (1 - e) * t[r] + 2 * (1 - e) * e * o[r] + e * e * b[r]
      );
      return new f(n, "lab");
    };
  else if (a.length === 4) {
    let e;
    [t, o, b, e] = a.map((n) => n.lab()), l = function(n) {
      const r = [0, 1, 2].map(
        (u) => (1 - n) * (1 - n) * (1 - n) * t[u] + 3 * (1 - n) * (1 - n) * n * o[u] + 3 * (1 - n) * n * n * b[u] + n * n * n * e[u]
      );
      return new f(r, "lab");
    };
  } else if (a.length >= 5) {
    let e, n, r;
    e = a.map((u) => u.lab()), r = a.length - 1, n = s(r), l = function(u) {
      const m = 1 - u, p = [0, 1, 2].map(
        (w) => e.reduce(
          (c, g, i) => c + n[i] * m ** (r - i) * u ** i * g[w],
          0
        )
      );
      return new f(p, "lab");
    };
  } else
    throw new RangeError("No point in running bezier with only one color.");
  return l;
}, C = (a) => {
  const l = z(a);
  return l.scale = () => h(l), l;
};
export {
  C as default
};
//# sourceMappingURL=bezier.js.map
