@pdf-viewer/react
Version:
A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.
1,370 lines (1,369 loc) • 40.5 kB
JavaScript
var we = (t, e, s) => {
if (!e.has(t))
throw TypeError("Cannot " + s);
};
var i = (t, e, s) => (we(t, e, "read from private field"), s ? s.call(t) : e.get(t)), l = (t, e, s) => {
if (e.has(t))
throw TypeError("Cannot add the same private member more than once");
e instanceof WeakSet ? e.add(t) : e.set(t, s);
}, o = (t, e, s, r) => (we(t, e, "write to private field"), r ? r.call(t, s) : e.set(t, s), s);
var ye = (t, e, s, r) => ({
set _(n) {
o(t, e, n, s);
},
get _() {
return i(t, e, r);
}
}), P = (t, e, s) => (we(t, e, "access private method"), s);
import { jsx as oe } from "react/jsx-runtime";
import { RPTheme as ze } from "./RPTheme.js";
import { ConfigContextProvider as Be } from "../contexts/ConfigContext.js";
import { useLoadWorker as Je } from "../utils/hooks/useLoadWorker.js";
import * as He from "react";
import { LicenseProvider as We } from "../contexts/LicenseContext.js";
var ge = class {
constructor() {
this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
}
subscribe(t) {
return this.listeners.add(t), this.onSubscribe(), () => {
this.listeners.delete(t), this.onUnsubscribe();
};
}
hasListeners() {
return this.listeners.size > 0;
}
onSubscribe() {
}
onUnsubscribe() {
}
}, be = typeof window > "u" || "Deno" in globalThis;
function Q() {
}
function Xe(t, e) {
return typeof t == "function" ? t(e) : t;
}
function Ye(t) {
return typeof t == "number" && t >= 0 && t !== 1 / 0;
}
function Ze(t, e) {
return Math.max(t + (e || 0) - Date.now(), 0);
}
function Ce(t, e) {
return typeof t == "function" ? t(e) : t;
}
function et(t, e) {
return typeof t == "function" ? t(e) : t;
}
function qe(t, e) {
const {
type: s = "all",
exact: r,
fetchStatus: n,
predicate: u,
queryKey: h,
stale: a
} = t;
if (h) {
if (r) {
if (e.queryHash !== Fe(h, e.options))
return !1;
} else if (!ce(e.queryKey, h))
return !1;
}
if (s !== "all") {
const f = e.isActive();
if (s === "active" && !f || s === "inactive" && f)
return !1;
}
return !(typeof a == "boolean" && e.isStale() !== a || n && n !== e.state.fetchStatus || u && !u(e));
}
function Ee(t, e) {
const { exact: s, status: r, predicate: n, mutationKey: u } = t;
if (u) {
if (!e.options.mutationKey)
return !1;
if (s) {
if (he(e.options.mutationKey) !== he(u))
return !1;
} else if (!ce(e.options.mutationKey, u))
return !1;
}
return !(r && e.state.status !== r || n && !n(e));
}
function Fe(t, e) {
return ((e == null ? void 0 : e.queryKeyHashFn) || he)(t);
}
function he(t) {
return JSON.stringify(
t,
(e, s) => Se(s) ? Object.keys(s).sort().reduce((r, n) => (r[n] = s[n], r), {}) : s
);
}
function ce(t, e) {
return t === e ? !0 : typeof t != typeof e ? !1 : t && e && typeof t == "object" && typeof e == "object" ? !Object.keys(e).some((s) => !ce(t[s], e[s])) : !1;
}
function Oe(t, e) {
if (t === e)
return t;
const s = De(t) && De(e);
if (s || Se(t) && Se(e)) {
const r = s ? t : Object.keys(t), n = r.length, u = s ? e : Object.keys(e), h = u.length, a = s ? [] : {};
let f = 0;
for (let w = 0; w < h; w++) {
const m = s ? w : u[w];
(!s && r.includes(m) || s) && t[m] === void 0 && e[m] === void 0 ? (a[m] = void 0, f++) : (a[m] = Oe(t[m], e[m]), a[m] === t[m] && t[m] !== void 0 && f++);
}
return n === h && f === n ? t : a;
}
return e;
}
function De(t) {
return Array.isArray(t) && t.length === Object.keys(t).length;
}
function Se(t) {
if (!Ae(t))
return !1;
const e = t.constructor;
if (e === void 0)
return !0;
const s = e.prototype;
return !(!Ae(s) || !s.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(t) !== Object.prototype);
}
function Ae(t) {
return Object.prototype.toString.call(t) === "[object Object]";
}
function tt(t) {
return new Promise((e) => {
setTimeout(e, t);
});
}
function st(t, e, s) {
if (typeof s.structuralSharing == "function")
return s.structuralSharing(t, e);
if (s.structuralSharing !== !1) {
if (process.env.NODE_ENV !== "production")
try {
return Oe(t, e);
} catch (r) {
console.error(
`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${s.queryHash}]: ${r}`
);
}
return Oe(t, e);
}
return e;
}
function rt(t, e, s = 0) {
const r = [...t, e];
return s && r.length > s ? r.slice(1) : r;
}
function it(t, e, s = 0) {
const r = [e, ...t];
return s && r.length > s ? r.slice(0, -1) : r;
}
var me = Symbol();
function Le(t, e) {
return process.env.NODE_ENV !== "production" && t.queryFn === me && console.error(
`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${t.queryHash}'`
), !t.queryFn && (e != null && e.initialPromise) ? () => e.initialPromise : !t.queryFn || t.queryFn === me ? () => Promise.reject(new Error(`Missing queryFn: '${t.queryHash}'`)) : t.queryFn;
}
var B, N, Z, Re, nt = (Re = class extends ge {
constructor() {
super();
l(this, B, void 0);
l(this, N, void 0);
l(this, Z, void 0);
o(this, Z, (e) => {
if (!be && window.addEventListener) {
const s = () => e();
return window.addEventListener("visibilitychange", s, !1), () => {
window.removeEventListener("visibilitychange", s);
};
}
});
}
onSubscribe() {
i(this, N) || this.setEventListener(i(this, Z));
}
onUnsubscribe() {
var e;
this.hasListeners() || ((e = i(this, N)) == null || e.call(this), o(this, N, void 0));
}
setEventListener(e) {
var s;
o(this, Z, e), (s = i(this, N)) == null || s.call(this), o(this, N, e((r) => {
typeof r == "boolean" ? this.setFocused(r) : this.onFocus();
}));
}
setFocused(e) {
i(this, B) !== e && (o(this, B, e), this.onFocus());
}
onFocus() {
const e = this.isFocused();
this.listeners.forEach((s) => {
s(e);
});
}
isFocused() {
var e;
return typeof i(this, B) == "boolean" ? i(this, B) : ((e = globalThis.document) == null ? void 0 : e.visibilityState) !== "hidden";
}
}, B = new WeakMap(), N = new WeakMap(), Z = new WeakMap(), Re), Ne = new nt(), ee, G, te, Te, at = (Te = class extends ge {
constructor() {
super();
l(this, ee, !0);
l(this, G, void 0);
l(this, te, void 0);
o(this, te, (e) => {
if (!be && window.addEventListener) {
const s = () => e(!0), r = () => e(!1);
return window.addEventListener("online", s, !1), window.addEventListener("offline", r, !1), () => {
window.removeEventListener("online", s), window.removeEventListener("offline", r);
};
}
});
}
onSubscribe() {
i(this, G) || this.setEventListener(i(this, te));
}
onUnsubscribe() {
var e;
this.hasListeners() || ((e = i(this, G)) == null || e.call(this), o(this, G, void 0));
}
setEventListener(e) {
var s;
o(this, te, e), (s = i(this, G)) == null || s.call(this), o(this, G, e(this.setOnline.bind(this)));
}
setOnline(e) {
i(this, ee) !== e && (o(this, ee, e), this.listeners.forEach((r) => {
r(e);
}));
}
isOnline() {
return i(this, ee);
}
}, ee = new WeakMap(), G = new WeakMap(), te = new WeakMap(), Te), ve = new at();
function ut() {
let t, e;
const s = new Promise((n, u) => {
t = n, e = u;
});
s.status = "pending", s.catch(() => {
});
function r(n) {
Object.assign(s, n), delete s.resolve, delete s.reject;
}
return s.resolve = (n) => {
r({
status: "fulfilled",
value: n
}), t(n);
}, s.reject = (n) => {
r({
status: "rejected",
reason: n
}), e(n);
}, s;
}
function ot(t) {
return Math.min(1e3 * 2 ** t, 3e4);
}
function Ge(t) {
return (t ?? "online") === "online" ? ve.isOnline() : !0;
}
var _e = class extends Error {
constructor(t) {
super("CancelledError"), this.revert = t == null ? void 0 : t.revert, this.silent = t == null ? void 0 : t.silent;
}
};
function Pe(t) {
return t instanceof _e;
}
function Ve(t) {
let e = !1, s = 0, r = !1, n;
const u = ut(), h = (c) => {
var p;
r || (y(new _e(c)), (p = t.abort) == null || p.call(t));
}, a = () => {
e = !0;
}, f = () => {
e = !1;
}, w = () => Ne.isFocused() && (t.networkMode === "always" || ve.isOnline()) && t.canRun(), m = () => Ge(t.networkMode) && t.canRun(), d = (c) => {
var p;
r || (r = !0, (p = t.onSuccess) == null || p.call(t, c), n == null || n(), u.resolve(c));
}, y = (c) => {
var p;
r || (r = !0, (p = t.onError) == null || p.call(t, c), n == null || n(), u.reject(c));
}, q = () => new Promise((c) => {
var p;
n = (E) => {
(r || w()) && c(E);
}, (p = t.onPause) == null || p.call(t);
}).then(() => {
var c;
n = void 0, r || (c = t.onContinue) == null || c.call(t);
}), S = () => {
if (r)
return;
let c;
const p = s === 0 ? t.initialPromise : void 0;
try {
c = p ?? t.fn();
} catch (E) {
c = Promise.reject(E);
}
Promise.resolve(c).then(d).catch((E) => {
var k;
if (r)
return;
const M = t.retry ?? (be ? 0 : 3), g = t.retryDelay ?? ot, D = typeof g == "function" ? g(s, E) : g, j = M === !0 || typeof M == "number" && s < M || typeof M == "function" && M(s, E);
if (e || !j) {
y(E);
return;
}
s++, (k = t.onFail) == null || k.call(t, s, E), tt(D).then(() => w() ? void 0 : q()).then(() => {
e ? y(E) : S();
});
});
};
return {
promise: u,
cancel: h,
continue: () => (n == null || n(), u),
cancelRetry: a,
continueRetry: f,
canStart: m,
start: () => (m() ? S() : q().then(S), u)
};
}
function ht() {
let t = [], e = 0, s = (a) => {
a();
}, r = (a) => {
a();
}, n = (a) => setTimeout(a, 0);
const u = (a) => {
e ? t.push(a) : n(() => {
s(a);
});
}, h = () => {
const a = t;
t = [], a.length && n(() => {
r(() => {
a.forEach((f) => {
s(f);
});
});
});
};
return {
batch: (a) => {
let f;
e++;
try {
f = a();
} finally {
e--, e || h();
}
return f;
},
/**
* All calls to the wrapped function will be batched.
*/
batchCalls: (a) => (...f) => {
u(() => {
a(...f);
});
},
schedule: u,
/**
* Use this method to set a custom notify function.
* This can be used to for example wrap notifications with `React.act` while running tests.
*/
setNotifyFunction: (a) => {
s = a;
},
/**
* Use this method to set a custom function to batch notifications together into a single tick.
* By default React Query will use the batch function provided by ReactDOM or React Native.
*/
setBatchNotifyFunction: (a) => {
r = a;
},
setScheduler: (a) => {
n = a;
}
};
}
var C = ht(), J, je, $e = (je = class {
constructor() {
l(this, J, void 0);
}
destroy() {
this.clearGcTimeout();
}
scheduleGc() {
this.clearGcTimeout(), Ye(this.gcTime) && o(this, J, setTimeout(() => {
this.optionalRemove();
}, this.gcTime));
}
updateGcTime(t) {
this.gcTime = Math.max(
this.gcTime || 0,
t ?? (be ? 1 / 0 : 5 * 60 * 1e3)
);
}
clearGcTimeout() {
i(this, J) && (clearTimeout(i(this, J)), o(this, J, void 0));
}
}, J = new WeakMap(), je), se, re, A, W, O, le, X, R, x, ke, ct = (ke = class extends $e {
constructor(e) {
super();
l(this, R);
l(this, se, void 0);
l(this, re, void 0);
l(this, A, void 0);
l(this, W, void 0);
l(this, O, void 0);
l(this, le, void 0);
l(this, X, void 0);
o(this, X, !1), o(this, le, e.defaultOptions), this.setOptions(e.options), this.observers = [], o(this, W, e.client), o(this, A, i(this, W).getQueryCache()), this.queryKey = e.queryKey, this.queryHash = e.queryHash, o(this, se, dt(this.options)), this.state = e.state ?? i(this, se), this.scheduleGc();
}
get meta() {
return this.options.meta;
}
get promise() {
var e;
return (e = i(this, O)) == null ? void 0 : e.promise;
}
setOptions(e) {
this.options = { ...i(this, le), ...e }, this.updateGcTime(this.options.gcTime);
}
optionalRemove() {
!this.observers.length && this.state.fetchStatus === "idle" && i(this, A).remove(this);
}
setData(e, s) {
const r = st(this.state.data, e, this.options);
return P(this, R, x).call(this, {
data: r,
type: "success",
dataUpdatedAt: s == null ? void 0 : s.updatedAt,
manual: s == null ? void 0 : s.manual
}), r;
}
setState(e, s) {
P(this, R, x).call(this, { type: "setState", state: e, setStateOptions: s });
}
cancel(e) {
var r, n;
const s = (r = i(this, O)) == null ? void 0 : r.promise;
return (n = i(this, O)) == null || n.cancel(e), s ? s.then(Q).catch(Q) : Promise.resolve();
}
destroy() {
super.destroy(), this.cancel({ silent: !0 });
}
reset() {
this.destroy(), this.setState(i(this, se));
}
isActive() {
return this.observers.some(
(e) => et(e.options.enabled, this) !== !1
);
}
isDisabled() {
return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === me || this.state.dataUpdateCount + this.state.errorUpdateCount === 0;
}
isStale() {
return this.state.isInvalidated ? !0 : this.getObserversCount() > 0 ? this.observers.some(
(e) => e.getCurrentResult().isStale
) : this.state.data === void 0;
}
isStaleByTime(e = 0) {
return this.state.isInvalidated || this.state.data === void 0 || !Ze(this.state.dataUpdatedAt, e);
}
onFocus() {
var s;
const e = this.observers.find((r) => r.shouldFetchOnWindowFocus());
e == null || e.refetch({ cancelRefetch: !1 }), (s = i(this, O)) == null || s.continue();
}
onOnline() {
var s;
const e = this.observers.find((r) => r.shouldFetchOnReconnect());
e == null || e.refetch({ cancelRefetch: !1 }), (s = i(this, O)) == null || s.continue();
}
addObserver(e) {
this.observers.includes(e) || (this.observers.push(e), this.clearGcTimeout(), i(this, A).notify({ type: "observerAdded", query: this, observer: e }));
}
removeObserver(e) {
this.observers.includes(e) && (this.observers = this.observers.filter((s) => s !== e), this.observers.length || (i(this, O) && (i(this, X) ? i(this, O).cancel({ revert: !0 }) : i(this, O).cancelRetry()), this.scheduleGc()), i(this, A).notify({ type: "observerRemoved", query: this, observer: e }));
}
getObserversCount() {
return this.observers.length;
}
invalidate() {
this.state.isInvalidated || P(this, R, x).call(this, { type: "invalidate" });
}
fetch(e, s) {
var f, w, m;
if (this.state.fetchStatus !== "idle") {
if (this.state.data !== void 0 && (s != null && s.cancelRefetch))
this.cancel({ silent: !0 });
else if (i(this, O))
return i(this, O).continueRetry(), i(this, O).promise;
}
if (e && this.setOptions(e), !this.options.queryFn) {
const d = this.observers.find((y) => y.options.queryFn);
d && this.setOptions(d.options);
}
process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error(
"As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"
));
const r = new AbortController(), n = (d) => {
Object.defineProperty(d, "signal", {
enumerable: !0,
get: () => (o(this, X, !0), r.signal)
});
}, u = () => {
const d = Le(this.options, s), y = {
client: i(this, W),
queryKey: this.queryKey,
meta: this.meta
};
return n(y), o(this, X, !1), this.options.persister ? this.options.persister(
d,
y,
this
) : d(y);
}, h = {
fetchOptions: s,
options: this.options,
queryKey: this.queryKey,
client: i(this, W),
state: this.state,
fetchFn: u
};
n(h), (f = this.options.behavior) == null || f.onFetch(
h,
this
), o(this, re, this.state), (this.state.fetchStatus === "idle" || this.state.fetchMeta !== ((w = h.fetchOptions) == null ? void 0 : w.meta)) && P(this, R, x).call(this, { type: "fetch", meta: (m = h.fetchOptions) == null ? void 0 : m.meta });
const a = (d) => {
var y, q, S, c;
Pe(d) && d.silent || P(this, R, x).call(this, {
type: "error",
error: d
}), Pe(d) || ((q = (y = i(this, A).config).onError) == null || q.call(
y,
d,
this
), (c = (S = i(this, A).config).onSettled) == null || c.call(
S,
this.state.data,
d,
this
)), this.scheduleGc();
};
return o(this, O, Ve({
initialPromise: s == null ? void 0 : s.initialPromise,
fn: h.fetchFn,
abort: r.abort.bind(r),
onSuccess: (d) => {
var y, q, S, c;
if (d === void 0) {
process.env.NODE_ENV !== "production" && console.error(
`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`
), a(new Error(`${this.queryHash} data is undefined`));
return;
}
try {
this.setData(d);
} catch (p) {
a(p);
return;
}
(q = (y = i(this, A).config).onSuccess) == null || q.call(y, d, this), (c = (S = i(this, A).config).onSettled) == null || c.call(
S,
d,
this.state.error,
this
), this.scheduleGc();
},
onError: a,
onFail: (d, y) => {
P(this, R, x).call(this, { type: "failed", failureCount: d, error: y });
},
onPause: () => {
P(this, R, x).call(this, { type: "pause" });
},
onContinue: () => {
P(this, R, x).call(this, { type: "continue" });
},
retry: h.options.retry,
retryDelay: h.options.retryDelay,
networkMode: h.options.networkMode,
canRun: () => !0
})), i(this, O).start();
}
}, se = new WeakMap(), re = new WeakMap(), A = new WeakMap(), W = new WeakMap(), O = new WeakMap(), le = new WeakMap(), X = new WeakMap(), R = new WeakSet(), x = function(e) {
const s = (r) => {
switch (e.type) {
case "failed":
return {
...r,
fetchFailureCount: e.failureCount,
fetchFailureReason: e.error
};
case "pause":
return {
...r,
fetchStatus: "paused"
};
case "continue":
return {
...r,
fetchStatus: "fetching"
};
case "fetch":
return {
...r,
...lt(r.data, this.options),
fetchMeta: e.meta ?? null
};
case "success":
return {
...r,
data: e.data,
dataUpdateCount: r.dataUpdateCount + 1,
dataUpdatedAt: e.dataUpdatedAt ?? Date.now(),
error: null,
isInvalidated: !1,
status: "success",
...!e.manual && {
fetchStatus: "idle",
fetchFailureCount: 0,
fetchFailureReason: null
}
};
case "error":
const n = e.error;
return Pe(n) && n.revert && i(this, re) ? { ...i(this, re), fetchStatus: "idle" } : {
...r,
error: n,
errorUpdateCount: r.errorUpdateCount + 1,
errorUpdatedAt: Date.now(),
fetchFailureCount: r.fetchFailureCount + 1,
fetchFailureReason: n,
fetchStatus: "idle",
status: "error"
};
case "invalidate":
return {
...r,
isInvalidated: !0
};
case "setState":
return {
...r,
...e.state
};
}
};
this.state = s(this.state), C.batch(() => {
this.observers.forEach((r) => {
r.onQueryUpdate();
}), i(this, A).notify({ query: this, type: "updated", action: e });
});
}, ke);
function lt(t, e) {
return {
fetchFailureCount: 0,
fetchFailureReason: null,
fetchStatus: Ge(e.networkMode) ? "fetching" : "paused",
...t === void 0 && {
error: null,
status: "pending"
}
};
}
function dt(t) {
const e = typeof t.initialData == "function" ? t.initialData() : t.initialData, s = e !== void 0, r = s ? typeof t.initialDataUpdatedAt == "function" ? t.initialDataUpdatedAt() : t.initialDataUpdatedAt : 0;
return {
data: e,
dataUpdateCount: 0,
dataUpdatedAt: s ? r ?? Date.now() : 0,
error: null,
errorUpdateCount: 0,
errorUpdatedAt: 0,
fetchFailureCount: 0,
fetchFailureReason: null,
fetchMeta: null,
isInvalidated: !1,
status: s ? "success" : "pending",
fetchStatus: "idle"
};
}
var U, Ue, ft = (Ue = class extends ge {
constructor(e = {}) {
super();
l(this, U, void 0);
this.config = e, o(this, U, /* @__PURE__ */ new Map());
}
build(e, s, r) {
const n = s.queryKey, u = s.queryHash ?? Fe(n, s);
let h = this.get(u);
return h || (h = new ct({
client: e,
queryKey: n,
queryHash: u,
options: e.defaultQueryOptions(s),
state: r,
defaultOptions: e.getQueryDefaults(n)
}), this.add(h)), h;
}
add(e) {
i(this, U).has(e.queryHash) || (i(this, U).set(e.queryHash, e), this.notify({
type: "added",
query: e
}));
}
remove(e) {
const s = i(this, U).get(e.queryHash);
s && (e.destroy(), s === e && i(this, U).delete(e.queryHash), this.notify({ type: "removed", query: e }));
}
clear() {
C.batch(() => {
this.getAll().forEach((e) => {
this.remove(e);
});
});
}
get(e) {
return i(this, U).get(e);
}
getAll() {
return [...i(this, U).values()];
}
find(e) {
const s = { exact: !0, ...e };
return this.getAll().find(
(r) => qe(s, r)
);
}
findAll(e = {}) {
const s = this.getAll();
return Object.keys(e).length > 0 ? s.filter((r) => qe(e, r)) : s;
}
notify(e) {
C.batch(() => {
this.listeners.forEach((s) => {
s(e);
});
});
}
onFocus() {
C.batch(() => {
this.getAll().forEach((e) => {
e.onFocus();
});
});
}
onOnline() {
C.batch(() => {
this.getAll().forEach((e) => {
e.onOnline();
});
});
}
}, U = new WeakMap(), Ue), K, F, Y, I, L, Ke, yt = (Ke = class extends $e {
constructor(e) {
super();
l(this, I);
l(this, K, void 0);
l(this, F, void 0);
l(this, Y, void 0);
this.mutationId = e.mutationId, o(this, F, e.mutationCache), o(this, K, []), this.state = e.state || pt(), this.setOptions(e.options), this.scheduleGc();
}
setOptions(e) {
this.options = e, this.updateGcTime(this.options.gcTime);
}
get meta() {
return this.options.meta;
}
addObserver(e) {
i(this, K).includes(e) || (i(this, K).push(e), this.clearGcTimeout(), i(this, F).notify({
type: "observerAdded",
mutation: this,
observer: e
}));
}
removeObserver(e) {
o(this, K, i(this, K).filter((s) => s !== e)), this.scheduleGc(), i(this, F).notify({
type: "observerRemoved",
mutation: this,
observer: e
});
}
optionalRemove() {
i(this, K).length || (this.state.status === "pending" ? this.scheduleGc() : i(this, F).remove(this));
}
continue() {
var e;
return ((e = i(this, Y)) == null ? void 0 : e.continue()) ?? // continuing a mutation assumes that variables are set, mutation must have been dehydrated before
this.execute(this.state.variables);
}
async execute(e) {
var n, u, h, a, f, w, m, d, y, q, S, c, p, E, M, g, D, j, k, fe;
o(this, Y, Ve({
fn: () => this.options.mutationFn ? this.options.mutationFn(e) : Promise.reject(new Error("No mutationFn found")),
onFail: (b, z) => {
P(this, I, L).call(this, { type: "failed", failureCount: b, error: z });
},
onPause: () => {
P(this, I, L).call(this, { type: "pause" });
},
onContinue: () => {
P(this, I, L).call(this, { type: "continue" });
},
retry: this.options.retry ?? 0,
retryDelay: this.options.retryDelay,
networkMode: this.options.networkMode,
canRun: () => i(this, F).canRun(this)
}));
const s = this.state.status === "pending", r = !i(this, Y).canStart();
try {
if (!s) {
P(this, I, L).call(this, { type: "pending", variables: e, isPaused: r }), await ((u = (n = i(this, F).config).onMutate) == null ? void 0 : u.call(
n,
e,
this
));
const z = await ((a = (h = this.options).onMutate) == null ? void 0 : a.call(h, e));
z !== this.state.context && P(this, I, L).call(this, {
type: "pending",
context: z,
variables: e,
isPaused: r
});
}
const b = await i(this, Y).start();
return await ((w = (f = i(this, F).config).onSuccess) == null ? void 0 : w.call(
f,
b,
e,
this.state.context,
this
)), await ((d = (m = this.options).onSuccess) == null ? void 0 : d.call(m, b, e, this.state.context)), await ((q = (y = i(this, F).config).onSettled) == null ? void 0 : q.call(
y,
b,
null,
this.state.variables,
this.state.context,
this
)), await ((c = (S = this.options).onSettled) == null ? void 0 : c.call(S, b, null, e, this.state.context)), P(this, I, L).call(this, { type: "success", data: b }), b;
} catch (b) {
try {
throw await ((E = (p = i(this, F).config).onError) == null ? void 0 : E.call(
p,
b,
e,
this.state.context,
this
)), await ((g = (M = this.options).onError) == null ? void 0 : g.call(
M,
b,
e,
this.state.context
)), await ((j = (D = i(this, F).config).onSettled) == null ? void 0 : j.call(
D,
void 0,
b,
this.state.variables,
this.state.context,
this
)), await ((fe = (k = this.options).onSettled) == null ? void 0 : fe.call(
k,
void 0,
b,
e,
this.state.context
)), b;
} finally {
P(this, I, L).call(this, { type: "error", error: b });
}
} finally {
i(this, F).runNext(this);
}
}
}, K = new WeakMap(), F = new WeakMap(), Y = new WeakMap(), I = new WeakSet(), L = function(e) {
const s = (r) => {
switch (e.type) {
case "failed":
return {
...r,
failureCount: e.failureCount,
failureReason: e.error
};
case "pause":
return {
...r,
isPaused: !0
};
case "continue":
return {
...r,
isPaused: !1
};
case "pending":
return {
...r,
context: e.context,
data: void 0,
failureCount: 0,
failureReason: null,
error: null,
isPaused: e.isPaused,
status: "pending",
variables: e.variables,
submittedAt: Date.now()
};
case "success":
return {
...r,
data: e.data,
failureCount: 0,
failureReason: null,
error: null,
status: "success",
isPaused: !1
};
case "error":
return {
...r,
data: void 0,
error: e.error,
failureCount: r.failureCount + 1,
failureReason: e.error,
isPaused: !1,
status: "error"
};
}
};
this.state = s(this.state), C.batch(() => {
i(this, K).forEach((r) => {
r.onMutationUpdate(e);
}), i(this, F).notify({
mutation: this,
type: "updated",
action: e
});
});
}, Ke);
function pt() {
return {
context: void 0,
data: void 0,
error: null,
failureCount: 0,
failureReason: null,
isPaused: !1,
status: "idle",
variables: void 0,
submittedAt: 0
};
}
var H, T, de, Ie, mt = (Ie = class extends ge {
constructor(e = {}) {
super();
l(this, H, void 0);
l(this, T, void 0);
l(this, de, void 0);
this.config = e, o(this, H, /* @__PURE__ */ new Set()), o(this, T, /* @__PURE__ */ new Map()), o(this, de, 0);
}
build(e, s, r) {
const n = new yt({
mutationCache: this,
mutationId: ++ye(this, de)._,
options: e.defaultMutationOptions(s),
state: r
});
return this.add(n), n;
}
add(e) {
i(this, H).add(e);
const s = pe(e);
if (typeof s == "string") {
const r = i(this, T).get(s);
r ? r.push(e) : i(this, T).set(s, [e]);
}
this.notify({ type: "added", mutation: e });
}
remove(e) {
if (i(this, H).delete(e)) {
const s = pe(e);
if (typeof s == "string") {
const r = i(this, T).get(s);
if (r)
if (r.length > 1) {
const n = r.indexOf(e);
n !== -1 && r.splice(n, 1);
} else
r[0] === e && i(this, T).delete(s);
}
}
this.notify({ type: "removed", mutation: e });
}
canRun(e) {
const s = pe(e);
if (typeof s == "string") {
const r = i(this, T).get(s), n = r == null ? void 0 : r.find(
(u) => u.state.status === "pending"
);
return !n || n === e;
} else
return !0;
}
runNext(e) {
var r;
const s = pe(e);
if (typeof s == "string") {
const n = (r = i(this, T).get(s)) == null ? void 0 : r.find((u) => u !== e && u.state.isPaused);
return (n == null ? void 0 : n.continue()) ?? Promise.resolve();
} else
return Promise.resolve();
}
clear() {
C.batch(() => {
i(this, H).forEach((e) => {
this.notify({ type: "removed", mutation: e });
}), i(this, H).clear(), i(this, T).clear();
});
}
getAll() {
return Array.from(i(this, H));
}
find(e) {
const s = { exact: !0, ...e };
return this.getAll().find(
(r) => Ee(s, r)
);
}
findAll(e = {}) {
return this.getAll().filter((s) => Ee(e, s));
}
notify(e) {
C.batch(() => {
this.listeners.forEach((s) => {
s(e);
});
});
}
resumePausedMutations() {
const e = this.getAll().filter((s) => s.state.isPaused);
return C.batch(
() => Promise.all(
e.map((s) => s.continue().catch(Q))
)
);
}
}, H = new WeakMap(), T = new WeakMap(), de = new WeakMap(), Ie);
function pe(t) {
var e;
return (e = t.options.scope) == null ? void 0 : e.id;
}
function Me(t) {
return {
onFetch: (e, s) => {
var m, d, y, q, S;
const r = e.options, n = (y = (d = (m = e.fetchOptions) == null ? void 0 : m.meta) == null ? void 0 : d.fetchMore) == null ? void 0 : y.direction, u = ((q = e.state.data) == null ? void 0 : q.pages) || [], h = ((S = e.state.data) == null ? void 0 : S.pageParams) || [];
let a = { pages: [], pageParams: [] }, f = 0;
const w = async () => {
let c = !1;
const p = (g) => {
Object.defineProperty(g, "signal", {
enumerable: !0,
get: () => (e.signal.aborted ? c = !0 : e.signal.addEventListener("abort", () => {
c = !0;
}), e.signal)
});
}, E = Le(e.options, e.fetchOptions), M = async (g, D, j) => {
if (c)
return Promise.reject();
if (D == null && g.pages.length)
return Promise.resolve(g);
const k = {
client: e.client,
queryKey: e.queryKey,
pageParam: D,
direction: j ? "backward" : "forward",
meta: e.options.meta
};
p(k);
const fe = await E(
k
), { maxPages: b } = e.options, z = j ? it : rt;
return {
pages: z(g.pages, fe, b),
pageParams: z(g.pageParams, D, b)
};
};
if (n && u.length) {
const g = n === "backward", D = g ? vt : Qe, j = {
pages: u,
pageParams: h
}, k = D(r, j);
a = await M(j, k, g);
} else {
const g = t ?? u.length;
do {
const D = f === 0 ? h[0] ?? r.initialPageParam : Qe(r, a);
if (f > 0 && D == null)
break;
a = await M(a, D), f++;
} while (f < g);
}
return a;
};
e.options.persister ? e.fetchFn = () => {
var c, p;
return (p = (c = e.options).persister) == null ? void 0 : p.call(
c,
w,
{
client: e.client,
queryKey: e.queryKey,
meta: e.options.meta,
signal: e.signal
},
s
);
} : e.fetchFn = w;
}
};
}
function Qe(t, { pages: e, pageParams: s }) {
const r = e.length - 1;
return e.length > 0 ? t.getNextPageParam(
e[r],
e,
s[r],
s
) : void 0;
}
function vt(t, { pages: e, pageParams: s }) {
var r;
return e.length > 0 ? (r = t.getPreviousPageParam) == null ? void 0 : r.call(t, e[0], e, s[0], s) : void 0;
}
var v, _, V, ie, ne, $, ae, ue, xe, gt = (xe = class {
constructor(t = {}) {
l(this, v, void 0);
l(this, _, void 0);
l(this, V, void 0);
l(this, ie, void 0);
l(this, ne, void 0);
l(this, $, void 0);
l(this, ae, void 0);
l(this, ue, void 0);
o(this, v, t.queryCache || new ft()), o(this, _, t.mutationCache || new mt()), o(this, V, t.defaultOptions || {}), o(this, ie, /* @__PURE__ */ new Map()), o(this, ne, /* @__PURE__ */ new Map()), o(this, $, 0);
}
mount() {
ye(this, $)._++, i(this, $) === 1 && (o(this, ae, Ne.subscribe(async (t) => {
t && (await this.resumePausedMutations(), i(this, v).onFocus());
})), o(this, ue, ve.subscribe(async (t) => {
t && (await this.resumePausedMutations(), i(this, v).onOnline());
})));
}
unmount() {
var t, e;
ye(this, $)._--, i(this, $) === 0 && ((t = i(this, ae)) == null || t.call(this), o(this, ae, void 0), (e = i(this, ue)) == null || e.call(this), o(this, ue, void 0));
}
isFetching(t) {
return i(this, v).findAll({ ...t, fetchStatus: "fetching" }).length;
}
isMutating(t) {
return i(this, _).findAll({ ...t, status: "pending" }).length;
}
getQueryData(t) {
var s;
const e = this.defaultQueryOptions({ queryKey: t });
return (s = i(this, v).get(e.queryHash)) == null ? void 0 : s.state.data;
}
ensureQueryData(t) {
const e = this.defaultQueryOptions(t), s = i(this, v).build(this, e), r = s.state.data;
return r === void 0 ? this.fetchQuery(t) : (t.revalidateIfStale && s.isStaleByTime(Ce(e.staleTime, s)) && this.prefetchQuery(e), Promise.resolve(r));
}
getQueriesData(t) {
return i(this, v).findAll(t).map(({ queryKey: e, state: s }) => {
const r = s.data;
return [e, r];
});
}
setQueryData(t, e, s) {
const r = this.defaultQueryOptions({ queryKey: t }), n = i(this, v).get(
r.queryHash
), u = n == null ? void 0 : n.state.data, h = Xe(e, u);
if (h !== void 0)
return i(this, v).build(this, r).setData(h, { ...s, manual: !0 });
}
setQueriesData(t, e, s) {
return C.batch(
() => i(this, v).findAll(t).map(({ queryKey: r }) => [
r,
this.setQueryData(r, e, s)
])
);
}
getQueryState(t) {
var s;
const e = this.defaultQueryOptions({ queryKey: t });
return (s = i(this, v).get(
e.queryHash
)) == null ? void 0 : s.state;
}
removeQueries(t) {
const e = i(this, v);
C.batch(() => {
e.findAll(t).forEach((s) => {
e.remove(s);
});
});
}
resetQueries(t, e) {
const s = i(this, v);
return C.batch(() => (s.findAll(t).forEach((r) => {
r.reset();
}), this.refetchQueries(
{
type: "active",
...t
},
e
)));
}
cancelQueries(t, e = {}) {
const s = { revert: !0, ...e }, r = C.batch(
() => i(this, v).findAll(t).map((n) => n.cancel(s))
);
return Promise.all(r).then(Q).catch(Q);
}
invalidateQueries(t, e = {}) {
return C.batch(() => (i(this, v).findAll(t).forEach((s) => {
s.invalidate();
}), (t == null ? void 0 : t.refetchType) === "none" ? Promise.resolve() : this.refetchQueries(
{
...t,
type: (t == null ? void 0 : t.refetchType) ?? (t == null ? void 0 : t.type) ?? "active"
},
e
)));
}
refetchQueries(t, e = {}) {
const s = {
...e,
cancelRefetch: e.cancelRefetch ?? !0
}, r = C.batch(
() => i(this, v).findAll(t).filter((n) => !n.isDisabled()).map((n) => {
let u = n.fetch(void 0, s);
return s.throwOnError || (u = u.catch(Q)), n.state.fetchStatus === "paused" ? Promise.resolve() : u;
})
);
return Promise.all(r).then(Q);
}
fetchQuery(t) {
const e = this.defaultQueryOptions(t);
e.retry === void 0 && (e.retry = !1);
const s = i(this, v).build(this, e);
return s.isStaleByTime(
Ce(e.staleTime, s)
) ? s.fetch(e) : Promise.resolve(s.state.data);
}
prefetchQuery(t) {
return this.fetchQuery(t).then(Q).catch(Q);
}
fetchInfiniteQuery(t) {
return t.behavior = Me(t.pages), this.fetchQuery(t);
}
prefetchInfiniteQuery(t) {
return this.fetchInfiniteQuery(t).then(Q).catch(Q);
}
ensureInfiniteQueryData(t) {
return t.behavior = Me(t.pages), this.ensureQueryData(t);
}
resumePausedMutations() {
return ve.isOnline() ? i(this, _).resumePausedMutations() : Promise.resolve();
}
getQueryCache() {
return i(this, v);
}
getMutationCache() {
return i(this, _);
}
getDefaultOptions() {
return i(this, V);
}
setDefaultOptions(t) {
o(this, V, t);
}
setQueryDefaults(t, e) {
i(this, ie).set(he(t), {
queryKey: t,
defaultOptions: e
});
}
getQueryDefaults(t) {
const e = [...i(this, ie).values()], s = {};
return e.forEach((r) => {
ce(t, r.queryKey) && Object.assign(s, r.defaultOptions);
}), s;
}
setMutationDefaults(t, e) {
i(this, ne).set(he(t), {
mutationKey: t,
defaultOptions: e
});
}
getMutationDefaults(t) {
const e = [...i(this, ne).values()], s = {};
return e.forEach((r) => {
ce(t, r.mutationKey) && Object.assign(s, r.defaultOptions);
}), s;
}
defaultQueryOptions(t) {
if (t._defaulted)
return t;
const e = {
...i(this, V).queries,
...this.getQueryDefaults(t.queryKey),
...t,
_defaulted: !0
};
return e.queryHash || (e.queryHash = Fe(
e.queryKey,
e
)), e.refetchOnReconnect === void 0 && (e.refetchOnReconnect = e.networkMode !== "always"), e.throwOnError === void 0 && (e.throwOnError = !!e.suspense), !e.networkMode && e.persister && (e.networkMode = "offlineFirst"), e.queryFn === me && (e.enabled = !1), e;
}
defaultMutationOptions(t) {
return t != null && t._defaulted ? t : {
...i(this, V).mutations,
...(t == null ? void 0 : t.mutationKey) && this.getMutationDefaults(t.mutationKey),
...t,
_defaulted: !0
};
}
clear() {
i(this, v).clear(), i(this, _).clear();
}
}, v = new WeakMap(), _ = new WeakMap(), V = new WeakMap(), ie = new WeakMap(), ne = new WeakMap(), $ = new WeakMap(), ae = new WeakMap(), ue = new WeakMap(), xe), bt = He.createContext(
void 0
), wt = ({
client: t,
children: e
}) => (He.useEffect(() => (t.mount(), () => {
t.unmount();
}), [t]), /* @__PURE__ */ oe(bt.Provider, { value: t, children: e }));
const Pt = new gt(), Dt = (t) => {
const { children: e, customVariables: s, customDarkVariables: r, workerUrl: n, licenseKey: u, ...h } = t, { workerUrlAdded: a } = Je(n);
return /* @__PURE__ */ oe(wt, { client: Pt, children: /* @__PURE__ */ oe(We, { licenseKey: u, children: /* @__PURE__ */ oe(Be, { workerUrlAdded: a, ...h, children: /* @__PURE__ */ oe(ze, { customDarkVariables: r, customVariables: s, children: e }) }) }) });
};
export {
Dt as RPConfig
};