@guardian/interactive-component-library 0.2.0-rc2 → 0.2.0-rc4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/molecules/canvas-map/lib/Map.js +2 -2
- package/dist/components/molecules/canvas-map/lib/projection/index.js +1 -1
- package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.js +1 -1
- package/dist/components/molecules/canvas-map/lib/sources/VectorSource.js +2 -2
- package/dist/components/molecules/modal/index.js +2 -2
- package/dist/components/molecules/result-summary/index.js +3 -1
- package/dist/components/molecules/svg-map/index.js +2 -1
- package/dist/components/molecules/svg-map/layers/Polygon.js +1 -1
- package/dist/components/particles/relative-time-sentence/index.js +2 -2
- package/package.json +14 -2
- package/dist/_virtual/_commonjsHelpers.js +0 -8
- package/dist/_virtual/dayjs.min.js +0 -4
- package/dist/_virtual/relativeTime.js +0 -4
- package/dist/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/color.js +0 -338
- package/dist/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/define.js +0 -13
- package/dist/node_modules/.pnpm/d3-composite-projections@1.4.0/node_modules/d3-composite-projections/src/albersUk.js +0 -108
- package/dist/node_modules/.pnpm/d3-composite-projections@1.4.0/node_modules/d3-composite-projections/src/bounds.js +0 -24
- package/dist/node_modules/.pnpm/d3-composite-projections@1.4.0/node_modules/d3-composite-projections/src/fit.js +0 -18
- package/dist/node_modules/.pnpm/d3-composite-projections@1.4.0/node_modules/d3-composite-projections/src/math.js +0 -4
- package/dist/node_modules/.pnpm/d3-dispatch@3.0.1/node_modules/d3-dispatch/src/dispatch.js +0 -70
- package/dist/node_modules/.pnpm/d3-ease@3.0.1/node_modules/d3-ease/src/cubic.js +0 -6
- package/dist/node_modules/.pnpm/d3-interpolate@3.0.1/node_modules/d3-interpolate/src/color.js +0 -24
- package/dist/node_modules/.pnpm/d3-interpolate@3.0.1/node_modules/d3-interpolate/src/constant.js +0 -4
- package/dist/node_modules/.pnpm/d3-interpolate@3.0.1/node_modules/d3-interpolate/src/number.js +0 -8
- package/dist/node_modules/.pnpm/d3-interpolate@3.0.1/node_modules/d3-interpolate/src/rgb.js +0 -20
- package/dist/node_modules/.pnpm/d3-interpolate@3.0.1/node_modules/d3-interpolate/src/string.js +0 -43
- package/dist/node_modules/.pnpm/d3-interpolate@3.0.1/node_modules/d3-interpolate/src/transform/decompose.js +0 -28
- package/dist/node_modules/.pnpm/d3-interpolate@3.0.1/node_modules/d3-interpolate/src/transform/index.js +0 -59
- package/dist/node_modules/.pnpm/d3-interpolate@3.0.1/node_modules/d3-interpolate/src/transform/parse.js +0 -18
- package/dist/node_modules/.pnpm/d3-path@2.0.0/node_modules/d3-path/src/path.js +0 -73
- package/dist/node_modules/.pnpm/d3-timer@3.0.1/node_modules/d3-timer/src/timeout.js +0 -13
- package/dist/node_modules/.pnpm/d3-timer@3.0.1/node_modules/d3-timer/src/timer.js +0 -96
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/interrupt.js +0 -21
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/selection/index.js +0 -5
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/selection/interrupt.js +0 -9
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/selection/transition.js +0 -39
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/attr.js +0 -55
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/attrTween.js +0 -42
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/delay.js +0 -18
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/duration.js +0 -18
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/ease.js +0 -14
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/easeVarying.js +0 -15
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/end.js +0 -23
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/filter.js +0 -16
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/index.js +0 -68
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/interpolate.js +0 -11
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/merge.js +0 -18
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/on.js +0 -23
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/remove.js +0 -13
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/schedule.js +0 -125
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/select.js +0 -20
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/selectAll.js +0 -24
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/selection.js +0 -8
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/style.js +0 -47
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/styleTween.js +0 -25
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/text.js +0 -18
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/textTween.js +0 -25
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/transition.js +0 -22
- package/dist/node_modules/.pnpm/d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/transition/tween.js +0 -64
- package/dist/node_modules/.pnpm/dayjs@1.11.12/node_modules/dayjs/dayjs.min.js +0 -282
- package/dist/node_modules/.pnpm/dayjs@1.11.12/node_modules/dayjs/plugin/relativeTime.js +0 -48
- package/dist/node_modules/.pnpm/flatbush@4.4.0/node_modules/flatbush/index.js +0 -339
- package/dist/node_modules/.pnpm/flatqueue@2.0.3/node_modules/flatqueue/index.js +0 -67
- package/dist/node_modules/.pnpm/preact-merge-refs@1.0.2_preact@10.21.0/node_modules/preact-merge-refs/lib/preact-merge-refs.modern.js +0 -10
- package/dist/node_modules/.pnpm/preact-transitioning@1.4.1_preact@10.21.0/node_modules/preact-transitioning/lib/preact-transitioning.modern.js +0 -63
- package/dist/node_modules/.pnpm/quickselect@2.0.0/node_modules/quickselect/index.js +0 -47
- package/dist/node_modules/.pnpm/rbush-knn@4.0.0/node_modules/rbush-knn/index.js +0 -42
- package/dist/node_modules/.pnpm/rbush@4.0.0/node_modules/rbush/index.js +0 -378
- package/dist/node_modules/.pnpm/tinyqueue@2.0.3/node_modules/tinyqueue/index.js +0 -65
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
class FlatQueue {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.ids = [];
|
|
4
|
-
this.values = [];
|
|
5
|
-
this.length = 0;
|
|
6
|
-
}
|
|
7
|
-
clear() {
|
|
8
|
-
this.length = 0;
|
|
9
|
-
}
|
|
10
|
-
push(id, value) {
|
|
11
|
-
let pos = this.length++;
|
|
12
|
-
while (pos > 0) {
|
|
13
|
-
const parent = pos - 1 >> 1;
|
|
14
|
-
const parentValue = this.values[parent];
|
|
15
|
-
if (value >= parentValue) break;
|
|
16
|
-
this.ids[pos] = this.ids[parent];
|
|
17
|
-
this.values[pos] = parentValue;
|
|
18
|
-
pos = parent;
|
|
19
|
-
}
|
|
20
|
-
this.ids[pos] = id;
|
|
21
|
-
this.values[pos] = value;
|
|
22
|
-
}
|
|
23
|
-
pop() {
|
|
24
|
-
if (this.length === 0) return void 0;
|
|
25
|
-
const top = this.ids[0];
|
|
26
|
-
this.length--;
|
|
27
|
-
if (this.length > 0) {
|
|
28
|
-
const id = this.ids[0] = this.ids[this.length];
|
|
29
|
-
const value = this.values[0] = this.values[this.length];
|
|
30
|
-
const halfLength = this.length >> 1;
|
|
31
|
-
let pos = 0;
|
|
32
|
-
while (pos < halfLength) {
|
|
33
|
-
let left = (pos << 1) + 1;
|
|
34
|
-
const right = left + 1;
|
|
35
|
-
let bestIndex = this.ids[left];
|
|
36
|
-
let bestValue = this.values[left];
|
|
37
|
-
const rightValue = this.values[right];
|
|
38
|
-
if (right < this.length && rightValue < bestValue) {
|
|
39
|
-
left = right;
|
|
40
|
-
bestIndex = this.ids[right];
|
|
41
|
-
bestValue = rightValue;
|
|
42
|
-
}
|
|
43
|
-
if (bestValue >= value) break;
|
|
44
|
-
this.ids[pos] = bestIndex;
|
|
45
|
-
this.values[pos] = bestValue;
|
|
46
|
-
pos = left;
|
|
47
|
-
}
|
|
48
|
-
this.ids[pos] = id;
|
|
49
|
-
this.values[pos] = value;
|
|
50
|
-
}
|
|
51
|
-
return top;
|
|
52
|
-
}
|
|
53
|
-
peek() {
|
|
54
|
-
if (this.length === 0) return void 0;
|
|
55
|
-
return this.ids[0];
|
|
56
|
-
}
|
|
57
|
-
peekValue() {
|
|
58
|
-
if (this.length === 0) return void 0;
|
|
59
|
-
return this.values[0];
|
|
60
|
-
}
|
|
61
|
-
shrink() {
|
|
62
|
-
this.ids.length = this.values.length = this.length;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export {
|
|
66
|
-
FlatQueue as default
|
|
67
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { createElement, cloneElement } from "preact";
|
|
2
|
-
import { mergeRefs as n } from "../../../../preact-merge-refs@1.0.2_preact@10.21.0/node_modules/preact-merge-refs/lib/preact-merge-refs.modern.js";
|
|
3
|
-
import { useMemo, useRef, useState, useEffect, useLayoutEffect } from "preact/hooks";
|
|
4
|
-
var T, c;
|
|
5
|
-
!function(e) {
|
|
6
|
-
e.APPEAR = "appear", e.APPEAR_ACTIVE = "appearActive", e.APPEAR_DONE = "appearDone", e.ENTER = "enter", e.ENTER_ACTIVE = "enterActive", e.ENTER_DONE = "enterDone", e.EXIT = "exit", e.EXIT_ACTIVE = "exitActive", e.EXIT_DONE = "exitDone";
|
|
7
|
-
}(T || (T = {})), function(e) {
|
|
8
|
-
e.ENTER = "onEnter", e.ENTERING = "onEntering", e.ENTERED = "onEntered", e.EXIT = "onExit", e.EXITING = "onExiting", e.EXITED = "onExited";
|
|
9
|
-
}(c || (c = {}));
|
|
10
|
-
const s = { [T.APPEAR]: [c.ENTER, T.APPEAR_ACTIVE], [T.APPEAR_ACTIVE]: [c.ENTERING, T.APPEAR_DONE, true], [T.APPEAR_DONE]: [c.ENTERED], [T.ENTER]: [c.ENTER, T.ENTER_ACTIVE], [T.ENTER_ACTIVE]: [c.ENTERING, T.ENTER_DONE, true], [T.ENTER_DONE]: [c.ENTERED], [T.EXIT]: [c.EXIT, T.EXIT_ACTIVE], [T.EXIT_ACTIVE]: [c.EXITING, T.EXIT_DONE, true], [T.EXIT_DONE]: [c.EXITED] };
|
|
11
|
-
var u = (r) => {
|
|
12
|
-
const { children: c2, in: u2 = false, appear: A = false, enter: N2 = true, exit: l = true, duration: I = 500, alwaysMounted: p2 = false, addEndListener: R2 } = r, P2 = useRef(), _2 = useRef();
|
|
13
|
-
let d2 = false;
|
|
14
|
-
const [f, D] = useState(() => (d2 = true, u2 ? A ? T.APPEAR : T.APPEAR_DONE : T.EXIT_DONE));
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
var e;
|
|
17
|
-
const { setTimeout: E, clearTimeout: t } = window, [n2, o, i] = s[f];
|
|
18
|
-
return null == (e = r[n2]) || e.call(r, P2.current), o && (i ? R2 ? R2(P2.current, () => D(o)) : _2.current = E(D, I, o) : D(o)), () => {
|
|
19
|
-
t(_2.current);
|
|
20
|
-
};
|
|
21
|
-
}, [f, I]), useLayoutEffect(() => {
|
|
22
|
-
d2 || D(u2 ? N2 ? T.ENTER : T.ENTER_DONE : l ? T.EXIT : T.EXIT_DONE);
|
|
23
|
-
}, [u2]);
|
|
24
|
-
const X = useMemo(() => {
|
|
25
|
-
const e = {};
|
|
26
|
-
return Object.values(T).forEach((r2) => {
|
|
27
|
-
e[r2] = f === r2;
|
|
28
|
-
}), e;
|
|
29
|
-
}, [f]);
|
|
30
|
-
if (!p2 && f === T.EXIT_DONE) return null;
|
|
31
|
-
const O = c2(X, f);
|
|
32
|
-
return cloneElement(O, { ref: n([P2, O.ref]) });
|
|
33
|
-
};
|
|
34
|
-
function N(e, r) {
|
|
35
|
-
if (null == e) return {};
|
|
36
|
-
var E, t, n2 = {}, o = Object.keys(e);
|
|
37
|
-
for (t = 0; t < o.length; t++) r.indexOf(E = o[t]) >= 0 || (n2[E] = e[E]);
|
|
38
|
-
return n2;
|
|
39
|
-
}
|
|
40
|
-
const p = ["children", "classNames"], R = { [T.APPEAR]: "-appear", [T.APPEAR_ACTIVE]: "-appear-active", [T.APPEAR_DONE]: "-appear-done", [T.ENTER]: "-enter", [T.ENTER_ACTIVE]: "-enter-active", [T.ENTER_DONE]: "-enter-done", [T.EXIT]: "-exit", [T.EXIT_ACTIVE]: "-exit-active", [T.EXIT_DONE]: "-exit-done" }, P = (...e) => e.filter((e2) => !!e2).join(" "), _ = (e, r) => "string" == typeof r ? `${r}${R[e]}` : r[e];
|
|
41
|
-
var d = (E) => {
|
|
42
|
-
const { children: t, classNames: n2 } = E, o = N(E, p);
|
|
43
|
-
return createElement(u, o, (r, E2) => {
|
|
44
|
-
const { className: o2 } = t.props, i = useMemo(() => P(o2, ((e, r2) => {
|
|
45
|
-
const E3 = _(e, r2);
|
|
46
|
-
switch (e) {
|
|
47
|
-
case T.APPEAR_ACTIVE:
|
|
48
|
-
return P(_(T.APPEAR, r2), E3);
|
|
49
|
-
case T.ENTER_ACTIVE:
|
|
50
|
-
return P(_(T.ENTER, r2), E3);
|
|
51
|
-
case T.EXIT_ACTIVE:
|
|
52
|
-
return P(_(T.EXIT, r2), E3);
|
|
53
|
-
default:
|
|
54
|
-
return E3;
|
|
55
|
-
}
|
|
56
|
-
})(E2, n2)), [o2, n2, E2]);
|
|
57
|
-
return cloneElement(t, { className: i });
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
export {
|
|
61
|
-
d as CSSTransition,
|
|
62
|
-
u as Transition
|
|
63
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
function quickselect(arr, k, left, right, compare) {
|
|
2
|
-
quickselectStep(arr, k, left || 0, right || arr.length - 1, compare || defaultCompare);
|
|
3
|
-
}
|
|
4
|
-
function quickselectStep(arr, k, left, right, compare) {
|
|
5
|
-
while (right > left) {
|
|
6
|
-
if (right - left > 600) {
|
|
7
|
-
var n = right - left + 1;
|
|
8
|
-
var m = k - left + 1;
|
|
9
|
-
var z = Math.log(n);
|
|
10
|
-
var s = 0.5 * Math.exp(2 * z / 3);
|
|
11
|
-
var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
|
|
12
|
-
var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
|
|
13
|
-
var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
|
|
14
|
-
quickselectStep(arr, k, newLeft, newRight, compare);
|
|
15
|
-
}
|
|
16
|
-
var t = arr[k];
|
|
17
|
-
var i = left;
|
|
18
|
-
var j = right;
|
|
19
|
-
swap(arr, left, k);
|
|
20
|
-
if (compare(arr[right], t) > 0) swap(arr, left, right);
|
|
21
|
-
while (i < j) {
|
|
22
|
-
swap(arr, i, j);
|
|
23
|
-
i++;
|
|
24
|
-
j--;
|
|
25
|
-
while (compare(arr[i], t) < 0) i++;
|
|
26
|
-
while (compare(arr[j], t) > 0) j--;
|
|
27
|
-
}
|
|
28
|
-
if (compare(arr[left], t) === 0) swap(arr, left, j);
|
|
29
|
-
else {
|
|
30
|
-
j++;
|
|
31
|
-
swap(arr, j, right);
|
|
32
|
-
}
|
|
33
|
-
if (j <= k) left = j + 1;
|
|
34
|
-
if (k <= j) right = j - 1;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function swap(arr, i, j) {
|
|
38
|
-
var tmp = arr[i];
|
|
39
|
-
arr[i] = arr[j];
|
|
40
|
-
arr[j] = tmp;
|
|
41
|
-
}
|
|
42
|
-
function defaultCompare(a, b) {
|
|
43
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
44
|
-
}
|
|
45
|
-
export {
|
|
46
|
-
quickselect as default
|
|
47
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import TinyQueue from "../../../tinyqueue@2.0.3/node_modules/tinyqueue/index.js";
|
|
2
|
-
function knn(tree, x, y, n, predicate, maxDistance) {
|
|
3
|
-
let node = tree.data;
|
|
4
|
-
const result = [];
|
|
5
|
-
const toBBox = tree.toBBox;
|
|
6
|
-
const queue = new TinyQueue(void 0, compareDist);
|
|
7
|
-
while (node) {
|
|
8
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
9
|
-
const child = node.children[i];
|
|
10
|
-
const dist = boxDist(x, y, node.leaf ? toBBox(child) : child);
|
|
11
|
-
{
|
|
12
|
-
queue.push({
|
|
13
|
-
node: child,
|
|
14
|
-
isItem: node.leaf,
|
|
15
|
-
dist
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
while (queue.length && queue.peek().isItem) {
|
|
20
|
-
const candidate = queue.pop().node;
|
|
21
|
-
if (!predicate || predicate(candidate))
|
|
22
|
-
result.push(candidate);
|
|
23
|
-
if (result.length === n) return result;
|
|
24
|
-
}
|
|
25
|
-
node = queue.pop();
|
|
26
|
-
if (node) node = node.node;
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
function compareDist(a, b) {
|
|
31
|
-
return a.dist - b.dist;
|
|
32
|
-
}
|
|
33
|
-
function boxDist(x, y, box) {
|
|
34
|
-
const dx = axisDist(x, box.minX, box.maxX), dy = axisDist(y, box.minY, box.maxY);
|
|
35
|
-
return dx * dx + dy * dy;
|
|
36
|
-
}
|
|
37
|
-
function axisDist(k, min, max) {
|
|
38
|
-
return k < min ? min - k : k <= max ? 0 : k - max;
|
|
39
|
-
}
|
|
40
|
-
export {
|
|
41
|
-
knn as default
|
|
42
|
-
};
|
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
import quickselect from "../../../quickselect@2.0.0/node_modules/quickselect/index.js";
|
|
2
|
-
class RBush {
|
|
3
|
-
constructor(maxEntries = 9) {
|
|
4
|
-
this._maxEntries = Math.max(4, maxEntries);
|
|
5
|
-
this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4));
|
|
6
|
-
this.clear();
|
|
7
|
-
}
|
|
8
|
-
all() {
|
|
9
|
-
return this._all(this.data, []);
|
|
10
|
-
}
|
|
11
|
-
search(bbox) {
|
|
12
|
-
let node = this.data;
|
|
13
|
-
const result = [];
|
|
14
|
-
if (!intersects(bbox, node)) return result;
|
|
15
|
-
const toBBox = this.toBBox;
|
|
16
|
-
const nodesToSearch = [];
|
|
17
|
-
while (node) {
|
|
18
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
19
|
-
const child = node.children[i];
|
|
20
|
-
const childBBox = node.leaf ? toBBox(child) : child;
|
|
21
|
-
if (intersects(bbox, childBBox)) {
|
|
22
|
-
if (node.leaf) result.push(child);
|
|
23
|
-
else if (contains(bbox, childBBox)) this._all(child, result);
|
|
24
|
-
else nodesToSearch.push(child);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
node = nodesToSearch.pop();
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
collides(bbox) {
|
|
32
|
-
let node = this.data;
|
|
33
|
-
if (!intersects(bbox, node)) return false;
|
|
34
|
-
const nodesToSearch = [];
|
|
35
|
-
while (node) {
|
|
36
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
37
|
-
const child = node.children[i];
|
|
38
|
-
const childBBox = node.leaf ? this.toBBox(child) : child;
|
|
39
|
-
if (intersects(bbox, childBBox)) {
|
|
40
|
-
if (node.leaf || contains(bbox, childBBox)) return true;
|
|
41
|
-
nodesToSearch.push(child);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
node = nodesToSearch.pop();
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
load(data) {
|
|
49
|
-
if (!(data && data.length)) return this;
|
|
50
|
-
if (data.length < this._minEntries) {
|
|
51
|
-
for (let i = 0; i < data.length; i++) {
|
|
52
|
-
this.insert(data[i]);
|
|
53
|
-
}
|
|
54
|
-
return this;
|
|
55
|
-
}
|
|
56
|
-
let node = this._build(data.slice(), 0, data.length - 1, 0);
|
|
57
|
-
if (!this.data.children.length) {
|
|
58
|
-
this.data = node;
|
|
59
|
-
} else if (this.data.height === node.height) {
|
|
60
|
-
this._splitRoot(this.data, node);
|
|
61
|
-
} else {
|
|
62
|
-
if (this.data.height < node.height) {
|
|
63
|
-
const tmpNode = this.data;
|
|
64
|
-
this.data = node;
|
|
65
|
-
node = tmpNode;
|
|
66
|
-
}
|
|
67
|
-
this._insert(node, this.data.height - node.height - 1, true);
|
|
68
|
-
}
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
insert(item) {
|
|
72
|
-
if (item) this._insert(item, this.data.height - 1);
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
clear() {
|
|
76
|
-
this.data = createNode([]);
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
remove(item, equalsFn) {
|
|
80
|
-
if (!item) return this;
|
|
81
|
-
let node = this.data;
|
|
82
|
-
const bbox = this.toBBox(item);
|
|
83
|
-
const path = [];
|
|
84
|
-
const indexes = [];
|
|
85
|
-
let i, parent, goingUp;
|
|
86
|
-
while (node || path.length) {
|
|
87
|
-
if (!node) {
|
|
88
|
-
node = path.pop();
|
|
89
|
-
parent = path[path.length - 1];
|
|
90
|
-
i = indexes.pop();
|
|
91
|
-
goingUp = true;
|
|
92
|
-
}
|
|
93
|
-
if (node.leaf) {
|
|
94
|
-
const index = findItem(item, node.children, equalsFn);
|
|
95
|
-
if (index !== -1) {
|
|
96
|
-
node.children.splice(index, 1);
|
|
97
|
-
path.push(node);
|
|
98
|
-
this._condense(path);
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (!goingUp && !node.leaf && contains(node, bbox)) {
|
|
103
|
-
path.push(node);
|
|
104
|
-
indexes.push(i);
|
|
105
|
-
i = 0;
|
|
106
|
-
parent = node;
|
|
107
|
-
node = node.children[0];
|
|
108
|
-
} else if (parent) {
|
|
109
|
-
i++;
|
|
110
|
-
node = parent.children[i];
|
|
111
|
-
goingUp = false;
|
|
112
|
-
} else node = null;
|
|
113
|
-
}
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
toBBox(item) {
|
|
117
|
-
return item;
|
|
118
|
-
}
|
|
119
|
-
compareMinX(a, b) {
|
|
120
|
-
return a.minX - b.minX;
|
|
121
|
-
}
|
|
122
|
-
compareMinY(a, b) {
|
|
123
|
-
return a.minY - b.minY;
|
|
124
|
-
}
|
|
125
|
-
toJSON() {
|
|
126
|
-
return this.data;
|
|
127
|
-
}
|
|
128
|
-
fromJSON(data) {
|
|
129
|
-
this.data = data;
|
|
130
|
-
return this;
|
|
131
|
-
}
|
|
132
|
-
_all(node, result) {
|
|
133
|
-
const nodesToSearch = [];
|
|
134
|
-
while (node) {
|
|
135
|
-
if (node.leaf) result.push(...node.children);
|
|
136
|
-
else nodesToSearch.push(...node.children);
|
|
137
|
-
node = nodesToSearch.pop();
|
|
138
|
-
}
|
|
139
|
-
return result;
|
|
140
|
-
}
|
|
141
|
-
_build(items, left, right, height) {
|
|
142
|
-
const N = right - left + 1;
|
|
143
|
-
let M = this._maxEntries;
|
|
144
|
-
let node;
|
|
145
|
-
if (N <= M) {
|
|
146
|
-
node = createNode(items.slice(left, right + 1));
|
|
147
|
-
calcBBox(node, this.toBBox);
|
|
148
|
-
return node;
|
|
149
|
-
}
|
|
150
|
-
if (!height) {
|
|
151
|
-
height = Math.ceil(Math.log(N) / Math.log(M));
|
|
152
|
-
M = Math.ceil(N / Math.pow(M, height - 1));
|
|
153
|
-
}
|
|
154
|
-
node = createNode([]);
|
|
155
|
-
node.leaf = false;
|
|
156
|
-
node.height = height;
|
|
157
|
-
const N2 = Math.ceil(N / M);
|
|
158
|
-
const N1 = N2 * Math.ceil(Math.sqrt(M));
|
|
159
|
-
multiSelect(items, left, right, N1, this.compareMinX);
|
|
160
|
-
for (let i = left; i <= right; i += N1) {
|
|
161
|
-
const right2 = Math.min(i + N1 - 1, right);
|
|
162
|
-
multiSelect(items, i, right2, N2, this.compareMinY);
|
|
163
|
-
for (let j = i; j <= right2; j += N2) {
|
|
164
|
-
const right3 = Math.min(j + N2 - 1, right2);
|
|
165
|
-
node.children.push(this._build(items, j, right3, height - 1));
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
calcBBox(node, this.toBBox);
|
|
169
|
-
return node;
|
|
170
|
-
}
|
|
171
|
-
_chooseSubtree(bbox, node, level, path) {
|
|
172
|
-
while (true) {
|
|
173
|
-
path.push(node);
|
|
174
|
-
if (node.leaf || path.length - 1 === level) break;
|
|
175
|
-
let minArea = Infinity;
|
|
176
|
-
let minEnlargement = Infinity;
|
|
177
|
-
let targetNode;
|
|
178
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
179
|
-
const child = node.children[i];
|
|
180
|
-
const area = bboxArea(child);
|
|
181
|
-
const enlargement = enlargedArea(bbox, child) - area;
|
|
182
|
-
if (enlargement < minEnlargement) {
|
|
183
|
-
minEnlargement = enlargement;
|
|
184
|
-
minArea = area < minArea ? area : minArea;
|
|
185
|
-
targetNode = child;
|
|
186
|
-
} else if (enlargement === minEnlargement) {
|
|
187
|
-
if (area < minArea) {
|
|
188
|
-
minArea = area;
|
|
189
|
-
targetNode = child;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
node = targetNode || node.children[0];
|
|
194
|
-
}
|
|
195
|
-
return node;
|
|
196
|
-
}
|
|
197
|
-
_insert(item, level, isNode) {
|
|
198
|
-
const bbox = isNode ? item : this.toBBox(item);
|
|
199
|
-
const insertPath = [];
|
|
200
|
-
const node = this._chooseSubtree(bbox, this.data, level, insertPath);
|
|
201
|
-
node.children.push(item);
|
|
202
|
-
extend(node, bbox);
|
|
203
|
-
while (level >= 0) {
|
|
204
|
-
if (insertPath[level].children.length > this._maxEntries) {
|
|
205
|
-
this._split(insertPath, level);
|
|
206
|
-
level--;
|
|
207
|
-
} else break;
|
|
208
|
-
}
|
|
209
|
-
this._adjustParentBBoxes(bbox, insertPath, level);
|
|
210
|
-
}
|
|
211
|
-
// split overflowed node into two
|
|
212
|
-
_split(insertPath, level) {
|
|
213
|
-
const node = insertPath[level];
|
|
214
|
-
const M = node.children.length;
|
|
215
|
-
const m = this._minEntries;
|
|
216
|
-
this._chooseSplitAxis(node, m, M);
|
|
217
|
-
const splitIndex = this._chooseSplitIndex(node, m, M);
|
|
218
|
-
const newNode = createNode(node.children.splice(splitIndex, node.children.length - splitIndex));
|
|
219
|
-
newNode.height = node.height;
|
|
220
|
-
newNode.leaf = node.leaf;
|
|
221
|
-
calcBBox(node, this.toBBox);
|
|
222
|
-
calcBBox(newNode, this.toBBox);
|
|
223
|
-
if (level) insertPath[level - 1].children.push(newNode);
|
|
224
|
-
else this._splitRoot(node, newNode);
|
|
225
|
-
}
|
|
226
|
-
_splitRoot(node, newNode) {
|
|
227
|
-
this.data = createNode([node, newNode]);
|
|
228
|
-
this.data.height = node.height + 1;
|
|
229
|
-
this.data.leaf = false;
|
|
230
|
-
calcBBox(this.data, this.toBBox);
|
|
231
|
-
}
|
|
232
|
-
_chooseSplitIndex(node, m, M) {
|
|
233
|
-
let index;
|
|
234
|
-
let minOverlap = Infinity;
|
|
235
|
-
let minArea = Infinity;
|
|
236
|
-
for (let i = m; i <= M - m; i++) {
|
|
237
|
-
const bbox1 = distBBox(node, 0, i, this.toBBox);
|
|
238
|
-
const bbox2 = distBBox(node, i, M, this.toBBox);
|
|
239
|
-
const overlap = intersectionArea(bbox1, bbox2);
|
|
240
|
-
const area = bboxArea(bbox1) + bboxArea(bbox2);
|
|
241
|
-
if (overlap < minOverlap) {
|
|
242
|
-
minOverlap = overlap;
|
|
243
|
-
index = i;
|
|
244
|
-
minArea = area < minArea ? area : minArea;
|
|
245
|
-
} else if (overlap === minOverlap) {
|
|
246
|
-
if (area < minArea) {
|
|
247
|
-
minArea = area;
|
|
248
|
-
index = i;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return index || M - m;
|
|
253
|
-
}
|
|
254
|
-
// sorts node children by the best axis for split
|
|
255
|
-
_chooseSplitAxis(node, m, M) {
|
|
256
|
-
const compareMinX = node.leaf ? this.compareMinX : compareNodeMinX;
|
|
257
|
-
const compareMinY = node.leaf ? this.compareMinY : compareNodeMinY;
|
|
258
|
-
const xMargin = this._allDistMargin(node, m, M, compareMinX);
|
|
259
|
-
const yMargin = this._allDistMargin(node, m, M, compareMinY);
|
|
260
|
-
if (xMargin < yMargin) node.children.sort(compareMinX);
|
|
261
|
-
}
|
|
262
|
-
// total margin of all possible split distributions where each node is at least m full
|
|
263
|
-
_allDistMargin(node, m, M, compare) {
|
|
264
|
-
node.children.sort(compare);
|
|
265
|
-
const toBBox = this.toBBox;
|
|
266
|
-
const leftBBox = distBBox(node, 0, m, toBBox);
|
|
267
|
-
const rightBBox = distBBox(node, M - m, M, toBBox);
|
|
268
|
-
let margin = bboxMargin(leftBBox) + bboxMargin(rightBBox);
|
|
269
|
-
for (let i = m; i < M - m; i++) {
|
|
270
|
-
const child = node.children[i];
|
|
271
|
-
extend(leftBBox, node.leaf ? toBBox(child) : child);
|
|
272
|
-
margin += bboxMargin(leftBBox);
|
|
273
|
-
}
|
|
274
|
-
for (let i = M - m - 1; i >= m; i--) {
|
|
275
|
-
const child = node.children[i];
|
|
276
|
-
extend(rightBBox, node.leaf ? toBBox(child) : child);
|
|
277
|
-
margin += bboxMargin(rightBBox);
|
|
278
|
-
}
|
|
279
|
-
return margin;
|
|
280
|
-
}
|
|
281
|
-
_adjustParentBBoxes(bbox, path, level) {
|
|
282
|
-
for (let i = level; i >= 0; i--) {
|
|
283
|
-
extend(path[i], bbox);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
_condense(path) {
|
|
287
|
-
for (let i = path.length - 1, siblings; i >= 0; i--) {
|
|
288
|
-
if (path[i].children.length === 0) {
|
|
289
|
-
if (i > 0) {
|
|
290
|
-
siblings = path[i - 1].children;
|
|
291
|
-
siblings.splice(siblings.indexOf(path[i]), 1);
|
|
292
|
-
} else this.clear();
|
|
293
|
-
} else calcBBox(path[i], this.toBBox);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
function findItem(item, items, equalsFn) {
|
|
298
|
-
if (!equalsFn) return items.indexOf(item);
|
|
299
|
-
for (let i = 0; i < items.length; i++) {
|
|
300
|
-
if (equalsFn(item, items[i])) return i;
|
|
301
|
-
}
|
|
302
|
-
return -1;
|
|
303
|
-
}
|
|
304
|
-
function calcBBox(node, toBBox) {
|
|
305
|
-
distBBox(node, 0, node.children.length, toBBox, node);
|
|
306
|
-
}
|
|
307
|
-
function distBBox(node, k, p, toBBox, destNode) {
|
|
308
|
-
if (!destNode) destNode = createNode(null);
|
|
309
|
-
destNode.minX = Infinity;
|
|
310
|
-
destNode.minY = Infinity;
|
|
311
|
-
destNode.maxX = -Infinity;
|
|
312
|
-
destNode.maxY = -Infinity;
|
|
313
|
-
for (let i = k; i < p; i++) {
|
|
314
|
-
const child = node.children[i];
|
|
315
|
-
extend(destNode, node.leaf ? toBBox(child) : child);
|
|
316
|
-
}
|
|
317
|
-
return destNode;
|
|
318
|
-
}
|
|
319
|
-
function extend(a, b) {
|
|
320
|
-
a.minX = Math.min(a.minX, b.minX);
|
|
321
|
-
a.minY = Math.min(a.minY, b.minY);
|
|
322
|
-
a.maxX = Math.max(a.maxX, b.maxX);
|
|
323
|
-
a.maxY = Math.max(a.maxY, b.maxY);
|
|
324
|
-
return a;
|
|
325
|
-
}
|
|
326
|
-
function compareNodeMinX(a, b) {
|
|
327
|
-
return a.minX - b.minX;
|
|
328
|
-
}
|
|
329
|
-
function compareNodeMinY(a, b) {
|
|
330
|
-
return a.minY - b.minY;
|
|
331
|
-
}
|
|
332
|
-
function bboxArea(a) {
|
|
333
|
-
return (a.maxX - a.minX) * (a.maxY - a.minY);
|
|
334
|
-
}
|
|
335
|
-
function bboxMargin(a) {
|
|
336
|
-
return a.maxX - a.minX + (a.maxY - a.minY);
|
|
337
|
-
}
|
|
338
|
-
function enlargedArea(a, b) {
|
|
339
|
-
return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) * (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY));
|
|
340
|
-
}
|
|
341
|
-
function intersectionArea(a, b) {
|
|
342
|
-
const minX = Math.max(a.minX, b.minX);
|
|
343
|
-
const minY = Math.max(a.minY, b.minY);
|
|
344
|
-
const maxX = Math.min(a.maxX, b.maxX);
|
|
345
|
-
const maxY = Math.min(a.maxY, b.maxY);
|
|
346
|
-
return Math.max(0, maxX - minX) * Math.max(0, maxY - minY);
|
|
347
|
-
}
|
|
348
|
-
function contains(a, b) {
|
|
349
|
-
return a.minX <= b.minX && a.minY <= b.minY && b.maxX <= a.maxX && b.maxY <= a.maxY;
|
|
350
|
-
}
|
|
351
|
-
function intersects(a, b) {
|
|
352
|
-
return b.minX <= a.maxX && b.minY <= a.maxY && b.maxX >= a.minX && b.maxY >= a.minY;
|
|
353
|
-
}
|
|
354
|
-
function createNode(children) {
|
|
355
|
-
return {
|
|
356
|
-
children,
|
|
357
|
-
height: 1,
|
|
358
|
-
leaf: true,
|
|
359
|
-
minX: Infinity,
|
|
360
|
-
minY: Infinity,
|
|
361
|
-
maxX: -Infinity,
|
|
362
|
-
maxY: -Infinity
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
function multiSelect(arr, left, right, n, compare) {
|
|
366
|
-
const stack = [left, right];
|
|
367
|
-
while (stack.length) {
|
|
368
|
-
right = stack.pop();
|
|
369
|
-
left = stack.pop();
|
|
370
|
-
if (right - left <= n) continue;
|
|
371
|
-
const mid = left + Math.ceil((right - left) / n / 2) * n;
|
|
372
|
-
quickselect(arr, mid, left, right, compare);
|
|
373
|
-
stack.push(left, mid, mid, right);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
export {
|
|
377
|
-
RBush as default
|
|
378
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
class TinyQueue {
|
|
2
|
-
constructor(data = [], compare = defaultCompare) {
|
|
3
|
-
this.data = data;
|
|
4
|
-
this.length = this.data.length;
|
|
5
|
-
this.compare = compare;
|
|
6
|
-
if (this.length > 0) {
|
|
7
|
-
for (let i = (this.length >> 1) - 1; i >= 0; i--) this._down(i);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
push(item) {
|
|
11
|
-
this.data.push(item);
|
|
12
|
-
this.length++;
|
|
13
|
-
this._up(this.length - 1);
|
|
14
|
-
}
|
|
15
|
-
pop() {
|
|
16
|
-
if (this.length === 0) return void 0;
|
|
17
|
-
const top = this.data[0];
|
|
18
|
-
const bottom = this.data.pop();
|
|
19
|
-
this.length--;
|
|
20
|
-
if (this.length > 0) {
|
|
21
|
-
this.data[0] = bottom;
|
|
22
|
-
this._down(0);
|
|
23
|
-
}
|
|
24
|
-
return top;
|
|
25
|
-
}
|
|
26
|
-
peek() {
|
|
27
|
-
return this.data[0];
|
|
28
|
-
}
|
|
29
|
-
_up(pos) {
|
|
30
|
-
const { data, compare } = this;
|
|
31
|
-
const item = data[pos];
|
|
32
|
-
while (pos > 0) {
|
|
33
|
-
const parent = pos - 1 >> 1;
|
|
34
|
-
const current = data[parent];
|
|
35
|
-
if (compare(item, current) >= 0) break;
|
|
36
|
-
data[pos] = current;
|
|
37
|
-
pos = parent;
|
|
38
|
-
}
|
|
39
|
-
data[pos] = item;
|
|
40
|
-
}
|
|
41
|
-
_down(pos) {
|
|
42
|
-
const { data, compare } = this;
|
|
43
|
-
const halfLength = this.length >> 1;
|
|
44
|
-
const item = data[pos];
|
|
45
|
-
while (pos < halfLength) {
|
|
46
|
-
let left = (pos << 1) + 1;
|
|
47
|
-
let best = data[left];
|
|
48
|
-
const right = left + 1;
|
|
49
|
-
if (right < this.length && compare(data[right], best) < 0) {
|
|
50
|
-
left = right;
|
|
51
|
-
best = data[right];
|
|
52
|
-
}
|
|
53
|
-
if (compare(best, item) >= 0) break;
|
|
54
|
-
data[pos] = best;
|
|
55
|
-
pos = left;
|
|
56
|
-
}
|
|
57
|
-
data[pos] = item;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function defaultCompare(a, b) {
|
|
61
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
TinyQueue as default
|
|
65
|
-
};
|