import g from "./dice.js";
import k from "./slice.js";
var D = (1 + Math.sqrt(5)) / 2;
function S(w, d, i, a, l, f) {
  for (var p = [], t = d.children, v, u, q = 0, r = 0, M = t.length, m, c, o = d.value, e, s, h, V, R, b, n; q < M; ) {
    m = l - i, c = f - a;
    do
      e = t[r++].value;
    while (!e && r < M);
    for (s = h = e, b = Math.max(c / m, m / c) / (o * w), n = e * e * b, R = Math.max(h / n, n / s); r < M; ++r) {
      if (e += u = t[r].value, u < s && (s = u), u > h && (h = u), n = e * e * b, V = Math.max(h / n, n / s), V > R) {
        e -= u;
        break;
      }
      R = V;
    }
    p.push(v = { value: e, dice: m < c, children: t.slice(q, r) }), v.dice ? g(v, i, a, l, o ? a += c * e / o : f) : k(v, i, a, o ? i += m * e / o : l, f), o -= e, q = r;
  }
  return p;
}
const A = (function w(d) {
  function i(a, l, f, p, t) {
    S(d, a, l, f, p, t);
  }
  return i.ratio = function(a) {
    return w((a = +a) > 1 ? a : 1);
  }, i;
})(D);
export {
  A as default,
  D as phi,
  S as squarifyRatio
};
