@pdf-viewer/react
Version:
A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.
1,388 lines (1,387 loc) • 41.3 kB
JavaScript
var Pt = (e, t, s) => {
if (!t.has(e))
throw TypeError("Cannot " + s);
};
var i = (e, t, s) => (Pt(e, t, "read from private field"), s ? s.call(e) : t.get(e)), l = (e, t, s) => {
if (t.has(e))
throw TypeError("Cannot add the same private member more than once");
t instanceof WeakSet ? t.add(e) : t.set(e, s);
}, o = (e, t, s, r) => (Pt(e, t, "write to private field"), r ? r.call(e, s) : t.set(e, s), s);
var pt = (e, t, s, r) => ({
set _(n) {
o(e, t, n, s);
},
get _() {
return i(e, t, r);
}
}), O = (e, t, s) => (Pt(e, t, "access private method"), s);
import { jsx as ot } from "react/jsx-runtime";
import { RPTheme as Jt } from "./RPTheme.js";
import { ConfigContextProvider as Wt } from "../contexts/ConfigContext.js";
import { useLoadWorker as Xt } from "../utils/hooks/useLoadWorker.js";
import * as Nt from "react";
import { LicenseProvider as Yt } from "../contexts/LicenseContext.js";
var bt = class {
constructor() {
this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
}
subscribe(e) {
return this.listeners.add(e), this.onSubscribe(), () => {
this.listeners.delete(e), this.onUnsubscribe();
};
}
hasListeners() {
return this.listeners.size > 0;
}
onSubscribe() {
}
onUnsubscribe() {
}
}, wt = typeof window > "u" || "Deno" in globalThis;
function M() {
}
function Zt(e, t) {
return typeof e == "function" ? e(t) : e;
}
function te(e) {
return typeof e == "number" && e >= 0 && e !== 1 / 0;
}
function ee(e, t) {
return Math.max(e + (t || 0) - Date.now(), 0);
}
function Ot(e, t) {
return typeof e == "function" ? e(t) : e;
}
function se(e, t) {
return typeof e == "function" ? e(t) : e;
}
function Dt(e, t) {
const {
type: s = "all",
exact: r,
fetchStatus: n,
predicate: u,
queryKey: d,
stale: a
} = e;
if (d) {
if (r) {
if (t.queryHash !== qt(d, t.options))
return !1;
} else if (!ct(t.queryKey, d))
return !1;
}
if (s !== "all") {
const y = t.isActive();
if (s === "active" && !y || s === "inactive" && y)
return !1;
}
return !(typeof a == "boolean" && t.isStale() !== a || n && n !== t.state.fetchStatus || u && !u(t));
}
function Qt(e, t) {
const { exact: s, status: r, predicate: n, mutationKey: u } = e;
if (u) {
if (!t.options.mutationKey)
return !1;
if (s) {
if (ht(t.options.mutationKey) !== ht(u))
return !1;
} else if (!ct(t.options.mutationKey, u))
return !1;
}
return !(r && t.state.status !== r || n && !n(t));
}
function qt(e, t) {
return ((t == null ? void 0 : t.queryKeyHashFn) || ht)(e);
}
function ht(e) {
return JSON.stringify(
e,
(t, s) => St(s) ? Object.keys(s).sort().reduce((r, n) => (r[n] = s[n], r), {}) : s
);
}
function ct(e, t) {
return e === t ? !0 : typeof e != typeof t ? !1 : e && t && typeof e == "object" && typeof t == "object" ? Object.keys(t).every((s) => ct(e[s], t[s])) : !1;
}
function Ct(e, t) {
if (e === t)
return e;
const s = At(e) && At(t);
if (s || St(e) && St(t)) {
const r = s ? e : Object.keys(e), n = r.length, u = s ? t : Object.keys(t), d = u.length, a = s ? [] : {}, y = new Set(r);
let S = 0;
for (let P = 0; P < d; P++) {
const m = s ? P : u[P];
(!s && y.has(m) || s) && e[m] === void 0 && t[m] === void 0 ? (a[m] = void 0, S++) : (a[m] = Ct(e[m], t[m]), a[m] === e[m] && e[m] !== void 0 && S++);
}
return n === d && S === n ? e : a;
}
return t;
}
function At(e) {
return Array.isArray(e) && e.length === Object.keys(e).length;
}
function St(e) {
if (!Mt(e))
return !1;
const t = e.constructor;
if (t === void 0)
return !0;
const s = t.prototype;
return !(!Mt(s) || !s.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(e) !== Object.prototype);
}
function Mt(e) {
return Object.prototype.toString.call(e) === "[object Object]";
}
function re(e) {
return new Promise((t) => {
setTimeout(t, e);
});
}
function ie(e, t, s) {
if (typeof s.structuralSharing == "function")
return s.structuralSharing(e, t);
if (s.structuralSharing !== !1) {
if (process.env.NODE_ENV !== "production")
try {
return Ct(e, t);
} catch (r) {
throw 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}`
), r;
}
return Ct(e, t);
}
return t;
}
function ne(e, t, s = 0) {
const r = [...e, t];
return s && r.length > s ? r.slice(1) : r;
}
function ae(e, t, s = 0) {
const r = [t, ...e];
return s && r.length > s ? r.slice(0, -1) : r;
}
var vt = Symbol();
function Gt(e, t) {
return process.env.NODE_ENV !== "production" && e.queryFn === vt && console.error(
`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`
), !e.queryFn && (t != null && t.initialPromise) ? () => t.initialPromise : !e.queryFn || e.queryFn === vt ? () => Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)) : e.queryFn;
}
var B, N, tt, xt, ue = (xt = class extends bt {
constructor() {
super();
l(this, B, void 0);
l(this, N, void 0);
l(this, tt, void 0);
o(this, tt, (t) => {
if (!wt && window.addEventListener) {
const s = () => t();
return window.addEventListener("visibilitychange", s, !1), () => {
window.removeEventListener("visibilitychange", s);
};
}
});
}
onSubscribe() {
i(this, N) || this.setEventListener(i(this, tt));
}
onUnsubscribe() {
var t;
this.hasListeners() || ((t = i(this, N)) == null || t.call(this), o(this, N, void 0));
}
setEventListener(t) {
var s;
o(this, tt, t), (s = i(this, N)) == null || s.call(this), o(this, N, t((r) => {
typeof r == "boolean" ? this.setFocused(r) : this.onFocus();
}));
}
setFocused(t) {
i(this, B) !== t && (o(this, B, t), this.onFocus());
}
onFocus() {
const t = this.isFocused();
this.listeners.forEach((s) => {
s(t);
});
}
isFocused() {
var t;
return typeof i(this, B) == "boolean" ? i(this, B) : ((t = globalThis.document) == null ? void 0 : t.visibilityState) !== "hidden";
}
}, B = new WeakMap(), N = new WeakMap(), tt = new WeakMap(), xt), _t = new ue(), et, G, st, jt, oe = (jt = class extends bt {
constructor() {
super();
l(this, et, !0);
l(this, G, void 0);
l(this, st, void 0);
o(this, st, (t) => {
if (!wt && window.addEventListener) {
const s = () => t(!0), r = () => t(!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, st));
}
onUnsubscribe() {
var t;
this.hasListeners() || ((t = i(this, G)) == null || t.call(this), o(this, G, void 0));
}
setEventListener(t) {
var s;
o(this, st, t), (s = i(this, G)) == null || s.call(this), o(this, G, t(this.setOnline.bind(this)));
}
setOnline(t) {
i(this, et) !== t && (o(this, et, t), this.listeners.forEach((r) => {
r(t);
}));
}
isOnline() {
return i(this, et);
}
}, et = new WeakMap(), G = new WeakMap(), st = new WeakMap(), jt), gt = new oe();
function he() {
let e, t;
const s = new Promise((n, u) => {
e = n, t = 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
}), e(n);
}, s.reject = (n) => {
r({
status: "rejected",
reason: n
}), t(n);
}, s;
}
function ce(e) {
return Math.min(1e3 * 2 ** e, 3e4);
}
function Vt(e) {
return (e ?? "online") === "online" ? gt.isOnline() : !0;
}
var $t = class extends Error {
constructor(e) {
super("CancelledError"), this.revert = e == null ? void 0 : e.revert, this.silent = e == null ? void 0 : e.silent;
}
};
function Ft(e) {
return e instanceof $t;
}
function zt(e) {
let t = !1, s = 0, r = !1, n;
const u = he(), d = (h) => {
var f;
r || (c(new $t(h)), (f = e.abort) == null || f.call(e));
}, a = () => {
t = !0;
}, y = () => {
t = !1;
}, S = () => _t.isFocused() && (e.networkMode === "always" || gt.isOnline()) && e.canRun(), P = () => Vt(e.networkMode) && e.canRun(), m = (h) => {
var f;
r || (r = !0, (f = e.onSuccess) == null || f.call(e, h), n == null || n(), u.resolve(h));
}, c = (h) => {
var f;
r || (r = !0, (f = e.onError) == null || f.call(e, h), n == null || n(), u.reject(h));
}, v = () => new Promise((h) => {
var f;
n = (F) => {
(r || S()) && h(F);
}, (f = e.onPause) == null || f.call(e);
}).then(() => {
var h;
n = void 0, r || (h = e.onContinue) == null || h.call(e);
}), g = () => {
if (r)
return;
let h;
const f = s === 0 ? e.initialPromise : void 0;
try {
h = f ?? e.fn();
} catch (F) {
h = Promise.reject(F);
}
Promise.resolve(h).then(m).catch((F) => {
var H;
if (r)
return;
const A = e.retry ?? (wt ? 0 : 3), b = e.retryDelay ?? ce, D = typeof b == "function" ? b(s, F) : b, x = A === !0 || typeof A == "number" && s < A || typeof A == "function" && A(s, F);
if (t || !x) {
c(F);
return;
}
s++, (H = e.onFail) == null || H.call(e, s, F), re(D).then(() => S() ? void 0 : v()).then(() => {
t ? c(F) : g();
});
});
};
return {
promise: u,
cancel: d,
continue: () => (n == null || n(), u),
cancelRetry: a,
continueRetry: y,
canStart: P,
start: () => (P() ? g() : v().then(g), u)
};
}
var le = (e) => setTimeout(e, 0);
function de() {
let e = [], t = 0, s = (a) => {
a();
}, r = (a) => {
a();
}, n = le;
const u = (a) => {
t ? e.push(a) : n(() => {
s(a);
});
}, d = () => {
const a = e;
e = [], a.length && n(() => {
r(() => {
a.forEach((y) => {
s(y);
});
});
});
};
return {
batch: (a) => {
let y;
t++;
try {
y = a();
} finally {
t--, t || d();
}
return y;
},
/**
* All calls to the wrapped function will be batched.
*/
batchCalls: (a) => (...y) => {
u(() => {
a(...y);
});
},
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 E = de(), J, kt, Bt = (kt = class {
constructor() {
l(this, J, void 0);
}
destroy() {
this.clearGcTimeout();
}
scheduleGc() {
this.clearGcTimeout(), te(this.gcTime) && o(this, J, setTimeout(() => {
this.optionalRemove();
}, this.gcTime));
}
updateGcTime(e) {
this.gcTime = Math.max(
this.gcTime || 0,
e ?? (wt ? 1 / 0 : 5 * 60 * 1e3)
);
}
clearGcTimeout() {
i(this, J) && (clearTimeout(i(this, J)), o(this, J, void 0));
}
}, J = new WeakMap(), kt), rt, W, Q, X, C, lt, Y, R, K, Ut, fe = (Ut = class extends Bt {
constructor(t) {
super();
l(this, R);
l(this, rt, void 0);
l(this, W, void 0);
l(this, Q, void 0);
l(this, X, void 0);
l(this, C, void 0);
l(this, lt, void 0);
l(this, Y, void 0);
o(this, Y, !1), o(this, lt, t.defaultOptions), this.setOptions(t.options), this.observers = [], o(this, X, t.client), o(this, Q, i(this, X).getQueryCache()), this.queryKey = t.queryKey, this.queryHash = t.queryHash, o(this, rt, pe(this.options)), this.state = t.state ?? i(this, rt), this.scheduleGc();
}
get meta() {
return this.options.meta;
}
get promise() {
var t;
return (t = i(this, C)) == null ? void 0 : t.promise;
}
setOptions(t) {
this.options = { ...i(this, lt), ...t }, this.updateGcTime(this.options.gcTime);
}
optionalRemove() {
!this.observers.length && this.state.fetchStatus === "idle" && i(this, Q).remove(this);
}
setData(t, s) {
const r = ie(this.state.data, t, this.options);
return O(this, R, K).call(this, {
data: r,
type: "success",
dataUpdatedAt: s == null ? void 0 : s.updatedAt,
manual: s == null ? void 0 : s.manual
}), r;
}
setState(t, s) {
O(this, R, K).call(this, { type: "setState", state: t, setStateOptions: s });
}
cancel(t) {
var r, n;
const s = (r = i(this, C)) == null ? void 0 : r.promise;
return (n = i(this, C)) == null || n.cancel(t), s ? s.then(M).catch(M) : Promise.resolve();
}
destroy() {
super.destroy(), this.cancel({ silent: !0 });
}
reset() {
this.destroy(), this.setState(i(this, rt));
}
isActive() {
return this.observers.some(
(t) => se(t.options.enabled, this) !== !1
);
}
isDisabled() {
return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === vt || this.state.dataUpdateCount + this.state.errorUpdateCount === 0;
}
isStatic() {
return this.getObserversCount() > 0 ? this.observers.some(
(t) => Ot(t.options.staleTime, this) === "static"
) : !1;
}
isStale() {
return this.getObserversCount() > 0 ? this.observers.some(
(t) => t.getCurrentResult().isStale
) : this.state.data === void 0 || this.state.isInvalidated;
}
isStaleByTime(t = 0) {
return this.state.data === void 0 ? !0 : t === "static" ? !1 : this.state.isInvalidated ? !0 : !ee(this.state.dataUpdatedAt, t);
}
onFocus() {
var s;
const t = this.observers.find((r) => r.shouldFetchOnWindowFocus());
t == null || t.refetch({ cancelRefetch: !1 }), (s = i(this, C)) == null || s.continue();
}
onOnline() {
var s;
const t = this.observers.find((r) => r.shouldFetchOnReconnect());
t == null || t.refetch({ cancelRefetch: !1 }), (s = i(this, C)) == null || s.continue();
}
addObserver(t) {
this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), i(this, Q).notify({ type: "observerAdded", query: this, observer: t }));
}
removeObserver(t) {
this.observers.includes(t) && (this.observers = this.observers.filter((s) => s !== t), this.observers.length || (i(this, C) && (i(this, Y) ? i(this, C).cancel({ revert: !0 }) : i(this, C).cancelRetry()), this.scheduleGc()), i(this, Q).notify({ type: "observerRemoved", query: this, observer: t }));
}
getObserversCount() {
return this.observers.length;
}
invalidate() {
this.state.isInvalidated || O(this, R, K).call(this, { type: "invalidate" });
}
fetch(t, s) {
var S, P, m;
if (this.state.fetchStatus !== "idle") {
if (this.state.data !== void 0 && (s != null && s.cancelRefetch))
this.cancel({ silent: !0 });
else if (i(this, C))
return i(this, C).continueRetry(), i(this, C).promise;
}
if (t && this.setOptions(t), !this.options.queryFn) {
const c = this.observers.find((v) => v.options.queryFn);
c && this.setOptions(c.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 = (c) => {
Object.defineProperty(c, "signal", {
enumerable: !0,
get: () => (o(this, Y, !0), r.signal)
});
}, u = () => {
const c = Gt(this.options, s), g = (() => {
const h = {
client: i(this, X),
queryKey: this.queryKey,
meta: this.meta
};
return n(h), h;
})();
return o(this, Y, !1), this.options.persister ? this.options.persister(
c,
g,
this
) : c(g);
}, a = (() => {
const c = {
fetchOptions: s,
options: this.options,
queryKey: this.queryKey,
client: i(this, X),
state: this.state,
fetchFn: u
};
return n(c), c;
})();
(S = this.options.behavior) == null || S.onFetch(a, this), o(this, W, this.state), (this.state.fetchStatus === "idle" || this.state.fetchMeta !== ((P = a.fetchOptions) == null ? void 0 : P.meta)) && O(this, R, K).call(this, { type: "fetch", meta: (m = a.fetchOptions) == null ? void 0 : m.meta });
const y = (c) => {
var v, g, h, f;
Ft(c) && c.silent || O(this, R, K).call(this, {
type: "error",
error: c
}), Ft(c) || ((g = (v = i(this, Q).config).onError) == null || g.call(
v,
c,
this
), (f = (h = i(this, Q).config).onSettled) == null || f.call(
h,
this.state.data,
c,
this
)), this.scheduleGc();
};
return o(this, C, zt({
initialPromise: s == null ? void 0 : s.initialPromise,
fn: a.fetchFn,
abort: r.abort.bind(r),
onSuccess: (c) => {
var v, g, h, f;
if (c === 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}`
), y(new Error(`${this.queryHash} data is undefined`));
return;
}
try {
this.setData(c);
} catch (F) {
y(F);
return;
}
(g = (v = i(this, Q).config).onSuccess) == null || g.call(v, c, this), (f = (h = i(this, Q).config).onSettled) == null || f.call(
h,
c,
this.state.error,
this
), this.scheduleGc();
},
onError: y,
onFail: (c, v) => {
O(this, R, K).call(this, { type: "failed", failureCount: c, error: v });
},
onPause: () => {
O(this, R, K).call(this, { type: "pause" });
},
onContinue: () => {
O(this, R, K).call(this, { type: "continue" });
},
retry: a.options.retry,
retryDelay: a.options.retryDelay,
networkMode: a.options.networkMode,
canRun: () => !0
})), i(this, C).start();
}
}, rt = new WeakMap(), W = new WeakMap(), Q = new WeakMap(), X = new WeakMap(), C = new WeakMap(), lt = new WeakMap(), Y = new WeakMap(), R = new WeakSet(), K = function(t) {
const s = (r) => {
switch (t.type) {
case "failed":
return {
...r,
fetchFailureCount: t.failureCount,
fetchFailureReason: t.error
};
case "pause":
return {
...r,
fetchStatus: "paused"
};
case "continue":
return {
...r,
fetchStatus: "fetching"
};
case "fetch":
return {
...r,
...ye(r.data, this.options),
fetchMeta: t.meta ?? null
};
case "success":
return o(this, W, void 0), {
...r,
data: t.data,
dataUpdateCount: r.dataUpdateCount + 1,
dataUpdatedAt: t.dataUpdatedAt ?? Date.now(),
error: null,
isInvalidated: !1,
status: "success",
...!t.manual && {
fetchStatus: "idle",
fetchFailureCount: 0,
fetchFailureReason: null
}
};
case "error":
const n = t.error;
return Ft(n) && n.revert && i(this, W) ? { ...i(this, W), 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,
...t.state
};
}
};
this.state = s(this.state), E.batch(() => {
this.observers.forEach((r) => {
r.onQueryUpdate();
}), i(this, Q).notify({ query: this, type: "updated", action: t });
});
}, Ut);
function ye(e, t) {
return {
fetchFailureCount: 0,
fetchFailureReason: null,
fetchStatus: Vt(t.networkMode) ? "fetching" : "paused",
...e === void 0 && {
error: null,
status: "pending"
}
};
}
function pe(e) {
const t = typeof e.initialData == "function" ? e.initialData() : e.initialData, s = t !== void 0, r = s ? typeof e.initialDataUpdatedAt == "function" ? e.initialDataUpdatedAt() : e.initialDataUpdatedAt : 0;
return {
data: t,
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 j, Kt, me = (Kt = class extends bt {
constructor(t = {}) {
super();
l(this, j, void 0);
this.config = t, o(this, j, /* @__PURE__ */ new Map());
}
build(t, s, r) {
const n = s.queryKey, u = s.queryHash ?? qt(n, s);
let d = this.get(u);
return d || (d = new fe({
client: t,
queryKey: n,
queryHash: u,
options: t.defaultQueryOptions(s),
state: r,
defaultOptions: t.getQueryDefaults(n)
}), this.add(d)), d;
}
add(t) {
i(this, j).has(t.queryHash) || (i(this, j).set(t.queryHash, t), this.notify({
type: "added",
query: t
}));
}
remove(t) {
const s = i(this, j).get(t.queryHash);
s && (t.destroy(), s === t && i(this, j).delete(t.queryHash), this.notify({ type: "removed", query: t }));
}
clear() {
E.batch(() => {
this.getAll().forEach((t) => {
this.remove(t);
});
});
}
get(t) {
return i(this, j).get(t);
}
getAll() {
return [...i(this, j).values()];
}
find(t) {
const s = { exact: !0, ...t };
return this.getAll().find(
(r) => Dt(s, r)
);
}
findAll(t = {}) {
const s = this.getAll();
return Object.keys(t).length > 0 ? s.filter((r) => Dt(t, r)) : s;
}
notify(t) {
E.batch(() => {
this.listeners.forEach((s) => {
s(t);
});
});
}
onFocus() {
E.batch(() => {
this.getAll().forEach((t) => {
t.onFocus();
});
});
}
onOnline() {
E.batch(() => {
this.getAll().forEach((t) => {
t.onOnline();
});
});
}
}, j = new WeakMap(), Kt), k, q, Z, U, L, It, ve = (It = class extends Bt {
constructor(t) {
super();
l(this, U);
l(this, k, void 0);
l(this, q, void 0);
l(this, Z, void 0);
this.mutationId = t.mutationId, o(this, q, t.mutationCache), o(this, k, []), this.state = t.state || ge(), this.setOptions(t.options), this.scheduleGc();
}
setOptions(t) {
this.options = t, this.updateGcTime(this.options.gcTime);
}
get meta() {
return this.options.meta;
}
addObserver(t) {
i(this, k).includes(t) || (i(this, k).push(t), this.clearGcTimeout(), i(this, q).notify({
type: "observerAdded",
mutation: this,
observer: t
}));
}
removeObserver(t) {
o(this, k, i(this, k).filter((s) => s !== t)), this.scheduleGc(), i(this, q).notify({
type: "observerRemoved",
mutation: this,
observer: t
});
}
optionalRemove() {
i(this, k).length || (this.state.status === "pending" ? this.scheduleGc() : i(this, q).remove(this));
}
continue() {
var t;
return ((t = i(this, Z)) == null ? void 0 : t.continue()) ?? // continuing a mutation assumes that variables are set, mutation must have been dehydrated before
this.execute(this.state.variables);
}
async execute(t) {
var u, d, a, y, S, P, m, c, v, g, h, f, F, A, b, D, x, H, ft, yt;
const s = () => {
O(this, U, L).call(this, { type: "continue" });
};
o(this, Z, zt({
fn: () => this.options.mutationFn ? this.options.mutationFn(t) : Promise.reject(new Error("No mutationFn found")),
onFail: (w, z) => {
O(this, U, L).call(this, { type: "failed", failureCount: w, error: z });
},
onPause: () => {
O(this, U, L).call(this, { type: "pause" });
},
onContinue: s,
retry: this.options.retry ?? 0,
retryDelay: this.options.retryDelay,
networkMode: this.options.networkMode,
canRun: () => i(this, q).canRun(this)
}));
const r = this.state.status === "pending", n = !i(this, Z).canStart();
try {
if (r)
s();
else {
O(this, U, L).call(this, { type: "pending", variables: t, isPaused: n }), await ((d = (u = i(this, q).config).onMutate) == null ? void 0 : d.call(
u,
t,
this
));
const z = await ((y = (a = this.options).onMutate) == null ? void 0 : y.call(a, t));
z !== this.state.context && O(this, U, L).call(this, {
type: "pending",
context: z,
variables: t,
isPaused: n
});
}
const w = await i(this, Z).start();
return await ((P = (S = i(this, q).config).onSuccess) == null ? void 0 : P.call(
S,
w,
t,
this.state.context,
this
)), await ((c = (m = this.options).onSuccess) == null ? void 0 : c.call(m, w, t, this.state.context)), await ((g = (v = i(this, q).config).onSettled) == null ? void 0 : g.call(
v,
w,
null,
this.state.variables,
this.state.context,
this
)), await ((f = (h = this.options).onSettled) == null ? void 0 : f.call(h, w, null, t, this.state.context)), O(this, U, L).call(this, { type: "success", data: w }), w;
} catch (w) {
try {
throw await ((A = (F = i(this, q).config).onError) == null ? void 0 : A.call(
F,
w,
t,
this.state.context,
this
)), await ((D = (b = this.options).onError) == null ? void 0 : D.call(
b,
w,
t,
this.state.context
)), await ((H = (x = i(this, q).config).onSettled) == null ? void 0 : H.call(
x,
void 0,
w,
this.state.variables,
this.state.context,
this
)), await ((yt = (ft = this.options).onSettled) == null ? void 0 : yt.call(
ft,
void 0,
w,
t,
this.state.context
)), w;
} finally {
O(this, U, L).call(this, { type: "error", error: w });
}
} finally {
i(this, q).runNext(this);
}
}
}, k = new WeakMap(), q = new WeakMap(), Z = new WeakMap(), U = new WeakSet(), L = function(t) {
const s = (r) => {
switch (t.type) {
case "failed":
return {
...r,
failureCount: t.failureCount,
failureReason: t.error
};
case "pause":
return {
...r,
isPaused: !0
};
case "continue":
return {
...r,
isPaused: !1
};
case "pending":
return {
...r,
context: t.context,
data: void 0,
failureCount: 0,
failureReason: null,
error: null,
isPaused: t.isPaused,
status: "pending",
variables: t.variables,
submittedAt: Date.now()
};
case "success":
return {
...r,
data: t.data,
failureCount: 0,
failureReason: null,
error: null,
status: "success",
isPaused: !1
};
case "error":
return {
...r,
data: void 0,
error: t.error,
failureCount: r.failureCount + 1,
failureReason: t.error,
isPaused: !1,
status: "error"
};
}
};
this.state = s(this.state), E.batch(() => {
i(this, k).forEach((r) => {
r.onMutationUpdate(t);
}), i(this, q).notify({
mutation: this,
type: "updated",
action: t
});
});
}, It);
function ge() {
return {
context: void 0,
data: void 0,
error: null,
failureCount: 0,
failureReason: null,
isPaused: !1,
status: "idle",
variables: void 0,
submittedAt: 0
};
}
var I, T, dt, Ht, be = (Ht = class extends bt {
constructor(t = {}) {
super();
l(this, I, void 0);
l(this, T, void 0);
l(this, dt, void 0);
this.config = t, o(this, I, /* @__PURE__ */ new Set()), o(this, T, /* @__PURE__ */ new Map()), o(this, dt, 0);
}
build(t, s, r) {
const n = new ve({
mutationCache: this,
mutationId: ++pt(this, dt)._,
options: t.defaultMutationOptions(s),
state: r
});
return this.add(n), n;
}
add(t) {
i(this, I).add(t);
const s = mt(t);
if (typeof s == "string") {
const r = i(this, T).get(s);
r ? r.push(t) : i(this, T).set(s, [t]);
}
this.notify({ type: "added", mutation: t });
}
remove(t) {
if (i(this, I).delete(t)) {
const s = mt(t);
if (typeof s == "string") {
const r = i(this, T).get(s);
if (r)
if (r.length > 1) {
const n = r.indexOf(t);
n !== -1 && r.splice(n, 1);
} else
r[0] === t && i(this, T).delete(s);
}
}
this.notify({ type: "removed", mutation: t });
}
canRun(t) {
const s = mt(t);
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 === t;
} else
return !0;
}
runNext(t) {
var r;
const s = mt(t);
if (typeof s == "string") {
const n = (r = i(this, T).get(s)) == null ? void 0 : r.find((u) => u !== t && u.state.isPaused);
return (n == null ? void 0 : n.continue()) ?? Promise.resolve();
} else
return Promise.resolve();
}
clear() {
E.batch(() => {
i(this, I).forEach((t) => {
this.notify({ type: "removed", mutation: t });
}), i(this, I).clear(), i(this, T).clear();
});
}
getAll() {
return Array.from(i(this, I));
}
find(t) {
const s = { exact: !0, ...t };
return this.getAll().find(
(r) => Qt(s, r)
);
}
findAll(t = {}) {
return this.getAll().filter((s) => Qt(t, s));
}
notify(t) {
E.batch(() => {
this.listeners.forEach((s) => {
s(t);
});
});
}
resumePausedMutations() {
const t = this.getAll().filter((s) => s.state.isPaused);
return E.batch(
() => Promise.all(
t.map((s) => s.continue().catch(M))
)
);
}
}, I = new WeakMap(), T = new WeakMap(), dt = new WeakMap(), Ht);
function mt(e) {
var t;
return (t = e.options.scope) == null ? void 0 : t.id;
}
function Rt(e) {
return {
onFetch: (t, s) => {
var P, m, c, v, g;
const r = t.options, n = (c = (m = (P = t.fetchOptions) == null ? void 0 : P.meta) == null ? void 0 : m.fetchMore) == null ? void 0 : c.direction, u = ((v = t.state.data) == null ? void 0 : v.pages) || [], d = ((g = t.state.data) == null ? void 0 : g.pageParams) || [];
let a = { pages: [], pageParams: [] }, y = 0;
const S = async () => {
let h = !1;
const f = (b) => {
Object.defineProperty(b, "signal", {
enumerable: !0,
get: () => (t.signal.aborted ? h = !0 : t.signal.addEventListener("abort", () => {
h = !0;
}), t.signal)
});
}, F = Gt(t.options, t.fetchOptions), A = async (b, D, x) => {
if (h)
return Promise.reject();
if (D == null && b.pages.length)
return Promise.resolve(b);
const ft = (() => {
const Et = {
client: t.client,
queryKey: t.queryKey,
pageParam: D,
direction: x ? "backward" : "forward",
meta: t.options.meta
};
return f(Et), Et;
})(), yt = await F(ft), { maxPages: w } = t.options, z = x ? ae : ne;
return {
pages: z(b.pages, yt, w),
pageParams: z(b.pageParams, D, w)
};
};
if (n && u.length) {
const b = n === "backward", D = b ? we : Tt, x = {
pages: u,
pageParams: d
}, H = D(r, x);
a = await A(x, H, b);
} else {
const b = e ?? u.length;
do {
const D = y === 0 ? d[0] ?? r.initialPageParam : Tt(r, a);
if (y > 0 && D == null)
break;
a = await A(a, D), y++;
} while (y < b);
}
return a;
};
t.options.persister ? t.fetchFn = () => {
var h, f;
return (f = (h = t.options).persister) == null ? void 0 : f.call(
h,
S,
{
client: t.client,
queryKey: t.queryKey,
meta: t.options.meta,
signal: t.signal
},
s
);
} : t.fetchFn = S;
}
};
}
function Tt(e, { pages: t, pageParams: s }) {
const r = t.length - 1;
return t.length > 0 ? e.getNextPageParam(
t[r],
t,
s[r],
s
) : void 0;
}
function we(e, { pages: t, pageParams: s }) {
var r;
return t.length > 0 ? (r = e.getPreviousPageParam) == null ? void 0 : r.call(e, t[0], t, s[0], s) : void 0;
}
var p, _, V, it, nt, $, at, ut, Lt, Pe = (Lt = class {
constructor(e = {}) {
l(this, p, void 0);
l(this, _, void 0);
l(this, V, void 0);
l(this, it, void 0);
l(this, nt, void 0);
l(this, $, void 0);
l(this, at, void 0);
l(this, ut, void 0);
o(this, p, e.queryCache || new me()), o(this, _, e.mutationCache || new be()), o(this, V, e.defaultOptions || {}), o(this, it, /* @__PURE__ */ new Map()), o(this, nt, /* @__PURE__ */ new Map()), o(this, $, 0);
}
mount() {
pt(this, $)._++, i(this, $) === 1 && (o(this, at, _t.subscribe(async (e) => {
e && (await this.resumePausedMutations(), i(this, p).onFocus());
})), o(this, ut, gt.subscribe(async (e) => {
e && (await this.resumePausedMutations(), i(this, p).onOnline());
})));
}
unmount() {
var e, t;
pt(this, $)._--, i(this, $) === 0 && ((e = i(this, at)) == null || e.call(this), o(this, at, void 0), (t = i(this, ut)) == null || t.call(this), o(this, ut, void 0));
}
isFetching(e) {
return i(this, p).findAll({ ...e, fetchStatus: "fetching" }).length;
}
isMutating(e) {
return i(this, _).findAll({ ...e, status: "pending" }).length;
}
/**
* Imperative (non-reactive) way to retrieve data for a QueryKey.
* Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.
*
* Hint: Do not use this function inside a component, because it won't receive updates.
* Use `useQuery` to create a `QueryObserver` that subscribes to changes.
*/
getQueryData(e) {
var s;
const t = this.defaultQueryOptions({ queryKey: e });
return (s = i(this, p).get(t.queryHash)) == null ? void 0 : s.state.data;
}
ensureQueryData(e) {
const t = this.defaultQueryOptions(e), s = i(this, p).build(this, t), r = s.state.data;
return r === void 0 ? this.fetchQuery(e) : (e.revalidateIfStale && s.isStaleByTime(Ot(t.staleTime, s)) && this.prefetchQuery(t), Promise.resolve(r));
}
getQueriesData(e) {
return i(this, p).findAll(e).map(({ queryKey: t, state: s }) => {
const r = s.data;
return [t, r];
});
}
setQueryData(e, t, s) {
const r = this.defaultQueryOptions({ queryKey: e }), n = i(this, p).get(
r.queryHash
), u = n == null ? void 0 : n.state.data, d = Zt(t, u);
if (d !== void 0)
return i(this, p).build(this, r).setData(d, { ...s, manual: !0 });
}
setQueriesData(e, t, s) {
return E.batch(
() => i(this, p).findAll(e).map(({ queryKey: r }) => [
r,
this.setQueryData(r, t, s)
])
);
}
getQueryState(e) {
var s;
const t = this.defaultQueryOptions({ queryKey: e });
return (s = i(this, p).get(
t.queryHash
)) == null ? void 0 : s.state;
}
removeQueries(e) {
const t = i(this, p);
E.batch(() => {
t.findAll(e).forEach((s) => {
t.remove(s);
});
});
}
resetQueries(e, t) {
const s = i(this, p);
return E.batch(() => (s.findAll(e).forEach((r) => {
r.reset();
}), this.refetchQueries(
{
type: "active",
...e
},
t
)));
}
cancelQueries(e, t = {}) {
const s = { revert: !0, ...t }, r = E.batch(
() => i(this, p).findAll(e).map((n) => n.cancel(s))
);
return Promise.all(r).then(M).catch(M);
}
invalidateQueries(e, t = {}) {
return E.batch(() => (i(this, p).findAll(e).forEach((s) => {
s.invalidate();
}), (e == null ? void 0 : e.refetchType) === "none" ? Promise.resolve() : this.refetchQueries(
{
...e,
type: (e == null ? void 0 : e.refetchType) ?? (e == null ? void 0 : e.type) ?? "active"
},
t
)));
}
refetchQueries(e, t = {}) {
const s = {
...t,
cancelRefetch: t.cancelRefetch ?? !0
}, r = E.batch(
() => i(this, p).findAll(e).filter((n) => !n.isDisabled() && !n.isStatic()).map((n) => {
let u = n.fetch(void 0, s);
return s.throwOnError || (u = u.catch(M)), n.state.fetchStatus === "paused" ? Promise.resolve() : u;
})
);
return Promise.all(r).then(M);
}
fetchQuery(e) {
const t = this.defaultQueryOptions(e);
t.retry === void 0 && (t.retry = !1);
const s = i(this, p).build(this, t);
return s.isStaleByTime(
Ot(t.staleTime, s)
) ? s.fetch(t) : Promise.resolve(s.state.data);
}
prefetchQuery(e) {
return this.fetchQuery(e).then(M).catch(M);
}
fetchInfiniteQuery(e) {
return e.behavior = Rt(e.pages), this.fetchQuery(e);
}
prefetchInfiniteQuery(e) {
return this.fetchInfiniteQuery(e).then(M).catch(M);
}
ensureInfiniteQueryData(e) {
return e.behavior = Rt(e.pages), this.ensureQueryData(e);
}
resumePausedMutations() {
return gt.isOnline() ? i(this, _).resumePausedMutations() : Promise.resolve();
}
getQueryCache() {
return i(this, p);
}
getMutationCache() {
return i(this, _);
}
getDefaultOptions() {
return i(this, V);
}
setDefaultOptions(e) {
o(this, V, e);
}
setQueryDefaults(e, t) {
i(this, it).set(ht(e), {
queryKey: e,
defaultOptions: t
});
}
getQueryDefaults(e) {
const t = [...i(this, it).values()], s = {};
return t.forEach((r) => {
ct(e, r.queryKey) && Object.assign(s, r.defaultOptions);
}), s;
}
setMutationDefaults(e, t) {
i(this, nt).set(ht(e), {
mutationKey: e,
defaultOptions: t
});
}
getMutationDefaults(e) {
const t = [...i(this, nt).values()], s = {};
return t.forEach((r) => {
ct(e, r.mutationKey) && Object.assign(s, r.defaultOptions);
}), s;
}
defaultQueryOptions(e) {
if (e._defaulted)
return e;
const t = {
...i(this, V).queries,
...this.getQueryDefaults(e.queryKey),
...e,
_defaulted: !0
};
return t.queryHash || (t.queryHash = qt(
t.queryKey,
t
)), t.refetchOnReconnect === void 0 && (t.refetchOnReconnect = t.networkMode !== "always"), t.throwOnError === void 0 && (t.throwOnError = !!t.suspense), !t.networkMode && t.persister && (t.networkMode = "offlineFirst"), t.queryFn === vt && (t.enabled = !1), t;
}
defaultMutationOptions(e) {
return e != null && e._defaulted ? e : {
...i(this, V).mutations,
...(e == null ? void 0 : e.mutationKey) && this.getMutationDefaults(e.mutationKey),
...e,
_defaulted: !0
};
}
clear() {
i(this, p).clear(), i(this, _).clear();
}
}, p = new WeakMap(), _ = new WeakMap(), V = new WeakMap(), it = new WeakMap(), nt = new WeakMap(), $ = new WeakMap(), at = new WeakMap(), ut = new WeakMap(), Lt), Fe = Nt.createContext(
void 0
), Oe = ({
client: e,
children: t
}) => (Nt.useEffect(() => (e.mount(), () => {
e.unmount();
}), [e]), /* @__PURE__ */ ot(Fe.Provider, { value: e, children: t }));
const Ce = new Pe(), Me = (e) => {
const { children: t, customVariables: s, customDarkVariables: r, workerUrl: n, licenseKey: u, ...d } = e, { workerUrlAdded: a } = Xt(n);
return /* @__PURE__ */ ot(Oe, { client: Ce, children: /* @__PURE__ */ ot(Yt, { licenseKey: u, children: /* @__PURE__ */ ot(Wt, { workerUrlAdded: a, ...d, children: /* @__PURE__ */ ot(Jt, { customDarkVariables: r, customVariables: s, children: t }) }) }) });
};
export {
Me as RPConfig
};