diff --git a/src/array.js b/src/array.js index c015cc9f..df69e807 100644 --- a/src/array.js +++ b/src/array.js @@ -1,4 +1,8 @@ -export var slice = Array.prototype.slice; +export default function(x) { + return typeof x === "object" && "length" in x + ? x // Array, TypedArray, NodeList, array-like + : Array.from(x); // Map, Set, iterable, string, or anything else +} export function shuffle(array) { var m = array.length, diff --git a/src/pack/enclose.js b/src/pack/enclose.js index c8dbd2a6..8b1d4d88 100644 --- a/src/pack/enclose.js +++ b/src/pack/enclose.js @@ -1,7 +1,7 @@ -import {shuffle, slice} from "../array.js"; +import {shuffle} from "../array.js"; export default function(circles) { - var i = 0, n = (circles = shuffle(slice.call(circles))).length, B = [], p, e; + var i = 0, n = (circles = shuffle(Array.from(circles))).length, B = [], p, e; while (i < n) { p = circles[i]; diff --git a/src/pack/siblings.js b/src/pack/siblings.js index 4488126d..05047cfd 100644 --- a/src/pack/siblings.js +++ b/src/pack/siblings.js @@ -1,3 +1,4 @@ +import array from "../array.js"; import enclose from "./enclose.js"; function place(b, a, c) { @@ -45,7 +46,7 @@ function Node(circle) { } export function packEnclose(circles) { - if (!(n = circles.length)) return 0; + if (!(n = (circles = array(circles)).length)) return 0; var a, b, c, n, aa, ca, i, j, k, sj, sk;