"use client";
import w from "./constant.js";
import y from "./number.js";
import N from "../../d3-interpolate/src/number.js";
import A from "../../d3-interpolate/src/value.js";
import { bisectRight as k } from "../../d3-array/src/bisect.js";
import M from "../../d3-interpolate/src/round.js";
var h = [0, 1];
function p(n) {
  return n;
}
function g(n, r) {
  return (r -= n = +n) ? function(i) {
    return (i - n) / r;
  } : w(isNaN(r) ? NaN : 0.5);
}
function d(n, r) {
  var i;
  return n > r && (i = n, n = r, r = i), function(e) {
    return Math.max(n, Math.min(r, e));
  };
}
function R(n, r, i) {
  var e = n[0], a = n[1], o = r[0], u = r[1];
  return a < e ? (e = g(a, e), o = i(u, o)) : (e = g(e, a), o = i(o, u)), function(l) {
    return o(e(l));
  };
}
function j(n, r, i) {
  var e = Math.min(n.length, r.length) - 1, a = new Array(e), o = new Array(e), u = -1;
  for (n[e] < n[0] && (n = n.slice().reverse(), r = r.slice().reverse()); ++u < e; )
    a[u] = g(n[u], n[u + 1]), o[u] = i(r[u], r[u + 1]);
  return function(l) {
    var c = k(n, l, 1, e) - 1;
    return o[c](a[c](l));
  };
}
function F(n, r) {
  return r.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown());
}
function z() {
  var n = h, r = h, i = A, e, a, o, u = p, l, c, s;
  function m() {
    var t = Math.min(n.length, r.length);
    return u !== p && (u = d(n[0], n[t - 1])), l = t > 2 ? j : R, c = s = null, f;
  }
  function f(t) {
    return t == null || isNaN(t = +t) ? o : (c || (c = l(n.map(e), r, i)))(e(u(t)));
  }
  return f.invert = function(t) {
    return u(a((s || (s = l(r, n.map(e), N)))(t)));
  }, f.domain = function(t) {
    return arguments.length ? (n = Array.from(t, y), m()) : n.slice();
  }, f.range = function(t) {
    return arguments.length ? (r = Array.from(t), m()) : r.slice();
  }, f.rangeRound = function(t) {
    return r = Array.from(t), i = M, m();
  }, f.clamp = function(t) {
    return arguments.length ? (u = t ? !0 : p, m()) : u !== p;
  }, f.interpolate = function(t) {
    return arguments.length ? (i = t, m()) : i;
  }, f.unknown = function(t) {
    return arguments.length ? (o = t, f) : o;
  }, function(t, v) {
    return e = t, a = v, m();
  };
}
function G() {
  return z()(p, p);
}
export {
  F as copy,
  G as default,
  p as identity,
  z as transformer
};
