import { a as tickStep, c as ascending, i as tickIncrement, n as precisionPrefix_default, o as ticks, r as precisionFixed_default, s as bisector, t as precisionRound_default } from "./precisionRound-CnHPY_5v.js";
import { i as formatSpecifier, n as formatPrefix, t as format } from "./defaultLocale-BpsHxBd7.js";
import { n as initRange } from "./init-uv0kkh4g.js";
import { d as value_default, p as number_default, u as round_default } from "./timer-YZl28NYN.js";
function number$1(i) {
  return i === null ? NaN : +i;
}
function* numbers(i, S) {
  if (S === void 0) for (let S2 of i) S2 != null && (S2 = +S2) >= S2 && (yield S2);
  else {
    let C = -1;
    for (let w of i) (w = S(w, ++C, i)) != null && (w = +w) >= w && (yield w);
  }
}
var ascendingBisect = bisector(ascending);
const bisectRight = ascendingBisect.right, bisectLeft = ascendingBisect.left;
bisector(number$1).center;
var bisect_default = bisectRight;
function constants(i) {
  return function() {
    return i;
  };
}
function number(i) {
  return +i;
}
var unit = [0, 1];
function identity(i) {
  return i;
}
function normalize(i, S) {
  return (S -= i = +i) ? function(C) {
    return (C - i) / S;
  } : constants(isNaN(S) ? NaN : 0.5);
}
function clamper(i, S) {
  var C;
  return i > S && (C = i, i = S, S = C), function(C2) {
    return Math.max(i, Math.min(S, C2));
  };
}
function bimap(i, S, C) {
  var w = i[0], T = i[1], E = S[0], D = S[1];
  return T < w ? (w = normalize(T, w), E = C(D, E)) : (w = normalize(w, T), E = C(E, D)), function(i2) {
    return E(w(i2));
  };
}
function polymap(i, S, C) {
  var w = Math.min(i.length, S.length) - 1, T = Array(w), E = Array(w), D = -1;
  for (i[w] < i[0] && (i = i.slice().reverse(), S = S.slice().reverse()); ++D < w; ) T[D] = normalize(i[D], i[D + 1]), E[D] = C(S[D], S[D + 1]);
  return function(S2) {
    var C2 = bisect_default(i, S2, 1, w) - 1;
    return E[C2](T[C2](S2));
  };
}
function copy(i, S) {
  return S.domain(i.domain()).range(i.range()).interpolate(i.interpolate()).clamp(i.clamp()).unknown(i.unknown());
}
function transformer() {
  var i = unit, S = unit, C = value_default, w, T, E, D = identity, O, k, A;
  function j() {
    var C2 = Math.min(i.length, S.length);
    return D !== identity && (D = clamper(i[0], i[C2 - 1])), O = C2 > 2 ? polymap : bimap, k = A = null, M;
  }
  function M(T2) {
    return T2 == null || isNaN(T2 = +T2) ? E : (k || (k = O(i.map(w), S, C)))(w(D(T2)));
  }
  return M.invert = function(C2) {
    return D(T((A || (A = O(S, i.map(w), number_default)))(C2)));
  }, M.domain = function(S2) {
    return arguments.length ? (i = Array.from(S2, number), j()) : i.slice();
  }, M.range = function(i2) {
    return arguments.length ? (S = Array.from(i2), j()) : S.slice();
  }, M.rangeRound = function(i2) {
    return S = Array.from(i2), C = round_default, j();
  }, M.clamp = function(i2) {
    return arguments.length ? (D = i2 ? true : identity, j()) : D !== identity;
  }, M.interpolate = function(i2) {
    return arguments.length ? (C = i2, j()) : C;
  }, M.unknown = function(i2) {
    return arguments.length ? (E = i2, M) : E;
  }, function(i2, S2) {
    return w = i2, T = S2, j();
  };
}
function continuous() {
  return transformer()(identity, identity);
}
function tickFormat(S, C, T, D) {
  var M = tickStep(S, C, T), N;
  switch (D = formatSpecifier(D ?? ",f"), D.type) {
    case "s":
      var P = Math.max(Math.abs(S), Math.abs(C));
      return D.precision == null && !isNaN(N = precisionPrefix_default(M, P)) && (D.precision = N), formatPrefix(D, P);
    case "":
    case "e":
    case "g":
    case "p":
    case "r":
      D.precision == null && !isNaN(N = precisionRound_default(M, Math.max(Math.abs(S), Math.abs(C)))) && (D.precision = N - (D.type === "e"));
      break;
    case "f":
    case "%":
      D.precision == null && !isNaN(N = precisionFixed_default(M)) && (D.precision = N - (D.type === "%") * 2);
      break;
  }
  return format(D);
}
function linearish(i) {
  var S = i.domain;
  return i.ticks = function(i2) {
    var C = S();
    return ticks(C[0], C[C.length - 1], i2 ?? 10);
  }, i.tickFormat = function(i2, C) {
    var w = S();
    return tickFormat(w[0], w[w.length - 1], i2 ?? 10, C);
  }, i.nice = function(w) {
    w ?? (w = 10);
    var T = S(), E = 0, D = T.length - 1, O = T[E], k = T[D], A, j, M = 10;
    for (k < O && (j = O, O = k, k = j, j = E, E = D, D = j); M-- > 0; ) {
      if (j = tickIncrement(O, k, w), j === A) return T[E] = O, T[D] = k, S(T);
      if (j > 0) O = Math.floor(O / j) * j, k = Math.ceil(k / j) * j;
      else if (j < 0) O = Math.ceil(O * j) / j, k = Math.floor(k * j) / j;
      else break;
      A = j;
    }
    return i;
  }, i;
}
function linear() {
  var i = continuous();
  return i.copy = function() {
    return copy(i, linear());
  }, initRange.apply(i, arguments), linearish(i);
}
export {
  copy as a,
  number as c,
  bisect_default as d,
  number$1 as f,
  continuous as i,
  bisectLeft as l,
  linearish as n,
  identity as o,
  numbers as p,
  tickFormat as r,
  transformer as s,
  linear as t,
  bisectRight as u
};
