taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
1,637 lines • 2.84 MB
JavaScript
var Z4 = Object.defineProperty;
var G4 = (t, e, r) => e in t ? Z4(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
var E = (t, e, r) => G4(t, typeof e != "symbol" ? e + "" : e, r);
import { jsxs as ee, jsx as O, Fragment as gt } from "react/jsx-runtime";
import * as ot from "react";
import M, { useLayoutEffect as bm, useEffect as ge, cloneElement as Bi, createElement as jt, createContext as cr, useState as ue, useRef as Ee, useMemo as Me, useImperativeHandle as HS, useCallback as _e, Component as bs, useContext as fr, forwardRef as Y4, Fragment as _r, isValidElement as WS, useId as ys, useSyncExternalStore as J4, useReducer as Q4, createRef as eM, PureComponent as Da, Children as VS, Suspense as tM } from "react";
import rM, { createPortal as nM } from "react-dom";
import de, { checkPropTypes as XS } from "prop-types";
const zs = globalThis || void 0 || self;
function cu(t, e) {
if (!t)
throw new Error(e || "loader assertion failed.");
}
function iM(t) {
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
}
var KS = { exports: {} }, _t = KS.exports = {}, rn, nn;
function H0() {
throw new Error("setTimeout has not been defined");
}
function W0() {
throw new Error("clearTimeout has not been defined");
}
(function() {
try {
typeof setTimeout == "function" ? rn = setTimeout : rn = H0;
} catch {
rn = H0;
}
try {
typeof clearTimeout == "function" ? nn = clearTimeout : nn = W0;
} catch {
nn = W0;
}
})();
function ZS(t) {
if (rn === setTimeout)
return setTimeout(t, 0);
if ((rn === H0 || !rn) && setTimeout)
return rn = setTimeout, setTimeout(t, 0);
try {
return rn(t, 0);
} catch {
try {
return rn.call(null, t, 0);
} catch {
return rn.call(this, t, 0);
}
}
}
function oM(t) {
if (nn === clearTimeout)
return clearTimeout(t);
if ((nn === W0 || !nn) && clearTimeout)
return nn = clearTimeout, clearTimeout(t);
try {
return nn(t);
} catch {
try {
return nn.call(null, t);
} catch {
return nn.call(this, t);
}
}
}
var Cn = [], Qo = !1, Ci, Hl = -1;
function sM() {
!Qo || !Ci || (Qo = !1, Ci.length ? Cn = Ci.concat(Cn) : Hl = -1, Cn.length && GS());
}
function GS() {
if (!Qo) {
var t = ZS(sM);
Qo = !0;
for (var e = Cn.length; e; ) {
for (Ci = Cn, Cn = []; ++Hl < e; )
Ci && Ci[Hl].run();
Hl = -1, e = Cn.length;
}
Ci = null, Qo = !1, oM(t);
}
}
_t.nextTick = function(t) {
var e = new Array(arguments.length - 1);
if (arguments.length > 1)
for (var r = 1; r < arguments.length; r++)
e[r - 1] = arguments[r];
Cn.push(new YS(t, e)), Cn.length === 1 && !Qo && ZS(GS);
};
function YS(t, e) {
this.fun = t, this.array = e;
}
YS.prototype.run = function() {
this.fun.apply(null, this.array);
};
_t.title = "browser";
_t.browser = !0;
_t.env = {};
_t.argv = [];
_t.version = "";
_t.versions = {};
function Bn() {
}
_t.on = Bn;
_t.addListener = Bn;
_t.once = Bn;
_t.off = Bn;
_t.removeListener = Bn;
_t.removeAllListeners = Bn;
_t.emit = Bn;
_t.prependListener = Bn;
_t.prependOnceListener = Bn;
_t.listeners = function(t) {
return [];
};
_t.binding = function(t) {
throw new Error("process.binding is not supported");
};
_t.cwd = function() {
return "/";
};
_t.chdir = function(t) {
throw new Error("process.chdir is not supported");
};
_t.umask = function() {
return 0;
};
var aM = KS.exports;
const Ce = /* @__PURE__ */ iM(aM), ym = (
// @ts-ignore process does not exist on browser
!!(typeof Ce != "object" || String(Ce) !== "[object process]" || Ce.browser)
), Mb = typeof Ce < "u" && Ce.version && /v([0-9]*)/.exec(Ce.version);
Mb && parseFloat(Mb[1]);
const sl = globalThis, co = globalThis.process || {}, lM = globalThis.navigator || {};
function JS(t) {
var n, i;
if (typeof window < "u" && ((n = window.process) == null ? void 0 : n.type) === "renderer" || typeof Ce < "u" && ((i = Ce.versions) != null && i.electron))
return !0;
const r = typeof navigator < "u" && navigator.userAgent;
return !!(r && r.indexOf("Electron") >= 0);
}
function Gi() {
return !// @ts-expect-error
(typeof Ce == "object" && String(Ce) === "[object process]" && !(Ce != null && Ce.browser)) || JS();
}
function uM(t) {
return Gi() ? JS() ? "Electron" : (lM.userAgent || "").indexOf("Edge") > -1 ? "Edge" : globalThis.chrome ? "Chrome" : globalThis.safari ? "Safari" : globalThis.mozInnerScreenX ? "Firefox" : "Unknown" : "Node";
}
const QS = "4.1.0";
function cM(t) {
try {
const e = window[t], r = "__storage_test__";
return e.setItem(r, r), e.removeItem(r), e;
} catch {
return null;
}
}
class fM {
constructor(e, r, n = "sessionStorage") {
this.storage = cM(n), this.id = e, this.config = r, this._loadConfiguration();
}
getConfiguration() {
return this.config;
}
setConfiguration(e) {
if (Object.assign(this.config, e), this.storage) {
const r = JSON.stringify(this.config);
this.storage.setItem(this.id, r);
}
}
// Get config from persistent store, if available
_loadConfiguration() {
let e = {};
if (this.storage) {
const r = this.storage.getItem(this.id);
e = r ? JSON.parse(r) : {};
}
return Object.assign(this.config, e), this;
}
}
function hM(t) {
let e;
return t < 10 ? e = `${t.toFixed(2)}ms` : t < 100 ? e = `${t.toFixed(1)}ms` : t < 1e3 ? e = `${t.toFixed(0)}ms` : e = `${(t / 1e3).toFixed(2)}s`, e;
}
function dM(t, e = 8) {
const r = Math.max(e - t.length, 0);
return `${" ".repeat(r)}${t}`;
}
var fu;
(function(t) {
t[t.BLACK = 30] = "BLACK", t[t.RED = 31] = "RED", t[t.GREEN = 32] = "GREEN", t[t.YELLOW = 33] = "YELLOW", t[t.BLUE = 34] = "BLUE", t[t.MAGENTA = 35] = "MAGENTA", t[t.CYAN = 36] = "CYAN", t[t.WHITE = 37] = "WHITE", t[t.BRIGHT_BLACK = 90] = "BRIGHT_BLACK", t[t.BRIGHT_RED = 91] = "BRIGHT_RED", t[t.BRIGHT_GREEN = 92] = "BRIGHT_GREEN", t[t.BRIGHT_YELLOW = 93] = "BRIGHT_YELLOW", t[t.BRIGHT_BLUE = 94] = "BRIGHT_BLUE", t[t.BRIGHT_MAGENTA = 95] = "BRIGHT_MAGENTA", t[t.BRIGHT_CYAN = 96] = "BRIGHT_CYAN", t[t.BRIGHT_WHITE = 97] = "BRIGHT_WHITE";
})(fu || (fu = {}));
const pM = 10;
function Tb(t) {
return typeof t != "string" ? t : (t = t.toUpperCase(), fu[t] || fu.WHITE);
}
function gM(t, e, r) {
return !Gi && typeof t == "string" && (e && (t = `\x1B[${Tb(e)}m${t}\x1B[39m`), r && (t = `\x1B[${Tb(r) + pM}m${t}\x1B[49m`)), t;
}
function mM(t, e = ["constructor"]) {
const r = Object.getPrototypeOf(t), n = Object.getOwnPropertyNames(r), i = t;
for (const o of n) {
const s = i[o];
typeof s == "function" && (e.find((a) => o === a) || (i[o] = s.bind(t)));
}
}
function vm(t, e) {
if (!t)
throw new Error("Assertion failed");
}
function fo() {
var e, r, n;
let t;
if (Gi() && sl.performance)
t = (r = (e = sl == null ? void 0 : sl.performance) == null ? void 0 : e.now) == null ? void 0 : r.call(e);
else if ("hrtime" in co) {
const i = (n = co == null ? void 0 : co.hrtime) == null ? void 0 : n.call(co);
t = i[0] * 1e3 + i[1] / 1e6;
} else
t = Date.now();
return t;
}
const ho = {
debug: Gi() && console.debug || console.log,
log: console.log,
info: console.info,
warn: console.warn,
error: console.error
}, bM = {
enabled: !0,
level: 0
};
function po() {
}
const Cb = {}, kb = { once: !0 };
class $a {
constructor({ id: e } = { id: "" }) {
this.VERSION = QS, this._startTs = fo(), this._deltaTs = fo(), this.userData = {}, this.LOG_THROTTLE_TIMEOUT = 0, this.id = e, this.userData = {}, this._storage = new fM(`__probe-${this.id}__`, bM), this.timeStamp(`${this.id} started`), mM(this), Object.seal(this);
}
set level(e) {
this.setLevel(e);
}
get level() {
return this.getLevel();
}
isEnabled() {
return this._storage.config.enabled;
}
getLevel() {
return this._storage.config.level;
}
/** @return milliseconds, with fractions */
getTotal() {
return Number((fo() - this._startTs).toPrecision(10));
}
/** @return milliseconds, with fractions */
getDelta() {
return Number((fo() - this._deltaTs).toPrecision(10));
}
/** @deprecated use logLevel */
set priority(e) {
this.level = e;
}
/** @deprecated use logLevel */
get priority() {
return this.level;
}
/** @deprecated use logLevel */
getPriority() {
return this.level;
}
// Configure
enable(e = !0) {
return this._storage.setConfiguration({ enabled: e }), this;
}
setLevel(e) {
return this._storage.setConfiguration({ level: e }), this;
}
/** return the current status of the setting */
get(e) {
return this._storage.config[e];
}
// update the status of the setting
set(e, r) {
this._storage.setConfiguration({ [e]: r });
}
/** Logs the current settings as a table */
settings() {
console.table ? console.table(this._storage.config) : console.log(this._storage.config);
}
// Unconditional logging
assert(e, r) {
if (!e)
throw new Error(r || "Assertion failed");
}
warn(e) {
return this._getLogFunction(0, e, ho.warn, arguments, kb);
}
error(e) {
return this._getLogFunction(0, e, ho.error, arguments);
}
/** Print a deprecation warning */
deprecated(e, r) {
return this.warn(`\`${e}\` is deprecated and will be removed in a later version. Use \`${r}\` instead`);
}
/** Print a removal warning */
removed(e, r) {
return this.error(`\`${e}\` has been removed. Use \`${r}\` instead`);
}
probe(e, r) {
return this._getLogFunction(e, r, ho.log, arguments, {
time: !0,
once: !0
});
}
log(e, r) {
return this._getLogFunction(e, r, ho.debug, arguments);
}
info(e, r) {
return this._getLogFunction(e, r, console.info, arguments);
}
once(e, r) {
return this._getLogFunction(e, r, ho.debug || ho.info, arguments, kb);
}
/** Logs an object as a table */
table(e, r, n) {
return r ? this._getLogFunction(e, r, console.table || po, n && [n], {
tag: vM(r)
}) : po;
}
time(e, r) {
return this._getLogFunction(e, r, console.time ? console.time : console.info);
}
timeEnd(e, r) {
return this._getLogFunction(e, r, console.timeEnd ? console.timeEnd : console.info);
}
timeStamp(e, r) {
return this._getLogFunction(e, r, console.timeStamp || po);
}
group(e, r, n = { collapsed: !1 }) {
const i = Pb({ logLevel: e, message: r, opts: n }), { collapsed: o } = n;
return i.method = (o ? console.groupCollapsed : console.group) || console.info, this._getLogFunction(i);
}
groupCollapsed(e, r, n = {}) {
return this.group(e, r, Object.assign({}, n, { collapsed: !0 }));
}
groupEnd(e) {
return this._getLogFunction(e, "", console.groupEnd || po);
}
// EXPERIMENTAL
withGroup(e, r, n) {
this.group(e, r)();
try {
n();
} finally {
this.groupEnd(e)();
}
}
trace() {
console.trace && console.trace();
}
// PRIVATE METHODS
/** Deduces log level from a variety of arguments */
_shouldLog(e) {
return this.isEnabled() && this.getLevel() >= e6(e);
}
_getLogFunction(e, r, n, i, o) {
if (this._shouldLog(e)) {
o = Pb({ logLevel: e, message: r, args: i, opts: o }), n = n || o.method, vm(n), o.total = this.getTotal(), o.delta = this.getDelta(), this._deltaTs = fo();
const s = o.tag || o.message;
if (o.once && s)
if (!Cb[s])
Cb[s] = fo();
else
return po;
return r = yM(this.id, o.message, o), n.bind(console, r, ...o.args);
}
return po;
}
}
$a.VERSION = QS;
function e6(t) {
if (!t)
return 0;
let e;
switch (typeof t) {
case "number":
e = t;
break;
case "object":
e = t.logLevel || t.priority || 0;
break;
default:
return 0;
}
return vm(Number.isFinite(e) && e >= 0), e;
}
function Pb(t) {
const { logLevel: e, message: r } = t;
t.logLevel = e6(e);
const n = t.args ? Array.from(t.args) : [];
for (; n.length && n.shift() !== r; )
;
switch (typeof e) {
case "string":
case "function":
r !== void 0 && n.unshift(r), t.message = e;
break;
case "object":
Object.assign(t, e);
break;
}
typeof t.message == "function" && (t.message = t.message());
const i = typeof t.message;
return vm(i === "string" || i === "object"), Object.assign(t, { args: n }, t.opts);
}
function yM(t, e, r) {
if (typeof e == "string") {
const n = r.time ? dM(hM(r.total)) : "";
e = r.time ? `${t}: ${n} ${e}` : `${t}: ${e}`, e = gM(e, r.color, r.background);
}
return e;
}
function vM(t) {
for (const e in t)
for (const r in t[e])
return r || "untitled";
return "empty";
}
const kf = "4.3.3", _M = kf[0] >= "0" && kf[0] <= "9" ? `v${kf}` : "";
function wM() {
const t = new $a({ id: "loaders.gl" });
return globalThis.loaders = globalThis.loaders || {}, globalThis.loaders.log = t, globalThis.loaders.version = _M, globalThis.probe = globalThis.probe || {}, globalThis.probe.loaders = t, t;
}
const xM = wM();
function SM(t, e) {
return t6(t || {}, e);
}
function t6(t, e, r = 0) {
if (r > 3)
return e;
const n = { ...t };
for (const [i, o] of Object.entries(e))
o && typeof o == "object" && !Array.isArray(o) ? n[i] = t6(n[i] || {}, e[i], r + 1) : n[i] = e[i];
return n;
}
const EM = "latest";
function AM() {
var t;
return (t = globalThis._loadersgl_) != null && t.version || (globalThis._loadersgl_ = globalThis._loadersgl_ || {}, globalThis._loadersgl_.version = "4.3.3"), globalThis._loadersgl_.version;
}
const RM = AM();
function ui(t, e) {
if (!t)
throw new Error(e || "loaders.gl assertion failed.");
}
const Ni = (
// @ts-ignore process.browser
typeof Ce != "object" || String(Ce) !== "[object process]" || Ce.browser
), MM = typeof window < "u" && typeof window.orientation < "u", Ib = typeof Ce < "u" && Ce.version && /v([0-9]*)/.exec(Ce.version);
Ib && parseFloat(Ib[1]);
class TM {
constructor(e, r) {
E(this, "name");
E(this, "workerThread");
E(this, "isRunning", !0);
/** Promise that resolves when Job is done */
E(this, "result");
E(this, "_resolve", () => {
});
E(this, "_reject", () => {
});
this.name = e, this.workerThread = r, this.result = new Promise((n, i) => {
this._resolve = n, this._reject = i;
});
}
/**
* Send a message to the job's worker thread
* @param data any data structure, ideally consisting mostly of transferrable objects
*/
postMessage(e, r) {
this.workerThread.postMessage({
source: "loaders.gl",
// Lets worker ignore unrelated messages
type: e,
payload: r
});
}
/**
* Call to resolve the `result` Promise with the supplied value
*/
done(e) {
ui(this.isRunning), this.isRunning = !1, this._resolve(e);
}
/**
* Call to reject the `result` Promise with the supplied error
*/
error(e) {
ui(this.isRunning), this.isRunning = !1, this._reject(e);
}
}
class Pf {
terminate() {
}
}
const If = /* @__PURE__ */ new Map();
function CM(t) {
ui(t.source && !t.url || !t.source && t.url);
let e = If.get(t.source || t.url);
return e || (t.url && (e = kM(t.url), If.set(t.url, e)), t.source && (e = r6(t.source), If.set(t.source, e))), ui(e), e;
}
function kM(t) {
if (!t.startsWith("http"))
return t;
const e = PM(t);
return r6(e);
}
function r6(t) {
const e = new Blob([t], { type: "application/javascript" });
return URL.createObjectURL(e);
}
function PM(t) {
return `try {
importScripts('${t}');
} catch (error) {
console.error(error);
throw error;
}`;
}
function n6(t, e = !0, r) {
const n = r || /* @__PURE__ */ new Set();
if (t) {
if (Ob(t))
n.add(t);
else if (Ob(t.buffer))
n.add(t.buffer);
else if (!ArrayBuffer.isView(t)) {
if (e && typeof t == "object")
for (const i in t)
n6(t[i], e, n);
}
}
return r === void 0 ? Array.from(n) : [];
}
function Ob(t) {
return t ? t instanceof ArrayBuffer || typeof MessagePort < "u" && t instanceof MessagePort || typeof ImageBitmap < "u" && t instanceof ImageBitmap || typeof OffscreenCanvas < "u" && t instanceof OffscreenCanvas : !1;
}
const Of = () => {
};
class V0 {
constructor(e) {
E(this, "name");
E(this, "source");
E(this, "url");
E(this, "terminated", !1);
E(this, "worker");
E(this, "onMessage");
E(this, "onError");
E(this, "_loadableURL", "");
const { name: r, source: n, url: i } = e;
ui(n || i), this.name = r, this.source = n, this.url = i, this.onMessage = Of, this.onError = (o) => console.log(o), this.worker = Ni ? this._createBrowserWorker() : this._createNodeWorker();
}
/** Checks if workers are supported on this platform */
static isSupported() {
return typeof Worker < "u" && Ni || typeof Pf < "u" && !Ni;
}
/**
* Terminate this worker thread
* @note Can free up significant memory
*/
destroy() {
this.onMessage = Of, this.onError = Of, this.worker.terminate(), this.terminated = !0;
}
get isRunning() {
return !!this.onMessage;
}
/**
* Send a message to this worker thread
* @param data any data structure, ideally consisting mostly of transferrable objects
* @param transferList If not supplied, calculated automatically by traversing data
*/
postMessage(e, r) {
r = r || n6(e), this.worker.postMessage(e, r);
}
// PRIVATE
/**
* Generate a standard Error from an ErrorEvent
* @param event
*/
_getErrorFromErrorEvent(e) {
let r = "Failed to load ";
return r += `worker ${this.name} from ${this.url}. `, e.message && (r += `${e.message} in `), e.lineno && (r += `:${e.lineno}:${e.colno}`), new Error(r);
}
/**
* Creates a worker thread on the browser
*/
_createBrowserWorker() {
this._loadableURL = CM({ source: this.source, url: this.url });
const e = new Worker(this._loadableURL, { name: this.name });
return e.onmessage = (r) => {
r.data ? this.onMessage(r.data) : this.onError(new Error("No data received"));
}, e.onerror = (r) => {
this.onError(this._getErrorFromErrorEvent(r)), this.terminated = !0;
}, e.onmessageerror = (r) => console.error(r), e;
}
/**
* Creates a worker thread in node.js
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
*/
_createNodeWorker() {
let e;
if (this.url) {
const n = this.url.includes(":/") || this.url.startsWith("/") ? this.url : `./${this.url}`;
e = new Pf(n, { eval: !1 });
} else if (this.source)
e = new Pf(this.source, { eval: !0 });
else
throw new Error("no worker");
return e.on("message", (r) => {
this.onMessage(r);
}), e.on("error", (r) => {
this.onError(r);
}), e.on("exit", (r) => {
}), e;
}
}
class IM {
/**
* @param processor - worker function
* @param maxConcurrency - max count of workers
*/
constructor(e) {
E(this, "name", "unnamed");
E(this, "source");
// | Function;
E(this, "url");
E(this, "maxConcurrency", 1);
E(this, "maxMobileConcurrency", 1);
E(this, "onDebug", () => {
});
E(this, "reuseWorkers", !0);
E(this, "props", {});
E(this, "jobQueue", []);
E(this, "idleQueue", []);
E(this, "count", 0);
E(this, "isDestroyed", !1);
this.source = e.source, this.url = e.url, this.setProps(e);
}
/** Checks if workers are supported on this platform */
static isSupported() {
return V0.isSupported();
}
/**
* Terminates all workers in the pool
* @note Can free up significant memory
*/
destroy() {
this.idleQueue.forEach((e) => e.destroy()), this.isDestroyed = !0;
}
setProps(e) {
this.props = { ...this.props, ...e }, e.name !== void 0 && (this.name = e.name), e.maxConcurrency !== void 0 && (this.maxConcurrency = e.maxConcurrency), e.maxMobileConcurrency !== void 0 && (this.maxMobileConcurrency = e.maxMobileConcurrency), e.reuseWorkers !== void 0 && (this.reuseWorkers = e.reuseWorkers), e.onDebug !== void 0 && (this.onDebug = e.onDebug);
}
async startJob(e, r = (i, o, s) => i.done(s), n = (i, o) => i.error(o)) {
const i = new Promise((o) => (this.jobQueue.push({ name: e, onMessage: r, onError: n, onStart: o }), this));
return this._startQueuedJob(), await i;
}
// PRIVATE
/**
* Starts first queued job if worker is available or can be created
* Called when job is started and whenever a worker returns to the idleQueue
*/
async _startQueuedJob() {
if (!this.jobQueue.length)
return;
const e = this._getAvailableWorker();
if (!e)
return;
const r = this.jobQueue.shift();
if (r) {
this.onDebug({
message: "Starting job",
name: r.name,
workerThread: e,
backlog: this.jobQueue.length
});
const n = new TM(r.name, e);
e.onMessage = (i) => r.onMessage(n, i.type, i.payload), e.onError = (i) => r.onError(n, i), r.onStart(n);
try {
await n.result;
} catch (i) {
console.error(`Worker exception: ${i}`);
} finally {
this.returnWorkerToQueue(e);
}
}
}
/**
* Returns a worker to the idle queue
* Destroys the worker if
* - pool is destroyed
* - if this pool doesn't reuse workers
* - if maxConcurrency has been lowered
* @param worker
*/
returnWorkerToQueue(e) {
// Workers on Node.js prevent the process from exiting.
// Until we figure out how to close them before exit, we always destroy them
!Ni || // If the pool is destroyed, there is no reason to keep the worker around
this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
!this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
this.count > this._getMaxConcurrency() ? (e.destroy(), this.count--) : this.idleQueue.push(e), this.isDestroyed || this._startQueuedJob();
}
/**
* Returns idle worker or creates new worker if maxConcurrency has not been reached
*/
_getAvailableWorker() {
if (this.idleQueue.length > 0)
return this.idleQueue.shift() || null;
if (this.count < this._getMaxConcurrency()) {
this.count++;
const e = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
return new V0({ name: e, source: this.source, url: this.url });
}
return null;
}
_getMaxConcurrency() {
return MM ? this.maxMobileConcurrency : this.maxConcurrency;
}
}
const OM = {
maxConcurrency: 3,
maxMobileConcurrency: 1,
reuseWorkers: !0,
onDebug: () => {
}
}, Kn = class Kn {
/** get global instance with WorkerFarm.getWorkerFarm() */
constructor(e) {
E(this, "props");
E(this, "workerPools", /* @__PURE__ */ new Map());
this.props = { ...OM }, this.setProps(e), this.workerPools = /* @__PURE__ */ new Map();
}
/** Checks if workers are supported on this platform */
static isSupported() {
return V0.isSupported();
}
/** Get the singleton instance of the global worker farm */
static getWorkerFarm(e = {}) {
return Kn._workerFarm = Kn._workerFarm || new Kn({}), Kn._workerFarm.setProps(e), Kn._workerFarm;
}
/**
* Terminate all workers in the farm
* @note Can free up significant memory
*/
destroy() {
for (const e of this.workerPools.values())
e.destroy();
this.workerPools = /* @__PURE__ */ new Map();
}
/**
* Set props used when initializing worker pools
* @param props
*/
setProps(e) {
this.props = { ...this.props, ...e };
for (const r of this.workerPools.values())
r.setProps(this._getWorkerPoolProps());
}
/**
* Returns a worker pool for the specified worker
* @param options - only used first time for a specific worker name
* @param options.name - the name of the worker - used to identify worker pool
* @param options.url -
* @param options.source -
* @example
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
*/
getWorkerPool(e) {
const { name: r, source: n, url: i } = e;
let o = this.workerPools.get(r);
return o || (o = new IM({
name: r,
source: n,
url: i
}), o.setProps(this._getWorkerPoolProps()), this.workerPools.set(r, o)), o;
}
_getWorkerPoolProps() {
return {
maxConcurrency: this.props.maxConcurrency,
maxMobileConcurrency: this.props.maxMobileConcurrency,
reuseWorkers: this.props.reuseWorkers,
onDebug: this.props.onDebug
};
}
};
// singleton
E(Kn, "_workerFarm");
let hu = Kn;
function BM(t, e = {}) {
const r = e[t.id] || {}, n = Ni ? `${t.id}-worker.js` : `${t.id}-worker-node.js`;
let i = r.workerUrl;
if (!i && t.id === "compression" && (i = e.workerUrl), e._workerType === "test" && (Ni ? i = `modules/${t.module}/dist/${n}` : i = `modules/${t.module}/src/workers/${t.id}-worker-node.ts`), !i) {
let o = t.version;
o === "latest" && (o = EM);
const s = o ? `@${o}` : "";
i = `https://unpkg.com/@loaders.gl/${t.module}${s}/dist/${n}`;
}
return ui(i), i;
}
function NM(t, e = RM) {
ui(t, "no worker provided");
const r = t.version;
return !(!e || !r);
}
function qM(t, e) {
return !hu.isSupported() || !Ni && !(e != null && e._nodeWorkers) ? !1 : t.worker && (e == null ? void 0 : e.worker);
}
async function DM(t, e, r, n, i) {
const o = t.id, s = BM(t, r), l = hu.getWorkerFarm(r).getWorkerPool({ name: o, url: s });
r = JSON.parse(JSON.stringify(r)), n = JSON.parse(JSON.stringify(n || {}));
const u = await l.startJob(
"process-on-worker",
// @ts-expect-error
$M.bind(null, i)
// eslint-disable-line @typescript-eslint/no-misused-promises
);
return u.postMessage("process", {
// @ts-ignore
input: e,
options: r,
context: n
}), await (await u.result).result;
}
async function $M(t, e, r, n) {
switch (r) {
case "done":
e.done(n);
break;
case "error":
e.error(new Error(n.error));
break;
case "process":
const { id: i, input: o, options: s } = n;
try {
const a = await t(o, s);
e.postMessage("done", { id: i, result: a });
} catch (a) {
const l = a instanceof Error ? a.message : "unknown error";
e.postMessage("error", { id: i, error: l });
}
break;
default:
console.warn(`parse-with-worker unknown message ${r}`);
}
}
function LM(t, e, r) {
if (r = r || t.byteLength, t.byteLength < r || e.byteLength < r)
return !1;
const n = new Uint8Array(t), i = new Uint8Array(e);
for (let o = 0; o < n.length; ++o)
if (n[o] !== i[o])
return !1;
return !0;
}
function FM(...t) {
return UM(t);
}
function UM(t) {
const e = t.map((o) => o instanceof ArrayBuffer ? new Uint8Array(o) : o), r = e.reduce((o, s) => o + s.byteLength, 0), n = new Uint8Array(r);
let i = 0;
for (const o of e)
n.set(o, i), i += o.byteLength;
return n.buffer;
}
async function jM(t) {
const e = [];
for await (const r of t)
e.push(r);
return FM(...e);
}
function Bb() {
let t;
if (typeof window < "u" && window.performance)
t = window.performance.now();
else if (typeof Ce < "u" && Ce.hrtime) {
const e = Ce.hrtime();
t = e[0] * 1e3 + e[1] / 1e6;
} else
t = Date.now();
return t;
}
class Nb {
constructor(e, r) {
this.sampleSize = 1, this.time = 0, this.count = 0, this.samples = 0, this.lastTiming = 0, this.lastSampleTime = 0, this.lastSampleCount = 0, this._count = 0, this._time = 0, this._samples = 0, this._startTime = 0, this._timerPending = !1, this.name = e, this.type = r, this.reset();
}
reset() {
return this.time = 0, this.count = 0, this.samples = 0, this.lastTiming = 0, this.lastSampleTime = 0, this.lastSampleCount = 0, this._count = 0, this._time = 0, this._samples = 0, this._startTime = 0, this._timerPending = !1, this;
}
setSampleSize(e) {
return this.sampleSize = e, this;
}
/** Call to increment count (+1) */
incrementCount() {
return this.addCount(1), this;
}
/** Call to decrement count (-1) */
decrementCount() {
return this.subtractCount(1), this;
}
/** Increase count */
addCount(e) {
return this._count += e, this._samples++, this._checkSampling(), this;
}
/** Decrease count */
subtractCount(e) {
return this._count -= e, this._samples++, this._checkSampling(), this;
}
/** Add an arbitrary timing and bump the count */
addTime(e) {
return this._time += e, this.lastTiming = e, this._samples++, this._checkSampling(), this;
}
/** Start a timer */
timeStart() {
return this._startTime = Bb(), this._timerPending = !0, this;
}
/** End a timer. Adds to time and bumps the timing count. */
timeEnd() {
return this._timerPending ? (this.addTime(Bb() - this._startTime), this._timerPending = !1, this._checkSampling(), this) : this;
}
getSampleAverageCount() {
return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
}
/** Calculate average time / count for the previous window */
getSampleAverageTime() {
return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
}
/** Calculate counts per second for the previous window */
getSampleHz() {
return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
}
getAverageCount() {
return this.samples > 0 ? this.count / this.samples : 0;
}
/** Calculate average time / count */
getAverageTime() {
return this.samples > 0 ? this.time / this.samples : 0;
}
/** Calculate counts per second */
getHz() {
return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
}
_checkSampling() {
this._samples === this.sampleSize && (this.lastSampleTime = this._time, this.lastSampleCount = this._count, this.count += this._count, this.time += this._time, this.samples += this._samples, this._time = 0, this._count = 0, this._samples = 0);
}
}
class Pc {
constructor(e) {
this.stats = {}, this.id = e.id, this.stats = {}, this._initializeStats(e.stats), Object.seal(this);
}
/** Acquire a stat. Create if it doesn't exist. */
get(e, r = "count") {
return this._getOrCreate({ name: e, type: r });
}
get size() {
return Object.keys(this.stats).length;
}
/** Reset all stats */
reset() {
for (const e of Object.values(this.stats))
e.reset();
return this;
}
forEach(e) {
for (const r of Object.values(this.stats))
e(r);
}
getTable() {
const e = {};
return this.forEach((r) => {
e[r.name] = {
time: r.time || 0,
count: r.count || 0,
average: r.getAverageTime() || 0,
hz: r.getHz() || 0
};
}), e;
}
_initializeStats(e = []) {
e.forEach((r) => this._getOrCreate(r));
}
_getOrCreate(e) {
const { name: r, type: n } = e;
let i = this.stats[r];
return i || (e instanceof Nb ? i = e : i = new Nb(r, n), this.stats[r] = i), i;
}
}
let zM = "";
const qb = {};
function HM(t) {
for (const e in qb)
if (t.startsWith(e)) {
const r = qb[e];
t = t.replace(e, r);
}
return !t.startsWith("http://") && !t.startsWith("https://") && (t = `${zM}${t}`), t;
}
function WM(t) {
return t && typeof t == "object" && t.isBuffer;
}
function i6(t) {
if (WM(t))
return t;
if (t instanceof ArrayBuffer)
return t;
if (ArrayBuffer.isView(t))
return t.byteOffset === 0 && t.byteLength === t.buffer.byteLength ? t.buffer : t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength);
if (typeof t == "string") {
const e = t;
return new TextEncoder().encode(e).buffer;
}
if (t && typeof t == "object" && t._toArrayBuffer)
return t._toArrayBuffer();
throw new Error("toArrayBuffer");
}
function o6(t) {
const e = t ? t.lastIndexOf("/") : -1;
return e >= 0 ? t.substr(e + 1) : "";
}
function VM(t) {
const e = t ? t.lastIndexOf("/") : -1;
return e >= 0 ? t.substr(0, e) : "";
}
const XM = (t) => typeof t == "boolean", ua = (t) => typeof t == "function", La = (t) => t !== null && typeof t == "object", Db = (t) => La(t) && t.constructor === {}.constructor, KM = (t) => !!t && typeof t[Symbol.iterator] == "function", ZM = (t) => t && typeof t[Symbol.asyncIterator] == "function", Yi = (t) => typeof Response < "u" && t instanceof Response || t && t.arrayBuffer && t.text && t.json, Ji = (t) => typeof Blob < "u" && t instanceof Blob, GM = (t) => t && typeof t == "object" && t.isBuffer, YM = (t) => typeof ReadableStream < "u" && t instanceof ReadableStream || La(t) && ua(t.tee) && ua(t.cancel) && ua(t.getReader), JM = (t) => La(t) && ua(t.read) && ua(t.pipe) && XM(t.readable), s6 = (t) => YM(t) || JM(t);
class QM extends Error {
constructor(r, n) {
super(r);
/** A best effort reason for why the fetch failed */
E(this, "reason");
/** The URL that failed to load. Empty string if not available. */
E(this, "url");
/** The Response object, if any. */
E(this, "response");
this.reason = n.reason, this.url = n.url, this.response = n.response;
}
}
const eT = /^data:([-\w.]+\/[-\w.+]+)(;|,)/, tT = /^([-\w.]+\/[-\w.+]+)/;
function $b(t, e) {
return t.toLowerCase() === e.toLowerCase();
}
function rT(t) {
const e = tT.exec(t);
return e ? e[1] : t;
}
function Lb(t) {
const e = eT.exec(t);
return e ? e[1] : "";
}
const a6 = /\?.*/;
function nT(t) {
const e = t.match(a6);
return e && e[0];
}
function _m(t) {
return t.replace(a6, "");
}
function iT(t) {
if (t.length < 50)
return t;
const e = t.slice(t.length - 15);
return `${t.substr(0, 32)}...${e}`;
}
function Ic(t) {
return Yi(t) ? t.url : Ji(t) ? t.name || "" : typeof t == "string" ? t : "";
}
function wm(t) {
if (Yi(t)) {
const e = t, r = e.headers.get("content-type") || "", n = _m(e.url);
return rT(r) || Lb(n);
}
return Ji(t) ? t.type || "" : typeof t == "string" ? Lb(t) : "";
}
function oT(t) {
return Yi(t) ? t.headers["content-length"] || -1 : Ji(t) ? t.size : typeof t == "string" ? t.length : t instanceof ArrayBuffer || ArrayBuffer.isView(t) ? t.byteLength : -1;
}
async function l6(t) {
if (Yi(t))
return t;
const e = {}, r = oT(t);
r >= 0 && (e["content-length"] = String(r));
const n = Ic(t), i = wm(t);
i && (e["content-type"] = i);
const o = await lT(t);
o && (e["x-first-bytes"] = o), typeof t == "string" && (t = new TextEncoder().encode(t));
const s = new Response(t, { headers: e });
return Object.defineProperty(s, "url", { value: n }), s;
}
async function sT(t) {
if (!t.ok)
throw await aT(t);
}
async function aT(t) {
const e = iT(t.url);
let r = `Failed to fetch resource (${t.status}) ${t.statusText}: ${e}`;
r = r.length > 100 ? `${r.slice(0, 100)}...` : r;
const n = {
reason: t.statusText,
url: t.url,
response: t
};
try {
const i = t.headers.get("Content-Type");
n.reason = !t.bodyUsed && (i != null && i.includes("application/json")) ? await t.json() : await t.text();
} catch {
}
return new QM(r, n);
}
async function lT(t) {
if (typeof t == "string")
return `data:,${t.slice(0, 5)}`;
if (t instanceof Blob) {
const r = t.slice(0, 5);
return await new Promise((n) => {
const i = new FileReader();
i.onload = (o) => {
var s;
return n((s = o == null ? void 0 : o.target) == null ? void 0 : s.result);
}, i.readAsDataURL(r);
});
}
if (t instanceof ArrayBuffer) {
const r = t.slice(0, 5);
return `data:base64,${uT(r)}`;
}
return null;
}
function uT(t) {
let e = "";
const r = new Uint8Array(t);
for (let n = 0; n < r.byteLength; n++)
e += String.fromCharCode(r[n]);
return btoa(e);
}
function cT(t) {
return !fT(t) && !hT(t);
}
function fT(t) {
return t.startsWith("http:") || t.startsWith("https:");
}
function hT(t) {
return t.startsWith("data:");
}
async function Fb(t, e) {
var r, n;
if (typeof t == "string") {
const i = HM(t);
return cT(i) && (r = globalThis.loaders) != null && r.fetchNode ? (n = globalThis.loaders) == null ? void 0 : n.fetchNode(i, e) : await fetch(i, e);
}
return await l6(t);
}
const Ub = new $a({ id: "loaders.gl" });
class dT {
log() {
return () => {
};
}
info() {
return () => {
};
}
warn() {
return () => {
};
}
error() {
return () => {
};
}
}
class pT {
constructor() {
E(this, "console");
this.console = console;
}
log(...e) {
return this.console.log.bind(this.console, ...e);
}
info(...e) {
return this.console.info.bind(this.console, ...e);
}
warn(...e) {
return this.console.warn.bind(this.console, ...e);
}
error(...e) {
return this.console.error.bind(this.console, ...e);
}
}
const u6 = {
// baseUri
fetch: null,
mimeType: void 0,
nothrow: !1,
log: new pT(),
// A probe.gl compatible (`log.log()()` syntax) that just logs to console
useLocalLibraries: !1,
CDN: "https://unpkg.com/@loaders.gl",
worker: !0,
// By default, use worker if provided by loader.
maxConcurrency: 3,
// How many worker instances should be created for each loader.
maxMobileConcurrency: 1,
// How many worker instances should be created for each loader on mobile devices.
reuseWorkers: ym,
// By default reuse workers in browser (Node.js refuses to terminate if browsers are running)
_nodeWorkers: !1,
// By default do not support node workers
_workerType: "",
// 'test' to use locally generated workers
limit: 0,
_limitMB: 0,
batchSize: "auto",
batchDebounceMs: 0,
metadata: !1,
// TODO - currently only implemented for parseInBatches, adds initial metadata batch,
transforms: []
}, gT = {
throws: "nothrow",
dataType: "(no longer used)",
uri: "baseUri",
// Warn if fetch options are used on top-level
method: "fetch.method",
headers: "fetch.headers",
body: "fetch.body",
mode: "fetch.mode",
credentials: "fetch.credentials",
cache: "fetch.cache",
redirect: "fetch.redirect",
referrer: "fetch.referrer",
referrerPolicy: "fetch.referrerPolicy",
integrity: "fetch.integrity",
keepalive: "fetch.keepalive",
signal: "fetch.signal"
};
function c6() {
globalThis.loaders = globalThis.loaders || {};
const { loaders: t } = globalThis;
return t._state || (t._state = {}), t._state;
}
function f6() {
const t = c6();
return t.globalOptions = t.globalOptions || { ...u6 }, t.globalOptions;
}
function mT(t, e, r, n) {
return r = r || [], r = Array.isArray(r) ? r : [r], bT(t, r), vT(e, t, n);
}
function bT(t, e) {
jb(t, null, u6, gT, e);
for (const r of e) {
const n = t && t[r.id] || {}, i = r.options && r.options[r.id] || {}, o = r.deprecatedOptions && r.deprecatedOptions[r.id] || {};
jb(n, r.id, i, o, e);
}
}
function jb(t, e, r, n, i) {
const o = e || "Top level", s = e ? `${e}.` : "";
for (const a in t) {
const l = !e && La(t[a]), u = a === "baseUri" && !e, c = a === "workerUrl" && e;
if (!(a in r) && !u && !c) {
if (a in n)
Ub.warn(`${o} loader option '${s}${a}' no longer supported, use '${n[a]}'`)();
else if (!l) {
const f = yT(a, i);
Ub.warn(`${o} loader option '${s}${a}' not recognized. ${f}`)();
}
}
}
}
function yT(t, e) {
const r = t.toLowerCase();
let n = "";
for (const i of e)
for (const o in i.options) {
if (t === o)
return `Did you mean '${i.id}.${o}'?`;
const s = o.toLowerCase();
(r.startsWith(s) || s.startsWith(r)) && (n = n || `Did you mean '${i.id}.${o}'?`);
}
return n;
}
function vT(t, e, r) {
const i = { ...t.options || {} };
return _T(i, r), i.log === null && (i.log = new dT()), zb(i, f6()), zb(i, e), i;
}
function zb(t, e) {
for (const r in e)
if (r in e) {
const n = e[r];
Db(n) && Db(t[r]) ? t[r] = {
...t[r],
...e[r]
} : t[r] = e[r];
}
}
function _T(t, e) {
e && !("baseUri" in t) && (t.baseUri = e);
}
function xm(t) {
return t ? (Array.isArray(t) && (t = t[0]), Array.isArray(t == null ? void 0 : t.extensions)) : !1;
}
function Sm(t) {
cu(t, "null loader"), cu(xm(t), "invalid loader");
let e;
return Array.isArray(t) && (e = t[1], t = t[0], t = {
...t,
options: { ...t.options, ...e }
}), (t != null && t.parseTextSync || t != null && t.parseText) && (t.text = !0), t.text || (t.binary = !0), t;
}
const h6 = () => {
const t = c6();
return t.loaderRegistry = t.loaderRegistry || [], t.loaderRegistry;
};
function wT(t) {
const e = h6();
t = Array.isArray(t) ? t : [t];
for (const r of t) {
const n = Sm(r);
e.find((i) => n === i) || e.unshift(n);
}
}
function xT() {
return h6();
}
const ST = /\.([^.]+)$/;
async function ET(t, e = [], r, n) {
if (!d6(t))
return null;
let i = Hb(t, e, { ...r, nothrow: !0 }, n);
if (i)
return i;
if (Ji(t) && (t = await t.slice(0, 10).arrayBuffer(), i = Hb(t, e, r, n)), !i && !(r != null && r.nothrow))
throw new Error(p6(t));
return i;
}
function Hb(t, e = [], r, n) {
if (!d6(t))
return null;
if (e && !Array.isArray(e))
return Sm(e);
let i = [];
e && (i = i.concat(e)), r != null && r.ignoreRegisteredLoaders || i.push(...xT()), RT(i);
const o = AT(t, i, r, n);
if (!o && !(r != null && r.nothrow))
throw new Error(p6(t));
return o;
}
function AT(t, e, r, n) {
const i = Ic(t), o = wm(t), s = _m(i) || (n == null ? void 0 : n.url);
let a = null, l = "";
return r != null && r.mimeType && (a = Bf(e, r == null ? void 0 : r.mimeType), l = `match forced by supplied MIME type ${r == null ? void 0 : r.mimeType}`), a = a || MT(e, s), l = l || (a ? `matched url ${s}` : ""), a = a || Bf(e, o), l = l || (a ? `matched MIME type ${o}` : ""), a = a || CT(e, t), l = l || (a ? `matched initial data ${g6(t)}` : ""), r != null && r.fallbackMimeType && (a = a || Bf(e, r == null ? void 0 : r.fallbackMimeType), l = l || (a ? `matched fallback MIME type ${o}` : "")), l && xM.log(1, `selectLoader selected ${a == null ? void 0 : a.name}: ${l}.`), a;
}
function d6(t) {
return !(t instanceof Response && t.status === 204);
}
function p6(t) {
const e = Ic(t), r = wm(t);
let n = "No valid loader found (";
n += e ? `${o6(e)}, ` : "no url provided, ", n += `MIME type: ${r ? `"${r}"` : "not provided"}, `;
const i = t ? g6(t) : "";
return n += i ? ` first bytes: "${i}"` : "first bytes: not available", n += ")", n;
}
function RT(t) {
for (const e of t)
Sm(e);
}
function MT(t, e) {
const r = e && ST.exec(e), n = r && r[1];
return n ? TT(t, n) : null;
}
function TT(t, e) {
e = e.toLowerCase();
for (const r of t)
for (const n of r.extensions)
if (n.toLowerCase() === e)
return r;
return null;
}
function Bf(t, e) {
var r;
for (const n of t)
if ((r = n.mimeTypes) != null && r.some((i) => $b(e, i)) || $b(e, `application/x.${n.id}`))
return n;
return null;
}
function CT(t, e) {
if (!e)
return null;
for (const r of t)
if (typeof e == "string") {
if (kT(e, r))
return r;
} else if (ArrayBuffer.isView(e)) {
if (Wb(e.buffer, e.byteOffset, r))
return r;
} else if (e instanceof ArrayBuffer && Wb(e, 0, r))
return r;
return null;
}
function kT(t, e) {
return e.testText ? e.testText(t) : (Array.isArray(e.tests) ? e.tests : [e.tests]).some((n) => t.startsWith(n));
}
function Wb(t, e, r) {
return (Array.isArray(r.tests) ? r.tests : [r.tests]).some((i) => PT(t, e, r, i));
}
function PT(t, e, r, n) {
if (n instanceof ArrayBuffer)
return LM(n, t, n.byteLength);
switch (typeof n) {
case "function":
return n(t);
case "string":
const i = X0(t, e, n.length);
return n === i;
default:
return !1;
}
}
function g6(t, e = 5) {
return typeof t == "string" ? t.slice(0, e) : ArrayBuffer.isView(t) ? X0(t.buffer, t.byteOffset, e) : t instanceof ArrayBuffer ? X0(t, 0, e) : "";
}
function X0(t, e, r) {
if (t.byteLength < e + r)
return "";
const n = new DataView(t);
let i = "";
for (let o = 0; o < r; o++)
i += String.fromCharCode(n.getUint8(e + o));
return i;
}
const IT = 256 * 1024;
function* OT(t, e) {
const r = (e == null ? void 0 : e.chunkSize) || IT;
let n = 0;
const i = new TextEncoder();
for (; n < t.length; ) {
const o = Math.min(t.length - n, r), s = t.slice(n, n + o);
n += o, yield i.encode(s);
}
}
const BT = 256 * 1024;
function* NT(t, e = {}) {
const { chunkSize: r = BT } = e;
let n = 0;
for (; n < t.byteLength; ) {
const i = Math.min(t.byteLength - n, r), o = new ArrayBuffer(i), s = new Uint8Array(t, n, i);
new Uint8Array(o).set(s), n += i, yield o;
}
}
const qT = 1024 * 1024;
async function* DT(t, e) {
const r = (e == null ? void 0 : e.chunkSize) || qT;
let n = 0;
for (; n < t.size; ) {
const i = n + r, o = await t.slice(n, i).arrayBuffer();
n = i, yield o;
}
}
function Vb(t, e) {
return ym ? $T(t, e) : LT(t);
}
async function* $T(t, e) {
const r = t.getReader();
let n;
try {
for (; ; ) {
const i = n || r.read();
e != null && e._streamReadAhead && (n = r.read());
const { done: o, value: s } = await i;
if (o)
return;
yield i6(s);
}
} catch {
r.releaseLock();
}
}
async function* LT(t, e) {
for await (const r of t)
yield i6(r);
}
function FT(t, e) {
if (typeof t == "string")
return OT(t, e);
if (t instanceof ArrayBuffer)
return NT(t, e);
if (Ji(t))
return DT(t, e);
if (s6(t))
return Vb(t, e);
if (Yi(t))
return Vb(t.body, e);
throw new Error("makeIterator");
}
const m6 = "Cannot convert supplied data type";
function UT(t, e, r) {
if (e.text && typeof t == "string")
return t;
if (GM(t) && (t = t.buffer), t instanceof ArrayBuffer) {
const n = t;
return e.text && !e.binary ? new TextDecoder("utf8").decode(n) : n;
}
if (ArrayBuffer.isView(t)) {
if (e.text && !e.binary)
return new TextDecoder("utf8").decode(t);
let n = t.buffer;
const i = t.byteLength || t.length;
return (t.byteOffset !== 0 || i !== n.byteLength) && (n = n.slice(t.byteOffset, t.byteOffset + i)), n;
}
throw new Error(m6);
}
async function jT(t, e, r) {
const n = t instanceof ArrayBuffer || ArrayBuffer.isView(t);
if (typeof t == "string" || n)
return UT(t, e);
if (Ji(t) && (t = await l6(t)), Yi(t)) {
const i = t;
return await sT(i), e.binary ? await i.arrayBuffer() : await i.text();
}
if (s6(t) && (t = FT(t, r)), KM(t) || ZM(t))
return jM(t);
throw new Error(m6);
}
function b6(t, e) {
const r = f6(), n = t || r;
return typeof n.fetch == "function" ? n.fetch : La(n.fetch) ? (i) => Fb(i, n.fetch) : e != null && e.fetch ? e == null ? void 0 : e.fetch : Fb;
}
function zT(t, e, r) {
if (r)
return r;
const n = {
fetch: b6(e, t),
...t
};
if (n.url) {
const i = _m(n.url);
n.baseUrl = i, n.queryString = nT(n.url), n.filename = o6(i), n.baseUrl = VM(i);
}
return Array.isArray(n.loaders) || (n.loaders = null), n;
}
function HT(t, e) {
if (t && !Array.isArray(t))
return t;
let r;
if (t && (r = Array.isArray(t) ? t : [t]), e && e.loaders) {
const n = Array.isArray(e.loaders) ? e.loaders : [e.loaders];
r = r ? [...r, ...n] : n;
}
return r && r.length ? r : void 0;
}
async function du(t, e, r, n) {
e && !Array.isArray(e) && !xm(e) && (n = void 0, r = e, e = void 0), t = await t, r = r || {};
const i = Ic(t), s = HT(e, n), a = await ET(t, s, r);
return a ? (r = mT(r, a, s, i), n = zT(
// @ts-expect-error
{ url: i, _parse: du, loaders: s },
r,
n || null
), await WT(a, t, r, n)) : null;
}
async function WT(t, e, r, n) {
if (NM(t), r = SM(t.options, r), Yi(e)) {
const o = e, { ok: s, redirected: a, status: l, statusText: u, type: c, url: f } = o, h = Object.fromEntries(o.headers.entries());
n.response = { headers: h, ok: s, redirected: a, status: l, statusText: u, type: c, url: f };
}
e = await jT(e, t, r);
const i = t;
if (i.parseTextSync && typeof e == "string")
return i.parseTextSync(e, r, n);
if (qM(t, r))
return await DM(t, e, r, n, du);
if (i.parseText && typeof e == "string")
return await i.parseText(e, r, n);
if (i.parse)
return await i.parse(e, r, n);
throw ui(!i.parseSync), new Error(`${t.id} loader - no parser found and worker is disabled`);
}
async function pu(t, e, r, n) {
let i, o;
!Array.isArray(e) && !xm(e) ? (i = [], o = e) : (i = e, o = r);
const s = b6(o);
let a = t;
return typeof t == "string" && (a = await s(t)), Ji(t) && (a = await s(t)), Array.isArray(i) ? await du(a, i, o) : await du(a, i, o);
}
const VT = "4.3.3";
var zS;
const XT = (zS = globalThis.loaders) == null ? void 0 : zS.parseImageNode, K0 = typeof Image < "u", Z0 = typeof ImageBitmap < "u", KT = !!XT, G0 = ym ? !0 : KT;
function ZT(t) {
switch (t) {
case "auto":
return Z0 || K0 || G0;
case "imagebitmap":
return Z0;
case "image":
return K0;
case "data":
return G0;
default:
throw new Error(`@loaders.gl/images: image ${t} not supported in this environment`);
}
}
function GT() {
if (Z0)
return "imagebitmap";
if (K0)
return "image";
if (G0)
return "data";
throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js");
}
function YT(t) {
const e = QT(t);
if (!e)
throw new Error("Not an image");
return e;
}
function JT(t) {
switch (YT(t)) {
case "data":
return t;
case "image":
case "imagebitmap":
const e = document.createElement("canvas"), r = e.getContext("2d");
if (!r)
throw new Error("getImageData");
return e.width = t.width, e.height = t.height, r.drawImage(t, 0, 0), r.getImageData(0, 0, t.width, t.height);
default:
throw new Error("getImageData");
}
}
function QT(t) {
return typeof ImageBitmap < "u" && t instanceof ImageBitmap ? "im