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oot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/flatbush@4.5.0/flatbush.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","(function (global, factory) {\n    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n    typeof define === 'function' && define.amd ? define(factory) :\n    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Flatbush = factory());\n})(this, (function () { 'use strict';\n\n    class FlatQueue {\n\n        constructor() {\n            this.ids = [];\n            this.values = [];\n            this.length = 0;\n        }\n\n        clear() {\n            this.length = 0;\n        }\n\n        push(id, value) {\n            let pos = this.length++;\n\n            while (pos > 0) {\n                const parent = (pos - 1) >> 1;\n                const parentValue = this.values[parent];\n                if (value >= parentValue) break;\n                this.ids[pos] = this.ids[parent];\n                this.values[pos] = parentValue;\n                pos = parent;\n            }\n\n            this.ids[pos] = id;\n            this.values[pos] = value;\n        }\n\n        pop() {\n            if (this.length === 0) return undefined;\n\n            const top = this.ids[0];\n            this.length--;\n\n            if (this.length > 0) {\n                const id = this.ids[0] = this.ids[this.length];\n                const value = this.values[0] = this.values[this.length];\n                const halfLength = this.length >> 1;\n                let pos = 0;\n\n                while (pos < halfLength) {\n                    let left = (pos << 1) + 1;\n                    const right = left + 1;\n                    let bestIndex = this.ids[left];\n                    let bestValue = this.values[left];\n                    const rightValue = this.values[right];\n\n                    if (right < this.length && rightValue < bestValue) {\n                        left = right;\n                        bestIndex = this.ids[right];\n                        bestValue = rightValue;\n                    }\n                    if (bestValue >= value) break;\n\n                    this.ids[pos] = bestIndex;\n                    this.values[pos] = bestValue;\n                    pos = left;\n                }\n\n                this.ids[pos] = id;\n                this.values[pos] = value;\n            }\n\n            return top;\n        }\n\n        peek() {\n            if (this.length === 0) return undefined;\n            return this.ids[0];\n        }\n\n        peekValue() {\n            if (this.length === 0) return undefined;\n            return this.values[0];\n        }\n\n        shrink() {\n            this.ids.length = this.values.length = this.length;\n        }\n    }\n\n    const ARRAY_TYPES = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array];\n    const VERSION = 3; // serialized format version\n\n    /** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor} TypedArrayConstructor */\n\n    class Flatbush {\n\n        /**\n         * Recreate a Flatbush index from raw `ArrayBuffer` or `SharedArrayBuffer` data.\n         * @param {ArrayBufferLike} data\n         * @param {number} [byteOffset=0] byte offset to the start of the Flatbush buffer in the referenced ArrayBuffer.\n         * @returns {Flatbush} index\n         */\n        static from(data, byteOffset = 0) {\n            if (byteOffset % 8 !== 0) {\n                throw new Error('byteOffset must be 8-byte aligned.');\n            }\n\n            // @ts-expect-error duck typing array buffers\n            if (!data || data.byteLength === undefined || data.buffer) {\n                throw new Error('Data must be an instance of ArrayBuffer or SharedArrayBuffer.');\n            }\n\n            const [magic, versionAndType] = new Uint8Array(data, byteOffset + 0, 2);\n            if (magic !== 0xfb) {\n                throw new Error('Data does not appear to be in a Flatbush format.');\n            }\n            const version = versionAndType >> 4;\n            if (version !== VERSION) {\n                throw new Error(`Got v${version} data when expected v${VERSION}.`);\n            }\n            const ArrayType = ARRAY_TYPES[versionAndType & 0x0f];\n            if (!ArrayType) {\n                throw new Error('Unrecognized array type.');\n            }\n            const [nodeSize] = new Uint16Array(data, byteOffset + 2, 1);\n            const [numItems] = new Uint32Array(data, byteOffset + 4, 1);\n\n            return new Flatbush(numItems, nodeSize, ArrayType, undefined, data, byteOffset);\n        }\n\n        /**\n         * Create a Flatbush index that will hold a given number of items.\n         * @param {number} numItems\n         * @param {number} [nodeSize=16] Size of the tree node (16 by default).\n         * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).\n         * @param {ArrayBufferConstructor | SharedArrayBufferConstructor} [ArrayBufferType=ArrayBuffer] The array buffer type used to store data (`ArrayBuffer` by default).\n         * @param {ArrayBufferLike} [data] (Only used internally)\n         * @param {number} [byteOffset=0] (Only used internally)\n         */\n        constructor(numItems, nodeSize = 16, ArrayType = Float64Array, ArrayBufferType = ArrayBuffer, data, byteOffset = 0) {\n            if (numItems === undefined) throw new Error('Missing required argument: numItems.');\n            if (isNaN(numItems) || numItems <= 0) throw new Error(`Unexpected numItems value: ${numItems}.`);\n\n            this.numItems = +numItems;\n            this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);\n            this.byteOffset = byteOffset;\n\n            // calculate the total number of nodes in the R-tree to allocate space for\n            // and the index of each tree level (used in search later)\n            let n = numItems;\n            let numNodes = n;\n            this._levelBounds = [n * 4];\n            do {\n                n = Math.ceil(n / this.nodeSize);\n                numNodes += n;\n                this._levelBounds.push(numNodes * 4);\n            } while (n !== 1);\n\n            this.ArrayType = ArrayType;\n            this.IndexArrayType = numNodes < 16384 ? Uint16Array : Uint32Array;\n\n            const arrayTypeIndex = ARRAY_TYPES.indexOf(ArrayType);\n            const nodesByteSize = numNodes * 4 * ArrayType.BYTES_PER_ELEMENT;\n\n            if (arrayTypeIndex < 0) {\n                throw new Error(`Unexpected typed array class: ${ArrayType}.`);\n            }\n\n            if (data) {\n                this.data = data;\n                // @ts-expect-error TS can't handle SharedArraBuffer overloads\n                this._boxes = new ArrayType(data, byteOffset + 8, numNodes * 4);\n                // @ts-expect-error TS can't handle SharedArraBuffer overloads\n                this._indices = new this.IndexArrayType(data, byteOffset + 8 + nodesByteSize, numNodes);\n\n                this._pos = numNodes * 4;\n                this.minX = this._boxes[this._pos - 4];\n                this.minY = this._boxes[this._pos - 3];\n                this.maxX = this._boxes[this._pos - 2];\n                this.maxY = this._boxes[this._pos - 1];\n\n            } else {\n                const data = this.data = new ArrayBufferType(8 + nodesByteSize + numNodes * this.IndexArrayType.BYTES_PER_ELEMENT);\n                // @ts-expect-error TS can't handle SharedArraBuffer overloads\n                this._boxes = new ArrayType(data, 8, numNodes * 4);\n                // @ts-expect-error TS can't handle SharedArraBuffer overloads\n                this._indices = new this.IndexArrayType(data, 8 + nodesByteSize, numNodes);\n                this._pos = 0;\n                this.minX = Infinity;\n                this.minY = Infinity;\n                this.maxX = -Infinity;\n                this.maxY = -Infinity;\n\n                new Uint8Array(data, 0, 2).set([0xfb, (VERSION << 4) + arrayTypeIndex]);\n                new Uint16Array(data, 2, 1)[0] = nodeSize;\n                new Uint32Array(data, 4, 1)[0] = numItems;\n            }\n\n            // a priority queue for k-nearest-neighbors queries\n            /** @type FlatQueue<number> */\n            this._queue = new FlatQueue();\n        }\n\n        /**\n         * Add a given rectangle to the index.\n         * @param {number} minX\n         * @param {number} minY\n         * @param {number} maxX\n         * @param {number} maxY\n         * @returns {number} A zero-based, incremental number that represents the newly added rectangle.\n         */\n        add(minX, minY, maxX = minX, maxY = minY) {\n            const index = this._pos >> 2;\n            const boxes = this._boxes;\n            this._indices[index] = index;\n            boxes[this._pos++] = minX;\n            boxes[this._pos++] = minY;\n            boxes[this._pos++] = maxX;\n            boxes[this._pos++] = maxY;\n\n            if (minX < this.minX) this.minX = minX;\n            if (minY < this.minY) this.minY = minY;\n            if (maxX > this.maxX) this.maxX = maxX;\n            if (maxY > this.maxY) this.maxY = maxY;\n\n            return index;\n        }\n\n        /** Perform indexing of the added rectangles. */\n        finish() {\n            if (this._pos >> 2 !== this.numItems) {\n                throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);\n            }\n            const boxes = this._boxes;\n\n            if (this.numItems <= this.nodeSize) {\n                // only one node, skip sorting and just fill the root box\n                boxes[this._pos++] = this.minX;\n                boxes[this._pos++] = this.minY;\n                boxes[this._pos++] = this.maxX;\n                boxes[this._pos++] = this.maxY;\n                return;\n            }\n\n            const width = (this.maxX - this.minX) || 1;\n            const height = (this.maxY - this.minY) || 1;\n            const hilbertValues = new Uint32Array(this.numItems);\n            const hilbertMax = (1 << 16) - 1;\n\n            // map item centers into Hilbert coordinate space and calculate Hilbert values\n            for (let i = 0, pos = 0; i < this.numItems; i++) {\n                const minX = boxes[pos++];\n                const minY = boxes[pos++];\n                const maxX = boxes[pos++];\n                const maxY = boxes[pos++];\n                const x = Math.floor(hilbertMax * ((minX + maxX) / 2 - this.minX) / width);\n                const y = Math.floor(hilbertMax * ((minY + maxY) / 2 - this.minY) / height);\n                hilbertValues[i] = hilbert(x, y);\n            }\n\n            // sort items by their Hilbert value (for packing later)\n            sort(hilbertValues, boxes, this._indices, 0, this.numItems - 1, this.nodeSize);\n\n            // generate nodes at each tree level, bottom-up\n            for (let i = 0, pos = 0; i < this._levelBounds.length - 1; i++) {\n                const end = this._levelBounds[i];\n\n                // generate a parent node for each block of consecutive <nodeSize> nodes\n                while (pos < end) {\n                    const nodeIndex = pos;\n\n                    // calculate bbox for the new node\n                    let nodeMinX = boxes[pos++];\n                    let nodeMinY = boxes[pos++];\n                    let nodeMaxX = boxes[pos++];\n                    let nodeMaxY = boxes[pos++];\n                    for (let j = 1; j < this.nodeSize && pos < end; j++) {\n                        nodeMinX = Math.min(nodeMinX, boxes[pos++]);\n                        nodeMinY = Math.min(nodeMinY, boxes[pos++]);\n                        nodeMaxX = Math.max(nodeMaxX, boxes[pos++]);\n                        nodeMaxY = Math.max(nodeMaxY, boxes[pos++]);\n                    }\n\n                    // add the new node to the tree data\n                    this._indices[this._pos >> 2] = nodeIndex;\n                    boxes[this._pos++] = nodeMinX;\n                    boxes[this._pos++] = nodeMinY;\n                    boxes[this._pos++] = nodeMaxX;\n                    boxes[this._pos++] = nodeMaxY;\n                }\n            }\n        }\n\n        /**\n         * Search the index by a bounding box.\n         * @param {number} minX\n         * @param {number} minY\n         * @param {number} maxX\n         * @param {number} maxY\n         * @param {(index: number, x0: number, y0: number, x1: number, y1: number) => boolean} [filterFn] An optional function that is called on every found item; if supplied, only items for which this function returns true will be included in the results array.\n         * @returns {number[]} An array of indices of items intersecting or touching the given bounding box.\n         */\n        search(minX, minY, maxX, maxY, filterFn) {\n            if (this._pos !== this._boxes.length) {\n                throw new Error('Data not yet indexed - call index.finish().');\n            }\n\n            /** @type number | undefined */\n            let nodeIndex = this._boxes.length - 4;\n            const queue = [];\n            const results = [];\n\n            while (nodeIndex !== undefined) {\n                // find the end index of the node\n                const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds));\n\n                // search through child nodes\n                for (let /** @type number */ pos = nodeIndex; pos < end; pos += 4) {\n                    // check if node bbox intersects with query bbox\n                    const x0 = this._boxes[pos];\n                    if (maxX < x0) continue;\n                    const y0 = this._boxes[pos + 1];\n                    if (maxY < y0) continue;\n                    const x1 = this._boxes[pos + 2];\n                    if (minX > x1) continue;\n                    const y1 = this._boxes[pos + 3];\n                    if (minY > y1) continue;\n\n                    const index = this._indices[pos >> 2] | 0;\n\n                    if (nodeIndex >= this.numItems * 4) {\n                        queue.push(index); // node; add it to the search queue\n\n                    } else if (filterFn === undefined || filterFn(index, x0, y0, x1, y1)) {\n                        results.push(index); // leaf item\n                    }\n                }\n\n                nodeIndex = queue.pop();\n            }\n\n            return results;\n        }\n\n        /**\n         * Search items in order of distance from the given point.\n         * @param {number} x\n         * @param {number} y\n         * @param {number} [maxResults=Infinity]\n         * @param {number} [maxDistance=Infinity]\n         * @param {(index: number) => boolean} [filterFn] An optional function for filtering the results.\n         * @returns {number[]} An array of indices of items found.\n         */\n        neighbors(x, y, maxResults = Infinity, maxDistance = Infinity, filterFn) {\n            if (this._pos !== this._boxes.length) {\n                throw new Error('Data not yet indexed - call index.finish().');\n            }\n\n            /** @type number | undefined */\n            let nodeIndex = this._boxes.length - 4;\n            const q = this._queue;\n            const results = [];\n            const maxDistSquared = maxDistance * maxDistance;\n\n            /* eslint-disable no-labels */\n            outer: while (nodeIndex !== undefined) {\n                // find the end index of the node\n                const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds));\n\n                // add child nodes to the queue\n                for (let pos = nodeIndex; pos < end; pos += 4) {\n                    const index = this._indices[pos >> 2] | 0;\n                    const minX = this._boxes[pos];\n                    const minY = this._boxes[pos + 1];\n                    const maxX = this._boxes[pos + 2];\n                    const maxY = this._boxes[pos + 3];\n                    const dx = x < minX ? minX - x : x > maxX ? x - maxX : 0;\n                    const dy = y < minY ? minY - y : y > maxY ? y - maxY : 0;\n                    const dist = dx * dx + dy * dy;\n                    if (dist > maxDistSquared) continue;\n\n                    if (nodeIndex >= this.numItems * 4) {\n                        q.push(index << 1, dist); // node (use even id)\n\n                    } else if (filterFn === undefined || filterFn(index)) {\n                        q.push((index << 1) + 1, dist); // leaf item (use odd id)\n                    }\n                }\n\n                // pop items from the queue\n                // @ts-expect-error q.length check eliminates undefined values\n                while (q.length && (q.peek() & 1)) {\n                    const dist = q.peekValue();\n                    // @ts-expect-error\n                    if (dist > maxDistSquared) break outer;\n                    // @ts-expect-error\n                    results.push(q.pop() >> 1);\n                    if (results.length === maxResults) break outer;\n                }\n\n                // @ts-expect-error\n                nodeIndex = q.length ? q.pop() >> 1 : undefined;\n            }\n\n            q.clear();\n            return results;\n        }\n    }\n\n    /**\n     * Binary search for the first value in the array bigger than the given.\n     * @param {number} value\n     * @param {number[]} arr\n     */\n    function upperBound(value, arr) {\n        let i = 0;\n        let j = arr.length - 1;\n        while (i < j) {\n            const m = (i + j) >> 1;\n            if (arr[m] > value) {\n                j = m;\n            } else {\n                i = m + 1;\n            }\n        }\n        return arr[i];\n    }\n\n    /**\n     * Custom quicksort that partially sorts bbox data alongside the hilbert values.\n     * @param {Uint32Array} values\n     * @param {InstanceType<TypedArrayConstructor>} boxes\n     * @param {Uint16Array | Uint32Array} indices\n     * @param {number} left\n     * @param {number} right\n     * @param {number} nodeSize\n     */\n    function sort(values, boxes, indices, left, right, nodeSize) {\n        if (Math.floor(left / nodeSize) >= Math.floor(right / nodeSize)) return;\n\n        // apply median of three method\n        const start = values[left];\n        const mid = values[(left + right) >> 1];\n        const end = values[right];\n\n        let pivot = end;\n\n        const x = Math.max(start, mid);\n        if (end > x) {\n            pivot = x;\n        } else if (x === start) {\n            pivot = Math.max(mid, end);\n        } else if (x === mid) {\n            pivot = Math.max(start, end);\n        }\n\n        let i = left - 1;\n        let j = right + 1;\n\n        while (true) {\n            do i++; while (values[i] < pivot);\n            do j--; while (values[j] > pivot);\n            if (i >= j) break;\n            swap(values, boxes, indices, i, j);\n        }\n\n        sort(values, boxes, indices, left, j, nodeSize);\n        sort(values, boxes, indices, j + 1, right, nodeSize);\n    }\n\n    /**\n     * Swap two values and two corresponding boxes.\n     * @param {Uint32Array} values\n     * @param {InstanceType<TypedArrayConstructor>} boxes\n     * @param {Uint16Array | Uint32Array} indices\n     * @param {number} i\n     * @param {number} j\n     */\n    function swap(values, boxes, indices, i, j) {\n        const temp = values[i];\n        values[i] = values[j];\n        values[j] = temp;\n\n        const k = 4 * i;\n        const m = 4 * j;\n\n        const a = boxes[k];\n        const b = boxes[k + 1];\n        const c = boxes[k + 2];\n        const d = boxes[k + 3];\n        boxes[k] = boxes[m];\n        boxes[k + 1] = boxes[m + 1];\n        boxes[k + 2] = boxes[m + 2];\n        boxes[k + 3] = boxes[m + 3];\n        boxes[m] = a;\n        boxes[m + 1] = b;\n        boxes[m + 2] = c;\n        boxes[m + 3] = d;\n\n        const e = indices[i];\n        indices[i] = indices[j];\n        indices[j] = e;\n    }\n\n    /**\n     * Fast Hilbert curve algorithm by http://threadlocalmutex.com/\n     * Ported from C++ https://github.com/rawrunprotected/hilbert_curves (public domain)\n     * @param {number} x\n     * @param {number} y\n     */\n    function hilbert(x, y) {\n        let a = x ^ y;\n        let b = 0xFFFF ^ a;\n        let c = 0xFFFF ^ (x | y);\n        let d = x & (y ^ 0xFFFF);\n\n        let A = a | (b >> 1);\n        let B = (a >> 1) ^ a;\n        let C = ((c >> 1) ^ (b & (d >> 1))) ^ c;\n        let D = ((a & (c >> 1)) ^ (d >> 1)) ^ d;\n\n        a = A; b = B; c = C; d = D;\n        A = ((a & (a >> 2)) ^ (b & (b >> 2)));\n        B = ((a & (b >> 2)) ^ (b & ((a ^ b) >> 2)));\n        C ^= ((a & (c >> 2)) ^ (b & (d >> 2)));\n        D ^= ((b & (c >> 2)) ^ ((a ^ b) & (d >> 2)));\n\n        a = A; b = B; c = C; d = D;\n        A = ((a & (a >> 4)) ^ (b & (b >> 4)));\n        B = ((a & (b >> 4)) ^ (b & ((a ^ b) >> 4)));\n        C ^= ((a & (c >> 4)) ^ (b & (d >> 4)));\n        D ^= ((b & (c >> 4)) ^ ((a ^ b) & (d >> 4)));\n\n        a = A; b = B; c = C; d = D;\n        C ^= ((a & (c >> 8)) ^ (b & (d >> 8)));\n        D ^= ((b & (c >> 8)) ^ ((a ^ b) & (d >> 8)));\n\n        a = C ^ (C >> 1);\n        b = D ^ (D >> 1);\n\n        let i0 = x ^ y;\n        let i1 = b | (0xFFFF ^ (i0 | a));\n\n        i0 = (i0 | (i0 << 8)) & 0x00FF00FF;\n        i0 = (i0 | (i0 << 4)) & 0x0F0F0F0F;\n        i0 = (i0 | (i0 << 2)) & 0x33333333;\n        i0 = (i0 | (i0 << 1)) & 0x55555555;\n\n        i1 = (i1 | (i1 << 8)) & 0x00FF00FF;\n        i1 = (i1 | (i1 << 4)) & 0x0F0F0F0F;\n        i1 = (i1 | (i1 << 2)) & 0x33333333;\n        i1 = (i1 | (i1 << 1)) & 0x55555555;\n\n        return ((i1 << 1) | i0) >>> 0;\n    }\n\n    return Flatbush;\n\n}));\n"]}