import B from "./identity.js";
var z = 1, H = 2, _ = 3, w = 4, P = 1e-6;
function N(n) {
  return "translate(" + n + ",0)";
}
function R(n) {
  return "translate(0," + n + ")";
}
function T(n) {
  return (r) => +n(r);
}
function X(n, r) {
  return r = Math.max(0, n.bandwidth() - r * 2) / 2, n.round() && (r = Math.round(r)), (l) => +n(l) + r;
}
function Y() {
  return !this.__axis;
}
function E(n, r) {
  var l = [], f = null, p = null, c = 6, a = 6, F = 3, e = typeof window < "u" && window.devicePixelRatio > 1 ? 0 : 0.5, o = n === z || n === w ? -1 : 1, h = n === w || n === H ? "x" : "y", V = n === z || n === _ ? N : R;
  function i(t) {
    var I = f ?? (r.ticks ? r.ticks.apply(r, l) : r.domain()), O = p ?? (r.tickFormat ? r.tickFormat.apply(r, l) : B), C = Math.max(c, 0) + F, b = r.range(), y = +b[0] + e, x = +b[b.length - 1] + e, A = (r.bandwidth ? X : T)(r.copy(), e), g = t.selection ? t.selection() : t, m = g.selectAll(".domain").data([null]), u = g.selectAll(".tick").data(I, r).order(), S = u.exit(), v = u.enter().append("g").attr("class", "tick"), d = u.select("line"), k = u.select("text");
    m = m.merge(m.enter().insert("path", ".tick").attr("class", "domain").attr("stroke", "currentColor")), u = u.merge(v), d = d.merge(v.append("line").attr("stroke", "currentColor").attr(h + "2", o * c)), k = k.merge(v.append("text").attr("fill", "currentColor").attr(h, o * C).attr("dy", n === z ? "0em" : n === _ ? "0.71em" : "0.32em")), t !== g && (m = m.transition(t), u = u.transition(t), d = d.transition(t), k = k.transition(t), S = S.transition(t).attr("opacity", P).attr("transform", function(s) {
      return isFinite(s = A(s)) ? V(s + e) : this.getAttribute("transform");
    }), v.attr("opacity", P).attr("transform", function(s) {
      var M = this.parentNode.__axis;
      return V((M && isFinite(M = M(s)) ? M : A(s)) + e);
    })), S.remove(), m.attr("d", n === w || n === H ? a ? "M" + o * a + "," + y + "H" + e + "V" + x + "H" + o * a : "M" + e + "," + y + "V" + x : a ? "M" + y + "," + o * a + "V" + e + "H" + x + "V" + o * a : "M" + y + "," + e + "H" + x), u.attr("opacity", 1).attr("transform", function(s) {
      return V(A(s) + e);
    }), d.attr(h + "2", o * c), k.attr(h, o * C).text(O), g.filter(Y).attr("fill", "none").attr("font-size", 10).attr("font-family", "sans-serif").attr("text-anchor", n === H ? "start" : n === w ? "end" : "middle"), g.each(function() {
      this.__axis = A;
    });
  }
  return i.scale = function(t) {
    return arguments.length ? (r = t, i) : r;
  }, i.ticks = function() {
    return l = Array.from(arguments), i;
  }, i.tickArguments = function(t) {
    return arguments.length ? (l = t == null ? [] : Array.from(t), i) : l.slice();
  }, i.tickValues = function(t) {
    return arguments.length ? (f = t == null ? null : Array.from(t), i) : f && f.slice();
  }, i.tickFormat = function(t) {
    return arguments.length ? (p = t, i) : p;
  }, i.tickSize = function(t) {
    return arguments.length ? (c = a = +t, i) : c;
  }, i.tickSizeInner = function(t) {
    return arguments.length ? (c = +t, i) : c;
  }, i.tickSizeOuter = function(t) {
    return arguments.length ? (a = +t, i) : a;
  }, i.tickPadding = function(t) {
    return arguments.length ? (F = +t, i) : F;
  }, i.offset = function(t) {
    return arguments.length ? (e = +t, i) : e;
  }, i;
}
function q(n) {
  return E(z, n);
}
function D(n) {
  return E(_, n);
}
export {
  D as axisBottom,
  q as axisTop
};
