import{I as k}from"./internmap.js";import{r as R,b as O,t as F,a as S,c as P}from"./d3-array.js";import{i as j,a as z,b as $}from"./d3-interpolate.js";import{f as q,p as B,a as C,b as D,c as E,d as G}from"./d3-format.js";function v(n,t){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(t).domain(n);break}return this}const w=Symbol("implicit");function N(){var n=new k,t=[],o=[],r=w;function e(i){let a=n.get(i);if(a===void 0){if(r!==w)return r;n.set(i,a=t.push(i)-1)}return o[a%o.length]}return e.domain=function(i){if(!arguments.length)return t.slice();t=[],n=new k;for(const a of i)n.has(a)||n.set(a,t.push(a)-1);return e},e.range=function(i){return arguments.length?(o=Array.from(i),e):o.slice()},e.unknown=function(i){return arguments.length?(r=i,e):r},e.copy=function(){return N(t,o).unknown(r)},v.apply(e,arguments),e}function I(){var n=N().unknown(void 0),t=n.domain,o=n.range,r=0,e=1,i,a,l=!1,s=0,c=0,g=.5;delete n.unknown;function f(){var u=t().length,h=e<r,m=h?e:r,y=h?r:e;i=(y-m)/Math.max(1,u-s+c*2),l&&(i=Math.floor(i)),m+=(y-m-i*(u-s))*g,a=i*(1-s),l&&(m=Math.round(m),a=Math.round(a));var M=R(u).map(function(A){return m+i*A});return o(h?M.reverse():M)}return n.domain=function(u){return arguments.length?(t(u),f()):t()},n.range=function(u){return arguments.length?([r,e]=u,r=+r,e=+e,f()):[r,e]},n.rangeRound=function(u){return[r,e]=u,r=+r,e=+e,l=!0,f()},n.bandwidth=function(){return a},n.step=function(){return i},n.round=function(u){return arguments.length?(l=!!u,f()):l},n.padding=function(u){return arguments.length?(s=Math.min(1,c=+u),f()):s},n.paddingInner=function(u){return arguments.length?(s=Math.min(1,u),f()):s},n.paddingOuter=function(u){return arguments.length?(c=+u,f()):c},n.align=function(u){return arguments.length?(g=Math.max(0,Math.min(1,u)),f()):g},n.copy=function(){return I(t(),[r,e]).round(l).paddingInner(s).paddingOuter(c).align(g)},v.apply(f(),arguments)}function x(n){var t=n.copy;return n.padding=n.paddingOuter,delete n.paddingInner,delete n.paddingOuter,n.copy=function(){return x(t())},n}function tn(){return x(I.apply(null,arguments).paddingInner(1))}function H(n){return function(){return n}}function J(n){return+n}var b=[0,1];function p(n){return n}function d(n,t){return(t-=n=+n)?function(o){return(o-n)/t}:H(isNaN(t)?NaN:.5)}function K(n,t){var o;return n>t&&(o=n,n=t,t=o),function(r){return Math.max(n,Math.min(t,r))}}function L(n,t,o){var r=n[0],e=n[1],i=t[0],a=t[1];return e<r?(r=d(e,r),i=o(a,i)):(r=d(r,e),i=o(i,a)),function(l){return i(r(l))}}function Q(n,t,o){var r=Math.min(n.length,t.length)-1,e=new Array(r),i=new Array(r),a=-1;for(n[r]<n[0]&&(n=n.slice().reverse(),t=t.slice().reverse());++a<r;)e[a]=d(n[a],n[a+1]),i[a]=o(t[a],t[a+1]);return function(l){var s=O(n,l,1,r)-1;return i[s](e[s](l))}}function T(n,t){return t.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function U(){var n=b,t=b,o=z,r,e,i,a=p,l,s,c;function g(){var u=Math.min(n.length,t.length);return a!==p&&(a=K(n[0],n[u-1])),l=u>2?Q:L,s=c=null,f}function f(u){return u==null||isNaN(u=+u)?i:(s||(s=l(n.map(r),t,o)))(r(a(u)))}return f.invert=function(u){return a(e((c||(c=l(t,n.map(r),j)))(u)))},f.domain=function(u){return arguments.length?(n=Array.from(u,J),g()):n.slice()},f.range=function(u){return arguments.length?(t=Array.from(u),g()):t.slice()},f.rangeRound=function(u){return t=Array.from(u),o=$,g()},f.clamp=function(u){return arguments.length?(a=u?!0:p,g()):a!==p},f.interpolate=function(u){return arguments.length?(o=u,g()):o},f.unknown=function(u){return arguments.length?(i=u,f):i},function(u,h){return r=u,e=h,g()}}function V(){return U()(p,p)}function W(n,t,o,r){var e=F(n,t,o),i;switch(r=q(r??",f"),r.type){case"s":{var a=Math.max(Math.abs(n),Math.abs(t));return r.precision==null&&!isNaN(i=D(e,a))&&(r.precision=i),E(r,a)}case"":case"e":case"g":case"p":case"r":{r.precision==null&&!isNaN(i=C(e,Math.max(Math.abs(n),Math.abs(t))))&&(r.precision=i-(r.type==="e"));break}case"f":case"%":{r.precision==null&&!isNaN(i=B(e))&&(r.precision=i-(r.type==="%")*2);break}}return G(r)}function X(n){var t=n.domain;return n.ticks=function(o){var r=t();return S(r[0],r[r.length-1],o??10)},n.tickFormat=function(o,r){var e=t();return W(e[0],e[e.length-1],o??10,r)},n.nice=function(o){o==null&&(o=10);var r=t(),e=0,i=r.length-1,a=r[e],l=r[i],s,c,g=10;for(l<a&&(c=a,a=l,l=c,c=e,e=i,i=c);g-- >0;){if(c=P(a,l,o),c===s)return r[e]=a,r[i]=l,t(r);if(c>0)a=Math.floor(a/c)*c,l=Math.ceil(l/c)*c;else if(c<0)a=Math.ceil(a*c)/c,l=Math.floor(l*c)/c;else break;s=c}return n},n}function Y(){var n=V();return n.copy=function(){return T(n,Y())},v.apply(n,arguments),X(n)}export{Y as l,tn as p};
