mirador
Version:
An open-source, web-based 'multi-up' viewer that supports zoom-pan-rotate functionality, ability to display/compare simple images, and images with annotations.
403 lines (402 loc) • 17 kB
JavaScript
import { $ as e, E as t, F as n, G as r, L as i, N as a, R as o, S as s, b as c, f as l, m as u, rt as d, tt as f, u as p, ut as m, w as h } from "./getters-DPoFra9X.js";
import { $t as g, Bt as _, It as v, Qt as y, Xt as b, Yt as x, p as S, t as C, un as w } from "./canvases-xKdr7cbX.js";
import { useEffect as T, useMemo as E, useRef as D } from "react";
//#region node_modules/lodash/_isFlattenable.js
var O = /* @__PURE__ */ m(((e, t) => {
var n = f(), r = h(), i = d(), a = n ? n.isConcatSpreadable : void 0;
function o(e) {
return i(e) || r(e) || !!(a && e && e[a]);
}
t.exports = o;
})), ee = /* @__PURE__ */ m(((e, t) => {
var n = x(), r = O();
function i(e, t, a, o, s) {
var c = -1, l = e.length;
for (a ||= r, s ||= []; ++c < l;) {
var u = e[c];
t > 0 && a(u) ? t > 1 ? i(u, t - 1, a, o, s) : n(s, u) : o || (s[s.length] = u);
}
return s;
}
t.exports = i;
})), k = /* @__PURE__ */ m(((e, t) => {
var n = o(), r = Math.max;
function i(e, t, i) {
return t = r(t === void 0 ? e.length - 1 : t, 0), function() {
for (var a = arguments, o = -1, s = r(a.length - t, 0), c = Array(s); ++o < s;) c[o] = a[t + o];
o = -1;
for (var l = Array(t + 1); ++o < t;) l[o] = a[o];
return l[t] = i(c), n(e, this, l);
};
}
t.exports = i;
})), A = /* @__PURE__ */ m(((e, t) => {
var i = r(), a = k(), o = n();
function s(e, t) {
return o(a(e, t, i), e + "");
}
t.exports = s;
})), j = /* @__PURE__ */ m(((e, t) => {
function n(e, t, n) {
for (var r = -1, i = e == null ? 0 : e.length; ++r < i;) if (n(t, e[r])) return !0;
return !1;
}
t.exports = n;
})), te = /* @__PURE__ */ m(((e, n) => {
var r = t(), a = i(), o = b();
n.exports = r && 1 / o(new r([, -0]))[1] == 1 / 0 ? function(e) {
return new r(e);
} : a;
})), M = /* @__PURE__ */ m(((e, t) => {
var n = g(), r = a(), i = j(), o = y(), s = te(), c = b(), l = 200;
function u(e, t, a) {
var u = -1, d = r, f = e.length, p = !0, m = [], h = m;
if (a) p = !1, d = i;
else if (f >= l) {
var g = t ? null : s(e);
if (g) return c(g);
p = !1, d = o, h = new n();
} else h = t ? [] : m;
outer: for (; ++u < f;) {
var _ = e[u], v = t ? t(_) : _;
if (_ = a || _ !== 0 ? _ : 0, p && v === v) {
for (var y = h.length; y--;) if (h[y] === v) continue outer;
t && h.push(v), m.push(_);
} else d(h, v, a) || (h !== m && h.push(v), m.push(_));
}
return m;
}
t.exports = u;
})), N = /* @__PURE__ */ m(((t, n) => {
var r = s(), i = e();
function a(e) {
return i(e) && r(e);
}
n.exports = a;
})), P = /* @__PURE__ */ m(((e, t) => {
var n = g(), r = a(), i = j(), o = w(), s = c(), l = y(), u = 200;
function d(e, t, a, c) {
var d = -1, f = r, p = !0, m = e.length, h = [], g = t.length;
if (!m) return h;
a && (t = o(t, s(a))), c ? (f = i, p = !1) : t.length >= u && (f = l, p = !1, t = new n(t));
outer: for (; ++d < m;) {
var _ = e[d], v = a == null ? _ : a(_);
if (_ = c || _ !== 0 ? _ : 0, p && v === v) {
for (var y = g; y--;) if (t[y] === v) continue outer;
h.push(_);
} else f(t, v, c) || h.push(_);
}
return h;
}
t.exports = d;
})), F = u([C, v], (e, t) => e ? t(e).imageResources : []), I = u([(e) => l(e).layers, (e, { windowId: t }) => t], (e, t) => e && e[t] || p), L = u([I, (e, { canvasId: t }) => t], (e, t) => e[t]), R = u([F, L], (e, t) => t ? e.sort((e, n) => t[e.id] && t[e.id].index !== void 0 && t[n.id] && t[n.id].index !== void 0 ? t[e.id].index - t[n.id].index : t[e.id] && t[e.id].index !== void 0 ? -1 : t[n.id] && t[n.id].index !== void 0 ? 1 : 0) : e), z = u([S, I], (e, t) => e.reduce((e, n) => (e[n] = t[n], e), {})), B = "text/plain", V = "us-ascii", H = "%(?:3A|2F|3F|23|5B|5D|40|21|24|26|27|28|29|2A|2B|2C|3B|3D)", U = "__normalize_url_encoded_reserved__", W = /__normalize_url_encoded_reserved__(\d+)__/g, G = new RegExp(H, "i"), K = new RegExp(H, "gi"), q = (e, t) => Array.isArray(t) && t.some((t) => t instanceof RegExp ? t.flags.includes("g") || t.flags.includes("y") ? new RegExp(t.source, t.flags.replaceAll(/[gy]/g, "")).test(e) : t.test(e) : t === e), J = /* @__PURE__ */ new Set([
"https:",
"http:",
"file:"
]), Y = (e) => {
if (typeof e != "string") return;
let t = e.trim().toLowerCase().replace(/:$/, "");
return t === "" ? void 0 : `${t}:`;
}, X = (e) => {
try {
let { protocol: t } = new URL(e), n = e.slice(0, t.length + 2).toLowerCase() === `${t}//`;
if (t === "localhost:" && !n && /^\d{1,5}([/?#]|$)/.test(e.slice(t.length))) return;
if (t.endsWith(":") && (!t.includes(".") || n) && !J.has(t)) return t;
} catch {}
}, Z = (e) => {
try {
return decodeURIComponent(e.replaceAll("+", "%20"));
} catch {
return new URLSearchParams(`${e}=`).keys().next().value;
}
}, ne = (e) => {
let t = /* @__PURE__ */ new Set();
if (!e) return t;
for (let n of e.slice(1).split("&")) n && !n.includes("=") && t.add(Z(n));
return t;
}, re = (e) => {
let t = e;
try {
t = decodeURIComponent(e);
} catch {
t = new URLSearchParams(e).toString();
}
let n = (e) => {
let t = /* @__PURE__ */ new Set();
for (let n of e.matchAll(W)) t.add(Number.parseInt(n[1], 10));
return t;
}, r = n(e);
for (let e of n(t)) r.add(e);
let i = 0;
for (; r.has(i);) i++;
return `${U}${i}__`;
}, ie = (e, t) => {
if (!t) return e.sort(), e.toString();
let n = (e) => e.replace(t, (e, t) => String.fromCodePoint(Number.parseInt(t, 16))), r = [...e.entries()];
return r.sort(([e], [t]) => {
let r = n(e), i = n(t);
return r < i ? -1 : +(r > i);
}), new URLSearchParams(r).toString();
}, Q = (e, t) => t ? e.replace(t, (e, t) => String.fromCodePoint(Number.parseInt(t, 16))) : e, ae = (e, t, n) => {
let r = t === "always", i = t === "never", a = r || i ? void 0 : ne(n), o = (e) => e.replaceAll("+", "%20"), s = (e) => r ? `${e}=` : i || a.has(Z(e)) ? e : `${e}=`, c = (e) => {
let t = e.indexOf("=");
if (t === -1) return s(o(e));
let n = e.slice(0, t), r = e.slice(t + 1);
return r === "" ? n === "" ? "=" : s(o(n)) : `${o(n)}=${r}`;
}, l = e.slice(1).split("&").filter(Boolean);
return l.length === 0 ? "" : `?${l.map((e) => c(e)).join("&")}`;
}, oe = (e, { stripHash: t }) => {
let n = /^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(e);
if (!n) throw Error(`Invalid URL: ${e}`);
let { type: r, data: i, hash: a } = n.groups, o = r.split(";"), s = o.at(-1) === "base64";
s && o.pop();
let c = o.shift().toLowerCase(), l = [...o.map((e) => {
let [t, n = ""] = e.split("=").map((e) => e.trim());
return t === "charset" && (n = n.toLowerCase(), n === V) ? "" : `${t}${n ? `=${n}` : ""}`;
}).filter(Boolean)];
s && l.push("base64"), (l.length > 0 || c && c !== B) && l.unshift(c);
let u = t || !a ? "" : `#${a}`;
return `data:${l.join(";")},${s ? i.trim() : i}${u}`;
};
function $(e, t) {
if (t = {
defaultProtocol: "http",
normalizeProtocol: !0,
forceHttp: !1,
forceHttps: !1,
stripAuthentication: !0,
stripHash: !1,
stripTextFragment: !0,
stripWWW: !0,
removeQueryParameters: [/^utm_\w+/i],
removeTrailingSlash: !0,
removeSingleSlash: !0,
removeDirectoryIndex: !1,
removeExplicitPort: !1,
sortQueryParameters: !0,
removePath: !1,
transformPath: !1,
emptyQueryValue: "preserve",
...t
}, typeof t.defaultProtocol == "string" && !t.defaultProtocol.endsWith(":") && (t.defaultProtocol = `${t.defaultProtocol}:`), e = e.trim(), /^data:/i.test(e)) return oe(e, t);
let n = Array.isArray(t.customProtocols) ? t.customProtocols : [], r = new Set(n.map((e) => Y(e)).filter(Boolean)), i = X(e);
if (i && !r.has(i)) return e;
let a = e.startsWith("//");
!(!a && /^\.*\//.test(e)) && !i && (e = e.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, t.defaultProtocol));
let o = new URL(e);
if (t.forceHttp && t.forceHttps) throw Error("The `forceHttp` and `forceHttps` options cannot be used together");
if (t.forceHttp && o.protocol === "https:" && (o.protocol = "http:"), t.forceHttps && o.protocol === "http:" && (o.protocol = "https:"), t.stripAuthentication && (o.username = "", o.password = ""), t.stripHash ? o.hash = "" : t.stripTextFragment && (o.hash = o.hash.replace(/#?:~:text.*?$/i, "")), o.pathname) {
let e = /\b[a-z][a-z\d+\-.]{1,50}:\/\//g, t = 0, n = "";
for (;;) {
let r = e.exec(o.pathname);
if (!r) break;
let i = r[0], a = r.index, s = o.pathname.slice(t, a);
n += s.replaceAll(/\/{2,}/g, "/"), n += i, t = a + i.length;
}
let r = o.pathname.slice(t);
n += r.replaceAll(/\/{2,}/g, "/"), o.pathname = n;
}
if (o.pathname) try {
o.pathname = decodeURI(o.pathname).replaceAll("\\", "%5C");
} catch {}
if (t.removeDirectoryIndex === !0 && (t.removeDirectoryIndex = [/^index\.[a-z]+$/]), Array.isArray(t.removeDirectoryIndex) && t.removeDirectoryIndex.length > 0) {
let e = o.pathname.split("/").filter(Boolean), n = e.at(-1);
n && q(n, t.removeDirectoryIndex) && (e.pop(), o.pathname = e.length > 0 ? `/${e.join("/")}/` : "/");
}
if (t.removePath && (o.pathname = "/"), t.transformPath && typeof t.transformPath == "function") {
let e = o.pathname.split("/").filter(Boolean), n = t.transformPath(e);
o.pathname = n?.length > 0 ? `/${n.join("/")}` : "/";
}
o.hostname && (o.hostname = o.hostname.replace(/\.$/, ""), t.stripWWW && /^www\.(?!www\.)[a-z\-\d]{1,63}\.[a-z.\-\d]{2,63}$/.test(o.hostname) && (o.hostname = o.hostname.replace(/^www\./, "")));
let s = o.search, c;
if (t.sortQueryParameters && G.test(s)) {
let e = re(s);
o.search = s.replaceAll(K, (t) => `${e}${t.slice(1).toUpperCase()}`), c = RegExp(`${e}([0-9A-F]{2})`, "g");
}
let l = Array.isArray(t.keepQueryParameters), { searchParams: u } = o;
if (!l && Array.isArray(t.removeQueryParameters) && t.removeQueryParameters.length > 0) for (let e of [...u.keys()]) q(Q(e, c), t.removeQueryParameters) && u.delete(e);
if (!l && t.removeQueryParameters === !0 && (o.search = ""), l && t.keepQueryParameters.length > 0) for (let e of [...u.keys()]) q(Q(e, c), t.keepQueryParameters) || u.delete(e);
else l && (o.search = "");
t.sortQueryParameters && (o.search = ie(o.searchParams, c), o.search = decodeURIComponent(o.search.replaceAll(/%(?:26|23|3f|25|2b)/gi, (e) => `%25${e.slice(1)}`)), c && (o.search = o.search.replace(c, "%$1"))), o.search = ae(o.search, t.emptyQueryValue, s), t.removeTrailingSlash && (o.pathname = o.pathname.replace(/\/$/, "")), t.removeExplicitPort && o.port && (o.port = "");
let d = e;
return e = o.toString(), !t.removeSingleSlash && o.pathname === "/" && !d.endsWith("/") && o.hash === "" && (e = e.replace(/\/$/, "")), (t.removeTrailingSlash || o.pathname === "/") && o.hash === "" && t.removeSingleSlash && (e = e.replace(/\/$/, "")), a && !t.normalizeProtocol && (e = e.replace(/^http:\/\//, "//")), t.stripProtocol && (e = e.replace(/^(?:https?:)?\/\//, "")), e;
}
//#endregion
//#region src/lib/CanvasWorld.js
var se = class {
constructor(e, t, n = "left-to-right") {
this.canvases = e, this.layers = t, this.viewingDirection = n, this._canvasDimensions = null;
}
get canvasIds() {
return this.canvases.map((e) => e.id);
}
get canvasDimensions() {
if (this._canvasDimensions) return this._canvasDimensions;
let [e, t] = this.canvasDirection, n = Math.min(...t === 0 ? this.canvases.map((e) => e.getHeight()) : this.canvases.map((e) => e.getWidth())), r = 0, i = 0, a = this.canvases.reduce((a, o) => {
let s = 0, c = 0;
return Number.isNaN(o.aspectRatio) || (t === 0 ? (s = n, c = Math.floor(n * o.aspectRatio)) : (c = n, s = Math.floor(n * (1 / o.aspectRatio)))), a.push({
canvas: o,
height: s,
width: c,
x: r,
y: i
}), r += e * c, i += t * s, a;
}, []), o = t === 0 ? n : Math.abs(i), s = e === 0 ? n : Math.abs(r);
return this._canvasDimensions = a.reduce((n, r) => (n.push({
...r,
x: e === -1 ? r.x + s - r.width : r.x,
y: t === -1 ? r.y + o - r.height : r.y
}), n), []), this._canvasDimensions;
}
contentResourceToWorldCoordinates(e) {
let t = this.canvases.findIndex((t) => t.imageResources.find((t) => t.id === e.id)), n = this.canvases[t];
if (!n) return [];
let [r, i, a, o] = this.canvasToWorldCoordinates(n.id), s = n.onFragment(e.id);
return s ? [
r + s[0],
i + s[1],
s[2],
s[3]
] : [
r,
i,
a,
o
];
}
canvasToWorldCoordinates(e) {
let t = this.canvasDimensions.find((t) => t.canvas.id === e);
return [
t.x,
t.y,
t.width,
t.height
];
}
get canvasDirection() {
switch (this.viewingDirection) {
case "left-to-right": return [1, 0];
case "right-to-left": return [-1, 0];
case "top-to-bottom": return [0, 1];
case "bottom-to-top": return [0, -1];
default: return [1, 0];
}
}
contentResource(e) {
let t = this.canvases.find((t) => t.imageServiceIds.some((t) => t && e && $(t, { stripAuthentication: !1 }) === $(e, { stripAuthentication: !1 })));
if (t) return t.imageResources.find((t) => $(_(t).id, { stripAuthentication: !1 }) === $(e, { stripAuthentication: !1 }));
}
getLayerMetadata(e) {
let t = this.canvases.find((t) => t.imageResources.find((t) => t.id === e.id));
if (!t) return;
let n = t.imageResources.findIndex((t) => t.id === e.id), r = t.imageResources.find((t) => t.id === e.id), i = this.layers && this.layers[t.canvas.id], a = i && i[e.id] || {};
return {
index: n,
opacity: 1,
total: t.imageResources.length,
visibility: !!r.preferred,
...a
};
}
layerOpacityOfImageResource(e) {
let t = this.getLayerMetadata(e);
return t ? t.visibility ? t.opacity : 0 : 1;
}
layerIndexOfImageResource(e) {
let t = this.getLayerMetadata(e);
if (t) return t.index;
}
offsetByCanvas(e) {
let t = this.canvasToWorldCoordinates(e);
return {
x: t[0],
y: t[1]
};
}
hasDimensions() {
return this.canvasDimensions.length > 0;
}
worldBounds() {
return [
0,
0,
Math.max(0, ...this.canvasDimensions.map((e) => e.x + e.width)),
Math.max(0, ...this.canvasDimensions.map((e) => e.y + e.height))
];
}
canvasAtPoint(e) {
let t = this.canvasDimensions.find((t) => t.x <= e.x && e.x <= t.x + t.width && t.y <= e.y && e.y <= t.y + t.height);
return t && t.canvas;
}
};
//#endregion
//#region node_modules/use-debounce/dist/index.module.js
function ce(e, t, n, r) {
var i = this, a = D(null), o = D(0), s = D(0), c = D(null), l = D([]), u = D(), d = D(), f = D(e), p = D(!0), m = D(), h = D();
f.current = e;
var g = typeof window < "u", _ = !t && t !== 0 && g;
if (typeof e != "function") throw TypeError("Expected a function");
t = +t || 0;
var v = !!(n ||= {}).leading, y = !("trailing" in n) || !!n.trailing, b = !!n.flushOnExit && y, x = "maxWait" in n, S = "debounceOnServer" in n && !!n.debounceOnServer, C = x ? Math.max(+n.maxWait || 0, t) : null, w = E(function() {
var e = function(e) {
var t = l.current, n = u.current;
return l.current = u.current = null, o.current = e, s.current = s.current || e, d.current = f.current.apply(n, t);
}, n = function(e, t) {
_ && cancelAnimationFrame(c.current), c.current = _ ? requestAnimationFrame(e) : setTimeout(e, t);
}, w = function(e) {
if (!p.current) return !1;
var n = e - a.current;
return !a.current || n >= t || n < 0 || x && e - o.current >= C;
}, T = function(t) {
return c.current = null, y && l.current ? e(t) : (l.current = u.current = null, d.current);
}, E = function e() {
var r = Date.now();
if (v && s.current === o.current && D(), w(r)) return T(r);
if (p.current) {
var i = t - (r - a.current);
n(e, x ? Math.min(i, C - (r - o.current)) : i);
}
}, D = function() {
r && r({});
}, O = function() {
if (g || S) {
var r, s = Date.now(), f = w(s);
if (l.current = [].slice.call(arguments), u.current = i, a.current = s, b && !m.current && (m.current = function() {
globalThis.document?.visibilityState === "hidden" && h.current.flush();
}, (r = globalThis.document) == null || r.addEventListener == null || r.addEventListener("visibilitychange", m.current)), f) {
if (!c.current && p.current) return o.current = a.current, n(E, t), v ? e(a.current) : d.current;
if (x) return n(E, t), e(a.current);
}
return c.current || n(E, t), d.current;
}
};
return O.cancel = function() {
var e = c.current;
e && (_ ? cancelAnimationFrame(c.current) : clearTimeout(c.current)), o.current = 0, l.current = a.current = u.current = c.current = null, e && r && r({});
}, O.isPending = function() {
return !!c.current;
}, O.flush = function() {
return c.current ? T(Date.now()) : d.current;
}, O;
}, [
v,
x,
t,
C,
y,
b,
_,
g,
S,
r
]);
return h.current = w, T(function() {
return p.current = !0, function() {
var e;
b && h.current.flush(), m.current &&= ((e = globalThis.document) == null || e.removeEventListener == null || e.removeEventListener("visibilitychange", m.current), null), p.current = !1;
};
}, [b]), w;
}
//#endregion
export { L as a, R as c, M as d, A as f, F as i, P as l, ee as m, se as n, z as o, k as p, $ as r, I as s, ce as t, N as u };
//# sourceMappingURL=index.module-dbOTBfsw.js.map