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